Repository navigation
MoE: keep the host MoE forward graph for backward; hot experts beat host-only on RNGD - #44
Merged
Merged
Conversation
…recompute) One of the three host MoE passes per layer, and with hot experts one of the three device calls. Equal bitwise to recomputing (test_host_mlp_keep_graph_equals_recompute). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Background
After #38, hot experts on RNGD were at parity with host-only: 13.0 vs 13.5 s/step, alternating steps at host load 120–150. #35 is still open for "faster than host-only". A per-step profile (Qwen3-30B-A3B, LoRA r16 q·v, S=128, hot fraction 0.25) shows where the time went:
HostMLP.backwardrecomputes the whole MoE block forward before its autograd pass. That is about a third of the host MoE time, and one of the three device calls per layer.Changes
npu_lora/moe.py:HostMLP(keep_graph=True).forwardbuilds the autograd graph and keeps(x, y)per layer.backwardreuses it when it receives the same input tensor, and otherwise recomputes as before. It costs the block's saved activations until that layer's backward, a few MB per layer at S=128.test_host_mlp_keep_graph_equals_recompute: LoRA input gradients and full-FT parameter gradients are bitwise equal to the recompute path;experiments/2026-10-21-moe-batched-hot-experts.md, with raw data and the profiler inexperiments/data/moe-batched/. STATUS updated.Verification
CPU:
python -m pytest -q tests(27 passed, torch 2.14.1+cpu, transformers 5.20.2).RNGD setup:
1fee9f2.main)Paired per round:
main: median −4.17 s (−45%).Reproduce:
python3 -m npu_lora.moe_prof MODEL DATA 0.25 128 6 out.jsonl, withexperiments/data/moe-batched/moe_prof.pycopied intonpu_lora/.Compatibility and limits
keep_graphis on by default. It speeds up host-only MoE too (9.21 → 8.00 s). Passkeep_graph=Falseto get the old memory profile.keep_graph; at load 53, hot was already faster.Related Issue
Closes #35
🤖 Generated with Claude Code