Skip to content

[high risk]Speedup 2.5-6X moe tuning and pin ngram to cpu - #2303

Merged
wenhuach21 merged 52 commits into
mainfrom
suport_fuse_moe
Sep 9, 2026
Merged

wenhuach21 merged 52 commits into
mainfrom
suport_fuse_moe

Conversation

@wenhuach21

@wenhuach21 wenhuach21 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Description

This PR introduces a new grouped-GEMM MoE experts forward path intended to significantly speed up MoE tuning, and adds mechanisms to keep very large ngram/PLE embedding tables off accelerators (CPU-pinned or GPU-sharded) to prevent VRAM/RAM blowups during per-block dispatch and tuning.

Changes:
Add a CUDA-focused grouped experts implementation (linear_grouped) with batched fake-quantization to reduce per-expert overhead during tuning.Add ngram embedding placement controls (AR_NGRAM_DEVICE) plus helpers to pin/shard ngram tables and to avoid relocating pinned/self-managed subtrees.Extend disk-stream materialization to handle wildcard shard concatenation and broader converter-driven weight reconstruction for newer checkpoint layouts.

Type of Change

Bug fix

Related Issues

Fixes or relates to #

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

TODO

check v2 has imatrix

@wenhuach21

Copy link
Copy Markdown
Contributor Author

main branch

026-09-04 15:16:39 INFO replace_modules.py L390: Found 40 modules to replace
Replacing modules: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 40/40 [00:10<00:00, 3.83it/s]
2026-09-04 15:16:49 INFO replace_modules.py L417: Replaced 40 modules
2026-09-04 15:16:49 INFO device.py L1482: [Memory Monitor] After applying custom replacements: 'peak_ram': 1.52GB
[transformers] loss_type=None was set in the config but it is unrecognized. Using the default loss: ForCausalLMLoss.
2026-09-04 15:16:53 INFO replace_modules.py L128: Experts (after replacement/skip) [model.language_model.layers.0.mlp.experts] (SequentialQwen3_5MoeExperts):
SequentialQwen3_5MoeExperts(
(0-255): 256 x Qwen3_5MoeMLP(
(gate_proj): Linear(in_features=2048, out_features=512, bias=False)
(up_proj): Linear(in_features=2048, out_features=512, bias=False)
(down_proj): Linear(in_features=512, out_features=2048, bias=False)
(act_fn): SiLUActivation()
)
)
2026-09-04 15:16:53 INFO base.py L988: Using predefined ignore_layers: model.language_model.layers.[0-39].mlp.gate
2026-09-04 15:16:53 INFO layer_config_resolver.py L401: Ignored layers: model.language_model.layers.[0-39].mlp.gate
2026-09-04 15:16:55 INFO layer_config_resolver.py L401: Ignored layers: model.language_model.layers.[0-39].mlp.gate
2026-09-04 15:16:58 INFO base.py L1329: torch.compile is enabled
2026-09-04 15:17:03 INFO orchestrator.py L570: start to cache block inputs
2026-09-04 15:17:03 INFO mllm.py L86: Using MLLM template: qwen3_5_moe
2026-09-04 15:17:03 INFO calib_dataset.py L1113: Preprocessing calibration dataset in a subprocess to avoid memory leaks...
2026-09-04 15:17:16 INFO device.py L1448: 'peak_ram': 3.08GB
2026-09-04 15:17:16 INFO orchestrator.py L602: caching done
Quantizing model.language_model.layers.0: 0%| | 0/40 [00:02<?, ?it/s]/home/wenhuach/miniforge3/envs/autoround/lib/python3.13/site-packages/torch/_dynamo/variables/functions.py:2590: UserWarning: Dynamo detected a call to a functools.lru_cache-wrapped function at 'fused_norm_gate.py:565'. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a potential risk, not something we have observed. Enable TORCH_LOGS=+dynamo for a DEBUG stack trace.

This call originates from:
File "/home/wenhuach/miniforge3/envs/autoround/lib/python3.13/site-packages/fla/modules/fused_norm_gate.py", line 565, in layer_norm_gated_bwd
NS = min(get_multiprocessor_count(x.device.index), T)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^

