Enable native mxfp4 training support for GPT-OSS models#40180
Conversation
- Add enable_training flag to Mxfp4Config for training mode activation - Update Mxfp4HfQuantizer.is_trainable to support training when flag is enabled - Implement MxFp4MatMulFunction PyTorch autograd integration with forward/backward - Add progressive hardware fallback strategy (FP4 → FP8 → BF16) for compatibility - Enhance Mxfp4GptOssExperts with dual forward paths for training/inference - Create comprehensive testing infrastructure with hardware validation This enables 4X memory savings during training by keeping weights quantized. Foundation ready for native mxfp4 training once Triton backward kernels are implemented.
|
[For maintainers] Suggested jobs to run (before merge) run-slow: mxfp4 |
|
@akacmazz Could you please update |
|
Thanks for pointing that out 🙏 @PavloFesenko I’ve updated the PR description from Edit Issue PR for #40170 to Fixes #40170. |
|
It seems a little early for this PR, since it has to fall back to |
| logger = logging.get_logger(__name__) | ||
|
|
||
|
|
||
| class ComputeBackend(Enum): |
There was a problem hiding this comment.
So this isn't actually MXFP4 training? It's MXFP4 weight storage and computation in a fallback dtype?
Enable native mxfp4 training support for GPT-OSS models
Fixes #40170
What does this PR do?
This PR adds the foundational infrastructure to enable native mxfp4 training for GPT-OSS models, addressing the issue where users currently must convert 4-bit weights to bfloat16 for training (using 4X more memory).
Key Features:
enable_trainingflagImplementation Details
1. Configuration Layer
enable_trainingparameter toMxfp4Configis_trainableproperty inMxfp4HfQuantizer2. PyTorch Autograd Integration
MxFp4MatMulFunctioncustom autograd functionmxfp4_matmul_with_gradientswrapper function3. Hardware Detection & Fallback
4. Expert Module Enhancement
Mxfp4GptOssExpertswith dual forward pathsenable_mxfp4_training()method for gradient activation5. Testing Infrastructure
tests/quantization/mxfp4/test_mxfp4.pyUsage Example
Hardware Support
Design Documentation
A comprehensive design specification for Triton backward kernels has been created at
MXFP4_BACKWARD_KERNEL_DESIGN.md, providing:Current Status
✅ Transformers Integration: Complete
⏳ Pending: Triton Kernel Implementation
kernels-community/triton_kernelsTesting
Before submitting
Who can review?
@SunMarc @MekkCyber @Rocketknight1
This PR provides the Transformers-side infrastructure for native mxfp4 training. The actual Triton backward kernels will need to be implemented separately in the
triton-kernelsrepository, but once available, this infrastructure will automatically utilize them.cc @Rocketknight1 (mentioned in the original issue as able to help with integration)