Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ MLX is licensed under the MIT License. The notice is retained in the model
directory's LICENSE. The adaptation preserves FP32 product/reduction boundaries
and BF16 output rounding.

The Inkling 2 MLX runner in models/mlx/resin_models_mlx/inkling2 follows the
arithmetic of models/cuda/resin_models_cuda/inkling2. Its NVFP4/MXFP8 activation
quantizer (quantization.py) adapts SGLang's Apache-2.0 Inkling 2 activation
quantization, as that CUDA module does:

https://github.com/sgl-project/sglang/tree/e62ac6279646c686d3b328f58d9b5c2c2d5927dc

Its fused routing and expert-activation kernels (kernels.py) reuse MLX v0.32.4's
sigmoid formula from mlx/backend/metal/kernels/unary_ops.h:

Copyright 2023-2024 Apple Inc.
https://github.com/ml-explore/mlx/tree/v0.32.4/mlx/backend/metal/kernels

MLX is licensed under the MIT License. The notice is retained in that model
directory's LICENSE.

The Qwen3.5 MLX vision adapter in
models/mlx/resin_models_mlx/qwen3_5/vision.py reuses MLX-VLM 0.7.11's Qwen3.5
and Qwen3-VL vision modules, including their geometry and encoder blocks:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ hardware, and serving limits.

Model runners are not tied to CUDA. `resin_models_mlx` runs
[dense and MoE Qwen3.5 models](models/mlx/resin_models_mlx/qwen3_5/README.md)
and [Inkling 2 Mini text](models/mlx/resin_models_mlx/inkling2/README.md)
on Apple Silicon with MLX, on the same core engine. For a small local model:

```bash
Expand Down
3 changes: 3 additions & 0 deletions crates/resin-recipe/src/inkling2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ impl Grammar for Inkling2Grammar {
pub struct Inkling2Recipe {
pub add_generation_prompt: Option<bool>,
pub reasoning_effort: Option<crate::ReasoningEffort>,
/// Rejects media for runners that serve only the language model.
#[serde(skip_serializing)]
pub text_only: bool,
#[serde(skip_serializing, deserialize_with = "crate::recipe::default_if_null")]
pub media_config: media::Config,
}
15 changes: 15 additions & 0 deletions crates/resin-recipe/src/inkling2/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ mod tests {
);
}
#[test]
fn text_only_recipe_refuses_media() {
use crate::{Recipe, inkling2::Inkling2Recipe};

assert!(
Inkling2Recipe::default()
.prepare_media(vec![], &Encoder)
.is_ok()
);
let text_only = Inkling2Recipe {
text_only: true,
..Default::default()
};
assert!(text_only.prepare_media(vec![], &Encoder).is_err());
}
#[test]
fn padding_is_negative_one_on_the_byte_scale() {
let config = Config {
size: Size {
Expand Down
9 changes: 8 additions & 1 deletion crates/resin-recipe/src/inkling2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,20 @@ impl crate::Recipe for Inkling2Recipe {
Ok(vec![encoder.special_id("<|content_model_end_sampling|>")?])
}
fn input_modalities(&self) -> &'static [&'static str] {
&["text", "image"]
if self.text_only {
&["text"]
} else {
&["text", "image"]
}
}
fn prepare_media(
&self,
sources: Vec<crate::media::Source>,
encoder: &dyn crate::Encoder,
) -> Result<crate::media::Prepared, Error> {
if self.text_only {
return Err(Error::new("this recipe does not support media"));
}
self.media_config.prepare(sources, encoder)
}
}
15 changes: 15 additions & 0 deletions crates/resin-recipe/tests/inkling2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,18 @@ fn pinned_inkling2_template_handles_named_headers_images_and_empty_content() {
assert!(Inkling2Recipe::default().render(&request).is_err());
}
}

#[test]
fn text_only_recipe_rejects_media() {
use resin_recipe::{Recipe, inkling2::Inkling2Recipe};

assert_eq!(
(&Inkling2Recipe::default() as &dyn Recipe).input_modalities(),
&["text", "image"]
);
let recipe = Inkling2Recipe {
text_only: true,
..Default::default()
};
assert_eq!((&recipe as &dyn Recipe).input_modalities(), &["text"]);
}
45 changes: 41 additions & 4 deletions deploy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,31 @@ def assistant_path(self) -> Path | None:
recipe="ornith",
text_only=True,
),
"inkling2-mini-mlx": ModelSpec(
name="inkling2-mini-mlx",
family="inkling2",
checkpoint=Checkpoint(
repo_id="thinkingmachines/Inkling-2-Mini",
revision="ed40e7da625f594fc9c4990f5f66be24873c22d7",
directory="",
required_files=(
"config.json",
"model.safetensors.index.json",
"hf_quant_config.json",
"tokenizer.json",
"processor_config.json",
),
),
# Target-only text on Apple Silicon; experts stay NVFP4/MXFP8.
backend="mlx",
gpu="Apple-Silicon",
label="inkling2-mini-mlx",
expert_backend="mlx-gather-qmm",
context_length=32_768,
max_batch_size=8,
gpu_memory_utilization=0.70,
text_only=True,
),
"inkling2-small": ModelSpec(
name="inkling2-small",
family="inkling2",
Expand Down Expand Up @@ -659,17 +684,27 @@ def create_runner(
if spec.backend == "mlx":
if draft_tokens:
raise ValueError(
"this MLX Qwen3.5 runner does not support draft decoding; "
f"the MLX {spec.family} runner does not support draft decoding; "
"use draft_tokens=0"
)
from resin_models_mlx.qwen3_5 import Qwen35MlxRunner

if groups is not None:
raise ValueError("the MLX runner executes on one Apple Silicon device")
if expert_backend not in (None, spec.expert_backend):
raise ValueError(f"{spec.name} uses expert_backend={spec.expert_backend!r}")
# MLX has no CUDA graphs or graph batch catalog; graph options and
# decode_batch_sizes do not apply. The batch limit sizes live state.
if spec.family == "inkling2":
from resin_models_mlx.inkling2 import Inkling2MlxRunner

return Inkling2MlxRunner(
checkpoint,
memory_utilization=memory,
max_seq_len=context_length,
max_batch_size=max_batch_size,
prefill_chunk_size=prefill_chunk_size,
)
from resin_models_mlx.qwen3_5 import Qwen35MlxRunner

return Qwen35MlxRunner(
checkpoint,
memory_utilization=memory,
Expand Down Expand Up @@ -815,10 +850,12 @@ def create_recipe(

# The native recipe takes the checkpoint's image settings directly.
processor_config = path / "processor_config.json"
options = {}
options: dict[str, Any] = {}
if processor_config.is_file():
config = json.loads(processor_config.read_text())
options["media_config"] = config["image_processor"]
if spec.text_only:
options["text_only"] = True
return get_native_recipe(
spec.family,
Tokenizer.from_file(str(path / "tokenizer.json")),
Expand Down
2 changes: 2 additions & 0 deletions models/mlx/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ resin_models_mlx = [
"_native/LICENSE*",
"qwen3_5/README.md",
"qwen3_5/LICENSE",
"inkling2/README.md",
"inkling2/LICENSE",
]
21 changes: 21 additions & 0 deletions models/mlx/resin_models_mlx/inkling2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright © 2023 Apple Inc.

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.
Loading
Loading