@huggingface/transformers 4.0.0-next.0 → 4.0.0-next.10

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 (364) hide show
  1. package/README.md +32 -6
  2. package/dist/ort-wasm-simd-threaded.jsep.mjs +31 -31
  3. package/dist/transformers.js +9261 -1709
  4. package/dist/transformers.min.js +25 -18
  5. package/dist/transformers.node.cjs +6119 -3174
  6. package/dist/transformers.node.min.cjs +25 -23
  7. package/dist/transformers.node.min.mjs +25 -23
  8. package/dist/transformers.node.mjs +6034 -3168
  9. package/dist/transformers.web.js +4255 -1381
  10. package/dist/transformers.web.min.js +23 -19
  11. package/package.json +6 -6
  12. package/src/backends/onnx.js +128 -53
  13. package/src/backends/utils/cacheWasm.js +28 -46
  14. package/src/cache_utils.js +62 -0
  15. package/src/configs.js +123 -23
  16. package/src/env.js +100 -11
  17. package/src/generation/logits_sampler.js +3 -15
  18. package/src/generation/parameters.js +1 -1
  19. package/src/generation/streamers.js +21 -0
  20. package/src/image_processors_utils.js +29 -23
  21. package/src/models/afmoe/modeling_afmoe.js +5 -0
  22. package/src/models/auto/image_processing_auto.js +2 -1
  23. package/src/models/auto/modeling_auto.js +16 -2
  24. package/src/models/auto/tokenization_auto.js +2 -1
  25. package/src/models/chatterbox/modeling_chatterbox.js +1 -1
  26. package/src/models/chmv2/image_processing_chmv2.js +3 -0
  27. package/src/models/chmv2/modeling_chmv2.js +4 -0
  28. package/src/models/clap/feature_extraction_clap.js +2 -1
  29. package/src/models/cohere2/modeling_cohere2.js +5 -0
  30. package/src/models/cohere_asr/feature_extraction_cohere_asr.js +117 -0
  31. package/src/models/cohere_asr/modeling_cohere_asr.js +11 -0
  32. package/src/models/cohere_asr/processing_cohere_asr.js +55 -0
  33. package/src/models/cohere_asr/tokenization_cohere_asr.js +3 -0
  34. package/src/models/deepseek_v3/modeling_deepseek_v3.js +5 -0
  35. package/src/models/detr/image_processing_detr.js +1 -1
  36. package/src/models/eurobert/modeling_eurobert.js +41 -0
  37. package/src/models/feature_extractors.js +3 -0
  38. package/src/models/gemma3/image_processing_gemma3.js +3 -0
  39. package/src/models/gemma3/modeling_gemma3.js +4 -1
  40. package/src/models/gemma3/processing_gemma3.js +45 -0
  41. package/src/models/gemma3n/modeling_gemma3n.js +2 -0
  42. package/src/models/glm46v/image_processing_glm46v.js +12 -0
  43. package/src/models/glm46v/processing_glm46v.js +5 -0
  44. package/src/models/glm_moe_dsa/modeling_glm_moe_dsa.js +5 -0
  45. package/src/models/glm_ocr/modeling_glm_ocr.js +78 -0
  46. package/src/models/granite_speech/feature_extraction_granite_speech.js +58 -0
  47. package/src/models/granite_speech/modeling_granite_speech.js +5 -0
  48. package/src/models/granite_speech/processing_granite_speech.js +62 -0
  49. package/src/models/grounding_dino/image_processing_grounding_dino.js +1 -1
  50. package/src/models/idefics3/modeling_idefics3.js +5 -32
  51. package/src/models/image_processors.js +4 -0
  52. package/src/models/lfm2_vl/image_processing_lfm2_vl.js +305 -0
  53. package/src/models/lfm2_vl/modeling_lfm2_vl.js +13 -0
  54. package/src/models/lfm2_vl/processing_lfm2_vl.js +77 -0
  55. package/src/models/lighton_ocr/modeling_lighton_ocr.js +3 -0
  56. package/src/models/llava/modeling_llava.js +1 -1
  57. package/src/models/marian/tokenization_marian.js +3 -2
  58. package/src/models/mistral3/modeling_mistral3.js +2 -2
  59. package/src/models/mistral4/modeling_mistral4.js +5 -0
  60. package/src/models/modeling_utils.js +283 -300
  61. package/src/models/models.js +26 -1
  62. package/src/models/nemotron_h/modeling_nemotron_h.js +5 -0
  63. package/src/models/olmo_hybrid/modeling_olmo_hybrid.js +5 -0
  64. package/src/models/paligemma/modeling_paligemma.js +2 -25
  65. package/src/models/paligemma/processing_paligemma.js +3 -2
  66. package/src/models/processors.js +8 -0
  67. package/src/models/qwen2_5_vl/modeling_qwen2_5_vl.js +9 -0
  68. package/src/models/qwen2_5_vl/processing_qwen2_5_vl.js +3 -0
  69. package/src/models/qwen2_moe/modeling_qwen2_moe.js +5 -0
  70. package/src/models/qwen2_vl/image_processing_qwen2_vl.js +15 -1
  71. package/src/models/qwen2_vl/modeling_qwen2_vl.js +240 -143
  72. package/src/models/qwen2_vl/processing_qwen2_vl.js +5 -4
  73. package/src/models/qwen3_5/modeling_qwen3_5.js +4 -0
  74. package/src/models/qwen3_5_moe/modeling_qwen3_5_moe.js +4 -0
  75. package/src/models/qwen3_moe/modeling_qwen3_moe.js +5 -0
  76. package/src/models/qwen3_next/modeling_qwen3_next.js +5 -0
  77. package/src/models/qwen3_vl/modeling_qwen3_vl.js +4 -0
  78. package/src/models/qwen3_vl/processing_qwen3_vl.js +3 -0
  79. package/src/models/qwen3_vl_moe/modeling_qwen3_vl_moe.js +4 -0
  80. package/src/models/registry.js +61 -5
  81. package/src/models/sam/image_processing_sam.js +1 -1
  82. package/src/models/session.js +33 -56
  83. package/src/models/smolvlm/modeling_smolvlm.js +7 -0
  84. package/src/models/solar_open/modeling_solar_open.js +5 -0
  85. package/src/models/tokenizers.js +1 -0
  86. package/src/models/ultravox/modeling_ultravox.js +1 -3
  87. package/src/models/voxtral/modeling_voxtral.js +3 -0
  88. package/src/models/voxtral_realtime/feature_extraction_voxtral_realtime.js +71 -0
  89. package/src/models/voxtral_realtime/modeling_voxtral_realtime.js +239 -0
  90. package/src/models/voxtral_realtime/processing_voxtral_realtime.js +113 -0
  91. package/src/models/whisper/feature_extraction_whisper.js +4 -13
  92. package/src/models/whisper/modeling_whisper.js +6 -5
  93. package/src/models/xlm/tokenization_xlm.js +2 -1
  94. package/src/pipelines/automatic-speech-recognition.js +47 -3
  95. package/src/pipelines/document-question-answering.js +1 -1
  96. package/src/pipelines/image-to-text.js +2 -2
  97. package/src/pipelines/index.js +313 -0
  98. package/src/pipelines/summarization.js +1 -1
  99. package/src/pipelines/text-generation.js +5 -1
  100. package/src/pipelines/text-to-audio.js +4 -2
  101. package/src/pipelines/text2text-generation.js +1 -1
  102. package/src/pipelines/translation.js +1 -1
  103. package/src/pipelines/zero-shot-classification.js +3 -2
  104. package/src/pipelines.js +140 -428
  105. package/src/tokenization_utils.js +42 -21
  106. package/src/transformers.js +10 -1
  107. package/src/utils/audio.js +20 -3
  108. package/src/utils/cache/CrossOriginStorageCache.js +251 -0
  109. package/src/utils/cache/FileCache.js +128 -0
  110. package/src/utils/cache/cross-origin-storage.d.ts +38 -0
  111. package/src/utils/cache.js +12 -4
  112. package/src/utils/core.js +23 -1
  113. package/src/utils/devices.js +22 -0
  114. package/src/utils/dtypes.js +55 -0
  115. package/src/utils/hub/{files.js → FileResponse.js} +0 -90
  116. package/src/utils/hub/utils.js +45 -5
  117. package/src/utils/hub.js +67 -23
  118. package/src/utils/image.js +14 -14
  119. package/src/utils/logger.js +67 -0
  120. package/src/utils/lru_cache.js +67 -0
  121. package/src/utils/memoize_promise.js +45 -0
  122. package/src/utils/model-loader.js +35 -17
  123. package/src/utils/model_registry/ModelRegistry.js +382 -0
  124. package/src/utils/model_registry/clear_cache.js +128 -0
  125. package/src/utils/model_registry/get_available_dtypes.js +68 -0
  126. package/src/utils/model_registry/get_file_metadata.js +162 -0
  127. package/src/utils/model_registry/get_files.js +42 -0
  128. package/src/utils/model_registry/get_model_files.js +114 -0
  129. package/src/utils/model_registry/get_pipeline_files.js +44 -0
  130. package/src/utils/model_registry/get_processor_files.js +20 -0
  131. package/src/utils/model_registry/get_tokenizer_files.js +21 -0
  132. package/src/utils/model_registry/is_cached.js +169 -0
  133. package/src/utils/model_registry/resolve_model_type.js +66 -0
  134. package/src/utils/random.js +225 -0
  135. package/src/utils/tensor.js +26 -23
  136. package/src/utils/video.js +2 -2
  137. package/types/backends/onnx.d.ts.map +1 -1
  138. package/types/backends/utils/cacheWasm.d.ts +3 -17
  139. package/types/backends/utils/cacheWasm.d.ts.map +1 -1
  140. package/types/cache_utils.d.ts +29 -0
  141. package/types/cache_utils.d.ts.map +1 -0
  142. package/types/configs.d.ts.map +1 -1
  143. package/types/env.d.ts +60 -27
  144. package/types/env.d.ts.map +1 -1
  145. package/types/generation/logits_sampler.d.ts +2 -2
  146. package/types/generation/logits_sampler.d.ts.map +1 -1
  147. package/types/generation/parameters.d.ts +1 -1
  148. package/types/generation/parameters.d.ts.map +1 -1
  149. package/types/generation/streamers.d.ts +1 -0
  150. package/types/generation/streamers.d.ts.map +1 -1
  151. package/types/image_processors_utils.d.ts +18 -1
  152. package/types/image_processors_utils.d.ts.map +1 -1
  153. package/types/models/afmoe/modeling_afmoe.d.ts +8 -0
  154. package/types/models/afmoe/modeling_afmoe.d.ts.map +1 -0
  155. package/types/models/{ast/modeling_ast.d.ts → audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.d.ts} +1 -1
  156. package/types/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.d.ts.map +1 -0
  157. package/types/models/auto/image_processing_auto.d.ts.map +1 -1
  158. package/types/models/auto/modeling_auto.d.ts +6 -0
  159. package/types/models/auto/modeling_auto.d.ts.map +1 -1
  160. package/types/models/auto/tokenization_auto.d.ts.map +1 -1
  161. package/types/models/chmv2/image_processing_chmv2.d.ts +4 -0
  162. package/types/models/chmv2/image_processing_chmv2.d.ts.map +1 -0
  163. package/types/models/chmv2/modeling_chmv2.d.ts +6 -0
  164. package/types/models/chmv2/modeling_chmv2.d.ts.map +1 -0
  165. package/types/models/clap/feature_extraction_clap.d.ts.map +1 -1
  166. package/types/models/cohere2/modeling_cohere2.d.ts +8 -0
  167. package/types/models/cohere2/modeling_cohere2.d.ts.map +1 -0
  168. package/types/models/cohere_asr/feature_extraction_cohere_asr.d.ts +25 -0
  169. package/types/models/cohere_asr/feature_extraction_cohere_asr.d.ts.map +1 -0
  170. package/types/models/cohere_asr/modeling_cohere_asr.d.ts +9 -0
  171. package/types/models/cohere_asr/modeling_cohere_asr.d.ts.map +1 -0
  172. package/types/models/cohere_asr/processing_cohere_asr.d.ts +27 -0
  173. package/types/models/cohere_asr/processing_cohere_asr.d.ts.map +1 -0
  174. package/types/models/cohere_asr/tokenization_cohere_asr.d.ts +4 -0
  175. package/types/models/cohere_asr/tokenization_cohere_asr.d.ts.map +1 -0
  176. package/types/models/deepseek_v3/modeling_deepseek_v3.d.ts +8 -0
  177. package/types/models/deepseek_v3/modeling_deepseek_v3.d.ts.map +1 -0
  178. package/types/models/detr/image_processing_detr.d.ts +1 -1
  179. package/types/models/eurobert/modeling_eurobert.d.ts +36 -0
  180. package/types/models/eurobert/modeling_eurobert.d.ts.map +1 -0
  181. package/types/models/feature_extractors.d.ts +3 -0
  182. package/types/models/gemma3/image_processing_gemma3.d.ts +4 -0
  183. package/types/models/gemma3/image_processing_gemma3.d.ts.map +1 -0
  184. package/types/models/gemma3/modeling_gemma3.d.ts +4 -1
  185. package/types/models/gemma3/modeling_gemma3.d.ts.map +1 -1
  186. package/types/models/gemma3/processing_gemma3.d.ts +20 -0
  187. package/types/models/gemma3/processing_gemma3.d.ts.map +1 -0
  188. package/types/models/gemma3n/modeling_gemma3n.d.ts +2 -0
  189. package/types/models/gemma3n/modeling_gemma3n.d.ts.map +1 -1
  190. package/types/models/glm46v/image_processing_glm46v.d.ts +4 -0
  191. package/types/models/glm46v/image_processing_glm46v.d.ts.map +1 -0
  192. package/types/models/glm46v/processing_glm46v.d.ts +4 -0
  193. package/types/models/glm46v/processing_glm46v.d.ts.map +1 -0
  194. package/types/models/glm_moe_dsa/modeling_glm_moe_dsa.d.ts +8 -0
  195. package/types/models/glm_moe_dsa/modeling_glm_moe_dsa.d.ts.map +1 -0
  196. package/types/models/glm_ocr/modeling_glm_ocr.d.ts +26 -0
  197. package/types/models/glm_ocr/modeling_glm_ocr.d.ts.map +1 -0
  198. package/types/models/granite_speech/feature_extraction_granite_speech.d.ts +16 -0
  199. package/types/models/granite_speech/feature_extraction_granite_speech.d.ts.map +1 -0
  200. package/types/models/granite_speech/modeling_granite_speech.d.ts +4 -0
  201. package/types/models/granite_speech/modeling_granite_speech.d.ts.map +1 -0
  202. package/types/models/granite_speech/processing_granite_speech.d.ts +19 -0
  203. package/types/models/granite_speech/processing_granite_speech.d.ts.map +1 -0
  204. package/types/models/grounding_dino/image_processing_grounding_dino.d.ts +1 -1
  205. package/types/models/idefics3/modeling_idefics3.d.ts +2 -18
  206. package/types/models/idefics3/modeling_idefics3.d.ts.map +1 -1
  207. package/types/models/image_processors.d.ts +4 -0
  208. package/types/models/lfm2_vl/image_processing_lfm2_vl.d.ts +41 -0
  209. package/types/models/lfm2_vl/image_processing_lfm2_vl.d.ts.map +1 -0
  210. package/types/models/lfm2_vl/modeling_lfm2_vl.d.ts +4 -0
  211. package/types/models/lfm2_vl/modeling_lfm2_vl.d.ts.map +1 -0
  212. package/types/models/lfm2_vl/processing_lfm2_vl.d.ts +18 -0
  213. package/types/models/lfm2_vl/processing_lfm2_vl.d.ts.map +1 -0
  214. package/types/models/lighton_ocr/modeling_lighton_ocr.d.ts +4 -0
  215. package/types/models/lighton_ocr/modeling_lighton_ocr.d.ts.map +1 -0
  216. package/types/models/marian/tokenization_marian.d.ts.map +1 -1
  217. package/types/models/mistral3/modeling_mistral3.d.ts +2 -2
  218. package/types/models/mistral3/modeling_mistral3.d.ts.map +1 -1
  219. package/types/models/mistral4/modeling_mistral4.d.ts +8 -0
  220. package/types/models/mistral4/modeling_mistral4.d.ts.map +1 -0
  221. package/types/models/modeling_utils.d.ts +46 -27
  222. package/types/models/modeling_utils.d.ts.map +1 -1
  223. package/types/models/models.d.ts +26 -1
  224. package/types/models/nemotron_h/modeling_nemotron_h.d.ts +8 -0
  225. package/types/models/nemotron_h/modeling_nemotron_h.d.ts.map +1 -0
  226. package/types/models/olmo_hybrid/modeling_olmo_hybrid.d.ts +8 -0
  227. package/types/models/olmo_hybrid/modeling_olmo_hybrid.d.ts.map +1 -0
  228. package/types/models/paligemma/modeling_paligemma.d.ts +2 -8
  229. package/types/models/paligemma/modeling_paligemma.d.ts.map +1 -1
  230. package/types/models/paligemma/processing_paligemma.d.ts.map +1 -1
  231. package/types/models/processors.d.ts +8 -0
  232. package/types/models/qwen2_5_vl/modeling_qwen2_5_vl.d.ts +7 -0
  233. package/types/models/qwen2_5_vl/modeling_qwen2_5_vl.d.ts.map +1 -0
  234. package/types/models/qwen2_5_vl/processing_qwen2_5_vl.d.ts +4 -0
  235. package/types/models/qwen2_5_vl/processing_qwen2_5_vl.d.ts.map +1 -0
  236. package/types/models/qwen2_moe/modeling_qwen2_moe.d.ts +8 -0
  237. package/types/models/qwen2_moe/modeling_qwen2_moe.d.ts.map +1 -0
  238. package/types/models/qwen2_vl/image_processing_qwen2_vl.d.ts +3 -0
  239. package/types/models/qwen2_vl/image_processing_qwen2_vl.d.ts.map +1 -1
  240. package/types/models/qwen2_vl/modeling_qwen2_vl.d.ts +44 -6
  241. package/types/models/qwen2_vl/modeling_qwen2_vl.d.ts.map +1 -1
  242. package/types/models/qwen2_vl/processing_qwen2_vl.d.ts +1 -0
  243. package/types/models/qwen2_vl/processing_qwen2_vl.d.ts.map +1 -1
  244. package/types/models/qwen3_5/modeling_qwen3_5.d.ts +6 -0
  245. package/types/models/qwen3_5/modeling_qwen3_5.d.ts.map +1 -0
  246. package/types/models/qwen3_5_moe/modeling_qwen3_5_moe.d.ts +7 -0
  247. package/types/models/qwen3_5_moe/modeling_qwen3_5_moe.d.ts.map +1 -0
  248. package/types/models/qwen3_moe/modeling_qwen3_moe.d.ts +8 -0
  249. package/types/models/qwen3_moe/modeling_qwen3_moe.d.ts.map +1 -0
  250. package/types/models/qwen3_next/modeling_qwen3_next.d.ts +8 -0
  251. package/types/models/qwen3_next/modeling_qwen3_next.d.ts.map +1 -0
  252. package/types/models/qwen3_vl/modeling_qwen3_vl.d.ts +7 -0
  253. package/types/models/qwen3_vl/modeling_qwen3_vl.d.ts.map +1 -0
  254. package/types/models/qwen3_vl/processing_qwen3_vl.d.ts +4 -0
  255. package/types/models/qwen3_vl/processing_qwen3_vl.d.ts.map +1 -0
  256. package/types/models/qwen3_vl_moe/modeling_qwen3_vl_moe.d.ts +7 -0
  257. package/types/models/qwen3_vl_moe/modeling_qwen3_vl_moe.d.ts.map +1 -0
  258. package/types/models/registry.d.ts +2 -1
  259. package/types/models/registry.d.ts.map +1 -1
  260. package/types/models/sam/image_processing_sam.d.ts +1 -1
  261. package/types/models/session.d.ts +3 -2
  262. package/types/models/session.d.ts.map +1 -1
  263. package/types/models/smolvlm/modeling_smolvlm.d.ts +8 -0
  264. package/types/models/smolvlm/modeling_smolvlm.d.ts.map +1 -0
  265. package/types/models/solar_open/modeling_solar_open.d.ts +8 -0
  266. package/types/models/solar_open/modeling_solar_open.d.ts.map +1 -0
  267. package/types/models/tokenizers.d.ts +1 -0
  268. package/types/models/ultravox/modeling_ultravox.d.ts +0 -2
  269. package/types/models/ultravox/modeling_ultravox.d.ts.map +1 -1
  270. package/types/models/voxtral/modeling_voxtral.d.ts +4 -0
  271. package/types/models/voxtral/modeling_voxtral.d.ts.map +1 -0
  272. package/types/models/voxtral_realtime/feature_extraction_voxtral_realtime.d.ts +28 -0
  273. package/types/models/voxtral_realtime/feature_extraction_voxtral_realtime.d.ts.map +1 -0
  274. package/types/models/voxtral_realtime/modeling_voxtral_realtime.d.ts +17 -0
  275. package/types/models/voxtral_realtime/modeling_voxtral_realtime.d.ts.map +1 -0
  276. package/types/models/voxtral_realtime/processing_voxtral_realtime.d.ts +44 -0
  277. package/types/models/voxtral_realtime/processing_voxtral_realtime.d.ts.map +1 -0
  278. package/types/models/whisper/feature_extraction_whisper.d.ts.map +1 -1
  279. package/types/models/whisper/modeling_whisper.d.ts.map +1 -1
  280. package/types/models/xlm/tokenization_xlm.d.ts.map +1 -1
  281. package/types/pipelines/automatic-speech-recognition.d.ts +7 -2
  282. package/types/pipelines/automatic-speech-recognition.d.ts.map +1 -1
  283. package/types/pipelines/document-question-answering.d.ts +2 -2
  284. package/types/pipelines/document-question-answering.d.ts.map +1 -1
  285. package/types/pipelines/image-to-text.d.ts +4 -4
  286. package/types/pipelines/image-to-text.d.ts.map +1 -1
  287. package/types/pipelines/index.d.ts +265 -0
  288. package/types/pipelines/index.d.ts.map +1 -0
  289. package/types/pipelines/summarization.d.ts +2 -2
  290. package/types/pipelines/summarization.d.ts.map +1 -1
  291. package/types/pipelines/text-generation.d.ts +7 -3
  292. package/types/pipelines/text-generation.d.ts.map +1 -1
  293. package/types/pipelines/text-to-audio.d.ts.map +1 -1
  294. package/types/pipelines/text2text-generation.d.ts +3 -3
  295. package/types/pipelines/text2text-generation.d.ts.map +1 -1
  296. package/types/pipelines/translation.d.ts +2 -2
  297. package/types/pipelines/translation.d.ts.map +1 -1
  298. package/types/pipelines/zero-shot-classification.d.ts.map +1 -1
  299. package/types/pipelines.d.ts +51 -291
  300. package/types/pipelines.d.ts.map +1 -1
  301. package/types/tokenization_utils.d.ts +44 -26
  302. package/types/tokenization_utils.d.ts.map +1 -1
  303. package/types/transformers.d.ts +7 -1
  304. package/types/transformers.d.ts.map +1 -1
  305. package/types/utils/audio.d.ts +5 -2
  306. package/types/utils/audio.d.ts.map +1 -1
  307. package/types/utils/cache/CrossOriginStorageCache.d.ts +120 -0
  308. package/types/utils/cache/CrossOriginStorageCache.d.ts.map +1 -0
  309. package/types/utils/cache/FileCache.d.ts +39 -0
  310. package/types/utils/cache/FileCache.d.ts.map +1 -0
  311. package/types/utils/cache.d.ts +10 -4
  312. package/types/utils/cache.d.ts.map +1 -1
  313. package/types/utils/core.d.ts +59 -2
  314. package/types/utils/core.d.ts.map +1 -1
  315. package/types/utils/devices.d.ts +15 -0
  316. package/types/utils/devices.d.ts.map +1 -1
  317. package/types/utils/dtypes.d.ts +17 -1
  318. package/types/utils/dtypes.d.ts.map +1 -1
  319. package/types/utils/hub/{files.d.ts → FileResponse.d.ts} +1 -32
  320. package/types/utils/hub/FileResponse.d.ts.map +1 -0
  321. package/types/utils/hub/utils.d.ts +19 -3
  322. package/types/utils/hub/utils.d.ts.map +1 -1
  323. package/types/utils/hub.d.ts +36 -7
  324. package/types/utils/hub.d.ts.map +1 -1
  325. package/types/utils/image.d.ts +1 -1
  326. package/types/utils/logger.d.ts +28 -0
  327. package/types/utils/logger.d.ts.map +1 -0
  328. package/types/utils/lru_cache.d.ts +38 -0
  329. package/types/utils/lru_cache.d.ts.map +1 -0
  330. package/types/utils/memoize_promise.d.ts +14 -0
  331. package/types/utils/memoize_promise.d.ts.map +1 -0
  332. package/types/utils/model-loader.d.ts +15 -0
  333. package/types/utils/model-loader.d.ts.map +1 -1
  334. package/types/utils/model_registry/ModelRegistry.d.ts +298 -0
  335. package/types/utils/model_registry/ModelRegistry.d.ts.map +1 -0
  336. package/types/utils/model_registry/clear_cache.d.ts +74 -0
  337. package/types/utils/model_registry/clear_cache.d.ts.map +1 -0
  338. package/types/utils/model_registry/get_available_dtypes.d.ts +26 -0
  339. package/types/utils/model_registry/get_available_dtypes.d.ts.map +1 -0
  340. package/types/utils/model_registry/get_file_metadata.d.ts +20 -0
  341. package/types/utils/model_registry/get_file_metadata.d.ts.map +1 -0
  342. package/types/utils/model_registry/get_files.d.ts +23 -0
  343. package/types/utils/model_registry/get_files.d.ts.map +1 -0
  344. package/types/utils/model_registry/get_model_files.d.ts +48 -0
  345. package/types/utils/model_registry/get_model_files.d.ts.map +1 -0
  346. package/types/utils/model_registry/get_pipeline_files.d.ts +22 -0
  347. package/types/utils/model_registry/get_pipeline_files.d.ts.map +1 -0
  348. package/types/utils/model_registry/get_processor_files.d.ts +9 -0
  349. package/types/utils/model_registry/get_processor_files.d.ts.map +1 -0
  350. package/types/utils/model_registry/get_tokenizer_files.d.ts +9 -0
  351. package/types/utils/model_registry/get_tokenizer_files.d.ts.map +1 -0
  352. package/types/utils/model_registry/is_cached.d.ts +105 -0
  353. package/types/utils/model_registry/is_cached.d.ts.map +1 -0
  354. package/types/utils/model_registry/resolve_model_type.d.ts +24 -0
  355. package/types/utils/model_registry/resolve_model_type.d.ts.map +1 -0
  356. package/types/utils/random.d.ts +86 -0
  357. package/types/utils/random.d.ts.map +1 -0
  358. package/types/utils/tensor.d.ts.map +1 -1
  359. package/src/utils/data-structures.js +0 -572
  360. package/types/models/ast/modeling_ast.d.ts.map +0 -1
  361. package/types/utils/data-structures.d.ts +0 -294
  362. package/types/utils/data-structures.d.ts.map +0 -1
  363. package/types/utils/hub/files.d.ts.map +0 -1
  364. /package/src/models/{ast/modeling_ast.js → audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.js} +0 -0
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @file Logger utility for Transformers.js with configurable log levels.
3
+ *
4
+ * @module utils/logger
5
+ */
6
+
7
+ import { env, LogLevel } from '../env.js';
8
+
9
+ /**
10
+ * Logger that respects the configured log level in env.logLevel.
11
+ *
12
+ * @example
13
+ * import { logger } from './utils/logger.js';
14
+ * logger.info('Model loaded successfully');
15
+ * logger.warn('Deprecated method used');
16
+ * logger.error('Failed to load model');
17
+ * logger.debug('Token count:', tokens.length);
18
+ */
19
+ export const logger = {
20
+ /**
21
+ * Log an error message. Only suppressed when logLevel is NONE.
22
+ * @param {...any} args - Arguments to log
23
+ */
24
+ error(...args) {
25
+ if (env.logLevel <= LogLevel.ERROR) {
26
+ console.error(...args);
27
+ }
28
+ },
29
+
30
+ /**
31
+ * Log a warning message. Shown when logLevel <= WARNING.
32
+ * @param {...any} args - Arguments to log
33
+ */
34
+ warn(...args) {
35
+ if (env.logLevel <= LogLevel.WARNING) {
36
+ console.warn(...args);
37
+ }
38
+ },
39
+
40
+ /**
41
+ * Log an info message. Shown when logLevel <= INFO.
42
+ * @param {...any} args - Arguments to log
43
+ */
44
+ info(...args) {
45
+ if (env.logLevel <= LogLevel.INFO) {
46
+ console.log(...args);
47
+ }
48
+ },
49
+
50
+ /**
51
+ * Log a debug message. Only shown when logLevel is DEBUG.
52
+ * @param {...any} args - Arguments to log
53
+ */
54
+ debug(...args) {
55
+ if (env.logLevel <= LogLevel.DEBUG) {
56
+ console.log(...args);
57
+ }
58
+ },
59
+
60
+ /**
61
+ * Log a message (alias for info). Shown when logLevel <= INFO.
62
+ * @param {...any} args - Arguments to log
63
+ */
64
+ log(...args) {
65
+ this.info(...args);
66
+ },
67
+ };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * A simple Least Recently Used (LRU) cache implementation in JavaScript.
3
+ * This cache stores key-value pairs and evicts the least recently used item
4
+ * when the capacity is exceeded.
5
+ */
6
+ export class LRUCache {
7
+ /** @type {number} */
8
+ #capacity;
9
+
10
+ /** @type {Map<any, any>} */
11
+ #cache;
12
+
13
+ /**
14
+ * Creates an LRUCache instance.
15
+ * @param {number} capacity The maximum number of items the cache can hold.
16
+ */
17
+ constructor(capacity) {
18
+ this.#capacity = capacity;
19
+ this.#cache = new Map();
20
+ }
21
+
22
+ /**
23
+ * Retrieves the value associated with the given key and marks the key as recently used.
24
+ * @param {any} key The key to retrieve.
25
+ * @returns {any} The value associated with the key, or undefined if the key does not exist.
26
+ */
27
+ get(key) {
28
+ if (!this.#cache.has(key)) return undefined;
29
+ const value = this.#cache.get(key);
30
+ this.#cache.delete(key);
31
+ this.#cache.set(key, value);
32
+ return value;
33
+ }
34
+
35
+ /**
36
+ * Inserts or updates the key-value pair in the cache.
37
+ * If the key already exists, it is updated and marked as recently used.
38
+ * If the cache exceeds its capacity, the least recently used item is evicted.
39
+ * @param {any} key The key to add or update.
40
+ * @param {any} value The value to associate with the key.
41
+ */
42
+ put(key, value) {
43
+ if (this.#cache.has(key)) {
44
+ this.#cache.delete(key);
45
+ }
46
+ this.#cache.set(key, value);
47
+ if (this.#cache.size > this.#capacity) {
48
+ this.#cache.delete(this.#cache.keys().next().value);
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Removes the entry for the given key from the cache.
54
+ * @param {any} key The key to delete.
55
+ * @returns {boolean} `true` if the entry existed and was removed, `false` otherwise.
56
+ */
57
+ delete(key) {
58
+ return this.#cache.delete(key);
59
+ }
60
+
61
+ /**
62
+ * Clears the cache.
63
+ */
64
+ clear() {
65
+ this.#cache.clear();
66
+ }
67
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @file Utility for memoizing promises by key.
3
+ *
4
+ * Ensures that a given async operation is only initiated once per key.
5
+ * Subsequent calls with the same key return the same pending or resolved promise.
6
+ * Rejected promises are evicted from the cache so callers can retry.
7
+ *
8
+ * The cache is bounded by `MAX_CACHE_SIZE`. When the limit is exceeded, the
9
+ * least-recently-used entry is evicted.
10
+ */
11
+
12
+ import { LRUCache } from './lru_cache.js';
13
+
14
+ const MAX_CACHE_SIZE = 100;
15
+
16
+ /** @type {LRUCache} */
17
+ const cache = new LRUCache(MAX_CACHE_SIZE);
18
+
19
+ /**
20
+ * Returns the cached promise for `key`, or calls `factory` to create one and caches it.
21
+ * Subsequent calls with the same key return the same promise whether it is still
22
+ * pending or already resolved, so the factory is never invoked more than once per key.
23
+ * If the promise rejects, the entry is removed from the cache so the operation can be retried.
24
+ *
25
+ * @template T
26
+ * @param {string} key A unique identifier for this async operation.
27
+ * @param {() => Promise<T>} factory A function that returns the promise to memoize.
28
+ * Only called when no entry exists for `key`.
29
+ * @returns {Promise<T>}
30
+ */
31
+ export function memoizePromise(key, factory) {
32
+ const cached = cache.get(key);
33
+ if (cached !== undefined) {
34
+ return cached;
35
+ }
36
+ const promise = factory().then(
37
+ (value) => value,
38
+ (err) => {
39
+ cache.delete(key);
40
+ return Promise.reject(err);
41
+ },
42
+ );
43
+ cache.put(key, promise);
44
+ return promise;
45
+ }
@@ -1,6 +1,37 @@
1
1
  import { getModelFile, MAX_EXTERNAL_DATA_CHUNKS } from './hub.js';
2
2
  import { apis } from '../env.js';
3
3
 
4
+ /**
5
+ * Resolves an `use_external_data_format` config value to the number of data chunks for a given file.
6
+ * @param {import('./hub.js').ExternalData|Record<string, import('./hub.js').ExternalData>|null|undefined} config The external data format configuration.
7
+ * @param {string} fullName The full ONNX file name (e.g., "model_quantized.onnx").
8
+ * @param {string} fileName The base file name (e.g., "model").
9
+ * @returns {number} The number of external data chunks (0 if none).
10
+ */
11
+ export function resolveExternalDataFormat(config, fullName, fileName) {
12
+ if (!config) return 0;
13
+ if (typeof config === 'object' && config !== null) {
14
+ if (config.hasOwnProperty(fullName)) return +config[fullName];
15
+ if (config.hasOwnProperty(fileName)) return +config[fileName];
16
+ return 0;
17
+ }
18
+ return +config; // (false=0, true=1, number remains the same)
19
+ }
20
+
21
+ /**
22
+ * Generates the file names for external data chunks.
23
+ * @param {string} fullName The full ONNX file name (e.g., "model_quantized.onnx").
24
+ * @param {number} numChunks The number of external data chunks.
25
+ * @returns {string[]} Array of external data file names.
26
+ */
27
+ export function getExternalDataChunkNames(fullName, numChunks) {
28
+ const names = [];
29
+ for (let i = 0; i < numChunks; ++i) {
30
+ names.push(`${fullName}_data${i === 0 ? '' : '_' + i}`);
31
+ }
32
+ return names;
33
+ }
34
+
4
35
  /**
5
36
  * Loads the core model file.
6
37
  *
@@ -42,28 +73,15 @@ export async function getModelDataFiles(
42
73
  /** @type {Promise<string|{path: string, data: Uint8Array}>[]} */
43
74
  let externalDataPromises = [];
44
75
 
45
- if (use_external_data_format) {
46
- let external_data_format;
47
- if (typeof use_external_data_format === 'object') {
48
- if (use_external_data_format.hasOwnProperty(baseName)) {
49
- external_data_format = use_external_data_format[baseName];
50
- } else if (use_external_data_format.hasOwnProperty(fileName)) {
51
- external_data_format = use_external_data_format[fileName];
52
- } else {
53
- external_data_format = false;
54
- }
55
- } else {
56
- external_data_format = use_external_data_format;
57
- }
58
-
59
- const num_chunks = +external_data_format; // (false=0, true=1, number remains the same)
76
+ const num_chunks = resolveExternalDataFormat(use_external_data_format, baseName, fileName);
77
+ if (num_chunks > 0) {
60
78
  if (num_chunks > MAX_EXTERNAL_DATA_CHUNKS) {
61
79
  throw new Error(
62
80
  `The number of external data chunks (${num_chunks}) exceeds the maximum allowed value (${MAX_EXTERNAL_DATA_CHUNKS}).`,
63
81
  );
64
82
  }
65
- for (let i = 0; i < num_chunks; ++i) {
66
- const path = `${baseName}_data${i === 0 ? '' : '_' + i}`;
83
+ const chunkNames = getExternalDataChunkNames(baseName, num_chunks);
84
+ for (const path of chunkNames) {
67
85
  const fullPath = `${options.subfolder ?? ''}/${path}`;
68
86
  externalDataPromises.push(
69
87
  new Promise(async (resolve, reject) => {
@@ -0,0 +1,382 @@
1
+ /**
2
+ * @file Model registry for cache and file operations
3
+ *
4
+ * Provides static methods for:
5
+ * - Discovering which files a model needs
6
+ * - Detecting available quantization levels (dtypes)
7
+ * - Getting file metadata
8
+ * - Checking cache status
9
+ *
10
+ * **Example:** Get all files needed for a model
11
+ * ```javascript
12
+ * const files = await ModelRegistry.get_files(
13
+ * "onnx-community/all-MiniLM-L6-v2-ONNX",
14
+ * { dtype: "fp16" },
15
+ * );
16
+ * console.log(files); // [ 'config.json', 'onnx/model_fp16.onnx', 'onnx/model_fp16.onnx_data', 'tokenizer.json', 'tokenizer_config.json' ]
17
+ * ```
18
+ *
19
+ * **Example:** Get all files needed for a specific pipeline task
20
+ * ```javascript
21
+ * const files = await ModelRegistry.get_pipeline_files(
22
+ * "text-generation",
23
+ * "onnx-community/Qwen3-0.6B-ONNX",
24
+ * { dtype: "q4" },
25
+ * );
26
+ * console.log(files); // [ 'config.json', 'onnx/model_q4.onnx', 'generation_config.json', 'tokenizer.json', 'tokenizer_config.json' ]
27
+ * ```
28
+ *
29
+ * **Example:** Get specific component files
30
+ * ```javascript
31
+ * const modelFiles = await ModelRegistry.get_model_files("onnx-community/all-MiniLM-L6-v2-ONNX", { dtype: "q4" });
32
+ * const tokenizerFiles = await ModelRegistry.get_tokenizer_files("onnx-community/all-MiniLM-L6-v2-ONNX");
33
+ * const processorFiles = await ModelRegistry.get_processor_files("onnx-community/all-MiniLM-L6-v2-ONNX");
34
+ * console.log(modelFiles); // [ 'config.json', 'onnx/model_q4.onnx', 'onnx/model_q4.onnx_data' ]
35
+ * console.log(tokenizerFiles); // [ 'tokenizer.json', 'tokenizer_config.json' ]
36
+ * console.log(processorFiles); // [ ]
37
+ * ```
38
+ *
39
+ * **Example:** Detect available quantization levels for a model
40
+ * ```javascript
41
+ * const dtypes = await ModelRegistry.get_available_dtypes("onnx-community/all-MiniLM-L6-v2-ONNX");
42
+ * console.log(dtypes); // [ 'fp32', 'fp16', 'int8', 'uint8', 'q8', 'q4' ]
43
+ *
44
+ * // Use the result to pick the best available dtype
45
+ * const preferredDtype = dtypes.includes("q4") ? "q4" : "fp32";
46
+ * const files = await ModelRegistry.get_files("onnx-community/all-MiniLM-L6-v2-ONNX", { dtype: preferredDtype });
47
+ * ```
48
+ *
49
+ * **Example:** Check file metadata without downloading
50
+ * ```javascript
51
+ * const metadata = await ModelRegistry.get_file_metadata(
52
+ * "onnx-community/Qwen3-0.6B-ONNX",
53
+ * "config.json"
54
+ * );
55
+ * console.log(metadata); // { exists: true, size: 912, contentType: 'application/json', fromCache: true }
56
+ * ```
57
+ *
58
+ * **Example:** Model cache management
59
+ * ```javascript
60
+ * const modelId = "onnx-community/Qwen3-0.6B-ONNX";
61
+ * const options = { dtype: "q4" };
62
+ *
63
+ * // Quickly check if the model is cached (probably false)
64
+ * let cached = await ModelRegistry.is_cached(modelId, options);
65
+ * console.log(cached); // false
66
+ *
67
+ * // Get per-file cache detail
68
+ * let cacheStatus = await ModelRegistry.is_cached_files(modelId, options);
69
+ * console.log(cacheStatus);
70
+ * // {
71
+ * // allCached: false,
72
+ * // files: [ { file: 'config.json', cached: true }, { file: 'onnx/model_q4.onnx', cached: false }, { file: 'generation_config.json', cached: false }, { file: 'tokenizer.json', cached: false }, { file: 'tokenizer_config.json', cached: false } ]
73
+ * // }
74
+ *
75
+ * // Download the model by instantiating a pipeline
76
+ * const generator = await pipeline("text-generation", modelId, options);
77
+ * const output = await generator(
78
+ * [{ role: "user", content: "What is the capital of France?" }],
79
+ * { max_new_tokens: 256, do_sample: false },
80
+ * );
81
+ * console.log(output[0].generated_text.at(-1).content); // <think>...</think>\n\nThe capital of France is **Paris**.
82
+ *
83
+ * // Check if the model is cached (should be true now)
84
+ * cached = await ModelRegistry.is_cached(modelId, options);
85
+ * console.log(cached); // true
86
+ *
87
+ * // Clear the cache
88
+ * const clearResult = await ModelRegistry.clear_cache(modelId, options);
89
+ * console.log(clearResult);
90
+ * // {
91
+ * // filesDeleted: 5,
92
+ * // filesCached: 5,
93
+ * // files: [ { file: 'config.json', deleted: true, wasCached: true }, { file: 'onnx/model_q4.onnx', deleted: true, wasCached: true }, { file: 'generation_config.json', deleted: true, wasCached: true }, { file: 'tokenizer.json', deleted: true, wasCached: true }, { file: 'tokenizer_config.json', deleted: true, wasCached: true } ]
94
+ * // }
95
+ *
96
+ * // Check if the model is cached (should be false again)
97
+ * cached = await ModelRegistry.is_cached(modelId, options);
98
+ * console.log(cached); // false
99
+ * ```
100
+ *
101
+ * @module utils/model_registry
102
+ */
103
+
104
+ import { get_files } from './get_files.js';
105
+ import { get_pipeline_files } from './get_pipeline_files.js';
106
+ import { get_model_files } from './get_model_files.js';
107
+ import { get_tokenizer_files } from './get_tokenizer_files.js';
108
+ import { get_processor_files } from './get_processor_files.js';
109
+ import { is_cached, is_cached_files, is_pipeline_cached, is_pipeline_cached_files } from './is_cached.js';
110
+ import { get_file_metadata } from './get_file_metadata.js';
111
+ import { clear_cache, clear_pipeline_cache } from './clear_cache.js';
112
+ import { get_available_dtypes } from './get_available_dtypes.js';
113
+
114
+ /**
115
+ * Static class for cache and file management operations.
116
+ * @hideconstructor
117
+ */
118
+ export class ModelRegistry {
119
+ /**
120
+ * Get all files (model, tokenizer, processor) needed for a model.
121
+ *
122
+ * @param {string} modelId - The model id (e.g., "onnx-community/bert-base-uncased-ONNX")
123
+ * @param {Object} [options] - Optional parameters
124
+ * @param {import('../../configs.js').PretrainedConfig} [options.config=null] - Pre-loaded config
125
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
126
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
127
+ * @param {string} [options.model_file_name=null] - Override the model file name (excluding .onnx suffix)
128
+ * @param {boolean} [options.include_tokenizer=true] - Whether to check for tokenizer files
129
+ * @param {boolean} [options.include_processor=true] - Whether to check for processor files
130
+ * @returns {Promise<string[]>} Array of file paths
131
+ *
132
+ * @example
133
+ * const files = await ModelRegistry.get_files('onnx-community/gpt2-ONNX');
134
+ * console.log(files); // ['config.json', 'tokenizer.json', 'onnx/model_q4.onnx', ...]
135
+ */
136
+ static async get_files(modelId, options = {}) {
137
+ return get_files(modelId, options);
138
+ }
139
+
140
+ /**
141
+ * Get all files needed for a specific pipeline task.
142
+ * Automatically determines which components are needed based on the task.
143
+ *
144
+ * @param {string} task - The pipeline task (e.g., "text-generation", "background-removal")
145
+ * @param {string} modelId - The model id (e.g., "onnx-community/bert-base-uncased-ONNX")
146
+ * @param {Object} [options] - Optional parameters
147
+ * @param {import('../../configs.js').PretrainedConfig} [options.config=null] - Pre-loaded config
148
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
149
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
150
+ * @param {string} [options.model_file_name=null] - Override the model file name (excluding .onnx suffix)
151
+ * @returns {Promise<string[]>} Array of file paths
152
+ *
153
+ * @example
154
+ * const files = await ModelRegistry.get_pipeline_files('text-generation', 'onnx-community/gpt2-ONNX');
155
+ * console.log(files); // ['config.json', 'tokenizer.json', 'onnx/model_q4.onnx', ...]
156
+ */
157
+ static async get_pipeline_files(task, modelId, options = {}) {
158
+ return get_pipeline_files(task, modelId, options);
159
+ }
160
+
161
+ /**
162
+ * Get model files needed for a specific model.
163
+ *
164
+ * @param {string} modelId - The model id
165
+ * @param {Object} [options] - Optional parameters
166
+ * @param {import('../../configs.js').PretrainedConfig} [options.config=null] - Pre-loaded config
167
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
168
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
169
+ * @param {string} [options.model_file_name=null] - Override the model file name (excluding .onnx suffix)
170
+ * @returns {Promise<string[]>} Array of model file paths
171
+ *
172
+ * @example
173
+ * const files = await ModelRegistry.get_model_files('onnx-community/bert-base-uncased-ONNX');
174
+ * console.log(files); // ['config.json', 'onnx/model_q4.onnx', 'generation_config.json']
175
+ */
176
+ static async get_model_files(modelId, options = {}) {
177
+ return get_model_files(modelId, options);
178
+ }
179
+
180
+ /**
181
+ * Get tokenizer files needed for a specific model.
182
+ *
183
+ * @param {string} modelId - The model id
184
+ * @returns {Promise<string[]>} Array of tokenizer file paths
185
+ *
186
+ * @example
187
+ * const files = await ModelRegistry.get_tokenizer_files('onnx-community/gpt2-ONNX');
188
+ * console.log(files); // ['tokenizer.json', 'tokenizer_config.json']
189
+ */
190
+ static async get_tokenizer_files(modelId) {
191
+ return get_tokenizer_files(modelId);
192
+ }
193
+
194
+ /**
195
+ * Get processor files needed for a specific model.
196
+ *
197
+ * @param {string} modelId - The model id
198
+ * @returns {Promise<string[]>} Array of processor file paths
199
+ *
200
+ * @example
201
+ * const files = await ModelRegistry.get_processor_files('onnx-community/vit-base-patch16-224-ONNX');
202
+ * console.log(files); // ['preprocessor_config.json']
203
+ */
204
+ static async get_processor_files(modelId) {
205
+ return get_processor_files(modelId);
206
+ }
207
+
208
+ /**
209
+ * Detects which quantization levels (dtypes) are available for a model
210
+ * by checking which ONNX files exist on the hub or locally.
211
+ *
212
+ * A dtype is considered available if all required model session files
213
+ * exist for that dtype.
214
+ *
215
+ * @param {string} modelId - The model id (e.g., "onnx-community/all-MiniLM-L6-v2-ONNX")
216
+ * @param {Object} [options] - Optional parameters
217
+ * @param {import('../../configs.js').PretrainedConfig} [options.config=null] - Pre-loaded config
218
+ * @param {string} [options.model_file_name=null] - Override the model file name (excluding .onnx suffix)
219
+ * @param {string} [options.revision='main'] - Model revision
220
+ * @param {string} [options.cache_dir=null] - Custom cache directory
221
+ * @param {boolean} [options.local_files_only=false] - Only check local files
222
+ * @returns {Promise<string[]>} Array of available dtype strings (e.g., ['fp32', 'fp16', 'q4', 'q8'])
223
+ *
224
+ * @example
225
+ * const dtypes = await ModelRegistry.get_available_dtypes('onnx-community/all-MiniLM-L6-v2-ONNX');
226
+ * console.log(dtypes); // ['fp32', 'fp16', 'int8', 'uint8', 'q8', 'q4']
227
+ */
228
+ static async get_available_dtypes(modelId, options = {}) {
229
+ return get_available_dtypes(modelId, options);
230
+ }
231
+
232
+ /**
233
+ * Quickly checks if a model is fully cached by verifying `config.json` is present,
234
+ * then confirming all required files are cached.
235
+ * Returns a plain boolean — use `is_cached_files` if you need per-file detail.
236
+ *
237
+ * @param {string} modelId - The model id
238
+ * @param {Object} [options] - Optional parameters
239
+ * @param {string} [options.cache_dir] - Custom cache directory
240
+ * @param {string} [options.revision] - Model revision (default: 'main')
241
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
242
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
243
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
244
+ * @returns {Promise<boolean>} Whether all required files are cached
245
+ *
246
+ * @example
247
+ * const cached = await ModelRegistry.is_cached('onnx-community/bert-base-uncased-ONNX');
248
+ * console.log(cached); // true or false
249
+ */
250
+ static async is_cached(modelId, options = {}) {
251
+ return is_cached(modelId, options);
252
+ }
253
+
254
+ /**
255
+ * Checks if all files for a given model are already cached, with per-file detail.
256
+ * Automatically determines which files are needed using get_files().
257
+ *
258
+ * @param {string} modelId - The model id
259
+ * @param {Object} [options] - Optional parameters
260
+ * @param {string} [options.cache_dir] - Custom cache directory
261
+ * @param {string} [options.revision] - Model revision (default: 'main')
262
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
263
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
264
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
265
+ * @returns {Promise<import('./is_cached.js').CacheCheckResult>} Object with allCached boolean and files array with cache status
266
+ *
267
+ * @example
268
+ * const status = await ModelRegistry.is_cached_files('onnx-community/bert-base-uncased-ONNX');
269
+ * console.log(status.allCached); // true or false
270
+ * console.log(status.files); // [{ file: 'config.json', cached: true }, ...]
271
+ */
272
+ static async is_cached_files(modelId, options = {}) {
273
+ return is_cached_files(modelId, options);
274
+ }
275
+
276
+ /**
277
+ * Quickly checks if all files for a specific pipeline task are cached by verifying
278
+ * `config.json` is present, then confirming all required files are cached.
279
+ * Returns a plain boolean — use `is_pipeline_cached_files` if you need per-file detail.
280
+ *
281
+ * @param {string} task - The pipeline task (e.g., "text-generation", "background-removal")
282
+ * @param {string} modelId - The model id
283
+ * @param {Object} [options] - Optional parameters
284
+ * @param {string} [options.cache_dir] - Custom cache directory
285
+ * @param {string} [options.revision] - Model revision (default: 'main')
286
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
287
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
288
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
289
+ * @returns {Promise<boolean>} Whether all required files are cached
290
+ *
291
+ * @example
292
+ * const cached = await ModelRegistry.is_pipeline_cached('text-generation', 'onnx-community/gpt2-ONNX');
293
+ * console.log(cached); // true or false
294
+ */
295
+ static async is_pipeline_cached(task, modelId, options = {}) {
296
+ return is_pipeline_cached(task, modelId, options);
297
+ }
298
+
299
+ /**
300
+ * Checks if all files for a specific pipeline task are already cached, with per-file detail.
301
+ * Automatically determines which components are needed based on the task.
302
+ *
303
+ * @param {string} task - The pipeline task (e.g., "text-generation", "background-removal")
304
+ * @param {string} modelId - The model id
305
+ * @param {Object} [options] - Optional parameters
306
+ * @param {string} [options.cache_dir] - Custom cache directory
307
+ * @param {string} [options.revision] - Model revision (default: 'main')
308
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
309
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype=null] - Override dtype
310
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device=null] - Override device
311
+ * @returns {Promise<import('./is_cached.js').CacheCheckResult>} Object with allCached boolean and files array with cache status
312
+ *
313
+ * @example
314
+ * const status = await ModelRegistry.is_pipeline_cached_files('text-generation', 'onnx-community/gpt2-ONNX');
315
+ * console.log(status.allCached); // true or false
316
+ * console.log(status.files); // [{ file: 'config.json', cached: true }, ...]
317
+ */
318
+ static async is_pipeline_cached_files(task, modelId, options = {}) {
319
+ return is_pipeline_cached_files(task, modelId, options);
320
+ }
321
+
322
+ /**
323
+ * Get metadata for a specific file without downloading it.
324
+ *
325
+ * @param {string} path_or_repo_id - Model id or path
326
+ * @param {string} filename - The file name
327
+ * @param {import('../hub.js').PretrainedOptions} [options] - Optional parameters
328
+ * @returns {Promise<{exists: boolean, size?: number, contentType?: string, fromCache?: boolean}>} File metadata
329
+ *
330
+ * @example
331
+ * const metadata = await ModelRegistry.get_file_metadata('onnx-community/gpt2-ONNX', 'config.json');
332
+ * console.log(metadata.exists, metadata.size); // true, 665
333
+ */
334
+ static async get_file_metadata(path_or_repo_id, filename, options = {}) {
335
+ return get_file_metadata(path_or_repo_id, filename, options);
336
+ }
337
+
338
+ /**
339
+ * Clears all cached files for a given model.
340
+ * Automatically determines which files are needed and removes them from the cache.
341
+ *
342
+ * @param {string} modelId - The model id (e.g., "onnx-community/gpt2-ONNX")
343
+ * @param {Object} [options] - Optional parameters
344
+ * @param {string} [options.cache_dir] - Custom cache directory
345
+ * @param {string} [options.revision] - Model revision (default: 'main')
346
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
347
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype] - Override dtype
348
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device] - Override device
349
+ * @param {boolean} [options.include_tokenizer=true] - Whether to clear tokenizer files
350
+ * @param {boolean} [options.include_processor=true] - Whether to clear processor files
351
+ * @returns {Promise<import('./clear_cache.js').CacheClearResult>} Object with deletion statistics and file status
352
+ *
353
+ * @example
354
+ * const result = await ModelRegistry.clear_cache('onnx-community/bert-base-uncased-ONNX');
355
+ * console.log(`Deleted ${result.filesDeleted} of ${result.filesCached} cached files`);
356
+ */
357
+ static async clear_cache(modelId, options = {}) {
358
+ return clear_cache(modelId, options);
359
+ }
360
+
361
+ /**
362
+ * Clears all cached files for a specific pipeline task.
363
+ * Automatically determines which components are needed based on the task.
364
+ *
365
+ * @param {string} task - The pipeline task (e.g., "text-generation", "image-classification")
366
+ * @param {string} modelId - The model id (e.g., "onnx-community/gpt2-ONNX")
367
+ * @param {Object} [options] - Optional parameters
368
+ * @param {string} [options.cache_dir] - Custom cache directory
369
+ * @param {string} [options.revision] - Model revision (default: 'main')
370
+ * @param {import('../../configs.js').PretrainedConfig} [options.config] - Pre-loaded config
371
+ * @param {import('../dtypes.js').DataType|Record<string, import('../dtypes.js').DataType>} [options.dtype] - Override dtype
372
+ * @param {import('../devices.js').DeviceType|Record<string, import('../devices.js').DeviceType>} [options.device] - Override device
373
+ * @returns {Promise<import('./clear_cache.js').CacheClearResult>} Object with deletion statistics and file status
374
+ *
375
+ * @example
376
+ * const result = await ModelRegistry.clear_pipeline_cache('text-generation', 'onnx-community/gpt2-ONNX');
377
+ * console.log(`Deleted ${result.filesDeleted} of ${result.filesCached} cached files`);
378
+ */
379
+ static async clear_pipeline_cache(task, modelId, options = {}) {
380
+ return clear_pipeline_cache(task, modelId, options);
381
+ }
382
+ }