[megatron] refactor: Refactor policy update failure handling from exception to warning in MegatronPPOActor to support FP16 training#5369
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the policy update failure handling in MegatronPPOActor to be more robust for FP16 training. Instead of raising a NotImplementedError when a policy update fails (e.g., due to gradient overflow), it now logs a warning and continues. This prevents training from crashing on transient errors. My review includes a suggestion to enhance this by adding a counter for consecutive failures to prevent silent training stalls in case of persistent issues.
| else: | ||
| raise NotImplementedError | ||
| logger.warning("Policy update failed, no update is made. This can be caused by gradient overflow in fp16 training.") | ||
|
|
There was a problem hiding this comment.
While replacing NotImplementedError with a warning is a good step to handle transient gradient overflows in FP16 training without crashing, it introduces a risk of silent failures. If policy updates fail repeatedly, the model will not learn, but the training script will continue to run, potentially wasting significant compute resources. This could happen if there's a more persistent instability issue.
To make this more robust, I suggest introducing a counter for consecutive update failures. If the number of consecutive failures exceeds a configurable threshold, it should raise an exception to halt the training. This provides a safety net against silent training failures while still allowing for occasional, transient issues.
You would need to:
- Initialize
self.consecutive_update_failures = 0in the__init__method. - Reset the counter with
self.consecutive_update_failures = 0inside theif update_successful:block (around line 812). - Implement the failure counting and check in this
elseblock as suggested below.
| else: | |
| raise NotImplementedError | |
| logger.warning("Policy update failed, no update is made. This can be caused by gradient overflow in fp16 training.") | |
| else: | |
| self.consecutive_update_failures += 1 | |
| logger.warning( | |
| f"Policy update failed ({self.consecutive_update_failures} consecutive), no update is made. " | |
| "This can be caused by gradient overflow in fp16 training." | |
| ) | |
| max_failures = self.config.get("max_consecutive_update_failures", 10) | |
| if self.consecutive_update_failures > max_failures: | |
| raise RuntimeError( | |
| f"Exceeded max consecutive policy update failures ({max_failures}). " | |
| "Training is likely unstable." | |
| ) |
|
@ISEEKYAN @vermouth1992 Could you please review this PR that supports FP16 training for Megatron ? Thanks. |
Refactor policy update failure handling from exception to warning in MegatronPPOActor to support FP16 training
What does this PR do?
Replaced NotImplementedError with a warning log when policy updates fail due to gradient overflow in FP16 training. This prevents abrupt termination and allows continued execution while alerting users to potential precision issues.
Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI){modules}includefsdp,megatron,veomni,sglang,vllm,rollout,trainer,ci,training_utils,recipe,hardware,deployment,ray,worker,single_controller,misc,perf,model,algo,env,tool,ckpt,doc,data,cfg,reward,like[megatron, fsdp, doc]{type}is infeat,fix,refactor,chore,test[BREAKING]to the beginning of the title.[BREAKING][fsdp, megatron] feat: dynamic batchingChecklist 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 (飞书群).)recipesubmodule, please also update the reference to the submodule commit viagit submodule update --remoteorcd recipe && git pull origin main.