Skip to content

Add native Flint model, strict checkpoint loading and tool protocol - #322

Merged
Gajesh2007 merged 4 commits into
mainfrom
codex/flint-native-support-20261021
Oct 22, 2026
Merged

Gajesh2007 merged 4 commits into
mainfrom
codex/flint-native-support-20261021

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 21, 2026 •

Copy link
Copy Markdown

Recursive's Flint checkpoint currently has no native Swift model or tool dialect in this SDK. This adds exact flint registration, strict BF16/official mixed-bit INT4 loading, hybrid full/sliding attention with learned sinks, and schema-aware streaming tool parsing. d-inference consumes this native implementation through its production CBv2 adapter.

Update — paged sliding-mask reuse (48bda794)

Within one paged prefill row/call, consecutive eligible query blocks with equal query and visible-key counts have byte-identical Boolean sliding masks: each block's first query sits (visible keys − queries) positions after its first visible key. PagedLayerCache now keeps only the last such mask locally and passes it as the same .array SDPA mask. Span, bidirectional, softcap and Qwen4-indexer paths, cold blocks, one-query tails, 128-query blocking, arithmetic order, gather-before-write and page ownership are unchanged.

flowchart LR
  subgraph Before
    A1["Each 128-query block"] --> B1["Build causal+window Bool mask"] --> C1["SDPA .array(mask)"]
  end
  subgraph After
    A2["Each 128-query block"] --> D2{"Same counts as last eligible block?"}
    D2 -->|"yes"| E2["Reuse identical mask"] --> C2["SDPA .array(mask)"]
    D2 -->|"no / ineligible"| B2["Build mask"] --> C2
  end
  classDef input fill:#dbeafe,stroke:#1d4ed8,color:#172554
  classDef gate fill:#fef3c7,stroke:#b45309,color:#451a03
  classDef native fill:#dcfce7,stroke:#15803d,color:#052e16
  class A1,A2 input
  class D2 gate
  class B1,B2,C1,C2,E2 native
Loading
Check Result
CBv2PagedSlidingMaskReuseTests (new): exact BF16/FP32 output and retained-KV bytes vs an independent per-block rebuild oracle; cold/wrapped histories incl. a prefill gather across the physical ring seam; partial and one-query tails; decode; reordered packed rows; reservation cleanup Passed
With CBv2PagedQueryBlocking, CBv2PagedQueryBlockBounds, CBv2PagedPackedSpan, CBv2AttentionSinkDtype, FlintPrefixTests, FlintTests (MLX_ENABLE_TF32=0, query block 128) 41 tests passed
Paged A/B/B/A through the provider release binary, official Flint INT4, fixed 4K prompt, 2048-token stripe, resolved backend paged 5,409 / 5,422 → 5,463 / 5,457 tok/s median (~+0.8%, non-overlapping ranges); 1K ~+0.3% (within noise)

Independent static review found the exactness argument sound; its ring-seam coverage and write-validation suggestions are included. The source-count estimate (4K mask builds 1,568 → 658) is not separately measured.

Earlier changes

Before — behavior and code flow

flowchart LR
  A["Flint checkpoint or tool stream"] --> B{"SDK registry / parser"}
  B --> C["Unsupported architecture / dialect"]
  classDef input fill:#dbeafe,stroke:#1d4ed8,color:#172554
  classDef blocked fill:#fee2e2,stroke:#b91c1c,color:#450a0a
  class A,B input
  class C blocked
Loading

After — behavior and code flow

flowchart LR
  A["Pinned Flint files"] --> B{"Strict configuration and tensors"}
  B --> C["Native decoder + CBv2 KV"]
  C --> D["Prefill final-row head / normal decode"]
  E["Flint tool stream"] --> F{"Schema-aware frame parser"}
  F --> G["Complete typed calls"]
  F --> H["Malformed frame rejected"]
  classDef input fill:#dbeafe,stroke:#1d4ed8,color:#172554
  classDef native fill:#dcfce7,stroke:#15803d,color:#052e16
  classDef blocked fill:#fee2e2,stroke:#b91c1c,color:#450a0a
  class A,B,E,F input
  class C,D,G native
  class H blocked
Loading

The CBv2 token-constraint mode now includes auto, allowing the provider to apply native Flint reasoning/tool boundaries without requiring a tool call. The provider owns the bounded grammar and HTTP tests in d-inference draft #1535.

The prompt-output optimization reuses the existing GPTOSS/Gemma CBv2 contract: every prompt token and KV write remains; unused vocabulary projections are omitted. FP32 routing probabilities, weighted reduction and head inputs are preserved. No TF32, activation quantization, MTP, or security/admission policy change is introduced. Packed prefill remains disabled.

Validation on physical M5 Max / 128 GiB, macOS 27.0, Swift 6.4, source-matched Metal library:

  • swift build --build-tests --scratch-path <owned-sdk-build> succeeded.
  • MLX_ENABLE_TF32=0 swift test --skip-build --scratch-path <owned-sdk-build> --filter 'FlintTests|FlintToolTests|FlintPrefixTests|ToolCallParserIntegrationTests': 19 native/parser tests (including both paged and contiguous restore cases) plus 47 server parser integration tests passed.
  • Independent NumPy full-model oracle, chunk sizes 1/127/512/513/514, window wrap, heterogeneous row removal, strict malformed checkpoint rejection/retry, prefill KV equality and continuation parity.
  • Schema-aware tool values, Unicode and all split boundaries, bounded scanner state, malformed/incomplete fail-closed parsing.
  • Physical Metal capture of official INT4 layers 0–2 and output head confirmed executed dense affine_qmm_t_nax and routed affine_gather_qmm_rhs_nax_nt BF16-activation kernels; the FP32 output head used its portable fallback. This proves those dispatches, not a whole-model NAX speedup.
  • scripts/check-unit-test-files.sh, fork-diff coverage check, Swift formatting and git diff --check passed. Dedicated refactor subagent reviewed the implementation; regressions were fixed and tests rerun.

The tested artifact is RecursiveSI/flint-int4@3b93f9053b530488405ae9fca51d4900d6ce21f0: group-64 affine INT4 projections/experts, INT8 embeddings, native BF16 KV; not NVFP4. All 11 serving files matched published SHA256 values. No weights are committed.

Credits: this is an attributed Swift adaptation of Prince Canuma's MIT mlx-vlm Flint implementation (#2565, reviewed 1a6ebd06459be3b18cb1c7922305c9e362612c62) and Recursive's Apache-2.0 rec conventions (e53663b262af4cb1ca498e596ca8b1a2d79e0800). The independent NumPy oracle also credits Prince's reference tests. Exact reuse/differences and complete licenses are in ThirdPartyNotices/Flint.md.

Draft limits: text-only model; raw string arguments cannot reliably contain the published protocol's literal </arg_value> terminator. Full-release BF16/reference quality, maximum-context/RAM tiers, reduced-precision KV and MTP are unqualified. Preview access was unavailable, so preview acceptance is not inherited. d-inference performance and broader HTTP qualification are being reported separately; the 2× M3 Ultra prefill and 400 tok/s decode targets are not claimed as achieved. This PR does not publish a model, activate a catalog, or release a provider.

jonathan308 and others added 3 commits October 21, 2026 13:46
Within one paged prefill row/call, consecutive eligible query blocks with the
same query and visible-key counts have byte-identical Boolean sliding masks:
each block's first query sits (visible keys - queries) positions after its
first visible key. Retain only the last such mask locally and pass it as the
same .array SDPA mask, instead of rebuilding it per block. Span, bidirectional,
softcap and Qwen4-indexer paths, cold blocks, one-query tails, arithmetic,
128-query blocking, gather-before-write and page ownership are unchanged.

New tests compare exact BF16/FP32 outputs and retained KV against an
independent per-block rebuild oracle across cold/wrapped histories (including
a prefill gather across the physical ring seam), partial tails, decode and
reordered packed rows. Paged A/B through the provider measured about +0.8%
at 4K fixed-prompt prefill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in main through #323, including the mlx-swift main pin (67dc7528),
GLM-5.3-Flash native support and Nemotron Super kernels. Resolve the
tool-call format conflicts by keeping both the Flint and GLM5 parsers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 marked this pull request as ready for review October 22, 2026 00:09
@Gajesh2007
Gajesh2007 merged commit 889fe3c into main Oct 22, 2026
6 checks passed
@Gajesh2007
Gajesh2007 deleted the codex/flint-native-support-20261021 branch October 22, 2026 00:39
Gajesh2007 added a commit that referenced this pull request Oct 22, 2026
Refresh before review: d-inference master pins SDK main 889fe3c, which adds
#322 (Flint tool protocol) and #326-#330. Resolved ToolCallProcessor.swift by
keeping Flint's tool protocol handling alongside the streamed tool_calls
fragments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 22, 2026
Brings #322 (Flint), #324, #326-#330 (CBv2 paged/MTP/SDPA, GPT-OSS), #325 and the
Nemotron Super fused MTP verify window: SDK main up to the commit d-inference
master pins (889fe3c). Main's later #331/#332 are left out until the provider
adopts #332's streamed tool-call type. Package.swift pins the cluster
mlx-swift 9fe34405 instead of main's 67dc7528; that was the only conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
javiech1 pushed a commit to javiech1/mlx-swift-lm that referenced this pull request Oct 24, 2026
* Add support for Qwen3-VL-MoE models.
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.

2 participants