xinference 0.15.1__py3-none-any.whl → 0.15.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xinference might be problematic. Click here for more details.

Files changed (23) hide show
  1. xinference/_version.py +3 -3
  2. xinference/core/model.py +2 -2
  3. xinference/model/audio/cosyvoice.py +3 -3
  4. xinference/model/image/stable_diffusion/core.py +30 -19
  5. xinference/model/llm/__init__.py +1 -1
  6. xinference/model/llm/llm_family.json +850 -2
  7. xinference/model/llm/llm_family_modelscope.json +893 -0
  8. xinference/model/llm/sglang/core.py +4 -0
  9. xinference/model/llm/vllm/core.py +5 -0
  10. xinference/web/ui/build/asset-manifest.json +3 -3
  11. xinference/web/ui/build/index.html +1 -1
  12. xinference/web/ui/build/static/js/{main.754740c0.js → main.29578905.js} +3 -3
  13. xinference/web/ui/build/static/js/main.29578905.js.map +1 -0
  14. xinference/web/ui/node_modules/.cache/babel-loader/c7bf40bab396765f67d0fed627ed3665890608b2d0edaa3e8cb7cfc96310db45.json +1 -0
  15. {xinference-0.15.1.dist-info → xinference-0.15.2.dist-info}/METADATA +5 -5
  16. {xinference-0.15.1.dist-info → xinference-0.15.2.dist-info}/RECORD +21 -21
  17. xinference/web/ui/build/static/js/main.754740c0.js.map +0 -1
  18. xinference/web/ui/node_modules/.cache/babel-loader/cd90b08d177025dfe84209596fc51878f8a86bcaa6a240848a3d2e5fd4c7ff24.json +0 -1
  19. /xinference/web/ui/build/static/js/{main.754740c0.js.LICENSE.txt → main.29578905.js.LICENSE.txt} +0 -0
  20. {xinference-0.15.1.dist-info → xinference-0.15.2.dist-info}/LICENSE +0 -0
  21. {xinference-0.15.1.dist-info → xinference-0.15.2.dist-info}/WHEEL +0 -0
  22. {xinference-0.15.1.dist-info → xinference-0.15.2.dist-info}/entry_points.txt +0 -0
  23. {xinference-0.15.1.dist-info → xinference-0.15.2.dist-info}/top_level.txt +0 -0
xinference/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-09-14T13:22:13+0800",
11
+ "date": "2024-09-20T16:58:06+0800",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "961d355102007e3cd7963a353105b2422a31d4fd",
15
- "version": "0.15.1"
14
+ "full-revisionid": "5de46e94c23785fa7e17e3e1d00c3afb6cb1c919",
15
+ "version": "0.15.2"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
xinference/core/model.py CHANGED
@@ -769,7 +769,7 @@ class ModelActor(xo.StatelessActor):
769
769
  self,
770
770
  image: "PIL.Image",
771
771
  prompt: str,
772
- negative_prompt: str,
772
+ negative_prompt: Optional[str] = None,
773
773
  n: int = 1,
774
774
  size: Optional[str] = None,
775
775
  response_format: str = "url",
@@ -777,12 +777,12 @@ class ModelActor(xo.StatelessActor):
777
777
  **kwargs,
778
778
  ):
779
779
  kwargs.pop("request_id", None)
780
+ kwargs["negative_prompt"] = negative_prompt
780
781
  if hasattr(self._model, "image_to_image"):
