@huggingface/transformers 3.5.0 → 3.5.1

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.
@@ -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
- const evaluated = this.evaluateBlock(node.body, scope);
1802
- result += evaluated.value;
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 (size.min_pixels !== undefined && size.max_pixels !== undefined) {
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.0';
4358
+ const VERSION = '3.5.1';
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";
@@ -6147,6 +6406,9 @@ __webpack_require__.r(__webpack_exports__);
6147
6406
  /* harmony export */ ConvNextV2ForImageClassification: () => (/* binding */ ConvNextV2ForImageClassification),
6148
6407
  /* harmony export */ ConvNextV2Model: () => (/* binding */ ConvNextV2Model),
6149
6408
  /* harmony export */ ConvNextV2PreTrainedModel: () => (/* binding */ ConvNextV2PreTrainedModel),
6409
+ /* harmony export */ DFineForObjectDetection: () => (/* binding */ DFineForObjectDetection),
6410
+ /* harmony export */ DFineModel: () => (/* binding */ DFineModel),
6411
+ /* harmony export */ DFinePreTrainedModel: () => (/* binding */ DFinePreTrainedModel),
6150
6412
  /* harmony export */ DPTForDepthEstimation: () => (/* binding */ DPTForDepthEstimation),
6151
6413
  /* harmony export */ DPTModel: () => (/* binding */ DPTModel),
6152
6414
  /* harmony export */ DPTPreTrainedModel: () => (/* binding */ DPTPreTrainedModel),
@@ -6431,6 +6693,9 @@ __webpack_require__.r(__webpack_exports__);
6431
6693
  /* harmony export */ Qwen2PreTrainedModel: () => (/* binding */ Qwen2PreTrainedModel),
6432
6694
  /* harmony export */ Qwen2VLForConditionalGeneration: () => (/* binding */ Qwen2VLForConditionalGeneration),
6433
6695
  /* harmony export */ Qwen2VLPreTrainedModel: () => (/* binding */ Qwen2VLPreTrainedModel),
6696
+ /* harmony export */ Qwen3ForCausalLM: () => (/* binding */ Qwen3ForCausalLM),
6697
+ /* harmony export */ Qwen3Model: () => (/* binding */ Qwen3Model),
6698
+ /* harmony export */ Qwen3PreTrainedModel: () => (/* binding */ Qwen3PreTrainedModel),
6434
6699
  /* harmony export */ RFDetrForObjectDetection: () => (/* binding */ RFDetrForObjectDetection),
6435
6700
  /* harmony export */ RFDetrModel: () => (/* binding */ RFDetrModel),
6436
6701
  /* harmony export */ RFDetrObjectDetectionOutput: () => (/* binding */ RFDetrObjectDetectionOutput),
@@ -6781,6 +7046,7 @@ async function getSession(pretrained_model_name_or_path, fileName, options) {
6781
7046
  const session_config = {
6782
7047
  dtype: selectedDtype,
6783
7048
  kv_cache_dtype,
7049
+ device: selectedDevice,
6784
7050
  }
6785
7051
 
6786
7052
  // Construct the model file name
@@ -6961,6 +7227,10 @@ function validateInputs(session, inputs) {
6961
7227
  return checkedInputs;
6962
7228
  }
6963
7229
 
7230
+ // Currently, Transformers.js doesn't support simultaneous execution of sessions in WASM/WebGPU.
7231
+ // For this reason, we need to chain the inference calls (otherwise we get "Error: Session already started").
7232
+ let webInferenceChain = Promise.resolve();
7233
+
6964
7234
  /**
6965
7235
  * Executes an InferenceSession using the specified inputs.
6966
7236
  * NOTE: `inputs` must contain at least the input names of the model.
@@ -6977,17 +7247,28 @@ async function sessionRun(session, inputs) {
6977
7247
  try {
6978
7248
  // pass the original ort tensor
6979
7249
  const ortFeed = Object.fromEntries(Object.entries(checkedInputs).map(([k, v]) => [k, v.ort_tensor]));
6980
- let output = await session.run(ortFeed);
6981
- output = replaceTensors(output);
6982
- return output;
7250
+ const run = () => session.run(ortFeed);
7251
+ const output = await ((_env_js__WEBPACK_IMPORTED_MODULE_14__.apis.IS_BROWSER_ENV || _env_js__WEBPACK_IMPORTED_MODULE_14__.apis.IS_WEBWORKER_ENV)
7252
+ ? (webInferenceChain = webInferenceChain.then(run))
7253
+ : run());
7254
+ return replaceTensors(output);
6983
7255
  } catch (e) {
6984
7256
  // Error messages can be long (nested) and uninformative. For this reason,
6985
7257
  // we apply minor formatting to show the most important information
6986
7258
  const formatted = Object.fromEntries(Object.entries(checkedInputs)
6987
- .map(([k, { type, dims, data }]) => [k, {
7259
+ .map(([k, tensor]) => {
6988
7260
  // Extract these properties from the underlying ORT tensor
6989
- type, dims, data,
6990
- }]));
7261
+ const unpacked = {
7262
+ type: tensor.type,
7263
+ dims: tensor.dims,
7264
+ location: tensor.location,
7265
+ }
7266
+ if (unpacked.location !== "gpu-buffer") {
7267
+ // Only return the data if it's not a GPU buffer
7268
+ unpacked.data = tensor.data;
7269
+ }
7270
+ return [k, unpacked];
7271
+ }));
6991
7272
 
6992
7273
  // This usually occurs when the inputs are of the wrong type.
6993
7274
  console.error(`An error occurred during model execution: "${e}".`);
@@ -11116,6 +11397,22 @@ class Qwen2Model extends Qwen2PreTrainedModel { }
11116
11397
  class Qwen2ForCausalLM extends Qwen2PreTrainedModel { }
11117
11398
  //////////////////////////////////////////////////
11118
11399
 
11400
+
11401
+ //////////////////////////////////////////////////
11402
+ // Qwen3 models
11403
+
11404
+ /**
11405
+ * The bare Qwen3 Model outputting raw hidden-states without any specific head on top.
11406
+ */
11407
+ class Qwen3PreTrainedModel extends PreTrainedModel { }
11408
+ /**
11409
+ * The bare Qwen3 Model outputting raw hidden-states without any specific head on top.
11410
+ */
11411
+ class Qwen3Model extends Qwen3PreTrainedModel { }
11412
+
11413
+ class Qwen3ForCausalLM extends Qwen3PreTrainedModel { }
11414
+ //////////////////////////////////////////////////
11415
+
11119
11416
  class Qwen2VLPreTrainedModel extends PreTrainedModel {
11120
11417
  forward_params = [
11121
11418
  // Text inputs
@@ -11751,7 +12048,7 @@ class RTDetrV2ForObjectDetection extends RTDetrV2PreTrainedModel {
11751
12048
  }
11752
12049
  }
11753
12050
 
11754
- class RTDetrV2ObjectDetectionOutput extends RTDetrObjectDetectionOutput {}
12051
+ class RTDetrV2ObjectDetectionOutput extends RTDetrObjectDetectionOutput { }
11755
12052
  //////////////////////////////////////////////////
11756
12053
 
11757
12054
  //////////////////////////////////////////////////
@@ -11766,7 +12063,20 @@ class RFDetrForObjectDetection extends RFDetrPreTrainedModel {
11766
12063
  }
11767
12064
  }
11768
12065
 
11769
- class RFDetrObjectDetectionOutput extends RTDetrObjectDetectionOutput {}
12066
+ class RFDetrObjectDetectionOutput extends RTDetrObjectDetectionOutput { }
12067
+ //////////////////////////////////////////////////
12068
+
12069
+ //////////////////////////////////////////////////
12070
+ class DFinePreTrainedModel extends PreTrainedModel { }
12071
+ class DFineModel extends DFinePreTrainedModel { }
12072
+ class DFineForObjectDetection extends DFinePreTrainedModel {
12073
+ /**
12074
+ * @param {any} model_inputs
12075
+ */
12076
+ async _call(model_inputs) {
12077
+ return new RTDetrObjectDetectionOutput(await super._call(model_inputs));
12078
+ }
12079
+ }
11770
12080
  //////////////////////////////////////////////////
11771
12081
 
11772
12082
  //////////////////////////////////////////////////
@@ -14078,6 +14388,7 @@ const MODEL_MAPPING_NAMES_ENCODER_ONLY = new Map([
14078
14388
  ['rt_detr', ['RTDetrModel', RTDetrModel]],
14079
14389
  ['rt_detr_v2', ['RTDetrV2Model', RTDetrV2Model]],
14080
14390
  ['rf_detr', ['RFDetrModel', RFDetrModel]],
14391
+ ['d_fine', ['DFineModel', DFineModel]],
14081
14392
  ['table-transformer', ['TableTransformerModel', TableTransformerModel]],
14082
14393
  ['vit', ['ViTModel', ViTModel]],
14083
14394
  ['ijepa', ['IJepaModel', IJepaModel]],
@@ -14165,6 +14476,7 @@ const MODEL_MAPPING_NAMES_DECODER_ONLY = new Map([
14165
14476
  ['glm', ['GlmModel', GlmModel]],
14166
14477
  ['openelm', ['OpenELMModel', OpenELMModel]],
14167
14478
  ['qwen2', ['Qwen2Model', Qwen2Model]],
14479
+ ['qwen3', ['Qwen3Model', Qwen3Model]],
14168
14480
  ['phi', ['PhiModel', PhiModel]],
14169
14481
  ['phi3', ['Phi3Model', Phi3Model]],
14170
14482
  ['mpt', ['MptModel', MptModel]],
@@ -14265,6 +14577,7 @@ const MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = new Map([
14265
14577
  ['glm', ['GlmForCausalLM', GlmForCausalLM]],
14266
14578
  ['openelm', ['OpenELMForCausalLM', OpenELMForCausalLM]],
14267
14579
  ['qwen2', ['Qwen2ForCausalLM', Qwen2ForCausalLM]],
14580
+ ['qwen3', ['Qwen3ForCausalLM', Qwen3ForCausalLM]],
14268
14581
  ['phi', ['PhiForCausalLM', PhiForCausalLM]],
14269
14582
  ['phi3', ['Phi3ForCausalLM', Phi3ForCausalLM]],
14270
14583
  ['mpt', ['MptForCausalLM', MptForCausalLM]],
@@ -14379,6 +14692,7 @@ const MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES = new Map([
14379
14692
  ['rt_detr', ['RTDetrForObjectDetection', RTDetrForObjectDetection]],
14380
14693
  ['rt_detr_v2', ['RTDetrV2ForObjectDetection', RTDetrV2ForObjectDetection]],
14381
14694
  ['rf_detr', ['RFDetrForObjectDetection', RFDetrForObjectDetection]],
14695
+ ['d_fine', ['DFineForObjectDetection', DFineForObjectDetection]],
14382
14696
  ['table-transformer', ['TableTransformerForObjectDetection', TableTransformerForObjectDetection]],
14383
14697
  ['yolos', ['YolosForObjectDetection', YolosForObjectDetection]],
14384
14698
  ]);
@@ -26525,22 +26839,29 @@ class PreTrainedTokenizer extends _utils_generic_js__WEBPACK_IMPORTED_MODULE_0__
26525
26839
  // For single input, we just wrap in an array, and then unwrap later.
26526
26840
  encodedTokens = [this._encode_plus(text, { text_pair, add_special_tokens, return_token_type_ids })];
26527
26841
  }
26528
- // At this point, tokens is batched: [batch_size, tokens]
26529
- // However, array may be jagged. So, we pad to max_length
26530
-
26842
+ // At this point, `encodedTokens` is batched, of shape [batch_size, tokens].
26843
+ // However, array may be jagged. So, we may need pad to max_length.
26531
26844
  if (max_length === null) {
26532
- if (padding === 'max_length') {
26845
+ max_length = this.model_max_length;
26846
+ } else if (truncation === null) {
26847
+ if (padding === true) {
26848
+ console.warn(
26849
+ "`max_length` is ignored when `padding: true` and there is no truncation strategy. " +
26850
+ "To pad to max length, use `padding: 'max_length'`."
26851
+ )
26533
26852
  max_length = this.model_max_length;
26534
- } else {
26535
- // Calculate max length from sequences
26536
- max_length = (0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_3__.max)(encodedTokens.map(x => x.input_ids.length))[0];
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.`)
26853
+ } else if (padding === false) {
26854
+ 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.");
26855
+ truncation = true;
26541
26856
  }
26542
26857
  }
26543
26858
 
26859
+ // padding: 'max_length' doesn't require any additional calculation
26860
+ // but padding: true has to calculate max_length from the sequences
26861
+ if (padding === true) {
26862
+ max_length = Math.min((0,_utils_maths_js__WEBPACK_IMPORTED_MODULE_3__.max)(encodedTokens.map(x => x.input_ids.length))[0], max_length ?? Infinity);
26863
+ }
26864
+
26544
26865
  // Ensure it is less than model max length
26545
26866
  max_length = Math.min(max_length, this.model_max_length ?? Infinity);
26546
26867
 
@@ -30091,7 +30412,7 @@ __webpack_require__.r(__webpack_exports__);
30091
30412
 
30092
30413
  /**
30093
30414
  * @file Utility functions to interact with the Hugging Face Hub (https://huggingface.co/models)
30094
- *
30415
+ *
30095
30416
  * @module utils/hub
30096
30417
  */
30097
30418
 
@@ -30109,7 +30430,7 @@ __webpack_require__.r(__webpack_exports__);
30109
30430
  const MAX_EXTERNAL_DATA_CHUNKS = 100;
30110
30431
 
30111
30432
  /**
30112
- * @typedef {Object} PretrainedOptions Options for loading a pretrained model.
30433
+ * @typedef {Object} PretrainedOptions Options for loading a pretrained model.
30113
30434
  * @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
30435
  * @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
30436
  * - The model is a model provided by the library (loaded with the *model id* string of a pretrained model).
@@ -30248,7 +30569,7 @@ class FileResponse {
30248
30569
  /**
30249
30570
  * Reads the contents of the file specified by the filePath property and returns a Promise that
30250
30571
  * resolves with a parsed JavaScript object containing the file's contents.
30251
- *
30572
+ *
30252
30573
  * @returns {Promise<Object>} A Promise that resolves with a parsed JavaScript object containing the file's contents.
30253
30574
  * @throws {Error} If the file cannot be read.
30254
30575
  */
@@ -30285,7 +30606,7 @@ const REPO_ID_REGEX = /^(\b[\w\-.]+\b\/)?\b[\w\-.]{1,96}\b$/;
30285
30606
  /**
30286
30607
  * Tests whether a string is a valid Hugging Face model ID or not.
30287
30608
  * Adapted from https://github.com/huggingface/huggingface_hub/blob/6378820ebb03f071988a96c7f3268f5bdf8f9449/src/huggingface_hub/utils/_validators.py#L119-L170
30288
- *
30609
+ *
30289
30610
  * @param {string} string The string to test
30290
30611
  * @returns {boolean} True if the string is a valid model ID, false otherwise.
30291
30612
  */
@@ -30304,9 +30625,14 @@ function isValidHfModelId(string) {
30304
30625
  */
30305
30626
  async function getFile(urlOrPath) {
30306
30627
 
30307
- if (_env_js__WEBPACK_IMPORTED_MODULE_2__.env.useFS && !isValidUrl(urlOrPath, ['http:', 'https:', 'blob:'])) {
30308
- return new FileResponse(urlOrPath.toString());
30309
-
30628
+ if (_env_js__WEBPACK_IMPORTED_MODULE_2__.env.useFS && !isValidUrl(urlOrPath, ["http:", "https:", "blob:"])) {
30629
+ return new FileResponse(
30630
+ urlOrPath instanceof URL
30631
+ ? urlOrPath.protocol === "file:"
30632
+ ? urlOrPath.pathname
30633
+ : urlOrPath.toString()
30634
+ : urlOrPath,
30635
+ );
30310
30636
  } else if (typeof process !== 'undefined' && process?.release?.name === 'node') {
30311
30637
  const IS_CI = !!process.env?.TESTING_REMOTELY;
30312
30638
  const version = _env_js__WEBPACK_IMPORTED_MODULE_2__.env.version;
@@ -30370,7 +30696,7 @@ function handleError(status, remoteURL, fatal) {
30370
30696
  class FileCache {
30371
30697
  /**
30372
30698
  * Instantiate a `FileCache` object.
30373
- * @param {string} path
30699
+ * @param {string} path
30374
30700
  */
30375
30701
  constructor(path) {
30376
30702
  this.path = path;
@@ -30378,7 +30704,7 @@ class FileCache {
30378
30704
 
30379
30705
  /**
30380
30706
  * Checks whether the given request is in the cache.
30381
- * @param {string} request
30707
+ * @param {string} request
30382
30708
  * @returns {Promise<FileResponse | undefined>}
30383
30709
  */
30384
30710
  async match(request) {
@@ -30395,8 +30721,8 @@ class FileCache {
30395
30721
 
30396
30722
  /**
30397
30723
  * Adds the given response to the cache.
30398
- * @param {string} request
30399
- * @param {Response} response
30724
+ * @param {string} request
30725
+ * @param {Response} response
30400
30726
  * @param {(data: {progress: number, loaded: number, total: number}) => void} [progress_callback] Optional.
30401
30727
  * The function to call with progress updates
30402
30728
  * @returns {Promise<void>}
@@ -30454,7 +30780,7 @@ class FileCache {
30454
30780
  }
30455
30781
 
30456
30782
  /**
30457
- *
30783
+ *
30458
30784
  * @param {FileCache|Cache} cache The cache to search
30459
30785
  * @param {string[]} names The names of the item to search for
30460
30786
  * @returns {Promise<FileResponse|Response|undefined>} The item from the cache, or undefined if not found.
@@ -34742,6 +35068,9 @@ __webpack_require__.r(__webpack_exports__);
34742
35068
  /* harmony export */ ConvNextV2ForImageClassification: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2ForImageClassification),
34743
35069
  /* harmony export */ ConvNextV2Model: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2Model),
34744
35070
  /* harmony export */ ConvNextV2PreTrainedModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.ConvNextV2PreTrainedModel),
35071
+ /* harmony export */ DFineForObjectDetection: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DFineForObjectDetection),
35072
+ /* harmony export */ DFineModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DFineModel),
35073
+ /* harmony export */ DFinePreTrainedModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DFinePreTrainedModel),
34745
35074
  /* harmony export */ DPTFeatureExtractor: () => (/* reexport safe */ _models_image_processors_js__WEBPACK_IMPORTED_MODULE_14__.DPTFeatureExtractor),
34746
35075
  /* harmony export */ DPTForDepthEstimation: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.DPTForDepthEstimation),
34747
35076
  /* harmony export */ DPTImageProcessor: () => (/* reexport safe */ _models_image_processors_js__WEBPACK_IMPORTED_MODULE_14__.DPTImageProcessor),
@@ -35129,6 +35458,9 @@ __webpack_require__.r(__webpack_exports__);
35129
35458
  /* harmony export */ Qwen2VLImageProcessor: () => (/* reexport safe */ _models_image_processors_js__WEBPACK_IMPORTED_MODULE_14__.Qwen2VLImageProcessor),
35130
35459
  /* harmony export */ Qwen2VLPreTrainedModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen2VLPreTrainedModel),
35131
35460
  /* harmony export */ Qwen2VLProcessor: () => (/* reexport safe */ _models_processors_js__WEBPACK_IMPORTED_MODULE_17__.Qwen2VLProcessor),
35461
+ /* harmony export */ Qwen3ForCausalLM: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen3ForCausalLM),
35462
+ /* harmony export */ Qwen3Model: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen3Model),
35463
+ /* harmony export */ Qwen3PreTrainedModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.Qwen3PreTrainedModel),
35132
35464
  /* harmony export */ RFDetrForObjectDetection: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RFDetrForObjectDetection),
35133
35465
  /* harmony export */ RFDetrModel: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RFDetrModel),
35134
35466
  /* harmony export */ RFDetrObjectDetectionOutput: () => (/* reexport safe */ _models_js__WEBPACK_IMPORTED_MODULE_2__.RFDetrObjectDetectionOutput),