-
Notifications
You must be signed in to change notification settings - Fork 230
[MoE] MoE Calibration with calibrate_all_experts
#1760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Change Purpose: - Add calibrate_all_experts option to improve MoE calibration Change Details: - Add `calibrate_all_experts` flag to MoE layers - Update `replace_modules_for_calibration` and `moe_calibration_context` to propagate the flag into modules - Modify expert forward passes: * Normal mode (default): compute output only for tokens routed to top-k experts, and combine their weighted results in the final output * Calibration mode (`calibrate_all_experts=True`): compute output for all tokens on every expert, but still apply the top-k gating to decide which token outputs contribute to the final result. Testing: - Add unit test to verify all experts are triggered during MoE calibration
Signed-off-by: Kyle Sayers <[email protected]>
👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review. Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed. |
Signed-off-by: Kyle Sayers <[email protected]>
calibrate_all_experts
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment below. I also agree with @brian-dellabetta's point that this could maybe be simplified by patching self.top_k
temporarily.
Signed-off-by: Kyle Sayers <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not get a chance to run through these as of yet but it would be good to run through nvfp4 for llama4 and qwen3 and validating performance on the b200 before landing this, if anybody has bandwidth to run these
Running those examples now |
FYI - Produced the following Qwen Model: With the following set-up: lm_eval \
--model vllm \
--model_args pretrained="Qwen/Qwen3-30B-A3B",dtype=auto,max_model_len=4096,add_bos_token=True\
--tasks gsm8k \
--batch_size auto
NVFP4: |Tasks|Version| Filter |n-shot| Metric | |Value | |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k| 3|flexible-extract| 5|exact_match|↑ |0.8734|± |0.0092|
| | |strict-match | 5|exact_match|↑ |0.8719|± |0.0092| Dense: |Tasks|Version| Filter |n-shot| Metric | |Value | |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k| 3|flexible-extract| 5|exact_match|↑ |0.8544|± |0.0097|
| | |strict-match | 5|exact_match|↑ |0.8916|± |0.0086| The only thing I noticed was speed but that may also be because of beaker just being slow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, for Llama4 NVFP4
lm_eval \
--model vllm \
--model_args pretrained="nm-testing/Llama-4-Scout-17B-16E-Instruct-NVFP4-0913",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
--tasks gsm8k_llama \
--apply_chat_template \
--fewshot_as_multiturn \
--batch_size auto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Two small comments
Thanks a ton @dsikka |
Signed-off-by: Kyle Sayers <[email protected]>
Coauthored with @dichn!
Purpose
calibrate_all_experts
option, which sends all tokens to all experts, but still produces the same outputs as if tokens had been gatedChanges
calibrate_all_experts=True
token gating occurs after passing tokens to experts, rather than beforeTesting