Skip to content

feat(lm): support Qwen3.8-Flash-Next with bounded SSD inference - #154

Open
Brooooooklyn wants to merge 1 commit into
mainfrom
codex/qwen38-flash-next-opt
Open

Brooooooklyn wants to merge 1 commit into
mainfrom
codex/qwen38-flash-next-opt

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Adds Qwen3.8-Flash-Next (qwen4_exp) to loadModel() and loadSession() for Hugging Face directories and split GGUF checkpoints. Large checkpoints can generate with a bounded resident working set and SSD reads for cold weights; GGUF quantized codes are preserved during import.

  • Calculate memory admission from tensor sizes, device RAM and live headroom; retain projections and expert slots within that budget and reuse a bounded prepared SSD cache.
  • Batch prefill projections and use hardware-gated packed expert, rotary and GDN kernels while preserving required BF16 rounding and fallback paths.
  • Add paged scheduling, isolated request state, warm continuation, cancellation, opt-in native MTP, and bounded image input with matching auxiliary weights.
  • Preserve independent array-copy ownership and MLX transformations, and make persistence fixtures independent of the host filesystem's free-space reserve.

The MLX submodule advances to published commit 6908f3fd2 for transposed K-quant expert gathers on NAX. Small reference fixtures, regeneration scripts, a guarded end-to-end smoke, and a public-API benchmark accompany the runtime.

Validation on M5 Max / 128 GiB:

  • Core release suite: 3,537 passed, 122 ignored; three existing debug-assertion tripwires excluded because release disables those assertions. Production cache limits remain unchanged.
  • Paged-attention smoke: 84 passed.
  • Loader/session tests: 59 passed.
  • Type checking, lint, Rust formatting and strict Clippy across all targets passed.
  • Regenerated declarations and all 85 native exports verified. Full UD-Q4_K_XL GGUF smoke passed (11 turn checks plus cancellation/reset), including greedy AR/MTP parity, concurrent owners, streaming continuation and images. Peak physical footprint: 32.2 GiB with a 32 GiB weight ceiling and 48 GiB guard.

Paged inference currently requires macOS Metal. MTP is opt-in; audio, video and image-bearing MTP are unsupported. Full BF16 generation and real-model contexts beyond 2,048 tokens remain unvalidated. The documented 1,320 prefill tok/s result is from the pre-cleanup build and its specified workload; this PR does not claim 1,500 tok/s or a matched mlx.fast comparison.


Note

High Risk
Large new inference path touching scheduling, SSD weight residency, paged KV, and cancellation on a dedicated model thread; incorrect cache or slot lifetimes could affect stability or memory under load.

Overview
Adds Qwen3.8-Flash-Next (qwen4_exp) end-to-end: a new SSD-oriented model family with bounded resident weights, GGUF/HF loading, optional auxiliary checkpoints for MTP/vision metadata, and public Qwen4ExpModel APIs for paged chat sessions (sync/stream, tool turns), async cache reset, scheduler telemetry, and residency introspection.

The Rust runtime introduces a full qwen4_exp stack—MoE with expert slotting and batched prefill, sparse/window attention with paged KV, linear (GDN) layers, PLE, native MTP draft paths, and memory admission tied to device headroom—plus loader/registry and README coverage as an inference-only SSD model type.

The hybrid scheduler gains an opt-in scheduler_wired_bytes hook so scheduled turns can run under a WiredLimitContext during generation. MxArray::deep_copy is fixed so sliced copies keep zero Metal buffer offset after source handles drop.

Reviewed by Cursor Bugbot for commit 51bb619. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Sep 15, 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

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4f7544c1-a6fd-4074-b5e2-f0df55b1aa16

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

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-15T07:43:20.274296Z 51bb619 PR opened
ℹ️ 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.

@cursor

cursor Bot commented Sep 15, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_ab150b88-d43f-4669-bcbe-3cfd47106e5b)

@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: 51bb619914

ℹ️ 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".

let cache_limit = CACHE_BYTES;
let mut s = Self {
tensors: HashMap::new(),
gguf: path.extension().is_some_and(|e| e == "gguf"),

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 Normalize the GGUF extension before dispatch

For a mixed-case filename such as model.GGUF, the public detector treats the path as GGUF because packages/lm/src/model-detection.ts lowercases the extension, but this case-sensitive comparison sets gguf to false. The native loader then calls index_safe and treats the GGUF file as a SafeTensors directory, so a model that was successfully detected as qwen4_exp cannot load. Apply the same case-insensitive extension check here.

Useful? React with 👍 / 👎.

Comment on lines +413 to +414
pub fn max_concurrent_sequences(&self) -> u32 {
crate::engine::hybrid_scheduler::scheduler_max_num_seqs_for(4) as u32

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 Report one sequence when forced serial

When MLX_SERVE_FORCE_SERIAL=1, the scheduler executes Qwen4 turns exclusively, but this method still reports up to four concurrent sequences. packages/server/src/registry.ts uses this value to select and size its counting semaphore, so several requests bypass the server's exclusive FIFO and no longer count against its waiting-queue limit even though they only queue serially in native code. Match the other hybrid models by returning 1 while forced-serial mode is active.

Useful? React with 👍 / 👎.

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