Skip to content

Commit 2f8c8a5

Browse files
committed
Merge branch 'main' into release/3.6
2 parents 42b3b6f + e9f9e08 commit 2f8c8a5

File tree

16 files changed

+83
-10
lines changed

16 files changed

+83
-10
lines changed

docs/source/Instruction/Megatron-SWIFT训练.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu2
4040

4141
首先,我们需要将HF格式的权重转为Megatron格式:
4242
- 若出现OOM,将`CUDA_VISIBLE_DEVICES=0`删除即可。
43+
- "ms-swift>=3.6"推荐增加`--test_convert_precision true`参数测试转换精度。
4344
```shell
4445
CUDA_VISIBLE_DEVICES=0 \
4546
swift export \
@@ -87,7 +88,8 @@ megatron sft \
8788

8889
最后,将Megatron格式权重转为HF格式:
8990
- 注意:`--mcore_model`请指向`iter_xxx`的上级目录。默认会使用`latest_checkpointed_iteration.txt`中对应的checkpoint。
90-
91+
- 若出现OOM,将`CUDA_VISIBLE_DEVICES=0`删除即可。
92+
- "ms-swift>=3.6"推荐增加`--test_convert_precision true`参数测试转换精度。
9193
```shell
9294
CUDA_VISIBLE_DEVICES=0 \
9395
swift export \

