@huggingface/transformers 4.0.0-next.4 → 4.0.0-next.6

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.
Files changed (187) hide show
  1. package/README.md +15 -5
  2. package/dist/ort-wasm-simd-threaded.jsep.mjs +28 -28
  3. package/dist/transformers.js +3446 -2296
  4. package/dist/transformers.min.js +17 -19
  5. package/dist/transformers.node.cjs +3456 -2263
  6. package/dist/transformers.node.min.cjs +20 -22
  7. package/dist/transformers.node.min.mjs +20 -22
  8. package/dist/transformers.node.mjs +3426 -2258
  9. package/dist/transformers.web.js +1647 -471
  10. package/dist/transformers.web.min.js +18 -18
  11. package/package.json +4 -4
  12. package/src/backends/onnx.js +128 -53
  13. package/src/backends/utils/cacheWasm.js +28 -46
  14. package/src/configs.js +63 -3
  15. package/src/env.js +93 -11
  16. package/src/generation/logits_sampler.js +3 -15
  17. package/src/image_processors_utils.js +2 -6
  18. package/src/models/afmoe/modeling_afmoe.js +5 -0
  19. package/src/models/auto/image_processing_auto.js +2 -1
  20. package/src/models/auto/modeling_auto.js +16 -2
  21. package/src/models/auto/tokenization_auto.js +2 -1
  22. package/src/models/clap/feature_extraction_clap.js +2 -1
  23. package/src/models/marian/tokenization_marian.js +3 -2
  24. package/src/models/modeling_utils.js +45 -7
  25. package/src/models/models.js +10 -0
  26. package/src/models/olmo_hybrid/modeling_olmo_hybrid.js +5 -0
  27. package/src/models/paligemma/processing_paligemma.js +3 -2
  28. package/src/models/processors.js +2 -0
  29. package/src/models/qwen2_5_vl/modeling_qwen2_5_vl.js +5 -0
  30. package/src/models/qwen2_5_vl/processing_qwen2_5_vl.js +3 -0
  31. package/src/models/qwen2_moe/modeling_qwen2_moe.js +5 -0
  32. package/src/models/qwen2_vl/image_processing_qwen2_vl.js +54 -0
  33. package/src/models/qwen2_vl/modeling_qwen2_vl.js +45 -6
  34. package/src/models/qwen3_5/modeling_qwen3_5.js +3 -0
  35. package/src/models/qwen3_5_moe/modeling_qwen3_5_moe.js +3 -0
  36. package/src/models/qwen3_moe/modeling_qwen3_moe.js +5 -0
  37. package/src/models/qwen3_next/modeling_qwen3_next.js +5 -0
  38. package/src/models/qwen3_vl/modeling_qwen3_vl.js +3 -0
  39. package/src/models/qwen3_vl/processing_qwen3_vl.js +3 -0
  40. package/src/models/qwen3_vl_moe/modeling_qwen3_vl_moe.js +3 -0
  41. package/src/models/registry.js +21 -5
  42. package/src/models/session.js +16 -50
  43. package/src/models/whisper/feature_extraction_whisper.js +2 -1
  44. package/src/models/whisper/modeling_whisper.js +6 -5
  45. package/src/models/xlm/tokenization_xlm.js +2 -1
  46. package/src/pipelines/automatic-speech-recognition.js +3 -2
  47. package/src/pipelines/index.js +313 -0
  48. package/src/pipelines/text-generation.js +4 -0
  49. package/src/pipelines/text-to-audio.js +4 -2
  50. package/src/pipelines/zero-shot-classification.js +3 -2
  51. package/src/pipelines.js +139 -428
  52. package/src/tokenization_utils.js +42 -21
  53. package/src/transformers.js +6 -1
  54. package/src/utils/audio.js +2 -1
  55. package/src/utils/cache/FileCache.js +128 -0
  56. package/src/utils/cache.js +7 -4
  57. package/src/utils/core.js +23 -1
  58. package/src/utils/devices.js +22 -0
  59. package/src/utils/dtypes.js +55 -0
  60. package/src/utils/hub/{files.js → FileResponse.js} +0 -90
  61. package/src/utils/hub/utils.js +45 -5
  62. package/src/utils/hub.js +63 -22
  63. package/src/utils/image.js +14 -14
  64. package/src/utils/logger.js +67 -0
  65. package/src/utils/model-loader.js +35 -17
  66. package/src/utils/model_registry/ModelRegistry.js +346 -0
  67. package/src/utils/model_registry/clear_cache.js +128 -0
  68. package/src/utils/model_registry/get_file_metadata.js +149 -0
  69. package/src/utils/model_registry/get_files.js +42 -0
  70. package/src/utils/model_registry/get_model_files.js +193 -0
  71. package/src/utils/model_registry/get_pipeline_files.js +44 -0
  72. package/src/utils/model_registry/get_processor_files.js +20 -0
  73. package/src/utils/model_registry/get_tokenizer_files.js +21 -0
  74. package/src/utils/model_registry/is_cached.js +169 -0
  75. package/src/utils/random.js +225 -0
  76. package/src/utils/tensor.js +8 -21
  77. package/src/utils/video.js +2 -2
  78. package/types/backends/onnx.d.ts.map +1 -1
  79. package/types/backends/utils/cacheWasm.d.ts +3 -17
  80. package/types/backends/utils/cacheWasm.d.ts.map +1 -1
  81. package/types/configs.d.ts.map +1 -1
  82. package/types/env.d.ts +52 -27
  83. package/types/env.d.ts.map +1 -1
  84. package/types/generation/logits_sampler.d.ts +2 -2
  85. package/types/generation/logits_sampler.d.ts.map +1 -1
  86. package/types/image_processors_utils.d.ts.map +1 -1
  87. package/types/models/afmoe/modeling_afmoe.d.ts +8 -0
  88. package/types/models/afmoe/modeling_afmoe.d.ts.map +1 -0
  89. package/types/models/auto/image_processing_auto.d.ts.map +1 -1
  90. package/types/models/auto/modeling_auto.d.ts +6 -0
  91. package/types/models/auto/modeling_auto.d.ts.map +1 -1
  92. package/types/models/auto/tokenization_auto.d.ts.map +1 -1
  93. package/types/models/clap/feature_extraction_clap.d.ts.map +1 -1
  94. package/types/models/marian/tokenization_marian.d.ts.map +1 -1
  95. package/types/models/modeling_utils.d.ts +13 -2
  96. package/types/models/modeling_utils.d.ts.map +1 -1
  97. package/types/models/models.d.ts +10 -0
  98. package/types/models/olmo_hybrid/modeling_olmo_hybrid.d.ts +8 -0
  99. package/types/models/olmo_hybrid/modeling_olmo_hybrid.d.ts.map +1 -0
  100. package/types/models/paligemma/processing_paligemma.d.ts.map +1 -1
  101. package/types/models/processors.d.ts +2 -0
  102. package/types/models/qwen2_5_vl/modeling_qwen2_5_vl.d.ts +4 -0
  103. package/types/models/qwen2_5_vl/modeling_qwen2_5_vl.d.ts.map +1 -0
  104. package/types/models/qwen2_5_vl/processing_qwen2_5_vl.d.ts +4 -0
  105. package/types/models/qwen2_5_vl/processing_qwen2_5_vl.d.ts.map +1 -0
  106. package/types/models/qwen2_moe/modeling_qwen2_moe.d.ts +8 -0
  107. package/types/models/qwen2_moe/modeling_qwen2_moe.d.ts.map +1 -0
  108. package/types/models/qwen2_vl/image_processing_qwen2_vl.d.ts +3 -0
  109. package/types/models/qwen2_vl/image_processing_qwen2_vl.d.ts.map +1 -1
  110. package/types/models/qwen2_vl/modeling_qwen2_vl.d.ts +1 -0
  111. package/types/models/qwen2_vl/modeling_qwen2_vl.d.ts.map +1 -1
  112. package/types/models/qwen3_5/modeling_qwen3_5.d.ts +4 -0
  113. package/types/models/qwen3_5/modeling_qwen3_5.d.ts.map +1 -0
  114. package/types/models/qwen3_5_moe/modeling_qwen3_5_moe.d.ts +4 -0
  115. package/types/models/qwen3_5_moe/modeling_qwen3_5_moe.d.ts.map +1 -0
  116. package/types/models/qwen3_moe/modeling_qwen3_moe.d.ts +8 -0
  117. package/types/models/qwen3_moe/modeling_qwen3_moe.d.ts.map +1 -0
  118. package/types/models/qwen3_next/modeling_qwen3_next.d.ts +8 -0
  119. package/types/models/qwen3_next/modeling_qwen3_next.d.ts.map +1 -0
  120. package/types/models/qwen3_vl/modeling_qwen3_vl.d.ts +4 -0
  121. package/types/models/qwen3_vl/modeling_qwen3_vl.d.ts.map +1 -0
  122. package/types/models/qwen3_vl/processing_qwen3_vl.d.ts +4 -0
  123. package/types/models/qwen3_vl/processing_qwen3_vl.d.ts.map +1 -0
  124. package/types/models/qwen3_vl_moe/modeling_qwen3_vl_moe.d.ts +4 -0
  125. package/types/models/qwen3_vl_moe/modeling_qwen3_vl_moe.d.ts.map +1 -0
  126. package/types/models/registry.d.ts +2 -1
  127. package/types/models/registry.d.ts.map +1 -1
  128. package/types/models/session.d.ts.map +1 -1
  129. package/types/models/whisper/feature_extraction_whisper.d.ts.map +1 -1
  130. package/types/models/whisper/modeling_whisper.d.ts.map +1 -1
  131. package/types/models/xlm/tokenization_xlm.d.ts.map +1 -1
  132. package/types/pipelines/automatic-speech-recognition.d.ts.map +1 -1
  133. package/types/pipelines/index.d.ts +265 -0
  134. package/types/pipelines/index.d.ts.map +1 -0
  135. package/types/pipelines/text-generation.d.ts +5 -1
  136. package/types/pipelines/text-generation.d.ts.map +1 -1
  137. package/types/pipelines/text-to-audio.d.ts.map +1 -1
  138. package/types/pipelines/zero-shot-classification.d.ts.map +1 -1
  139. package/types/pipelines.d.ts +50 -291
  140. package/types/pipelines.d.ts.map +1 -1
  141. package/types/tokenization_utils.d.ts +44 -26
  142. package/types/tokenization_utils.d.ts.map +1 -1
  143. package/types/transformers.d.ts +4 -1
  144. package/types/transformers.d.ts.map +1 -1
  145. package/types/utils/audio.d.ts.map +1 -1
  146. package/types/utils/cache/FileCache.d.ts +39 -0
  147. package/types/utils/cache/FileCache.d.ts.map +1 -0
  148. package/types/utils/cache.d.ts +10 -4
  149. package/types/utils/cache.d.ts.map +1 -1
  150. package/types/utils/core.d.ts +59 -2
  151. package/types/utils/core.d.ts.map +1 -1
  152. package/types/utils/devices.d.ts +15 -0
  153. package/types/utils/devices.d.ts.map +1 -1
  154. package/types/utils/dtypes.d.ts +16 -0
  155. package/types/utils/dtypes.d.ts.map +1 -1
  156. package/types/utils/hub/{files.d.ts → FileResponse.d.ts} +1 -32
  157. package/types/utils/hub/FileResponse.d.ts.map +1 -0
  158. package/types/utils/hub/utils.d.ts +19 -3
  159. package/types/utils/hub/utils.d.ts.map +1 -1
  160. package/types/utils/hub.d.ts +36 -7
  161. package/types/utils/hub.d.ts.map +1 -1
  162. package/types/utils/logger.d.ts +28 -0
  163. package/types/utils/logger.d.ts.map +1 -0
  164. package/types/utils/model-loader.d.ts +15 -0
  165. package/types/utils/model-loader.d.ts.map +1 -1
  166. package/types/utils/model_registry/ModelRegistry.d.ts +271 -0
  167. package/types/utils/model_registry/ModelRegistry.d.ts.map +1 -0
  168. package/types/utils/model_registry/clear_cache.d.ts +74 -0
  169. package/types/utils/model_registry/clear_cache.d.ts.map +1 -0
  170. package/types/utils/model_registry/get_file_metadata.d.ts +20 -0
  171. package/types/utils/model_registry/get_file_metadata.d.ts.map +1 -0
  172. package/types/utils/model_registry/get_files.d.ts +23 -0
  173. package/types/utils/model_registry/get_files.d.ts.map +1 -0
  174. package/types/utils/model_registry/get_model_files.d.ts +22 -0
  175. package/types/utils/model_registry/get_model_files.d.ts.map +1 -0
  176. package/types/utils/model_registry/get_pipeline_files.d.ts +22 -0
  177. package/types/utils/model_registry/get_pipeline_files.d.ts.map +1 -0
  178. package/types/utils/model_registry/get_processor_files.d.ts +9 -0
  179. package/types/utils/model_registry/get_processor_files.d.ts.map +1 -0
  180. package/types/utils/model_registry/get_tokenizer_files.d.ts +9 -0
  181. package/types/utils/model_registry/get_tokenizer_files.d.ts.map +1 -0
  182. package/types/utils/model_registry/is_cached.d.ts +105 -0
  183. package/types/utils/model_registry/is_cached.d.ts.map +1 -0
  184. package/types/utils/random.d.ts +86 -0
  185. package/types/utils/random.d.ts.map +1 -0
  186. package/types/utils/tensor.d.ts.map +1 -1
  187. package/types/utils/hub/files.d.ts.map +0 -1
@@ -5,32 +5,41 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // ignore-modules:node:fs
8
- var emptyObj = {};
9
- var node_fs_default = emptyObj;
8
+ var node_fs_default = {};
10
9
 
11
10
  // ignore-modules:node:path
12
- var emptyObj2 = {};
13
- var node_path_default = emptyObj2;
11
+ var node_path_default = {};
14
12
 
15
13
  // ignore-modules:node:url
16
- var emptyObj3 = {};
17
- var node_url_default = emptyObj3;
14
+ var node_url_default = {};
18
15
 
19
16
  // src/env.js
20
- var VERSION = "4.0.0-next.4";
21
- var IS_PROCESS_AVAILABLE = typeof process !== "undefined";
22
- var IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === "node";
17
+ var VERSION = "4.0.0-next.6";
18
+ var HAS_SELF = typeof self !== "undefined";
23
19
  var IS_FS_AVAILABLE = !isEmpty(node_fs_default);
24
20
  var IS_PATH_AVAILABLE = !isEmpty(node_path_default);
21
+ var IS_WEB_CACHE_AVAILABLE = HAS_SELF && "caches" in self;
25
22
  var IS_DENO_RUNTIME = typeof globalThis.Deno !== "undefined";
26
23
  var IS_BUN_RUNTIME = typeof globalThis.Bun !== "undefined";
24
+ var IS_DENO_WEB_RUNTIME = IS_DENO_RUNTIME && IS_WEB_CACHE_AVAILABLE && !IS_FS_AVAILABLE;
25
+ var IS_PROCESS_AVAILABLE = typeof process !== "undefined";
26
+ var IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === "node" && !IS_DENO_WEB_RUNTIME;
27
27
  var IS_BROWSER_ENV = typeof window !== "undefined" && typeof window.document !== "undefined";
