Skip to content

Commit 7c77f32

Browse files
authored
Merge pull request #283 from oxideai/release/0.25.2
release: 0.25.2
2 parents 48176b5 + be17a08 commit 7c77f32

File tree

35 files changed

+2623
-59
lines changed

35 files changed

+2623
-59
lines changed

.github/dependabot.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
- package-ecosystem: github-actions
8+
directory: /
9+
schedule:
10+
interval: weekly
11+
- package-ecosystem: gitsubmodule
12+
directory: /
13+
schedule:
14+
interval: weekly

.github/workflows/publish-docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
group: ${{ github.workflow }}-${{ github.ref }}
2222
steps:
2323
- name: Checkout
24-
uses: actions/checkout@v4
24+
uses: actions/checkout@v5
2525
with:
2626
submodules: true
2727
- name: Setup Dependencies
@@ -35,7 +35,7 @@ jobs:
3535
- name: Setup Pages
3636
uses: actions/configure-pages@v5
3737
- name: Upload artifact
38-
uses: actions/upload-pages-artifact@v3
38+
uses: actions/upload-pages-artifact@v4
3939
with:
4040
path: './target/doc'
4141
deploy-docs:
@@ -47,4 +47,4 @@ jobs:
4747
steps:
4848
- name: Deploy to GitHub Pages
4949
id: deployment
50-
uses: actions/deploy-pages@v4
50+
uses: actions/deploy-pages@v4

.github/workflows/validate.yml

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,42 @@ on:
55
- main
66
pull_request:
77
types: [opened, synchronize]
8-
8+
99
concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
1212
jobs:
13-
rustfmt-check:
13+
checks:
1414
runs-on: blaze/macos-15
1515
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v4
16+
- uses: actions/checkout@v5
1817
with:
1918
submodules: true
20-
- name: Setup Xcode
21-
run: sudo xcodes select 16.0
22-
- name: Install Rust
23-
uses: actions-rust-lang/setup-rust-toolchain@v1
19+
- run: sudo xcodes select 16.4
20+
- uses: actions-rust-lang/setup-rust-toolchain@v1
2421
with:
2522
components: rustfmt, clippy
26-
- name: Run cargo fmt
27-
run: cargo fmt -- --check
28-
- name: Run cargo clippy
29-
run: cargo clippy -- -D warnings
23+
- run: cargo --version
24+
- run: cargo fmt -- --check
25+
- run: cargo clippy -- -D warnings
3026

3127
tests:
32-
runs-on: blaze/macos-15
28+
runs-on: blaze/${{ matrix.runner }}
3329
strategy:
3430
matrix:
35-
rust: [ stable, 1.81.0 ]
36-
include:
37-
- cache: stable
38-
rust: stable
39-
- cache: 1-81-0
40-
rust: 1.81.0
31+
runner: [ macos-15 ]
32+
rust: [ 1.82.0, stable ]
4133
steps:
42-
- name: Checkout
43-
uses: actions/checkout@v4
34+
- uses: actions/checkout@v5
4435
with:
4536
submodules: true
46-
- name: Setup Xcode
47-
run: sudo xcodes select 16.0
48-
- name: Install Rust
49-
uses: actions-rust-lang/setup-rust-toolchain@v1
37+
- run: sudo xcodes select 16.4
38+
- uses: actions-rust-lang/setup-rust-toolchain@v1
5039
with:
5140
cache: false
5241
toolchain: ${{ matrix.rust }}
5342
rustflags: "" # Disable when we're ready
54-
- name: Setup cache
55-
uses: Swatinem/rust-cache@v2
43+
- uses: Swatinem/rust-cache@v2
5644
with:
57-
key: ${{ runner.os }}-${{ matrix.cache }}-${{ matrix.backend }}-${{ hashFiles('**/Cargo.toml') }}
58-
- name: Run tests
59-
run: cargo test --all -- --test-threads=1 # MLX is not thread safe
45+
key: ${{ matrix.rust }}-${{ matrix.runner }}-${{ hashFiles('**/Cargo.toml') }}
46+
- run: cargo test --all -- --test-threads=1 # MLX is not thread safe

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ Cargo.lock
1616
settings.json
1717
**.DS_Store
1818
.idea
19+
20+
# Local cache
21+
cache/

