Skip to content

feat:support exporting fp8 weights in FP8 E2E#6045

Draft
eternally-z wants to merge 1 commit intoverl-project:mainfrom
meituan-search:feature/export_fp8
Draft

feat:support exporting fp8 weights in FP8 E2E#6045
eternally-z wants to merge 1 commit intoverl-project:mainfrom
meituan-search:feature/export_fp8

Conversation

@eternally-z
Copy link
Copy Markdown
Contributor

What does this PR do?

we support exporting fp8 weights in Megatron-Bridge. This pr enable verl using the feature.

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, vllm_omni, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • 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.

# 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.

Copy link
Copy Markdown
Contributor

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

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 introduces support for FP8 weight export and rollout by adding export_weight_dtype and skip_mid_quantization configurations. It updates the Megatron engine and workers to handle FP8 weight initialization and optimizer parameter reloading, and ensures the Prometheus metrics directory is created on Ray workers. Feedback was provided regarding redundant validation and normalization of the export weight data type in the optimizer initialization logic, suggesting the use of the already validated value stored in the bridge.

Comment on lines +348 to +351
export_weight_dtype = self.engine_config.export_weight_dtype
if isinstance(export_weight_dtype, str):
export_weight_dtype = export_weight_dtype.lower()
if export_weight_dtype == "fp8" and self.bridge is not None:
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.

high

The normalization and validation of export_weight_dtype is redundant here. It has already been processed and validated in _build_tf_config (lines 238-245) and stored in self.bridge.export_weight_dtype. Repeating this logic here is redundant and could lead to inconsistencies if the validation logic changes in one place but not the other.

Suggested change
export_weight_dtype = self.engine_config.export_weight_dtype
if isinstance(export_weight_dtype, str):
export_weight_dtype = export_weight_dtype.lower()
if export_weight_dtype == "fp8" and self.bridge is not None:
if self.bridge is not None and getattr(self.bridge, "export_weight_dtype", None) == "fp8":

Comment on lines +530 to +535
export_weight_dtype = self.config.actor.megatron.get("export_weight_dtype", "bf16")
if isinstance(export_weight_dtype, str):
export_weight_dtype = export_weight_dtype.lower()
if export_weight_dtype not in ("bf16", "fp16", "fp8"):
export_weight_dtype = "bf16"
if export_weight_dtype == "fp8" and self.bridge is not None:
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.

high

This block redundantly re-fetches and re-normalizes export_weight_dtype from the configuration. This logic is already handled in _init_hf_config_and_tf_config (lines 239-246), where the value is validated (raising ValueError for invalid inputs) and stored in self.bridge.export_weight_dtype. Additionally, the fallback to "bf16" at line 534 is inconsistent with the ValueError raised earlier in the initialization flow. Using the stored value from the bridge is safer and cleaner.

Suggested change
export_weight_dtype = self.config.actor.megatron.get("export_weight_dtype", "bf16")
if isinstance(export_weight_dtype, str):
export_weight_dtype = export_weight_dtype.lower()
if export_weight_dtype not in ("bf16", "fp16", "fp8"):
export_weight_dtype = "bf16"
if export_weight_dtype == "fp8" and self.bridge is not None:
if self.bridge is not None and getattr(self.bridge, "export_weight_dtype", None) == "fp8":

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.

1 participant