Add after-load fusion for static quantized MLPs#46997
Open
LiangSu8899 wants to merge 1 commit into
Open
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: finegrained_fp8 |
7cd4640 to
3d7f4ad
Compare
Member
|
cc @SunMarc maybe? |
Contributor
CI recapDashboard: View test results in Grafana |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
This PR adds an opt-in after-load fusion path for static quantized MLP modules.
Today,
fusion_configsupports pre-initialization module fusion such as patch embeddings. Some quantized fusions, however, need the quantized weights and frozen scales to be available first. Static FP8 MLP fusion is one of those cases: the replacement module needs the loaded FP8 weights, activation scales, and weight scales before it can safely dispatch to a Hub kernel.This PR extends the fusion mapping machinery with after-load fusion specs and wires that path into the
FineGrainedFP8quantizer after weight loading. The first supported after-load fusion family isstatic_quantized_mlp.Why this matters:
External validation from a prototype HF kernels integration:
K=2048,H=16384:M=50: BF160.151 ms-> static FP8 fused0.070 ms, about2.1xfaster;M=512: BF160.581 ms-> static FP8 fused0.275 ms, about2.1xfaster;1.2x-1.6xfaster.21.56 msvs dynamic36.23 ms, about1.68xfaster;24.85 msvs dynamic47.97 ms, about1.93xfaster;0.9999275, max abs0.0195, p99 abs0.0156, MSE1.675e-05;0.9998960, max abs0.0215, p99 abs0.0195, MSE2.008e-05.98.2%.The detailed reproduction notes are available at https://github.com/flashrt-project/FlashRT-HF-kernels/blob/main/docs/static-vs-dynamic-fp8.md, and calibration robustness notes are available at https://github.com/flashrt-project/FlashRT/blob/main/docs/calibration.md. These are external validation results and are not required by the Transformers test suite.
The implementation is intentionally opt-in and backend-neutral:
model.config.fusion_config;Example config shape:
Supported in this PR:
FineGrainedFP8FP8Linearmodules;gate_proj,up_proj,down_projand SiLU or tanh-approx GELU activations;fc1,fc2, and tanh-approx GELU activation;This is meant to be a narrow mechanism extension that can later be reused for related static quantized fusions, for example NVFP4/MXFP4 MLP kernels or additional MLP layouts.
Fixes # (issue)
Code Agent Policy
The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.
PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.
This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read
CONTRIBUTING.md.This PR is opened as a draft so the author can review all changed lines before marking the Code Agent Policy checkbox and moving it to ready for review.
Before submitting
Pull Request checks?
to it if that's the case.
Tests
Result:
8 passed, 1 warningResult:
4 passed, 1 warningResult:
All checks passed!Result:
2 files already formattedPATH=/path/to/venv/bin:$PATH python utils/check_copies.py git diff --checkResult: passed
Reviewer notes
The main API question is whether
fusion_config["static_quantized_mlp"]is the right public surface for after-load quantized fusion specs, or whether maintainers would prefer a quantizer-owned registration mechanism.Potential reviewers: quantization, kernels, and model loading maintainers.