Skip to content

Commit 88989d2

Browse files
authored
MLX snippet updates (#1397)
h/t @gary149
1 parent 5ba705d commit 88989d2

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

packages/tasks/src/model-libraries-snippets.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,19 +1309,53 @@ model = SwarmFormerModel.from_pretrained("${model.id}")
13091309
`,
13101310
];
13111311

1312-
export const mlx = (model: ModelData): string[] => [
1312+
const mlx_unknown = (model: ModelData): string[] => [
13131313
`pip install huggingface_hub hf_transfer
13141314
13151315
export HF_HUB_ENABLE_HF_TRANSFER=1
13161316
huggingface-cli download --local-dir ${nameWithoutNamespace(model.id)} ${model.id}`,
13171317
];
13181318

1319+
const mlxlm = (model: ModelData): string[] => [
1320+
`pip install --upgrade mlx-lm
1321+
1322+
mlx_lm.generate --model ${model.id} --prompt "Hello"`,
1323+
];
1324+
1325+
const mlxchat = (model: ModelData): string[] => [
1326+
`pip install --upgrade mlx-lm
1327+
1328+
mlx_lm.chat --model ${model.id}`,
1329+
];
1330+
1331+
const mlxvlm = (model: ModelData): string[] => [
1332+
`pip install --upgrade mlx-vlm
1333+
1334+
mlx_vlm.generate --model ${model.id} \\
1335+
--prompt "Describe this image." \\
1336+
--image "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"`,
1337+
];
1338+
13191339
export const mlxim = (model: ModelData): string[] => [
13201340
`from mlxim.model import create_model
13211341
13221342
model = create_model(${model.id})`,
13231343
];
13241344

1345+
export const mlx = (model: ModelData): string[] => {
1346+
if (model.tags.includes("image-text-to-text")) {
1347+
return mlxvlm(model);
1348+
}
1349+
if (model.tags.includes("conversational")) {
1350+
if (model.config?.tokenizer_config?.chat_template) {
1351+
return mlxchat(model);
1352+
} else {
1353+
return mlxlm(model);
1354+
}
1355+
}
1356+
return mlx_unknown(model);
1357+
};
1358+
13251359
export const model2vec = (model: ModelData): string[] => [
13261360
`from model2vec import StaticModel
13271361

0 commit comments

Comments
 (0)