Skip to content

fix(ds4): correct layer-split HC handoff, per-device state, and greedy decode in local path#507

Draft
Graffioh wants to merge 4 commits into
Luce-Org:codex/ds4-rocmfpx-serverfrom
Graffioh:codex/fix-ds4-hc-shard-handoff
Draft

fix(ds4): correct layer-split HC handoff, per-device state, and greedy decode in local path#507
Graffioh wants to merge 4 commits into
Luce-Org:codex/ds4-rocmfpx-serverfrom
Graffioh:codex/fix-ds4-hc-shard-handoff

Conversation

@Graffioh

@Graffioh Graffioh commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes correctness and device-isolation issues in the DeepSeek4 HC layer-split path:

  • hand off the updated full HC state between local shards
  • scope HC weights and cached decode graphs to each shard
  • keep independent CUDA/HIP HC scratch and F16 mirrors per GPU device
  • propagate the request sampler configuration and seed
  • compute greedy argmax on the GPU, copying only the selected token instead of the full logits
  • add coverage for HC handoff, sampler propagation, GPU argmax, and per-device scratch

Stack

Stacked on #503. The HC-complete layer-range implementation fixed here is introduced by #503. Retarget this PR to the branch where #503 lands once merged.

Implementation

Local layer split now follows the correct HC flow:

token embeddings -> shard 0 -> full HC state -> shard 1 -> ... -> final shard

Runtime caches are owned by each shard and keyed by weights, context, backend, device, layer range, and output ownership. HC scratch is stored in independently locked slots indexed by CUDA/HIP device.

For greedy decode, the final shard uses ggml_argmax and returns one int32_t. Full logits are transferred only when CPU-side sampling or penalties require them. This applies to cached, dynamic, fused, local, and remote target-shard paths.

Validation

  • git diff --check and C++ syntax checks passed
  • Release CUDA H200 builds passed for test_deepseek4_unit and dflash_server
  • tested on one H200 in both single-shard and virtual two-shard configurations
  • virtual split [0,22) / [22,43) on cuda:0 completed sequential greedy requests without HC, CUDA, crash, or abort errors
  • the virtual split validates HC handoff, per-shard cache reuse, and local greedy decode
  • still needs validation on lucebox3 and lucebox5, especially the real multi-device device 0 -> device 1 -> device 0 scratch path

@Graffioh Graffioh changed the title fix(deepseek4): correct HC shard handoff and scope runtime caches per shard fix(ds4): correct HC shard handoff and scope runtime caches per shard Jul 11, 2026
@davide221

Copy link
Copy Markdown
Contributor

We plan to run two AMD GPUs in the same HIP process. g_scratch is currently shared across devices, so the second shard may reuse scratch memory allocated on the first GPU. Please keep one scratch buffer per HIP device, set the correct device in HC worker threads

@Graffioh Graffioh force-pushed the codex/fix-ds4-hc-shard-handoff branch from 8f89434 to bf8dc45 Compare July 13, 2026 15:03
@Graffioh Graffioh force-pushed the codex/fix-ds4-hc-shard-handoff branch from bf8dc45 to ecf55b1 Compare July 13, 2026 15:13
@Graffioh Graffioh changed the title fix(ds4): correct HC shard handoff and scope runtime caches per shard fix(ds4): correct layer-split HC handoff, per-device state, and greedy decode in local path Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants