@huggingface/tasks 0.21.35 → 0.21.37
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/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 +220 -69
- package/dist/commonjs/model-libraries-snippets.spec.js +31 -0
- package/dist/commonjs/model-libraries.js +1 -1
- 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 +220 -69
- package/dist/esm/model-libraries-snippets.spec.js +32 -1
- package/dist/esm/model-libraries.js +1 -1
- package/package.json +1 -1
- 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 +290 -72
- package/src/model-libraries.ts +1 -1
|
@@ -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
|
|
|
@@ -1031,83 +1036,288 @@ import soundfile as sf
|
|
|
1031
1036
|
sf.write('output.wav', audio, 24000)`,
|
|
1032
1037
|
];
|
|
1033
1038
|
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1039
|
+
/**
|
|
1040
|
+
* Detect LTX-2.5 (split weights + Gemma 4 TE file) vs LTX-2.3
|
|
1041
|
+
* (monolith checkpoint + separate Gemma 3 root). Prefer explicit tags / ids /
|
|
1042
|
+
* base_model refs; fall back to 2.3 for unmarked legacy cards.
|
|
1043
|
+
*/
|
|
1044
|
+
function _isLtx25Model(model: ModelData): boolean {
|
|
1045
|
+
const refs: string[] = [model.id, ...(model.tags ?? [])];
|
|
1046
|
+
const base = model.cardData?.base_model;
|
|
1047
|
+
if (Array.isArray(base)) {
|
|
1048
|
+
refs.push(...base);
|
|
1049
|
+
} else if (base) {
|
|
1050
|
+
refs.push(base);
|
|
1051
|
+
}
|
|
1052
|
+
return refs.some((ref) => /ltx[-_]?2\.5/i.test(ref));
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
const _LTX_I2V_HINT = `# For image-to-video, add: --image path/to/image.jpg 0 0.8`;
|
|
1056
|
+
const _LTX_GEMMA3_ROOT = "models/gemma-3-12b";
|
|
1057
|
+
const _LTX_DEFAULT_PROMPT = "A beautiful sunset over the ocean";
|
|
1058
|
+
|
|
1059
|
+
function _ltxInstall(is25: boolean): string {
|
|
1060
|
+
// natten is only needed for the LTX-2.5 diffusion VAE (skipped automatically on Windows/macOS).
|
|
1061
|
+
return `# Install the LTX-2 pipelines
|
|
1037
1062
|
git clone https://github.com/Lightricks/LTX-2.git
|
|
1038
1063
|
cd LTX-2
|
|
1039
|
-
uv sync --frozen`;
|
|
1064
|
+
uv sync ${is25 ? "--extra natten" : "--frozen"}`;
|
|
1065
|
+
}
|
|
1040
1066
|
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1067
|
+
function _ltxRun(
|
|
1068
|
+
module: string,
|
|
1069
|
+
args: string[],
|
|
1070
|
+
comment: string,
|
|
1071
|
+
options?: { hint?: boolean; footer?: string },
|
|
1072
|
+
): string {
|
|
1073
|
+
const body = `uv run python -m ltx_pipelines.${module} \\\n ${args.join(" \\\n ")}`;
|
|
1074
|
+
const parts = [`# ${comment}`, body];
|
|
1075
|
+
if (options?.footer) {
|
|
1076
|
+
parts.push(options.footer);
|
|
1077
|
+
}
|
|
1078
|
+
if (options?.hint) {
|
|
1079
|
+
parts.push(_LTX_I2V_HINT);
|
|
1080
|
+
}
|
|
1081
|
+
return parts.join("\n");
|
|
1082
|
+
}
|
|
1045
1083
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1084
|
+
interface Ltx25SplitPaths {
|
|
1085
|
+
transformer: string;
|
|
1086
|
+
textEncoder: string;
|
|
1087
|
+
videoVae: string;
|
|
1088
|
+
audioVae: string;
|
|
1089
|
+
spatialUpsampler: string;
|
|
1090
|
+
temporalUpsampler?: string;
|
|
1091
|
+
}
|
|
1049
1092
|
|
|
1050
|
-
|
|
1093
|
+
const _LTX_DETAILING_LORA_REPO = "Lightricks/LTX-2.5-22b-IC-LoRA-Pixel-Spatial-Upscaler";
|
|
1094
|
+
const _LTX_DETAILING_LORA_FILE = "ltx-2.5-22b-ic-lora-pixel-spatial-upscaler-x2-1.0.safetensors";
|
|
1095
|
+
|
|
1096
|
+
function _ltx25SplitArgs(paths: Ltx25SplitPaths): string[] {
|
|
1097
|
+
const args = [
|
|
1098
|
+
`--transformer-path ${paths.transformer}`,
|
|
1099
|
+
`--text-encoder-path ${paths.textEncoder}`,
|
|
1100
|
+
`--video-vae-path ${paths.videoVae}`,
|
|
1101
|
+
`--audio-vae-path ${paths.audioVae}`,
|
|
1102
|
+
`--spatial-upsampler-path ${paths.spatialUpsampler}`,
|
|
1103
|
+
];
|
|
1104
|
+
if (paths.temporalUpsampler) {
|
|
1105
|
+
args.push(`--temporal-upsampler-path ${paths.temporalUpsampler}`);
|
|
1106
|
+
}
|
|
1107
|
+
return args;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
function _ltx25RepoPaths(localDir: string): { distilled: Ltx25SplitPaths; dfr: Ltx25SplitPaths } {
|
|
1111
|
+
const shared = {
|
|
1112
|
+
transformer: `${localDir}/diffusion_models/<distilled-transformer>.safetensors`,
|
|
1113
|
+
textEncoder: `${localDir}/text_encoders/gemma4-12b-with-proj-ltx-2.5-bf16.safetensors`,
|
|
1114
|
+
videoVae: `${localDir}/vae/<video-vae>.safetensors`,
|
|
1115
|
+
audioVae: `${localDir}/vae/<audio-vae>.safetensors`,
|
|
1116
|
+
spatialUpsampler: `${localDir}/latent_upscale_models/<spatial-upsampler>.safetensors`,
|
|
1117
|
+
};
|
|
1118
|
+
return {
|
|
1119
|
+
distilled: shared,
|
|
1120
|
+
// DFR runs on the distilled transformer; detailing IC-LoRA is required separately.
|
|
1121
|
+
dfr: {
|
|
1122
|
+
...shared,
|
|
1123
|
+
temporalUpsampler: `${localDir}/latent_upscale_models/<temporal-upsampler>.safetensors`,
|
|
1124
|
+
},
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
function _ltx25BasePlaceholderPaths(): Ltx25SplitPaths {
|
|
1129
|
+
return {
|
|
1130
|
+
transformer: "path/to/distilled-transformer.safetensors",
|
|
1131
|
+
textEncoder: "path/to/gemma4-12b-with-proj-ltx-2.5-bf16.safetensors",
|
|
1132
|
+
videoVae: "path/to/video-vae.safetensors",
|
|
1133
|
+
audioVae: "path/to/audio-vae.safetensors",
|
|
1134
|
+
spatialUpsampler: "path/to/spatial-upsampler.safetensors",
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
function _ltx25Download(modelId: string, localDir: string, kind: "base" | "adapter"): string {
|
|
1139
|
+
if (kind === "adapter") {
|
|
1140
|
+
return `# Download the adapter weights from this repo
|
|
1141
|
+
# (base components come from Lightricks/LTX-2.5 — see Files and versions)
|
|
1142
|
+
hf download ${modelId} --local-dir ${localDir}`;
|
|
1143
|
+
}
|
|
1144
|
+
const detailingDir = `models/${_LTX_DETAILING_LORA_REPO.split("/")[1]}`;
|
|
1145
|
+
return `# Download weights from this repo
|
|
1146
|
+
# Substitute filenames from this repo's "Files and versions" if they differ
|
|
1147
|
+
hf download ${modelId} \\
|
|
1148
|
+
diffusion_models/<distilled-transformer>.safetensors \\
|
|
1149
|
+
text_encoders/gemma4-12b-with-proj-ltx-2.5-bf16.safetensors \\
|
|
1150
|
+
vae/<video-vae>.safetensors \\
|
|
1151
|
+
vae/<audio-vae>.safetensors \\
|
|
1152
|
+
latent_upscale_models/<spatial-upsampler>.safetensors \\
|
|
1153
|
+
latent_upscale_models/<temporal-upsampler>.safetensors \\
|
|
1154
|
+
--local-dir ${localDir}
|
|
1155
|
+
# DFR requires the detailing IC-LoRA (separate repo; strength is fixed at 0.5)
|
|
1156
|
+
hf download ${_LTX_DETAILING_LORA_REPO} --local-dir ${detailingDir}`;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
function _ltx23Download(modelId: string, localDir: string): string {
|
|
1160
|
+
return `# Download the weights from this repo, plus the Gemma text encoder
|
|
1161
|
+
hf download ${modelId} --local-dir ${localDir}
|
|
1162
|
+
hf download google/gemma-3-12b-it-qat-q4_0-unquantized --local-dir ${_LTX_GEMMA3_ROOT}`;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
function _ltx25Snippets(model: ModelData, localDir: string, tags: string[]): string[] {
|
|
1166
|
+
const install = _ltxInstall(true);
|
|
1167
|
+
const loraArg = `--lora ${localDir}/<weights>.safetensors 1.0`;
|
|
1168
|
+
const basePaths = _ltx25BasePlaceholderPaths();
|
|
1169
|
+
|
|
1170
|
+
if (tags.includes("ic-lora")) {
|
|
1171
|
+
return [
|
|
1172
|
+
install,
|
|
1173
|
+
_ltx25Download(model.id, localDir, "adapter"),
|
|
1174
|
+
_ltxRun(
|
|
1175
|
+
"ic_lora",
|
|
1176
|
+
[
|
|
1177
|
+
..._ltx25SplitArgs(basePaths),
|
|
1178
|
+
loraArg,
|
|
1179
|
+
"--video-conditioning reference.mp4 1.0",
|
|
1180
|
+
`--prompt "your prompt here"`,
|
|
1181
|
+
"--output-path output.mp4",
|
|
1182
|
+
],
|
|
1183
|
+
"Video-to-video with the IC-LoRA (runs on the distilled LTX-2.5 base)",
|
|
1184
|
+
),
|
|
1185
|
+
];
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
if (tags.includes("lora")) {
|
|
1189
|
+
return [
|
|
1190
|
+
install,
|
|
1191
|
+
_ltx25Download(model.id, localDir, "adapter"),
|
|
1192
|
+
_ltxRun(
|
|
1193
|
+
"distilled",
|
|
1194
|
+
[..._ltx25SplitArgs(basePaths), loraArg, `--prompt "your prompt here"`, "--output-path output.mp4"],
|
|
1195
|
+
"Text/image-to-video with the LoRA on the distilled LTX-2.5 pipeline",
|
|
1196
|
+
{ hint: true },
|
|
1197
|
+
),
|
|
1198
|
+
];
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
const { distilled, dfr } = _ltx25RepoPaths(localDir);
|
|
1202
|
+
const detailingDir = `models/${_LTX_DETAILING_LORA_REPO.split("/")[1]}`;
|
|
1203
|
+
return [
|
|
1204
|
+
install,
|
|
1205
|
+
_ltx25Download(model.id, localDir, "base"),
|
|
1206
|
+
_ltxRun(
|
|
1207
|
+
"distilled",
|
|
1208
|
+
[
|
|
1209
|
+
..._ltx25SplitArgs(distilled),
|
|
1210
|
+
"--num-frames 121",
|
|
1211
|
+
`--prompt "${_LTX_DEFAULT_PROMPT}"`,
|
|
1212
|
+
"--output-path output.mp4",
|
|
1213
|
+
],
|
|
1214
|
+
"Distilled LTX-2.5 pipeline (fast)",
|
|
1215
|
+
{ hint: true },
|
|
1216
|
+
),
|
|
1217
|
+
_ltxRun(
|
|
1218
|
+
"dfr_pipeline",
|
|
1219
|
+
[
|
|
1220
|
+
..._ltx25SplitArgs(dfr),
|
|
1221
|
+
`--detailing-lora ${detailingDir}/${_LTX_DETAILING_LORA_FILE}`,
|
|
1222
|
+
"--spatial-upscalings 1",
|
|
1223
|
+
"--temporal-upscalings 1",
|
|
1224
|
+
"--height 1088",
|
|
1225
|
+
"--width 1920",
|
|
1226
|
+
"--num-frames 121",
|
|
1227
|
+
`--prompt "${_LTX_DEFAULT_PROMPT}"`,
|
|
1228
|
+
"--output-path output.mp4",
|
|
1229
|
+
],
|
|
1230
|
+
"DFR pipeline (higher detail fidelity; optional temporal 2x/4x)",
|
|
1231
|
+
{
|
|
1232
|
+
footer: "# For 4K: --spatial-upscalings 2 --width 3840 --height 2176",
|
|
1233
|
+
hint: true,
|
|
1234
|
+
},
|
|
1235
|
+
),
|
|
1236
|
+
];
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
function _ltx23Snippets(model: ModelData, localDir: string, tags: string[]): string[] {
|
|
1240
|
+
const install = _ltxInstall(false);
|
|
1241
|
+
const download = _ltx23Download(model.id, localDir);
|
|
1242
|
+
const loraArg = `--lora ${localDir}/<weights>.safetensors 1.0`;
|
|
1243
|
+
const gemma = `--gemma-root ${_LTX_GEMMA3_ROOT}`;
|
|
1051
1244
|
|
|
1052
|
-
// IC-LoRA: video-to-video / image-to-video with a control (reference) signal.
|
|
1053
|
-
// Checked before "lora" because an IC-LoRA repo may carry both tags.
|
|
1054
1245
|
if (tags.includes("ic-lora")) {
|
|
1055
1246
|
return [
|
|
1056
1247
|
install,
|
|
1057
1248
|
download,
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1249
|
+
_ltxRun(
|
|
1250
|
+
"ic_lora",
|
|
1251
|
+
[
|
|
1252
|
+
"--distilled-checkpoint-path path/to/distilled_checkpoint.safetensors",
|
|
1253
|
+
"--spatial-upsampler-path path/to/spatial_upsampler.safetensors",
|
|
1254
|
+
gemma,
|
|
1255
|
+
loraArg,
|
|
1256
|
+
"--video-conditioning reference.mp4 1.0",
|
|
1257
|
+
`--prompt "your prompt here"`,
|
|
1258
|
+
"--output-path output.mp4",
|
|
1259
|
+
],
|
|
1260
|
+
"Video-to-video with the IC-LoRA (runs on the distilled base model)",
|
|
1261
|
+
),
|
|
1067
1262
|
];
|
|
1068
1263
|
}
|
|
1069
1264
|
|
|
1070
|
-
// Standard LoRA applied on top of the base pipeline.
|
|
1071
1265
|
if (tags.includes("lora")) {
|
|
1072
1266
|
return [
|
|
1073
1267
|
install,
|
|
1074
1268
|
download,
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1269
|
+
_ltxRun(
|
|
1270
|
+
"ti2vid_two_stages_hq",
|
|
1271
|
+
[
|
|
1272
|
+
"--checkpoint-path path/to/checkpoint.safetensors",
|
|
1273
|
+
"--distilled-lora path/to/distilled_lora.safetensors 0.8",
|
|
1274
|
+
"--spatial-upsampler-path path/to/spatial_upsampler.safetensors",
|
|
1275
|
+
gemma,
|
|
1276
|
+
loraArg,
|
|
1277
|
+
`--prompt "your prompt here"`,
|
|
1278
|
+
"--output-path output.mp4",
|
|
1279
|
+
],
|
|
1280
|
+
"Text/image-to-video with the LoRA on the HQ two-stage base pipeline",
|
|
1281
|
+
{ hint: true },
|
|
1282
|
+
),
|
|
1085
1283
|
];
|
|
1086
1284
|
}
|
|
1087
1285
|
|
|
1088
|
-
// Base model: the fast (distilled) and HQ (two-stage) pipelines. Substitute the
|
|
1089
|
-
// .safetensors filenames with the ones listed under this repo's "Files and versions".
|
|
1090
1286
|
return [
|
|
1091
1287
|
install,
|
|
1092
1288
|
download,
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
${
|
|
1289
|
+
_ltxRun(
|
|
1290
|
+
"distilled",
|
|
1291
|
+
[
|
|
1292
|
+
`--distilled-checkpoint-path ${localDir}/<distilled-checkpoint>.safetensors`,
|
|
1293
|
+
`--spatial-upsampler-path ${localDir}/<spatial-upsampler>.safetensors`,
|
|
1294
|
+
gemma,
|
|
1295
|
+
`--prompt "${_LTX_DEFAULT_PROMPT}"`,
|
|
1296
|
+
"--output-path output.mp4",
|
|
1297
|
+
],
|
|
1298
|
+
"Fast pipeline (distilled model, no distilled LoRA needed)",
|
|
1299
|
+
{ hint: true },
|
|
1300
|
+
),
|
|
1301
|
+
_ltxRun(
|
|
1302
|
+
"ti2vid_two_stages_hq",
|
|
1303
|
+
[
|
|
1304
|
+
`--checkpoint-path ${localDir}/<checkpoint>.safetensors`,
|
|
1305
|
+
`--distilled-lora ${localDir}/<distilled-lora>.safetensors 0.8`,
|
|
1306
|
+
`--spatial-upsampler-path ${localDir}/<spatial-upsampler>.safetensors`,
|
|
1307
|
+
gemma,
|
|
1308
|
+
`--prompt "${_LTX_DEFAULT_PROMPT}"`,
|
|
1309
|
+
"--output-path output.mp4",
|
|
1310
|
+
],
|
|
1311
|
+
"HQ pipeline (two-stage, higher quality)",
|
|
1312
|
+
{ hint: true },
|
|
1313
|
+
),
|
|
1110
1314
|
];
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
export const ltx = (model: ModelData): string[] => {
|
|
1318
|
+
const localDir = `models/${nameWithoutNamespace(model.id)}`;
|
|
1319
|
+
const tags = model.tags ?? [];
|
|
1320
|
+
return _isLtx25Model(model) ? _ltx25Snippets(model, localDir, tags) : _ltx23Snippets(model, localDir, tags);
|
|
1111
1321
|
};
|
|
1112
1322
|
|
|
1113
1323
|
export const lightning_ir = (model: ModelData): string[] => {
|
|
@@ -1275,7 +1485,7 @@ model = MeshAnything(args)`,
|
|
|
1275
1485
|
|
|
1276
1486
|
export const multimolecule = (model: ModelData): string[] => {
|
|
1277
1487
|
const widgetExample = model.widgetData?.[0] as WidgetExampleTextInput | undefined;
|
|
1278
|
-
const exampleText = widgetExample?.text;
|
|
1488
|
+
const exampleText = escapeStringForJson(widgetExample?.text ?? "");
|
|
1279
1489
|
const maskToken = model.mask_token ?? "<mask>";
|
|
1280
1490
|
const sequence = exampleText?.replace(maskToken, "A");
|
|
1281
1491
|
|
|
@@ -1343,8 +1553,9 @@ openasr transcribe audio.wav --model ${modelId}`,
|
|
|
1343
1553
|
};
|
|
1344
1554
|
|
|
1345
1555
|
export const paddlenlp = (model: ModelData): string[] => {
|
|
1346
|
-
|
|
1347
|
-
|
|
1556
|
+
const architecture = model.config?.architectures?.[0];
|
|
1557
|
+
// interpolated as a Python class name, so a non-identifier is treated as absent
|
|
1558
|
+
if (architecture && isValidIdentifier(architecture)) {
|
|
1348
1559
|
return [
|
|
1349
1560
|
[
|
|
1350
1561
|
`from paddlenlp.transformers import AutoTokenizer, ${architecture}`,
|
|
@@ -1602,7 +1813,7 @@ const skopsPickle = (model: ModelData, modelFile: string) => {
|
|
|
1602
1813
|
from skops.hub_utils import download
|
|
1603
1814
|
download("${model.id}", "path_to_folder")
|
|
1604
1815
|
model = joblib.load(
|
|
1605
|
-
"${modelFile}"
|
|
1816
|
+
"${escapeStringForJson(modelFile)}"
|
|
1606
1817
|
)
|
|
1607
1818
|
# only load pickle files from sources you trust
|
|
1608
1819
|
# read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
|
|
@@ -1616,7 +1827,7 @@ from skops.io import load
|
|
|
1616
1827
|
download("${model.id}", "path_to_folder")
|
|
1617
1828
|
# make sure model file is in skops format
|
|
1618
1829
|
# if model is a pickle file, make sure it's from a source you trust
|
|
1619
|
-
model = load("path_to_folder/${modelFile}")`,
|
|
1830
|
+
model = load("path_to_folder/${escapeStringForJson(modelFile)}")`,
|
|
1620
1831
|
];
|
|
1621
1832
|
};
|
|
1622
1833
|
|
|
@@ -1894,11 +2105,18 @@ const hasChatTemplate = (model: ModelData): boolean =>
|
|
|
1894
2105
|
model.config?.processor_config?.chat_template !== undefined ||
|
|
1895
2106
|
model.config?.chat_template_jinja !== undefined;
|
|
1896
2107
|
|
|
2108
|
+
// interpolated as a Python class name (and into RegExps in pruna_transformers), so a non-identifier is treated as absent
|
|
2109
|
+
const autoModelClass = (model: ModelData): string | undefined => {
|
|
2110
|
+
const autoModel = model.transformersInfo?.auto_model;
|
|
2111
|
+
return autoModel && isValidIdentifier(autoModel) ? autoModel : undefined;
|
|
2112
|
+
};
|
|
2113
|
+
|
|
1897
2114
|
export const transformers = (model: ModelData): string[] => {
|
|
1898
2115
|
const info = model.transformersInfo;
|
|
1899
2116
|
if (!info) {
|
|
1900
2117
|
return [`# ⚠️ Type of model unknown`];
|
|
1901
2118
|
}
|
|
2119
|
+
const auto_model = autoModelClass(model) ?? "AutoModel";
|
|
1902
2120
|
const remote_code_snippet = model.tags.includes(TAG_CUSTOM_CODE) ? ", trust_remote_code=True" : "";
|
|
1903
2121
|
|
|
1904
2122
|
const autoSnippet = [];
|
|
@@ -1911,10 +2129,10 @@ export const transformers = (model: ModelData): string[] => {
|
|
|
1911
2129
|
: "processor";
|
|
1912
2130
|
autoSnippet.push(
|
|
1913
2131
|
"# Load model directly",
|
|
1914
|
-
`from transformers import ${info.processor}, ${
|
|
2132
|
+
`from transformers import ${info.processor}, ${auto_model}`,
|
|
1915
2133
|
"",
|
|
1916
2134
|
`${processorVarName} = ${info.processor}.from_pretrained("${model.id}"` + remote_code_snippet + ")",
|
|
1917
|
-
`model = ${
|
|
2135
|
+
`model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")',
|
|
1918
2136
|
);
|
|
1919
2137
|
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
|
|
1920
2138
|
if (model.tags.includes("image-text-to-text")) {
|
|
@@ -1950,8 +2168,8 @@ export const transformers = (model: ModelData): string[] => {
|
|
|
1950
2168
|
} else {
|
|
1951
2169
|
autoSnippet.push(
|
|
1952
2170
|
"# Load model directly",
|
|
1953
|
-
`from transformers import ${
|
|
1954
|
-
`model = ${
|
|
2171
|
+
`from transformers import ${auto_model}`,
|
|
2172
|
+
`model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")',
|
|
1955
2173
|
);
|
|
1956
2174
|
}
|
|
1957
2175
|
|
|
@@ -2054,7 +2272,7 @@ export const peft = (model: ModelData): string[] => {
|
|
|
2054
2272
|
`from peft import PeftModel
|
|
2055
2273
|
from transformers import AutoModelFor${pefttask}
|
|
2056
2274
|
|
|
2057
|
-
base_model = AutoModelFor${pefttask}.from_pretrained("${peftBaseModel}")
|
|
2275
|
+
base_model = AutoModelFor${pefttask}.from_pretrained("${escapeStringForJson(peftBaseModel)}")
|
|
2058
2276
|
model = PeftModel.from_pretrained(base_model, "${model.id}")`,
|
|
2059
2277
|
];
|
|
2060
2278
|
};
|
|
@@ -2485,7 +2703,7 @@ const pruna_diffusers = (model: ModelData): string[] => {
|
|
|
2485
2703
|
};
|
|
2486
2704
|
|
|
2487
2705
|
const pruna_transformers = (model: ModelData): string[] => {
|
|
2488
|
-
const
|
|
2706
|
+
const auto_model = autoModelClass(model);
|
|
2489
2707
|
const transformersSnippets = transformers(model);
|
|
2490
2708
|
|
|
2491
2709
|
// Replace pipeline with PrunaModel
|
|
@@ -2496,13 +2714,13 @@ const pruna_transformers = (model: ModelData): string[] => {
|
|
|
2496
2714
|
);
|
|
2497
2715
|
|
|
2498
2716
|
// Additional cleanup if auto_model info is available
|
|
2499
|
-
if (
|
|
2717
|
+
if (auto_model) {
|
|
2500
2718
|
processedSnippets = processedSnippets.map((snippet) =>
|
|
2501
2719
|
snippet
|
|
2502
|
-
.replace(new RegExp(`from transformers import ${
|
|
2503
|
-
.replace(new RegExp(`${
|
|
2504
|
-
.replace(new RegExp(`^.*from.*import.*(, *${
|
|
2505
|
-
line.replace(new RegExp(`, *${
|
|
2720
|
+
.replace(new RegExp(`from transformers import ${auto_model}\n?`, "g"), "")
|
|
2721
|
+
.replace(new RegExp(`${auto_model}.from_pretrained`, "g"), "PrunaModel.from_pretrained")
|
|
2722
|
+
.replace(new RegExp(`^.*from.*import.*(, *${auto_model})+.*$`, "gm"), (line) =>
|
|
2723
|
+
line.replace(new RegExp(`, *${auto_model}`, "g"), ""),
|
|
2506
2724
|
),
|
|
2507
2725
|
);
|
|
2508
2726
|
}
|
package/src/model-libraries.ts
CHANGED
|
@@ -804,7 +804,7 @@ export const MODEL_LIBRARIES_UI_ELEMENTS = {
|
|
|
804
804
|
countDownloads: `path_extension:"pt"`,
|
|
805
805
|
},
|
|
806
806
|
ltx: {
|
|
807
|
-
prettyLabel: "LTX
|
|
807
|
+
prettyLabel: "LTX-2",
|
|
808
808
|
repoName: "LTX-2",
|
|
809
809
|
repoUrl: "https://github.com/Lightricks/LTX-2",
|
|
810
810
|
docsUrl: "https://github.com/Lightricks/LTX-2",
|