-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[NPU] feat: Support FSDP worker and vLLM Ascend #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
2e88f88
bdd0764
63ac392
c31e901
ee7d9fa
7ea5091
354fdd0
92b2de2
35576f2
90028f1
196afcb
9498189
a98298a
d8417c3
528af81
97d2fad
63c00b9
2f22dca
fbe16cf
ed22d71
1c071c6
e94006a
b58808d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| ======== | ||
| verl x Ascend | ||
| ======== | ||
|
|
||
| 我们在 verl 上增加对华为昇腾设备的支持。 | ||
|
|
||
| ======= | ||
| 硬件支持 | ||
| ======= | ||
|
|
||
| * Atlas 800T A2 | ||
| * Atlas 200T A2 Box16 | ||
|
|
||
| ======= | ||
| 安装 | ||
| ======= | ||
|
|
||
| ------ | ||
| 环境准备 | ||
| ------ | ||
|
|
||
| | 软件 | 版本 | | ||
| | --------- | ----------- | | ||
| | Python | == 3.10 | | ||
| | torch | == 2.5.1 | | ||
| | torch_npu | == 2.5.1rc1 | | ||
| | CANN | == 8.1.RC1 | | ||
|
|
||
| 1. 使用 vLLM,需遵循 vllm-ascend 的安装教程 <https://vllm-ascend.readthedocs.io/en/v0.7.3/installation.html>。 | ||
| 2. 为了能够在 ASCEND NPU 上正常使能 flash_attention_2, transformers 版本需要大于等于 4.51.4(not released),因此暂时使用源码安装。 | ||
|
|
||
| .. code-block:: bash | ||
| git clone --depth 1 https://github.com/huggingface/transformers.git | ||
| cd transformers | ||
| pip install -e . | ||
|
|
||
| 3. 目前支持 LLM 模型的 GRPO 训练,VLM模型的 GRPO 训练因为 vllm-ascend 的问题将会在后续支持,涉及到的issue为: | ||
|
|
||
| https://github.com/vllm-project/vllm-ascend/issues/809 | ||
| https://github.com/vllm-project/vllm-ascend/issues/825 | ||
|
|
||
|
|
||
| ------ | ||
| 源码安装 | ||
| ------ | ||
|
|
||
| .. code-block:: bash | ||
| git clone https://github.com/volcengine/verl.git | ||
| cd verl | ||
| pip install -r requirements-npu.txt | ||
| pip install -e . | ||
|
|
||
| ------ | ||
| vLLM | ||
| ------ | ||
|
|
||
| 为了保证能够在 verl 上正常使用 vLLM,需要安装 vLLM Ascend 插件(`vllm-ascend`)。关于在华为昇腾上支持的 vLLM 版本以及和 vLLM Ascend 的配套关系请参考`安装教程 <https://vllm-ascend.readthedocs.io/en/v0.7.1rc1/installation.html>`_。 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个安装教程的URL指向的是v0.7.1rc1版本,建议调整为v0.7.3版本的文档 |
||
|
|
||
| ------ | ||
| Ray | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ray这部分下方貌似没有对应的内容,请确认,如果确实没有内容,建议删除章节标题 |
||
| ------ | ||
|
|
||
| ------ | ||
| 其他第三方库说明 | ||
| ------ | ||
|
|
||
| +--------------+--------+ | ||
| | 软件 | 说明 | | ||
| +==============+========+ | ||
| | flash_attn | 不支持 | | ||
| +--------------+--------+ | ||
| | liger-kernel | 不支持 | | ||
| +--------------+--------+ | ||
|
|
||
| ------ | ||
| 精度对比 | ||
| ------ | ||
|
|
||
| 根据经验,对于SFT等微调算法,我们期望在相同配置下,在华为昇腾设备上的 Loss 与英伟达 GPU 的 Loss 平均误差小于 2%,具体计算方式如下: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里建议调整为“平均绝对误差小于等于2%” |
||
|
|
||
| .. image:: https://github.com/eric-haibin-lin/verl-community/tree/main/docs/loss_comparison.png | ||
| :alt: Alt text | ||
|
|
||
| 其中,N 表示训练的步数。更多信息请参考[精度计算说明](https://www.hiascend.com/document/detail/zh/Pytorch/600/ptmoddevg/trainingmigrguide/LMaccuracy_0001.html)。 | ||
|
|
||
| 根据经验,对于GRPO等强化学习算法,我们期望在相同配置下,在华为昇腾设备上的 reward 与英伟达 GPU 的 reward 平均绝对误差小于 4%,具体计算参考 Loss 计算。 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里建议调整为“平均绝对误差小于等于4%” |
||
|
|
||
| ------ | ||
| 进展 | ||
| ------ | ||
|
|
||
| +--------+--------+ | ||
| | 算法 | 进展 | | ||
| +========+========+ | ||
| | SFT | 已支持 | | ||
| +--------+--------+ | ||
| | PPO | 已支持 | | ||
| +--------+--------+ | ||
| | GRPO | 已支持 | | ||
| +--------+--------+ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # requirements.txt records the full set of dependencies for development | ||
| accelerate | ||
| codetiming | ||
| datasets | ||
| dill | ||
| hydra-core | ||
| numpy | ||
| pandas | ||
| peft | ||
| pyarrow>=15.0.0 | ||
| pybind11 | ||
| pylatexenc | ||
| ray | ||
| tensordict<0.6 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里做最高版本的限制的原因是什么? |
||
| wandb | ||
| mathruler | ||
| torchdata | ||
| einops | ||
| qwen_vl_utils | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Tested with 1 & 8 NPUs | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议归档我们实测过的脚本和配置,在tests下新建一个npu文件夹,统一在内部归档 |
||
|
|
||
| set -x | ||
|
|
||
| export VLLM_ATTENTION_BACKEND=XFORMERS | ||
|
|
||
| python3 -m verl.trainer.main_ppo \ | ||
| algorithm.adv_estimator=grpo \ | ||
| data.train_files=$HOME/data/gsm8k/train.parquet \ | ||
| data.val_files=$HOME/data/gsm8k/test.parquet \ | ||
| data.train_batch_size=128 \ | ||
| data.max_prompt_length=512 \ | ||
| data.max_response_length=128 \ | ||
| data.filter_overlong_prompts=True \ | ||
| data.truncation='error' \ | ||
| actor_rollout_ref.model.path=Qwen/Qwen2.5-0.5B-Instruct \ | ||
| actor_rollout_ref.actor.optim.lr=1e-6 \ | ||
| actor_rollout_ref.model.use_remove_padding=False \ | ||
| actor_rollout_ref.actor.ppo_mini_batch_size=64 \ | ||
| actor_rollout_ref.actor.ppo_micro_batch_size_per_gpu=20 \ | ||
| actor_rollout_ref.actor.use_kl_loss=True \ | ||
| actor_rollout_ref.actor.kl_loss_coef=0.001 \ | ||
| actor_rollout_ref.actor.kl_loss_type=low_var_kl \ | ||
| actor_rollout_ref.model.enable_gradient_checkpointing=True \ | ||
| actor_rollout_ref.actor.fsdp_config.param_offload=False \ | ||
| actor_rollout_ref.actor.fsdp_config.optimizer_offload=False \ | ||
| actor_rollout_ref.rollout.log_prob_micro_batch_size_per_gpu=40 \ | ||
| actor_rollout_ref.rollout.enable_chunked_prefill=False \ | ||
| actor_rollout_ref.rollout.tensor_model_parallel_size=2 \ | ||
| actor_rollout_ref.rollout.name=vllm \ | ||
| actor_rollout_ref.rollout.gpu_memory_utilization=0.6 \ | ||
| actor_rollout_ref.rollout.n=5 \ | ||
| actor_rollout_ref.ref.log_prob_micro_batch_size_per_gpu=40 \ | ||
| actor_rollout_ref.ref.fsdp_config.param_offload=True \ | ||
| algorithm.kl_ctrl.kl_coef=0.001 \ | ||
| trainer.critic_warmup=0 \ | ||
| trainer.logger=['console'] \ | ||
| trainer.project_name='verl_grpo_example_gsm8k' \ | ||
| trainer.experiment_name='qwen2_7b_function_rm' \ | ||
| trainer.n_gpus_per_node=8 \ | ||
| trainer.nnodes=1 \ | ||
| trainer.save_freq=-1 \ | ||
| trainer.test_freq=5 \ | ||
| trainer.total_epochs=1 $@ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Tested with 1 & 8 NPUs | ||
| set -x | ||
|
|
||
| if [ "$#" -lt 2 ]; then | ||
| echo "Usage: run_gen_deepseek_v2_lite_math_npu.sh <nproc_per_node> <save_path> [other_configs...]" | ||
| exit 1 | ||
| fi | ||
|
|
||
| nproc_per_node=$1 | ||
| save_path=$2 | ||
|
|
||
| # Shift the arguments so $@ refers to the rest | ||
| shift 2 | ||
|
|
||
| python3 -m verl.trainer.main_generation \ | ||
| trainer.nnodes=1 \ | ||
| trainer.n_gpus_per_node=8 \ | ||
| data.path=~/data/rlhf/gsm8k/test.parquet \ | ||
| data.prompt_key=prompt \ | ||
| data.n_samples=1 \ | ||
| data.output_path=~/data/rlhf/math/deepseek_v2_lite_gen_test.parquet \ | ||
| model.path=deepseek-ai/deepseek-llm-7b-chat \ | ||
| +model.trust_remote_code=True \ | ||
| rollout.temperature=1.0 \ | ||
| rollout.top_k=50 \ | ||
| rollout.top_p=0.7 \ | ||
| rollout.prompt_length=2048 \ | ||
| rollout.response_length=1024 \ | ||
| rollout.tensor_model_parallel_size=2 \ | ||
| rollout.gpu_memory_utilization=0.8 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,13 @@ | |
|
|
||
| import logging | ||
| import os | ||
| import pkg_resources | ||
|
|
||
| from pkg_resources import DistributionNotFound | ||
| from packaging.version import parse as parse_version | ||
| from .protocol import DataProto | ||
| from .utils.logging_utils import set_basic_config | ||
| from verl.utils.device import is_npu_available | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 保持风格统一,建议使用相对引用格式 |
||
|
|
||
| version_folder = os.path.dirname(os.path.join(os.path.abspath(__file__))) | ||
|
|
||
|
|
@@ -38,3 +42,19 @@ | |
| from modelscope.utils.hf_util import patch_hub | ||
|
|
||
| patch_hub() | ||
|
|
||
| if is_npu_available: | ||
| from .utils import npu_patch | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如上,相应调整。 |
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 多余空行请移除 |
||
| package_name = 'transformers' | ||
| required_version_spec = '4.51.0' | ||
| try: | ||
| installed_version = pkg_resources.get_distribution(package_name).version | ||
| installed = parse_version(installed_version) | ||
| required = parse_version(required_version_spec) | ||
|
|
||
| if not installed >= required: | ||
| raise ValueError(f"{package_name} version required >= {required_version_spec} on ASCEND NPU, current version is {installed}.") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 描述歧义,建议调整为 |
||
| except DistributionNotFound as e: | ||
| raise ImportError( | ||
| f"{package_name} not installed。please run pip install {package_name}=={required_version_spec}") from e | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 出现中文句号,且 |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下文提及支持SFT,这里描述仅支持GRPO,前后描述矛盾,请确认