xinference 0.13.2__py3-none-any.whl → 0.13.4__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 (103) hide show
  1. xinference/__init__.py +0 -1
  2. xinference/_version.py +3 -3
  3. xinference/api/restful_api.py +30 -5
  4. xinference/client/restful/restful_client.py +18 -3
  5. xinference/constants.py +0 -4
  6. xinference/core/chat_interface.py +2 -2
  7. xinference/core/image_interface.py +6 -3
  8. xinference/core/model.py +9 -4
  9. xinference/core/scheduler.py +4 -4
  10. xinference/core/supervisor.py +2 -0
  11. xinference/core/worker.py +7 -0
  12. xinference/deploy/utils.py +6 -0
  13. xinference/model/audio/core.py +9 -4
  14. xinference/model/audio/cosyvoice.py +136 -0
  15. xinference/model/audio/model_spec.json +24 -0
  16. xinference/model/audio/model_spec_modelscope.json +27 -0
  17. xinference/model/core.py +25 -4
  18. xinference/model/embedding/core.py +88 -13
  19. xinference/model/embedding/model_spec.json +8 -0
  20. xinference/model/embedding/model_spec_modelscope.json +8 -0
  21. xinference/model/flexible/core.py +8 -2
  22. xinference/model/flexible/launchers/__init__.py +1 -0
  23. xinference/model/flexible/launchers/image_process_launcher.py +70 -0
  24. xinference/model/image/core.py +8 -5
  25. xinference/model/image/model_spec.json +36 -5
  26. xinference/model/image/model_spec_modelscope.json +21 -3
  27. xinference/model/image/stable_diffusion/core.py +36 -28
  28. xinference/model/llm/core.py +6 -4
  29. xinference/model/llm/ggml/llamacpp.py +7 -5
  30. xinference/model/llm/llm_family.json +802 -82
  31. xinference/model/llm/llm_family.py +6 -6
  32. xinference/model/llm/llm_family_csghub.json +39 -0
  33. xinference/model/llm/llm_family_modelscope.json +295 -47
  34. xinference/model/llm/mlx/core.py +7 -0
  35. xinference/model/llm/pytorch/chatglm.py +246 -5
  36. xinference/model/llm/pytorch/cogvlm2.py +1 -1
  37. xinference/model/llm/pytorch/deepseek_vl.py +2 -1
  38. xinference/model/llm/pytorch/falcon.py +2 -1
  39. xinference/model/llm/pytorch/llama_2.py +4 -2
  40. xinference/model/llm/pytorch/omnilmm.py +2 -1
  41. xinference/model/llm/pytorch/qwen_vl.py +2 -1
  42. xinference/model/llm/pytorch/vicuna.py +2 -1
  43. xinference/model/llm/pytorch/yi_vl.py +2 -1
  44. xinference/model/llm/sglang/core.py +12 -6
  45. xinference/model/llm/utils.py +78 -1
  46. xinference/model/llm/vllm/core.py +9 -5
  47. xinference/model/rerank/core.py +4 -3
  48. xinference/thirdparty/cosyvoice/__init__.py +0 -0
  49. xinference/thirdparty/cosyvoice/bin/__init__.py +0 -0
  50. xinference/thirdparty/cosyvoice/bin/inference.py +114 -0
  51. xinference/thirdparty/cosyvoice/bin/train.py +136 -0
  52. xinference/thirdparty/cosyvoice/cli/__init__.py +0 -0
  53. xinference/thirdparty/cosyvoice/cli/cosyvoice.py +83 -0
  54. xinference/thirdparty/cosyvoice/cli/frontend.py +168 -0
  55. xinference/thirdparty/cosyvoice/cli/model.py +60 -0
  56. xinference/thirdparty/cosyvoice/dataset/__init__.py +0 -0
  57. xinference/thirdparty/cosyvoice/dataset/dataset.py +160 -0
  58. xinference/thirdparty/cosyvoice/dataset/processor.py +369 -0
  59. xinference/thirdparty/cosyvoice/flow/__init__.py +0 -0
  60. xinference/thirdparty/cosyvoice/flow/decoder.py +222 -0
  61. xinference/thirdparty/cosyvoice/flow/flow.py +135 -0
  62. xinference/thirdparty/cosyvoice/flow/flow_matching.py +138 -0
  63. xinference/thirdparty/cosyvoice/flow/length_regulator.py +49 -0
  64. xinference/thirdparty/cosyvoice/hifigan/__init__.py +0 -0
  65. xinference/thirdparty/cosyvoice/hifigan/f0_predictor.py +55 -0
  66. xinference/thirdparty/cosyvoice/hifigan/generator.py +391 -0
  67. xinference/thirdparty/cosyvoice/llm/__init__.py +0 -0
  68. xinference/thirdparty/cosyvoice/llm/llm.py +206 -0
  69. xinference/thirdparty/cosyvoice/transformer/__init__.py +0 -0
  70. xinference/thirdparty/cosyvoice/transformer/activation.py +84 -0
  71. xinference/thirdparty/cosyvoice/transformer/attention.py +326 -0
  72. xinference/thirdparty/cosyvoice/transformer/convolution.py +145 -0
  73. xinference/thirdparty/cosyvoice/transformer/decoder.py +396 -0
  74. xinference/thirdparty/cosyvoice/transformer/decoder_layer.py +132 -0
  75. xinference/thirdparty/cosyvoice/transformer/embedding.py +293 -0
  76. xinference/thirdparty/cosyvoice/transformer/encoder.py +472 -0
  77. xinference/thirdparty/cosyvoice/transformer/encoder_layer.py +236 -0
  78. xinference/thirdparty/cosyvoice/transformer/label_smoothing_loss.py +96 -0
  79. xinference/thirdparty/cosyvoice/transformer/positionwise_feed_forward.py +115 -0
  80. xinference/thirdparty/cosyvoice/transformer/subsampling.py +383 -0
  81. xinference/thirdparty/cosyvoice/utils/__init__.py +0 -0
  82. xinference/thirdparty/cosyvoice/utils/class_utils.py +70 -0
  83. xinference/thirdparty/cosyvoice/utils/common.py +103 -0
  84. xinference/thirdparty/cosyvoice/utils/executor.py +110 -0
  85. xinference/thirdparty/cosyvoice/utils/file_utils.py +41 -0
  86. xinference/thirdparty/cosyvoice/utils/frontend_utils.py +125 -0
  87. xinference/thirdparty/cosyvoice/utils/mask.py +227 -0
  88. xinference/thirdparty/cosyvoice/utils/scheduler.py +739 -0
  89. xinference/thirdparty/cosyvoice/utils/train_utils.py +289 -0
  90. xinference/web/ui/build/asset-manifest.json +3 -3
  91. xinference/web/ui/build/index.html +1 -1
  92. xinference/web/ui/build/static/js/{main.95c1d652.js → main.af906659.js} +3 -3
  93. xinference/web/ui/build/static/js/main.af906659.js.map +1 -0
  94. xinference/web/ui/node_modules/.cache/babel-loader/2cd5e4279ad7e13a1f41d486e9fca7756295bfad5bd77d90992f4ac3e10b496d.json +1 -0
  95. {xinference-0.13.2.dist-info → xinference-0.13.4.dist-info}/METADATA +39 -11
  96. {xinference-0.13.2.dist-info → xinference-0.13.4.dist-info}/RECORD +101 -57
  97. xinference/web/ui/build/static/js/main.95c1d652.js.map +0 -1
  98. xinference/web/ui/node_modules/.cache/babel-loader/709711edada3f1596b309d571285fd31f1c364d66f4425bc28723d0088cc351a.json +0 -1
  99. /xinference/web/ui/build/static/js/{main.95c1d652.js.LICENSE.txt → main.af906659.js.LICENSE.txt} +0 -0
  100. {xinference-0.13.2.dist-info → xinference-0.13.4.dist-info}/LICENSE +0 -0
  101. {xinference-0.13.2.dist-info → xinference-0.13.4.dist-info}/WHEEL +0 -0
  102. {xinference-0.13.2.dist-info → xinference-0.13.4.dist-info}/entry_points.txt +0 -0
  103. {xinference-0.13.2.dist-info → xinference-0.13.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,289 @@
1
+ # Copyright (c) 2021 Mobvoi Inc. (authors: Binbin Zhang)
2
+ # 2023 Horizon Inc. (authors: Xingchen Song)
3
+ # 2024 Alibaba Inc (authors: Xiang Lyu)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from contextlib import nullcontext
18
+ import logging
19
+ import os
20
+ import torch
21
+ import json
22
+ import re
23
+ import datetime
24
+ import yaml
25
+
26
+ import deepspeed
27
+ import torch.optim as optim
28
+ import torch.distributed as dist
29
+
30
+ from torch.utils.tensorboard import SummaryWriter
31
+ from torch.utils.data import DataLoader
32
+ from torch.nn.utils import clip_grad_norm_
33
+
34
+ from deepspeed.runtime.zero.stage_1_and_2 import estimate_zero2_model_states_mem_needs_all_live
35
+
36
+ from cosyvoice.dataset.dataset import Dataset
37
+ from cosyvoice.utils.scheduler import WarmupLR, NoamHoldAnnealing, ConstantLR
38
+
39
+
40
+ def init_distributed(args):
41
+ world_size = int(os.environ.get('WORLD_SIZE', 1))
42
+ local_rank = int(os.environ.get('LOCAL_RANK', 0))
43
+ rank = int(os.environ.get('RANK', 0))
44
+ logging.info('training on multiple gpus, this gpu {}'.format(local_rank) +
45
+ ', rank {}, world_size {}'.format(rank, world_size))
46
+ if args.train_engine == 'torch_ddp':
47
+ torch.cuda.set_device(local_rank)
48
+ dist.init_process_group(args.dist_backend)
49
+ else:
50
+ deepspeed.init_distributed(dist_backend=args.dist_backend)
51
+ return world_size, local_rank, rank
52
+
53
+
54
+ def init_dataset_and_dataloader(args, configs):
55
+ train_dataset = Dataset(args.train_data, data_pipeline=configs['data_pipeline'], mode='train', shuffle=True, partition=True)
56
+ cv_dataset = Dataset(args.cv_data, data_pipeline=configs['data_pipeline'], mode='train', shuffle=False, partition=False)
57
+
58
+ # do not use persistent_workers=True, as whisper tokenizer opens tiktoken file each time when the for loop starts
59
+ train_data_loader = DataLoader(train_dataset,
60
+ batch_size=None,
61
+ pin_memory=args.pin_memory,
62
+ num_workers=args.num_workers,
63
+ prefetch_factor=args.prefetch)
64
+ cv_data_loader = DataLoader(cv_dataset,
65
+ batch_size=None,
66
+ pin_memory=args.pin_memory,
67
+ num_workers=args.num_workers,
68
+ prefetch_factor=args.prefetch)
69
+ return train_dataset, cv_dataset, train_data_loader, cv_data_loader
70
+
71
+
72
+
73
+ def check_modify_and_save_config(args, configs):
74
+ if args.train_engine == "torch_ddp":
75
+ configs['train_conf']["dtype"] = 'fp32'
76
+ else:
77
+ with open(args.deepspeed_config, 'r') as fin:
78
+ ds_configs = json.load(fin)
79
+ if "fp16" in ds_configs and ds_configs["fp16"]["enabled"]:
80
+ configs['train_conf']["dtype"] = "fp16"
81
+ elif "bf16" in ds_configs and ds_configs["bf16"]["enabled"]:
82
+ configs['train_conf']["dtype"] = "bf16"
83
+ else:
84
+ configs['train_conf']["dtype"] = "fp32"
85
+ assert ds_configs["train_micro_batch_size_per_gpu"] == 1
86
+ # if use deepspeed, override ddp config
87
+ configs['train_conf']['save_per_step'] = int(configs['train_conf']['save_per_step'] * configs['train_conf']['accum_grad'] / ds_configs["gradient_accumulation_steps"])
88
+ configs['train_conf']['accum_grad'] = ds_configs["gradient_accumulation_steps"]
89
+ configs['train_conf']['grad_clip'] = ds_configs["gradient_clipping"]
90
+ configs['train_conf']['log_interval'] = ds_configs["steps_per_print"]
91
+ return configs
92
+
93
+
94
+ def wrap_cuda_model(args, model):
95
+ local_world_size = int(os.environ.get('LOCAL_WORLD_SIZE', 1))
96
+ world_size = int(os.environ.get('WORLD_SIZE', 1))
97
+ if args.train_engine == "torch_ddp": # native pytorch ddp
98
+ assert (torch.cuda.is_available())
99
+ model.cuda()
100
+ model = torch.nn.parallel.DistributedDataParallel(model, find_unused_parameters=True)
101
+ else:
102
+ if int(os.environ.get('RANK', 0)) == 0:
103
+ logging.info("Estimating model states memory needs (zero2)...")
104
+ estimate_zero2_model_states_mem_needs_all_live(
105
+ model,
106
+ num_gpus_per_node=local_world_size,
107
+ num_nodes=world_size // local_world_size)
108
+ return model
109
+
110
+
111
+ def init_optimizer_and_scheduler(args, configs, model):
112
+ if configs['train_conf']['optim'] == 'adam':
113
+ optimizer = optim.Adam(model.parameters(), **configs['train_conf']['optim_conf'])
114
+ elif configs['train_conf']['optim'] == 'adamw':
115
+ optimizer = optim.AdamW(model.parameters(), **configs['train_conf']['optim_conf'])
116
+ else:
117
+ raise ValueError("unknown optimizer: " + configs['train_conf'])
118
+
119
+ if configs['train_conf']['scheduler'] == 'warmuplr':
120
+ scheduler_type = WarmupLR
121
+ scheduler = WarmupLR(optimizer, **configs['train_conf']['scheduler_conf'])
122
+ elif configs['train_conf']['scheduler'] == 'NoamHoldAnnealing':
123
+ scheduler_type = NoamHoldAnnealing
124
+ scheduler = NoamHoldAnnealing(optimizer, **configs['train_conf']['scheduler_conf'])
125
+ elif configs['train_conf']['scheduler'] == 'constantlr':
126
+ scheduler_type = ConstantLR
127
+ scheduler = ConstantLR(optimizer)
128
+ else:
129
+ raise ValueError("unknown scheduler: " + configs['train_conf'])
130
+
131
+ # use deepspeed optimizer for speedup
132
+ if args.train_engine == "deepspeed":
133
+ def scheduler(opt):
134
+ return scheduler_type(opt, **configs['train_conf']['scheduler_conf'])
135
+ model, optimizer, _, scheduler = deepspeed.initialize(
136
+ args=args,
137
+ model=model,
138
+ optimizer=None,
139
+ lr_scheduler=scheduler,
140
+ model_parameters=model.parameters())
141
+
142
+ return model, optimizer, scheduler
143
+
144
+
145
+ def init_summarywriter(args):
146
+ writer = None
147
+ if int(os.environ.get('RANK', 0)) == 0:
148
+ os.makedirs(args.model_dir, exist_ok=True)
149
+ writer = SummaryWriter(args.tensorboard_dir)
150
+ return writer
151
+
152
+
153
+ def save_model(model, model_name, info_dict):
154
+ rank = int(os.environ.get('RANK', 0))
155
+ model_dir = info_dict["model_dir"]
156
+ save_model_path = os.path.join(model_dir, '{}.pt'.format(model_name))
157
+
158
+ if info_dict["train_engine"] == "torch_ddp":
159
+ if rank == 0:
160
+ torch.save(model.module.state_dict(), save_model_path)
161
+ else:
162
+ with torch.no_grad():
163
+ model.save_checkpoint(save_dir=model_dir,
164
+ tag=model_name,
165
+ client_state=info_dict)
166
+ if rank == 0:
167
+ info_path = re.sub('.pt$', '.yaml', save_model_path)
168
+ info_dict['save_time'] = datetime.datetime.now().strftime('%d/%m/%Y %H:%M:%S')
169
+ with open(info_path, 'w') as fout:
170
+ data = yaml.dump(info_dict)
171
+ fout.write(data)
172
+ logging.info('[Rank {}] Checkpoint: save to checkpoint {}'.format(rank, save_model_path))
173
+
174
+
175
+ def cosyvoice_join(group_join, info_dict):
176
+ world_size = int(os.environ.get('WORLD_SIZE', 1))
177
+ local_rank = int(os.environ.get('LOCAL_RANK', 0))
178
+ rank = int(os.environ.get('RANK', 0))
179
+
180
+ if info_dict["batch_idx"] != 0:
181
+ # we try to join all rank in both ddp and deepspeed mode, in case different rank has different lr
182
+ try:
183
+ dist.monitored_barrier(group=group_join,
184
+ timeout=group_join.options._timeout)
185
+ return False
186
+ except RuntimeError as e:
187
+ logging.info("Detected uneven workload distribution: {}\n".format(e) +
188
+ "Break current worker to manually join all workers, " +
189
+ "world_size {}, current rank {}, current local_rank {}\n".
190
+ format(world_size, rank, local_rank))
191
+ return True
192
+ else:
193
+ return False
194
+
195
+
196
+ def batch_forward(model, batch, info_dict):
197
+ device = int(os.environ.get('LOCAL_RANK', 0))
198
+
199
+ dtype = info_dict["dtype"]
200
+ if dtype == "fp16":
201
+ dtype = torch.float16
202
+ elif dtype == "bf16":
203
+ dtype = torch.bfloat16
204
+ else: # fp32
205
+ dtype = torch.float32
206
+
207
+ if info_dict['train_engine'] == 'torch_ddp':
208
+ autocast = nullcontext()
209
+ else:
210
+ autocast = torch.cuda.amp.autocast(enabled=True, dtype=dtype, cache_enabled=False)
211
+
212
+ with autocast:
213
+ info_dict['loss_dict'] = model(batch, device)
214
+ return info_dict
215
+
216
+
217
+ def batch_backward(model, info_dict):
218
+ if info_dict["train_engine"] == "deepspeed":
219
+ scaled_loss = model.backward(info_dict['loss_dict']['loss'])
220
+ else:
221
+ scaled_loss = info_dict['loss_dict']['loss'] / info_dict['accum_grad']
222
+ scaled_loss.backward()
223
+
224
+ info_dict['loss_dict']['loss'] = scaled_loss
225
+ return info_dict
226
+
227
+
228
+ def update_parameter_and_lr(model, optimizer, scheduler, info_dict):
229
+ grad_norm = 0.0
230
+ if info_dict['train_engine'] == "deepspeed":
231
+ info_dict["is_gradient_accumulation_boundary"] = model.is_gradient_accumulation_boundary()
232
+ model.step()
233
+ grad_norm = model.get_global_grad_norm()
234
+ elif (info_dict['batch_idx'] + 1) % info_dict["accum_grad"] == 0:
235
+ grad_norm = clip_grad_norm_(model.parameters(), info_dict['grad_clip'])
236
+ if torch.isfinite(grad_norm):
237
+ optimizer.step()
238
+ optimizer.zero_grad()
239
+ scheduler.step()
240
+ info_dict["lr"] = optimizer.param_groups[0]['lr']
241
+ info_dict["grad_norm"] = grad_norm
242
+ return info_dict
243
+
244
+
245
+ def log_per_step(writer, info_dict):
246
+ tag = info_dict["tag"]
247
+ epoch = info_dict.get('epoch', 0)
248
+ step = info_dict["step"]
249
+ batch_idx = info_dict["batch_idx"]
250
+ loss_dict = info_dict['loss_dict']
251
+ rank = int(os.environ.get('RANK', 0))
252
+
253
+ # only rank 0 write to tensorboard to avoid multi-process write
254
+ if writer is not None:
255
+ if (info_dict['train_engine'] == 'deepspeed' and info_dict['is_gradient_accumulation_boundary'] is True) or \
256
+ (info_dict['train_engine'] == 'torch_ddp' and (info_dict['batch_idx'] + 1) % info_dict['accum_grad'] == 0):
257
+ for k in ['epoch', 'lr', 'grad_norm']:
258
+ writer.add_scalar('{}/{}'.format(tag, k), info_dict[k], step + 1)
259
+ for k, v in loss_dict.items():
260
+ writer.add_scalar('{}/{}'.format(tag, k), v, step + 1)
261
+
262
+ # TRAIN & CV, Shell log (stdout)
263
+ if (info_dict['batch_idx'] + 1) % info_dict['log_interval'] == 0:
264
+ log_str = '{} Batch {}/{} '.format(tag, epoch, batch_idx + 1)
265
+ for name, value in loss_dict.items():
266
+ log_str += '{} {:.6f} '.format(name, value)
267
+ if tag == "TRAIN":
268
+ log_str += 'lr {:.8f} grad_norm {:.6f}'.format(
269
+ info_dict["lr"], info_dict['grad_norm'])
270
+ log_str += ' rank {}'.format(rank)
271
+ logging.debug(log_str)
272
+
273
+
274
+ def log_per_save(writer, info_dict):
275
+ tag = info_dict["tag"]
276
+ epoch = info_dict["epoch"]
277
+ step = info_dict["step"]
278
+ loss_dict = info_dict["loss_dict"]
279
+ lr = info_dict['lr']
280
+ rank = int(os.environ.get('RANK', 0))
281
+ logging.info(
282
+ 'Epoch {} Step {} CV info lr {} {} rank {}'.format(
283
+ epoch, step + 1, lr, rank, ' '.join(['{}_{}'.format(k, v) for k, v in loss_dict.items()])))
284
+
285
+ if writer is not None:
286
+ for k in ['epoch', 'lr']:
287
+ writer.add_scalar('{}/{}'.format(tag, k), info_dict[k], step + 1)
288
+ for k, v in loss_dict.items():
289
+ writer.add_scalar('{}/{}'.format(tag, k), v, step + 1)
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.4bafd904.css",
4
- "main.js": "./static/js/main.95c1d652.js",
4
+ "main.js": "./static/js/main.af906659.js",
5
5
  "static/media/icon.webp": "./static/media/icon.4603d52c63041e5dfbfd.webp",
6
6
  "index.html": "./index.html",
7
7
  "main.4bafd904.css.map": "./static/css/main.4bafd904.css.map",
8
- "main.95c1d652.js.map": "./static/js/main.95c1d652.js.map"
8
+ "main.af906659.js.map": "./static/js/main.af906659.js.map"
9
9
  },
10
10
  "entrypoints": [
11
11
  "static/css/main.4bafd904.css",
12
- "static/js/main.95c1d652.js"
12
+ "static/js/main.af906659.js"
13
13
  ]
14
14
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.svg"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><title>Xinference</title><script defer="defer" src="./static/js/main.95c1d652.js"></script><link href="./static/css/main.4bafd904.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.svg"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><title>Xinference</title><script defer="defer" src="./static/js/main.af906659.js"></script><link href="./static/css/main.4bafd904.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>