Cargo.toml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[workspace.package]
2-
# All but mlx-sys should follow the same version. mlx-sys should follow
2+
# All but mlx-sys should follow the same version. mlx-sys should follow
33
# the version of mlx-c.
4-
version = "0.25.1"
4+
version = "0.25.2"
55
edition = "2021"
66
authors = [
77
"Minghua Wu <michael.wu1107@gmail.com>",
@@ -13,13 +13,16 @@ keywords = ["mlx", "deep-learning", "machine-learning"]
1313
categories = ["science"]
1414
license = "MIT OR Apache-2.0"
1515
documentation = "https://oxideai.github.io/mlx-rs/mlx_rs/"
16+
rust-version = "1.82.0"
1617

1718
[workspace]
1819
members = [
19-
"mlx-macros",
20-
"mlx-sys",
21-
"mlx-rs",
20+
"mlx-macros",
21+
"mlx-sys",
22+
"mlx-rs",
2223
"mlx-internal-macros",
24+
"mlx-lm",
25+
"mlx-lm-utils",
2326
"mlx-tests",
2427
"examples/*",
2528
]
@@ -31,7 +34,9 @@ resolver = "2"
3134
mlx-sys = { version = "=0.2.0", path = "mlx-sys" }
3235
mlx-macros = { version = "0.25", path = "mlx-macros" }
3336
mlx-internal-macros = { version = "0.25", path = "mlx-internal-macros" }
34-
mlx-rs = { version = "0.25.1", path = "mlx-rs" }
37+
mlx-rs = { version = "0.25", path = "mlx-rs" }
38+
mlx-lm = { version = "0.0.1", path = "mlx-lm" }
39+
mlx-lm-utils = { version = "0.0.1", path = "mlx-lm-utils" }
3540

3641
# external dependencies
3742
thiserror = "2"
@@ -45,18 +50,18 @@ num_enum = "0.7"
4550
num-traits = "0.2"
4651
paste = "1"
4752
smallvec = "1"
48-
strum = { version = "0.26", features = ["derive"] }
53+
strum = { version = "0.27", features = ["derive"] }
4954
libc = "0.2"
5055
parking_lot = "0.12"
5156
tempfile = "3"
5257
itertools = "0.14"
5358
syn = { version = "2", features = ["full"] }
5459
quote = "1"
55-
darling = "0.20"
60+
darling = "0.21"
5661
proc-macro2 = "1"
57-
bindgen = "0.70"
62+
bindgen = "0.72"
5863
cmake = "0.1"
5964
cc = "1"
60-
safetensors = "0.5"
65+
safetensors = "0.6"
6166
bytemuck = "1"
62-
memmap2 = "0.9"
67+
memmap2 = "0.9"

examples/lm/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "lm"
3+
version.workspace = true
4+
edition.workspace = true
5+
authors.workspace = true
6+
repository.workspace = true
7+
keywords.workspace = true
8+
categories.workspace = true
9+
license.workspace = true
10+
documentation.workspace = true
11+
rust-version.workspace = true
12+
13+
[dependencies]
14+
mlx-rs.workspace = true
15+
mlx-lm.workspace = true
16+
mlx-lm-utils.workspace = true
17+
18+
anyhow = "1"

examples/lm/src/main.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use std::path::Path;
2+
3+
use mlx_lm::{cache::ConcatKeyValueCache, models::qwen3::load_qwen3_model};
4+
use mlx_lm_utils::tokenizer::{
5+
load_model_chat_template_from_file, ApplyChatTemplateArgs, Conversation, Role, Tokenizer,
6+
};
7+
use mlx_rs::{
8+
ops::indexing::{IndexOp, NewAxis},
9+
transforms::eval,
10+
Array,
11+
};
12+
13+
const CACHED_TEST_MODEL_DIR: &str = "./cache/Qwen3-4B-bf16";
14+
15+
fn qwen3() -> anyhow::Result<()> {
16+
let model_dir = Path::new(CACHED_TEST_MODEL_DIR);
17+
18+
let model_id = "mlx-community/Qwen3-4B-bf16".to_string();
19+
let tokenizer_file = model_dir.join("tokenizer.json");
20+
let tokenizer_config_file = model_dir.join("tokenizer_config.json");
21+
let mut tokenizer =
22+
Tokenizer::from_file(tokenizer_file).map_err(|e| anyhow::anyhow!("{:?}", e))?;
23+
let model_chat_template = load_model_chat_template_from_file(tokenizer_config_file)?
24+
.expect("Model chat template not found");
25+
26+
let conversations = vec![Conversation {
27+
role: Role::User,
28+
content: "what's your name?",
29+
}];
30+
let args = ApplyChatTemplateArgs {
31+
conversations: vec![conversations.into()],
32+
documents: None,
33+
model_id: &model_id,
34+
chat_template_id: None,
35+
add_generation_prompt: None,
36+
continue_final_message: None,
37+
};
38+
let encodings = tokenizer.apply_chat_template_and_encode(model_chat_template, args)?;
39+
let prompt: Vec<u32> = encodings
40+
.iter()
41+
.flat_map(|encoding| encoding.get_ids())
42+
.copied()
43+
.collect();
44+
let prompt_tokens = Array::from(&prompt[..]).index(NewAxis);
45+
46+
let mut cache = Vec::new();
47+
let mut model = load_qwen3_model(model_dir)?;
48+
let generate = mlx_lm::models::qwen3::Generate::<ConcatKeyValueCache>::new(
49+
&mut model,
50+
&mut cache,
51+
0.2,
52+
&prompt_tokens,
53+
);
54+
55+
let mut tokens = Vec::new();
56+
for (token, ntoks) in generate.zip(0..256) {
57+
let token = token.unwrap();
58+
tokens.push(token.clone());
59+
60+
if ntoks == 0 {
61+
eval(&tokens).unwrap();
62+
}
63+
64+
if tokens.len() % 20 == 0 {
65+
eval(&tokens).unwrap();
66+
let slice: Vec<u32> = tokens.drain(..).map(|t| t.item::<u32>()).collect();
67+
let s = tokenizer.decode(&slice, true).unwrap();
68+
print!("{s}");
69+
}
70+
}
71+
72+
eval(&tokens).unwrap();
73+
let slice: Vec<u32> = tokens.drain(..).map(|t| t.item::<u32>()).collect();
74+
let s = tokenizer.decode(&slice, true).unwrap();
75+
println!("{s}");
76+
77+
println!("------");
78+
79+
Ok(())
80+
}
81+
82+
fn main() -> anyhow::Result<()> {
83+
qwen3()
84+
}

examples/mistral/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ authors.workspace = true
99
mlx-rs.workspace = true
1010

1111
# External dependencies
12-
tokenizers = "=0.21.0" # 0.21.1 uses features that went stable in 1.82 while our MSRV is 1.81
13-
thiserror = "1.0"
12+
tokenizers = "0.22.0"
13+
thiserror = "2"
1414
anyhow = "1.0"
15-
hf-hub = "=0.4.1" # 0.4.2 uses features that went stable in 1.82 while our MSRV is 1.81
15+
hf-hub = "0.4.3"
1616
dotenv = "0.15"
1717
serde = { version = "1", features = ["derive"] }
1818
serde_json = "1"
1919
clap = { version = "4", features = ["derive"] }
2020
safetensors.workspace = true
21-
22-
# Fix idna-adapter version so that it works with rustc 1.81
23-
idna_adapter = "=1.2.0"
21+
idna_adapter = "1.2"

mlx-lm-utils/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/hf_cache/

mlx-lm-utils/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "mlx-lm-utils"
3+
version = "0.0.1"
4+
edition.workspace = true
5+
authors.workspace = true
6+
repository.workspace = true
7+
keywords.workspace = true
8+
categories.workspace = true
9+
license.workspace = true
10+
documentation.workspace = true
11+
12+
[dependencies]
13+
minijinja = { version = "2", features = ["loader"] }
14+
minijinja-contrib = { version = "2", features = ["pycompat"] }
15+
serde = { version = "1", features = ["derive"] }
16+
serde_json = "1"
17+
thiserror = "2"
18+
tokenizers = "0.22"

0 commit comments

Comments
 (0)