@huggingface/tasks 0.21.34 → 0.21.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/eval.d.ts +5 -0
- package/dist/commonjs/eval.d.ts.map +1 -1
- package/dist/commonjs/eval.js +5 -0
- package/dist/commonjs/local-apps.js +2 -2
- package/dist/commonjs/local-apps.spec.js +2 -2
- package/dist/commonjs/model-libraries-snippets.d.ts.map +1 -1
- package/dist/commonjs/model-libraries-snippets.js +25 -16
- package/dist/commonjs/model-libraries-snippets.spec.js +31 -0
- package/dist/esm/eval.d.ts +5 -0
- package/dist/esm/eval.d.ts.map +1 -1
- package/dist/esm/eval.js +5 -0
- package/dist/esm/local-apps.js +2 -2
- package/dist/esm/local-apps.spec.js +2 -2
- package/dist/esm/model-libraries-snippets.d.ts.map +1 -1
- package/dist/esm/model-libraries-snippets.js +25 -16
- package/dist/esm/model-libraries-snippets.spec.js +32 -1
- package/package.json +1 -1
- package/src/eval.ts +6 -0
- package/src/local-apps.spec.ts +2 -2
- package/src/local-apps.ts +2 -2
- package/src/model-libraries-snippets.spec.ts +46 -1
- package/src/model-libraries-snippets.ts +32 -19
package/dist/commonjs/eval.d.ts
CHANGED
|
@@ -147,5 +147,10 @@ export declare const EVALUATION_FRAMEWORKS: {
|
|
|
147
147
|
readonly description: "MMMU is a new benchmark designed to evaluate multimodal models on massive multi-discipline tasks demanding college-level subject knowledge and deliberate reasoning.";
|
|
148
148
|
readonly url: "https://mmmu-benchmark.github.io/";
|
|
149
149
|
};
|
|
150
|
+
readonly extractbench: {
|
|
151
|
+
readonly name: "extractbench";
|
|
152
|
+
readonly description: "ExtractBench is a benchmark for schema-guided data extraction from enterprise documents, scoring schema-valid JSON extraction and evidence grounding without an LLM judge.";
|
|
153
|
+
readonly url: "https://github.com/run-llama/ExtractBench";
|
|
154
|
+
};
|
|
150
155
|
};
|
|
151
156
|
//# sourceMappingURL=eval.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../src/eval.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB
|
|
1
|
+
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../src/eval.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4KxB,CAAC"}
|
package/dist/commonjs/eval.js
CHANGED
|
@@ -150,4 +150,9 @@ exports.EVALUATION_FRAMEWORKS = {
|
|
|
150
150
|
description: "MMMU is a new benchmark designed to evaluate multimodal models on massive multi-discipline tasks demanding college-level subject knowledge and deliberate reasoning.",
|
|
151
151
|
url: "https://mmmu-benchmark.github.io/",
|
|
152
152
|
},
|
|
153
|
+
extractbench: {
|
|
154
|
+
name: "extractbench",
|
|
155
|
+
description: "ExtractBench is a benchmark for schema-guided data extraction from enterprise documents, scoring schema-valid JSON extraction and evidence grounding without an LLM judge.",
|
|
156
|
+
url: "https://github.com/run-llama/ExtractBench",
|
|
157
|
+
},
|
|
153
158
|
};
|
|
@@ -393,7 +393,7 @@ const snippetPi = (model, filepath) => {
|
|
|
393
393
|
serverStep,
|
|
394
394
|
{
|
|
395
395
|
title: "Configure the model in Pi",
|
|
396
|
-
setup: "# Install Pi:\nnpm install -g @
|
|
396
|
+
setup: "# Install Pi:\nnpm install -g @earendil-works/pi-coding-agent",
|
|
397
397
|
content: `# Add to ~/.pi/agent/models.json:\n${modelsJson}`,
|
|
398
398
|
},
|
|
399
399
|
{
|
|
@@ -694,7 +694,7 @@ exports.LOCAL_APPS = {
|
|
|
694
694
|
},
|
|
695
695
|
pi: {
|
|
696
696
|
prettyLabel: "Pi",
|
|
697
|
-
docsUrl: "https://github.com/
|
|
697
|
+
docsUrl: "https://github.com/earendil-works/pi",
|
|
698
698
|
mainTask: "text-generation",
|
|
699
699
|
displayOnModelPage: isToolCallingLocalAgentModel,
|
|
700
700
|
snippet: snippetPi,
|
|
@@ -122,7 +122,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \\
|
|
|
122
122
|
};
|
|
123
123
|
const snippet = snippetFunc(model);
|
|
124
124
|
(0, vitest_1.expect)(snippet[0].content).toContain(`llama serve -hf bartowski/Llama-3.2-3B-Instruct-GGUF:{{QUANT_TAG}}`);
|
|
125
|
-
(0, vitest_1.expect)(snippet[1].setup).toContain("npm install -g @
|
|
125
|
+
(0, vitest_1.expect)(snippet[1].setup).toContain("npm install -g @earendil-works/pi-coding-agent");
|
|
126
126
|
(0, vitest_1.expect)(snippet[1].content).toContain(`"id": "bartowski/Llama-3.2-3B-Instruct-GGUF:{{QUANT_TAG}}"`);
|
|
127
127
|
(0, vitest_1.expect)(snippet[2].content).toContain("pi");
|
|
128
128
|
});
|
|
@@ -142,7 +142,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \\
|
|
|
142
142
|
const snippet = snippetFunc(model);
|
|
143
143
|
(0, vitest_1.expect)(snippet[0].setup).toContain("uv tool install mlx-lm");
|
|
144
144
|
(0, vitest_1.expect)(snippet[0].content).toContain('mlx_lm.server --model "mlx-community/Llama-3.2-3B-Instruct-mlx"');
|
|
145
|
-
(0, vitest_1.expect)(snippet[1].setup).toContain("npm install -g @
|
|
145
|
+
(0, vitest_1.expect)(snippet[1].setup).toContain("npm install -g @earendil-works/pi-coding-agent");
|
|
146
146
|
(0, vitest_1.expect)(snippet[1].content).toContain('"baseUrl": "http://localhost:8080/v1"');
|
|
147
147
|
(0, vitest_1.expect)(snippet[1].content).toContain('"id": "mlx-community/Llama-3.2-3B-Instruct-mlx"');
|
|
148
148
|
(0, vitest_1.expect)(snippet[2].content).toContain("pi");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-libraries-snippets.d.ts","sourceRoot":"","sources":["../../src/model-libraries-snippets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"model-libraries-snippets.d.ts","sourceRoot":"","sources":["../../src/model-libraries-snippets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAoBjD,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,KAAG,MAAM,EAOjD,CAAC;AAkBF,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,KAAG,MAAM,EAKjD,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,OAAO,SAAS,KAAG,MAAM,EAIhD,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,KAAG,MAAM,EAIjD,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,SAAS,KAAG,MAAM,EAkBlD,CAAC;AAaF,eAAO,MAAM,IAAI,GAAI,OAAO,SAAS,KAAG,MAAM,EAY7C,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,KAAG,MAAM,EAIjD,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,OAAO,SAAS,KAAG,MAAM,EAI9C,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,MAAM,EAenC,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,OAAO,SAAS,KAAG,MAAM,EAsB5D,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,KAAG,MAAM,EAYxD,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,OAAO,SAAS,KAAG,MAAM,EAkBhD,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,MAAM,EAmDxC,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,MAAM,EAcvC,CAAC;AAEF,eAAO,MAAM,iBAAiB,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AAM,IAAI,GAAI,OAAO,SAAS,KAAG,MAAM,EAQ7C,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,OAAO,SAAS,KAAG,MAAM,EAyBhD,CAAC;AAEF,eAAO,MAAM,IAAI,GAAI,OAAO,SAAS,KAAG,MAAM,EAI7C,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,OAAO,SAAS,KAAG,MAAM,EAI/C,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,SAAS,KAAG,MAAM,EAqBlD,CAAC;AA4BF,eAAO,MAAM,MAAM,GAAI,OAAO,SAAS,KAAG,MAAM,EAO/C,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,KAAG,MAAM,EAUnD,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,MAAM,EAYnC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,KAAG,MAAM,EAKvD,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,OAAO,SAAS,KAAG,MAAM,EAI9C,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,OAAO,SAAS,KAAG,MAAM,EAiB9C,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,OAAO,SAAS,KAAG,MAAM,EAgD9C,CAAC"}
|
|
@@ -12,11 +12,12 @@ function nameWithoutNamespace(modelId) {
|
|
|
12
12
|
return splitted.length === 1 ? splitted[0] : splitted[1];
|
|
13
13
|
}
|
|
14
14
|
const escapeStringForJson = (str) => JSON.stringify(str).slice(1, -1); // slice is needed to remove surrounding quotes added by JSON.stringify
|
|
15
|
+
const isValidIdentifier = (str) => /^[A-Za-z_]\w*$/.test(str);
|
|
15
16
|
//#region snippets
|
|
16
17
|
const adapters = (model) => [
|
|
17
18
|
`from adapters import AutoAdapterModel
|
|
18
19
|
|
|
19
|
-
model = AutoAdapterModel.from_pretrained("${model.config?.adapter_transformers?.model_name}")
|
|
20
|
+
model = AutoAdapterModel.from_pretrained("${escapeStringForJson(model.config?.adapter_transformers?.model_name ?? "fill-in-model-name")}")
|
|
20
21
|
model.load_adapter("${model.id}", set_active=True)`,
|
|
21
22
|
];
|
|
22
23
|
exports.adapters = adapters;
|
|
@@ -73,7 +74,7 @@ result, message = detector.detect_watermark(watermarked_audio, sr)`;
|
|
|
73
74
|
};
|
|
74
75
|
exports.audioseal = audioseal;
|
|
75
76
|
function get_base_diffusers_model(model) {
|
|
76
|
-
return model.cardData?.base_model?.toString() ?? "fill-in-base-model";
|
|
77
|
+
return escapeStringForJson(model.cardData?.base_model?.toString() ?? "fill-in-base-model");
|
|
77
78
|
}
|
|
78
79
|
function get_prompt_from_diffusers_model(model) {
|
|
79
80
|
const prompt = model.widgetData?.[0]?.text ?? model.cardData?.instance_prompt;
|
|
@@ -918,7 +919,8 @@ backbone = keras_hub.models.Backbone.from_preset("hf://${modelId}")
|
|
|
918
919
|
`;
|
|
919
920
|
const keras_hub = (model) => {
|
|
920
921
|
const modelId = model.id;
|
|
921
|
-
|
|
922
|
+
// interpolated as a Python class name, so a non-identifier is treated as absent
|
|
923
|
+
const tasks = (model.config?.keras_hub?.tasks ?? []).filter(isValidIdentifier);
|
|
922
924
|
const snippets = [];
|
|
923
925
|
// First, generate tasks with examples
|
|
924
926
|
for (const [task, snippet] of Object.entries(_keras_hub_tasks_with_example)) {
|
|
@@ -1225,7 +1227,7 @@ model = MeshAnything(args)`,
|
|
|
1225
1227
|
exports.mesh_anything = mesh_anything;
|
|
1226
1228
|
const multimolecule = (model) => {
|
|
1227
1229
|
const widgetExample = model.widgetData?.[0];
|
|
1228
|
-
const exampleText = widgetExample?.text;
|
|
1230
|
+
const exampleText = escapeStringForJson(widgetExample?.text ?? "");
|
|
1229
1231
|
const maskToken = model.mask_token ?? "<mask>";
|
|
1230
1232
|
const sequence = exampleText?.replace(maskToken, "A");
|
|
1231
1233
|
const snippets = [`pip install multimolecule`];
|
|
@@ -1283,8 +1285,9 @@ openasr transcribe audio.wav --model ${modelId}`,
|
|
|
1283
1285
|
};
|
|
1284
1286
|
exports.openasr = openasr;
|
|
1285
1287
|
const paddlenlp = (model) => {
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
+
const architecture = model.config?.architectures?.[0];
|
|
1289
|
+
// interpolated as a Python class name, so a non-identifier is treated as absent
|
|
1290
|
+
if (architecture && isValidIdentifier(architecture)) {
|
|
1288
1291
|
return [
|
|
1289
1292
|
[
|
|
1290
1293
|
`from paddlenlp.transformers import AutoTokenizer, ${architecture}`,
|
|
@@ -1536,7 +1539,7 @@ const skopsPickle = (model, modelFile) => {
|
|
|
1536
1539
|
from skops.hub_utils import download
|
|
1537
1540
|
download("${model.id}", "path_to_folder")
|
|
1538
1541
|
model = joblib.load(
|
|
1539
|
-
"${modelFile}"
|
|
1542
|
+
"${escapeStringForJson(modelFile)}"
|
|
1540
1543
|
)
|
|
1541
1544
|
# only load pickle files from sources you trust
|
|
1542
1545
|
# read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
|
|
@@ -1549,7 +1552,7 @@ from skops.io import load
|
|
|
1549
1552
|
download("${model.id}", "path_to_folder")
|
|
1550
1553
|
# make sure model file is in skops format
|
|
1551
1554
|
# if model is a pickle file, make sure it's from a source you trust
|
|
1552
|
-
model = load("path_to_folder/${modelFile}")`,
|
|
1555
|
+
model = load("path_to_folder/${escapeStringForJson(modelFile)}")`,
|
|
1553
1556
|
];
|
|
1554
1557
|
};
|
|
1555
1558
|
const skopsJobLib = (model) => {
|
|
@@ -1816,11 +1819,17 @@ exports.terratorch = terratorch;
|
|
|
1816
1819
|
const hasChatTemplate = (model) => model.config?.tokenizer_config?.chat_template !== undefined ||
|
|
1817
1820
|
model.config?.processor_config?.chat_template !== undefined ||
|
|
1818
1821
|
model.config?.chat_template_jinja !== undefined;
|
|
1822
|
+
// interpolated as a Python class name (and into RegExps in pruna_transformers), so a non-identifier is treated as absent
|
|
1823
|
+
const autoModelClass = (model) => {
|
|
1824
|
+
const autoModel = model.transformersInfo?.auto_model;
|
|
1825
|
+
return autoModel && isValidIdentifier(autoModel) ? autoModel : undefined;
|
|
1826
|
+
};
|
|
1819
1827
|
const transformers = (model) => {
|
|
1820
1828
|
const info = model.transformersInfo;
|
|
1821
1829
|
if (!info) {
|
|
1822
1830
|
return [`# ⚠️ Type of model unknown`];
|
|
1823
1831
|
}
|
|
1832
|
+
const auto_model = autoModelClass(model) ?? "AutoModel";
|
|
1824
1833
|
const remote_code_snippet = model.tags.includes(TAG_CUSTOM_CODE) ? ", trust_remote_code=True" : "";
|
|
1825
1834
|
const autoSnippet = [];
|
|
1826
1835
|
if (info.processor) {
|
|
@@ -1829,7 +1838,7 @@ const transformers = (model) => {
|
|
|
1829
1838
|
: info.processor === "AutoFeatureExtractor"
|
|
1830
1839
|
? "extractor"
|
|
1831
1840
|
: "processor";
|
|
1832
|
-
autoSnippet.push("# Load model directly", `from transformers import ${info.processor}, ${
|
|
1841
|
+
autoSnippet.push("# Load model directly", `from transformers import ${info.processor}, ${auto_model}`, "", `${processorVarName} = ${info.processor}.from_pretrained("${model.id}"` + remote_code_snippet + ")", `model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")');
|
|
1833
1842
|
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
|
|
1834
1843
|
if (model.tags.includes("image-text-to-text")) {
|
|
1835
1844
|
autoSnippet.push("messages = [", [
|
|
@@ -1849,7 +1858,7 @@ const transformers = (model) => {
|
|
|
1849
1858
|
}
|
|
1850
1859
|
}
|
|
1851
1860
|
else {
|
|
1852
|
-
autoSnippet.push("# Load model directly", `from transformers import ${
|
|
1861
|
+
autoSnippet.push("# Load model directly", `from transformers import ${auto_model}`, `model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")');
|
|
1853
1862
|
}
|
|
1854
1863
|
if (model.pipeline_tag && library_to_tasks_js_1.LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
|
|
1855
1864
|
const pipelineSnippet = ["# Use a pipeline as a high-level helper"];
|
|
@@ -1927,7 +1936,7 @@ const peft = (model) => {
|
|
|
1927
1936
|
`from peft import PeftModel
|
|
1928
1937
|
from transformers import AutoModelFor${pefttask}
|
|
1929
1938
|
|
|
1930
|
-
base_model = AutoModelFor${pefttask}.from_pretrained("${peftBaseModel}")
|
|
1939
|
+
base_model = AutoModelFor${pefttask}.from_pretrained("${escapeStringForJson(peftBaseModel)}")
|
|
1931
1940
|
model = PeftModel.from_pretrained(base_model, "${model.id}")`,
|
|
1932
1941
|
];
|
|
1933
1942
|
};
|
|
@@ -2342,18 +2351,18 @@ const pruna_diffusers = (model) => {
|
|
|
2342
2351
|
.trim());
|
|
2343
2352
|
};
|
|
2344
2353
|
const pruna_transformers = (model) => {
|
|
2345
|
-
const
|
|
2354
|
+
const auto_model = autoModelClass(model);
|
|
2346
2355
|
const transformersSnippets = (0, exports.transformers)(model);
|
|
2347
2356
|
// Replace pipeline with PrunaModel
|
|
2348
2357
|
let processedSnippets = transformersSnippets.map((snippet) => snippet
|
|
2349
2358
|
.replace(/from transformers import pipeline/g, "from pruna import PrunaModel")
|
|
2350
2359
|
.replace(/pipeline\([^)]*\)/g, `PrunaModel.from_pretrained("${model.id}")`));
|
|
2351
2360
|
// Additional cleanup if auto_model info is available
|
|
2352
|
-
if (
|
|
2361
|
+
if (auto_model) {
|
|
2353
2362
|
processedSnippets = processedSnippets.map((snippet) => snippet
|
|
2354
|
-
.replace(new RegExp(`from transformers import ${
|
|
2355
|
-
.replace(new RegExp(`${
|
|
2356
|
-
.replace(new RegExp(`^.*from.*import.*(, *${
|
|
2363
|
+
.replace(new RegExp(`from transformers import ${auto_model}\n?`, "g"), "")
|
|
2364
|
+
.replace(new RegExp(`${auto_model}.from_pretrained`, "g"), "PrunaModel.from_pretrained")
|
|
2365
|
+
.replace(new RegExp(`^.*from.*import.*(, *${auto_model})+.*$`, "gm"), (line) => line.replace(new RegExp(`, *${auto_model}`, "g"), "")));
|
|
2357
2366
|
}
|
|
2358
2367
|
return processedSnippets;
|
|
2359
2368
|
};
|
|
@@ -52,4 +52,35 @@ output = llm(
|
|
|
52
52
|
)
|
|
53
53
|
print(output)`);
|
|
54
54
|
});
|
|
55
|
+
// a repo owner can put anything in config.json / the model card, so every interpolated value
|
|
56
|
+
// must either be escaped (string literals) or rejected (bare identifiers)
|
|
57
|
+
(0, vitest_1.describe)("repo-controlled values are not injectable", () => {
|
|
58
|
+
const PAYLOAD = `")\nimport os; os.system("id`;
|
|
59
|
+
vitest_1.it.each([
|
|
60
|
+
["adapters", model_libraries_snippets_js_1.adapters, { config: { adapter_transformers: { model_name: PAYLOAD } } }],
|
|
61
|
+
["diffusers", model_libraries_snippets_js_1.diffusers, { tags: ["lora"], cardData: { base_model: PAYLOAD, instance_prompt: PAYLOAD } }],
|
|
62
|
+
["keras_hub", model_libraries_snippets_js_1.keras_hub, { config: { keras_hub: { tasks: [PAYLOAD, "TextClassifier"] } } }],
|
|
63
|
+
["paddlenlp", model_libraries_snippets_js_1.paddlenlp, { config: { architectures: [PAYLOAD] } }],
|
|
64
|
+
["peft", model_libraries_snippets_js_1.peft, { config: { peft: { base_model_name_or_path: PAYLOAD, task_type: "CAUSAL_LM" } } }],
|
|
65
|
+
["multimolecule", model_libraries_snippets_js_1.multimolecule, { widgetData: [{ text: PAYLOAD }] }],
|
|
66
|
+
["transformers", model_libraries_snippets_js_1.transformers, { transformersInfo: { auto_model: PAYLOAD, processor: "AutoTokenizer" } }],
|
|
67
|
+
[
|
|
68
|
+
"sklearn",
|
|
69
|
+
model_libraries_snippets_js_1.sklearn,
|
|
70
|
+
{ tags: ["skops"], config: { sklearn: { model: { file: PAYLOAD }, model_format: "pickle" } } },
|
|
71
|
+
],
|
|
72
|
+
])("%s", (_name, snippetFn, model) => {
|
|
73
|
+
const snippet = snippetFn({ id: "user/model", tags: [], inference: "", ...model }).join("\n");
|
|
74
|
+
(0, vitest_1.expect)(snippet).not.toContain(PAYLOAD);
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)("keras_hub keeps the valid task next to a rejected one", () => {
|
|
77
|
+
const model = {
|
|
78
|
+
id: "user/model",
|
|
79
|
+
tags: [],
|
|
80
|
+
inference: "",
|
|
81
|
+
config: { keras_hub: { tasks: [PAYLOAD, "TextClassifier"] } },
|
|
82
|
+
};
|
|
83
|
+
(0, vitest_1.expect)((0, model_libraries_snippets_js_1.keras_hub)(model).join("\n")).toContain("keras_hub.models.TextClassifier.from_preset");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
55
86
|
});
|
package/dist/esm/eval.d.ts
CHANGED
|
@@ -147,5 +147,10 @@ export declare const EVALUATION_FRAMEWORKS: {
|
|
|
147
147
|
readonly description: "MMMU is a new benchmark designed to evaluate multimodal models on massive multi-discipline tasks demanding college-level subject knowledge and deliberate reasoning.";
|
|
148
148
|
readonly url: "https://mmmu-benchmark.github.io/";
|
|
149
149
|
};
|
|
150
|
+
readonly extractbench: {
|
|
151
|
+
readonly name: "extractbench";
|
|
152
|
+
readonly description: "ExtractBench is a benchmark for schema-guided data extraction from enterprise documents, scoring schema-valid JSON extraction and evidence grounding without an LLM judge.";
|
|
153
|
+
readonly url: "https://github.com/run-llama/ExtractBench";
|
|
154
|
+
};
|
|
150
155
|
};
|
|
151
156
|
//# sourceMappingURL=eval.d.ts.map
|
package/dist/esm/eval.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../src/eval.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB
|
|
1
|
+
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../src/eval.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4KxB,CAAC"}
|
package/dist/esm/eval.js
CHANGED
|
@@ -147,4 +147,9 @@ export const EVALUATION_FRAMEWORKS = {
|
|
|
147
147
|
description: "MMMU is a new benchmark designed to evaluate multimodal models on massive multi-discipline tasks demanding college-level subject knowledge and deliberate reasoning.",
|
|
148
148
|
url: "https://mmmu-benchmark.github.io/",
|
|
149
149
|
},
|
|
150
|
+
extractbench: {
|
|
151
|
+
name: "extractbench",
|
|
152
|
+
description: "ExtractBench is a benchmark for schema-guided data extraction from enterprise documents, scoring schema-valid JSON extraction and evidence grounding without an LLM judge.",
|
|
153
|
+
url: "https://github.com/run-llama/ExtractBench",
|
|
154
|
+
},
|
|
150
155
|
};
|
package/dist/esm/local-apps.js
CHANGED
|
@@ -390,7 +390,7 @@ const snippetPi = (model, filepath) => {
|
|
|
390
390
|
serverStep,
|
|
391
391
|
{
|
|
392
392
|
title: "Configure the model in Pi",
|
|
393
|
-
setup: "# Install Pi:\nnpm install -g @
|
|
393
|
+
setup: "# Install Pi:\nnpm install -g @earendil-works/pi-coding-agent",
|
|
394
394
|
content: `# Add to ~/.pi/agent/models.json:\n${modelsJson}`,
|
|
395
395
|
},
|
|
396
396
|
{
|
|
@@ -691,7 +691,7 @@ export const LOCAL_APPS = {
|
|
|
691
691
|
},
|
|
692
692
|
pi: {
|
|
693
693
|
prettyLabel: "Pi",
|
|
694
|
-
docsUrl: "https://github.com/
|
|
694
|
+
docsUrl: "https://github.com/earendil-works/pi",
|
|
695
695
|
mainTask: "text-generation",
|
|
696
696
|
displayOnModelPage: isToolCallingLocalAgentModel,
|
|
697
697
|
snippet: snippetPi,
|
|
@@ -120,7 +120,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \\
|
|
|
120
120
|
};
|
|
121
121
|
const snippet = snippetFunc(model);
|
|
122
122
|
expect(snippet[0].content).toContain(`llama serve -hf bartowski/Llama-3.2-3B-Instruct-GGUF:{{QUANT_TAG}}`);
|
|
123
|
-
expect(snippet[1].setup).toContain("npm install -g @
|
|
123
|
+
expect(snippet[1].setup).toContain("npm install -g @earendil-works/pi-coding-agent");
|
|
124
124
|
expect(snippet[1].content).toContain(`"id": "bartowski/Llama-3.2-3B-Instruct-GGUF:{{QUANT_TAG}}"`);
|
|
125
125
|
expect(snippet[2].content).toContain("pi");
|
|
126
126
|
});
|
|
@@ -140,7 +140,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \\
|
|
|
140
140
|
const snippet = snippetFunc(model);
|
|
141
141
|
expect(snippet[0].setup).toContain("uv tool install mlx-lm");
|
|
142
142
|
expect(snippet[0].content).toContain('mlx_lm.server --model "mlx-community/Llama-3.2-3B-Instruct-mlx"');
|
|
143
|
-
expect(snippet[1].setup).toContain("npm install -g @
|
|
143
|
+
expect(snippet[1].setup).toContain("npm install -g @earendil-works/pi-coding-agent");
|
|
144
144
|
expect(snippet[1].content).toContain('"baseUrl": "http://localhost:8080/v1"');
|
|
145
145
|
expect(snippet[1].content).toContain('"id": "mlx-community/Llama-3.2-3B-Instruct-mlx"');
|
|
146
146
|
expect(snippet[2].content).toContain("pi");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-libraries-snippets.d.ts","sourceRoot":"","sources":["../../src/model-libraries-snippets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"model-libraries-snippets.d.ts","sourceRoot":"","sources":["../../src/model-libraries-snippets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAoBjD,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,KAAG,MAAM,EAOjD,CAAC;AAkBF,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,KAAG,MAAM,EAKjD,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,OAAO,SAAS,KAAG,MAAM,EAIhD,CAAC;AAEF,eAAO,MA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MAAM,cAAc,GAAI,OAAO,SAAS,KAAG,MAAM,EAKvD,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,OAAO,SAAS,KAAG,MAAM,EAI9C,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,OAAO,SAAS,KAAG,MAAM,EAiB9C,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,OAAO,SAAS,KAAG,MAAM,EAgD9C,CAAC"}
|
|
@@ -7,11 +7,12 @@ function nameWithoutNamespace(modelId) {
|
|
|
7
7
|
return splitted.length === 1 ? splitted[0] : splitted[1];
|
|
8
8
|
}
|
|
9
9
|
const escapeStringForJson = (str) => JSON.stringify(str).slice(1, -1); // slice is needed to remove surrounding quotes added by JSON.stringify
|
|
10
|
+
const isValidIdentifier = (str) => /^[A-Za-z_]\w*$/.test(str);
|
|
10
11
|
//#region snippets
|
|
11
12
|
export const adapters = (model) => [
|
|
12
13
|
`from adapters import AutoAdapterModel
|
|
13
14
|
|
|
14
|
-
model = AutoAdapterModel.from_pretrained("${model.config?.adapter_transformers?.model_name}")
|
|
15
|
+
model = AutoAdapterModel.from_pretrained("${escapeStringForJson(model.config?.adapter_transformers?.model_name ?? "fill-in-model-name")}")
|
|
15
16
|
model.load_adapter("${model.id}", set_active=True)`,
|
|
16
17
|
];
|
|
17
18
|
const allennlpUnknown = (model) => [
|
|
@@ -63,7 +64,7 @@ result, message = detector.detect_watermark(watermarked_audio, sr)`;
|
|
|
63
64
|
return [watermarkSnippet, detectorSnippet];
|
|
64
65
|
};
|
|
65
66
|
function get_base_diffusers_model(model) {
|
|
66
|
-
return model.cardData?.base_model?.toString() ?? "fill-in-base-model";
|
|
67
|
+
return escapeStringForJson(model.cardData?.base_model?.toString() ?? "fill-in-base-model");
|
|
67
68
|
}
|
|
68
69
|
function get_prompt_from_diffusers_model(model) {
|
|
69
70
|
const prompt = model.widgetData?.[0]?.text ?? model.cardData?.instance_prompt;
|
|
@@ -877,7 +878,8 @@ backbone = keras_hub.models.Backbone.from_preset("hf://${modelId}")
|
|
|
877
878
|
`;
|
|
878
879
|
export const keras_hub = (model) => {
|
|
879
880
|
const modelId = model.id;
|
|
880
|
-
|
|
881
|
+
// interpolated as a Python class name, so a non-identifier is treated as absent
|
|
882
|
+
const tasks = (model.config?.keras_hub?.tasks ?? []).filter(isValidIdentifier);
|
|
881
883
|
const snippets = [];
|
|
882
884
|
// First, generate tasks with examples
|
|
883
885
|
for (const [task, snippet] of Object.entries(_keras_hub_tasks_with_example)) {
|
|
@@ -1170,7 +1172,7 @@ model = MeshAnything(args)`,
|
|
|
1170
1172
|
];
|
|
1171
1173
|
export const multimolecule = (model) => {
|
|
1172
1174
|
const widgetExample = model.widgetData?.[0];
|
|
1173
|
-
const exampleText = widgetExample?.text;
|
|
1175
|
+
const exampleText = escapeStringForJson(widgetExample?.text ?? "");
|
|
1174
1176
|
const maskToken = model.mask_token ?? "<mask>";
|
|
1175
1177
|
const sequence = exampleText?.replace(maskToken, "A");
|
|
1176
1178
|
const snippets = [`pip install multimolecule`];
|
|
@@ -1225,8 +1227,9 @@ openasr transcribe audio.wav --model ${modelId}`,
|
|
|
1225
1227
|
];
|
|
1226
1228
|
};
|
|
1227
1229
|
export const paddlenlp = (model) => {
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
+
const architecture = model.config?.architectures?.[0];
|
|
1231
|
+
// interpolated as a Python class name, so a non-identifier is treated as absent
|
|
1232
|
+
if (architecture && isValidIdentifier(architecture)) {
|
|
1230
1233
|
return [
|
|
1231
1234
|
[
|
|
1232
1235
|
`from paddlenlp.transformers import AutoTokenizer, ${architecture}`,
|
|
@@ -1465,7 +1468,7 @@ const skopsPickle = (model, modelFile) => {
|
|
|
1465
1468
|
from skops.hub_utils import download
|
|
1466
1469
|
download("${model.id}", "path_to_folder")
|
|
1467
1470
|
model = joblib.load(
|
|
1468
|
-
"${modelFile}"
|
|
1471
|
+
"${escapeStringForJson(modelFile)}"
|
|
1469
1472
|
)
|
|
1470
1473
|
# only load pickle files from sources you trust
|
|
1471
1474
|
# read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
|
|
@@ -1478,7 +1481,7 @@ from skops.io import load
|
|
|
1478
1481
|
download("${model.id}", "path_to_folder")
|
|
1479
1482
|
# make sure model file is in skops format
|
|
1480
1483
|
# if model is a pickle file, make sure it's from a source you trust
|
|
1481
|
-
model = load("path_to_folder/${modelFile}")`,
|
|
1484
|
+
model = load("path_to_folder/${escapeStringForJson(modelFile)}")`,
|
|
1482
1485
|
];
|
|
1483
1486
|
};
|
|
1484
1487
|
const skopsJobLib = (model) => {
|
|
@@ -1731,11 +1734,17 @@ model = BACKBONE_REGISTRY.build("${model.id}")`,
|
|
|
1731
1734
|
const hasChatTemplate = (model) => model.config?.tokenizer_config?.chat_template !== undefined ||
|
|
1732
1735
|
model.config?.processor_config?.chat_template !== undefined ||
|
|
1733
1736
|
model.config?.chat_template_jinja !== undefined;
|
|
1737
|
+
// interpolated as a Python class name (and into RegExps in pruna_transformers), so a non-identifier is treated as absent
|
|
1738
|
+
const autoModelClass = (model) => {
|
|
1739
|
+
const autoModel = model.transformersInfo?.auto_model;
|
|
1740
|
+
return autoModel && isValidIdentifier(autoModel) ? autoModel : undefined;
|
|
1741
|
+
};
|
|
1734
1742
|
export const transformers = (model) => {
|
|
1735
1743
|
const info = model.transformersInfo;
|
|
1736
1744
|
if (!info) {
|
|
1737
1745
|
return [`# ⚠️ Type of model unknown`];
|
|
1738
1746
|
}
|
|
1747
|
+
const auto_model = autoModelClass(model) ?? "AutoModel";
|
|
1739
1748
|
const remote_code_snippet = model.tags.includes(TAG_CUSTOM_CODE) ? ", trust_remote_code=True" : "";
|
|
1740
1749
|
const autoSnippet = [];
|
|
1741
1750
|
if (info.processor) {
|
|
@@ -1744,7 +1753,7 @@ export const transformers = (model) => {
|
|
|
1744
1753
|
: info.processor === "AutoFeatureExtractor"
|
|
1745
1754
|
? "extractor"
|
|
1746
1755
|
: "processor";
|
|
1747
|
-
autoSnippet.push("# Load model directly", `from transformers import ${info.processor}, ${
|
|
1756
|
+
autoSnippet.push("# Load model directly", `from transformers import ${info.processor}, ${auto_model}`, "", `${processorVarName} = ${info.processor}.from_pretrained("${model.id}"` + remote_code_snippet + ")", `model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")');
|
|
1748
1757
|
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
|
|
1749
1758
|
if (model.tags.includes("image-text-to-text")) {
|
|
1750
1759
|
autoSnippet.push("messages = [", [
|
|
@@ -1764,7 +1773,7 @@ export const transformers = (model) => {
|
|
|
1764
1773
|
}
|
|
1765
1774
|
}
|
|
1766
1775
|
else {
|
|
1767
|
-
autoSnippet.push("# Load model directly", `from transformers import ${
|
|
1776
|
+
autoSnippet.push("# Load model directly", `from transformers import ${auto_model}`, `model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")');
|
|
1768
1777
|
}
|
|
1769
1778
|
if (model.pipeline_tag && LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
|
|
1770
1779
|
const pipelineSnippet = ["# Use a pipeline as a high-level helper"];
|
|
@@ -1840,7 +1849,7 @@ export const peft = (model) => {
|
|
|
1840
1849
|
`from peft import PeftModel
|
|
1841
1850
|
from transformers import AutoModelFor${pefttask}
|
|
1842
1851
|
|
|
1843
|
-
base_model = AutoModelFor${pefttask}.from_pretrained("${peftBaseModel}")
|
|
1852
|
+
base_model = AutoModelFor${pefttask}.from_pretrained("${escapeStringForJson(peftBaseModel)}")
|
|
1844
1853
|
model = PeftModel.from_pretrained(base_model, "${model.id}")`,
|
|
1845
1854
|
];
|
|
1846
1855
|
};
|
|
@@ -2230,18 +2239,18 @@ const pruna_diffusers = (model) => {
|
|
|
2230
2239
|
.trim());
|
|
2231
2240
|
};
|
|
2232
2241
|
const pruna_transformers = (model) => {
|
|
2233
|
-
const
|
|
2242
|
+
const auto_model = autoModelClass(model);
|
|
2234
2243
|
const transformersSnippets = transformers(model);
|
|
2235
2244
|
// Replace pipeline with PrunaModel
|
|
2236
2245
|
let processedSnippets = transformersSnippets.map((snippet) => snippet
|
|
2237
2246
|
.replace(/from transformers import pipeline/g, "from pruna import PrunaModel")
|
|
2238
2247
|
.replace(/pipeline\([^)]*\)/g, `PrunaModel.from_pretrained("${model.id}")`));
|
|
2239
2248
|
// Additional cleanup if auto_model info is available
|
|
2240
|
-
if (
|
|
2249
|
+
if (auto_model) {
|
|
2241
2250
|
processedSnippets = processedSnippets.map((snippet) => snippet
|
|
2242
|
-
.replace(new RegExp(`from transformers import ${
|
|
2243
|
-
.replace(new RegExp(`${
|
|
2244
|
-
.replace(new RegExp(`^.*from.*import.*(, *${
|
|
2251
|
+
.replace(new RegExp(`from transformers import ${auto_model}\n?`, "g"), "")
|
|
2252
|
+
.replace(new RegExp(`${auto_model}.from_pretrained`, "g"), "PrunaModel.from_pretrained")
|
|
2253
|
+
.replace(new RegExp(`^.*from.*import.*(, *${auto_model})+.*$`, "gm"), (line) => line.replace(new RegExp(`, *${auto_model}`, "g"), "")));
|
|
2245
2254
|
}
|
|
2246
2255
|
return processedSnippets;
|
|
2247
2256
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { llama_cpp_python } from "./model-libraries-snippets.js";
|
|
2
|
+
import { adapters, diffusers, keras_hub, llama_cpp_python, multimolecule, paddlenlp, peft, sklearn, transformers, } from "./model-libraries-snippets.js";
|
|
3
3
|
describe("model-libraries-snippets", () => {
|
|
4
4
|
it("llama_cpp_python conversational", async () => {
|
|
5
5
|
const model = {
|
|
@@ -50,4 +50,35 @@ output = llm(
|
|
|
50
50
|
)
|
|
51
51
|
print(output)`);
|
|
52
52
|
});
|
|
53
|
+
// a repo owner can put anything in config.json / the model card, so every interpolated value
|
|
54
|
+
// must either be escaped (string literals) or rejected (bare identifiers)
|
|
55
|
+
describe("repo-controlled values are not injectable", () => {
|
|
56
|
+
const PAYLOAD = `")\nimport os; os.system("id`;
|
|
57
|
+
it.each([
|
|
58
|
+
["adapters", adapters, { config: { adapter_transformers: { model_name: PAYLOAD } } }],
|
|
59
|
+
["diffusers", diffusers, { tags: ["lora"], cardData: { base_model: PAYLOAD, instance_prompt: PAYLOAD } }],
|
|
60
|
+
["keras_hub", keras_hub, { config: { keras_hub: { tasks: [PAYLOAD, "TextClassifier"] } } }],
|
|
61
|
+
["paddlenlp", paddlenlp, { config: { architectures: [PAYLOAD] } }],
|
|
62
|
+
["peft", peft, { config: { peft: { base_model_name_or_path: PAYLOAD, task_type: "CAUSAL_LM" } } }],
|
|
63
|
+
["multimolecule", multimolecule, { widgetData: [{ text: PAYLOAD }] }],
|
|
64
|
+
["transformers", transformers, { transformersInfo: { auto_model: PAYLOAD, processor: "AutoTokenizer" } }],
|
|
65
|
+
[
|
|
66
|
+
"sklearn",
|
|
67
|
+
sklearn,
|
|
68
|
+
{ tags: ["skops"], config: { sklearn: { model: { file: PAYLOAD }, model_format: "pickle" } } },
|
|
69
|
+
],
|
|
70
|
+
])("%s", (_name, snippetFn, model) => {
|
|
71
|
+
const snippet = snippetFn({ id: "user/model", tags: [], inference: "", ...model }).join("\n");
|
|
72
|
+
expect(snippet).not.toContain(PAYLOAD);
|
|
73
|
+
});
|
|
74
|
+
it("keras_hub keeps the valid task next to a rejected one", () => {
|
|
75
|
+
const model = {
|
|
76
|
+
id: "user/model",
|
|
77
|
+
tags: [],
|
|
78
|
+
inference: "",
|
|
79
|
+
config: { keras_hub: { tasks: [PAYLOAD, "TextClassifier"] } },
|
|
80
|
+
};
|
|
81
|
+
expect(keras_hub(model).join("\n")).toContain("keras_hub.models.TextClassifier.from_preset");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
53
84
|
});
|
package/package.json
CHANGED
package/src/eval.ts
CHANGED
|
@@ -167,4 +167,10 @@ export const EVALUATION_FRAMEWORKS = {
|
|
|
167
167
|
"MMMU is a new benchmark designed to evaluate multimodal models on massive multi-discipline tasks demanding college-level subject knowledge and deliberate reasoning.",
|
|
168
168
|
url: "https://mmmu-benchmark.github.io/",
|
|
169
169
|
},
|
|
170
|
+
extractbench: {
|
|
171
|
+
name: "extractbench",
|
|
172
|
+
description:
|
|
173
|
+
"ExtractBench is a benchmark for schema-guided data extraction from enterprise documents, scoring schema-valid JSON extraction and evidence grounding without an LLM judge.",
|
|
174
|
+
url: "https://github.com/run-llama/ExtractBench",
|
|
175
|
+
},
|
|
170
176
|
} as const;
|
package/src/local-apps.spec.ts
CHANGED
|
@@ -133,7 +133,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \\
|
|
|
133
133
|
const snippet = snippetFunc(model);
|
|
134
134
|
|
|
135
135
|
expect(snippet[0].content).toContain(`llama serve -hf bartowski/Llama-3.2-3B-Instruct-GGUF:{{QUANT_TAG}}`);
|
|
136
|
-
expect(snippet[1].setup).toContain("npm install -g @
|
|
136
|
+
expect(snippet[1].setup).toContain("npm install -g @earendil-works/pi-coding-agent");
|
|
137
137
|
expect(snippet[1].content).toContain(`"id": "bartowski/Llama-3.2-3B-Instruct-GGUF:{{QUANT_TAG}}"`);
|
|
138
138
|
expect(snippet[2].content).toContain("pi");
|
|
139
139
|
});
|
|
@@ -155,7 +155,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \\
|
|
|
155
155
|
|
|
156
156
|
expect(snippet[0].setup).toContain("uv tool install mlx-lm");
|
|
157
157
|
expect(snippet[0].content).toContain('mlx_lm.server --model "mlx-community/Llama-3.2-3B-Instruct-mlx"');
|
|
158
|
-
expect(snippet[1].setup).toContain("npm install -g @
|
|
158
|
+
expect(snippet[1].setup).toContain("npm install -g @earendil-works/pi-coding-agent");
|
|
159
159
|
expect(snippet[1].content).toContain('"baseUrl": "http://localhost:8080/v1"');
|
|
160
160
|
expect(snippet[1].content).toContain('"id": "mlx-community/Llama-3.2-3B-Instruct-mlx"');
|
|
161
161
|
expect(snippet[2].content).toContain("pi");
|
package/src/local-apps.ts
CHANGED
|
@@ -509,7 +509,7 @@ const snippetPi = (model: ModelData, filepath?: string): LocalAppSnippet[] => {
|
|
|
509
509
|
serverStep,
|
|
510
510
|
{
|
|
511
511
|
title: "Configure the model in Pi",
|
|
512
|
-
setup: "# Install Pi:\nnpm install -g @
|
|
512
|
+
setup: "# Install Pi:\nnpm install -g @earendil-works/pi-coding-agent",
|
|
513
513
|
content: `# Add to ~/.pi/agent/models.json:\n${modelsJson}`,
|
|
514
514
|
},
|
|
515
515
|
{
|
|
@@ -820,7 +820,7 @@ export const LOCAL_APPS = {
|
|
|
820
820
|
},
|
|
821
821
|
pi: {
|
|
822
822
|
prettyLabel: "Pi",
|
|
823
|
-
docsUrl: "https://github.com/
|
|
823
|
+
docsUrl: "https://github.com/earendil-works/pi",
|
|
824
824
|
mainTask: "text-generation",
|
|
825
825
|
displayOnModelPage: isToolCallingLocalAgentModel,
|
|
826
826
|
snippet: snippetPi,
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import type { ModelData } from "./model-data.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
adapters,
|
|
5
|
+
diffusers,
|
|
6
|
+
keras_hub,
|
|
7
|
+
llama_cpp_python,
|
|
8
|
+
multimolecule,
|
|
9
|
+
paddlenlp,
|
|
10
|
+
peft,
|
|
11
|
+
sklearn,
|
|
12
|
+
transformers,
|
|
13
|
+
} from "./model-libraries-snippets.js";
|
|
4
14
|
|
|
5
15
|
describe("model-libraries-snippets", () => {
|
|
6
16
|
it("llama_cpp_python conversational", async () => {
|
|
@@ -55,4 +65,39 @@ output = llm(
|
|
|
55
65
|
)
|
|
56
66
|
print(output)`);
|
|
57
67
|
});
|
|
68
|
+
|
|
69
|
+
// a repo owner can put anything in config.json / the model card, so every interpolated value
|
|
70
|
+
// must either be escaped (string literals) or rejected (bare identifiers)
|
|
71
|
+
describe("repo-controlled values are not injectable", () => {
|
|
72
|
+
const PAYLOAD = `")\nimport os; os.system("id`;
|
|
73
|
+
|
|
74
|
+
it.each([
|
|
75
|
+
["adapters", adapters, { config: { adapter_transformers: { model_name: PAYLOAD } } }],
|
|
76
|
+
["diffusers", diffusers, { tags: ["lora"], cardData: { base_model: PAYLOAD, instance_prompt: PAYLOAD } }],
|
|
77
|
+
["keras_hub", keras_hub, { config: { keras_hub: { tasks: [PAYLOAD, "TextClassifier"] } } }],
|
|
78
|
+
["paddlenlp", paddlenlp, { config: { architectures: [PAYLOAD] } }],
|
|
79
|
+
["peft", peft, { config: { peft: { base_model_name_or_path: PAYLOAD, task_type: "CAUSAL_LM" } } }],
|
|
80
|
+
["multimolecule", multimolecule, { widgetData: [{ text: PAYLOAD }] }],
|
|
81
|
+
["transformers", transformers, { transformersInfo: { auto_model: PAYLOAD, processor: "AutoTokenizer" } }],
|
|
82
|
+
[
|
|
83
|
+
"sklearn",
|
|
84
|
+
sklearn,
|
|
85
|
+
{ tags: ["skops"], config: { sklearn: { model: { file: PAYLOAD }, model_format: "pickle" } } },
|
|
86
|
+
],
|
|
87
|
+
])("%s", (_name, snippetFn, model) => {
|
|
88
|
+
const snippet = snippetFn({ id: "user/model", tags: [], inference: "", ...model } as ModelData).join("\n");
|
|
89
|
+
|
|
90
|
+
expect(snippet).not.toContain(PAYLOAD);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("keras_hub keeps the valid task next to a rejected one", () => {
|
|
94
|
+
const model = {
|
|
95
|
+
id: "user/model",
|
|
96
|
+
tags: [],
|
|
97
|
+
inference: "",
|
|
98
|
+
config: { keras_hub: { tasks: [PAYLOAD, "TextClassifier"] } },
|
|
99
|
+
};
|
|
100
|
+
expect(keras_hub(model as ModelData).join("\n")).toContain("keras_hub.models.TextClassifier.from_preset");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
58
103
|
});
|
|
@@ -14,12 +14,16 @@ function nameWithoutNamespace(modelId: string): string {
|
|
|
14
14
|
|
|
15
15
|
const escapeStringForJson = (str: string): string => JSON.stringify(str).slice(1, -1); // slice is needed to remove surrounding quotes added by JSON.stringify
|
|
16
16
|
|
|
17
|
+
const isValidIdentifier = (str: string): boolean => /^[A-Za-z_]\w*$/.test(str);
|
|
18
|
+
|
|
17
19
|
//#region snippets
|
|
18
20
|
|
|
19
21
|
export const adapters = (model: ModelData): string[] => [
|
|
20
22
|
`from adapters import AutoAdapterModel
|
|
21
23
|
|
|
22
|
-
model = AutoAdapterModel.from_pretrained("${
|
|
24
|
+
model = AutoAdapterModel.from_pretrained("${escapeStringForJson(
|
|
25
|
+
model.config?.adapter_transformers?.model_name ?? "fill-in-model-name",
|
|
26
|
+
)}")
|
|
23
27
|
model.load_adapter("${model.id}", set_active=True)`,
|
|
24
28
|
];
|
|
25
29
|
|
|
@@ -79,7 +83,7 @@ result, message = detector.detect_watermark(watermarked_audio, sr)`;
|
|
|
79
83
|
};
|
|
80
84
|
|
|
81
85
|
function get_base_diffusers_model(model: ModelData): string {
|
|
82
|
-
return model.cardData?.base_model?.toString() ?? "fill-in-base-model";
|
|
86
|
+
return escapeStringForJson(model.cardData?.base_model?.toString() ?? "fill-in-base-model");
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
function get_prompt_from_diffusers_model(model: ModelData): string | undefined {
|
|
@@ -957,7 +961,8 @@ backbone = keras_hub.models.Backbone.from_preset("hf://${modelId}")
|
|
|
957
961
|
|
|
958
962
|
export const keras_hub = (model: ModelData): string[] => {
|
|
959
963
|
const modelId = model.id;
|
|
960
|
-
|
|
964
|
+
// interpolated as a Python class name, so a non-identifier is treated as absent
|
|
965
|
+
const tasks = (model.config?.keras_hub?.tasks ?? []).filter(isValidIdentifier);
|
|
961
966
|
|
|
962
967
|
const snippets: string[] = [];
|
|
963
968
|
|
|
@@ -1275,7 +1280,7 @@ model = MeshAnything(args)`,
|
|
|
1275
1280
|
|
|
1276
1281
|
export const multimolecule = (model: ModelData): string[] => {
|
|
1277
1282
|
const widgetExample = model.widgetData?.[0] as WidgetExampleTextInput | undefined;
|
|
1278
|
-
const exampleText = widgetExample?.text;
|
|
1283
|
+
const exampleText = escapeStringForJson(widgetExample?.text ?? "");
|
|
1279
1284
|
const maskToken = model.mask_token ?? "<mask>";
|
|
1280
1285
|
const sequence = exampleText?.replace(maskToken, "A");
|
|
1281
1286
|
|
|
@@ -1343,8 +1348,9 @@ openasr transcribe audio.wav --model ${modelId}`,
|
|
|
1343
1348
|
};
|
|
1344
1349
|
|
|
1345
1350
|
export const paddlenlp = (model: ModelData): string[] => {
|
|
1346
|
-
|
|
1347
|
-
|
|
1351
|
+
const architecture = model.config?.architectures?.[0];
|
|
1352
|
+
// interpolated as a Python class name, so a non-identifier is treated as absent
|
|
1353
|
+
if (architecture && isValidIdentifier(architecture)) {
|
|
1348
1354
|
return [
|
|
1349
1355
|
[
|
|
1350
1356
|
`from paddlenlp.transformers import AutoTokenizer, ${architecture}`,
|
|
@@ -1602,7 +1608,7 @@ const skopsPickle = (model: ModelData, modelFile: string) => {
|
|
|
1602
1608
|
from skops.hub_utils import download
|
|
1603
1609
|
download("${model.id}", "path_to_folder")
|
|
1604
1610
|
model = joblib.load(
|
|
1605
|
-
"${modelFile}"
|
|
1611
|
+
"${escapeStringForJson(modelFile)}"
|
|
1606
1612
|
)
|
|
1607
1613
|
# only load pickle files from sources you trust
|
|
1608
1614
|
# read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
|
|
@@ -1616,7 +1622,7 @@ from skops.io import load
|
|
|
1616
1622
|
download("${model.id}", "path_to_folder")
|
|
1617
1623
|
# make sure model file is in skops format
|
|
1618
1624
|
# if model is a pickle file, make sure it's from a source you trust
|
|
1619
|
-
model = load("path_to_folder/${modelFile}")`,
|
|
1625
|
+
model = load("path_to_folder/${escapeStringForJson(modelFile)}")`,
|
|
1620
1626
|
];
|
|
1621
1627
|
};
|
|
1622
1628
|
|
|
@@ -1894,11 +1900,18 @@ const hasChatTemplate = (model: ModelData): boolean =>
|
|
|
1894
1900
|
model.config?.processor_config?.chat_template !== undefined ||
|
|
1895
1901
|
model.config?.chat_template_jinja !== undefined;
|
|
1896
1902
|
|
|
1903
|
+
// interpolated as a Python class name (and into RegExps in pruna_transformers), so a non-identifier is treated as absent
|
|
1904
|
+
const autoModelClass = (model: ModelData): string | undefined => {
|
|
1905
|
+
const autoModel = model.transformersInfo?.auto_model;
|
|
1906
|
+
return autoModel && isValidIdentifier(autoModel) ? autoModel : undefined;
|
|
1907
|
+
};
|
|
1908
|
+
|
|
1897
1909
|
export const transformers = (model: ModelData): string[] => {
|
|
1898
1910
|
const info = model.transformersInfo;
|
|
1899
1911
|
if (!info) {
|
|
1900
1912
|
return [`# ⚠️ Type of model unknown`];
|
|
1901
1913
|
}
|
|
1914
|
+
const auto_model = autoModelClass(model) ?? "AutoModel";
|
|
1902
1915
|
const remote_code_snippet = model.tags.includes(TAG_CUSTOM_CODE) ? ", trust_remote_code=True" : "";
|
|
1903
1916
|
|
|
1904
1917
|
const autoSnippet = [];
|
|
@@ -1911,10 +1924,10 @@ export const transformers = (model: ModelData): string[] => {
|
|
|
1911
1924
|
: "processor";
|
|
1912
1925
|
autoSnippet.push(
|
|
1913
1926
|
"# Load model directly",
|
|
1914
|
-
`from transformers import ${info.processor}, ${
|
|
1927
|
+
`from transformers import ${info.processor}, ${auto_model}`,
|
|
1915
1928
|
"",
|
|
1916
1929
|
`${processorVarName} = ${info.processor}.from_pretrained("${model.id}"` + remote_code_snippet + ")",
|
|
1917
|
-
`model = ${
|
|
1930
|
+
`model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")',
|
|
1918
1931
|
);
|
|
1919
1932
|
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
|
|
1920
1933
|
if (model.tags.includes("image-text-to-text")) {
|
|
@@ -1950,8 +1963,8 @@ export const transformers = (model: ModelData): string[] => {
|
|
|
1950
1963
|
} else {
|
|
1951
1964
|
autoSnippet.push(
|
|
1952
1965
|
"# Load model directly",
|
|
1953
|
-
`from transformers import ${
|
|
1954
|
-
`model = ${
|
|
1966
|
+
`from transformers import ${auto_model}`,
|
|
1967
|
+
`model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")',
|
|
1955
1968
|
);
|
|
1956
1969
|
}
|
|
1957
1970
|
|
|
@@ -2054,7 +2067,7 @@ export const peft = (model: ModelData): string[] => {
|
|
|
2054
2067
|
`from peft import PeftModel
|
|
2055
2068
|
from transformers import AutoModelFor${pefttask}
|
|
2056
2069
|
|
|
2057
|
-
base_model = AutoModelFor${pefttask}.from_pretrained("${peftBaseModel}")
|
|
2070
|
+
base_model = AutoModelFor${pefttask}.from_pretrained("${escapeStringForJson(peftBaseModel)}")
|
|
2058
2071
|
model = PeftModel.from_pretrained(base_model, "${model.id}")`,
|
|
2059
2072
|
];
|
|
2060
2073
|
};
|
|
@@ -2485,7 +2498,7 @@ const pruna_diffusers = (model: ModelData): string[] => {
|
|
|
2485
2498
|
};
|
|
2486
2499
|
|
|
2487
2500
|
const pruna_transformers = (model: ModelData): string[] => {
|
|
2488
|
-
const
|
|
2501
|
+
const auto_model = autoModelClass(model);
|
|
2489
2502
|
const transformersSnippets = transformers(model);
|
|
2490
2503
|
|
|
2491
2504
|
// Replace pipeline with PrunaModel
|
|
@@ -2496,13 +2509,13 @@ const pruna_transformers = (model: ModelData): string[] => {
|
|
|
2496
2509
|
);
|
|
2497
2510
|
|
|
2498
2511
|
// Additional cleanup if auto_model info is available
|
|
2499
|
-
if (
|
|
2512
|
+
if (auto_model) {
|
|
2500
2513
|
processedSnippets = processedSnippets.map((snippet) =>
|
|
2501
2514
|
snippet
|
|
2502
|
-
.replace(new RegExp(`from transformers import ${
|
|
2503
|
-
.replace(new RegExp(`${
|
|
2504
|
-
.replace(new RegExp(`^.*from.*import.*(, *${
|
|
2505
|
-
line.replace(new RegExp(`, *${
|
|
2515
|
+
.replace(new RegExp(`from transformers import ${auto_model}\n?`, "g"), "")
|
|
2516
|
+
.replace(new RegExp(`${auto_model}.from_pretrained`, "g"), "PrunaModel.from_pretrained")
|
|
2517
|
+
.replace(new RegExp(`^.*from.*import.*(, *${auto_model})+.*$`, "gm"), (line) =>
|
|
2518
|
+
line.replace(new RegExp(`, *${auto_model}`, "g"), ""),
|
|
2506
2519
|
),
|
|
2507
2520
|
);
|
|
2508
2521
|
}
|