Skip to content

[Fix] humming: Free replaced MoE weights after each sublayer transform - #45200

Merged
BBuf merged 2 commits into
sgl-project:mainfrom
DarkraiHL:humming-moe-release-replaced
Nov 2, 2026
Merged

BBuf merged 2 commits into
sgl-project:mainfrom
DarkraiHL:humming-moe-release-replaced

Conversation

@DarkraiHL

@DarkraiHL DarkraiHL commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

--moe-runner-backend humming replaces every MoE sublayer tensor with a padded, repacked copy of a different size while loading. The originals stay referenced until the next sublayer, and later allocations split their cached blocks, so much of that memory is never returned. On 8× H20-3e (141 GB), DeepSeek-V4.1-Flash with TP-sharded experts holds 100.6 GB per GPU after loading at TP4 (81.8–82.2 GB with this PR) and 57.1 GB at TP8 (50.0 GB). At TP4, with or without DSpark, the server fails to start with the default --mem-fraction-static 0.8 (TP4 + DSpark shown):

RuntimeError: The DSV4 SWA pool cap (707840 tokens, 15.81 GB) leaves no room for the full KV pool within the available 9.62 GB. ...

Modifications

  • After each sublayer transform, drop every reference to the replaced tensors (including the loop variables) and call torch.cuda.empty_cache(), in both Humming MoE paths. Padding, kernels and the forward pass are unchanged.
  • CPU unit test test_humming_moe_release_replaced.py: no replaced tensor is still referenced when the cache is emptied, for both paths. It fails on main.

Accuracy Tests

GSM8K (python -m sglang.test.few_shot_gsm8k, 1319 questions):

main this PR
TP4 fails to start 0.913
TP4 + DSpark fails to start 0.919 / 0.920 / 0.926
TP8 0.920 / 0.926 / 0.919 0.920 / 0.926 / 0.920

Speed Tests and Profiling

8× H20-3e, lmsysorg/sglang:nightly-dev-20261019-3c560089, the DeepSeek-V4.1-Flash H200 low-latency cookbook recipe with --moe-runner-backend humming --ep-size 1, SGLANG_HUMMING_INPUT_QUANT_CONFIG='{"dtype": "float8e4m3"}' and SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1. Decode: python -m sglang.bench_serving --dataset-name random-ids --random-input-len 1024 --random-output-len 512; TP8 is the mean of 3 alternating runs on one node.

main this PR
TP4: weights per GPU 100.6 GB, fails to start 81.8–82.2 GB, KV 10.18M tokens
TP4 + DSpark fails to start KV 6.92–7.02M tokens
TP8: weights per GPU / KV tokens 57.1 GB / 26.2–26.6M 50.0 GB / 31.1M
TP8: output tok/s, c1 / c32 / c64 149.6 / 1795 / 2452 150.3 / 1790 / 2435
TP8: median TPOT at c64 20.40 ms 20.41 ms

With #45083 (TP4 + CP4 + DSpark), KV grows from 4.88M to 10.88M tokens. Loading is not slower. With Humming's generic SM90 heuristics (the ones H100/H200 select) forced on the same machine, the memory numbers are the same and TP4 + DSpark starts.

Checklist


CI States

Latest PR Test (Base): ❌ Run #41305143474
Latest PR Test (Extra): ❌ Run #41305143468
Latest PR Test (AMD ROCm 10): ❌ Run #41305143371

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@DarkraiHL

Copy link
Copy Markdown
Contributor Author

@jinzhen-lin @BBuf
A small load-time memory fix for the Humming MoE path. The tensors that transform_humming_layer replaces stay stranded in the caching allocator. On DeepSeek-V4.1-Flash with TP-sharded experts that costs 7–19 GB per GPU, and TP4 does not start at the default --mem-fraction-static. The MXFP4 MoE path and the FP8 HIP int4 path already call torch.cuda.empty_cache() after replacing their weights. This PR does the same after each Humming sublayer and adds a CPU unit test.

Could you take a look when you have time?

@DarkraiHL
DarkraiHL force-pushed the humming-moe-release-replaced branch from 6a0c46f to f9f2e1f Compare October 31, 2026 23:13

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] LGTM. Please wait for the related CPU CI.

@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Nov 1, 2026
@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] @DarkraiHL these CI failures look related to this change, could you take a look?

  • base-a-test-cpu (12): ✗ FAILED: /home/runner/work/sglang/sglang/test/registered/unit/layers/quantization/test_humming_moe_release_replaced.py returned exit code 1" and "RuntimeError: invalid argument to exchangeDevice". Th

@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

1 similar comment
@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

The Humming transform swaps every MoE sublayer tensor for a padded, repacked
copy of a different size. The sublayer helpers drop the originals when they
return, but their blocks stay in the CUDA cache, later allocations split them,
and the remainders stay reserved for the process lifetime. Empty the CUDA cache
after each sublayer.
@DarkraiHL
DarkraiHL force-pushed the humming-moe-release-replaced branch from f9f2e1f to 1c38e9a Compare November 1, 2026 09:00
@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] @DarkraiHL these CI failures look related to this change, could you take a look?

  • base-a-test-cpu (12): RuntimeError: invalid argument to exchangeDevice" and "✗ FAILED: /home/runner/work/sglang/sglang/test/registered/unit/layers/quantization/test_humming_moe_release_replaced.py returned exit code 1". Th

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] LGTM.

@BBuf
BBuf merged commit 61d2005 into sgl-project:main Nov 2, 2026
149 of 160 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants