Repository navigation
Expose Falcon-H1 encoder surface at @_spi(FalconH1Encoder) - #596
Merged
Merged
Conversation
Mirrors the Gemma 3/4 encoder exposures (ml-explore#387, and the Gemma 4 follow-up) for Falcon-H1, so client code can run the decoder stack over an embedding it built itself rather than over a single token id. The motivating case is a DualAR TTS model (Audio8 TTS Preview 0.1b, model_type `arktts`, `slow_backbone: falcon_h1`) whose slow-stack input is a text embedding summed with ten codec-codebook embeddings. Such a client never has one token id to look up, so `FalconH1ModelInner.callAsFunction(_:mask:cache:)` is unreachable for it, and today the only options are to fork the file or re-implement the mask setup and layer loop against internal details. Exposed at @_spi(FalconH1Encoder) scope, keeping this off the advertised public API of MLXLLM while making it usable outside the module: * FalconH1Configuration.hiddenSize / .numHiddenLayers / .rmsNormEps / .embeddingMultiplier * FalconH1DecoderLayer and its callAsFunction * FalconH1ModelInner.init, .embedTokens, .layers, .finalLayerNorm * FalconH1ModelInner.callAsFunction(inputsEmbeds:cache:) — new * FalconH1ModelInner.callAsFunction(_:mask:cache:) — was internal `callAsFunction(inputsEmbeds:cache:)` is the seam; the token-id overload now delegates to it, so the two paths cannot drift. No behaviour changes for existing callers: FalconH1Model still embeds, runs the stack and applies the head exactly as before. `FalconH1ModelInner.init` is exposed because constructing `FalconH1Model` is not an equivalent way in: the wrapper adds an `lm_head` whenever `tie_word_embeddings` is false, which is the decoded default. A client bringing its own head does not want that module and would otherwise have to account for it when matching module keys against a checkpoint. `FalconH1Model.model` and the mask helpers (`createSSMMask`, `createAttentionMask`) were already public, and none of the layer's stored property types are `private`, so unlike the Gemma 4 change nothing else had to widen. FalconH1EncoderAccessTests proves sufficiency the way the Gemma access tests do: it drives the stack using ONLY the exposed surface, importing MLXLLM without @testable and opting in via @_spi(FalconH1Encoder). It checks shape, determinism, that the seam agrees with the token path, that the layer stack can be driven a layer at a time to tap every hidden state, and that the stack actually transforms its input — the last so the suite cannot pass on a seam that returns its argument or runs zero layers. One test earns its place beyond access checking. `sanitize()` folds `embedding_multiplier` into `embed_tokens.weight`, which is right when the token lookup is the only thing entering the stack but is a live trap for a composite- embedding client: fold it and add unscaled contributions, and the lookup half is scaled while the rest is not. Measured against the PyTorch reference for the model above, that is 77% relative error on the embedding and 38% on the final hidden state — while still producing plausible audio of the right length, so listening does not catch it. testCompositeEmbeddingMultiplierEquivalence pins `(raw + other) * m == folded + other * m` and asserts the unscaled-remainder variant is observably different, both at the embedding and after the stack, so the wrong form cannot quietly become the expected one. Runs on a tiny randomly-initialized model; no weights are downloaded. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xocialize
force-pushed
the
falcon-h1-encoder-spi
branch
from
August 30, 2026 19:59
1843f6c to
ac28e3b
Compare
xocialize
added a commit
to xocialize/mlx-engine-swift
that referenced
this pull request
Aug 30, 2026
Second Audio8 checkpoint, same package repo. Upstream published a compact preview carrying the SAME model_type (arktts) but slow_backbone: falcon_h1 — a Falcon-H1 hybrid slow stack replacing the pure-attention one, plus a compact semantic head. ~170M LM; fast AR, prompt layout, sampling and codec unchanged. Avail 🧪 deliberately: the weights are published (mlx-community/Audio8-TTS-Preview-0.1b-bf16) but the package branch is unmerged and depends on an unmerged upstream PR (ml-explore/mlx-swift-lm#596, the @_spi(FalconH1Encoder) inputsEmbeds seam). Val 🟡: CLI gates only, no in-app run. Tracked count 68 -> 69; published stays 47, since this row is not published yet. The lint does not check either number, so they are updated by hand here rather than discovered later as drift. Two things in the row worth surfacing outside it: C7 is genuinely TWO weight layers here — the LM carries a revenue-capped community licence (commercial use only below US$2M annual revenue) while the bundled codec is Apache-2.0, byte-identical to the 0.6b's and converted from that Apache-2.0 repo. The manifest declares the stricter one. The LicenseRef is NOT on permissiveAllowlist: it is declared package-locally so the engine records a LicenseAdvisory rather than admitting it silently. Allowlisting is prepared on branch audio8-community-license and left unmerged on purpose — it changes what .permissiveOnly admits fleet-wide and wants its own contract bump and tag, which an audio port should not land as a side effect. And a gate that had stopped checking anything: the --stream envelope bound was hardcoded to the 0.6b's 4.2 GB, so against the new package it asserted a number that package does not declare, and passed. It now reads peakActivationBytes from the package under test. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xocialize
added a commit
to xocialize/mlx-audio8-tts-swift
that referenced
this pull request
Aug 30, 2026
Wraps Audio8-TTS-Preview-0.1b as a conformant ModelPackage alongside the 0.6b's Audio8Package, and extracts the shared behaviour so there is only one copy of it. REFACTOR FIRST. The two checkpoints differ ONLY in their manifest — licence, footprints, provenance, surface summary — and in which repo their configuration defaults to. Everything else (conditioning, AR rollout, cancellation cadence, metaData plane, windowed streaming decode) is identical, and Audio8TTS already dispatches the architectural difference internally from slow_backbone in config.json. So load/unload/run/runStream/prepared move to Audio8Runtime<C> and both packages become thin. Duplicating ~200 lines of inference glue is exactly the shape that drifts — a streaming twin quietly conditioning differently from its batch sibling is the failure this file's own comments already warn about, and that risk doubles with every copy. All seven pre-existing 0.6b gates re-run green after the extraction (s0/s1/s2/s5/ validate/cancel/stream), and the offline suite is 18/18 unchanged. SEPARATE CONFIGURATION TYPE, on purpose. Audio8MiniConfiguration duplicates ~60 lines of Codable boilerplate rather than sharing Audio8Configuration, for one reason: the DEFAULT repo. A package that silently loads a different checkpoint than its manifest declares is a worse failure than a little duplication. A test pins it. C7 IS GENUINELY TWO LAYERS. The LM carries the Audio8 Community Licence (revenue-capped: commercial use permitted only below US$2M annual revenue); the bundled codec is Apache-2.0, byte-identical to the 0.6b's and converted from that Apache-2.0 repo. The manifest declares the stricter of the two — a consumer cleared for the LM is cleared for both. The LicenseRef is declared via a local extension and is NOT on permissiveAllowlist, so the engine records a LicenseAdvisory rather than admitting it silently (enforcement is .advisory since contract 1.28.0, so it classifies rather than blocks — and a revenue cap is exactly what an app should be showing users). Engine-side allowlisting is prepared on mlx-engine-swift@audio8-community-license and left unmerged deliberately: it changes what .permissiveOnly admits fleet-wide and wants its own contract bump and tag. MEASURED, through this package's own lifecycle — never estimated: resident floor 1611 MB -> declared 1.81 GB transient 3711 MB -> declared 4.40 GB Envelope is flat in length (3457/3457/3458 MB at 64/128/234 frames), for the same reason the 0.6b's is: they share the windowed decode. HONEST LIMIT recorded in both the manifest doc comment and MEASUREMENTS.md — the sweep requests up to 512 frames but this checkpoint hits EOS at 234 on the sweep text, so flatness rests on 64->234 measured plus the shared mechanism the 0.6b verified to 1035, not on a 512-frame measurement here. Kept visible because the 0.6b's declaration was revised upward three times for exactly the sample-never-reaches-the-cap reason. Note the resident saving (34%) is far smaller than the 3.5x LM shrink suggests, and the transient is slightly HIGHER than the 0.6b's — the unchanged codec dominates both axes. Anyone picking this for a memory budget should size against 1.6 GB. SPECIALTY STRENGTH IS NOT COPIED. voiceClone is declared at 0.8 against the 0.6b's 1.0: strength is a selection signal, and this checkpoint clones measurably less faithfully (Seed-TTS SIM 56.7/68.2 vs 63.2/73.1). Copying the sibling's weight would tell a selector the two are interchangeable for the one job they are picked for. A test pins the inequality. TESTS ASSERT WHAT IS TRUE, not what the sibling asserts. Copying testLicenseIsPermissiveOnBothLayers would have been a passing test asserting a falsehood about a revenue-capped licence, and the 0.6b's "resident floor below the weight bytes — was it measured?" threshold would pass this package vacuously since its floor is ~800 MB lower. Both are rewritten against this checkpoint's actual numbers. 31/31 green (13 new). GATE FIX carried along: --stream's envelope bound was hardcoded to the 0.6b's 4.2 GB, so against this package it asserted a number the package does not declare — and passed. That is how a gate stops checking anything. It now reads peakActivationBytes from the package under test. The live gates also pick their package from the checkpoint's own config.json rather than from a flag nobody would remember to pass. NEW DEPENDENCY: mlx-swift-lm, for the Falcon-H1 layers — the same dependency mlx-gepard-swift already carries in this area, so this is convention rather than an outlier. TEMPORARILY pinned to the fork branch carrying ml-explore/mlx-swift-lm#596, which adds the @_spi(FalconH1Encoder) inputsEmbeds seam: arktts feeds the slow stack a COMPOSITE embedding and can never enter through the token-id path. Flip the pin to upstream when that merges; nothing else changes. Live gates green: validate (load 0.25 s, RTF 0.46, unload -> MLX active 0 / cache 0), cancel (CancellationError at 1.51 s), stream (byte-identical aggregate, first audio 4.24 s ahead), s5 (bit-identical windowed decode at chunk >= 48). KNOWN LIMITATION (AB-L-0076): no token-exact gate exists for the GPU rollout, and cannot with a CPU oracle — the codec's VQ encode is not code-exact across devices, so the reference conditioning itself differs. Python-MLX on GPU scores 7.76% against the CPU oracle; this port scores 12.06%. --s2gen therefore checks length and audio level and reports agreement as information, not as pass/fail. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
xocialize
added a commit
to xocialize/mlx-engine-swift
that referenced
this pull request
Aug 31, 2026
…-D-0055) Two corrections to the row, both because it described a pending state that has since resolved. LICENCE. The row said the LicenseRef was "NOT yet" on permissiveAllowlist with the engine-side change "prepared ... and deliberately NOT merged" — which reads as pending. It is now a DECISION (AB-D-0055): the LicenseRef stays package-local so the engine records a LicenseAdvisory rather than admitting silently, because that advisory is the point — a US$2M commercial cap is what a consuming app should show its users, and allowlisting would remove a true warning while buying no capability (nothing is gated; enforcement is .advisory since 1.28.0). The row now also carries the counter-argument, so it is not re-litigated from scratch: the fleet DOES allowlist ltx2Community, the same source-available-with-a-revenue-gate shape, which even carries a non-compete this licence lacks. What decided it is the threshold — US$2M against US$10M, 5x lower, low enough to bind a real business rather than only a large one. The branch stays parked so reversing costs a rebase, not a rewrite, and the row says not to merge it without revisiting the decision. MERGE STATE. The package branch has merged to mlx-audio8-tts-swift main, and the Python rung (Neywa-Labs/mlx-audio#933) merged upstream. Avail stays 🧪 for reasons that are now different and worth stating precisely: the package is merged but not TAGGED, and main still carries a temporary fork pin to xocialize/mlx-swift-lm@falcon-h1-encoder-spi until ml-explore/mlx-swift-lm#596 merges — so it is not yet consumable from a version pin. mlx-audio#933 is likewise merged but not in a tagged release (latest v0.5.0 predates it). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
davidkoski
approved these changes
Aug 31, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Change looks good, thanks!
djandrewgibbons
pushed a commit
to djandrewgibbons/mlx-swift-lm
that referenced
this pull request
Sep 1, 2026
…e#596) Mirrors the Gemma 3/4 encoder exposures (ml-explore#387, and the Gemma 4 follow-up) for Falcon-H1, so client code can run the decoder stack over an embedding it built itself rather than over a single token id. The motivating case is a DualAR TTS model (Audio8 TTS Preview 0.1b, model_type `arktts`, `slow_backbone: falcon_h1`) whose slow-stack input is a text embedding summed with ten codec-codebook embeddings. Such a client never has one token id to look up, so `FalconH1ModelInner.callAsFunction(_:mask:cache:)` is unreachable for it, and today the only options are to fork the file or re-implement the mask setup and layer loop against internal details. Exposed at @_spi(FalconH1Encoder) scope, keeping this off the advertised public API of MLXLLM while making it usable outside the module: * FalconH1Configuration.hiddenSize / .numHiddenLayers / .rmsNormEps / .embeddingMultiplier * FalconH1DecoderLayer and its callAsFunction * FalconH1ModelInner.init, .embedTokens, .layers, .finalLayerNorm * FalconH1ModelInner.callAsFunction(inputsEmbeds:cache:) — new * FalconH1ModelInner.callAsFunction(_:mask:cache:) — was internal `callAsFunction(inputsEmbeds:cache:)` is the seam; the token-id overload now delegates to it, so the two paths cannot drift. No behaviour changes for existing callers: FalconH1Model still embeds, runs the stack and applies the head exactly as before. `FalconH1ModelInner.init` is exposed because constructing `FalconH1Model` is not an equivalent way in: the wrapper adds an `lm_head` whenever `tie_word_embeddings` is false, which is the decoded default. A client bringing its own head does not want that module and would otherwise have to account for it when matching module keys against a checkpoint. `FalconH1Model.model` and the mask helpers (`createSSMMask`, `createAttentionMask`) were already public, and none of the layer's stored property types are `private`, so unlike the Gemma 4 change nothing else had to widen. FalconH1EncoderAccessTests proves sufficiency the way the Gemma access tests do: it drives the stack using ONLY the exposed surface, importing MLXLLM without @testable and opting in via @_spi(FalconH1Encoder). It checks shape, determinism, that the seam agrees with the token path, that the layer stack can be driven a layer at a time to tap every hidden state, and that the stack actually transforms its input — the last so the suite cannot pass on a seam that returns its argument or runs zero layers. One test earns its place beyond access checking. `sanitize()` folds `embedding_multiplier` into `embed_tokens.weight`, which is right when the token lookup is the only thing entering the stack but is a live trap for a composite- embedding client: fold it and add unscaled contributions, and the lookup half is scaled while the rest is not. Measured against the PyTorch reference for the model above, that is 77% relative error on the embedding and 38% on the final hidden state — while still producing plausible audio of the right length, so listening does not catch it. testCompositeEmbeddingMultiplierEquivalence pins `(raw + other) * m == folded + other * m` and asserts the unscaled-remainder variant is observably different, both at the embedding and after the stack, so the wrong form cannot quietly become the expected one. Runs on a tiny randomly-initialized model; no weights are downloaded. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
xocialize
added a commit
to xocialize/mlx-audio8-tts-swift
that referenced
this pull request
Oct 1, 2026
…ken-exact with TF32 off mlx-swift-lm 3.32.3 ships ml-explore/mlx-swift-lm#596, so the fork-branch pin becomes "3.32.3"..<"3.33.0". FalconH1.swift/SSM.swift are byte-identical to the fork; CPU gates (s0/s1/s2) are byte-identical and every GPU gate passes on 0.32.3. --s2gen: the GPU-vs-CPU divergence it blamed on cross-device VQ encode was TF32 (fp32 LM). With MLX_ENABLE_TF32=0, set at entry for this mode, the rollout is 107/107 frames, 100% token-exact on mlx-swift 0.31.6 and 0.32.3, so the gate now checks exact length and 100% agreement. MEASUREMENTS.md corrected. Production (bf16 LM) is unaffected by TF32. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirrors the Gemma 3/4 encoder exposures (#387 and the Gemma 4 follow-up) for Falcon-H1, so client code can run the decoder stack over an embedding it built itself rather than over a single token id.
Motivation
The motivating case is a DualAR TTS model — Audio8 TTS Preview 0.1b,
model_type: arktts,slow_backbone: falcon_h1— whose slow-stack input is a text embedding summed with ten codec-codebook embeddings. Such a client never has a single token id to look up, soFalconH1ModelInner.callAsFunction(_:mask:cache:)is unreachable for it. Today the only options are to fork the file or re-implement the mask setup and layer loop against internal details.What is exposed
At
@_spi(FalconH1Encoder)scope, keeping this off the advertised public API of MLXLLM:FalconH1Configuration.hiddenSize/.numHiddenLayers/.rmsNormEps/.embeddingMultiplierFalconH1DecoderLayerand itscallAsFunctionFalconH1ModelInner.embedTokens/.layers/.finalLayerNormFalconH1ModelInner.callAsFunction(inputsEmbeds:cache:)— newFalconH1ModelInner.callAsFunction(_:mask:cache:)— was internalcallAsFunction(inputsEmbeds:cache:)is the seam, and the token-id overload now delegates to it so the two paths cannot drift. No behaviour change for existing callers:FalconH1Modelstill embeds, runs the stack, and applies the head exactly as before.Unlike the Gemma 4 change, nothing else had to widen —
FalconH1Model.modeland the mask helpers were already public, and none of the decoder layer's stored property types areprivate.Tests
FalconH1EncoderAccessTestsproves sufficiency the way the Gemma access tests do: it drives the stack using only the exposed surface, importing MLXLLM without@testableand opting in via@_spi(FalconH1Encoder). It checks shape, determinism, seam-vs-token-path agreement, layer-at-a-time driving for an all-hidden-states tap, and that the stack actually transforms its input — the last so the suite cannot pass on a seam that returns its argument or runs zero layers.One test earns its place beyond access checking.
sanitize()foldsembedding_multiplierintoembed_tokens.weight, which is correct when the token lookup is the only thing entering the stack, but is a live trap for a composite-embedding client: fold it and then add unscaled contributions, and the lookup half is scaled while the rest is not. Measured against the PyTorch reference for the model above, that is 77% relative error on the embedding and 38% on the final hidden state — while still producing plausible audio of the right length, so listening does not catch it.testCompositeEmbeddingMultiplierEquivalencepins(raw + other) * m == folded + other * mand asserts the unscaled-remainder variant is observably different, both at the embedding and after the stack, so the wrong form cannot quietly become the expected one. The doc comment on the new seam spells the same thing out.Runs on a tiny randomly-initialized model; no weights are downloaded.
swift test --filter FalconH1: 14 tests, 0 failures (5 new, 8 existing, 1 registry).🤖 Generated with Claude Code