Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Support sd-turbo #797

Merged
merged 5 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ jobs:
if [ "$MODULE" == "gpu" ]; then
${{ env.SELF_HOST_PYTHON }} -m pip install "openai>1"
${{ env.SELF_HOST_PYTHON }} -m pip install -U modelscope
${{ env.SELF_HOST_PYTHON }} -m pip install -U sse_starlette
${{ env.SELF_HOST_PYTHON }} -m pytest --timeout=1500 \
-W ignore::PendingDeprecationWarning \
--cov-config=setup.cfg --cov-report=xml --cov=xinference xinference/model/image/tests/test_stable_diffusion.py
Expand Down
9 changes: 8 additions & 1 deletion xinference/api/restful_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class TextToImageRequest(BaseModel):
n: Optional[int] = 1
response_format: Optional[str] = "url"
size: Optional[str] = "1024*1024"
kwargs: Optional[str] = None
user: Optional[str] = None


Expand Down Expand Up @@ -645,8 +646,14 @@ async def create_images(self, request: TextToImageRequest) -> JSONResponse:
raise HTTPException(status_code=500, detail=str(e))

try:
if request.kwargs:
kwargs = json.loads(request.kwargs)
image_list = await model.text_to_image(
request.prompt, request.n, request.size, request.response_format
prompt=request.prompt,
n=request.n,
size=request.size,
response_format=request.response_format,
**kwargs,
)
return JSONResponse(content=image_list)
except RuntimeError as re:
Expand Down
2 changes: 2 additions & 0 deletions xinference/client/restful/restful_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def text_to_image(
n: int = 1,
size: str = "1024*1024",
response_format: str = "url",
**kwargs,
) -> "ImageList":
"""
Creates an image by the input text.
Expand All @@ -180,6 +181,7 @@ def text_to_image(
"n": n,
"size": size,
"response_format": response_format,
"kwargs": json.dumps(kwargs),
}
response = requests.post(url, json=request_body)
if response.status_code != 200:
Expand Down
6 changes: 6 additions & 0 deletions xinference/model/image/model_spec.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[
{
"model_name": "sd-turbo",
"model_family": "stable_diffusion",
"model_id": "stabilityai/sd-turbo",
"model_revision": "1681ed09e0cff58eeb41e878a49893228b78b94c"
},
{
"model_name": "stable-diffusion-v1.5",
"model_family": "stable_diffusion",
Expand Down
10 changes: 9 additions & 1 deletion xinference/model/image/stable_diffusion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ def _call_model(
response_format: str,
**kwargs,
):
logger.debug("stable diffusion kwargs: %s", kwargs)
logger.debug(
"stable diffusion args: %s",
dict(
kwargs,
height=height,
width=width,
num_images_per_prompt=num_images_per_prompt,
),
)
assert callable(self._model)
images = self._model(
height=height,
Expand Down
26 changes: 26 additions & 0 deletions xinference/model/image/tests/test_stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,32 @@ def test_restful_api_for_image_with_mlsd_controlnet(setup):
logger.info("test result %s", r)


def test_restful_api_for_sd_turbo(setup):
endpoint, _ = setup
from ....client import Client

client = Client(endpoint)

model_uid = client.launch_model(
model_uid="my_controlnet",
model_name="sd-turbo",
model_type="image",
)
model = client.get_model(model_uid)

r = model.text_to_image(
prompt="A cinematic shot of a baby raccoon wearing an intricate italian priest robe.",
size="512*512",
num_inference_steps=10,
)
logger.info("test result %s", r)
from PIL import Image

with open(r["data"][0]["url"], "rb") as f:
img = Image.open(f)
assert img.size == (512, 512)


def test_get_cache_status():
from ..core import get_cache_status

Expand Down
Loading