Skip to content

feat(kv-int8): --max-context caps the window; YaRN above the native window - #358

Merged
Brooooooklyn merged 1 commit into
mainfrom
feat/kv-int8-s22-max-context
Nov 12, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
feat/kv-int8-s22-max-context

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Contributor

Stage S22 of the Splash int8 KV alignment (stack #344). Base: FN1 (#357).

mlx serve and mlx agent take --max-context N, as Splash 1.6 does. Past the native window, the target RoPE uses static YaRN.

--max-context N  (K = 1024, M = 1,000,000; 1..=1,010,000; unset = auto)
  N ≤ native (262,144) → caps every window; RoPE unchanged (bit for bit)
  N > native           → YaRN factor N/native on the target RoPE; the draft keeps its own
  N > default-lane plan window → the load fails (Splash ServingRuntime::start text)
families: qwen3_5, qwen3_5_moe, qwen4_exp; others refuse the option

Splash rules ported

  • YaRN math as Splash rotaryInverseFrequencies / attentionFactor: beta_fast 32, beta_slow 1, rotated q/k dims × 0.1·ln(f)+1. YaRN is on only where native is 262,144.
  • The plan prices the served window. Flash Next's KV allowance is N.
  • The default lane (DFlash2 with a draft, else the pool, else the flat lane) refuses an N above its plan window. The other lanes clamp to N.
  • A checkpoint whose RoPE is already scaled is refused (rope_type / GGUF rope.scaling.type).
  • The cold-tier key gets rope yarn <%.17g> <native> only with YaRN. The saved config.json never carries the factor. Training refuses a YaRN load.
  • Deleted: the four draft-window caps and the draft's max_position_embeddings accessors (Splash caps by the target only).

Tests

Not in this PR

  • No live run past 262,144 tokens. The live check (100K / 400K on qwen3.8-27b, and T=0 output unchanged with no flag) is not run.
  • Splash's prefill attentionPairs cap is not ported. Fused mlx_qk_norm_rope steps aside under YaRN, so decode past native is slower.
  • YaRN angles match Splash within f32 tolerance, not bit for bit (MLX inverts the periods on the GPU).

🤖 Generated with Claude Code

@Brooooooklyn
Brooooooklyn added this pull request to stack #344 November 10, 2026 11:28
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 333d5c01-0128-4955-801b-9650d215386e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T15:51:44.237991Z 65bdcb8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: cd34d9a182

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s22-max-context branch from cd34d9a to a0ff878 Compare November 10, 2026 11:56
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s22-max-context branch from a0ff878 to a1287cb Compare November 12, 2026 13:41
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-fn1-flash-next-plan branch from b43b26a to 6bf14f1 Compare November 12, 2026 13:41
@Brooooooklyn
Brooooooklyn removed this pull request from stack #344 November 12, 2026 15:43
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-fn1-flash-next-plan branch from 6bf14f1 to b3f945c Compare November 12, 2026 15:49
Base automatically changed from feat/kv-int8-fn1-flash-next-plan to main November 12, 2026 15:49
…indow

mlx serve and mlx agent take --max-context N (K = 1024, M = 1,000,000,
1 to 1,010,000, auto = unset), parsed like Splash parse_max_context. The
loader hands it to qwen3_5, qwen3_5_moe and qwen4_exp loads as
maxContextTokens; other families refuse it.

Splash rules:
- N at or below the native window only caps: every published window,
  preflight and scheduled turn holds at most N. The trained window stays
  native. Flat qwen3_5 / MoE chat turns hold it natively too.
- N past the native window turns on static YaRN on the target RoPE
  (servedFor): factor N / native, beta_fast 32, beta_slow 1, rotated q/k
  dims times 0.1 ln(factor) + 1 (rotaryInverseFrequencies,
  attentionFactor). Image rows and the Flash Next indexer take the same
  table. The DFlash2 draft keeps its own RoPE.
- YaRN only where the native window is 262,144; up to 1,010,000.
- The plan prices the served window; Flash Next's KV allowance is N.
- N above the default turn's lane fails the load with Splash's
  ServingRuntime::start text. The default lane is DFlash2 with a draft,
  else the pool, else the flat lane of a load with neither; the other
  lanes are clamped to N. N past native with no plan (device memory
  unreadable) fails too.
- A checkpoint whose RoPE is already scaled is refused (rope_type, else
  type, not default; a GGUF rope.scaling.type other than none).
- The cold-tier key gets "rope yarn <%.17g> <native>" only with YaRN; the
  saved config.json never carries the factor. Training refuses a YaRN load.
- /v1/models shows N until the load-free estimate lands; a refused
  estimate leaves the trained window.

Deleted: the four draft-window caps (load plan, speculative_window,
constrain_dflash2_context_params, DFlash2Model::propose) and the draft's
max_position_embeddings accessors. Splash caps by the target only.

Fused mlx_qk_norm_rope and the source QK path step aside under YaRN.
Below the native window the RoPE is today's kernel bit for bit.

Tests: 400K gives factor 1.5625, attention factor 0x3f85b665 and Splash's
-O3 table bit for bit; a 100K cap publishes 102,400 on both lanes while
the plan prices 262,144; 400K plans 409,600; on a flat load whose
4 GiB plan holds 45,056 rows, 40,000 publishes 40,000 and 45,057 is
refused. 31 Rust and 15 TS named
mutations, each red when on and green when off. No model was loaded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s22-max-context branch from a1287cb to 65bdcb8 Compare November 12, 2026 15:49
@Brooooooklyn
Brooooooklyn merged commit fb84cad into main Nov 12, 2026
@Brooooooklyn
Brooooooklyn deleted the feat/kv-int8-s22-max-context branch November 12, 2026 15:49
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
…ees it (#359)

Stage S21 of the Splash int8 KV alignment (stack #344). Base: S22
(#358).

The model holds one wired residency for its life, as Splash 1.6
`metal::Residency` does. `--idle-release` frees the weights after an
idle time.

```
load ──► lease(max_rec − pool sets) ─┬─ drive loop marks the clock before GPU work
                                     ├─ beat thread: requestResidency every 500 ms
                                     │    (MLX sets + one pool set per LayerKVPool, not on a queue)
                                     └─ no command for --idle-release (default 10m, off = never)
                                          ├─ Rust: lease ends, pool sets end, residency_kick
                                          └─ TS:   chat model unloaded, dispose() frees weights
next request ──► lazy load again (restores += 1)
POST /v1/memory/release ──► 200 | 409 engine_busy | 503 server_shutdown  (Splash fieldless body rules)
```

## Changes
- qwen3_5, qwen3_5_moe and qwen4_exp: one lease in
`HybridScheduler::drive` covers every lane, DFlash2 included. The 14
per-turn `WiredLimitContext` sites and `scheduler_wired_bytes` are
deleted.
- `mlx-paged-attn`: `residency.rs` (one process clock, 500 ms beat, pool
residency set) and the `residency_kick` kernel.
- The addon sets `MLX_METAL_RESIDENCY_REFRESH_INTERVAL_MS=500` when
unset. New napi: `setResidencyKeepAlive`, `dispose()` on the three model
classes.
- `mlx serve` / `mlx agent`: `--idle-release`. `/health` gains `weights`
and `work.releasePending`. The 30 s cache clear stays.
- Flash Next: banks stay non-volatile between turns (Splash
`ExpertStore` has no timed purge). `SLOT_RECLAIM_FALLBACK`, the 30 s
purge, bank suspend/activate and slow-source detection are deleted.

## Gaps vs Splash
- The release unloads the whole model. KV, prefix cache, sessions and
state go too. Restore is a full load with no governor (S11).
- MLX's own sets stay attached to its queues, so wiring uses the lease
plus the pool sets.
- Training drops the lease. Rerank, ASR and TTS models are not released.
`--allow-idle-sleep` is not ported.

## Tests
- 10 new Rust tests, 3 new and 8 changed TS test files. 18 named
mutations, each red when on and green when off.
- `cargo fmt --check`, `cargo clippy --all-targets -D warnings`, `yarn
typecheck`, `vp lint`, `vp fmt --check`: clean.
- Rust (`RUST_TEST_THREADS=1`): stream, engine::, qwen3_5, qwen4_exp,
memory_plan, model_thread, cache_limit, grpo::engine, qwen3_asr,
qwen3::model: all pass. `mlx-paged-attn --lib`: 200 pass.
- TS: `__test__/server`, `__test__/server/host`, cli serve / agent-args
/ agent-update / launch-claude / delegate: 1725 pass.

## Not in this PR
- No live run. To check on qwen3.8-27b + dflash2 with `--idle-release
2m`: wired bytes stay up between turns, release and restore log lines,
`/health`, 409 while streaming, and an A/B of the 500 ms refresh against
0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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