Commit Graph

574 Commits

Author SHA1 Message Date
Awni Hannun 1e0c5727b6 add responses API with examples 2025-09-20 12:52:34 -07:00
Awni Hannun c991106dbf fix quant predicate (#485) 2025-09-18 13:56:37 -07:00
Ivan Fioravanti a7f534c3f5 Gated-Delta Fused Kernel (Qwen3Next) (#454)
* apply gating in recurrent_gated_delta_rule

* update cache with new state

* prealocate outputs in recurrent_gated_delta_rule

* feat(kernel): gated-delta kernel scaffolding with CPU fallbacks and tests; integrate in Qwen3Next behind flag

* feat(kernel): implement Metal kernel for gated delta prefill with time iteration to optimize performance

* faster single time step kernel

* use kernel for prefill

* version bump

---------

Co-authored-by: Goekdeniz-Guelmez <gulmezdeniz1999@gmail.com>
Co-authored-by: Awni Hannun <awni@apple.com>
v0.28.0
2025-09-17 14:23:40 -07:00
Robert Collins 04d6d926f3 Extends quantization predicate with config (#476)
Adds config parameter to quantization predicate
Enables fine-grained quantization control
Supports per-parameter quantization strategies
Improves flexibility in model quantization configuration
2025-09-17 14:02:47 -07:00
Gökdeniz Gülmez 38dc092e1f Fix llama4 text and make trainable (#474)
* in. com.

* format

* add copyright

* nits + removings
2025-09-17 13:52:22 -07:00
Gökdeniz Gülmez de47734510 Adding support for mamba2 (#392)
* initial commit

* update tuner/utils.py

* update ACKNOWLEDGMENTS.md

* update

* nits

* movinf mamba2 cache over to cache.py + clean up

* clean up

* fix residual_in_fp32

* updates

* adding default args

* updates

* first working inference with codestral mamba

* clean up

* adding 1b mamba 2

* udpdates

* updates

* updates

* finish

* clean up

* clean ups

* format

* nits

* adding some einsums

* format again

* optimize + format

* nits

* nits

* more speed

* use custom kernel

* update

* format

* nits

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-16 15:33:03 -07:00
n8programs 9e89bb5c25 smol bugfix (#473)
Co-authored-by: N8 <n8@n8programs.com>
2025-09-16 15:32:56 -07:00
Robert Collins b2564b5226 Adds LLaMA 4 text model implementation in MLX (#469)
* Adds LLaMA 4 text model implementation in MLX

Implements full LLaMA 4 text model architecture in MLX
Supports configurable attention and MLP variants
Adds RoPE, RMSNorm, and attention temperature tuning
Enables dual-branch MLP and per-layer RoPE control
Integrates weight loading from safetensors with config mapping
Handles token embedding and layer normalization properly

* nits + fixes

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-16 14:48:22 -07:00
Ivan Fioravanti 502554646d fix: handle cache offset safely for mamba error (#472)
* fix: handle cache offset safely for mamba error

* fix

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-16 14:48:16 -07:00
Awni Hannun 40dd25d7b7 Batch support for mamba-style models (#468)
* support mamba in batch inference

* works with nemotron

* granite

* add to plamo2

* more models + fixes

* fix
2025-09-16 08:01:45 -07:00
Awni Hannun 55bb9471b8 Batch generation (#443)
* initial batch generation

* more in batch generate

* concatenation

* use batch API in eval

* unique max tokens per prompt

* basic continuous batching

* simplify

* better perf by ensuring everything in same stream

* use data class for response

* check cache type
2025-09-15 16:02:45 -07:00
Awni Hannun 9a11a81add fix gemma3 window (#465) 2025-09-15 11:01:21 -07:00
Awni Hannun 4aaac2072d Add groups to ssm kernel and update more models (#456)
* Add groups to ssm kernel and update more models

* faster prompt processing
2025-09-15 09:37:24 -07:00
Neil Mehta 469461f463 fix VL models (#464) 2025-09-15 09:37:05 -07:00
Zhedong Cen 714157be6d Add an introduction to the default LLM in README.md (#461)
* Add introduction of default LLM in README.md

* Update README.md

---------

Co-authored-by: Awni Hannun <awni.hannun@gmail.com>
2025-09-15 06:14:38 -07:00
Gökdeniz Gülmez 06a9fdc5ad Adding GLM (#457)
* in. com.

* upd.

* format

* nits

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-13 21:41:02 -07:00
Awni Hannun 420418ca4e Update README.md 2025-09-13 14:29:54 -07:00
Gökdeniz Gülmez d6c45998f0 fix qwen3 next (#453)
* apply gating in recurrent_gated_delta_rule

* update cache with new state

* prealocate outputs in recurrent_gated_delta_rule

* format

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-13 07:03:03 -07:00
Gökdeniz Gülmez 42828df17a Update bitnet, nemotron h to use build in relu2 from MLX (#446)
* upd. bitnet, nemotron h

* format
2025-09-13 07:02:29 -07:00
Awni Hannun 80c217ff96 Faster ssm (#451)
* faster ssm

* comment + support batching
2025-09-12 17:40:08 -07:00
Gökdeniz Gülmez cf8e59ef76 Adding Qwen3 Next (#441)
* in. com.

* adding attention + gated rms norm

* adding Qwen3NextDecoderLayer

* adding Qwen3NextModel

* adding Model

* adding MLP

* adding Qwen3NextGatedDeltaNet

* updates

* updates

* upd. ackn.

* nits

* making it trainable

* inference fix

* gibberish inference

* fix training

* fix for batching

* nits

* optimize

* updates

* closer

* upd.

* fix inference

* fix

* optimization

* nits

* minimize

* clean ups

* format

* nits

* format again

* set some defaults

* alternateing layer defaults

* remove MTP layers

* add head dim but optional

* nits + format

* some nits

* some fixes

* fixes

* move f to innit

* optimized recurrent_gated_delta_rule

* optmize and shorten recurrent_gated_delta_rule a lot + moving g = mx.exp(g) up to fix gibberish output

* make train better

* nits

* nits + fix

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-12 17:29:48 -07:00
Gökdeniz Gülmez 7b84eb6bd1 Adding Ling Mini (#450)
* in. com.

* fixes

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-12 11:57:59 -07:00
squaredice 547b6b7e26 fix(quantization): parameterize hardcoded group_size in mixed_quant_predicate_builder (#449)
- Added group_size parameter to mixed_quant_predicate_builder with default of 64 for backward compatibility.
- Propagated q_group_size from convert function to the builder call.
- Improves flexibility for custom quantization schemes without altering core logic.
2025-09-12 06:16:36 -07:00
Awni Hannun 319c453828 sdpa with sinks (#418)
* sdpa with sinks

* bump mlx

* fix
2025-09-11 20:00:52 -07:00
Awni Hannun 64b3c51a58 fix server paths (#448)
* fix server paths

* remove relative condition
2025-09-11 14:05:38 -07:00
Gabe Goodhart 1537efd29a model: GraniteMoeHybrid (#442)
* feat(models): Add initial implementation of GraniteMoeHybrid generated by Claude Code

This commit was entirely generated using Claude Code and the following
prompt:

---
I've got an in-depth feature request for you to add. I need you to add support for the GraniteMoeHybrid architecture to the `mlx-lm` project. The task is to extend the existing set of model architecture implementations in `mlx_lm/models` by adding a new module named `granitemoehybrid.py`. Here are a few key pointers on this model architecture:

* It is a hybrid-recurrent model that uses `mamba2` for some layers (recurrent) and `granitemoe` for some layers (attention)
* It is very similar to the `nemotron_h` architecture implemented in `mlx_lm/models/nemotron_h.py`, but with a few key differences
    * In `GraniteMoeHybrid`, each layer has either a `mamba2` block or a `granitemoe` attention block AND a MoE block, whereas in `nemotron_h`, each "layer" is a single block that is either `mamba2`, `attention` (llama), or `ffn` (not MoE).
    * The config for `GraniteMoeHybrid` uses the `layer_types` field to determine whether to use `mamba2` or `granitemoe` attention for each layer
* The `transformers` implementation can be found at https://github.com/huggingface/transformers/blob/main/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py
    * The config can be found at https://github.com/huggingface/transformers/blob/main/src/transformers/models/granitemoehybrid/configuration_granitemoehybrid.py
* The PR adding support in `llama.cpp` is: https://github.com/ggml-org/llama.cpp/pull/13550
    * NOTE: In `llama.cpp`, I made the architecture slightly more flexible such that each layer could use either a MoE block OR a fully-connected FFN block after the recurrent/attention block
* For the `granitemoe` attention, the architecture is very similar to standard `llama` attention, but it includes 4 additional scalar multipliers that are pulled from config:
    * `embedding_multiplier`:
        * Multiply the input embeddings by this scalar before the first layer
        * Used here in `transformers` https://github.com/huggingface/transformers/blob/main/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py#L1347
    * `attention_multiplier`:
        * Used as the scaling factor in standard attention in place of the default 1/sqrt(n_embed_head)
        * Used here in `transformers`: https://github.com/huggingface/transformers/blob/main/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py#L217

The goal of this project is to create a fully working local implementation of the model in `mlx_lm`. You can find a local model to test with at /Users/ghart/models/granite-4.0-tiny-preview/. You can find a version of the `nemotron_h` model to test with at /Users/ghart/models/nvidia/NVIDIA-Nemotron-Nano-9B-v2/. To accomplish this project, you'll need to take the following steps:

1. Get a development environment working (you can use `uv` to manage your virtual env) and install the necessary dependencies
2. Run a sample inference with a model that is already known to work (eg `/Users/ghart/models/nvidia/NVIDIA-Nemotron-Nano-9B-v2/`)
3. Create the new module at `mlx_lm/models/granitemoehybrid.py`
4. Implement the model architecture, test, and iterate until you've got things working locally

Once you've got it working, let me know and I'll review and commit
---

Branch: GraniteHybrid

Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>

* fix(models): Claude Code fixes to architecture bugs

Inference now matches transormers. Further refinement by me comming next.

Branch: GraniteHybrid

Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>

* fix: Cleanup trailing whitespace and unused imports / config params

Branch: GraniteHybrid

Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>

* refactor: Refactor implementations to more closely resemble related models

This keeps the implementation of the attention block closer to GraniteMoe
for an easier diff view in the future. The functionality is identical.

Branch: GraniteHybrid

Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>

* nits + rebase

---------

Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-10 08:37:32 -07:00
Gökdeniz Gülmez 4a085c7618 Add lille 130m (#429)
* in. com.

* inference works

* rebase

* cpyrgt

* upd. ackn

* clean up residuals

* format

* rebase + nits

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-09 21:21:24 -07:00
Gökdeniz Gülmez 87961a743a adding Kwai-Klear/Klear-46B-A2.5B-Instruct (#437)
* in. com.

* clean up

* sanitize

* fix

* nits

* making it trainable

* format

* upd. ackn

* rebase + nits

* rebase + nits

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-09 20:10:16 -07:00
Gökdeniz Gülmez d79f3cd612 remove manual conv class in mamba1 (#436)
* remove manual conv class

* remove slice

* add sanitize

* format
2025-09-09 20:09:43 -07:00
Awni Hannun 103877ea3e some cleanup + tests towards batching (#430) 2025-09-09 13:05:11 -07:00
Awni Hannun 64574e19b8 fix hunyuan v1 dense (#440) 2025-09-09 12:56:30 -07:00
Nathan Sashihara 1b08ef199b Avoid cache-trimming crash in server for longcat chat and baichuan_m1 (#434)
* Avoid cache-trimming crash in server for longcat chat and baichuan_m1

* fix

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-08 10:09:41 -07:00
Awni Hannun 4ce11c6e50 allow fp8 (#431) 2025-09-08 06:35:47 -07:00
Gökdeniz Gülmez 0f268680c8 Fix Nemotron H loading error (#426)
* fix

* format
v0.27.1
2025-09-04 09:03:00 -07:00
Gökdeniz Gülmez 3ae6583393 Adding longcat flash (#423)
* in. com.

* udpates

* working

* fix rope

* import rope from deepseek file

* nits

* making it trainable

* adding to lora

* update ackn

* fixes

* fixes

* bump

* bump

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-04 08:51:34 -07:00
Gökdeniz Gülmez dccde59664 Add nemotron h (#407)
* init commit

* updates

* working

* updates

* format

* working

* updates

* format

* making it trainable

* clean up

* clean up

* updates

* clean up

* format

* nits

* final format

* nits + format

* fix mamba

* perf + nits

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-03 21:22:01 -07:00
Gökdeniz Gülmez 30c30a2a7e add Apertus from Swiss AI (#421)
* innit. com.

* fix Xielu

* update ackn.

* making it trainable

* nits

* format

* compile nonlinearity

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-03 07:25:23 -07:00
Gökdeniz Gülmez 6dd9d48bdc had to add self.args and self.model_type into the model class for mlx-lm-lore (#422)
* fix

* nits

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-03 06:30:22 -07:00
Gökdeniz Gülmez f5741cae33 Adding ibm Granite MoE (#413)
* init comm

* upd ackn

* upd train

* training working

* format and testing training

* use switch layer

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-09-02 07:51:22 -07:00
Nathan Sashihara 3b9074f48a server allow specifying seed (#414)
* server allow specifying seed

* seed test only require immediate consistency
2025-09-02 06:13:21 -07:00
n8programs e797abf49b np random seed (#415)
Co-authored-by: N8 <n8@n8programs.com>
2025-08-30 06:04:40 -07:00
Awni Hannun 60320dc234 version (#410) v0.27.0 2025-08-29 10:51:47 -07:00
Awni Hannun 1cd6045176 support mxfp4 (#385)
* support mxfp4

* support mxfp4

* updates

* Add Qwen2-VL model implementation (#384)

* Add Qwen2-VL + Qwen2.5-VL

* Fixed model sanitize method to handle both HF and MLX parameter formats

* Cleaned up MRoPE implemenation

* Formatted code

* Added type casting in MRoPE

* Removed unused instance variables

* Removed unnecessary MRoPE implemenation

* bump version

---------

Co-authored-by: Awni Hannun <awni@apple.com>

* Add `mlx_lm.perplexity` (#397)

* smoll update

* mlx_lm.perplexity

* pre commit cleaning

* bugfixes

* formatting

* use hf dataset

---------

Co-authored-by: N8 <n8@n8programs.com>
Co-authored-by: Awni Hannun <awni@apple.com>

* benchmark script (#396)

* Don't reload default model (#400)

* only apply lm_head to the last token (#406)

* only apply lm_head to the last token

* peel off last token instead and use lazy eval

* fix

* bump mlx, fix dwq for gpt-oss, comments

---------

Co-authored-by: Vincent Amato <vincentaamato@gmail.com>
Co-authored-by: n8programs <43304488+N8python@users.noreply.github.com>
Co-authored-by: N8 <n8@n8programs.com>
2025-08-29 10:45:14 -07:00
Nader Akoury d17184063a fix prompt cache corruption when generation is interrupted (#405)
Co-authored-by: Nader Akoury <git@dojoteef.com>
2025-08-29 08:38:45 -07:00
Awni Hannun 24fefe3d05 only apply lm_head to the last token (#406)
* only apply lm_head to the last token

* peel off last token instead and use lazy eval

* fix
2025-08-28 12:31:12 -07:00
Awni Hannun da1309f5a7 Don't reload default model (#400) 2025-08-26 15:42:09 -07:00
Awni Hannun bdcac4b635 benchmark script (#396) 2025-08-26 15:38:27 -07:00
n8programs 04a113fbdc Add mlx_lm.perplexity (#397)
* smoll update

* mlx_lm.perplexity

* pre commit cleaning

* bugfixes

* formatting

* use hf dataset

---------

Co-authored-by: N8 <n8@n8programs.com>
Co-authored-by: Awni Hannun <awni@apple.com>
2025-08-26 06:25:38 -07:00
Vincent Amato cd9884dab3 Add Qwen2-VL model implementation (#384)
* Add Qwen2-VL + Qwen2.5-VL

* Fixed model sanitize method to handle both HF and MLX parameter formats

* Cleaned up MRoPE implemenation

* Formatted code

* Added type casting in MRoPE

* Removed unused instance variables

* Removed unnecessary MRoPE implemenation

* bump version

---------

Co-authored-by: Awni Hannun <awni@apple.com>
v0.26.4
2025-08-25 08:54:04 -07:00
Daniel Nakov 249b0a11d6 Add support for ByteDance Seed-OSS-36B-Instruct model (#391)
* Add support for ByteDance Seed-OSS-36B-Instruct model

- Add seed_oss.py model implementation with proper attention bias handling
- Supports both input projection bias (attention_bias) and output projection bias (attention_out_bias)
- Handles tied vs untied word embeddings via lm_head
- Fixes mask broadcasting issues for MLX compatibility
- Enables conversion and inference for ByteDance-Seed/Seed-OSS-36B-Instruct

* nits

---------

Co-authored-by: Awni Hannun <awni@apple.com>
2025-08-21 16:34:16 -07:00