torch._dynamo.utils.warn_once(msg)
/home/wenhuach/miniforge3/envs/autoround/lib/python3.13/site-packages/torch/_dynamo/variables/functions.py:2431: UserWarning: Dynamo does not know how to trace the builtin cuda_utils.get_device_properties. This function is either a Python builtin (e.g. _warnings.warn) or a third-party C/C++ Python extension (perhaps created with pybind).
If it is a Python builtin, please file an issue on GitHub so the PyTorch team can add support for it and see the next case for a workaround.
If it is a third-party C/C++ Python extension, please either wrap it into a PyTorch-understood custom operator (see https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html for more details) or, if it is traceable, use torch.compiler.allow_in_graph.
torch._dynamo.utils.warn_once(explanation + "\n" + "\n".join(hints))
2026-09-04 15:20:10 INFO quantizer.py L545: Unquantized layers: ['mlp.shared_expert_gate']
quantized 776/777 layers in the block, loss iter 0: 1.099e-05 -> iter 175: 8.358e-07
2026-09-04 15:20:15 INFO device.py L1448: 'peak_ram': 19.44GB, 'peak_vram': 19.45GB
Quantizing model.language_model.layers.1: 2%|████▋ | 1/40 [03:35<2:20:03, 215.47s/it]2026-09-04 15:25:11 INFO quantizer.py L545: Unquantized layers: ['mlp.shared_expert_gate']
quantized 776/777 layers in the block, loss iter 0: 3.570e-06 -> iter 182: 1.313e-06
2026-09-04 15:25:17 INFO device.py L1448: 'peak_ram': 21.55GB, 'peak_vram': 24.61GB
Quantizing model.language_model.layers.2: 5%|█████████▎ | 2/40 [08:38<2:49:13, 267.20s/it]qTraceback (most recent call last):

current

(autoround) wenhuach@mlp-dgx-01:~/auto-round$ CUDA_VISIBLE_DEVICES=2 python3 -m auto_round /models/Qwen3.6-35B-A3B --output_dir "/data2/wenhuach" --tasks lambada_openai
2026-09-04 15:12:19 INFO main.py L309: start to quantize /models/Qwen3.6-35B-A3B
2026-09-04 15:12:19 INFO model.py L347: Fused-MoE checkpoint detected: building a meta skeleton and materializing weights per block (set AR_DISABLE_AUTO_META_LOAD=1 to load the whole model on CPU instead).
2026-09-04 15:12:22 INFO device.py L1446: Before applying custom replacements 'peak_ram': 1.07GB
2026-09-04 15:12:24 INFO moe_experts_interface.py L783: [MoE Prep] Unfused 40 MOE experts modules
2026-09-04 15:12:25 INFO device.py L1446: After applying custom replacements 'peak_ram': 1.26GB
2026-09-04 15:12:25 INFO replace_modules.py L102: Prepared 40 MOE modules for quantization
2026-09-04 15:12:25 INFO replace_modules.py L161: Experts (before unfuse) [model.language_model.layers.0.mlp.experts] (Qwen3_5MoeExperts):
Qwen3_5MoeExperts(
(act_fn): SiLUActivation()
)
2026-09-04 15:12:25 INFO replace_modules.py L162: Experts (after unfuse) [model.language_model.layers.0.mlp.experts] (Qwen3_5MoeExperts):
Qwen3_5MoeExperts(
(act_fn): SiLUActivation()
(0-255): 256 x _ExpertContainer(
(down_proj): Linear(in_features=512, out_features=2048, bias=False)
(gate_proj): Linear(in_features=2048, out_features=512, bias=False)
(up_proj): Linear(in_features=2048, out_features=512, bias=False)
)
)
2026-09-04 15:12:27 INFO base.py L2127: format is not set, using default auto_round format.
2026-09-04 15:12:27 WARNING logging.py L340: some layers are skipped quantization (shape not divisible by 32): model.language_model.layers.[0-39].mlp.shared_expert_gate, model.visual.blocks.[0-26].mlp.linear_fc1, model.visual.blocks.[0-26].mlp.linear_fc2
2026-09-04 15:12:28 INFO base.py L988: Using predefined ignore_layers: model.language_model.layers.[0-39].mlp.gate
2026-09-04 15:12:28 INFO layer_config_resolver.py L401: Ignored layers: model.language_model.layers.[0-39].mlp.gate
2026-09-04 15:12:29 INFO layer_config_resolver.py L401: Ignored layers: model.language_model.layers.[0-39].mlp.gate
2026-09-04 15:12:33 INFO base.py L1329: torch.compile is enabled
2026-09-04 15:12:33 INFO composer.py L219: Block-forward torch.compile is disabled because grouped MoE experts run eager; the per-layer qdq stays compiled.
2026-09-04 15:12:37 INFO orchestrator.py L570: start to cache block inputs
2026-09-04 15:12:37 INFO mllm.py L86: Using MLLM template: qwen3_5_moe
2026-09-04 15:12:37 INFO calib_dataset.py L1113: Preprocessing calibration dataset in a subprocess to avoid memory leaks...
2026-09-04 15:12:50 INFO device.py L1448: 'peak_ram': 3.13GB
2026-09-04 15:12:50 INFO orchestrator.py L602: caching done
Quantizing model.language_model.layers.0: 0%| | 0/40 [00:01<?, ?it/s]
2026-09-04 15:13:40 INFO quantizer.py L545: Unquantized layers: ['mlp.shared_expert_gate']
quantized 776/777 layers in the block, loss iter 0: 1.099e-05 -> iter 199: 8.291e-07
2026-09-04 15:13:45 INFO device.py L1448: 'peak_ram': 17.78GB, 'peak_vram': 24.52GB
Quantizing model.language_model.layers.1: 2%|████▋ | 1/40 [01:30<59:04, 90.87s/it]
2026-09-04 15:15:05 INFO quantizer.py L545: Unquantized layers: ['mlp.shared_expert_gate']
quantized 776/777 layers in the block, loss iter 0: 3.474e-06 -> iter 182: 1.286e-06
2026-09-04 15:15:09 INFO device.py L1448: 'peak_ram': 17.78GB, 'peak_vram': 27.47GB
Quantizing model.language_model.layers.2: 5%|█████████▍ | 2/40 [02:53<54:38, 86.26s/it]