781
782
  return await self._call_wrapper_json(
782
783
  self._model.image_to_image,
783
784
  image,
784
785
  prompt,
785
- negative_prompt,
786
786
  n,
787
787
  size,
788
788
  response_format,
@@ -122,10 +122,10 @@ class CosyVoiceModel:
122
122
  last_pos = new_last_pos
123
123
 
124
124
  def _generator_block():
125
- chunk = next(output)
126
- assert isinstance(chunk, dict), "Expected data to be of type dict"
125
+ chunks = [o["tts_speech"] for o in output]
126
+ t = torch.cat(chunks, dim=1)
127
127
  with BytesIO() as out:
128
- torchaudio.save(out, chunk["tts_speech"], 22050, format=response_format)
128
+ torchaudio.save(out, t, 22050, format=response_format)
129
129
  return out.getvalue()
130
130
 
131
131
  return _generator_stream() if stream else _generator_block()
@@ -21,6 +21,7 @@ import re
21
21
  import sys
22
22
  import time
23
23
  import uuid
24
+ import warnings
24
25
  from concurrent.futures import ThreadPoolExecutor
25
26
  from functools import partial
26
27
  from io import BytesIO
@@ -31,7 +32,7 @@ import torch
31
32
  from PIL import ImageOps
32
33
 
33
34
  from ....constants import XINFERENCE_IMAGE_DIR
34
- from ....device_utils import move_model_to_available_device
35
+ from ....device_utils import get_available_device, move_model_to_available_device
35
36
  from ....types import Image, ImageList, LoRA
36
37
  from ..sdapi import SDAPIDiffusionModelMixin
37
38
 
@@ -60,6 +61,23 @@ SAMPLING_METHODS = [
60
61
  ]
61
62
 
62
63
 
64
+ def model_accept_param(params: Union[str, List[str]], model: Any) -> bool:
65
+ params = [params] if isinstance(params, str) else params
66
+ # model is diffusers Pipeline
67
+ parameters = inspect.signature(model.__call__).parameters # type: ignore
68
+ allow_params = False
69
+ for param in parameters.values():
70
+ if param.kind == inspect.Parameter.VAR_KEYWORD:
71
+ # the __call__ can accept **kwargs,
72
+ # we treat it as it can accept any parameters
73
+ allow_params = True
74
+ break
75
+ if not allow_params:
76
+ if all(param in parameters for param in params):
77
+ allow_params = True
78
+ return allow_params
79
+
80
+
63
81
  class DiffusionModel(SDAPIDiffusionModelMixin):
64
82
  def __init__(
65
83
  self,
@@ -187,7 +205,7 @@ class DiffusionModel(SDAPIDiffusionModelMixin):
187
205
 
188
206
  @staticmethod
189
207
  def _get_scheduler(model: Any, sampler_name: str):
190
- if not sampler_name:
208
+ if not sampler_name or sampler_name == "default":
191
209
  return
192
210
 
193
211
  assert model is not None
@@ -283,13 +301,14 @@ class DiffusionModel(SDAPIDiffusionModelMixin):
283
301
  origin_size = kwargs.pop("origin_size", None)
284
302
  seed = kwargs.pop("seed", None)
285
303
  if seed is not None:
286
- kwargs["generator"] = generator = torch.Generator(device=self._model.device) # type: ignore
304
+ kwargs["generator"] = generator = torch.Generator(device=get_available_device()) # type: ignore
287
305
  if seed != -1:
288
306
  kwargs["generator"] = generator.manual_seed(seed)
289
307
  sampler_name = kwargs.pop("sampler_name", None)
290
308
  assert callable(model)
291
309
  with self._reset_when_done(model, sampler_name):
292
310
  logger.debug("stable diffusion args: %s, model: %s", kwargs, model)
311
+ self._filter_kwargs(model, kwargs)
293
312
  images = model(**kwargs).images
294
313
 
295
314
  # revert padding if padded
@@ -328,11 +347,17 @@ class DiffusionModel(SDAPIDiffusionModelMixin):
328
347
  raise ValueError(f"Unsupported response format: {response_format}")
329
348
 
330
349
  @classmethod
331
- def _filter_kwargs(cls, kwargs: dict):
350
+ def _filter_kwargs(cls, model, kwargs: dict):
332
351
  for arg in ["negative_prompt", "num_inference_steps"]:
333
352
  if not kwargs.get(arg):
334
353
  kwargs.pop(arg, None)
335
354
 
355
+ for key in list(kwargs):
356
+ allow_key = model_accept_param(key, model)
357
+ if not allow_key:
358
+ warnings.warn(f"{type(model)} cannot accept `{key}`, will ignore it")
359
+ kwargs.pop(key)
360
+
336
361
  def text_to_image(
337
362
  self,
338
363
  prompt: str,
@@ -346,7 +371,6 @@ class DiffusionModel(SDAPIDiffusionModelMixin):
346
371
  width, height = map(int, re.split(r"[^\d]+", size))
347
372
  generate_kwargs = self._model_spec.default_generate_config.copy() # type: ignore
348
373
  generate_kwargs.update({k: v for k, v in kwargs.items() if v is not None})
349
- self._filter_kwargs(generate_kwargs)
350
374
  return self._call_model(
351
375
  prompt=prompt,
352
376
  height=height,
@@ -368,7 +392,6 @@ class DiffusionModel(SDAPIDiffusionModelMixin):
368
392
  self,
369
393
  image: PIL.Image,
370
394
  prompt: Optional[Union[str, List[str]]] = None,
371
- negative_prompt: Optional[Union[str, List[str]]] = None,
372
395
  n: int = 1,
373
396
  size: Optional[str] = None,
374
397
  response_format: str = "url",
@@ -404,19 +427,10 @@ class DiffusionModel(SDAPIDiffusionModelMixin):
404
427
  kwargs["height"] = height
405
428
  else:
406
429
  # SD3 image2image cannot accept width and height
407
- parameters = inspect.signature(model.__call__).parameters # type: ignore
408
- allow_width_height = False
409
- for param in parameters.values():
410
- if param.kind == inspect.Parameter.VAR_KEYWORD:
411
- allow_width_height = True
412
- break
413
- if "width" in parameters or "height" in parameters:
414
- allow_width_height = True
430
+ allow_width_height = model_accept_param(["width", "height"], model)
415
431
  if allow_width_height:
416
432
  kwargs["width"], kwargs["height"] = image.size
417
433
 
418
- kwargs["negative_prompt"] = negative_prompt
419
- self._filter_kwargs(kwargs)
420
434
  return self._call_model(
421
435
  image=image,
422
436
  prompt=prompt,
@@ -431,7 +445,6 @@ class DiffusionModel(SDAPIDiffusionModelMixin):
431
445
  image: PIL.Image,
432
446
  mask_image: PIL.Image,
433
447
  prompt: Optional[Union[str, List[str]]] = None,
434
- negative_prompt: Optional[Union[str, List[str]]] = None,
435
448
  n: int = 1,
436
449
  size: str = "1024*1024",
437
450
  response_format: str = "url",
@@ -469,8 +482,6 @@ class DiffusionModel(SDAPIDiffusionModelMixin):
469
482
  # calculate actual image size after padding
470
483
  width, height = image.size
471
484
 
472
- kwargs["negative_prompt"] = negative_prompt
473
- self._filter_kwargs(kwargs)
474
485
  return self._call_model(
475
486
  image=image,
476
487
  mask_image=mask_image,
@@ -121,7 +121,7 @@ def register_custom_model():
121
121
  with codecs.open(
122
122
  os.path.join(user_defined_llm_dir, f), encoding="utf-8"
123
123
  ) as fd:
124
- user_defined_llm_family = CustomLLMFamilyV1.parse_obj(json.load(fd))
124
+ user_defined_llm_family = CustomLLMFamilyV1.parse_raw(fd.read())
125
125
  register_llm(user_defined_llm_family, persist=False)
126
126
  except Exception as e:
127
127
  warnings.warn(f"{user_defined_llm_dir}/{f} has error, {e}")