Skip to content

feat(kimi-k3): serve DSpark drafts (fc_norm + AttnRes tap) - #1031

Open
torchspec-bot wants to merge 3 commits into
mainfrom
feat/k3-dspark-torchspec-draft-recreated
Open

feat(kimi-k3): serve DSpark drafts (fc_norm + AttnRes tap)#1031
torchspec-bot wants to merge 3 commits into
mainfrom
feat/k3-dspark-torchspec-draft-recreated

Conversation

@torchspec-bot

Copy link
Copy Markdown
Collaborator

Summary

A K3 DSpark draft needs two things the Inferact reference checkpoint does not. Both currently fail silently — they cost acceptance rate and raise nothing, which is the reason this PR makes each one declared and enforced rather than inferred.

fc_norm — the draft normalizes each target tap on its own before the taps are concatenated and projected. Its five weights ride in the checkpoint; without the modules they have no destination and context_proj sees inputs on a scale it was never trained for. A draft that declares "fc_norm": true gets the modules and ships one fc_norm.N.weight per tap; declaring it without the weights, or shipping weights without declaring it, now fails the load rather than serving an identity-weight norm. The incremental-projection fast path re-projects from pre-split fc columns and would skip the norms entirely, so it stands down for such a draft instead of quietly disagreeing with project_target_hidden.

aux_hidden_stream — K3's residual backbone mixes across blocks, so the value a consumer layer actually reads is the pre-norm AttnRes mixture, not the running prefix sum. A draft trained against that stream must be fed it. The checkpoint declares which stream it wants, the target refuses a request it cannot honour, and the resolved choice is logged next to the tap ids at startup:

DFLASH/DSpark target capture: layers=(7, 31, 47, 63, 87) stream=attn_res

The default is unchanged — a checkpoint that declares neither field behaves exactly as before. TOKENSPEED_DFLASH_AUX_STREAM overrides the checkpoint for A/B runs.

Test Plan

test/runtime/test_k3_dspark_torchspec_draft.py — 24 new tests covering config defaults and validation, stream resolution and env override, _wire_aux_hidden_stream, set_dflash_aux_hidden_stream, _dspark_capture_stream (prefix / attn_res / consumer weights / last layer / no blocks), fc_norm projection ordering and its strict=True length mismatch, and the incremental-projection stand-down. All use synthetic configs — no checkpoint required, so they run in ordinary CI.

End-to-end, Kimi-K3 + a TorchSpec DSpark draft, TP16 across 4× GB200 (requires #1015 to start at all):

aux stream acc_len
attn_res (what the draft trained against) 5.383

Reproducibility caveat, stated plainly: the TorchSpec checkpoint these numbers come from is not public, so the end-to-end table above is not something a reviewer can independently re-run today. The unit tests are self-contained. Happy to hold this PR until a checkpoint is available if you'd rather not take serving-side evidence on trust.

A full-length GSM8K run is blocked on an unrelated engine hang under sustained load in the target's KDA prefill path — it reproduces with stream=prefix, so it predates this change. Filing separately.

A TorchSpec-trained K3 DSpark draft needs two things the Inferact reference
checkpoint does not, and both fail silently -- they cost acceptance rate and
raise nothing.

fc_norm: the draft normalizes each target tap on its own before the taps are
concatenated and projected. Its five weights ride in the checkpoint; without
the modules they have no destination and context_proj sees inputs on a scale
it was never trained for. The incremental-projection fast path re-projects
from pre-split fc columns and would skip it, so it stands down for such a
draft rather than quietly disagreeing with project_target_hidden.

aux_hidden_stream: K3's residual backbone mixes across blocks, so the value a
consumer layer actually reads is the pre-norm AttnRes mixture, not the running
prefix sum. Drafts trained against that stream must be fed it. The checkpoint
declares which one it wants, the target refuses a request it cannot honour, and
TOKENSPEED_DFLASH_AUX_STREAM exists to A/B the claim. Default is unchanged.

Signed-off-by: torchspec-bot <262938024+torchspec-bot@users.noreply.github.com>
@torchspec-bot
torchspec-bot requested review from a team as code owners August 10, 2026 06:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f1e48b5d1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


import torch
from torch import nn
from tokenspeed_kernel.ops.layernorm.triton import segmented_rmsnorm

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bump the kernel floor for the new RMSNorm API

In deployments where the runtime wheel is upgraded while an older tokenspeed-kernel wheel satisfying the existing tokenspeed-kernel>=0.1.3.dev0 dependency remains installed, this unconditional import fails before K3 DSpark can even serve prefix-only checkpoints because segmented_rmsnorm only exists in the kernel half of this commit. Please raise the runtime dependency floor or add a guarded fallback so the new runtime cannot be paired with a kernel that lacks the symbol.

Useful? React with 👍 / 👎.

Signed-off-by: Torchspec bot <262938024+torchspec-bot@users.noreply.github.com>
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