Skip to content

DFlash split 2: drafter module + tap APIs - #206

Open
dusterbloom wants to merge 4 commits into
panbanda:mainfrom
dusterbloom:codex/dflash-2-drafter
Open

DFlash split 2: drafter module + tap APIs#206
dusterbloom wants to merge 4 commits into
panbanda:mainfrom
dusterbloom:codex/dflash-2-drafter

Conversation

@dusterbloom

@dusterbloom dusterbloom commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Second split of the DFlash stack (from #204): the block-diffusion drafter module — drafter architecture, config parsing, safetensors loading hook, cache-crop helper, and accept_prefix tests.

⚠️ Stacking — please read

Stacked on #205 (split-1). GitHub cross-repo PRs can only target main, so until #205 merges, this diff is cumulative (it shows split-1 + split-2). Review the top commit (f515b868) only — the diff narrows to just the drafter once #205 lands.

Stack order: #205 (foundation) → this (drafter) → engine draft-verify loop → config/doctor/docs → per-request selection + streaming.

Validation

  • cargo clippy + cargo fmt --check — clean
  • cargo test -p higgs-models (drafter + accept_prefix) — pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new speculative-decoding drafter implementation with configurable settings, drafter cache management, and prefix acceptance with a bonus token.
    • Expanded public model APIs to support forwarding with tap hidden states, returning verification “tape” outputs, and replaying rollback after acceptance.
    • Added hybrid-cache accessors and utilities to back up/restore hybrid state for safer speculative flows.
  • Chores

    • Updated CI to run key checks on the macos-15 GitHub-hosted runner for improved consistency.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@dusterbloom, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 50 minutes and 30 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8720cf73-730c-4b5e-b82f-42613599b9be

📥 Commits

Reviewing files that changed from the base of the PR and between 1237cfa and b12e1ed.

📒 Files selected for processing (2)
  • crates/higgs-models/src/dflash.rs
  • crates/higgs-models/src/lib.rs
📝 Walkthrough

Walkthrough

Adds a new dflash module for speculative decoding, extends AnyCache and AnyModel with hybrid-cache DFlash helpers, and pins CI jobs to macos-15.

Changes

DFlash Speculative Decoding Drafter

Layer / File(s) Summary
DFlash config, public types, and AnyCache/AnyModel interface
crates/higgs-models/src/dflash.rs, crates/higgs-models/src/lib.rs
Defines DFlashConfig, DEFAULT_DECODE_BLOCK_SIZE, TapsTapeOutput, hybrid cache accessors, module export, and the new AnyModel DFlash dispatch methods.
DFlash neural components: MLP, Attention, DecoderLayer, DFlashDrafter
crates/higgs-models/src/dflash.rs
Implements DFlashMLP, DFlashAttention, DFlashDecoderLayer, and DFlashDrafter with tap projection, per-layer KV caches, and hidden-state output.
State backup, cache utilities, acceptance logic, and model loading
crates/higgs-models/src/dflash.rs
Adds GdnStateBackup, crop_drafter_cache, accept_prefix, and load_dflash_drafter.
Unit and integration tests
crates/higgs-models/src/dflash.rs
Covers accept_prefix, sliding-window KV eviction, and an ignored real-weight loading test.

CI Runner Pin

Layer / File(s) Summary
Pin CI jobs to macos-15
.github/workflows/ci.yml
Updates test, build, lint, msrv, and coverage jobs from macos-latest to macos-15.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested Reviewers

  • panbanda

Poem

A bunny hopped through taps and light,
With caches tucked in snug and tight.
On macOS-15 the tests now run,
And DFlash dances, quick and spun.
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main changes: the new DFlash drafter module and the added tap APIs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/higgs-models/src/dflash.rs`:
- Around line 34-53: Add rustdoc comments for the new public API surface in
DFlashConfig and DFlashDrafter::config, including the struct itself and each
public field introduced in dflash.rs. Use the existing identifiers DFlashConfig,
its fields, and DFlashDrafter::config to locate the changes, and document any
new user-facing behavior so the public config surface is covered consistently
with the Rust docs guidelines.
- Around line 457-459: In DFlash::forward, validate that the cache length
exactly matches self.layers before iterating, since zipping
self.layers.iter_mut() with cache.iter_mut() can silently skip extra decoder
layers or ignore surplus cache entries. Add an explicit length check near the
loop and return an error if the sizes differ, then keep the existing forward
pass logic unchanged once the lengths are confirmed.
- Around line 671-724: In `loads_modal_drafter_against_real_weights` and the
surrounding cache assertions, remove the clippy blockers by replacing the
`as`-based size conversion in `zeros` with a checked integer conversion,
avoiding direct indexing into `cache` by using safe accessors or pattern
matching for the two entries, and eliminating `expect()` in favor of explicit
error handling or assertions. Update the affected test helpers in `dflash.rs` so
the same symbols (`zeros`, `cache`, `load_dflash_drafter`) still drive the
checks without triggering clippy.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1067480d-8eb5-4975-aaac-6d7fceaabb3a

📥 Commits

Reviewing files that changed from the base of the PR and between 9a7437e and f515b86.

📒 Files selected for processing (4)
  • .github/workflows/ci.yml
  • crates/higgs-models/src/dflash.rs
  • crates/higgs-models/src/lib.rs
  • crates/higgs-models/src/qwen3_next.rs

Comment on lines +34 to +53
pub struct DFlashConfig {
pub hidden_size: i32,
pub num_hidden_layers: i32,
pub num_attention_heads: i32,
pub num_key_value_heads: i32,
#[serde(default = "default_head_dim")]
pub head_dim: i32,
pub intermediate_size: i32,
#[serde(default = "default_rms_norm_eps")]
pub rms_norm_eps: f32,
#[serde(default = "default_rope_theta")]
pub rope_theta: f32,
#[serde(default = "default_block_size")]
pub block_size: i32,
pub vocab_size: i32,
#[serde(default)]
pub layer_types: Option<Vec<String>>,
#[serde(default)]
pub sliding_window: Option<i32>,
dflash_config: DFlashSubConfig,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add rustdoc for the public config surface.

DFlashConfig, its public fields, and DFlashDrafter::config are new public API. As per coding guidelines, "**/*.rs: Add doc comments on public structs/fields in Rust when changing user-facing behavior".

Also applies to: 371-385

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/higgs-models/src/dflash.rs` around lines 34 - 53, Add rustdoc comments
for the new public API surface in DFlashConfig and DFlashDrafter::config,
including the struct itself and each public field introduced in dflash.rs. Use
the existing identifiers DFlashConfig, its fields, and DFlashDrafter::config to
locate the changes, and document any new user-facing behavior so the public
config surface is covered consistently with the Rust docs guidelines.

Source: Coding guidelines

Comment on lines +457 to +459
let mut h = noise.clone();
for (layer, lc) in self.layers.iter_mut().zip(cache.iter_mut()) {
h = layer.forward(&h, &target_hidden, lc, cache_offset)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Validate cache length before zipping.

A short cache silently skips decoder layers; a long cache is partially ignored.

Proposed fix
         if taps.len() != self.config.num_taps() {
             return Err(Exception::custom(format!(
                 "expected {} taps, got {}",
                 self.config.num_taps(),
                 taps.len()
             )));
         }
+
+        if cache.len() != self.layers.len() {
+            return Err(Exception::custom(format!(
+                "expected {} cache layers, got {}",
+                self.layers.len(),
+                cache.len()
+            )));
+        }
 
         // Cache offset = max cached seq length (0 on first round)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let mut h = noise.clone();
for (layer, lc) in self.layers.iter_mut().zip(cache.iter_mut()) {
h = layer.forward(&h, &target_hidden, lc, cache_offset)?;
if taps.len() != self.config.num_taps() {
return Err(Exception::custom(format!(
"expected {} taps, got {}",
self.config.num_taps(),
taps.len()
)));
}
if cache.len() != self.layers.len() {
return Err(Exception::custom(format!(
"expected {} cache layers, got {}",
self.layers.len(),
cache.len()
)));
}
let mut h = noise.clone();
for (layer, lc) in self.layers.iter_mut().zip(cache.iter_mut()) {
h = layer.forward(&h, &target_hidden, lc, cache_offset)?;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/higgs-models/src/dflash.rs` around lines 457 - 459, In
DFlash::forward, validate that the cache length exactly matches self.layers
before iterating, since zipping self.layers.iter_mut() with cache.iter_mut() can
silently skip extra decoder layers or ignore surplus cache entries. Add an
explicit length check near the loop and return an error if the sizes differ,
then keep the existing forward pass logic unchanged once the lengths are
confirmed.

Comment thread crates/higgs-models/src/dflash.rs Outdated
@dusterbloom
dusterbloom force-pushed the codex/dflash-2-drafter branch from f515b86 to 1237cfa Compare June 24, 2026 15:57
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