sushi, a fork of ddalcu's mlx-serve Copyright (c) 2026 David Dalcu sushi as a whole is distributed under the MIT License (see LICENSE). It incorporates third-party software that remains under its own license, listed below. Those licenses continue to apply to those portions. A copy of the Apache License, Version 2.0 ships with this distribution as LICENSE-APACHE-2.0. The source comments at each site name their upstream too. ================================================================================ MIT-licensed tree construction ================================================================================ The confidence calibration and row choice in src/dflash_policy.zig follow mlx-serve src/dflash_policy.zig (https://github.com/ddalcu/mlx-serve), Copyright (c) 2026 David Dalcu, under the MIT terms in LICENSE. The codex launch instructions in src/assets/codex_model_instructions.md follow mlx-serve src/assets/codex_model_instructions.md (https://github.com/ddalcu/mlx-serve), Copyright (c) 2026 David Dalcu, under the MIT terms in LICENSE; the tool list is adjusted to what codex-cli 0.154 declares. The DeepSeek-V4.1 image plan, letterbox box and aligner unfold in src/dsv41/dsv41_vision.zig follow mlx-serve's dsv41_vision.zig (https://github.com/ddalcu/mlx-serve), Copyright (c) 2026 David Dalcu, under the MIT terms in LICENSE; their numbers are re-derived against the release's inference/image_processor.py and vision.py. The lattice and best-first draft tree in src/glm5/glm5_dflash_tree.zig are adapted from mlx-serve src/dflash.zig (https://github.com/ddalcu/mlx-serve), Copyright (c) 2026 David Dalcu, under the MIT terms in LICENSE. Its tree policy was ported from TensorFold (https://github.com/ashhart/TensorFold): MIT License Copyright (c) 2026 TensorFold contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ MIT License ================================================================================ -------------------------------------------------------------------------------- DeepSeek-V4.1-Flash reference implementation https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash-1017 Copyright (c) 2023 DeepSeek Licensed under the MIT License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. The DeepSeek-V4.1 forward in src/dsv41/dsv41_model.zig follows the release's `inference/model.py` (attention, compressor and indexer, hyper-connections, router, Engram and DSpark stages), the fake-quantization round trips in src/dsv41/dsv41_qat.zig follow `act_quant` and `fp4_act_quant` in `inference/kernel.py`, the n-gram hash and compressed vocabulary map in src/dsv41/dsv41_engram.zig follow `inference/engram.py`, and the image processor and tower in src/dsv41/dsv41_vision.zig follow `inference/image_processor.py` and `inference/vision.py`. All are implemented in Zig against mlx-c with SSD-streamed expert banks. `src/fixtures/dsv41_chat_template.jinja` is a Jinja transcription of the release's `encoding/encoding.py`, and `src/fixtures/dsv41_template_cases.json` and `src/dsv41/fixtures/dsv41_engram_token_map.bin` are generated from that encoder and the release's tokenizer. tests/dsv41/dump_dsv41_fixtures.py, tests/dsv41/dump_dsv41_template_cases.py, tests/dsv41/dump_dsv41_token_map.py and tests/dsv41/dump_dsv41_vision_fixtures.py run the unmodified reference externally to generate independent numerical fixtures. -------------------------------------------------------------------------------- Zig standard test runner https://codeberg.org/ziglang/zig (its standard test runner, `test_runner.zig` of the compiler library, 0.17.1) Copyright (c) Zig contributors Licensed under the MIT License (Expat), with the terms quoted above. scripts/test_runner.zig is that runner, unchanged but for `runTest`, which asks the engine after every test whether it is at rest. ================================================================================ Apache License, Version 2.0 ================================================================================ -------------------------------------------------------------------------------- MiMo V2 reference implementation https://huggingface.co/XiaomiMiMo/MiMo-V2.6-Flash-RL Copyright 2026 Xiaomi Corporation. Copyright 2026 The HuggingFace Inc. team. Licensed under the Apache License, Version 2.0. The MiMo attention and routing implementation in src/trunk.zig follows the reference's partial rotary embedding, asymmetric K/V, attention-sink, value-scaling and sigmoid-routing contracts. It is implemented in Zig against mlx-c with SSD-streamed expert banks. tests/mimo2/dump_mimo_v2_fixtures.py loads the unmodified reference externally to generate independent numerical fixtures. The TP-aware FP8 QKV reconstruction in `src/mimo2/mimo_source.zig` follows `conversion/mimo.py`, reimplemented in Zig. The MiMo-ViT vision tower in `src/mimo2/mimo_vision.zig` is a port of the reference's `MiMoVisionTransformer` (`modeling_mimo_v2.py`), and its image preprocessing follows the vendor serving processors (`smart_resize`, bilinear resampling, ImageNet normalization). The three MTP heads in `src/mimo2/mimo_mtp.zig` follow the MiMo-V2 MTP layer as XiaomiMiMo's vLLM and SGLang integrations compose it (Apache-2.0). Both are reimplemented in Zig against mlx-c; tests/mimo2/dump_mimo_vision_fixtures.py and tests/mimo2/dump_mimo_v2_mtp_fixtures.py render their fixtures from the unmodified reference modules. `src/fixtures/mimo_v26_chat_template.jinja` is the checkpoint's `chat_template` from tokenizer_config.json, unmodified, used as a test fixture; the model repository declares it under the MIT License. -------------------------------------------------------------------------------- MTPLX https://github.com/youssofal/mtplx Copyright 2026 Youssof Altoukhi Licensed under the Apache License, Version 2.0. Reproduced from MTPLX's NOTICE file: MTPLX Copyright 2026 Youssof Altoukhi MTPLX is a native MTP speculative decoding project for Apple Silicon. Preferred attribution for public projects, products, benchmarks, articles, and research that use or build on MTPLX: Powered by MTPLX by Youssof Altoukhi https://github.com/youssofal/mtplx If MTPLX informs academic or technical writing, please cite the repository using the included CITATION.cff metadata. This product includes Metal kernel code adapted from dflash-mlx (https://github.com/bstnxbt/dflash-mlx), Copyright dflash-mlx contributors, licensed under the Apache License 2.0. See mtplx/nax_verify.py for details. Used in sushi (`src/trunk.zig`): * The verify-shaped quantized matmul kernel family (`verifyQmm`), ported from `mtplx/verify_kernels.py`. Their design: one threadgroup per column tile, split-K reduction across simdgroups, sequential per-column dequant and FMA chains, named-scalar codegen with literal accumulator indices. * The NAX m16 tensor-ops tile for M5-class GPUs, ported from `mtplx/nax_verify.py`, together with its host contract: the M-padding dispatch, the environment gating and the availability probes. Modifications by mlx-serve: the kernels were reimplemented in Zig against mlx-c, the Metal sources are generated by comptime codegen rather than Python f-strings, and the NAX tile's dequantization loop was extended from 4-bit only to 4-, 5- and 6-bit affine weights. MTPLX's own NOTICE also credits vllm-metal and PipeNetwork for parts of MTPLX that sushi does not use. Those notices are omitted here as permitted by Apache-2.0 section 4(d). -------------------------------------------------------------------------------- dflash-mlx https://github.com/bstnxbt/dflash-mlx Copyright dflash-mlx contributors Licensed under the Apache License, Version 2.0. Reached through MTPLX's `nax_verify.py`, which is a port of dflash-mlx's `dflash_mlx/verify_qmm.py`, itself based on DFlash (arXiv:2602.06036). The matmul2d tensor extents and strides in our NAX kernel are dflash's working convention. -------------------------------------------------------------------------------- Inco Splash https://github.com/incoai/splash Licensed under the Apache License, Version 2.0. The matmul2d packed-KV attention kernel (sushi_qkv_mpp in src/trunk.zig) follows the structure of Splash's q8 attention tile (runtime/metal/kernels/common/q8_attention_tile.h): per-page QK and PV through the MetalPerformancePrimitives tensor op with an online softmax and split-KV partials. Re-implemented over MLX's affine group-quantized cache, reached here through upstream mlx-serve's port and extended to separate key and value widths. -------------------------------------------------------------------------------- oMLX, by jundot Copyright oMLX contributors Licensed under the Apache License, Version 2.0. Used in sushi (`src/glm5/glm5_hc_prefill.zig`): * The HC RMS reduction maps virtual MLX normalization threads as in `hc_mix1` from `omlx/patches/mlx_vlm_glm5_next_compat/decode_kernels.py` at 6745c39c. The following projection retains Sushi's own four-SIMD-group reduction order. The MLX-derived normalization arithmetic is MIT licensed. Used in sushi (`src/glm5/glm5_decode.zig`): * The copy-free three-bank affine QKV dispatch adapts `multi_qmv` from `omlx/patches/mlx_vlm_glm5_next_compat/decode_kernels.py` at 6745c39c. It is restricted to one BF16 input row, 5-, 6- and 8-bit weights and group128; each bank keeps its original packed weights, scales and biases. Its MLX-derived qmv-fast arithmetic retains the MIT attribution below. The affine row tile in `src/glm5/glm5_dflash_qmm.zig` adapts that arithmetic to reuse each weight group across up to four verification rows, retaining the per-row dot, scale/bias update and SIMD reduction order. Its 5- and 6-bit paths, and the coefficient hoist in `src/glm5/glm5_dflash_a6_hoist.zig`, also adapt MLX `load_vector` and `qdot` from `quantized.h`, including grouped activation sums and split-byte products, under the MIT attribution below. Used in sushi (`src/glm5/glm5_kda_fused.zig`): * The one-token KDA body adapts `_KDA_SOURCE` from the same 6745c39c GLM decode-kernel module. It uses externally projected BF16 gates, prepared decay constants and runtime-matched unary math, while retaining FP32 recurrent state. The sigmoid expressions derive from MLX's MIT-licensed elementwise functors. Used in sushi (`src/glm5/glm5_kda_prework.zig`): * Parallel token/head prework adapts the KDA decode arithmetic above and `_PREWORK_SOURCE` in `omlx/patches/glm53_kda_prework.py` at 6745c39c. It keeps BF16 convolution/SiLU boundaries, reuses qualified unary math, adds vector decay and beta outputs, and preserves the compact tail's existing bit semantics. MLX-derived sigmoid expressions remain MIT licensed. Used in sushi (`src/glm5/glm5_router.zig`): * The FP32 router GEMV/sigmoid and stable top-k selection adapt `_ROUTER_LOGITS_SOURCE` and `_ROUTER_SELECT_SOURCE` from the same 6745c39c GLM module. Storage checks and native fallback were added; one-token FP32 score and tie-order parity is retained. Used in sushi (`src/trunk.zig`): * The GatedDeltaNet blocked-sequence prefill kernel, ported from `custom_kernels/qwen35_prefill/gdn.py` (`gated_delta_blocked_seq`). * The software-pipelined GatedDeltaNet prefill kernel in `src/kernels/gdn_pipelined.metal`, from `_pipelined_source(12)` in `omlx/custom_kernels/qwen35_prefill/gdn.py` at 730bd6a (oMLX #4006), via Samuel Reed (@STRML), mlx-serve #641. State and output accesses are generic over StT and OutT to retain sushi's bf16 state contract. * The per-dispatch key-chunk budget in the head-dim-256 fused causal attention path, whose design comes from `qwen35_fa256_attention.py`. * The direct-index Qwen4 QSA prefill design (attend to each query's selected blocks by gathered index, never through a dense [S, kv] mask; one threadgroup per query token), from the exact QSA prefill of PR #3244 (`qsa_fast.py`, `qwen4_qsa_sparse_gqa`). The `sushi_attn_qsa256` kernel body itself derives from our own `sushi_attn_p256`, not from their source. thank you Jonathan Spangler. Modifications by mlx-serve: reimplemented in Zig against mlx-c, and the fa256 chunking carries exact online-softmax state between dispatches so a chunked run is bit-identical to a single dispatch. -------------------------------------------------------------------------------- jinja.cpp https://github.com/wangzhaode/jinja.cpp Copyright 2025 Wang Zhaode Licensed under the Apache License, Version 2.0. Behaviour and builtin set ported from jinja.cpp: the chat-template engine in `src/template/` (Zig) serves the filters, tests, methods and globals jinja.cpp serves, and the names only jinja.cpp has (the `strip` filter, `str.indent`, `list.append`) with jinja.cpp's result, read from its `value.cpp`. The engine is a fresh Zig design; no jinja.cpp source is vendored or linked. -------------------------------------------------------------------------------- AngelSpec https://github.com/Tencent/AngelSpec Copyright (C) 2026 Tencent. All rights reserved. Licensed under the Apache License, Version 2.0. Hy4-Flash's DFly2 drafter forward in src/hy4flash/hy4_dfly.zig follows the released drafter's training code at commit 0505773a (`angelspec/models/draft/dflash.py`, `hy4_mla.py`, `dspark.py`, and `angelspec/models/dflash.py`): the slot-0 MTP fusion, the block-causal mask, the hidden correction's served chain and the confidence head over its output. It is reimplemented in Zig on Sushi Cooler. ================================================================================ MIT License ================================================================================ -------------------------------------------------------------------------------- mlx-serve, after sushi detached https://github.com/ddalcu/mlx-serve Copyright (c) 2026 David Dalcu and mlx-serve contributors Licensed under the MIT License, the license and copyright of this project's LICENSE. Ported after the 2026-09-17 detach; each site names its upstream pull request: * SSD accounting (`src/kv_disk_cache.zig`) and rescan retry (`src/model_registry.zig`), from mlx-serve #601 and #550 by @brandondyal. Modifications: SSD deltas retain sushi's ring files and transactional metadata publication. * Affine KV activation dtype preservation (`src/trunk.zig` and `src/kv_quant.zig`), from mlx-serve #553 by Jason Titus (@jasontitus). Modifications: cache writes use sushi's shared batched/solo chunk path; the regression also forces capacity growth. * MTP prompt lookup (`src/mtp_lookup.zig`, the lookup row in `src/round_cost.zig`, the lookup round in `src/generate.zig`), from mlx-serve #523 and #533 by Samuel Reed (@STRML). Modifications: drafts capped at 8, the qwen4 head only, both rounds priced from sushi's own MTP cost source, an ordinary match must agree past the start of a line, and no lookup under a forced MTP depth. * The fused GatedDeltaNet decode step (`src/qwen4/gdn_decode.zig`): the GDN prework and recurrence in one dispatch, David Dalcu's K1 kernel (mlx-serve 27407892 and 89eeb249), and its verify-width variant with the host plumbing from mlx-serve #517 by Samuel Reed (@STRML). Modifications: the kernels emit the bf16 output, state and capture buffers of sushi's own chain and carry each stored capture state to the next token as sushi's capture kernel does; the Hadamard norm-gate-rotate kernel is not ported. * GDN verify norm-gate and rollback-history folding (`src/qwen4/gdn_decode.zig`, `src/trunk.zig`, `src/mlx.zig`), from mlx-serve #558 by Samuel Reed (@STRML). Modifications: bf16-only with sushi's per-token state rounding; the pipeline probe uses independent dummy inputs to preserve deferred PLE, and the default dispatch serves two rows only. * Batched Qwen4 decode's async evaluation ladder and its deferred-PLE guard (`src/trunk.zig`), from mlx-serve #584 by @cowboycoderhq. Modifications: host-only PLE, synthetic bf16 table fixtures and a separate batched engagement line; serial decode keeps its existing default. * Prefill/decode wall-time sharing (`src/scheduler.zig`, `src/generate.zig`, `src/main.zig`, `src/server.zig`, `tests/test_prefill_interleave.sh`), from mlx-serve #568 by Samuel Reed (@STRML). Modifications: share zero retains sushi's single boundary tick; its admission and adaptive-widening checks remain in place, and decode-time budget arithmetic saturates on overflow. * The fused QSA pooled-key kernel (`sushi_qsa_pool_rope`, `qsaPoolNormRopeFused` in `src/trunk.zig`): the indexer's block mean, key RMSNorm and partial RoPE in one dispatch, bit-identical to the MLX op chain it replaces, from mlx-serve #556 by Samuel Reed (@STRML). Modifications: no environment switch; a microbenchmark arm compares it with the chain. * The one-session hot prefix cache default (`defaultPrefixCacheAsk`, `oneSessionEntryBytes` and `prefix_cache_mem_explicit` in `src/server.zig`, the flag in `src/main.zig`), from mlx-serve #575 by Samuel Reed (@STRML). Modifications: both served architectures take it, the session counts the capacity a request reserves and the sliding-window ring, and the grown ask leaves room for the n-gram table's page cache and a cold full-context prompt. The app-side settings changes are not ported. * Prefill chunks that another chunk follows run no CED decoder tail (`extendState` in `src/dsv41/dsv41_model.zig`), from CommunityServe/plugins #11 by Samuel Reed (@STRML), MIT. Modifications: the chunk loop in `src/generate.zig` decides, and a chunk that takes a restore point or precedes a chunk of the window's rows or fewer keeps its tail. * The DeepSeek-V4.1 fused attention kernel's matrix-unit arm (`dsv41_attn_nax` in `src/dsv41/dsv41_kernels.zig`: the `matmul2d` fragment helpers and the tiling of both products), from CommunityServe/plugins #6 by Samuel Reed (@STRML), MIT. Modifications: the epilogue store and the packed FP4 row load run on the fragment layout. * The Hy4-Flash prefill attention core (`src/hy4flash/hy4_attn.zig`: the same fragment layout and tiling of both products, keys the scores' left operand and the values' right operand, an f32 operand split into bf16 parts), after the kernel above by Samuel Reed (@STRML), MIT. Modifications: Hy4's 576-wide key row whose first 512 channels are the values, f32 queries split in three, row ranges and picks read where they lie, one simdgroup for the rope channels. * The DeepSeek-V4.1 DSpark copy round (`Index.matchBest`, `copyLen` and `CopyBackoff` in `src/mtp_lookup.zig`, the copy arm in `src/dsv41/dsv41_dspark.zig`), from CommunityServe/plugins #15 by Samuel Reed (@STRML), MIT. Modifications: the index and match code are the MTP lookup's, copies stop at eight verify rows, and the generator keeps the backoff per request. * The SSD restore that evaluates each chunk before opening the next and drops the MLX error its failure latched (`src/kv_disk_cache.zig`, the fd-limit arm of `tests/test_prefix_cache_restart.sh`), from mlx-serve #527 by @brandondyal. Modifications: the ring-restore entry point drops its latch too. * The first append after a short shared restore sizes its copy from the request rather than the donor's buffer (`src/trunk.zig`), from mlx-serve 0405fd10 (#492, reported by @celestial-rose) by David Dalcu. Modifications: the copy is taken whenever the donor's buffer is longer than the request reserves, and a donated checkout adopts its buffers. * Restore by move on demand when a warm share does not fit (`checkoutRestored` in `src/prefix_cache.zig`, its admission-pass call in `src/scheduler.zig`) and the one-token full-hit guard, from mlx-serve a456fd01 (#518) by David Dalcu. Modifications: only qwen4_exp's inference-thread admission pass takes the checkout. * Live-request KV residency and the per-request `/metrics.json` sessions (`Session`, `renderJson` and `appendUnclaimedCached` in `src/metrics.zig`, `publishLiveKvResidency` and `publishCachedSessions` in `src/scheduler.zig`, `liveSessions`, the `/metrics.json` handler and `/props` `kv_cache_bytes` in `src/server.zig`), from mlx-serve 4e00f2af and eca42620 (#590) by David Dalcu. Modifications: rows add sushi's poll-stable submit sequence `request_id`, the request's `max_tokens` and `elapsed_seconds` (0 on a cached row) and do not emit `entry_id`; a donated checkout is counted once, QSA banks by their capacity buffers, a slot's ring restore points count, and `/props` gains only `kv_cache_bytes`. * `ignore_eos` (`requestEosSlice` in `src/server.zig`), from mlx-serve eca42620 (#590) by David Dalcu. Modifications: `/v1/completions` only; a chat request that sets it is refused by name. * The SSD restore's rows credited at admission (`LookupResult.slot_owned` in `src/prefix_cache.zig`, its read in `src/scheduler.zig`), from mlx-serve #621 by Josh Bellis (@jdbellis). Modifications: the hybrid restore only (MiMo's ring restore stays uncredited), proved by a live peak-against-bill read before landing. * Checked `config.json` reads (`cfgField`, `cfgInt`, `cfgF32`, `cfgObject` and `cfgString` in `src/model.zig`, the root and size checks in `src/model_discovery.zig`), from mlx-serve #608 by @alinselea. Modifications: scoped to the common prelude, the qwen4_exp branch and discovery; qwen4_exp adds a geometry refusal, and the fixtures are the served packs' configs. * The DeepSeek-V4.1-Flash arm (`src/dsv41/dsv41_{borrow,config,engram,kernels,model,prefix,qat,scope,source,stream,vision}.zig`, `src/fixtures/dsv41_chat_template.jinja`, `src/dsv41/fixtures/dsv41_engram_token_map.bin`, the spaced DSML tags in `src/chat.zig`), from mlx-serve's `deepseek_v41.zig`, `dsv41_engram.zig` and `src/chat.zig` at f1c3276f by David Dalcu. Modifications: the MLX-native path only (no embedded ds4 engine); the op scope, Engram lookup, attention and indexer formulation were rewritten against the release's `inference/model.py` and pinned to it by a tiny-model oracle, the expert stream rides sushi's shared expert cache, and the template cases are regenerated from the release's encoder. The fused Metal kernels (`src/dsv41/dsv41_kernels.zig`) are the `dsv41_*` kernels of the same file at 49bb6be0, with the expert dots rewritten for the release's mxfp4 banks (upstream's are affine repacks), MLX's own exp, cos and sin, and the rotary, hyper-connection and Engram indexing adapted to the original checkpoint layout. The release itself is MIT, Copyright (c) 2023 DeepSeek. * The DSpark speculative decoder of that arm (`dspark`, `draft`, `verify` and `finishVerify` in `src/dsv41/dsv41_model.zig`, `Generator.nextDrafterRound`), from mlx-serve's `deepseek_v41.zig` at 49bb6be0 (`dsparkDraft`, `dsparkBeginWith`, `dsparkFinish` and their rollback of a verify chunk) by David Dalcu. Modifications: the stages and heads load from the original `mtp.*` tensors with resident mxfp4 experts, the draft attention and the attention-output round trip follow the release's `DSparkAttention`, the verify chunk goes through the shared forward and the streamed expert cache, rejected rows leave the backbone rings by their 16 rows of slack, and the rounds run behind sushi's `--mtp` and spec-tick dispatch, sampled requests verifying by the exact rule for a point-mass draft. -------------------------------------------------------------------------------- MLX https://github.com/ml-explore/mlx Copyright (c) 2023 Apple Inc. Pinned submodule at `lib/mlx-src`, built by `scripts/build-mlx.sh` and linked into the sushi binary. Unmodified as a dependency. Separately, Metal source from MLX was ported into `src/trunk.zig`: the fused head-dim-256 prefill attention kernel (`sushi_attn_p256`) began as a self-contained port of MLX's steel attention (FA-2 online softmax, float32 accumulation, exp2 softmax) specialized to head_dim 256, and its fragment layout mirrors MLX's `BaseMMAFrag`. Modifications by mlx-serve: the v2 tiling (BQ=64, BK=32, 8 simdgroups, register-resident Q, uint4 staging) was picked by our own microbenchmark sweep, and a sliding-window band arm and key-axis chunked dispatch were added. The verifier expert-pair kernel (`VERIFY_EXPERT_REUSE_SOURCE`) adapts the 4-bit affine `qmv_impl`, `load_vector` and `qdot` arithmetic from MLX's `backend/metal/kernels/quantized.h`. Modifications: sorted expert-run pairing, shared packed-weight reads for two inputs, and verification-only shape guards. The fused expert reduction preserves the bf16 partial-sum order of MLX `reduction/reduce_col.h:col_reduce_small` while gathering, weighting and reducing in one dispatch. The batched coarse-head pair kernel (`MTP_COARSE_PAIRS_SOURCE`) adapts the 3-bit affine qmv-fast reduction from quantized.h, sharing each packed read across two input rows. The engine of our own in `src/tensor/` launches MLX's compiled kernels from `sushi.metallib` — compiled at build time from our lean instantiation units in `src/tensor/metallib/` and the pinned MLX Metal kernel headers and whole-file kernels in `lib/mlx-src/mlx/backend/metal/kernels/` (MIT License, Copyright (c) 2023-2026 Apple Inc.) — and ports the host code that picks and dispatches them, from MLX's Metal backend (Copyright (c) 2023-2026 Apple Inc.): * `stock.zig`: the dispatch of RMS norm (`fast::RMSNorm::eval_gpu`), layer norm (`fast::LayerNorm::eval_gpu`, with `fast::layer_norm`'s result type and its default weight and bias), softmax (`Softmax::eval_gpu`), dequantize (`fast::Dequantize::eval_gpu`, `fp_dequantize`) and affine quantize (`fast::Quantize::eval_gpu`, `quantize_impl`), with the kernel names MLX gives them. * `stock.zig` also launches the scalar and vector binary kernels (`binary_op_gpu_inplace`, `get_kernel_name` in `mlx/backend/metal/binary.cpp`) for LogAddExp, Power and Remainder. * `stock.zig`: `fast::RoPE::eval_gpu` (`mlx/backend/metal/rope.cpp`), `LogSumExp::eval_gpu` (`mlx/backend/metal/logsumexp.cpp`), and `conv_1D_gpu`'s depthwise kernel and its dilated steel implicit-GEMM path (`mlx/backend/metal/conv.cpp`) with `get_block_dims_common` (`mlx/backend/common/utils.cpp`). * `matmul.zig`: `mlx::core::matmul` and `Matmul::eval_gpu` with `check_transpose`, `collapse_batches`, `gemv_wide`, `gemv`, `dot_product`, `steel_matmul` and its tile choices (`GEMM_TPARAM_MACRO`), the fused and split-K dispatches for NAX and SIMD, `get_block_dims` and the `GEMMParams` and `GEMMSpiltKParams` layouts. * `reduce.zig`: `Reduce::eval_gpu`, `get_reduction_plan`, the row, column and all-reduce dispatches, `collapse_contiguous_dims`, `get_2d_grid_dims` and `ArgReduce::eval_gpu`. * `sort.zig`: `gpu_merge_sort` with its single-block and multi-block plans and `SearchSorted::eval_gpu` (`mlx/backend/metal/sort.cpp`). * `scan.zig`: `scan_gpu_inplace` for a scan along the last axis (`mlx/backend/metal/scan.cpp`) and `get_2d_grid_dims` with a divisor. * `random.zig`: `RandomBits::eval_gpu` (`mlx/backend/metal/primitives.cpp`) and the op chains of `mlx/random.cpp` (`uniform`, `gumbel`, `categorical_inverse_cdf`, `categorical_impl`). * `quantized.zig`: `quantized_matmul` (`mlx/ops.cpp`) and `QuantizedMatmul::eval_gpu`, `qmm_splitk`, `qmm` and `qmm_nax` (`mlx/backend/metal/quantized.cpp`) with `get_qmv_batch_limit` and `ensure_row_contiguous_matrix`. * `gather_mm.zig`: `gather_mm` (`mlx/ops.cpp`) and `GatherMM::eval_gpu` with `gather_mv`, `gather_mm_wide` and `gather_mm` (`mlx/backend/metal/matmul.cpp`). * `attention.zig`: `routeOf` follows `has_fused_kernel` and `ScaledDotProductAttention::use_fallback`, and `route.zig`'s `attentionChain` is `fast::scaled_dot_product_attention`'s op-chain fallback (`mlx/fast.cpp`). * `attention.zig`: `fast::scaled_dot_product_attention` (`mlx/fast.cpp`) and `ScaledDotProductAttention::eval_gpu` with `sdpa_full_self_attention_nax`, `sdpa_vector` and `sdpa_vector_2pass` (`mlx/backend/metal/scaled_dot_product_attention.cpp`), and the `AttnParams` layout. * `stock.zig` also holds `Erf::eval_gpu`, `Tanh::eval_gpu`, and the Cos, Sin, Log1p and Sign kernels (`unary_op_gpu_inplace`, `mlx/backend/metal/unary.cpp`). * `dtype_rule.zig`: MLX's dtype rules from `mlx/ops.cpp` (`at_least_float`, `sum`'s and `cumsum`'s output types, `quantized_matmul`'s promotion), applied by `route.zig` before an op runs. * `kernel.zig`: the signature a custom kernel's source is wrapped in follows `fast::metal_kernel` (`mlx/backend/metal/custom_kernel.cpp`). * `mlx_bf16_math.metal`: MLX's bfloat math and simd overloads (`backend/metal/kernels/bf16_math.h`) and the two bit casts of `bf16.h`, unmodified, which `kernel.zig` puts before a custom kernel's source as MLX's `utils.h` does. * `ops.zig`: `sushi_sigmoid`, `sushi_maximum` and `sushi_minimum` are MLX's `Sigmoid`, `Maximum` and `Minimum` functors (`backend/metal/kernels/unary_ops.h`, `binary_ops.h`), and `chains.zig`'s PLE gate writes MLX's `Sign` functor inline. `ops.viewStrides` ports `Reshape::prepare_reshape` with `collapse_contiguous_dims` (`mlx/primitives.cpp`, `mlx/backend/common/utils.cpp`), and the strided elementwise kernel's three-axis arm reads its locations as `binary_g_nd3` and `elem_to_loc_3` do (`backend/metal/kernels/binary.h`, `utils.h`). * `core.zig`: the pass rules (a barrier between dispatches that share a buffer, a fence between passes over untracked buffers) follow `mlx/backend/metal/device.cpp`. Modifications: Zig, eager dispatch on a queue of the engine's own, one axis per reduction, no complex types. The row-identical 8-bit projection kernel in `src/mtp_qmv.zig` adapts `qmv_fast_impl`, `qmv_impl`, `load_vector` and `qdot` from MLX `backend/metal/kernels/quantized.h` (Copyright (c) 2023-2024 Apple Inc.). It shares packed weights across input rows while preserving each serial row's lane assignment, reduction order and output rounding. The eight-row DFlash FFN kernel and the fused gate/up/SiLU kernel in `src/dflash_qmv.zig` adapt `qmv_wide_impl` and affine four-bit `dequantize` from MLX `backend/metal/kernels/quantized.h`. They specialize the A4 group-64 FFN geometries and share decoded weights across the input rows while retaining MLX's subchunk accumulation and lane-shuffle reduction order. The HC RMS kernel in `src/glm5/glm5_hc_prefill.zig` adapts the four-value-per-thread `rms_looped` reduction from MLX `backend/metal/kernels/rms_norm.metal` (Copyright 2024 Apple Inc.), also reflected in oMLX's HC normalization helper. It reads BF16 residuals directly and retains FP32 normalization before the mix. The affine QKV kernel in `src/glm5/glm5_decode.zig` also adapts `qmv_fast_impl`, `load_vector` and `qdot` from MLX quantized.h through oMLX's multi_qmv wrapper. It preserves each independent row's arithmetic while selecting three banks inside one dispatch; no concatenated weight buffer is created. The row-identical dense projection kernels in `src/mtp_dense_rows.zig` adapt MLX v0.32.2 `backend/metal/kernels/gemv.h` and `dot.h`. Modifications: independent activation rows share a dispatch, with the serial BF16 router and scalar-gate reduction trees preserved. The Hy4-Flash rope kernel in `src/hy4flash/hy4_rope.zig` adapts `rope_single_impl` and the frequency of `rope_single` and `rope` from MLX `backend/metal/kernels/rope.metal` (Copyright 2023-2024 Apple Inc.). Modifications: the rotation covers a row's trailing dims, the leading dims are copied beside it, the input is read through its strides and the output is written at the dtype the caller asks for. The indexer score kernel in `src/hy4flash/hy4_index.zig` adapts the same rotation, applied to the query's and the pooled keys' trailing dims as they are staged in threadgroup memory. The attention front kernel in `src/hy4flash/hy4_front.zig` adapts the same rotation and `rms_single_row` (below), the latent's norm and its key's rotation in one launch. The Hy4-Flash RMS norm kernel in `src/hy4flash/hy4_norm.zig` adapts `rms_single_row` from MLX `backend/metal/kernels/rms_norm.metal` (Copyright 2024 Apple Inc.). Modifications: the weight is read at its own dtype and widened, the rows are read through their strides and may be the sum of two inputs, and the output is written at the dtype the caller asks for. The Engram head-norm kernel in `src/hy4flash/hy4_engram_gate.zig` adapts the same `rms_single_row`, one row per hash head with that head's weight. The layer-boundary form of the hyper-connection kernel in `src/hy4flash/hy4_hc.zig` adapts it too, its threads run as lanes of the mix's threadgroup and the normed row kept in threadgroup memory. The Hy4-Flash one-row BF16 product in `src/hy4flash/hy4_gemv.zig` adapts `GEMVKernel` from MLX `backend/metal/kernels/gemv.h` (Copyright 2023-2024 Apple Inc.) at its 4 x 4 rows-a-simdgroup tile. Modifications: the f32 row is rounded to BF16 as it is read, and the sum is rounded to BF16 and written f32. The Hy4-Flash one-row f32 product in `src/hy4flash/hy4_row.zig` adapts the same `GEMVKernel` at its 4 x 4 rows-a-simdgroup tile and at its bm1 bn8 tile. Modifications: the BF16 weight is widened as it is read, and the first tile's rows are spread over more simdgroups. Several other kernels of ours deliberately reproduce the exact arithmetic of MLX ops (reduction order, accumulator dtype, `fast::exp`, the `precise::rsqrt` variant) so a fused kernel stays bit-identical to the op chain it replaces. Those are our own implementations written against MLX's observable behaviour, not copies of its source. The original QSA NAX kernel adapted MLX's `steel/attn/nax.h` (Copyright (c) 2025 Apple Inc., MIT License). The dense-cache branches of `src/kernels/qsa_nax.metal` and `src/kernels/qsa_nax_header.metal` port oMLX's occupancy-tuned QSA kernel from `omlx/patches/mlx_vlm_qwen4_exp_compat/vendor/mlx_vlm/models/ qwen4_exp/qsa_nax.py` at d6b2b92 (Apache-2.0). https://github.com/jundot/omlx/pull/4020 Original mlx-serve QSA NAX implementation contributed by Nikolai V. The packed-cache branches retain the original MLX-derived split-head-dimension implementation and two-term bf16 PV. Dense-cache port via mlx-serve PR #636 (bfe518f), contributed by Samuel Reed (@STRML). `src/kernels/attn_pd_nax_header.metal` adapts the same cooperative fragment layout and MMA wrapper from `steel/attn/nax.h`, and `src/kernels/attn_pd_nax.metal` follows the structure of MLX's NAX steel attention (Copyright (c) 2025 Apple Inc., MIT License): 16 query rows per simdgroup, 16x32x16 matmul2d tiles, K/V fragments read from device memory. Modifications: asymmetric query/key and value widths, the SIMD kernel's key-axis chunked dispatch with fp32 carries, cache-coordinate causal and sliding-band masks, per-head sinks, and a two-term bf16 PV. -------------------------------------------------------------------------------- mlx-lm https://github.com/ml-explore/mlx-lm Copyright (c) 2023-2026 Apple Inc. Used in sushi: * The GatedDeltaNet fused recurrence kernel in `src/trunk.zig` (`gdnKernelSource`) is a port of `mlx_lm/models/gated_delta.py`'s `_make_gated_delta_kernel(has_mask=False, vectorized=False)`. * The global-sort MoE gather (`_gather_sort`: argsort the flattened (token, expert) pairs, gather rows, run with sorted indices, then inverse permute) is theirs, used by our multi-position MoE paths in `src/trunk.zig`. Modifications by mlx-serve: reimplemented in Zig against mlx-c, and the GDN kernel is extended by a sequence variant (`capture_seq`) that records the recurrence state after every intermediate timestep so speculative decoding can roll back without re-running the prefix. -------------------------------------------------------------------------------- mlx-c https://github.com/ml-explore/mlx-c Copyright (c) 2023 ml-explore Pinned submodule at `lib/mlxc-src`, built by `scripts/build-mlx.sh` and linked into the sushi binary. Pinned to an upstream commit chosen for compatibility with the pinned MLX version. Unmodified. -------------------------------------------------------------------------------- mlxfast-challenge https://github.com/Layr-Labs/mlxfast-challenge Copyright (c) 2026 Layr Labs, Inc. Four decode fast paths in `src/trunk.zig` were derived from their tree over two porting rounds in July 2026: * The certified lm_head prune, a port of `LagunaLmHeadPrune.swift`: an MXFP8 coarse GEMV producing a certified per-row bound, a mask, and an exact pass over the surviving candidates. * The fused decode QK-norm + RoPE kernel, from their `laguna_sliding_qk_norm_rope_*`. * The fused MoE down + router-weighting + K-reduction tail, from their fused routed down-reduce, including its measured 4-rows-per-simdgroup choice. Modifications by mlx-serve: all four were written in Zig against mlx-c rather than Swift. The down-reduce kernel's per-row arithmetic is our own `gatherQmv` body with their fusion structure around it; the QK-norm+RoPE kernel extracts cos/sin by a probe row through stock `mlx_fast_rope` instead of re-deriving the angles; the lm_head prune is gated on argmax-only requests and ships opt-in behind `SUSHI_LMHEAD_PRUNE=1` after our own A/B measured it slower in the live graph than in a microbenchmark. -------------------------------------------------------------------------------- qwen-3.8-mtp-challenge https://github.com/Layr-Labs/qwen-3.8-mtp-challenge Copyright (c) 2026 Layr Labs, Inc. and the challenge submitters Ideas and code derived from validated challenge submissions at commit b6ce964, ported in August 2026 (each item names the submission's co-author handle): * The hd-256 causal sdpa query split for 6-9-row verify blocks (`splitCausalSdpa` in `src/trunk.zig`), from `Vendor/mlx-swift-lm/.../AttentionUtils.swift` at b6ce964 (a-github-name): split the queries at row 5 so both halves ride MLX's sdpa vector path, with bottom-right causal alignment keeping each half's key window exact. * Requantizing a dense bf16 MTP draft head at load time, from the 4-bit/g64 head declared in `mtp-head.manifest.json` at deb63ad (noskillcoding) — an idea rather than code: the draft head only proposes tokens, verification corrects them, so its weights can be served narrow. * The draft-rerank top-32 shortlist kernels (`sushi_mtp_top32_partial` / `sushi_mtp_top32_finalize` in `src/mtp.zig`), from `qwen35DraftTop32PartialKernel` / `qwen35DraftTop32FinalizeKernel` in their `Qwen35.swift` at 474c750 (submission 942e5ab2): an exact top-32 of a full-vocab row in two dispatches (per-thread slot selection under a taken-bitmask, simd_max rounds, ordinal-mapped floats), replacing a full GPU argsort. The surrounding scheme (coarse 2-bit proposal readout re-scored by the exact head's own 32 rows) is theirs as well; our re-score uses the trunk lm_head instead of a compact draft head. Modifications by mlx-serve: reimplemented in Zig against mlx-c; the query split is gated per shape and kill-switched (`SUSHI_SDPA_SPLIT`), the head requantization uses our existing per-weight quantization path. ================================================================================ Other licenses ================================================================================ -------------------------------------------------------------------------------- libwebp https://chromium.googlesource.com/webm/libwebp Copyright (c) 2010, Google Inc. All rights reserved. Licensed under the BSD 3-Clause License. Linked into the sushi binary for WebP image decoding. Unmodified. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- stb_image https://github.com/nothings/stb Copyright (c) 2017 Sean Barrett Public domain (Unlicense), or MIT at your option. Vendored under `lib/` and compiled into the sushi binary for image-input decoding. Unmodified. -------------------------------------------------------------------------------- hash-prospector (lowbias32) https://github.com/skeeto/hash-prospector Chris Wellons Public domain (Unlicense). `src/sampler_draw.zig` uses its two-round 32-bit integer mix (the shifts 16, 15, 16 and the multipliers 0x7feb352d, 0x846ca68b) as the counter hash behind a sampled draw's Gumbel noise. ================================================================================ Reference implementations ================================================================================ No code from the following was copied into sushi. They were read as specifications while writing our own implementations of the same architectures, and they are listed because they made that work possible. * turboderp/exllamav3 (MIT), the EXL3 format. `src/exl3/` re-implements the 16x16 trellis packing, the MCG and MUL1 decodes, the tensor-core permutation and the suh/svh Hadamard from that reference. `src/encoder/` re-implements the quantizer procedure in `modules/quant/exl3_lib/quantize.py`: block-RMS regularize, the 0.025 diagonal damping, 16-row block LDL, reverse LDLQ and the golden-section global scale folded into suh. The tile search is our own Viterbi over the same trellis, a CPU reference and a Metal kernel, not their CUDA kernel, and the output-Hessian sensitivity path is not implemented. No exllamav3 code is shipped. Model weights downloaded at runtime carry their own licenses from their publishers. sushi does not redistribute them. `src/fixtures/prose_pride_and_prejudice.txt` is Jane Austen's Pride and Prejudice (1813), in the public domain, as Project Gutenberg eBook #1342 with the Project Gutenberg header and footer removed (its license allows that for a public-domain work once every reference to Project Gutenberg is gone). `sushi bench` embeds it as its prose corpus. WikiText-103 (Merity et al., CC BY-SA 3.0) is downloaded at runtime by `sushi convert exl3` as calibration text. sushi does not redistribute it. -------------------------------------------------------------------------------- DOMPurify 3.4.16 https://github.com/cure53/DOMPurify/tree/3.4.16 Copyright Cure53 and other contributors. Dual-licensed under Apache-2.0 OR MPL-2.0; used here under Apache-2.0. The minified production bundle is vendored inline in src/webui/index.html (with only the source-map comment removed). Full upstream license text: src/webui/DOMPurify.LICENSE. ================================================================================ Tencent Hy License, Version 1.0 ================================================================================ -------------------------------------------------------------------------------- Hy4-Flash release files https://huggingface.co/tencent/Hy4-flash Copyright (c) Tencent Licensed under the Tencent Hy License, Version 1.0 (derived from the Apache License, Version 2.0), shipped with the release as LICENSE. src/hy4flash/fixtures/hy_v4_flash.json is the release's `config.json`, unmodified; src/hy4flash/fixtures/hy4_tensors.txt lists the release's tensor names, dtypes and shapes as its safetensors shard headers give them; hy4_chat_template.jinja is the release's `chat_template.jinja` and hy4_pre_tokenizer.json its tokenizer.json's `pre_tokenizer`, both unmodified. The Hy4-Flash forward in src/hy4flash/ follows the release's modeling code in huggingface/transformers (`models/hy_v4_flash`) and the llama.cpp graph of ggml-org/llama.cpp pull request 32517, implemented in Zig on Sushi Cooler.