ds4 icon indicating copy to clipboard operation
ds4 copied to clipboard

ROCm: fuse QKV RMSNorm and KV RoPE

Open jyatesdotdev opened this issue 3 months ago • 0 comments

Summary

  • replace the existing ROCm two-launch Q/KV weighted RMSNorm + KV RoPE wrapper with one kernel for shapes up to 256 RoPE pairs, removing one launch per decoded layer;
  • retain the existing two-launch path for larger shapes and add DS4_ROCM_DISABLE_QKV_KV_ROPE_FUSION=1 as a process-start diagnostic rollback;
  • add bit-exact differential coverage for dense, inverse, scaled, YaRN, zero-rotation, 256-pair boundary, 257-pair fallback, and invalid-shape cases.

The DeepSeek V4 graph and public GPU API are unchanged: ds4f-mxfp4 already calls this entry point, whose ROCm compatibility implementation previously chained the two launches. The optimization is independent of routed-expert quantization and applies to both Q4_K and MXFP4 models.

Correctness

On Radeon 8060S / gfx1151:

  • warning-clean ROCm builds passed on both hosts;
  • make HIPCC=/opt/rocm-therock/bin/hipcc test-rocm-qkv-fusion passed all 12 positive cases plus invalid-shape coverage bit-exactly;
  • full-model fused and fallback runs produced identical output across all 40 measured responses.

The focused standalone commit also passes a warning-clean strict CPU build, and its ROCm implementation and differential-test payload are byte-identical to the live-tested integration source.

Performance

A balanced same-binary A/B (fallback -> fused -> fused -> fallback) used fresh processes, a discarded warmup, and 800 measured decode tokens per arm:

  • server decode: 14.5749 -> 14.6032 tok/s (+0.1944%);
  • sampled QKV time: -1.376%;
  • sampled total GPU stream time: -0.218%.

Both paired comparisons were positive. The run used v3 TCP; transport behavior was unchanged. Absolute throughput was measured on the integration tree containing #656, while the same-binary environment toggle isolated only this fusion.

Scope

This is a ROCm attention-launch optimization. It does not include the MXFP4 routed-expert changes from #656, RDMA/NHI transport work, profiling telemetry, or batching changes.

jyatesdotdev avatar Aug 07 '26 01:08 jyatesdotdev