@wenhuach21 wenhuach21 changed the title Speedup 3X moe tuning Speedup 3X moe tuning via grouped experts Sep 4, 2026
@wenhuach21

Copy link
Copy Markdown
Contributor Author

accuracy is not matched for now

wenhuach21 and others added 4 commits September 8, 2026 17:20
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@wenhuach21 wenhuach21 changed the title [high risk]Speedup 2.5-4X moe tuning via grouped experts and pin ngram to cpu to fix qwen ram issue [high risk]Speedup 2.5-4X moe tuning and pin ngram to cpu Sep 8, 2026
@wenhuach21

Copy link
Copy Markdown
Contributor Author

(autoround) wenhuach@mlp-dgx-01:~/auto-round$ CUDA_VISIBLE_DEVICES=6 python3 -m auto_round /models/Qwen3.6-35B-A3B/ --tasks mmlu --format fake --output_dir /data4/wenhuach --eval_bs 4
W0908 17:27:08.914000 3454376 site-packages/torch/utils/_pytree.py:630] <enum 'KernelPreference'> is an Enum subclass and is now natively supported by torch.compile as an opaque value type. Calling register_constant() on Enum subclasses is deprecated and will be an error in a future release.
W0908 17:27:08.944000 3454376 site-packages/torch/utils/_pytree.py:630] <enum 'ScaleCalculationMode'> is an Enum subclass and is now natively supported by torch.compile as an opaque value type. Calling register_constant() on Enum subclasses is deprecated and will be an error in a future release.
2026-09-08 17:27:10 INFO main.py L309: start to quantize /models/Qwen3.6-35B-A3B
Loading weights: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1026/1026 [00:00<00:00, 6885.17it/s]
2026-09-08 17:27:14 INFO device.py L1591: [Memory Monitor] Before applying custom replacements: 'peak_ram': 1.3GB
2026-09-08 17:27:14 INFO replace_modules.py L421: Found 40 modules to replace
Replacing modules: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 40/40 [00:12<00:00, 3.21it/s]
2026-09-08 17:27:26 INFO replace_modules.py L448: Replaced 40 modules
2026-09-08 17:27:26 INFO device.py L1594: [Memory Monitor] After applying custom replacements: 'peak_ram': 1.42GB
2026-09-08 17:27:27 INFO replace_modules.py L160: Experts (before replacement) [model.language_model.layers.0.mlp.experts] (Qwen3_5MoeExperts):
Qwen3_5MoeExperts(
(act_fn): SiLUActivation()
)
2026-09-08 17:27:27 INFO replace_modules.py L161: Experts (after replacement) [model.language_model.layers.0.mlp.experts] (SequentialQwen3_5MoeExperts):
SequentialQwen3_5MoeExperts(
(0-255): 256 x Qwen3_5MoeMLP(
(gate_proj): Linear(in_features=2048, out_features=512, bias=False)
(up_proj): Linear(in_features=2048, out_features=512, bias=False)
(down_proj): Linear(in_features=512, out_features=2048, bias=False)
(act_fn): SiLUActivation()
)
(256): SiLUActivation()
)
2026-09-08 17:27:27 INFO base.py L999: Using predefined ignore_layers: model.language_model.layers.[0-39].mlp.gate
2026-09-08 17:27:27 INFO layer_config_resolver.py L401: Ignored layers: model.language_model.layers.[0-39].mlp.gate
2026-09-08 17:27:29 INFO layer_config_resolver.py L401: Ignored layers: model.language_model.layers.[0-39].mlp.gate
2026-09-08 17:27:32 INFO base.py L1340: torch.compile is enabled
2026-09-08 17:27:37 INFO orchestrator.py L587: start to cache block inputs
2026-09-08 17:27:37 INFO mllm.py L86: Using MLLM template: qwen3_5_moe
2026-09-08 17:27:37 INFO mllm.py L125: Multimodal model with non-MLLM calibration dataset 'NeelNanda/pile-10k' and quant_nontext_module=False: using the standard text dataloader (vision/audio towers are not being quantized, so text-only calibration through the full-model forward is sufficient).
2026-09-08 17:27:37 INFO calib_dataset.py L1113: Preprocessing calibration dataset in a subprocess to avoid memory leaks...
2026-09-08 17:27:50 INFO device.py L1560: 'peak_ram': 3.01GB
2026-09-08 17:27:50 INFO orchestrator.py L619: caching done
Quantizing model.language_model.layers.0: 0%| | 0/40 [00:02<?, ?it/s]2026-09-08 17:28:44 INFO quantizer.py L548: Unquantized layers: ['mlp.shared_expert_gate']
quantized 776/777 layers in the block, loss iter 0: 1.099e-05 -> iter 140: 8.766e-07
2026-09-08 17:28:49 INFO device.py L1560: 'peak_ram': 18.94GB, 'peak_vram': 25.18GB
Quantizing model.language_model.layers.1: 2%|████▍ | 1/40 [00:58<38:17, 58.91s/it]2026-09-08 17:29:36 INFO quantizer.py L548: Unquantized layers: ['mlp.shared_expert_gate']
quantized 776/777 layers in the block, loss iter 0: 3.543e-06 -> iter 182: 1.309e-06
2026-09-08 17:29:40 INFO device.py L1560: 'peak_ram': 22.13GB, 'peak_vram': 28.29GB
Quantizing model.language_model.layers.2: 5%|████████▉ | 2/40 [01:50<34:34, 54.58s/it]2026-09-08 17:30:21 INFO quantizer.py L548: Unquantized layers: ['mlp.shared_expert_gate']
quantized 776/777 layers in the block, loss iter 0: 7.851e-06 -> iter 191: 2.250e-06
2026-09-08 17:30:26 INFO device.py L1560: 'peak_ram': 25.28GB, 'peak_vram': 28.62GB
Quantizing model.language_model.layers.3: 8%|█████████████▎ | 3/40 [02:35<31:06, 50.44s/it]2026-09-08 17:31:10 INFO quantizer.py L548: Unquantized layers: ['mlp.shared_expert_gate']
quantized 775/776 layers in the block, loss iter 0: 9.733e-06 -> iter 173: 3.259e-06
2026-09-08 17:31:14 INFO device.py L1560: 'peak_ram': 25.37GB, 'peak_vram': 28.62GB
Quantizing model.language_model.layers.4: 10%|█████████████████▊ | 4/40 [03:24<29:48, 49.69s/it]

@wenhuach21 wenhuach21 changed the title [high risk]Speedup 2.5-4X moe tuning and pin ngram to cpu [high risk]Speedup 2.5-6X moe tuning and pin ngram to cpu Sep 8, 2026
@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@wenhuach21

Copy link
Copy Markdown
Contributor Author

please have a review

@wenhuach21

Copy link
Copy Markdown
Contributor Author

nemetron still has issues, trackign here #2324

@wenhuach21

Copy link
Copy Markdown
Contributor Author

merge first, will fix issues in other prs

@wenhuach21
wenhuach21 merged commit 678f8f5 into main Sep 9, 2026
48 of 51 checks passed
@wenhuach21
wenhuach21 deleted the suport_fuse_moe branch September 9, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants