Skip to content

fix(offload): dedupe tied weights across layerwise targets - #1111

Merged
DefTruth merged 2 commits into
mainfrom
dev
Sep 4, 2026
Merged

DefTruth merged 2 commits into
mainfrom
dev

Conversation

@DefTruth

@DefTruth DefTruth commented Sep 4, 2026

Copy link
Copy Markdown
Member

Weight tying (e.g. lm_head.weight is embed_tokens.weight, Qwen3-4B) made two targets reference the same live parameter with independent pinned mirrors and onload/offload state machines: one target's CPU rebind poisoned the other's GPU residency bookkeeping, and async prefetch exposed half-copied tensors to the other's forward (torn vocab embedding reads -> wrong conditioning; with prefetch_limit it crashed on device mismatch instead).

Shared states are now owned by their first target: duplicates are dropped from later targets (tie_deduped, bookkeeping-only transport), owners are forced persistent so the shared tensor stays resident for the handle lifetime, and prefetch_residency_bytes is recomputed after the drop.

Trade-offs: tied tensors stay GPU-resident (bypassing persistent_buckets, Qwen3-4B fp16 embedding ~778MB), and attaching a GPU-resident model briefly allocates the duplicate pinned mirror before dedupe frees it. Non-CPU-mirror offload devices are out of scope.

Verified: tied toy LM (Embedding + blocks + norm + tied lm_head) is bitwise-equal to the GPU-resident baseline across sync / async / async+prefetch_limit, with owner-forced-persistent and tie_deduped structure asserts; real klein_fit TE outputs are bitwise-stable across offload variants; all 37 layerwise offload tests pass.

DefTruth and others added 2 commits September 4, 2026 09:19
Weight tying (e.g. lm_head.weight is embed_tokens.weight, Qwen3-4B) made two
targets reference the same live parameter with independent pinned mirrors and
onload/offload state machines: one target's CPU rebind poisoned the other's
GPU residency bookkeeping, and async prefetch exposed half-copied tensors to
the other's forward (torn vocab embedding reads -> wrong conditioning; with
prefetch_limit it crashed on device mismatch instead).

Shared states are now owned by their first target: duplicates are dropped from
later targets (tie_deduped, bookkeeping-only transport), owners are forced
persistent so the shared tensor stays resident for the handle lifetime, and
prefetch_residency_bytes is recomputed after the drop.

Trade-offs: tied tensors stay GPU-resident (bypassing persistent_buckets,
Qwen3-4B fp16 embedding ~778MB), and attaching a GPU-resident model briefly
allocates the duplicate pinned mirror before dedupe frees it. Non-CPU-mirror
offload devices are out of scope.

Verified: tied toy LM (Embedding + blocks + norm + tied lm_head) is
bitwise-equal to the GPU-resident baseline across sync / async /
async+prefetch_limit, with owner-forced-persistent and tie_deduped structure
asserts; real klein_fit TE outputs are bitwise-stable across offload variants;
all 37 layerwise offload tests pass.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@DefTruth
DefTruth merged commit 51979f0 into main Sep 4, 2026
4 checks passed
@DefTruth
DefTruth deleted the dev branch September 4, 2026 10:16
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.

1 participant