Skip to content

[megatron] fix: support FP8 padding for BSHD actor forward - #6887

Closed
gem-mint wants to merge 1 commit into
verl-project:mainfrom
gem-mint:bshd-fp8-actor-main
Closed

[megatron] fix: support FP8 padding for BSHD actor forward#6887
gem-mint wants to merge 1 commit into
verl-project:mainfrom
gem-mint:bshd-fp8-actor-main

Conversation

@gem-mint

@gem-mint gem-mint commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What

This is the main-branch companion to #6884, requested by maintainers so the BSHD FP8 actor update fix is available on main as well as release/v0.7.1.

It removes the hard BSHD FP8 assertion in the Megatron actor forward path, propagates use_fp8_padding into regular BSHD preprocessing for the input and logits processor arguments, and aligns BSHD padded sequence length so TransformerEngine FP8 block quantization sees a local token count divisible by 128. The main branch already had equivalent alignment logic in preprocess_bshd_engine; this patch factors that into a helper and reuses it for regular BSHD too.

Why

With data_format=bshd and fp8=hybrid/e4m3, actor update currently fails before forward with:

AssertionError: fp8 is not supported for bshd format yet

Removing the assertion alone is not enough: the padded BSHD shape must also satisfy TE FP8 block quantization alignment.

Duplicate-work check

Per AGENTS.md, I checked for overlapping work before opening this PR:

  • gh issue view 5508 --repo verl-project/verl --comments
  • gh pr list --repo verl-project/verl --state open --search "5508 in:body" --limit 20
  • gh pr list --repo verl-project/verl --state open --search "bshd fp8" --limit 20
  • gh pr list --repo verl-project/verl --state open --search "actor fp8 padding" --limit 20
  • gh pr list --repo verl-project/verl --state open --search '"fp8 is not supported for bshd format yet"' --limit 20

The only same-scope result is #6884, which targets release/v0.7.1. #6703 appears in some keyword searches but fixes a THD/CP OOB issue and is not a duplicate of this BSHD actor-padding fix.

Tests

  • git diff --check passed
  • python -m py_compile tests/models/test_mcore_bshd_fp8_padding.py verl/models/mcore/util.py verl/models/mcore/model_forward.py passed using the local bundled Python
  • python -m pytest tests/models/test_mcore_bshd_fp8_padding.py -q could not run locally because this Windows helper environment does not have pytest installed
  • A direct execution attempt of the test function could not run locally because this helper environment does not have torch installed

AI assistance was used to prepare this patch; human review done before marking ready for review.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: gem-mint <146161229+gem-mint@users.noreply.github.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enables FP8 support for the BSHD format. It removes the assertion blocking FP8 in BSHD, propagates the use_fp8_padding parameter to preprocess_bshd, and extracts the sequence length alignment logic into a reusable helper function _align_bshd_max_seqlen_for_fp8. Additionally, a unit test has been added to verify the FP8 padding alignment and roundtrip functionality. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@gem-mint
gem-mint marked this pull request as ready for review June 29, 2026 09:17
@wuxibin89 wuxibin89 changed the title [mcore] fix: support FP8 padding for BSHD actor forward [megatron] fix: support FP8 padding for BSHD actor forward Jun 29, 2026
Comment thread verl/models/mcore/util.py
position_ids: torch.Tensor,
sequence_parallel: bool = False,
pre_process: bool = True,
use_fp8_padding: bool = False,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preprocess_bshd is not used anymore, we now use preprocess_bshd_engine

@wuxibin89

Copy link
Copy Markdown
Collaborator

Never mind, I decide not to support fp8 in BSHD format.

@wuxibin89 wuxibin89 closed this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants