[rollout, vllm] feat: support blockwise FP8 rollout for vLLM v0.11 MoE RL#4222
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for blockwise FP8 rollout for MoE models with vLLM v0.11.0 by introducing a new monkey-patch function and conditionally applying it based on the vLLM version. The changes are logical, but I have two suggestions to improve code quality and correctness. First, there is some duplicated code in the new process_weights_after_loading_moe_for_vllm11 function that can be refactored into a helper function to improve maintainability. Second, the vLLM version check uses string comparison, which is not robust and can lead to incorrect behavior with future vLLM versions; I've suggested using packaging.version for a more reliable comparison.
| if self.allow_deep_gemm and not is_deep_gemm_e8m0_used(): | ||
| if expert_weight_is_col_major(layer.w13_weight_scale_inv): | ||
| layer.w13_weight_scale_inv = get_col_major_tma_aligned_tensor(layer.w13_weight_scale_inv) | ||
| if expert_weight_is_col_major(layer.w2_weight_scale_inv): | ||
| layer.w2_weight_scale_inv = get_col_major_tma_aligned_tensor(layer.w2_weight_scale_inv) | ||
|
|
||
| if is_deep_gemm_e8m0_used(): | ||
| assert layer.weight_block_size is not None | ||
| # Re-quantise the expert weights so their scales are UE8M0. | ||
| block_sz = tuple(layer.weight_block_size) | ||
| requant_weight_ue8m0_inplace( | ||
| layer.w13_weight.data, | ||
| layer.w13_weight_scale_inv.data, | ||
| block_sz, | ||
| ) | ||
| requant_weight_ue8m0_inplace( | ||
| layer.w2_weight.data, | ||
| layer.w2_weight_scale_inv.data, | ||
| block_sz, | ||
| ) | ||
|
|
||
| # Ensure column-major TMA alignment expected by DeepGEMM. | ||
| if expert_weight_is_col_major(layer.w13_weight_scale_inv): | ||
| layer.w13_weight_scale_inv = get_col_major_tma_aligned_tensor(layer.w13_weight_scale_inv) | ||
| if expert_weight_is_col_major(layer.w2_weight_scale_inv): | ||
| layer.w2_weight_scale_inv = get_col_major_tma_aligned_tensor(layer.w2_weight_scale_inv) |
There was a problem hiding this comment.
There's duplicated code for aligning DeepGEMM scales. This logic appears in two separate if blocks. To improve maintainability and reduce redundancy, you can extract this logic into a nested helper function.
def _align_scales(l):
if expert_weight_is_col_major(l.w13_weight_scale_inv):
l.w13_weight_scale_inv = get_col_major_tma_aligned_tensor(l.w13_weight_scale_inv)
if expert_weight_is_col_major(l.w2_weight_scale_inv):
l.w2_weight_scale_inv = get_col_major_tma_aligned_tensor(l.w2_weight_scale_inv)
if self.allow_deep_gemm and not is_deep_gemm_e8m0_used():
_align_scales(layer)
if is_deep_gemm_e8m0_used():
assert layer.weight_block_size is not None
# Re-quantise the expert weights so their scales are UE8M0.
block_sz = tuple(layer.weight_block_size)
requant_weight_ue8m0_inplace(
layer.w13_weight.data,
layer.w13_weight_scale_inv.data,
block_sz,
)
requant_weight_ue8m0_inplace(
layer.w2_weight.data,
layer.w2_weight_scale_inv.data,
block_sz,
)
# Ensure column-major TMA alignment expected by DeepGEMM.
_align_scales(layer)| patcher2 = patch( | ||
| func2_path, | ||
| process_weights_after_loading_moe_for_vllm11 | ||
| if vllm.__version__ >= "0.11.0" |
There was a problem hiding this comment.
Comparing version strings directly using operators like >= can lead to incorrect results for some versioning schemes (e.g., '0.9.0' is lexicographically greater than '0.11.0'). For robust version comparison, it's recommended to use a dedicated library like packaging.version. This will prevent potential bugs if vllm releases versions like 0.12.0 or 1.0.0. Note that a similar issue exists on line 462 for patcher1.
| if vllm.__version__ >= "0.11.0" | |
| if __import__("packaging").version.parse(vllm.__version__) >= __import__("packaging").version.parse("0.11.0") |
|
cc @Agoniii |
|
@jQizhang Can we avoid this patch by bump vllm image to 0.11.1? |
@wuxibin89 I haven't tested with vLLM 0.11.1 yet. However, since vLLM 0.11.1 also removes the weight_loader attribute in process_weights_after_loading, the issue with quantized weight updates will likely persist. Therefore, I think the patch may still be needed for vLLM 0.11.1. |
…E RL (verl-project#4222) ### What does this PR do? This PR enables support for **blockwise FP8 rollout** for **MoE** models using **vLLM v0.11.0**. **Relationship to previous work:** This is a follow-up to verl-project#3519. Please refer to that PR for the full support matrix, detailed usage instructions, experimental results, and other related context. **Implementation Details:** To support FP8 MoE RL with vLLM v0.11.0, this PR applies a monkey patch to the vLLM MoE model method: `vllm.model_executor.layers.quantization.fp8.Fp8MoEMethod.process_weights_after_loading`. This modification allows the system to correctly handle model weight loading after quantization. ### Checklist Before Starting - [x] Search for similar PRs. Paste at least one query link here: verl-project#3519 - [x] Format the PR title as `[{modules}] {type}: {description}` (This will be checked by the CI) - `{modules}` include `fsdp`, `megatron`, `sglang`, `vllm`, `rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `hardware`, `deployment`, `ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data` - If this PR involves multiple modules, separate them with `,` like `[megatron, fsdp, doc]` - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test` - If this PR breaks any API (CLI arguments, config, function signature, etc.), add `[BREAKING]` to the beginning of the title. - Example: `[BREAKING][fsdp, megatron] feat: dynamic batching` ### Test > For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc. ### API and Usage Example > Demonstrate how the API changes if any, and provide usage example(s) if possible. ```python # Add code snippet or script demonstrating how to use this ``` ### Design & Code Changes > Demonstrate the high-level design if this PR is complex, and list the specific changes. ### Checklist Before Submitting > [!IMPORTANT] > Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review. - [x] Read the [Contribute Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md). - [x] Apply [pre-commit checks](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting): `pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always` - [ ] Add / Update [the documentation](https://github.com/volcengine/verl/tree/main/docs). - [ ] Add unit or end-to-end test(s) to [the CI workflow](https://github.com/volcengine/verl/tree/main/.github/workflows) to cover all the code. If not feasible, explain why: ... - [ ] Once your PR is ready for CI, send a message in [the `ci-request` channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the `verl` Slack workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ). (If not accessible, please try [the Feishu group (飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).)
…E RL (verl-project#4222) ### What does this PR do? This PR enables support for **blockwise FP8 rollout** for **MoE** models using **vLLM v0.11.0**. **Relationship to previous work:** This is a follow-up to verl-project#3519. Please refer to that PR for the full support matrix, detailed usage instructions, experimental results, and other related context. **Implementation Details:** To support FP8 MoE RL with vLLM v0.11.0, this PR applies a monkey patch to the vLLM MoE model method: `vllm.model_executor.layers.quantization.fp8.Fp8MoEMethod.process_weights_after_loading`. This modification allows the system to correctly handle model weight loading after quantization. ### Checklist Before Starting - [x] Search for similar PRs. Paste at least one query link here: verl-project#3519 - [x] Format the PR title as `[{modules}] {type}: {description}` (This will be checked by the CI) - `{modules}` include `fsdp`, `megatron`, `sglang`, `vllm`, `rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `hardware`, `deployment`, `ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data` - If this PR involves multiple modules, separate them with `,` like `[megatron, fsdp, doc]` - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test` - If this PR breaks any API (CLI arguments, config, function signature, etc.), add `[BREAKING]` to the beginning of the title. - Example: `[BREAKING][fsdp, megatron] feat: dynamic batching` ### Test > For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc. ### API and Usage Example > Demonstrate how the API changes if any, and provide usage example(s) if possible. ```python # Add code snippet or script demonstrating how to use this ``` ### Design & Code Changes > Demonstrate the high-level design if this PR is complex, and list the specific changes. ### Checklist Before Submitting > [!IMPORTANT] > Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review. - [x] Read the [Contribute Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md). - [x] Apply [pre-commit checks](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting): `pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always` - [ ] Add / Update [the documentation](https://github.com/volcengine/verl/tree/main/docs). - [ ] Add unit or end-to-end test(s) to [the CI workflow](https://github.com/volcengine/verl/tree/main/.github/workflows) to cover all the code. If not feasible, explain why: ... - [ ] Once your PR is ready for CI, send a message in [the `ci-request` channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the `verl` Slack workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ). (If not accessible, please try [the Feishu group (飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).)
…E RL (verl-project#4222) ### What does this PR do? This PR enables support for **blockwise FP8 rollout** for **MoE** models using **vLLM v0.11.0**. **Relationship to previous work:** This is a follow-up to verl-project#3519. Please refer to that PR for the full support matrix, detailed usage instructions, experimental results, and other related context. **Implementation Details:** To support FP8 MoE RL with vLLM v0.11.0, this PR applies a monkey patch to the vLLM MoE model method: `vllm.model_executor.layers.quantization.fp8.Fp8MoEMethod.process_weights_after_loading`. This modification allows the system to correctly handle model weight loading after quantization. ### Checklist Before Starting - [x] Search for similar PRs. Paste at least one query link here: verl-project#3519 - [x] Format the PR title as `[{modules}] {type}: {description}` (This will be checked by the CI) - `{modules}` include `fsdp`, `megatron`, `sglang`, `vllm`, `rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `hardware`, `deployment`, `ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data` - If this PR involves multiple modules, separate them with `,` like `[megatron, fsdp, doc]` - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test` - If this PR breaks any API (CLI arguments, config, function signature, etc.), add `[BREAKING]` to the beginning of the title. - Example: `[BREAKING][fsdp, megatron] feat: dynamic batching` ### Test > For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc. ### API and Usage Example > Demonstrate how the API changes if any, and provide usage example(s) if possible. ```python # Add code snippet or script demonstrating how to use this ``` ### Design & Code Changes > Demonstrate the high-level design if this PR is complex, and list the specific changes. ### Checklist Before Submitting > [!IMPORTANT] > Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review. - [x] Read the [Contribute Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md). - [x] Apply [pre-commit checks](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting): `pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always` - [ ] Add / Update [the documentation](https://github.com/volcengine/verl/tree/main/docs). - [ ] Add unit or end-to-end test(s) to [the CI workflow](https://github.com/volcengine/verl/tree/main/.github/workflows) to cover all the code. If not feasible, explain why: ... - [ ] Once your PR is ready for CI, send a message in [the `ci-request` channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the `verl` Slack workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ). (If not accessible, please try [the Feishu group (飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).)
What does this PR do?
This PR enables support for blockwise FP8 rollout for MoE models using vLLM v0.11.0.
Relationship to previous work:
This is a follow-up to #3519. Please refer to that PR for the full support matrix, detailed usage instructions, experimental results, and other related context.
Implementation Details:
To support FP8 MoE RL with vLLM v0.11.0, this PR applies a monkey patch to the vLLM MoE model method:
vllm.model_executor.layers.quantization.fp8.Fp8MoEMethod.process_weights_after_loading.This modification allows the system to correctly handle model weight loading after quantization.
Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI){modules}includefsdp,megatron,sglang,vllm,rollout,trainer,ci,training_utils,recipe,hardware,deployment,ray,worker,single_controller,misc,perf,model,algo,env,tool,ckpt,doc,data,like[megatron, fsdp, doc]{type}is infeat,fix,refactor,chore,test[BREAKING]to the beginning of the title.[BREAKING][fsdp, megatron] feat: dynamic batchingTest
API and Usage Example
# Add code snippet or script demonstrating how to use thisDesign & Code Changes
Checklist Before Submitting
Important
Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=alwaysci-requestchannel in theverlSlack workspace. (If not accessible, please try the Feishu group (飞书群).)