docs/source/Instruction/命令行参数.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110
- top_p: top_p参数,默认为None。读取generation_config.json。
111111
- repetition_penalty: 重复惩罚项。默认为None,读取generation_config.json。
112112
- num_beams: beam search的并行保留数量,默认为1。
113-
- 🔥stream: 流式输出,默认为`False`
113+
- 🔥stream: 流式输出,默认为`None`,即使用交互式界面时为True,数据集批量推理时为False。
114+
- "ms-swift<3.6"stream默认值为False。
114115
- stop_words: 除了eos_token外额外的停止词,默认为`[]`
115116
- 注意:eos_token会在输出respsone中被删除,额外停止词会在输出中保留。
116117
- logprobs: 是否输出logprobs,默认为False。
@@ -515,6 +516,8 @@ soft overlong 奖励参数
515516
- swanlab_project: swanlab的project,需要在页面中预先创建好:[https://swanlab.cn/space/~](https://swanlab.cn/space/~)
516517
- swanlab_workspace: 默认为None,会使用api-key对应的username。
517518
- swanlab_exp_name: 实验名,可以为空,为空时默认传入--output_dir的值。
519+
- swanlab_lark_webhook_url: 默认为None。swanlab的lark webhook url,用于推送实验结果到飞书。
520+
- swanlab_lark_secret: 默认为None。swanlab的lark secret,用于推送实验结果到飞书。
518521
- swanlab_mode: 可选cloud和local,云模式或者本地模式。
519522

520523
### 推理参数

docs/source_en/Instruction/Command-line-parameters.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ Refer to the [generation_config](https://huggingface.co/docs/transformers/main_c
112112
- top_p: The top_p parameter, defaults to None. It is read from generation_config.json.
113113
- repetition_penalty: The repetition penalty. Defaults to None and is read from generation_config.json.
114114
- num_beams: The number of beams reserved for parallel beam search, default is 1.
115-
- 🔥stream: Stream output, default is `False`.
115+
- 🔥stream: Streaming output. Default is `None`, which means it is set to True when using the interactive interface and False during batch inference on datasets.
116+
- For "ms-swift<3.6", the default value of stream is False.
116117
- stop_words: Additional stop words beyond eos_token, default is`[]`.
117118
- Note: eos_token will be removed in the output response, whereas additional stop words will be retained in the output.
118119
- logprobs: Whether to output logprobs, default is False.
@@ -535,6 +536,8 @@ Soft overlong reward parameters:
535536
- **swanlab_project**: SwanLab's project, which needs to be created in advance on the page: [https://swanlab.cn/space/~](https://swanlab.cn/space/~)
536537
- **swanlab_workspace**: Defaults to `None`, will use the username associated with the API key
537538
- **swanlab_exp_name**: Experiment name, can be left empty. If empty, the value of `--output_dir` will be used by default
539+
- swanlab_lark_webhook_url: Defaults to None. SwanLab's Lark webhook URL, used for pushing experiment results to Lark.
540+
- swanlab_lark_secret: Defaults to None. SwanLab's Lark secret, used for pushing experiment results to Lark.
538541
- **swanlab_mode**: Optional values are `cloud` and `local`, representing cloud mode or local mode
539542

540543

docs/source_en/Instruction/Megatron-SWIFT-Training.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ The training module in the dependent library Megatron-LM will be cloned and inst
4040
This section introduces a quick start example for fine-tuning the self-awareness of the Qwen2.5-7B-Instruct model using two 80GiB A100 GPUs. The following best practices can be completed within 10 minutes.
4141

4242
First, we need to convert the weights from HF (Hugging Face) format to Megatron format:
43-
- If OOM occurs, simply remove `CUDA_VISIBLE_DEVICES=0`.
43+
- If you encounter OOM, simply remove `CUDA_VISIBLE_DEVICES=0`.
44+
- For "ms-swift>=3.6", it is recommended to add the `--test_convert_precision true` parameter to test conversion precision.
4445
```shell
4546
CUDA_VISIBLE_DEVICES=0 \
4647
swift export \
@@ -88,6 +89,8 @@ megatron sft \
8889

8990
Finally, convert the Megatron format weights back to HF format:
9091
- Note: Please point `--mcore_model` to the parent directory of `iter_xxx`. By default, the corresponding checkpoint from `latest_checkpointed_iteration.txt` will be used.
92+
- If you encounter OOM, simply remove `CUDA_VISIBLE_DEVICES=0`.
93+
- For "ms-swift>=3.6", it is recommended to add the `--test_convert_precision true` parameter to test conversion precision.
9194

9295
```shell
9396
CUDA_VISIBLE_DEVICES=0 \

swift/llm/argument/app_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AppArguments(WebUIArguments, DeployArguments):
1919

2020
lang: Literal['en', 'zh'] = 'en'
2121
verbose: bool = False
22+
stream: bool = True
2223

2324
def _init_torch_dtype(self) -> None:
2425
if self.base_url:

swift/llm/argument/base_args/base_args.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def __post_init__(self):
153153
self._init_custom_register()
154154
self._import_external_plugins()
155155
self._init_model_kwargs()
156+
self._init_stream()
156157
# The Seq2SeqTrainingArguments has a property called world_size, which cannot be assigned a value.
157158
self.rank, self.local_rank, self.global_world_size, self.local_world_size = get_dist_setting()
158159
logger.info(f'rank: {self.rank}, local_rank: {self.local_rank}, '
@@ -223,6 +224,8 @@ def load_args_from_ckpt(self) -> None:
223224
'bnb_4bit_quant_type',
224225
'bnb_4bit_use_double_quant',
225226
]
227+
if 'megatron' in self.__class__.__name__.lower():
228+
force_load_keys = []
226229
# If the current value is None or an empty list and it is among the following keys
227230
load_keys = [
228231
'custom_register_path',

swift/llm/argument/base_args/generation_args.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ class GenerationArguments:
3232
repetition_penalty: Optional[float] = None
3333
num_beams: int = 1
3434

35-
stream: bool = False
35+
stream: Optional[bool] = None
3636
stop_words: List[str] = field(default_factory=list)
3737
logprobs: bool = False
3838
top_logprobs: Optional[int] = None
3939

40+
def _init_stream(self):
41+
if self.stream is None:
42+
self.stream = False
43+
4044
def get_request_config(self):
4145
if getattr(self, 'task_type') != 'causal_lm':
4246
return

swift/llm/argument/deploy_args.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from swift.llm import safe_snapshot_download
66
from swift.utils import find_free_port, get_logger
7+
from .base_args import BaseArguments
78
from .infer_args import InferArguments
89

910
logger = get_logger()
@@ -66,7 +67,7 @@ def _init_ckpt_dir(self, adapters=None):
6667
return super()._init_ckpt_dir(self.adapters + list(self.adapter_mapping.values()))
6768

6869
def _init_stream(self):
69-
pass
70+
return BaseArguments._init_stream(self)
7071

7172
def _init_eval_human(self):
7273
pass

swift/llm/argument/infer_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ def _init_result_path(self, folder_name: str) -> None:
180180

181181
def _init_stream(self):
182182
self.eval_human = not (self.dataset and self.split_dataset_ratio > 0 or self.val_dataset)
183-
183+
if self.stream is None:
184+
self.stream = self.eval_human
184185
if self.stream and self.num_beams != 1:
185186
self.stream = False
186187
logger.info('Setting args.stream: False')
@@ -199,7 +200,6 @@ def __post_init__(self) -> None:
199200
VllmArguments.__post_init__(self)
200201
self._init_result_path('infer_result')
201202
self._init_eval_human()
202-
self._init_stream()
203203
self._init_ddp()
204204

205205
def _init_eval_human(self):

swift/llm/argument/train_args.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class SwanlabArguments:
6868
swanlab_project: Optional[str] = None
6969
swanlab_workspace: Optional[str] = None
7070
swanlab_exp_name: Optional[str] = None
71+
swanlab_lark_webhook_url: Optional[str] = None
72+
swanlab_lark_secret: Optional[str] = None
7173
swanlab_mode: Literal['cloud', 'local'] = 'cloud'
7274

7375
def _init_swanlab(self):
@@ -80,6 +82,15 @@ def _init_swanlab(self):
8082
from swanlab.integration.transformers import SwanLabCallback
8183
if self.swanlab_token:
8284
swanlab.login(self.swanlab_token)
85+
86+
if self.swanlab_lark_webhook_url is not None:
87+
from swanlab.plugin.notification import LarkCallback
88+
lark_callback = LarkCallback(
89+
webhook_url=self.swanlab_lark_webhook_url,
90+
secret=self.swanlab_lark_secret,
91+
)
92+
swanlab.register_callbacks([lark_callback])
93+
8394
INTEGRATION_TO_CALLBACK['swanlab'] = SwanLabCallback(
8495
project=self.swanlab_project,
8596
workspace=self.swanlab_workspace,

0 commit comments

Comments
 (0)