xinference 0.9.3__py3-none-any.whl → 0.10.0__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 (64) hide show
  1. xinference/_version.py +3 -3
  2. xinference/api/oauth2/auth_service.py +47 -18
  3. xinference/api/oauth2/types.py +1 -0
  4. xinference/api/restful_api.py +16 -11
  5. xinference/client/restful/restful_client.py +12 -2
  6. xinference/conftest.py +13 -2
  7. xinference/constants.py +2 -0
  8. xinference/core/supervisor.py +32 -1
  9. xinference/core/worker.py +139 -20
  10. xinference/deploy/cmdline.py +119 -20
  11. xinference/model/llm/__init__.py +6 -0
  12. xinference/model/llm/llm_family.json +711 -10
  13. xinference/model/llm/llm_family_modelscope.json +557 -7
  14. xinference/model/llm/pytorch/chatglm.py +2 -1
  15. xinference/model/llm/pytorch/core.py +2 -0
  16. xinference/model/llm/pytorch/deepseek_vl.py +232 -0
  17. xinference/model/llm/pytorch/internlm2.py +2 -1
  18. xinference/model/llm/pytorch/omnilmm.py +153 -0
  19. xinference/model/llm/sglang/__init__.py +13 -0
  20. xinference/model/llm/sglang/core.py +365 -0
  21. xinference/model/llm/utils.py +46 -13
  22. xinference/model/llm/vllm/core.py +10 -0
  23. xinference/thirdparty/deepseek_vl/__init__.py +31 -0
  24. xinference/thirdparty/deepseek_vl/models/__init__.py +28 -0
  25. xinference/thirdparty/deepseek_vl/models/clip_encoder.py +242 -0
  26. xinference/thirdparty/deepseek_vl/models/image_processing_vlm.py +208 -0
  27. xinference/thirdparty/deepseek_vl/models/modeling_vlm.py +170 -0
  28. xinference/thirdparty/deepseek_vl/models/processing_vlm.py +390 -0
  29. xinference/thirdparty/deepseek_vl/models/projector.py +100 -0
  30. xinference/thirdparty/deepseek_vl/models/sam.py +593 -0
  31. xinference/thirdparty/deepseek_vl/models/siglip_vit.py +681 -0
  32. xinference/thirdparty/deepseek_vl/utils/__init__.py +18 -0
  33. xinference/thirdparty/deepseek_vl/utils/conversation.py +348 -0
  34. xinference/thirdparty/deepseek_vl/utils/io.py +78 -0
  35. xinference/thirdparty/omnilmm/__init__.py +0 -0
  36. xinference/thirdparty/omnilmm/chat.py +216 -0
  37. xinference/thirdparty/omnilmm/constants.py +4 -0
  38. xinference/thirdparty/omnilmm/conversation.py +332 -0
  39. xinference/thirdparty/omnilmm/model/__init__.py +1 -0
  40. xinference/thirdparty/omnilmm/model/omnilmm.py +594 -0
  41. xinference/thirdparty/omnilmm/model/resampler.py +166 -0
  42. xinference/thirdparty/omnilmm/model/utils.py +563 -0
  43. xinference/thirdparty/omnilmm/train/__init__.py +13 -0
  44. xinference/thirdparty/omnilmm/train/train_utils.py +150 -0
  45. xinference/thirdparty/omnilmm/utils.py +134 -0
  46. xinference/web/ui/build/asset-manifest.json +3 -3
  47. xinference/web/ui/build/index.html +1 -1
  48. xinference/web/ui/build/static/js/main.98516614.js +3 -0
  49. xinference/web/ui/build/static/js/main.98516614.js.map +1 -0
  50. xinference/web/ui/node_modules/.cache/babel-loader/139969fd25258eb7decc9505f30b779089bba50c402bb5c663008477c7bff73b.json +1 -0
  51. xinference/web/ui/node_modules/.cache/babel-loader/3f357ab57b8e7fade54c667f0e0ebf2787566f72bfdca0fea14e395b5c203753.json +1 -0
  52. xinference/web/ui/node_modules/.cache/babel-loader/9d7c49815d97539207e5aab2fb967591b5fed7791218a0762539efc9491f36af.json +1 -0
  53. xinference/web/ui/node_modules/.cache/babel-loader/d0d0b591d9adaf42b83ad6633f8b7c118541a4b80ea957c303d3bf9b86fbad0a.json +1 -0
  54. {xinference-0.9.3.dist-info → xinference-0.10.0.dist-info}/METADATA +21 -5
  55. {xinference-0.9.3.dist-info → xinference-0.10.0.dist-info}/RECORD +60 -31
  56. xinference/web/ui/build/static/js/main.66b1c4fb.js +0 -3
  57. xinference/web/ui/build/static/js/main.66b1c4fb.js.map +0 -1
  58. xinference/web/ui/node_modules/.cache/babel-loader/c2124cfe036b26befcbd386d1d17743b1a58d0b7a041a17bb67f9924400d63c3.json +0 -1
  59. xinference/web/ui/node_modules/.cache/babel-loader/fd4a8ae5d192331af1bedd1d2d70efcc569708ee6cc4cb479b225d059482aa81.json +0 -1
  60. /xinference/web/ui/build/static/js/{main.66b1c4fb.js.LICENSE.txt → main.98516614.js.LICENSE.txt} +0 -0
  61. {xinference-0.9.3.dist-info → xinference-0.10.0.dist-info}/LICENSE +0 -0
  62. {xinference-0.9.3.dist-info → xinference-0.10.0.dist-info}/WHEEL +0 -0
  63. {xinference-0.9.3.dist-info → xinference-0.10.0.dist-info}/entry_points.txt +0 -0
  64. {xinference-0.9.3.dist-info → xinference-0.10.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,332 @@
1
+ import dataclasses
2
+ from enum import Enum, auto
3
+ from typing import List
4
+
5
+
6
+ class SeparatorStyle(Enum):
7
+ """Different separator style."""
8
+
9
+ SINGLE = auto()
10
+ TWO = auto()
11
+
12
+
13
+ @dataclasses.dataclass
14
+ class Conversation:
15
+ """A class that keeps all conversation history."""
16
+
17
+ system: str
18
+ roles: List[str]
19
+ messages: List[List[str]]
20
+ offset: int
21
+ sep_style: SeparatorStyle = SeparatorStyle.SINGLE
22
+ sep: str = "###"
23
+ sep2: str = None
24
+ version: str = "Unknown"
25
+
26
+ skip_next: bool = False
27
+
28
+ def get_prompt(self):
29
+ if self.sep_style == SeparatorStyle.SINGLE:
30
+ ret = self.system + self.sep
31
+ for role, message in self.messages:
32
+ if message:
33
+ if type(message) is tuple:
34
+ message, _, _ = message
35
+ ret += role + ": " + message + self.sep
36
+ else:
37
+ ret += role + ":"
38
+ return ret
39
+ elif self.sep_style == SeparatorStyle.TWO:
40
+ seps = [self.sep, self.sep2]
41
+ ret = self.system + seps[0]
42
+ for i, (role, message) in enumerate(self.messages):
43
+ if message:
44
+ if type(message) is tuple:
45
+ message, _, _ = message
46
+ ret += role + ": " + message + seps[i % 2]
47
+ else:
48
+ ret += role + ":"
49
+ return ret
50
+ else:
51
+ raise ValueError(f"Invalid style: {self.sep_style}")
52
+
53
+ def append_message(self, role, message):
54
+ self.messages.append([role, message])
55
+
56
+ def get_images(self, return_pil=False):
57
+ images = []
58
+ for i, (role, msg) in enumerate(self.messages[self.offset :]):
59
+ if i % 2 == 0:
60
+ if type(msg) is tuple:
61
+ import base64
62
+ from io import BytesIO
63
+
64
+ from PIL import Image
65
+
66
+ msg, image, image_process_mode = msg
67
+ if image_process_mode == "Pad":
68
+
69
+ def expand2square(pil_img, background_color=(122, 116, 104)):
70
+ width, height = pil_img.size
71
+ if width == height:
72
+ return pil_img
73
+ elif width > height:
74
+ result = Image.new(
75
+ pil_img.mode, (width, width), background_color
76
+ )
77
+ result.paste(pil_img, (0, (width - height) // 2))
78
+ return result
79
+ else:
80
+ result = Image.new(
81
+ pil_img.mode, (height, height), background_color
82
+ )
83
+ result.paste(pil_img, ((height - width) // 2, 0))
84
+ return result
85
+
86
+ image = expand2square(image)
87
+ elif image_process_mode == "Crop":
88
+ pass
89
+ elif image_process_mode == "Resize":
90
+ image = image.resize((224, 224))
91
+ else:
92
+ raise ValueError(
93
+ f"Invalid image_process_mode: {image_process_mode}"
94
+ )
95
+ max_hw, min_hw = max(image.size), min(image.size)
96
+ aspect_ratio = max_hw / min_hw
97
+ max_len, min_len = 800, 400
98
+ shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
99
+ longest_edge = int(shortest_edge * aspect_ratio)
100
+ W, H = image.size
101
+ if H > W:
102
+ H, W = longest_edge, shortest_edge
103
+ else:
104
+ H, W = shortest_edge, longest_edge
105
+ image = image.resize((W, H))
106
+ if return_pil:
107
+ images.append(image)
108
+ else:
109
+ buffered = BytesIO()
110
+ image.save(buffered, format="JPEG")
111
+ img_b64_str = base64.b64encode(buffered.getvalue()).decode()
112
+ images.append(img_b64_str)
113
+ return images
114
+
115
+ def to_gradio_chatbot(self):
116
+ ret = []
117
+ for i, (role, msg) in enumerate(self.messages[self.offset :]):
118
+ if i % 2 == 0:
119
+ if type(msg) is tuple:
120
+ import base64
121
+ from io import BytesIO
122
+
123
+ msg, image, image_process_mode = msg
124
+ max_hw, min_hw = max(image.size), min(image.size)
125
+ aspect_ratio = max_hw / min_hw
126
+ max_len, min_len = 800, 400
127
+ shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
128
+ longest_edge = int(shortest_edge * aspect_ratio)
129
+ W, H = image.size
130
+ if H > W:
131
+ H, W = longest_edge, shortest_edge
132
+ else:
133
+ H, W = shortest_edge, longest_edge
134
+ image = image.resize((W, H))
135
+ # image = image.resize((224, 224))
136
+ buffered = BytesIO()
137
+ image.save(buffered, format="JPEG")
138
+ img_b64_str = base64.b64encode(buffered.getvalue()).decode()
139
+ img_str = f'<img src="data:image/png;base64,{img_b64_str}" alt="user upload image" />'
140
+ msg = msg.replace("<image>", img_str)
141
+ ret.append([msg, None])
142
+ else:
143
+ ret[-1][-1] = msg
144
+ return ret
145
+
146
+ def copy(self):
147
+ return Conversation(
148
+ system=self.system,
149
+ roles=self.roles,
150
+ messages=[[x, y] for x, y in self.messages],
151
+ offset=self.offset,
152
+ sep_style=self.sep_style,
153
+ sep=self.sep,
154
+ sep2=self.sep2,
155
+ )
156
+
157
+ def dict(self):
158
+ if len(self.get_images()) > 0:
159
+ return {
160
+ "system": self.system,
161
+ "roles": self.roles,
162
+ "messages": [
163
+ [x, y[0] if type(y) is tuple else y] for x, y in self.messages
164
+ ],
165
+ "offset": self.offset,
166
+ "sep": self.sep,
167
+ "sep2": self.sep2,
168
+ }
169
+ return {
170
+ "system": self.system,
171
+ "roles": self.roles,
172
+ "messages": self.messages,
173
+ "offset": self.offset,
174
+ "sep": self.sep,
175
+ "sep2": self.sep2,
176
+ }
177
+
178
+
179
+ conv_v1 = Conversation(
180
+ system="A chat between a curious human and an artificial intelligence assistant. "
181
+ "The assistant gives helpful, detailed, and polite answers to the human's questions.",
182
+ roles=("Human", "Assistant"),
183
+ messages=(
184
+ ("Human", "Give three tips for staying healthy."),
185
+ (
186
+ "Assistant",
187
+ "Sure, here are three tips for staying healthy:\n"
188
+ "1. Exercise regularly: Regular physical activity can help improve your overall health and wellbeing. "
189
+ "It can also help reduce your risk of chronic conditions such as obesity, diabetes, heart disease, "
190
+ "and certain cancers. Aim for at least 150 minutes of moderate-intensity aerobic exercise or "
191
+ "75 minutes of vigorous-intensity aerobic exercise per week, along with muscle-strengthening "
192
+ "activities at least two days per week.\n"
193
+ "2. Eat a balanced diet: Eating a balanced diet that is rich in fruits, "
194
+ "vegetables, whole grains, lean proteins, and healthy fats can help support "
195
+ "your overall health. Try to limit your intake of processed and high-sugar foods, "
196
+ "and aim to drink plenty of water throughout the day.\n"
197
+ "3. Get enough sleep: Getting enough quality sleep is essential for your physical "
198
+ "and mental health. Adults should aim for seven to nine hours of sleep per night. "
199
+ "Establish a regular sleep schedule and try to create a relaxing bedtime routine to "
200
+ "help improve the quality of your sleep.",
201
+ ),
202
+ ),
203
+ offset=2,
204
+ sep_style=SeparatorStyle.SINGLE,
205
+ sep="###",
206
+ )
207
+
208
+ conv_v1_2 = Conversation(
209
+ system="A chat between a curious human and an artificial intelligence assistant. "
210
+ "The assistant gives helpful, detailed, and polite answers to the human's questions.",
211
+ roles=("Human", "Assistant"),
212
+ messages=(
213
+ (
214
+ "Human",
215
+ "What are the key differences between renewable and non-renewable energy sources?",
216
+ ),
217
+ (
218
+ "Assistant",
219
+ "Renewable energy sources are those that can be replenished naturally in a relatively "
220
+ "short amount of time, such as solar, wind, hydro, geothermal, and biomass. "
221
+ "Non-renewable energy sources, on the other hand, are finite and will eventually be "
222
+ "depleted, such as coal, oil, and natural gas. Here are some key differences between "
223
+ "renewable and non-renewable energy sources:\n"
224
+ "1. Availability: Renewable energy sources are virtually inexhaustible, while non-renewable "
225
+ "energy sources are finite and will eventually run out.\n"
226
+ "2. Environmental impact: Renewable energy sources have a much lower environmental impact "
227
+ "than non-renewable sources, which can lead to air and water pollution, greenhouse gas emissions, "
228
+ "and other negative effects.\n"
229
+ "3. Cost: Renewable energy sources can be more expensive to initially set up, but they typically "
230
+ "have lower operational costs than non-renewable sources.\n"
231
+ "4. Reliability: Renewable energy sources are often more reliable and can be used in more remote "
232
+ "locations than non-renewable sources.\n"
233
+ "5. Flexibility: Renewable energy sources are often more flexible and can be adapted to different "
234
+ "situations and needs, while non-renewable sources are more rigid and inflexible.\n"
235
+ "6. Sustainability: Renewable energy sources are more sustainable over the long term, while "
236
+ "non-renewable sources are not, and their depletion can lead to economic and social instability.\n",
237
+ ),
238
+ ),
239
+ offset=2,
240
+ sep_style=SeparatorStyle.SINGLE,
241
+ sep="###",
242
+ )
243
+
244
+ conv_vicuna_v1_1 = Conversation(
245
+ system="A chat between a curious user and an artificial intelligence assistant. "
246
+ "The assistant gives helpful, detailed, and polite answers to the user's questions.",
247
+ roles=("USER", "ASSISTANT"),
248
+ version="v1",
249
+ messages=(),
250
+ offset=0,
251
+ sep_style=SeparatorStyle.TWO,
252
+ sep=" ",
253
+ sep2="</s>",
254
+ )
255
+
256
+ conv_bair_v1 = Conversation(
257
+ system="BEGINNING OF CONVERSATION:",
258
+ roles=("USER", "GPT"),
259
+ messages=(),
260
+ offset=0,
261
+ sep_style=SeparatorStyle.TWO,
262
+ sep=" ",
263
+ sep2="</s>",
264
+ )
265
+
266
+ simple_conv = Conversation(
267
+ system="You are LLaVA, a large language model trained by UW Madison WAIV Lab, based on LLaMA architecture."
268
+ "You are designed to assist human with a variety of tasks using natural language."
269
+ "Follow the instructions carefully.",
270
+ roles=("Human", "Assistant"),
271
+ messages=(
272
+ ("Human", "Hi!"),
273
+ ("Assistant", "Hi there! How can I help you today?\n"),
274
+ ),
275
+ offset=2,
276
+ sep_style=SeparatorStyle.SINGLE,
277
+ sep="###",
278
+ )
279
+
280
+ simple_conv_multimodal = Conversation(
281
+ system="A chat between a curious user and an artificial intelligence assistant. "
282
+ "The assistant gives helpful, detailed, and polite answers to the user's questions.",
283
+ roles=("Human", "Assistant"),
284
+ messages=(),
285
+ offset=0,
286
+ sep_style=SeparatorStyle.SINGLE,
287
+ sep="###",
288
+ )
289
+
290
+ simple_conv_legacy = Conversation(
291
+ system="You are LLaVA, a large language model trained by UW Madison WAIV Lab."
292
+ "You are designed to assist human with a variety of tasks using natural language."
293
+ "Follow the instructions carefully.",
294
+ roles=("Human", "Assistant"),
295
+ messages=(
296
+ ("Human", "Hi!\n\n### Response:"),
297
+ ("Assistant", "Hi there! How can I help you today?\n"),
298
+ ),
299
+ offset=2,
300
+ sep_style=SeparatorStyle.SINGLE,
301
+ sep="###",
302
+ )
303
+
304
+ conv_llava_v1 = Conversation(
305
+ system="You are LLaVA, a large language and vision assistant trained by UW Madison WAIV Lab."
306
+ "You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language."
307
+ "Follow the instructions carefully and explain your answers in detail.",
308
+ roles=("USER", "ASSISTANT"),
309
+ version="v1",
310
+ messages=(),
311
+ offset=0,
312
+ sep_style=SeparatorStyle.TWO,
313
+ sep=" ",
314
+ sep2="</s>",
315
+ )
316
+
317
+ default_conversation = conv_v1_2
318
+ conv_templates = {
319
+ "default": conv_v1_2,
320
+ "simple": simple_conv,
321
+ "simple_legacy": simple_conv_legacy,
322
+ "multimodal": simple_conv_multimodal,
323
+ "llava_v1": conv_llava_v1,
324
+ # fastchat
325
+ "v1": conv_v1_2,
326
+ "bair_v1": conv_bair_v1,
327
+ "vicuna_v1_1": conv_vicuna_v1_1,
328
+ }
329
+
330
+
331
+ if __name__ == "__main__":
332
+ print(default_conversation.get_prompt())
@@ -0,0 +1 @@
1
+ from .omnilmm import OmniLMMForCausalLM