28
- var IS_WEBWORKER_ENV = typeof self !== "undefined" && ["DedicatedWorkerGlobalScope", "ServiceWorkerGlobalScope", "SharedWorkerGlobalScope"].includes(
28
+ var IS_WEBWORKER_ENV = HAS_SELF && ["DedicatedWorkerGlobalScope", "ServiceWorkerGlobalScope", "SharedWorkerGlobalScope"].includes(
29
29
  self.constructor?.name
30
30
  );
31
- var IS_WEB_CACHE_AVAILABLE = typeof self !== "undefined" && "caches" in self;
31
+ var IS_WEB_ENV = IS_BROWSER_ENV || IS_WEBWORKER_ENV || IS_DENO_WEB_RUNTIME;
32
32
  var IS_WEBGPU_AVAILABLE = IS_NODE_ENV || typeof navigator !== "undefined" && "gpu" in navigator;
33
33
  var IS_WEBNN_AVAILABLE = typeof navigator !== "undefined" && "ml" in navigator;
34
+ var IS_CRYPTO_AVAILABLE = typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function";
35
+ var IS_CHROME_AVAILABLE = (
36
+ // @ts-ignore - chrome may not exist in all environments
37
+ typeof chrome !== "undefined" && typeof chrome.runtime !== "undefined" && typeof chrome.runtime.id === "string"
38
+ );
39
+ var IS_SERVICE_WORKER_ENV = (
40
+ // @ts-ignore - ServiceWorkerGlobalScope may not exist in all environments
41
+ typeof ServiceWorkerGlobalScope !== "undefined" && HAS_SELF && self instanceof ServiceWorkerGlobalScope
42
+ );
34
43
  var isSafari = () => {
35
44
  if (typeof navigator === "undefined") {
36
45
  return false;
@@ -47,6 +56,12 @@ var apis = Object.freeze({
47
56
  IS_BROWSER_ENV,
48
57
  /** Whether we are running in a web worker environment */
49
58
  IS_WEBWORKER_ENV,
59
+ /** Whether we are running in a web-like environment (browser, web worker, or Deno web runtime) */
60
+ IS_WEB_ENV,
61
+ /** Whether we are running in a service worker environment */
62
+ IS_SERVICE_WORKER_ENV,
63
+ /** Whether we are running in Deno's web runtime (CDN imports, Cache API available, no filesystem) */
64
+ IS_DENO_WEB_RUNTIME,
50
65
  /** Whether the Cache API is available */
51
66
  IS_WEB_CACHE_AVAILABLE,
52
67
  /** Whether the WebGPU API is available */
@@ -62,7 +77,11 @@ var apis = Object.freeze({
62
77
  /** Whether the filesystem API is available */
63
78
  IS_FS_AVAILABLE,
64
79
  /** Whether the path API is available */
65
- IS_PATH_AVAILABLE
80
+ IS_PATH_AVAILABLE,
81
+ /** Whether the crypto API is available */
82
+ IS_CRYPTO_AVAILABLE,
83
+ /** Whether the Chrome runtime API is available */
84
+ IS_CHROME_AVAILABLE
66
85
  });
67
86
  var RUNNING_LOCALLY = IS_FS_AVAILABLE && IS_PATH_AVAILABLE;
68
87
  var dirname__ = "./";
@@ -77,6 +96,20 @@ if (RUNNING_LOCALLY) {
77
96
  var DEFAULT_CACHE_DIR = RUNNING_LOCALLY ? node_path_default.join(dirname__, "/.cache/") : null;
78
97
  var DEFAULT_LOCAL_MODEL_PATH = "/models/";
79
98
  var localModelPath = RUNNING_LOCALLY ? node_path_default.join(dirname__, DEFAULT_LOCAL_MODEL_PATH) : DEFAULT_LOCAL_MODEL_PATH;
99
+ var DEFAULT_FETCH = typeof globalThis.fetch === "function" ? globalThis.fetch.bind(globalThis) : void 0;
100
+ var LogLevel = Object.freeze({
101
+ /** All messages including debug output (value: 10) */
102
+ DEBUG: 10,
103
+ /** Errors, warnings, and info messages (value: 20) */
104
+ INFO: 20,
105
+ /** Errors and warnings (value: 30) */
106
+ WARNING: 30,
107
+ /** Only error messages (value: 40) */
108
+ ERROR: 40,
109
+ /** No logging output (value: 50) */
110
+ NONE: 50
111
+ });
112
+ var logLevel = LogLevel.WARNING;
80
113
  var env = {
81
114
  version: VERSION,
82
115
  /////////////////// Backends settings ///////////////////
@@ -85,28 +118,132 @@ var env = {
85
118
  // onnxruntime-web/onnxruntime-node
86
119
  onnx: {}
87
120
  },
121
+ /////////////////// Logging settings ///////////////////
122
+ get logLevel() {
123
+ return logLevel;
124
+ },
125
+ set logLevel(level) {
126
+ logLevel = level;
127
+ env.backends.onnx?.setLogLevel?.(level);
128
+ },
88
129
  /////////////////// Model settings ///////////////////
89
130
  allowRemoteModels: true,
90
131
  remoteHost: "https://huggingface.co/",
91
132
  remotePathTemplate: "{model}/resolve/{revision}/",
92
- allowLocalModels: !(IS_BROWSER_ENV || IS_WEBWORKER_ENV),
133
+ allowLocalModels: !(IS_BROWSER_ENV || IS_WEBWORKER_ENV || IS_DENO_WEB_RUNTIME),
134
+ // Default to true for non-web environments, false for web environments
93
135
  localModelPath,
94
136
  useFS: IS_FS_AVAILABLE,
95
137
  /////////////////// Cache settings ///////////////////
96
- useBrowserCache: IS_WEB_CACHE_AVAILABLE && !IS_DENO_RUNTIME,
138
+ useBrowserCache: IS_WEB_CACHE_AVAILABLE,
97
139
  useFSCache: IS_FS_AVAILABLE,
98
140
  cacheDir: DEFAULT_CACHE_DIR,
99
141
  useCustomCache: false,
100
142
  customCache: null,
101
143
  useWasmCache: IS_WEB_CACHE_AVAILABLE || IS_FS_AVAILABLE,
102
- cacheKey: "transformers-cache"
144
+ cacheKey: "transformers-cache",
145
+ /////////////////// Custom fetch /////////////////////
146
+ fetch: DEFAULT_FETCH
103
147
  //////////////////////////////////////////////////////
104
148
  };
105
149
  function isEmpty(obj) {
106
150
  return Object.keys(obj).length === 0;
107
151
  }
108
152
 
109
- // ../../node_modules/.pnpm/@huggingface+tokenizers@0.1.1/node_modules/@huggingface/tokenizers/dist/tokenizers.mjs
153
+ // src/utils/core.js
154
+ function dispatchCallback(progress_callback, data) {
155
+ if (progress_callback) progress_callback(data);
156
+ }
157
+ function isIntegralNumber(x) {
158
+ return Number.isInteger(x) || typeof x === "bigint";
159
+ }
160
+ function isNullishDimension(x) {
161
+ return x === null || x === void 0 || x === -1;
162
+ }
163
+ function calculateDimensions(arr) {
164
+ const dimensions = [];
165
+ let current = arr;
166
+ while (Array.isArray(current)) {
167
+ dimensions.push(current.length);
168
+ current = current[0];
169
+ }
170
+ return dimensions;
171
+ }
172
+ function mergeArrays(...arrs) {
173
+ return Array.prototype.concat.apply([], arrs);
174
+ }
175
+ function product(...a) {
176
+ return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e])));
177
+ }
178
+ function calculateReflectOffset(i, w) {
179
+ return Math.abs((i + w) % (2 * w) - w);
180
+ }
181
+ function pick(o, props) {
182
+ return Object.assign(
183
+ {},
184
+ ...props.map((prop) => {
185
+ if (o[prop] !== void 0) {
186
+ return { [prop]: o[prop] };
187
+ }
188
+ })
189
+ );
190
+ }
191
+ function count(arr, value) {
192
+ let count2 = 0;
193
+ for (const v of arr) {
194
+ if (v === value) ++count2;
195
+ }
196
+ return count2;
197
+ }
198
+
199
+ // src/utils/logger.js
200
+ var logger = {
201
+ /**
202
+ * Log an error message. Only suppressed when logLevel is NONE.
203
+ * @param {...any} args - Arguments to log
204
+ */
205
+ error(...args) {
206
+ if (env.logLevel <= LogLevel.ERROR) {
207
+ console.error(...args);
208
+ }
209
+ },
210
+ /**
211
+ * Log a warning message. Shown when logLevel <= WARNING.
212
+ * @param {...any} args - Arguments to log
213
+ */
214
+ warn(...args) {
215
+ if (env.logLevel <= LogLevel.WARNING) {
216
+ console.warn(...args);
217
+ }
218
+ },
219
+ /**
220
+ * Log an info message. Shown when logLevel <= INFO.
221
+ * @param {...any} args - Arguments to log
222
+ */
223
+ info(...args) {
224
+ if (env.logLevel <= LogLevel.INFO) {
225
+ console.log(...args);
226
+ }
227
+ },
228
+ /**
229
+ * Log a debug message. Only shown when logLevel is DEBUG.
230
+ * @param {...any} args - Arguments to log
231
+ */
232
+ debug(...args) {
233
+ if (env.logLevel <= LogLevel.DEBUG) {
234
+ console.log(...args);
235
+ }
236
+ },
237
+ /**
238
+ * Log a message (alias for info). Shown when logLevel <= INFO.
239
+ * @param {...any} args - Arguments to log
240
+ */
241
+ log(...args) {
242
+ this.info(...args);
243
+ }
244
+ };
245
+
246
+ // ../../node_modules/.pnpm/@huggingface+tokenizers@0.1.2/node_modules/@huggingface/tokenizers/dist/tokenizers.mjs
110
247
  var DictionarySplitter = class {
111
248
  /**
112
249
  * @param dictionary The dictionary of words to use for splitting.
@@ -230,6 +367,14 @@ var PROBLEMATIC_REGEX_MAP = /* @__PURE__ */ new Map([
230
367
  // JS doesn't support possessive quantifiers (these are used in recent OpenAI tokenizers).
231
368
  ["[^\\r\\n\\p{L}\\p{N}]?+", "[^\\r\\n\\p{L}\\p{N}]?"],
232
369
  ["[^\\s\\p{L}\\p{N}]++", "[^\\s\\p{L}\\p{N}]+"],
370
+ // JS doesn't support atomic groups (these are used in AFMoE tokenizers).
371
+ ["(?>\\p{Nd}{510})", "(?:\\p{Nd}{510})"],
372
+ // JS doesn't support stacking quantifiers.
373
+ // Uncaught SyntaxError: Invalid regular expression: /\p{Nd}{3}+/u: Nothing to repeat
374
+ ["\\p{Nd}{3}+", "(?:\\p{Nd}{3})+"],
375
+ // \G is an invalid escape in JS, and in most cases is just used as an optimization.
376
+ // So, we can safely remove it.
377
+ ["\\G", ""],
233
378
  // Used to override the default (invalid) regex of the bloom pretokenizer.
234
379
  // For more information, see https://github.com/huggingface/transformers.js/issues/94
235
380
  [` ?[^(\\s|[${BLOOM_SPLIT_CHARS}])]+`, ` ?[^\\s${BLOOM_SPLIT_CHARS}]+`]
@@ -239,6 +384,7 @@ var clean_up_tokenization = (text) => text.replace(/ \./g, ".").replace(/ \?/g,
239
384
  var create_pattern = (pattern, invert = true) => {
240
385
  if (pattern.Regex !== void 0) {
241
386
  let regex = pattern.Regex.replace(/\\([#&~])/g, "$1");
387
+ regex = regex.replace(/\\A/g, "^").replace(/\\z/g, "$").replace(/\\Z/g, "(?=\\r?\\n?$)");
242
388
  for (const [key, value] of PROBLEMATIC_REGEX_MAP) {
243
389
  regex = regex.replaceAll(key, value);
244
390
  }
@@ -5380,53 +5526,7 @@ var Callable2 = (
5380
5526
  }
5381
5527
  );
5382
5528
 
5383
- // src/utils/core.js
5384
- function dispatchCallback(progress_callback, data) {
5385
- if (progress_callback) progress_callback(data);
5386
- }
5387
- function isIntegralNumber(x) {
5388
- return Number.isInteger(x) || typeof x === "bigint";
5389
- }
5390
- function isNullishDimension(x) {
5391
- return x === null || x === void 0 || x === -1;
5392
- }
5393
- function calculateDimensions(arr) {
5394
- const dimensions = [];
5395
- let current = arr;
5396
- while (Array.isArray(current)) {
5397
- dimensions.push(current.length);
5398
- current = current[0];
5399
- }
5400
- return dimensions;
5401
- }
5402
- function mergeArrays(...arrs) {
5403
- return Array.prototype.concat.apply([], arrs);
5404
- }
5405
- function product(...a) {
5406
- return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e])));
5407
- }
5408
- function calculateReflectOffset(i, w) {
5409
- return Math.abs((i + w) % (2 * w) - w);
5410
- }
5411
- function pick(o, props) {
5412
- return Object.assign(
5413
- {},
5414
- ...props.map((prop) => {
5415
- if (o[prop] !== void 0) {
5416
- return { [prop]: o[prop] };
5417
- }
5418
- })
5419
- );
5420
- }
5421
- function count(arr, value) {
5422
- let count2 = 0;
5423
- for (const v of arr) {
5424
- if (v === value) ++count2;
5425
- }
5426
- return count2;
5427
- }
5428
-
5429
- // src/utils/hub/files.js
5529
+ // src/utils/hub/FileResponse.js
5430
5530
  var CONTENT_TYPE_MAP = {
5431
5531
  txt: "text/plain",
5432
5532
  html: "text/html",
@@ -5537,6 +5637,170 @@ var FileResponse = class _FileResponse {
5537
5637
  return JSON.parse(await this.text());
5538
5638
  }
5539
5639
  };
5640
+
5641
+ // src/utils/random.js
5642
+ var Random = class {
5643
+ constructor(seed) {
5644
+ this._mt = new Uint32Array(624);
5645
+ this._idx = 625;
5646
+ this._gauss_next = null;
5647
+ this._random_fn = this.random.bind(this);
5648
+ this.seed(seed);
5649
+ }
5650
+ /**
5651
+ * Seeds this instance's PRNG.
5652
+ *
5653
+ * When called with a number, initializes the state deterministically from that value.
5654
+ * When called with no arguments (or `undefined`/`null`), seeds from OS entropy
5655
+ * via `crypto.getRandomValues`, matching Python's `random.seed()` behaviour.
5656
+ *
5657
+ * @param {number} [n] The seed value. Omit to seed from OS entropy.
5658
+ */
5659
+ seed(n) {
5660
+ if (n === void 0 || n === null) {
5661
+ if (apis.IS_CRYPTO_AVAILABLE) {
5662
+ const buf = new Uint32Array(1);
5663
+ crypto.getRandomValues(buf);
5664
+ n = buf[0];
5665
+ } else {
5666
+ n = Date.now() >>> 0;
5667
+ }
5668
+ }
5669
+ const mt = this._mt;
5670
+ const u = (a, b) => Math.imul(a, b) >>> 0, key = [];
5671
+ for (let v = n || 0; v > 0; v = Math.floor(v / 4294967296)) key.push(v & 4294967295);
5672
+ if (!key.length) key.push(0);
5673
+ mt[0] = 19650218;
5674
+ for (let k = 1; k < 624; ++k) mt[k] = u(1812433253, mt[k - 1] ^ mt[k - 1] >>> 30) + k >>> 0;
5675
+ let i = 1, j = 0;
5676
+ for (let k = Math.max(624, key.length); k > 0; --k, ++i, ++j) {
5677
+ if (i >= 624) {
5678
+ mt[0] = mt[623];
5679
+ i = 1;
5680
+ }
5681
+ if (j >= key.length) j = 0;
5682
+ mt[i] = (mt[i] ^ u(mt[i - 1] ^ mt[i - 1] >>> 30, 1664525)) + key[j] + j >>> 0;
5683
+ }
5684
+ for (let k = 623; k > 0; --k, ++i) {
5685
+ if (i >= 624) {
5686
+ mt[0] = mt[623];
5687
+ i = 1;
5688
+ }
5689
+ mt[i] = (mt[i] ^ u(mt[i - 1] ^ mt[i - 1] >>> 30, 1566083941)) - i >>> 0;
5690
+ }
5691
+ mt[0] = 2147483648;
5692
+ this._idx = 624;
5693
+ this._gauss_next = null;
5694
+ }
5695
+ /**
5696
+ * Generates a random unsigned 32-bit integer.
5697
+ *
5698
+ * Performs the "twist" step when the state buffer is exhausted,
5699
+ * then applies the standard MT19937 tempering transform.
5700
+ *
5701
+ * @returns {number} A random integer in the range [0, 2^32 - 1].
5702
+ */
5703
+ _int32() {
5704
+ const mt = this._mt;
5705
+ if (this._idx >= 624) {
5706
+ for (let k = 0; k < 624; ++k) {
5707
+ const y2 = mt[k] & 2147483648 | mt[(k + 1) % 624] & 2147483647;
5708
+ mt[k] = (mt[(k + 397) % 624] ^ y2 >>> 1 ^ (y2 & 1 ? 2567483615 : 0)) >>> 0;
5709
+ }
5710
+ this._idx = 0;
5711
+ }
5712
+ let y = mt[this._idx++];
5713
+ y ^= y >>> 11;
5714
+ y ^= y << 7 & 2636928640;
5715
+ y ^= y << 15 & 4022730752;
5716
+ y ^= y >>> 18;
5717
+ return y >>> 0;
5718
+ }
5719
+ /**
5720
+ * Generates a random floating-point number in the half-open interval [0, 1).
5721
+ *
5722
+ * Combines two 32-bit integers (using 53 bits of precision) to produce
5723
+ * a uniformly distributed double, matching Python's `random.random()`.
5724
+ *
5725
+ * @returns {number} A random float in [0, 1).
5726
+ */
5727
+ random() {
5728
+ return ((this._int32() >>> 5) * 67108864 + (this._int32() >>> 6)) / 9007199254740992;
5729
+ }
5730
+ /**
5731
+ * Generates a random number from a Gaussian (normal) distribution.
5732
+ *
5733
+ * Uses the Box-Muller transform with a cached spare value,
5734
+ * matching Python's `random.gauss()` output for the same seed.
5735
+ *
5736
+ * @param {number} [mu=0] The mean of the distribution.
5737
+ * @param {number} [sigma=1] The standard deviation of the distribution.
5738
+ * @returns {number} A normally distributed random value.
5739
+ */
5740
+ gauss(mu = 0, sigma = 1) {
5741
+ let z = this._gauss_next;
5742
+ this._gauss_next = null;
5743
+ if (z === null) {
5744
+ const x2pi = this.random() * 2 * Math.PI, g2rad = Math.sqrt(-2 * Math.log(1 - this.random()));
5745
+ z = Math.cos(x2pi) * g2rad;
5746
+ this._gauss_next = Math.sin(x2pi) * g2rad;
5747
+ }
5748
+ return mu + z * sigma;
5749
+ }
5750
+ /**
5751
+ * Shuffles an array in-place using the Fisher-Yates algorithm.
5752
+ *
5753
+ * Uses rejection sampling via `getrandbits`-style bit masking to ensure
5754
+ * a uniform distribution, matching Python's `random.shuffle()`.
5755
+ *
5756
+ * @param {any[]} arr The array to shuffle in-place.
5757
+ */
5758
+ shuffle(arr) {
5759
+ for (let i = arr.length - 1; i > 0; --i) {
5760
+ const k = 32 - Math.clz32(i + 1);
5761
+ let r = this._int32() >>> 32 - k;
5762
+ while (r > i) r = this._int32() >>> 32 - k;
5763
+ const t = arr[i];
5764
+ arr[i] = arr[r];
5765
+ arr[r] = t;
5766
+ }
5767
+ }
5768
+ /**
5769
+ * Selects a single element from a weighted population.
5770
+ *
5771
+ * Matches Python's `random.choices(population, weights=weights, k=1)[0]`
5772
+ *
5773
+ * @param {any[]} population The array of items to choose from.
5774
+ * @param {number[]} weights An array of non-negative weights, one per population element.
5775
+ * @returns {*} A single randomly selected element from the population.
5776
+ */
5777
+ choices(population, weights) {
5778
+ return population[_weightedIndexWith(this._random_fn, weights)];
5779
+ }
5780
+ };
5781
+ function _weightedIndexWith(randomFn, weights) {
5782
+ let sum = 0;
5783
+ for (let i = 0; i < weights.length; ++i) sum += weights[i];
5784
+ let x = randomFn() * sum;
5785
+ for (let i = 0; i < weights.length; ++i) {
5786
+ x -= weights[i];
5787
+ if (x < 0) return i;
5788
+ }
5789
+ return weights.length - 1;
5790
+ }
5791
+ var _default = new Random();
5792
+ var random = Object.freeze({
5793
+ Random,
5794
+ seed: _default.seed.bind(_default),
5795
+ random: _default.random.bind(_default),
5796
+ gauss: _default.gauss.bind(_default),
5797
+ shuffle: _default.shuffle.bind(_default),
5798
+ choices: _default.choices.bind(_default)
5799
+ });
5800
+ var _weightedIndex = (weights) => _weightedIndexWith(random.random, weights);
5801
+
5802
+ // src/utils/cache/FileCache.js
5803
+ var rng = new Random();
5540
5804
  var FileCache = class {
5541
5805
  /**
5542
5806
  * Instantiate a `FileCache` object.
@@ -5568,13 +5832,16 @@ var FileCache = class {
5568
5832
  * @returns {Promise<void>}
5569
5833
  */
5570
5834
  async put(request, response, progress_callback = void 0) {
5571
- let filePath = node_path_default.join(this.path, request);
5835
+ const filePath = node_path_default.join(this.path, request);
5836
+ const id = apis.IS_PROCESS_AVAILABLE ? process.pid : Date.now();
5837
+ const randomSuffix = rng._int32().toString(36);
5838
+ const tmpPath = filePath + `.tmp.${id}.${randomSuffix}`;
5572
5839
  try {
5573
5840
  const contentLength = response.headers.get("Content-Length");
5574
5841
  const total = parseInt(contentLength ?? "0");
5575
5842
  let loaded = 0;
5576
5843
  await node_fs_default.promises.mkdir(node_path_default.dirname(filePath), { recursive: true });
5577
- const fileStream = node_fs_default.createWriteStream(filePath);
5844
+ const fileStream = node_fs_default.createWriteStream(tmpPath);
5578
5845
  const reader = response.body.getReader();
5579
5846
  while (true) {
5580
5847
  const { done, value } = await reader.read();
@@ -5594,18 +5861,34 @@ var FileCache = class {
5594
5861
  const progress = total ? loaded / total * 100 : 0;
5595
5862
  progress_callback?.({ progress, loaded, total });
5596
5863
  }
5597
- fileStream.close();
5864
+ await new Promise((resolve, reject) => {
5865
+ fileStream.close((err) => err ? reject(err) : resolve());
5866
+ });
5867
+ await node_fs_default.promises.rename(tmpPath, filePath);
5598
5868
  } catch (error) {
5599
5869
  try {
5600
- await node_fs_default.promises.unlink(filePath);
5870
+ await node_fs_default.promises.unlink(tmpPath);
5601
5871
  } catch {
5602
5872
  }
5603
5873
  throw error;
5604
5874
  }
5605
5875
  }
5876
+ /**
5877
+ * Deletes the cache entry for the given request.
5878
+ * @param {string} request
5879
+ * @returns {Promise<boolean>} A Promise that resolves to `true` if the cache entry was deleted, `false` otherwise.
5880
+ */
5881
+ async delete(request) {
5882
+ let filePath = node_path_default.join(this.path, request);
5883
+ try {
5884
+ await node_fs_default.promises.unlink(filePath);
5885
+ return true;
5886
+ } catch (error) {
5887
+ return false;
5888
+ }
5889
+ }
5606
5890
  // TODO add the rest?
5607
5891
  // addAll(requests: RequestInfo[]): Promise<void>;
5608
- // delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
5609
5892
  // keys(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Request>>;
5610
5893
  // match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
5611
5894
  // matchAll(request?: RequestInfo | URL, options?: CacheQueryOptions): Promise<ReadonlyArray<Response>>;
@@ -5669,12 +5952,12 @@ function handleError(status, remoteURL, fatal) {
5669
5952
  const message = ERROR_MAPPING[status] ?? `Error (${status}) occurred while trying to load file`;
5670
5953
  throw Error(`${message}: "${remoteURL}".`);
5671
5954
  }
5672
- async function readResponse(response, progress_callback) {
5955
+ async function readResponse(response, progress_callback, expectedSize) {
5673
5956
  const contentLength = response.headers.get("Content-Length");
5674
- if (contentLength === null) {
5675
- console.warn("Unable to determine content-length from response headers. Will expand buffer when needed.");
5957
+ let total = contentLength ? parseInt(contentLength, 10) : expectedSize ?? 0;
5958
+ if (contentLength === null && !expectedSize) {
5959
+ logger.warn("Unable to determine content-length from response headers. Will expand buffer when needed.");
5676
5960
  }
5677
- let total = parseInt(contentLength ?? "0");
5678
5961
  let buffer = new Uint8Array(total);
5679
5962
  let loaded = 0;
5680
5963
  const reader = response.body.getReader();
@@ -5697,6 +5980,20 @@ async function readResponse(response, progress_callback) {
5697
5980
  await read();
5698
5981
  return buffer;
5699
5982
  }
5983
+ function isBlobURL(url) {
5984
+ return isValidUrl(url, ["blob:"]);
5985
+ }
5986
+ function toAbsoluteURL(url) {
5987
+ let baseURL;
5988
+ if (typeof location !== "undefined" && location.href) {
5989
+ baseURL = location.href;
5990
+ } else if (typeof import.meta !== "undefined" && import.meta.url) {
5991
+ baseURL = import.meta.url;
5992
+ } else {
5993
+ return url;
5994
+ }
5995
+ return new URL(url, baseURL).href;
5996
+ }
5700
5997
 
5701
5998
  // src/utils/cache.js
5702
5999
  async function getCache(file_cache_dir = null) {
@@ -5719,7 +6016,7 @@ async function getCache(file_cache_dir = null) {
5719
6016
  try {
5720
6017
  cache = await caches.open(env.cacheKey);
5721
6018
  } catch (e) {
5722
- console.warn("An error occurred while opening the browser cache:", e);
6019
+ logger.warn("An error occurred while opening the browser cache:", e);
5723
6020
  }
5724
6021
  }
5725
6022
  if (!cache && env.useFSCache) {
@@ -5742,16 +6039,109 @@ async function tryCache(cache, ...names) {
5742
6039
  return void 0;
5743
6040
  }
5744
6041
 
6042
+ // src/utils/model_registry/get_file_metadata.js
6043
+ async function fetch_file_head(urlOrPath) {
6044
+ if (!isValidUrl(urlOrPath, ["http:", "https:"])) {
6045
+ return null;
6046
+ }
6047
+ const headers = getFetchHeaders(urlOrPath);
6048
+ headers.set("Range", "bytes=0-0");
6049
+ return env.fetch(urlOrPath, { method: "GET", headers });
6050
+ }
6051
+ async function get_file_metadata(path_or_repo_id, filename, options = {}) {
6052
+ const cache = await getCache(options?.cache_dir);
6053
+ const { localPath, remoteURL, proposedCacheKey, validModelId } = buildResourcePaths(
6054
+ path_or_repo_id,
6055
+ filename,
6056
+ options,
6057
+ cache
6058
+ );
6059
+ const cachedResponse = await checkCachedResource(cache, localPath, proposedCacheKey);
6060
+ if (cachedResponse !== void 0 && typeof cachedResponse !== "string") {
6061
+ const size = cachedResponse.headers.get("content-length");
6062
+ const contentType = cachedResponse.headers.get("content-type");
6063
+ return {
6064
+ exists: true,
6065
+ size: size ? parseInt(size, 10) : void 0,
6066
+ contentType: contentType || void 0,
6067
+ fromCache: true
6068
+ };
6069
+ }
6070
+ if (env.allowLocalModels) {
6071
+ const isURL = isValidUrl(localPath, ["http:", "https:"]);
6072
+ if (!isURL) {
6073
+ try {
6074
+ const response = await getFile(localPath);
6075
+ if (typeof response !== "string" && response.status !== 404) {
6076
+ const size = response.headers.get("content-length");
6077
+ const contentType = response.headers.get("content-type");
6078
+ return {
6079
+ exists: true,
6080
+ size: size ? parseInt(size, 10) : void 0,
6081
+ contentType: contentType || void 0,
6082
+ fromCache: false
6083
+ };
6084
+ }
6085
+ } catch (e) {
6086
+ }
6087
+ }
6088
+ }
6089
+ if (env.allowRemoteModels && !options.local_files_only && validModelId) {
6090
+ try {
6091
+ const rangeResponse = await fetch_file_head(remoteURL);
6092
+ if (rangeResponse && rangeResponse.status >= 200 && rangeResponse.status < 300) {
6093
+ let size;
6094
+ const contentType = rangeResponse.headers.get("content-type");
6095
+ if (rangeResponse.status === 206) {
6096
+ const contentRange = rangeResponse.headers.get("content-range");
6097
+ if (contentRange) {
6098
+ const match = contentRange.match(/bytes \d+-\d+\/(\d+)/);
6099
+ if (match) {
6100
+ size = parseInt(match[1], 10);
6101
+ }
6102
+ }
6103
+ } else if (rangeResponse.status === 200) {
6104
+ try {
6105
+ await rangeResponse.body?.cancel();
6106
+ } catch (cancelError) {
6107
+ }
6108
+ }
6109
+ if (size === void 0) {
6110
+ const contentLength = rangeResponse.headers.get("content-length");
6111
+ size = contentLength ? parseInt(contentLength, 10) : void 0;
6112
+ }
6113
+ return {
6114
+ exists: true,
6115
+ size,
6116
+ contentType: contentType || void 0,
6117
+ fromCache: false
6118
+ };
6119
+ }
6120
+ } catch (e) {
6121
+ logger.warn(`Unable to fetch file metadata for "${remoteURL}": ${e}`);
6122
+ }
6123
+ }
6124
+ return { exists: false, fromCache: false };
6125
+ }
6126
+
5745
6127
  // src/utils/hub.js
5746
6128
  async function getFile(urlOrPath) {
5747
6129
  if (env.useFS && !isValidUrl(urlOrPath, ["http:", "https:", "blob:"])) {
5748
6130
  return new FileResponse(
5749
6131
  urlOrPath instanceof URL ? urlOrPath.protocol === "file:" ? urlOrPath.pathname : urlOrPath.toString() : urlOrPath
5750
6132
  );
5751
- } else if (typeof process !== "undefined" && process?.release?.name === "node") {
6133
+ } else {
6134
+ return env.fetch(urlOrPath, {
6135
+ headers: getFetchHeaders(urlOrPath)
6136
+ });
6137
+ }
6138
+ }
6139
+ function getFetchHeaders(urlOrPath) {
6140
+ const isNode = typeof process !== "undefined" && process?.release?.name === "node";
6141
+ const headers = new Headers();
6142
+ if (isNode) {
5752
6143
  const IS_CI = !!process.env?.TESTING_REMOTELY;
5753
6144
  const version = env.version;
5754
- const headers = new Headers();
5755
6145
  headers.set("User-Agent", `transformers.js/${version}; is_ci/${IS_CI};`);
5756
6146
  const isHFURL = isValidUrl(urlOrPath, ["http:", "https:"], ["huggingface.co", "hf.co"]);
5757
6147
  if (isHFURL) {
@@ -5760,10 +6150,9 @@ async function getFile(urlOrPath) {
5760
6150
  headers.set("Authorization", `Bearer ${token}`);
5761
6151
  }
5762
6152
  }
5763
- return fetch(urlOrPath, { headers });
5764
6153
  } else {
5765
- return fetch(urlOrPath);
5766
6154
  }
6155
+ return headers;
5767
6156
  }
5768
6157
  function buildResourcePaths(path_or_repo_id, filename, options = {}, cache = null) {
5769
6158
  const revision = options.revision ?? "main";
@@ -5823,7 +6212,7 @@ async function storeCachedResource(path_or_repo_id, filename, cache, cacheKey, r
5823
6212
  }
5824
6213
  )
5825
6214
  ).catch((err) => {
5826
- console.warn(`Unable to add response to browser cache: ${err}.`);
6215
+ logger.warn(`Unable to add response to browser cache: ${err}.`);
5827
6216
  });
5828
6217
  }
5829
6218
  }
@@ -5847,7 +6236,7 @@ async function loadResourceFile(path_or_repo_id, filename, fatal = true, options
5847
6236
  response = await getFile(localPath);
5848
6237
  cacheKey = localPath;
5849
6238
  } catch (e) {
5850
- console.warn(`Unable to load from local path "${localPath}": "${e}"`);
6239
+ logger.warn(`Unable to load from local path "${localPath}": "${e}"`);
5851
6240
  }
5852
6241
  } else if (options.local_files_only) {
5853
6242
  throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${requestURL}.`);
@@ -5906,14 +6295,31 @@ async function loadResourceFile(path_or_repo_id, filename, fatal = true, options
5906
6295
  total: buffer.length
5907
6296
  });
5908
6297
  } else {
5909
- buffer = await readResponse(response, (data) => {
5910
- dispatchCallback(options.progress_callback, {
5911
- status: "progress",
5912
- name: path_or_repo_id,
5913
- file: filename,
5914
- ...data
5915
- });
5916
- });
6298
+ let expectedSize;
6299
+ const contentLength = response.headers.get("content-length");
6300
+ if (contentLength) {
6301
+ expectedSize = parseInt(contentLength, 10);
6302
+ } else {
6303
+ try {
6304
+ const metadata = await get_file_metadata(path_or_repo_id, filename, options);
6305
+ if (metadata.size) {
6306
+ expectedSize = metadata.size;
6307
+ }
6308
+ } catch (e) {
6309
+ }
6310
+ }
6311
+ buffer = await readResponse(
6312
+ response,
6313
+ (data) => {
6314
+ dispatchCallback(options.progress_callback, {
6315
+ status: "progress",
6316
+ name: path_or_repo_id,
6317
+ file: filename,
6318
+ ...data
6319
+ });
6320
+ },
6321
+ expectedSize
6322
+ );
5917
6323
  }
5918
6324
  }
5919
6325
  result = buffer;
@@ -6760,20 +7166,9 @@ var uint16_to_float32 = /* @__PURE__ */ (function() {
6760
7166
  // ignore-modules:onnxruntime-node
6761
7167
  var onnxruntime_node_exports = {};
6762
7168
  __export(onnxruntime_node_exports, {
6763
- Readable: () => Readable,
6764
- createReadStream: () => createReadStream,
6765
- createWriteStream: () => createWriteStream,
6766
- default: () => onnxruntime_node_default,
6767
- pipeline: () => pipeline
7169
+ default: () => onnxruntime_node_default
6768
7170
  });
6769
- var noop = () => {
6770
- };
6771
- var emptyObj4 = {};
6772
- var onnxruntime_node_default = emptyObj4;
6773
- var Readable = { fromWeb: noop };
6774
- var pipeline = noop;
6775
- var createWriteStream = noop;
6776
- var createReadStream = noop;
7171
+ var onnxruntime_node_default = {};
6777
7172
 
6778
7173
  // src/backends/onnx.js
6779
7174
  import * as ONNX_WEB from "onnxruntime-web/webgpu";
@@ -6791,9 +7186,9 @@ async function loadAndCacheFile(url) {
6791
7186
  }
6792
7187
  }
6793
7188
  } catch (error) {
6794
- console.warn(`Failed to load ${fileName} from cache:`, error);
7189
+ logger.warn(`Failed to load ${fileName} from cache:`, error);
6795
7190
  }
6796
- const response = await fetch(url);
7191
+ const response = await env.fetch(url);
6797
7192
  if (!response.ok) {
6798
7193
  throw new Error(`Failed to fetch ${fileName}: ${response.status} ${response.statusText}`);
6799
7194
  }
@@ -6801,7 +7196,7 @@ async function loadAndCacheFile(url) {
6801
7196
  try {
6802
7197
  await cache.put(url, response.clone());
6803
7198
  } catch (e) {
6804
- console.warn(`Failed to cache ${fileName}:`, e);
7199
+ logger.warn(`Failed to cache ${fileName}:`, e);
6805
7200
  }
6806
7201
  }
6807
7202
  return response;
@@ -6812,38 +7207,26 @@ async function loadWasmBinary(wasmURL) {
6812
7207
  try {
6813
7208
  return await response.arrayBuffer();
6814
7209
  } catch (error) {
6815
- console.warn("Failed to read WASM binary:", error);
7210
+ logger.warn("Failed to read WASM binary:", error);
6816
7211
  return null;
6817
7212
  }
6818
7213
  }
6819
7214
  async function loadWasmFactory(libURL) {
7215
+ if (apis.IS_SERVICE_WORKER_ENV || apis.IS_CHROME_AVAILABLE) {
7216
+ return libURL;
7217
+ }
6820
7218
  const response = await loadAndCacheFile(libURL);
6821
7219
  if (!response || typeof response === "string") return null;
6822
7220
  try {
6823
7221
  let code = await response.text();
6824
- const baseUrl = libURL.split("/").slice(0, -1).join("/");
6825
- code = code.replace(/import\.meta\.url/g, `"${baseUrl}"`);
7222
+ code = code.replaceAll("globalThis.process?.versions?.node", "false");
6826
7223
  const blob = new Blob([code], { type: "text/javascript" });
6827
7224
  return URL.createObjectURL(blob);
6828
7225
  } catch (error) {
6829
- console.warn("Failed to read WASM binary:", error);
7226
+ logger.warn("Failed to read WASM factory:", error);
6830
7227
  return null;
6831
7228
  }
6832
7229
  }
6833
- function isBlobURL(url) {
6834
- return isValidUrl(url, ["blob:"]);
6835
- }
6836
- function toAbsoluteURL(url) {
6837
- let baseURL;
6838
- if (typeof location !== "undefined" && location.href) {
6839
- baseURL = location.href;
6840
- } else if (typeof import.meta !== "undefined" && import.meta.url) {
6841
- baseURL = import.meta.url;
6842
- } else {
6843
- return url;
6844
- }
6845
- return new URL(url, baseURL).href;
6846
- }
6847
7230
 
6848
7231
  // src/backends/onnx.js
6849
7232
  import { Tensor } from "onnxruntime-common";
@@ -6873,8 +7256,26 @@ var DEVICE_TO_EXECUTION_PROVIDER_MAPPING = Object.freeze({
6873
7256
  "webnn-cpu": { name: "webnn", deviceType: "cpu" }
6874
7257
  // WebNN CPU
6875
7258
  });
6876
- var LOG_LEVELS = ["verbose", "info", "warning", "error", "fatal"];
6877
- var DEFAULT_LOG_LEVEL = 4;
7259
+ function getOnnxLogSeverityLevel(logLevel2) {
7260
+ if (logLevel2 <= LogLevel.DEBUG) {
7261
+ return 0;
7262
+ } else if (logLevel2 <= LogLevel.INFO) {
7263
+ return 2;
7264
+ } else if (logLevel2 <= LogLevel.WARNING) {
7265
+ return 3;
7266
+ } else if (logLevel2 <= LogLevel.ERROR) {
7267
+ return 3;
7268
+ } else {
7269
+ return 4;
7270
+ }
7271
+ }
7272
+ var ONNX_LOG_LEVEL_NAMES = {
7273
+ 0: "verbose",
7274
+ 1: "info",
7275
+ 2: "warning",
7276
+ 3: "error",
7277
+ 4: "fatal"
7278
+ };
6878
7279
  var supportedDevices = [];
6879
7280
  var defaultDevices;
6880
7281
  var ONNX;
@@ -6924,7 +7325,6 @@ function deviceToExecutionProviders(device = null) {
6924
7325
  }
6925
7326
  throw new Error(`Unsupported device: "${device}". Should be one of: ${supportedDevices.join(", ")}.`);
6926
7327
  }
6927
- var IS_WEB_ENV = apis.IS_BROWSER_ENV || apis.IS_WEBWORKER_ENV;
6928
7328
  var webInitChain = Promise.resolve();
6929
7329
  var wasmLoadPromise = null;
6930
7330
  async function ensureWasmLoaded() {
@@ -6933,6 +7333,11 @@ async function ensureWasmLoaded() {
6933
7333
  }
6934
7334
  const shouldUseWasmCache = env.useWasmCache && typeof ONNX_ENV?.wasm?.wasmPaths === "object" && ONNX_ENV?.wasm?.wasmPaths?.wasm && ONNX_ENV?.wasm?.wasmPaths?.mjs;
6935
7335
  if (!shouldUseWasmCache) {
7336
+ if (apis.IS_DENO_WEB_RUNTIME) {
7337
+ throw new Error(
7338
+ "env.useWasmCache=false is not supported in Deno's web runtime. Remove the useWasmCache override."
7339
+ );
7340
+ }
6936
7341
  wasmLoadPromise = Promise.resolve();
6937
7342
  return wasmLoadPromise;
6938
7343
  }
@@ -6941,6 +7346,7 @@ async function ensureWasmLoaded() {
6941
7346
  /** @type {{ wasm: string, mjs: string }} */
6942
7347
  ONNX_ENV.wasm.wasmPaths
6943
7348
  );
7349
+ let wasmBinaryLoaded = false;
6944
7350
  await Promise.all([
6945
7351
  // Load and cache the WASM binary
6946
7352
  urls.wasm && !isBlobURL(urls.wasm) ? (async () => {
@@ -6948,12 +7354,13 @@ async function ensureWasmLoaded() {
6948
7354
  const wasmBinary = await loadWasmBinary(toAbsoluteURL(urls.wasm));
6949
7355
  if (wasmBinary) {
6950
7356
  ONNX_ENV.wasm.wasmBinary = wasmBinary;
7357
+ wasmBinaryLoaded = true;
6951
7358
  }
6952
7359
  } catch (err) {
6953
- console.warn("Failed to pre-load WASM binary:", err);
7360
+ logger.warn("Failed to pre-load WASM binary:", err);
6954
7361
  }
6955
7362
  })() : Promise.resolve(),
6956
- // Load and cache the WASM factory
7363
+ // Load and cache the WASM factory as a blob URL
6957
7364
  urls.mjs && !isBlobURL(urls.mjs) ? (async () => {
6958
7365
  try {
6959
7366
  const wasmFactoryBlob = await loadWasmFactory(toAbsoluteURL(urls.mjs));
@@ -6961,58 +7368,70 @@ async function ensureWasmLoaded() {
6961
7368
  ONNX_ENV.wasm.wasmPaths.mjs = wasmFactoryBlob;
6962
7369
  }
6963
7370
  } catch (err) {
6964
- console.warn("Failed to pre-load WASM factory:", err);
7371
+ logger.warn("Failed to pre-load WASM factory:", err);
6965
7372
  }
6966
7373
  })() : Promise.resolve()
6967
7374
  ]);
7375
+ if (!wasmBinaryLoaded) {
7376
+ ONNX_ENV.wasm.wasmPaths.mjs = urls.mjs;
7377
+ }
6968
7378
  })();
6969
7379
  return wasmLoadPromise;
6970
7380
  }
6971
7381
  async function createInferenceSession(buffer_or_path, session_options, session_config) {
6972
7382
  await ensureWasmLoaded();
7383
+ const logSeverityLevel = getOnnxLogSeverityLevel(env.logLevel ?? LogLevel.WARNING);
6973
7384
  const load = () => InferenceSession.create(buffer_or_path, {
6974
- // Set default log level, but allow overriding through session options
6975
- logSeverityLevel: DEFAULT_LOG_LEVEL,
7385
+ // Set default log severity level, but allow overriding through session options
7386
+ logSeverityLevel,
6976
7387
  ...session_options
6977
7388
  });
6978
- const session = await (IS_WEB_ENV ? webInitChain = webInitChain.then(load) : load());
7389
+ const session = await (apis.IS_WEB_ENV ? webInitChain = webInitChain.then(load) : load());
6979
7390
  session.config = session_config;
6980
7391
  return session;
6981
7392
  }
6982
7393
  var webInferenceChain = Promise.resolve();
6983
7394
  async function runInferenceSession(session, ortFeed) {
6984
7395
  const run = () => session.run(ortFeed);
6985
- const output = await (IS_WEB_ENV ? webInferenceChain = webInferenceChain.then(run) : run());
6986
- return output;
7396
+ return apis.IS_WEB_ENV ? webInferenceChain = webInferenceChain.then(run) : run();
6987
7397
  }
6988
7398
  function isONNXTensor(x) {
6989
7399
  return x instanceof ONNX.Tensor;
6990
7400
  }
6991
7401
  var ONNX_ENV = ONNX?.env;
6992
- ONNX_ENV.logLevel = LOG_LEVELS[DEFAULT_LOG_LEVEL];
6993
- if (ONNX_ENV?.wasm) {
6994
- if (
6995
- // @ts-ignore Cannot find name 'ServiceWorkerGlobalScope'.ts(2304)
6996
- !(typeof ServiceWorkerGlobalScope !== "undefined" && self instanceof ServiceWorkerGlobalScope) && ONNX_ENV.versions?.web && !ONNX_ENV.wasm.wasmPaths
6997
- ) {
6998
- const wasmPathPrefix = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ONNX_ENV.versions.web}/dist/`;
6999
- ONNX_ENV.wasm.wasmPaths = apis.IS_SAFARI ? {
7000
- mjs: `${wasmPathPrefix}ort-wasm-simd-threaded.mjs`,
7001
- wasm: `${wasmPathPrefix}ort-wasm-simd-threaded.wasm`
7002
- } : {
7003
- mjs: `${wasmPathPrefix}ort-wasm-simd-threaded.asyncify.mjs`,
7004
- wasm: `${wasmPathPrefix}ort-wasm-simd-threaded.asyncify.wasm`
7005
- };
7006
- }
7007
- ONNX_ENV.wasm.proxy = false;
7008
- }
7009
- if (ONNX_ENV?.webgpu) {
7010
- ONNX_ENV.webgpu.powerPreference = "high-performance";
7011
- }
7012
7402
  function isONNXProxy() {
7013
7403
  return ONNX_ENV?.wasm?.proxy;
7014
7404
  }
7015
- env.backends.onnx = ONNX_ENV;
7405
+ if (ONNX_ENV) {
7406
+ let setLogLevel = function(logLevel2) {
7407
+ const severityLevel = getOnnxLogSeverityLevel(logLevel2);
7408
+ ONNX_ENV.logLevel = ONNX_LOG_LEVEL_NAMES[severityLevel];
7409
+ };
7410
+ if (ONNX_ENV.wasm) {
7411
+ if (
7412
+ // @ts-ignore Cannot find name 'ServiceWorkerGlobalScope'.ts(2304)
7413
+ !(typeof ServiceWorkerGlobalScope !== "undefined" && self instanceof ServiceWorkerGlobalScope) && ONNX_ENV.versions?.web && !ONNX_ENV.wasm.wasmPaths
7414
+ ) {
7415
+ const wasmPathPrefix = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ONNX_ENV.versions.web}/dist/`;
7416
+ ONNX_ENV.wasm.wasmPaths = apis.IS_SAFARI ? {
7417
+ mjs: `${wasmPathPrefix}ort-wasm-simd-threaded.mjs`,
7418
+ wasm: `${wasmPathPrefix}ort-wasm-simd-threaded.wasm`
7419
+ } : {
7420
+ mjs: `${wasmPathPrefix}ort-wasm-simd-threaded.asyncify.mjs`,
7421
+ wasm: `${wasmPathPrefix}ort-wasm-simd-threaded.asyncify.wasm`
7422
+ };
7423
+ }
7424
+ ONNX_ENV.wasm.proxy = false;
7425
+ }
7426
+ if (ONNX_ENV.webgpu) {
7427
+ ONNX_ENV.webgpu.powerPreference = "high-performance";
7428
+ }
7429
+ setLogLevel(env.logLevel ?? LogLevel.WARNING);
7430
+ env.backends.onnx = {
7431
+ ...ONNX_ENV,
7432
+ setLogLevel
7433
+ };
7434
+ }
7016
7435
 
7017
7436
  // src/ops/registry.js
7018
7437
  var wrap = async (session_bytes, session_options, names) => {
@@ -8099,6 +8518,16 @@ var DEVICE_TYPES = Object.freeze({
8099
8518
  "webnn-cpu": "webnn-cpu"
8100
8519
  // WebNN CPU
8101
8520
  });
8521
+ var DEFAULT_DEVICE = apis.IS_NODE_ENV ? "cpu" : "wasm";
8522
+ function selectDevice(deviceConfig, fileName, { warn } = {}) {
8523
+ if (!deviceConfig) return DEFAULT_DEVICE;
8524
+ if (typeof deviceConfig === "string") return deviceConfig;
8525
+ if (deviceConfig.hasOwnProperty(fileName)) return deviceConfig[fileName];
8526
+ if (warn) {
8527
+ warn(`device not specified for "${fileName}". Using the default device (${DEFAULT_DEVICE}).`);
8528
+ }
8529
+ return DEFAULT_DEVICE;
8530
+ }
8102
8531
 
8103
8532
  // src/utils/dtypes.js
8104
8533
  var isWebGpuFp16Supported = /* @__PURE__ */ (function() {
@@ -8132,6 +8561,7 @@ var DATA_TYPES = Object.freeze({
8132
8561
  q4f16: "q4f16"
8133
8562
  // fp16 model with int4 block weight quantization
8134
8563
  });
8564
+ var DEFAULT_DEVICE_DTYPE = DATA_TYPES.fp32;
8135
8565
  var DEFAULT_DEVICE_DTYPE_MAPPING = Object.freeze({
8136
8566
  // NOTE: If not specified, will default to fp32
8137
8567
  [DEVICE_TYPES.wasm]: DATA_TYPES.q8
@@ -8146,6 +8576,45 @@ var DEFAULT_DTYPE_SUFFIX_MAPPING = Object.freeze({
8146
8576
  [DATA_TYPES.q4f16]: "_q4f16",
8147
8577
  [DATA_TYPES.bnb4]: "_bnb4"
8148
8578
  });
8579
+ function selectDtype(dtype, fileName, selectedDevice, { configDtype = null, warn } = {}) {
8580
+ let resolved;
8581
+ let needsWarn = false;
8582
+ if (dtype && typeof dtype !== "string") {
8583
+ if (dtype.hasOwnProperty(fileName)) {
8584
+ resolved = dtype[fileName];
8585
+ } else {
8586
+ resolved = null;
8587
+ needsWarn = true;
8588
+ }
8589
+ } else {
8590
+ resolved = /** @type {string|null|undefined} */
8591
+ dtype;
8592
+ }
8593
+ let result;
8594
+ if (resolved === DATA_TYPES.auto) {
8595
+ if (configDtype) {
8596
+ const fallback = typeof configDtype === "string" ? configDtype : configDtype?.[fileName];
8597
+ if (fallback && fallback !== DATA_TYPES.auto && DATA_TYPES.hasOwnProperty(fallback)) {
8598
+ return (
8599
+ /** @type {DataType} */
8600
+ fallback
8601
+ );
8602
+ }
8603
+ }
8604
+ result = DEFAULT_DEVICE_DTYPE_MAPPING[selectedDevice] ?? DEFAULT_DEVICE_DTYPE;
8605
+ } else if (resolved && DATA_TYPES.hasOwnProperty(resolved)) {
8606
+ result = /** @type {DataType} */
8607
+ resolved;
8608
+ } else {
8609
+ result = DEFAULT_DEVICE_DTYPE_MAPPING[selectedDevice] ?? DEFAULT_DEVICE_DTYPE;
8610
+ }
8611
+ if (needsWarn && warn) {
8612
+ warn(
8613
+ `dtype not specified for "${fileName}". Using the default dtype (${result}) for this device (${selectedDevice}).`
8614
+ );
8615
+ }
8616
+ return result;
8617
+ }
8149
8618
  var DataTypeMap = Object.freeze({
8150
8619
  float32: Float32Array,
8151
8620
  // @ts-ignore ts(2552) Limited availability of Float16Array across browsers:
@@ -9297,24 +9766,17 @@ function rand(size) {
9297
9766
  const length = size.reduce((a, b) => a * b, 1);
9298
9767
  return new Tensor2(
9299
9768
  "float32",
9300
- Float32Array.from({ length }, () => Math.random()),
9769
+ Float32Array.from({ length }, () => random.random()),
9301
9770
  size
9302
9771
  );
9303
9772
  }
9304
9773
  function randn(size) {
9305
9774
  const length = size.reduce((a, b) => a * b, 1);
9306
- const data = new Float32Array(length);
9307
- for (let i = 0; i < length; i += 2) {
9308
- const u = 1 - Math.random();
9309
- const v = Math.random();
9310
- const mag = Math.sqrt(-2 * Math.log(u));
9311
- const angle = 2 * Math.PI * v;
9312
- data[i] = mag * Math.cos(angle);
9313
- if (i + 1 < length) {
9314
- data[i + 1] = mag * Math.sin(angle);
9315
- }
9316
- }
9317
- return new Tensor2("float32", data, size);
9775
+ return new Tensor2(
9776
+ "float32",
9777
+ Float32Array.from({ length }, () => random.gauss()),
9778
+ size
9779
+ );
9318
9780
  }
9319
9781
  function quantize_embeddings(tensor, precision) {
9320
9782
  if (tensor.dims.length !== 2) {
@@ -9343,13 +9805,24 @@ function quantize_embeddings(tensor, precision) {
9343
9805
  return new Tensor2(dtype, outputData, [tensor.dims[0], tensor.dims[1] / 8]);
9344
9806
  }
9345
9807
 
9808
+ // src/utils/model_registry/get_tokenizer_files.js
9809
+ async function get_tokenizer_files(modelId) {
9810
+ if (!modelId) {
9811
+ throw new Error("modelId is required for get_tokenizer_files");
9812
+ }
9813
+ const metadata = await get_file_metadata(modelId, "tokenizer_config.json", {});
9814
+ if (metadata.exists) {
9815
+ return ["tokenizer.json", "tokenizer_config.json"];
9816
+ }
9817
+ return [];
9818
+ }
9819
+
9346
9820
  // src/tokenization_utils.js
9347
9821
  async function loadTokenizer(pretrained_model_name_or_path, options) {
9348
- const info = await Promise.all([
9349
- getModelJSON(pretrained_model_name_or_path, "tokenizer.json", true, options),
9350
- getModelJSON(pretrained_model_name_or_path, "tokenizer_config.json", true, options)
9351
- ]);
9352
- return info;
9822
+ const tokenizerFiles = await get_tokenizer_files(pretrained_model_name_or_path);
9823
+ return await Promise.all(
9824
+ tokenizerFiles.map((file) => getModelJSON(pretrained_model_name_or_path, file, true, options))
9825
+ );
9353
9826
  }
9354
9827
  function prepareTensorForDecode(tensor) {
9355
9828
  const dims = tensor.dims;
@@ -9523,10 +9996,10 @@ var PreTrainedTokenizer = class extends Callable2 {
9523
9996
  * @param {string|string[]} [options.text_pair=null] Optional second sequence to be encoded. If set, must be the same type as text.
9524
9997
  * @param {boolean|'max_length'} [options.padding=false] Whether to pad the input sequences.
9525
9998
  * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model.
9526
- * @param {boolean} [options.truncation=null] Whether to truncate the input sequences.
9527
- * @param {number} [options.max_length=null] Maximum length of the returned list and optionally padding length.
9999
+ * @param {boolean|null} [options.truncation=null] Whether to truncate the input sequences.
10000
+ * @param {number|null} [options.max_length=null] Maximum length of the returned list and optionally padding length.
9528
10001
  * @param {boolean} [options.return_tensor=true] Whether to return the results as Tensors or arrays.
9529
- * @param {boolean} [options.return_token_type_ids=null] Whether to return the token type ids.
10002
+ * @param {boolean|null} [options.return_token_type_ids=null] Whether to return the token type ids.
9530
10003
  * @returns {BatchEncoding} Object to be passed to the model.
9531
10004
  */
9532
10005
  _call(text, {
@@ -9572,12 +10045,12 @@ var PreTrainedTokenizer = class extends Callable2 {
9572
10045
  max_length = this.model_max_length;
9573
10046
  } else if (truncation === null) {
9574
10047
  if (padding === true) {
9575
- console.warn(
10048
+ logger.warn(
9576
10049
  "`max_length` is ignored when `padding: true` and there is no truncation strategy. To pad to max length, use `padding: 'max_length'`."
9577
10050
  );
9578
10051
  max_length = this.model_max_length;
9579
10052
  } else if (padding === false) {
9580
- console.warn(
10053
+ logger.warn(
9581
10054
  "Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation: true` to explicitly truncate examples to max length."
9582
10055
  );
9583
10056
  truncation = true;
@@ -9661,9 +10134,9 @@ var PreTrainedTokenizer = class extends Callable2 {
9661
10134
  *
9662
10135
  * @param {string} text The text to encode.
9663
10136
  * @param {Object} options An optional object containing the following properties:
9664
- * @param {string} [options.text_pair=null] The optional second text to encode.
10137
+ * @param {string|null} [options.text_pair=null] The optional second text to encode.
9665
10138
  * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model.
9666
- * @param {boolean} [options.return_token_type_ids=null] Whether to return token_type_ids.
10139
+ * @param {boolean|null} [options.return_token_type_ids=null] Whether to return token_type_ids.
9667
10140
  * @returns {{input_ids: number[], attention_mask: number[], token_type_ids?: number[]}} An object containing the encoded text.
9668
10141
  * @private
9669
10142
  */
@@ -9683,7 +10156,7 @@ var PreTrainedTokenizer = class extends Callable2 {
9683
10156
  * Converts a string into a sequence of tokens.
9684
10157
  * @param {string} text The sequence to be encoded.
9685
10158
  * @param {Object} options An optional object containing the following properties:
9686
- * @param {string} [options.pair] A second sequence to be encoded with the first.
10159
+ * @param {string|null} [options.pair] A second sequence to be encoded with the first.
9687
10160
  * @param {boolean} [options.add_special_tokens=false] Whether or not to add the special tokens associated with the corresponding model.
9688
10161
  * @returns {string[]} The list of tokens.
9689
10162
  */
@@ -9695,9 +10168,9 @@ var PreTrainedTokenizer = class extends Callable2 {
9695
10168
  *
9696
10169
  * @param {string} text The text to encode.
9697
10170
  * @param {Object} options An optional object containing the following properties:
9698
- * @param {string} [options.text_pair=null] The optional second text to encode.
10171
+ * @param {string|null} [options.text_pair=null] The optional second text to encode.
9699
10172
  * @param {boolean} [options.add_special_tokens=true] Whether or not to add the special tokens associated with the corresponding model.
9700
- * @param {boolean} [options.return_token_type_ids=null] Whether to return token_type_ids.
10173
+ * @param {boolean|null} [options.return_token_type_ids=null] Whether to return token_type_ids.
9701
10174
  * @returns {number[]} An array of token IDs representing the encoded text(s).
9702
10175
  */
9703
10176
  encode(text, { text_pair = null, add_special_tokens = true, return_token_type_ids = null } = {}) {
@@ -9744,7 +10217,7 @@ var PreTrainedTokenizer = class extends Callable2 {
9744
10217
  * @param {number[]|bigint[]} token_ids List of token ids to decode
9745
10218
  * @param {Object} decode_args Optional arguments for decoding
9746
10219
  * @param {boolean} [decode_args.skip_special_tokens=false] Whether to skip special tokens during decoding
9747
- * @param {boolean} [decode_args.clean_up_tokenization_spaces=null] Whether to clean up tokenization spaces during decoding.
10220
+ * @param {boolean|null} [decode_args.clean_up_tokenization_spaces=null] Whether to clean up tokenization spaces during decoding.
9748
10221
  * If null, the value is set to `this.decoder.cleanup` if it exists, falling back to `this.clean_up_tokenization_spaces` if it exists, falling back to `true`.
9749
10222
  * @returns {string} The decoded string
9750
10223
  */
@@ -9760,7 +10233,7 @@ var PreTrainedTokenizer = class extends Callable2 {
9760
10233
  * template for better generation tracking.
9761
10234
  *
9762
10235
  * @param {Object} options An optional object containing the following properties:
9763
- * @param {string} [options.chat_template=null]
10236
+ * @param {string|null} [options.chat_template=null]
9764
10237
  * A Jinja template or the name of a template to use for this conversion.
9765
10238
  * It is usually not necessary to pass anything to this argument,
9766
10239
  * as the model's template will be used by default.
@@ -9829,7 +10302,7 @@ var PreTrainedTokenizer = class extends Callable2 {
9829
10302
  * @param {Message[]} conversation A list of message objects with `"role"` and `"content"` keys,
9830
10303
  * representing the chat history so far.
9831
10304
  * @param {Object} options An optional object containing the following properties:
9832
- * @param {string} [options.chat_template=null] A Jinja template to use for this conversion. If
10305
+ * @param {string|null} [options.chat_template=null] A Jinja template to use for this conversion. If
9833
10306
  * this is not passed, the model's chat template will be used instead.
9834
10307
  * @param {Object[]} [options.tools=null]
9835
10308
  * A list of tools (callable functions) that will be accessible to the model. If the template does not
@@ -9850,7 +10323,7 @@ var PreTrainedTokenizer = class extends Callable2 {
9850
10323
  * @param {boolean} [options.tokenize=true] Whether to tokenize the output. If false, the output will be a string.
9851
10324
  * @param {boolean} [options.padding=false] Whether to pad sequences to the maximum length. Has no effect if tokenize is false.
9852
10325
  * @param {boolean} [options.truncation=false] Whether to truncate sequences to the maximum length. Has no effect if tokenize is false.
9853
- * @param {number} [options.max_length=null] Maximum length (in tokens) to use for padding or truncation. Has no effect if tokenize is false.
10326
+ * @param {number|null} [options.max_length=null] Maximum length (in tokens) to use for padding or truncation. Has no effect if tokenize is false.
9854
10327
  * If not specified, the tokenizer's `max_length` attribute will be used as a default.
9855
10328
  * @param {boolean} [options.return_tensor=true] Whether to return the output as a Tensor or an Array. Has no effect if tokenize is false.
9856
10329
  * @param {boolean} [options.return_dict=true] Whether to return a dictionary with named outputs. Has no effect if tokenize is false.
@@ -10128,7 +10601,7 @@ var MarianTokenizer = class extends PreTrainedTokenizer {
10128
10601
  super(tokenizerJSON, tokenizerConfig);
10129
10602
  this.languageRegex = /^(>>\w+<<)\s*/g;
10130
10603
  this.supported_language_codes = Array.from(this.get_vocab().keys()).filter((x) => this.languageRegex.test(x));
10131
- console.warn(
10604
+ logger.warn(
10132
10605
  'WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.'
10133
10606
  );
10134
10607
  }
@@ -10148,7 +10621,7 @@ var MarianTokenizer = class extends PreTrainedTokenizer {
10148
10621
  } else if (remainder.length === 2) {
10149
10622
  const [language, text2] = remainder;
10150
10623
  if (!this.supported_language_codes.includes(language)) {
10151
- console.warn(
10624
+ logger.warn(
10152
10625
  `Unsupported language code "${language}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`
10153
10626
  );
10154
10627
  }
@@ -10865,7 +11338,7 @@ var XLMTokenizer = class extends PreTrainedTokenizer {
10865
11338
  return_token_type_ids = true;
10866
11339
  constructor(tokenizerJSON, tokenizerConfig) {
10867
11340
  super(tokenizerJSON, tokenizerConfig);
10868
- console.warn(
11341
+ logger.warn(
10869
11342
  'WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.'
10870
11343
  );
10871
11344
  }
@@ -10899,7 +11372,7 @@ var AutoTokenizer = class {
10899
11372
  const tokenizerName = tokenizerConfig.tokenizer_class?.replace(/Fast$/, "") ?? "PreTrainedTokenizer";
10900
11373
  let cls = tokenizers_exports[tokenizerName];
10901
11374
  if (!cls) {
10902
- console.warn(`Unknown tokenizer class "${tokenizerName}", attempting to construct from base class.`);
11375
+ logger.warn(`Unknown tokenizer class "${tokenizerName}", attempting to construct from base class.`);
10903
11376
  cls = PreTrainedTokenizer;
10904
11377
  }
10905
11378
  return new cls(tokenizerJSON, tokenizerConfig);
@@ -11048,6 +11521,8 @@ __export(processors_exports, {
11048
11521
  Processor: () => Processor,
11049
11522
  PyAnnoteProcessor: () => PyAnnoteProcessor,
11050
11523
  Qwen2VLProcessor: () => Qwen2VLProcessor,
11524
+ Qwen2_5_VLProcessor: () => Qwen2_5_VLProcessor,
11525
+ Qwen3VLProcessor: () => Qwen3VLProcessor,
11051
11526
  Sam2Processor: () => Sam2Processor,
11052
11527
  Sam2VideoProcessor: () => Sam2VideoProcessor,
11053
11528
  SamProcessor: () => SamProcessor,
@@ -11122,14 +11597,14 @@ __export(feature_extractors_exports, {
11122
11597
  });
11123
11598
 
11124
11599
  // ignore-modules:node:stream
11125
- var noop2 = () => {
11600
+ var noop = () => {
11126
11601
  };
11127
- var Readable2 = { fromWeb: noop2 };
11602
+ var Readable = { fromWeb: noop };
11128
11603
 
11129
11604
  // ignore-modules:node:stream/promises
11130
- var noop3 = () => {
11605
+ var noop2 = () => {
11131
11606
  };
11132
- var pipeline2 = noop3;
11607
+ var pipeline = noop2;
11133
11608
 
11134
11609
  // src/utils/io.js
11135
11610
  async function saveBlob(path, blob) {
@@ -11146,9 +11621,9 @@ async function saveBlob(path, blob) {
11146
11621
  URL.revokeObjectURL(dataURL);
11147
11622
  } else if (apis.IS_FS_AVAILABLE) {
11148
11623
  const webStream = blob.stream();
11149
- const nodeStream = Readable2.fromWeb(webStream);
11624
+ const nodeStream = Readable.fromWeb(webStream);
11150
11625
  const fileStream = node_fs_default.createWriteStream(path);
11151
- await pipeline2(nodeStream, fileStream);
11626
+ await pipeline(nodeStream, fileStream);
11152
11627
  } else {
11153
11628
  throw new Error("Unable to save because filesystem is disabled in this environment.");
11154
11629
  }
@@ -11164,7 +11639,7 @@ async function read_audio(url, sampling_rate) {
11164
11639
  const response = await (await getFile(url)).arrayBuffer();
11165
11640
  const audioCTX = new AudioContext({ sampleRate: sampling_rate });
11166
11641
  if (typeof sampling_rate === "undefined") {
11167
- console.warn(`No sampling rate provided, using default of ${audioCTX.sampleRate}Hz.`);
11642
+ logger.warn(`No sampling rate provided, using default of ${audioCTX.sampleRate}Hz.`);
11168
11643
  }
11169
11644
  const decoded = await audioCTX.decodeAudioData(response);
11170
11645
  let audio;
@@ -11820,7 +12295,7 @@ var ClapFeatureExtractor = class extends FeatureExtractor {
11820
12295
  if (diff > 0) {
11821
12296
  if (truncation === "rand_trunc") {
11822
12297
  longer = true;
11823
- const idx = Math.floor(Math.random() * (diff + 1));
12298
+ const idx = Math.floor(random.random() * (diff + 1));
11824
12299
  waveform = waveform.subarray(idx, idx + max_length);
11825
12300
  input_mel = await this._extract_fbank_features(
11826
12301
  waveform,
@@ -12553,7 +13028,7 @@ var WhisperFeatureExtractor = class extends FeatureExtractor {
12553
13028
  const length = max_length ?? this.config.n_samples;
12554
13029
  if (audio.length > length) {
12555
13030
  if (audio.length > this.config.n_samples) {
12556
- console.warn(
13031
+ logger.warn(
12557
13032
  "Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."
12558
13033
  );
12559
13034
  }
@@ -12600,18 +13075,16 @@ var ChatterboxProcessor = class extends Processor {
12600
13075
  };
12601
13076
 
12602
13077
  // ignore-modules:sharp
12603
- var emptyObj5 = {};
12604
- var sharp_default = emptyObj5;
13078
+ var sharp_default = {};
12605
13079
 
12606
13080
  // src/utils/image.js
12607
13081
  var createCanvasFunction;
12608
13082
  var ImageDataClass;
12609
13083
  var loadImageFunction;
12610
- var IS_BROWSER_OR_WEBWORKER = apis.IS_BROWSER_ENV || apis.IS_WEBWORKER_ENV;
12611
- if (IS_BROWSER_OR_WEBWORKER) {
13084
+ if (apis.IS_WEB_ENV) {
12612
13085
  createCanvasFunction = (width, height) => {
12613
13086
  if (!self.OffscreenCanvas) {
12614
- throw new Error("OffscreenCanvas not supported by this browser.");
13087
+ throw new Error("OffscreenCanvas not supported by this environment.");
12615
13088
  }
12616
13089
  return new self.OffscreenCanvas(width, height);
12617
13090
  };
@@ -12701,7 +13174,7 @@ var RawImage = class _RawImage {
12701
13174
  * @returns {RawImage} The image object.
12702
13175
  */
12703
13176
  static fromCanvas(canvas) {
12704
- if (!IS_BROWSER_OR_WEBWORKER) {
13177
+ if (!apis.IS_WEB_ENV) {
12705
13178
  throw new Error("fromCanvas() is only supported in browser environments.");
12706
13179
  }
12707
13180
  const ctx = (
@@ -12730,7 +13203,7 @@ var RawImage = class _RawImage {
12730
13203
  * @returns {Promise<RawImage>} The image object.
12731
13204
  */
12732
13205
  static async fromBlob(blob) {
12733
- if (IS_BROWSER_OR_WEBWORKER) {
13206
+ if (apis.IS_WEB_ENV) {
12734
13207
  const img = await loadImageFunction(blob);
12735
13208
  const ctx = createCanvasFunction(img.width, img.height).getContext("2d");
12736
13209
  ctx.drawImage(img, 0, 0);
@@ -12911,7 +13384,7 @@ var RawImage = class _RawImage {
12911
13384
  } else if (nullish_height) {
12912
13385
  height = width / this.width * this.height;
12913
13386
  }
12914
- if (IS_BROWSER_OR_WEBWORKER) {
13387
+ if (apis.IS_WEB_ENV) {
12915
13388
  const numChannels = this.channels;
12916
13389
  const canvas = this.toCanvas();
12917
13390
  const ctx = createCanvasFunction(width, height).getContext("2d");
@@ -12924,7 +13397,7 @@ var RawImage = class _RawImage {
12924
13397
  case "box":
12925
13398
  case "hamming":
12926
13399
  if (resampleMethod === "box" || resampleMethod === "hamming") {
12927
- console.warn(
13400
+ logger.warn(
12928
13401
  `Resampling method ${resampleMethod} is not yet supported. Using bilinear instead.`
12929
13402
  );
12930
13403
  resampleMethod = "bilinear";
@@ -12959,7 +13432,7 @@ var RawImage = class _RawImage {
12959
13432
  if (left === 0 && right === 0 && top === 0 && bottom === 0) {
12960
13433
  return this;
12961
13434
  }
12962
- if (IS_BROWSER_OR_WEBWORKER) {
13435
+ if (apis.IS_WEB_ENV) {
12963
13436
  const numChannels = this.channels;
12964
13437
  const canvas = this.toCanvas();
12965
13438
  const newWidth = this.width + left + right;
@@ -12983,7 +13456,7 @@ var RawImage = class _RawImage {
12983
13456
  }
12984
13457
  const crop_width = x_max - x_min + 1;
12985
13458
  const crop_height = y_max - y_min + 1;
12986
- if (IS_BROWSER_OR_WEBWORKER) {
13459
+ if (apis.IS_WEB_ENV) {
12987
13460
  const numChannels = this.channels;
12988
13461
  const canvas = this.toCanvas();
12989
13462
  const ctx = createCanvasFunction(crop_width, crop_height).getContext("2d");
@@ -13011,7 +13484,7 @@ var RawImage = class _RawImage {
13011
13484
  }
13012
13485
  const width_offset = (this.width - crop_width) / 2;
13013
13486
  const height_offset = (this.height - crop_height) / 2;
13014
- if (IS_BROWSER_OR_WEBWORKER) {
13487
+ if (apis.IS_WEB_ENV) {
13015
13488
  const numChannels = this.channels;
13016
13489
  const canvas = this.toCanvas();
13017
13490
  const ctx = createCanvasFunction(crop_width, crop_height).getContext("2d");
@@ -13089,7 +13562,7 @@ var RawImage = class _RawImage {
13089
13562
  }
13090
13563
  }
13091
13564
  async toBlob(type = "image/png", quality = 1) {
13092
- if (!IS_BROWSER_OR_WEBWORKER) {
13565
+ if (!apis.IS_WEB_ENV) {
13093
13566
  throw new Error("toBlob() is only supported in browser environments.");
13094
13567
  }
13095
13568
  const canvas = this.toCanvas();
@@ -13106,7 +13579,7 @@ var RawImage = class _RawImage {
13106
13579
  return tensor;
13107
13580
  }
13108
13581
  toCanvas() {
13109
- if (!IS_BROWSER_OR_WEBWORKER) {
13582
+ if (!apis.IS_WEB_ENV) {
13110
13583
  throw new Error("toCanvas() is only supported in browser environments.");
13111
13584
  }
13112
13585
  const cloned = this.clone().rgba();
@@ -13190,7 +13663,7 @@ var RawImage = class _RawImage {
13190
13663
  * @returns {Promise<void>}
13191
13664
  */
13192
13665
  async save(path) {
13193
- if (IS_BROWSER_OR_WEBWORKER) {
13666
+ if (apis.IS_WEB_ENV) {
13194
13667
  if (apis.IS_WEBWORKER_ENV) {
13195
13668
  throw new Error("Unable to save an image from a Web Worker.");
13196
13669
  }
@@ -13210,7 +13683,7 @@ var RawImage = class _RawImage {
13210
13683
  * @returns {import('sharp').Sharp} The Sharp instance.
13211
13684
  */
13212
13685
  toSharp() {
13213
- if (IS_BROWSER_OR_WEBWORKER) {
13686
+ if (apis.IS_WEB_ENV) {
13214
13687
  throw new Error("toSharp() is only supported in server-side environments.");
13215
13688
  }
13216
13689
  return sharp_default(this.data, {
@@ -13423,30 +13896,9 @@ function compute_segments(mask_probs, pred_scores, pred_labels, mask_threshold,
13423
13896
  }
13424
13897
  return [segmentation, segments];
13425
13898
  }
13426
- function smart_resize(height, width, factor = 28, min_pixels = 56 * 56, max_pixels = 14 * 14 * 4 * 1280) {
13427
- if (height < factor || width < factor) {
13428
- throw new Error(`height:${height} or width:${width} must be larger than factor:${factor}`);
13429
- } else if (Math.max(height, width) / Math.min(height, width) > 200) {
13430
- throw new Error(
13431
- `absolute aspect ratio must be smaller than 200, got ${Math.max(height, width) / Math.min(height, width)}`
13432
- );
13433
- }
13434
- let h_bar = Math.round(height / factor) * factor;
13435
- let w_bar = Math.round(width / factor) * factor;
13436
- if (h_bar * w_bar > max_pixels) {
13437
- const beta = Math.sqrt(height * width / max_pixels);
13438
- h_bar = Math.floor(height / beta / factor) * factor;
13439
- w_bar = Math.floor(width / beta / factor) * factor;
13440
- } else if (h_bar * w_bar < min_pixels) {
13441
- const beta = Math.sqrt(min_pixels / (height * width));
13442
- h_bar = Math.ceil(height * beta / factor) * factor;
13443
- w_bar = Math.ceil(width * beta / factor) * factor;
13444
- }
13445
- return [h_bar, w_bar];
13446
- }
13447
13899
  function post_process_panoptic_segmentation(outputs, threshold = 0.5, mask_threshold = 0.5, overlap_mask_area_threshold = 0.8, label_ids_to_fuse = null, target_sizes = null) {
13448
13900
  if (label_ids_to_fuse === null) {
13449
- console.warn("`label_ids_to_fuse` unset. No instance will be fused.");
13901
+ logger.warn("`label_ids_to_fuse` unset. No instance will be fused.");
13450
13902
  label_ids_to_fuse = /* @__PURE__ */ new Set();
13451
13903
  }
13452
13904
  const class_queries_logits = outputs.class_queries_logits ?? outputs.logits;
@@ -13713,9 +14165,6 @@ var ImageProcessor = class extends Callable2 {
13713
14165
  return [newWidth, newHeight];
13714
14166
  } else if (this.size_divisibility !== void 0) {
13715
14167
  return enforce_size_divisibility([srcWidth, srcHeight], this.size_divisibility);
13716
- } else if (this.min_pixels !== void 0 && this.max_pixels !== void 0) {
13717
- const factor = this.config.patch_size * this.config.merge_size;
13718
- return smart_resize(srcHeight, srcWidth, factor, this.min_pixels, this.max_pixels);
13719
14168
  } else {
13720
14169
  throw new Error(
13721
14170
  `Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(size)}`
@@ -14539,7 +14988,40 @@ var PvtImageProcessor = class extends ImageProcessor {
14539
14988
  };
14540
14989
 
14541
14990
  // src/models/qwen2_vl/image_processing_qwen2_vl.js
14991
+ function smart_resize(height, width, factor = 28, min_pixels = 56 * 56, max_pixels = 14 * 14 * 4 * 1280) {
14992
+ if (height < factor || width < factor) {
14993
+ throw new Error(`height:${height} or width:${width} must be larger than factor:${factor}`);
14994
+ } else if (Math.max(height, width) / Math.min(height, width) > 200) {
14995
+ throw new Error(
14996
+ `absolute aspect ratio must be smaller than 200, got ${Math.max(height, width) / Math.min(height, width)}`
14997
+ );
14998
+ }
14999
+ let h_bar = Math.round(height / factor) * factor;
15000
+ let w_bar = Math.round(width / factor) * factor;
15001
+ if (h_bar * w_bar > max_pixels) {
15002
+ const beta = Math.sqrt(height * width / max_pixels);
15003
+ h_bar = Math.floor(height / beta / factor) * factor;
15004
+ w_bar = Math.floor(width / beta / factor) * factor;
15005
+ } else if (h_bar * w_bar < min_pixels) {
15006
+ const beta = Math.sqrt(min_pixels / (height * width));
15007
+ h_bar = Math.ceil(height * beta / factor) * factor;
15008
+ w_bar = Math.ceil(width * beta / factor) * factor;
15009
+ }
15010
+ return [h_bar, w_bar];
15011
+ }
14542
15012
  var Qwen2VLImageProcessor = class extends ImageProcessor {
15013
+ constructor(config) {
15014
+ super(config);
15015
+ this.min_pixels = config.min_pixels ?? config.size?.shortest_edge;
15016
+ this.max_pixels = config.max_pixels ?? config.size?.longest_edge;
15017
+ this.patch_size = config.patch_size;
15018
+ this.merge_size = config.merge_size;
15019
+ }
15020
+ /** @type {ImageProcessor['get_resize_output_image_size']} */
15021
+ get_resize_output_image_size(image, size) {
15022
+ const factor = this.patch_size * this.merge_size;
15023
+ return smart_resize(image.height, image.width, factor, this.min_pixels, this.max_pixels);
15024
+ }
14543
15025
  async _call(images, ...args) {
14544
15026
  const { pixel_values, original_sizes, reshaped_input_sizes } = await super._call(images, ...args);
14545
15027
  let patches = pixel_values;
@@ -14941,7 +15423,7 @@ var AutoImageProcessor = class {
14941
15423
  let image_processor_class = image_processors_exports[key?.replace(/Fast$/, "")];
14942
15424
  if (!image_processor_class) {
14943
15425
  if (key !== void 0) {
14944
- console.warn(
15426
+ logger.warn(
14945
15427
  `Image processor type '${key}' not found, assuming base ImageProcessor. Please report this at ${GITHUB_ISSUE_URL}.`
14946
15428
  );
14947
15429
  }
@@ -15610,7 +16092,7 @@ var PaliGemmaProcessor = class extends Processor {
15610
16092
  // `images` is required, `text` is optional
15611
16093
  async _call(images, text = null, kwargs = {}) {
15612
16094
  if (!text) {
15613
- console.warn(
16095
+ logger.warn(
15614
16096
  "You are using PaliGemma without a text prefix. It will perform as a picture-captioning model."
15615
16097
  );
15616
16098
  text = "";
@@ -15632,7 +16114,7 @@ var PaliGemmaProcessor = class extends Processor {
15632
16114
  return expanded_sample.slice(0, bos_index) + bos_token + expanded_sample.slice(bos_index) + "\n";
15633
16115
  });
15634
16116
  } else {
15635
- console.warn(
16117
+ logger.warn(
15636
16118
  "You are passing both `text` and `images` to `PaliGemmaProcessor`. The processor expects special image tokens in the text, as many tokens as there are images per each text. It is recommended to add `<image>` tokens in the very beginning of your text. For this call, we will infer how many images each text has and add special tokens."
15637
16119
  );
15638
16120
  input_strings = text.map(
@@ -15788,6 +16270,14 @@ var Qwen2VLProcessor = class extends Processor {
15788
16270
  }
15789
16271
  };
15790
16272
 
16273
+ // src/models/qwen2_5_vl/processing_qwen2_5_vl.js
16274
+ var Qwen2_5_VLProcessor = class extends Qwen2VLProcessor {
16275
+ };
16276
+
16277
+ // src/models/qwen3_vl/processing_qwen3_vl.js
16278
+ var Qwen3VLProcessor = class extends Qwen2_5_VLProcessor {
16279
+ };
16280
+
15791
16281
  // src/models/sam/processing_sam.js
15792
16282
  var SamProcessor = class extends Processor {
15793
16283
  static image_processor_class = AutoImageProcessor;
@@ -16033,6 +16523,9 @@ function getNormalizedConfig(config) {
16033
16523
  case "gemma3n":
16034
16524
  case "chatterbox":
16035
16525
  case "mistral3":
16526
+ case "qwen2_5_vl":
16527
+ case "qwen3_vl":
16528
+ case "qwen3_vl_moe":
16036
16529
  init_normalized_config = getNormalizedConfig(config.text_config);
16037
16530
  break;
16038
16531
  case "moondream1":
@@ -16069,6 +16562,7 @@ function getNormalizedConfig(config) {
16069
16562
  case "nanochat":
16070
16563
  case "apertus":
16071
16564
  case "arcee":
16565
+ case "afmoe":
16072
16566
  case "lfm2":
16073
16567
  case "lfm2_moe":
16074
16568
  case "smollm3":
@@ -16083,7 +16577,12 @@ function getNormalizedConfig(config) {
16083
16577
  case "mistral":
16084
16578
  case "starcoder2":
16085
16579
  case "qwen2":
16580
+ case "qwen2_moe":
16086
16581
  case "qwen2_vl":
16582
+ case "qwen2_5_vl_text":
16583
+ case "qwen3_moe":
16584
+ case "qwen3_vl_text":
16585
+ case "qwen3_vl_moe_text":
16087
16586
  case "phi":
16088
16587
  case "phi3":
16089
16588
  case "phi3_v":
@@ -16228,7 +16727,10 @@ function getCacheShapes(config, options) {
16228
16727
  const pkv_prefix = options?.prefix ?? "past_key_values";
16229
16728
  const conv_prefix = pkv_prefix === "present" ? "present" : "past";
16230
16729
  const cache_values = {};
16231
- const { layer_types, num_attention_heads, num_key_value_heads, hidden_size, conv_L_cache } = config;
16730
+ const { layer_types, num_attention_heads, num_key_value_heads, hidden_size, conv_L_cache } = (
16731
+ /** @type {any} */
16732
+ config
16733
+ );
16232
16734
  const head_dim = hidden_size / num_attention_heads;
16233
16735
  const batch_size = options?.batch_size ?? 1;
16234
16736
  for (let i = 0; i < layer_types.length; ++i) {
@@ -16274,11 +16776,65 @@ function getCacheShapes(config, options) {
16274
16776
  }
16275
16777
  if (!layer_types || layer_types[i] === "attention") {
16276
16778
  for (const kv of ["key", "value"]) {
16277
- cache_values[`${pkv_prefix}.${i}.${kv}`] = [batch_size, num_key_value_heads, 0, head_dim];
16779
+ cache_values[`${pkv_prefix}.${i}.${kv}`] = [batch_size, num_key_value_heads, 0, head_dim];
16780
+ }
16781
+ }
16782
+ }
16783
+ return cache_values;
16784
+ } else if (["qwen3_next", "qwen3_5_text", "qwen3_5_moe_text", "olmo_hybrid"].includes(config.model_type)) {
16785
+ const pkv_prefix = options?.prefix ?? "past_key_values";
16786
+ const conv_prefix = pkv_prefix === "present" ? "present" : "past";
16787
+ const cache_values = {};
16788
+ const {
16789
+ head_dim,
16790
+ layer_types,
16791
+ num_attention_heads,
16792
+ num_key_value_heads,
16793
+ hidden_size,
16794
+ linear_num_value_heads,
16795
+ linear_num_key_heads,
16796
+ linear_key_head_dim,
16797
+ linear_value_head_dim,
16798
+ linear_conv_kernel_dim
16799
+ } = (
16800
+ /** @type {any} */
16801
+ config
16802
+ );
16803
+ const key_dim = linear_key_head_dim * linear_num_key_heads;
16804
+ const value_dim = linear_value_head_dim * linear_num_value_heads;
16805
+ const final_head_dim = head_dim ?? hidden_size / num_attention_heads;
16806
+ const batch_size = options?.batch_size ?? 1;
16807
+ for (let i = 0; i < layer_types.length; ++i) {
16808
+ if (layer_types[i] === "full_attention") {
16809
+ for (const kv of ["key", "value"]) {
16810
+ cache_values[`${pkv_prefix}.${i}.${kv}`] = [batch_size, num_key_value_heads, 0, final_head_dim];
16811
+ }
16812
+ } else if (layer_types[i] === "linear_attention") {
16813
+ if (config.model_type === "olmo_hybrid") {
16814
+ cache_values[`${conv_prefix}_conv.${i}.key`] = [batch_size, key_dim, linear_conv_kernel_dim];
16815
+ cache_values[`${conv_prefix}_conv.${i}.value`] = [batch_size, value_dim, linear_conv_kernel_dim];
16816
+ cache_values[`${conv_prefix}_conv.${i}.query`] = [batch_size, key_dim, linear_conv_kernel_dim];
16817
+ } else {
16818
+ const conv_dim = key_dim * 2 + value_dim;
16819
+ cache_values[`${conv_prefix}_conv.${i}`] = [batch_size, conv_dim, linear_conv_kernel_dim];
16278
16820
  }
16821
+ cache_values[`${conv_prefix}_recurrent.${i}`] = [
16822
+ batch_size,
16823
+ linear_num_value_heads,
16824
+ linear_key_head_dim,
16825
+ linear_value_head_dim
16826
+ ];
16827
+ } else {
16828
+ throw new Error(`Unsupported layer type: ${layer_types[i]}`);
16279
16829
  }
16280
16830
  }
16281
16831
  return cache_values;
16832
+ } else if (["qwen3_5", "qwen3_5_moe"].includes(config.model_type)) {
16833
+ return getCacheShapes(
16834
+ /**@type {any} */
16835
+ config.text_config,
16836
+ options
16837
+ );
16282
16838
  }
16283
16839
  return getKeyValueShapes(config, options);
16284
16840
  }
@@ -16383,6 +16939,22 @@ var AutoConfig = class {
16383
16939
  };
16384
16940
 
16385
16941
  // src/utils/model-loader.js
16942
+ function resolveExternalDataFormat(config, fullName, fileName) {
16943
+ if (!config) return 0;
16944
+ if (typeof config === "object" && config !== null) {
16945
+ if (config.hasOwnProperty(fullName)) return +config[fullName];
16946
+ if (config.hasOwnProperty(fileName)) return +config[fileName];
16947
+ return 0;
16948
+ }
16949
+ return +config;
16950
+ }
16951
+ function getExternalDataChunkNames(fullName, numChunks) {
16952
+ const names = [];
16953
+ for (let i = 0; i < numChunks; ++i) {
16954
+ names.push(`${fullName}_data${i === 0 ? "" : "_" + i}`);
16955
+ }
16956
+ return names;
16957
+ }
16386
16958
  async function getCoreModelFile(pretrained_model_name_or_path, fileName, options, suffix) {
16387
16959
  const baseName = `${fileName}${suffix}.onnx`;
16388
16960
  const fullPath = `${options.subfolder ?? ""}/${baseName}`;
@@ -16392,27 +16964,15 @@ async function getModelDataFiles(pretrained_model_name_or_path, fileName, suffix
16392
16964
  const baseName = `${fileName}${suffix}.onnx`;
16393
16965
  const return_path = apis.IS_NODE_ENV;
16394
16966
  let externalDataPromises = [];
16395
- if (use_external_data_format) {
16396
- let external_data_format;
16397
- if (typeof use_external_data_format === "object") {
16398
- if (use_external_data_format.hasOwnProperty(baseName)) {
16399
- external_data_format = use_external_data_format[baseName];
16400
- } else if (use_external_data_format.hasOwnProperty(fileName)) {
16401
- external_data_format = use_external_data_format[fileName];
16402
- } else {
16403
- external_data_format = false;
16404
- }
16405
- } else {
16406
- external_data_format = use_external_data_format;
16407
- }
16408
- const num_chunks = +external_data_format;
16967
+ const num_chunks = resolveExternalDataFormat(use_external_data_format, baseName, fileName);
16968
+ if (num_chunks > 0) {
16409
16969
  if (num_chunks > MAX_EXTERNAL_DATA_CHUNKS) {
16410
16970
  throw new Error(
16411
16971
  `The number of external data chunks (${num_chunks}) exceeds the maximum allowed value (${MAX_EXTERNAL_DATA_CHUNKS}).`
16412
16972
  );
16413
16973
  }
16414
- for (let i = 0; i < num_chunks; ++i) {
16415
- const path = `${baseName}_data${i === 0 ? "" : "_" + i}`;
16974
+ const chunkNames = getExternalDataChunkNames(baseName, num_chunks);
16975
+ for (const path of chunkNames) {
16416
16976
  const fullPath = `${options.subfolder ?? ""}/${path}`;
16417
16977
  externalDataPromises.push(
16418
16978
  new Promise(async (resolve, reject) => {
@@ -16442,18 +17002,11 @@ async function getModelDataFiles(pretrained_model_name_or_path, fileName, suffix
16442
17002
  // src/models/session.js
16443
17003
  async function getSession(pretrained_model_name_or_path, fileName, options, is_decoder = false) {
16444
17004
  let custom_config = options.config?.["transformers.js_config"] ?? {};
16445
- let device = options.device ?? custom_config.device;
16446
- if (device && typeof device !== "string") {
16447
- if (device.hasOwnProperty(fileName)) {
16448
- device = device[fileName];
16449
- } else {
16450
- console.warn(`device not specified for "${fileName}". Using the default device.`);
16451
- device = null;
16452
- }
16453
- }
16454
17005
  const selectedDevice = (
16455
17006
  /** @type {import("../utils/devices.js").DeviceType} */
16456
- device ?? (apis.IS_NODE_ENV ? "cpu" : "wasm")
17007
+ selectDevice(options.device ?? custom_config.device, fileName, {
17008
+ warn: (msg) => logger.info(msg)
17009
+ })
16457
17010
  );
16458
17011
  const executionProviders = deviceToExecutionProviders(selectedDevice);
16459
17012
  const device_config = custom_config.device_config ?? {};
@@ -16463,31 +17016,12 @@ async function getSession(pretrained_model_name_or_path, fileName, options, is_d
16463
17016
  ...device_config[selectedDevice]
16464
17017
  };
16465
17018
  }
16466
- let dtype = options.dtype ?? custom_config.dtype;
16467
- if (typeof dtype !== "string") {
16468
- if (dtype && dtype.hasOwnProperty(fileName)) {
16469
- dtype = dtype[fileName];
16470
- } else {
16471
- dtype = DEFAULT_DEVICE_DTYPE_MAPPING[selectedDevice] ?? DATA_TYPES.fp32;
16472
- console.warn(
16473
- `dtype not specified for "${fileName}". Using the default dtype (${dtype}) for this device (${selectedDevice}).`
16474
- );
16475
- }
16476
- }
16477
- if (dtype === DATA_TYPES.auto) {
16478
- let config_dtype = custom_config.dtype;
16479
- if (typeof config_dtype !== "string") {
16480
- config_dtype = config_dtype?.[fileName];
16481
- }
16482
- if (config_dtype && config_dtype !== DATA_TYPES.auto && DATA_TYPES.hasOwnProperty(config_dtype)) {
16483
- dtype = config_dtype;
16484
- } else {
16485
- dtype = DEFAULT_DEVICE_DTYPE_MAPPING[selectedDevice] ?? DATA_TYPES.fp32;
16486
- }
16487
- }
16488
17019
  const selectedDtype = (
16489
17020
  /** @type {import("../utils/dtypes.js").DataType} */
16490
- dtype
17021
+ selectDtype(options.dtype ?? custom_config.dtype, fileName, selectedDevice, {
17022
+ configDtype: custom_config.dtype,
17023
+ warn: (msg) => logger.info(msg)
17024
+ })
16491
17025
  );
16492
17026
  if (!DEFAULT_DTYPE_SUFFIX_MAPPING.hasOwnProperty(selectedDtype)) {
16493
17027
  throw new Error(`Invalid dtype: ${selectedDtype}. Should be one of: ${Object.keys(DATA_TYPES).join(", ")}`);
@@ -16507,7 +17041,7 @@ async function getSession(pretrained_model_name_or_path, fileName, options, is_d
16507
17041
  if (free_dimension_overrides) {
16508
17042
  session_options.freeDimensionOverrides ??= free_dimension_overrides;
16509
17043
  } else if (selectedDevice.startsWith("webnn") && !session_options.freeDimensionOverrides) {
16510
- console.warn(
17044
+ logger.warn(
16511
17045
  `WebNN does not currently support dynamic shapes and requires 'free_dimension_overrides' to be set in config.json, preferably as a field within config["transformers.js_config"]["device_config"]["${selectedDevice}"]. When 'free_dimension_overrides' is not set, you may experience significant performance degradation.`
16512
17046
  );
16513
17047
  }
@@ -16603,8 +17137,8 @@ async function sessionRun(session, inputs) {
16603
17137
  return [k, unpacked];
16604
17138
  })
16605
17139
  );
16606
- console.error(`An error occurred during model execution: "${e}".`);
16607
- console.error("Inputs given to model:", formatted);
17140
+ logger.error(`An error occurred during model execution: "${e}".`);
17141
+ logger.error("Inputs given to model:", formatted);
16608
17142
  throw e;
16609
17143
  }
16610
17144
  }
@@ -16628,7 +17162,7 @@ function validateInputs(session, inputs) {
16628
17162
  const numInputsNeeded = session.inputNames.length;
16629
17163
  if (numInputsProvided > numInputsNeeded) {
16630
17164
  let ignored = Object.keys(inputs).filter((inputName) => !session.inputNames.includes(inputName));
16631
- console.warn(
17165
+ logger.warn(
16632
17166
  `WARNING: Too many inputs were provided (${numInputsProvided} > ${numInputsNeeded}). The following inputs will be ignored: "${ignored.join(", ")}".`
16633
17167
  );
16634
17168
  }
@@ -17761,22 +18295,11 @@ var LogitsSampler = class extends Callable2 {
17761
18295
  }
17762
18296
  /**
17763
18297
  * Selects an item randomly based on the specified probabilities.
17764
- * @param {import("../transformers.js").DataArray} probabilities An array of probabilities to use for selection.
18298
+ * @param {Float32Array} probabilities An array of probabilities to use for selection.
17765
18299
  * @returns {number} The index of the selected item.
17766
18300
  */
17767
18301
  randomSelect(probabilities) {
17768
- let sumProbabilities = 0;
17769
- for (let i = 0; i < probabilities.length; ++i) {
17770
- sumProbabilities += probabilities[i];
17771
- }
17772
- let r = Math.random() * sumProbabilities;
17773
- for (let i = 0; i < probabilities.length; ++i) {
17774
- r -= probabilities[i];
17775
- if (r <= 0) {
17776
- return i;
17777
- }
17778
- }
17779
- return 0;
18302
+ return _weightedIndex(probabilities);
17780
18303
  }
17781
18304
  /**
17782
18305
  * Returns a Sampler object based on the specified options.
@@ -17868,6 +18391,14 @@ var MODEL_MAPPING_NAMES = null;
17868
18391
  function registerTaskMappings(mappings) {
17869
18392
  MODEL_MAPPING_NAMES = mappings;
17870
18393
  }
18394
+ function getPastLength(past_key_values) {
18395
+ for (const name in past_key_values) {
18396
+ if (name.startsWith("past_key_values.")) {
18397
+ return past_key_values[name].dims.at(-2);
18398
+ }
18399
+ }
18400
+ return Object.values(past_key_values)[0].dims.at(-2);
18401
+ }
17871
18402
  function toI64Tensor(items) {
17872
18403
  if (items instanceof Tensor2) {
17873
18404
  return items;
@@ -18282,7 +18813,7 @@ var PreTrainedModel = class extends Callable2 {
18282
18813
  if (modelType === void 0) {
18283
18814
  const type = modelName ?? config?.model_type;
18284
18815
  if (type !== "custom") {
18285
- console.warn(
18816
+ logger.warn(
18286
18817
  `Model type for '${type}' not found, assuming encoder-only architecture. Please report this at ${GITHUB_ISSUE_URL}.`
18287
18818
  );
18288
18819
  }
@@ -18373,7 +18904,7 @@ var PreTrainedModel = class extends Callable2 {
18373
18904
  processors.push(new ClassifierFreeGuidanceLogitsProcessor(generation_config.guidance_scale));
18374
18905
  }
18375
18906
  if (generation_config.temperature === 0 && generation_config.do_sample) {
18376
- console.warn(
18907
+ logger.warn(
18377
18908
  "`do_sample` changed to false because `temperature: 0` implies greedy sampling (always selecting the most likely token), which is incompatible with `do_sample: true`."
18378
18909
  );
18379
18910
  generation_config.do_sample = false;
@@ -18746,7 +19277,7 @@ var PreTrainedModel = class extends Callable2 {
18746
19277
  const pkvs = /* @__PURE__ */ Object.create(null);
18747
19278
  for (const name in decoderResults) {
18748
19279
  if (name.startsWith("present")) {
18749
- const newName = name.replace("present_ssm", "past_ssm").replace("present_conv", "past_conv").replace("present", "past_key_values");
19280
+ const newName = name.replace("present_ssm", "past_ssm").replace("present_conv", "past_conv").replace("present_recurrent", "past_recurrent").replace("present", "past_key_values");
18750
19281
  const is_encoder_pkv = name.includes("encoder");
18751
19282
  if (is_encoder_pkv && pastKeyValues) {
18752
19283
  pkvs[newName] = pastKeyValues[newName];
@@ -18907,7 +19438,7 @@ async function generic_text_to_text_forward(self2, {
18907
19438
  }));
18908
19439
  } else if (past_key_values && modality_values && input_ids.dims[1] === 1) {
18909
19440
  const target_length = input_ids.dims[1];
18910
- const past_length = Object.values(past_key_values)[0].dims.at(-2);
19441
+ const past_length = getPastLength(past_key_values);
18911
19442
  attention_mask = cat(
18912
19443
  [
18913
19444
  ones([input_ids.dims[0], past_length]),
@@ -18918,7 +19449,20 @@ async function generic_text_to_text_forward(self2, {
18918
19449
  }
18919
19450
  }
18920
19451
  if (!position_ids) {
18921
- if (self2.config.model_type === "qwen2_vl") {
19452
+ if (
19453
+ // Handle special case for qwen vl models
19454
+ [
19455
+ "qwen2_vl",
19456
+ "qwen2_5_vl",
19457
+ "qwen2_5_vl_text",
19458
+ "qwen3_vl",
19459
+ "qwen3_vl_text",
19460
+ "qwen3_5",
19461
+ "qwen3_5_text",
19462
+ "qwen3_5_moe",
19463
+ "qwen3_5_moe_text"
19464
+ ].includes(self2.config.model_type)
19465
+ ) {
18922
19466
  const { image_grid_thw, video_grid_thw } = kwargs;
18923
19467
  [position_ids] = self2.get_rope_index(input_ids, image_grid_thw, video_grid_thw, attention_mask);
18924
19468
  }
@@ -18985,7 +19529,7 @@ function create_position_ids(model_inputs, past_key_values = null, start_index =
18985
19529
  return position_ids;
18986
19530
  }
18987
19531
  function decoder_prepare_inputs_for_generation(self2, input_ids, model_inputs, generation_config) {
18988
- const past_length = model_inputs.past_key_values ? Object.values(model_inputs.past_key_values)[0].dims.at(-2) : 0;
19532
+ const past_length = model_inputs.past_key_values ? getPastLength(model_inputs.past_key_values) : 0;
18989
19533
  if (!model_inputs.attention_mask) {
18990
19534
  let dims;
18991
19535
  for (const key of ["input_ids", "inputs_embeds", "position_ids"]) {
@@ -19100,6 +19644,9 @@ __export(models_exports, {
19100
19644
  ASTForAudioClassification: () => ASTForAudioClassification,
19101
19645
  ASTModel: () => ASTModel,
19102
19646
  ASTPreTrainedModel: () => ASTPreTrainedModel,
19647
+ AfmoeForCausalLM: () => AfmoeForCausalLM,
19648
+ AfmoeModel: () => AfmoeModel,
19649
+ AfmoePreTrainedModel: () => AfmoePreTrainedModel,
19103
19650
  AlbertForMaskedLM: () => AlbertForMaskedLM,
19104
19651
  AlbertForQuestionAnswering: () => AlbertForQuestionAnswering,
19105
19652
  AlbertForSequenceClassification: () => AlbertForSequenceClassification,
@@ -19466,6 +20013,9 @@ __export(models_exports, {
19466
20013
  Olmo3Model: () => Olmo3Model,
19467
20014
  Olmo3PreTrainedModel: () => Olmo3PreTrainedModel,
19468
20015
  OlmoForCausalLM: () => OlmoForCausalLM,
20016
+ OlmoHybridForCausalLM: () => OlmoHybridForCausalLM,
20017
+ OlmoHybridModel: () => OlmoHybridModel,
20018
+ OlmoHybridPreTrainedModel: () => OlmoHybridPreTrainedModel,
19469
20019
  OlmoModel: () => OlmoModel,
19470
20020
  OlmoPreTrainedModel: () => OlmoPreTrainedModel,
19471
20021
  OpenELMForCausalLM: () => OpenELMForCausalLM,
@@ -19504,12 +20054,26 @@ __export(models_exports, {
19504
20054
  PyAnnotePreTrainedModel: () => PyAnnotePreTrainedModel,
19505
20055
  Qwen2ForCausalLM: () => Qwen2ForCausalLM,
19506
20056
  Qwen2Model: () => Qwen2Model,
20057
+ Qwen2MoeForCausalLM: () => Qwen2MoeForCausalLM,
20058
+ Qwen2MoeModel: () => Qwen2MoeModel,
20059
+ Qwen2MoePreTrainedModel: () => Qwen2MoePreTrainedModel,
19507
20060
  Qwen2PreTrainedModel: () => Qwen2PreTrainedModel,
19508
20061
  Qwen2VLForConditionalGeneration: () => Qwen2VLForConditionalGeneration,
19509
20062
  Qwen2VLPreTrainedModel: () => Qwen2VLPreTrainedModel,
20063
+ Qwen2_5_VLForConditionalGeneration: () => Qwen2_5_VLForConditionalGeneration,
19510
20064
  Qwen3ForCausalLM: () => Qwen3ForCausalLM,
19511
20065
  Qwen3Model: () => Qwen3Model,
20066
+ Qwen3MoeForCausalLM: () => Qwen3MoeForCausalLM,
20067
+ Qwen3MoeModel: () => Qwen3MoeModel,
20068
+ Qwen3MoePreTrainedModel: () => Qwen3MoePreTrainedModel,
20069
+ Qwen3NextForCausalLM: () => Qwen3NextForCausalLM,
20070
+ Qwen3NextModel: () => Qwen3NextModel,
20071
+ Qwen3NextPreTrainedModel: () => Qwen3NextPreTrainedModel,
19512
20072
  Qwen3PreTrainedModel: () => Qwen3PreTrainedModel,
20073
+ Qwen3VLForConditionalGeneration: () => Qwen3VLForConditionalGeneration,
20074
+ Qwen3VLMoeForConditionalGeneration: () => Qwen3VLMoeForConditionalGeneration,
20075
+ Qwen3_5ForConditionalGeneration: () => Qwen3_5ForConditionalGeneration,
20076
+ Qwen3_5MoeForConditionalGeneration: () => Qwen3_5MoeForConditionalGeneration,
19513
20077
  RFDetrForObjectDetection: () => RFDetrForObjectDetection,
19514
20078
  RFDetrModel: () => RFDetrModel,
19515
20079
  RFDetrObjectDetectionOutput: () => RFDetrObjectDetectionOutput,
@@ -19720,6 +20284,14 @@ var ApertusModel = class extends ApertusPreTrainedModel {
19720
20284
  var ApertusForCausalLM = class extends ApertusPreTrainedModel {
19721
20285
  };
19722
20286
 
20287
+ // src/models/afmoe/modeling_afmoe.js
20288
+ var AfmoePreTrainedModel = class extends PreTrainedModel {
20289
+ };
20290
+ var AfmoeModel = class extends AfmoePreTrainedModel {
20291
+ };
20292
+ var AfmoeForCausalLM = class extends AfmoePreTrainedModel {
20293
+ };
20294
+
19723
20295
  // src/models/arcee/modeling_arcee.js
19724
20296
  var ArceePreTrainedModel = class extends PreTrainedModel {
19725
20297
  };
@@ -22061,6 +22633,14 @@ var Olmo3Model = class extends Olmo3PreTrainedModel {
22061
22633
  var Olmo3ForCausalLM = class extends Olmo3PreTrainedModel {
22062
22634
  };
22063
22635
 
22636
+ // src/models/olmo_hybrid/modeling_olmo_hybrid.js
22637
+ var OlmoHybridPreTrainedModel = class extends PreTrainedModel {
22638
+ };
22639
+ var OlmoHybridModel = class extends OlmoHybridPreTrainedModel {
22640
+ };
22641
+ var OlmoHybridForCausalLM = class extends OlmoHybridPreTrainedModel {
22642
+ };
22643
+
22064
22644
  // src/models/openelm/modeling_openelm.js
22065
22645
  var OpenELMPreTrainedModel = class extends PreTrainedModel {
22066
22646
  };
@@ -22265,6 +22845,14 @@ var Qwen2Model = class extends Qwen2PreTrainedModel {
22265
22845
  var Qwen2ForCausalLM = class extends Qwen2PreTrainedModel {
22266
22846
  };
22267
22847
 
22848
+ // src/models/qwen2_moe/modeling_qwen2_moe.js
22849
+ var Qwen2MoePreTrainedModel = class extends PreTrainedModel {
22850
+ };
22851
+ var Qwen2MoeModel = class extends Qwen2MoePreTrainedModel {
22852
+ };
22853
+ var Qwen2MoeForCausalLM = class extends Qwen2MoePreTrainedModel {
22854
+ };
22855
+
22268
22856
  // src/models/qwen2_vl/modeling_qwen2_vl.js
22269
22857
  var Qwen2VLPreTrainedModel = class extends PreTrainedModel {
22270
22858
  forward_params = [
@@ -22279,6 +22867,7 @@ var Qwen2VLPreTrainedModel = class extends PreTrainedModel {
22279
22867
  ];
22280
22868
  };
22281
22869
  var Qwen2VLForConditionalGeneration = class extends Qwen2VLPreTrainedModel {
22870
+ image_grid_thw_name = "grid_thw";
22282
22871
  /**
22283
22872
  * Calculate the 3D rope index based on image and video's temporal, height and width in LLM.
22284
22873
  *
@@ -22443,7 +23032,10 @@ var Qwen2VLForConditionalGeneration = class extends Qwen2VLPreTrainedModel {
22443
23032
  }
22444
23033
  }
22445
23034
  async encode_image({ pixel_values, image_grid_thw }) {
22446
- const features = (await sessionRun(this.sessions["vision_encoder"], { pixel_values, grid_thw: image_grid_thw })).image_features;
23035
+ const features = (await sessionRun(this.sessions["vision_encoder"], {
23036
+ pixel_values,
23037
+ [this.image_grid_thw_name]: image_grid_thw
23038
+ })).image_features;
22447
23039
  return features;
22448
23040
  }
22449
23041
  _merge_input_ids_with_image_features(kwargs) {
@@ -22464,15 +23056,41 @@ var Qwen2VLForConditionalGeneration = class extends Qwen2VLPreTrainedModel {
22464
23056
  );
22465
23057
  } else {
22466
23058
  model_inputs.pixel_values = null;
22467
- const delta = BigInt(Object.values(model_inputs.past_key_values)[0].dims.at(-2));
22468
- const rope_deltas_list = model_inputs.rope_deltas.map((x) => delta + x);
22469
- model_inputs.position_ids = stack([rope_deltas_list, rope_deltas_list, rope_deltas_list], 0);
23059
+ const past_length = getPastLength(model_inputs.past_key_values);
23060
+ if (past_length < model_inputs.input_ids.dims[1]) {
23061
+ const [full_position_ids, rope_deltas] = this.get_rope_index(
23062
+ model_inputs.input_ids,
23063
+ model_inputs.image_grid_thw,
23064
+ model_inputs.video_grid_thw,
23065
+ model_inputs.attention_mask
23066
+ );
23067
+ model_inputs.rope_deltas = rope_deltas;
23068
+ model_inputs.position_ids = full_position_ids.slice(null, null, [past_length, null]);
23069
+ model_inputs.input_ids = model_inputs.input_ids.slice(null, [past_length, null]);
23070
+ } else {
23071
+ if (!model_inputs.rope_deltas) {
23072
+ [, model_inputs.rope_deltas] = this.get_rope_index(
23073
+ model_inputs.input_ids,
23074
+ model_inputs.image_grid_thw,
23075
+ model_inputs.video_grid_thw,
23076
+ model_inputs.attention_mask
23077
+ );
23078
+ }
23079
+ const delta = BigInt(past_length);
23080
+ const rope_deltas_list = model_inputs.rope_deltas.map((x) => delta + x);
23081
+ model_inputs.position_ids = stack([rope_deltas_list, rope_deltas_list, rope_deltas_list], 0);
23082
+ }
22470
23083
  }
22471
23084
  }
22472
23085
  return model_inputs;
22473
23086
  }
22474
23087
  };
22475
23088
 
23089
+ // src/models/qwen2_5_vl/modeling_qwen2_5_vl.js
23090
+ var Qwen2_5_VLForConditionalGeneration = class extends Qwen2VLForConditionalGeneration {
23091
+ image_grid_thw_name = "image_grid_thw";
23092
+ };
23093
+
22476
23094
  // src/models/qwen3/modeling_qwen3.js
22477
23095
  var Qwen3PreTrainedModel = class extends PreTrainedModel {
22478
23096
  };
@@ -22481,6 +23099,38 @@ var Qwen3Model = class extends Qwen3PreTrainedModel {
22481
23099
  var Qwen3ForCausalLM = class extends Qwen3PreTrainedModel {
22482
23100
  };
22483
23101
 
23102
+ // src/models/qwen3_moe/modeling_qwen3_moe.js
23103
+ var Qwen3MoePreTrainedModel = class extends PreTrainedModel {
23104
+ };
23105
+ var Qwen3MoeModel = class extends Qwen3MoePreTrainedModel {
23106
+ };
23107
+ var Qwen3MoeForCausalLM = class extends Qwen3MoePreTrainedModel {
23108
+ };
23109
+
23110
+ // src/models/qwen3_next/modeling_qwen3_next.js
23111
+ var Qwen3NextPreTrainedModel = class extends PreTrainedModel {
23112
+ };
23113
+ var Qwen3NextModel = class extends Qwen3NextPreTrainedModel {
23114
+ };
23115
+ var Qwen3NextForCausalLM = class extends Qwen3NextPreTrainedModel {
23116
+ };
23117
+
23118
+ // src/models/qwen3_vl/modeling_qwen3_vl.js
23119
+ var Qwen3VLForConditionalGeneration = class extends Qwen2_5_VLForConditionalGeneration {
23120
+ };
23121
+
23122
+ // src/models/qwen3_vl_moe/modeling_qwen3_vl_moe.js
23123
+ var Qwen3VLMoeForConditionalGeneration = class extends Qwen3VLForConditionalGeneration {
23124
+ };
23125
+
23126
+ // src/models/qwen3_5/modeling_qwen3_5.js
23127
+ var Qwen3_5ForConditionalGeneration = class extends Qwen3VLForConditionalGeneration {
23128
+ };
23129
+
23130
+ // src/models/qwen3_5_moe/modeling_qwen3_5_moe.js
23131
+ var Qwen3_5MoeForConditionalGeneration = class extends Qwen3_5ForConditionalGeneration {
23132
+ };
23133
+
22484
23134
  // src/models/resnet/modeling_resnet.js
22485
23135
  var ResNetPreTrainedModel = class extends PreTrainedModel {
22486
23136
  };
@@ -23538,7 +24188,7 @@ var WhisperForConditionalGeneration = class extends WhisperPreTrainedModel {
23538
24188
  const task = generation_config.task;
23539
24189
  if (generation_config.is_multilingual) {
23540
24190
  if (!language) {
23541
- console.warn("No language specified - defaulting to English (en).");
24191
+ logger.warn("No language specified - defaulting to English (en).");
23542
24192
  language = "en";
23543
24193
  }
23544
24194
  const language_code = whisper_language_to_code(language);
@@ -23553,7 +24203,7 @@ var WhisperForConditionalGeneration = class extends WhisperPreTrainedModel {
23553
24203
  if (!generation_config.return_timestamps && generation_config.no_timestamps_token_id && init_tokens.at(-1) !== generation_config.no_timestamps_token_id) {
23554
24204
  init_tokens.push(generation_config.no_timestamps_token_id);
23555
24205
  } else if (generation_config.return_timestamps && init_tokens.at(-1) === generation_config.no_timestamps_token_id) {
23556
- console.warn(
24206
+ logger.warn(
23557
24207
  "<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."
23558
24208
  );
23559
24209
  init_tokens.pop();
@@ -23595,7 +24245,7 @@ var WhisperForConditionalGeneration = class extends WhisperPreTrainedModel {
23595
24245
  );
23596
24246
  }
23597
24247
  if (generation_config.task === "translate") {
23598
- console.warn("Token-level timestamps may not be reliable for task 'translate'.");
24248
+ logger.warn("Token-level timestamps may not be reliable for task 'translate'.");
23599
24249
  }
23600
24250
  generation_config.output_attentions = true;
23601
24251
  generation_config.return_dict_in_generate = true;
@@ -23636,13 +24286,13 @@ var WhisperForConditionalGeneration = class extends WhisperPreTrainedModel {
23636
24286
  );
23637
24287
  }
23638
24288
  if (num_frames == null) {
23639
- console.warn(
24289
+ logger.warn(
23640
24290
  "`num_frames` has not been set, meaning the entire audio will be analyzed. This may lead to inaccurate token-level timestamps for short audios (< 30 seconds)."
23641
24291
  );
23642
24292
  }
23643
24293
  let median_filter_width = this.config.median_filter_width;
23644
24294
  if (median_filter_width === void 0) {
23645
- console.warn("Model config has no `median_filter_width`, using default value of 7.");
24295
+ logger.warn("Model config has no `median_filter_width`, using default value of 7.");
23646
24296
  median_filter_width = 7;
23647
24297
  }
23648
24298
  const batch = generate_outputs.cross_attentions;
@@ -23960,6 +24610,7 @@ var MODEL_MAPPING_NAMES_DECODER_ONLY = /* @__PURE__ */ new Map([
23960
24610
  ["apertus", "ApertusModel"],
23961
24611
  ["nanochat", "NanoChatModel"],
23962
24612
  ["arcee", "ArceeModel"],
24613
+ ["afmoe", "AfmoeModel"],
23963
24614
  ["lfm2", "Lfm2Model"],
23964
24615
  ["lfm2_moe", "Lfm2MoeModel"],
23965
24616
  ["smollm3", "SmolLM3Model"],
@@ -23967,6 +24618,7 @@ var MODEL_MAPPING_NAMES_DECODER_ONLY = /* @__PURE__ */ new Map([
23967
24618
  ["olmo", "OlmoModel"],
23968
24619
  ["olmo2", "Olmo2Model"],
23969
24620
  ["olmo3", "Olmo3Model"],
24621
+ ["olmo_hybrid", "OlmoHybridModel"],
23970
24622
  ["mobilellm", "MobileLLMModel"],
23971
24623
  ["granite", "GraniteModel"],
23972
24624
  ["granitemoehybrid", "GraniteMoeHybridModel"],
@@ -23980,7 +24632,10 @@ var MODEL_MAPPING_NAMES_DECODER_ONLY = /* @__PURE__ */ new Map([
23980
24632
  ["glm", "GlmModel"],
23981
24633
  ["openelm", "OpenELMModel"],
23982
24634
  ["qwen2", "Qwen2Model"],
24635
+ ["qwen2_moe", "Qwen2MoeModel"],
23983
24636
  ["qwen3", "Qwen3Model"],
24637
+ ["qwen3_moe", "Qwen3MoeModel"],
24638
+ ["qwen3_next", "Qwen3NextModel"],
23984
24639
  ["phi", "PhiModel"],
23985
24640
  ["phi3", "Phi3Model"],
23986
24641
  ["mpt", "MptModel"],
@@ -23988,7 +24643,7 @@ var MODEL_MAPPING_NAMES_DECODER_ONLY = /* @__PURE__ */ new Map([
23988
24643
  ["mistral", "MistralModel"],
23989
24644
  ["ministral", "MinistralModel"],
23990
24645
  ["ministral3", "Ministral3Model"],
23991
- ["ernie4_5", "Ernie4_5_Model"],
24646
+ ["ernie4_5", "Ernie4_5ForCausalLM"],
23992
24647
  ["starcoder2", "Starcoder2Model"],
23993
24648
  ["falcon", "FalconModel"],
23994
24649
  ["falcon_h1", "FalconH1Model"],
@@ -24074,6 +24729,7 @@ var MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = /* @__PURE__ */ new Map([
24074
24729
  ["apertus", "ApertusForCausalLM"],
24075
24730
  ["llama4_text", "Llama4ForCausalLM"],
24076
24731
  ["arcee", "ArceeForCausalLM"],
24732
+ ["afmoe", "AfmoeForCausalLM"],
24077
24733
  ["lfm2", "Lfm2ForCausalLM"],
24078
24734
  ["lfm2_moe", "Lfm2MoeForCausalLM"],
24079
24735
  ["smollm3", "SmolLM3ForCausalLM"],
@@ -24081,6 +24737,7 @@ var MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = /* @__PURE__ */ new Map([
24081
24737
  ["olmo", "OlmoForCausalLM"],
24082
24738
  ["olmo2", "Olmo2ForCausalLM"],
24083
24739
  ["olmo3", "Olmo3ForCausalLM"],
24740
+ ["olmo_hybrid", "OlmoHybridForCausalLM"],
24084
24741
  ["mobilellm", "MobileLLMForCausalLM"],
24085
24742
  ["granite", "GraniteForCausalLM"],
24086
24743
  ["granitemoehybrid", "GraniteMoeHybridForCausalLM"],
@@ -24094,7 +24751,10 @@ var MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = /* @__PURE__ */ new Map([
24094
24751
  ["glm", "GlmForCausalLM"],
24095
24752
  ["openelm", "OpenELMForCausalLM"],
24096
24753
  ["qwen2", "Qwen2ForCausalLM"],
24754
+ ["qwen2_moe", "Qwen2MoeForCausalLM"],
24097
24755
  ["qwen3", "Qwen3ForCausalLM"],
24756
+ ["qwen3_moe", "Qwen3MoeForCausalLM"],
24757
+ ["qwen3_next", "Qwen3NextForCausalLM"],
24098
24758
  ["phi", "PhiForCausalLM"],
24099
24759
  ["phi3", "Phi3ForCausalLM"],
24100
24760
  ["mpt", "MptForCausalLM"],
@@ -24103,7 +24763,7 @@ var MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = /* @__PURE__ */ new Map([
24103
24763
  ["mistral", "MistralForCausalLM"],
24104
24764
  ["ministral", "MinistralForCausalLM"],
24105
24765
  ["ministral3", "Ministral3ForCausalLM"],
24106
- ["ernie4_5", "Ernie4_5_ForCausalLM"],
24766
+ ["ernie4_5", "Ernie4_5ForCausalLM"],
24107
24767
  ["starcoder2", "Starcoder2ForCausalLM"],
24108
24768
  ["falcon", "FalconForCausalLM"],
24109
24769
  ["falcon_h1", "FalconH1ForCausalLM"],
@@ -24164,7 +24824,12 @@ var MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES = /* @__PURE__ */ new Map([
24164
24824
  ["llava_onevision", "LlavaOnevisionForConditionalGeneration"],
24165
24825
  ["moondream1", "Moondream1ForConditionalGeneration"],
24166
24826
  ["florence2", "Florence2ForConditionalGeneration"],
24167
- ["qwen2-vl", "Qwen2VLForConditionalGeneration"],
24827
+ ["qwen2_vl", "Qwen2VLForConditionalGeneration"],
24828
+ ["qwen2_5_vl", "Qwen2_5_VLForConditionalGeneration"],
24829
+ ["qwen3_vl", "Qwen3VLForConditionalGeneration"],
24830
+ ["qwen3_vl_moe", "Qwen3VLMoeForConditionalGeneration"],
24831
+ ["qwen3_5", "Qwen3_5ForConditionalGeneration"],
24832
+ ["qwen3_5_moe", "Qwen3_5MoeForConditionalGeneration"],
24168
24833
  ["idefics3", "Idefics3ForConditionalGeneration"],
24169
24834
  ["smolvlm", "SmolVLMForConditionalGeneration"],
24170
24835
  ["paligemma", "PaliGemmaForConditionalGeneration"],
@@ -24364,17 +25029,18 @@ for (const [name, model, type] of CUSTOM_MAPPING) {
24364
25029
  MODEL_CLASS_TO_NAME_MAPPING.set(model, name);
24365
25030
  MODEL_NAME_TO_CLASS_MAPPING.set(name, model);
24366
25031
  }
24367
- var CUSTOM_ARCHITECTURES = /* @__PURE__ */ new Map([
25032
+ var CUSTOM_ARCHITECTURES_MAPPING = /* @__PURE__ */ new Map([
24368
25033
  ["modnet", MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES],
24369
25034
  ["birefnet", MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES],
24370
25035
  ["isnet", MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES],
24371
25036
  ["ben", MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]
24372
25037
  ]);
24373
- for (const [name, mapping] of CUSTOM_ARCHITECTURES.entries()) {
25038
+ for (const [name, mapping] of CUSTOM_ARCHITECTURES_MAPPING.entries()) {
24374
25039
  mapping.set(name, "PreTrainedModel");
24375
25040
  MODEL_TYPE_MAPPING.set(name, MODEL_TYPES.EncoderOnly);
24376
25041
  MODEL_NAME_TO_CLASS_MAPPING.set(name, PreTrainedModel);
24377
25042
  }
25043
+ var CUSTOM_ARCHITECTURES = new Set(CUSTOM_ARCHITECTURES_MAPPING.keys());
24378
25044
  MODEL_TYPE_MAPPING.set("PreTrainedModel", MODEL_TYPES.EncoderOnly);
24379
25045
  MODEL_CLASS_TO_NAME_MAPPING.set(PreTrainedModel, "PreTrainedModel");
24380
25046
  var MODEL_MAPPINGS = {
@@ -24423,6 +25089,18 @@ var PretrainedMixin = class {
24423
25089
  * the model type is not found in the mapping.
24424
25090
  */
24425
25091
  static BASE_IF_FAIL = false;
25092
+ /**
25093
+ * Check whether this AutoModel class supports a given model type.
25094
+ * @param {string} model_type The model type from config (e.g., 'bert', 'whisper').
25095
+ * @returns {boolean} Whether this class can handle the given model type.
25096
+ */
25097
+ static supports(model_type) {
25098
+ if (!this.MODEL_CLASS_MAPPINGS) return false;
25099
+ for (const mapping of this.MODEL_CLASS_MAPPINGS) {
25100
+ if (mapping.has(model_type)) return true;
25101
+ }
25102
+ return this.BASE_IF_FAIL;
25103
+ }
24426
25104
  /** @type {typeof PreTrainedModel.from_pretrained} */
24427
25105
  static async from_pretrained(pretrained_model_name_or_path, {
24428
25106
  progress_callback = null,
@@ -24454,7 +25132,7 @@ var PretrainedMixin = class {
24454
25132
  if (!this.MODEL_CLASS_MAPPINGS) {
24455
25133
  throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: " + this.name);
24456
25134
  }
24457
- const model_type = options.config.model_type;
25135
+ const { model_type } = options.config;
24458
25136
  for (const MODEL_CLASS_MAPPING of this.MODEL_CLASS_MAPPINGS) {
24459
25137
  let modelInfo = MODEL_CLASS_MAPPING.get(model_type);
24460
25138
  if (!modelInfo) {
@@ -24470,7 +25148,7 @@ var PretrainedMixin = class {
24470
25148
  }
24471
25149
  if (this.BASE_IF_FAIL) {
24472
25150
  if (!CUSTOM_ARCHITECTURES.has(model_type)) {
24473
- console.warn(`Unknown model class "${model_type}", attempting to construct from base class.`);
25151
+ logger.warn(`Unknown model class "${model_type}", attempting to construct from base class.`);
24474
25152
  }
24475
25153
  return await PreTrainedModel.from_pretrained(pretrained_model_name_or_path, options);
24476
25154
  } else {
@@ -24873,6 +25551,10 @@ function isChat(x) {
24873
25551
  }
24874
25552
  var TextGenerationPipeline = class extends /** @type {new (options: TextPipelineConstructorArgs) => TextGenerationPipelineType} */
24875
25553
  Pipeline {
25554
+ /**
25555
+ * @param {string | string[] | import('../tokenization_utils.js').Message[] | import('../tokenization_utils.js').Message[][]} texts
25556
+ * @param {Partial<TextGenerationConfig>} generate_kwargs
25557
+ */
24876
25558
  async _call(texts, generate_kwargs = {}) {
24877
25559
  let isBatched = false;
24878
25560
  let isChatInput = false;
@@ -24968,12 +25650,12 @@ Pipeline {
24968
25650
  );
24969
25651
  this.entailment_id = this.label2id["entailment"];
24970
25652
  if (this.entailment_id === void 0) {
24971
- console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id.");
25653
+ logger.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id.");
24972
25654
  this.entailment_id = 2;
24973
25655
  }
24974
25656
  this.contradiction_id = this.label2id["contradiction"] ?? this.label2id["not_entailment"];
24975
25657
  if (this.contradiction_id === void 0) {
24976
- console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id.");
25658
+ logger.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id.");
24977
25659
  this.contradiction_id = 0;
24978
25660
  }
24979
25661
  }
@@ -25111,10 +25793,10 @@ Pipeline {
25111
25793
  }
25112
25794
  async _call_wav2vec2(audio, kwargs) {
25113
25795
  if (kwargs.language) {
25114
- console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".');
25796
+ logger.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".');
25115
25797
  }
25116
25798
  if (kwargs.task) {
25117
- console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');
25799
+ logger.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');
25118
25800
  }
25119
25801
  const single = !Array.isArray(audio);
25120
25802
  const batchedAudio = single ? [audio] : audio;
@@ -25246,7 +25928,7 @@ Pipeline {
25246
25928
  }
25247
25929
  async _prepare_speaker_embeddings(speaker_embeddings, batch_size) {
25248
25930
  if (typeof speaker_embeddings === "string" || speaker_embeddings instanceof URL) {
25249
- speaker_embeddings = new Float32Array(await (await fetch(speaker_embeddings)).arrayBuffer());
25931
+ speaker_embeddings = new Float32Array(await (await env.fetch(speaker_embeddings)).arrayBuffer());
25250
25932
  }
25251
25933
  if (speaker_embeddings instanceof Float32Array) {
25252
25934
  speaker_embeddings = new Tensor2("float32", speaker_embeddings, [speaker_embeddings.length]);
@@ -25332,7 +26014,7 @@ Pipeline {
25332
26014
  }
25333
26015
  async _call_text_to_spectrogram(text_inputs, { speaker_embeddings }) {
25334
26016
  if (!this.vocoder) {
25335
- console.log("No vocoder specified, using default HifiGan vocoder.");
26017
+ logger.info("No vocoder specified, using default HifiGan vocoder.");
25336
26018
  this.vocoder = await AutoModel.from_pretrained(this.DEFAULT_VOCODER_ID, { dtype: "fp32" });
25337
26019
  }
25338
26020
  const { input_ids } = this.tokenizer(text_inputs, {
@@ -25799,43 +26481,33 @@ Pipeline {
25799
26481
  }
25800
26482
  };
25801
26483
 
25802
- // src/pipelines.js
26484
+ // src/pipelines/index.js
25803
26485
  var SUPPORTED_TASKS = Object.freeze({
25804
26486
  "text-classification": {
25805
- tokenizer: AutoTokenizer,
25806
26487
  pipeline: TextClassificationPipeline,
25807
26488
  model: AutoModelForSequenceClassification,
25808
26489
  default: {
25809
- // TODO: replace with original
25810
- // "model": "distilbert-base-uncased-finetuned-sst-2-english",
25811
26490
  model: "Xenova/distilbert-base-uncased-finetuned-sst-2-english"
25812
26491
  },
25813
26492
  type: "text"
25814
26493
  },
25815
26494
  "token-classification": {
25816
- tokenizer: AutoTokenizer,
25817
26495
  pipeline: TokenClassificationPipeline,
25818
26496
  model: AutoModelForTokenClassification,
25819
26497
  default: {
25820
- // TODO: replace with original
25821
- // "model": "Davlan/bert-base-multilingual-cased-ner-hrl",
25822
26498
  model: "Xenova/bert-base-multilingual-cased-ner-hrl"
25823
26499
  },
25824
26500
  type: "text"
25825
26501
  },
25826
26502
  "question-answering": {
25827
- tokenizer: AutoTokenizer,
25828
26503
  pipeline: QuestionAnsweringPipeline,
25829
26504
  model: AutoModelForQuestionAnswering,
25830
26505
  default: {
25831
- // TODO: replace with original
25832
- // "model": "distilbert-base-cased-distilled-squad",
25833
26506
  model: "Xenova/distilbert-base-cased-distilled-squad"
25834
26507
  },
25835
26508
  type: "text"
25836
26509
  },
25837
26510
  "fill-mask": {
25838
- tokenizer: AutoTokenizer,
25839
26511
  pipeline: FillMaskPipeline,
25840
26512
  model: AutoModelForMaskedLM,
25841
26513
  default: {
@@ -25845,40 +26517,30 @@ var SUPPORTED_TASKS = Object.freeze({
25845
26517
  type: "text"
25846
26518
  },
25847
26519
  summarization: {
25848
- tokenizer: AutoTokenizer,
25849
26520
  pipeline: SummarizationPipeline,
25850
26521
  model: AutoModelForSeq2SeqLM,
25851
26522
  default: {
25852
- // TODO: replace with original
25853
- // "model": "sshleifer/distilbart-cnn-6-6",
25854
26523
  model: "Xenova/distilbart-cnn-6-6"
25855
26524
  },
25856
26525
  type: "text"
25857
26526
  },
25858
26527
  translation: {
25859
- tokenizer: AutoTokenizer,
25860
26528
  pipeline: TranslationPipeline,
25861
26529
  model: AutoModelForSeq2SeqLM,
25862
26530
  default: {
25863
- // TODO: replace with original
25864
- // "model": "t5-small",
25865
26531
  model: "Xenova/t5-small"
25866
26532
  },
25867
26533
  type: "text"
25868
26534
  },
25869
26535
  "text2text-generation": {
25870
- tokenizer: AutoTokenizer,
25871
26536
  pipeline: Text2TextGenerationPipeline,
25872
26537
  model: AutoModelForSeq2SeqLM,
25873
26538
  default: {
25874
- // TODO: replace with original
25875
- // "model": "google/flan-t5-small",
25876
26539
  model: "Xenova/flan-t5-small"
25877
26540
  },
25878
26541
  type: "text"
25879
26542
  },
25880
26543
  "text-generation": {
25881
- tokenizer: AutoTokenizer,
25882
26544
  pipeline: TextGenerationPipeline,
25883
26545
  model: AutoModelForCausalLM,
25884
26546
  default: {
@@ -25888,12 +26550,9 @@ var SUPPORTED_TASKS = Object.freeze({
25888
26550
  type: "text"
25889
26551
  },
25890
26552
  "zero-shot-classification": {
25891
- tokenizer: AutoTokenizer,
25892
26553
  pipeline: ZeroShotClassificationPipeline,
25893
26554
  model: AutoModelForSequenceClassification,
25894
26555
  default: {
25895
- // TODO: replace with original
25896
- // "model": "typeform/distilbert-base-uncased-mnli",
25897
26556
  model: "Xenova/distilbert-base-uncased-mnli"
25898
26557
  },
25899
26558
  type: "text"
@@ -25901,47 +26560,30 @@ var SUPPORTED_TASKS = Object.freeze({
25901
26560
  "audio-classification": {
25902
26561
  pipeline: AudioClassificationPipeline,
25903
26562
  model: AutoModelForAudioClassification,
25904
- processor: AutoProcessor,
25905
26563
  default: {
25906
- // TODO: replace with original
25907
- // "model": "superb/wav2vec2-base-superb-ks",
25908
26564
  model: "Xenova/wav2vec2-base-superb-ks"
25909
26565
  },
25910
26566
  type: "audio"
25911
26567
  },
25912
26568
  "zero-shot-audio-classification": {
25913
- tokenizer: AutoTokenizer,
25914
26569
  pipeline: ZeroShotAudioClassificationPipeline,
25915
26570
  model: AutoModel,
25916
- processor: AutoProcessor,
25917
26571
  default: {
25918
- // TODO: replace with original
25919
- // "model": "laion/clap-htsat-fused",
25920
26572
  model: "Xenova/clap-htsat-unfused"
25921
26573
  },
25922
26574
  type: "multimodal"
25923
26575
  },
25924
26576
  "automatic-speech-recognition": {
25925
- tokenizer: AutoTokenizer,
25926
26577
  pipeline: AutomaticSpeechRecognitionPipeline,
25927
26578
  model: [AutoModelForSpeechSeq2Seq, AutoModelForCTC],
25928
- processor: AutoProcessor,
25929
26579
  default: {
25930
- // TODO: replace with original
25931
- // "model": "openai/whisper-tiny.en",
25932
26580
  model: "Xenova/whisper-tiny.en"
25933
26581
  },
25934
26582
  type: "multimodal"
25935
26583
  },
25936
26584
  "text-to-audio": {
25937
- tokenizer: AutoTokenizer,
25938
26585
  pipeline: TextToAudioPipeline,
25939
26586
  model: [AutoModelForTextToWaveform, AutoModelForTextToSpectrogram],
25940
- processor: [
25941
- AutoProcessor,
25942
- /* Some don't use a processor */
25943
- null
25944
- ],
25945
26587
  default: {
25946
26588
  model: "onnx-community/Supertonic-TTS-ONNX",
25947
26589
  dtype: "fp32"
@@ -25949,124 +26591,86 @@ var SUPPORTED_TASKS = Object.freeze({
25949
26591
  type: "text"
25950
26592
  },
25951
26593
  "image-to-text": {
25952
- tokenizer: AutoTokenizer,
25953
26594
  pipeline: ImageToTextPipeline,
25954
26595
  model: AutoModelForVision2Seq,
25955
- processor: AutoProcessor,
25956
26596
  default: {
25957
- // TODO: replace with original
25958
- // "model": "nlpconnect/vit-gpt2-image-captioning",
25959
26597
  model: "Xenova/vit-gpt2-image-captioning"
25960
26598
  },
25961
26599
  type: "multimodal"
25962
26600
  },
25963
26601
  "image-classification": {
25964
- // no tokenizer
25965
26602
  pipeline: ImageClassificationPipeline,
25966
26603
  model: AutoModelForImageClassification,
25967
- processor: AutoProcessor,
25968
26604
  default: {
25969
- // TODO: replace with original
25970
- // "model": "google/vit-base-patch16-224",
25971
26605
  model: "Xenova/vit-base-patch16-224"
25972
26606
  },
25973
26607
  type: "multimodal"
25974
26608
  },
25975
26609
  "image-segmentation": {
25976
- // no tokenizer
25977
26610
  pipeline: ImageSegmentationPipeline,
25978
26611
  model: [AutoModelForImageSegmentation, AutoModelForSemanticSegmentation, AutoModelForUniversalSegmentation],
25979
- processor: AutoProcessor,
25980
26612
  default: {
25981
- // TODO: replace with original
25982
- // "model": "facebook/detr-resnet-50-panoptic",
25983
26613
  model: "Xenova/detr-resnet-50-panoptic"
25984
26614
  },
25985
26615
  type: "multimodal"
25986
26616
  },
25987
26617
  "background-removal": {
25988
- // no tokenizer
25989
26618
  pipeline: BackgroundRemovalPipeline,
25990
26619
  model: [AutoModelForImageSegmentation, AutoModelForSemanticSegmentation, AutoModelForUniversalSegmentation],
25991
- processor: AutoProcessor,
25992
26620
  default: {
25993
26621
  model: "Xenova/modnet"
25994
26622
  },
25995
26623
  type: "image"
25996
26624
  },
25997
26625
  "zero-shot-image-classification": {
25998
- tokenizer: AutoTokenizer,
25999
26626
  pipeline: ZeroShotImageClassificationPipeline,
26000
26627
  model: AutoModel,
26001
- processor: AutoProcessor,
26002
26628
  default: {
26003
- // TODO: replace with original
26004
- // "model": "openai/clip-vit-base-patch32",
26005
26629
  model: "Xenova/clip-vit-base-patch32"
26006
26630
  },
26007
26631
  type: "multimodal"
26008
26632
  },
26009
26633
  "object-detection": {
26010
- // no tokenizer
26011
26634
  pipeline: ObjectDetectionPipeline,
26012
26635
  model: AutoModelForObjectDetection,
26013
- processor: AutoProcessor,
26014
26636
  default: {
26015
- // TODO: replace with original
26016
- // "model": "facebook/detr-resnet-50",
26017
26637
  model: "Xenova/detr-resnet-50"
26018
26638
  },
26019
26639
  type: "multimodal"
26020
26640
  },
26021
26641
  "zero-shot-object-detection": {
26022
- tokenizer: AutoTokenizer,
26023
26642
  pipeline: ZeroShotObjectDetectionPipeline,
26024
26643
  model: AutoModelForZeroShotObjectDetection,
26025
- processor: AutoProcessor,
26026
26644
  default: {
26027
- // TODO: replace with original
26028
- // "model": "google/owlvit-base-patch32",
26029
26645
  model: "Xenova/owlvit-base-patch32"
26030
26646
  },
26031
26647
  type: "multimodal"
26032
26648
  },
26033
26649
  "document-question-answering": {
26034
- tokenizer: AutoTokenizer,
26035
26650
  pipeline: DocumentQuestionAnsweringPipeline,
26036
26651
  model: AutoModelForDocumentQuestionAnswering,
26037
- processor: AutoProcessor,
26038
26652
  default: {
26039
- // TODO: replace with original
26040
- // "model": "naver-clova-ix/donut-base-finetuned-docvqa",
26041
26653
  model: "Xenova/donut-base-finetuned-docvqa"
26042
26654
  },
26043
26655
  type: "multimodal"
26044
26656
  },
26045
26657
  "image-to-image": {
26046
- // no tokenizer
26047
26658
  pipeline: ImageToImagePipeline,
26048
26659
  model: AutoModelForImageToImage,
26049
- processor: AutoProcessor,
26050
26660
  default: {
26051
- // TODO: replace with original
26052
- // "model": "caidas/swin2SR-classical-sr-x2-64",
26053
26661
  model: "Xenova/swin2SR-classical-sr-x2-64"
26054
26662
  },
26055
26663
  type: "image"
26056
26664
  },
26057
26665
  "depth-estimation": {
26058
- // no tokenizer
26059
26666
  pipeline: DepthEstimationPipeline,
26060
26667
  model: AutoModelForDepthEstimation,
26061
- processor: AutoProcessor,
26062
26668
  default: {
26063
26669
  model: "onnx-community/depth-anything-v2-small"
26064
26670
  },
26065
26671
  type: "image"
26066
26672
  },
26067
- // This task serves as a useful interface for dealing with sentence-transformers (https://huggingface.co/sentence-transformers).
26068
26673
  "feature-extraction": {
26069
- tokenizer: AutoTokenizer,
26070
26674
  pipeline: FeatureExtractionPipeline,
26071
26675
  model: AutoModel,
26072
26676
  default: {
@@ -26076,7 +26680,6 @@ var SUPPORTED_TASKS = Object.freeze({
26076
26680
  type: "text"
26077
26681
  },
26078
26682
  "image-feature-extraction": {
26079
- processor: AutoProcessor,
26080
26683
  pipeline: ImageFeatureExtractionPipeline,
26081
26684
  model: [AutoModelForImageFeatureExtraction, AutoModel],
26082
26685
  default: {
@@ -26095,7 +26698,193 @@ var TASK_ALIASES = Object.freeze({
26095
26698
  // Add for backwards compatibility
26096
26699
  embeddings: "feature-extraction"
26097
26700
  });
26098
- async function pipeline3(task, model = null, {
26701
+
26702
+ // src/utils/model_registry/get_model_files.js
26703
+ async function get_model_files(modelId, { config = null, dtype: overrideDtype = null, device: overrideDevice = null, model_file_name = null } = {}) {
26704
+ config = await AutoConfig.from_pretrained(modelId, { config });
26705
+ const files = [
26706
+ // Add config.json (always loaded)
26707
+ "config.json"
26708
+ ];
26709
+ const custom_config = config["transformers.js_config"] ?? {};
26710
+ const use_external_data_format = custom_config.use_external_data_format;
26711
+ const subfolder = "onnx";
26712
+ const rawDevice = overrideDevice ?? custom_config.device;
26713
+ let dtype = overrideDtype ?? custom_config.dtype;
26714
+ let modelType;
26715
+ const architectures = (
26716
+ /** @type {string[]} */
26717
+ config.architectures || []
26718
+ );
26719
+ let foundInMapping = false;
26720
+ for (const arch of architectures) {
26721
+ const mappedType = MODEL_TYPE_MAPPING.get(arch);
26722
+ if (mappedType !== void 0) {
26723
+ modelType = mappedType;
26724
+ foundInMapping = true;
26725
+ break;
26726
+ }
26727
+ }
26728
+ if (!foundInMapping && config.model_type) {
26729
+ const mappedType = MODEL_TYPE_MAPPING.get(config.model_type);
26730
+ if (mappedType !== void 0) {
26731
+ modelType = mappedType;
26732
+ foundInMapping = true;
26733
+ }
26734
+ if (!foundInMapping) {
26735
+ for (const mapping of Object.values(MODEL_MAPPING_NAMES)) {
26736
+ if (mapping.has(config.model_type)) {
26737
+ modelType = MODEL_TYPE_MAPPING.get(mapping.get(config.model_type));
26738
+ foundInMapping = true;
26739
+ break;
26740
+ }
26741
+ }
26742
+ }
26743
+ }
26744
+ if (!foundInMapping) {
26745
+ const archList = architectures.length > 0 ? architectures.join(", ") : "(none)";
26746
+ logger.warn(
26747
+ `[get_model_files] Architecture(s) not found in MODEL_TYPE_MAPPING: [${archList}] for model type '${config.model_type}'. Falling back to EncoderOnly (single model.onnx file). If you encounter issues, please report at: ${GITHUB_ISSUE_URL}`
26748
+ );
26749
+ modelType = MODEL_TYPES.EncoderOnly;
26750
+ }
26751
+ const add_model_file = (fileName, baseName = null) => {
26752
+ baseName = baseName ?? fileName;
26753
+ const selectedDevice = selectDevice(rawDevice, fileName);
26754
+ const selectedDtype = selectDtype(dtype, fileName, selectedDevice);
26755
+ const suffix = DEFAULT_DTYPE_SUFFIX_MAPPING[selectedDtype] ?? "";
26756
+ const fullName = `${baseName}${suffix}.onnx`;
26757
+ const fullPath = subfolder ? `${subfolder}/${fullName}` : fullName;
26758
+ files.push(fullPath);
26759
+ const num_chunks = resolveExternalDataFormat(use_external_data_format, fullName, fileName);
26760
+ for (const dataFileName of getExternalDataChunkNames(fullName, num_chunks)) {
26761
+ const dataFilePath = subfolder ? `${subfolder}/${dataFileName}` : dataFileName;
26762
+ files.push(dataFilePath);
26763
+ }
26764
+ };
26765
+ const singleModelName = model_file_name ?? "model";
26766
+ if (modelType === MODEL_TYPES.DecoderOnly) {
26767
+ add_model_file("model", singleModelName);
26768
+ files.push("generation_config.json");
26769
+ } else if (modelType === MODEL_TYPES.DecoderOnlyWithoutHead) {
26770
+ add_model_file("model", singleModelName);
26771
+ } else if (modelType === MODEL_TYPES.Seq2Seq || modelType === MODEL_TYPES.Vision2Seq) {
26772
+ add_model_file("model", "encoder_model");
26773
+ add_model_file("decoder_model_merged");
26774
+ files.push("generation_config.json");
26775
+ } else if (modelType === MODEL_TYPES.MaskGeneration) {
26776
+ add_model_file("model", "vision_encoder");
26777
+ add_model_file("prompt_encoder_mask_decoder");
26778
+ } else if (modelType === MODEL_TYPES.EncoderDecoder) {
26779
+ add_model_file("model", "encoder_model");
26780
+ add_model_file("decoder_model_merged");
26781
+ } else if (modelType === MODEL_TYPES.ImageTextToText) {
26782
+ add_model_file("embed_tokens");
26783
+ add_model_file("vision_encoder");
26784
+ add_model_file("decoder_model_merged");
26785
+ if (config.is_encoder_decoder) {
26786
+ add_model_file("model", "encoder_model");
26787
+ }
26788
+ files.push("generation_config.json");
26789
+ } else if (modelType === MODEL_TYPES.AudioTextToText) {
26790
+ add_model_file("embed_tokens");
26791
+ add_model_file("audio_encoder");
26792
+ add_model_file("decoder_model_merged");
26793
+ files.push("generation_config.json");
26794
+ } else if (modelType === MODEL_TYPES.ImageAudioTextToText) {
26795
+ add_model_file("embed_tokens");
26796
+ add_model_file("audio_encoder");
26797
+ add_model_file("vision_encoder");
26798
+ add_model_file("decoder_model_merged");
26799
+ files.push("generation_config.json");
26800
+ } else if (modelType === MODEL_TYPES.Musicgen) {
26801
+ add_model_file("model", "text_encoder");
26802
+ add_model_file("decoder_model_merged");
26803
+ add_model_file("encodec_decode");
26804
+ files.push("generation_config.json");
26805
+ } else if (modelType === MODEL_TYPES.MultiModality) {
26806
+ add_model_file("prepare_inputs_embeds");
26807
+ add_model_file("model", "language_model");
26808
+ add_model_file("lm_head");
26809
+ add_model_file("gen_head");
26810
+ add_model_file("gen_img_embeds");
26811
+ add_model_file("image_decode");
26812
+ files.push("generation_config.json");
26813
+ } else if (modelType === MODEL_TYPES.Phi3V) {
26814
+ add_model_file("prepare_inputs_embeds");
26815
+ add_model_file("model");
26816
+ add_model_file("vision_encoder");
26817
+ files.push("generation_config.json");
26818
+ } else if (modelType === MODEL_TYPES.Chatterbox) {
26819
+ add_model_file("embed_tokens");
26820
+ add_model_file("speech_encoder");
26821
+ add_model_file("model", "language_model");
26822
+ add_model_file("conditional_decoder");
26823
+ files.push("generation_config.json");
26824
+ } else if (modelType === MODEL_TYPES.AutoEncoder) {
26825
+ add_model_file("encoder_model");
26826
+ add_model_file("decoder_model");
26827
+ } else if (modelType === MODEL_TYPES.Supertonic) {
26828
+ add_model_file("text_encoder");
26829
+ add_model_file("latent_denoiser");
26830
+ add_model_file("voice_decoder");
26831
+ } else {
26832
+ add_model_file("model", singleModelName);
26833
+ }
26834
+ return files;
26835
+ }
26836
+
26837
+ // src/utils/model_registry/get_processor_files.js
26838
+ async function get_processor_files(modelId) {
26839
+ if (!modelId) {
26840
+ throw new Error("modelId is required");
26841
+ }
26842
+ const metadata = await get_file_metadata(modelId, IMAGE_PROCESSOR_NAME, {});
26843
+ return metadata.exists ? [IMAGE_PROCESSOR_NAME] : [];
26844
+ }
26845
+
26846
+ // src/utils/model_registry/get_files.js
26847
+ async function get_files(modelId, {
26848
+ config = null,
26849
+ dtype = null,
26850
+ device = null,
26851
+ model_file_name = null,
26852
+ include_tokenizer = true,
26853
+ include_processor = true
26854
+ } = {}) {
26855
+ const files = await get_model_files(modelId, { config, dtype, device, model_file_name });
26856
+ if (include_tokenizer) {
26857
+ const tokenizerFiles = await get_tokenizer_files(modelId);
26858
+ files.push(...tokenizerFiles);
26859
+ }
26860
+ if (include_processor) {
26861
+ const processorFiles = await get_processor_files(modelId);
26862
+ files.push(...processorFiles);
26863
+ }
26864
+ return files;
26865
+ }
26866
+
26867
+ // src/utils/model_registry/get_pipeline_files.js
26868
+ async function get_pipeline_files(task, modelId, options = {}) {
26869
+ task = TASK_ALIASES[task] ?? task;
26870
+ const taskConfig = SUPPORTED_TASKS[task];
26871
+ if (!taskConfig) {
26872
+ throw new Error(
26873
+ `Unsupported pipeline task: ${task}. Must be one of [${Object.keys(SUPPORTED_TASKS).join(", ")}]`
26874
+ );
26875
+ }
26876
+ const { type } = taskConfig;
26877
+ const include_tokenizer = type !== "audio" && type !== "image";
26878
+ const include_processor = type !== "text";
26879
+ return get_files(modelId, {
26880
+ ...options,
26881
+ include_tokenizer,
26882
+ include_processor
26883
+ });
26884
+ }
26885
+
26886
+ // src/pipelines.js
26887
+ async function pipeline2(task, model = null, {
26099
26888
  progress_callback = null,
26100
26889
  config = null,
26101
26890
  cache_dir = null,
@@ -26115,13 +26904,51 @@ async function pipeline3(task, model = null, {
26115
26904
  }
26116
26905
  if (!model) {
26117
26906
  model = pipelineInfo.default.model;
26118
- console.log(`No model specified. Using default model: "${model}".`);
26907
+ logger.info(`No model specified. Using default model: "${model}".`);
26119
26908
  if (!dtype && pipelineInfo.default.dtype) {
26120
26909
  dtype = pipelineInfo.default.dtype;
26121
26910
  }
26122
26911
  }
26912
+ const expected_files = await get_pipeline_files(task, model, {
26913
+ device,
26914
+ dtype
26915
+ });
26916
+ let files_loading = {};
26917
+ if (progress_callback) {
26918
+ const metadata = await Promise.all(expected_files.map(async (file) => get_file_metadata(model, file)));
26919
+ metadata.forEach((m, i) => {
26920
+ if (m.exists) {
26921
+ files_loading[expected_files[i]] = {
26922
+ loaded: 0,
26923
+ total: m.size ?? 0
26924
+ };
26925
+ }
26926
+ });
26927
+ }
26123
26928
  const pretrainedOptions = {
26124
- progress_callback,
26929
+ progress_callback: progress_callback ? (
26930
+ /** @param {import('./utils/core.js').ProgressInfo} info */
26931
+ (info) => {
26932
+ if (info.status === "progress") {
26933
+ files_loading[info.file] = {
26934
+ loaded: info.loaded,
26935
+ total: info.total
26936
+ };
26937
+ const loaded = Object.values(files_loading).reduce((acc, curr) => acc + curr.loaded, 0);
26938
+ const total = Object.values(files_loading).reduce((acc, curr) => acc + curr.total, 0);
26939
+ const progress = total > 0 ? loaded / total * 100 : 0;
26940
+ progress_callback({
26941
+ status: "progress_total",
26942
+ name: info.name,
26943
+ progress,
26944
+ loaded,
26945
+ total,
26946
+ files: structuredClone(files_loading)
26947
+ });
26948
+ }
26949
+ progress_callback(info);
26950
+ }
26951
+ ) : void 0,
26125
26952
  config,
26126
26953
  cache_dir,
26127
26954
  local_files_only,
@@ -26133,13 +26960,31 @@ async function pipeline3(task, model = null, {
26133
26960
  model_file_name,
26134
26961
  session_options
26135
26962
  };
26136
- const classes = /* @__PURE__ */ new Map([
26137
- ["tokenizer", pipelineInfo.tokenizer],
26138
- ["model", pipelineInfo.model],
26139
- ["processor", pipelineInfo.processor]
26963
+ const hasTokenizer = expected_files.includes("tokenizer.json");
26964
+ const hasProcessor = expected_files.includes("preprocessor_config.json");
26965
+ const modelClasses = pipelineInfo.model;
26966
+ let modelPromise;
26967
+ if (Array.isArray(modelClasses)) {
26968
+ const resolvedConfig = config ?? await AutoConfig.from_pretrained(model, pretrainedOptions);
26969
+ const { model_type } = resolvedConfig;
26970
+ const matchedClass = modelClasses.find((cls) => cls.supports(model_type));
26971
+ if (!matchedClass) {
26972
+ throw Error(
26973
+ `Unsupported model type "${model_type}" for task "${task}". None of the candidate model classes support this type.`
26974
+ );
26975
+ }
26976
+ modelPromise = matchedClass.from_pretrained(model, { ...pretrainedOptions, config: resolvedConfig });
26977
+ } else {
26978
+ modelPromise = modelClasses.from_pretrained(model, pretrainedOptions);
26979
+ }
26980
+ const [tokenizer, processor, model_loaded] = await Promise.all([
26981
+ hasTokenizer ? AutoTokenizer.from_pretrained(model, pretrainedOptions) : null,
26982
+ hasProcessor ? AutoProcessor.from_pretrained(model, pretrainedOptions) : null,
26983
+ modelPromise
26140
26984
  ]);
26141
- const results = await loadItems(classes, model, pretrainedOptions);
26142
- results.task = task;
26985
+ const results = { task, model: model_loaded };
26986
+ if (tokenizer) results.tokenizer = tokenizer;
26987
+ if (processor) results.processor = processor;
26143
26988
  dispatchCallback(progress_callback, {
26144
26989
  status: "ready",
26145
26990
  task,
@@ -26148,48 +26993,6 @@ async function pipeline3(task, model = null, {
26148
26993
  const pipelineClass = pipelineInfo.pipeline;
26149
26994
  return new pipelineClass(results);
26150
26995
  }
26151
- async function loadItems(mapping, model, pretrainedOptions) {
26152
- const result = /* @__PURE__ */ Object.create(null);
26153
- const promises = [];
26154
- for (const [name, cls] of mapping.entries()) {
26155
- if (!cls) continue;
26156
- let promise;
26157
- if (Array.isArray(cls)) {
26158
- promise = new Promise(async (resolve, reject) => {
26159
- let e;
26160
- for (const c of cls) {
26161
- if (c === null) {
26162
- resolve(null);
26163
- return;
26164
- }
26165
- try {
26166
- resolve(await c.from_pretrained(model, pretrainedOptions));
26167
- return;
26168
- } catch (err) {
26169
- if (err.message?.includes("Unsupported model type")) {
26170
- e = err;
26171
- } else if (err.message?.includes("Could not locate file")) {
26172
- e = err;
26173
- } else {
26174
- reject(err);
26175
- return;
26176
- }
26177
- }
26178
- }
26179
- reject(e);
26180
- });
26181
- } else {
26182
- promise = cls.from_pretrained(model, pretrainedOptions);
26183
- }
26184
- result[name] = promise;
26185
- promises.push(promise);
26186
- }
26187
- await Promise.all(promises);
26188
- for (const [name, promise] of Object.entries(result)) {
26189
- result[name] = await promise;
26190
- }
26191
- return result;
26192
- }
26193
26996
 
26194
26997
  // src/generation/streamers.js
26195
26998
  var is_chinese_char2 = (cp) => cp >= 19968 && cp <= 40959 || cp >= 13312 && cp <= 19903 || cp >= 131072 && cp <= 173791 || cp >= 173824 && cp <= 177983 || cp >= 177984 && cp <= 178207 || cp >= 178208 && cp <= 183983 || cp >= 63744 && cp <= 64255 || cp >= 194560 && cp <= 195103;
@@ -26438,7 +27241,7 @@ async function load_video(src, { num_frames = null, fps = null } = {}) {
26438
27241
  }
26439
27242
  await new Promise((resolve) => video.onloadedmetadata = resolve);
26440
27243
  if (video.seekable.start(0) === video.seekable.end(0)) {
26441
- const response = await fetch(video.src);
27244
+ const response = await env.fetch(video.src);
26442
27245
  const blob = await response.blob();
26443
27246
  video.src = URL.createObjectURL(blob);
26444
27247
  await new Promise((resolve) => video.onloadedmetadata = resolve);
@@ -26474,11 +27277,362 @@ async function load_video(src, { num_frames = null, fps = null } = {}) {
26474
27277
  video.remove();
26475
27278
  return new RawVideo(frames, duration);
26476
27279
  }
27280
+
27281
+ // src/utils/model_registry/is_cached.js
27282
+ async function check_files_cache(modelId, files, options = {}) {
27283
+ const cache = await getCache(options?.cache_dir);
27284
+ if (!cache) {
27285
+ const fileStatuses2 = files.map((filename) => ({ file: filename, cached: false }));
27286
+ return { allCached: false, files: fileStatuses2 };
27287
+ }
27288
+ const fileStatuses = await Promise.all(
27289
+ files.map(async (filename) => {
27290
+ const { localPath, proposedCacheKey } = buildResourcePaths(modelId, filename, options, cache);
27291
+ const cached = await checkCachedResource(cache, localPath, proposedCacheKey);
27292
+ return { file: filename, cached: !!cached };
27293
+ })
27294
+ );
27295
+ return { allCached: fileStatuses.every((f) => f.cached), files: fileStatuses };
27296
+ }
27297
+ async function is_file_cached(modelId, filename, options = {}) {
27298
+ const cache = await getCache(options?.cache_dir);
27299
+ if (!cache) return false;
27300
+ const { localPath, proposedCacheKey } = buildResourcePaths(modelId, filename, options, cache);
27301
+ return !!await checkCachedResource(cache, localPath, proposedCacheKey);
27302
+ }
27303
+ async function is_cached(modelId, options = {}) {
27304
+ if (!modelId) {
27305
+ throw new Error("modelId is required");
27306
+ }
27307
+ if (!await is_file_cached(modelId, "config.json", options)) {
27308
+ return false;
27309
+ }
27310
+ const files = await get_files(modelId, options);
27311
+ const result = await check_files_cache(modelId, files, options);
27312
+ return result.allCached;
27313
+ }
27314
+ async function is_cached_files(modelId, options = {}) {
27315
+ if (!modelId) {
27316
+ throw new Error("modelId is required");
27317
+ }
27318
+ const files = await get_files(modelId, options);
27319
+ return await check_files_cache(modelId, files, options);
27320
+ }
27321
+ async function is_pipeline_cached(task, modelId, options = {}) {
27322
+ if (!task) {
27323
+ throw new Error("task is required");
27324
+ }
27325
+ if (!modelId) {
27326
+ throw new Error("modelId is required");
27327
+ }
27328
+ if (!await is_file_cached(modelId, "config.json", options)) {
27329
+ return false;
27330
+ }
27331
+ const files = await get_pipeline_files(task, modelId, options);
27332
+ const result = await check_files_cache(modelId, files, options);
27333
+ return result.allCached;
27334
+ }
27335
+ async function is_pipeline_cached_files(task, modelId, options = {}) {
27336
+ if (!task) {
27337
+ throw new Error("task is required");
27338
+ }
27339
+ if (!modelId) {
27340
+ throw new Error("modelId is required");
27341
+ }
27342
+ const files = await get_pipeline_files(task, modelId, options);
27343
+ return await check_files_cache(modelId, files, options);
27344
+ }
27345
+
27346
+ // src/utils/model_registry/clear_cache.js
27347
+ async function clear_files_from_cache(modelId, files, options = {}) {
27348
+ const cache = await getCache(options?.cache_dir);
27349
+ if (!cache) {
27350
+ return {
27351
+ filesDeleted: 0,
27352
+ filesCached: 0,
27353
+ files: files.map((filename) => ({ file: filename, deleted: false, wasCached: false }))
27354
+ };
27355
+ }
27356
+ if (!cache.delete) {
27357
+ throw new Error("Cache does not support delete operation");
27358
+ }
27359
+ const results = await Promise.all(
27360
+ files.map(async (filename) => {
27361
+ const { localPath, proposedCacheKey } = buildResourcePaths(modelId, filename, options, cache);
27362
+ const cached = await checkCachedResource(cache, localPath, proposedCacheKey);
27363
+ const wasCached = !!cached;
27364
+ let deleted = false;
27365
+ if (wasCached) {
27366
+ const deletedWithProposed = await cache.delete(proposedCacheKey);
27367
+ const deletedWithLocal = !deletedWithProposed && proposedCacheKey !== localPath ? await cache.delete(localPath) : false;
27368
+ deleted = deletedWithProposed || deletedWithLocal;
27369
+ }
27370
+ return { file: filename, deleted, wasCached };
27371
+ })
27372
+ );
27373
+ return {
27374
+ filesDeleted: results.filter((r) => r.deleted).length,
27375
+ filesCached: results.filter((r) => r.wasCached).length,
27376
+ files: results
27377
+ };
27378
+ }
27379
+ async function clear_cache(modelId, options = {}) {
27380
+ if (!modelId) {
27381
+ throw new Error("modelId is required");
27382
+ }
27383
+ const files = await get_files(modelId, options);
27384
+ return await clear_files_from_cache(modelId, files, options);
27385
+ }
27386
+ async function clear_pipeline_cache(task, modelId, options = {}) {
27387
+ if (!task) {
27388
+ throw new Error("task is required");
27389
+ }
27390
+ if (!modelId) {
27391
+ throw new Error("modelId is required");
27392
+ }
27393
+ const files = await get_pipeline_files(task, modelId, options);
27394
+ return await clear_files_from_cache(modelId, files, options);
27395
+ }
27396
+
27397
+ // src/utils/model_registry/ModelRegistry.js
27398
+ var ModelRegistry = class {
27399
+ /**
27400
+ * Get all files (model, tokenizer, processor) needed for a model.
27401
+ *
27402
+ * @param {string} modelId - The model id (e.g., "onnx-community/bert-base-uncased-ONNX")
27403
+ * @param {Object} [options] - Optional parameters
27404
+ * @param {import('../../configs.js').PretrainedConfig} [options.config=null] - Pre-loaded config
27405
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
27406
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
27407
+ * @param {string} [options.model_file_name=null] - Override the model file name (excluding .onnx suffix)
27408
+ * @param {boolean} [options.include_tokenizer=true] - Whether to check for tokenizer files
27409
+ * @param {boolean} [options.include_processor=true] - Whether to check for processor files
27410
+ * @returns {Promise<string[]>} Array of file paths
27411
+ *
27412
+ * @example
27413
+ * const files = await ModelRegistry.get_files('onnx-community/gpt2-ONNX');
27414
+ * console.log(files); // ['config.json', 'tokenizer.json', 'onnx/model_q4.onnx', ...]
27415
+ */
27416
+ static async get_files(modelId, options = {}) {
27417
+ return get_files(modelId, options);
27418
+ }
27419
+ /**
27420
+ * Get all files needed for a specific pipeline task.
27421
+ * Automatically determines which components are needed based on the task.
27422
+ *
27423
+ * @param {string} task - The pipeline task (e.g., "text-generation", "background-removal")
27424
+ * @param {string} modelId - The model id (e.g., "onnx-community/bert-base-uncased-ONNX")
27425
+ * @param {Object} [options] - Optional parameters
27426
+ * @param {import('../../configs.js').PretrainedConfig} [options.config=null] - Pre-loaded config
27427
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
27428
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
27429
+ * @param {string} [options.model_file_name=null] - Override the model file name (excluding .onnx suffix)
27430
+ * @returns {Promise<string[]>} Array of file paths
27431
+ *
27432
+ * @example
27433
+ * const files = await ModelRegistry.get_pipeline_files('text-generation', 'onnx-community/gpt2-ONNX');
27434
+ * console.log(files); // ['config.json', 'tokenizer.json', 'onnx/model_q4.onnx', ...]
27435
+ */
27436
+ static async get_pipeline_files(task, modelId, options = {}) {
27437
+ return get_pipeline_files(task, modelId, options);
27438
+ }
27439
+ /**
27440
+ * Get model files needed for a specific model.
27441
+ *
27442
+ * @param {string} modelId - The model id
27443
+ * @param {Object} [options] - Optional parameters
27444
+ * @param {import('../../configs.js').PretrainedConfig} [options.config=null] - Pre-loaded config
27445
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
27446
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
27447
+ * @param {string} [options.model_file_name=null] - Override the model file name (excluding .onnx suffix)
27448
+ * @returns {Promise<string[]>} Array of model file paths
27449
+ *
27450
+ * @example
27451
+ * const files = await ModelRegistry.get_model_files('onnx-community/bert-base-uncased-ONNX');
27452
+ * console.log(files); // ['config.json', 'onnx/model_q4.onnx', 'generation_config.json']
27453
+ */
27454
+ static async get_model_files(modelId, options = {}) {
27455
+ return get_model_files(modelId, options);
27456
+ }
27457
+ /**
27458
+ * Get tokenizer files needed for a specific model.
27459
+ *
27460
+ * @param {string} modelId - The model id
27461
+ * @returns {Promise<string[]>} Array of tokenizer file paths
27462
+ *
27463
+ * @example
27464
+ * const files = await ModelRegistry.get_tokenizer_files('onnx-community/gpt2-ONNX');
27465
+ * console.log(files); // ['tokenizer.json', 'tokenizer_config.json']
27466
+ */
27467
+ static async get_tokenizer_files(modelId) {
27468
+ return get_tokenizer_files(modelId);
27469
+ }
27470
+ /**
27471
+ * Get processor files needed for a specific model.
27472
+ *
27473
+ * @param {string} modelId - The model id
27474
+ * @returns {Promise<string[]>} Array of processor file paths
27475
+ *
27476
+ * @example
27477
+ * const files = await ModelRegistry.get_processor_files('onnx-community/vit-base-patch16-224-ONNX');
27478
+ * console.log(files); // ['preprocessor_config.json']
27479
+ */
27480
+ static async get_processor_files(modelId) {
27481
+ return get_processor_files(modelId);
27482
+ }
27483
+ /**
27484
+ * Quickly checks if a model is fully cached by verifying `config.json` is present,
27485
+ * then confirming all required files are cached.
27486
+ * Returns a plain boolean — use `is_cached_files` if you need per-file detail.
27487
+ *
27488
+ * @param {string} modelId - The model id
27489
+ * @param {Object} [options] - Optional parameters
27490
+ * @param {string} [options.cache_dir] - Custom cache directory
27491
+ * @param {string} [options.revision] - Model revision (default: 'main')
27492
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
27493
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
27494
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
27495
+ * @returns {Promise<boolean>} Whether all required files are cached
27496
+ *
27497
+ * @example
27498
+ * const cached = await ModelRegistry.is_cached('onnx-community/bert-base-uncased-ONNX');
27499
+ * console.log(cached); // true or false
27500
+ */
27501
+ static async is_cached(modelId, options = {}) {
27502
+ return is_cached(modelId, options);
27503
+ }
27504
+ /**
27505
+ * Checks if all files for a given model are already cached, with per-file detail.
27506
+ * Automatically determines which files are needed using get_files().
27507
+ *
27508
+ * @param {string} modelId - The model id
27509
+ * @param {Object} [options] - Optional parameters
27510
+ * @param {string} [options.cache_dir] - Custom cache directory
27511
+ * @param {string} [options.revision] - Model revision (default: 'main')
27512
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
27513
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
27514
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
27515
+ * @returns {Promise<import('./is_cached.js').CacheCheckResult>} Object with allCached boolean and files array with cache status
27516
+ *
27517
+ * @example
27518
+ * const status = await ModelRegistry.is_cached_files('onnx-community/bert-base-uncased-ONNX');
27519
+ * console.log(status.allCached); // true or false
27520
+ * console.log(status.files); // [{ file: 'config.json', cached: true }, ...]
27521
+ */
27522
+ static async is_cached_files(modelId, options = {}) {
27523
+ return is_cached_files(modelId, options);
27524
+ }
27525
+ /**
27526
+ * Quickly checks if all files for a specific pipeline task are cached by verifying
27527
+ * `config.json` is present, then confirming all required files are cached.
27528
+ * Returns a plain boolean — use `is_pipeline_cached_files` if you need per-file detail.
27529
+ *
27530
+ * @param {string} task - The pipeline task (e.g., "text-generation", "background-removal")
27531
+ * @param {string} modelId - The model id
27532
+ * @param {Object} [options] - Optional parameters
27533
+ * @param {string} [options.cache_dir] - Custom cache directory
27534
+ * @param {string} [options.revision] - Model revision (default: 'main')
27535
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
27536
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
27537
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
27538
+ * @returns {Promise<boolean>} Whether all required files are cached
27539
+ *
27540
+ * @example
27541
+ * const cached = await ModelRegistry.is_pipeline_cached('text-generation', 'onnx-community/gpt2-ONNX');
27542
+ * console.log(cached); // true or false
27543
+ */
27544
+ static async is_pipeline_cached(task, modelId, options = {}) {
27545
+ return is_pipeline_cached(task, modelId, options);
27546
+ }
27547
+ /**
27548
+ * Checks if all files for a specific pipeline task are already cached, with per-file detail.
27549
+ * Automatically determines which components are needed based on the task.
27550
+ *
27551
+ * @param {string} task - The pipeline task (e.g., "text-generation", "background-removal")
27552
+ * @param {string} modelId - The model id
27553
+ * @param {Object} [options] - Optional parameters
27554
+ * @param {string} [options.cache_dir] - Custom cache directory
27555
+ * @param {string} [options.revision] - Model revision (default: 'main')
27556
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
27557
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
27558
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
27559
+ * @returns {Promise<import('./is_cached.js').CacheCheckResult>} Object with allCached boolean and files array with cache status
27560
+ *
27561
+ * @example
27562
+ * const status = await ModelRegistry.is_pipeline_cached_files('text-generation', 'onnx-community/gpt2-ONNX');
27563
+ * console.log(status.allCached); // true or false
27564
+ * console.log(status.files); // [{ file: 'config.json', cached: true }, ...]
27565
+ */
27566
+ static async is_pipeline_cached_files(task, modelId, options = {}) {
27567
+ return is_pipeline_cached_files(task, modelId, options);
27568
+ }
27569
+ /**
27570
+ * Get metadata for a specific file without downloading it.
27571
+ *
27572
+ * @param {string} path_or_repo_id - Model id or path
27573
+ * @param {string} filename - The file name
27574
+ * @param {import('../hub.js').PretrainedOptions} [options] - Optional parameters
27575
+ * @returns {Promise<{exists: boolean, size?: number, contentType?: string, fromCache?: boolean}>} File metadata
27576
+ *
27577
+ * @example
27578
+ * const metadata = await ModelRegistry.get_file_metadata('onnx-community/gpt2-ONNX', 'config.json');
27579
+ * console.log(metadata.exists, metadata.size); // true, 665
27580
+ */
27581
+ static async get_file_metadata(path_or_repo_id, filename, options = {}) {
27582
+ return get_file_metadata(path_or_repo_id, filename, options);
27583
+ }
27584
+ /**
27585
+ * Clears all cached files for a given model.
27586
+ * Automatically determines which files are needed and removes them from the cache.
27587
+ *
27588
+ * @param {string} modelId - The model id (e.g., "onnx-community/gpt2-ONNX")
27589
+ * @param {Object} [options] - Optional parameters
27590
+ * @param {string} [options.cache_dir] - Custom cache directory
27591
+ * @param {string} [options.revision] - Model revision (default: 'main')
27592
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
27593
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype] - Override dtype
27594
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device] - Override device
27595
+ * @param {boolean} [options.include_tokenizer=true] - Whether to clear tokenizer files
27596
+ * @param {boolean} [options.include_processor=true] - Whether to clear processor files
27597
+ * @returns {Promise<import('./clear_cache.js').CacheClearResult>} Object with deletion statistics and file status
27598
+ *
27599
+ * @example
27600
+ * const result = await ModelRegistry.clear_cache('onnx-community/bert-base-uncased-ONNX');
27601
+ * console.log(`Deleted ${result.filesDeleted} of ${result.filesCached} cached files`);
27602
+ */
27603
+ static async clear_cache(modelId, options = {}) {
27604
+ return clear_cache(modelId, options);
27605
+ }
27606
+ /**
27607
+ * Clears all cached files for a specific pipeline task.
27608
+ * Automatically determines which components are needed based on the task.
27609
+ *
27610
+ * @param {string} task - The pipeline task (e.g., "text-generation", "image-classification")
27611
+ * @param {string} modelId - The model id (e.g., "onnx-community/gpt2-ONNX")
27612
+ * @param {Object} [options] - Optional parameters
27613
+ * @param {string} [options.cache_dir] - Custom cache directory
27614
+ * @param {string} [options.revision] - Model revision (default: 'main')
27615
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
27616
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype] - Override dtype
27617
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device] - Override device
27618
+ * @returns {Promise<import('./clear_cache.js').CacheClearResult>} Object with deletion statistics and file status
27619
+ *
27620
+ * @example
27621
+ * const result = await ModelRegistry.clear_pipeline_cache('text-generation', 'onnx-community/gpt2-ONNX');
27622
+ * console.log(`Deleted ${result.filesDeleted} of ${result.filesCached} cached files`);
27623
+ */
27624
+ static async clear_pipeline_cache(task, modelId, options = {}) {
27625
+ return clear_pipeline_cache(task, modelId, options);
27626
+ }
27627
+ };
26477
27628
  export {
26478
27629
  ASTFeatureExtractor,
26479
27630
  ASTForAudioClassification,
26480
27631
  ASTModel,
26481
27632
  ASTPreTrainedModel,
27633
+ AfmoeForCausalLM,
27634
+ AfmoeModel,
27635
+ AfmoePreTrainedModel,
26482
27636
  AlbertForMaskedLM,
26483
27637
  AlbertForQuestionAnswering,
26484
27638
  AlbertForSequenceClassification,
@@ -26845,6 +27999,7 @@ export {
26845
27999
  LlavaPreTrainedModel,
26846
28000
  LlavaProcessor,
26847
28001
  LlavaQwen2ForCausalLM,
28002
+ LogLevel,
26848
28003
  LogitsProcessor,
26849
28004
  LogitsProcessorList,
26850
28005
  LogitsWarper,
@@ -26944,6 +28099,7 @@ export {
26944
28099
  MobileViTV2ForImageClassification,
26945
28100
  MobileViTV2Model,
26946
28101
  MobileViTV2PreTrainedModel,
28102
+ ModelRegistry,
26947
28103
  ModernBertDecoderForCausalLM,
26948
28104
  ModernBertDecoderModel,
26949
28105
  ModernBertDecoderPreTrainedModel,
@@ -26994,6 +28150,9 @@ export {
26994
28150
  Olmo3Model,
26995
28151
  Olmo3PreTrainedModel,
26996
28152
  OlmoForCausalLM,
28153
+ OlmoHybridForCausalLM,
28154
+ OlmoHybridModel,
28155
+ OlmoHybridPreTrainedModel,
26997
28156
  OlmoModel,
26998
28157
  OlmoPreTrainedModel,
26999
28158
  OpenELMForCausalLM,
@@ -27049,15 +28208,31 @@ export {
27049
28208
  QuestionAnsweringPipeline,
27050
28209
  Qwen2ForCausalLM,
27051
28210
  Qwen2Model,
28211
+ Qwen2MoeForCausalLM,
28212
+ Qwen2MoeModel,
28213
+ Qwen2MoePreTrainedModel,
27052
28214
  Qwen2PreTrainedModel,
27053
28215
  Qwen2Tokenizer,
27054
28216
  Qwen2VLForConditionalGeneration,
27055
28217
  Qwen2VLImageProcessor,
27056
28218
  Qwen2VLPreTrainedModel,
27057
28219
  Qwen2VLProcessor,
28220
+ Qwen2_5_VLForConditionalGeneration,
28221
+ Qwen2_5_VLProcessor,
27058
28222
  Qwen3ForCausalLM,
27059
28223
  Qwen3Model,
28224
+ Qwen3MoeForCausalLM,
28225
+ Qwen3MoeModel,
28226
+ Qwen3MoePreTrainedModel,
28227
+ Qwen3NextForCausalLM,
28228
+ Qwen3NextModel,
28229
+ Qwen3NextPreTrainedModel,
27060
28230
  Qwen3PreTrainedModel,
28231
+ Qwen3VLForConditionalGeneration,
28232
+ Qwen3VLMoeForConditionalGeneration,
28233
+ Qwen3VLProcessor,
28234
+ Qwen3_5ForConditionalGeneration,
28235
+ Qwen3_5MoeForConditionalGeneration,
27061
28236
  RFDetrForObjectDetection,
27062
28237
  RFDetrModel,
27063
28238
  RFDetrObjectDetectionOutput,
@@ -27310,10 +28485,11 @@ export {
27310
28485
  ones,
27311
28486
  ones_like,
27312
28487
  permute,
27313
- pipeline3 as pipeline,
28488
+ pipeline2 as pipeline,
27314
28489
  quantize_embeddings,
27315
28490
  rand,
27316
28491
  randn,
28492
+ random,
27317
28493
  read_audio,
27318
28494
  rfft,
27319
28495
  slice2 as slice,