feat: add parameter-level precision control for BF16 training #7750
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: #7747
Hi DeepSpeed team,
I hope this PR finds you well. I'm submitting this fix to resolve issue #7747, which addresses the problem where MoE router parameters are forcibly cast to bf16 under DeepSpeed bf16 configuration, causing dtype mismatch in fp32 routing logic.
Key changes:
Added should_preserve_dtype() helper function to check parameter preservation flags
Enhanced parameter processing in _setup_for_real_optimizer() to handle mixed precision scenarios
Updated storage management in _update_storage_to_flattened_tensor() to preserve original data types
Included comprehensive tests and documentation
Usage:
Users can now mark specific parameters with param.preserve_dtype = True to maintain their original precision while still benefiting from BF16 mixed precision training for other parameters.
This solution is backward compatible and provides an official mechanism for handling numerically sensitive modules like MoE routers. I've tested this thoroughly and believe it will be valuable for users facing similar precision-related issues.
Looking forward to your feedback and review. Thank you for your time and consideration!
Best regards,