Skip to content

Fuse packed QKV projection for milestone 7e1 - #12

Closed
feitreim wants to merge 1 commit into
mainfrom
feat/qkv-fusion-7e1
Closed

feitreim wants to merge 1 commit into
mainfrom
feat/qkv-fusion-7e1

Conversation

@feitreim

Copy link
Copy Markdown
Owner

Summary

  • replace the default three-projection GPU QKV path with one statically typed packed [D, 3D] projection
  • pack QKV weights, gradients, and AdamW moments while retaining the unfused path as the GPU oracle
  • combine QKV forward, parameter-gradient, input-gradient, and optimizer launches; add explicit pack/unpack CUDA kernels
  • preserve the version-1 RTCKPT01 field order by unpacking/repacking only at checkpoint boundaries
  • make the profiler execute unfused and fused paths from the same seed in one process, using outer-only CUDA events for the performance gate and detailed events for affected rows
  • document and mark SPEC milestone 7e1 complete

B200 performance gate

Same process/container, B=1 T=64 VOCAB=50257 D=1536 H=24 HD=64 FF=4096, two warmups per path, then ten normal full steps per path:

path mean full step
separate Q/K/V baseline 244.5441 ms
packed QKV candidate 227.1921 ms
delta -17.3520 ms (-7.10%, 1.076x)

Affected rows from the detailed step in the same process:

work baseline candidate
forward projections 0.2474 ms 0.1374 ms (qkv.gemm + unpack)
backward QKV projection work 1.5045 ms 1.4268 ms (pack + combined GEMMs + accumulate)
AdamW QKV update 0.0735 ms 0.0597 ms
all named kernels 196.5038 ms 196.1600 ms

Modal run: https://modal.com/apps/feitreim/main/ap-BxaYHpLzuJeCPcez3QfrBq

Validation

  • cargo test --workspace — 31 tests passed
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --manifest-path gpu/llama-model/Cargo.toml -- --check
  • git diff --check
  • B200 cargo oxide run llama-model
    • full fp32 forward/backward and AdamW parity against CPU
    • tiny-batch overfit: 1.386825 -> 0.000148
  • B200 Wikipedia trainer checkpoint test
    • saved steps 1 and 2
    • resumed at step 2 / next batch 2 and completed step 3

Notes

  • compute-sanitizer --tool memcheck cannot execute on the B200 with the repository's current CUDA 13 image. It exits before the program runs with Device not supported and CUDA_ERROR_NO_BINARY_FOR_GPU; the normal B200 CUDA runs above pass.
  • Repository-wide cargo fmt --all --check still reports pre-existing formatting drift in untouched crates/data files. The changed GPU crate is formatted.

@feitreim

Copy link
Copy Markdown
Owner Author

Closing without merge: this PR was built against the pre-31a5d6c roadmap (its SPEC edit renumbers 7e and marks '7e1' complete for what is actually the QKV slice of 7e3) and its integration layer predates the 7e2 workspace refactor (six per-step allocations, no correctness coverage of the unfused oracle). The packed-QKV kernel math itself was review-verified correct — pack/unpack orientation, packed gradient GEMMs, byte-compatible RTCKPT01 — so the 7e3 implementation should feel free to lift those kernels. Superseded by the in-progress 7e3 work based on the current workspace architecture.

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