@huggingface/transformers 3.5.0 → 3.5.2
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/README.md +129 -127
- package/dist/transformers.js +408 -54
- package/dist/transformers.js.map +1 -1
- package/dist/transformers.min.js +1 -1
- package/dist/transformers.min.js.map +1 -1
- package/dist/transformers.node.cjs +401 -53
- package/dist/transformers.node.cjs.map +1 -1
- package/dist/transformers.node.min.cjs +1 -1
- package/dist/transformers.node.min.cjs.map +1 -1
- package/dist/transformers.node.min.mjs +1 -1
- package/dist/transformers.node.min.mjs.map +1 -1
- package/dist/transformers.node.mjs +408 -54
- package/dist/transformers.node.mjs.map +1 -1
- package/dist/transformers.web.js +408 -54
- package/dist/transformers.web.js.map +1 -1
- package/dist/transformers.web.min.js +1 -1
- package/dist/transformers.web.min.js.map +1 -1
- package/package.json +2 -2
- package/src/base/image_processors_utils.js +6 -3
- package/src/configs.js +1 -0
- package/src/env.js +1 -1
- package/src/generation/configuration_utils.js +5 -5
- package/src/generation/logits_process.js +2 -2
- package/src/generation/streamers.js +5 -1
- package/src/models.js +58 -9
- package/src/pipelines.js +1 -1
- package/src/tokenizers.js +27 -16
- package/src/transformers.js +8 -0
- package/src/utils/hub.js +17 -12
- package/types/base/image_processors_utils.d.ts +2 -0
- package/types/base/image_processors_utils.d.ts.map +1 -1
- package/types/configs.d.ts.map +1 -1
- package/types/generation/configuration_utils.d.ts +5 -5
- package/types/generation/logits_process.d.ts +2 -2
- package/types/generation/streamers.d.ts.map +1 -1
- package/types/models/auto/image_processing_auto.d.ts.map +1 -1
- package/types/models.d.ts +23 -1
- package/types/models.d.ts.map +1 -1
- package/types/tokenizers.d.ts +2 -2
- package/types/tokenizers.d.ts.map +1 -1
- package/types/transformers.d.ts +4 -0
- package/types/transformers.d.ts.map +1 -1
- package/types/utils/hub.d.ts.map +1 -1
|
@@ -162,7 +162,9 @@ var TOKEN_TYPES = Object.freeze({
|
|
|
162
162
|
Or: "Or",
|
|
163
163
|
Not: "UnaryOperator",
|
|
164
164
|
Macro: "Macro",
|
|
165
|
-
EndMacro: "EndMacro"
|
|
165
|
+
EndMacro: "EndMacro",
|
|
166
|
+
Break: "Break",
|
|
167
|
+
Continue: "Continue"
|
|
166
168
|
});
|
|
167
169
|
var KEYWORDS = Object.freeze({
|
|
168
170
|
set: TOKEN_TYPES.Set,
|
|
@@ -181,6 +183,8 @@ var KEYWORDS = Object.freeze({
|
|
|
181
183
|
"not in": TOKEN_TYPES.NotIn,
|
|
182
184
|
macro: TOKEN_TYPES.Macro,
|
|
183
185
|
endmacro: TOKEN_TYPES.EndMacro,
|
|
186
|
+
break: TOKEN_TYPES.Break,
|
|
187
|
+
continue: TOKEN_TYPES.Continue,
|
|
184
188
|
// Literals
|
|
185
189
|
true: TOKEN_TYPES.BooleanLiteral,
|
|
186
190
|
false: TOKEN_TYPES.BooleanLiteral,
|
|
@@ -407,6 +411,12 @@ var For = class extends Statement {
|
|
|
407
411
|
}
|
|
408
412
|
type = "For";
|
|
409
413
|
};
|
|
414
|
+
var Break = class extends Statement {
|
|
415
|
+
type = "Break";
|
|
416
|
+
};
|
|
417
|
+
var Continue = class extends Statement {
|
|
418
|
+
type = "Continue";
|
|
419
|
+
};
|
|
410
420
|
var SetStatement = class extends Statement {
|
|
411
421
|
constructor(assignee, value, body) {
|
|
412
422
|
super();
|
|
@@ -605,6 +615,16 @@ function parse(tokens) {
|
|
|
605
615
|
expect(TOKEN_TYPES.EndFor, "Expected endfor token");
|
|
606
616
|
expect(TOKEN_TYPES.CloseStatement, "Expected %} token");
|
|
607
617
|
break;
|
|
618
|
+
case TOKEN_TYPES.Break:
|
|
619
|
+
++current;
|
|
620
|
+
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
|
621
|
+
result = new Break();
|
|
622
|
+
break;
|
|
623
|
+
case TOKEN_TYPES.Continue:
|
|
624
|
+
++current;
|
|
625
|
+
expect(TOKEN_TYPES.CloseStatement, "Expected closing statement token");
|
|
626
|
+
result = new Continue();
|
|
627
|
+
break;
|
|
608
628
|
default:
|
|
609
629
|
throw new SyntaxError(`Unknown statement type: ${tokens[current].type}`);
|
|
610
630
|
}
|
|
@@ -1002,6 +1022,10 @@ function titleCase(value) {
|
|
|
1002
1022
|
}
|
|
1003
1023
|
|
|
1004
1024
|
// src/runtime.ts
|
|
1025
|
+
var BreakControl = class extends Error {
|
|
1026
|
+
};
|
|
1027
|
+
var ContinueControl = class extends Error {
|
|
1028
|
+
};
|
|
1005
1029
|
var RuntimeValue = class {
|
|
1006
1030
|
type = "RuntimeValue";
|
|
1007
1031
|
value;
|
|
@@ -1067,6 +1091,32 @@ var StringValue = class extends RuntimeValue {
|
|
|
1067
1091
|
return new StringValue(this.value.trimStart());
|
|
1068
1092
|
})
|
|
1069
1093
|
],
|
|
1094
|
+
[
|
|
1095
|
+
"startswith",
|
|
1096
|
+
new FunctionValue((args) => {
|
|
1097
|
+
if (args.length === 0) {
|
|
1098
|
+
throw new Error("startswith() requires at least one argument");
|
|
1099
|
+
}
|
|
1100
|
+
const prefix = args[0];
|
|
1101
|
+
if (!(prefix instanceof StringValue)) {
|
|
1102
|
+
throw new Error("startswith() argument must be a string");
|
|
1103
|
+
}
|
|
1104
|
+
return new BooleanValue(this.value.startsWith(prefix.value));
|
|
1105
|
+
})
|
|
1106
|
+
],
|
|
1107
|
+
[
|
|
1108
|
+
"endswith",
|
|
1109
|
+
new FunctionValue((args) => {
|
|
1110
|
+
if (args.length === 0) {
|
|
1111
|
+
throw new Error("endswith() requires at least one argument");
|
|
1112
|
+
}
|
|
1113
|
+
const suffix = args[0];
|
|
1114
|
+
if (!(suffix instanceof StringValue)) {
|
|
1115
|
+
throw new Error("endswith() argument must be a string");
|
|
1116
|
+
}
|
|
1117
|
+
return new BooleanValue(this.value.endsWith(suffix.value));
|
|
1118
|
+
})
|
|
1119
|
+
],
|
|
1070
1120
|
[
|
|
1071
1121
|
"split",
|
|
1072
1122
|
// follows Python's `str.split(sep=None, maxsplit=-1)` function behavior
|
|
@@ -1798,8 +1848,18 @@ var Interpreter = class {
|
|
|
1798
1848
|
]);
|
|
1799
1849
|
scope.setVariable("loop", new ObjectValue(loop));
|
|
1800
1850
|
scopeUpdateFunctions[i](scope);
|
|
1801
|
-
|
|
1802
|
-
|
|
1851
|
+
try {
|
|
1852
|
+
const evaluated = this.evaluateBlock(node.body, scope);
|
|
1853
|
+
result += evaluated.value;
|
|
1854
|
+
} catch (err) {
|
|
1855
|
+
if (err instanceof ContinueControl) {
|
|
1856
|
+
continue;
|
|
1857
|
+
}
|
|
1858
|
+
if (err instanceof BreakControl) {
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
1861
|
+
throw err;
|
|
1862
|
+
}
|
|
1803
1863
|
noIteration = false;
|
|
1804
1864
|
}
|
|
1805
1865
|
if (noIteration) {
|
|
@@ -1859,6 +1919,10 @@ var Interpreter = class {
|
|
|
1859
1919
|
return this.evaluateFor(statement, environment);
|
|
1860
1920
|
case "Macro":
|
|
1861
1921
|
return this.evaluateMacro(statement, environment);
|
|
1922
|
+
case "Break":
|
|
1923
|
+
throw new BreakControl();
|
|
1924
|
+
case "Continue":
|
|
1925
|
+
throw new ContinueControl();
|
|
1862
1926
|
case "NumericLiteral":
|
|
1863
1927
|
return new NumericValue(Number(statement.value));
|
|
1864
1928
|
case "StringLiteral":
|
|
@@ -1961,6 +2025,194 @@ function toJSON(input, indent, depth) {
|
|
|
1961
2025
|
}
|
|
1962
2026
|
}
|
|
1963
2027
|
|
|
2028
|
+
// src/format.ts
|
|
2029
|
+
var NEWLINE = "\n";
|
|
2030
|
+
var OPEN_STATEMENT = "{%- ";
|
|
2031
|
+
var CLOSE_STATEMENT = " -%}";
|
|
2032
|
+
var OPERATOR_PRECEDENCE = {
|
|
2033
|
+
MultiplicativeBinaryOperator: 2,
|
|
2034
|
+
AdditiveBinaryOperator: 1,
|
|
2035
|
+
ComparisonBinaryOperator: 0
|
|
2036
|
+
};
|
|
2037
|
+
function format(program, indent = " ") {
|
|
2038
|
+
const indentStr = typeof indent === "number" ? " ".repeat(indent) : indent;
|
|
2039
|
+
const body = formatStatements(program.body, 0, indentStr);
|
|
2040
|
+
return body.replace(/\n$/, "");
|
|
2041
|
+
}
|
|
2042
|
+
function createStatement(...text) {
|
|
2043
|
+
return OPEN_STATEMENT + text.join(" ") + CLOSE_STATEMENT;
|
|
2044
|
+
}
|
|
2045
|
+
function formatStatements(stmts, depth, indentStr) {
|
|
2046
|
+
return stmts.map((stmt) => formatStatement(stmt, depth, indentStr)).join(NEWLINE);
|
|
2047
|
+
}
|
|
2048
|
+
function formatStatement(node, depth, indentStr) {
|
|
2049
|
+
const pad = indentStr.repeat(depth);
|
|
2050
|
+
switch (node.type) {
|
|
2051
|
+
case "Program":
|
|
2052
|
+
return formatStatements(node.body, depth, indentStr);
|
|
2053
|
+
case "If":
|
|
2054
|
+
return formatIf(node, depth, indentStr);
|
|
2055
|
+
case "For":
|
|
2056
|
+
return formatFor(node, depth, indentStr);
|
|
2057
|
+
case "Set":
|
|
2058
|
+
return formatSet(node, depth, indentStr);
|
|
2059
|
+
case "Macro":
|
|
2060
|
+
return formatMacro(node, depth, indentStr);
|
|
2061
|
+
case "Break":
|
|
2062
|
+
return pad + createStatement("break");
|
|
2063
|
+
case "Continue":
|
|
2064
|
+
return pad + createStatement("continue");
|
|
2065
|
+
default:
|
|
2066
|
+
return pad + "{{- " + formatExpression(node) + " -}}";
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
function formatIf(node, depth, indentStr) {
|
|
2070
|
+
const pad = indentStr.repeat(depth);
|
|
2071
|
+
const clauses = [];
|
|
2072
|
+
let current = node;
|
|
2073
|
+
while (current) {
|
|
2074
|
+
clauses.push({ test: current.test, body: current.body });
|
|
2075
|
+
if (current.alternate.length === 1 && current.alternate[0].type === "If") {
|
|
2076
|
+
current = current.alternate[0];
|
|
2077
|
+
} else {
|
|
2078
|
+
break;
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
let out = pad + createStatement("if", formatExpression(clauses[0].test)) + NEWLINE + formatStatements(clauses[0].body, depth + 1, indentStr);
|
|
2082
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
2083
|
+
out += NEWLINE + pad + createStatement("elif", formatExpression(clauses[i].test)) + NEWLINE + formatStatements(clauses[i].body, depth + 1, indentStr);
|
|
2084
|
+
}
|
|
2085
|
+
if (current && current.alternate.length > 0) {
|
|
2086
|
+
out += NEWLINE + pad + createStatement("else") + NEWLINE + formatStatements(current.alternate, depth + 1, indentStr);
|
|
2087
|
+
}
|
|
2088
|
+
out += NEWLINE + pad + createStatement("endif");
|
|
2089
|
+
return out;
|
|
2090
|
+
}
|
|
2091
|
+
function formatFor(node, depth, indentStr) {
|
|
2092
|
+
const pad = indentStr.repeat(depth);
|
|
2093
|
+
let formattedIterable = "";
|
|
2094
|
+
if (node.iterable.type === "SelectExpression") {
|
|
2095
|
+
const n = node.iterable;
|
|
2096
|
+
formattedIterable = `${formatExpression(n.iterable)} if ${formatExpression(n.test)}`;
|
|
2097
|
+
} else {
|
|
2098
|
+
formattedIterable = formatExpression(node.iterable);
|
|
2099
|
+
}
|
|
2100
|
+
let out = pad + createStatement("for", formatExpression(node.loopvar), "in", formattedIterable) + NEWLINE + formatStatements(node.body, depth + 1, indentStr);
|
|
2101
|
+
if (node.defaultBlock.length > 0) {
|
|
2102
|
+
out += NEWLINE + pad + createStatement("else") + NEWLINE + formatStatements(node.defaultBlock, depth + 1, indentStr);
|
|
2103
|
+
}
|
|
2104
|
+
out += NEWLINE + pad + createStatement("endfor");
|
|
2105
|
+
return out;
|
|
2106
|
+
}
|
|
2107
|
+
function formatSet(node, depth, indentStr) {
|
|
2108
|
+
const pad = indentStr.repeat(depth);
|
|
2109
|
+
const left = formatExpression(node.assignee);
|
|
2110
|
+
const right = node.value ? formatExpression(node.value) : "";
|
|
2111
|
+
const value = pad + createStatement("set", `${left}${node.value ? " = " + right : ""}`);
|
|
2112
|
+
if (node.body.length === 0) {
|
|
2113
|
+
return value;
|
|
2114
|
+
}
|
|
2115
|
+
return value + NEWLINE + formatStatements(node.body, depth + 1, indentStr) + NEWLINE + pad + createStatement("endset");
|
|
2116
|
+
}
|
|
2117
|
+
function formatMacro(node, depth, indentStr) {
|
|
2118
|
+
const pad = indentStr.repeat(depth);
|
|
2119
|
+
const args = node.args.map(formatExpression).join(", ");
|
|
2120
|
+
return pad + createStatement("macro", `${node.name.value}(${args})`) + NEWLINE + formatStatements(node.body, depth + 1, indentStr) + NEWLINE + pad + createStatement("endmacro");
|
|
2121
|
+
}
|
|
2122
|
+
function formatExpression(node, parentPrec = -1) {
|
|
2123
|
+
switch (node.type) {
|
|
2124
|
+
case "Identifier":
|
|
2125
|
+
return node.value;
|
|
2126
|
+
case "NullLiteral":
|
|
2127
|
+
return "none";
|
|
2128
|
+
case "NumericLiteral":
|
|
2129
|
+
case "BooleanLiteral":
|
|
2130
|
+
return `${node.value}`;
|
|
2131
|
+
case "StringLiteral":
|
|
2132
|
+
return JSON.stringify(node.value);
|
|
2133
|
+
case "BinaryExpression": {
|
|
2134
|
+
const n = node;
|
|
2135
|
+
const thisPrecedence = OPERATOR_PRECEDENCE[n.operator.type] ?? 0;
|
|
2136
|
+
const left = formatExpression(n.left, thisPrecedence);
|
|
2137
|
+
const right = formatExpression(n.right, thisPrecedence + 1);
|
|
2138
|
+
const expr = `${left} ${n.operator.value} ${right}`;
|
|
2139
|
+
return thisPrecedence < parentPrec ? `(${expr})` : expr;
|
|
2140
|
+
}
|
|
2141
|
+
case "UnaryExpression": {
|
|
2142
|
+
const n = node;
|
|
2143
|
+
const val = n.operator.value + (n.operator.value === "not" ? " " : "") + formatExpression(n.argument, Infinity);
|
|
2144
|
+
return val;
|
|
2145
|
+
}
|
|
2146
|
+
case "LogicalNegationExpression":
|
|
2147
|
+
return `not ${formatExpression(node.argument, Infinity)}`;
|
|
2148
|
+
case "CallExpression": {
|
|
2149
|
+
const n = node;
|
|
2150
|
+
const args = n.args.map((a) => formatExpression(a, -1)).join(", ");
|
|
2151
|
+
return `${formatExpression(n.callee, -1)}(${args})`;
|
|
2152
|
+
}
|
|
2153
|
+
case "MemberExpression": {
|
|
2154
|
+
const n = node;
|
|
2155
|
+
let obj = formatExpression(n.object, -1);
|
|
2156
|
+
if (n.object.type !== "Identifier") {
|
|
2157
|
+
obj = `(${obj})`;
|
|
2158
|
+
}
|
|
2159
|
+
let prop = formatExpression(n.property, -1);
|
|
2160
|
+
if (!n.computed && n.property.type !== "Identifier") {
|
|
2161
|
+
prop = `(${prop})`;
|
|
2162
|
+
}
|
|
2163
|
+
return n.computed ? `${obj}[${prop}]` : `${obj}.${prop}`;
|
|
2164
|
+
}
|
|
2165
|
+
case "FilterExpression": {
|
|
2166
|
+
const n = node;
|
|
2167
|
+
const operand = formatExpression(n.operand, Infinity);
|
|
2168
|
+
if (n.filter.type === "CallExpression") {
|
|
2169
|
+
return `${operand} | ${formatExpression(n.filter, -1)}`;
|
|
2170
|
+
}
|
|
2171
|
+
return `${operand} | ${n.filter.value}`;
|
|
2172
|
+
}
|
|
2173
|
+
case "SelectExpression": {
|
|
2174
|
+
const n = node;
|
|
2175
|
+
return `${formatExpression(n.iterable, -1)} | select(${formatExpression(n.test, -1)})`;
|
|
2176
|
+
}
|
|
2177
|
+
case "TestExpression": {
|
|
2178
|
+
const n = node;
|
|
2179
|
+
return `${formatExpression(n.operand, -1)} is${n.negate ? " not" : ""} ${n.test.value}`;
|
|
2180
|
+
}
|
|
2181
|
+
case "ArrayLiteral":
|
|
2182
|
+
case "TupleLiteral": {
|
|
2183
|
+
const elems = node.value.map((e) => formatExpression(e, -1));
|
|
2184
|
+
const brackets = node.type === "ArrayLiteral" ? "[]" : "()";
|
|
2185
|
+
return `${brackets[0]}${elems.join(", ")}${brackets[1]}`;
|
|
2186
|
+
}
|
|
2187
|
+
case "ObjectLiteral": {
|
|
2188
|
+
const entries = Array.from(node.value.entries()).map(
|
|
2189
|
+
([k, v]) => `${formatExpression(k, -1)}: ${formatExpression(v, -1)}`
|
|
2190
|
+
);
|
|
2191
|
+
return `{ ${entries.join(", ")} }`;
|
|
2192
|
+
}
|
|
2193
|
+
case "SliceExpression": {
|
|
2194
|
+
const n = node;
|
|
2195
|
+
const s = n.start ? formatExpression(n.start, -1) : "";
|
|
2196
|
+
const t = n.stop ? formatExpression(n.stop, -1) : "";
|
|
2197
|
+
const st = n.step ? `:${formatExpression(n.step, -1)}` : "";
|
|
2198
|
+
return `${s}:${t}${st}`;
|
|
2199
|
+
}
|
|
2200
|
+
case "KeywordArgumentExpression": {
|
|
2201
|
+
const n = node;
|
|
2202
|
+
return `${n.key.value}=${formatExpression(n.value, -1)}`;
|
|
2203
|
+
}
|
|
2204
|
+
case "If": {
|
|
2205
|
+
const n = node;
|
|
2206
|
+
const test = formatExpression(n.test, -1);
|
|
2207
|
+
const body = formatExpression(n.body[0], 0);
|
|
2208
|
+
const alternate = formatExpression(n.alternate[0], -1);
|
|
2209
|
+
return `${body} if ${test} else ${alternate}`;
|
|
2210
|
+
}
|
|
2211
|
+
default:
|
|
2212
|
+
throw new Error(`Unknown expression type: ${node.type}`);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
|
|
1964
2216
|
// src/index.ts
|
|
1965
2217
|
var Template = class {
|
|
1966
2218
|
parsed;
|
|
@@ -1991,6 +2243,9 @@ var Template = class {
|
|
|
1991
2243
|
const result = interpreter.run(this.parsed);
|
|
1992
2244
|
return result.value;
|
|
1993
2245
|
}
|
|
2246
|
+
format(options) {
|
|
2247
|
+
return format(this.parsed, options?.indent || " ");
|
|
2248
|
+
}
|
|
1994
2249
|
};
|
|
1995
2250
|
|
|
1996
2251
|
|
|
@@ -2949,6 +3204,10 @@ class ImageProcessor extends _utils_generic_js__WEBPACK_IMPORTED_MODULE_0__.Call
|
|
|
2949
3204
|
this.pad_size = config.pad_size;
|
|
2950
3205
|
// @ts-expect-error TS2339
|
|
2951
3206
|
this.do_pad = config.do_pad;
|
|
3207
|
+
// @ts-expect-error TS2339
|
|
3208
|
+
this.min_pixels = config.min_pixels;
|
|
3209
|
+
// @ts-expect-error TS2339
|
|
3210
|
+
this.max_pixels = config.max_pixels;
|
|
2952
3211
|
|
|
2953
3212
|
if (this.do_pad && !this.pad_size && this.size && this.size.width !== undefined && this.size.height !== undefined) {
|
|
2954
3213
|
// Should pad, but no pad size specified
|
|
@@ -3222,12 +3481,11 @@ class ImageProcessor extends _utils_generic_js__WEBPACK_IMPORTED_MODULE_0__.Call
|
|
|
3222
3481
|
|
|
3223
3482
|
} else if (this.size_divisibility !== undefined) {
|
|
3224
3483
|
return enforce_size_divisibility([srcWidth, srcHeight], this.size_divisibility);
|
|
3225
|
-
} else if (
|
|
3484
|
+
} else if (this.min_pixels !== undefined && this.max_pixels !== undefined) {
|
|
3226
3485
|
// Custom resize logic for Qwen2-VL models
|
|
3227
|
-
const { min_pixels, max_pixels } = size;
|
|
3228
3486
|
// @ts-expect-error TS2339
|
|
3229
3487
|
const factor = this.config.patch_size * this.config.merge_size;
|
|
3230
|
-
return smart_resize(srcHeight, srcWidth, factor, min_pixels, max_pixels);
|
|
3488
|
+
return smart_resize(srcHeight, srcWidth, factor, this.min_pixels, this.max_pixels);
|
|
3231
3489
|
} else {
|
|
3232
3490
|
throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(size)}`);
|
|
3233
3491
|
}
|
|
@@ -3756,6 +4014,7 @@ function getNormalizedConfig(config) {
|
|
|
3756
4014
|
mapping['hidden_size'] = 'hidden_size';
|
|
3757
4015
|
mapping['num_attention_heads'] = 'num_attention_heads';
|
|
3758
4016
|
break;
|
|
4017
|
+
case 'qwen3':
|
|
3759
4018
|
case 'gemma':
|
|
3760
4019
|
case 'gemma2':
|
|
3761
4020
|
case 'gemma3_text':
|
|
@@ -4096,7 +4355,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4096
4355
|
|
|
4097
4356
|
|
|
4098
4357
|
|
|
4099
|
-
const VERSION = '3.5.
|
|
4358
|
+
const VERSION = '3.5.2';
|
|
4100
4359
|
|
|
4101
4360
|
// Check if various APIs are available (depends on environment)
|
|
4102
4361
|
const IS_BROWSER_ENV = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
@@ -4326,7 +4585,7 @@ class GenerationConfig {
|
|
|
4326
4585
|
|
|
4327
4586
|
/**
|
|
4328
4587
|
* Number of groups to divide `num_beams` into in order to ensure diversity among different groups of beams.
|
|
4329
|
-
* See [this paper](https://
|
|
4588
|
+
* See [this paper](https://huggingface.co/papers/1610.02424) for more details.
|
|
4330
4589
|
* @type {number}
|
|
4331
4590
|
* @default 1
|
|
4332
4591
|
*/
|
|
@@ -4371,7 +4630,7 @@ class GenerationConfig {
|
|
|
4371
4630
|
/**
|
|
4372
4631
|
* Local typicality measures how similar the conditional probability of predicting a target token next is to the expected conditional probability of predicting a random token next, given the partial text already generated.
|
|
4373
4632
|
* If set to float < 1, the smallest set of the most locally typical tokens with probabilities that add up to `typical_p` or higher are kept for generation.
|
|
4374
|
-
* See [this paper](https://
|
|
4633
|
+
* See [this paper](https://huggingface.co/papers/2202.00666) for more details.
|
|
4375
4634
|
* @type {number}
|
|
4376
4635
|
* @default 1.0
|
|
4377
4636
|
*/
|
|
@@ -4380,7 +4639,7 @@ class GenerationConfig {
|
|
|
4380
4639
|
/**
|
|
4381
4640
|
* If set to float strictly between 0 and 1, only tokens with a conditional probability greater than `epsilon_cutoff` will be sampled.
|
|
4382
4641
|
* In the paper, suggested values range from 3e-4 to 9e-4, depending on the size of the model.
|
|
4383
|
-
* See [Truncation Sampling as Language Model Desmoothing](https://
|
|
4642
|
+
* See [Truncation Sampling as Language Model Desmoothing](https://huggingface.co/papers/2210.15191) for more details.
|
|
4384
4643
|
* @type {number}
|
|
4385
4644
|
* @default 0.0
|
|
4386
4645
|
*/
|
|
@@ -4390,7 +4649,7 @@ class GenerationConfig {
|
|
|
4390
4649
|
* Eta sampling is a hybrid of locally typical sampling and epsilon sampling.
|
|
4391
4650
|
* If set to float strictly between 0 and 1, a token is only considered if it is greater than either `eta_cutoff` or `sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits)))`.
|
|
4392
4651
|
* The latter term is intuitively the expected next token probability, scaled by `sqrt(eta_cutoff)`. In the paper, suggested values range from 3e-4 to 2e-3, depending on the size of the model.
|
|
4393
|
-
* See [Truncation Sampling as Language Model Desmoothing](https://
|
|
4652
|
+
* See [Truncation Sampling as Language Model Desmoothing](https://huggingface.co/papers/2210.15191) for more details.
|
|
4394
4653
|
* @type {number}
|
|
4395
4654
|
* @default 0.0
|
|
4396
4655
|
*/
|
|
@@ -4406,7 +4665,7 @@ class GenerationConfig {
|
|
|
4406
4665
|
|
|
4407
4666
|
/**
|
|
4408
4667
|
* The parameter for repetition penalty. 1.0 means no penalty.
|
|
4409
|
-
* See [this paper](https://
|
|
4668
|
+
* See [this paper](https://huggingface.co/papers/1909.05858) for more details.
|
|
4410
4669
|
* @type {number}
|
|
4411
4670
|
* @default 1.0
|
|
4412
4671
|
*/
|
|
@@ -5080,7 +5339,7 @@ class NoRepeatNGramLogitsProcessor extends LogitsProcessor {
|
|
|
5080
5339
|
* This penalty is applied at most once per token. Note that, for decoder-only models like most LLMs,
|
|
5081
5340
|
* the considered tokens include the prompt.
|
|
5082
5341
|
*
|
|
5083
|
-
* In the original [paper](https://
|
|
5342
|
+
* In the original [paper](https://huggingface.co/papers/1909.05858), the authors suggest the use of a
|
|
5084
5343
|
* penalty of around 1.2 to achieve a good balance between truthful generation and lack of repetition.
|
|
5085
5344
|
* To penalize and reduce repetition, use `penalty` values above 1.0, where a higher value penalizes
|
|
5086
5345
|
* more strongly. To reward and encourage repetition, use `penalty` values between 0.0 and 1.0, where
|
|
@@ -5250,7 +5509,7 @@ class NoBadWordsLogitsProcessor extends LogitsProcessor {
|
|
|
5250
5509
|
* correspond to the unconditional logits (predicted from an empty or 'null' prompt). The processor computes a
|
|
5251
5510
|
* weighted average across the conditional and unconditional logits, parameterised by the `guidance_scale`.
|
|
5252
5511
|
*
|
|
5253
|
-
* See [the paper](https://
|
|
5512
|
+
* See [the paper](https://huggingface.co/papers/2306.05284) for more information.
|
|
5254
5513
|
*/
|
|
5255
5514
|
class ClassifierFreeGuidanceLogitsProcessor extends LogitsProcessor {
|
|
5256
5515
|
|
|
@@ -6020,7 +6279,11 @@ class WhisperTextStreamer extends TextStreamer {
|
|
|
6020
6279
|
this.on_chunk_start?.(time);
|
|
6021
6280
|
}
|
|
6022
6281
|
this.waiting_for_timestamp = !this.waiting_for_timestamp; // Toggle
|
|
6023
|
-
|
|
6282
|
+
|
|
6283
|
+
// NOTE: Timestamp tokens should not be printed. Although, since they
|
|
6284
|
+
// aren't classified as "special tokens", we need to handle them here.
|
|
6285
|
+
this.token_callback_function?.(tokens);
|
|
6286
|
+
return;
|
|
6024
6287
|
}
|
|
6025
6288
|
}
|
|
6026
6289
|
return super.put(value);
|
|
@@ -6147,6 +6410,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
6147
6410
|
/* harmony export */ ConvNextV2ForImageClassification: () => (/* binding */ ConvNextV2ForImageClassification),
|
|
6148
6411
|
/* harmony export */ ConvNextV2Model: () => (/* binding */ ConvNextV2Model),
|
|
6149
6412
|
/* harmony export */ ConvNextV2PreTrainedModel: () => (/* binding */ ConvNextV2PreTrainedModel),
|
|
6413
|
+
/* harmony export */ DFineForObjectDetection: () => (/* binding */ DFineForObjectDetection),
|
|
6414
|
+
/* harmony export */ DFineModel: () => (/* binding */ DFineModel),
|
|
6415
|
+
/* harmony export */ DFinePreTrainedModel: () => (/* binding */ DFinePreTrainedModel),
|
|
6150
6416
|
/* harmony export */ DPTForDepthEstimation: () => (/* binding */ DPTForDepthEstimation),
|
|
6151
6417
|
/* harmony export */ DPTModel: () => (/* binding */ DPTModel),
|
|
6152
6418
|
/* harmony export */ DPTPreTrainedModel: () => (/* binding */ DPTPreTrainedModel),
|
|
@@ -6431,6 +6697,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
6431
6697
|
/* harmony export */ Qwen2PreTrainedModel: () => (/* binding */ Qwen2PreTrainedModel),
|
|
6432
6698
|
/* harmony export */ Qwen2VLForConditionalGeneration: () => (/* binding */ Qwen2VLForConditionalGeneration),
|
|
6433
6699
|
/* harmony export */ Qwen2VLPreTrainedModel: () => (/* binding */ Qwen2VLPreTrainedModel),
|
|
6700
|
+
/* harmony export */ Qwen3ForCausalLM: () => (/* binding */ Qwen3ForCausalLM),
|
|
6701
|
+
/* harmony export */ Qwen3Model: () => (/* binding */ Qwen3Model),
|
|
6702
|
+
/* harmony export */ Qwen3PreTrainedModel: () => (/* binding */ Qwen3PreTrainedModel),
|
|
6434
6703
|
/* harmony export */ RFDetrForObjectDetection: () => (/* binding */ RFDetrForObjectDetection),
|
|
6435
6704
|
/* harmony export */ RFDetrModel: () => (/* binding */ RFDetrModel),
|
|
6436
6705
|
/* harmony export */ RFDetrObjectDetectionOutput: () => (/* binding */ RFDetrObjectDetectionOutput),
|
|
@@ -6781,6 +7050,7 @@ async function getSession(pretrained_model_name_or_path, fileName, options) {
|
|
|
6781
7050
|
const session_config = {
|
|
6782
7051
|
dtype: selectedDtype,
|
|
6783
7052
|
kv_cache_dtype,
|
|
7053
|
+
device: selectedDevice,
|
|
6784
7054
|
}
|
|
6785
7055
|
|
|
6786
7056
|
// Construct the model file name
|
|
@@ -6961,6 +7231,10 @@ function validateInputs(session, inputs) {
|
|
|
6961
7231
|
return checkedInputs;
|
|
6962
7232
|
}
|
|
6963
7233
|
|
|
7234
|
+
// Currently, Transformers.js doesn't support simultaneous execution of sessions in WASM/WebGPU.
|
|
7235
|
+
// For this reason, we need to chain the inference calls (otherwise we get "Error: Session already started").
|
|
7236
|
+
let webInferenceChain = Promise.resolve();
|
|
7237
|
+
|
|
6964
7238
|
/**
|
|
6965
7239
|
* Executes an InferenceSession using the specified inputs.
|
|
6966
7240
|
* NOTE: `inputs` must contain at least the input names of the model.
|
|
@@ -6977,17 +7251,28 @@ async function sessionRun(session, inputs) {
|
|
|
6977
7251
|
try {
|
|
6978
7252
|
// pass the original ort tensor
|
|
6979
7253
|
const ortFeed = Object.fromEntries(Object.entries(checkedInputs).map(([k, v]) => [k, v.ort_tensor]));
|
|
6980
|
-
|
|
6981
|
-
output =
|
|
6982
|
-
|
|
7254
|
+
const run = () => session.run(ortFeed);
|
|
7255
|
+
const output = await ((_env_js__WEBPACK_IMPORTED_MODULE_14__.apis.IS_BROWSER_ENV || _env_js__WEBPACK_IMPORTED_MODULE_14__.apis.IS_WEBWORKER_ENV)
|
|
7256
|
+
? (webInferenceChain = webInferenceChain.then(run))
|
|
7257
|
+
: run());
|
|
7258
|
+
return replaceTensors(output);
|
|
6983
7259
|
} catch (e) {
|
|
6984
7260
|
// Error messages can be long (nested) and uninformative. For this reason,
|
|
6985
7261
|
// we apply minor formatting to show the most important information
|
|
6986
7262
|
const formatted = Object.fromEntries(Object.entries(checkedInputs)
|
|
6987
|
-
.map(([k,
|
|
7263
|
+
.map(([k, tensor]) => {
|
|
6988
7264
|
// Extract these properties from the underlying ORT tensor
|
|
6989
|
-
|
|
6990
|
-
|
|
7265
|
+
const unpacked = {
|
|
7266
|
+
type: tensor.type,
|
|
7267
|
+
dims: tensor.dims,
|
|
7268
|
+
location: tensor.location,
|
|
7269
|
+
}
|
|
7270
|
+
if (unpacked.location !== "gpu-buffer") {
|
|
7271
|
+
// Only return the data if it's not a GPU buffer
|
|
7272
|
+
unpacked.data = tensor.data;
|
|
7273
|
+
}
|
|
7274
|
+
return [k, unpacked];
|
|
7275
|
+
}));
|
|
6991
7276
|
|
|
6992
7277
|
// This usually occurs when the inputs are of the wrong type.
|
|
6993
7278
|
console.error(`An error occurred during model execution: "${e}".`);
|
|
@@ -11116,6 +11401,22 @@ class Qwen2Model extends Qwen2PreTrainedModel { }
|
|
|
11116
11401
|
class Qwen2ForCausalLM extends Qwen2PreTrainedModel { }
|
|
11117
11402
|
//////////////////////////////////////////////////
|
|
11118
11403
|
|
|
11404
|
+
|
|
11405
|
+
//////////////////////////////////////////////////
|
|
11406
|
+
// Qwen3 models
|
|
11407
|
+
|
|
11408
|
+
/**
|
|
11409
|
+
* The bare Qwen3 Model outputting raw hidden-states without any specific head on top.
|
|
11410
|
+
*/
|
|
11411
|
+
class Qwen3PreTrainedModel extends PreTrainedModel { }
|
|
11412
|
+
/**
|
|
11413
|
+
* The bare Qwen3 Model outputting raw hidden-states without any specific head on top.
|
|
11414
|
+
*/
|
|
11415
|
+
class Qwen3Model extends Qwen3PreTrainedModel { }
|
|
11416
|
+
|
|
11417
|
+
class Qwen3ForCausalLM extends Qwen3PreTrainedModel { }
|
|
11418
|
+
//////////////////////////////////////////////////
|
|
11419
|
+
|
|
11119
11420
|
class Qwen2VLPreTrainedModel extends PreTrainedModel {
|
|
11120
11421
|
forward_params = [
|
|
11121
11422
|
// Text inputs
|
|
@@ -11751,7 +12052,7 @@ class RTDetrV2ForObjectDetection extends RTDetrV2PreTrainedModel {
|
|
|
11751
12052
|
}
|
|
11752
12053
|
}
|
|
11753
12054
|
|
|
11754
|
-
class RTDetrV2ObjectDetectionOutput extends RTDetrObjectDetectionOutput {}
|
|
12055
|
+
class RTDetrV2ObjectDetectionOutput extends RTDetrObjectDetectionOutput { }
|
|
11755
12056
|
//////////////////////////////////////////////////
|
|
11756
12057
|
|
|
11757
12058
|
//////////////////////////////////////////////////
|
|
@@ -11766,7 +12067,20 @@ class RFDetrForObjectDetection extends RFDetrPreTrainedModel {
|
|
|
11766
12067
|
}
|
|
11767
12068
|
}
|
|
11768
12069
|
|
|
11769
|
-
class RFDetrObjectDetectionOutput extends RTDetrObjectDetectionOutput {}
|
|
12070
|
+
class RFDetrObjectDetectionOutput extends RTDetrObjectDetectionOutput { }
|
|
12071
|
+
//////////////////////////////////////////////////
|
|
12072
|
+
|
|
12073
|
+
//////////////////////////////////////////////////
|
|
12074
|
+
class DFinePreTrainedModel extends PreTrainedModel { }
|
|
12075
|
+
class DFineModel extends DFinePreTrainedModel { }
|
|
12076
|
+
class DFineForObjectDetection extends DFinePreTrainedModel {
|
|
12077
|
+
/**
|
|
12078
|
+
* @param {any} model_inputs
|
|
12079
|
+
*/
|
|
12080
|
+
async _call(model_inputs) {
|
|
12081
|
+
return new RTDetrObjectDetectionOutput(await super._call(model_inputs));
|
|
12082
|
+
}
|
|
12083
|
+
}
|
|
11770
12084
|
//////////////////////////////////////////////////
|
|
11771
12085
|
|
|
11772
12086
|
//////////////////////////////////////////////////
|
|
@@ -13552,7 +13866,7 @@ class DecisionTransformerPreTrainedModel extends PreTrainedModel { }
|
|
|
13552
13866
|
|
|
13553
13867
|
/**
|
|
13554
13868
|
* The model builds upon the GPT2 architecture to perform autoregressive prediction of actions in an offline RL setting.
|
|
13555
|
-
* Refer to the paper for more details: https://
|
|
13869
|
+
* Refer to the paper for more details: https://huggingface.co/papers/2106.01345
|
|
13556
13870
|
*/
|
|
13557
13871
|
class DecisionTransformerModel extends DecisionTransformerPreTrainedModel { }
|
|
13558
13872
|
|
|
@@ -14078,6 +14392,7 @@ const MODEL_MAPPING_NAMES_ENCODER_ONLY = new Map([
|
|
|
14078
14392
|
['rt_detr', ['RTDetrModel', RTDetrModel]],
|
|
14079
14393
|
['rt_detr_v2', ['RTDetrV2Model', RTDetrV2Model]],
|
|
14080
14394
|
['rf_detr', ['RFDetrModel', RFDetrModel]],
|
|
14395
|
+
['d_fine', ['DFineModel', DFineModel]],
|
|
14081
14396
|
['table-transformer', ['TableTransformerModel', TableTransformerModel]],
|
|
14082
14397
|
['vit', ['ViTModel', ViTModel]],
|
|
14083
14398
|
['ijepa', ['IJepaModel', IJepaModel]],
|
|
@@ -14165,6 +14480,7 @@ const MODEL_MAPPING_NAMES_DECODER_ONLY = new Map([
|
|
|
14165
14480
|
['glm', ['GlmModel', GlmModel]],
|
|
14166
14481
|
['openelm', ['OpenELMModel', OpenELMModel]],
|
|
14167
14482
|
['qwen2', ['Qwen2Model', Qwen2Model]],
|
|
14483
|
+
['qwen3', ['Qwen3Model', Qwen3Model]],
|
|
14168
14484
|
['phi', ['PhiModel', PhiModel]],
|
|
14169
14485
|
['phi3', ['Phi3Model', Phi3Model]],
|
|
14170
14486
|
['mpt', ['MptModel', MptModel]],
|
|
@@ -14265,6 +14581,7 @@ const MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = new Map([
|
|
|
14265
14581
|
['glm', ['GlmForCausalLM', GlmForCausalLM]],
|
|
14266
14582
|
['openelm', ['OpenELMForCausalLM', OpenELMForCausalLM]],
|
|
14267
14583
|
['qwen2', ['Qwen2ForCausalLM', Qwen2ForCausalLM]],
|
|
14584
|
+
['qwen3', ['Qwen3ForCausalLM', Qwen3ForCausalLM]],
|
|
14268
14585
|
['phi', ['PhiForCausalLM', PhiForCausalLM]],
|
|
14269
14586
|
['phi3', ['Phi3ForCausalLM', Phi3ForCausalLM]],
|
|
14270
14587
|
['mpt', ['MptForCausalLM', MptForCausalLM]],
|
|
@@ -14379,6 +14696,7 @@ const MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES = new Map([
|
|
|
14379
14696
|
['rt_detr', ['RTDetrForObjectDetection', RTDetrForObjectDetection]],
|
|
14380
14697
|
['rt_detr_v2', ['RTDetrV2ForObjectDetection', RTDetrV2ForObjectDetection]],
|
|
14381
14698
|
['rf_detr', ['RFDetrForObjectDetection', RFDetrForObjectDetection]],
|
|
14699
|
+
['d_fine', ['DFineForObjectDetection', DFineForObjectDetection]],
|
|
14382
14700
|
['table-transformer', ['TableTransformerForObjectDetection', TableTransformerForObjectDetection]],
|
|
14383
14701
|
['yolos', ['YolosForObjectDetection', YolosForObjectDetection]],
|
|
14384
14702
|
]);
|
|
@@ -22048,7 +22366,7 @@ class AutomaticSpeechRecognitionPipeline extends (/** @type {new (options: TextA
|
|
|
22048
22366
|
for (const aud of preparedAudios) {
|
|
22049
22367
|
const inputs = await this.processor(aud);
|
|
22050
22368
|
|
|
22051
|
-
// According to the [paper](https://
|
|
22369
|
+
// According to the [paper](https://huggingface.co/papers/2410.15608):
|
|
22052
22370
|
// "We use greedy decoding, with a heuristic limit of 6 output tokens
|
|
22053
22371
|
// per second of audio to avoid repeated output sequences."
|
|
22054
22372
|
const max_new_tokens = Math.floor(aud.length / sampling_rate) * 6;
|
|
@@ -24085,15 +24403,19 @@ class TokenizerModel extends _utils_generic_js__WEBPACK_IMPORTED_MODULE_0__.Call
|
|
|
24085
24403
|
return new BPE(config);
|
|
24086
24404
|
|
|
24087
24405
|
default:
|
|
24088
|
-
// Some older tokenizers, like `google-t5/t5-small` and `distilbert/distilbert-base-uncased`, do not have a `type` field.
|
|
24406
|
+
// Some older tokenizers, like `google-t5/t5-small`, `openai-community/gpt2`, and `distilbert/distilbert-base-uncased`, do not have a `type` field.
|
|
24089
24407
|
// In this case, we can infer the tokenizer type based on the structure of the `vocab` field and other properties.
|
|
24090
24408
|
if (config.vocab) {
|
|
24091
24409
|
if (Array.isArray(config.vocab)) {
|
|
24092
24410
|
// config.vocab is of type `[string, number][]`
|
|
24093
24411
|
// @ts-ignore
|
|
24094
24412
|
return new Unigram(config, ...args);
|
|
24095
|
-
} else if (
|
|
24096
|
-
|
|
24413
|
+
} else if (Object.hasOwn(config, 'continuing_subword_prefix') && Object.hasOwn(config, 'unk_token')) {
|
|
24414
|
+
if (Object.hasOwn(config, 'merges')) {
|
|
24415
|
+
return new BPE(config);
|
|
24416
|
+
} else {
|
|
24417
|
+
return new WordPieceTokenizer(config);
|
|
24418
|
+
}
|
|
24097
24419
|
} else {
|
|
24098
24420
|
// @ts-ignore
|
|
24099
24421
|
return new LegacyTokenizerModel(config, ...args);
|
|
@@ -26525,22 +26847,29 @@ class PreTrainedTokenizer extends _utils_generic_js__WEBPACK_IMPORTED_MODULE_0__
|
|
|
26525
26847
|
// For single input, we just wrap in an array, and then unwrap later.
|
|
26526
26848
|
encodedTokens = [this._encode_plus(text, { text_pair, add_special_tokens, return_token_type_ids })];
|
|
26527
26849
|
}
|
|
26528
|
-
// At this point,
|
|
26529
|
-
// However, array may be jagged. So, we pad to max_length
|
|
26530
|
-
|
|
26850
|
+
// At this point, `encodedTokens` is batched, of shape [batch_size, tokens].
|
|
26851
|
+
// However, array may be jagged. So, we may need pad to max_length.
|
|
26531
26852
|
if (max_length === null) {
|
|
26532
|
-
|
|
26853
|
+
max_length = this.model_max_length;
|
|
26854
|
+
} else if (truncation === null) {
|
|
26855
|
+
if (padding === true) {
|
|
26856
|
+
console.warn(
|
|
26857
|
+
"`max_length` is ignored when `padding: true` and there is no truncation strategy. " +
|
|
26858
|
+
"To pad to max length, use `padding: 'max_length'`."
|
|
26859
|
+
)
|
|
26533
26860
|
max_length = this.model_max_length;
|
|
26534
|
-
} else {
|
|
26535
|
-
|
|
26536
|
-
|
|
26537
|
-
}
|
|
26538
|
-
} else {
|
|
26539
|
-
if (!truncation) {
|
|
26540
|
-
console.warn(`Truncation was not explicitly activated but \`max_length\` is provided a specific value, please use \`truncation=true\` to explicitly truncate examples to max length.`)
|
|
26861
|
+
} else if (padding === false) {
|
|
26862
|
+
console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation: true` to explicitly truncate examples to max length.");
|
|
26863
|
+
truncation = true;
|
|
26541
26864
|
}
|
|
26542
26865
|
}
|
|
26543
26866
|
|
|
26867
|
+
// padding: 'max_length' doesn't require any additional calculation
|
|
26868
|
+
// but padding: true has to calculate max_length from the sequences
|
|
26869
|
+
if (padding === true) {
|
|
26870
|
+
max_length = Math.min((0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_3__.max)(encodedTokens.map(x => x.input_ids.length))[0], max_length ?? Infinity);
|
|
26871
|
+
}
|
|
26872
|
+
|
|
26544
26873
|
// Ensure it is less than model max length
|
|
26545
26874
|
max_length = Math.min(max_length, this.model_max_length ?? Infinity);
|
|
26546
26875
|
|
|
@@ -27227,7 +27556,7 @@ function _build_translation_inputs(self, raw_inputs, tokenizer_options, generate
|
|
|
27227
27556
|
* between any pair of 200+ languages — including low-resource languages like Asturian,
|
|
27228
27557
|
* Luganda, Urdu and more. It aims to help people communicate with anyone, anywhere,
|
|
27229
27558
|
* regardless of their language preferences. For more information, check out their
|
|
27230
|
-
* [paper](https://
|
|
27559
|
+
* [paper](https://huggingface.co/papers/2207.04672).
|
|
27231
27560
|
*
|
|
27232
27561
|
* For a list of supported languages (along with their language codes),
|
|
27233
27562
|
* @see {@link https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200}
|
|
@@ -27258,7 +27587,7 @@ class NllbTokenizer extends PreTrainedTokenizer {
|
|
|
27258
27587
|
* The M2M100Tokenizer class is used to tokenize text for M2M100 ("Many-to-Many") models.
|
|
27259
27588
|
*
|
|
27260
27589
|
* M2M100 is a multilingual encoder-decoder (seq-to-seq) model trained for Many-to-Many
|
|
27261
|
-
* multilingual translation. It was introduced in this [paper](https://
|
|
27590
|
+
* multilingual translation. It was introduced in this [paper](https://huggingface.co/papers/2010.11125)
|
|
27262
27591
|
* and first released in [this](https://github.com/pytorch/fairseq/tree/master/examples/m2m_100) repository.
|
|
27263
27592
|
*
|
|
27264
27593
|
* For a list of supported languages (along with their language codes),
|
|
@@ -30091,7 +30420,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30091
30420
|
|
|
30092
30421
|
/**
|
|
30093
30422
|
* @file Utility functions to interact with the Hugging Face Hub (https://huggingface.co/models)
|
|
30094
|
-
*
|
|
30423
|
+
*
|
|
30095
30424
|
* @module utils/hub
|
|
30096
30425
|
*/
|
|
30097
30426
|
|
|
@@ -30109,7 +30438,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30109
30438
|
const MAX_EXTERNAL_DATA_CHUNKS = 100;
|
|
30110
30439
|
|
|
30111
30440
|
/**
|
|
30112
|
-
* @typedef {Object} PretrainedOptions Options for loading a pretrained model.
|
|
30441
|
+
* @typedef {Object} PretrainedOptions Options for loading a pretrained model.
|
|
30113
30442
|
* @property {import('./core.js').ProgressCallback} [progress_callback=null] If specified, this function will be called during model construction, to provide the user with progress updates.
|
|
30114
30443
|
* @property {import('../configs.js').PretrainedConfig} [config=null] Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
|
|
30115
30444
|
* - The model is a model provided by the library (loaded with the *model id* string of a pretrained model).
|
|
@@ -30248,7 +30577,7 @@ class FileResponse {
|
|
|
30248
30577
|
/**
|
|
30249
30578
|
* Reads the contents of the file specified by the filePath property and returns a Promise that
|
|
30250
30579
|
* resolves with a parsed JavaScript object containing the file's contents.
|
|
30251
|
-
*
|
|
30580
|
+
*
|
|
30252
30581
|
* @returns {Promise<Object>} A Promise that resolves with a parsed JavaScript object containing the file's contents.
|
|
30253
30582
|
* @throws {Error} If the file cannot be read.
|
|
30254
30583
|
*/
|
|
@@ -30285,7 +30614,7 @@ const REPO_ID_REGEX = /^(\b[\w\-.]+\b\/)?\b[\w\-.]{1,96}\b$/;
|
|
|
30285
30614
|
/**
|
|
30286
30615
|
* Tests whether a string is a valid Hugging Face model ID or not.
|
|
30287
30616
|
* Adapted from https://github.com/huggingface/huggingface_hub/blob/6378820ebb03f071988a96c7f3268f5bdf8f9449/src/huggingface_hub/utils/_validators.py#L119-L170
|
|
30288
|
-
*
|
|
30617
|
+
*
|
|
30289
30618
|
* @param {string} string The string to test
|
|
30290
30619
|
* @returns {boolean} True if the string is a valid model ID, false otherwise.
|
|
30291
30620
|
*/
|
|
@@ -30304,9 +30633,14 @@ function isValidHfModelId(string) {
|
|
|
30304
30633
|
*/
|
|
30305
30634
|
async function getFile(urlOrPath) {
|
|
30306
30635
|
|
|
30307
|
-
if (_env_js__WEBPACK_IMPORTED_MODULE_2__.env.useFS && !isValidUrl(urlOrPath, [
|
|
30308
|
-
return new FileResponse(
|
|
30309
|
-
|
|
30636
|
+
if (_env_js__WEBPACK_IMPORTED_MODULE_2__.env.useFS && !isValidUrl(urlOrPath, ["http:", "https:", "blob:"])) {
|
|
30637
|
+
return new FileResponse(
|
|
30638
|
+
urlOrPath instanceof URL
|
|
30639
|
+
? urlOrPath.protocol === "file:"
|
|
30640
|
+
? urlOrPath.pathname
|
|
30641
|
+
: urlOrPath.toString()
|
|
30642
|
+
: urlOrPath,
|
|
30643
|
+
);
|
|
30310
30644
|
} else if (typeof process !== 'undefined' && process?.release?.name === 'node') {
|
|
30311
30645
|
const IS_CI = !!process.env?.TESTING_REMOTELY;
|
|
30312
30646
|
const version = _env_js__WEBPACK_IMPORTED_MODULE_2__.env.version;
|
|
@@ -30370,7 +30704,7 @@ function handleError(status, remoteURL, fatal) {
|
|
|
30370
30704
|
class FileCache {
|
|
30371
30705
|
/**
|
|
30372
30706
|
* Instantiate a `FileCache` object.
|
|
30373
|
-
* @param {string} path
|
|
30707
|
+
* @param {string} path
|
|
30374
30708
|
*/
|
|
30375
30709
|
constructor(path) {
|
|
30376
30710
|
this.path = path;
|
|
@@ -30378,7 +30712,7 @@ class FileCache {
|
|
|
30378
30712
|
|
|
30379
30713
|
/**
|
|
30380
30714
|
* Checks whether the given request is in the cache.
|
|
30381
|
-
* @param {string} request
|
|
30715
|
+
* @param {string} request
|
|
30382
30716
|
* @returns {Promise<FileResponse | undefined>}
|
|
30383
30717
|
*/
|
|
30384
30718
|
async match(request) {
|
|
@@ -30395,8 +30729,8 @@ class FileCache {
|
|
|
30395
30729
|
|
|
30396
30730
|
/**
|
|
30397
30731
|
* Adds the given response to the cache.
|
|
30398
|
-
* @param {string} request
|
|
30399
|
-
* @param {Response} response
|
|
30732
|
+
* @param {string} request
|
|
30733
|
+
* @param {Response} response
|
|
30400
30734
|
* @param {(data: {progress: number, loaded: number, total: number}) => void} [progress_callback] Optional.
|
|
30401
30735
|
* The function to call with progress updates
|
|
30402
30736
|
* @returns {Promise<void>}
|
|
@@ -30454,7 +30788,7 @@ class FileCache {
|
|
|
30454
30788
|
}
|
|
30455
30789
|
|
|
30456
30790
|
/**
|
|
30457
|
-
*
|
|
30791
|
+
*
|
|
30458
30792
|
* @param {FileCache|Cache} cache The cache to search
|
|
30459
30793
|
* @param {string[]} names The names of the item to search for
|
|
30460
30794
|
* @returns {Promise<FileResponse|Response|undefined>} The item from the cache, or undefined if not found.
|
|
@@ -34742,6 +35076,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
34742
35076
|
/* harmony export */ ConvNextV2ForImageClassification: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2ForImageClassification),
|
|
34743
35077
|
/* harmony export */ ConvNextV2Model: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2Model),
|
|
34744
35078
|
/* harmony export */ ConvNextV2PreTrainedModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2PreTrainedModel),
|
|
35079
|
+
/* harmony export */ DFineForObjectDetection: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DFineForObjectDetection),
|
|
35080
|
+
/* harmony export */ DFineModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DFineModel),
|
|
35081
|
+
/* harmony export */ DFinePreTrainedModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DFinePreTrainedModel),
|
|
34745
35082
|
/* harmony export */ DPTFeatureExtractor: () => (/* reexport safe */ _models_image_processors_js__WEBPACK_IMPORTED_MODULE_14__.DPTFeatureExtractor),
|
|
34746
35083
|
/* harmony export */ DPTForDepthEstimation: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DPTForDepthEstimation),
|
|
34747
35084
|
/* harmony export */ DPTImageProcessor: () => (/* reexport safe */ _models_image_processors_js__WEBPACK_IMPORTED_MODULE_14__.DPTImageProcessor),
|
|
@@ -35129,6 +35466,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
35129
35466
|
/* harmony export */ Qwen2VLImageProcessor: () => (/* reexport safe */ _models_image_processors_js__WEBPACK_IMPORTED_MODULE_14__.Qwen2VLImageProcessor),
|
|
35130
35467
|
/* harmony export */ Qwen2VLPreTrainedModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen2VLPreTrainedModel),
|
|
35131
35468
|
/* harmony export */ Qwen2VLProcessor: () => (/* reexport safe */ _models_processors_js__WEBPACK_IMPORTED_MODULE_17__.Qwen2VLProcessor),
|
|
35469
|
+
/* harmony export */ Qwen3ForCausalLM: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen3ForCausalLM),
|
|
35470
|
+
/* harmony export */ Qwen3Model: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen3Model),
|
|
35471
|
+
/* harmony export */ Qwen3PreTrainedModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen3PreTrainedModel),
|
|
35132
35472
|
/* harmony export */ RFDetrForObjectDetection: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RFDetrForObjectDetection),
|
|
35133
35473
|
/* harmony export */ RFDetrModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RFDetrModel),
|
|
35134
35474
|
/* harmony export */ RFDetrObjectDetectionOutput: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RFDetrObjectDetectionOutput),
|
|
@@ -35454,6 +35794,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
35454
35794
|
|
|
35455
35795
|
|
|
35456
35796
|
|
|
35797
|
+
|
|
35798
|
+
// Expose common types used across the library for developers to access
|
|
35799
|
+
/**
|
|
35800
|
+
* @typedef {import('./utils/hub.js').PretrainedModelOptions} PretrainedModelOptions
|
|
35801
|
+
* @typedef {import('./base/processing_utils.js').PretrainedProcessorOptions} PretrainedProcessorOptions
|
|
35802
|
+
* @typedef {import('./utils/dtypes.js').DataType} DataType
|
|
35803
|
+
* @typedef {import('./utils/devices.js').DeviceType} DeviceType
|
|
35804
|
+
*/
|
|
35457
35805
|
|
|
35458
35806
|
})();
|
|
35459
35807
|
|