Skip to content

Commit ea81928

Browse files
committed
Merge branch 'main' into release/3.3
2 parents 379b0af + 4c76918 commit ea81928

File tree

13 files changed

+99
-114
lines changed

13 files changed

+99
-114
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ Running Environment:
120120
| python | >=3.9 | 3.10 | |
121121
| cuda | | cuda12 | No need to install if using CPU, NPU, MPS |
122122
| torch | >=2.0 | | |
123-
| transformers | >=4.33 | 4.50 | |
123+
| transformers | >=4.33 | 4.51 | |
124124
| modelscope | >=1.19 | | |
125125
| peft | >=0.11,<0.16 | ||
126126
| trl | >=0.13,<0.17 | 0.16 |RLHF|
127127
| deepspeed | >=0.14 | 0.14.5 | Training |
128-
| vllm | >=0.5.1,<0.8 | 0.7.3 | Inference/Deployment/Evaluation |
128+
| vllm | >=0.5.1 | 0.8.3 | Inference/Deployment/Evaluation |
129129
| lmdeploy | >=0.5 | 0.7.2.post1 | Inference/Deployment/Evaluation |
130130
| evalscope | >=0.11 | | Evaluation |
131131

README_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ pip install -e .
115115
| python | >=3.9 | 3.10 ||
116116
| cuda | | cuda12 |使用cpu、npu、mps则无需安装|
117117
| torch | >=2.0 | ||
118-
| transformers | >=4.33 | 4.50 ||
118+
| transformers | >=4.33 | 4.51 ||
119119
| modelscope | >=1.19 | ||
120120
| peft | >=0.11,<0.16 | ||
121121
| trl | >=0.13,<0.17 | 0.16 |RLHF|
122122
| deepspeed | >=0.14 | 0.14.5 |训练|
123-
| vllm | >=0.5.1,<0.8 | 0.7.3 |推理/部署/评测|
123+
| vllm | >=0.5.1 | 0.8.3 |推理/部署/评测|
124124
| lmdeploy | >=0.5 | 0.7.2.post1 |推理/部署/评测|
125125
| evalscope | >=0.11 | |评测|
126126

docs/source/GetStarted/SWIFT安装.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu2
6464
| python | >=3.9 | 3.10 ||
6565
| cuda | | cuda12 |使用cpu、npu、mps则无需安装|
6666
| torch | >=2.0 | ||
67-
| transformers | >=4.33 | 4.50 ||
67+
| transformers | >=4.33 | 4.51 ||
6868
| modelscope | >=1.19 | ||
6969
| peft | >=0.11,<0.16 | ||
7070
| trl | >=0.13,<0.17 | 0.16 |RLHF|
7171
| deepspeed | >=0.14 | 0.14.5 |训练|
72-
| vllm | >=0.5.1,<0.8 | 0.7.3 |推理/部署/评测|
72+
| vllm | >=0.5.1 | 0.8.3 |推理/部署/评测|
7373
| lmdeploy | >=0.5 | 0.7.2.post1 |推理/部署/评测|
7474
| evalscope | >=0.11 | |评测|
7575

