Skip to content

Commit e932b91

Browse files
pcuencaDeep-Unlearning
authored andcommitted
MLX snippet updates (#1397)
h/t @gary149
1 parent ce1de0f commit e932b91

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
@@ -1340,19 +1340,53 @@ model = SwarmFormerModel.from_pretrained("${model.id}")
13401340
`,
13411341
];
13421342

1343-
export const mlx = (model: ModelData): string[] => [
1343+
const mlx_unknown = (model: ModelData): string[] => [
13441344
`pip install huggingface_hub hf_transfer
13451345
13461346
export HF_HUB_ENABLE_HF_TRANSFER=1
13471347
huggingface-cli download --local-dir ${nameWithoutNamespace(model.id)} ${model.id}`,
13481348
];
13491349

1350+
const mlxlm = (model: ModelData): string[] => [
1351+
`pip install --upgrade mlx-lm
1352+
1353+
mlx_lm.generate --model ${model.id} --prompt "Hello"`,
1354+
];
1355+
1356+
const mlxchat = (model: ModelData): string[] => [
1357+
`pip install --upgrade mlx-lm
1358+
1359+
mlx_lm.chat --model ${model.id}`,
1360+
];
1361+
1362+
const mlxvlm = (model: ModelData): string[] => [
1363+
`pip install --upgrade mlx-vlm
1364+
1365+
mlx_vlm.generate --model ${model.id} \\
1366+
--prompt "Describe this image." \\
1367+
--image "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"`,
1368+
];
1369+
13501370
export const mlxim = (model: ModelData): string[] => [
13511371
`from mlxim.model import create_model
13521372
13531373
model = create_model(${model.id})`,
13541374
];
13551375

1376+
export const mlx = (model: ModelData): string[] => {
1377+
if (model.tags.includes("image-text-to-text")) {
1378+
return mlxvlm(model);
1379+
}
1380+
if (model.tags.includes("conversational")) {
1381+
if (model.config?.tokenizer_config?.chat_template) {
1382+
return mlxchat(model);
1383+
} else {
1384+
return mlxlm(model);
1385+
}
1386+
}
1387+
return mlx_unknown(model);
1388+
};
1389+
13561390
export const model2vec = (model: ModelData): string[] => [
13571391
`from model2vec import StaticModel
13581392

0 commit comments

Comments
 (0)