Skip to content

Commit 6f35f28

Browse files
authored
Update readme & fix generate (#4041)
1 parent 51cafe5 commit 6f35f28

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ You can contact us and communicate with us by adding our group:
5151

5252

5353
## 📝 Introduction
54-
🍲 ms-swift is an official framework provided by the ModelScope community for fine-tuning and deploying large language models and multi-modal large models. It currently supports the training (pre-training, fine-tuning, human alignment), inference, evaluation, quantization, and deployment of 450+ large models and 150+ multi-modal large models. These large language models (LLMs) include models such as Qwen2.5, InternLM3, GLM4, Mistral, DeepSeek-R1, Yi1.5, TeleChat2, Baichuan2, and Gemma2. The multi-modal LLMs include models such as Qwen2.5-VL, Qwen2-Audio, Llama3.4, Llava, InternVL2.5, MiniCPM-V-2.6, GLM4v, Xcomposer2.5, Yi-VL, DeepSeek-VL2, Phi3.5-Vision, and GOT-OCR2.
54+
🍲 ms-swift is an official framework provided by the ModelScope community for fine-tuning and deploying large language models and multi-modal large models. It currently supports the training (pre-training, fine-tuning, human alignment), inference, evaluation, quantization, and deployment of 450+ large models and 150+ multi-modal large models. These large language models (LLMs) include models such as Qwen3, Qwen3-MoE, Qwen2.5, InternLM3, GLM4, Mistral, DeepSeek-R1, Yi1.5, TeleChat2, Baichuan2, and Gemma2. The multi-modal LLMs include models such as Qwen2.5-VL, Qwen2-Audio, Llama3.4, Llava, InternVL2.5, MiniCPM-V-2.6, GLM4v, Xcomposer2.5, Yi-VL, DeepSeek-VL2, Phi3.5-Vision, and GOT-OCR2.
5555

5656
🍔 Additionally, ms-swift incorporates the latest training technologies, including lightweight techniques such as LoRA, QLoRA, Llama-Pro, LongLoRA, GaLore, Q-GaLore, LoRA+, LISA, DoRA, FourierFt, ReFT, UnSloth, and Liger, as well as human alignment training methods like DPO, GRPO, RM, PPO, KTO, CPO, SimPO, and ORPO. ms-swift supports acceleration of inference, evaluation, and deployment modules using vLLM and LMDeploy, and it supports model quantization with technologies like GPTQ, AWQ, and BNB. Furthermore, ms-swift offers a Gradio-based Web UI and a wealth of best practices.
5757

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<img src="asset/discord_qr.jpg" width="200" height="200"> | <img src="asset/wechat.png" width="200" height="200">
5050

5151
## 📝 简介
52-
🍲 ms-swift是魔搭社区提供的大模型与多模态大模型微调部署框架,现已支持450+大模型与150+多模态大模型的训练(预训练、微调、人类对齐)、推理、评测、量化与部署。其中大模型包括:Qwen2.5、InternLM3、GLM4、Mistral、DeepSeek-R1、Yi1.5、TeleChat2、Baichuan2、Gemma2等模型,多模态大模型包括:Qwen2.5-VL、Qwen2-Audio、Llama4、Llava、InternVL2.5、MiniCPM-V-2.6、GLM4v、Xcomposer2.5、Yi-VL、DeepSeek-VL2、Phi3.5-Vision、GOT-OCR2等模型。
52+
🍲 ms-swift是魔搭社区提供的大模型与多模态大模型微调部署框架,现已支持450+大模型与150+多模态大模型的训练(预训练、微调、人类对齐)、推理、评测、量化与部署。其中大模型包括:Qwen3、Qwen3-MoE、Qwen2.5、InternLM3、GLM4、Mistral、DeepSeek-R1、Yi1.5、TeleChat2、Baichuan2、Gemma2等模型,多模态大模型包括:Qwen2.5-VL、Qwen2-Audio、Llama4、Llava、InternVL2.5、MiniCPM-V-2.6、GLM4v、Xcomposer2.5、Yi-VL、DeepSeek-VL2、Phi3.5-Vision、GOT-OCR2等模型。
5353

5454
🍔 除此之外,ms-swift汇集了最新的训练技术,包括LoRA、QLoRA、Llama-Pro、LongLoRA、GaLore、Q-GaLore、LoRA+、LISA、DoRA、FourierFt、ReFT、UnSloth、和Liger等轻量化训练技术,以及DPO、GRPO、RM、PPO、KTO、CPO、SimPO、ORPO等人类对齐训练方法。ms-swift支持使用vLLM和LMDeploy对推理、评测和部署模块进行加速,并支持使用GPTQ、AWQ、BNB等技术对大模型进行量化。ms-swift还提供了基于Gradio的Web-UI界面及丰富的最佳实践。
5555

swift/llm/template/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,11 @@ def decode_prm(self, input_ids: torch.Tensor, logits: torch.Tensor) -> Any:
535535
raise NotImplementedError
536536

537537
def generate(self, model, *args, **kwargs):
538-
if 'use_model_defaults' in inspect.signature(model.generate).parameters and 'use_model_defaults' not in kwargs:
538+
if isinstance(model, PeftModel):
539+
signature = inspect.signature(model.model.generate)
540+
else:
541+
signature = inspect.signature(model.generate)
542+
if 'use_model_defaults' in signature.parameters and 'use_model_defaults' not in kwargs:
539543
kwargs['use_model_defaults'] = False
540544
return model.generate(*args, **kwargs)
541545

swift/trainers/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from types import FunctionType, MethodType
55
from typing import List, Union
66

7+
from peft import PeftModel
78
from torch.nn import Module
89

910
from swift.utils import get_logger
@@ -13,7 +14,10 @@
1314

1415
def can_return_loss(model: Module) -> bool:
1516
"""Check if a given model can return loss."""
16-
signature = inspect.signature(model.forward)
17+
if isinstance(model, PeftModel):
18+
signature = inspect.signature(model.model.forward)
19+
else:
20+
signature = inspect.signature(model.forward)
1721
for p in signature.parameters:
1822
if p == 'return_loss' and signature.parameters[p].default is True:
1923
return True
@@ -23,7 +27,10 @@ def can_return_loss(model: Module) -> bool:
2327
def find_labels(model: Module) -> List[str]:
2428
"""Find the labels used by a given model."""
2529
model_name = model.__class__.__name__
26-
signature = inspect.signature(model.forward)
30+
if isinstance(model, PeftModel):
31+
signature = inspect.signature(model.model.forward)
32+
else:
33+
signature = inspect.signature(model.forward)
2734
if 'QuestionAnswering' in model_name:
2835
return [p for p in signature.parameters if 'label' in p or p in ('start_positions', 'end_positions')]
2936
else:

0 commit comments

Comments
 (0)