docs/source_en/GetStarted/SWIFT-installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ More images can be found [here](https://modelscope.cn/docs/intro/environment-set
6565
| python | >=3.9 | 3.10 | |
6666
| cuda | | cuda12 | No need to install if using CPU, NPU, MPS |
6767
| torch | >=2.0 | | |
68-
| transformers | >=4.33 | 4.50 | |
68+
| transformers | >=4.33 | 4.51 | |
6969
| modelscope | >=1.19 | | |
7070
| peft | >=0.11,<0.16 | | |
7171
| trl | >=0.13,<0.17 | 0.16 | RLHF |
7272
| deepspeed | >=0.14 | 0.14.5 | Training |
73-
| vllm | >=0.5.1,<0.8 | 0.7.3 | Inference/Deployment/Evaluation |
73+
| vllm | >=0.5.1 | 0.8.3 | Inference/Deployment/Evaluation |
7474
| lmdeploy | >=0.5 | 0.7.2.post1 | Inference/Deployment/Evaluation |
7575
| evalscope | >=0.11 | | Evaluation |
7676

requirements/install_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# please use python=3.10, cuda12.*
22
# sh requirements/install_all.sh
3-
pip install "vllm>=0.5.1,<0.8" -U
3+
pip install "vllm>=0.5.1" -U
44
pip install "lmdeploy>=0.5" -U --no-deps
55
pip install autoawq -U --no-deps
66
pip install auto_gptq optimum bitsandbytes -U

swift/llm/argument/base_args/template_args.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TemplateArguments:
3333
system: Optional[str] = None # Override the default_system in the template.
3434
max_length: Optional[int] = None
3535

36-
truncation_strategy: Literal['delete', 'left', 'right'] = 'delete'
36+
truncation_strategy: Optional[Literal['delete', 'left', 'right']] = None
3737
max_pixels: Optional[int] = None
3838
tools_prompt: str = 'react_en' # Override the default_tools_prompt in the template.
3939
norm_bbox: Literal['norm1000', 'none', None] = None
@@ -53,6 +53,8 @@ def __post_init__(self):
5353
assert os.path.isfile(self.system), f'self.system: {self.system}'
5454
with open(self.system, 'r') as f:
5555
self.system = f.read()
56+
if self.truncation_strategy is None:
57+
self.truncation_strategy = 'delete'
5658

5759
def get_template_kwargs(self):
5860
truncation_strategy = self.truncation_strategy

swift/llm/argument/rlhf_args.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class GRPOArguments(GRPOArgumentsMixin):
5656
# multi step
5757
num_iterations: int = 1
5858

59+
truncation_strategy: Optional[Literal['delete', 'left', 'right']] = None
60+
5961

6062
@dataclass
6163
class RLHFArguments(GRPOArguments, PPOArguments, RewardModelArguments, TrainArguments):
@@ -108,7 +110,6 @@ def __post_init__(self):
108110
self._init_ppo()
109111
self._set_default()
110112
super().__post_init__()
111-
self._init_grpo_ds3()
112113
self._check_rlhf()
113114
self._check_grpo()
114115

@@ -139,7 +140,11 @@ def _init_grpo(self):
139140
self.gradient_accumulation_steps = 1
140141
self.remove_unused_columns = False
141142
logger.info(f'Setting args.remove_unused_columns: {self.remove_unused_columns}')
142-
self.truncation_strategy = 'left' # Used for trimming the excessively long parts of a prompt.
143+
if self.truncation_strategy is None:
144+
self.truncation_strategy = 'left'
145+
assert self.truncation_strategy == 'left', \
146+
"GRPO requires `truncation_strategy='left'`," \
147+
f"Current value: `truncation_strategy='{self.truncation_strategy}'`."
143148
if self.beta is None:
144149
self.beta = 0.04 # https://arxiv.org/abs/2402.03300
145150
if self.async_generate:
@@ -189,11 +194,6 @@ def _set_default(self):
189194
elif self.rlhf_type in ['kto']:
190195
self.loss_type = 'kto'
191196

192-
def _init_grpo_ds3(self):
193-
if self.rlhf_type == 'grpo' and self.deepspeed:
194-
if 'zero_optimization' in self.deepspeed and self.deepspeed['zero_optimization']['stage'] == 3:
195-
self.deepspeed['zero_optimization']['stage3_prefetch_bucket_size'] = 0
196-
197197
def _check_rlhf(self):
198198
if self.sequence_parallel_size > 1:
199199
raise ValueError('RLHF do not support sequence parallel')

swift/llm/model/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,17 @@ def _get_config_attrs(config: Union[PretrainedConfig, Dict[str, Any]],
9898
else:
9999
return []
100100

101+
value = deep_getattr(config, attr_name, None)
102+
if value is not None and parent_key in [None, 'language_config', 'llm_config', 'text_config']:
103+
res.append((config, value))
104+
101105
for k in keys:
102106
if k.endswith('_config'):
103107
if isinstance(config, dict):
104108
v = config[k]
105109
else:
106110
v = getattr(config, k)
107111
res += HfConfigFactory._get_config_attrs(v, attr_name, k)
108-
value = deep_getattr(config, attr_name, None)
109-
if value is not None and parent_key in [None, 'language_config', 'llm_config', 'text_config']:
110-
res.append((config, value))
111112
return res
112113

113114
@staticmethod

swift/llm/template/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,13 @@ def _encode(self, inputs: StdTemplateInputs) -> Dict[str, Any]:
969969
if loss_scale is not None:
970970
loss_scale = loss_scale[:self.max_length]
971971
else:
972+
if len(input_ids) > self.max_length:
973+
logger.warning_once(
974+
'Input data was left-truncated because its length exceeds `max_length` (input length: '
975+
f'{len(input_ids)}, max_length: {self.max_length}). '
976+
'This may cause loss of important tokens (e.g., image tokens) and lead to errors. '
977+
'To avoid this, consider increasing `max_length` or pre-filtering long sequences.',
978+
hash_id='max_length_check')
972979
input_ids = input_ids[-self.max_length:]
973980
if labels is not None:
974981
labels = labels[-self.max_length:]

swift/trainers/rlhf_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ def __post_init__(self):
5252
if self.cosine_max_len is None:
5353
self.cosine_max_len = self.max_completion_length
5454
self.vllm_limit_mm_per_prompt = ModelArguments.parse_to_dict(self.vllm_limit_mm_per_prompt)
55+
56+
if self.deepspeed and 'zero_optimization' in self.deepspeed and self.deepspeed['zero_optimization'][
57+
'stage'] == 3:
58+
# https://github.com/modelscope/ms-swift/issues/3237
59+
self.deepspeed['zero_optimization']['stage3_prefetch_bucket_size'] = 0
60+
self.deepspeed_plugin.hf_ds_config.config['zero_optimization']['stage3_prefetch_bucket_size'] = 0

0 commit comments

Comments
 (0)