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

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 (165) hide show
  1. package/README.md +8 -3
  2. package/dist/ort-wasm-simd-threaded.jsep.mjs +28 -28
  3. package/dist/transformers.js +3093 -2100
  4. package/dist/transformers.min.js +17 -19
  5. package/dist/transformers.node.cjs +3079 -2059
  6. package/dist/transformers.node.min.cjs +19 -21
  7. package/dist/transformers.node.min.mjs +19 -21
  8. package/dist/transformers.node.mjs +3067 -2059
  9. package/dist/transformers.web.js +1295 -276
  10. package/dist/transformers.web.min.js +15 -15
  11. package/package.json +4 -4
  12. package/src/backends/onnx.js +66 -10
  13. package/src/backends/utils/cacheWasm.js +9 -6
  14. package/src/configs.js +51 -3
  15. package/src/env.js +66 -7
  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 +2 -1
  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 +14 -4
  25. package/src/models/models.js +5 -0
  26. package/src/models/paligemma/processing_paligemma.js +3 -2
  27. package/src/models/processors.js +2 -0
  28. package/src/models/qwen2_5_vl/modeling_qwen2_5_vl.js +5 -0
  29. package/src/models/qwen2_5_vl/processing_qwen2_5_vl.js +3 -0
  30. package/src/models/qwen2_vl/image_processing_qwen2_vl.js +54 -0
  31. package/src/models/qwen2_vl/modeling_qwen2_vl.js +8 -2
  32. package/src/models/qwen3_5/modeling_qwen3_5.js +3 -0
  33. package/src/models/qwen3_5_moe/modeling_qwen3_5_moe.js +3 -0
  34. package/src/models/qwen3_vl/modeling_qwen3_vl.js +3 -0
  35. package/src/models/qwen3_vl/processing_qwen3_vl.js +3 -0
  36. package/src/models/registry.js +7 -1
  37. package/src/models/session.js +16 -50
  38. package/src/models/whisper/feature_extraction_whisper.js +2 -1
  39. package/src/models/whisper/modeling_whisper.js +6 -5
  40. package/src/models/xlm/tokenization_xlm.js +2 -1
  41. package/src/pipelines/automatic-speech-recognition.js +3 -2
  42. package/src/pipelines/index.js +395 -0
  43. package/src/pipelines/text-generation.js +4 -0
  44. package/src/pipelines/text-to-audio.js +4 -2
  45. package/src/pipelines/zero-shot-classification.js +3 -2
  46. package/src/pipelines.js +104 -356
  47. package/src/tokenization_utils.js +42 -21
  48. package/src/transformers.js +6 -1
  49. package/src/utils/audio.js +2 -1
  50. package/src/utils/cache.js +4 -1
  51. package/src/utils/core.js +23 -1
  52. package/src/utils/devices.js +22 -0
  53. package/src/utils/dtypes.js +55 -0
  54. package/src/utils/hub/files.js +17 -2
  55. package/src/utils/hub/utils.js +10 -4
  56. package/src/utils/hub.js +57 -17
  57. package/src/utils/image.js +2 -1
  58. package/src/utils/logger.js +67 -0
  59. package/src/utils/model-loader.js +35 -17
  60. package/src/utils/model_registry/ModelRegistry.js +299 -0
  61. package/src/utils/model_registry/clear_cache.js +128 -0
  62. package/src/utils/model_registry/get_file_metadata.js +149 -0
  63. package/src/utils/model_registry/get_files.js +42 -0
  64. package/src/utils/model_registry/get_model_files.js +182 -0
  65. package/src/utils/model_registry/get_pipeline_files.js +53 -0
  66. package/src/utils/model_registry/get_processor_files.js +20 -0
  67. package/src/utils/model_registry/get_tokenizer_files.js +21 -0
  68. package/src/utils/model_registry/is_cached.js +92 -0
  69. package/src/utils/random.js +225 -0
  70. package/src/utils/tensor.js +8 -21
  71. package/src/utils/video.js +2 -2
  72. package/types/backends/onnx.d.ts.map +1 -1
  73. package/types/backends/utils/cacheWasm.d.ts.map +1 -1
  74. package/types/configs.d.ts.map +1 -1
  75. package/types/env.d.ts +42 -24
  76. package/types/env.d.ts.map +1 -1
  77. package/types/generation/logits_sampler.d.ts +2 -2
  78. package/types/generation/logits_sampler.d.ts.map +1 -1
  79. package/types/image_processors_utils.d.ts.map +1 -1
  80. package/types/models/afmoe/modeling_afmoe.d.ts +8 -0
  81. package/types/models/afmoe/modeling_afmoe.d.ts.map +1 -0
  82. package/types/models/auto/image_processing_auto.d.ts.map +1 -1
  83. package/types/models/auto/modeling_auto.d.ts.map +1 -1
  84. package/types/models/auto/tokenization_auto.d.ts.map +1 -1
  85. package/types/models/clap/feature_extraction_clap.d.ts.map +1 -1
  86. package/types/models/marian/tokenization_marian.d.ts.map +1 -1
  87. package/types/models/modeling_utils.d.ts.map +1 -1
  88. package/types/models/models.d.ts +5 -0
  89. package/types/models/paligemma/processing_paligemma.d.ts.map +1 -1
  90. package/types/models/processors.d.ts +2 -0
  91. package/types/models/qwen2_5_vl/modeling_qwen2_5_vl.d.ts +4 -0
  92. package/types/models/qwen2_5_vl/modeling_qwen2_5_vl.d.ts.map +1 -0
  93. package/types/models/qwen2_5_vl/processing_qwen2_5_vl.d.ts +4 -0
  94. package/types/models/qwen2_5_vl/processing_qwen2_5_vl.d.ts.map +1 -0
  95. package/types/models/qwen2_vl/image_processing_qwen2_vl.d.ts +3 -0
  96. package/types/models/qwen2_vl/image_processing_qwen2_vl.d.ts.map +1 -1
  97. package/types/models/qwen2_vl/modeling_qwen2_vl.d.ts +1 -0
  98. package/types/models/qwen2_vl/modeling_qwen2_vl.d.ts.map +1 -1
  99. package/types/models/qwen3_5/modeling_qwen3_5.d.ts +4 -0
  100. package/types/models/qwen3_5/modeling_qwen3_5.d.ts.map +1 -0
  101. package/types/models/qwen3_5_moe/modeling_qwen3_5_moe.d.ts +4 -0
  102. package/types/models/qwen3_5_moe/modeling_qwen3_5_moe.d.ts.map +1 -0
  103. package/types/models/qwen3_vl/modeling_qwen3_vl.d.ts +4 -0
  104. package/types/models/qwen3_vl/modeling_qwen3_vl.d.ts.map +1 -0
  105. package/types/models/qwen3_vl/processing_qwen3_vl.d.ts +4 -0
  106. package/types/models/qwen3_vl/processing_qwen3_vl.d.ts.map +1 -0
  107. package/types/models/registry.d.ts.map +1 -1
  108. package/types/models/session.d.ts.map +1 -1
  109. package/types/models/whisper/feature_extraction_whisper.d.ts.map +1 -1
  110. package/types/models/whisper/modeling_whisper.d.ts.map +1 -1
  111. package/types/models/xlm/tokenization_xlm.d.ts.map +1 -1
  112. package/types/pipelines/automatic-speech-recognition.d.ts.map +1 -1
  113. package/types/pipelines/index.d.ts +299 -0
  114. package/types/pipelines/index.d.ts.map +1 -0
  115. package/types/pipelines/text-generation.d.ts +5 -1
  116. package/types/pipelines/text-generation.d.ts.map +1 -1
  117. package/types/pipelines/text-to-audio.d.ts.map +1 -1
  118. package/types/pipelines/zero-shot-classification.d.ts.map +1 -1
  119. package/types/pipelines.d.ts +50 -291
  120. package/types/pipelines.d.ts.map +1 -1
  121. package/types/tokenization_utils.d.ts +44 -26
  122. package/types/tokenization_utils.d.ts.map +1 -1
  123. package/types/transformers.d.ts +4 -1
  124. package/types/transformers.d.ts.map +1 -1
  125. package/types/utils/audio.d.ts.map +1 -1
  126. package/types/utils/cache.d.ts +6 -0
  127. package/types/utils/cache.d.ts.map +1 -1
  128. package/types/utils/core.d.ts +59 -2
  129. package/types/utils/core.d.ts.map +1 -1
  130. package/types/utils/devices.d.ts +15 -0
  131. package/types/utils/devices.d.ts.map +1 -1
  132. package/types/utils/dtypes.d.ts +16 -0
  133. package/types/utils/dtypes.d.ts.map +1 -1
  134. package/types/utils/hub/files.d.ts +6 -0
  135. package/types/utils/hub/files.d.ts.map +1 -1
  136. package/types/utils/hub/utils.d.ts +2 -1
  137. package/types/utils/hub/utils.d.ts.map +1 -1
  138. package/types/utils/hub.d.ts +29 -0
  139. package/types/utils/hub.d.ts.map +1 -1
  140. package/types/utils/image.d.ts.map +1 -1
  141. package/types/utils/logger.d.ts +28 -0
  142. package/types/utils/logger.d.ts.map +1 -0
  143. package/types/utils/model-loader.d.ts +15 -0
  144. package/types/utils/model-loader.d.ts.map +1 -1
  145. package/types/utils/model_registry/ModelRegistry.d.ts +211 -0
  146. package/types/utils/model_registry/ModelRegistry.d.ts.map +1 -0
  147. package/types/utils/model_registry/clear_cache.d.ts +74 -0
  148. package/types/utils/model_registry/clear_cache.d.ts.map +1 -0
  149. package/types/utils/model_registry/get_file_metadata.d.ts +20 -0
  150. package/types/utils/model_registry/get_file_metadata.d.ts.map +1 -0
  151. package/types/utils/model_registry/get_files.d.ts +23 -0
  152. package/types/utils/model_registry/get_files.d.ts.map +1 -0
  153. package/types/utils/model_registry/get_model_files.d.ts +22 -0
  154. package/types/utils/model_registry/get_model_files.d.ts.map +1 -0
  155. package/types/utils/model_registry/get_pipeline_files.d.ts +21 -0
  156. package/types/utils/model_registry/get_pipeline_files.d.ts.map +1 -0
  157. package/types/utils/model_registry/get_processor_files.d.ts +9 -0
  158. package/types/utils/model_registry/get_processor_files.d.ts.map +1 -0
  159. package/types/utils/model_registry/get_tokenizer_files.d.ts +9 -0
  160. package/types/utils/model_registry/get_tokenizer_files.d.ts.map +1 -0
  161. package/types/utils/model_registry/is_cached.d.ts +62 -0
  162. package/types/utils/model_registry/is_cached.d.ts.map +1 -0
  163. package/types/utils/random.d.ts +86 -0
  164. package/types/utils/random.d.ts.map +1 -0
  165. package/types/utils/tensor.d.ts.map +1 -1
@@ -1,13 +1,13 @@
1
- var e0=Object.defineProperty;var us=(t,e)=>{for(var s in e)e0(t,s,{get:e[s],enumerable:!0})};var t0={},De=t0;var s0={},et=s0;var r0={},vg=r0;var n0="4.0.0-next.4",Ag=typeof process<"u",Mg=Ag&&process?.release?.name==="node",tr=!zg(De),Sg=!zg(et),o0=typeof globalThis.Deno<"u",Wv=typeof globalThis.Bun<"u",Og=typeof window<"u"&&typeof window.document<"u",Ig=typeof self<"u"&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),Nl=typeof self<"u"&&"caches"in self,i0=Mg||typeof navigator<"u"&&"gpu"in navigator,a0=typeof navigator<"u"&&"ml"in navigator,l0=()=>{if(typeof navigator>"u")return!1;let t=navigator.userAgent,s=(navigator.vendor||"").indexOf("Apple")>-1,r=!t.match(/CriOS|FxiOS|EdgiOS|OPiOS|mercury|brave/i)&&!t.includes("Chrome")&&!t.includes("Android");return s&&r},c0=l0(),ee=Object.freeze({IS_BROWSER_ENV:Og,IS_WEBWORKER_ENV:Ig,IS_WEB_CACHE_AVAILABLE:Nl,IS_WEBGPU_AVAILABLE:i0,IS_WEBNN_AVAILABLE:a0,IS_SAFARI:c0,IS_PROCESS_AVAILABLE:Ag,IS_NODE_ENV:Mg,IS_FS_AVAILABLE:tr,IS_PATH_AVAILABLE:Sg}),Ll=tr&&Sg,Do="./";if(Ll){let t=Object(import.meta).url;t?Do=et.dirname(et.dirname(vg.fileURLToPath(t))):typeof __dirname<"u"&&(Do=et.dirname(__dirname))}var u0=Ll?et.join(Do,"/.cache/"):null,Eg="/models/",p0=Ll?et.join(Do,Eg):Eg,_e={version:n0,backends:{onnx:{}},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(Og||Ig),localModelPath:p0,useFS:tr,useBrowserCache:Nl&&!o0,useFSCache:tr,cacheDir:u0,useCustomCache:!1,customCache:null,useWasmCache:Nl||tr,cacheKey:"transformers-cache"};function zg(t){return Object.keys(t).length===0}var d0=class{constructor(t){this.trie=this._build_trie(t)}_build_trie(t){let e=Object.create(null);for(let s of t){let r=e;for(let n=0;n<s.length;++n){let o=s[n];r=r[o]??=Object.create(null)}r.end=s}return e}split(t){let e=[],s=t.length,r=0,n=0;for(;n<s;){let o=this.trie,i=null,a=n;for(;a<s&&(o=o[t[a]]);)o.end&&(i=o.end),++a;i?(n>r&&e.push(t.slice(r,n)),e.push(i),n+=i.length,r=n):++n}return r<s&&e.push(t.slice(r)),e}},Tg=d0,_0=class{constructor(t){this.content=t.content,this.id=t.id,this.single_word=t.single_word??!1,this.lstrip=t.lstrip??!1,this.rstrip=t.rstrip??!1,this.special=t.special??!1,this.normalized=t.normalized??!this.special}},f0=_0,Fg=(()=>{let t=[...Array.from({length:94},(n,o)=>o+33),...Array.from({length:12},(n,o)=>o+161),...Array.from({length:82},(n,o)=>o+174)],e=t.slice(),s=0;for(let n=0;n<256;++n)t.includes(n)||(t.push(n),e.push(256+s),s+=1);let r=e.map(n=>String.fromCharCode(n));return Object.fromEntries(t.map((n,o)=>[n,r[o]]))})(),m0=t=>Object.fromEntries(Object.entries(t).map(([e,s])=>[s,e])),h0=m0(Fg),Pg=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",x0=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"],["(?i:[sdmt]|ll|ve|re)","(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])"],["[^\\r\\n\\p{L}\\p{N}]?+","[^\\r\\n\\p{L}\\p{N}]?"],["[^\\s\\p{L}\\p{N}]++","[^\\s\\p{L}\\p{N}]+"],[` ?[^(\\s|[${Pg}])]+`,` ?[^\\s${Pg}]+`]]),jo="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",Rl=t=>t.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n't/g,"n't").replace(/ 'm/g,"'m").replace(/ 's/g,"'s").replace(/ 've/g,"'ve").replace(/ 're/g,"'re"),Bo=(t,e=!0)=>{if(t.Regex!==void 0){let s=t.Regex.replace(/\\([#&~])/g,"$1");for(let[r,n]of x0)s=s.replaceAll(r,n);try{return new RegExp(s,"gu")}catch(r){if(!(r instanceof SyntaxError)||!r.message.toLowerCase().includes("invalid property name"))throw r;let n=!1,o=s.replace(/(\\[pP])\{([^}=]+)\}/g,(i,a,l)=>{try{return new RegExp(`\\p{${l}}`,"u"),`${a}{${l}}`}catch{return n=!0,`${a}{Script=${l}}`}});if(!n)throw r;try{return new RegExp(o,"gu")}catch{throw r}}}else if(t.String!==void 0){let s=g0(t.String);return new RegExp(e?s:`(${s})`,"gu")}else return console.warn("Unknown pattern type:",t),null},g0=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),w0=(t,e,s)=>{let r=[],n=0;for(;n<t.length;){if(r.push(t[n]),(e.get(t[n])??s)!==s){++n;continue}for(;++n<t.length&&(e.get(t[n])??s)===s;)e.get(r.at(-1))!==s&&(r[r.length-1]+=t[n])}return r},y0=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,b0=t=>Number.isInteger(t)||typeof t=="bigint",k0=t=>{let e=0;for(let s of t)++e;return e},v0=t=>Dg(t.toLowerCase()),tt=(...t)=>Array.prototype.concat.apply([],t),Fl=t=>new Map(Object.entries(t)),E0=(t,e)=>{let s=[],r=0;for(let n of t.matchAll(e)){let o=n[0];r<n.index&&s.push(t.slice(r,n.index)),o.length>0&&s.push(o),r=n.index+o.length}return r<t.length&&s.push(t.slice(r)),s},Dg=t=>t.replace(/\p{M}/gu,""),Cg=(t,e,s=[])=>{if(!t||Array.isArray(t)||typeof t!="object")return`${e} must be a valid object`;for(let r of s)if(!(r in t))return`${e} must contain a "${r}" property`;return null},A0=t=>t.match(/\S+/g)||[],M0=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},sr=M0,S0=class extends sr{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},wt=S0,O0=class extends wt{tokenize_chinese_chars(t){let e=[];for(let s=0;s<t.length;++s){let r=t[s],n=r.charCodeAt(0);y0(n)?(e.push(" "),e.push(r),e.push(" ")):e.push(r)}return e.join("")}strip_accents(t){return t.normalize("NFD").replace(/\p{Mn}/gu,"")}is_control(t){switch(t){case" ":case`
2
- `:case"\r":return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(t)}}clean_text(t){let e=[];for(let s of t){let r=s.charCodeAt(0);r===0||r===65533||this.is_control(s)||(/^\s$/.test(s)?e.push(" "):e.push(s))}return e.join("")}normalize(t){return this.config.clean_text&&(t=this.clean_text(t)),this.config.handle_chinese_chars&&(t=this.tokenize_chinese_chars(t)),this.config.lowercase?(t=t.toLowerCase(),this.config.strip_accents!==!1&&(t=this.strip_accents(t))):this.config.strip_accents&&(t=this.strip_accents(t)),t}},I0=O0,z0=class extends wt{constructor(t){super(t),this.charsmap=t.precompiled_charsmap??null}normalize(t){return t=t.replace(/[\u0001-\u0008\u000B\u000E-\u001F\u007F\u008F\u009F]/gm,""),t=t.replace(/[\u0009\u000A\u000C\u000D\u00A0\u1680\u2000-\u200F\u2028\u2029\u202F\u205F\u2581\u3000\uFEFF\uFFFD]/gm," "),t.includes("\uFF5E")?t=t.split("\uFF5E").map(s=>s.normalize("NFKC")).join("\uFF5E"):t=t.normalize("NFKC"),t}},T0=z0,P0=class extends wt{constructor(t){super(t),this.normalizers=(t.normalizers??[]).map(e=>jg(e))}normalize(t){return this.normalizers.reduce((e,s)=>s?s.normalize(e):e,t)}},C0=P0,N0=class extends wt{normalize(t){let e=Bo(this.config.pattern??{});return e===null?t:t.replaceAll(e,this.config.content??"")}},L0=N0,$0=class extends wt{constructor(){super(...arguments),this.form="NFC"}normalize(t){return t=t.normalize(this.form),t}},Uo=$0,R0=class extends Uo{constructor(){super(...arguments),this.form="NFC"}},F0=R0,D0=class extends Uo{constructor(){super(...arguments),this.form="NFD"}},j0=D0,B0=class extends Uo{constructor(){super(...arguments),this.form="NFKC"}},U0=B0,q0=class extends Uo{constructor(){super(...arguments),this.form="NFKD"}},G0=q0,W0=class extends wt{normalize(t){return this.config.strip_left&&this.config.strip_right?t=t.trim():(this.config.strip_left&&(t=t.trimStart()),this.config.strip_right&&(t=t.trimEnd())),t}},V0=W0,H0=class extends wt{normalize(t){return Dg(t)}},X0=H0,K0=class extends wt{normalize(t){return t.toLowerCase()}},Q0=K0,J0=class extends wt{normalize(t){return t=this.config.prepend+t,t}},Y0=J0;function Z0(t){if(t===null)return null;switch(t.type){case"BertNormalizer":return new I0(t);case"Precompiled":return new T0(t);case"Sequence":return new C0(t);case"Replace":return new L0(t);case"NFC":return new F0(t);case"NFD":return new j0(t);case"NFKC":return new U0(t);case"NFKD":return new G0(t);case"Strip":return new V0(t);case"StripAccents":return new X0(t);case"Lowercase":return new Q0(t);case"Prepend":return new Y0(t);default:throw new Error(`Unknown Normalizer type: ${t.type}`)}}var jg=Z0,eb=class extends sr{pre_tokenize(t,e){return(Array.isArray(t)?t.map(s=>this.pre_tokenize_text(s,e)):this.pre_tokenize_text(t,e)).flat()}_call(t,e){return this.pre_tokenize(t,e)}},st=eb,tb=class extends st{constructor(t){super(),this.config=t,this.add_prefix_space=this.config.add_prefix_space??!1,this.trim_offsets=this.config.trim_offsets??!1,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=Fg,this.text_encoder=new TextEncoder}pre_tokenize_text(t,e){return this.add_prefix_space&&!t.startsWith(" ")&&(t=" "+t),(this.use_regex?t.match(this.pattern)||[]:[t]).map(r=>Array.from(this.text_encoder.encode(r),n=>this.byte_encoder[n]).join(""))}},sb=tb,rb=class extends st{pre_tokenize_text(t,e){return t.match(/\w+|[^\w\s]+/g)||[]}},nb=rb,ob=class extends st{constructor(t){super(),this.replacement=t.replacement??"\u2581",this.str_rep=t.str_rep||this.replacement,this.prepend_scheme=t.prepend_scheme??"always"}pre_tokenize_text(t,e){let{section_index:s=void 0}=e??{},r=t.replaceAll(" ",this.str_rep);return!r.startsWith(this.replacement)&&(this.prepend_scheme==="always"||this.prepend_scheme==="first"&&s===0)&&(r=this.str_rep+r),[r]}},ib=ob,ab=class extends st{constructor(t){super(),this.config=t,this.pattern=Bo(this.config.pattern??{},this.config.invert??!0)}pre_tokenize_text(t){return this.pattern===null?[]:this.config.invert?t.match(this.pattern)||[]:this.config.behavior?.toLowerCase()==="removed"?t.split(this.pattern).filter(e=>e):E0(t,this.pattern)}},lb=ab,cb=class extends st{constructor(t){super(),this.config=t,this.pattern=new RegExp(`[^${jo}]+|[${jo}]+`,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},ub=cb,pb=class extends st{constructor(t){super(),this.config=t;let e=`[^\\d]+|\\d${this.config.individual_digits?"":"+"}`;this.pattern=new RegExp(e,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},db=pb,_b=class extends st{constructor(){super(),this.pattern=new RegExp(`[^\\s${jo}]+|[${jo}]`,"gu")}pre_tokenize_text(t,e){return t.trim().match(this.pattern)||[]}},fb=_b,mb=class extends st{constructor(t){super(),this.config=t,this.pattern=Bo(this.config.pattern??{}),this.content=this.config.content??""}pre_tokenize_text(t){return this.pattern===null?[t]:[t.replaceAll(this.pattern,this.config.content??"")]}},hb=mb,xb=class extends st{constructor(t){super(),this.tokenizers=(t.pretokenizers??[]).map(e=>Bg(e))}pre_tokenize_text(t,e){return this.tokenizers.reduce((s,r)=>r?r.pre_tokenize(s,e):s,[t])}},gb=xb,wb=class extends st{pre_tokenize_text(t){return A0(t)}},yb=wb,bb=class extends st{constructor(t){super(),this.config=t,this._length=t.length}pre_tokenize_text(t){let e=[];for(let s=0;s<t.length;s+=this._length)e.push(t.slice(s,s+this._length));return e}},kb=bb;function vb(t){if(t===null)return null;switch(t.type){case"BertPreTokenizer":return new fb;case"Sequence":return new gb(t);case"Whitespace":return new nb;case"WhitespaceSplit":return new yb;case"Metaspace":return new ib(t);case"ByteLevel":return new sb(t);case"Split":return new lb(t);case"Punctuation":return new ub(t);case"Digits":return new db(t);case"Replace":return new hb(t);case"FixedLength":return new kb(t);default:throw new Error(`Unknown PreTokenizer type: ${t.type}`)}}var Bg=vb,Eb=class extends sr{constructor(t){super(),this.config=t,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}_call(t){let e=this.encode(t);return this.fuse_unk&&(e=w0(e,this.tokens_to_ids,this.unk_token_id)),e}},qo=Eb,Ab=class extends qo{constructor(t){super(t),this.max_input_chars_per_word=100,this.tokens_to_ids=Fl(t.vocab),this.unk_token_id=this.tokens_to_ids.get(t.unk_token),this.unk_token=t.unk_token,this.max_input_chars_per_word=t.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(let[e,s]of this.tokens_to_ids)this.vocab[s]=e}encode(t){let e=[];for(let s of t){let r=[...s];if(r.length>this.max_input_chars_per_word){e.push(this.unk_token);continue}let n=!1,o=0,i=[];for(;o<r.length;){let a=r.length,l=null;for(;o<a;){let c=r.slice(o,a).join("");if(o>0&&(c=this.config.continuing_subword_prefix+c),this.tokens_to_ids.has(c)){l=c;break}--a}if(l===null){n=!0;break}i.push(l),o=a}n?e.push(this.unk_token):e.push(...i)}return e}},Ng=Ab,Lg=class Ug{constructor(e,s){this.is_leaf=e,this.children=s}static default(){return new Ug(!1,new Map)}},Mb=class{constructor(){this.root=Lg.default()}extend(t){for(let e of t)this.push(e)}push(t){let e=this.root;for(let s of t){let r=e.children.get(s);r===void 0&&(r=Lg.default(),e.children.set(s,r)),e=r}e.is_leaf=!0}*common_prefix_search(t){let e=this.root;if(e===void 0)return;let s="";for(let r of t){if(s+=r,e=e.children.get(r),e===void 0)return;e.is_leaf&&(yield s)}}},Sb=Mb,$l=class qg{constructor(e,s,r,n,o){this.token_id=e,this.node_id=s,this.pos=r,this.length=n,this.score=o,this.prev=null,this.backtrace_score=0}clone(){let e=new qg(this.token_id,this.node_id,this.pos,this.length,this.score);return e.prev=this.prev,e.backtrace_score=this.backtrace_score,e}},Ob=class{constructor(t,e,s){this.chars=Array.from(t),this.len=this.chars.length,this.bos_token_id=e,this.eos_token_id=s,this.nodes=[],this.begin_nodes=Array.from({length:this.len+1},()=>[]),this.end_nodes=Array.from({length:this.len+1},()=>[]);let r=new $l(this.bos_token_id??0,0,0,0,0),n=new $l(this.eos_token_id??0,1,this.len,0,0);this.nodes.push(r.clone()),this.nodes.push(n.clone()),this.begin_nodes[this.len].push(n),this.end_nodes[0].push(r)}insert(t,e,s,r){let n=this.nodes.length,o=new $l(r,n,t,e,s);this.begin_nodes[t].push(o),this.end_nodes[t+e].push(o),this.nodes.push(o)}viterbi(){let t=this.len,e=0;for(;e<=t;){if(this.begin_nodes[e].length==0)return[];for(let i of this.begin_nodes[e]){i.prev=null;let a=0,l=null;for(let c of this.end_nodes[e]){let u=c.backtrace_score+i.score;(l===null||u>a)&&(l=c.clone(),a=u)}if(l!==null)i.prev=l,i.backtrace_score=a;else return[]}++e}let s=[],n=this.begin_nodes[t][0].prev;if(n===null)return[];let o=n.clone();for(;o.prev!==null;)s.push(o.clone()),o=o.clone().prev.clone();return s.reverse(),s}piece(t){return this.chars.slice(t.pos,t.pos+t.length).join("")}tokens(){return this.viterbi().map(e=>this.piece(e))}token_ids(){return this.viterbi().map(e=>e.token_id)}},Ib=Ob;function zb(t){if(t.length===0)throw new Error("Array must not be empty");let e=t[0],s=0;for(let r=1;r<t.length;++r)t[r]<e&&(e=t[r],s=r);return[e,s]}var Tb=class extends qo{constructor(t,e){super(t);let s=t.vocab.length;this.vocab=new Array(s),this.scores=new Array(s);for(let r=0;r<s;++r)[this.vocab[r],this.scores[r]]=t.vocab[r];this.unk_token_id=t.unk_id,this.unk_token=this.vocab[t.unk_id],this.tokens_to_ids=new Map(this.vocab.map((r,n)=>[r,n])),this.bos_token=" ",this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=e,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.unk_token=this.vocab[this.unk_token_id],this.min_score=zb(this.scores)[0],this.unk_score=this.min_score-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new Sb,this.trie.extend(this.vocab),this.fuse_unk=!0}populate_nodes(t){let e=t.chars,s=1,r=0;for(;r<e.length;){let n=!1,o=[],i=e.slice(r).join(""),a=this.trie.common_prefix_search(i);for(let l of a){o.push(l);let c=this.tokens_to_ids.get(l),u=this.scores[c],p=k0(l);t.insert(r,p,u,c),!n&&p===s&&(n=!0)}n||t.insert(r,s,this.unk_score,this.unk_token_id),r+=s}}tokenize(t){let e=new Ib(t,this.bos_token_id,this.eos_token_id);return this.populate_nodes(e),e.tokens()}encode(t){let e=[];for(let s of t){let r=this.tokenize(s);e.push(...r)}return e}},$g=Tb,Pb=class{constructor(t=(s,r)=>s>r,e=1/0){this._heap=[],this._comparator=t,this._max_size=e}get size(){return this._heap.length}is_empty(){return this.size===0}peek(){return this._heap[0]}push(...t){return this.extend(t)}extend(t){for(let e of t)if(this.size<this._max_size)this._heap.push(e),this._sift_up();else{let s=this._smallest();this._comparator(e,this._heap[s])&&(this._heap[s]=e,this._sift_up_from(s))}return this.size}pop(){let t=this.peek(),e=this.size-1;return e>0&&this._swap(0,e),this._heap.pop(),this._sift_down(),t}replace(t){let e=this.peek();return this._heap[0]=t,this._sift_down(),e}_parent(t){return(t+1>>>1)-1}_left(t){return(t<<1)+1}_right(t){return t+1<<1}_greater(t,e){return this._comparator(this._heap[t],this._heap[e])}_swap(t,e){let s=this._heap[t];this._heap[t]=this._heap[e],this._heap[e]=s}_sift_up(){this._sift_up_from(this.size-1)}_sift_up_from(t){for(;t>0&&this._greater(t,this._parent(t));)this._swap(t,this._parent(t)),t=this._parent(t)}_sift_down(){let t=0;for(;this._left(t)<this.size&&this._greater(this._left(t),t)||this._right(t)<this.size&&this._greater(this._right(t),t);){let e=this._right(t)<this.size&&this._greater(this._right(t),this._left(t))?this._right(t):this._left(t);this._swap(t,e),t=e}}_smallest(){return 2**Math.floor(Math.log2(this.size))-1}},Cb=Pb,Nb=class{constructor(t){this.capacity=t,this.cache=new Map}get(t){if(!this.cache.has(t))return;let e=this.cache.get(t);return this.cache.delete(t),this.cache.set(t,e),e}put(t,e){this.cache.has(t)&&this.cache.delete(t),this.cache.set(t,e),this.cache.size>this.capacity&&this.cache.delete(this.cache.keys().next().value)}clear(){this.cache.clear()}},Lb=Nb,$b=class extends qo{constructor(t){super(t),this.tokens_to_ids=Fl(t.vocab),this.unk_token_id=this.tokens_to_ids.get(t.unk_token),this.unk_token=t.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(let[s,r]of this.tokens_to_ids)this.vocab[r]=s;let e=Array.isArray(t.merges[0]);this.merges=e?t.merges:t.merges.map(s=>s.split(" ",2)),this.bpe_ranks=new Map(this.merges.map((s,r)=>[JSON.stringify(s),r])),this.end_of_word_suffix=t.end_of_word_suffix,this.continuing_subword_suffix=t.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.ignore_merges=this.config.ignore_merges??!1,this.max_length_to_cache=256,this.cache_capacity=1e4,this.cache=new Lb(this.cache_capacity)}clear_cache(){this.cache.clear()}bpe(t){if(t.length===0)return[];let e=this.cache.get(t);if(e!==void 0)return e;let s=Array.from(t);this.end_of_word_suffix&&(s[s.length-1]+=this.end_of_word_suffix);let r=[];if(s.length>1){let n=new Cb((a,l)=>a.score<l.score),o={token:s[0],bias:0,prev:null,next:null},i=o;for(let a=1;a<s.length;++a){let l={bias:a/s.length,token:s[a],prev:i,next:null};i.next=l,this.add_node(n,i),i=l}for(;!n.is_empty();){let a=n.pop();if(a.deleted||!a.next||a.next.deleted)continue;if(a.deleted=!0,a.next.deleted=!0,a.prev){let c={...a.prev};a.prev.deleted=!0,a.prev=c,c.prev?c.prev.next=c:o=c}let l={token:a.token+a.next.token,bias:a.bias,prev:a.prev,next:a.next.next};l.prev?(l.prev.next=l,this.add_node(n,l.prev)):o=l,l.next&&(l.next.prev=l,this.add_node(n,l))}for(let a=o;a!==null;a=a.next)r.push(a.token)}else r=s;if(this.continuing_subword_suffix)for(let n=0;n<r.length-1;++n)r[n]+=this.continuing_subword_suffix;return t.length<this.max_length_to_cache&&this.cache.put(t,r),r}add_node(t,e){let s=this.bpe_ranks.get(JSON.stringify([e.token,e.next.token]));s!==void 0&&(e.score=s+e.bias,t.push(e))}encode(t){let e=[];for(let s of t){if(this.ignore_merges&&this.tokens_to_ids.has(s)){e.push(s);continue}let r=this.bpe(s);for(let n of r)if(this.tokens_to_ids.has(n))e.push(n);else if(this.byte_fallback){let o=Array.from(this.text_encoder.encode(n)).map(i=>`<0x${i.toString(16).toUpperCase().padStart(2,"0")}>`);o.every(i=>this.tokens_to_ids.has(i))?e.push(...o):e.push(this.unk_token)}else e.push(this.unk_token)}return e}},Rg=$b,Rb=class extends qo{constructor(t,e){super(t);let s=t.vocab;this.tokens_to_ids=Fl(e.target_lang?s[e.target_lang]:s),this.bos_token=e.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=e.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=e.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=e.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(let[r,n]of this.tokens_to_ids)this.vocab[n]=r}encode(t){return t}},Fb=Rb;function Db(t,e){switch(t.type){case"WordPiece":return new Ng(t);case"Unigram":return new $g(t,e.eos_token);case"BPE":return new Rg(t);default:if(t.vocab)return Array.isArray(t.vocab)?new $g(t,e.eos_token):Object.hasOwn(t,"continuing_subword_prefix")&&Object.hasOwn(t,"unk_token")?Object.hasOwn(t,"merges")?new Rg(t):new Ng(t):new Fb(t,{target_lang:e.target_lang,bos_token:e.bos_token,eos_token:e.eos_token,pad_token:e.pad_token,unk_token:e.unk_token});throw new Error(`Unknown TokenizerModel type: ${t?.type}`)}}var jb=Db,Bb=class extends sr{constructor(t){super(),this.config=t}_call(t,...e){return this.post_process(t,...e)}},rr=Bb,Ub=class extends rr{post_process(t,e=null,s=!0){let r=e===null?this.config.single:this.config.pair,n=[],o=[];for(let i of r)"SpecialToken"in i?s&&(n.push(i.SpecialToken.id),o.push(i.SpecialToken.type_id)):"Sequence"in i&&(i.Sequence.id==="A"?(n=tt(n,t),o=tt(o,new Array(t.length).fill(i.Sequence.type_id))):i.Sequence.id==="B"&&(n=tt(n,e),o=tt(o,new Array(e.length).fill(i.Sequence.type_id))));return{tokens:n,token_type_ids:o}}},qb=Ub,Gb=class extends rr{post_process(t,e=null){return{tokens:t,tokens_pair:e}}},Wb=Gb,Vb=class extends rr{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e=null,s=!0){s&&(t=tt([this.cls[0]],t,[this.sep[0]]));let r=new Array(t.length).fill(0);if(e){let n=[],o=s?[this.sep[0]]:[];t=tt(t,n,e,o),r=tt(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},Hb=Vb,Xb=class extends rr{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e,s=!0){s&&(t=tt([this.cls[0]],t,[this.sep[0]]));let r=new Array(t.length).fill(0);if(e){let n=s?[this.sep[0]]:[],o=s?[this.sep[0]]:[];t=tt(t,n,e,o),r=tt(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},Kb=Xb,Qb=class extends rr{constructor(t){super(t),this.processors=(t.processors??[]).map(e=>Gg(e))}post_process(t,e=null,s=!0){let r={tokens:t,tokens_pair:e};for(let n of this.processors)r=n.post_process(r.tokens,r.tokens_pair,s);return r}},Jb=Qb;function Yb(t){if(t===null)return null;switch(t.type){case"TemplateProcessing":return new qb(t);case"ByteLevel":return new Wb(t);case"BertProcessing":return new Hb(t);case"RobertaProcessing":return new Kb(t);case"Sequence":return new Jb(t);default:throw new Error(`Unknown PostProcessor type: ${t.type}`)}}var Gg=Yb,Zb=class extends sr{constructor(t){super(),this.config=t,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets="trim_offsets"in t?t.trim_offsets:!1}_call(t){return this.decode(t)}decode(t){return this.decode_chain(t).join("")}},We=Zb,e1=class extends We{constructor(t){super(t),this.byte_decoder=h0,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(t){let e=t.join(""),s=new Uint8Array([...e].map(r=>this.byte_decoder[r]));return this.text_decoder.decode(s)}decode_chain(t){let e=[],s=[];for(let r of t)this.added_tokens.find(n=>n.content===r)!==void 0?(s.length>0&&(e.push(this.convert_tokens_to_string(s)),s=[]),e.push(r)):s.push(r);return s.length>0&&e.push(this.convert_tokens_to_string(s)),e}},t1=e1,s1=class extends We{constructor(t){super(t),this.cleanup=t.cleanup}decode_chain(t){return t.map((e,s)=>{if(s!==0){let r=this.config.prefix;r&&e.startsWith(r)?e=e.replace(r,""):e=" "+e}return this.cleanup&&(e=Rl(e)),e})}},r1=s1,n1=class extends We{constructor(t){super(t),this.replacement=t.replacement??"\u2581"}decode_chain(t){let e=[];for(let s=0;s<t.length;++s){let r=t[s].replaceAll(this.replacement," ");s==0&&r.startsWith(" ")&&(r=r.substring(1)),e.push(r)}return e}},o1=n1,i1=class extends We{constructor(t){super(t),this.suffix=t.suffix??""}decode_chain(t){return t.map((e,s)=>e.replaceAll(this.suffix,s===t.length-1?"":" "))}},a1=i1,l1=class extends We{constructor(t){super(t),this.pad_token=t.pad_token??"",this.word_delimiter_token=t.word_delimiter_token??"",this.cleanup=t.cleanup}convert_tokens_to_string(t){if(t.length===0)return"";let e=[t[0]];for(let n=1;n<t.length;++n)t[n]!==e.at(-1)&&e.push(t[n]);let r=e.filter(n=>n!==this.pad_token).join("");return this.cleanup&&(r=Rl(r).replaceAll(this.word_delimiter_token," ").trim()),r}decode_chain(t){return[this.convert_tokens_to_string(t)]}},c1=l1,u1=class extends We{constructor(t){super(t),this.decoders=(t.decoders??[]).map(e=>Wg(e))}decode_chain(t){return this.decoders.reduce((e,s)=>s.decode_chain(e),t)}},p1=u1,d1=class extends We{decode_chain(t){let e=Bo(this.config.pattern),s=this.config.content??"";return e===null?t:t.map(r=>r.replaceAll(e,s))}},_1=d1,f1=class extends We{decode_chain(t){return[t.join("")]}},m1=f1,h1=class extends We{constructor(t){super(t),this.content=t.content??"",this.start=t.start??0,this.stop=t.stop??0}decode_chain(t){return t.map(e=>{let s=0;for(let n=0;n<this.start&&e[n]===this.content;++n){s=n+1;continue}let r=e.length;for(let n=0;n<this.stop;++n){let o=e.length-n-1;if(e[o]===this.content){r=o;continue}else break}return e.slice(s,r)})}},x1=h1,g1=class extends We{constructor(t){super(t),this.text_decoder=new TextDecoder}decode_chain(t){let e=[],s=[];for(let r of t){let n=null;if(r.length===6&&r.startsWith("<0x")&&r.endsWith(">")){let o=parseInt(r.slice(3,5),16);isNaN(o)||(n=o)}if(n!==null)s.push(n);else{if(s.length>0){let o=this.text_decoder.decode(Uint8Array.from(s));e.push(o),s=[]}e.push(r)}}if(s.length>0){let r=this.text_decoder.decode(Uint8Array.from(s));e.push(r),s=[]}return e}},w1=g1;function y1(t){if(t===null)return null;switch(t.type){case"ByteLevel":return new t1(t);case"WordPiece":return new r1(t);case"Metaspace":return new o1(t);case"BPEDecoder":return new a1(t);case"CTC":return new c1(t);case"Sequence":return new p1(t);case"Replace":return new _1(t);case"Fuse":return new m1(t);case"Strip":return new x1(t);case"ByteFallback":return new w1(t);default:throw new Error(`Unknown Decoder type: ${t.type}`)}}var Wg=y1,b1=class{constructor(t,e){let s=Cg(t,"Tokenizer",["model","decoder","post_processor","pre_tokenizer","normalizer"]);if(s)throw new Error(s);let r=Cg(e,"Config");if(r)throw new Error(r);this.tokenizer=t,this.config=e,this.normalizer=jg(this.tokenizer.normalizer),this.pre_tokenizer=Bg(this.tokenizer.pre_tokenizer),this.model=jb(this.tokenizer.model,this.config),this.post_processor=Gg(this.tokenizer.post_processor),this.decoder=Wg(this.tokenizer.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];let n=[],o=[];this.added_tokens_map=new Map;for(let i of this.tokenizer.added_tokens){let a=new f0(i);if(this.added_tokens.push(a),this.model.tokens_to_ids.set(a.content,a.id),this.model.vocab[a.id]=a.content,a.special&&(this.special_tokens.push(a.content),this.all_special_ids.push(a.id)),this.added_tokens_map.set(a.content,a),a.normalized&&this.normalizer!==null){let l=this.normalizer(a.content);o.push(l),this.added_tokens_map.set(l,a)}else n.push(a.content)}(this.config.additional_special_tokens??[]).forEach(i=>{this.special_tokens.includes(i)||this.special_tokens.push(i)}),this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.splitter_unnormalized=new Tg(n),this.splitter_normalized=new Tg(o),this.remove_space=this.config.remove_space,this.clean_up_tokenization_spaces=this.config.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=this.config.do_lowercase_and_remove_accent??!1}encode(t,{text_pair:e=null,add_special_tokens:s=!0,return_token_type_ids:r=null}={}){let{tokens:n,token_type_ids:o}=this.tokenize_helper(t,{text_pair:e,add_special_tokens:s}),i=n.map(l=>this.added_tokens_map.get(l)?.id??this.model.tokens_to_ids.get(l)??this.model.unk_token_id),a={ids:i,tokens:n,attention_mask:new Array(i.length).fill(1)};return r&&o&&(a.token_type_ids=o),a}decode(t,e={}){if(!Array.isArray(t)||t.length===0||!b0(t[0]))throw Error("token_ids must be a non-empty array of integers.");let s=t.map(n=>this.model.vocab[Number(n)]??this.model.unk_token);e.skip_special_tokens&&(s=s.filter(n=>!this.special_tokens.includes(n)));let r=this.decoder?this.decoder(s):s.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(r=r.replaceAll(this.decoder.end_of_word_suffix," "),e.skip_special_tokens&&(r=r.trim())),(e.clean_up_tokenization_spaces??this.clean_up_tokenization_spaces)&&(r=Rl(r)),r}tokenize(t,{text_pair:e=null,add_special_tokens:s=!1}={}){return this.tokenize_helper(t,{text_pair:e,add_special_tokens:s}).tokens}encode_text(t){if(t===null)return null;let e=this.splitter_unnormalized.split(t);return e.forEach((s,r)=>{let n=this.added_tokens_map.get(s);n&&(n.lstrip&&r>0&&(e[r-1]=e[r-1].trimEnd()),n.rstrip&&r<e.length-1&&(e[r+1]=e[r+1].trimStart()))}),e.flatMap((s,r)=>{if(s.length===0)return[];if(this.added_tokens_map.has(s))return[s];if(this.remove_space===!0&&(s=s.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(s=v0(s)),this.normalizer!==null&&(s=this.normalizer(s)),s.length===0)return[];let n=this.splitter_normalized.split(s);return n.forEach((o,i)=>{let a=this.added_tokens_map.get(o);a&&(a.lstrip&&i>0&&(n[i-1]=n[i-1].trimEnd()),a.rstrip&&i<n.length-1&&(n[i+1]=n[i+1].trimStart()))}),n.flatMap(o=>{if(o.length===0)return[];if(this.added_tokens_map.has(o))return[o];let i=this.pre_tokenizer!==null?this.pre_tokenizer(o,{section_index:r}):[o];return this.model(i)})})}tokenize_helper(t,{text_pair:e=null,add_special_tokens:s=!0}){let r=this.encode_text(t),n=this.encode_text(e||null);return this.post_processor?this.post_processor(r,n,s):{tokens:tt(r??[],n??[])}}token_to_id(t){return this.model.tokens_to_ids.get(t)}id_to_token(t){return this.model.vocab[t]}get_added_tokens_decoder(){let t=new Map;for(let e of this.added_tokens)t.set(e.id,e);return t}get_vocab(t=!0){let e=new Map;for(let s=0;s<this.model.vocab.length;++s){let r=this.model.vocab[s];(t||!this.added_tokens_map.has(r))&&e.set(r,s)}return e}},Vg=b1;var M=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",OpenCurlyBracket:"OpenCurlyBracket",CloseCurlyBracket:"CloseCurlyBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Comment:"Comment"}),Ve=class{constructor(t,e){this.value=t,this.type=e}};function Hg(t){return/\w/.test(t)}function nr(t){return/[0-9]/.test(t)}function Xg(t){return/\s/.test(t)}var k1=[["{%",M.OpenStatement],["%}",M.CloseStatement],["{{",M.OpenExpression],["}}",M.CloseExpression],["(",M.OpenParen],[")",M.CloseParen],["{",M.OpenCurlyBracket],["}",M.CloseCurlyBracket],["[",M.OpenSquareBracket],["]",M.CloseSquareBracket],[",",M.Comma],[".",M.Dot],[":",M.Colon],["|",M.Pipe],["<=",M.ComparisonBinaryOperator],[">=",M.ComparisonBinaryOperator],["==",M.ComparisonBinaryOperator],["!=",M.ComparisonBinaryOperator],["<",M.ComparisonBinaryOperator],[">",M.ComparisonBinaryOperator],["+",M.AdditiveBinaryOperator],["-",M.AdditiveBinaryOperator],["~",M.AdditiveBinaryOperator],["*",M.MultiplicativeBinaryOperator],["/",M.MultiplicativeBinaryOperator],["%",M.MultiplicativeBinaryOperator],["=",M.Equals]],v1=new Map([["n",`
3
- `],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function E1(t,e={}){return t.endsWith(`
4
- `)&&(t=t.slice(0,-1)),e.lstrip_blocks&&(t=t.replace(/^[ \t]*({[#%-])/gm,"$1")),e.trim_blocks&&(t=t.replace(/([#%-]})\n/g,"$1")),t.replace(/{%\s*(end)?generation\s*%}/gs,"")}function A1(t,e={}){let s=[],r=E1(t,e),n=0,o=0,i=c=>{let u="";for(;c(r[n]);){if(r[n]==="\\"){if(++n,n>=r.length)throw new SyntaxError("Unexpected end of input");let p=r[n++],d=v1.get(p);if(d===void 0)throw new SyntaxError(`Unexpected escaped character: ${p}`);u+=d;continue}if(u+=r[n++],n>=r.length)throw new SyntaxError("Unexpected end of input")}return u},a=()=>{let c=s.at(-1);c&&c.type===M.Text&&(c.value=c.value.trimEnd(),c.value===""&&s.pop())},l=()=>{for(;n<r.length&&Xg(r[n]);)++n};e:for(;n<r.length;){let c=s.at(-1)?.type;if(c===void 0||c===M.CloseStatement||c===M.CloseExpression||c===M.Comment){let p="";for(;n<r.length&&!(r[n]==="{"&&(r[n+1]==="%"||r[n+1]==="{"||r[n+1]==="#"));)p+=r[n++];if(p.length>0){s.push(new Ve(p,M.Text));continue}}if(r[n]==="{"&&r[n+1]==="#"){n+=2;let p=r[n]==="-";p&&++n;let d="";for(;r[n]!=="#"||r[n+1]!=="}";){if(n+2>=r.length)throw new SyntaxError("Missing end of comment tag");d+=r[n++]}let _=d.endsWith("-");_&&(d=d.slice(0,-1)),p&&a(),s.push(new Ve(d,M.Comment)),n+=2,_&&l();continue}if(r.slice(n,n+3)==="{%-"){a(),s.push(new Ve("{%",M.OpenStatement)),n+=3;continue}if(r.slice(n,n+3)==="{{-"){a(),s.push(new Ve("{{",M.OpenExpression)),o=0,n+=3;continue}if(i(Xg),r.slice(n,n+3)==="-%}"){s.push(new Ve("%}",M.CloseStatement)),n+=3,l();continue}if(r.slice(n,n+3)==="-}}"){s.push(new Ve("}}",M.CloseExpression)),n+=3,l();continue}let u=r[n];if(u==="-"||u==="+"){let p=s.at(-1)?.type;if(p===M.Text||p===void 0)throw new SyntaxError(`Unexpected character: ${u}`);switch(p){case M.Identifier:case M.NumericLiteral:case M.StringLiteral:case M.CloseParen:case M.CloseSquareBracket:break;default:{++n;let d=i(nr);s.push(new Ve(`${u}${d}`,d.length>0?M.NumericLiteral:M.UnaryOperator));continue}}}for(let[p,d]of k1){if(p==="}}"&&o>0)continue;if(r.slice(n,n+p.length)===p){s.push(new Ve(p,d)),d===M.OpenExpression?o=0:d===M.OpenCurlyBracket?++o:d===M.CloseCurlyBracket&&--o,n+=p.length;continue e}}if(u==="'"||u==='"'){++n;let p=i(d=>d!==u);s.push(new Ve(p,M.StringLiteral)),++n;continue}if(nr(u)){let p=i(nr);if(r[n]==="."&&nr(r[n+1])){++n;let d=i(nr);p=`${p}.${d}`}s.push(new Ve(p,M.NumericLiteral));continue}if(Hg(u)){let p=i(Hg);s.push(new Ve(p,M.Identifier));continue}throw new SyntaxError(`Unexpected character: ${u}`)}return s}var nt=class{type="Statement"},M1=class extends nt{constructor(t){super(),this.body=t}type="Program"},S1=class extends nt{constructor(t,e,s){super(),this.test=t,this.body=e,this.alternate=s}type="If"},O1=class extends nt{constructor(t,e,s,r){super(),this.loopvar=t,this.iterable=e,this.body=s,this.defaultBlock=r}type="For"},I1=class extends nt{type="Break"},z1=class extends nt{type="Continue"},T1=class extends nt{constructor(t,e,s){super(),this.assignee=t,this.value=e,this.body=s}type="Set"},P1=class extends nt{constructor(t,e,s){super(),this.name=t,this.args=e,this.body=s}type="Macro"},C1=class extends nt{constructor(t){super(),this.value=t}type="Comment"},qe=class extends nt{type="Expression"},N1=class extends qe{constructor(t,e,s){super(),this.object=t,this.property=e,this.computed=s}type="MemberExpression"},Kg=class extends qe{constructor(t,e){super(),this.callee=t,this.args=e}type="CallExpression"},ps=class extends qe{constructor(t){super(),this.value=t}type="Identifier"},ds=class extends qe{constructor(t){super(),this.value=t}type="Literal"},L1=class extends ds{type="IntegerLiteral"},$1=class extends ds{type="FloatLiteral"},Qg=class extends ds{type="StringLiteral"},R1=class extends ds{type="ArrayLiteral"},Jg=class extends ds{type="TupleLiteral"},F1=class extends ds{type="ObjectLiteral"},or=class extends qe{constructor(t,e,s){super(),this.operator=t,this.left=e,this.right=s}type="BinaryExpression"},D1=class extends qe{constructor(t,e){super(),this.operand=t,this.filter=e}type="FilterExpression"},j1=class extends nt{constructor(t,e){super(),this.filter=t,this.body=e}type="FilterStatement"},B1=class extends qe{constructor(t,e){super(),this.lhs=t,this.test=e}type="SelectExpression"},U1=class extends qe{constructor(t,e,s){super(),this.operand=t,this.negate=e,this.test=s}type="TestExpression"},q1=class extends qe{constructor(t,e){super(),this.operator=t,this.argument=e}type="UnaryExpression"},G1=class extends qe{constructor(t=void 0,e=void 0,s=void 0){super(),this.start=t,this.stop=e,this.step=s}type="SliceExpression"},W1=class extends qe{constructor(t,e){super(),this.key=t,this.value=e}type="KeywordArgumentExpression"},V1=class extends qe{constructor(t){super(),this.argument=t}type="SpreadExpression"},H1=class extends nt{constructor(t,e,s){super(),this.call=t,this.callerArgs=e,this.body=s}type="CallStatement"},X1=class extends qe{constructor(t,e,s){super(),this.condition=t,this.trueExpr=e,this.falseExpr=s}type="Ternary"};function K1(t){let e=new M1([]),s=0;function r(k,v){let I=t[s++];if(!I||I.type!==k)throw new Error(`Parser Error: ${v}. ${I.type} !== ${k}.`);return I}function n(k){if(!l(k))throw new SyntaxError(`Expected ${k}`);++s}function o(){switch(t[s].type){case M.Comment:return new C1(t[s++].value);case M.Text:return c();case M.OpenStatement:return u();case M.OpenExpression:return p();default:throw new SyntaxError(`Unexpected token type: ${t[s].type}`)}}function i(...k){return s+k.length<=t.length&&k.every((v,I)=>v===t[s+I].type)}function a(...k){return t[s]?.type===M.OpenStatement&&t[s+1]?.type===M.Identifier&&k.includes(t[s+1]?.value)}function l(...k){return s+k.length<=t.length&&k.every((v,I)=>t[s+I].type==="Identifier"&&v===t[s+I].value)}function c(){return new Qg(r(M.Text,"Expected text token").value)}function u(){if(r(M.OpenStatement,"Expected opening statement token"),t[s].type!==M.Identifier)throw new SyntaxError(`Unknown statement, got ${t[s].type}`);let k=t[s].value,v;switch(k){case"set":++s,v=d();break;case"if":++s,v=_(),r(M.OpenStatement,"Expected {% token"),n("endif"),r(M.CloseStatement,"Expected %} token");break;case"macro":++s,v=m(),r(M.OpenStatement,"Expected {% token"),n("endmacro"),r(M.CloseStatement,"Expected %} token");break;case"for":++s,v=x(),r(M.OpenStatement,"Expected {% token"),n("endfor"),r(M.CloseStatement,"Expected %} token");break;case"call":{++s;let I=null;i(M.OpenParen)&&(I=R());let Q=Y();if(Q.type!=="Identifier")throw new SyntaxError("Expected identifier following call statement");let Z=R();r(M.CloseStatement,"Expected closing statement token");let Ie=[];for(;!a("endcall");)Ie.push(o());r(M.OpenStatement,"Expected '{%'"),n("endcall"),r(M.CloseStatement,"Expected closing statement token");let Ee=new Kg(Q,Z);v=new H1(Ee,I,Ie);break}case"break":++s,r(M.CloseStatement,"Expected closing statement token"),v=new I1;break;case"continue":++s,r(M.CloseStatement,"Expected closing statement token"),v=new z1;break;case"filter":{++s;let I=Y();I instanceof ps&&i(M.OpenParen)&&(I=F(I)),r(M.CloseStatement,"Expected closing statement token");let Q=[];for(;!a("endfilter");)Q.push(o());r(M.OpenStatement,"Expected '{%'"),n("endfilter"),r(M.CloseStatement,"Expected '%}'"),v=new j1(I,Q);break}default:throw new SyntaxError(`Unknown statement type: ${k}`)}return v}function p(){r(M.OpenExpression,"Expected opening expression token");let k=g();return r(M.CloseExpression,"Expected closing expression token"),k}function d(){let k=h(),v=null,I=[];if(i(M.Equals))++s,v=h();else{for(r(M.CloseStatement,"Expected %} token");!a("endset");)I.push(o());r(M.OpenStatement,"Expected {% token"),n("endset")}return r(M.CloseStatement,"Expected closing statement token"),new T1(k,v,I)}function _(){let k=g();r(M.CloseStatement,"Expected closing statement token");let v=[],I=[];for(;!a("elif","else","endif");)v.push(o());if(a("elif")){++s,++s;let Q=_();I.push(Q)}else if(a("else"))for(++s,++s,r(M.CloseStatement,"Expected closing statement token");!a("endif");)I.push(o());return new S1(k,v,I)}function m(){let k=Y();if(k.type!=="Identifier")throw new SyntaxError("Expected identifier following macro statement");let v=R();r(M.CloseStatement,"Expected closing statement token");let I=[];for(;!a("endmacro");)I.push(o());return new P1(k,v,I)}function h(k=!1){let v=k?Y:g,I=[v()],Q=i(M.Comma);for(;Q&&(++s,I.push(v()),!!i(M.Comma)););return Q?new Jg(I):I[0]}function x(){let k=h(!0);if(!(k instanceof ps||k instanceof Jg))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${k.type} instead`);if(!l("in"))throw new SyntaxError("Expected `in` keyword following loop variable");++s;let v=g();r(M.CloseStatement,"Expected closing statement token");let I=[];for(;!a("endfor","else");)I.push(o());let Q=[];if(a("else"))for(++s,++s,r(M.CloseStatement,"Expected closing statement token");!a("endfor");)Q.push(o());return new O1(k,v,I,Q)}function g(){return w()}function w(){let k=y();if(l("if")){++s;let v=y();if(l("else")){++s;let I=w();return new X1(v,k,I)}else return new B1(k,v)}return k}function y(){let k=E();for(;l("or");){let v=t[s];++s;let I=E();k=new or(v,k,I)}return k}function E(){let k=A();for(;l("and");){let v=t[s];++s;let I=A();k=new or(v,k,I)}return k}function A(){let k;for(;l("not");){let v=t[s];++s;let I=A();k=new q1(v,I)}return k??b()}function b(){let k=O();for(;;){let v;if(l("not","in"))v=new Ve("not in",M.Identifier),s+=2;else if(l("in"))v=t[s++];else if(i(M.ComparisonBinaryOperator))v=t[s++];else break;let I=O();k=new or(v,k,I)}return k}function O(){let k=X();for(;i(M.AdditiveBinaryOperator);){let v=t[s];++s;let I=X();k=new or(v,k,I)}return k}function N(){let k=D(Y());return i(M.OpenParen)?F(k):k}function F(k){let v=new Kg(k,R());return v=D(v),i(M.OpenParen)&&(v=F(v)),v}function R(){r(M.OpenParen,"Expected opening parenthesis for arguments list");let k=B();return r(M.CloseParen,"Expected closing parenthesis for arguments list"),k}function B(){let k=[];for(;!i(M.CloseParen);){let v;if(t[s].type===M.MultiplicativeBinaryOperator&&t[s].value==="*"){++s;let I=g();v=new V1(I)}else if(v=g(),i(M.Equals)){if(++s,!(v instanceof ps))throw new SyntaxError("Expected identifier for keyword argument");let I=g();v=new W1(v,I)}k.push(v),i(M.Comma)&&++s}return k}function G(){let k=[],v=!1;for(;!i(M.CloseSquareBracket);)i(M.Colon)?(k.push(void 0),++s,v=!0):(k.push(g()),i(M.Colon)&&(++s,v=!0));if(k.length===0)throw new SyntaxError("Expected at least one argument for member/slice expression");if(v){if(k.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new G1(...k)}return k[0]}function D(k){for(;i(M.Dot)||i(M.OpenSquareBracket);){let v=t[s];++s;let I,Q=v.type===M.OpenSquareBracket;if(Q)I=G(),r(M.CloseSquareBracket,"Expected closing square bracket");else if(I=Y(),I.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");k=new N1(k,I,Q)}return k}function X(){let k=V();for(;i(M.MultiplicativeBinaryOperator);){let v=t[s++],I=V();k=new or(v,k,I)}return k}function V(){let k=re();for(;l("is");){++s;let v=l("not");v&&++s;let I=Y();if(!(I instanceof ps))throw new SyntaxError("Expected identifier for the test");k=new U1(k,v,I)}return k}function re(){let k=N();for(;i(M.Pipe);){++s;let v=Y();if(!(v instanceof ps))throw new SyntaxError("Expected identifier for the filter");i(M.OpenParen)&&(v=F(v)),k=new D1(k,v)}return k}function Y(){let k=t[s++];switch(k.type){case M.NumericLiteral:{let v=k.value;return v.includes(".")?new $1(Number(v)):new L1(Number(v))}case M.StringLiteral:{let v=k.value;for(;i(M.StringLiteral);)v+=t[s++].value;return new Qg(v)}case M.Identifier:return new ps(k.value);case M.OpenParen:{let v=h();return r(M.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),v}case M.OpenSquareBracket:{let v=[];for(;!i(M.CloseSquareBracket);)v.push(g()),i(M.Comma)&&++s;return++s,new R1(v)}case M.OpenCurlyBracket:{let v=new Map;for(;!i(M.CloseCurlyBracket);){let I=g();r(M.Colon,"Expected colon between key and value in object literal");let Q=g();v.set(I,Q),i(M.Comma)&&++s}return++s,new F1(v)}default:throw new SyntaxError(`Unexpected token: ${k.type}`)}}for(;s<t.length;)e.body.push(o());return e}function Q1(t,e,s=1){if(e===void 0&&(e=t,t=0),s===0)throw new Error("range() step must not be zero");let r=[];if(s>0)for(let n=t;n<e;n+=s)r.push(n);else for(let n=t;n>e;n+=s)r.push(n);return r}function Yg(t,e,s,r=1){let n=Math.sign(r);n>=0?(e=(e??=0)<0?Math.max(t.length+e,0):Math.min(e,t.length),s=(s??=t.length)<0?Math.max(t.length+s,0):Math.min(s,t.length)):(e=(e??=t.length-1)<0?Math.max(t.length+e,-1):Math.min(e,t.length-1),s=(s??=-1)<-1?Math.max(t.length+s,-1):Math.min(s,t.length-1));let o=[];for(let i=e;n*i<n*s;i+=r)o.push(t[i]);return o}function J1(t){return t.replace(/\b\w/g,e=>e.toUpperCase())}function Y1(t){return Z1(new Date,t)}function Z1(t,e){let s=new Intl.DateTimeFormat(void 0,{month:"long"}),r=new Intl.DateTimeFormat(void 0,{month:"short"}),n=o=>o<10?"0"+o:o.toString();return e.replace(/%[YmdbBHM%]/g,o=>{switch(o){case"%Y":return t.getFullYear().toString();case"%m":return n(t.getMonth()+1);case"%d":return n(t.getDate());case"%b":return r.format(t);case"%B":return s.format(t);case"%H":return n(t.getHours());case"%M":return n(t.getMinutes());case"%%":return"%";default:return o}})}function ek(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function tk(t,e,s,r){if(r===0)return t;let n=r==null||r<0?1/0:r,o=e.length===0?new RegExp("(?=)","gu"):new RegExp(ek(e),"gu");return t.replaceAll(o,i=>n>0?(--n,s):i)}var Zg=class extends Error{},ew=class extends Error{},ut=class{type="RuntimeValue";value;builtins=new Map;constructor(t=void 0){this.value=t}__bool__(){return new U(!!this.value)}toString(){return String(this.value)}},H=class extends ut{type="IntegerValue"},ye=class extends ut{type="FloatValue";toString(){return this.value%1===0?this.value.toFixed(1):this.value.toString()}},$=class extends ut{type="StringValue";builtins=new Map([["upper",new me(()=>new $(this.value.toUpperCase()))],["lower",new me(()=>new $(this.value.toLowerCase()))],["strip",new me(()=>new $(this.value.trim()))],["title",new me(()=>new $(J1(this.value)))],["capitalize",new me(()=>new $(this.value.charAt(0).toUpperCase()+this.value.slice(1)))],["length",new H(this.value.length)],["rstrip",new me(()=>new $(this.value.trimEnd()))],["lstrip",new me(()=>new $(this.value.trimStart()))],["startswith",new me(t=>{if(t.length===0)throw new Error("startswith() requires at least one argument");let e=t[0];if(e instanceof $)return new U(this.value.startsWith(e.value));if(e instanceof te){for(let s of e.value){if(!(s instanceof $))throw new Error("startswith() tuple elements must be strings");if(this.value.startsWith(s.value))return new U(!0)}return new U(!1)}throw new Error("startswith() argument must be a string or tuple of strings")})],["endswith",new me(t=>{if(t.length===0)throw new Error("endswith() requires at least one argument");let e=t[0];if(e instanceof $)return new U(this.value.endsWith(e.value));if(e instanceof te){for(let s of e.value){if(!(s instanceof $))throw new Error("endswith() tuple elements must be strings");if(this.value.endsWith(s.value))return new U(!0)}return new U(!1)}throw new Error("endswith() argument must be a string or tuple of strings")})],["split",new me(t=>{let e=t[0]??new he;if(!(e instanceof $||e instanceof he))throw new Error("sep argument must be a string or null");let s=t[1]??new H(-1);if(!(s instanceof H))throw new Error("maxsplit argument must be a number");let r=[];if(e instanceof he){let n=this.value.trimStart();for(let{0:o,index:i}of n.matchAll(/\S+/g)){if(s.value!==-1&&r.length>=s.value&&i!==void 0){r.push(o+n.slice(i+o.length));break}r.push(o)}}else{if(e.value==="")throw new Error("empty separator");r=this.value.split(e.value),s.value!==-1&&r.length>s.value&&r.push(r.splice(s.value).join(e.value))}return new te(r.map(n=>new $(n)))})],["replace",new me(t=>{if(t.length<2)throw new Error("replace() requires at least two arguments");let e=t[0],s=t[1];if(!(e instanceof $&&s instanceof $))throw new Error("replace() arguments must be strings");let r;if(t.length>2?t[2].type==="KeywordArgumentsValue"?r=t[2].value.get("count")??new he:r=t[2]:r=new he,!(r instanceof H||r instanceof he))throw new Error("replace() count argument must be a number or null");return new $(tk(this.value,e.value,s.value,r.value))})]])},U=class extends ut{type="BooleanValue"},sk=/[\x7f-\uffff]/g;function tw(t){return t.replace(sk,e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0"))}function Ht(t,e={},s=0,r=!0){let{indent:n=null,ensureAscii:o=!1,separators:i=null,sortKeys:a=!1}=e,l,c;switch(i?[l,c]=i:n?(l=",",c=": "):(l=", ",c=": "),t.type){case"NullValue":return"null";case"UndefinedValue":return r?"null":"undefined";case"IntegerValue":case"FloatValue":case"BooleanValue":return JSON.stringify(t.value);case"StringValue":{let u=JSON.stringify(t.value);return o&&(u=tw(u)),u}case"ArrayValue":case"ObjectValue":{let u=n?" ".repeat(n):"",p=`
5
- `+u.repeat(s),d=p+u;if(t.type==="ArrayValue"){let _=t.value.map(m=>Ht(m,e,s+1,r));return n?`[${d}${_.join(`${l}${d}`)}${p}]`:`[${_.join(l)}]`}else{let _=Array.from(t.value.entries());a&&(_=_.sort(([h],[x])=>h.localeCompare(x)));let m=_.map(([h,x])=>{let g=JSON.stringify(h);o&&(g=tw(g));let w=`${g}${c}${Ht(x,e,s+1,r)}`;return n?`${d}${w}`:w});return n?`{${m.join(l)}${p}}`:`{${m.join(l)}}`}}default:throw new Error(`Cannot convert to JSON: ${t.type}`)}}var Le=class extends ut{type="ObjectValue";__bool__(){return new U(this.value.size>0)}builtins=new Map([["get",new me(([t,e])=>{if(!(t instanceof $))throw new Error(`Object key must be a string: got ${t.type}`);return this.value.get(t.value)??e??new he})],["items",new me(()=>this.items())],["keys",new me(()=>this.keys())],["values",new me(()=>this.values())],["dictsort",new me(t=>{let e=new Map,s=t.filter(a=>a instanceof ir?(e=a.value,!1):!0),r=s.at(0)??e.get("case_sensitive")??new U(!1);if(!(r instanceof U))throw new Error("case_sensitive must be a boolean");let n=s.at(1)??e.get("by")??new $("key");if(!(n instanceof $))throw new Error("by must be a string");if(!["key","value"].includes(n.value))throw new Error("by must be either 'key' or 'value'");let o=s.at(2)??e.get("reverse")??new U(!1);if(!(o instanceof U))throw new Error("reverse must be a boolean");let i=Array.from(this.value.entries()).map(([a,l])=>new te([new $(a),l])).sort((a,l)=>{let c=n.value==="key"?0:1,u=a.value[c],p=l.value[c],d=Dl(u,p,r.value);return o.value?-d:d});return new te(i)})]]);items(){return new te(Array.from(this.value.entries()).map(([t,e])=>new te([new $(t),e])))}keys(){return new te(Array.from(this.value.keys()).map(t=>new $(t)))}values(){return new te(Array.from(this.value.values()))}toString(){return Ht(this,{},0,!1)}},ir=class extends Le{type="KeywordArgumentsValue"},te=class extends ut{type="ArrayValue";builtins=new Map([["length",new H(this.value.length)]]);__bool__(){return new U(this.value.length>0)}toString(){return Ht(this,{},0,!1)}},sw=class extends te{type="TupleValue"},me=class extends ut{type="FunctionValue"},he=class extends ut{type="NullValue"},fe=class extends ut{type="UndefinedValue"},Vt=class{constructor(t){this.parent=t}variables=new Map([["namespace",new me(t=>{if(t.length===0)return new Le(new Map);if(t.length!==1||!(t[0]instanceof Le))throw new Error("`namespace` expects either zero arguments or a single object argument");return t[0]})]]);tests=new Map([["boolean",t=>t.type==="BooleanValue"],["callable",t=>t instanceof me],["odd",t=>{if(!(t instanceof H))throw new Error(`cannot odd on ${t.type}`);return t.value%2!==0}],["even",t=>{if(!(t instanceof H))throw new Error(`cannot even on ${t.type}`);return t.value%2===0}],["false",t=>t.type==="BooleanValue"&&!t.value],["true",t=>t.type==="BooleanValue"&&t.value],["none",t=>t.type==="NullValue"],["string",t=>t.type==="StringValue"],["number",t=>t instanceof H||t instanceof ye],["integer",t=>t instanceof H],["iterable",t=>t.type==="ArrayValue"||t.type==="StringValue"],["mapping",t=>t.type==="ObjectValue"],["lower",t=>{let e=t.value;return t.type==="StringValue"&&e===e.toLowerCase()}],["upper",t=>{let e=t.value;return t.type==="StringValue"&&e===e.toUpperCase()}],["none",t=>t.type==="NullValue"],["defined",t=>t.type!=="UndefinedValue"],["undefined",t=>t.type==="UndefinedValue"],["equalto",(t,e)=>t.value===e.value],["eq",(t,e)=>t.value===e.value]]);set(t,e){return this.declareVariable(t,Go(e))}declareVariable(t,e){if(this.variables.has(t))throw new SyntaxError(`Variable already declared: ${t}`);return this.variables.set(t,e),e}setVariable(t,e){return this.variables.set(t,e),e}resolve(t){if(this.variables.has(t))return this;if(this.parent)return this.parent.resolve(t);throw new Error(`Unknown variable: ${t}`)}lookupVariable(t){try{return this.resolve(t).variables.get(t)??new fe}catch{return new fe}}};function rk(t){t.set("false",!1),t.set("true",!0),t.set("none",null),t.set("raise_exception",e=>{throw new Error(e)}),t.set("range",Q1),t.set("strftime_now",Y1),t.set("True",!0),t.set("False",!1),t.set("None",null)}function rw(t,e){let s=e.split("."),r=t;for(let n of s)if(r instanceof Le)r=r.value.get(n)??new fe;else if(r instanceof te){let o=parseInt(n,10);if(!isNaN(o)&&o>=0&&o<r.value.length)r=r.value[o];else return new fe}else return new fe;return r}function Dl(t,e,s=!1){if(t instanceof he&&e instanceof he)return 0;if(t instanceof he||e instanceof he)throw new Error(`Cannot compare ${t.type} with ${e.type}`);if(t instanceof fe&&e instanceof fe)return 0;if(t instanceof fe||e instanceof fe)throw new Error(`Cannot compare ${t.type} with ${e.type}`);let r=o=>o instanceof H||o instanceof ye||o instanceof U,n=o=>o instanceof U?o.value?1:0:o.value;if(r(t)&&r(e)){let o=n(t),i=n(e);return o<i?-1:o>i?1:0}if(t.type!==e.type)throw new Error(`Cannot compare different types: ${t.type} and ${e.type}`);if(t.type==="StringValue"){let o=t.value,i=e.value;return s||(o=o.toLowerCase(),i=i.toLowerCase()),o<i?-1:o>i?1:0}else throw new Error(`Cannot compare type: ${t.type}`)}var nk=class{global;constructor(t){this.global=t??new Vt}run(t){return this.evaluate(t,this.global)}evaluateBinaryExpression(t,e){let s=this.evaluate(t.left,e);switch(t.operator.value){case"and":return s.__bool__().value?this.evaluate(t.right,e):s;case"or":return s.__bool__().value?s:this.evaluate(t.right,e)}let r=this.evaluate(t.right,e);switch(t.operator.value){case"==":return new U(s.value==r.value);case"!=":return new U(s.value!=r.value)}if(s instanceof fe||r instanceof fe){if(r instanceof fe&&["in","not in"].includes(t.operator.value))return new U(t.operator.value==="not in");throw new Error(`Cannot perform operation ${t.operator.value} on undefined values`)}else{if(s instanceof he||r instanceof he)throw new Error("Cannot perform operation on null values");if(t.operator.value==="~")return new $(s.value.toString()+r.value.toString());if((s instanceof H||s instanceof ye)&&(r instanceof H||r instanceof ye)){let n=s.value,o=r.value;switch(t.operator.value){case"+":case"-":case"*":{let i=t.operator.value==="+"?n+o:t.operator.value==="-"?n-o:n*o;return s instanceof ye||r instanceof ye?new ye(i):new H(i)}case"/":return new ye(n/o);case"%":{let i=n%o;return s instanceof ye||r instanceof ye?new ye(i):new H(i)}case"<":return new U(n<o);case">":return new U(n>o);case">=":return new U(n>=o);case"<=":return new U(n<=o)}}else if(s instanceof te&&r instanceof te){if(t.operator.value==="+")return new te(s.value.concat(r.value))}else if(r instanceof te){let n=r.value.find(o=>o.value===s.value)!==void 0;switch(t.operator.value){case"in":return new U(n);case"not in":return new U(!n)}}}if((s instanceof $||r instanceof $)&&t.operator.value==="+")return new $(s.value.toString()+r.value.toString());if(s instanceof $&&r instanceof $)switch(t.operator.value){case"in":return new U(r.value.includes(s.value));case"not in":return new U(!r.value.includes(s.value))}if(s instanceof $&&r instanceof Le)switch(t.operator.value){case"in":return new U(r.value.has(s.value));case"not in":return new U(!r.value.has(s.value))}throw new SyntaxError(`Unknown operator "${t.operator.value}" between ${s.type} and ${r.type}`)}evaluateArguments(t,e){let s=[],r=new Map;for(let n of t)if(n.type==="SpreadExpression"){let o=n,i=this.evaluate(o.argument,e);if(!(i instanceof te))throw new Error(`Cannot unpack non-iterable type: ${i.type}`);for(let a of i.value)s.push(a)}else if(n.type==="KeywordArgumentExpression"){let o=n;r.set(o.key.value,this.evaluate(o.value,e))}else{if(r.size>0)throw new Error("Positional arguments must come before keyword arguments");s.push(this.evaluate(n,e))}return[s,r]}applyFilter(t,e,s){if(e.type==="Identifier"){let r=e;if(r.value==="tojson")return new $(Ht(t,{}));if(t instanceof te)switch(r.value){case"list":return t;case"first":return t.value[0];case"last":return t.value[t.value.length-1];case"length":return new H(t.value.length);case"reverse":return new te(t.value.slice().reverse());case"sort":return new te(t.value.slice().sort((n,o)=>Dl(n,o,!1)));case"join":return new $(t.value.map(n=>n.value).join(""));case"string":return new $(Ht(t,{},0,!1));case"unique":{let n=new Set,o=[];for(let i of t.value)n.has(i.value)||(n.add(i.value),o.push(i));return new te(o)}default:throw new Error(`Unknown ArrayValue filter: ${r.value}`)}else if(t instanceof $)switch(r.value){case"length":case"upper":case"lower":case"title":case"capitalize":{let n=t.builtins.get(r.value);if(n instanceof me)return n.value([],s);if(n instanceof H)return n;throw new Error(`Unknown StringValue filter: ${r.value}`)}case"trim":return new $(t.value.trim());case"indent":return new $(t.value.split(`
1
+ var U0=Object.defineProperty;var As=(t,e)=>{for(var s in e)U0(t,s,{get:e[s],enumerable:!0})};var Fe={};var He={};var Jg={};var B0="4.0.0-next.5",Ms=!aw(Fe),tw=!aw(He),Oi=typeof self<"u"&&"caches"in self,q0=typeof globalThis.Deno<"u",EE=typeof globalThis.Bun<"u",sw=q0&&Oi&&!Ms,rw=typeof process<"u",nw=rw&&process?.release?.name==="node"&&!sw,ow=typeof window<"u"&&typeof window.document<"u",iw=typeof self<"u"&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),G0=nw||typeof navigator<"u"&&"gpu"in navigator,W0=typeof navigator<"u"&&"ml"in navigator,V0=typeof crypto<"u"&&typeof crypto.getRandomValues=="function",H0=()=>{if(typeof navigator>"u")return!1;let t=navigator.userAgent,s=(navigator.vendor||"").indexOf("Apple")>-1,r=!t.match(/CriOS|FxiOS|EdgiOS|OPiOS|mercury|brave/i)&&!t.includes("Chrome")&&!t.includes("Android");return s&&r},K0=H0(),Z=Object.freeze({IS_BROWSER_ENV:ow,IS_WEBWORKER_ENV:iw,IS_WEB_CACHE_AVAILABLE:Oi,IS_WEBGPU_AVAILABLE:G0,IS_WEBNN_AVAILABLE:W0,IS_SAFARI:K0,IS_PROCESS_AVAILABLE:rw,IS_NODE_ENV:nw,IS_FS_AVAILABLE:Ms,IS_PATH_AVAILABLE:tw,IS_CRYPTO_AVAILABLE:V0}),oc=Ms&&tw,Ii="./";if(oc){let t=Object(import.meta).url;t?Ii=He.dirname(He.dirname(Jg.fileURLToPath(t))):typeof __dirname<"u"&&(Ii=He.dirname(__dirname))}var X0=oc?He.join(Ii,"/.cache/"):null,Zg="/models/",Q0=oc?He.join(Ii,Zg):Zg,Y0=typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0,Ue=Object.freeze({DEBUG:10,INFO:20,WARNING:30,ERROR:40,NONE:50}),ew=Ue.WARNING,H={version:B0,backends:{onnx:{}},get logLevel(){return ew},set logLevel(t){ew=t,H.backends.onnx?.setLogLevel?.(t)},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(ow||iw||sw),localModelPath:Q0,useFS:Ms,useBrowserCache:Oi,useFSCache:Ms,cacheDir:X0,useCustomCache:!1,customCache:null,useWasmCache:Oi||Ms,cacheKey:"transformers-cache",fetch:Y0};function aw(t){return Object.keys(t).length===0}function At(t,e){t&&t(e)}function lw(t){return Number.isInteger(t)||typeof t=="bigint"}function ic(t){return t==null||t===-1}function ac(t){let e=[],s=t;for(;Array.isArray(s);)e.push(s.length),s=s[0];return e}function Pe(...t){return Array.prototype.concat.apply([],t)}function cw(...t){return t.reduce((e,s)=>e.flatMap(r=>s.map(n=>[r,n])))}function Ss(t,e){return Math.abs((t+e)%(2*e)-e)}function Me(t,e){return Object.assign({},...e.map(s=>{if(t[s]!==void 0)return{[s]:t[s]}}))}function uw(t,e){let s=0;for(let r of t)r===e&&++s;return s}var L={error(...t){H.logLevel<=Ue.ERROR&&console.error(...t)},warn(...t){H.logLevel<=Ue.WARNING&&console.warn(...t)},info(...t){H.logLevel<=Ue.INFO&&console.log(...t)},debug(...t){H.logLevel<=Ue.DEBUG&&console.log(...t)},log(...t){this.info(...t)}};var J0=class{constructor(t){this.trie=this._build_trie(t)}_build_trie(t){let e=Object.create(null);for(let s of t){let r=e;for(let n=0;n<s.length;++n){let o=s[n];r=r[o]??=Object.create(null)}r.end=s}return e}split(t){let e=[],s=t.length,r=0,n=0;for(;n<s;){let o=this.trie,i=null,a=n;for(;a<s&&(o=o[t[a]]);)o.end&&(i=o.end),++a;i?(n>r&&e.push(t.slice(r,n)),e.push(i),n+=i.length,r=n):++n}return r<s&&e.push(t.slice(r)),e}},pw=J0,Z0=class{constructor(t){this.content=t.content,this.id=t.id,this.single_word=t.single_word??!1,this.lstrip=t.lstrip??!1,this.rstrip=t.rstrip??!1,this.special=t.special??!1,this.normalized=t.normalized??!this.special}},eb=Z0,gw=(()=>{let t=[...Array.from({length:94},(n,o)=>o+33),...Array.from({length:12},(n,o)=>o+161),...Array.from({length:82},(n,o)=>o+174)],e=t.slice(),s=0;for(let n=0;n<256;++n)t.includes(n)||(t.push(n),e.push(256+s),s+=1);let r=e.map(n=>String.fromCharCode(n));return Object.fromEntries(t.map((n,o)=>[n,r[o]]))})(),tb=t=>Object.fromEntries(Object.entries(t).map(([e,s])=>[s,e])),sb=tb(gw),dw=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",rb=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"],["(?i:[sdmt]|ll|ve|re)","(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])"],["[^\\r\\n\\p{L}\\p{N}]?+","[^\\r\\n\\p{L}\\p{N}]?"],["[^\\s\\p{L}\\p{N}]++","[^\\s\\p{L}\\p{N}]+"],["(?>\\p{Nd}{510})","(?:\\p{Nd}{510})"],["\\p{Nd}{3}+","(?:\\p{Nd}{3})+"],["\\G",""],[` ?[^(\\s|[${dw}])]+`,` ?[^\\s${dw}]+`]]),Ti="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",cc=t=>t.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n't/g,"n't").replace(/ 'm/g,"'m").replace(/ 's/g,"'s").replace(/ 've/g,"'ve").replace(/ 're/g,"'re"),zi=(t,e=!0)=>{if(t.Regex!==void 0){let s=t.Regex.replace(/\\([#&~])/g,"$1");s=s.replace(/\\A/g,"^").replace(/\\z/g,"$").replace(/\\Z/g,"(?=\\r?\\n?$)");for(let[r,n]of rb)s=s.replaceAll(r,n);try{return new RegExp(s,"gu")}catch(r){if(!(r instanceof SyntaxError)||!r.message.toLowerCase().includes("invalid property name"))throw r;let n=!1,o=s.replace(/(\\[pP])\{([^}=]+)\}/g,(i,a,l)=>{try{return new RegExp(`\\p{${l}}`,"u"),`${a}{${l}}`}catch{return n=!0,`${a}{Script=${l}}`}});if(!n)throw r;try{return new RegExp(o,"gu")}catch{throw r}}}else if(t.String!==void 0){let s=nb(t.String);return new RegExp(e?s:`(${s})`,"gu")}else return console.warn("Unknown pattern type:",t),null},nb=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ob=(t,e,s)=>{let r=[],n=0;for(;n<t.length;){if(r.push(t[n]),(e.get(t[n])??s)!==s){++n;continue}for(;++n<t.length&&(e.get(t[n])??s)===s;)e.get(r.at(-1))!==s&&(r[r.length-1]+=t[n])}return r},ib=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,ab=t=>Number.isInteger(t)||typeof t=="bigint",lb=t=>{let e=0;for(let s of t)++e;return e},cb=t=>ww(t.toLowerCase()),rt=(...t)=>Array.prototype.concat.apply([],t),uc=t=>new Map(Object.entries(t)),ub=(t,e)=>{let s=[],r=0;for(let n of t.matchAll(e)){let o=n[0];r<n.index&&s.push(t.slice(r,n.index)),o.length>0&&s.push(o),r=n.index+o.length}return r<t.length&&s.push(t.slice(r)),s},ww=t=>t.replace(/\p{M}/gu,""),_w=(t,e,s=[])=>{if(!t||Array.isArray(t)||typeof t!="object")return`${e} must be a valid object`;for(let r of s)if(!(r in t))return`${e} must contain a "${r}" property`;return null},pb=t=>t.match(/\S+/g)||[],db=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},fr=db,_b=class extends fr{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},Mt=_b,fb=class extends Mt{tokenize_chinese_chars(t){let e=[];for(let s=0;s<t.length;++s){let r=t[s],n=r.charCodeAt(0);ib(n)?(e.push(" "),e.push(r),e.push(" ")):e.push(r)}return e.join("")}strip_accents(t){return t.normalize("NFD").replace(/\p{Mn}/gu,"")}is_control(t){switch(t){case" ":case`
2
+ `:case"\r":return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(t)}}clean_text(t){let e=[];for(let s of t){let r=s.charCodeAt(0);r===0||r===65533||this.is_control(s)||(/^\s$/.test(s)?e.push(" "):e.push(s))}return e.join("")}normalize(t){return this.config.clean_text&&(t=this.clean_text(t)),this.config.handle_chinese_chars&&(t=this.tokenize_chinese_chars(t)),this.config.lowercase?(t=t.toLowerCase(),this.config.strip_accents!==!1&&(t=this.strip_accents(t))):this.config.strip_accents&&(t=this.strip_accents(t)),t}},mb=fb,hb=class extends Mt{constructor(t){super(t),this.charsmap=t.precompiled_charsmap??null}normalize(t){return t=t.replace(/[\u0001-\u0008\u000B\u000E-\u001F\u007F\u008F\u009F]/gm,""),t=t.replace(/[\u0009\u000A\u000C\u000D\u00A0\u1680\u2000-\u200F\u2028\u2029\u202F\u205F\u2581\u3000\uFEFF\uFFFD]/gm," "),t.includes("\uFF5E")?t=t.split("\uFF5E").map(s=>s.normalize("NFKC")).join("\uFF5E"):t=t.normalize("NFKC"),t}},xb=hb,gb=class extends Mt{constructor(t){super(t),this.normalizers=(t.normalizers??[]).map(e=>yw(e))}normalize(t){return this.normalizers.reduce((e,s)=>s?s.normalize(e):e,t)}},wb=gb,yb=class extends Mt{normalize(t){let e=zi(this.config.pattern??{});return e===null?t:t.replaceAll(e,this.config.content??"")}},bb=yb,kb=class extends Mt{constructor(){super(...arguments),this.form="NFC"}normalize(t){return t=t.normalize(this.form),t}},Pi=kb,vb=class extends Pi{constructor(){super(...arguments),this.form="NFC"}},Eb=vb,Ab=class extends Pi{constructor(){super(...arguments),this.form="NFD"}},Mb=Ab,Sb=class extends Pi{constructor(){super(...arguments),this.form="NFKC"}},Ob=Sb,Ib=class extends Pi{constructor(){super(...arguments),this.form="NFKD"}},Tb=Ib,zb=class extends Mt{normalize(t){return this.config.strip_left&&this.config.strip_right?t=t.trim():(this.config.strip_left&&(t=t.trimStart()),this.config.strip_right&&(t=t.trimEnd())),t}},Pb=zb,Cb=class extends Mt{normalize(t){return ww(t)}},Nb=Cb,Lb=class extends Mt{normalize(t){return t.toLowerCase()}},$b=Lb,Rb=class extends Mt{normalize(t){return t=this.config.prepend+t,t}},Fb=Rb;function Db(t){if(t===null)return null;switch(t.type){case"BertNormalizer":return new mb(t);case"Precompiled":return new xb(t);case"Sequence":return new wb(t);case"Replace":return new bb(t);case"NFC":return new Eb(t);case"NFD":return new Mb(t);case"NFKC":return new Ob(t);case"NFKD":return new Tb(t);case"Strip":return new Pb(t);case"StripAccents":return new Nb(t);case"Lowercase":return new $b(t);case"Prepend":return new Fb(t);default:throw new Error(`Unknown Normalizer type: ${t.type}`)}}var yw=Db,jb=class extends fr{pre_tokenize(t,e){return(Array.isArray(t)?t.map(s=>this.pre_tokenize_text(s,e)):this.pre_tokenize_text(t,e)).flat()}_call(t,e){return this.pre_tokenize(t,e)}},nt=jb,Ub=class extends nt{constructor(t){super(),this.config=t,this.add_prefix_space=this.config.add_prefix_space??!1,this.trim_offsets=this.config.trim_offsets??!1,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=gw,this.text_encoder=new TextEncoder}pre_tokenize_text(t,e){return this.add_prefix_space&&!t.startsWith(" ")&&(t=" "+t),(this.use_regex?t.match(this.pattern)||[]:[t]).map(r=>Array.from(this.text_encoder.encode(r),n=>this.byte_encoder[n]).join(""))}},Bb=Ub,qb=class extends nt{pre_tokenize_text(t,e){return t.match(/\w+|[^\w\s]+/g)||[]}},Gb=qb,Wb=class extends nt{constructor(t){super(),this.replacement=t.replacement??"\u2581",this.str_rep=t.str_rep||this.replacement,this.prepend_scheme=t.prepend_scheme??"always"}pre_tokenize_text(t,e){let{section_index:s=void 0}=e??{},r=t.replaceAll(" ",this.str_rep);return!r.startsWith(this.replacement)&&(this.prepend_scheme==="always"||this.prepend_scheme==="first"&&s===0)&&(r=this.str_rep+r),[r]}},Vb=Wb,Hb=class extends nt{constructor(t){super(),this.config=t,this.pattern=zi(this.config.pattern??{},this.config.invert??!0)}pre_tokenize_text(t){return this.pattern===null?[]:this.config.invert?t.match(this.pattern)||[]:this.config.behavior?.toLowerCase()==="removed"?t.split(this.pattern).filter(e=>e):ub(t,this.pattern)}},Kb=Hb,Xb=class extends nt{constructor(t){super(),this.config=t,this.pattern=new RegExp(`[^${Ti}]+|[${Ti}]+`,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},Qb=Xb,Yb=class extends nt{constructor(t){super(),this.config=t;let e=`[^\\d]+|\\d${this.config.individual_digits?"":"+"}`;this.pattern=new RegExp(e,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},Jb=Yb,Zb=class extends nt{constructor(){super(),this.pattern=new RegExp(`[^\\s${Ti}]+|[${Ti}]`,"gu")}pre_tokenize_text(t,e){return t.trim().match(this.pattern)||[]}},e1=Zb,t1=class extends nt{constructor(t){super(),this.config=t,this.pattern=zi(this.config.pattern??{}),this.content=this.config.content??""}pre_tokenize_text(t){return this.pattern===null?[t]:[t.replaceAll(this.pattern,this.config.content??"")]}},s1=t1,r1=class extends nt{constructor(t){super(),this.tokenizers=(t.pretokenizers??[]).map(e=>bw(e))}pre_tokenize_text(t,e){return this.tokenizers.reduce((s,r)=>r?r.pre_tokenize(s,e):s,[t])}},n1=r1,o1=class extends nt{pre_tokenize_text(t){return pb(t)}},i1=o1,a1=class extends nt{constructor(t){super(),this.config=t,this._length=t.length}pre_tokenize_text(t){let e=[];for(let s=0;s<t.length;s+=this._length)e.push(t.slice(s,s+this._length));return e}},l1=a1;function c1(t){if(t===null)return null;switch(t.type){case"BertPreTokenizer":return new e1;case"Sequence":return new n1(t);case"Whitespace":return new Gb;case"WhitespaceSplit":return new i1;case"Metaspace":return new Vb(t);case"ByteLevel":return new Bb(t);case"Split":return new Kb(t);case"Punctuation":return new Qb(t);case"Digits":return new Jb(t);case"Replace":return new s1(t);case"FixedLength":return new l1(t);default:throw new Error(`Unknown PreTokenizer type: ${t.type}`)}}var bw=c1,u1=class extends fr{constructor(t){super(),this.config=t,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}_call(t){let e=this.encode(t);return this.fuse_unk&&(e=ob(e,this.tokens_to_ids,this.unk_token_id)),e}},Ci=u1,p1=class extends Ci{constructor(t){super(t),this.max_input_chars_per_word=100,this.tokens_to_ids=uc(t.vocab),this.unk_token_id=this.tokens_to_ids.get(t.unk_token),this.unk_token=t.unk_token,this.max_input_chars_per_word=t.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(let[e,s]of this.tokens_to_ids)this.vocab[s]=e}encode(t){let e=[];for(let s of t){let r=[...s];if(r.length>this.max_input_chars_per_word){e.push(this.unk_token);continue}let n=!1,o=0,i=[];for(;o<r.length;){let a=r.length,l=null;for(;o<a;){let c=r.slice(o,a).join("");if(o>0&&(c=this.config.continuing_subword_prefix+c),this.tokens_to_ids.has(c)){l=c;break}--a}if(l===null){n=!0;break}i.push(l),o=a}n?e.push(this.unk_token):e.push(...i)}return e}},fw=p1,mw=class kw{constructor(e,s){this.is_leaf=e,this.children=s}static default(){return new kw(!1,new Map)}},d1=class{constructor(){this.root=mw.default()}extend(t){for(let e of t)this.push(e)}push(t){let e=this.root;for(let s of t){let r=e.children.get(s);r===void 0&&(r=mw.default(),e.children.set(s,r)),e=r}e.is_leaf=!0}*common_prefix_search(t){let e=this.root;if(e===void 0)return;let s="";for(let r of t){if(s+=r,e=e.children.get(r),e===void 0)return;e.is_leaf&&(yield s)}}},_1=d1,lc=class vw{constructor(e,s,r,n,o){this.token_id=e,this.node_id=s,this.pos=r,this.length=n,this.score=o,this.prev=null,this.backtrace_score=0}clone(){let e=new vw(this.token_id,this.node_id,this.pos,this.length,this.score);return e.prev=this.prev,e.backtrace_score=this.backtrace_score,e}},f1=class{constructor(t,e,s){this.chars=Array.from(t),this.len=this.chars.length,this.bos_token_id=e,this.eos_token_id=s,this.nodes=[],this.begin_nodes=Array.from({length:this.len+1},()=>[]),this.end_nodes=Array.from({length:this.len+1},()=>[]);let r=new lc(this.bos_token_id??0,0,0,0,0),n=new lc(this.eos_token_id??0,1,this.len,0,0);this.nodes.push(r.clone()),this.nodes.push(n.clone()),this.begin_nodes[this.len].push(n),this.end_nodes[0].push(r)}insert(t,e,s,r){let n=this.nodes.length,o=new lc(r,n,t,e,s);this.begin_nodes[t].push(o),this.end_nodes[t+e].push(o),this.nodes.push(o)}viterbi(){let t=this.len,e=0;for(;e<=t;){if(this.begin_nodes[e].length==0)return[];for(let i of this.begin_nodes[e]){i.prev=null;let a=0,l=null;for(let c of this.end_nodes[e]){let u=c.backtrace_score+i.score;(l===null||u>a)&&(l=c.clone(),a=u)}if(l!==null)i.prev=l,i.backtrace_score=a;else return[]}++e}let s=[],n=this.begin_nodes[t][0].prev;if(n===null)return[];let o=n.clone();for(;o.prev!==null;)s.push(o.clone()),o=o.clone().prev.clone();return s.reverse(),s}piece(t){return this.chars.slice(t.pos,t.pos+t.length).join("")}tokens(){return this.viterbi().map(e=>this.piece(e))}token_ids(){return this.viterbi().map(e=>e.token_id)}},m1=f1;function h1(t){if(t.length===0)throw new Error("Array must not be empty");let e=t[0],s=0;for(let r=1;r<t.length;++r)t[r]<e&&(e=t[r],s=r);return[e,s]}var x1=class extends Ci{constructor(t,e){super(t);let s=t.vocab.length;this.vocab=new Array(s),this.scores=new Array(s);for(let r=0;r<s;++r)[this.vocab[r],this.scores[r]]=t.vocab[r];this.unk_token_id=t.unk_id,this.unk_token=this.vocab[t.unk_id],this.tokens_to_ids=new Map(this.vocab.map((r,n)=>[r,n])),this.bos_token=" ",this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=e,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.unk_token=this.vocab[this.unk_token_id],this.min_score=h1(this.scores)[0],this.unk_score=this.min_score-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new _1,this.trie.extend(this.vocab),this.fuse_unk=!0}populate_nodes(t){let e=t.chars,s=1,r=0;for(;r<e.length;){let n=!1,o=[],i=e.slice(r).join(""),a=this.trie.common_prefix_search(i);for(let l of a){o.push(l);let c=this.tokens_to_ids.get(l),u=this.scores[c],p=lb(l);t.insert(r,p,u,c),!n&&p===s&&(n=!0)}n||t.insert(r,s,this.unk_score,this.unk_token_id),r+=s}}tokenize(t){let e=new m1(t,this.bos_token_id,this.eos_token_id);return this.populate_nodes(e),e.tokens()}encode(t){let e=[];for(let s of t){let r=this.tokenize(s);e.push(...r)}return e}},hw=x1,g1=class{constructor(t=(s,r)=>s>r,e=1/0){this._heap=[],this._comparator=t,this._max_size=e}get size(){return this._heap.length}is_empty(){return this.size===0}peek(){return this._heap[0]}push(...t){return this.extend(t)}extend(t){for(let e of t)if(this.size<this._max_size)this._heap.push(e),this._sift_up();else{let s=this._smallest();this._comparator(e,this._heap[s])&&(this._heap[s]=e,this._sift_up_from(s))}return this.size}pop(){let t=this.peek(),e=this.size-1;return e>0&&this._swap(0,e),this._heap.pop(),this._sift_down(),t}replace(t){let e=this.peek();return this._heap[0]=t,this._sift_down(),e}_parent(t){return(t+1>>>1)-1}_left(t){return(t<<1)+1}_right(t){return t+1<<1}_greater(t,e){return this._comparator(this._heap[t],this._heap[e])}_swap(t,e){let s=this._heap[t];this._heap[t]=this._heap[e],this._heap[e]=s}_sift_up(){this._sift_up_from(this.size-1)}_sift_up_from(t){for(;t>0&&this._greater(t,this._parent(t));)this._swap(t,this._parent(t)),t=this._parent(t)}_sift_down(){let t=0;for(;this._left(t)<this.size&&this._greater(this._left(t),t)||this._right(t)<this.size&&this._greater(this._right(t),t);){let e=this._right(t)<this.size&&this._greater(this._right(t),this._left(t))?this._right(t):this._left(t);this._swap(t,e),t=e}}_smallest(){return 2**Math.floor(Math.log2(this.size))-1}},w1=g1,y1=class{constructor(t){this.capacity=t,this.cache=new Map}get(t){if(!this.cache.has(t))return;let e=this.cache.get(t);return this.cache.delete(t),this.cache.set(t,e),e}put(t,e){this.cache.has(t)&&this.cache.delete(t),this.cache.set(t,e),this.cache.size>this.capacity&&this.cache.delete(this.cache.keys().next().value)}clear(){this.cache.clear()}},b1=y1,k1=class extends Ci{constructor(t){super(t),this.tokens_to_ids=uc(t.vocab),this.unk_token_id=this.tokens_to_ids.get(t.unk_token),this.unk_token=t.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(let[s,r]of this.tokens_to_ids)this.vocab[r]=s;let e=Array.isArray(t.merges[0]);this.merges=e?t.merges:t.merges.map(s=>s.split(" ",2)),this.bpe_ranks=new Map(this.merges.map((s,r)=>[JSON.stringify(s),r])),this.end_of_word_suffix=t.end_of_word_suffix,this.continuing_subword_suffix=t.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.ignore_merges=this.config.ignore_merges??!1,this.max_length_to_cache=256,this.cache_capacity=1e4,this.cache=new b1(this.cache_capacity)}clear_cache(){this.cache.clear()}bpe(t){if(t.length===0)return[];let e=this.cache.get(t);if(e!==void 0)return e;let s=Array.from(t);this.end_of_word_suffix&&(s[s.length-1]+=this.end_of_word_suffix);let r=[];if(s.length>1){let n=new w1((a,l)=>a.score<l.score),o={token:s[0],bias:0,prev:null,next:null},i=o;for(let a=1;a<s.length;++a){let l={bias:a/s.length,token:s[a],prev:i,next:null};i.next=l,this.add_node(n,i),i=l}for(;!n.is_empty();){let a=n.pop();if(a.deleted||!a.next||a.next.deleted)continue;if(a.deleted=!0,a.next.deleted=!0,a.prev){let c={...a.prev};a.prev.deleted=!0,a.prev=c,c.prev?c.prev.next=c:o=c}let l={token:a.token+a.next.token,bias:a.bias,prev:a.prev,next:a.next.next};l.prev?(l.prev.next=l,this.add_node(n,l.prev)):o=l,l.next&&(l.next.prev=l,this.add_node(n,l))}for(let a=o;a!==null;a=a.next)r.push(a.token)}else r=s;if(this.continuing_subword_suffix)for(let n=0;n<r.length-1;++n)r[n]+=this.continuing_subword_suffix;return t.length<this.max_length_to_cache&&this.cache.put(t,r),r}add_node(t,e){let s=this.bpe_ranks.get(JSON.stringify([e.token,e.next.token]));s!==void 0&&(e.score=s+e.bias,t.push(e))}encode(t){let e=[];for(let s of t){if(this.ignore_merges&&this.tokens_to_ids.has(s)){e.push(s);continue}let r=this.bpe(s);for(let n of r)if(this.tokens_to_ids.has(n))e.push(n);else if(this.byte_fallback){let o=Array.from(this.text_encoder.encode(n)).map(i=>`<0x${i.toString(16).toUpperCase().padStart(2,"0")}>`);o.every(i=>this.tokens_to_ids.has(i))?e.push(...o):e.push(this.unk_token)}else e.push(this.unk_token)}return e}},xw=k1,v1=class extends Ci{constructor(t,e){super(t);let s=t.vocab;this.tokens_to_ids=uc(e.target_lang?s[e.target_lang]:s),this.bos_token=e.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=e.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=e.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=e.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(let[r,n]of this.tokens_to_ids)this.vocab[n]=r}encode(t){return t}},E1=v1;function A1(t,e){switch(t.type){case"WordPiece":return new fw(t);case"Unigram":return new hw(t,e.eos_token);case"BPE":return new xw(t);default:if(t.vocab)return Array.isArray(t.vocab)?new hw(t,e.eos_token):Object.hasOwn(t,"continuing_subword_prefix")&&Object.hasOwn(t,"unk_token")?Object.hasOwn(t,"merges")?new xw(t):new fw(t):new E1(t,{target_lang:e.target_lang,bos_token:e.bos_token,eos_token:e.eos_token,pad_token:e.pad_token,unk_token:e.unk_token});throw new Error(`Unknown TokenizerModel type: ${t?.type}`)}}var M1=A1,S1=class extends fr{constructor(t){super(),this.config=t}_call(t,...e){return this.post_process(t,...e)}},mr=S1,O1=class extends mr{post_process(t,e=null,s=!0){let r=e===null?this.config.single:this.config.pair,n=[],o=[];for(let i of r)"SpecialToken"in i?s&&(n.push(i.SpecialToken.id),o.push(i.SpecialToken.type_id)):"Sequence"in i&&(i.Sequence.id==="A"?(n=rt(n,t),o=rt(o,new Array(t.length).fill(i.Sequence.type_id))):i.Sequence.id==="B"&&(n=rt(n,e),o=rt(o,new Array(e.length).fill(i.Sequence.type_id))));return{tokens:n,token_type_ids:o}}},I1=O1,T1=class extends mr{post_process(t,e=null){return{tokens:t,tokens_pair:e}}},z1=T1,P1=class extends mr{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e=null,s=!0){s&&(t=rt([this.cls[0]],t,[this.sep[0]]));let r=new Array(t.length).fill(0);if(e){let n=[],o=s?[this.sep[0]]:[];t=rt(t,n,e,o),r=rt(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},C1=P1,N1=class extends mr{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e,s=!0){s&&(t=rt([this.cls[0]],t,[this.sep[0]]));let r=new Array(t.length).fill(0);if(e){let n=s?[this.sep[0]]:[],o=s?[this.sep[0]]:[];t=rt(t,n,e,o),r=rt(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},L1=N1,$1=class extends mr{constructor(t){super(t),this.processors=(t.processors??[]).map(e=>Ew(e))}post_process(t,e=null,s=!0){let r={tokens:t,tokens_pair:e};for(let n of this.processors)r=n.post_process(r.tokens,r.tokens_pair,s);return r}},R1=$1;function F1(t){if(t===null)return null;switch(t.type){case"TemplateProcessing":return new I1(t);case"ByteLevel":return new z1(t);case"BertProcessing":return new C1(t);case"RobertaProcessing":return new L1(t);case"Sequence":return new R1(t);default:throw new Error(`Unknown PostProcessor type: ${t.type}`)}}var Ew=F1,D1=class extends fr{constructor(t){super(),this.config=t,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets="trim_offsets"in t?t.trim_offsets:!1}_call(t){return this.decode(t)}decode(t){return this.decode_chain(t).join("")}},Ke=D1,j1=class extends Ke{constructor(t){super(t),this.byte_decoder=sb,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(t){let e=t.join(""),s=new Uint8Array([...e].map(r=>this.byte_decoder[r]));return this.text_decoder.decode(s)}decode_chain(t){let e=[],s=[];for(let r of t)this.added_tokens.find(n=>n.content===r)!==void 0?(s.length>0&&(e.push(this.convert_tokens_to_string(s)),s=[]),e.push(r)):s.push(r);return s.length>0&&e.push(this.convert_tokens_to_string(s)),e}},U1=j1,B1=class extends Ke{constructor(t){super(t),this.cleanup=t.cleanup}decode_chain(t){return t.map((e,s)=>{if(s!==0){let r=this.config.prefix;r&&e.startsWith(r)?e=e.replace(r,""):e=" "+e}return this.cleanup&&(e=cc(e)),e})}},q1=B1,G1=class extends Ke{constructor(t){super(t),this.replacement=t.replacement??"\u2581"}decode_chain(t){let e=[];for(let s=0;s<t.length;++s){let r=t[s].replaceAll(this.replacement," ");s==0&&r.startsWith(" ")&&(r=r.substring(1)),e.push(r)}return e}},W1=G1,V1=class extends Ke{constructor(t){super(t),this.suffix=t.suffix??""}decode_chain(t){return t.map((e,s)=>e.replaceAll(this.suffix,s===t.length-1?"":" "))}},H1=V1,K1=class extends Ke{constructor(t){super(t),this.pad_token=t.pad_token??"",this.word_delimiter_token=t.word_delimiter_token??"",this.cleanup=t.cleanup}convert_tokens_to_string(t){if(t.length===0)return"";let e=[t[0]];for(let n=1;n<t.length;++n)t[n]!==e.at(-1)&&e.push(t[n]);let r=e.filter(n=>n!==this.pad_token).join("");return this.cleanup&&(r=cc(r).replaceAll(this.word_delimiter_token," ").trim()),r}decode_chain(t){return[this.convert_tokens_to_string(t)]}},X1=K1,Q1=class extends Ke{constructor(t){super(t),this.decoders=(t.decoders??[]).map(e=>Aw(e))}decode_chain(t){return this.decoders.reduce((e,s)=>s.decode_chain(e),t)}},Y1=Q1,J1=class extends Ke{decode_chain(t){let e=zi(this.config.pattern),s=this.config.content??"";return e===null?t:t.map(r=>r.replaceAll(e,s))}},Z1=J1,ek=class extends Ke{decode_chain(t){return[t.join("")]}},tk=ek,sk=class extends Ke{constructor(t){super(t),this.content=t.content??"",this.start=t.start??0,this.stop=t.stop??0}decode_chain(t){return t.map(e=>{let s=0;for(let n=0;n<this.start&&e[n]===this.content;++n){s=n+1;continue}let r=e.length;for(let n=0;n<this.stop;++n){let o=e.length-n-1;if(e[o]===this.content){r=o;continue}else break}return e.slice(s,r)})}},rk=sk,nk=class extends Ke{constructor(t){super(t),this.text_decoder=new TextDecoder}decode_chain(t){let e=[],s=[];for(let r of t){let n=null;if(r.length===6&&r.startsWith("<0x")&&r.endsWith(">")){let o=parseInt(r.slice(3,5),16);isNaN(o)||(n=o)}if(n!==null)s.push(n);else{if(s.length>0){let o=this.text_decoder.decode(Uint8Array.from(s));e.push(o),s=[]}e.push(r)}}if(s.length>0){let r=this.text_decoder.decode(Uint8Array.from(s));e.push(r),s=[]}return e}},ok=nk;function ik(t){if(t===null)return null;switch(t.type){case"ByteLevel":return new U1(t);case"WordPiece":return new q1(t);case"Metaspace":return new W1(t);case"BPEDecoder":return new H1(t);case"CTC":return new X1(t);case"Sequence":return new Y1(t);case"Replace":return new Z1(t);case"Fuse":return new tk(t);case"Strip":return new rk(t);case"ByteFallback":return new ok(t);default:throw new Error(`Unknown Decoder type: ${t.type}`)}}var Aw=ik,ak=class{constructor(t,e){let s=_w(t,"Tokenizer",["model","decoder","post_processor","pre_tokenizer","normalizer"]);if(s)throw new Error(s);let r=_w(e,"Config");if(r)throw new Error(r);this.tokenizer=t,this.config=e,this.normalizer=yw(this.tokenizer.normalizer),this.pre_tokenizer=bw(this.tokenizer.pre_tokenizer),this.model=M1(this.tokenizer.model,this.config),this.post_processor=Ew(this.tokenizer.post_processor),this.decoder=Aw(this.tokenizer.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];let n=[],o=[];this.added_tokens_map=new Map;for(let i of this.tokenizer.added_tokens){let a=new eb(i);if(this.added_tokens.push(a),this.model.tokens_to_ids.set(a.content,a.id),this.model.vocab[a.id]=a.content,a.special&&(this.special_tokens.push(a.content),this.all_special_ids.push(a.id)),this.added_tokens_map.set(a.content,a),a.normalized&&this.normalizer!==null){let l=this.normalizer(a.content);o.push(l),this.added_tokens_map.set(l,a)}else n.push(a.content)}(this.config.additional_special_tokens??[]).forEach(i=>{this.special_tokens.includes(i)||this.special_tokens.push(i)}),this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.splitter_unnormalized=new pw(n),this.splitter_normalized=new pw(o),this.remove_space=this.config.remove_space,this.clean_up_tokenization_spaces=this.config.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=this.config.do_lowercase_and_remove_accent??!1}encode(t,{text_pair:e=null,add_special_tokens:s=!0,return_token_type_ids:r=null}={}){let{tokens:n,token_type_ids:o}=this.tokenize_helper(t,{text_pair:e,add_special_tokens:s}),i=n.map(l=>this.added_tokens_map.get(l)?.id??this.model.tokens_to_ids.get(l)??this.model.unk_token_id),a={ids:i,tokens:n,attention_mask:new Array(i.length).fill(1)};return r&&o&&(a.token_type_ids=o),a}decode(t,e={}){if(!Array.isArray(t)||t.length===0||!ab(t[0]))throw Error("token_ids must be a non-empty array of integers.");let s=t.map(n=>this.model.vocab[Number(n)]??this.model.unk_token);e.skip_special_tokens&&(s=s.filter(n=>!this.special_tokens.includes(n)));let r=this.decoder?this.decoder(s):s.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(r=r.replaceAll(this.decoder.end_of_word_suffix," "),e.skip_special_tokens&&(r=r.trim())),(e.clean_up_tokenization_spaces??this.clean_up_tokenization_spaces)&&(r=cc(r)),r}tokenize(t,{text_pair:e=null,add_special_tokens:s=!1}={}){return this.tokenize_helper(t,{text_pair:e,add_special_tokens:s}).tokens}encode_text(t){if(t===null)return null;let e=this.splitter_unnormalized.split(t);return e.forEach((s,r)=>{let n=this.added_tokens_map.get(s);n&&(n.lstrip&&r>0&&(e[r-1]=e[r-1].trimEnd()),n.rstrip&&r<e.length-1&&(e[r+1]=e[r+1].trimStart()))}),e.flatMap((s,r)=>{if(s.length===0)return[];if(this.added_tokens_map.has(s))return[s];if(this.remove_space===!0&&(s=s.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(s=cb(s)),this.normalizer!==null&&(s=this.normalizer(s)),s.length===0)return[];let n=this.splitter_normalized.split(s);return n.forEach((o,i)=>{let a=this.added_tokens_map.get(o);a&&(a.lstrip&&i>0&&(n[i-1]=n[i-1].trimEnd()),a.rstrip&&i<n.length-1&&(n[i+1]=n[i+1].trimStart()))}),n.flatMap(o=>{if(o.length===0)return[];if(this.added_tokens_map.has(o))return[o];let i=this.pre_tokenizer!==null?this.pre_tokenizer(o,{section_index:r}):[o];return this.model(i)})})}tokenize_helper(t,{text_pair:e=null,add_special_tokens:s=!0}){let r=this.encode_text(t),n=this.encode_text(e||null);return this.post_processor?this.post_processor(r,n,s):{tokens:rt(r??[],n??[])}}token_to_id(t){return this.model.tokens_to_ids.get(t)}id_to_token(t){return this.model.vocab[t]}get_added_tokens_decoder(){let t=new Map;for(let e of this.added_tokens)t.set(e.id,e);return t}get_vocab(t=!0){let e=new Map;for(let s=0;s<this.model.vocab.length;++s){let r=this.model.vocab[s];(t||!this.added_tokens_map.has(r))&&e.set(r,s)}return e}},Mw=ak;var M=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",OpenCurlyBracket:"OpenCurlyBracket",CloseCurlyBracket:"CloseCurlyBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Comment:"Comment"}),Xe=class{constructor(t,e){this.value=t,this.type=e}};function Sw(t){return/\w/.test(t)}function hr(t){return/[0-9]/.test(t)}function Ow(t){return/\s/.test(t)}var lk=[["{%",M.OpenStatement],["%}",M.CloseStatement],["{{",M.OpenExpression],["}}",M.CloseExpression],["(",M.OpenParen],[")",M.CloseParen],["{",M.OpenCurlyBracket],["}",M.CloseCurlyBracket],["[",M.OpenSquareBracket],["]",M.CloseSquareBracket],[",",M.Comma],[".",M.Dot],[":",M.Colon],["|",M.Pipe],["<=",M.ComparisonBinaryOperator],[">=",M.ComparisonBinaryOperator],["==",M.ComparisonBinaryOperator],["!=",M.ComparisonBinaryOperator],["<",M.ComparisonBinaryOperator],[">",M.ComparisonBinaryOperator],["+",M.AdditiveBinaryOperator],["-",M.AdditiveBinaryOperator],["~",M.AdditiveBinaryOperator],["*",M.MultiplicativeBinaryOperator],["/",M.MultiplicativeBinaryOperator],["%",M.MultiplicativeBinaryOperator],["=",M.Equals]],ck=new Map([["n",`
3
+ `],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function uk(t,e={}){return t.endsWith(`
4
+ `)&&(t=t.slice(0,-1)),e.lstrip_blocks&&(t=t.replace(/^[ \t]*({[#%-])/gm,"$1")),e.trim_blocks&&(t=t.replace(/([#%-]})\n/g,"$1")),t.replace(/{%\s*(end)?generation\s*%}/gs,"")}function pk(t,e={}){let s=[],r=uk(t,e),n=0,o=0,i=c=>{let u="";for(;c(r[n]);){if(r[n]==="\\"){if(++n,n>=r.length)throw new SyntaxError("Unexpected end of input");let p=r[n++],d=ck.get(p);if(d===void 0)throw new SyntaxError(`Unexpected escaped character: ${p}`);u+=d;continue}if(u+=r[n++],n>=r.length)throw new SyntaxError("Unexpected end of input")}return u},a=()=>{let c=s.at(-1);c&&c.type===M.Text&&(c.value=c.value.trimEnd(),c.value===""&&s.pop())},l=()=>{for(;n<r.length&&Ow(r[n]);)++n};e:for(;n<r.length;){let c=s.at(-1)?.type;if(c===void 0||c===M.CloseStatement||c===M.CloseExpression||c===M.Comment){let p="";for(;n<r.length&&!(r[n]==="{"&&(r[n+1]==="%"||r[n+1]==="{"||r[n+1]==="#"));)p+=r[n++];if(p.length>0){s.push(new Xe(p,M.Text));continue}}if(r[n]==="{"&&r[n+1]==="#"){n+=2;let p=r[n]==="-";p&&++n;let d="";for(;r[n]!=="#"||r[n+1]!=="}";){if(n+2>=r.length)throw new SyntaxError("Missing end of comment tag");d+=r[n++]}let _=d.endsWith("-");_&&(d=d.slice(0,-1)),p&&a(),s.push(new Xe(d,M.Comment)),n+=2,_&&l();continue}if(r.slice(n,n+3)==="{%-"){a(),s.push(new Xe("{%",M.OpenStatement)),n+=3;continue}if(r.slice(n,n+3)==="{{-"){a(),s.push(new Xe("{{",M.OpenExpression)),o=0,n+=3;continue}if(i(Ow),r.slice(n,n+3)==="-%}"){s.push(new Xe("%}",M.CloseStatement)),n+=3,l();continue}if(r.slice(n,n+3)==="-}}"){s.push(new Xe("}}",M.CloseExpression)),n+=3,l();continue}let u=r[n];if(u==="-"||u==="+"){let p=s.at(-1)?.type;if(p===M.Text||p===void 0)throw new SyntaxError(`Unexpected character: ${u}`);switch(p){case M.Identifier:case M.NumericLiteral:case M.StringLiteral:case M.CloseParen:case M.CloseSquareBracket:break;default:{++n;let d=i(hr);s.push(new Xe(`${u}${d}`,d.length>0?M.NumericLiteral:M.UnaryOperator));continue}}}for(let[p,d]of lk){if(p==="}}"&&o>0)continue;if(r.slice(n,n+p.length)===p){s.push(new Xe(p,d)),d===M.OpenExpression?o=0:d===M.OpenCurlyBracket?++o:d===M.CloseCurlyBracket&&--o,n+=p.length;continue e}}if(u==="'"||u==='"'){++n;let p=i(d=>d!==u);s.push(new Xe(p,M.StringLiteral)),++n;continue}if(hr(u)){let p=i(hr);if(r[n]==="."&&hr(r[n+1])){++n;let d=i(hr);p=`${p}.${d}`}s.push(new Xe(p,M.NumericLiteral));continue}if(Sw(u)){let p=i(Sw);s.push(new Xe(p,M.Identifier));continue}throw new SyntaxError(`Unexpected character: ${u}`)}return s}var it=class{type="Statement"},dk=class extends it{constructor(t){super(),this.body=t}type="Program"},_k=class extends it{constructor(t,e,s){super(),this.test=t,this.body=e,this.alternate=s}type="If"},fk=class extends it{constructor(t,e,s,r){super(),this.loopvar=t,this.iterable=e,this.body=s,this.defaultBlock=r}type="For"},mk=class extends it{type="Break"},hk=class extends it{type="Continue"},xk=class extends it{constructor(t,e,s){super(),this.assignee=t,this.value=e,this.body=s}type="Set"},gk=class extends it{constructor(t,e,s){super(),this.name=t,this.args=e,this.body=s}type="Macro"},wk=class extends it{constructor(t){super(),this.value=t}type="Comment"},We=class extends it{type="Expression"},yk=class extends We{constructor(t,e,s){super(),this.object=t,this.property=e,this.computed=s}type="MemberExpression"},Iw=class extends We{constructor(t,e){super(),this.callee=t,this.args=e}type="CallExpression"},Os=class extends We{constructor(t){super(),this.value=t}type="Identifier"},Is=class extends We{constructor(t){super(),this.value=t}type="Literal"},bk=class extends Is{type="IntegerLiteral"},kk=class extends Is{type="FloatLiteral"},Tw=class extends Is{type="StringLiteral"},vk=class extends Is{type="ArrayLiteral"},zw=class extends Is{type="TupleLiteral"},Ek=class extends Is{type="ObjectLiteral"},xr=class extends We{constructor(t,e,s){super(),this.operator=t,this.left=e,this.right=s}type="BinaryExpression"},Ak=class extends We{constructor(t,e){super(),this.operand=t,this.filter=e}type="FilterExpression"},Mk=class extends it{constructor(t,e){super(),this.filter=t,this.body=e}type="FilterStatement"},Sk=class extends We{constructor(t,e){super(),this.lhs=t,this.test=e}type="SelectExpression"},Ok=class extends We{constructor(t,e,s){super(),this.operand=t,this.negate=e,this.test=s}type="TestExpression"},Ik=class extends We{constructor(t,e){super(),this.operator=t,this.argument=e}type="UnaryExpression"},Tk=class extends We{constructor(t=void 0,e=void 0,s=void 0){super(),this.start=t,this.stop=e,this.step=s}type="SliceExpression"},zk=class extends We{constructor(t,e){super(),this.key=t,this.value=e}type="KeywordArgumentExpression"},Pk=class extends We{constructor(t){super(),this.argument=t}type="SpreadExpression"},Ck=class extends it{constructor(t,e,s){super(),this.call=t,this.callerArgs=e,this.body=s}type="CallStatement"},Nk=class extends We{constructor(t,e,s){super(),this.condition=t,this.trueExpr=e,this.falseExpr=s}type="Ternary"};function Lk(t){let e=new dk([]),s=0;function r(v,E){let T=t[s++];if(!T||T.type!==v)throw new Error(`Parser Error: ${E}. ${T.type} !== ${v}.`);return T}function n(v){if(!l(v))throw new SyntaxError(`Expected ${v}`);++s}function o(){switch(t[s].type){case M.Comment:return new wk(t[s++].value);case M.Text:return c();case M.OpenStatement:return u();case M.OpenExpression:return p();default:throw new SyntaxError(`Unexpected token type: ${t[s].type}`)}}function i(...v){return s+v.length<=t.length&&v.every((E,T)=>E===t[s+T].type)}function a(...v){return t[s]?.type===M.OpenStatement&&t[s+1]?.type===M.Identifier&&v.includes(t[s+1]?.value)}function l(...v){return s+v.length<=t.length&&v.every((E,T)=>t[s+T].type==="Identifier"&&E===t[s+T].value)}function c(){return new Tw(r(M.Text,"Expected text token").value)}function u(){if(r(M.OpenStatement,"Expected opening statement token"),t[s].type!==M.Identifier)throw new SyntaxError(`Unknown statement, got ${t[s].type}`);let v=t[s].value,E;switch(v){case"set":++s,E=d();break;case"if":++s,E=_(),r(M.OpenStatement,"Expected {% token"),n("endif"),r(M.CloseStatement,"Expected %} token");break;case"macro":++s,E=f(),r(M.OpenStatement,"Expected {% token"),n("endmacro"),r(M.CloseStatement,"Expected %} token");break;case"for":++s,E=x(),r(M.OpenStatement,"Expected {% token"),n("endfor"),r(M.CloseStatement,"Expected %} token");break;case"call":{++s;let T=null;i(M.OpenParen)&&(T=F());let J=te();if(J.type!=="Identifier")throw new SyntaxError("Expected identifier following call statement");let se=F();r(M.CloseStatement,"Expected closing statement token");let Ie=[];for(;!a("endcall");)Ie.push(o());r(M.OpenStatement,"Expected '{%'"),n("endcall"),r(M.CloseStatement,"Expected closing statement token");let Ae=new Iw(J,se);E=new Ck(Ae,T,Ie);break}case"break":++s,r(M.CloseStatement,"Expected closing statement token"),E=new mk;break;case"continue":++s,r(M.CloseStatement,"Expected closing statement token"),E=new hk;break;case"filter":{++s;let T=te();T instanceof Os&&i(M.OpenParen)&&(T=D(T)),r(M.CloseStatement,"Expected closing statement token");let J=[];for(;!a("endfilter");)J.push(o());r(M.OpenStatement,"Expected '{%'"),n("endfilter"),r(M.CloseStatement,"Expected '%}'"),E=new Mk(T,J);break}default:throw new SyntaxError(`Unknown statement type: ${v}`)}return E}function p(){r(M.OpenExpression,"Expected opening expression token");let v=g();return r(M.CloseExpression,"Expected closing expression token"),v}function d(){let v=h(),E=null,T=[];if(i(M.Equals))++s,E=h();else{for(r(M.CloseStatement,"Expected %} token");!a("endset");)T.push(o());r(M.OpenStatement,"Expected {% token"),n("endset")}return r(M.CloseStatement,"Expected closing statement token"),new xk(v,E,T)}function _(){let v=g();r(M.CloseStatement,"Expected closing statement token");let E=[],T=[];for(;!a("elif","else","endif");)E.push(o());if(a("elif")){++s,++s;let J=_();T.push(J)}else if(a("else"))for(++s,++s,r(M.CloseStatement,"Expected closing statement token");!a("endif");)T.push(o());return new _k(v,E,T)}function f(){let v=te();if(v.type!=="Identifier")throw new SyntaxError("Expected identifier following macro statement");let E=F();r(M.CloseStatement,"Expected closing statement token");let T=[];for(;!a("endmacro");)T.push(o());return new gk(v,E,T)}function h(v=!1){let E=v?te:g,T=[E()],J=i(M.Comma);for(;J&&(++s,T.push(E()),!!i(M.Comma)););return J?new zw(T):T[0]}function x(){let v=h(!0);if(!(v instanceof Os||v instanceof zw))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${v.type} instead`);if(!l("in"))throw new SyntaxError("Expected `in` keyword following loop variable");++s;let E=g();r(M.CloseStatement,"Expected closing statement token");let T=[];for(;!a("endfor","else");)T.push(o());let J=[];if(a("else"))for(++s,++s,r(M.CloseStatement,"Expected closing statement token");!a("endfor");)J.push(o());return new fk(v,E,T,J)}function g(){return w()}function w(){let v=y();if(l("if")){++s;let E=y();if(l("else")){++s;let T=w();return new Nk(E,v,T)}else return new Sk(v,E)}return v}function y(){let v=b();for(;l("or");){let E=t[s];++s;let T=b();v=new xr(E,v,T)}return v}function b(){let v=A();for(;l("and");){let E=t[s];++s;let T=A();v=new xr(E,v,T)}return v}function A(){let v;for(;l("not");){let E=t[s];++s;let T=A();v=new Ik(E,T)}return v??k()}function k(){let v=O();for(;;){let E;if(l("not","in"))E=new Xe("not in",M.Identifier),s+=2;else if(l("in"))E=t[s++];else if(i(M.ComparisonBinaryOperator))E=t[s++];else break;let T=O();v=new xr(E,v,T)}return v}function O(){let v=Q();for(;i(M.AdditiveBinaryOperator);){let E=t[s];++s;let T=Q();v=new xr(E,v,T)}return v}function N(){let v=j(te());return i(M.OpenParen)?D(v):v}function D(v){let E=new Iw(v,F());return E=j(E),i(M.OpenParen)&&(E=D(E)),E}function F(){r(M.OpenParen,"Expected opening parenthesis for arguments list");let v=B();return r(M.CloseParen,"Expected closing parenthesis for arguments list"),v}function B(){let v=[];for(;!i(M.CloseParen);){let E;if(t[s].type===M.MultiplicativeBinaryOperator&&t[s].value==="*"){++s;let T=g();E=new Pk(T)}else if(E=g(),i(M.Equals)){if(++s,!(E instanceof Os))throw new SyntaxError("Expected identifier for keyword argument");let T=g();E=new zk(E,T)}v.push(E),i(M.Comma)&&++s}return v}function W(){let v=[],E=!1;for(;!i(M.CloseSquareBracket);)i(M.Colon)?(v.push(void 0),++s,E=!0):(v.push(g()),i(M.Colon)&&(++s,E=!0));if(v.length===0)throw new SyntaxError("Expected at least one argument for member/slice expression");if(E){if(v.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new Tk(...v)}return v[0]}function j(v){for(;i(M.Dot)||i(M.OpenSquareBracket);){let E=t[s];++s;let T,J=E.type===M.OpenSquareBracket;if(J)T=W(),r(M.CloseSquareBracket,"Expected closing square bracket");else if(T=te(),T.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");v=new yk(v,T,J)}return v}function Q(){let v=K();for(;i(M.MultiplicativeBinaryOperator);){let E=t[s++],T=K();v=new xr(E,v,T)}return v}function K(){let v=oe();for(;l("is");){++s;let E=l("not");E&&++s;let T=te();if(!(T instanceof Os))throw new SyntaxError("Expected identifier for the test");v=new Ok(v,E,T)}return v}function oe(){let v=N();for(;i(M.Pipe);){++s;let E=te();if(!(E instanceof Os))throw new SyntaxError("Expected identifier for the filter");i(M.OpenParen)&&(E=D(E)),v=new Ak(v,E)}return v}function te(){let v=t[s++];switch(v.type){case M.NumericLiteral:{let E=v.value;return E.includes(".")?new kk(Number(E)):new bk(Number(E))}case M.StringLiteral:{let E=v.value;for(;i(M.StringLiteral);)E+=t[s++].value;return new Tw(E)}case M.Identifier:return new Os(v.value);case M.OpenParen:{let E=h();return r(M.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),E}case M.OpenSquareBracket:{let E=[];for(;!i(M.CloseSquareBracket);)E.push(g()),i(M.Comma)&&++s;return++s,new vk(E)}case M.OpenCurlyBracket:{let E=new Map;for(;!i(M.CloseCurlyBracket);){let T=g();r(M.Colon,"Expected colon between key and value in object literal");let J=g();E.set(T,J),i(M.Comma)&&++s}return++s,new Ek(E)}default:throw new SyntaxError(`Unexpected token: ${v.type}`)}}for(;s<t.length;)e.body.push(o());return e}function $k(t,e,s=1){if(e===void 0&&(e=t,t=0),s===0)throw new Error("range() step must not be zero");let r=[];if(s>0)for(let n=t;n<e;n+=s)r.push(n);else for(let n=t;n>e;n+=s)r.push(n);return r}function Pw(t,e,s,r=1){let n=Math.sign(r);n>=0?(e=(e??=0)<0?Math.max(t.length+e,0):Math.min(e,t.length),s=(s??=t.length)<0?Math.max(t.length+s,0):Math.min(s,t.length)):(e=(e??=t.length-1)<0?Math.max(t.length+e,-1):Math.min(e,t.length-1),s=(s??=-1)<-1?Math.max(t.length+s,-1):Math.min(s,t.length-1));let o=[];for(let i=e;n*i<n*s;i+=r)o.push(t[i]);return o}function Rk(t){return t.replace(/\b\w/g,e=>e.toUpperCase())}function Fk(t){return Dk(new Date,t)}function Dk(t,e){let s=new Intl.DateTimeFormat(void 0,{month:"long"}),r=new Intl.DateTimeFormat(void 0,{month:"short"}),n=o=>o<10?"0"+o:o.toString();return e.replace(/%[YmdbBHM%]/g,o=>{switch(o){case"%Y":return t.getFullYear().toString();case"%m":return n(t.getMonth()+1);case"%d":return n(t.getDate());case"%b":return r.format(t);case"%B":return s.format(t);case"%H":return n(t.getHours());case"%M":return n(t.getMinutes());case"%%":return"%";default:return o}})}function jk(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Uk(t,e,s,r){if(r===0)return t;let n=r==null||r<0?1/0:r,o=e.length===0?new RegExp("(?=)","gu"):new RegExp(jk(e),"gu");return t.replaceAll(o,i=>n>0?(--n,s):i)}var Cw=class extends Error{},Nw=class extends Error{},dt=class{type="RuntimeValue";value;builtins=new Map;constructor(t=void 0){this.value=t}__bool__(){return new q(!!this.value)}toString(){return String(this.value)}},X=class extends dt{type="IntegerValue"},be=class extends dt{type="FloatValue";toString(){return this.value%1===0?this.value.toFixed(1):this.value.toString()}},R=class extends dt{type="StringValue";builtins=new Map([["upper",new he(()=>new R(this.value.toUpperCase()))],["lower",new he(()=>new R(this.value.toLowerCase()))],["strip",new he(()=>new R(this.value.trim()))],["title",new he(()=>new R(Rk(this.value)))],["capitalize",new he(()=>new R(this.value.charAt(0).toUpperCase()+this.value.slice(1)))],["length",new X(this.value.length)],["rstrip",new he(()=>new R(this.value.trimEnd()))],["lstrip",new he(()=>new R(this.value.trimStart()))],["startswith",new he(t=>{if(t.length===0)throw new Error("startswith() requires at least one argument");let e=t[0];if(e instanceof R)return new q(this.value.startsWith(e.value));if(e instanceof re){for(let s of e.value){if(!(s instanceof R))throw new Error("startswith() tuple elements must be strings");if(this.value.startsWith(s.value))return new q(!0)}return new q(!1)}throw new Error("startswith() argument must be a string or tuple of strings")})],["endswith",new he(t=>{if(t.length===0)throw new Error("endswith() requires at least one argument");let e=t[0];if(e instanceof R)return new q(this.value.endsWith(e.value));if(e instanceof re){for(let s of e.value){if(!(s instanceof R))throw new Error("endswith() tuple elements must be strings");if(this.value.endsWith(s.value))return new q(!0)}return new q(!1)}throw new Error("endswith() argument must be a string or tuple of strings")})],["split",new he(t=>{let e=t[0]??new xe;if(!(e instanceof R||e instanceof xe))throw new Error("sep argument must be a string or null");let s=t[1]??new X(-1);if(!(s instanceof X))throw new Error("maxsplit argument must be a number");let r=[];if(e instanceof xe){let n=this.value.trimStart();for(let{0:o,index:i}of n.matchAll(/\S+/g)){if(s.value!==-1&&r.length>=s.value&&i!==void 0){r.push(o+n.slice(i+o.length));break}r.push(o)}}else{if(e.value==="")throw new Error("empty separator");r=this.value.split(e.value),s.value!==-1&&r.length>s.value&&r.push(r.splice(s.value).join(e.value))}return new re(r.map(n=>new R(n)))})],["replace",new he(t=>{if(t.length<2)throw new Error("replace() requires at least two arguments");let e=t[0],s=t[1];if(!(e instanceof R&&s instanceof R))throw new Error("replace() arguments must be strings");let r;if(t.length>2?t[2].type==="KeywordArgumentsValue"?r=t[2].value.get("count")??new xe:r=t[2]:r=new xe,!(r instanceof X||r instanceof xe))throw new Error("replace() count argument must be a number or null");return new R(Uk(this.value,e.value,s.value,r.value))})]])},q=class extends dt{type="BooleanValue"},Bk=/[\x7f-\uffff]/g;function Lw(t){return t.replace(Bk,e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0"))}function is(t,e={},s=0,r=!0){let{indent:n=null,ensureAscii:o=!1,separators:i=null,sortKeys:a=!1}=e,l,c;switch(i?[l,c]=i:n?(l=",",c=": "):(l=", ",c=": "),t.type){case"NullValue":return"null";case"UndefinedValue":return r?"null":"undefined";case"IntegerValue":case"FloatValue":case"BooleanValue":return JSON.stringify(t.value);case"StringValue":{let u=JSON.stringify(t.value);return o&&(u=Lw(u)),u}case"ArrayValue":case"ObjectValue":{let u=n?" ".repeat(n):"",p=`
5
+ `+u.repeat(s),d=p+u;if(t.type==="ArrayValue"){let _=t.value.map(f=>is(f,e,s+1,r));return n?`[${d}${_.join(`${l}${d}`)}${p}]`:`[${_.join(l)}]`}else{let _=Array.from(t.value.entries());a&&(_=_.sort(([h],[x])=>h.localeCompare(x)));let f=_.map(([h,x])=>{let g=JSON.stringify(h);o&&(g=Lw(g));let w=`${g}${c}${is(x,e,s+1,r)}`;return n?`${d}${w}`:w});return n?`{${f.join(l)}${p}}`:`{${f.join(l)}}`}}default:throw new Error(`Cannot convert to JSON: ${t.type}`)}}var $e=class extends dt{type="ObjectValue";__bool__(){return new q(this.value.size>0)}builtins=new Map([["get",new he(([t,e])=>{if(!(t instanceof R))throw new Error(`Object key must be a string: got ${t.type}`);return this.value.get(t.value)??e??new xe})],["items",new he(()=>this.items())],["keys",new he(()=>this.keys())],["values",new he(()=>this.values())],["dictsort",new he(t=>{let e=new Map,s=t.filter(a=>a instanceof gr?(e=a.value,!1):!0),r=s.at(0)??e.get("case_sensitive")??new q(!1);if(!(r instanceof q))throw new Error("case_sensitive must be a boolean");let n=s.at(1)??e.get("by")??new R("key");if(!(n instanceof R))throw new Error("by must be a string");if(!["key","value"].includes(n.value))throw new Error("by must be either 'key' or 'value'");let o=s.at(2)??e.get("reverse")??new q(!1);if(!(o instanceof q))throw new Error("reverse must be a boolean");let i=Array.from(this.value.entries()).map(([a,l])=>new re([new R(a),l])).sort((a,l)=>{let c=n.value==="key"?0:1,u=a.value[c],p=l.value[c],d=pc(u,p,r.value);return o.value?-d:d});return new re(i)})]]);items(){return new re(Array.from(this.value.entries()).map(([t,e])=>new re([new R(t),e])))}keys(){return new re(Array.from(this.value.keys()).map(t=>new R(t)))}values(){return new re(Array.from(this.value.values()))}toString(){return is(this,{},0,!1)}},gr=class extends $e{type="KeywordArgumentsValue"},re=class extends dt{type="ArrayValue";builtins=new Map([["length",new X(this.value.length)]]);__bool__(){return new q(this.value.length>0)}toString(){return is(this,{},0,!1)}},$w=class extends re{type="TupleValue"},he=class extends dt{type="FunctionValue"},xe=class extends dt{type="NullValue"},me=class extends dt{type="UndefinedValue"},os=class{constructor(t){this.parent=t}variables=new Map([["namespace",new he(t=>{if(t.length===0)return new $e(new Map);if(t.length!==1||!(t[0]instanceof $e))throw new Error("`namespace` expects either zero arguments or a single object argument");return t[0]})]]);tests=new Map([["boolean",t=>t.type==="BooleanValue"],["callable",t=>t instanceof he],["odd",t=>{if(!(t instanceof X))throw new Error(`cannot odd on ${t.type}`);return t.value%2!==0}],["even",t=>{if(!(t instanceof X))throw new Error(`cannot even on ${t.type}`);return t.value%2===0}],["false",t=>t.type==="BooleanValue"&&!t.value],["true",t=>t.type==="BooleanValue"&&t.value],["none",t=>t.type==="NullValue"],["string",t=>t.type==="StringValue"],["number",t=>t instanceof X||t instanceof be],["integer",t=>t instanceof X],["iterable",t=>t.type==="ArrayValue"||t.type==="StringValue"],["mapping",t=>t.type==="ObjectValue"],["lower",t=>{let e=t.value;return t.type==="StringValue"&&e===e.toLowerCase()}],["upper",t=>{let e=t.value;return t.type==="StringValue"&&e===e.toUpperCase()}],["none",t=>t.type==="NullValue"],["defined",t=>t.type!=="UndefinedValue"],["undefined",t=>t.type==="UndefinedValue"],["equalto",(t,e)=>t.value===e.value],["eq",(t,e)=>t.value===e.value]]);set(t,e){return this.declareVariable(t,Ni(e))}declareVariable(t,e){if(this.variables.has(t))throw new SyntaxError(`Variable already declared: ${t}`);return this.variables.set(t,e),e}setVariable(t,e){return this.variables.set(t,e),e}resolve(t){if(this.variables.has(t))return this;if(this.parent)return this.parent.resolve(t);throw new Error(`Unknown variable: ${t}`)}lookupVariable(t){try{return this.resolve(t).variables.get(t)??new me}catch{return new me}}};function qk(t){t.set("false",!1),t.set("true",!0),t.set("none",null),t.set("raise_exception",e=>{throw new Error(e)}),t.set("range",$k),t.set("strftime_now",Fk),t.set("True",!0),t.set("False",!1),t.set("None",null)}function Rw(t,e){let s=e.split("."),r=t;for(let n of s)if(r instanceof $e)r=r.value.get(n)??new me;else if(r instanceof re){let o=parseInt(n,10);if(!isNaN(o)&&o>=0&&o<r.value.length)r=r.value[o];else return new me}else return new me;return r}function pc(t,e,s=!1){if(t instanceof xe&&e instanceof xe)return 0;if(t instanceof xe||e instanceof xe)throw new Error(`Cannot compare ${t.type} with ${e.type}`);if(t instanceof me&&e instanceof me)return 0;if(t instanceof me||e instanceof me)throw new Error(`Cannot compare ${t.type} with ${e.type}`);let r=o=>o instanceof X||o instanceof be||o instanceof q,n=o=>o instanceof q?o.value?1:0:o.value;if(r(t)&&r(e)){let o=n(t),i=n(e);return o<i?-1:o>i?1:0}if(t.type!==e.type)throw new Error(`Cannot compare different types: ${t.type} and ${e.type}`);if(t.type==="StringValue"){let o=t.value,i=e.value;return s||(o=o.toLowerCase(),i=i.toLowerCase()),o<i?-1:o>i?1:0}else throw new Error(`Cannot compare type: ${t.type}`)}var Gk=class{global;constructor(t){this.global=t??new os}run(t){return this.evaluate(t,this.global)}evaluateBinaryExpression(t,e){let s=this.evaluate(t.left,e);switch(t.operator.value){case"and":return s.__bool__().value?this.evaluate(t.right,e):s;case"or":return s.__bool__().value?s:this.evaluate(t.right,e)}let r=this.evaluate(t.right,e);switch(t.operator.value){case"==":return new q(s.value==r.value);case"!=":return new q(s.value!=r.value)}if(s instanceof me||r instanceof me){if(r instanceof me&&["in","not in"].includes(t.operator.value))return new q(t.operator.value==="not in");throw new Error(`Cannot perform operation ${t.operator.value} on undefined values`)}else{if(s instanceof xe||r instanceof xe)throw new Error("Cannot perform operation on null values");if(t.operator.value==="~")return new R(s.value.toString()+r.value.toString());if((s instanceof X||s instanceof be)&&(r instanceof X||r instanceof be)){let n=s.value,o=r.value;switch(t.operator.value){case"+":case"-":case"*":{let i=t.operator.value==="+"?n+o:t.operator.value==="-"?n-o:n*o;return s instanceof be||r instanceof be?new be(i):new X(i)}case"/":return new be(n/o);case"%":{let i=n%o;return s instanceof be||r instanceof be?new be(i):new X(i)}case"<":return new q(n<o);case">":return new q(n>o);case">=":return new q(n>=o);case"<=":return new q(n<=o)}}else if(s instanceof re&&r instanceof re){if(t.operator.value==="+")return new re(s.value.concat(r.value))}else if(r instanceof re){let n=r.value.find(o=>o.value===s.value)!==void 0;switch(t.operator.value){case"in":return new q(n);case"not in":return new q(!n)}}}if((s instanceof R||r instanceof R)&&t.operator.value==="+")return new R(s.value.toString()+r.value.toString());if(s instanceof R&&r instanceof R)switch(t.operator.value){case"in":return new q(r.value.includes(s.value));case"not in":return new q(!r.value.includes(s.value))}if(s instanceof R&&r instanceof $e)switch(t.operator.value){case"in":return new q(r.value.has(s.value));case"not in":return new q(!r.value.has(s.value))}throw new SyntaxError(`Unknown operator "${t.operator.value}" between ${s.type} and ${r.type}`)}evaluateArguments(t,e){let s=[],r=new Map;for(let n of t)if(n.type==="SpreadExpression"){let o=n,i=this.evaluate(o.argument,e);if(!(i instanceof re))throw new Error(`Cannot unpack non-iterable type: ${i.type}`);for(let a of i.value)s.push(a)}else if(n.type==="KeywordArgumentExpression"){let o=n;r.set(o.key.value,this.evaluate(o.value,e))}else{if(r.size>0)throw new Error("Positional arguments must come before keyword arguments");s.push(this.evaluate(n,e))}return[s,r]}applyFilter(t,e,s){if(e.type==="Identifier"){let r=e;if(r.value==="tojson")return new R(is(t,{}));if(t instanceof re)switch(r.value){case"list":return t;case"first":return t.value[0];case"last":return t.value[t.value.length-1];case"length":return new X(t.value.length);case"reverse":return new re(t.value.slice().reverse());case"sort":return new re(t.value.slice().sort((n,o)=>pc(n,o,!1)));case"join":return new R(t.value.map(n=>n.value).join(""));case"string":return new R(is(t,{},0,!1));case"unique":{let n=new Set,o=[];for(let i of t.value)n.has(i.value)||(n.add(i.value),o.push(i));return new re(o)}default:throw new Error(`Unknown ArrayValue filter: ${r.value}`)}else if(t instanceof R)switch(r.value){case"length":case"upper":case"lower":case"title":case"capitalize":{let n=t.builtins.get(r.value);if(n instanceof he)return n.value([],s);if(n instanceof X)return n;throw new Error(`Unknown StringValue filter: ${r.value}`)}case"trim":return new R(t.value.trim());case"indent":return new R(t.value.split(`
6
6
  `).map((n,o)=>o===0||n.length===0?n:" "+n).join(`
7
- `));case"join":case"string":return t;case"int":{let n=parseInt(t.value,10);return new H(isNaN(n)?0:n)}case"float":{let n=parseFloat(t.value);return new ye(isNaN(n)?0:n)}default:throw new Error(`Unknown StringValue filter: ${r.value}`)}else if(t instanceof H||t instanceof ye)switch(r.value){case"abs":return t instanceof H?new H(Math.abs(t.value)):new ye(Math.abs(t.value));case"int":return new H(Math.floor(t.value));case"float":return new ye(t.value);default:throw new Error(`Unknown NumericValue filter: ${r.value}`)}else if(t instanceof Le)switch(r.value){case"items":return new te(Array.from(t.value.entries()).map(([n,o])=>new te([new $(n),o])));case"length":return new H(t.value.size);default:{let n=t.builtins.get(r.value);if(n)return n instanceof me?n.value([],s):n;throw new Error(`Unknown ObjectValue filter: ${r.value}`)}}else if(t instanceof U)switch(r.value){case"bool":return new U(t.value);case"int":return new H(t.value?1:0);case"float":return new ye(t.value?1:0);case"string":return new $(t.value?"true":"false");default:throw new Error(`Unknown BooleanValue filter: ${r.value}`)}throw new Error(`Cannot apply filter "${r.value}" to type: ${t.type}`)}else if(e.type==="CallExpression"){let r=e;if(r.callee.type!=="Identifier")throw new Error(`Unknown filter: ${r.callee.type}`);let n=r.callee.value;if(n==="tojson"){let[,o]=this.evaluateArguments(r.args,s),i=o.get("indent")??new he;if(!(i instanceof H||i instanceof he))throw new Error("If set, indent must be a number");let a=o.get("ensure_ascii")??new U(!1);if(!(a instanceof U))throw new Error("If set, ensure_ascii must be a boolean");let l=o.get("sort_keys")??new U(!1);if(!(l instanceof U))throw new Error("If set, sort_keys must be a boolean");let c=o.get("separators")??new he,u=null;if(c instanceof te||c instanceof sw){if(c.value.length!==2)throw new Error("separators must be a tuple of two strings");let[p,d]=c.value;if(!(p instanceof $)||!(d instanceof $))throw new Error("separators must be a tuple of two strings");u=[p.value,d.value]}else if(!(c instanceof he))throw new Error("If set, separators must be a tuple of two strings");return new $(Ht(t,{indent:i.value,ensureAscii:a.value,sortKeys:l.value,separators:u}))}else if(n==="join"){let o;if(t instanceof $)o=Array.from(t.value);else if(t instanceof te)o=t.value.map(c=>c.value);else throw new Error(`Cannot apply filter "${n}" to type: ${t.type}`);let[i,a]=this.evaluateArguments(r.args,s),l=i.at(0)??a.get("separator")??new $("");if(!(l instanceof $))throw new Error("separator must be a string");return new $(o.join(l.value))}else if(n==="int"||n==="float"){let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("default")??(n==="int"?new H(0):new ye(0));if(t instanceof $){let l=n==="int"?parseInt(t.value,10):parseFloat(t.value);return isNaN(l)?a:n==="int"?new H(l):new ye(l)}else{if(t instanceof H||t instanceof ye)return t;if(t instanceof U)return n==="int"?new H(t.value?1:0):new ye(t.value?1:0);throw new Error(`Cannot apply filter "${n}" to type: ${t.type}`)}}else if(n==="default"){let[o,i]=this.evaluateArguments(r.args,s),a=o[0]??new $(""),l=o[1]??i.get("boolean")??new U(!1);if(!(l instanceof U))throw new Error("`default` filter flag must be a boolean");return t instanceof fe||l.value&&!t.__bool__().value?a:t}if(t instanceof te){switch(n){case"sort":{let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("reverse")??new U(!1);if(!(a instanceof U))throw new Error("reverse must be a boolean");let l=o.at(1)??i.get("case_sensitive")??new U(!1);if(!(l instanceof U))throw new Error("case_sensitive must be a boolean");let c=o.at(2)??i.get("attribute")??new he;if(!(c instanceof $||c instanceof H||c instanceof he))throw new Error("attribute must be a string, integer, or null");let u=p=>{if(c instanceof he)return p;let d=c instanceof H?String(c.value):c.value;return rw(p,d)};return new te(t.value.slice().sort((p,d)=>{let _=u(p),m=u(d),h=Dl(_,m,l.value);return a.value?-h:h}))}case"selectattr":case"rejectattr":{let o=n==="selectattr";if(t.value.some(p=>!(p instanceof Le)))throw new Error(`\`${n}\` can only be applied to array of objects`);if(r.args.some(p=>p.type!=="StringLiteral"))throw new Error(`arguments of \`${n}\` must be strings`);let[i,a,l]=r.args.map(p=>this.evaluate(p,s)),c;if(a){let p=s.tests.get(a.value);if(!p)throw new Error(`Unknown test: ${a.value}`);c=p}else c=(...p)=>p[0].__bool__().value;let u=t.value.filter(p=>{let d=p.value.get(i.value),_=d?c(d,l):!1;return o?_:!_});return new te(u)}case"map":{let[,o]=this.evaluateArguments(r.args,s);if(o.has("attribute")){let i=o.get("attribute");if(!(i instanceof $))throw new Error("attribute must be a string");let a=o.get("default"),l=t.value.map(c=>{if(!(c instanceof Le))throw new Error("items in map must be an object");let u=rw(c,i.value);return u instanceof fe?a??new fe:u});return new te(l)}else throw new Error("`map` expressions without `attribute` set are not currently supported.")}}throw new Error(`Unknown ArrayValue filter: ${n}`)}else if(t instanceof $){switch(n){case"indent":{let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("width")??new H(4);if(!(a instanceof H))throw new Error("width must be a number");let l=o.at(1)??i.get("first")??new U(!1),c=o.at(2)??i.get("blank")??new U(!1),u=t.value.split(`
8
- `),p=" ".repeat(a.value),d=u.map((_,m)=>!l.value&&m===0||!c.value&&_.length===0?_:p+_);return new $(d.join(`
9
- `))}case"replace":{let o=t.builtins.get("replace");if(!(o instanceof me))throw new Error("replace filter not available");let[i,a]=this.evaluateArguments(r.args,s);return o.value([...i,new ir(a)],s)}}throw new Error(`Unknown StringValue filter: ${n}`)}else if(t instanceof Le){let o=t.builtins.get(n);if(o&&o instanceof me){let[i,a]=this.evaluateArguments(r.args,s);return a.size>0&&i.push(new ir(a)),o.value(i,s)}throw new Error(`Unknown ObjectValue filter: ${n}`)}else throw new Error(`Cannot apply filter "${n}" to type: ${t.type}`)}throw new Error(`Unknown filter: ${e.type}`)}evaluateFilterExpression(t,e){let s=this.evaluate(t.operand,e);return this.applyFilter(s,t.filter,e)}evaluateTestExpression(t,e){let s=this.evaluate(t.operand,e),r=e.tests.get(t.test.value);if(!r)throw new Error(`Unknown test: ${t.test.value}`);let n=r(s);return new U(t.negate?!n:n)}evaluateSelectExpression(t,e){return this.evaluate(t.test,e).__bool__().value?this.evaluate(t.lhs,e):new fe}evaluateUnaryExpression(t,e){let s=this.evaluate(t.argument,e);if(t.operator.value==="not")return new U(!s.value);throw new SyntaxError(`Unknown operator: ${t.operator.value}`)}evaluateTernaryExpression(t,e){return this.evaluate(t.condition,e).__bool__().value?this.evaluate(t.trueExpr,e):this.evaluate(t.falseExpr,e)}evalProgram(t,e){return this.evaluateBlock(t.body,e)}evaluateBlock(t,e){let s="";for(let r of t){let n=this.evaluate(r,e);n.type!=="NullValue"&&n.type!=="UndefinedValue"&&(s+=n.toString())}return new $(s)}evaluateIdentifier(t,e){return e.lookupVariable(t.value)}evaluateCallExpression(t,e){let[s,r]=this.evaluateArguments(t.args,e);r.size>0&&s.push(new ir(r));let n=this.evaluate(t.callee,e);if(n.type!=="FunctionValue")throw new Error(`Cannot call something that is not a function: got ${n.type}`);return n.value(s,e)}evaluateSliceExpression(t,e,s){if(!(t instanceof te||t instanceof $))throw new Error("Slice object must be an array or string");let r=this.evaluate(e.start,s),n=this.evaluate(e.stop,s),o=this.evaluate(e.step,s);if(!(r instanceof H||r instanceof fe))throw new Error("Slice start must be numeric or undefined");if(!(n instanceof H||n instanceof fe))throw new Error("Slice stop must be numeric or undefined");if(!(o instanceof H||o instanceof fe))throw new Error("Slice step must be numeric or undefined");return t instanceof te?new te(Yg(t.value,r.value,n.value,o.value)):new $(Yg(Array.from(t.value),r.value,n.value,o.value).join(""))}evaluateMemberExpression(t,e){let s=this.evaluate(t.object,e),r;if(t.computed){if(t.property.type==="SliceExpression")return this.evaluateSliceExpression(s,t.property,e);r=this.evaluate(t.property,e)}else r=new $(t.property.value);let n;if(s instanceof Le){if(!(r instanceof $))throw new Error(`Cannot access property with non-string: got ${r.type}`);n=s.value.get(r.value)??s.builtins.get(r.value)}else if(s instanceof te||s instanceof $)if(r instanceof H)n=s.value.at(r.value),s instanceof $&&(n=new $(s.value.at(r.value)));else if(r instanceof $)n=s.builtins.get(r.value);else throw new Error(`Cannot access property with non-string/non-number: got ${r.type}`);else{if(!(r instanceof $))throw new Error(`Cannot access property with non-string: got ${r.type}`);n=s.builtins.get(r.value)}return n instanceof ut?n:new fe}evaluateSet(t,e){let s=t.value?this.evaluate(t.value,e):this.evaluateBlock(t.body,e);if(t.assignee.type==="Identifier"){let r=t.assignee.value;e.setVariable(r,s)}else if(t.assignee.type==="TupleLiteral"){let r=t.assignee;if(!(s instanceof te))throw new Error(`Cannot unpack non-iterable type in set: ${s.type}`);let n=s.value;if(n.length!==r.value.length)throw new Error(`Too ${r.value.length>n.length?"few":"many"} items to unpack in set`);for(let o=0;o<r.value.length;++o){let i=r.value[o];if(i.type!=="Identifier")throw new Error(`Cannot unpack to non-identifier in set: ${i.type}`);e.setVariable(i.value,n[o])}}else if(t.assignee.type==="MemberExpression"){let r=t.assignee,n=this.evaluate(r.object,e);if(!(n instanceof Le))throw new Error("Cannot assign to member of non-object");if(r.property.type!=="Identifier")throw new Error("Cannot assign to member with non-identifier property");n.value.set(r.property.value,s)}else throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(t.assignee)}`);return new he}evaluateIf(t,e){let s=this.evaluate(t.test,e);return this.evaluateBlock(s.__bool__().value?t.body:t.alternate,e)}evaluateFor(t,e){let s=new Vt(e),r,n;if(t.iterable.type==="SelectExpression"){let c=t.iterable;n=this.evaluate(c.lhs,s),r=c.test}else n=this.evaluate(t.iterable,s);if(!(n instanceof te||n instanceof Le))throw new Error(`Expected iterable or object type in for loop: got ${n.type}`);n instanceof Le&&(n=n.keys());let o=[],i=[];for(let c=0;c<n.value.length;++c){let u=new Vt(s),p=n.value[c],d;if(t.loopvar.type==="Identifier")d=_=>_.setVariable(t.loopvar.value,p);else if(t.loopvar.type==="TupleLiteral"){let _=t.loopvar;if(p.type!=="ArrayValue")throw new Error(`Cannot unpack non-iterable type: ${p.type}`);let m=p;if(_.value.length!==m.value.length)throw new Error(`Too ${_.value.length>m.value.length?"few":"many"} items to unpack`);d=h=>{for(let x=0;x<_.value.length;++x){if(_.value[x].type!=="Identifier")throw new Error(`Cannot unpack non-identifier type: ${_.value[x].type}`);h.setVariable(_.value[x].value,m.value[x])}}}else throw new Error(`Invalid loop variable(s): ${t.loopvar.type}`);r&&(d(u),!this.evaluate(r,u).__bool__().value)||(o.push(p),i.push(d))}let a="",l=!0;for(let c=0;c<o.length;++c){let u=new Map([["index",new H(c+1)],["index0",new H(c)],["revindex",new H(o.length-c)],["revindex0",new H(o.length-c-1)],["first",new U(c===0)],["last",new U(c===o.length-1)],["length",new H(o.length)],["previtem",c>0?o[c-1]:new fe],["nextitem",c<o.length-1?o[c+1]:new fe]]);s.setVariable("loop",new Le(u)),i[c](s);try{let p=this.evaluateBlock(t.body,s);a+=p.value}catch(p){if(p instanceof ew)continue;if(p instanceof Zg)break;throw p}l=!1}if(l){let c=this.evaluateBlock(t.defaultBlock,s);a+=c.value}return new $(a)}evaluateMacro(t,e){return e.setVariable(t.name.value,new me((s,r)=>{let n=new Vt(r);s=s.slice();let o;s.at(-1)?.type==="KeywordArgumentsValue"&&(o=s.pop());for(let i=0;i<t.args.length;++i){let a=t.args[i],l=s[i];if(a.type==="Identifier"){let c=a;if(!l)throw new Error(`Missing positional argument: ${c.value}`);n.setVariable(c.value,l)}else if(a.type==="KeywordArgumentExpression"){let c=a,u=l??o?.value.get(c.key.value)??this.evaluate(c.value,n);n.setVariable(c.key.value,u)}else throw new Error(`Unknown argument type: ${a.type}`)}return this.evaluateBlock(t.body,n)})),new he}evaluateCallStatement(t,e){let s=new me((a,l)=>{let c=new Vt(l);if(t.callerArgs)for(let u=0;u<t.callerArgs.length;++u){let p=t.callerArgs[u];if(p.type!=="Identifier")throw new Error(`Caller parameter must be an identifier, got ${p.type}`);c.setVariable(p.value,a[u]??new fe)}return this.evaluateBlock(t.body,c)}),[r,n]=this.evaluateArguments(t.call.args,e);r.push(new ir(n));let o=this.evaluate(t.call.callee,e);if(o.type!=="FunctionValue")throw new Error(`Cannot call something that is not a function: got ${o.type}`);let i=new Vt(e);return i.setVariable("caller",s),o.value(r,i)}evaluateFilterStatement(t,e){let s=this.evaluateBlock(t.body,e);return this.applyFilter(s,t.filter,e)}evaluate(t,e){if(!t)return new fe;switch(t.type){case"Program":return this.evalProgram(t,e);case"Set":return this.evaluateSet(t,e);case"If":return this.evaluateIf(t,e);case"For":return this.evaluateFor(t,e);case"Macro":return this.evaluateMacro(t,e);case"CallStatement":return this.evaluateCallStatement(t,e);case"Break":throw new Zg;case"Continue":throw new ew;case"IntegerLiteral":return new H(t.value);case"FloatLiteral":return new ye(t.value);case"StringLiteral":return new $(t.value);case"ArrayLiteral":return new te(t.value.map(s=>this.evaluate(s,e)));case"TupleLiteral":return new sw(t.value.map(s=>this.evaluate(s,e)));case"ObjectLiteral":{let s=new Map;for(let[r,n]of t.value){let o=this.evaluate(r,e);if(!(o instanceof $))throw new Error(`Object keys must be strings: got ${o.type}`);s.set(o.value,this.evaluate(n,e))}return new Le(s)}case"Identifier":return this.evaluateIdentifier(t,e);case"CallExpression":return this.evaluateCallExpression(t,e);case"MemberExpression":return this.evaluateMemberExpression(t,e);case"UnaryExpression":return this.evaluateUnaryExpression(t,e);case"BinaryExpression":return this.evaluateBinaryExpression(t,e);case"FilterExpression":return this.evaluateFilterExpression(t,e);case"FilterStatement":return this.evaluateFilterStatement(t,e);case"TestExpression":return this.evaluateTestExpression(t,e);case"SelectExpression":return this.evaluateSelectExpression(t,e);case"Ternary":return this.evaluateTernaryExpression(t,e);case"Comment":return new he;default:throw new SyntaxError(`Unknown node type: ${t.type}`)}}};function Go(t){switch(typeof t){case"number":return Number.isInteger(t)?new H(t):new ye(t);case"string":return new $(t);case"boolean":return new U(t);case"undefined":return new fe;case"object":return t===null?new he:Array.isArray(t)?new te(t.map(Go)):new Le(new Map(Object.entries(t).map(([e,s])=>[e,Go(s)])));case"function":return new me((e,s)=>{let r=t(...e.map(n=>n.value))??null;return Go(r)});default:throw new Error(`Cannot convert to runtime value: ${t}`)}}var Ae=`
10
- `,ok="{%- ",ik=" -%}";function ak(t){switch(t.operator.type){case"MultiplicativeBinaryOperator":return 4;case"AdditiveBinaryOperator":return 3;case"ComparisonBinaryOperator":return 2;case"Identifier":return t.operator.value==="and"?1:t.operator.value==="in"||t.operator.value==="not in"?2:0}return 0}function lk(t,e=" "){let s=typeof e=="number"?" ".repeat(e):e;return rt(t.body,0,s).replace(/\n$/,"")}function Te(...t){return ok+t.join(" ")+ik}function rt(t,e,s){return t.map(r=>ck(r,e,s)).join(Ae)}function ck(t,e,s){let r=s.repeat(e);switch(t.type){case"Program":return rt(t.body,e,s);case"If":return uk(t,e,s);case"For":return pk(t,e,s);case"Set":return dk(t,e,s);case"Macro":return _k(t,e,s);case"Break":return r+Te("break");case"Continue":return r+Te("continue");case"CallStatement":return fk(t,e,s);case"FilterStatement":return mk(t,e,s);case"Comment":return r+"{# "+t.value+" #}";default:return r+"{{- "+se(t)+" -}}"}}function uk(t,e,s){let r=s.repeat(e),n=[],o=t;for(;o&&(n.push({test:o.test,body:o.body}),o.alternate.length===1&&o.alternate[0].type==="If");)o=o.alternate[0];let i=r+Te("if",se(n[0].test))+Ae+rt(n[0].body,e+1,s);for(let a=1;a<n.length;++a)i+=Ae+r+Te("elif",se(n[a].test))+Ae+rt(n[a].body,e+1,s);return o&&o.alternate.length>0&&(i+=Ae+r+Te("else")+Ae+rt(o.alternate,e+1,s)),i+=Ae+r+Te("endif"),i}function pk(t,e,s){let r=s.repeat(e),n="";if(t.iterable.type==="SelectExpression"){let i=t.iterable;n=`${se(i.lhs)} if ${se(i.test)}`}else n=se(t.iterable);let o=r+Te("for",se(t.loopvar),"in",n)+Ae+rt(t.body,e+1,s);return t.defaultBlock.length>0&&(o+=Ae+r+Te("else")+Ae+rt(t.defaultBlock,e+1,s)),o+=Ae+r+Te("endfor"),o}function dk(t,e,s){let r=s.repeat(e),n=se(t.assignee),o=t.value?se(t.value):"",i=r+Te("set",`${n}${t.value?" = "+o:""}`);return t.body.length===0?i:i+Ae+rt(t.body,e+1,s)+Ae+r+Te("endset")}function _k(t,e,s){let r=s.repeat(e),n=t.args.map(se).join(", ");return r+Te("macro",`${t.name.value}(${n})`)+Ae+rt(t.body,e+1,s)+Ae+r+Te("endmacro")}function fk(t,e,s){let r=s.repeat(e),n=t.callerArgs&&t.callerArgs.length>0?`(${t.callerArgs.map(se).join(", ")})`:"",o=se(t.call),i=r+Te(`call${n}`,o)+Ae;return i+=rt(t.body,e+1,s)+Ae,i+=r+Te("endcall"),i}function mk(t,e,s){let r=s.repeat(e),n=t.filter.type==="Identifier"?t.filter.value:se(t.filter),o=r+Te("filter",n)+Ae;return o+=rt(t.body,e+1,s)+Ae,o+=r+Te("endfilter"),o}function se(t,e=-1){switch(t.type){case"SpreadExpression":return`*${se(t.argument)}`;case"Identifier":return t.value;case"IntegerLiteral":return`${t.value}`;case"FloatLiteral":return`${t.value}`;case"StringLiteral":return JSON.stringify(t.value);case"BinaryExpression":{let s=t,r=ak(s),n=se(s.left,r),o=se(s.right,r+1),i=`${n} ${s.operator.value} ${o}`;return r<e?`(${i})`:i}case"UnaryExpression":{let s=t;return s.operator.value+(s.operator.value==="not"?" ":"")+se(s.argument,1/0)}case"CallExpression":{let s=t,r=s.args.map(se).join(", ");return`${se(s.callee)}(${r})`}case"MemberExpression":{let s=t,r=se(s.object);["Identifier","MemberExpression","CallExpression","StringLiteral","IntegerLiteral","FloatLiteral","ArrayLiteral","TupleLiteral","ObjectLiteral"].includes(s.object.type)||(r=`(${r})`);let n=se(s.property);return!s.computed&&s.property.type!=="Identifier"&&(n=`(${n})`),s.computed?`${r}[${n}]`:`${r}.${n}`}case"FilterExpression":{let s=t,r=se(s.operand,1/0);return s.filter.type==="CallExpression"?`${r} | ${se(s.filter)}`:`${r} | ${s.filter.value}`}case"SelectExpression":{let s=t;return`${se(s.lhs)} if ${se(s.test)}`}case"TestExpression":{let s=t;return`${se(s.operand)} is${s.negate?" not":""} ${s.test.value}`}case"ArrayLiteral":case"TupleLiteral":{let s=t.value.map(se),r=t.type==="ArrayLiteral"?"[]":"()";return`${r[0]}${s.join(", ")}${r[1]}`}case"ObjectLiteral":return`{${Array.from(t.value.entries()).map(([r,n])=>`${se(r)}: ${se(n)}`).join(", ")}}`;case"SliceExpression":{let s=t,r=s.start?se(s.start):"",n=s.stop?se(s.stop):"",o=s.step?`:${se(s.step)}`:"";return`${r}:${n}${o}`}case"KeywordArgumentExpression":{let s=t;return`${s.key.value}=${se(s.value)}`}case"Ternary":{let s=t,r=`${se(s.trueExpr)} if ${se(s.condition,0)} else ${se(s.falseExpr)}`;return e>-1?`(${r})`:r}default:throw new Error(`Unknown expression type: ${t.type}`)}}var nw=class{parsed;constructor(t){let e=A1(t,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=K1(e)}render(t){let e=new Vt;if(rk(e),t)for(let[n,o]of Object.entries(t))e.set(n,o);return new nk(e).run(this.parsed).value}format(t){return lk(this.parsed,t?.indent||" ")}};var ke=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}_call(...t){throw Error("Must implement _call method in subclass")}};function yt(t,e){t&&t(e)}function ow(t){return Number.isInteger(t)||typeof t=="bigint"}function jl(t){return t==null||t===-1}function Bl(t){let e=[],s=t;for(;Array.isArray(s);)e.push(s.length),s=s[0];return e}function Pe(...t){return Array.prototype.concat.apply([],t)}function iw(...t){return t.reduce((e,s)=>e.flatMap(r=>s.map(n=>[r,n])))}function _s(t,e){return Math.abs((t+e)%(2*e)-e)}function Me(t,e){return Object.assign({},...e.map(s=>{if(t[s]!==void 0)return{[s]:t[s]}}))}function aw(t,e){let s=0;for(let r of t)r===e&&++s;return s}var hk={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif"},Xt=class t{constructor(e){if(this.filePath=e,this.headers=new Headers,this.exists=De.existsSync(e),this.exists){this.status=200,this.statusText="OK";let s=De.statSync(e);this.headers.set("content-length",s.size.toString()),this.updateContentType();let r=De.createReadStream(e);this.body=new ReadableStream({start(n){r.on("data",o=>n.enqueue(o)),r.on("end",()=>n.close()),r.on("error",o=>n.error(o))},cancel(){r.destroy()}})}else this.status=404,this.statusText="Not Found",this.body=null}updateContentType(){let e=this.filePath.toString().split(".").pop().toLowerCase();this.headers.set("content-type",hk[e]??"application/octet-stream")}clone(){let e=new t(this.filePath);return e.exists=this.exists,e.status=this.status,e.statusText=this.statusText,e.headers=new Headers(this.headers),e}async arrayBuffer(){return(await De.promises.readFile(this.filePath)).buffer}async blob(){let e=await De.promises.readFile(this.filePath);return new Blob([e],{type:this.headers.get("content-type")})}async text(){return await De.promises.readFile(this.filePath,"utf8")}async json(){return JSON.parse(await this.text())}},fs=class{constructor(e){this.path=e}async match(e){let s=et.join(this.path,e),r=new Xt(s);if(r.exists)return r}async put(e,s,r=void 0){let n=et.join(this.path,e);try{let o=s.headers.get("Content-Length"),i=parseInt(o??"0"),a=0;await De.promises.mkdir(et.dirname(n),{recursive:!0});let l=De.createWriteStream(n),c=s.body.getReader();for(;;){let{done:u,value:p}=await c.read();if(u)break;await new Promise((_,m)=>{l.write(p,h=>{if(h){m(h);return}_()})}),a+=p.length;let d=i?a/i*100:0;r?.({progress:d,loaded:a,total:i})}l.close()}catch(o){try{await De.promises.unlink(n)}catch{}throw o}}};var lw={400:"Bad request error occurred while trying to load file",401:"Unauthorized access to file",403:"Forbidden access to file",404:"Could not locate file",408:"Request timeout error occurred while trying to load file",500:"Internal server error error occurred while trying to load file",502:"Bad gateway error occurred while trying to load file",503:"Service unavailable error occurred while trying to load file",504:"Gateway timeout error occurred while trying to load file"},Wo=100,cw=/^(\b[\w\-.]+\b\/)?\b[\w\-.]{1,96}\b$/;function ar(...t){return t=t.map((e,s)=>(s&&(e=e.replace(new RegExp("^/"),"")),s!==t.length-1&&(e=e.replace(new RegExp("/$"),"")),e)),t.join("/")}function ms(t,e=null,s=null){let r;try{r=new URL(t)}catch{return!1}return!(e&&!e.includes(r.protocol)||s&&!s.includes(r.hostname))}function uw(t){return!(!cw.test(t)||t.includes("..")||t.includes("--")||t.endsWith(".git")||t.endsWith(".ipynb"))}function pw(t,e,s){if(!s)return null;let r=lw[t]??`Error (${t}) occurred while trying to load file`;throw Error(`${r}: "${e}".`)}async function dw(t,e){let s=t.headers.get("Content-Length");s===null&&console.warn("Unable to determine content-length from response headers. Will expand buffer when needed.");let r=parseInt(s??"0"),n=new Uint8Array(r),o=0,i=t.body.getReader();async function a(){let{done:l,value:c}=await i.read();if(l)return;let u=o+c.length;if(u>r){r=u;let d=new Uint8Array(r);d.set(n),n=d}n.set(c,o),o=u;let p=o/r*100;return e({progress:p,loaded:o,total:r}),a()}return await a(),n}async function Vo(t=null){let e=null;if(_e.useCustomCache){if(!_e.customCache)throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");if(!_e.customCache.match||!_e.customCache.put)throw new Error("`env.customCache` must be an object which implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache");e=_e.customCache}if(!e&&_e.useBrowserCache){if(typeof caches>"u")throw Error("Browser cache is not available in this environment.");try{e=await caches.open(_e.cacheKey)}catch(s){console.warn("An error occurred while opening the browser cache:",s)}}if(!e&&_e.useFSCache){if(!ee.IS_FS_AVAILABLE)throw Error("File System Cache is not available in this environment.");e=new fs(t??_e.cacheDir)}return e}async function _w(t,...e){for(let s of e)try{let r=await t.match(s);if(r)return r}catch{continue}}async function hs(t){if(_e.useFS&&!ms(t,["http:","https:","blob:"]))return new Xt(t instanceof URL?t.protocol==="file:"?t.pathname:t.toString():t);if(typeof process<"u"&&process?.release?.name==="node"){let e=!!process.env?.TESTING_REMOTELY,s=_e.version,r=new Headers;if(r.set("User-Agent",`transformers.js/${s}; is_ci/${e};`),ms(t,["http:","https:"],["huggingface.co","hf.co"])){let o=process.env?.HF_TOKEN??process.env?.HF_ACCESS_TOKEN;o&&r.set("Authorization",`Bearer ${o}`)}return fetch(t,{headers:r})}else return fetch(t)}function xk(t,e,s={},r=null){let n=s.revision??"main",o=ar(t,e),i=uw(t),a=i?ar(_e.localModelPath,o):o,l=ar(_e.remoteHost,_e.remotePathTemplate.replaceAll("{model}",t).replaceAll("{revision}",encodeURIComponent(n)),e),c=r instanceof fs?n==="main"?o:ar(t,n,e):l;return{requestURL:o,localPath:a,remoteURL:l,proposedCacheKey:c,validModelId:i}}async function gk(t,e,s){if(t)return await _w(t,e,s)}async function wk(t,e,s,r,n,o,i={}){if(await s.match(r)===void 0)if(o)typeof n!="string"&&await s.put(r,new Response(o,{headers:n.headers})).catch(a=>{console.warn(`Unable to add response to browser cache: ${a}.`)});else{let a=i.progress_callback?l=>yt(i.progress_callback,{status:"progress",name:t,file:e,...l}):void 0;await s.put(r,n,a)}}async function yk(t,e,s=!0,r={},n=!1,o=null){let{requestURL:i,localPath:a,remoteURL:l,proposedCacheKey:c,validModelId:u}=xk(t,e,r,o),p,d=!1,_;_=await gk(o,a,c);let m=_!==void 0;if(!m){if(_e.allowLocalModels)if(ms(i,["http:","https:"])){if(r.local_files_only)throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${i}.`);if(!_e.allowRemoteModels)throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${i}.`)}else try{_=await hs(a),p=a}catch(w){console.warn(`Unable to load from local path "${a}": "${w}"`)}if(_===void 0||typeof _!="string"&&_.status===404){if(r.local_files_only||!_e.allowRemoteModels){if(s)throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${a}".`);return null}if(!u)throw Error(`Local file missing at "${a}" and download aborted due to invalid model ID "${t}".`);if(_=await hs(l),_.status!==200)return pw(_.status,l,s);p=c}d=o&&typeof Response<"u"&&_ instanceof Response&&_.status===200}yt(r.progress_callback,{status:"download",name:t,file:e});let h;if(!(ee.IS_NODE_ENV&&n)){let g;typeof _!="string"&&(r.progress_callback?m&&typeof navigator<"u"&&/firefox/i.test(navigator.userAgent)?(g=new Uint8Array(await _.arrayBuffer()),yt(r.progress_callback,{status:"progress",name:t,file:e,progress:100,loaded:g.length,total:g.length})):g=await dw(_,w=>{yt(r.progress_callback,{status:"progress",name:t,file:e,...w})}):g=new Uint8Array(await _.arrayBuffer())),h=g}if(d&&p&&typeof _!="string"&&await wk(t,e,o,p,_,h,r),yt(r.progress_callback,{status:"done",name:t,file:e}),h){if(!ee.IS_NODE_ENV&&n)throw new Error("Cannot return path in a browser environment.");return h}if(_ instanceof Xt)return _.filePath;let x=await o?.match(p);if(x instanceof Xt)return x.filePath;if(x instanceof Response)return new Uint8Array(await x.arrayBuffer());if(typeof x=="string")return x;throw new Error("Unable to get model file path or buffer.")}async function lr(t,e,s=!0,r={},n=!1){if(!_e.allowLocalModels){if(r.local_files_only)throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).");if(!_e.allowRemoteModels)throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.")}yt(r.progress_callback,{status:"initiate",name:t,file:e});let o=await Vo(r?.cache_dir);return await yk(t,e,s,r,n,o)}async function Ul(t,e,s=!0,r={}){let n=await lr(t,e,s,r,!1);return n===null?null:new TextDecoder("utf-8").decode(n)}async function Se(t,e,s=!0,r={}){let n=await Ul(t,e,s,r);return n===null?{}:JSON.parse(n)}function mw(t,[e,s,r],[n,o],i="bilinear",a=!1){let l=o/r,c=n/s,u=new t.constructor(n*o*e),p=s*r,d=n*o;for(let _=0;_<n;++_)for(let m=0;m<o;++m){let h=_*o+m,x=(m+.5)/l-.5,g=(_+.5)/c-.5,w=Math.floor(x),y=Math.floor(g),E=Math.min(w+1,r-1),A=Math.min(y+1,s-1);w=Math.max(w,0),y=Math.max(y,0);let b=x-w,O=g-y,N=(1-b)*(1-O),F=b*(1-O),R=(1-b)*O,B=b*O,G=y*r,D=A*r,X=G+w,V=G+E,re=D+w,Y=D+E;for(let k=0;k<e;++k){let v=k*p;u[k*d+h]=N*t[v+X]+F*t[v+V]+R*t[v+re]+B*t[v+Y]}}return u}function hw(t,e,s){let r=new Array(s.length),n=new Array(s.length);for(let a=s.length-1,l=1;a>=0;--a)n[a]=l,r[a]=e[s[a]],l*=r[a];let o=s.map((a,l)=>n[s.indexOf(l)]),i=new t.constructor(t.length);for(let a=0;a<t.length;++a){let l=0;for(let c=e.length-1,u=a;c>=0;--c)l+=u%e[c]*o[c],u=Math.floor(u/e[c]);i[l]=t[a]}return[i,r]}function ce(t){let e=ie(t)[0],s=t.map(o=>Math.exp(o-e)),r=s.reduce((o,i)=>o+i,0);return s.map(o=>o/r)}function Gl(t){let e=ie(t)[0],s=0;for(let o=0;o<t.length;++o)s+=Math.exp(t[o]-e);let r=Math.log(s);return t.map(o=>o-e-r)}function xw(t,e){let s=0;for(let r=0;r<t.length;++r)s+=t[r]*e[r];return s}function bk(t,e){let s=xw(t,e),r=fw(t),n=fw(e);return s/(r*n)}function fw(t){return Math.sqrt(t.reduce((e,s)=>e+s*s,0))}function cr(t){if(t.length===0)throw Error("Array must not be empty");let e=t[0],s=0;for(let r=1;r<t.length;++r)t[r]<e&&(e=t[r],s=r);return[e,s]}function ie(t){if(t.length===0)throw Error("Array must not be empty");let e=t[0],s=0;for(let r=1;r<t.length;++r)t[r]>e&&(e=t[r],s=r);return[e,s]}function gw(t){return t>0&&(t&t-1)===0}var Ho=class{constructor(e){if(this.size=e|0,this.size<=1||!gw(this.size))throw new Error("FFT size must be a power of two larger than 1");this._csize=e<<1,this.table=new Float64Array(this.size*2);for(let r=0;r<this.table.length;r+=2){let n=Math.PI*r/this.size;this.table[r]=Math.cos(n),this.table[r+1]=-Math.sin(n)}let s=0;for(let r=1;this.size>r;r<<=1)++s;this._width=s%2===0?s-1:s,this._bitrev=new Int32Array(1<<this._width);for(let r=0;r<this._bitrev.length;++r){this._bitrev[r]=0;for(let n=0;n<this._width;n+=2){let o=this._width-n-2;this._bitrev[r]|=(r>>>n&3)<<o}}}createComplexArray(){return new Float64Array(this._csize)}fromComplexArray(e,s){let r=s||new Array(e.length>>>1);for(let n=0;n<e.length;n+=2)r[n>>>1]=e[n];return r}toComplexArray(e,s){let r=s||this.createComplexArray();for(let n=0;n<r.length;n+=2)r[n]=e[n>>>1],r[n+1]=0;return r}transform(e,s){if(e===s)throw new Error("Input and output buffers must be different");this._transform4(e,s,1)}realTransform(e,s){if(e===s)throw new Error("Input and output buffers must be different");this._realTransform4(e,s,1)}inverseTransform(e,s){if(e===s)throw new Error("Input and output buffers must be different");this._transform4(e,s,-1);for(let r=0;r<e.length;++r)e[r]/=this.size}_transform4(e,s,r){let n=this._csize,i=1<<this._width,a=n/i<<1,l,c,u=this._bitrev;if(a===4)for(l=0,c=0;l<n;l+=a,++c){let d=u[c];this._singleTransform2(s,e,l,d,i)}else for(l=0,c=0;l<n;l+=a,++c){let d=u[c];this._singleTransform4(s,e,l,d,i,r)}let p=this.table;for(i>>=2;i>=2;i>>=2){a=n/i<<1;let d=a>>>2;for(l=0;l<n;l+=a){let _=l+d-1;for(let m=l,h=0;m<_;m+=2,h+=i){let x=m,g=x+d,w=g+d,y=w+d,E=e[x],A=e[x+1],b=e[g],O=e[g+1],N=e[w],F=e[w+1],R=e[y],B=e[y+1],G=p[h],D=r*p[h+1],X=b*G-O*D,V=b*D+O*G,re=p[2*h],Y=r*p[2*h+1],k=N*re-F*Y,v=N*Y+F*re,I=p[3*h],Q=r*p[3*h+1],Z=R*I-B*Q,Ie=R*Q+B*I,Ee=E+k,ht=A+v,xt=E-k,Gt=A-v,lt=X+Z,Ye=V+Ie,gt=r*(X-Z),vt=r*(V-Ie);e[x]=Ee+lt,e[x+1]=ht+Ye,e[g]=xt+vt,e[g+1]=Gt-gt,e[w]=Ee-lt,e[w+1]=ht-Ye,e[y]=xt-vt,e[y+1]=Gt+gt}}}}_singleTransform2(e,s,r,n,o){let i=e[n],a=e[n+1],l=e[n+o],c=e[n+o+1];s[r]=i+l,s[r+1]=a+c,s[r+2]=i-l,s[r+3]=a-c}_singleTransform4(e,s,r,n,o,i){let a=o*2,l=o*3,c=e[n],u=e[n+1],p=e[n+o],d=e[n+o+1],_=e[n+a],m=e[n+a+1],h=e[n+l],x=e[n+l+1],g=c+_,w=u+m,y=c-_,E=u-m,A=p+h,b=d+x,O=i*(p-h),N=i*(d-x);s[r]=g+A,s[r+1]=w+b,s[r+2]=y+N,s[r+3]=E-O,s[r+4]=g-A,s[r+5]=w-b,s[r+6]=y-N,s[r+7]=E+O}_realTransform4(e,s,r){let n=this._csize,i=1<<this._width,a=n/i<<1,l,c,u=this._bitrev;if(a===4)for(l=0,c=0;l<n;l+=a,++c){let _=u[c];this._singleRealTransform2(s,e,l,_>>>1,i>>>1)}else for(l=0,c=0;l<n;l+=a,++c){let _=u[c];this._singleRealTransform4(s,e,l,_>>>1,i>>>1,r)}let p=this.table;for(i>>=2;i>=2;i>>=2){a=n/i<<1;let _=a>>>1,m=_>>>1,h=m>>>1;for(l=0;l<n;l+=a)for(let x=0,g=0;x<=h;x+=2,g+=i){let w=l+x,y=w+m,E=y+m,A=E+m,b=e[w],O=e[w+1],N=e[y],F=e[y+1],R=e[E],B=e[E+1],G=e[A],D=e[A+1],X=b,V=O,re=p[g],Y=r*p[g+1],k=N*re-F*Y,v=N*Y+F*re,I=p[2*g],Q=r*p[2*g+1],Z=R*I-B*Q,Ie=R*Q+B*I,Ee=p[3*g],ht=r*p[3*g+1],xt=G*Ee-D*ht,Gt=G*ht+D*Ee,lt=X+Z,Ye=V+Ie,gt=X-Z,vt=V-Ie,Wt=k+xt,Et=v+Gt,$o=r*(k-xt),Ro=r*(v-Gt);if(e[w]=lt+Wt,e[w+1]=Ye+Et,e[y]=gt+Ro,e[y+1]=vt-$o,x===0){e[E]=lt-Wt,e[E+1]=Ye-Et;continue}if(x===h)continue;let Fo=l+m-x,ct=l+_-x;e[Fo]=gt-r*Ro,e[Fo+1]=-vt-r*$o,e[ct]=lt-r*Wt,e[ct+1]=-Ye+r*Et}}let d=n>>>1;for(let _=2;_<d;_+=2)e[n-_]=e[_],e[n-_+1]=-e[_+1]}_singleRealTransform2(e,s,r,n,o){let i=e[n],a=e[n+o];s[r]=i+a,s[r+1]=0,s[r+2]=i-a,s[r+3]=0}_singleRealTransform4(e,s,r,n,o,i){let a=o*2,l=o*3,c=e[n],u=e[n+o],p=e[n+a],d=e[n+l],_=c+p,m=c-p,h=u+d,x=i*(u-d);s[r]=_+h,s[r+1]=0,s[r+2]=m,s[r+3]=-x,s[r+4]=_-h,s[r+5]=0,s[r+6]=m,s[r+7]=x}},ql=class{constructor(e){let s=2*(e-1),r=2*(2*e-1),n=2**Math.ceil(Math.log2(r));this.bufferSize=n,this._a=s;let o=new Float64Array(r),i=new Float64Array(n);this._chirpBuffer=new Float64Array(n),this._buffer1=new Float64Array(n),this._buffer2=new Float64Array(n),this._outBuffer1=new Float64Array(n),this._outBuffer2=new Float64Array(n);let a=-2*Math.PI/e,l=Math.cos(a),c=Math.sin(a);for(let u=0;u<r>>1;++u){let p=(u+1-e)**2/2,d=Math.sqrt(l**2+c**2)**p,_=p*Math.atan2(c,l),m=2*u;o[m]=d*Math.cos(_),o[m+1]=d*Math.sin(_),i[m]=o[m],i[m+1]=-o[m+1]}this._slicedChirpBuffer=o.subarray(s,r),this._f=new Ho(n>>1),this._f.transform(this._chirpBuffer,i)}_transform(e,s,r){let n=this._buffer1,o=this._buffer2,i=this._outBuffer1,a=this._outBuffer2,l=this._chirpBuffer,c=this._slicedChirpBuffer,u=this._a;if(r)for(let p=0;p<c.length;p+=2){let d=p+1,_=p>>1,m=s[_];n[p]=m*c[p],n[d]=m*c[d]}else for(let p=0;p<c.length;p+=2){let d=p+1;n[p]=s[p]*c[p]-s[d]*c[d],n[d]=s[p]*c[d]+s[d]*c[p]}this._f.transform(i,n);for(let p=0;p<l.length;p+=2){let d=p+1;o[p]=i[p]*l[p]-i[d]*l[d],o[d]=i[p]*l[d]+i[d]*l[p]}this._f.inverseTransform(a,o);for(let p=0;p<a.length;p+=2){let d=a[p+u],_=a[p+u+1],m=c[p],h=c[p+1];e[p]=d*m-_*h,e[p+1]=d*h+_*m}}transform(e,s){this._transform(e,s,!1)}realTransform(e,s){this._transform(e,s,!0)}},Xo=class{constructor(e){this.fft_length=e,this.isPowerOfTwo=gw(e),this.isPowerOfTwo?(this.fft=new Ho(e),this.outputBufferSize=2*e):(this.fft=new ql(e),this.outputBufferSize=this.fft.bufferSize)}realTransform(e,s){this.fft.realTransform(e,s)}transform(e,s){this.fft.transform(e,s)}};function ww(t,e){if(e%2===0||e<=0)throw new Error("Window size must be a positive odd number");let s=new t.constructor(t.length),r=new t.constructor(e),n=Math.floor(e/2);for(let o=0;o<t.length;++o){let i=0;for(let a=-n;a<=n;++a){let l=o+a;l<0?l=Math.abs(l):l>=t.length&&(l=2*(t.length-1)-l),r[i++]=t[l]}r.sort(),s[o]=r[n]}return s}function Kt(t,e){let s=Math.pow(10,e);return Math.round(t*s)/s}function yw(t){let e=Math.round(t);return Math.abs(t)%1===.5?e%2===0?e:e-1:e}function bw(t){let e=t.length,s=t[0].length,r=[e+1,s+1],n=Array.from({length:r[0]},()=>Array(r[1]).fill(1/0));n[0][0]=0;let o=Array.from({length:r[0]},()=>Array(r[1]).fill(-1));for(let u=1;u<r[1];++u)for(let p=1;p<r[0];++p){let d=n[p-1][u-1],_=n[p-1][u],m=n[p][u-1],h,x;d<_&&d<m?(h=d,x=0):_<d&&_<m?(h=_,x=1):(h=m,x=2),n[p][u]=t[p-1][u-1]+h,o[p][u]=x}for(let u=0;u<r[1];++u)o[0][u]=2;for(let u=0;u<r[0];++u)o[u][0]=1;let i=e,a=s,l=[],c=[];for(;i>0||a>0;)switch(l.push(i-1),c.push(a-1),o[i][a]){case 0:--i,--a;break;case 1:--i;break;case 2:--a;break;default:throw new Error(`Internal error in dynamic time warping. Unexpected trace[${i}, ${a}]. Please file a bug report.`)}return l.reverse(),c.reverse(),[l,c]}var kw=(function(){let t=null;return function(e){if(!t){t=new Float32Array(65536);let o=new ArrayBuffer(4),i=new Uint32Array(o),a=new Float32Array(o);for(let l=0;l<t.length;++l){let c=0,u=(l&32768)<<16,p=(l&31744)>>10,d=l&1023;if(p===31)c=u|2139095040|d<<13;else if(p===0)if(d===0)c=u;else{let _=113;for(;(d&1024)===0;)d<<=1,--_;d&=-1025,c=u|_<<23|d<<13}else c=u|p+112<<23|d<<13;i[0]=c,t[l]=a[0]}}let s=e.length,r=t,n=new Float32Array(s);for(let o=0;o<s;++o)n[o]=r[e[o]];return n}})();var Wl={};us(Wl,{Readable:()=>Ek,createReadStream:()=>Sk,createWriteStream:()=>Mk,default:()=>vk,pipeline:()=>Ak});var Ko=()=>{},kk={},vk=kk,Ek={fromWeb:Ko},Ak=Ko,Mk=Ko,Sk=Ko;import*as Ok from"onnxruntime-web/webgpu";async function vw(t){let e=t.split("/").pop(),s;try{if(s=await Vo(),s){let n=await s.match(t);if(n)return n}}catch(n){console.warn(`Failed to load ${e} from cache:`,n)}let r=await fetch(t);if(!r.ok)throw new Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);if(s)try{await s.put(t,r.clone())}catch(n){console.warn(`Failed to cache ${e}:`,n)}return r}async function Ew(t){let e=await vw(t);if(!e||typeof e=="string")return null;try{return await e.arrayBuffer()}catch(s){return console.warn("Failed to read WASM binary:",s),null}}async function Aw(t){let e=await vw(t);if(!e||typeof e=="string")return null;try{let s=await e.text(),r=t.split("/").slice(0,-1).join("/");s=s.replace(/import\.meta\.url/g,`"${r}"`);let n=new Blob([s],{type:"text/javascript"});return URL.createObjectURL(n)}catch(s){return console.warn("Failed to read WASM binary:",s),null}}function Vl(t){return ms(t,["blob:"])}function Hl(t){let e;if(typeof location<"u"&&location.href)e=location.href;else if(typeof import.meta<"u"&&import.meta.url)e=import.meta.url;else return t;return new URL(t,e).href}import{Tensor as Pw}from"onnxruntime-common";var Ik=Object.freeze({auto:null,gpu:null,cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",coreml:"coreml",webnn:{name:"webnn",deviceType:"cpu"},"webnn-npu":{name:"webnn",deviceType:"npu"},"webnn-gpu":{name:"webnn",deviceType:"gpu"},"webnn-cpu":{name:"webnn",deviceType:"cpu"}}),zk=["verbose","info","warning","error","fatal"],Iw=4,He=[],Xl,gs,Mw=Symbol.for("onnxruntime");if(Mw in globalThis)gs=globalThis[Mw];else if(ee.IS_NODE_ENV){switch(gs=Wl,process.platform){case"win32":He.push("dml");break;case"linux":process.arch==="x64"&&He.push("cuda");break;case"darwin":He.push("coreml");break}He.push("webgpu"),He.push("cpu"),Xl=["cpu"]}else gs=Ok,ee.IS_WEBNN_AVAILABLE&&He.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),ee.IS_WEBGPU_AVAILABLE&&He.push("webgpu"),He.push("wasm"),Xl=["wasm"];var Tk=gs.InferenceSession;function zw(t=null){if(!t)return Xl;switch(t){case"auto":return He;case"gpu":return He.filter(e=>["webgpu","cuda","dml","webnn-gpu"].includes(e))}if(He.includes(t))return[Ik[t]??t];throw new Error(`Unsupported device: "${t}". Should be one of: ${He.join(", ")}.`)}var Tw=ee.IS_BROWSER_ENV||ee.IS_WEBWORKER_ENV,Sw=Promise.resolve(),xs=null;async function Pk(){return xs||(_e.useWasmCache&&typeof Ce?.wasm?.wasmPaths=="object"&&Ce?.wasm?.wasmPaths?.wasm&&Ce?.wasm?.wasmPaths?.mjs?(xs=(async()=>{let e=Ce.wasm.wasmPaths;await Promise.all([e.wasm&&!Vl(e.wasm)?(async()=>{try{let s=await Ew(Hl(e.wasm));s&&(Ce.wasm.wasmBinary=s)}catch(s){console.warn("Failed to pre-load WASM binary:",s)}})():Promise.resolve(),e.mjs&&!Vl(e.mjs)?(async()=>{try{let s=await Aw(Hl(e.mjs));s&&(Ce.wasm.wasmPaths.mjs=s)}catch(s){console.warn("Failed to pre-load WASM factory:",s)}})():Promise.resolve()])})(),xs):(xs=Promise.resolve(),xs))}async function Qo(t,e,s){await Pk();let r=()=>Tk.create(t,{logSeverityLevel:Iw,...e}),n=await(Tw?Sw=Sw.then(r):r());return n.config=s,n}var Ow=Promise.resolve();async function Jo(t,e){let s=()=>t.run(e);return await(Tw?Ow=Ow.then(s):s())}function Yo(t){return t instanceof gs.Tensor}var Ce=gs?.env;Ce.logLevel=zk[Iw];if(Ce?.wasm){if(!(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope)&&Ce.versions?.web&&!Ce.wasm.wasmPaths){let t=`https://cdn.jsdelivr.net/npm/onnxruntime-web@${Ce.versions.web}/dist/`;Ce.wasm.wasmPaths=ee.IS_SAFARI?{mjs:`${t}ort-wasm-simd-threaded.mjs`,wasm:`${t}ort-wasm-simd-threaded.wasm`}:{mjs:`${t}ort-wasm-simd-threaded.asyncify.mjs`,wasm:`${t}ort-wasm-simd-threaded.asyncify.wasm`}}Ce.wasm.proxy=!1}Ce?.webgpu&&(Ce.webgpu.powerPreference="high-performance");function ur(){return Ce?.wasm?.proxy}_e.backends.onnx=Ce;var At=async(t,e,s)=>{let r=await Qo(new Uint8Array(t),e);return(async n=>{let o=ur(),i=Object.fromEntries(Object.entries(n).map(([l,c])=>[l,(o?c.clone():c).ort_tensor])),a=await Jo(r,i);return Array.isArray(s)?s.map(l=>new S(a[l])):new S(a[s])})},pt=class{static session_options={};static get nearest_interpolate_4d(){return this._nearest_interpolate_4d||(this._nearest_interpolate_4d=At([8,10,18,0,58,129,1,10,41,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,18,10,4,109,111,100,101,34,7,110,101,97,114,101,115,116,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,21],this.session_options,"y")),this._nearest_interpolate_4d}static get bilinear_interpolate_4d(){return this._bilinear_interpolate_4d||(this._bilinear_interpolate_4d=At([8,9,18,0,58,128,1,10,40,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,17,10,4,109,111,100,101,34,6,108,105,110,101,97,114,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bilinear_interpolate_4d}static get bicubic_interpolate_4d(){return this._bicubic_interpolate_4d||(this._bicubic_interpolate_4d=At([8,9,18,0,58,127,10,39,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,16,10,4,109,111,100,101,34,5,99,117,98,105,99,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bicubic_interpolate_4d}static get matmul(){return this._matmul||(this._matmul=At([8,9,18,0,58,55,10,17,10,1,97,10,1,98,18,1,99,34,6,77,97,116,77,117,108,18,1,114,90,9,10,1,97,18,4,10,2,8,1,90,9,10,1,98,18,4,10,2,8,1,98,9,10,1,99,18,4,10,2,8,1,66,2,16,20],this.session_options,"c")),this._matmul}static get stft(){return this._stft||(this._stft=At([8,7,18,0,58,148,1,10,38,10,1,115,10,1,106,10,1,119,10,1,108,18,1,111,34,4,83,84,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,115,90,26,10,1,115,18,21,10,19,8,1,18,15,10,3,18,1,98,10,3,18,1,115,10,3,18,1,99,90,11,10,1,106,18,6,10,4,8,7,18,0,90,16,10,1,119,18,11,10,9,8,1,18,5,10,3,18,1,119,90,11,10,1,108,18,6,10,4,8,7,18,0,98,31,10,1,111,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,102,10,3,18,1,100,10,3,18,1,99,66,2,16,17],this.session_options,"o")),this._stft}static get rfft(){return this._rfft||(this._rfft=At([8,9,18,0,58,97,10,33,10,1,120,10,0,10,1,97,18,1,121,34,3,68,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,100,90,21,10,1,120,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,90,11,10,1,97,18,6,10,4,8,7,18,0,98,21,10,1,121,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,66,2,16,20],this.session_options,"y")),this._rfft}static get top_k(){return this._top_k||(this._top_k=At([8,10,18,0,58,73,10,18,10,1,120,10,1,107,18,1,118,18,1,105,34,4,84,111,112,75,18,1,116,90,9,10,1,120,18,4,10,2,8,1,90,15,10,1,107,18,10,10,8,8,7,18,4,10,2,8,1,98,9,10,1,118,18,4,10,2,8,1,98,9,10,1,105,18,4,10,2,8,7,66,2,16,21],this.session_options,["v","i"])),this._top_k}static get slice(){return this._slice||(this._slice=At([8,7,18,0,58,96,10,25,10,1,120,10,1,115,10,1,101,10,1,97,10,1,116,18,1,121,34,5,83,108,105,99,101,18,1,114,90,9,10,1,120,18,4,10,2,8,1,90,9,10,1,115,18,4,10,2,8,7,90,9,10,1,101,18,4,10,2,8,7,90,9,10,1,97,18,4,10,2,8,7,90,9,10,1,116,18,4,10,2,8,7,98,9,10,1,121,18,4,10,2,8,1,66,2,16,13],this.session_options,"y")),this._slice}};var Cw=Object.freeze({auto:"auto",gpu:"gpu",cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",coreml:"coreml",webnn:"webnn","webnn-npu":"webnn-npu","webnn-gpu":"webnn-gpu","webnn-cpu":"webnn-cpu"});var Nw=(function(){let t;return async function(){if(t===void 0)if(!ee.IS_WEBGPU_AVAILABLE)t=!1;else try{t=(await navigator.gpu.requestAdapter()).features.has("shader-f16")}catch{t=!1}return t}})(),Ne=Object.freeze({auto:"auto",fp32:"fp32",fp16:"fp16",q8:"q8",int8:"int8",uint8:"uint8",q4:"q4",bnb4:"bnb4",q4f16:"q4f16"}),Kl=Object.freeze({[Cw.wasm]:Ne.q8}),Ql=Object.freeze({[Ne.fp32]:"",[Ne.fp16]:"_fp16",[Ne.int8]:"_int8",[Ne.uint8]:"_uint8",[Ne.q8]:"_quantized",[Ne.q4]:"_q4",[Ne.q4f16]:"_q4f16",[Ne.bnb4]:"_bnb4"}),ws=Object.freeze({float32:Float32Array,float16:typeof Float16Array<"u"?Float16Array:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array,uint4:Uint8Array,int4:Int8Array});var S=class t{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return Yo(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new Pw(e[0],e[1],e[2]),new Proxy(this,{get:(s,r)=>{if(typeof r=="string"){let n=Number(r);if(Number.isInteger(n))return s._getitem(n)}return s[r]},set:(s,r,n)=>s[r]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){let[e,...s]=this.dims;if(s.length>0){let r=s.reduce((n,o)=>n*o);for(let n=0;n<e;++n)yield this._subarray(n,r,s)}else yield*this.data}_getitem(e){let[s,...r]=this.dims;if(e=dt(e,s),r.length>0){let n=r.reduce((o,i)=>o*i);return this._subarray(e,n,r)}else return new t(this.type,[this.data[e]],r)}indexOf(e){let s=this.data;for(let r=0;r<s.length;++r)if(s[r]==e)return r;return-1}_subarray(e,s,r){let n=e*s,o=(e+1)*s,i="subarray"in this.data?this.data.subarray(n,o):this.data.slice(n,o);return new t(this.type,i,r)}item(){let e=this.data;if(e.length!==1)throw new Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return Ck(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){let e=this.data;for(let s=0;s<e.length;++s)e[s]=1/(1+Math.exp(-e[s]));return this}map(e){return this.clone().map_(e)}map_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]=e(s[r],r,s);return this}mul(e){return this.clone().mul_(e)}mul_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]*=e;return this}div(e){return this.clone().div_(e)}div_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]/=e;return this}add(e){return this.clone().add_(e)}add_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]+=e;return this}sub(e){return this.clone().sub_(e)}sub_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]-=e;return this}clone(){return new t(this.type,this.data.slice(),this.dims.slice())}slice(...e){let s=[],r=[];for(let u=0;u<this.dims.length;++u){let p=e[u];if(p==null)r.push([0,this.dims[u]]),s.push(this.dims[u]);else if(typeof p=="number")p=dt(p,this.dims[u],u),r.push([p,p+1]);else if(Array.isArray(p)&&p.length===2){let[d,_]=p;if(d=d===null?0:dt(d,this.dims[u],u,!1),_=_===null?this.dims[u]:dt(_,this.dims[u],u,!1),d>_)throw new Error(`Invalid slice: ${p}`);let m=[Math.max(d,0),Math.min(_,this.dims[u])];r.push(m),s.push(m[1]-m[0])}else throw new Error(`Invalid slice: ${p}`)}let n=r.map(([u,p])=>p-u),o=n.reduce((u,p)=>u*p),i=this.data,a=new i.constructor(o),l=this.stride(),c=!0;for(let u=1;u<n.length;++u)if(r[u][0]!==0||r[u][1]!==this.dims[u]){c=!1;break}if(c){let u=r[0][0]*l[0],p=r[0][1]*l[0];if(ArrayBuffer.isView(i))a.set(i.subarray(u,p));else if(Array.isArray(i)){let d=i.slice(u,p);for(let _=0;_<d.length;++_)a[_]=d[_]}else throw new Error("Unsupported data type for slicing")}else for(let u=0;u<o;++u){let p=0;for(let d=n.length-1,_=u;d>=0;--d){let m=n[d];p+=(_%m+r[d][0])*l[d],_=Math.floor(_/m)}a[u]=i[p]}return new t(this.type,a,s)}permute(...e){return Nk(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,s=!1){return this.norm(1,e,s)}norm(e="fro",s=null,r=!1){if(e==="fro")e=2;else if(typeof e=="string")throw Error(`Unsupported norm: ${e}`);let n=this.data,o=(c,u)=>c+u**e;if(s===null){let c=n.reduce(o,0)**(1/e);return new t(this.type,[c],[])}let[i,a,l]=pr(o,this,s,r);if(e!==1)for(let c=0;c<a.length;++c)a[c]=a[c]**(1/e);return new t(i,a,l)}normalize_(e=2,s=1){s=dt(s,this.dims.length);let r=this.norm(e,s,!0),n=this.data,o=r.data;for(let i=0;i<n.length;++i){let a=0;for(let l=this.dims.length-1,c=i,u=1;l>=0;--l){let p=this.dims[l];if(l!==s){let d=c%p;a+=d*u,u*=this.dims[l]}c=Math.floor(c/p)}n[i]/=o[a]}return this}normalize(e=2,s=1){return this.clone().normalize_(e,s)}stride(){return Jl(this.dims)}squeeze(e=null){return new t(this.type,this.data,Lw(this.dims,e))}squeeze_(e=null){return this.dims=Lw(this.dims,e),this}unsqueeze(e){return new t(this.type,this.data,$w(this.dims,e))}unsqueeze_(e){return this.dims=$w(this.dims,e),this}flatten_(e=0,s=-1){s=(s+this.dims.length)%this.dims.length;let r=this.dims.slice(0,e),n=this.dims.slice(e,s+1),o=this.dims.slice(s+1);return this.dims=[...r,n.reduce((i,a)=>i*a,1),...o],this}flatten(e=0,s=-1){return this.clone().flatten_(e,s)}view(...e){let s=-1;for(let n=0;n<e.length;++n)if(e[n]===-1){if(s!==-1)throw new Error("Only one dimension can be inferred");s=n}let r=this.data;if(s!==-1){let n=e.reduce((o,i,a)=>a!==s?o*i:o,1);e[s]=r.length/n}return new t(this.type,r,e)}neg_(){let e=this.data;for(let s=0;s<e.length;++s)e[s]=-e[s];return this}neg(){return this.clone().neg_()}gt(e){let s=new Uint8Array(this.data.length),r=this.data;for(let n=0;n<r.length;++n)s[n]=r[n]>e?1:0;return new t("bool",s,this.dims)}lt(e){let s=new Uint8Array(this.data.length),r=this.data;for(let n=0;n<r.length;++n)s[n]=r[n]<e?1:0;return new t("bool",s,this.dims)}clamp_(e,s){let r=this.data;for(let n=0;n<r.length;++n)r[n]=Math.min(Math.max(r[n],e),s);return this}clamp(e,s){return this.clone().clamp_(e,s)}round_(){let e=this.data;for(let s=0;s<e.length;++s)e[s]=Math.round(e[s]);return this}round(){return this.clone().round_()}mean(e=null,s=!1){return ti(this,e,s)}min(e=null,s=!1){if(e===null){let i=cr(this.data)[0];return new t(this.type,[i],[])}let[r,n,o]=pr((i,a)=>Math.min(i,a),this,e,s,1/0);return new t(r,n,o)}max(e=null,s=!1){if(e===null){let i=ie(this.data)[0];return new t(this.type,[i],[])}let[r,n,o]=pr((i,a)=>Math.max(i,a),this,e,s,-1/0);return new t(r,n,o)}argmin(e=null,s=!1){if(e!==null)throw new Error("`dim !== null` not yet implemented.");let r=cr(this.data)[1];return new t("int64",[BigInt(r)],[])}argmax(e=null,s=!1){if(e!==null)throw new Error("`dim !== null` not yet implemented.");let r=ie(this.data)[1];return new t("int64",[BigInt(r)],[])}repeat(...e){if(e.length<this.dims.length)throw new Error(`Number of dimensions of repeat dims (${e.length}) cannot be smaller than number of dimensions of tensor (${this.dims.length})`);if(e.every(u=>u===1)){if(e.length===this.dims.length)return this.clone();let u=e.length-this.dims.length,p=Array(u).fill(1).concat(this.dims);return new t(this.type,this.data.slice(),p)}let s=e.length-this.dims.length,r=Array(s).fill(1).concat(this.dims),n=r.map((u,p)=>u*e[p]),o=n.reduce((u,p)=>u*p,1),i=this.data,a=new i.constructor(o),l=Jl(r),c=Jl(n);for(let u=0;u<o;++u){let p=u,d=0;for(let _=0;_<n.length;++_){let m=Math.floor(p/c[_]);p=p%c[_];let h=m%r[_];d+=h*l[_]}a[u]=i[d]}return new t(this.type,a,n)}tile(...e){if(e.length<this.dims.length){let s=this.dims.length-e.length;e=Array(s).fill(1).concat(e)}return this.repeat(...e)}to(e){if(this.type===e)return this;if(!ws.hasOwnProperty(e))throw new Error(`Unsupported type: ${e}`);let s,r=["int64","uint64"].includes(this.type),n=["int64","uint64"].includes(e);if(r&&!n)s=Number;else if(!r&&n)["float16","float32","float64"].includes(this.type)?s=o=>BigInt(Math.floor(o)):s=BigInt;else if(this.type==="float16"&&e=="float32"&&this.data instanceof Uint16Array)return new t(e,kw(this.data),this.dims);return new t(e,ws[e].from(this.data,s),this.dims)}};function Ck(t,e){let s=t.length,r=e.reduce((o,i)=>o*i);if(s!==r)throw Error(`cannot reshape array of size ${s} into shape (${e})`);let n=t;for(let o=e.length-1;o>=0;o--)n=n.reduce((i,a)=>{let l=i[i.length-1];return l.length<e[o]?l.push(a):i.push([a]),i},[[]]);return n[0]}function Nk(t,e){let[s,r]=hw(t.data,t.dims,e);return new S(t.type,s,r)}function Yl(t,[e,s],r="bilinear",n=!1){let o=t.dims.at(-3)??1,i=t.dims.at(-2),a=t.dims.at(-1),l=mw(t.data,[o,i,a],[e,s],r,n);return new S(t.type,l,[o,e,s])}async function Xe(t,{size:e=null,mode:s="bilinear"}={}){if(t.dims.length!==4)throw new Error("`interpolate_4d` currently only supports 4D input.");if(!e)throw new Error("`interpolate_4d` requires a `size` argument.");let r;if(e.length===2)r=[...t.dims.slice(0,2),...e];else if(e.length===3)r=[t.dims[0],...e];else if(e.length===4)r=e;else throw new Error("`size` must be of length 2, 3, or 4.");let n;if(s==="nearest")n=await pt.nearest_interpolate_4d;else if(s==="bilinear")n=await pt.bilinear_interpolate_4d;else if(s==="bicubic")n=await pt.bicubic_interpolate_4d;else throw new Error(`Unsupported mode: ${s}`);let o=new S("int64",new BigInt64Array(r.map(BigInt)),[r.length]);return await n({x:t,s:o})}async function Rw(t,e){return await(await pt.matmul)({a:t,b:e})}async function zM(t,e){return await(await pt.rfft)({x:t,a:e})}async function ot(t,e){let s=await pt.top_k;return e==null?e=t.dims.at(-1):e=Math.min(e,t.dims.at(-1)),await s({x:t,k:new S("int64",[BigInt(e)],[1])})}var Zo=t=>new S("int64",t,[t.length]);async function ei(t,e,s,r,n){return await(await pt.slice)({x:t,s:Zo(e),e:Zo(s),a:Zo(r),t:Zo(n??new Array(r.length).fill(1))})}function Fw(t,e){let s=t.data,r=e.data,n=[t.dims[0],t.dims[2]],o=new s.constructor(n[0]*n[1]),[i,a,l]=t.dims,c=0;for(let u=0;u<i;++u){let p=u*l*a;for(let d=0;d<l;++d){let _=0,m=0,h=u*a,x=p+d;for(let w=0;w<a;++w){let y=Number(r[h+w]);m+=y,_+=s[x+w*l]*y}let g=_/m;o[c++]=g}}return new S(t.type,o,n)}function TM(t,e,{eps:s=1e-5}={}){if(t.dims.length!==2)throw new Error("`layer_norm` currently only supports 2D input.");let[r,n]=t.dims;if(e.length!==1&&e[0]!==n)throw new Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");let[o,i]=Zl(t,1,0,!0),a=o.data,l=i.data,c=t.data,u=new c.constructor(c.length);for(let p=0;p<r;++p){let d=p*n;for(let _=0;_<n;++_){let m=d+_;u[m]=(c[m]-l[p])/(a[p]+s)}}return new S(t.type,u,t.dims)}function Lw(t,e){return t=t.slice(),e===null?t=t.filter(s=>s!==1):typeof e=="number"?t[e]===1&&t.splice(e,1):Array.isArray(e)&&(t=t.filter((s,r)=>s!==1||!e.includes(r))),t}function $w(t,e){return e=dt(e,t.length+1),t=t.slice(),t.splice(e,0,1),t}function dt(t,e,s=null,r=!0){if(t<-e||t>=e){if(r)throw new Error(`IndexError: index ${t} is out of bounds for dimension${s===null?"":" "+s} with size ${e}`);return t<-e?0:e}return t<0&&(t=(t%e+e)%e),t}function ne(t,e=0){e=dt(e,t[0].dims.length);let s=t[0].dims.slice();s[e]=t.reduce((i,a)=>i+a.dims[e],0);let r=s.reduce((i,a)=>i*a,1),n=new t[0].data.constructor(r),o=t[0].type;if(e===0){let i=0;for(let a of t){let l=a.data;n.set(l,i),i+=l.length}}else{let i=0;for(let a=0;a<t.length;++a){let{data:l,dims:c}=t[a];for(let u=0;u<l.length;++u){let p=0;for(let d=c.length-1,_=u,m=1;d>=0;--d){let h=c[d],x=_%h;d===e&&(x+=i),p+=x*m,m*=s[d],_=Math.floor(_/h)}n[p]=l[u]}i+=c[e]}}return new S(o,n,s)}function Ke(t,e=0){return ne(t.map(s=>s.unsqueeze(e)),e)}function pr(t,e,s,r=!1,n=null){let o=e.data,i=e.dims;s=dt(s,i.length);let a=i.slice();a[s]=1;let l=new o.constructor(o.length/i[s]);n!==null&&l.fill(n);for(let c=0;c<o.length;++c){let u=0;for(let p=i.length-1,d=c,_=1;p>=0;--p){let m=i[p];if(p!==s){let h=d%m;u+=h*_,_*=a[p]}d=Math.floor(d/m)}l[u]=t(l[u],o[c],c,u)}return r||a.splice(s,1),[e.type,l,a]}function Zl(t,e=null,s=1,r=!1){let n=t.data,o=t.dims;if(e===null){let _=n.reduce((g,w)=>g+w,0)/n.length,m=Math.sqrt(n.reduce((g,w)=>g+(w-_)**2,0)/(n.length-s)),h=new S(t.type,[_],[]);return[new S(t.type,[m],[]),h]}e=dt(e,o.length);let i=ti(t,e,r),a=i.data,[l,c,u]=pr((d,_,m,h)=>d+(_-a[h])**2,t,e,r);for(let d=0;d<c.length;++d)c[d]=Math.sqrt(c[d]/(o[e]-s));return[new S(l,c,u),i]}function ti(t,e=null,s=!1){let r=t.dims,n=t.data;if(e===null){let l=n.reduce((c,u)=>c+u,0);return new S(t.type,[l/n.length],[])}e=dt(e,r.length);let[o,i,a]=pr((l,c)=>l+c,t,e,s);if(r[e]!==1)for(let l=0;l<i.length;++l)i[l]/=r[e];return new S(o,i,a)}function Jl(t){let e=new Array(t.length);for(let s=t.length-1,r=1;s>=0;--s)e[s]=r,r*=t[s];return e}function ec(t,e,s,r){let n=t.reduce((o,i)=>o*i,1);return new S(s,new r(n).fill(e),t)}function xe(t,e){let s,r;if(typeof e=="number")s="float32",r=Float32Array;else if(typeof e=="bigint")s="int64",r=BigInt64Array;else if(typeof e=="boolean")s="bool",r=Uint8Array;else throw new Error(`Unsupported data type: ${typeof e}`);return ec(t,e,s,r)}function dr(t,e){return xe(t.dims,e)}function Oe(t){return ec(t,1n,"int64",BigInt64Array)}function si(t){return Oe(t.dims)}function tc(t){return ec(t,0n,"int64",BigInt64Array)}function sc(t){return tc(t.dims)}function PM(t){let e=t.reduce((s,r)=>s*r,1);return new S("float32",Float32Array.from({length:e},()=>Math.random()),t)}function Dw(t){let e=t.reduce((r,n)=>r*n,1),s=new Float32Array(e);for(let r=0;r<e;r+=2){let n=1-Math.random(),o=Math.random(),i=Math.sqrt(-2*Math.log(n)),a=2*Math.PI*o;s[r]=i*Math.cos(a),r+1<e&&(s[r+1]=i*Math.sin(a))}return new S("float32",s,t)}function jw(t,e){if(t.dims.length!==2)throw new Error("The tensor must have 2 dimensions");if(t.dims.at(-1)%8!==0)throw new Error("The last dimension of the tensor must be a multiple of 8");if(!["binary","ubinary"].includes(e))throw new Error("The precision must be either 'binary' or 'ubinary'");let s=e==="binary",r=s?"int8":"uint8",n=s?Int8Array:Uint8Array,o=t.data,i=new n(o.length/8);for(let a=0;a<o.length;++a){let l=o[a]>0?1:0,c=Math.floor(a/8),u=a%8;i[c]|=l<<7-u,s&&u===0&&(i[c]-=128)}return new S(r,i,[t.dims[0],t.dims[1]/8])}async function rc(t,e){return await Promise.all([Se(t,"tokenizer.json",!0,e),Se(t,"tokenizer_config.json",!0,e)])}function nc(t){let e=t.dims;switch(e.length){case 1:return t.tolist();case 2:if(e[0]!==1)throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return t.tolist()[0];default:throw new Error(`Expected tensor to have 1-2 dimensions, got ${e.length}.`)}}var Lk=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function $k(t,e,s,r){for(let n of Object.keys(t)){let o=e-t[n].length,i=s(n),a=new Array(o).fill(i);t[n]=r==="right"?Pe(t[n],a):Pe(a,t[n])}}function Rk(t,e){for(let s of Object.keys(t))t[s].length=e}function Qt(t,...e){for(let s of e){if(!Object.hasOwn(t,s))continue;let r=t[s];if(r)if(typeof r=="object"){if(r.__type==="AddedToken")return r.content;throw Error(`Unknown token: ${r}`)}else return r}return null}function Fk(t){let e=[];for(let s of t.get_added_tokens_decoder().values())s.special&&e.push(s);return e}var T=class extends ke{return_token_type_ids=!1;padding_side="right";constructor(e,s){if(super(),this._tokenizerJSON=e,this._tokenizerConfig=s,this._tokenizer=new Vg(e,s),this.config=s,this.padding_side=s.padding_side??this.padding_side,this.mask_token=Qt(s,"mask_token"),this.mask_token_id=this._tokenizer.token_to_id(this.mask_token),this.pad_token=Qt(s,"pad_token","eos_token"),this.pad_token_id=this._tokenizer.token_to_id(this.pad_token),this.sep_token=Qt(s,"sep_token"),this.sep_token_id=this._tokenizer.token_to_id(this.sep_token),this.unk_token=Qt(s,"unk_token"),this.unk_token_id=this._tokenizer.token_to_id(this.unk_token),this.bos_token=Qt(s,"bos_token"),this.bos_token_id=this._tokenizer.token_to_id(this.bos_token),this.eos_token=Qt(s,"eos_token"),this.eos_token_id=this._tokenizer.token_to_id(this.eos_token),this.chat_template=s.chat_template??null,Array.isArray(this.chat_template)){let n=Object.create(null);for(let{name:o,template:i}of this.chat_template){if(typeof o!="string"||typeof i!="string")throw new Error('Chat template must be a list of objects with "name" and "template" properties');n[o]=i}this.chat_template=n}this._compiled_template_cache=new Map;let r=Fk(this._tokenizer);this.all_special_ids=r.map(n=>n.id),this.all_special_tokens=r.map(n=>n.content)}static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main"}={}){let a=await rc(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i});return new this(...a)}get_vocab(){return this._tokenizer.get_vocab()}get model_max_length(){return this._tokenizerConfig.model_max_length??1/0}get add_eos_token(){return this._tokenizerConfig.add_eos_token}get add_bos_token(){return this._tokenizerConfig.add_bos_token}convert_tokens_to_ids(e){return typeof e=="string"?this._tokenizer.token_to_id(e):e.map(s=>this._tokenizer.token_to_id(s))}_call(e,{text_pair:s=null,add_special_tokens:r=!0,padding:n=!1,truncation:o=null,max_length:i=null,return_tensor:a=!0,return_token_type_ids:l=null}={}){let c=Array.isArray(e),u;if(c){if(e.length===0)throw Error("text array must be non-empty");if(s!==null){if(Array.isArray(s)){if(e.length!==s.length)throw Error("text and text_pair must have the same length")}else throw Error("text_pair must also be an array");u=e.map((d,_)=>this._encode_plus(d,{text_pair:s[_],add_special_tokens:r,return_token_type_ids:l}))}else u=e.map(d=>this._encode_plus(d,{add_special_tokens:r,return_token_type_ids:l}))}else{if(e==null)throw Error("text may not be null or undefined");if(Array.isArray(s))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");u=[this._encode_plus(e,{text_pair:s,add_special_tokens:r,return_token_type_ids:l})]}if(i===null?i=this.model_max_length:o===null&&(n===!0?(console.warn("`max_length` is ignored when `padding: true` and there is no truncation strategy. To pad to max length, use `padding: 'max_length'`."),i=this.model_max_length):n===!1&&(console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation: true` to explicitly truncate examples to max length."),o=!0)),n===!0&&(i=Math.min(ie(u.map(d=>d.input_ids.length))[0],i??1/0)),i=Math.min(i,this.model_max_length??1/0),n||o)for(let d=0;d<u.length;++d)u[d].input_ids.length!==i&&(u[d].input_ids.length>i?o&&Rk(u[d],i):n&&$k(u[d],i,_=>_==="input_ids"?this.pad_token_id:0,this.padding_side));let p={};if(a){if(!(n&&o)&&u.some(_=>{for(let m of Object.keys(_))if(_[m].length!==u[0][m]?.length)return!0;return!1}))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");let d=[u.length,u[0].input_ids.length];for(let _ of Object.keys(u[0]))p[_]=new S("int64",BigInt64Array.from(u.flatMap(m=>m[_]).map(BigInt)),d)}else{for(let d of Object.keys(u[0]))p[d]=u.map(_=>_[d]);if(!c)for(let d of Object.keys(p))p[d]=p[d][0]}return p}_encode_text(e){return e===null?null:this._tokenizer.encode(e).tokens}_encode_plus(e,{text_pair:s=null,add_special_tokens:r=!0,return_token_type_ids:n=null}={}){let{ids:o,attention_mask:i,token_type_ids:a}=this._tokenizer.encode(e,{text_pair:s,add_special_tokens:r,return_token_type_ids:n??this.return_token_type_ids});return{input_ids:o,attention_mask:i,...a?{token_type_ids:a}:{}}}tokenize(e,{pair:s=null,add_special_tokens:r=!1}={}){return this._tokenizer.tokenize(e,{text_pair:s,add_special_tokens:r})}encode(e,{text_pair:s=null,add_special_tokens:r=!0,return_token_type_ids:n=null}={}){return this._tokenizer.encode(e,{text_pair:s,add_special_tokens:r,return_token_type_ids:n}).ids}batch_decode(e,s={}){return e instanceof S&&(e=e.tolist()),e.map(r=>this.decode(r,s))}decode(e,s={}){if(e instanceof S&&(e=nc(e)),!Array.isArray(e)||e.length===0||!ow(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,s)}decode_single(e,{skip_special_tokens:s=!1,clean_up_tokenization_spaces:r=null}){return this._tokenizer.decode(e,{skip_special_tokens:s,clean_up_tokenization_spaces:r})}get_chat_template({chat_template:e=null,tools:s=null}={}){if(this.chat_template&&typeof this.chat_template=="object"){let r=this.chat_template;if(e!==null&&Object.hasOwn(r,e))e=r[e];else if(e===null)if(s!==null&&"tool_use"in r)e=r.tool_use;else if("default"in r)e=r.default;else throw Error(`This model has multiple chat templates with no default specified! Please either pass a chat template or the name of the template you wish to use to the 'chat_template' argument. Available template names are ${Object.keys(r).sort()}.`)}else if(e===null)if(this.chat_template)e=this.chat_template;else throw Error("Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating");return e}apply_chat_template(e,{tools:s=null,documents:r=null,chat_template:n=null,add_generation_prompt:o=!1,tokenize:i=!0,padding:a=!1,truncation:l=!1,max_length:c=null,return_tensor:u=!0,return_dict:p=!0,tokenizer_kwargs:d={},..._}={}){if(n=this.get_chat_template({chat_template:n,tools:s}),typeof n!="string")throw Error(`chat_template must be a string, but got ${typeof n}`);let m=this._compiled_template_cache.get(n);m===void 0&&(m=new nw(n),this._compiled_template_cache.set(n,m));let h=Object.create(null);for(let g of Lk){let w=Qt(this.config,g);w&&(h[g]=w)}let x=m.render({messages:e,add_generation_prompt:o,tools:s,documents:r,...h,..._});if(i){let g=this._call(x,{add_special_tokens:!1,padding:a,truncation:l,max_length:c,return_tensor:u,...d});return p?g:g.input_ids}return x}};function ys(t,e,s,r){if(!("language_codes"in t)||!Array.isArray(t.language_codes))throw new Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!("languageRegex"in t)||!(t.languageRegex instanceof RegExp))throw new Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!("lang_to_token"in t)||typeof t.lang_to_token!="function")throw new Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");let n=r.src_lang,o=r.tgt_lang;if(!t.language_codes.includes(o))throw new Error(`Target language code "${o}" is not valid. Must be one of: {${t.language_codes.join(", ")}}`);if(n!==void 0){if(!t.language_codes.includes(n))throw new Error(`Source language code "${n}" is not valid. Must be one of: {${t.language_codes.join(", ")}}`);for(let i of t._tokenizer.post_processor.config.single)if("SpecialToken"in i&&t.languageRegex.test(i.SpecialToken.id)){i.SpecialToken.id=t.lang_to_token(n);break}}return r.forced_bos_token_id=t._tokenizer.token_to_id(t.lang_to_token(o)),t._call(e,s)}var Kc={};us(Kc,{AlbertTokenizer:()=>oc,AutoTokenizer:()=>L,BartTokenizer:()=>ic,BertTokenizer:()=>ac,BlenderbotSmallTokenizer:()=>lc,BlenderbotTokenizer:()=>cc,BloomTokenizer:()=>uc,CLIPTokenizer:()=>dc,CamembertTokenizer:()=>pc,CodeGenTokenizer:()=>fc,CodeLlamaTokenizer:()=>_c,CohereTokenizer:()=>mc,ConvBertTokenizer:()=>hc,DebertaTokenizer:()=>gc,DebertaV2Tokenizer:()=>xc,DistilBertTokenizer:()=>wc,ElectraTokenizer:()=>yc,EsmTokenizer:()=>bc,FalconTokenizer:()=>kc,GPT2Tokenizer:()=>Ac,GPTNeoXTokenizer:()=>Ec,GemmaTokenizer:()=>vc,HerbertTokenizer:()=>Mc,LlamaTokenizer:()=>Sc,M2M100Tokenizer:()=>Oc,MBart50Tokenizer:()=>zc,MBartTokenizer:()=>_r,MPNetTokenizer:()=>Cc,MarianTokenizer:()=>Ic,MgpstrTokenizer:()=>Tc,MobileBertTokenizer:()=>Pc,NllbTokenizer:()=>Nc,NougatTokenizer:()=>Lc,PreTrainedTokenizer:()=>T,Qwen2Tokenizer:()=>$c,RoFormerTokenizer:()=>Fc,RobertaTokenizer:()=>Rc,SiglipTokenizer:()=>Dc,SpeechT5Tokenizer:()=>jc,SqueezeBertTokenizer:()=>Bc,T5Tokenizer:()=>Uc,TokenizersBackend:()=>T,VitsTokenizer:()=>Gc,Wav2Vec2CTCTokenizer:()=>Wc,WhisperTokenizer:()=>Vc,XLMRobertaTokenizer:()=>Hc,XLMTokenizer:()=>Xc});var oc=class extends T{return_token_type_ids=!0};var ic=class extends T{};var ac=class extends T{return_token_type_ids=!0};var lc=class extends T{};var cc=class extends T{};var uc=class extends T{};var pc=class extends T{};var dc=class extends T{};var _c=class extends T{};var fc=class extends T{};var mc=class extends T{};var hc=class extends T{return_token_type_ids=!0};var xc=class extends T{return_token_type_ids=!0};var gc=class extends T{return_token_type_ids=!0};var wc=class extends T{};var yc=class extends T{return_token_type_ids=!0};var bc=class extends T{};var kc=class extends T{};var vc=class extends T{};var Ec=class extends T{};var Ac=class extends T{};var Mc=class extends T{return_token_type_ids=!0};var Sc=class extends T{padding_side="left"};var Oc=class extends T{constructor(e,s){super(e,s),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.all_special_tokens.filter(r=>this.languageRegex.test(r)).map(r=>r.slice(2,-2)),this.lang_to_token=r=>`__${r}__`}_build_translation_inputs(e,s,r){return ys(this,e,s,r)}};var Ic=class extends T{constructor(e,s){super(e,s),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=Array.from(this.get_vocab().keys()).filter(r=>this.languageRegex.test(r)),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(e===null)return null;let[s,...r]=e.trim().split(this.languageRegex);if(r.length===0)return super._encode_text(s);if(r.length===2){let[n,o]=r;return this.supported_language_codes.includes(n)||console.warn(`Unsupported language code "${n}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),Pe([n],super._encode_text(o))}}};var _r=class extends T{constructor(e,s){super(e,s),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.all_special_tokens.filter(r=>this.languageRegex.test(r)).map(r=>r),this.lang_to_token=r=>r}_build_translation_inputs(e,s,r){return ys(this,e,s,r)}};var zc=class extends _r{};var Tc=class extends T{};var Pc=class extends T{return_token_type_ids=!0};var Cc=class extends T{};var Nc=class extends T{constructor(e,s){super(e,s),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.all_special_tokens.filter(r=>this.languageRegex.test(r)),this.lang_to_token=r=>r}_build_translation_inputs(e,s,r){return ys(this,e,s,r)}};var Lc=class extends T{};var $c=class extends T{};var Rc=class extends T{};var Fc=class extends T{return_token_type_ids=!0};var Dc=class extends T{};var jc=class extends T{};var Bc=class extends T{return_token_type_ids=!0};var Uc=class extends T{};var qc=class extends We{decode_chain(e){let s="";for(let r=1;r<e.length;r+=2)s+=e[r];return[s]}},Gc=class extends T{constructor(e,s){super(e,s),this._tokenizer.decoder=new qc({type:"VitsDecoder"})}};var Wc=class extends T{};var Bw=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],fr=new Map(Bw),Dk=new Map([...Bw.map(([t,e])=>[e,t]),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);function Uw(t){t=t.toLowerCase();let e=Dk.get(t);if(e===void 0){let s=t.match(/^<\|([a-z]{2})\|>$/);if(s&&(t=s[1]),fr.has(t))e=t;else{let n=t.length===2?fr.keys():fr.values();throw new Error(`Language "${t}" is not supported. Must be one of: ${JSON.stringify(Array.from(n))}`)}}return e}var jk="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",qw=new RegExp(`^[${jk}]+$`,"gu"),Vc=class extends T{get timestamp_begin(){return this._tokenizer.token_to_id("<|notimestamps|>")+1}_decode_asr(e,{return_timestamps:s=!1,return_language:r=!1,time_precision:n=null,force_full_sequences:o=!0}={}){if(n===null)throw Error("Must specify time_precision");let i=null,a=s==="word";function l(){return{language:i,timestamp:[null,null],text:""}}let c=[],u=l(),p=0,d=this.timestamp_begin,m=d+1500,h=[],x=[],g=!1,w=null,y=new Set(this.all_special_ids);for(let b of e){let O=b.tokens,N=a?b.token_timestamps:null,F=null,R=d;if("stride"in b){let[D,X,V]=b.stride;if(p-=X,w=D-V,X&&(R=X/n+d),V)for(let re=O.length-1;re>=0;--re){let Y=Number(O[re]);if(Y>=d){if(F!==null&&(Y-d)*n<w)break;F=Y}}}let B=[],G=[];for(let D=0;D<O.length;++D){let X=Number(O[D]);if(y.has(X)){let V=this.decode([X]),re=fr.get(V.slice(2,-2));if(re!==void 0){if(i!==null&&re!==i&&!s){h.push(B);let Y=this.findLongestCommonSequence(h)[0],k=this.decode(Y);u.text=k,c.push(u),h=[],B=[],u=l()}i=u.language=re}}else if(X>=d&&X<=m){let V=(X-d)*n+p,re=Kt(V,2);if(F!==null&&X>=F)g=!0;else if(g||h.length>0&&X<R)g=!1;else if(u.timestamp[0]===null)u.timestamp[0]=re;else if(re!==u.timestamp[0]){u.timestamp[1]=re,h.push(B),a&&x.push(G);let[Y,k]=this.findLongestCommonSequence(h,x),v=this.decode(Y);u.text=v,a&&(u.words=this.collateWordTimestamps(Y,k,i)),c.push(u),h=[],B=[],x=[],G=[],u=l()}}else if(B.push(X),a){let V=Kt(N[D]+p,2),re;if(D+1<N.length){re=Kt(N[D+1]+p,2);let Y=this.decode([X]);qw.test(Y)&&(re=Kt(Math.min(V+n,re),2))}else re=null;G.push([V,re])}}if("stride"in b){let[D,X,V]=b.stride;p+=D-V}B.length>0?(h.push(B),a&&x.push(G)):h.every(D=>D.length===0)&&(u=l(),h=[],B=[],x=[],G=[])}if(h.length>0){if(o&&s)throw new Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");let[b,O]=this.findLongestCommonSequence(h,x),N=this.decode(b);u.text=N,a&&(u.words=this.collateWordTimestamps(b,O,i)),c.push(u)}let E=Object.create(null),A=c.map(b=>b.text).join("");if(s||r){for(let b=0;b<c.length;++b){let O=c[b];s||delete O.timestamp,r||delete O.language}if(a){let b=[];for(let O of c)for(let N of O.words)b.push(N);E={chunks:b}}else E={chunks:c}}return[A,E]}findLongestCommonSequence(e,s=null){let r=e[0],n=r.length,o=[],i=Array.isArray(s)&&s.length>0,a=i?[]:null,l=i?s[0]:null;for(let c=1;c<e.length;++c){let u=e[c],p=0,d=[n,n,0,0],_=u.length;for(let E=1;E<n+_;++E){let A=Math.max(0,n-E),b=Math.min(n,n+_-E),O=r.slice(A,b),N=Math.max(0,E-n),F=Math.min(_,E),R=u.slice(N,F);if(O.length!==R.length)throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let B;i?B=O.filter((X,V)=>X===R[V]&&l[A+V]<=s[c][N+V]).length:B=O.filter((X,V)=>X===R[V]).length;let G=E/1e4,D=B/E+G;B>1&&D>p&&(p=D,d=[A,b,N,F])}let[m,h,x,g]=d,w=Math.floor((h+m)/2),y=Math.floor((g+x)/2);o.push(...r.slice(0,w)),r=u.slice(y),n=r.length,i&&(a.push(...l.slice(0,w)),l=s[c].slice(y))}return o.push(...r),i?(a.push(...l),[o,a]):[o,[]]}collateWordTimestamps(e,s,r){let[n,o,i]=this.combineTokensIntoWords(e,r),a=[];for(let l=0;l<n.length;++l){let c=i[l];a.push({text:n[l],timestamp:[s[c.at(0)][0],s[c.at(-1)][1]]})}return a}combineTokensIntoWords(e,s,r=`"'\u201C\xA1\xBF([{-`,n=`"'.\u3002,\uFF0C!\uFF01?\uFF1F:\uFF1A\u201D)]}\u3001`){s=s??"english";let o,i,a;return["chinese","japanese","thai","lao","myanmar"].includes(s)?[o,i,a]=this.splitTokensOnUnicode(e):[o,i,a]=this.splitTokensOnSpaces(e),this.mergePunctuations(o,i,a,r,n)}decode(e,s){let r;return s?.decode_with_timestamps?(e instanceof S&&(e=nc(e)),r=this.decodeWithTimestamps(e,s)):r=super.decode(e,s),r}decodeWithTimestamps(e,s){let r=s?.time_precision??.02,n=this.all_special_ids.at(-1)+1,o=[[]];for(let i of e)if(i=Number(i),i>=n){let a=((i-n)*r).toFixed(2);o.push(`<|${a}|>`),o.push([])}else o[o.length-1].push(i);return o=o.map(i=>typeof i=="string"?i:super.decode(i,s)),o.join("")}splitTokensOnUnicode(e){let s=this.decode(e,{decode_with_timestamps:!0}),r="\uFFFD",n=[],o=[],i=[],a=[],l=[],c=0;for(let u=0;u<e.length;++u){let p=e[u];a.push(p),l.push(u);let d=this.decode(a,{decode_with_timestamps:!0});(!d.includes(r)||s[c+d.indexOf(r)]===r)&&(n.push(d),o.push(a),i.push(l),a=[],l=[],c+=d.length)}return[n,o,i]}splitTokensOnSpaces(e){let[s,r,n]=this.splitTokensOnUnicode(e),o=[],i=[],a=[];for(let l=0;l<s.length;++l){let c=s[l],u=r[l],p=n[l],d=u[0]>=this._tokenizer.token_to_id("<|endoftext|>"),_=c.startsWith(" "),m=c.trim(),h=qw.test(m);if(d||_||h||o.length===0)o.push(c),i.push(u),a.push(p);else{let x=o.length-1;o[x]+=c,i[x].push(...u),a[x].push(...p)}}return[o,i,a]}mergePunctuations(e,s,r,n,o){let i=structuredClone(e),a=structuredClone(s),l=structuredClone(r),c=i.length-2,u=i.length-1;for(;c>=0;)i[c].startsWith(" ")&&n.includes(i[c].trim())?(i[u]=i[c]+i[u],a[u]=Pe(a[c],a[u]),l[u]=Pe(l[c],l[u]),i[c]="",a[c]=[],l[c]=[]):u=c,--c;for(c=0,u=1;u<i.length;)!i[c].endsWith(" ")&&o.includes(i[u])?(i[c]+=i[u],a[c]=Pe(a[c],a[u]),l[c]=Pe(l[c],l[u]),i[u]="",a[u]=[],l[u]=[]):c=u,++u;return[i.filter(p=>p),a.filter(p=>p.length>0),l.filter(p=>p.length>0)]}};var Hc=class extends T{};var Xc=class extends T{return_token_type_ids=!0;constructor(e,s){super(e,s),console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}};var L=class{static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main"}={}){let[a,l]=await rc(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i}),c=l.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer",u=Kc[c];return u||(console.warn(`Unknown tokenizer class "${c}", attempting to construct from base class.`),u=T),new u(a,l)}};var bs="https://github.com/huggingface/transformers.js/issues/new/choose";var mr="preprocessor_config.json",ks=mr,Gw="processor_config.json",Ww="chat_template.jinja";var j=class extends ke{static classes=["image_processor_class","tokenizer_class","feature_extractor_class"];static uses_processor_config=!1;static uses_chat_template_file=!1;constructor(e,s,r){super(),this.config=e,this.components=s,this.chat_template=r}get image_processor(){return this.components.image_processor}get tokenizer(){return this.components.tokenizer}get feature_extractor(){return this.components.feature_extractor}apply_chat_template(e,s={}){if(!this.tokenizer)throw new Error("Unable to apply chat template without a tokenizer.");return this.tokenizer.apply_chat_template(e,{tokenize:!1,chat_template:this.chat_template??void 0,...s})}batch_decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.batch_decode(...e)}decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.decode(...e)}async _call(e,...s){for(let r of[this.image_processor,this.feature_extractor,this.tokenizer])if(r)return r(e,...s);throw new Error("No image processor, feature extractor, or tokenizer found.")}static async from_pretrained(e,s={}){let[r,n,o]=await Promise.all([this.uses_processor_config?Se(e,Gw,!0,s):{},Promise.all(this.classes.filter(i=>i in this).map(async i=>{let a=await this[i].from_pretrained(e,s);return[i.replace(/_class$/,""),a]})).then(Object.fromEntries),this.uses_chat_template_file?Ul(e,Ww,!0,s):null]);return new this(r,n,o)}};var Si={};us(Si,{ChatterboxProcessor:()=>uu,Florence2Processor:()=>ep,Gemma3nProcessor:()=>tp,GroundingDinoProcessor:()=>sp,Idefics3Processor:()=>Ei,JinaCLIPProcessor:()=>np,LlavaProcessor:()=>op,MgpstrProcessor:()=>ip,MoonshineProcessor:()=>ap,OwlViTProcessor:()=>lp,PaliGemmaProcessor:()=>cp,Phi3VProcessor:()=>up,PixtralProcessor:()=>pp,Processor:()=>j,PyAnnoteProcessor:()=>dp,Qwen2VLProcessor:()=>_p,Sam2Processor:()=>Ai,Sam2VideoProcessor:()=>fp,SamProcessor:()=>kr,SmolVLMProcessor:()=>Ei,SpeechT5Processor:()=>mp,UltravoxProcessor:()=>hp,VLChatProcessor:()=>rp,VoxtralProcessor:()=>xp,Wav2Vec2Processor:()=>gp,Wav2Vec2ProcessorWithLM:()=>wp,WhisperProcessor:()=>yp});var pe=class extends ke{constructor(e){super(),this.config=e}static async from_pretrained(e,s={}){let r=await Se(e,mr,!0,s);return new this(r)}};function ge(t,e){if(!(t instanceof Float32Array||t instanceof Float64Array))throw new Error(`${e} expects input to be a Float32Array or a Float64Array, but got ${t?.constructor?.name??typeof t} instead. If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}var yr={};us(yr,{ASTFeatureExtractor:()=>Yc,ChatterboxFeatureExtractor:()=>Zc,ClapFeatureExtractor:()=>eu,DacFeatureExtractor:()=>gr,EncodecFeatureExtractor:()=>xr,FeatureExtractor:()=>pe,Gemma3nAudioFeatureExtractor:()=>tu,MoonshineFeatureExtractor:()=>su,ParakeetFeatureExtractor:()=>ru,PyAnnoteFeatureExtractor:()=>wr,SeamlessM4TFeatureExtractor:()=>nu,SnacFeatureExtractor:()=>ou,SpeechT5FeatureExtractor:()=>iu,Wav2Vec2FeatureExtractor:()=>au,WeSpeakerFeatureExtractor:()=>lu,WhisperFeatureExtractor:()=>cu});var Bk=()=>{};var Vw={fromWeb:Bk};var Uk=()=>{};var Hw=Uk;async function ri(t,e){if(ee.IS_BROWSER_ENV){if(ee.IS_WEBWORKER_ENV)throw new Error("Unable to save a file from a Web Worker.");let s=URL.createObjectURL(e),r=document.createElement("a");r.href=s,r.download=t,r.click(),r.remove(),URL.revokeObjectURL(s)}else if(ee.IS_FS_AVAILABLE){let s=e.stream(),r=Vw.fromWeb(s),n=De.createWriteStream(t);await Hw(r,n)}else throw new Error("Unable to save because filesystem is disabled in this environment.")}async function Jc(t,e){if(typeof AudioContext>"u")throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");let s=await(await hs(t)).arrayBuffer(),r=new AudioContext({sampleRate:e});typeof e>"u"&&console.warn(`No sampling rate provided, using default of ${r.sampleRate}Hz.`);let n=await r.decodeAudioData(s),o;if(n.numberOfChannels===2){let i=Math.sqrt(2),a=n.getChannelData(0),l=n.getChannelData(1);o=new Float32Array(a.length);for(let c=0;c<n.length;++c)o[c]=i*(a[c]+l[c])/2}else o=n.getChannelData(0);return o}function Qw(t,e){if(t<1)return new Float64Array;if(t===1)return new Float64Array([1]);let s=1-e,r=2*Math.PI/(t-1),n=new Float64Array(t);for(let o=0;o<t;++o)n[o]=e-s*Math.cos(o*r);return n}function Xw(t){return Qw(t,.5)}function qk(t){return Qw(t,.54)}var Gk={htk:t=>2595*Math.log10(1+t/700),kaldi:t=>1127*Math.log(1+t/700),slaney:(t,e=1e3,s=15,r=27/Math.log(6.4))=>t>=e?s+Math.log(t/e)*r:3*t/200};function Qc(t,e="htk"){let s=Gk[e];if(!s)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof t=="number"?s(t):t.map(r=>s(r))}var Wk={htk:t=>700*(10**(t/2595)-1),kaldi:t=>700*(Math.exp(t/1127)-1),slaney:(t,e=1e3,s=15,r=Math.log(6.4)/27)=>t>=s?e*Math.exp(r*(t-s)):200*t/3};function Vk(t,e="htk"){let s=Wk[e];if(!s)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof t=="number"?s(t):t.map(r=>s(r))}function Hk(t,e){let s=Float64Array.from({length:e.length-1},(i,a)=>e[a+1]-e[a]),r=Array.from({length:t.length},()=>new Array(e.length));for(let i=0;i<t.length;++i){let a=r[i];for(let l=0;l<e.length;++l)a[l]=e[l]-t[i]}let n=e.length-2,o=Array.from({length:n},()=>new Array(t.length));for(let i=0;i<t.length;++i){let a=r[i];for(let l=0;l<n;++l){let c=-a[l]/s[l],u=a[l+2]/s[l+1];o[l][i]=Math.max(0,Math.min(c,u))}}return o}function Kw(t,e,s){let r=(e-t)/(s-1);return Float64Array.from({length:s},(n,o)=>t+r*o)}function Re(t,e,s,r,n,o=null,i="htk",a=!1){if(o!==null&&o!=="slaney")throw new Error('norm must be one of null or "slaney"');if(t<2)throw new Error(`Require num_frequency_bins: ${t} >= 2`);if(s>r)throw new Error(`Require min_frequency: ${s} <= max_frequency: ${r}`);let l=Qc(s,i),c=Qc(r,i),u=Kw(l,c,e+2),p=Vk(u,i),d;if(a){let m=n/((t-1)*2);d=Qc(Float64Array.from({length:t},(h,x)=>x*m),i),p=u}else d=Kw(0,Math.floor(n/2),t);let _=Hk(d,p);if(o!==null&&o==="slaney")for(let m=0;m<e;++m){let h=_[m],x=2/(p[m+2]-p[m]);for(let g=0;g<t;++g)h[g]*=x}return _}function Xk(t,e,s){let r=new t.constructor(t.length+e+s),n=t.length-1;for(let o=0;o<t.length;++o)r[e+o]=t[o];for(let o=1;o<=e;++o)r[e-o]=t[_s(o,n)];for(let o=1;o<=s;++o)r[n+e+o]=t[_s(n-o,n)];return r}function Jw(t,e,s,r,n){if(s<=0)throw new Error("reference must be greater than zero");if(r<=0)throw new Error("min_value must be greater than zero");s=Math.max(r,s);let o=Math.log10(s);for(let i=0;i<t.length;++i)t[i]=e*Math.log10(Math.max(r,t[i])-o);if(n!==null){if(n<=0)throw new Error("db_range must be greater than zero");let i=ie(t)[0]-n;for(let a=0;a<t.length;++a)t[a]=Math.max(t[a],i)}return t}function Kk(t,e=1,s=1e-5,r=null){return Jw(t,20,e,s,r)}function Qk(t,e=1,s=1e-10,r=null){return Jw(t,10,e,s,r)}async function je(t,e,s,r,{fft_length:n=null,power:o=1,center:i=!0,pad_mode:a="reflect",onesided:l=!0,preemphasis:c=null,preemphasis_htk_flavor:u=!0,mel_filters:p=null,mel_floor:d=1e-10,log_mel:_=null,reference:m=1,min_value:h=1e-10,db_range:x=null,remove_dc_offset:g=null,min_num_frames:w=null,max_num_frames:y=null,do_pad:E=!0,transpose:A=!1,mel_offset:b=0}={}){let O=e.length;if(n===null&&(n=s),s>n)throw Error(`frame_length (${s}) may not be larger than fft_length (${n})`);if(O!==s)throw new Error(`Length of the window (${O}) must equal frame_length (${s})`);if(r<=0)throw new Error("hop_length must be greater than zero");if(o===null&&p!==null)throw new Error("You have provided `mel_filters` but `power` is `None`. Mel spectrogram computation is not yet supported for complex-valued spectrogram. Specify `power` to fix this issue.");if(!u)throw new Error("`preemphasis_htk_flavor=false` is not currently supported.");if(i)switch(a){case"reflect":{let v=Math.floor((n-1)/2)+1;t=Xk(t,v,v);break}case"constant":{let v=Math.floor(n/2),I=new t.constructor(t.length+2*v);I.set(t,v),t=I;break}default:throw new Error(`pad_mode="${a}" not implemented yet.`)}let N=Math.floor(1+Math.floor((t.length-s)/r));w!==null&&N<w&&(N=w);let F=l?Math.floor(n/2)+1:n,R=N,B=N;y!==null&&(y>N?E&&(B=y):B=R=y);let G=new Xo(n),D=new Float64Array(n),X=new Float64Array(G.outputBufferSize),V=new Float32Array(F*B);for(let v=0;v<R;++v){let I=v*r,Q=Math.min(t.length-I,s);Q!==s&&D.fill(0,0,s);for(let Z=0;Z<Q;++Z)D[Z]=t[I+Z];if(g){let Z=0;for(let Ee=0;Ee<Q;++Ee)Z+=D[Ee];let Ie=Z/Q;for(let Ee=0;Ee<Q;++Ee)D[Ee]-=Ie}if(c!==null){for(let Z=Q-1;Z>=1;--Z)D[Z]-=c*D[Z-1];D[0]*=1-c}for(let Z=0;Z<e.length;++Z)D[Z]*=e[Z];G.realTransform(X,D);for(let Z=0;Z<F;++Z){let Ie=Z<<1;V[Z*B+v]=X[Ie]**2+X[Ie+1]**2}}if(o!==null&&o!==2){let v=o/2;for(let I=0;I<V.length;++I)V[I]**=v}let re=p.length,Y=await Rw(new S("float32",p.flat(),[re,F]),new S("float32",V,[F,B]));A&&(Y=Y.transpose(1,0));let k=Y.data;for(let v=0;v<k.length;++v)k[v]=b+Math.max(d,k[v]);if(o!==null&&_!==null){let v=Math.min(k.length,R*re);switch(_){case"log":for(let I=0;I<v;++I)k[I]=Math.log(k[I]);break;case"log10":for(let I=0;I<v;++I)k[I]=Math.log10(k[I]);break;case"dB":if(o===1)Kk(k,m,h,x);else if(o===2)Qk(k,m,h,x);else throw new Error(`Cannot use log_mel option '${_}' with power ${o}`);break;default:throw new Error(`log_mel must be one of null, 'log', 'log10' or 'dB'. Got '${_}'`)}}return Y}function Be(t,e,{periodic:s=!0,frame_length:r=null,center:n=!0}={}){let o=s?t+1:t,i;switch(e){case"boxcar":i=new Float64Array(o).fill(1);break;case"hann":case"hann_window":i=Xw(o);break;case"hamming":i=qk(o);break;case"povey":i=Xw(o).map(a=>Math.pow(a,.85));break;default:throw new Error(`Unknown window type ${e}.`)}if(s&&(i=i.subarray(0,t)),r===null)return i;if(t>r)throw new Error(`Length of the window (${t}) may not be larger than frame_length (${r})`);return i}function Jk(t,e){let s=t.reduce((o,i)=>o+i.length,0),r=new ArrayBuffer(44),n=new DataView(r);return ni(n,0,"RIFF"),n.setUint32(4,36+s*4,!0),ni(n,8,"WAVE"),ni(n,12,"fmt "),n.setUint32(16,16,!0),n.setUint16(20,3,!0),n.setUint16(22,1,!0),n.setUint32(24,e,!0),n.setUint32(28,e*4,!0),n.setUint16(32,4,!0),n.setUint16(34,32,!0),ni(n,36,"data"),n.setUint32(40,s*4,!0),new Blob([r,...t.map(o=>o.buffer)],{type:"audio/wav"})}function ni(t,e,s){for(let r=0;r<s.length;++r)t.setUint8(e+r,s.charCodeAt(r))}var hr=class{constructor(e,s){this.audio=e,this.sampling_rate=s}get data(){if(Array.isArray(this.audio)){if(this.audio.length===0)return new Float32Array(0);if(this.audio.length===1)return this.audio[0];let e=this.audio.reduce((n,o)=>n+o.length,0),s=new Float32Array(e),r=0;for(let n of this.audio)s.set(n,r),r+=n.length;return s}else return this.audio}toBlob(){let e=this.audio;return e instanceof Float32Array&&(e=[e]),Jk(e,this.sampling_rate)}async save(e){return ri(e,this.toBlob())}};var Yc=class extends pe{constructor(e){super(e);let s=this.config.sampling_rate,r=Re(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Be(400,"hann",{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,s){return je(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:s,transpose:!0})}async _call(e){ge(e,"ASTFeatureExtractor");let s=await this._extract_fbank_features(e,this.config.max_length);if(this.config.do_normalize){let r=this.std*2,n=s.data;for(let o=0;o<n.length;++o)n[o]=(n[o]-this.mean)/r}return{input_values:s.unsqueeze_(0)}}};var xr=class extends pe{async _call(e){ge(e,"EncodecFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=this.config.feature_size;if(e.length%s!==0)throw new Error(`The length of the audio data must be a multiple of the number of channels (${s}).`);let r=[1,s,e.length/s];return{input_values:new S("float32",e,r)}}};var Zc=class extends pe{async _call(e){ge(e,"ChatterboxFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,e.length];return{input_values:new S("float32",e,s)}}};var eu=class extends pe{constructor(e){super(e),this.mel_filters=Re(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,null,"htk"),this.mel_filters_slaney=Re(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,"slaney","slaney"),this.window=Be(this.config.fft_window_size,"hann")}async _get_input_mel(e,s,r,n){let o,i=!1,a=e.length-s;if(a>0)if(r==="rand_trunc"){i=!0;let l=Math.floor(Math.random()*(a+1));e=e.subarray(l,l+s),o=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}else throw new Error(`Truncation strategy "${r}" not implemented`);else{if(a<0){let l=new Float64Array(s);if(l.set(e),n==="repeat")for(let c=e.length;c<s;c+=e.length)l.set(e.subarray(0,Math.min(e.length,s-c)),c);else if(n==="repeatpad")for(let c=e.length;c<-a;c+=e.length)l.set(e,c);e=l}if(r==="fusion")throw new Error(`Truncation strategy "${r}" not implemented`);o=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}return o.unsqueeze_(0)}async _extract_fbank_features(e,s,r=null){return je(e,this.window,this.config.fft_window_size,this.config.hop_length,{power:2,mel_filters:s,log_mel:"dB",max_num_frames:r,do_pad:!1,transpose:!0})}async _call(e,{max_length:s=null}={}){return ge(e,"ClapFeatureExtractor"),{input_features:(await this._get_input_mel(e,s??this.config.nb_max_samples,this.config.truncation,this.config.padding)).unsqueeze_(0)}}};var gr=class extends xr{};var tu=class extends pe{constructor(e){super(e);let{fft_length:s,feature_size:r,min_frequency:n,max_frequency:o,sampling_rate:i,frame_length:a}=this.config,l=Re(Math.floor(1+s/2),r,n,o,i,null,"htk",!1);this.mel_filters=l,this.window=Be(a,"hann")}async _extract_fbank_features(e,s){return je(e,this.window,this.config.frame_length,this.config.hop_length,{fft_length:this.config.fft_length,center:!1,onesided:!0,preemphasis:this.config.preemphasis,preemphasis_htk_flavor:this.config.preemphasis_htk_flavor,mel_filters:this.mel_filters,log_mel:"log",mel_floor:this.config.mel_floor,remove_dc_offset:!1,transpose:!0})}async _call(e,{max_length:s=48e4,truncation:r=!0,padding:n=!0,pad_to_multiple_of:o=128}={}){if(ge(e,"Gemma3nAudioFeatureExtractor"),r&&e.length>s&&(e=e.slice(0,s)),n&&e.length%o!==0){let l=o-e.length%o,c=new Float64Array(e.length+l);c.set(e),this.config.padding_value!==0&&c.fill(this.config.padding_value,e.length),e=c}let i=await this._extract_fbank_features(e,this.config.max_length),a=xe([1,i.dims[0]],!0);return{input_features:i.unsqueeze_(0),input_features_mask:a}}};var su=class extends pe{async _call(e){ge(e,"MoonshineFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,e.length];return{input_values:new S("float32",e,s)}}};var Yk=1e-5,ru=class extends pe{constructor(e){super(e),this.config.mel_filters??=Re(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,this.config.sampling_rate/2,this.config.sampling_rate,"slaney","slaney");let s=Be(this.config.win_length,"hann",{periodic:!1});this.window=new Float64Array(this.config.n_fft);let r=Math.floor((this.config.n_fft-this.config.win_length)/2);this.window.set(s,r)}async _extract_fbank_features(e){let s=this.config.preemphasis;e=new Float64Array(e);for(let n=e.length-1;n>=1;--n)e[n]-=s*e[n-1];return await je(e,this.window,this.window.length,this.config.hop_length,{fft_length:this.config.n_fft,power:2,mel_filters:this.config.mel_filters,log_mel:"log",mel_floor:-1/0,pad_mode:"constant",center:!0,transpose:!0,mel_offset:2**-24})}async _call(e){ge(e,"ParakeetFeatureExtractor");let s=await this._extract_fbank_features(e),r=Math.floor((e.length+Math.floor(this.config.n_fft/2)*2-this.config.n_fft)/this.config.hop_length),n=s.data;n.fill(0,r*s.dims[1]);let[o,i]=s.dims,a=new Float64Array(i),l=new Float64Array(i);for(let p=0;p<r;++p){let d=p*i;for(let _=0;_<i;++_){let m=n[d+_];a[_]+=m,l[_]+=m*m}}let c=r>1?r-1:1;for(let p=0;p<i;++p){let d=a[p]/r,_=(l[p]-r*d*d)/c,h=1/(Math.sqrt(_)+Yk);for(let x=0;x<r;++x){let g=x*i+p;n[g]=(n[g]-d)*h}}let u=new BigInt64Array(o);return u.fill(1n,0,r),{input_features:s.unsqueeze_(0),attention_mask:new S("int64",u,[1,o])}}};var wr=class extends pe{async _call(e){ge(e,"PyAnnoteFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,1,e.length];return{input_values:new S("float32",e,s)}}samples_to_frames(e){return(e-this.config.offset)/this.config.step}post_process_speaker_diarization(e,s){let r=s/this.samples_to_frames(s)/this.config.sampling_rate,n=[];for(let o of e.tolist()){let i=[],a=-1;for(let l=0;l<o.length;++l){let c=ce(o[l]),[u,p]=ie(c),[d,_]=[l,l+1];p!==a?(a=p,i.push({id:p,start:d,end:_,score:u})):(i.at(-1).end=_,i.at(-1).score+=u)}n.push(i.map(({id:l,start:c,end:u,score:p})=>({id:l,start:c*r,end:u*r,confidence:p/(u-c)})))}return n}};var nu=class extends pe{constructor(e){super(e);let s=this.config.sampling_rate,r=Re(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Be(400,"povey",{periodic:!1})}async _extract_fbank_features(e,s){return e=e.map(r=>r*32768),je(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:s,transpose:!0})}async _call(e,{padding:s=!0,pad_to_multiple_of:r=2,do_normalize_per_mel_bins:n=!0,return_attention_mask:o=!0}={}){ge(e,"SeamlessM4TFeatureExtractor");let i=await this._extract_fbank_features(e,this.config.max_length);if(n){let[m,h]=i.dims,x=i.data;for(let g=0;g<h;++g){let w=0;for(let b=0;b<m;++b)w+=x[b*h+g];let y=w/m,E=0;for(let b=0;b<m;++b)E+=(x[b*h+g]-y)**2;E/=m-1;let A=Math.sqrt(E+1e-7);for(let b=0;b<m;++b){let O=b*h+g;x[O]=(x[O]-y)/A}}}let a;if(s){let[m,h]=i.dims,x=i.data,g=m%r;if(g>0){let w=new Float32Array(h*(m+g));w.set(x),w.fill(this.config.padding_value,x.length);let y=m+g;i=new S(i.type,w,[y,h]),o&&(a=new S("int64",new BigInt64Array(y),[1,y]),a.data.fill(1n,0,m))}}let[l,c]=i.dims,u=this.config.stride;if(l%u!==0)throw new Error(`The number of frames (${l}) must be a multiple of the stride (${u}).`);let d=i.view(1,Math.floor(l/u),c*u),_={input_features:d};if(o){let m=d.dims[1],h=new BigInt64Array(m);if(a){let x=a.data;for(let g=1,w=0;g<l;g+=u,++w)h[w]=x[g]}else h.fill(1n);_.attention_mask=new S("int64",h,[1,m])}return _}};var ou=class extends gr{};var iu=class extends pe{};var au=class extends pe{_zero_mean_unit_var_norm(e){let r=e.reduce((o,i)=>o+i,0)/e.length,n=e.reduce((o,i)=>o+(i-r)**2,0)/e.length;return e.map(o=>(o-r)/Math.sqrt(n+1e-7))}async _call(e){ge(e,"Wav2Vec2FeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=e;this.config.do_normalize&&(s=this._zero_mean_unit_var_norm(s));let r=[1,s.length];return{input_values:new S("float32",s,r),attention_mask:new S("int64",new BigInt64Array(s.length).fill(1n),r)}}};var lu=class extends pe{constructor(e){super(e);let s=this.config.sampling_rate,r=Re(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Be(400,"hamming",{periodic:!1}),this.min_num_frames=this.config.min_num_frames}async _extract_fbank_features(e){return e=e.map(s=>s*32768),je(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,transpose:!0,min_num_frames:this.min_num_frames})}async _call(e){ge(e,"WeSpeakerFeatureExtractor");let s=(await this._extract_fbank_features(e)).unsqueeze_(0);if(this.config.fbank_centering_span===null){let r=s.mean(1).data,n=s.data,[o,i,a]=s.dims;for(let l=0;l<o;++l){let c=l*i*a,u=l*a;for(let p=0;p<i;++p){let d=c+p*a;for(let _=0;_<a;++_)n[d+_]-=r[u+_]}}}return{input_features:s}}};var cu=class extends pe{constructor(e){super(e),this.config.mel_filters??=Re(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=Be(this.config.n_fft,"hann")}async _extract_fbank_features(e){let s=await je(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:Math.min(Math.floor(e.length/this.config.hop_length),this.config.nb_max_frames)}),r=s.data,n=ie(r)[0];for(let o=0;o<r.length;++o)r[o]=(Math.max(r[o],n-8)+4)/4;return s}async _call(e,{max_length:s=null}={}){ge(e,"WhisperFeatureExtractor");let r,n=s??this.config.n_samples;return e.length>n?(e.length>this.config.n_samples&&console.warn("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`."),r=e.slice(0,n)):(r=new Float32Array(n),r.set(e)),{input_features:(await this._extract_fbank_features(r)).unsqueeze_(0)}}};var ve=class{static async from_pretrained(e,s={}){let r=await Se(e,mr,!0,s),n=r.feature_extractor_type,o=yr[n];if(!o)throw new Error(`Unknown feature_extractor_type: '${n}'. Please report this at ${bs}.`);return new o(r)}};var uu=class extends j{static tokenizer_class=L;static feature_extractor_class=ve;async _call(e,s=null){let r=this.tokenizer(e),n=s?await this.feature_extractor(s):{};return{...r,...n}}};var Zk={},oi=Zk;var Jt,Yw,Mt,it=ee.IS_BROWSER_ENV||ee.IS_WEBWORKER_ENV;if(it)Jt=(t,e)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(t,e)},Mt=self.createImageBitmap,Yw=self.ImageData;else if(oi)Mt=async t=>{let s=(await t.metadata()).channels,{data:r,info:n}=await t.rotate().raw().toBuffer({resolveWithObject:!0}),o=new we(new Uint8ClampedArray(r),n.width,n.height,n.channels);return s!==void 0&&s!==n.channels&&o.convert(s),o};else throw new Error("Unable to load image processing library.");var ev={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},tv=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]),we=class t{constructor(e,s,r,n){this.data=e,this.width=s,this.height=r,this.channels=n}get size(){return[this.width,this.height]}static async read(e){if(e instanceof t)return e;if(typeof e=="string"||e instanceof URL)return await this.fromURL(e);if(e instanceof Blob)return await this.fromBlob(e);if(typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)return this.fromCanvas(e);throw new Error(`Unsupported input type: ${typeof e}`)}static fromCanvas(e){if(!it)throw new Error("fromCanvas() is only supported in browser environments.");let r=e.getContext("2d").getImageData(0,0,e.width,e.height).data;return new t(r,e.width,e.height,4)}static async fromURL(e){let s=await hs(e);if(s.status!==200)throw new Error(`Unable to read image from "${e}" (${s.status} ${s.statusText})`);let r=await s.blob();return this.fromBlob(r)}static async fromBlob(e){if(it){let s=await Mt(e),r=Jt(s.width,s.height).getContext("2d");return r.drawImage(s,0,0),new this(r.getImageData(0,0,s.width,s.height).data,s.width,s.height,4)}else{let s=oi(await e.arrayBuffer());return await Mt(s)}}static fromTensor(e,s="CHW"){if(e.dims.length!==3)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if(s==="CHW")e=e.transpose(1,2,0);else if(s!=="HWC")throw new Error(`Unsupported channel format: ${s}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new t(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(this.channels===1)return this;let e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let s=0,r=0;s<this.data.length;s+=this.channels){let n=this.data[s],o=this.data[s+1],i=this.data[s+2];e[r++]=Math.round(.2989*n+.587*o+.114*i)}break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(this.channels===3)return this;let e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let s=0,r=0;s<this.data.length;++s)e[r++]=this.data[s],e[r++]=this.data[s],e[r++]=this.data[s];break;case 4:for(let s=0,r=0;s<this.data.length;s+=4)e[r++]=this.data[s],e[r++]=this.data[s+1],e[r++]=this.data[s+2];break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(this.channels===4)return this;let e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let s=0,r=0;s<this.data.length;++s)e[r++]=this.data[s],e[r++]=this.data[s],e[r++]=this.data[s],e[r++]=255;break;case 3:for(let s=0,r=0;s<this.data.length;s+=3)e[r++]=this.data[s],e[r++]=this.data[s+1],e[r++]=this.data[s+2],e[r++]=255;break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}putAlpha(e){if(e.width!==this.width||e.height!==this.height)throw new Error(`Expected mask size to be ${this.width}x${this.height}, but got ${e.width}x${e.height}`);if(e.channels!==1)throw new Error(`Expected mask to have 1 channel, but got ${e.channels}`);let s=this.data,r=e.data,n=this.width*this.height;if(this.channels===3){let o=new Uint8ClampedArray(n*4);for(let i=0,a=0,l=0;i<n;++i)o[l++]=s[a++],o[l++]=s[a++],o[l++]=s[a++],o[l++]=r[i];return this._update(o,this.width,this.height,4)}else if(this.channels===4){for(let o=0;o<n;++o)s[4*o+3]=r[o];return this}throw new Error(`Expected image to have 3 or 4 channels, but got ${this.channels}`)}async resize(e,s,{resample:r=2}={}){if(this.width===e&&this.height===s)return this;let n=ev[r]??r,o=jl(e),i=jl(s);if(o&&i)return this;if(o?e=s/this.height*this.width:i&&(s=e/this.width*this.height),it){let a=this.channels,l=this.toCanvas(),c=Jt(e,s).getContext("2d");return c.drawImage(l,0,0,e,s),new t(c.getImageData(0,0,e,s).data,e,s,4).convert(a)}else{let a=this.toSharp();switch(n){case"box":case"hamming":(n==="box"||n==="hamming")&&(console.warn(`Resampling method ${n} is not yet supported. Using bilinear instead.`),n="bilinear");case"nearest":case"bilinear":case"bicubic":a=a.affine([e/this.width,0,0,s/this.height],{interpolator:n});break;case"lanczos":a=a.resize({width:e,height:s,fit:"fill",kernel:"lanczos3"});break;default:throw new Error(`Resampling method ${n} is not supported.`)}return await Mt(a)}}async pad([e,s,r,n]){if(e=Math.max(e,0),s=Math.max(s,0),r=Math.max(r,0),n=Math.max(n,0),e===0&&s===0&&r===0&&n===0)return this;if(it){let o=this.channels,i=this.toCanvas(),a=this.width+e+s,l=this.height+r+n,c=Jt(a,l).getContext("2d");return c.drawImage(i,0,0,this.width,this.height,e,r,this.width,this.height),new t(c.getImageData(0,0,a,l).data,a,l,4).convert(o)}else{let o=this.toSharp().extend({left:e,right:s,top:r,bottom:n});return await Mt(o)}}async crop([e,s,r,n]){if(e=Math.max(e,0),s=Math.max(s,0),r=Math.min(r,this.width-1),n=Math.min(n,this.height-1),e===0&&s===0&&r===this.width-1&&n===this.height-1)return this;let o=r-e+1,i=n-s+1;if(it){let a=this.channels,l=this.toCanvas(),c=Jt(o,i).getContext("2d");return c.drawImage(l,e,s,o,i,0,0,o,i),new t(c.getImageData(0,0,o,i).data,o,i,4).convert(a)}else{let a=this.toSharp().extract({left:e,top:s,width:o,height:i});return await Mt(a)}}async center_crop(e,s){if(this.width===e&&this.height===s)return this;let r=(this.width-e)/2,n=(this.height-s)/2;if(it){let o=this.channels,i=this.toCanvas(),a=Jt(e,s).getContext("2d"),l=0,c=0,u=0,p=0;return r>=0?l=r:u=-r,n>=0?c=n:p=-n,a.drawImage(i,l,c,e,s,u,p,e,s),new t(a.getImageData(0,0,e,s).data,e,s,4).convert(o)}else{let o=this.toSharp();if(r>=0&&n>=0)o=o.extract({left:Math.floor(r),top:Math.floor(n),width:e,height:s});else if(r<=0&&n<=0){let i=Math.floor(-n),a=Math.floor(-r);o=o.extend({top:i,left:a,right:e-this.width-a,bottom:s-this.height-i})}else{let i=[0,0],a=0;n<0?(i[0]=Math.floor(-n),i[1]=s-this.height-i[0]):a=Math.floor(n);let l=[0,0],c=0;r<0?(l[0]=Math.floor(-r),l[1]=e-this.width-l[0]):c=Math.floor(r),o=o.extend({top:i[0],bottom:i[1],left:l[0],right:l[1]}).extract({left:c,top:a,width:e,height:s})}return await Mt(o)}}async toBlob(e="image/png",s=1){if(!it)throw new Error("toBlob() is only supported in browser environments.");return await this.toCanvas().convertToBlob({type:e,quality:s})}toTensor(e="CHW"){let s=new S("uint8",new Uint8Array(this.data),[this.height,this.width,this.channels]);if(e!=="HWC")if(e==="CHW")s=s.permute(2,0,1);else throw new Error(`Unsupported channel format: ${e}`);return s}toCanvas(){if(!it)throw new Error("toCanvas() is only supported in browser environments.");let e=this.clone().rgba(),s=Jt(e.width,e.height),r=new Yw(e.data,e.width,e.height);return s.getContext("2d").putImageData(r,0,0),s}split(){let{data:e,width:s,height:r,channels:n}=this,o=e.constructor,i=e.length/n,a=Array.from({length:n},()=>new o(i));for(let l=0;l<i;++l){let c=n*l;for(let u=0;u<n;++u)a[u][l]=e[c+u]}return a.map(l=>new t(l,s,r,1))}_update(e,s,r,n=null){return this.data=e,this.width=s,this.height=r,n!==null&&(this.channels=n),this}clone(){return new t(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(it){if(ee.IS_WEBWORKER_ENV)throw new Error("Unable to save an image from a Web Worker.");let s=e.split(".").pop().toLowerCase(),r=tv.get(s)??"image/png",n=await this.toBlob(r);return ri(e,n)}else if(ee.IS_FS_AVAILABLE)await this.toSharp().toFile(e);else throw new Error("Unable to save the image because filesystem is disabled in this environment.")}toSharp(){if(it)throw new Error("toSharp() is only supported in server-side environments.");return oi(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}},sv=we.read.bind(we);function Zw(t,e,s=0,r=null){let n=t/e,o=yw(n)*e;return r!==null&&o>r&&(o=Math.floor(n)*e),o<s&&(o=Math.ceil(n)*e),o}function pu([t,e],s){return[Math.max(Math.floor(t/s),1)*s,Math.max(Math.floor(e/s),1)*s]}function du([t,e,s,r]){return[t-s/2,e-r/2,t+s/2,e+r/2]}function St(t,e=.5,s=null,r=!1){let n=t.logits,o=t.pred_boxes,[i,a,l]=n.dims;if(s!==null&&s.length!==i)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let c=[];for(let u=0;u<i;++u){let p=s!==null?s[u]:null,d={boxes:[],classes:[],scores:[]},_=n[u],m=o[u];for(let h=0;h<a;++h){let x=_[h],g=[],w;if(r){w=x.sigmoid().data;for(let y=0;y<w.length;++y)w[y]>e&&g.push(y)}else{let y=ie(x.data)[1];if(y===l-1||(w=ce(x.data),w[y]<e))continue;g.push(y)}for(let y of g){let E=m[h].data;E=du(E),p!==null&&(E=E.map((A,b)=>A*p[(b+1)%2])),d.boxes.push(E),d.classes.push(y),d.scores.push(w[y])}}c.push(d)}return c}function ii(t,e=null){let s=t.logits,r=s.dims[0];if(e!==null&&e.length!==r)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let n=[];for(let o=0;o<r;++o){let i=e!==null?e[o]:null,a=s[o];i!==null&&(a=Yl(a,i,"bilinear",!1));let[l,c]=i??a.dims.slice(-2),u=new S("int32",new Int32Array(l*c),[l,c]),p=a[0].data,d=u.data;for(let h=1;h<a.dims[0];++h){let x=a[h].data;for(let g=0;g<x.length;++g)x[g]>p[g]&&(p[g]=x[g],d[g]=h)}let _=new Array(a.dims[0]);for(let h=0;h<d.length;++h){let x=d[h];_[x]=x}let m=_.filter(h=>h!==void 0);n.push({segmentation:u,labels:m})}return n}function rv(t,e,s,r){let n=[],o=[],i=[];for(let a=0;a<t.dims[0];++a){let l=t[a],c=e[a],u=ie(l.data)[1];if(u===r)continue;let d=ce(l.data)[u];d>s&&(n.push(c),o.push(d),i.push(u))}return[n,o,i]}function nv(t,e,s,r=.5,n=.8){let o=[],i=0,a=0,l=e[s].data;for(let u=0;u<t.length;++u)t[u]===s&&(o.push(u),++i),l[u]>=r&&++a;let c=i>0&&a>0;return c&&(c=i/a>n),[c,o]}function ov(t,e,s,r,n,o=null,i=null){let[a,l]=i??t[0].dims,c=new S("int32",new Int32Array(a*l),[a,l]),u=[];if(i!==null)for(let h=0;h<t.length;++h)t[h]=Yl(t[h],i,"bilinear",!1);let p=new Int32Array(t[0].data.length),d=new Float32Array(t[0].data.length);for(let h=0;h<t.length;++h){let x=e[h],g=t[h].data;for(let w=0;w<g.length;++w)g[w]*=x,g[w]>d[w]&&(p[w]=h,d[w]=g[w])}let _=0,m=c.data;for(let h=0;h<s.length;++h){let x=s[h],[g,w]=nv(p,t,h,r,n);if(g){++_;for(let y of w)m[y]=_;u.push({id:_,label_id:x,score:e[h]})}}return[c,u]}function iv(t,e,s=28,r=3136,n=784*1280){if(t<s||e<s)throw new Error(`height:${t} or width:${e} must be larger than factor:${s}`);if(Math.max(t,e)/Math.min(t,e)>200)throw new Error(`absolute aspect ratio must be smaller than 200, got ${Math.max(t,e)/Math.min(t,e)}`);let o=Math.round(t/s)*s,i=Math.round(e/s)*s;if(o*i>n){let a=Math.sqrt(t*e/n);o=Math.floor(t/a/s)*s,i=Math.floor(e/a/s)*s}else if(o*i<r){let a=Math.sqrt(r/(t*e));o=Math.ceil(t*a/s)*s,i=Math.ceil(e*a/s)*s}return[o,i]}function ai(t,e=.5,s=.5,r=.8,n=null,o=null){n===null&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),n=new Set);let i=t.class_queries_logits??t.logits,l=(t.masks_queries_logits??t.pred_masks).sigmoid(),[c,u,p]=i.dims;if(p-=1,o!==null&&o.length!==c)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let d=[];for(let _=0;_<c;++_){let m=o!==null?o[_]:null,h=i[_],x=l[_],[g,w,y]=rv(h,x,e,p);if(y.length===0){let[b,O]=m??x.dims.slice(-2),N=new S("int32",new Int32Array(b*O).fill(-1),[b,O]);d.push({segmentation:N,segments_info:[]});continue}let[E,A]=ov(g,w,y,s,r,n,m);d.push({segmentation:E,segments_info:A})}return d}function li(t,e=.5,s=null){throw new Error("`post_process_instance_segmentation` is not yet implemented.")}var P=class extends ke{constructor(e){super(),this.image_mean=e.image_mean??e.mean,this.image_std=e.image_std??e.std,this.resample=e.resample??2,this.do_rescale=e.do_rescale??!0,this.rescale_factor=e.rescale_factor??1/255,this.do_normalize=e.do_normalize,this.do_thumbnail=e.do_thumbnail,this.size=e.size??e.image_size,this.do_resize=e.do_resize??this.size!==void 0,this.size_divisibility=e.size_divisibility??e.size_divisor,this.do_center_crop=e.do_center_crop,this.crop_size=e.crop_size,this.do_convert_rgb=e.do_convert_rgb??!0,this.do_crop_margin=e.do_crop_margin,this.pad_size=e.pad_size,this.do_pad=e.do_pad,this.min_pixels=e.min_pixels,this.max_pixels=e.max_pixels,this.do_pad&&!this.pad_size&&this.size&&this.size.width!==void 0&&this.size.height!==void 0&&(this.pad_size=this.size),this.do_flip_channel_order=e.do_flip_channel_order??!1,this.config=e}async thumbnail(e,s,r=2){let n=e.height,o=e.width,i=s.height,a=s.width,l=Math.min(n,i),c=Math.min(o,a);return l===n&&c===o?e:(n>o?c=Math.floor(o*l/n):o>n&&(l=Math.floor(n*c/o)),await e.resize(c,l,{resample:r}))}async crop_margin(e,s=200){let r=e.clone().grayscale(),n=cr(r.data)[0],i=ie(r.data)[0]-n;if(i===0)return e;let a=s/255,l=r.width,c=r.height,u=0,p=0,d=r.data;for(let _=0;_<r.height;++_){let m=_*r.width;for(let h=0;h<r.width;++h)(d[m+h]-n)/i<a&&(l=Math.min(l,h),c=Math.min(c,_),u=Math.max(u,h),p=Math.max(p,_))}return e=await e.crop([l,c,u,p]),e}pad_image(e,s,r,{mode:n="constant",center:o=!1,constant_values:i=0}={}){let[a,l,c]=s,u,p;if(typeof r=="number"?(u=r,p=r):r==="square"?u=p=Math.max(a,l):(u=r.width,p=r.height),u!==l||p!==a){let d=new Float32Array(u*p*c);if(Array.isArray(i))for(let h=0;h<d.length;++h)d[h]=i[h%c];else i!==0&&d.fill(i);let[_,m]=o?[Math.floor((u-l)/2),Math.floor((p-a)/2)]:[0,0];for(let h=0;h<a;++h){let x=(h+m)*u,g=h*l;for(let w=0;w<l;++w){let y=(x+w+_)*c,E=(g+w)*c;for(let A=0;A<c;++A)d[y+A]=e[E+A]}}if(n==="symmetric"){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");let h=a-1,x=l-1;for(let g=0;g<p;++g){let w=g*u,y=_s(g,h)*l;for(let E=0;E<u;++E){if(g<a&&E<l)continue;let A=(w+E)*c,b=(y+_s(E,x))*c;for(let O=0;O<c;++O)d[A+O]=e[b+O]}}}e=d,s=[p,u,c]}return[e,s]}rescale(e){for(let s=0;s<e.length;++s)e[s]=this.rescale_factor*e[s]}get_resize_output_image_size(e,s){let[r,n]=e.size,o,i;if(this.do_thumbnail){let{height:a,width:l}=s;o=Math.min(a,l)}else Number.isInteger(s)?(o=s,i=this.config.max_size??o):s!==void 0&&(o=s.shortest_edge,i=s.longest_edge);if(o!==void 0||i!==void 0){let a=o===void 0?1:Math.max(o/r,o/n),l=r*a,c=n*a,u=i===void 0?1:Math.min(i/l,i/c),p=Math.floor(Number((l*u).toFixed(2))),d=Math.floor(Number((c*u).toFixed(2)));return this.size_divisibility!==void 0&&([p,d]=pu([p,d],this.size_divisibility)),[p,d]}else if(s!==void 0&&s.width!==void 0&&s.height!==void 0){let a=s.width,l=s.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let c=l/n,u=a/r;Math.abs(1-u)<Math.abs(1-c)?c=u:u=c,l=Zw(c*n,this.config.ensure_multiple_of),a=Zw(u*r,this.config.ensure_multiple_of)}return[a,l]}else{if(this.size_divisibility!==void 0)return pu([r,n],this.size_divisibility);if(this.min_pixels!==void 0&&this.max_pixels!==void 0){let a=this.config.patch_size*this.config.merge_size;return iv(n,r,a,this.min_pixels,this.max_pixels)}else throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(s)}`)}}async resize(e){let[s,r]=this.get_resize_output_image_size(e,this.size);return await e.resize(s,r,{resample:this.resample})}async preprocess(e,{do_normalize:s=null,do_pad:r=null,do_convert_rgb:n=null,do_convert_grayscale:o=null,do_flip_channel_order:i=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));let[a,l]=e.size;if(n??this.do_convert_rgb?e=e.rgb():o&&(e=e.grayscale()),this.do_resize&&(e=await this.resize(e)),this.do_thumbnail&&(e=await this.thumbnail(e,this.size,this.resample)),this.do_center_crop){let _,m;Number.isInteger(this.crop_size)?(_=this.crop_size,m=this.crop_size):(_=this.crop_size.width,m=this.crop_size.height),e=await e.center_crop(_,m)}let c=[e.height,e.width],u=Float32Array.from(e.data),p=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(u),s??this.do_normalize){let _=this.image_mean;Array.isArray(this.image_mean)||(_=new Array(e.channels).fill(_));let m=this.image_std;if(Array.isArray(this.image_std)||(m=new Array(e.channels).fill(m)),_.length!==e.channels||m.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${_.length}) and \`image_std\` (${m.length}) must match the number of channels in the image (${e.channels}).`);for(let h=0;h<u.length;h+=e.channels)for(let x=0;x<e.channels;++x)u[h+x]=(u[h+x]-_[x])/m[x]}if(r??this.do_pad){if(this.pad_size)[u,p]=this.pad_image(u,[e.height,e.width,e.channels],this.pad_size);else if(this.size_divisibility){let[_,m]=pu([p[1],p[0]],this.size_divisibility);[u,p]=this.pad_image(u,p,{width:_,height:m})}}if(i??this.do_flip_channel_order){if(p[2]!==3)throw new Error("Flipping channel order is only supported for RGB images.");for(let _=0;_<u.length;_+=3){let m=u[_];u[_]=u[_+2],u[_+2]=m}}let d=new S("float32",u,p).permute(2,0,1);return{original_size:[l,a],reshaped_input_size:c,pixel_values:d}}async _call(e,...s){Array.isArray(e)||(e=[e]);let r=await Promise.all(e.map(o=>this.preprocess(o)));return{pixel_values:Ke(r.map(o=>o.pixel_values),0),original_sizes:r.map(o=>o.original_size),reshaped_input_sizes:r.map(o=>o.reshaped_input_size)}}static async from_pretrained(e,s={}){let r=await Se(e,ks,!0,s);return new this(r)}};var Ss={};us(Ss,{BeitFeatureExtractor:()=>_u,BitImageProcessor:()=>fu,CLIPFeatureExtractor:()=>hu,CLIPImageProcessor:()=>ci,ChineseCLIPFeatureExtractor:()=>mu,ConvNextFeatureExtractor:()=>xu,ConvNextImageProcessor:()=>ui,DINOv3ViTImageProcessor:()=>yu,DPTFeatureExtractor:()=>ku,DPTImageProcessor:()=>_i,DeiTFeatureExtractor:()=>gu,DeiTImageProcessor:()=>pi,DetrFeatureExtractor:()=>wu,DetrImageProcessor:()=>di,DonutFeatureExtractor:()=>bu,DonutImageProcessor:()=>vs,EfficientNetImageProcessor:()=>vu,GLPNFeatureExtractor:()=>Eu,GroundingDinoImageProcessor:()=>Au,Idefics3ImageProcessor:()=>fi,ImageFeatureExtractor:()=>P,ImageProcessor:()=>P,JinaCLIPImageProcessor:()=>Su,LlavaOnevisionImageProcessor:()=>Ou,Mask2FormerImageProcessor:()=>zu,MaskFormerFeatureExtractor:()=>Iu,MaskFormerImageProcessor:()=>Es,MobileNetV1FeatureExtractor:()=>Tu,MobileNetV1ImageProcessor:()=>mi,MobileNetV2FeatureExtractor:()=>Pu,MobileNetV2ImageProcessor:()=>hi,MobileNetV3FeatureExtractor:()=>Cu,MobileNetV3ImageProcessor:()=>xi,MobileNetV4FeatureExtractor:()=>Nu,MobileNetV4ImageProcessor:()=>gi,MobileViTFeatureExtractor:()=>Lu,MobileViTImageProcessor:()=>wi,NougatImageProcessor:()=>$u,OwlViTFeatureExtractor:()=>Ru,OwlViTImageProcessor:()=>As,Owlv2ImageProcessor:()=>Fu,Phi3VImageProcessor:()=>Bu,PixtralImageProcessor:()=>Uu,PvtImageProcessor:()=>qu,Qwen2VLImageProcessor:()=>Gu,RTDetrImageProcessor:()=>Wu,Sam2ImageProcessor:()=>br,Sam3ImageProcessor:()=>br,SamImageProcessor:()=>br,SapiensFeatureExtractor:()=>Vu,SapiensImageProcessor:()=>yi,SegformerFeatureExtractor:()=>Hu,SegformerImageProcessor:()=>bi,SiglipImageProcessor:()=>Xu,SmolVLMImageProcessor:()=>fi,Swin2SRImageProcessor:()=>Ku,VLMImageProcessor:()=>Mu,ViTFeatureExtractor:()=>Qu,ViTImageProcessor:()=>ki,VitMatteImageProcessor:()=>Ju,VitPoseImageProcessor:()=>Yu,YolosFeatureExtractor:()=>Zu,YolosImageProcessor:()=>vi});var _u=class extends P{};var fu=class extends P{};var mu=class extends P{};var ci=class extends P{},hu=class extends ci{};var ui=class extends P{constructor(e){super(e),this.crop_pct=this.config.crop_pct??224/256}async resize(e){let s=this.size?.shortest_edge;if(s===void 0)throw new Error("Size dictionary must contain 'shortest_edge' key.");if(s<384){let r=Math.floor(s/this.crop_pct),[n,o]=this.get_resize_output_image_size(e,{shortest_edge:r});e=await e.resize(n,o,{resample:this.resample}),e=await e.center_crop(s,s)}else e=await e.resize(s,s,{resample:this.resample});return e}},xu=class extends ui{};var pi=class extends P{},gu=class extends pi{};var di=class extends P{async _call(e){let s=await super._call(e),r=[s.pixel_values.dims[0],64,64],n=xe(r,1n);return{...s,pixel_mask:n}}post_process_object_detection(...e){return St(...e)}post_process_panoptic_segmentation(...e){return ai(...e)}post_process_instance_segmentation(...e){return li(...e)}},wu=class extends di{};var yu=class extends P{};var vs=class extends P{pad_image(e,s,r,n={}){let[o,i,a]=s,l=this.image_mean;Array.isArray(this.image_mean)||(l=new Array(a).fill(l));let c=this.image_std;Array.isArray(c)||(c=new Array(a).fill(l));let u=l.map((p,d)=>-p/c[d]);return super.pad_image(e,s,r,{center:!0,constant_values:u,...n})}},bu=class extends vs{};var _i=class extends P{},ku=class extends _i{};var vu=class extends P{constructor(e){super(e),this.include_top=this.config.include_top??!0,this.include_top&&(this.image_std=this.image_std.map(s=>s*s))}};var Eu=class extends P{};var Au=class extends P{async _call(e){let s=await super._call(e),r=s.pixel_values.dims,n=Oe([r[0],r[2],r[3]]);return{...s,pixel_mask:n}}};var fi=class extends P{constructor(e){super(e),this.do_image_splitting=e.do_image_splitting??!0,this.max_image_size=e.max_image_size}get_resize_for_vision_encoder(e,s){let[r,n]=e.dims.slice(-2),o=n/r;return n>=r?(n=Math.ceil(n/s)*s,r=Math.floor(n/o),r=Math.ceil(r/s)*s):(r=Math.ceil(r/s)*s,n=Math.floor(r*o),n=Math.ceil(n/s)*s),{height:r,width:n}}async _call(e,{do_image_splitting:s=null,return_row_col_info:r=!1}={}){let n;if(!Array.isArray(e))n=[[e]];else{if(e.length===0||!e[0])throw new Error("No images provided.");Array.isArray(e[0])?n=e:n=[e]}let o=[],i=[],a=[],l=[],c=[];for(let g of n){let w=await Promise.all(g.map(A=>this.preprocess(A)));l.push(...w.map(A=>A.original_size)),c.push(...w.map(A=>A.reshaped_input_size)),w.forEach(A=>A.pixel_values.unsqueeze_(0));let{longest_edge:y}=this.max_image_size,E;if(s??this.do_image_splitting){let A=new Array(w.length),b=new Array(w.length);E=await Promise.all(w.map(async(O,N)=>{let F=this.get_resize_for_vision_encoder(O.pixel_values,y),R=await Xe(O.pixel_values,{size:[F.height,F.width]}),{frames:B,num_splits_h:G,num_splits_w:D}=await this.split_image(R,this.max_image_size);return A[N]=G,b[N]=D,ne(B,0)})),i.push(A),a.push(b)}else{let A=[y,y];E=await Promise.all(w.map(b=>Xe(b.pixel_values,{size:A}))),i.push(new Array(w.length).fill(0)),a.push(new Array(w.length).fill(0))}o.push(ne(E,0))}let u=o.length,[p,d,_,m]=o[0].dims,h,x;if(u===1)h=o[0].unsqueeze_(0),x=xe([u,p,_,m],!0);else{let g=Math.max(...o.map(E=>E.dims.at(0)));x=xe([u,g,_,m],!0);let w=x.data,y=g*_*m;for(let E=0;E<u;++E){let A=o[E].dims[0];if(A<g){o[E]=ne([o[E],xe([g-A,d,_,m],0)],0);let b=E*y+A*_*m,O=(E+1)*y;w.fill(!1,b,O)}}h=Ke(o,0)}return{pixel_values:h,pixel_attention_mask:x,original_sizes:l,reshaped_input_sizes:c,...r?{rows:i,cols:a}:{}}}async split_image(e,{longest_edge:s}){let r=s,n=s,o=[],[i,a]=e.dims.slice(-2),l=0,c=0;if(i>r||a>n){l=Math.ceil(i/r),c=Math.ceil(a/n);let u=Math.ceil(i/l),p=Math.ceil(a/c);for(let m=0;m<l;++m)for(let h=0;h<c;++h){let x,g,w,y;m===l-1?(g=i-u,y=i):(g=m*u,y=(m+1)*u),h===c-1?(x=a-p,w=a):(x=h*p,w=(h+1)*p);let b=await ei(e,[g,x],[y,w],[2,3]);o.push(b)}let d=r,_=n;(i!==d||a!==_)&&(e=await Xe(e,{size:[d,_]}))}return o.push(e),{frames:o,num_splits_h:l,num_splits_w:c}}};var Mu=class extends P{constructor(e){super({do_pad:!0,pad_size:{width:e.image_size,height:e.image_size},...e}),this.constant_values=this.config.background_color.map(s=>s*this.rescale_factor)}pad_image(e,s,r,n){return super.pad_image(e,s,r,{constant_values:this.constant_values,center:!0,...n})}};var Su=class extends P{constructor(e){let{resize_mode:s,fill_color:r,interpolation:n,size:o,...i}=e,a=s==="squash"?{width:o,height:o}:s==="shortest"?{shortest_edge:o}:{longest_edge:o},l=n==="bicubic"?3:2;super({...i,size:a,resample:l,do_center_crop:!0,crop_size:o,do_normalize:!0})}};var Ou=class extends P{};var Es=class extends P{post_process_panoptic_segmentation(...e){return ai(...e)}post_process_instance_segmentation(...e){return li(...e)}},Iu=class extends Es{};var zu=class extends Es{};var mi=class extends P{},Tu=class extends mi{};var hi=class extends P{},Pu=class extends hi{};var xi=class extends P{},Cu=class extends xi{};var gi=class extends P{},Nu=class extends gi{};var wi=class extends P{},Lu=class extends wi{};var $u=class extends vs{};var As=class extends P{post_process_object_detection(...e){return St(...e)}},Ru=class extends As{};var Fu=class extends As{};var Ge=336,av=[2,3],{ceil:Du,floor:Ms,sqrt:ju}=Math,Bu=class extends P{constructor(e){super({...e,do_normalize:!0,do_pad:!0,pad_size:"custom",do_convert_rgb:!0,do_resize:!0}),this._num_crops=e.num_crops}calc_num_image_tokens_from_image_size(e,s){let{num_img_tokens:r}=this.config;return Ms((Ms(s/Ge)*Ms(e/Ge)+1)*r+1+(Ms(s/Ge)+1)*ju(r))}get_resize_output_image_size(e,s){let r=this._num_crops,[n,o]=e.size,i=n/o,a=1;for(;a*Math.ceil(a/i)<=r;)a+=1;a-=1;let l=Math.floor(a*336),c=Math.floor(l/i);return[l,c]}pad_image(e,s,r,n={}){let[o,i]=s,a=Ge*Du(o/Ge),l=Ge*Du(i/Ge),c=[1,1,1].map((u,p)=>(u-this.image_mean[p])/this.image_std[p]);return super.pad_image(e,s,{width:l,height:a},{center:!0,constant_values:c,...n})}async _call(e,{num_crops:s=null}={}){if(this._num_crops=s??=this.config.num_crops,s<4||ju(s)%1!==0)throw new Error("num_crops must be a square number >= 4");Array.isArray(e)||(e=[e]);let r=e.length,n=await Promise.all(e.map(d=>this.preprocess(d))),o=n.map(d=>d.original_size),i=n.map(d=>d.reshaped_input_size),a=[];for(let{pixel_values:d}of n){d.unsqueeze_(0);let[_,m]=d.dims.slice(-2),h=await Xe(d,{size:[Ge,Ge],mode:"bicubic"});if(s>0){let x=[],g=ju(s),w=Ms(m/g),y=Ms(_/g);for(let A=0;A<g;++A)for(let b=0;b<g;++b){let O,N,F,R;A===g-1?(N=_-y,R=_):(N=A*y,R=(A+1)*y),b===g-1?(O=m-w,F=m):(O=b*w,F=(b+1)*w);let D=await ei(d,[N,O],[R,F],av);x.push(D)}let E=await Xe(ne(x,0),{size:[Ge,Ge],mode:"bicubic"});a.push(ne([h,E],0))}else a.push(h)}let l=Ke(a,0),c=i.map(d=>d.map(_=>Ge*Du(_/Ge))),u=new S("int64",c.flat(),[r,2]),p=c.map(([d,_])=>this.calc_num_image_tokens_from_image_size(_,d));return{pixel_values:l,original_sizes:o,reshaped_input_sizes:i,image_sizes:u,num_img_tokens:p}}};var Uu=class extends P{get_resize_output_image_size(e,s){let{longest_edge:r}=s;if(r===void 0)throw new Error("size must contain 'longest_edge'");let[n,o]=e.size,i=Math.max(n,o)/r,a=n,l=o;i>1&&(a=Math.floor(n/i),l=Math.floor(o/i));let{patch_size:c,spatial_merge_size:u}=this.config;if(!u)throw new Error("config must contain 'spatial_merge_size'");let p=c*u,d=Math.floor((a-1)/p)+1,_=Math.floor((l-1)/p)+1;return[d*p,_*p]}};var qu=class extends P{};var Gu=class extends P{async _call(e,...s){let{pixel_values:r,original_sizes:n,reshaped_input_sizes:o}=await super._call(e,...s),i=r,{temporal_patch_size:a,merge_size:l,patch_size:c}=this.config;i.dims[0]===1&&(i=ne(Array.from({length:a},()=>i),0));let u=i.dims[0]/a,p=i.dims[1],d=Math.floor(i.dims[2]/c),_=Math.floor(i.dims[3]/c),m=i.view(u,a,p,Math.floor(d/l),l,c,Math.floor(_/l),l,c).permute(0,3,6,4,7,2,1,5,8).view(u*d*_,p*a*c*c),h=new S("int64",[u,d,_],[1,3]);return{pixel_values:m,image_grid_thw:h,original_sizes:n,reshaped_input_sizes:o}}};var Wu=class extends P{post_process_object_detection(...e){return St(...e)}};var br=class extends P{reshape_input_points(e,s,r,n=!1){e=structuredClone(e);let o=Bl(e);if(o.length===3)n||(o=[1,...o]),e=[e];else if(o.length!==4)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let i=0;i<e.length;++i){let[a,l]=s[i],[c,u]=r[i],p=[u/l,c/a];for(let d=0;d<e[i].length;++d)for(let _=0;_<e[i][d].length;++_)for(let m=0;m<e[i][d][_].length;++m)e[i][d][_][m]*=p[m%2]}return new S("float32",Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,s){let r=Bl(e);if(r.length===2)r=[1,...r],e=[e];else if(r.length!==3)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");if(r.some((n,o)=>n!==s.dims[o]))throw Error(`The first ${r.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new S("int64",e.flat(1/0).map(BigInt),r)}async _call(e,{input_points:s=null,input_labels:r=null,input_boxes:n=null}={}){let o=await super._call(e);if(s&&(o.input_points=this.reshape_input_points(s,o.original_sizes,o.reshaped_input_sizes)),r){if(!o.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");o.input_labels=this.add_input_labels(r,o.input_points)}return n&&(o.input_boxes=this.reshape_input_points(n,o.original_sizes,o.reshaped_input_sizes,!0)),o}async post_process_masks(e,s,r,{mask_threshold:n=0,binarize:o=!0,pad_size:i=null}={}){let a=[];i=i??this.pad_size??this.size;let l=[i.height,i.width];for(let c=0;c<s.length;++c){let u=s[c],p=r[c],d=await Xe(e[c],{mode:"bilinear",size:l});if(d=d.slice(null,null,[0,p[0]],[0,p[1]]),d=await Xe(d,{mode:"bilinear",size:u}),o){let _=d.data,m=new Uint8Array(_.length);for(let h=0;h<_.length;++h)_[h]>n&&(m[h]=1);d=new S("bool",m,d.dims)}a.push(d)}return a}generate_crop_boxes(e,s,{crop_n_layers:r=0,overlap_ratio:n=512/1500,points_per_crop:o=32,crop_n_points_downscale_factor:i=1}={}){}};var yi=class extends P{post_process_semantic_segmentation(...e){return ii(...e)}},Vu=class extends yi{};var bi=class extends P{post_process_semantic_segmentation(...e){return ii(...e)}},Hu=class extends bi{};var Xu=class extends P{};var Ku=class extends P{pad_image(e,s,r,n={}){let[o,i,a]=s;return super.pad_image(e,s,{width:i+(r-i%r)%r,height:o+(r-o%r)%r},{mode:"symmetric",center:!1,constant_values:-1,...n})}};var ki=class extends P{},Qu=class extends ki{};var Ju=class extends P{async _call(e,s){Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);let r=await Promise.all(e.map(i=>this.preprocess(i))),n=await Promise.all(s.map(i=>this.preprocess(i,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})));return{pixel_values:Ke(r.map((i,a)=>ne([i.pixel_values,n[a].pixel_values],0)),0),original_sizes:r.map(i=>i.original_size),reshaped_input_sizes:r.map(i=>i.reshaped_input_size)}}};var Yu=class extends P{post_process_pose_estimation(e,s,{threshold:r=null}={}){let n=e.tolist(),[o,i,a,l]=e.dims,c=[];for(let u=0;u<o;++u){let p=n[u],d=s[u],_=[];for(let m=0;m<d.length;++m){let h=d[m],x=[],g=[],w=[],y=h.at(-2)/l,E=h.at(-1)/a;for(let A=0;A<p.length;++A){let[b,O]=[0,0],N=0,F=-1/0,R=p[A];for(let G=0;G<R.length;++G){let D=R[G];for(let X=0;X<D.length;++X){let V=D[X];N+=V,F=Math.max(F,V),b+=(X+.5)*V,O+=G*V}}if(r!=null&&F<r)continue;let B=[y*b/N,E*O/N];x.push(B),w.push(A),g.push(F)}_.push({bbox:h,scores:g,labels:w,keypoints:x})}c.push(_)}return c}};var vi=class extends P{post_process_object_detection(...e){return St(...e)}},Zu=class extends vi{};var de=class{static async from_pretrained(e,s={}){let r=await Se(e,ks,!0,s),n=r.image_processor_type??r.feature_extractor_type,o=Ss[n?.replace(/Fast$/,"")];return o||(n!==void 0&&console.warn(`Image processor type '${n}' not found, assuming base ImageProcessor. Please report this at ${bs}.`),o=P),new o(r)}};var ep=class extends j{static tokenizer_class=L;static image_processor_class=de;constructor(e,s,r){super(e,s,r);let{tasks_answer_post_processing_type:n,task_prompts_without_inputs:o,task_prompts_with_input:i}=this.image_processor.config;this.tasks_answer_post_processing_type=new Map(Object.entries(n??{})),this.task_prompts_without_inputs=new Map(Object.entries(o??{})),this.task_prompts_with_input=new Map(Object.entries(i??{})),this.regexes={quad_boxes:/(.+?)<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm,bboxes:/([^<]+)?<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm},this.size_per_bin=1e3}construct_prompts(e){typeof e=="string"&&(e=[e]);let s=[];for(let r of e)if(this.task_prompts_without_inputs.has(r))s.push(this.task_prompts_without_inputs.get(r));else{for(let[n,o]of this.task_prompts_with_input)if(r.includes(n)){s.push(o.replaceAll("{input}",r).replaceAll(n,""));break}s.length!==e.length&&s.push(r)}return s}post_process_generation(e,s,r){let n=this.tasks_answer_post_processing_type.get(s)??"pure_text";e=e.replaceAll("<s>","").replaceAll("</s>","");let o;switch(n){case"pure_text":o=e;break;case"description_with_bboxes":case"bboxes":case"phrase_grounding":case"ocr":let i=n==="ocr"?"quad_boxes":"bboxes",a=e.matchAll(this.regexes[i]),l=[],c=[];for(let[u,p,...d]of a)l.push(p?p.trim():l.at(-1)??""),c.push(d.map((_,m)=>(Number(_)+.5)/this.size_per_bin*r[m%2]));o={labels:l,[i]:c};break;default:throw new Error(`Task "${s}" (of type "${n}") not yet implemented.`)}return{[s]:o}}async _call(e,s=null,r={}){if(!e&&!s)throw new Error("Either text or images must be provided");let n=await this.image_processor(e,r),o=s?this.tokenizer(this.construct_prompts(s),r):{};return{...n,...o}}};var tp=class extends j{static image_processor_class=de;static feature_extractor_class=ve;static tokenizer_class=L;static uses_processor_config=!0;static uses_chat_template_file=!0;constructor(e,s,r){super(e,s,r),this.audio_seq_length=this.config.audio_seq_length,this.image_seq_length=this.config.image_seq_length;let{audio_token_id:n,boa_token:o,audio_token:i,eoa_token:a,image_token_id:l,boi_token:c,image_token:u,eoi_token:p}=this.tokenizer.config;this.audio_token_id=n,this.boa_token=o,this.audio_token=i;let d=i.repeat(this.audio_seq_length);this.full_audio_sequence=`
7
+ `));case"join":case"string":return t;case"int":{let n=parseInt(t.value,10);return new X(isNaN(n)?0:n)}case"float":{let n=parseFloat(t.value);return new be(isNaN(n)?0:n)}default:throw new Error(`Unknown StringValue filter: ${r.value}`)}else if(t instanceof X||t instanceof be)switch(r.value){case"abs":return t instanceof X?new X(Math.abs(t.value)):new be(Math.abs(t.value));case"int":return new X(Math.floor(t.value));case"float":return new be(t.value);default:throw new Error(`Unknown NumericValue filter: ${r.value}`)}else if(t instanceof $e)switch(r.value){case"items":return new re(Array.from(t.value.entries()).map(([n,o])=>new re([new R(n),o])));case"length":return new X(t.value.size);default:{let n=t.builtins.get(r.value);if(n)return n instanceof he?n.value([],s):n;throw new Error(`Unknown ObjectValue filter: ${r.value}`)}}else if(t instanceof q)switch(r.value){case"bool":return new q(t.value);case"int":return new X(t.value?1:0);case"float":return new be(t.value?1:0);case"string":return new R(t.value?"true":"false");default:throw new Error(`Unknown BooleanValue filter: ${r.value}`)}throw new Error(`Cannot apply filter "${r.value}" to type: ${t.type}`)}else if(e.type==="CallExpression"){let r=e;if(r.callee.type!=="Identifier")throw new Error(`Unknown filter: ${r.callee.type}`);let n=r.callee.value;if(n==="tojson"){let[,o]=this.evaluateArguments(r.args,s),i=o.get("indent")??new xe;if(!(i instanceof X||i instanceof xe))throw new Error("If set, indent must be a number");let a=o.get("ensure_ascii")??new q(!1);if(!(a instanceof q))throw new Error("If set, ensure_ascii must be a boolean");let l=o.get("sort_keys")??new q(!1);if(!(l instanceof q))throw new Error("If set, sort_keys must be a boolean");let c=o.get("separators")??new xe,u=null;if(c instanceof re||c instanceof $w){if(c.value.length!==2)throw new Error("separators must be a tuple of two strings");let[p,d]=c.value;if(!(p instanceof R)||!(d instanceof R))throw new Error("separators must be a tuple of two strings");u=[p.value,d.value]}else if(!(c instanceof xe))throw new Error("If set, separators must be a tuple of two strings");return new R(is(t,{indent:i.value,ensureAscii:a.value,sortKeys:l.value,separators:u}))}else if(n==="join"){let o;if(t instanceof R)o=Array.from(t.value);else if(t instanceof re)o=t.value.map(c=>c.value);else throw new Error(`Cannot apply filter "${n}" to type: ${t.type}`);let[i,a]=this.evaluateArguments(r.args,s),l=i.at(0)??a.get("separator")??new R("");if(!(l instanceof R))throw new Error("separator must be a string");return new R(o.join(l.value))}else if(n==="int"||n==="float"){let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("default")??(n==="int"?new X(0):new be(0));if(t instanceof R){let l=n==="int"?parseInt(t.value,10):parseFloat(t.value);return isNaN(l)?a:n==="int"?new X(l):new be(l)}else{if(t instanceof X||t instanceof be)return t;if(t instanceof q)return n==="int"?new X(t.value?1:0):new be(t.value?1:0);throw new Error(`Cannot apply filter "${n}" to type: ${t.type}`)}}else if(n==="default"){let[o,i]=this.evaluateArguments(r.args,s),a=o[0]??new R(""),l=o[1]??i.get("boolean")??new q(!1);if(!(l instanceof q))throw new Error("`default` filter flag must be a boolean");return t instanceof me||l.value&&!t.__bool__().value?a:t}if(t instanceof re){switch(n){case"sort":{let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("reverse")??new q(!1);if(!(a instanceof q))throw new Error("reverse must be a boolean");let l=o.at(1)??i.get("case_sensitive")??new q(!1);if(!(l instanceof q))throw new Error("case_sensitive must be a boolean");let c=o.at(2)??i.get("attribute")??new xe;if(!(c instanceof R||c instanceof X||c instanceof xe))throw new Error("attribute must be a string, integer, or null");let u=p=>{if(c instanceof xe)return p;let d=c instanceof X?String(c.value):c.value;return Rw(p,d)};return new re(t.value.slice().sort((p,d)=>{let _=u(p),f=u(d),h=pc(_,f,l.value);return a.value?-h:h}))}case"selectattr":case"rejectattr":{let o=n==="selectattr";if(t.value.some(p=>!(p instanceof $e)))throw new Error(`\`${n}\` can only be applied to array of objects`);if(r.args.some(p=>p.type!=="StringLiteral"))throw new Error(`arguments of \`${n}\` must be strings`);let[i,a,l]=r.args.map(p=>this.evaluate(p,s)),c;if(a){let p=s.tests.get(a.value);if(!p)throw new Error(`Unknown test: ${a.value}`);c=p}else c=(...p)=>p[0].__bool__().value;let u=t.value.filter(p=>{let d=p.value.get(i.value),_=d?c(d,l):!1;return o?_:!_});return new re(u)}case"map":{let[,o]=this.evaluateArguments(r.args,s);if(o.has("attribute")){let i=o.get("attribute");if(!(i instanceof R))throw new Error("attribute must be a string");let a=o.get("default"),l=t.value.map(c=>{if(!(c instanceof $e))throw new Error("items in map must be an object");let u=Rw(c,i.value);return u instanceof me?a??new me:u});return new re(l)}else throw new Error("`map` expressions without `attribute` set are not currently supported.")}}throw new Error(`Unknown ArrayValue filter: ${n}`)}else if(t instanceof R){switch(n){case"indent":{let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("width")??new X(4);if(!(a instanceof X))throw new Error("width must be a number");let l=o.at(1)??i.get("first")??new q(!1),c=o.at(2)??i.get("blank")??new q(!1),u=t.value.split(`
8
+ `),p=" ".repeat(a.value),d=u.map((_,f)=>!l.value&&f===0||!c.value&&_.length===0?_:p+_);return new R(d.join(`
9
+ `))}case"replace":{let o=t.builtins.get("replace");if(!(o instanceof he))throw new Error("replace filter not available");let[i,a]=this.evaluateArguments(r.args,s);return o.value([...i,new gr(a)],s)}}throw new Error(`Unknown StringValue filter: ${n}`)}else if(t instanceof $e){let o=t.builtins.get(n);if(o&&o instanceof he){let[i,a]=this.evaluateArguments(r.args,s);return a.size>0&&i.push(new gr(a)),o.value(i,s)}throw new Error(`Unknown ObjectValue filter: ${n}`)}else throw new Error(`Cannot apply filter "${n}" to type: ${t.type}`)}throw new Error(`Unknown filter: ${e.type}`)}evaluateFilterExpression(t,e){let s=this.evaluate(t.operand,e);return this.applyFilter(s,t.filter,e)}evaluateTestExpression(t,e){let s=this.evaluate(t.operand,e),r=e.tests.get(t.test.value);if(!r)throw new Error(`Unknown test: ${t.test.value}`);let n=r(s);return new q(t.negate?!n:n)}evaluateSelectExpression(t,e){return this.evaluate(t.test,e).__bool__().value?this.evaluate(t.lhs,e):new me}evaluateUnaryExpression(t,e){let s=this.evaluate(t.argument,e);if(t.operator.value==="not")return new q(!s.value);throw new SyntaxError(`Unknown operator: ${t.operator.value}`)}evaluateTernaryExpression(t,e){return this.evaluate(t.condition,e).__bool__().value?this.evaluate(t.trueExpr,e):this.evaluate(t.falseExpr,e)}evalProgram(t,e){return this.evaluateBlock(t.body,e)}evaluateBlock(t,e){let s="";for(let r of t){let n=this.evaluate(r,e);n.type!=="NullValue"&&n.type!=="UndefinedValue"&&(s+=n.toString())}return new R(s)}evaluateIdentifier(t,e){return e.lookupVariable(t.value)}evaluateCallExpression(t,e){let[s,r]=this.evaluateArguments(t.args,e);r.size>0&&s.push(new gr(r));let n=this.evaluate(t.callee,e);if(n.type!=="FunctionValue")throw new Error(`Cannot call something that is not a function: got ${n.type}`);return n.value(s,e)}evaluateSliceExpression(t,e,s){if(!(t instanceof re||t instanceof R))throw new Error("Slice object must be an array or string");let r=this.evaluate(e.start,s),n=this.evaluate(e.stop,s),o=this.evaluate(e.step,s);if(!(r instanceof X||r instanceof me))throw new Error("Slice start must be numeric or undefined");if(!(n instanceof X||n instanceof me))throw new Error("Slice stop must be numeric or undefined");if(!(o instanceof X||o instanceof me))throw new Error("Slice step must be numeric or undefined");return t instanceof re?new re(Pw(t.value,r.value,n.value,o.value)):new R(Pw(Array.from(t.value),r.value,n.value,o.value).join(""))}evaluateMemberExpression(t,e){let s=this.evaluate(t.object,e),r;if(t.computed){if(t.property.type==="SliceExpression")return this.evaluateSliceExpression(s,t.property,e);r=this.evaluate(t.property,e)}else r=new R(t.property.value);let n;if(s instanceof $e){if(!(r instanceof R))throw new Error(`Cannot access property with non-string: got ${r.type}`);n=s.value.get(r.value)??s.builtins.get(r.value)}else if(s instanceof re||s instanceof R)if(r instanceof X)n=s.value.at(r.value),s instanceof R&&(n=new R(s.value.at(r.value)));else if(r instanceof R)n=s.builtins.get(r.value);else throw new Error(`Cannot access property with non-string/non-number: got ${r.type}`);else{if(!(r instanceof R))throw new Error(`Cannot access property with non-string: got ${r.type}`);n=s.builtins.get(r.value)}return n instanceof dt?n:new me}evaluateSet(t,e){let s=t.value?this.evaluate(t.value,e):this.evaluateBlock(t.body,e);if(t.assignee.type==="Identifier"){let r=t.assignee.value;e.setVariable(r,s)}else if(t.assignee.type==="TupleLiteral"){let r=t.assignee;if(!(s instanceof re))throw new Error(`Cannot unpack non-iterable type in set: ${s.type}`);let n=s.value;if(n.length!==r.value.length)throw new Error(`Too ${r.value.length>n.length?"few":"many"} items to unpack in set`);for(let o=0;o<r.value.length;++o){let i=r.value[o];if(i.type!=="Identifier")throw new Error(`Cannot unpack to non-identifier in set: ${i.type}`);e.setVariable(i.value,n[o])}}else if(t.assignee.type==="MemberExpression"){let r=t.assignee,n=this.evaluate(r.object,e);if(!(n instanceof $e))throw new Error("Cannot assign to member of non-object");if(r.property.type!=="Identifier")throw new Error("Cannot assign to member with non-identifier property");n.value.set(r.property.value,s)}else throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(t.assignee)}`);return new xe}evaluateIf(t,e){let s=this.evaluate(t.test,e);return this.evaluateBlock(s.__bool__().value?t.body:t.alternate,e)}evaluateFor(t,e){let s=new os(e),r,n;if(t.iterable.type==="SelectExpression"){let c=t.iterable;n=this.evaluate(c.lhs,s),r=c.test}else n=this.evaluate(t.iterable,s);if(!(n instanceof re||n instanceof $e))throw new Error(`Expected iterable or object type in for loop: got ${n.type}`);n instanceof $e&&(n=n.keys());let o=[],i=[];for(let c=0;c<n.value.length;++c){let u=new os(s),p=n.value[c],d;if(t.loopvar.type==="Identifier")d=_=>_.setVariable(t.loopvar.value,p);else if(t.loopvar.type==="TupleLiteral"){let _=t.loopvar;if(p.type!=="ArrayValue")throw new Error(`Cannot unpack non-iterable type: ${p.type}`);let f=p;if(_.value.length!==f.value.length)throw new Error(`Too ${_.value.length>f.value.length?"few":"many"} items to unpack`);d=h=>{for(let x=0;x<_.value.length;++x){if(_.value[x].type!=="Identifier")throw new Error(`Cannot unpack non-identifier type: ${_.value[x].type}`);h.setVariable(_.value[x].value,f.value[x])}}}else throw new Error(`Invalid loop variable(s): ${t.loopvar.type}`);r&&(d(u),!this.evaluate(r,u).__bool__().value)||(o.push(p),i.push(d))}let a="",l=!0;for(let c=0;c<o.length;++c){let u=new Map([["index",new X(c+1)],["index0",new X(c)],["revindex",new X(o.length-c)],["revindex0",new X(o.length-c-1)],["first",new q(c===0)],["last",new q(c===o.length-1)],["length",new X(o.length)],["previtem",c>0?o[c-1]:new me],["nextitem",c<o.length-1?o[c+1]:new me]]);s.setVariable("loop",new $e(u)),i[c](s);try{let p=this.evaluateBlock(t.body,s);a+=p.value}catch(p){if(p instanceof Nw)continue;if(p instanceof Cw)break;throw p}l=!1}if(l){let c=this.evaluateBlock(t.defaultBlock,s);a+=c.value}return new R(a)}evaluateMacro(t,e){return e.setVariable(t.name.value,new he((s,r)=>{let n=new os(r);s=s.slice();let o;s.at(-1)?.type==="KeywordArgumentsValue"&&(o=s.pop());for(let i=0;i<t.args.length;++i){let a=t.args[i],l=s[i];if(a.type==="Identifier"){let c=a;if(!l)throw new Error(`Missing positional argument: ${c.value}`);n.setVariable(c.value,l)}else if(a.type==="KeywordArgumentExpression"){let c=a,u=l??o?.value.get(c.key.value)??this.evaluate(c.value,n);n.setVariable(c.key.value,u)}else throw new Error(`Unknown argument type: ${a.type}`)}return this.evaluateBlock(t.body,n)})),new xe}evaluateCallStatement(t,e){let s=new he((a,l)=>{let c=new os(l);if(t.callerArgs)for(let u=0;u<t.callerArgs.length;++u){let p=t.callerArgs[u];if(p.type!=="Identifier")throw new Error(`Caller parameter must be an identifier, got ${p.type}`);c.setVariable(p.value,a[u]??new me)}return this.evaluateBlock(t.body,c)}),[r,n]=this.evaluateArguments(t.call.args,e);r.push(new gr(n));let o=this.evaluate(t.call.callee,e);if(o.type!=="FunctionValue")throw new Error(`Cannot call something that is not a function: got ${o.type}`);let i=new os(e);return i.setVariable("caller",s),o.value(r,i)}evaluateFilterStatement(t,e){let s=this.evaluateBlock(t.body,e);return this.applyFilter(s,t.filter,e)}evaluate(t,e){if(!t)return new me;switch(t.type){case"Program":return this.evalProgram(t,e);case"Set":return this.evaluateSet(t,e);case"If":return this.evaluateIf(t,e);case"For":return this.evaluateFor(t,e);case"Macro":return this.evaluateMacro(t,e);case"CallStatement":return this.evaluateCallStatement(t,e);case"Break":throw new Cw;case"Continue":throw new Nw;case"IntegerLiteral":return new X(t.value);case"FloatLiteral":return new be(t.value);case"StringLiteral":return new R(t.value);case"ArrayLiteral":return new re(t.value.map(s=>this.evaluate(s,e)));case"TupleLiteral":return new $w(t.value.map(s=>this.evaluate(s,e)));case"ObjectLiteral":{let s=new Map;for(let[r,n]of t.value){let o=this.evaluate(r,e);if(!(o instanceof R))throw new Error(`Object keys must be strings: got ${o.type}`);s.set(o.value,this.evaluate(n,e))}return new $e(s)}case"Identifier":return this.evaluateIdentifier(t,e);case"CallExpression":return this.evaluateCallExpression(t,e);case"MemberExpression":return this.evaluateMemberExpression(t,e);case"UnaryExpression":return this.evaluateUnaryExpression(t,e);case"BinaryExpression":return this.evaluateBinaryExpression(t,e);case"FilterExpression":return this.evaluateFilterExpression(t,e);case"FilterStatement":return this.evaluateFilterStatement(t,e);case"TestExpression":return this.evaluateTestExpression(t,e);case"SelectExpression":return this.evaluateSelectExpression(t,e);case"Ternary":return this.evaluateTernaryExpression(t,e);case"Comment":return new xe;default:throw new SyntaxError(`Unknown node type: ${t.type}`)}}};function Ni(t){switch(typeof t){case"number":return Number.isInteger(t)?new X(t):new be(t);case"string":return new R(t);case"boolean":return new q(t);case"undefined":return new me;case"object":return t===null?new xe:Array.isArray(t)?new re(t.map(Ni)):new $e(new Map(Object.entries(t).map(([e,s])=>[e,Ni(s)])));case"function":return new he((e,s)=>{let r=t(...e.map(n=>n.value))??null;return Ni(r)});default:throw new Error(`Cannot convert to runtime value: ${t}`)}}var Se=`
10
+ `,Wk="{%- ",Vk=" -%}";function Hk(t){switch(t.operator.type){case"MultiplicativeBinaryOperator":return 4;case"AdditiveBinaryOperator":return 3;case"ComparisonBinaryOperator":return 2;case"Identifier":return t.operator.value==="and"?1:t.operator.value==="in"||t.operator.value==="not in"?2:0}return 0}function Kk(t,e=" "){let s=typeof e=="number"?" ".repeat(e):e;return ot(t.body,0,s).replace(/\n$/,"")}function Ce(...t){return Wk+t.join(" ")+Vk}function ot(t,e,s){return t.map(r=>Xk(r,e,s)).join(Se)}function Xk(t,e,s){let r=s.repeat(e);switch(t.type){case"Program":return ot(t.body,e,s);case"If":return Qk(t,e,s);case"For":return Yk(t,e,s);case"Set":return Jk(t,e,s);case"Macro":return Zk(t,e,s);case"Break":return r+Ce("break");case"Continue":return r+Ce("continue");case"CallStatement":return ev(t,e,s);case"FilterStatement":return tv(t,e,s);case"Comment":return r+"{# "+t.value+" #}";default:return r+"{{- "+ne(t)+" -}}"}}function Qk(t,e,s){let r=s.repeat(e),n=[],o=t;for(;o&&(n.push({test:o.test,body:o.body}),o.alternate.length===1&&o.alternate[0].type==="If");)o=o.alternate[0];let i=r+Ce("if",ne(n[0].test))+Se+ot(n[0].body,e+1,s);for(let a=1;a<n.length;++a)i+=Se+r+Ce("elif",ne(n[a].test))+Se+ot(n[a].body,e+1,s);return o&&o.alternate.length>0&&(i+=Se+r+Ce("else")+Se+ot(o.alternate,e+1,s)),i+=Se+r+Ce("endif"),i}function Yk(t,e,s){let r=s.repeat(e),n="";if(t.iterable.type==="SelectExpression"){let i=t.iterable;n=`${ne(i.lhs)} if ${ne(i.test)}`}else n=ne(t.iterable);let o=r+Ce("for",ne(t.loopvar),"in",n)+Se+ot(t.body,e+1,s);return t.defaultBlock.length>0&&(o+=Se+r+Ce("else")+Se+ot(t.defaultBlock,e+1,s)),o+=Se+r+Ce("endfor"),o}function Jk(t,e,s){let r=s.repeat(e),n=ne(t.assignee),o=t.value?ne(t.value):"",i=r+Ce("set",`${n}${t.value?" = "+o:""}`);return t.body.length===0?i:i+Se+ot(t.body,e+1,s)+Se+r+Ce("endset")}function Zk(t,e,s){let r=s.repeat(e),n=t.args.map(ne).join(", ");return r+Ce("macro",`${t.name.value}(${n})`)+Se+ot(t.body,e+1,s)+Se+r+Ce("endmacro")}function ev(t,e,s){let r=s.repeat(e),n=t.callerArgs&&t.callerArgs.length>0?`(${t.callerArgs.map(ne).join(", ")})`:"",o=ne(t.call),i=r+Ce(`call${n}`,o)+Se;return i+=ot(t.body,e+1,s)+Se,i+=r+Ce("endcall"),i}function tv(t,e,s){let r=s.repeat(e),n=t.filter.type==="Identifier"?t.filter.value:ne(t.filter),o=r+Ce("filter",n)+Se;return o+=ot(t.body,e+1,s)+Se,o+=r+Ce("endfilter"),o}function ne(t,e=-1){switch(t.type){case"SpreadExpression":return`*${ne(t.argument)}`;case"Identifier":return t.value;case"IntegerLiteral":return`${t.value}`;case"FloatLiteral":return`${t.value}`;case"StringLiteral":return JSON.stringify(t.value);case"BinaryExpression":{let s=t,r=Hk(s),n=ne(s.left,r),o=ne(s.right,r+1),i=`${n} ${s.operator.value} ${o}`;return r<e?`(${i})`:i}case"UnaryExpression":{let s=t;return s.operator.value+(s.operator.value==="not"?" ":"")+ne(s.argument,1/0)}case"CallExpression":{let s=t,r=s.args.map(ne).join(", ");return`${ne(s.callee)}(${r})`}case"MemberExpression":{let s=t,r=ne(s.object);["Identifier","MemberExpression","CallExpression","StringLiteral","IntegerLiteral","FloatLiteral","ArrayLiteral","TupleLiteral","ObjectLiteral"].includes(s.object.type)||(r=`(${r})`);let n=ne(s.property);return!s.computed&&s.property.type!=="Identifier"&&(n=`(${n})`),s.computed?`${r}[${n}]`:`${r}.${n}`}case"FilterExpression":{let s=t,r=ne(s.operand,1/0);return s.filter.type==="CallExpression"?`${r} | ${ne(s.filter)}`:`${r} | ${s.filter.value}`}case"SelectExpression":{let s=t;return`${ne(s.lhs)} if ${ne(s.test)}`}case"TestExpression":{let s=t;return`${ne(s.operand)} is${s.negate?" not":""} ${s.test.value}`}case"ArrayLiteral":case"TupleLiteral":{let s=t.value.map(ne),r=t.type==="ArrayLiteral"?"[]":"()";return`${r[0]}${s.join(", ")}${r[1]}`}case"ObjectLiteral":return`{${Array.from(t.value.entries()).map(([r,n])=>`${ne(r)}: ${ne(n)}`).join(", ")}}`;case"SliceExpression":{let s=t,r=s.start?ne(s.start):"",n=s.stop?ne(s.stop):"",o=s.step?`:${ne(s.step)}`:"";return`${r}:${n}${o}`}case"KeywordArgumentExpression":{let s=t;return`${s.key.value}=${ne(s.value)}`}case"Ternary":{let s=t,r=`${ne(s.trueExpr)} if ${ne(s.condition,0)} else ${ne(s.falseExpr)}`;return e>-1?`(${r})`:r}default:throw new Error(`Unknown expression type: ${t.type}`)}}var Fw=class{parsed;constructor(t){let e=pk(t,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=Lk(e)}render(t){let e=new os;if(qk(e),t)for(let[n,o]of Object.entries(t))e.set(n,o);return new Gk(e).run(this.parsed).value}format(t){return Kk(this.parsed,t?.indent||" ")}};var ve=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}_call(...t){throw Error("Must implement _call method in subclass")}};var sv={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif"},as=class t{constructor(e){if(this.filePath=e,this.headers=new Headers,this.exists=Fe.existsSync(e),this.exists){this.status=200,this.statusText="OK";let s=Fe.statSync(e);this.headers.set("content-length",s.size.toString()),this.updateContentType();let r=Fe.createReadStream(e);this.body=new ReadableStream({start(n){r.on("data",o=>n.enqueue(o)),r.on("end",()=>n.close()),r.on("error",o=>n.error(o))},cancel(){r.destroy()}})}else this.status=404,this.statusText="Not Found",this.body=null}updateContentType(){let e=this.filePath.toString().split(".").pop().toLowerCase();this.headers.set("content-type",sv[e]??"application/octet-stream")}clone(){let e=new t(this.filePath);return e.exists=this.exists,e.status=this.status,e.statusText=this.statusText,e.headers=new Headers(this.headers),e}async arrayBuffer(){return(await Fe.promises.readFile(this.filePath)).buffer}async blob(){let e=await Fe.promises.readFile(this.filePath);return new Blob([e],{type:this.headers.get("content-type")})}async text(){return await Fe.promises.readFile(this.filePath,"utf8")}async json(){return JSON.parse(await this.text())}},Ts=class{constructor(e){this.path=e}async match(e){let s=He.join(this.path,e),r=new as(s);if(r.exists)return r}async put(e,s,r=void 0){let n=He.join(this.path,e);try{let o=s.headers.get("Content-Length"),i=parseInt(o??"0"),a=0;await Fe.promises.mkdir(He.dirname(n),{recursive:!0});let l=Fe.createWriteStream(n),c=s.body.getReader();for(;;){let{done:u,value:p}=await c.read();if(u)break;await new Promise((_,f)=>{l.write(p,h=>{if(h){f(h);return}_()})}),a+=p.length;let d=i?a/i*100:0;r?.({progress:d,loaded:a,total:i})}l.close()}catch(o){try{await Fe.promises.unlink(n)}catch{}throw o}}async delete(e){let s=He.join(this.path,e);try{return await Fe.promises.unlink(s),!0}catch{return!1}}};var Dw={400:"Bad request error occurred while trying to load file",401:"Unauthorized access to file",403:"Forbidden access to file",404:"Could not locate file",408:"Request timeout error occurred while trying to load file",500:"Internal server error error occurred while trying to load file",502:"Bad gateway error occurred while trying to load file",503:"Service unavailable error occurred while trying to load file",504:"Gateway timeout error occurred while trying to load file"},Li=100,jw=/^(\b[\w\-.]+\b\/)?\b[\w\-.]{1,96}\b$/;function wr(...t){return t=t.map((e,s)=>(s&&(e=e.replace(new RegExp("^/"),"")),s!==t.length-1&&(e=e.replace(new RegExp("/$"),"")),e)),t.join("/")}function St(t,e=null,s=null){let r;try{r=new URL(t)}catch{return!1}return!(e&&!e.includes(r.protocol)||s&&!s.includes(r.hostname))}function Uw(t){return!(!jw.test(t)||t.includes("..")||t.includes("--")||t.endsWith(".git")||t.endsWith(".ipynb"))}function Bw(t,e,s){if(!s)return null;let r=Dw[t]??`Error (${t}) occurred while trying to load file`;throw Error(`${r}: "${e}".`)}async function qw(t,e,s){let r=t.headers.get("Content-Length"),n=r?parseInt(r,10):s??0;r===null&&!s&&L.warn("Unable to determine content-length from response headers. Will expand buffer when needed.");let o=new Uint8Array(n),i=0,a=t.body.getReader();async function l(){let{done:c,value:u}=await a.read();if(c)return;let p=i+u.length;if(p>n){n=p;let _=new Uint8Array(n);_.set(o),o=_}o.set(u,i),i=p;let d=i/n*100;return e({progress:d,loaded:i,total:n}),l()}return await l(),o}async function _t(t=null){let e=null;if(H.useCustomCache){if(!H.customCache)throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");if(!H.customCache.match||!H.customCache.put)throw new Error("`env.customCache` must be an object which implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache");e=H.customCache}if(!e&&H.useBrowserCache){if(typeof caches>"u")throw Error("Browser cache is not available in this environment.");try{e=await caches.open(H.cacheKey)}catch(s){L.warn("An error occurred while opening the browser cache:",s)}}if(!e&&H.useFSCache){if(!Z.IS_FS_AVAILABLE)throw Error("File System Cache is not available in this environment.");e=new Ts(t??H.cacheDir)}return e}async function Gw(t,...e){for(let s of e)try{let r=await t.match(s);if(r)return r}catch{continue}}async function rv(t){if(!St(t,["http:","https:"]))return null;let e=dc(t);return e.set("Range","bytes=0-0"),H.fetch(t,{method:"GET",headers:e})}async function ft(t,e,s={}){let r=await _t(s?.cache_dir),{localPath:n,remoteURL:o,proposedCacheKey:i,validModelId:a}=ls(t,e,s,r),l=await cs(r,n,i);if(l!==void 0&&typeof l!="string"){let c=l.headers.get("content-length"),u=l.headers.get("content-type");return{exists:!0,size:c?parseInt(c,10):void 0,contentType:u||void 0,fromCache:!0}}if(H.allowLocalModels&&!St(n,["http:","https:"]))try{let u=await Lt(n);if(typeof u!="string"&&u.status!==404){let p=u.headers.get("content-length"),d=u.headers.get("content-type");return{exists:!0,size:p?parseInt(p,10):void 0,contentType:d||void 0,fromCache:!1}}}catch{}if(H.allowRemoteModels&&!s.local_files_only&&a)try{let c=await rv(o);if(c&&c.status>=200&&c.status<300){let u,p=c.headers.get("content-type");if(c.status===206){let d=c.headers.get("content-range");if(d){let _=d.match(/bytes \d+-\d+\/(\d+)/);_&&(u=parseInt(_[1],10))}}else if(c.status===200)try{await c.body?.cancel()}catch{}if(u===void 0){let d=c.headers.get("content-length");u=d?parseInt(d,10):void 0}return{exists:!0,size:u,contentType:p||void 0,fromCache:!1}}}catch(c){L.warn(`Unable to fetch file metadata for "${o}": ${c}`)}return{exists:!1,fromCache:!1}}async function Lt(t){return H.useFS&&!St(t,["http:","https:","blob:"])?new as(t instanceof URL?t.protocol==="file:"?t.pathname:t.toString():t):H.fetch(t,{headers:dc(t)})}function dc(t){let e=typeof process<"u"&&process?.release?.name==="node",s=new Headers;if(e){let r=!!process.env?.TESTING_REMOTELY,n=H.version;if(s.set("User-Agent",`transformers.js/${n}; is_ci/${r};`),St(t,["http:","https:"],["huggingface.co","hf.co"])){let i=process.env?.HF_TOKEN??process.env?.HF_ACCESS_TOKEN;i&&s.set("Authorization",`Bearer ${i}`)}}return s}function ls(t,e,s={},r=null){let n=s.revision??"main",o=wr(t,e),i=Uw(t),a=i?wr(H.localModelPath,o):o,l=wr(H.remoteHost,H.remotePathTemplate.replaceAll("{model}",t).replaceAll("{revision}",encodeURIComponent(n)),e),c=r instanceof Ts?n==="main"?o:wr(t,n,e):l;return{requestURL:o,localPath:a,remoteURL:l,proposedCacheKey:c,validModelId:i}}async function cs(t,e,s){if(t)return await Gw(t,e,s)}async function nv(t,e,s,r,n,o,i={}){if(await s.match(r)===void 0)if(o)typeof n!="string"&&await s.put(r,new Response(o,{headers:n.headers})).catch(a=>{L.warn(`Unable to add response to browser cache: ${a}.`)});else{let a=i.progress_callback?l=>At(i.progress_callback,{status:"progress",name:t,file:e,...l}):void 0;await s.put(r,n,a)}}async function ov(t,e,s=!0,r={},n=!1,o=null){let{requestURL:i,localPath:a,remoteURL:l,proposedCacheKey:c,validModelId:u}=ls(t,e,r,o),p,d=!1,_;_=await cs(o,a,c);let f=_!==void 0;if(!f){if(H.allowLocalModels)if(St(i,["http:","https:"])){if(r.local_files_only)throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${i}.`);if(!H.allowRemoteModels)throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${i}.`)}else try{_=await Lt(a),p=a}catch(w){L.warn(`Unable to load from local path "${a}": "${w}"`)}if(_===void 0||typeof _!="string"&&_.status===404){if(r.local_files_only||!H.allowRemoteModels){if(s)throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${a}".`);return null}if(!u)throw Error(`Local file missing at "${a}" and download aborted due to invalid model ID "${t}".`);if(_=await Lt(l),_.status!==200)return Bw(_.status,l,s);p=c}d=o&&typeof Response<"u"&&_ instanceof Response&&_.status===200}At(r.progress_callback,{status:"download",name:t,file:e});let h;if(!(Z.IS_NODE_ENV&&n)){let g;if(typeof _!="string")if(!r.progress_callback)g=new Uint8Array(await _.arrayBuffer());else if(f&&typeof navigator<"u"&&/firefox/i.test(navigator.userAgent))g=new Uint8Array(await _.arrayBuffer()),At(r.progress_callback,{status:"progress",name:t,file:e,progress:100,loaded:g.length,total:g.length});else{let w,y=_.headers.get("content-length");if(y)w=parseInt(y,10);else try{let b=await ft(t,e,r);b.size&&(w=b.size)}catch{}g=await qw(_,b=>{At(r.progress_callback,{status:"progress",name:t,file:e,...b})},w)}h=g}if(d&&p&&typeof _!="string"&&await nv(t,e,o,p,_,h,r),At(r.progress_callback,{status:"done",name:t,file:e}),h){if(!Z.IS_NODE_ENV&&n)throw new Error("Cannot return path in a browser environment.");return h}if(_ instanceof as)return _.filePath;let x=await o?.match(p);if(x instanceof as)return x.filePath;if(x instanceof Response)return new Uint8Array(await x.arrayBuffer());if(typeof x=="string")return x;throw new Error("Unable to get model file path or buffer.")}async function yr(t,e,s=!0,r={},n=!1){if(!H.allowLocalModels){if(r.local_files_only)throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).");if(!H.allowRemoteModels)throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.")}At(r.progress_callback,{status:"initiate",name:t,file:e});let o=await _t(r?.cache_dir);return await ov(t,e,s,r,n,o)}async function _c(t,e,s=!0,r={}){let n=await yr(t,e,s,r,!1);return n===null?null:new TextDecoder("utf-8").decode(n)}async function Te(t,e,s=!0,r={}){let n=await _c(t,e,s,r);return n===null?{}:JSON.parse(n)}function Vw(t,[e,s,r],[n,o],i="bilinear",a=!1){let l=o/r,c=n/s,u=new t.constructor(n*o*e),p=s*r,d=n*o;for(let _=0;_<n;++_)for(let f=0;f<o;++f){let h=_*o+f,x=(f+.5)/l-.5,g=(_+.5)/c-.5,w=Math.floor(x),y=Math.floor(g),b=Math.min(w+1,r-1),A=Math.min(y+1,s-1);w=Math.max(w,0),y=Math.max(y,0);let k=x-w,O=g-y,N=(1-k)*(1-O),D=k*(1-O),F=(1-k)*O,B=k*O,W=y*r,j=A*r,Q=W+w,K=W+b,oe=j+w,te=j+b;for(let v=0;v<e;++v){let E=v*p;u[v*d+h]=N*t[E+Q]+D*t[E+K]+F*t[E+oe]+B*t[E+te]}}return u}function Hw(t,e,s){let r=new Array(s.length),n=new Array(s.length);for(let a=s.length-1,l=1;a>=0;--a)n[a]=l,r[a]=e[s[a]],l*=r[a];let o=s.map((a,l)=>n[s.indexOf(l)]),i=new t.constructor(t.length);for(let a=0;a<t.length;++a){let l=0;for(let c=e.length-1,u=a;c>=0;--c)l+=u%e[c]*o[c],u=Math.floor(u/e[c]);i[l]=t[a]}return[i,r]}function pe(t){let e=le(t)[0],s=t.map(o=>Math.exp(o-e)),r=s.reduce((o,i)=>o+i,0);return s.map(o=>o/r)}function mc(t){let e=le(t)[0],s=0;for(let o=0;o<t.length;++o)s+=Math.exp(t[o]-e);let r=Math.log(s);return t.map(o=>o-e-r)}function Kw(t,e){let s=0;for(let r=0;r<t.length;++r)s+=t[r]*e[r];return s}function iv(t,e){let s=Kw(t,e),r=Ww(t),n=Ww(e);return s/(r*n)}function Ww(t){return Math.sqrt(t.reduce((e,s)=>e+s*s,0))}function br(t){if(t.length===0)throw Error("Array must not be empty");let e=t[0],s=0;for(let r=1;r<t.length;++r)t[r]<e&&(e=t[r],s=r);return[e,s]}function le(t){if(t.length===0)throw Error("Array must not be empty");let e=t[0],s=0;for(let r=1;r<t.length;++r)t[r]>e&&(e=t[r],s=r);return[e,s]}function Xw(t){return t>0&&(t&t-1)===0}var $i=class{constructor(e){if(this.size=e|0,this.size<=1||!Xw(this.size))throw new Error("FFT size must be a power of two larger than 1");this._csize=e<<1,this.table=new Float64Array(this.size*2);for(let r=0;r<this.table.length;r+=2){let n=Math.PI*r/this.size;this.table[r]=Math.cos(n),this.table[r+1]=-Math.sin(n)}let s=0;for(let r=1;this.size>r;r<<=1)++s;this._width=s%2===0?s-1:s,this._bitrev=new Int32Array(1<<this._width);for(let r=0;r<this._bitrev.length;++r){this._bitrev[r]=0;for(let n=0;n<this._width;n+=2){let o=this._width-n-2;this._bitrev[r]|=(r>>>n&3)<<o}}}createComplexArray(){return new Float64Array(this._csize)}fromComplexArray(e,s){let r=s||new Array(e.length>>>1);for(let n=0;n<e.length;n+=2)r[n>>>1]=e[n];return r}toComplexArray(e,s){let r=s||this.createComplexArray();for(let n=0;n<r.length;n+=2)r[n]=e[n>>>1],r[n+1]=0;return r}transform(e,s){if(e===s)throw new Error("Input and output buffers must be different");this._transform4(e,s,1)}realTransform(e,s){if(e===s)throw new Error("Input and output buffers must be different");this._realTransform4(e,s,1)}inverseTransform(e,s){if(e===s)throw new Error("Input and output buffers must be different");this._transform4(e,s,-1);for(let r=0;r<e.length;++r)e[r]/=this.size}_transform4(e,s,r){let n=this._csize,i=1<<this._width,a=n/i<<1,l,c,u=this._bitrev;if(a===4)for(l=0,c=0;l<n;l+=a,++c){let d=u[c];this._singleTransform2(s,e,l,d,i)}else for(l=0,c=0;l<n;l+=a,++c){let d=u[c];this._singleTransform4(s,e,l,d,i,r)}let p=this.table;for(i>>=2;i>=2;i>>=2){a=n/i<<1;let d=a>>>2;for(l=0;l<n;l+=a){let _=l+d-1;for(let f=l,h=0;f<_;f+=2,h+=i){let x=f,g=x+d,w=g+d,y=w+d,b=e[x],A=e[x+1],k=e[g],O=e[g+1],N=e[w],D=e[w+1],F=e[y],B=e[y+1],W=p[h],j=r*p[h+1],Q=k*W-O*j,K=k*j+O*W,oe=p[2*h],te=r*p[2*h+1],v=N*oe-D*te,E=N*te+D*oe,T=p[3*h],J=r*p[3*h+1],se=F*T-B*J,Ie=F*J+B*T,Ae=b+v,kt=A+E,vt=b-v,rs=A-E,ut=Q+se,tt=K+Ie,Et=r*(Q-se),Ct=r*(K-Ie);e[x]=Ae+ut,e[x+1]=kt+tt,e[g]=vt+Ct,e[g+1]=rs-Et,e[w]=Ae-ut,e[w+1]=kt-tt,e[y]=vt-Ct,e[y+1]=rs+Et}}}}_singleTransform2(e,s,r,n,o){let i=e[n],a=e[n+1],l=e[n+o],c=e[n+o+1];s[r]=i+l,s[r+1]=a+c,s[r+2]=i-l,s[r+3]=a-c}_singleTransform4(e,s,r,n,o,i){let a=o*2,l=o*3,c=e[n],u=e[n+1],p=e[n+o],d=e[n+o+1],_=e[n+a],f=e[n+a+1],h=e[n+l],x=e[n+l+1],g=c+_,w=u+f,y=c-_,b=u-f,A=p+h,k=d+x,O=i*(p-h),N=i*(d-x);s[r]=g+A,s[r+1]=w+k,s[r+2]=y+N,s[r+3]=b-O,s[r+4]=g-A,s[r+5]=w-k,s[r+6]=y-N,s[r+7]=b+O}_realTransform4(e,s,r){let n=this._csize,i=1<<this._width,a=n/i<<1,l,c,u=this._bitrev;if(a===4)for(l=0,c=0;l<n;l+=a,++c){let _=u[c];this._singleRealTransform2(s,e,l,_>>>1,i>>>1)}else for(l=0,c=0;l<n;l+=a,++c){let _=u[c];this._singleRealTransform4(s,e,l,_>>>1,i>>>1,r)}let p=this.table;for(i>>=2;i>=2;i>>=2){a=n/i<<1;let _=a>>>1,f=_>>>1,h=f>>>1;for(l=0;l<n;l+=a)for(let x=0,g=0;x<=h;x+=2,g+=i){let w=l+x,y=w+f,b=y+f,A=b+f,k=e[w],O=e[w+1],N=e[y],D=e[y+1],F=e[b],B=e[b+1],W=e[A],j=e[A+1],Q=k,K=O,oe=p[g],te=r*p[g+1],v=N*oe-D*te,E=N*te+D*oe,T=p[2*g],J=r*p[2*g+1],se=F*T-B*J,Ie=F*J+B*T,Ae=p[3*g],kt=r*p[3*g+1],vt=W*Ae-j*kt,rs=W*kt+j*Ae,ut=Q+se,tt=K+Ie,Et=Q-se,Ct=K-Ie,ns=v+vt,Nt=E+rs,Ai=r*(v-vt),Mi=r*(E-rs);if(e[w]=ut+ns,e[w+1]=tt+Nt,e[y]=Et+Mi,e[y+1]=Ct-Ai,x===0){e[b]=ut-ns,e[b+1]=tt-Nt;continue}if(x===h)continue;let Si=l+f-x,pt=l+_-x;e[Si]=Et-r*Mi,e[Si+1]=-Ct-r*Ai,e[pt]=ut-r*ns,e[pt+1]=-tt+r*Nt}}let d=n>>>1;for(let _=2;_<d;_+=2)e[n-_]=e[_],e[n-_+1]=-e[_+1]}_singleRealTransform2(e,s,r,n,o){let i=e[n],a=e[n+o];s[r]=i+a,s[r+1]=0,s[r+2]=i-a,s[r+3]=0}_singleRealTransform4(e,s,r,n,o,i){let a=o*2,l=o*3,c=e[n],u=e[n+o],p=e[n+a],d=e[n+l],_=c+p,f=c-p,h=u+d,x=i*(u-d);s[r]=_+h,s[r+1]=0,s[r+2]=f,s[r+3]=-x,s[r+4]=_-h,s[r+5]=0,s[r+6]=f,s[r+7]=x}},fc=class{constructor(e){let s=2*(e-1),r=2*(2*e-1),n=2**Math.ceil(Math.log2(r));this.bufferSize=n,this._a=s;let o=new Float64Array(r),i=new Float64Array(n);this._chirpBuffer=new Float64Array(n),this._buffer1=new Float64Array(n),this._buffer2=new Float64Array(n),this._outBuffer1=new Float64Array(n),this._outBuffer2=new Float64Array(n);let a=-2*Math.PI/e,l=Math.cos(a),c=Math.sin(a);for(let u=0;u<r>>1;++u){let p=(u+1-e)**2/2,d=Math.sqrt(l**2+c**2)**p,_=p*Math.atan2(c,l),f=2*u;o[f]=d*Math.cos(_),o[f+1]=d*Math.sin(_),i[f]=o[f],i[f+1]=-o[f+1]}this._slicedChirpBuffer=o.subarray(s,r),this._f=new $i(n>>1),this._f.transform(this._chirpBuffer,i)}_transform(e,s,r){let n=this._buffer1,o=this._buffer2,i=this._outBuffer1,a=this._outBuffer2,l=this._chirpBuffer,c=this._slicedChirpBuffer,u=this._a;if(r)for(let p=0;p<c.length;p+=2){let d=p+1,_=p>>1,f=s[_];n[p]=f*c[p],n[d]=f*c[d]}else for(let p=0;p<c.length;p+=2){let d=p+1;n[p]=s[p]*c[p]-s[d]*c[d],n[d]=s[p]*c[d]+s[d]*c[p]}this._f.transform(i,n);for(let p=0;p<l.length;p+=2){let d=p+1;o[p]=i[p]*l[p]-i[d]*l[d],o[d]=i[p]*l[d]+i[d]*l[p]}this._f.inverseTransform(a,o);for(let p=0;p<a.length;p+=2){let d=a[p+u],_=a[p+u+1],f=c[p],h=c[p+1];e[p]=d*f-_*h,e[p+1]=d*h+_*f}}transform(e,s){this._transform(e,s,!1)}realTransform(e,s){this._transform(e,s,!0)}},Ri=class{constructor(e){this.fft_length=e,this.isPowerOfTwo=Xw(e),this.isPowerOfTwo?(this.fft=new $i(e),this.outputBufferSize=2*e):(this.fft=new fc(e),this.outputBufferSize=this.fft.bufferSize)}realTransform(e,s){this.fft.realTransform(e,s)}transform(e,s){this.fft.transform(e,s)}};function Qw(t,e){if(e%2===0||e<=0)throw new Error("Window size must be a positive odd number");let s=new t.constructor(t.length),r=new t.constructor(e),n=Math.floor(e/2);for(let o=0;o<t.length;++o){let i=0;for(let a=-n;a<=n;++a){let l=o+a;l<0?l=Math.abs(l):l>=t.length&&(l=2*(t.length-1)-l),r[i++]=t[l]}r.sort(),s[o]=r[n]}return s}function us(t,e){let s=Math.pow(10,e);return Math.round(t*s)/s}function Yw(t){let e=Math.round(t);return Math.abs(t)%1===.5?e%2===0?e:e-1:e}function Jw(t){let e=t.length,s=t[0].length,r=[e+1,s+1],n=Array.from({length:r[0]},()=>Array(r[1]).fill(1/0));n[0][0]=0;let o=Array.from({length:r[0]},()=>Array(r[1]).fill(-1));for(let u=1;u<r[1];++u)for(let p=1;p<r[0];++p){let d=n[p-1][u-1],_=n[p-1][u],f=n[p][u-1],h,x;d<_&&d<f?(h=d,x=0):_<d&&_<f?(h=_,x=1):(h=f,x=2),n[p][u]=t[p-1][u-1]+h,o[p][u]=x}for(let u=0;u<r[1];++u)o[0][u]=2;for(let u=0;u<r[0];++u)o[u][0]=1;let i=e,a=s,l=[],c=[];for(;i>0||a>0;)switch(l.push(i-1),c.push(a-1),o[i][a]){case 0:--i,--a;break;case 1:--i;break;case 2:--a;break;default:throw new Error(`Internal error in dynamic time warping. Unexpected trace[${i}, ${a}]. Please file a bug report.`)}return l.reverse(),c.reverse(),[l,c]}var Zw=(function(){let t=null;return function(e){if(!t){t=new Float32Array(65536);let o=new ArrayBuffer(4),i=new Uint32Array(o),a=new Float32Array(o);for(let l=0;l<t.length;++l){let c=0,u=(l&32768)<<16,p=(l&31744)>>10,d=l&1023;if(p===31)c=u|2139095040|d<<13;else if(p===0)if(d===0)c=u;else{let _=113;for(;(d&1024)===0;)d<<=1,--_;d&=-1025,c=u|_<<23|d<<13}else c=u|p+112<<23|d<<13;i[0]=c,t[l]=a[0]}}let s=e.length,r=t,n=new Float32Array(s);for(let o=0;o<s;++o)n[o]=r[e[o]];return n}})();var hc={};As(hc,{default:()=>av});var av={};import*as lv from"onnxruntime-web/webgpu";async function ey(t){let e=t.split("/").pop(),s;try{if(s=await _t(),s){let n=await s.match(t);if(n)return n}}catch(n){L.warn(`Failed to load ${e} from cache:`,n)}let r=await H.fetch(t);if(!r.ok)throw new Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);if(s)try{await s.put(t,r.clone())}catch(n){L.warn(`Failed to cache ${e}:`,n)}return r}async function ty(t){let e=await ey(t);if(!e||typeof e=="string")return null;try{return await e.arrayBuffer()}catch(s){return L.warn("Failed to read WASM binary:",s),null}}async function sy(t){let e=await ey(t);if(!e||typeof e=="string")return null;try{let s=await e.text(),r=t.split("/").slice(0,-1).join("/");s=s.replaceAll("import.meta.url",`"${r}"`),s=s.replaceAll("globalThis.process?.versions?.node","false");let n=new Blob([s],{type:"text/javascript"});return URL.createObjectURL(n)}catch(s){return L.warn("Failed to read WASM binary:",s),null}}function xc(t){return St(t,["blob:"])}function gc(t){let e;if(typeof location<"u"&&location.href)e=location.href;else if(typeof import.meta<"u"&&import.meta.url)e=import.meta.url;else return t;return new URL(t,e).href}import{Tensor as uy}from"onnxruntime-common";var cv=Object.freeze({auto:null,gpu:null,cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",coreml:"coreml",webnn:{name:"webnn",deviceType:"cpu"},"webnn-npu":{name:"webnn",deviceType:"npu"},"webnn-gpu":{name:"webnn",deviceType:"gpu"},"webnn-cpu":{name:"webnn",deviceType:"cpu"}});function iy(t){return t<=Ue.DEBUG?0:t<=Ue.INFO?2:t<=Ue.WARNING||t<=Ue.ERROR?3:4}var uv={0:"verbose",1:"info",2:"warning",3:"error",4:"fatal"},Qe=[],wc,Ps,ry=Symbol.for("onnxruntime");if(ry in globalThis)Ps=globalThis[ry];else if(Z.IS_NODE_ENV){switch(Ps=hc,process.platform){case"win32":Qe.push("dml");break;case"linux":process.arch==="x64"&&Qe.push("cuda");break;case"darwin":Qe.push("coreml");break}Qe.push("webgpu"),Qe.push("cpu"),wc=["cpu"]}else Ps=lv,Z.IS_WEBNN_AVAILABLE&&Qe.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),Z.IS_WEBGPU_AVAILABLE&&Qe.push("webgpu"),Qe.push("wasm"),wc=["wasm"];var pv=Ps.InferenceSession;function ay(t=null){if(!t)return wc;switch(t){case"auto":return Qe;case"gpu":return Qe.filter(e=>["webgpu","cuda","dml","webnn-gpu"].includes(e))}if(Qe.includes(t))return[cv[t]??t];throw new Error(`Unsupported device: "${t}". Should be one of: ${Qe.join(", ")}.`)}var ly=Z.IS_BROWSER_ENV||Z.IS_WEBWORKER_ENV,ny=Promise.resolve(),zs=null;async function dv(){return zs||(H.useWasmCache&&typeof Ne?.wasm?.wasmPaths=="object"&&Ne?.wasm?.wasmPaths?.wasm&&Ne?.wasm?.wasmPaths?.mjs?(zs=(async()=>{let e=Ne.wasm.wasmPaths;await Promise.all([e.wasm&&!xc(e.wasm)?(async()=>{try{let s=await ty(gc(e.wasm));s&&(Ne.wasm.wasmBinary=s)}catch(s){L.warn("Failed to pre-load WASM binary:",s)}})():Promise.resolve(),e.mjs&&!xc(e.mjs)?(async()=>{try{let s=await sy(gc(e.mjs));s&&(Ne.wasm.wasmPaths.mjs=s)}catch(s){L.warn("Failed to pre-load WASM factory:",s)}})():Promise.resolve()])})(),zs):(zs=Promise.resolve(),zs))}async function Fi(t,e,s){await dv();let r=iy(H.logLevel??Ue.WARNING),n=()=>pv.create(t,{logSeverityLevel:r,...e}),o=await(ly?ny=ny.then(n):n());return o.config=s,o}var oy=Promise.resolve();async function Di(t,e){let s=()=>t.run(e);return await(ly?oy=oy.then(s):s())}function ji(t){return t instanceof Ps.Tensor}var Ne=Ps?.env;if(Ne?.wasm){if(!(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope)&&Ne.versions?.web&&!Ne.wasm.wasmPaths){let t=`https://cdn.jsdelivr.net/npm/onnxruntime-web@${Ne.versions.web}/dist/`;Ne.wasm.wasmPaths=Z.IS_SAFARI?{mjs:`${t}ort-wasm-simd-threaded.mjs`,wasm:`${t}ort-wasm-simd-threaded.wasm`}:{mjs:`${t}ort-wasm-simd-threaded.asyncify.mjs`,wasm:`${t}ort-wasm-simd-threaded.asyncify.wasm`}}Ne.wasm.proxy=!1}Ne?.webgpu&&(Ne.webgpu.powerPreference="high-performance");function kr(){return Ne?.wasm?.proxy}function cy(t){let e=iy(t);Ne.logLevel=uv[e]}cy(H.logLevel??Ue.WARNING);H.backends.onnx={...Ne,setLogLevel:cy};var $t=async(t,e,s)=>{let r=await Fi(new Uint8Array(t),e);return(async n=>{let o=kr(),i=Object.fromEntries(Object.entries(n).map(([l,c])=>[l,(o?c.clone():c).ort_tensor])),a=await Di(r,i);return Array.isArray(s)?s.map(l=>new S(a[l])):new S(a[s])})},mt=class{static session_options={};static get nearest_interpolate_4d(){return this._nearest_interpolate_4d||(this._nearest_interpolate_4d=$t([8,10,18,0,58,129,1,10,41,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,18,10,4,109,111,100,101,34,7,110,101,97,114,101,115,116,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,21],this.session_options,"y")),this._nearest_interpolate_4d}static get bilinear_interpolate_4d(){return this._bilinear_interpolate_4d||(this._bilinear_interpolate_4d=$t([8,9,18,0,58,128,1,10,40,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,17,10,4,109,111,100,101,34,6,108,105,110,101,97,114,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bilinear_interpolate_4d}static get bicubic_interpolate_4d(){return this._bicubic_interpolate_4d||(this._bicubic_interpolate_4d=$t([8,9,18,0,58,127,10,39,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,16,10,4,109,111,100,101,34,5,99,117,98,105,99,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bicubic_interpolate_4d}static get matmul(){return this._matmul||(this._matmul=$t([8,9,18,0,58,55,10,17,10,1,97,10,1,98,18,1,99,34,6,77,97,116,77,117,108,18,1,114,90,9,10,1,97,18,4,10,2,8,1,90,9,10,1,98,18,4,10,2,8,1,98,9,10,1,99,18,4,10,2,8,1,66,2,16,20],this.session_options,"c")),this._matmul}static get stft(){return this._stft||(this._stft=$t([8,7,18,0,58,148,1,10,38,10,1,115,10,1,106,10,1,119,10,1,108,18,1,111,34,4,83,84,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,115,90,26,10,1,115,18,21,10,19,8,1,18,15,10,3,18,1,98,10,3,18,1,115,10,3,18,1,99,90,11,10,1,106,18,6,10,4,8,7,18,0,90,16,10,1,119,18,11,10,9,8,1,18,5,10,3,18,1,119,90,11,10,1,108,18,6,10,4,8,7,18,0,98,31,10,1,111,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,102,10,3,18,1,100,10,3,18,1,99,66,2,16,17],this.session_options,"o")),this._stft}static get rfft(){return this._rfft||(this._rfft=$t([8,9,18,0,58,97,10,33,10,1,120,10,0,10,1,97,18,1,121,34,3,68,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,100,90,21,10,1,120,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,90,11,10,1,97,18,6,10,4,8,7,18,0,98,21,10,1,121,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,66,2,16,20],this.session_options,"y")),this._rfft}static get top_k(){return this._top_k||(this._top_k=$t([8,10,18,0,58,73,10,18,10,1,120,10,1,107,18,1,118,18,1,105,34,4,84,111,112,75,18,1,116,90,9,10,1,120,18,4,10,2,8,1,90,15,10,1,107,18,10,10,8,8,7,18,4,10,2,8,1,98,9,10,1,118,18,4,10,2,8,1,98,9,10,1,105,18,4,10,2,8,7,66,2,16,21],this.session_options,["v","i"])),this._top_k}static get slice(){return this._slice||(this._slice=$t([8,7,18,0,58,96,10,25,10,1,120,10,1,115,10,1,101,10,1,97,10,1,116,18,1,121,34,5,83,108,105,99,101,18,1,114,90,9,10,1,120,18,4,10,2,8,1,90,9,10,1,115,18,4,10,2,8,7,90,9,10,1,101,18,4,10,2,8,7,90,9,10,1,97,18,4,10,2,8,7,90,9,10,1,116,18,4,10,2,8,7,98,9,10,1,121,18,4,10,2,8,1,66,2,16,13],this.session_options,"y")),this._slice}};var py=Object.freeze({auto:"auto",gpu:"gpu",cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",coreml:"coreml",webnn:"webnn","webnn-npu":"webnn-npu","webnn-gpu":"webnn-gpu","webnn-cpu":"webnn-cpu"}),yc=Z.IS_NODE_ENV?"cpu":"wasm";function Ui(t,e,{warn:s}={}){return t?typeof t=="string"?t:t.hasOwnProperty(e)?t[e]:(s&&s(`device not specified for "${e}". Using the default device (${yc}).`),yc):yc}var fy=(function(){let t;return async function(){if(t===void 0)if(!Z.IS_WEBGPU_AVAILABLE)t=!1;else try{t=(await navigator.gpu.requestAdapter()).features.has("shader-f16")}catch{t=!1}return t}})(),Le=Object.freeze({auto:"auto",fp32:"fp32",fp16:"fp16",q8:"q8",int8:"int8",uint8:"uint8",q4:"q4",bnb4:"bnb4",q4f16:"q4f16"}),dy=Le.fp32,_y=Object.freeze({[py.wasm]:Le.q8}),vr=Object.freeze({[Le.fp32]:"",[Le.fp16]:"_fp16",[Le.int8]:"_int8",[Le.uint8]:"_uint8",[Le.q8]:"_quantized",[Le.q4]:"_q4",[Le.q4f16]:"_q4f16",[Le.bnb4]:"_bnb4"});function Bi(t,e,s,{configDtype:r=null,warn:n}={}){let o,i=!1;t&&typeof t!="string"?t.hasOwnProperty(e)?o=t[e]:(o=null,i=!0):o=t;let a;if(o===Le.auto){if(r){let l=typeof r=="string"?r:r?.[e];if(l&&l!==Le.auto&&Le.hasOwnProperty(l))return l}a=_y[s]??dy}else o&&Le.hasOwnProperty(o)?a=o:a=_y[s]??dy;return i&&n&&n(`dtype not specified for "${e}". Using the default dtype (${a}) for this device (${s}).`),a}var Cs=Object.freeze({float32:Float32Array,float16:typeof Float16Array<"u"?Float16Array:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array,uint4:Uint8Array,int4:Int8Array});var qi=class{constructor(e){this._mt=new Uint32Array(624),this._idx=625,this._gauss_next=null,this._random_fn=this.random.bind(this),this.seed(e)}seed(e){if(e==null)if(Z.IS_CRYPTO_AVAILABLE){let a=new Uint32Array(1);crypto.getRandomValues(a),e=a[0]}else e=Date.now()>>>0;let s=this._mt,r=(a,l)=>Math.imul(a,l)>>>0,n=[];for(let a=e||0;a>0;a=Math.floor(a/4294967296))n.push(a&4294967295);n.length||n.push(0),s[0]=19650218;for(let a=1;a<624;++a)s[a]=r(1812433253,s[a-1]^s[a-1]>>>30)+a>>>0;let o=1,i=0;for(let a=Math.max(624,n.length);a>0;--a,++o,++i)o>=624&&(s[0]=s[623],o=1),i>=n.length&&(i=0),s[o]=(s[o]^r(s[o-1]^s[o-1]>>>30,1664525))+n[i]+i>>>0;for(let a=623;a>0;--a,++o)o>=624&&(s[0]=s[623],o=1),s[o]=(s[o]^r(s[o-1]^s[o-1]>>>30,1566083941))-o>>>0;s[0]=2147483648,this._idx=624,this._gauss_next=null}_int32(){let e=this._mt;if(this._idx>=624){for(let r=0;r<624;++r){let n=e[r]&2147483648|e[(r+1)%624]&2147483647;e[r]=(e[(r+397)%624]^n>>>1^(n&1?2567483615:0))>>>0}this._idx=0}let s=e[this._idx++];return s^=s>>>11,s^=s<<7&2636928640,s^=s<<15&4022730752,s^=s>>>18,s>>>0}random(){return((this._int32()>>>5)*67108864+(this._int32()>>>6))/9007199254740992}gauss(e=0,s=1){let r=this._gauss_next;if(this._gauss_next=null,r===null){let n=this.random()*2*Math.PI,o=Math.sqrt(-2*Math.log(1-this.random()));r=Math.cos(n)*o,this._gauss_next=Math.sin(n)*o}return e+r*s}shuffle(e){for(let s=e.length-1;s>0;--s){let r=32-Math.clz32(s+1),n=this._int32()>>>32-r;for(;n>s;)n=this._int32()>>>32-r;let o=e[s];e[s]=e[n],e[n]=o}}choices(e,s){return e[my(this._random_fn,s)]}};function my(t,e){let s=0;for(let n=0;n<e.length;++n)s+=e[n];let r=t()*s;for(let n=0;n<e.length;++n)if(r-=e[n],r<0)return n;return e.length-1}var ht=new qi,ps=Object.freeze({Random:qi,seed:ht.seed.bind(ht),random:ht.random.bind(ht),gauss:ht.gauss.bind(ht),shuffle:ht.shuffle.bind(ht),choices:ht.choices.bind(ht)}),hy=t=>my(ps.random,t);var S=class t{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return ji(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new uy(e[0],e[1],e[2]),new Proxy(this,{get:(s,r)=>{if(typeof r=="string"){let n=Number(r);if(Number.isInteger(n))return s._getitem(n)}return s[r]},set:(s,r,n)=>s[r]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){let[e,...s]=this.dims;if(s.length>0){let r=s.reduce((n,o)=>n*o);for(let n=0;n<e;++n)yield this._subarray(n,r,s)}else yield*this.data}_getitem(e){let[s,...r]=this.dims;if(e=xt(e,s),r.length>0){let n=r.reduce((o,i)=>o*i);return this._subarray(e,n,r)}else return new t(this.type,[this.data[e]],r)}indexOf(e){let s=this.data;for(let r=0;r<s.length;++r)if(s[r]==e)return r;return-1}_subarray(e,s,r){let n=e*s,o=(e+1)*s,i="subarray"in this.data?this.data.subarray(n,o):this.data.slice(n,o);return new t(this.type,i,r)}item(){let e=this.data;if(e.length!==1)throw new Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return _v(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){let e=this.data;for(let s=0;s<e.length;++s)e[s]=1/(1+Math.exp(-e[s]));return this}map(e){return this.clone().map_(e)}map_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]=e(s[r],r,s);return this}mul(e){return this.clone().mul_(e)}mul_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]*=e;return this}div(e){return this.clone().div_(e)}div_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]/=e;return this}add(e){return this.clone().add_(e)}add_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]+=e;return this}sub(e){return this.clone().sub_(e)}sub_(e){let s=this.data;for(let r=0;r<s.length;++r)s[r]-=e;return this}clone(){return new t(this.type,this.data.slice(),this.dims.slice())}slice(...e){let s=[],r=[];for(let u=0;u<this.dims.length;++u){let p=e[u];if(p==null)r.push([0,this.dims[u]]),s.push(this.dims[u]);else if(typeof p=="number")p=xt(p,this.dims[u],u),r.push([p,p+1]);else if(Array.isArray(p)&&p.length===2){let[d,_]=p;if(d=d===null?0:xt(d,this.dims[u],u,!1),_=_===null?this.dims[u]:xt(_,this.dims[u],u,!1),d>_)throw new Error(`Invalid slice: ${p}`);let f=[Math.max(d,0),Math.min(_,this.dims[u])];r.push(f),s.push(f[1]-f[0])}else throw new Error(`Invalid slice: ${p}`)}let n=r.map(([u,p])=>p-u),o=n.reduce((u,p)=>u*p),i=this.data,a=new i.constructor(o),l=this.stride(),c=!0;for(let u=1;u<n.length;++u)if(r[u][0]!==0||r[u][1]!==this.dims[u]){c=!1;break}if(c){let u=r[0][0]*l[0],p=r[0][1]*l[0];if(ArrayBuffer.isView(i))a.set(i.subarray(u,p));else if(Array.isArray(i)){let d=i.slice(u,p);for(let _=0;_<d.length;++_)a[_]=d[_]}else throw new Error("Unsupported data type for slicing")}else for(let u=0;u<o;++u){let p=0;for(let d=n.length-1,_=u;d>=0;--d){let f=n[d];p+=(_%f+r[d][0])*l[d],_=Math.floor(_/f)}a[u]=i[p]}return new t(this.type,a,s)}permute(...e){return fv(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,s=!1){return this.norm(1,e,s)}norm(e="fro",s=null,r=!1){if(e==="fro")e=2;else if(typeof e=="string")throw Error(`Unsupported norm: ${e}`);let n=this.data,o=(c,u)=>c+u**e;if(s===null){let c=n.reduce(o,0)**(1/e);return new t(this.type,[c],[])}let[i,a,l]=Er(o,this,s,r);if(e!==1)for(let c=0;c<a.length;++c)a[c]=a[c]**(1/e);return new t(i,a,l)}normalize_(e=2,s=1){s=xt(s,this.dims.length);let r=this.norm(e,s,!0),n=this.data,o=r.data;for(let i=0;i<n.length;++i){let a=0;for(let l=this.dims.length-1,c=i,u=1;l>=0;--l){let p=this.dims[l];if(l!==s){let d=c%p;a+=d*u,u*=this.dims[l]}c=Math.floor(c/p)}n[i]/=o[a]}return this}normalize(e=2,s=1){return this.clone().normalize_(e,s)}stride(){return bc(this.dims)}squeeze(e=null){return new t(this.type,this.data,xy(this.dims,e))}squeeze_(e=null){return this.dims=xy(this.dims,e),this}unsqueeze(e){return new t(this.type,this.data,gy(this.dims,e))}unsqueeze_(e){return this.dims=gy(this.dims,e),this}flatten_(e=0,s=-1){s=(s+this.dims.length)%this.dims.length;let r=this.dims.slice(0,e),n=this.dims.slice(e,s+1),o=this.dims.slice(s+1);return this.dims=[...r,n.reduce((i,a)=>i*a,1),...o],this}flatten(e=0,s=-1){return this.clone().flatten_(e,s)}view(...e){let s=-1;for(let n=0;n<e.length;++n)if(e[n]===-1){if(s!==-1)throw new Error("Only one dimension can be inferred");s=n}let r=this.data;if(s!==-1){let n=e.reduce((o,i,a)=>a!==s?o*i:o,1);e[s]=r.length/n}return new t(this.type,r,e)}neg_(){let e=this.data;for(let s=0;s<e.length;++s)e[s]=-e[s];return this}neg(){return this.clone().neg_()}gt(e){let s=new Uint8Array(this.data.length),r=this.data;for(let n=0;n<r.length;++n)s[n]=r[n]>e?1:0;return new t("bool",s,this.dims)}lt(e){let s=new Uint8Array(this.data.length),r=this.data;for(let n=0;n<r.length;++n)s[n]=r[n]<e?1:0;return new t("bool",s,this.dims)}clamp_(e,s){let r=this.data;for(let n=0;n<r.length;++n)r[n]=Math.min(Math.max(r[n],e),s);return this}clamp(e,s){return this.clone().clamp_(e,s)}round_(){let e=this.data;for(let s=0;s<e.length;++s)e[s]=Math.round(e[s]);return this}round(){return this.clone().round_()}mean(e=null,s=!1){return Vi(this,e,s)}min(e=null,s=!1){if(e===null){let i=br(this.data)[0];return new t(this.type,[i],[])}let[r,n,o]=Er((i,a)=>Math.min(i,a),this,e,s,1/0);return new t(r,n,o)}max(e=null,s=!1){if(e===null){let i=le(this.data)[0];return new t(this.type,[i],[])}let[r,n,o]=Er((i,a)=>Math.max(i,a),this,e,s,-1/0);return new t(r,n,o)}argmin(e=null,s=!1){if(e!==null)throw new Error("`dim !== null` not yet implemented.");let r=br(this.data)[1];return new t("int64",[BigInt(r)],[])}argmax(e=null,s=!1){if(e!==null)throw new Error("`dim !== null` not yet implemented.");let r=le(this.data)[1];return new t("int64",[BigInt(r)],[])}repeat(...e){if(e.length<this.dims.length)throw new Error(`Number of dimensions of repeat dims (${e.length}) cannot be smaller than number of dimensions of tensor (${this.dims.length})`);if(e.every(u=>u===1)){if(e.length===this.dims.length)return this.clone();let u=e.length-this.dims.length,p=Array(u).fill(1).concat(this.dims);return new t(this.type,this.data.slice(),p)}let s=e.length-this.dims.length,r=Array(s).fill(1).concat(this.dims),n=r.map((u,p)=>u*e[p]),o=n.reduce((u,p)=>u*p,1),i=this.data,a=new i.constructor(o),l=bc(r),c=bc(n);for(let u=0;u<o;++u){let p=u,d=0;for(let _=0;_<n.length;++_){let f=Math.floor(p/c[_]);p=p%c[_];let h=f%r[_];d+=h*l[_]}a[u]=i[d]}return new t(this.type,a,n)}tile(...e){if(e.length<this.dims.length){let s=this.dims.length-e.length;e=Array(s).fill(1).concat(e)}return this.repeat(...e)}to(e){if(this.type===e)return this;if(!Cs.hasOwnProperty(e))throw new Error(`Unsupported type: ${e}`);let s,r=["int64","uint64"].includes(this.type),n=["int64","uint64"].includes(e);if(r&&!n)s=Number;else if(!r&&n)["float16","float32","float64"].includes(this.type)?s=o=>BigInt(Math.floor(o)):s=BigInt;else if(this.type==="float16"&&e=="float32"&&this.data instanceof Uint16Array)return new t(e,Zw(this.data),this.dims);return new t(e,Cs[e].from(this.data,s),this.dims)}};function _v(t,e){let s=t.length,r=e.reduce((o,i)=>o*i);if(s!==r)throw Error(`cannot reshape array of size ${s} into shape (${e})`);let n=t;for(let o=e.length-1;o>=0;o--)n=n.reduce((i,a)=>{let l=i[i.length-1];return l.length<e[o]?l.push(a):i.push([a]),i},[[]]);return n[0]}function fv(t,e){let[s,r]=Hw(t.data,t.dims,e);return new S(t.type,s,r)}function kc(t,[e,s],r="bilinear",n=!1){let o=t.dims.at(-3)??1,i=t.dims.at(-2),a=t.dims.at(-1),l=Vw(t.data,[o,i,a],[e,s],r,n);return new S(t.type,l,[o,e,s])}async function Ye(t,{size:e=null,mode:s="bilinear"}={}){if(t.dims.length!==4)throw new Error("`interpolate_4d` currently only supports 4D input.");if(!e)throw new Error("`interpolate_4d` requires a `size` argument.");let r;if(e.length===2)r=[...t.dims.slice(0,2),...e];else if(e.length===3)r=[t.dims[0],...e];else if(e.length===4)r=e;else throw new Error("`size` must be of length 2, 3, or 4.");let n;if(s==="nearest")n=await mt.nearest_interpolate_4d;else if(s==="bilinear")n=await mt.bilinear_interpolate_4d;else if(s==="bicubic")n=await mt.bicubic_interpolate_4d;else throw new Error(`Unsupported mode: ${s}`);let o=new S("int64",new BigInt64Array(r.map(BigInt)),[r.length]);return await n({x:t,s:o})}async function wy(t,e){return await(await mt.matmul)({a:t,b:e})}async function OS(t,e){return await(await mt.rfft)({x:t,a:e})}async function at(t,e){let s=await mt.top_k;return e==null?e=t.dims.at(-1):e=Math.min(e,t.dims.at(-1)),await s({x:t,k:new S("int64",[BigInt(e)],[1])})}var Gi=t=>new S("int64",t,[t.length]);async function Wi(t,e,s,r,n){return await(await mt.slice)({x:t,s:Gi(e),e:Gi(s),a:Gi(r),t:Gi(n??new Array(r.length).fill(1))})}function yy(t,e){let s=t.data,r=e.data,n=[t.dims[0],t.dims[2]],o=new s.constructor(n[0]*n[1]),[i,a,l]=t.dims,c=0;for(let u=0;u<i;++u){let p=u*l*a;for(let d=0;d<l;++d){let _=0,f=0,h=u*a,x=p+d;for(let w=0;w<a;++w){let y=Number(r[h+w]);f+=y,_+=s[x+w*l]*y}let g=_/f;o[c++]=g}}return new S(t.type,o,n)}function IS(t,e,{eps:s=1e-5}={}){if(t.dims.length!==2)throw new Error("`layer_norm` currently only supports 2D input.");let[r,n]=t.dims;if(e.length!==1&&e[0]!==n)throw new Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");let[o,i]=vc(t,1,0,!0),a=o.data,l=i.data,c=t.data,u=new c.constructor(c.length);for(let p=0;p<r;++p){let d=p*n;for(let _=0;_<n;++_){let f=d+_;u[f]=(c[f]-l[p])/(a[p]+s)}}return new S(t.type,u,t.dims)}function xy(t,e){return t=t.slice(),e===null?t=t.filter(s=>s!==1):typeof e=="number"?t[e]===1&&t.splice(e,1):Array.isArray(e)&&(t=t.filter((s,r)=>s!==1||!e.includes(r))),t}function gy(t,e){return e=xt(e,t.length+1),t=t.slice(),t.splice(e,0,1),t}function xt(t,e,s=null,r=!0){if(t<-e||t>=e){if(r)throw new Error(`IndexError: index ${t} is out of bounds for dimension${s===null?"":" "+s} with size ${e}`);return t<-e?0:e}return t<0&&(t=(t%e+e)%e),t}function ie(t,e=0){e=xt(e,t[0].dims.length);let s=t[0].dims.slice();s[e]=t.reduce((i,a)=>i+a.dims[e],0);let r=s.reduce((i,a)=>i*a,1),n=new t[0].data.constructor(r),o=t[0].type;if(e===0){let i=0;for(let a of t){let l=a.data;n.set(l,i),i+=l.length}}else{let i=0;for(let a=0;a<t.length;++a){let{data:l,dims:c}=t[a];for(let u=0;u<l.length;++u){let p=0;for(let d=c.length-1,_=u,f=1;d>=0;--d){let h=c[d],x=_%h;d===e&&(x+=i),p+=x*f,f*=s[d],_=Math.floor(_/h)}n[p]=l[u]}i+=c[e]}}return new S(o,n,s)}function Je(t,e=0){return ie(t.map(s=>s.unsqueeze(e)),e)}function Er(t,e,s,r=!1,n=null){let o=e.data,i=e.dims;s=xt(s,i.length);let a=i.slice();a[s]=1;let l=new o.constructor(o.length/i[s]);n!==null&&l.fill(n);for(let c=0;c<o.length;++c){let u=0;for(let p=i.length-1,d=c,_=1;p>=0;--p){let f=i[p];if(p!==s){let h=d%f;u+=h*_,_*=a[p]}d=Math.floor(d/f)}l[u]=t(l[u],o[c],c,u)}return r||a.splice(s,1),[e.type,l,a]}function vc(t,e=null,s=1,r=!1){let n=t.data,o=t.dims;if(e===null){let _=n.reduce((g,w)=>g+w,0)/n.length,f=Math.sqrt(n.reduce((g,w)=>g+(w-_)**2,0)/(n.length-s)),h=new S(t.type,[_],[]);return[new S(t.type,[f],[]),h]}e=xt(e,o.length);let i=Vi(t,e,r),a=i.data,[l,c,u]=Er((d,_,f,h)=>d+(_-a[h])**2,t,e,r);for(let d=0;d<c.length;++d)c[d]=Math.sqrt(c[d]/(o[e]-s));return[new S(l,c,u),i]}function Vi(t,e=null,s=!1){let r=t.dims,n=t.data;if(e===null){let l=n.reduce((c,u)=>c+u,0);return new S(t.type,[l/n.length],[])}e=xt(e,r.length);let[o,i,a]=Er((l,c)=>l+c,t,e,s);if(r[e]!==1)for(let l=0;l<i.length;++l)i[l]/=r[e];return new S(o,i,a)}function bc(t){let e=new Array(t.length);for(let s=t.length-1,r=1;s>=0;--s)e[s]=r,r*=t[s];return e}function Ec(t,e,s,r){let n=t.reduce((o,i)=>o*i,1);return new S(s,new r(n).fill(e),t)}function ge(t,e){let s,r;if(typeof e=="number")s="float32",r=Float32Array;else if(typeof e=="bigint")s="int64",r=BigInt64Array;else if(typeof e=="boolean")s="bool",r=Uint8Array;else throw new Error(`Unsupported data type: ${typeof e}`);return Ec(t,e,s,r)}function Ar(t,e){return ge(t.dims,e)}function Oe(t){return Ec(t,1n,"int64",BigInt64Array)}function Hi(t){return Oe(t.dims)}function Ac(t){return Ec(t,0n,"int64",BigInt64Array)}function Mc(t){return Ac(t.dims)}function TS(t){let e=t.reduce((s,r)=>s*r,1);return new S("float32",Float32Array.from({length:e},()=>ps.random()),t)}function by(t){let e=t.reduce((s,r)=>s*r,1);return new S("float32",Float32Array.from({length:e},()=>ps.gauss()),t)}function ky(t,e){if(t.dims.length!==2)throw new Error("The tensor must have 2 dimensions");if(t.dims.at(-1)%8!==0)throw new Error("The last dimension of the tensor must be a multiple of 8");if(!["binary","ubinary"].includes(e))throw new Error("The precision must be either 'binary' or 'ubinary'");let s=e==="binary",r=s?"int8":"uint8",n=s?Int8Array:Uint8Array,o=t.data,i=new n(o.length/8);for(let a=0;a<o.length;++a){let l=o[a]>0?1:0,c=Math.floor(a/8),u=a%8;i[c]|=l<<7-u,s&&u===0&&(i[c]-=128)}return new S(r,i,[t.dims[0],t.dims[1]/8])}async function Ns(t){if(!t)throw new Error("modelId is required for get_tokenizer_files");return(await ft(t,"tokenizer_config.json",{})).exists?["tokenizer.json","tokenizer_config.json"]:[]}async function Sc(t,e){let s=await Ns(t);return await Promise.all(s.map(r=>Te(t,r,!0,e)))}function Oc(t){let e=t.dims;switch(e.length){case 1:return t.tolist();case 2:if(e[0]!==1)throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return t.tolist()[0];default:throw new Error(`Expected tensor to have 1-2 dimensions, got ${e.length}.`)}}var mv=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function hv(t,e,s,r){for(let n of Object.keys(t)){let o=e-t[n].length,i=s(n),a=new Array(o).fill(i);t[n]=r==="right"?Pe(t[n],a):Pe(a,t[n])}}function xv(t,e){for(let s of Object.keys(t))t[s].length=e}function ds(t,...e){for(let s of e){if(!Object.hasOwn(t,s))continue;let r=t[s];if(r)if(typeof r=="object"){if(r.__type==="AddedToken")return r.content;throw Error(`Unknown token: ${r}`)}else return r}return null}function gv(t){let e=[];for(let s of t.get_added_tokens_decoder().values())s.special&&e.push(s);return e}var P=class extends ve{return_token_type_ids=!1;padding_side="right";constructor(e,s){if(super(),this._tokenizerJSON=e,this._tokenizerConfig=s,this._tokenizer=new Mw(e,s),this.config=s,this.padding_side=s.padding_side??this.padding_side,this.mask_token=ds(s,"mask_token"),this.mask_token_id=this._tokenizer.token_to_id(this.mask_token),this.pad_token=ds(s,"pad_token","eos_token"),this.pad_token_id=this._tokenizer.token_to_id(this.pad_token),this.sep_token=ds(s,"sep_token"),this.sep_token_id=this._tokenizer.token_to_id(this.sep_token),this.unk_token=ds(s,"unk_token"),this.unk_token_id=this._tokenizer.token_to_id(this.unk_token),this.bos_token=ds(s,"bos_token"),this.bos_token_id=this._tokenizer.token_to_id(this.bos_token),this.eos_token=ds(s,"eos_token"),this.eos_token_id=this._tokenizer.token_to_id(this.eos_token),this.chat_template=s.chat_template??null,Array.isArray(this.chat_template)){let n=Object.create(null);for(let{name:o,template:i}of this.chat_template){if(typeof o!="string"||typeof i!="string")throw new Error('Chat template must be a list of objects with "name" and "template" properties');n[o]=i}this.chat_template=n}this._compiled_template_cache=new Map;let r=gv(this._tokenizer);this.all_special_ids=r.map(n=>n.id),this.all_special_tokens=r.map(n=>n.content)}static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main"}={}){let a=await Sc(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i});return new this(...a)}get_vocab(){return this._tokenizer.get_vocab()}get model_max_length(){return this._tokenizerConfig.model_max_length??1/0}get add_eos_token(){return this._tokenizerConfig.add_eos_token}get add_bos_token(){return this._tokenizerConfig.add_bos_token}convert_tokens_to_ids(e){return typeof e=="string"?this._tokenizer.token_to_id(e):e.map(s=>this._tokenizer.token_to_id(s))}_call(e,{text_pair:s=null,add_special_tokens:r=!0,padding:n=!1,truncation:o=null,max_length:i=null,return_tensor:a=!0,return_token_type_ids:l=null}={}){let c=Array.isArray(e),u;if(c){if(e.length===0)throw Error("text array must be non-empty");if(s!==null){if(Array.isArray(s)){if(e.length!==s.length)throw Error("text and text_pair must have the same length")}else throw Error("text_pair must also be an array");u=e.map((d,_)=>this._encode_plus(d,{text_pair:s[_],add_special_tokens:r,return_token_type_ids:l}))}else u=e.map(d=>this._encode_plus(d,{add_special_tokens:r,return_token_type_ids:l}))}else{if(e==null)throw Error("text may not be null or undefined");if(Array.isArray(s))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");u=[this._encode_plus(e,{text_pair:s,add_special_tokens:r,return_token_type_ids:l})]}if(i===null?i=this.model_max_length:o===null&&(n===!0?(L.warn("`max_length` is ignored when `padding: true` and there is no truncation strategy. To pad to max length, use `padding: 'max_length'`."),i=this.model_max_length):n===!1&&(L.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation: true` to explicitly truncate examples to max length."),o=!0)),n===!0&&(i=Math.min(le(u.map(d=>d.input_ids.length))[0],i??1/0)),i=Math.min(i,this.model_max_length??1/0),n||o)for(let d=0;d<u.length;++d)u[d].input_ids.length!==i&&(u[d].input_ids.length>i?o&&xv(u[d],i):n&&hv(u[d],i,_=>_==="input_ids"?this.pad_token_id:0,this.padding_side));let p={};if(a){if(!(n&&o)&&u.some(_=>{for(let f of Object.keys(_))if(_[f].length!==u[0][f]?.length)return!0;return!1}))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");let d=[u.length,u[0].input_ids.length];for(let _ of Object.keys(u[0]))p[_]=new S("int64",BigInt64Array.from(u.flatMap(f=>f[_]).map(BigInt)),d)}else{for(let d of Object.keys(u[0]))p[d]=u.map(_=>_[d]);if(!c)for(let d of Object.keys(p))p[d]=p[d][0]}return p}_encode_text(e){return e===null?null:this._tokenizer.encode(e).tokens}_encode_plus(e,{text_pair:s=null,add_special_tokens:r=!0,return_token_type_ids:n=null}={}){let{ids:o,attention_mask:i,token_type_ids:a}=this._tokenizer.encode(e,{text_pair:s,add_special_tokens:r,return_token_type_ids:n??this.return_token_type_ids});return{input_ids:o,attention_mask:i,...a?{token_type_ids:a}:{}}}tokenize(e,{pair:s=null,add_special_tokens:r=!1}={}){return this._tokenizer.tokenize(e,{text_pair:s,add_special_tokens:r})}encode(e,{text_pair:s=null,add_special_tokens:r=!0,return_token_type_ids:n=null}={}){return this._tokenizer.encode(e,{text_pair:s,add_special_tokens:r,return_token_type_ids:n}).ids}batch_decode(e,s={}){return e instanceof S&&(e=e.tolist()),e.map(r=>this.decode(r,s))}decode(e,s={}){if(e instanceof S&&(e=Oc(e)),!Array.isArray(e)||e.length===0||!lw(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,s)}decode_single(e,{skip_special_tokens:s=!1,clean_up_tokenization_spaces:r=null}){return this._tokenizer.decode(e,{skip_special_tokens:s,clean_up_tokenization_spaces:r})}get_chat_template({chat_template:e=null,tools:s=null}={}){if(this.chat_template&&typeof this.chat_template=="object"){let r=this.chat_template;if(e!==null&&Object.hasOwn(r,e))e=r[e];else if(e===null)if(s!==null&&"tool_use"in r)e=r.tool_use;else if("default"in r)e=r.default;else throw Error(`This model has multiple chat templates with no default specified! Please either pass a chat template or the name of the template you wish to use to the 'chat_template' argument. Available template names are ${Object.keys(r).sort()}.`)}else if(e===null)if(this.chat_template)e=this.chat_template;else throw Error("Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating");return e}apply_chat_template(e,{tools:s=null,documents:r=null,chat_template:n=null,add_generation_prompt:o=!1,tokenize:i=!0,padding:a=!1,truncation:l=!1,max_length:c=null,return_tensor:u=!0,return_dict:p=!0,tokenizer_kwargs:d={},..._}={}){if(n=this.get_chat_template({chat_template:n,tools:s}),typeof n!="string")throw Error(`chat_template must be a string, but got ${typeof n}`);let f=this._compiled_template_cache.get(n);f===void 0&&(f=new Fw(n),this._compiled_template_cache.set(n,f));let h=Object.create(null);for(let g of mv){let w=ds(this.config,g);w&&(h[g]=w)}let x=f.render({messages:e,add_generation_prompt:o,tools:s,documents:r,...h,..._});if(i){let g=this._call(x,{add_special_tokens:!1,padding:a,truncation:l,max_length:c,return_tensor:u,...d});return p?g:g.input_ids}return x}};function Ls(t,e,s,r){if(!("language_codes"in t)||!Array.isArray(t.language_codes))throw new Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!("languageRegex"in t)||!(t.languageRegex instanceof RegExp))throw new Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!("lang_to_token"in t)||typeof t.lang_to_token!="function")throw new Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");let n=r.src_lang,o=r.tgt_lang;if(!t.language_codes.includes(o))throw new Error(`Target language code "${o}" is not valid. Must be one of: {${t.language_codes.join(", ")}}`);if(n!==void 0){if(!t.language_codes.includes(n))throw new Error(`Source language code "${n}" is not valid. Must be one of: {${t.language_codes.join(", ")}}`);for(let i of t._tokenizer.post_processor.config.single)if("SpecialToken"in i&&t.languageRegex.test(i.SpecialToken.id)){i.SpecialToken.id=t.lang_to_token(n);break}}return r.forced_bos_token_id=t._tokenizer.token_to_id(t.lang_to_token(o)),t._call(e,s)}var wu={};As(wu,{AlbertTokenizer:()=>Ic,AutoTokenizer:()=>$,BartTokenizer:()=>Tc,BertTokenizer:()=>zc,BlenderbotSmallTokenizer:()=>Pc,BlenderbotTokenizer:()=>Cc,BloomTokenizer:()=>Nc,CLIPTokenizer:()=>$c,CamembertTokenizer:()=>Lc,CodeGenTokenizer:()=>Fc,CodeLlamaTokenizer:()=>Rc,CohereTokenizer:()=>Dc,ConvBertTokenizer:()=>jc,DebertaTokenizer:()=>Bc,DebertaV2Tokenizer:()=>Uc,DistilBertTokenizer:()=>qc,ElectraTokenizer:()=>Gc,EsmTokenizer:()=>Wc,FalconTokenizer:()=>Vc,GPT2Tokenizer:()=>Xc,GPTNeoXTokenizer:()=>Kc,GemmaTokenizer:()=>Hc,HerbertTokenizer:()=>Qc,LlamaTokenizer:()=>Yc,M2M100Tokenizer:()=>Jc,MBart50Tokenizer:()=>eu,MBartTokenizer:()=>Mr,MPNetTokenizer:()=>ru,MarianTokenizer:()=>Zc,MgpstrTokenizer:()=>tu,MobileBertTokenizer:()=>su,NllbTokenizer:()=>nu,NougatTokenizer:()=>ou,PreTrainedTokenizer:()=>P,Qwen2Tokenizer:()=>iu,RoFormerTokenizer:()=>lu,RobertaTokenizer:()=>au,SiglipTokenizer:()=>cu,SpeechT5Tokenizer:()=>uu,SqueezeBertTokenizer:()=>pu,T5Tokenizer:()=>du,TokenizersBackend:()=>P,VitsTokenizer:()=>fu,Wav2Vec2CTCTokenizer:()=>mu,WhisperTokenizer:()=>hu,XLMRobertaTokenizer:()=>xu,XLMTokenizer:()=>gu});var Ic=class extends P{return_token_type_ids=!0};var Tc=class extends P{};var zc=class extends P{return_token_type_ids=!0};var Pc=class extends P{};var Cc=class extends P{};var Nc=class extends P{};var Lc=class extends P{};var $c=class extends P{};var Rc=class extends P{};var Fc=class extends P{};var Dc=class extends P{};var jc=class extends P{return_token_type_ids=!0};var Uc=class extends P{return_token_type_ids=!0};var Bc=class extends P{return_token_type_ids=!0};var qc=class extends P{};var Gc=class extends P{return_token_type_ids=!0};var Wc=class extends P{};var Vc=class extends P{};var Hc=class extends P{};var Kc=class extends P{};var Xc=class extends P{};var Qc=class extends P{return_token_type_ids=!0};var Yc=class extends P{padding_side="left"};var Jc=class extends P{constructor(e,s){super(e,s),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.all_special_tokens.filter(r=>this.languageRegex.test(r)).map(r=>r.slice(2,-2)),this.lang_to_token=r=>`__${r}__`}_build_translation_inputs(e,s,r){return Ls(this,e,s,r)}};var Zc=class extends P{constructor(e,s){super(e,s),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=Array.from(this.get_vocab().keys()).filter(r=>this.languageRegex.test(r)),L.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(e===null)return null;let[s,...r]=e.trim().split(this.languageRegex);if(r.length===0)return super._encode_text(s);if(r.length===2){let[n,o]=r;return this.supported_language_codes.includes(n)||L.warn(`Unsupported language code "${n}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),Pe([n],super._encode_text(o))}}};var Mr=class extends P{constructor(e,s){super(e,s),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.all_special_tokens.filter(r=>this.languageRegex.test(r)).map(r=>r),this.lang_to_token=r=>r}_build_translation_inputs(e,s,r){return Ls(this,e,s,r)}};var eu=class extends Mr{};var tu=class extends P{};var su=class extends P{return_token_type_ids=!0};var ru=class extends P{};var nu=class extends P{constructor(e,s){super(e,s),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.all_special_tokens.filter(r=>this.languageRegex.test(r)),this.lang_to_token=r=>r}_build_translation_inputs(e,s,r){return Ls(this,e,s,r)}};var ou=class extends P{};var iu=class extends P{};var au=class extends P{};var lu=class extends P{return_token_type_ids=!0};var cu=class extends P{};var uu=class extends P{};var pu=class extends P{return_token_type_ids=!0};var du=class extends P{};var _u=class extends Ke{decode_chain(e){let s="";for(let r=1;r<e.length;r+=2)s+=e[r];return[s]}},fu=class extends P{constructor(e,s){super(e,s),this._tokenizer.decoder=new _u({type:"VitsDecoder"})}};var mu=class extends P{};var vy=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],Sr=new Map(vy),wv=new Map([...vy.map(([t,e])=>[e,t]),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);function Ey(t){t=t.toLowerCase();let e=wv.get(t);if(e===void 0){let s=t.match(/^<\|([a-z]{2})\|>$/);if(s&&(t=s[1]),Sr.has(t))e=t;else{let n=t.length===2?Sr.keys():Sr.values();throw new Error(`Language "${t}" is not supported. Must be one of: ${JSON.stringify(Array.from(n))}`)}}return e}var yv="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",Ay=new RegExp(`^[${yv}]+$`,"gu"),hu=class extends P{get timestamp_begin(){return this._tokenizer.token_to_id("<|notimestamps|>")+1}_decode_asr(e,{return_timestamps:s=!1,return_language:r=!1,time_precision:n=null,force_full_sequences:o=!0}={}){if(n===null)throw Error("Must specify time_precision");let i=null,a=s==="word";function l(){return{language:i,timestamp:[null,null],text:""}}let c=[],u=l(),p=0,d=this.timestamp_begin,f=d+1500,h=[],x=[],g=!1,w=null,y=new Set(this.all_special_ids);for(let k of e){let O=k.tokens,N=a?k.token_timestamps:null,D=null,F=d;if("stride"in k){let[j,Q,K]=k.stride;if(p-=Q,w=j-K,Q&&(F=Q/n+d),K)for(let oe=O.length-1;oe>=0;--oe){let te=Number(O[oe]);if(te>=d){if(D!==null&&(te-d)*n<w)break;D=te}}}let B=[],W=[];for(let j=0;j<O.length;++j){let Q=Number(O[j]);if(y.has(Q)){let K=this.decode([Q]),oe=Sr.get(K.slice(2,-2));if(oe!==void 0){if(i!==null&&oe!==i&&!s){h.push(B);let te=this.findLongestCommonSequence(h)[0],v=this.decode(te);u.text=v,c.push(u),h=[],B=[],u=l()}i=u.language=oe}}else if(Q>=d&&Q<=f){let K=(Q-d)*n+p,oe=us(K,2);if(D!==null&&Q>=D)g=!0;else if(g||h.length>0&&Q<F)g=!1;else if(u.timestamp[0]===null)u.timestamp[0]=oe;else if(oe!==u.timestamp[0]){u.timestamp[1]=oe,h.push(B),a&&x.push(W);let[te,v]=this.findLongestCommonSequence(h,x),E=this.decode(te);u.text=E,a&&(u.words=this.collateWordTimestamps(te,v,i)),c.push(u),h=[],B=[],x=[],W=[],u=l()}}else if(B.push(Q),a){let K=us(N[j]+p,2),oe;if(j+1<N.length){oe=us(N[j+1]+p,2);let te=this.decode([Q]);Ay.test(te)&&(oe=us(Math.min(K+n,oe),2))}else oe=null;W.push([K,oe])}}if("stride"in k){let[j,Q,K]=k.stride;p+=j-K}B.length>0?(h.push(B),a&&x.push(W)):h.every(j=>j.length===0)&&(u=l(),h=[],B=[],x=[],W=[])}if(h.length>0){if(o&&s)throw new Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");let[k,O]=this.findLongestCommonSequence(h,x),N=this.decode(k);u.text=N,a&&(u.words=this.collateWordTimestamps(k,O,i)),c.push(u)}let b=Object.create(null),A=c.map(k=>k.text).join("");if(s||r){for(let k=0;k<c.length;++k){let O=c[k];s||delete O.timestamp,r||delete O.language}if(a){let k=[];for(let O of c)for(let N of O.words)k.push(N);b={chunks:k}}else b={chunks:c}}return[A,b]}findLongestCommonSequence(e,s=null){let r=e[0],n=r.length,o=[],i=Array.isArray(s)&&s.length>0,a=i?[]:null,l=i?s[0]:null;for(let c=1;c<e.length;++c){let u=e[c],p=0,d=[n,n,0,0],_=u.length;for(let b=1;b<n+_;++b){let A=Math.max(0,n-b),k=Math.min(n,n+_-b),O=r.slice(A,k),N=Math.max(0,b-n),D=Math.min(_,b),F=u.slice(N,D);if(O.length!==F.length)throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let B;i?B=O.filter((Q,K)=>Q===F[K]&&l[A+K]<=s[c][N+K]).length:B=O.filter((Q,K)=>Q===F[K]).length;let W=b/1e4,j=B/b+W;B>1&&j>p&&(p=j,d=[A,k,N,D])}let[f,h,x,g]=d,w=Math.floor((h+f)/2),y=Math.floor((g+x)/2);o.push(...r.slice(0,w)),r=u.slice(y),n=r.length,i&&(a.push(...l.slice(0,w)),l=s[c].slice(y))}return o.push(...r),i?(a.push(...l),[o,a]):[o,[]]}collateWordTimestamps(e,s,r){let[n,o,i]=this.combineTokensIntoWords(e,r),a=[];for(let l=0;l<n.length;++l){let c=i[l];a.push({text:n[l],timestamp:[s[c.at(0)][0],s[c.at(-1)][1]]})}return a}combineTokensIntoWords(e,s,r=`"'\u201C\xA1\xBF([{-`,n=`"'.\u3002,\uFF0C!\uFF01?\uFF1F:\uFF1A\u201D)]}\u3001`){s=s??"english";let o,i,a;return["chinese","japanese","thai","lao","myanmar"].includes(s)?[o,i,a]=this.splitTokensOnUnicode(e):[o,i,a]=this.splitTokensOnSpaces(e),this.mergePunctuations(o,i,a,r,n)}decode(e,s){let r;return s?.decode_with_timestamps?(e instanceof S&&(e=Oc(e)),r=this.decodeWithTimestamps(e,s)):r=super.decode(e,s),r}decodeWithTimestamps(e,s){let r=s?.time_precision??.02,n=this.all_special_ids.at(-1)+1,o=[[]];for(let i of e)if(i=Number(i),i>=n){let a=((i-n)*r).toFixed(2);o.push(`<|${a}|>`),o.push([])}else o[o.length-1].push(i);return o=o.map(i=>typeof i=="string"?i:super.decode(i,s)),o.join("")}splitTokensOnUnicode(e){let s=this.decode(e,{decode_with_timestamps:!0}),r="\uFFFD",n=[],o=[],i=[],a=[],l=[],c=0;for(let u=0;u<e.length;++u){let p=e[u];a.push(p),l.push(u);let d=this.decode(a,{decode_with_timestamps:!0});(!d.includes(r)||s[c+d.indexOf(r)]===r)&&(n.push(d),o.push(a),i.push(l),a=[],l=[],c+=d.length)}return[n,o,i]}splitTokensOnSpaces(e){let[s,r,n]=this.splitTokensOnUnicode(e),o=[],i=[],a=[];for(let l=0;l<s.length;++l){let c=s[l],u=r[l],p=n[l],d=u[0]>=this._tokenizer.token_to_id("<|endoftext|>"),_=c.startsWith(" "),f=c.trim(),h=Ay.test(f);if(d||_||h||o.length===0)o.push(c),i.push(u),a.push(p);else{let x=o.length-1;o[x]+=c,i[x].push(...u),a[x].push(...p)}}return[o,i,a]}mergePunctuations(e,s,r,n,o){let i=structuredClone(e),a=structuredClone(s),l=structuredClone(r),c=i.length-2,u=i.length-1;for(;c>=0;)i[c].startsWith(" ")&&n.includes(i[c].trim())?(i[u]=i[c]+i[u],a[u]=Pe(a[c],a[u]),l[u]=Pe(l[c],l[u]),i[c]="",a[c]=[],l[c]=[]):u=c,--c;for(c=0,u=1;u<i.length;)!i[c].endsWith(" ")&&o.includes(i[u])?(i[c]+=i[u],a[c]=Pe(a[c],a[u]),l[c]=Pe(l[c],l[u]),i[u]="",a[u]=[],l[u]=[]):c=u,++u;return[i.filter(p=>p),a.filter(p=>p.length>0),l.filter(p=>p.length>0)]}};var xu=class extends P{};var gu=class extends P{return_token_type_ids=!0;constructor(e,s){super(e,s),L.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}};var $=class{static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main"}={}){let[a,l]=await Sc(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i}),c=l.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer",u=wu[c];return u||(L.warn(`Unknown tokenizer class "${c}", attempting to construct from base class.`),u=P),new u(a,l)}};var Rt="https://github.com/huggingface/transformers.js/issues/new/choose";var Or="preprocessor_config.json",Ot=Or,My="processor_config.json",Sy="chat_template.jinja";var U=class extends ve{static classes=["image_processor_class","tokenizer_class","feature_extractor_class"];static uses_processor_config=!1;static uses_chat_template_file=!1;constructor(e,s,r){super(),this.config=e,this.components=s,this.chat_template=r}get image_processor(){return this.components.image_processor}get tokenizer(){return this.components.tokenizer}get feature_extractor(){return this.components.feature_extractor}apply_chat_template(e,s={}){if(!this.tokenizer)throw new Error("Unable to apply chat template without a tokenizer.");return this.tokenizer.apply_chat_template(e,{tokenize:!1,chat_template:this.chat_template??void 0,...s})}batch_decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.batch_decode(...e)}decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.decode(...e)}async _call(e,...s){for(let r of[this.image_processor,this.feature_extractor,this.tokenizer])if(r)return r(e,...s);throw new Error("No image processor, feature extractor, or tokenizer found.")}static async from_pretrained(e,s={}){let[r,n,o]=await Promise.all([this.uses_processor_config?Te(e,My,!0,s):{},Promise.all(this.classes.filter(i=>i in this).map(async i=>{let a=await this[i].from_pretrained(e,s);return[i.replace(/_class$/,""),a]})).then(Object.fromEntries),this.uses_chat_template_file?_c(e,Sy,!0,s):null]);return new this(r,n,o)}};var ga={};As(ga,{ChatterboxProcessor:()=>Nu,Florence2Processor:()=>Ep,Gemma3nProcessor:()=>Ap,GroundingDinoProcessor:()=>Mp,Idefics3Processor:()=>ma,JinaCLIPProcessor:()=>Op,LlavaProcessor:()=>Ip,MgpstrProcessor:()=>Tp,MoonshineProcessor:()=>zp,OwlViTProcessor:()=>Pp,PaliGemmaProcessor:()=>Cp,Phi3VProcessor:()=>Np,PixtralProcessor:()=>Lp,Processor:()=>U,PyAnnoteProcessor:()=>$p,Qwen2VLProcessor:()=>Lr,Qwen2_5_VLProcessor:()=>$r,Qwen3VLProcessor:()=>Rp,Sam2Processor:()=>ha,Sam2VideoProcessor:()=>Fp,SamProcessor:()=>Rr,SmolVLMProcessor:()=>ma,SpeechT5Processor:()=>Dp,UltravoxProcessor:()=>jp,VLChatProcessor:()=>Sp,VoxtralProcessor:()=>Up,Wav2Vec2Processor:()=>Bp,Wav2Vec2ProcessorWithLM:()=>qp,WhisperProcessor:()=>Gp});var _e=class extends ve{constructor(e){super(),this.config=e}static async from_pretrained(e,s={}){let r=await Te(e,Or,!0,s);return new this(r)}};function we(t,e){if(!(t instanceof Float32Array||t instanceof Float64Array))throw new Error(`${e} expects input to be a Float32Array or a Float64Array, but got ${t?.constructor?.name??typeof t} instead. If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}var Cr={};As(Cr,{ASTFeatureExtractor:()=>ku,ChatterboxFeatureExtractor:()=>vu,ClapFeatureExtractor:()=>Eu,DacFeatureExtractor:()=>zr,EncodecFeatureExtractor:()=>Tr,FeatureExtractor:()=>_e,Gemma3nAudioFeatureExtractor:()=>Au,MoonshineFeatureExtractor:()=>Mu,ParakeetFeatureExtractor:()=>Su,PyAnnoteFeatureExtractor:()=>Pr,SeamlessM4TFeatureExtractor:()=>Ou,SnacFeatureExtractor:()=>Iu,SpeechT5FeatureExtractor:()=>Tu,Wav2Vec2FeatureExtractor:()=>zu,WeSpeakerFeatureExtractor:()=>Pu,WhisperFeatureExtractor:()=>Cu});var bv=()=>{};var Oy={fromWeb:bv};var kv=()=>{};var Iy=kv;async function Ki(t,e){if(Z.IS_BROWSER_ENV){if(Z.IS_WEBWORKER_ENV)throw new Error("Unable to save a file from a Web Worker.");let s=URL.createObjectURL(e),r=document.createElement("a");r.href=s,r.download=t,r.click(),r.remove(),URL.revokeObjectURL(s)}else if(Z.IS_FS_AVAILABLE){let s=e.stream(),r=Oy.fromWeb(s),n=Fe.createWriteStream(t);await Iy(r,n)}else throw new Error("Unable to save because filesystem is disabled in this environment.")}async function bu(t,e){if(typeof AudioContext>"u")throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");let s=await(await Lt(t)).arrayBuffer(),r=new AudioContext({sampleRate:e});typeof e>"u"&&L.warn(`No sampling rate provided, using default of ${r.sampleRate}Hz.`);let n=await r.decodeAudioData(s),o;if(n.numberOfChannels===2){let i=Math.sqrt(2),a=n.getChannelData(0),l=n.getChannelData(1);o=new Float32Array(a.length);for(let c=0;c<n.length;++c)o[c]=i*(a[c]+l[c])/2}else o=n.getChannelData(0);return o}function Py(t,e){if(t<1)return new Float64Array;if(t===1)return new Float64Array([1]);let s=1-e,r=2*Math.PI/(t-1),n=new Float64Array(t);for(let o=0;o<t;++o)n[o]=e-s*Math.cos(o*r);return n}function Ty(t){return Py(t,.5)}function vv(t){return Py(t,.54)}var Ev={htk:t=>2595*Math.log10(1+t/700),kaldi:t=>1127*Math.log(1+t/700),slaney:(t,e=1e3,s=15,r=27/Math.log(6.4))=>t>=e?s+Math.log(t/e)*r:3*t/200};function yu(t,e="htk"){let s=Ev[e];if(!s)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof t=="number"?s(t):t.map(r=>s(r))}var Av={htk:t=>700*(10**(t/2595)-1),kaldi:t=>700*(Math.exp(t/1127)-1),slaney:(t,e=1e3,s=15,r=Math.log(6.4)/27)=>t>=s?e*Math.exp(r*(t-s)):200*t/3};function Mv(t,e="htk"){let s=Av[e];if(!s)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof t=="number"?s(t):t.map(r=>s(r))}function Sv(t,e){let s=Float64Array.from({length:e.length-1},(i,a)=>e[a+1]-e[a]),r=Array.from({length:t.length},()=>new Array(e.length));for(let i=0;i<t.length;++i){let a=r[i];for(let l=0;l<e.length;++l)a[l]=e[l]-t[i]}let n=e.length-2,o=Array.from({length:n},()=>new Array(t.length));for(let i=0;i<t.length;++i){let a=r[i];for(let l=0;l<n;++l){let c=-a[l]/s[l],u=a[l+2]/s[l+1];o[l][i]=Math.max(0,Math.min(c,u))}}return o}function zy(t,e,s){let r=(e-t)/(s-1);return Float64Array.from({length:s},(n,o)=>t+r*o)}function De(t,e,s,r,n,o=null,i="htk",a=!1){if(o!==null&&o!=="slaney")throw new Error('norm must be one of null or "slaney"');if(t<2)throw new Error(`Require num_frequency_bins: ${t} >= 2`);if(s>r)throw new Error(`Require min_frequency: ${s} <= max_frequency: ${r}`);let l=yu(s,i),c=yu(r,i),u=zy(l,c,e+2),p=Mv(u,i),d;if(a){let f=n/((t-1)*2);d=yu(Float64Array.from({length:t},(h,x)=>x*f),i),p=u}else d=zy(0,Math.floor(n/2),t);let _=Sv(d,p);if(o!==null&&o==="slaney")for(let f=0;f<e;++f){let h=_[f],x=2/(p[f+2]-p[f]);for(let g=0;g<t;++g)h[g]*=x}return _}function Ov(t,e,s){let r=new t.constructor(t.length+e+s),n=t.length-1;for(let o=0;o<t.length;++o)r[e+o]=t[o];for(let o=1;o<=e;++o)r[e-o]=t[Ss(o,n)];for(let o=1;o<=s;++o)r[n+e+o]=t[Ss(n-o,n)];return r}function Cy(t,e,s,r,n){if(s<=0)throw new Error("reference must be greater than zero");if(r<=0)throw new Error("min_value must be greater than zero");s=Math.max(r,s);let o=Math.log10(s);for(let i=0;i<t.length;++i)t[i]=e*Math.log10(Math.max(r,t[i])-o);if(n!==null){if(n<=0)throw new Error("db_range must be greater than zero");let i=le(t)[0]-n;for(let a=0;a<t.length;++a)t[a]=Math.max(t[a],i)}return t}function Iv(t,e=1,s=1e-5,r=null){return Cy(t,20,e,s,r)}function Tv(t,e=1,s=1e-10,r=null){return Cy(t,10,e,s,r)}async function Be(t,e,s,r,{fft_length:n=null,power:o=1,center:i=!0,pad_mode:a="reflect",onesided:l=!0,preemphasis:c=null,preemphasis_htk_flavor:u=!0,mel_filters:p=null,mel_floor:d=1e-10,log_mel:_=null,reference:f=1,min_value:h=1e-10,db_range:x=null,remove_dc_offset:g=null,min_num_frames:w=null,max_num_frames:y=null,do_pad:b=!0,transpose:A=!1,mel_offset:k=0}={}){let O=e.length;if(n===null&&(n=s),s>n)throw Error(`frame_length (${s}) may not be larger than fft_length (${n})`);if(O!==s)throw new Error(`Length of the window (${O}) must equal frame_length (${s})`);if(r<=0)throw new Error("hop_length must be greater than zero");if(o===null&&p!==null)throw new Error("You have provided `mel_filters` but `power` is `None`. Mel spectrogram computation is not yet supported for complex-valued spectrogram. Specify `power` to fix this issue.");if(!u)throw new Error("`preemphasis_htk_flavor=false` is not currently supported.");if(i)switch(a){case"reflect":{let E=Math.floor((n-1)/2)+1;t=Ov(t,E,E);break}case"constant":{let E=Math.floor(n/2),T=new t.constructor(t.length+2*E);T.set(t,E),t=T;break}default:throw new Error(`pad_mode="${a}" not implemented yet.`)}let N=Math.floor(1+Math.floor((t.length-s)/r));w!==null&&N<w&&(N=w);let D=l?Math.floor(n/2)+1:n,F=N,B=N;y!==null&&(y>N?b&&(B=y):B=F=y);let W=new Ri(n),j=new Float64Array(n),Q=new Float64Array(W.outputBufferSize),K=new Float32Array(D*B);for(let E=0;E<F;++E){let T=E*r,J=Math.min(t.length-T,s);J!==s&&j.fill(0,0,s);for(let se=0;se<J;++se)j[se]=t[T+se];if(g){let se=0;for(let Ae=0;Ae<J;++Ae)se+=j[Ae];let Ie=se/J;for(let Ae=0;Ae<J;++Ae)j[Ae]-=Ie}if(c!==null){for(let se=J-1;se>=1;--se)j[se]-=c*j[se-1];j[0]*=1-c}for(let se=0;se<e.length;++se)j[se]*=e[se];W.realTransform(Q,j);for(let se=0;se<D;++se){let Ie=se<<1;K[se*B+E]=Q[Ie]**2+Q[Ie+1]**2}}if(o!==null&&o!==2){let E=o/2;for(let T=0;T<K.length;++T)K[T]**=E}let oe=p.length,te=await wy(new S("float32",p.flat(),[oe,D]),new S("float32",K,[D,B]));A&&(te=te.transpose(1,0));let v=te.data;for(let E=0;E<v.length;++E)v[E]=k+Math.max(d,v[E]);if(o!==null&&_!==null){let E=Math.min(v.length,F*oe);switch(_){case"log":for(let T=0;T<E;++T)v[T]=Math.log(v[T]);break;case"log10":for(let T=0;T<E;++T)v[T]=Math.log10(v[T]);break;case"dB":if(o===1)Iv(v,f,h,x);else if(o===2)Tv(v,f,h,x);else throw new Error(`Cannot use log_mel option '${_}' with power ${o}`);break;default:throw new Error(`log_mel must be one of null, 'log', 'log10' or 'dB'. Got '${_}'`)}}return te}function qe(t,e,{periodic:s=!0,frame_length:r=null,center:n=!0}={}){let o=s?t+1:t,i;switch(e){case"boxcar":i=new Float64Array(o).fill(1);break;case"hann":case"hann_window":i=Ty(o);break;case"hamming":i=vv(o);break;case"povey":i=Ty(o).map(a=>Math.pow(a,.85));break;default:throw new Error(`Unknown window type ${e}.`)}if(s&&(i=i.subarray(0,t)),r===null)return i;if(t>r)throw new Error(`Length of the window (${t}) may not be larger than frame_length (${r})`);return i}function zv(t,e){let s=t.reduce((o,i)=>o+i.length,0),r=new ArrayBuffer(44),n=new DataView(r);return Xi(n,0,"RIFF"),n.setUint32(4,36+s*4,!0),Xi(n,8,"WAVE"),Xi(n,12,"fmt "),n.setUint32(16,16,!0),n.setUint16(20,3,!0),n.setUint16(22,1,!0),n.setUint32(24,e,!0),n.setUint32(28,e*4,!0),n.setUint16(32,4,!0),n.setUint16(34,32,!0),Xi(n,36,"data"),n.setUint32(40,s*4,!0),new Blob([r,...t.map(o=>o.buffer)],{type:"audio/wav"})}function Xi(t,e,s){for(let r=0;r<s.length;++r)t.setUint8(e+r,s.charCodeAt(r))}var Ir=class{constructor(e,s){this.audio=e,this.sampling_rate=s}get data(){if(Array.isArray(this.audio)){if(this.audio.length===0)return new Float32Array(0);if(this.audio.length===1)return this.audio[0];let e=this.audio.reduce((n,o)=>n+o.length,0),s=new Float32Array(e),r=0;for(let n of this.audio)s.set(n,r),r+=n.length;return s}else return this.audio}toBlob(){let e=this.audio;return e instanceof Float32Array&&(e=[e]),zv(e,this.sampling_rate)}async save(e){return Ki(e,this.toBlob())}};var ku=class extends _e{constructor(e){super(e);let s=this.config.sampling_rate,r=De(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=qe(400,"hann",{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,s){return Be(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:s,transpose:!0})}async _call(e){we(e,"ASTFeatureExtractor");let s=await this._extract_fbank_features(e,this.config.max_length);if(this.config.do_normalize){let r=this.std*2,n=s.data;for(let o=0;o<n.length;++o)n[o]=(n[o]-this.mean)/r}return{input_values:s.unsqueeze_(0)}}};var Tr=class extends _e{async _call(e){we(e,"EncodecFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=this.config.feature_size;if(e.length%s!==0)throw new Error(`The length of the audio data must be a multiple of the number of channels (${s}).`);let r=[1,s,e.length/s];return{input_values:new S("float32",e,r)}}};var vu=class extends _e{async _call(e){we(e,"ChatterboxFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,e.length];return{input_values:new S("float32",e,s)}}};var Eu=class extends _e{constructor(e){super(e),this.mel_filters=De(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,null,"htk"),this.mel_filters_slaney=De(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,"slaney","slaney"),this.window=qe(this.config.fft_window_size,"hann")}async _get_input_mel(e,s,r,n){let o,i=!1,a=e.length-s;if(a>0)if(r==="rand_trunc"){i=!0;let l=Math.floor(ps.random()*(a+1));e=e.subarray(l,l+s),o=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}else throw new Error(`Truncation strategy "${r}" not implemented`);else{if(a<0){let l=new Float64Array(s);if(l.set(e),n==="repeat")for(let c=e.length;c<s;c+=e.length)l.set(e.subarray(0,Math.min(e.length,s-c)),c);else if(n==="repeatpad")for(let c=e.length;c<-a;c+=e.length)l.set(e,c);e=l}if(r==="fusion")throw new Error(`Truncation strategy "${r}" not implemented`);o=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}return o.unsqueeze_(0)}async _extract_fbank_features(e,s,r=null){return Be(e,this.window,this.config.fft_window_size,this.config.hop_length,{power:2,mel_filters:s,log_mel:"dB",max_num_frames:r,do_pad:!1,transpose:!0})}async _call(e,{max_length:s=null}={}){return we(e,"ClapFeatureExtractor"),{input_features:(await this._get_input_mel(e,s??this.config.nb_max_samples,this.config.truncation,this.config.padding)).unsqueeze_(0)}}};var zr=class extends Tr{};var Au=class extends _e{constructor(e){super(e);let{fft_length:s,feature_size:r,min_frequency:n,max_frequency:o,sampling_rate:i,frame_length:a}=this.config,l=De(Math.floor(1+s/2),r,n,o,i,null,"htk",!1);this.mel_filters=l,this.window=qe(a,"hann")}async _extract_fbank_features(e,s){return Be(e,this.window,this.config.frame_length,this.config.hop_length,{fft_length:this.config.fft_length,center:!1,onesided:!0,preemphasis:this.config.preemphasis,preemphasis_htk_flavor:this.config.preemphasis_htk_flavor,mel_filters:this.mel_filters,log_mel:"log",mel_floor:this.config.mel_floor,remove_dc_offset:!1,transpose:!0})}async _call(e,{max_length:s=48e4,truncation:r=!0,padding:n=!0,pad_to_multiple_of:o=128}={}){if(we(e,"Gemma3nAudioFeatureExtractor"),r&&e.length>s&&(e=e.slice(0,s)),n&&e.length%o!==0){let l=o-e.length%o,c=new Float64Array(e.length+l);c.set(e),this.config.padding_value!==0&&c.fill(this.config.padding_value,e.length),e=c}let i=await this._extract_fbank_features(e,this.config.max_length),a=ge([1,i.dims[0]],!0);return{input_features:i.unsqueeze_(0),input_features_mask:a}}};var Mu=class extends _e{async _call(e){we(e,"MoonshineFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,e.length];return{input_values:new S("float32",e,s)}}};var Pv=1e-5,Su=class extends _e{constructor(e){super(e),this.config.mel_filters??=De(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,this.config.sampling_rate/2,this.config.sampling_rate,"slaney","slaney");let s=qe(this.config.win_length,"hann",{periodic:!1});this.window=new Float64Array(this.config.n_fft);let r=Math.floor((this.config.n_fft-this.config.win_length)/2);this.window.set(s,r)}async _extract_fbank_features(e){let s=this.config.preemphasis;e=new Float64Array(e);for(let n=e.length-1;n>=1;--n)e[n]-=s*e[n-1];return await Be(e,this.window,this.window.length,this.config.hop_length,{fft_length:this.config.n_fft,power:2,mel_filters:this.config.mel_filters,log_mel:"log",mel_floor:-1/0,pad_mode:"constant",center:!0,transpose:!0,mel_offset:2**-24})}async _call(e){we(e,"ParakeetFeatureExtractor");let s=await this._extract_fbank_features(e),r=Math.floor((e.length+Math.floor(this.config.n_fft/2)*2-this.config.n_fft)/this.config.hop_length),n=s.data;n.fill(0,r*s.dims[1]);let[o,i]=s.dims,a=new Float64Array(i),l=new Float64Array(i);for(let p=0;p<r;++p){let d=p*i;for(let _=0;_<i;++_){let f=n[d+_];a[_]+=f,l[_]+=f*f}}let c=r>1?r-1:1;for(let p=0;p<i;++p){let d=a[p]/r,_=(l[p]-r*d*d)/c,h=1/(Math.sqrt(_)+Pv);for(let x=0;x<r;++x){let g=x*i+p;n[g]=(n[g]-d)*h}}let u=new BigInt64Array(o);return u.fill(1n,0,r),{input_features:s.unsqueeze_(0),attention_mask:new S("int64",u,[1,o])}}};var Pr=class extends _e{async _call(e){we(e,"PyAnnoteFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,1,e.length];return{input_values:new S("float32",e,s)}}samples_to_frames(e){return(e-this.config.offset)/this.config.step}post_process_speaker_diarization(e,s){let r=s/this.samples_to_frames(s)/this.config.sampling_rate,n=[];for(let o of e.tolist()){let i=[],a=-1;for(let l=0;l<o.length;++l){let c=pe(o[l]),[u,p]=le(c),[d,_]=[l,l+1];p!==a?(a=p,i.push({id:p,start:d,end:_,score:u})):(i.at(-1).end=_,i.at(-1).score+=u)}n.push(i.map(({id:l,start:c,end:u,score:p})=>({id:l,start:c*r,end:u*r,confidence:p/(u-c)})))}return n}};var Ou=class extends _e{constructor(e){super(e);let s=this.config.sampling_rate,r=De(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=qe(400,"povey",{periodic:!1})}async _extract_fbank_features(e,s){return e=e.map(r=>r*32768),Be(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:s,transpose:!0})}async _call(e,{padding:s=!0,pad_to_multiple_of:r=2,do_normalize_per_mel_bins:n=!0,return_attention_mask:o=!0}={}){we(e,"SeamlessM4TFeatureExtractor");let i=await this._extract_fbank_features(e,this.config.max_length);if(n){let[f,h]=i.dims,x=i.data;for(let g=0;g<h;++g){let w=0;for(let k=0;k<f;++k)w+=x[k*h+g];let y=w/f,b=0;for(let k=0;k<f;++k)b+=(x[k*h+g]-y)**2;b/=f-1;let A=Math.sqrt(b+1e-7);for(let k=0;k<f;++k){let O=k*h+g;x[O]=(x[O]-y)/A}}}let a;if(s){let[f,h]=i.dims,x=i.data,g=f%r;if(g>0){let w=new Float32Array(h*(f+g));w.set(x),w.fill(this.config.padding_value,x.length);let y=f+g;i=new S(i.type,w,[y,h]),o&&(a=new S("int64",new BigInt64Array(y),[1,y]),a.data.fill(1n,0,f))}}let[l,c]=i.dims,u=this.config.stride;if(l%u!==0)throw new Error(`The number of frames (${l}) must be a multiple of the stride (${u}).`);let d=i.view(1,Math.floor(l/u),c*u),_={input_features:d};if(o){let f=d.dims[1],h=new BigInt64Array(f);if(a){let x=a.data;for(let g=1,w=0;g<l;g+=u,++w)h[w]=x[g]}else h.fill(1n);_.attention_mask=new S("int64",h,[1,f])}return _}};var Iu=class extends zr{};var Tu=class extends _e{};var zu=class extends _e{_zero_mean_unit_var_norm(e){let r=e.reduce((o,i)=>o+i,0)/e.length,n=e.reduce((o,i)=>o+(i-r)**2,0)/e.length;return e.map(o=>(o-r)/Math.sqrt(n+1e-7))}async _call(e){we(e,"Wav2Vec2FeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=e;this.config.do_normalize&&(s=this._zero_mean_unit_var_norm(s));let r=[1,s.length];return{input_values:new S("float32",s,r),attention_mask:new S("int64",new BigInt64Array(s.length).fill(1n),r)}}};var Pu=class extends _e{constructor(e){super(e);let s=this.config.sampling_rate,r=De(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=qe(400,"hamming",{periodic:!1}),this.min_num_frames=this.config.min_num_frames}async _extract_fbank_features(e){return e=e.map(s=>s*32768),Be(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,transpose:!0,min_num_frames:this.min_num_frames})}async _call(e){we(e,"WeSpeakerFeatureExtractor");let s=(await this._extract_fbank_features(e)).unsqueeze_(0);if(this.config.fbank_centering_span===null){let r=s.mean(1).data,n=s.data,[o,i,a]=s.dims;for(let l=0;l<o;++l){let c=l*i*a,u=l*a;for(let p=0;p<i;++p){let d=c+p*a;for(let _=0;_<a;++_)n[d+_]-=r[u+_]}}}return{input_features:s}}};var Cu=class extends _e{constructor(e){super(e),this.config.mel_filters??=De(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=qe(this.config.n_fft,"hann")}async _extract_fbank_features(e){let s=await Be(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:Math.min(Math.floor(e.length/this.config.hop_length),this.config.nb_max_frames)}),r=s.data,n=le(r)[0];for(let o=0;o<r.length;++o)r[o]=(Math.max(r[o],n-8)+4)/4;return s}async _call(e,{max_length:s=null}={}){we(e,"WhisperFeatureExtractor");let r,n=s??this.config.n_samples;return e.length>n?(e.length>this.config.n_samples&&L.warn("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`."),r=e.slice(0,n)):(r=new Float32Array(n),r.set(e)),{input_features:(await this._extract_fbank_features(r)).unsqueeze_(0)}}};var Ee=class{static async from_pretrained(e,s={}){let r=await Te(e,Or,!0,s),n=r.feature_extractor_type,o=Cr[n];if(!o)throw new Error(`Unknown feature_extractor_type: '${n}'. Please report this at ${Rt}.`);return new o(r)}};var Nu=class extends U{static tokenizer_class=$;static feature_extractor_class=Ee;async _call(e,s=null){let r=this.tokenizer(e),n=s?await this.feature_extractor(s):{};return{...r,...n}}};var Qi={};var _s,Ny,Ft,lt=Z.IS_BROWSER_ENV||Z.IS_WEBWORKER_ENV;if(lt)_s=(t,e)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(t,e)},Ft=self.createImageBitmap,Ny=self.ImageData;else if(Qi)Ft=async t=>{let s=(await t.metadata()).channels,{data:r,info:n}=await t.rotate().raw().toBuffer({resolveWithObject:!0}),o=new ye(new Uint8ClampedArray(r),n.width,n.height,n.channels);return s!==void 0&&s!==n.channels&&o.convert(s),o};else throw new Error("Unable to load image processing library.");var Cv={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},Nv=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]),ye=class t{constructor(e,s,r,n){this.data=e,this.width=s,this.height=r,this.channels=n}get size(){return[this.width,this.height]}static async read(e){if(e instanceof t)return e;if(typeof e=="string"||e instanceof URL)return await this.fromURL(e);if(e instanceof Blob)return await this.fromBlob(e);if(typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)return this.fromCanvas(e);throw new Error(`Unsupported input type: ${typeof e}`)}static fromCanvas(e){if(!lt)throw new Error("fromCanvas() is only supported in browser environments.");let r=e.getContext("2d").getImageData(0,0,e.width,e.height).data;return new t(r,e.width,e.height,4)}static async fromURL(e){let s=await Lt(e);if(s.status!==200)throw new Error(`Unable to read image from "${e}" (${s.status} ${s.statusText})`);let r=await s.blob();return this.fromBlob(r)}static async fromBlob(e){if(lt){let s=await Ft(e),r=_s(s.width,s.height).getContext("2d");return r.drawImage(s,0,0),new this(r.getImageData(0,0,s.width,s.height).data,s.width,s.height,4)}else{let s=Qi(await e.arrayBuffer());return await Ft(s)}}static fromTensor(e,s="CHW"){if(e.dims.length!==3)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if(s==="CHW")e=e.transpose(1,2,0);else if(s!=="HWC")throw new Error(`Unsupported channel format: ${s}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new t(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(this.channels===1)return this;let e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let s=0,r=0;s<this.data.length;s+=this.channels){let n=this.data[s],o=this.data[s+1],i=this.data[s+2];e[r++]=Math.round(.2989*n+.587*o+.114*i)}break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(this.channels===3)return this;let e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let s=0,r=0;s<this.data.length;++s)e[r++]=this.data[s],e[r++]=this.data[s],e[r++]=this.data[s];break;case 4:for(let s=0,r=0;s<this.data.length;s+=4)e[r++]=this.data[s],e[r++]=this.data[s+1],e[r++]=this.data[s+2];break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(this.channels===4)return this;let e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let s=0,r=0;s<this.data.length;++s)e[r++]=this.data[s],e[r++]=this.data[s],e[r++]=this.data[s],e[r++]=255;break;case 3:for(let s=0,r=0;s<this.data.length;s+=3)e[r++]=this.data[s],e[r++]=this.data[s+1],e[r++]=this.data[s+2],e[r++]=255;break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}putAlpha(e){if(e.width!==this.width||e.height!==this.height)throw new Error(`Expected mask size to be ${this.width}x${this.height}, but got ${e.width}x${e.height}`);if(e.channels!==1)throw new Error(`Expected mask to have 1 channel, but got ${e.channels}`);let s=this.data,r=e.data,n=this.width*this.height;if(this.channels===3){let o=new Uint8ClampedArray(n*4);for(let i=0,a=0,l=0;i<n;++i)o[l++]=s[a++],o[l++]=s[a++],o[l++]=s[a++],o[l++]=r[i];return this._update(o,this.width,this.height,4)}else if(this.channels===4){for(let o=0;o<n;++o)s[4*o+3]=r[o];return this}throw new Error(`Expected image to have 3 or 4 channels, but got ${this.channels}`)}async resize(e,s,{resample:r=2}={}){if(this.width===e&&this.height===s)return this;let n=Cv[r]??r,o=ic(e),i=ic(s);if(o&&i)return this;if(o?e=s/this.height*this.width:i&&(s=e/this.width*this.height),lt){let a=this.channels,l=this.toCanvas(),c=_s(e,s).getContext("2d");return c.drawImage(l,0,0,e,s),new t(c.getImageData(0,0,e,s).data,e,s,4).convert(a)}else{let a=this.toSharp();switch(n){case"box":case"hamming":(n==="box"||n==="hamming")&&(L.warn(`Resampling method ${n} is not yet supported. Using bilinear instead.`),n="bilinear");case"nearest":case"bilinear":case"bicubic":a=a.affine([e/this.width,0,0,s/this.height],{interpolator:n});break;case"lanczos":a=a.resize({width:e,height:s,fit:"fill",kernel:"lanczos3"});break;default:throw new Error(`Resampling method ${n} is not supported.`)}return await Ft(a)}}async pad([e,s,r,n]){if(e=Math.max(e,0),s=Math.max(s,0),r=Math.max(r,0),n=Math.max(n,0),e===0&&s===0&&r===0&&n===0)return this;if(lt){let o=this.channels,i=this.toCanvas(),a=this.width+e+s,l=this.height+r+n,c=_s(a,l).getContext("2d");return c.drawImage(i,0,0,this.width,this.height,e,r,this.width,this.height),new t(c.getImageData(0,0,a,l).data,a,l,4).convert(o)}else{let o=this.toSharp().extend({left:e,right:s,top:r,bottom:n});return await Ft(o)}}async crop([e,s,r,n]){if(e=Math.max(e,0),s=Math.max(s,0),r=Math.min(r,this.width-1),n=Math.min(n,this.height-1),e===0&&s===0&&r===this.width-1&&n===this.height-1)return this;let o=r-e+1,i=n-s+1;if(lt){let a=this.channels,l=this.toCanvas(),c=_s(o,i).getContext("2d");return c.drawImage(l,e,s,o,i,0,0,o,i),new t(c.getImageData(0,0,o,i).data,o,i,4).convert(a)}else{let a=this.toSharp().extract({left:e,top:s,width:o,height:i});return await Ft(a)}}async center_crop(e,s){if(this.width===e&&this.height===s)return this;let r=(this.width-e)/2,n=(this.height-s)/2;if(lt){let o=this.channels,i=this.toCanvas(),a=_s(e,s).getContext("2d"),l=0,c=0,u=0,p=0;return r>=0?l=r:u=-r,n>=0?c=n:p=-n,a.drawImage(i,l,c,e,s,u,p,e,s),new t(a.getImageData(0,0,e,s).data,e,s,4).convert(o)}else{let o=this.toSharp();if(r>=0&&n>=0)o=o.extract({left:Math.floor(r),top:Math.floor(n),width:e,height:s});else if(r<=0&&n<=0){let i=Math.floor(-n),a=Math.floor(-r);o=o.extend({top:i,left:a,right:e-this.width-a,bottom:s-this.height-i})}else{let i=[0,0],a=0;n<0?(i[0]=Math.floor(-n),i[1]=s-this.height-i[0]):a=Math.floor(n);let l=[0,0],c=0;r<0?(l[0]=Math.floor(-r),l[1]=e-this.width-l[0]):c=Math.floor(r),o=o.extend({top:i[0],bottom:i[1],left:l[0],right:l[1]}).extract({left:c,top:a,width:e,height:s})}return await Ft(o)}}async toBlob(e="image/png",s=1){if(!lt)throw new Error("toBlob() is only supported in browser environments.");return await this.toCanvas().convertToBlob({type:e,quality:s})}toTensor(e="CHW"){let s=new S("uint8",new Uint8Array(this.data),[this.height,this.width,this.channels]);if(e!=="HWC")if(e==="CHW")s=s.permute(2,0,1);else throw new Error(`Unsupported channel format: ${e}`);return s}toCanvas(){if(!lt)throw new Error("toCanvas() is only supported in browser environments.");let e=this.clone().rgba(),s=_s(e.width,e.height),r=new Ny(e.data,e.width,e.height);return s.getContext("2d").putImageData(r,0,0),s}split(){let{data:e,width:s,height:r,channels:n}=this,o=e.constructor,i=e.length/n,a=Array.from({length:n},()=>new o(i));for(let l=0;l<i;++l){let c=n*l;for(let u=0;u<n;++u)a[u][l]=e[c+u]}return a.map(l=>new t(l,s,r,1))}_update(e,s,r,n=null){return this.data=e,this.width=s,this.height=r,n!==null&&(this.channels=n),this}clone(){return new t(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(lt){if(Z.IS_WEBWORKER_ENV)throw new Error("Unable to save an image from a Web Worker.");let s=e.split(".").pop().toLowerCase(),r=Nv.get(s)??"image/png",n=await this.toBlob(r);return Ki(e,n)}else if(Z.IS_FS_AVAILABLE)await this.toSharp().toFile(e);else throw new Error("Unable to save the image because filesystem is disabled in this environment.")}toSharp(){if(lt)throw new Error("toSharp() is only supported in server-side environments.");return Qi(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}},Lv=ye.read.bind(ye);function Ly(t,e,s=0,r=null){let n=t/e,o=Yw(n)*e;return r!==null&&o>r&&(o=Math.floor(n)*e),o<s&&(o=Math.ceil(n)*e),o}function Lu([t,e],s){return[Math.max(Math.floor(t/s),1)*s,Math.max(Math.floor(e/s),1)*s]}function $u([t,e,s,r]){return[t-s/2,e-r/2,t+s/2,e+r/2]}function Dt(t,e=.5,s=null,r=!1){let n=t.logits,o=t.pred_boxes,[i,a,l]=n.dims;if(s!==null&&s.length!==i)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let c=[];for(let u=0;u<i;++u){let p=s!==null?s[u]:null,d={boxes:[],classes:[],scores:[]},_=n[u],f=o[u];for(let h=0;h<a;++h){let x=_[h],g=[],w;if(r){w=x.sigmoid().data;for(let y=0;y<w.length;++y)w[y]>e&&g.push(y)}else{let y=le(x.data)[1];if(y===l-1||(w=pe(x.data),w[y]<e))continue;g.push(y)}for(let y of g){let b=f[h].data;b=$u(b),p!==null&&(b=b.map((A,k)=>A*p[(k+1)%2])),d.boxes.push(b),d.classes.push(y),d.scores.push(w[y])}}c.push(d)}return c}function Yi(t,e=null){let s=t.logits,r=s.dims[0];if(e!==null&&e.length!==r)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let n=[];for(let o=0;o<r;++o){let i=e!==null?e[o]:null,a=s[o];i!==null&&(a=kc(a,i,"bilinear",!1));let[l,c]=i??a.dims.slice(-2),u=new S("int32",new Int32Array(l*c),[l,c]),p=a[0].data,d=u.data;for(let h=1;h<a.dims[0];++h){let x=a[h].data;for(let g=0;g<x.length;++g)x[g]>p[g]&&(p[g]=x[g],d[g]=h)}let _=new Array(a.dims[0]);for(let h=0;h<d.length;++h){let x=d[h];_[x]=x}let f=_.filter(h=>h!==void 0);n.push({segmentation:u,labels:f})}return n}function $v(t,e,s,r){let n=[],o=[],i=[];for(let a=0;a<t.dims[0];++a){let l=t[a],c=e[a],u=le(l.data)[1];if(u===r)continue;let d=pe(l.data)[u];d>s&&(n.push(c),o.push(d),i.push(u))}return[n,o,i]}function Rv(t,e,s,r=.5,n=.8){let o=[],i=0,a=0,l=e[s].data;for(let u=0;u<t.length;++u)t[u]===s&&(o.push(u),++i),l[u]>=r&&++a;let c=i>0&&a>0;return c&&(c=i/a>n),[c,o]}function Fv(t,e,s,r,n,o=null,i=null){let[a,l]=i??t[0].dims,c=new S("int32",new Int32Array(a*l),[a,l]),u=[];if(i!==null)for(let h=0;h<t.length;++h)t[h]=kc(t[h],i,"bilinear",!1);let p=new Int32Array(t[0].data.length),d=new Float32Array(t[0].data.length);for(let h=0;h<t.length;++h){let x=e[h],g=t[h].data;for(let w=0;w<g.length;++w)g[w]*=x,g[w]>d[w]&&(p[w]=h,d[w]=g[w])}let _=0,f=c.data;for(let h=0;h<s.length;++h){let x=s[h],[g,w]=Rv(p,t,h,r,n);if(g){++_;for(let y of w)f[y]=_;u.push({id:_,label_id:x,score:e[h]})}}return[c,u]}function Ji(t,e=.5,s=.5,r=.8,n=null,o=null){n===null&&(L.warn("`label_ids_to_fuse` unset. No instance will be fused."),n=new Set);let i=t.class_queries_logits??t.logits,l=(t.masks_queries_logits??t.pred_masks).sigmoid(),[c,u,p]=i.dims;if(p-=1,o!==null&&o.length!==c)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let d=[];for(let _=0;_<c;++_){let f=o!==null?o[_]:null,h=i[_],x=l[_],[g,w,y]=$v(h,x,e,p);if(y.length===0){let[k,O]=f??x.dims.slice(-2),N=new S("int32",new Int32Array(k*O).fill(-1),[k,O]);d.push({segmentation:N,segments_info:[]});continue}let[b,A]=Fv(g,w,y,s,r,n,f);d.push({segmentation:b,segments_info:A})}return d}function Zi(t,e=.5,s=null){throw new Error("`post_process_instance_segmentation` is not yet implemented.")}var C=class extends ve{constructor(e){super(),this.image_mean=e.image_mean??e.mean,this.image_std=e.image_std??e.std,this.resample=e.resample??2,this.do_rescale=e.do_rescale??!0,this.rescale_factor=e.rescale_factor??1/255,this.do_normalize=e.do_normalize,this.do_thumbnail=e.do_thumbnail,this.size=e.size??e.image_size,this.do_resize=e.do_resize??this.size!==void 0,this.size_divisibility=e.size_divisibility??e.size_divisor,this.do_center_crop=e.do_center_crop,this.crop_size=e.crop_size,this.do_convert_rgb=e.do_convert_rgb??!0,this.do_crop_margin=e.do_crop_margin,this.pad_size=e.pad_size,this.do_pad=e.do_pad,this.min_pixels=e.min_pixels,this.max_pixels=e.max_pixels,this.do_pad&&!this.pad_size&&this.size&&this.size.width!==void 0&&this.size.height!==void 0&&(this.pad_size=this.size),this.do_flip_channel_order=e.do_flip_channel_order??!1,this.config=e}async thumbnail(e,s,r=2){let n=e.height,o=e.width,i=s.height,a=s.width,l=Math.min(n,i),c=Math.min(o,a);return l===n&&c===o?e:(n>o?c=Math.floor(o*l/n):o>n&&(l=Math.floor(n*c/o)),await e.resize(c,l,{resample:r}))}async crop_margin(e,s=200){let r=e.clone().grayscale(),n=br(r.data)[0],i=le(r.data)[0]-n;if(i===0)return e;let a=s/255,l=r.width,c=r.height,u=0,p=0,d=r.data;for(let _=0;_<r.height;++_){let f=_*r.width;for(let h=0;h<r.width;++h)(d[f+h]-n)/i<a&&(l=Math.min(l,h),c=Math.min(c,_),u=Math.max(u,h),p=Math.max(p,_))}return e=await e.crop([l,c,u,p]),e}pad_image(e,s,r,{mode:n="constant",center:o=!1,constant_values:i=0}={}){let[a,l,c]=s,u,p;if(typeof r=="number"?(u=r,p=r):r==="square"?u=p=Math.max(a,l):(u=r.width,p=r.height),u!==l||p!==a){let d=new Float32Array(u*p*c);if(Array.isArray(i))for(let h=0;h<d.length;++h)d[h]=i[h%c];else i!==0&&d.fill(i);let[_,f]=o?[Math.floor((u-l)/2),Math.floor((p-a)/2)]:[0,0];for(let h=0;h<a;++h){let x=(h+f)*u,g=h*l;for(let w=0;w<l;++w){let y=(x+w+_)*c,b=(g+w)*c;for(let A=0;A<c;++A)d[y+A]=e[b+A]}}if(n==="symmetric"){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");let h=a-1,x=l-1;for(let g=0;g<p;++g){let w=g*u,y=Ss(g,h)*l;for(let b=0;b<u;++b){if(g<a&&b<l)continue;let A=(w+b)*c,k=(y+Ss(b,x))*c;for(let O=0;O<c;++O)d[A+O]=e[k+O]}}}e=d,s=[p,u,c]}return[e,s]}rescale(e){for(let s=0;s<e.length;++s)e[s]=this.rescale_factor*e[s]}get_resize_output_image_size(e,s){let[r,n]=e.size,o,i;if(this.do_thumbnail){let{height:a,width:l}=s;o=Math.min(a,l)}else Number.isInteger(s)?(o=s,i=this.config.max_size??o):s!==void 0&&(o=s.shortest_edge,i=s.longest_edge);if(o!==void 0||i!==void 0){let a=o===void 0?1:Math.max(o/r,o/n),l=r*a,c=n*a,u=i===void 0?1:Math.min(i/l,i/c),p=Math.floor(Number((l*u).toFixed(2))),d=Math.floor(Number((c*u).toFixed(2)));return this.size_divisibility!==void 0&&([p,d]=Lu([p,d],this.size_divisibility)),[p,d]}else if(s!==void 0&&s.width!==void 0&&s.height!==void 0){let a=s.width,l=s.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let c=l/n,u=a/r;Math.abs(1-u)<Math.abs(1-c)?c=u:u=c,l=Ly(c*n,this.config.ensure_multiple_of),a=Ly(u*r,this.config.ensure_multiple_of)}return[a,l]}else{if(this.size_divisibility!==void 0)return Lu([r,n],this.size_divisibility);throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(s)}`)}}async resize(e){let[s,r]=this.get_resize_output_image_size(e,this.size);return await e.resize(s,r,{resample:this.resample})}async preprocess(e,{do_normalize:s=null,do_pad:r=null,do_convert_rgb:n=null,do_convert_grayscale:o=null,do_flip_channel_order:i=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));let[a,l]=e.size;if(n??this.do_convert_rgb?e=e.rgb():o&&(e=e.grayscale()),this.do_resize&&(e=await this.resize(e)),this.do_thumbnail&&(e=await this.thumbnail(e,this.size,this.resample)),this.do_center_crop){let _,f;Number.isInteger(this.crop_size)?(_=this.crop_size,f=this.crop_size):(_=this.crop_size.width,f=this.crop_size.height),e=await e.center_crop(_,f)}let c=[e.height,e.width],u=Float32Array.from(e.data),p=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(u),s??this.do_normalize){let _=this.image_mean;Array.isArray(this.image_mean)||(_=new Array(e.channels).fill(_));let f=this.image_std;if(Array.isArray(this.image_std)||(f=new Array(e.channels).fill(f)),_.length!==e.channels||f.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${_.length}) and \`image_std\` (${f.length}) must match the number of channels in the image (${e.channels}).`);for(let h=0;h<u.length;h+=e.channels)for(let x=0;x<e.channels;++x)u[h+x]=(u[h+x]-_[x])/f[x]}if(r??this.do_pad){if(this.pad_size)[u,p]=this.pad_image(u,[e.height,e.width,e.channels],this.pad_size);else if(this.size_divisibility){let[_,f]=Lu([p[1],p[0]],this.size_divisibility);[u,p]=this.pad_image(u,p,{width:_,height:f})}}if(i??this.do_flip_channel_order){if(p[2]!==3)throw new Error("Flipping channel order is only supported for RGB images.");for(let _=0;_<u.length;_+=3){let f=u[_];u[_]=u[_+2],u[_+2]=f}}let d=new S("float32",u,p).permute(2,0,1);return{original_size:[l,a],reshaped_input_size:c,pixel_values:d}}async _call(e,...s){Array.isArray(e)||(e=[e]);let r=await Promise.all(e.map(o=>this.preprocess(o)));return{pixel_values:Je(r.map(o=>o.pixel_values),0),original_sizes:r.map(o=>o.original_size),reshaped_input_sizes:r.map(o=>o.reshaped_input_size)}}static async from_pretrained(e,s={}){let r=await Te(e,Ot,!0,s);return new this(r)}};var js={};As(js,{BeitFeatureExtractor:()=>Ru,BitImageProcessor:()=>Fu,CLIPFeatureExtractor:()=>ju,CLIPImageProcessor:()=>ea,ChineseCLIPFeatureExtractor:()=>Du,ConvNextFeatureExtractor:()=>Uu,ConvNextImageProcessor:()=>ta,DINOv3ViTImageProcessor:()=>Gu,DPTFeatureExtractor:()=>Vu,DPTImageProcessor:()=>na,DeiTFeatureExtractor:()=>Bu,DeiTImageProcessor:()=>sa,DetrFeatureExtractor:()=>qu,DetrImageProcessor:()=>ra,DonutFeatureExtractor:()=>Wu,DonutImageProcessor:()=>$s,EfficientNetImageProcessor:()=>Hu,GLPNFeatureExtractor:()=>Ku,GroundingDinoImageProcessor:()=>Xu,Idefics3ImageProcessor:()=>oa,ImageFeatureExtractor:()=>C,ImageProcessor:()=>C,JinaCLIPImageProcessor:()=>Yu,LlavaOnevisionImageProcessor:()=>Ju,Mask2FormerImageProcessor:()=>ep,MaskFormerFeatureExtractor:()=>Zu,MaskFormerImageProcessor:()=>Rs,MobileNetV1FeatureExtractor:()=>tp,MobileNetV1ImageProcessor:()=>ia,MobileNetV2FeatureExtractor:()=>sp,MobileNetV2ImageProcessor:()=>aa,MobileNetV3FeatureExtractor:()=>rp,MobileNetV3ImageProcessor:()=>la,MobileNetV4FeatureExtractor:()=>np,MobileNetV4ImageProcessor:()=>ca,MobileViTFeatureExtractor:()=>op,MobileViTImageProcessor:()=>ua,NougatImageProcessor:()=>ip,OwlViTFeatureExtractor:()=>ap,OwlViTImageProcessor:()=>Fs,Owlv2ImageProcessor:()=>lp,Phi3VImageProcessor:()=>pp,PixtralImageProcessor:()=>dp,PvtImageProcessor:()=>_p,Qwen2VLImageProcessor:()=>fp,RTDetrImageProcessor:()=>mp,Sam2ImageProcessor:()=>Nr,Sam3ImageProcessor:()=>Nr,SamImageProcessor:()=>Nr,SapiensFeatureExtractor:()=>hp,SapiensImageProcessor:()=>pa,SegformerFeatureExtractor:()=>xp,SegformerImageProcessor:()=>da,SiglipImageProcessor:()=>gp,SmolVLMImageProcessor:()=>oa,Swin2SRImageProcessor:()=>wp,VLMImageProcessor:()=>Qu,ViTFeatureExtractor:()=>yp,ViTImageProcessor:()=>_a,VitMatteImageProcessor:()=>bp,VitPoseImageProcessor:()=>kp,YolosFeatureExtractor:()=>vp,YolosImageProcessor:()=>fa});var Ru=class extends C{};var Fu=class extends C{};var Du=class extends C{};var ea=class extends C{},ju=class extends ea{};var ta=class extends C{constructor(e){super(e),this.crop_pct=this.config.crop_pct??224/256}async resize(e){let s=this.size?.shortest_edge;if(s===void 0)throw new Error("Size dictionary must contain 'shortest_edge' key.");if(s<384){let r=Math.floor(s/this.crop_pct),[n,o]=this.get_resize_output_image_size(e,{shortest_edge:r});e=await e.resize(n,o,{resample:this.resample}),e=await e.center_crop(s,s)}else e=await e.resize(s,s,{resample:this.resample});return e}},Uu=class extends ta{};var sa=class extends C{},Bu=class extends sa{};var ra=class extends C{async _call(e){let s=await super._call(e),r=[s.pixel_values.dims[0],64,64],n=ge(r,1n);return{...s,pixel_mask:n}}post_process_object_detection(...e){return Dt(...e)}post_process_panoptic_segmentation(...e){return Ji(...e)}post_process_instance_segmentation(...e){return Zi(...e)}},qu=class extends ra{};var Gu=class extends C{};var $s=class extends C{pad_image(e,s,r,n={}){let[o,i,a]=s,l=this.image_mean;Array.isArray(this.image_mean)||(l=new Array(a).fill(l));let c=this.image_std;Array.isArray(c)||(c=new Array(a).fill(l));let u=l.map((p,d)=>-p/c[d]);return super.pad_image(e,s,r,{center:!0,constant_values:u,...n})}},Wu=class extends $s{};var na=class extends C{},Vu=class extends na{};var Hu=class extends C{constructor(e){super(e),this.include_top=this.config.include_top??!0,this.include_top&&(this.image_std=this.image_std.map(s=>s*s))}};var Ku=class extends C{};var Xu=class extends C{async _call(e){let s=await super._call(e),r=s.pixel_values.dims,n=Oe([r[0],r[2],r[3]]);return{...s,pixel_mask:n}}};var oa=class extends C{constructor(e){super(e),this.do_image_splitting=e.do_image_splitting??!0,this.max_image_size=e.max_image_size}get_resize_for_vision_encoder(e,s){let[r,n]=e.dims.slice(-2),o=n/r;return n>=r?(n=Math.ceil(n/s)*s,r=Math.floor(n/o),r=Math.ceil(r/s)*s):(r=Math.ceil(r/s)*s,n=Math.floor(r*o),n=Math.ceil(n/s)*s),{height:r,width:n}}async _call(e,{do_image_splitting:s=null,return_row_col_info:r=!1}={}){let n;if(!Array.isArray(e))n=[[e]];else{if(e.length===0||!e[0])throw new Error("No images provided.");Array.isArray(e[0])?n=e:n=[e]}let o=[],i=[],a=[],l=[],c=[];for(let g of n){let w=await Promise.all(g.map(A=>this.preprocess(A)));l.push(...w.map(A=>A.original_size)),c.push(...w.map(A=>A.reshaped_input_size)),w.forEach(A=>A.pixel_values.unsqueeze_(0));let{longest_edge:y}=this.max_image_size,b;if(s??this.do_image_splitting){let A=new Array(w.length),k=new Array(w.length);b=await Promise.all(w.map(async(O,N)=>{let D=this.get_resize_for_vision_encoder(O.pixel_values,y),F=await Ye(O.pixel_values,{size:[D.height,D.width]}),{frames:B,num_splits_h:W,num_splits_w:j}=await this.split_image(F,this.max_image_size);return A[N]=W,k[N]=j,ie(B,0)})),i.push(A),a.push(k)}else{let A=[y,y];b=await Promise.all(w.map(k=>Ye(k.pixel_values,{size:A}))),i.push(new Array(w.length).fill(0)),a.push(new Array(w.length).fill(0))}o.push(ie(b,0))}let u=o.length,[p,d,_,f]=o[0].dims,h,x;if(u===1)h=o[0].unsqueeze_(0),x=ge([u,p,_,f],!0);else{let g=Math.max(...o.map(b=>b.dims.at(0)));x=ge([u,g,_,f],!0);let w=x.data,y=g*_*f;for(let b=0;b<u;++b){let A=o[b].dims[0];if(A<g){o[b]=ie([o[b],ge([g-A,d,_,f],0)],0);let k=b*y+A*_*f,O=(b+1)*y;w.fill(!1,k,O)}}h=Je(o,0)}return{pixel_values:h,pixel_attention_mask:x,original_sizes:l,reshaped_input_sizes:c,...r?{rows:i,cols:a}:{}}}async split_image(e,{longest_edge:s}){let r=s,n=s,o=[],[i,a]=e.dims.slice(-2),l=0,c=0;if(i>r||a>n){l=Math.ceil(i/r),c=Math.ceil(a/n);let u=Math.ceil(i/l),p=Math.ceil(a/c);for(let f=0;f<l;++f)for(let h=0;h<c;++h){let x,g,w,y;f===l-1?(g=i-u,y=i):(g=f*u,y=(f+1)*u),h===c-1?(x=a-p,w=a):(x=h*p,w=(h+1)*p);let k=await Wi(e,[g,x],[y,w],[2,3]);o.push(k)}let d=r,_=n;(i!==d||a!==_)&&(e=await Ye(e,{size:[d,_]}))}return o.push(e),{frames:o,num_splits_h:l,num_splits_w:c}}};var Qu=class extends C{constructor(e){super({do_pad:!0,pad_size:{width:e.image_size,height:e.image_size},...e}),this.constant_values=this.config.background_color.map(s=>s*this.rescale_factor)}pad_image(e,s,r,n){return super.pad_image(e,s,r,{constant_values:this.constant_values,center:!0,...n})}};var Yu=class extends C{constructor(e){let{resize_mode:s,fill_color:r,interpolation:n,size:o,...i}=e,a=s==="squash"?{width:o,height:o}:s==="shortest"?{shortest_edge:o}:{longest_edge:o},l=n==="bicubic"?3:2;super({...i,size:a,resample:l,do_center_crop:!0,crop_size:o,do_normalize:!0})}};var Ju=class extends C{};var Rs=class extends C{post_process_panoptic_segmentation(...e){return Ji(...e)}post_process_instance_segmentation(...e){return Zi(...e)}},Zu=class extends Rs{};var ep=class extends Rs{};var ia=class extends C{},tp=class extends ia{};var aa=class extends C{},sp=class extends aa{};var la=class extends C{},rp=class extends la{};var ca=class extends C{},np=class extends ca{};var ua=class extends C{},op=class extends ua{};var ip=class extends $s{};var Fs=class extends C{post_process_object_detection(...e){return Dt(...e)}},ap=class extends Fs{};var lp=class extends Fs{};var Ve=336,Dv=[2,3],{ceil:cp,floor:Ds,sqrt:up}=Math,pp=class extends C{constructor(e){super({...e,do_normalize:!0,do_pad:!0,pad_size:"custom",do_convert_rgb:!0,do_resize:!0}),this._num_crops=e.num_crops}calc_num_image_tokens_from_image_size(e,s){let{num_img_tokens:r}=this.config;return Ds((Ds(s/Ve)*Ds(e/Ve)+1)*r+1+(Ds(s/Ve)+1)*up(r))}get_resize_output_image_size(e,s){let r=this._num_crops,[n,o]=e.size,i=n/o,a=1;for(;a*Math.ceil(a/i)<=r;)a+=1;a-=1;let l=Math.floor(a*336),c=Math.floor(l/i);return[l,c]}pad_image(e,s,r,n={}){let[o,i]=s,a=Ve*cp(o/Ve),l=Ve*cp(i/Ve),c=[1,1,1].map((u,p)=>(u-this.image_mean[p])/this.image_std[p]);return super.pad_image(e,s,{width:l,height:a},{center:!0,constant_values:c,...n})}async _call(e,{num_crops:s=null}={}){if(this._num_crops=s??=this.config.num_crops,s<4||up(s)%1!==0)throw new Error("num_crops must be a square number >= 4");Array.isArray(e)||(e=[e]);let r=e.length,n=await Promise.all(e.map(d=>this.preprocess(d))),o=n.map(d=>d.original_size),i=n.map(d=>d.reshaped_input_size),a=[];for(let{pixel_values:d}of n){d.unsqueeze_(0);let[_,f]=d.dims.slice(-2),h=await Ye(d,{size:[Ve,Ve],mode:"bicubic"});if(s>0){let x=[],g=up(s),w=Ds(f/g),y=Ds(_/g);for(let A=0;A<g;++A)for(let k=0;k<g;++k){let O,N,D,F;A===g-1?(N=_-y,F=_):(N=A*y,F=(A+1)*y),k===g-1?(O=f-w,D=f):(O=k*w,D=(k+1)*w);let j=await Wi(d,[N,O],[F,D],Dv);x.push(j)}let b=await Ye(ie(x,0),{size:[Ve,Ve],mode:"bicubic"});a.push(ie([h,b],0))}else a.push(h)}let l=Je(a,0),c=i.map(d=>d.map(_=>Ve*cp(_/Ve))),u=new S("int64",c.flat(),[r,2]),p=c.map(([d,_])=>this.calc_num_image_tokens_from_image_size(_,d));return{pixel_values:l,original_sizes:o,reshaped_input_sizes:i,image_sizes:u,num_img_tokens:p}}};var dp=class extends C{get_resize_output_image_size(e,s){let{longest_edge:r}=s;if(r===void 0)throw new Error("size must contain 'longest_edge'");let[n,o]=e.size,i=Math.max(n,o)/r,a=n,l=o;i>1&&(a=Math.floor(n/i),l=Math.floor(o/i));let{patch_size:c,spatial_merge_size:u}=this.config;if(!u)throw new Error("config must contain 'spatial_merge_size'");let p=c*u,d=Math.floor((a-1)/p)+1,_=Math.floor((l-1)/p)+1;return[d*p,_*p]}};var _p=class extends C{};function jv(t,e,s=28,r=3136,n=784*1280){if(t<s||e<s)throw new Error(`height:${t} or width:${e} must be larger than factor:${s}`);if(Math.max(t,e)/Math.min(t,e)>200)throw new Error(`absolute aspect ratio must be smaller than 200, got ${Math.max(t,e)/Math.min(t,e)}`);let o=Math.round(t/s)*s,i=Math.round(e/s)*s;if(o*i>n){let a=Math.sqrt(t*e/n);o=Math.floor(t/a/s)*s,i=Math.floor(e/a/s)*s}else if(o*i<r){let a=Math.sqrt(r/(t*e));o=Math.ceil(t*a/s)*s,i=Math.ceil(e*a/s)*s}return[o,i]}var fp=class extends C{constructor(e){super(e),this.min_pixels=e.min_pixels??e.size?.shortest_edge,this.max_pixels=e.max_pixels??e.size?.longest_edge,this.patch_size=e.patch_size,this.merge_size=e.merge_size}get_resize_output_image_size(e,s){let r=this.patch_size*this.merge_size;return jv(e.height,e.width,r,this.min_pixels,this.max_pixels)}async _call(e,...s){let{pixel_values:r,original_sizes:n,reshaped_input_sizes:o}=await super._call(e,...s),i=r,{temporal_patch_size:a,merge_size:l,patch_size:c}=this.config;i.dims[0]===1&&(i=ie(Array.from({length:a},()=>i),0));let u=i.dims[0]/a,p=i.dims[1],d=Math.floor(i.dims[2]/c),_=Math.floor(i.dims[3]/c),f=i.view(u,a,p,Math.floor(d/l),l,c,Math.floor(_/l),l,c).permute(0,3,6,4,7,2,1,5,8).view(u*d*_,p*a*c*c),h=new S("int64",[u,d,_],[1,3]);return{pixel_values:f,image_grid_thw:h,original_sizes:n,reshaped_input_sizes:o}}};var mp=class extends C{post_process_object_detection(...e){return Dt(...e)}};var Nr=class extends C{reshape_input_points(e,s,r,n=!1){e=structuredClone(e);let o=ac(e);if(o.length===3)n||(o=[1,...o]),e=[e];else if(o.length!==4)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let i=0;i<e.length;++i){let[a,l]=s[i],[c,u]=r[i],p=[u/l,c/a];for(let d=0;d<e[i].length;++d)for(let _=0;_<e[i][d].length;++_)for(let f=0;f<e[i][d][_].length;++f)e[i][d][_][f]*=p[f%2]}return new S("float32",Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,s){let r=ac(e);if(r.length===2)r=[1,...r],e=[e];else if(r.length!==3)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");if(r.some((n,o)=>n!==s.dims[o]))throw Error(`The first ${r.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new S("int64",e.flat(1/0).map(BigInt),r)}async _call(e,{input_points:s=null,input_labels:r=null,input_boxes:n=null}={}){let o=await super._call(e);if(s&&(o.input_points=this.reshape_input_points(s,o.original_sizes,o.reshaped_input_sizes)),r){if(!o.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");o.input_labels=this.add_input_labels(r,o.input_points)}return n&&(o.input_boxes=this.reshape_input_points(n,o.original_sizes,o.reshaped_input_sizes,!0)),o}async post_process_masks(e,s,r,{mask_threshold:n=0,binarize:o=!0,pad_size:i=null}={}){let a=[];i=i??this.pad_size??this.size;let l=[i.height,i.width];for(let c=0;c<s.length;++c){let u=s[c],p=r[c],d=await Ye(e[c],{mode:"bilinear",size:l});if(d=d.slice(null,null,[0,p[0]],[0,p[1]]),d=await Ye(d,{mode:"bilinear",size:u}),o){let _=d.data,f=new Uint8Array(_.length);for(let h=0;h<_.length;++h)_[h]>n&&(f[h]=1);d=new S("bool",f,d.dims)}a.push(d)}return a}generate_crop_boxes(e,s,{crop_n_layers:r=0,overlap_ratio:n=512/1500,points_per_crop:o=32,crop_n_points_downscale_factor:i=1}={}){}};var pa=class extends C{post_process_semantic_segmentation(...e){return Yi(...e)}},hp=class extends pa{};var da=class extends C{post_process_semantic_segmentation(...e){return Yi(...e)}},xp=class extends da{};var gp=class extends C{};var wp=class extends C{pad_image(e,s,r,n={}){let[o,i,a]=s;return super.pad_image(e,s,{width:i+(r-i%r)%r,height:o+(r-o%r)%r},{mode:"symmetric",center:!1,constant_values:-1,...n})}};var _a=class extends C{},yp=class extends _a{};var bp=class extends C{async _call(e,s){Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);let r=await Promise.all(e.map(i=>this.preprocess(i))),n=await Promise.all(s.map(i=>this.preprocess(i,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})));return{pixel_values:Je(r.map((i,a)=>ie([i.pixel_values,n[a].pixel_values],0)),0),original_sizes:r.map(i=>i.original_size),reshaped_input_sizes:r.map(i=>i.reshaped_input_size)}}};var kp=class extends C{post_process_pose_estimation(e,s,{threshold:r=null}={}){let n=e.tolist(),[o,i,a,l]=e.dims,c=[];for(let u=0;u<o;++u){let p=n[u],d=s[u],_=[];for(let f=0;f<d.length;++f){let h=d[f],x=[],g=[],w=[],y=h.at(-2)/l,b=h.at(-1)/a;for(let A=0;A<p.length;++A){let[k,O]=[0,0],N=0,D=-1/0,F=p[A];for(let W=0;W<F.length;++W){let j=F[W];for(let Q=0;Q<j.length;++Q){let K=j[Q];N+=K,D=Math.max(D,K),k+=(Q+.5)*K,O+=W*K}}if(r!=null&&D<r)continue;let B=[y*k/N,b*O/N];x.push(B),w.push(A),g.push(D)}_.push({bbox:h,scores:g,labels:w,keypoints:x})}c.push(_)}return c}};var fa=class extends C{post_process_object_detection(...e){return Dt(...e)}},vp=class extends fa{};var fe=class{static async from_pretrained(e,s={}){let r=await Te(e,Ot,!0,s),n=r.image_processor_type??r.feature_extractor_type,o=js[n?.replace(/Fast$/,"")];return o||(n!==void 0&&L.warn(`Image processor type '${n}' not found, assuming base ImageProcessor. Please report this at ${Rt}.`),o=C),new o(r)}};var Ep=class extends U{static tokenizer_class=$;static image_processor_class=fe;constructor(e,s,r){super(e,s,r);let{tasks_answer_post_processing_type:n,task_prompts_without_inputs:o,task_prompts_with_input:i}=this.image_processor.config;this.tasks_answer_post_processing_type=new Map(Object.entries(n??{})),this.task_prompts_without_inputs=new Map(Object.entries(o??{})),this.task_prompts_with_input=new Map(Object.entries(i??{})),this.regexes={quad_boxes:/(.+?)<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm,bboxes:/([^<]+)?<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm},this.size_per_bin=1e3}construct_prompts(e){typeof e=="string"&&(e=[e]);let s=[];for(let r of e)if(this.task_prompts_without_inputs.has(r))s.push(this.task_prompts_without_inputs.get(r));else{for(let[n,o]of this.task_prompts_with_input)if(r.includes(n)){s.push(o.replaceAll("{input}",r).replaceAll(n,""));break}s.length!==e.length&&s.push(r)}return s}post_process_generation(e,s,r){let n=this.tasks_answer_post_processing_type.get(s)??"pure_text";e=e.replaceAll("<s>","").replaceAll("</s>","");let o;switch(n){case"pure_text":o=e;break;case"description_with_bboxes":case"bboxes":case"phrase_grounding":case"ocr":let i=n==="ocr"?"quad_boxes":"bboxes",a=e.matchAll(this.regexes[i]),l=[],c=[];for(let[u,p,...d]of a)l.push(p?p.trim():l.at(-1)??""),c.push(d.map((_,f)=>(Number(_)+.5)/this.size_per_bin*r[f%2]));o={labels:l,[i]:c};break;default:throw new Error(`Task "${s}" (of type "${n}") not yet implemented.`)}return{[s]:o}}async _call(e,s=null,r={}){if(!e&&!s)throw new Error("Either text or images must be provided");let n=await this.image_processor(e,r),o=s?this.tokenizer(this.construct_prompts(s),r):{};return{...n,...o}}};var Ap=class extends U{static image_processor_class=fe;static feature_extractor_class=Ee;static tokenizer_class=$;static uses_processor_config=!0;static uses_chat_template_file=!0;constructor(e,s,r){super(e,s,r),this.audio_seq_length=this.config.audio_seq_length,this.image_seq_length=this.config.image_seq_length;let{audio_token_id:n,boa_token:o,audio_token:i,eoa_token:a,image_token_id:l,boi_token:c,image_token:u,eoi_token:p}=this.tokenizer.config;this.audio_token_id=n,this.boa_token=o,this.audio_token=i;let d=i.repeat(this.audio_seq_length);this.full_audio_sequence=`
11
11
 
12
12
  ${o}${d}${a}
13
13
 
@@ -15,10 +15,10 @@ ${o}${d}${a}
15
15
 
16
16
  ${c}${_}${p}
17
17
 
18
- `}async _call(e,s=null,r=null,n={}){typeof e=="string"&&(e=[e]);let o;r&&(o=await this.feature_extractor(r,n),e=e.map(l=>l.replaceAll(this.audio_token,this.full_audio_sequence)));let i;return s&&(i=await this.image_processor(s,n),e=e.map(l=>l.replaceAll(this.image_token,this.full_image_sequence))),{...this.tokenizer(e,n),...i,...o}}};function lv(t,e){let r=t.dims.at(-1)-1,n=t.tolist();n.fill(!1,0,1),n.fill(!1,r);let o=e.tolist();return n.map((i,a)=>i?a:null).filter(i=>i!==null).map(i=>o[i])}var sp=class extends j{static tokenizer_class=L;static image_processor_class=de;async _call(e,s,r={}){let n=e?await this.image_processor(e,r):{};return{...s?this.tokenizer(s,r):{},...n}}post_process_grounded_object_detection(e,s,{box_threshold:r=.25,text_threshold:n=.25,target_sizes:o=null}={}){let{logits:i,pred_boxes:a}=e,l=i.dims[0];if(o!==null&&o.length!==l)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let c=i.dims.at(1),u=i.sigmoid(),p=u.max(-1).tolist(),d=a.tolist().map(m=>m.map(h=>du(h))),_=[];for(let m=0;m<l;++m){let h=o!==null?o[m]:null;h!==null&&(d[m]=d[m].map(E=>E.map((A,b)=>A*h[(b+1)%2])));let x=p[m],g=[],w=[],y=[];for(let E=0;E<c;++E){let A=x[E];if(A<=r)continue;let b=d[m][E],O=u[m][E];g.push(A),y.push(b);let N=lv(O.gt(n),s[m]);w.push(N)}_.push({scores:g,boxes:y,labels:this.batch_decode(w)})}return _}};function cv(t,e,s,r,n,o){let i="";for(let a=0;a<e;++a){for(let l=0;l<s;++l)i+=r+`<row_${a+1}_col_${l+1}>`+n.repeat(t);i+=`
18
+ `}async _call(e,s=null,r=null,n={}){typeof e=="string"&&(e=[e]);let o;r&&(o=await this.feature_extractor(r,n),e=e.map(l=>l.replaceAll(this.audio_token,this.full_audio_sequence)));let i;return s&&(i=await this.image_processor(s,n),e=e.map(l=>l.replaceAll(this.image_token,this.full_image_sequence))),{...this.tokenizer(e,n),...i,...o}}};function Uv(t,e){let r=t.dims.at(-1)-1,n=t.tolist();n.fill(!1,0,1),n.fill(!1,r);let o=e.tolist();return n.map((i,a)=>i?a:null).filter(i=>i!==null).map(i=>o[i])}var Mp=class extends U{static tokenizer_class=$;static image_processor_class=fe;async _call(e,s,r={}){let n=e?await this.image_processor(e,r):{};return{...s?this.tokenizer(s,r):{},...n}}post_process_grounded_object_detection(e,s,{box_threshold:r=.25,text_threshold:n=.25,target_sizes:o=null}={}){let{logits:i,pred_boxes:a}=e,l=i.dims[0];if(o!==null&&o.length!==l)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let c=i.dims.at(1),u=i.sigmoid(),p=u.max(-1).tolist(),d=a.tolist().map(f=>f.map(h=>$u(h))),_=[];for(let f=0;f<l;++f){let h=o!==null?o[f]:null;h!==null&&(d[f]=d[f].map(b=>b.map((A,k)=>A*h[(k+1)%2])));let x=p[f],g=[],w=[],y=[];for(let b=0;b<c;++b){let A=x[b];if(A<=r)continue;let k=d[f][b],O=u[f][b];g.push(A),y.push(k);let N=Uv(O.gt(n),s[f]);w.push(N)}_.push({scores:g,boxes:y,labels:this.batch_decode(w)})}return _}};function Bv(t,e,s,r,n,o){let i="";for(let a=0;a<e;++a){for(let l=0;l<s;++l)i+=r+`<row_${a+1}_col_${l+1}>`+n.repeat(t);i+=`
19
19
  `}return i+=`
20
- ${r}${o}`+n.repeat(t)+`${r}`,i}function uv(t,e,s,r){return`${e}${r}`+s.repeat(t)+`${e}`}function pv(t,e,s,r,n,o){return t===0&&e===0?uv(s,r,n,o):cv(s,t,e,r,n,o)}var Ei=class extends j{static image_processor_class=de;static tokenizer_class=L;static uses_processor_config=!0;fake_image_token="<fake_token_around_image>";image_token="<image>";global_img_token="<global-img>";async _call(e,s=null,r={}){r.return_row_col_info??=!0;let n;s&&(n=await this.image_processor(s,r)),Array.isArray(e)||(e=[e]);let o=n.rows??[new Array(e.length).fill(0)],i=n.cols??[new Array(e.length).fill(0)],a=this.config.image_seq_len,l=[],c=[];for(let p=0;p<e.length;++p){let d=e[p],_=o[p],m=i[p];l.push(aw(d,this.image_token));let h=_.map((w,y)=>pv(w,m[y],a,this.fake_image_token,this.image_token,this.global_img_token)),x=d.split(this.image_token);if(x.length===0)throw new Error("The image token should be present in the text.");let g=x[0];for(let w=0;w<h.length;++w)g+=h[w]+x[w+1];c.push(g)}return{...this.tokenizer(c),...n}}};var rp=class extends j{static image_processor_class=de;static tokenizer_class=L;static uses_processor_config=!0;constructor(e,s,r){super(e,s,r),this.image_tag=this.config.image_tag,this.image_start_tag=this.config.image_start_tag,this.image_end_tag=this.config.image_end_tag,this.num_image_tokens=this.config.num_image_tokens}async _call(e,{images:s=null,chat_template:r="default"}={}){s?Array.isArray(s)||(s=[s]):s=await Promise.all(e.filter(x=>x.images).flatMap(x=>x.images).map(x=>we.read(x)));let n=this.tokenizer,o=n.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0,chat_template:r}),i=x=>n.encode(x,{add_special_tokens:!1}),a=o.split(this.image_tag),l=a.length-1;if(s.length!==l)throw new Error(`Number of images provided (${s.length}) does not match number of "${this.image_tag}" image tags (${l})`);let[c,u,p]=n.convert_tokens_to_ids([this.image_tag,this.image_start_tag,this.image_end_tag]),d=i(a[0]),_=new Array(d.length).fill(!1);for(let x=1;x<a.length;++x){let g=new Array(this.num_image_tokens).fill(c),w=i(a[x]);d=Pe(d,[u],g,[p],w);let y=new Array(this.num_image_tokens).fill(!0);_=Pe(_,[!1],y,[!1],new Array(w.length).fill(!1))}let m=[1,d.length],h={input_ids:new S("int64",d,m),attention_mask:new S("int64",new Array(d.length).fill(1),m),images_seq_mask:new S("bool",_,m),images_emb_mask:new S("bool",new Array(l*this.num_image_tokens).fill(!0),[1,l,this.num_image_tokens])};if(s&&s.length>0){let x=await this.image_processor(s);return x.pixel_values.unsqueeze_(0),{...h,...x}}return h}};var np=class extends j{static tokenizer_class=L;static image_processor_class=de;async _call(e=null,s=null,r={}){if(!e&&!s)throw new Error("Either text or images must be provided");let n=e?this.tokenizer(e,r):{},o=s?await this.image_processor(s,r):{};return{...n,...o}}};var op=class extends j{static tokenizer_class=L;static image_processor_class=de;static uses_processor_config=!0;async _call(e,s=null,r={}){let n=await this.image_processor(e,r);if(s){let[i,a]=n.pixel_values.dims.slice(-2),{image_token:l,patch_size:c,num_additional_image_tokens:u}=this.config,p=Math.floor(i/c)*Math.floor(a/c)+u;s=structuredClone(s),Array.isArray(s)||(s=[s]);for(let d=0;d<s.length;++d)s[d]=s[d].replace(l,l.repeat(p))}let o=s?this.tokenizer(s,r):{};return{...n,...o}}};var ey={char:["char_decode",1],bpe:["bpe_decode",2],wp:["wp_decode",102]},ip=class extends j{static tokenizer_class=L;static image_processor_class=de;get char_tokenizer(){return this.components.char_tokenizer}get bpe_tokenizer(){return this.components.bpe_tokenizer}get wp_tokenizer(){return this.components.wp_tokenizer}_decode_helper(e,s){if(!ey.hasOwnProperty(s))throw new Error(`Format ${s} is not supported.`);let[r,n]=ey[s],o=this[r].bind(this),[i,a]=e.dims,l=[],c=[],u=e.tolist();for(let d=0;d<i;++d){let _=u[d],m=[],h=[];for(let g=1;g<a;++g){let[w,y]=ie(ce(_[g]));if(h.push(w),y==n)break;m.push(y)}let x=h.length>0?h.reduce((g,w)=>g*w,1):0;c.push(m),l.push(x)}return[o(c),l]}char_decode(e){return this.char_tokenizer.batch_decode(e).map(s=>s.replaceAll(" ",""))}bpe_decode(e){return this.bpe_tokenizer.batch_decode(e)}wp_decode(e){return this.wp_tokenizer.batch_decode(e).map(s=>s.replaceAll(" ",""))}batch_decode([e,s,r]){let[n,o]=this._decode_helper(e,"char"),[i,a]=this._decode_helper(s,"bpe"),[l,c]=this._decode_helper(r,"wp"),u=[],p=[];for(let d=0;d<n.length;++d){let[_,m]=ie([o[d],a[d],c[d]]);u.push([n[d],i[d],l[d]][m]),p.push(_)}return{generated_text:u,scores:p,char_preds:n,bpe_preds:i,wp_preds:l}}static async from_pretrained(...e){let s=await super.from_pretrained(...e),r=await L.from_pretrained("Xenova/gpt2"),n=await L.from_pretrained("Xenova/bert-base-uncased");return s.components={image_processor:s.image_processor,char_tokenizer:s.tokenizer,bpe_tokenizer:r,wp_tokenizer:n},s}async _call(e,s=null){let r=await this.image_processor(e);return s&&(r.labels=this.tokenizer(s).input_ids),r}};var ap=class extends j{static tokenizer_class=L;static feature_extractor_class=ve;async _call(e){return await this.feature_extractor(e)}};var lp=class extends j{static tokenizer_class=L;static image_processor_class=de};var Os="<image>";function dv(t,e,s,r,n){return`${r.repeat(s*n)}${e}${t}
21
- `}var cp=class extends j{static tokenizer_class=L;static image_processor_class=de;static uses_processor_config=!1;async _call(e,s=null,r={}){s||(console.warn("You are using PaliGemma without a text prefix. It will perform as a picture-captioning model."),s=""),Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);let n=this.tokenizer.bos_token,o=this.image_processor.config.image_seq_length,i;s.some(c=>c.includes(Os))?i=s.map(c=>{let u=c.replaceAll(Os,Os.repeat(o)),p=u.lastIndexOf(Os),d=p===-1?0:p+Os.length;return u.slice(0,d)+n+u.slice(d)+`
22
- `}):(console.warn("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."),i=s.map(c=>dv(c,n,o,Os,e.length)));let a=this.tokenizer(i,r);return{...await this.image_processor(e,r),...a}}};var ty="<|image|>",_v=/<\|image_\d+\|>/g,up=class extends j{static image_processor_class=de;static tokenizer_class=L;async _call(e,s=null,{padding:r=!0,truncation:n=!0,num_crops:o=null}={}){Array.isArray(e)||(e=[e]);let i,a;if(s){a=await this.image_processor(s,{num_crops:o});let{num_img_tokens:l}=a,c=e.map((p,d)=>p.split(_v).join(ty.repeat(l[d])));i=this.tokenizer(c,{padding:r,truncation:n});let u=this.tokenizer._tokenizer.token_to_id(ty);i.input_ids.map_(p=>p==u?-p:p)}else i=this.tokenizer(e);return{...i,...a}}};var pp=class extends j{static tokenizer_class=L;static image_processor_class=de;static uses_processor_config=!0;async _call(e,s=null,r={}){let n=await this.image_processor(e,r);if(s){let[i,a]=n.pixel_values.dims.slice(-2),{image_token:l,image_break_token:c,image_end_token:u,patch_size:p,spatial_merge_size:d}=this.config,_=p*d,m=Math.floor(i/_),h=Math.floor(a/_);s=structuredClone(s),Array.isArray(s)||(s=[s]);for(let x=0;x<s.length;++x){let g=l.repeat(h),w=g+c,y=g+u,E=w.repeat(m-1)+y;s[x]=s[x].replace(l,E)}}let o=s?this.tokenizer(s,r):{};return{...n,...o}}};var dp=class extends j{static feature_extractor_class=wr;async _call(e){return await this.feature_extractor(e)}post_process_speaker_diarization(...e){return this.feature_extractor.post_process_speaker_diarization(...e)}get sampling_rate(){return this.feature_extractor.config.sampling_rate}};var _p=class extends j{static image_processor_class=de;static tokenizer_class=L;async _call(e,s=null,...r){Array.isArray(e)||(e=[e]);let n,o;if(s&&(n=await this.image_processor(s),o=n.image_grid_thw),o){let a=this.image_processor.config.merge_size**2,l=0,c=o.tolist();e=e.map(u=>{for(;u.includes("<|image_pad|>");){let p=Number(c[l++].reduce((d,_)=>d*_,1n));u=u.replace("<|image_pad|>","<|placeholder|>".repeat(Math.floor(p/a)))}return u.replaceAll("<|placeholder|>","<|image_pad|>")})}return{...this.tokenizer(e),...n}}};var kr=class extends j{static image_processor_class=de;async _call(...e){return await this.image_processor(...e)}post_process_masks(...e){return this.image_processor.post_process_masks(...e)}reshape_input_points(...e){return this.image_processor.reshape_input_points(...e)}};var Ai=class extends kr{},fp=class extends Ai{};var mp=class extends j{static tokenizer_class=L;static feature_extractor_class=ve;async _call(e){return await this.feature_extractor(e)}};var hp=class extends j{static tokenizer_class=L;static feature_extractor_class=ve;static uses_processor_config=!0;async _call(e,s=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(s){let i=s.length,{input_features:a}=await this.feature_extractor(s,{...r,max_length:i}),l=Math.round(i/this.config.encoder_ds_factor+1e-4),c=1+Math.ceil(l/this.config.stack_factor);n.audio_token_len=[c],n.audio_values=a;let u=this.config.audio_placeholder;if(!e.includes(u))throw new Error(`The input text does not contain the image token ${u}.`);e=e.replaceAll(u,u.repeat(c))}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};var Mi="[AUDIO]",fv="[BEGIN_AUDIO]",mv=375;function hv(t,e){let s=[];for(let r=0;r<t.length;r+=e)s.push(t.subarray(r,Math.min(r+e,t.length)));return s}var xp=class extends j{static tokenizer_class=L;static feature_extractor_class=ve;static uses_processor_config=!1;async _call(e,s=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(s){if(!e.includes(Mi))throw new Error(`The input text does not contain the audio token ${Mi}.`);Array.isArray(s)||(s=[s]);let i=e.split(Mi),a=i.length-1;if(a!==s.length)throw new Error(`The number of audio inputs (${s.length}) does not match the number of audio tokens in the text (${a}).`);let l=this.feature_extractor.config.n_samples,c=s.map(m=>hv(m,l)),u=c.map(m=>m.length),p=c.flat(),d=(await Promise.all(p.map(m=>this.feature_extractor(m,r)))).map(m=>m.input_features);n.audio_values=d.length>1?ne(d,0):d[0];let _=i[0];for(let m=0;m<u.length;++m){_+=fv;for(let h=0;h<u[m];++h)_+=Mi.repeat(mv);_+=i[m+1]}e=_}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};var gp=class extends j{static tokenizer_class=L;static feature_extractor_class=ve;async _call(e){return await this.feature_extractor(e)}};var wp=class extends j{static tokenizer_class=L;static feature_extractor_class=ve;async _call(e){return await this.feature_extractor(e)}};var yp=class extends j{static tokenizer_class=L;static feature_extractor_class=ve;async _call(e){return await this.feature_extractor(e)}};var ze=class{static async from_pretrained(e,s={}){let r=await Se(e,ks,!0,s),{image_processor_type:n,feature_extractor_type:o,processor_class:i}=r;if(i&&Si[i])return Si[i].from_pretrained(e,s);if(!n&&!o)throw new Error("No `image_processor_type` or `feature_extractor_type` found in the config.");let a={};if(n){let c=Ss[n.replace(/Fast$/,"")];if(!c)throw new Error(`Unknown image_processor_type: '${n}'.`);a.image_processor=new c(r)}if(o){let c=Ss[o];if(c)a.image_processor=new c(r);else{let u=yr[o];if(!u)throw new Error(`Unknown feature_extractor_type: '${o}'.`);a.feature_extractor=new u(r)}}let l={};return new j(l,a,null)}};async function xv(t,e){return await Se(t,"config.json",!0,e)}function Is(t){let e={},s={};switch(t.model_type){case"llava":case"paligemma":case"gemma3":case"florence2":case"llava_onevision":case"idefics3":case"ultravox":case"voxtral":case"smolvlm":case"gemma3n":case"chatterbox":case"mistral3":s=Is(t.text_config);break;case"moondream1":s=Is(t.phi_config);break;case"musicgen":s=Is(t.decoder);break;case"multi_modality":s=Is(t.language_config);break;case"gpt2":case"gptj":case"jais":case"codegen":case"gpt_bigcode":e.num_heads="n_head",e.num_layers="n_layer",e.hidden_size="n_embd";break;case"gpt_neox":case"stablelm":case"opt":case"falcon":case"modernbert-decoder":e.num_heads="num_attention_heads",e.num_layers="num_hidden_layers",e.hidden_size="hidden_size";break;case"gpt_oss":case"llama":case"llama4_text":case"nanochat":case"apertus":case"arcee":case"lfm2":case"lfm2_moe":case"smollm3":case"olmo":case"olmo2":case"olmo3":case"mobilellm":case"granite":case"granitemoehybrid":case"cohere":case"cohere2":case"mistral":case"starcoder2":case"qwen2":case"qwen2_vl":case"phi":case"phi3":case"phi3_v":case"llava_qwen2":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.hidden_size="hidden_size",e.num_attention_heads="num_attention_heads",e.dim_kv="head_dim";break;case"qwen3":case"gemma":case"gemma2":case"vaultgemma":case"gemma3_text":case"gemma3n_text":case"glm":case"helium":case"ernie4_5":case"hunyuan_v1_dense":case"falcon_h1":case"ministral":case"ministral3":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.dim_kv="head_dim";break;case"openelm":e.num_heads="num_kv_heads",e.num_layers="num_transformer_layers",e.dim_kv="head_dim";break;case"gpt_neo":case"donut-swin":e.num_heads="num_heads",e.num_layers="num_layers",e.hidden_size="hidden_size";break;case"bloom":e.num_heads="n_head",e.num_layers="n_layer",e.hidden_size="hidden_size";break;case"mpt":e.num_heads="n_heads",e.num_layers="n_layers",e.hidden_size="d_model";break;case"exaone":e.num_heads="num_key_value_heads",e.num_layers="num_layers",e.dim_kv="head_dim",e.num_attention_heads="num_attention_heads";break;case"youtu":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.dim_kv="qk_head_dim",e.num_attention_heads="num_attention_heads";break;case"t5":case"mt5":case"longt5":e.num_decoder_layers="num_decoder_layers",e.num_decoder_heads="num_heads",e.decoder_dim_kv="d_kv",e.num_encoder_layers="num_layers",e.num_encoder_heads="num_heads",e.encoder_dim_kv="d_kv";break;case"bart":case"mbart":case"marian":case"whisper":case"lite-whisper":case"m2m_100":case"blenderbot":case"blenderbot-small":case"florence2_language":e.num_decoder_layers="decoder_layers",e.num_decoder_heads="decoder_attention_heads",e.decoder_hidden_size="d_model",e.num_encoder_layers="encoder_layers",e.num_encoder_heads="encoder_attention_heads",e.encoder_hidden_size="d_model";break;case"speecht5":e.num_decoder_layers="decoder_layers",e.num_decoder_heads="decoder_attention_heads",e.decoder_hidden_size="hidden_size",e.num_encoder_layers="encoder_layers",e.num_encoder_heads="encoder_attention_heads",e.encoder_hidden_size="hidden_size";break;case"trocr":e.num_encoder_layers=e.num_decoder_layers="decoder_layers",e.num_encoder_heads=e.num_decoder_heads="decoder_attention_heads",e.encoder_hidden_size=e.decoder_hidden_size="d_model";break;case"musicgen_decoder":e.num_encoder_layers=e.num_decoder_layers="num_hidden_layers",e.num_encoder_heads=e.num_decoder_heads="num_attention_heads",e.encoder_hidden_size=e.decoder_hidden_size="hidden_size";break;case"moonshine":e.num_decoder_layers="decoder_num_hidden_layers",e.num_decoder_heads="decoder_num_key_value_heads",e.num_encoder_layers="encoder_num_hidden_layers",e.num_encoder_heads="encoder_num_key_value_heads",e.encoder_hidden_size=e.decoder_hidden_size="hidden_size";break;case"vision-encoder-decoder":let n=Is(t.decoder),o="num_decoder_layers"in n,i=Me(t,["model_type","is_encoder_decoder"]);return o?(i.num_decoder_layers=n.num_decoder_layers,i.num_decoder_heads=n.num_decoder_heads,i.decoder_hidden_size=n.decoder_hidden_size,i.num_encoder_layers=n.num_encoder_layers,i.num_encoder_heads=n.num_encoder_heads,i.encoder_hidden_size=n.encoder_hidden_size):(i.num_layers=n.num_layers,i.num_heads=n.num_heads,i.hidden_size=n.hidden_size),i}let r={...s,...Me(t,["model_type","multi_query","is_encoder_decoder"])};for(let n in e)r[n]=t[e[n]];return r}function Ii(t,e){if(["lfm2","lfm2_moe"].includes(t.model_type)){let s=e?.prefix??"past_key_values",r=s==="present"?"present":"past",n={},{layer_types:o,num_attention_heads:i,num_key_value_heads:a,hidden_size:l,conv_L_cache:c}=t,u=l/i,p=e?.batch_size??1;for(let d=0;d<o.length;++d)if(o[d]==="full_attention")for(let _ of["key","value"])n[`${s}.${d}.${_}`]=[p,a,0,u];else if(o[d]==="conv")n[`${r}_conv.${d}`]=[p,l,c];else throw new Error(`Unsupported layer type: ${o[d]}`);return n}else if(["granitemoehybrid","falcon_h1"].includes(t.model_type)){let s=e?.prefix??"past_key_values",r=s==="present"?"present":"past",n={},{layer_types:o,num_hidden_layers:i,num_attention_heads:a,num_key_value_heads:l,hidden_size:c,mamba_d_conv:u,mamba_n_heads:p,mamba_d_head:d,mamba_d_state:_,mamba_n_groups:m,mamba_expand:h,mamba_d_ssm:x}=t,g=c/a,w=e?.batch_size??1,y=(x??h*c)+2*m*_;for(let E=0;E<i;++E)if((!o||o[E]==="mamba")&&(n[`${r}_conv.${E}`]=[w,y,u],n[`${r}_ssm.${E}`]=[w,p,d,_]),!o||o[E]==="attention")for(let A of["key","value"])n[`${s}.${E}.${A}`]=[w,l,0,g];return n}return gv(t,e)}function gv(t,{prefix:e="past_key_values",batch_size:s=1}={}){let r={},n=t.normalized_config;if(n.is_encoder_decoder&&"num_encoder_heads"in n&&"num_decoder_heads"in n){let o=n.encoder_dim_kv??n.encoder_hidden_size/n.num_encoder_heads,i=n.decoder_dim_kv??n.decoder_hidden_size/n.num_decoder_heads,a=[s,n.num_encoder_heads,0,o],l=[s,n.num_decoder_heads,0,i];for(let c=0;c<n.num_decoder_layers;++c)r[`${e}.${c}.encoder.key`]=a,r[`${e}.${c}.encoder.value`]=a,r[`${e}.${c}.decoder.key`]=l,r[`${e}.${c}.decoder.value`]=l}else{let o=n.num_heads,i=n.num_layers,a=n.dim_kv??n.hidden_size/(n.num_attention_heads??o);if(n.model_type==="falcon"){let l=[s*o,0,a];for(let c=0;c<i;++c)r[`${e}.${c}.key`]=l,r[`${e}.${c}.value`]=l}else if(n.multi_query){let l=[s*o,0,2*a];for(let c=0;c<i;++c)r[`${e}.${c}.key_value`]=l}else if(n.model_type==="bloom"){let l=[s*o,a,0],c=[s*o,0,a];for(let u=0;u<i;++u)r[`${e}.${u}.key`]=l,r[`${e}.${u}.value`]=c}else if(n.model_type==="openelm")for(let l=0;l<i;++l){let c=[s,o[l],0,a];r[`${e}.${l}.key`]=c,r[`${e}.${l}.value`]=c}else{let l=[s,o,0,a];for(let c=0;c<i;++c)r[`${e}.${c}.key`]=l,r[`${e}.${c}.value`]=l}}return r}var Oi=class t{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=Is(this)}static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main"}={}){r&&!(r instanceof t)&&(r=new t(r));let a=r??await xv(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i});return new this(a)}},Yt=class{static async from_pretrained(...e){return Oi.from_pretrained(...e)}};async function sy(t,e,s,r){let n=`${e}${r}.onnx`,o=`${s.subfolder??""}/${n}`;return await lr(t,o,!0,s,ee.IS_NODE_ENV)}async function ry(t,e,s,r,n,o={}){let i=`${e}${s}.onnx`,a=ee.IS_NODE_ENV,l=[];if(n){let c;typeof n=="object"?n.hasOwnProperty(i)?c=n[i]:n.hasOwnProperty(e)?c=n[e]:c=!1:c=n;let u=+c;if(u>Wo)throw new Error(`The number of external data chunks (${u}) exceeds the maximum allowed value (${Wo}).`);for(let p=0;p<u;++p){let d=`${i}_data${p===0?"":"_"+p}`,_=`${r.subfolder??""}/${d}`;l.push(new Promise(async(m,h)=>{let x=await lr(t,_,!0,r,a);m(x instanceof Uint8Array?{path:d,data:x}:d)}))}}else o.externalData!==void 0&&(l=o.externalData.map(async c=>{if(typeof c.data=="string"){let u=await lr(t,c.data,!0,r);return{...c,data:u}}return c}));return Promise.all(l)}async function wv(t,e,s,r=!1){let n=s.config?.["transformers.js_config"]??{},o=s.device??n.device;o&&typeof o!="string"&&(o.hasOwnProperty(e)?o=o[e]:(console.warn(`device not specified for "${e}". Using the default device.`),o=null));let i=o??(ee.IS_NODE_ENV?"cpu":"wasm"),a=zw(i),l=n.device_config??{};l.hasOwnProperty(i)&&(n={...n,...l[i]});let c=s.dtype??n.dtype;if(typeof c!="string"&&(c&&c.hasOwnProperty(e)?c=c[e]:(c=Kl[i]??Ne.fp32,console.warn(`dtype not specified for "${e}". Using the default dtype (${c}) for this device (${i}).`))),c===Ne.auto){let A=n.dtype;typeof A!="string"&&(A=A?.[e]),A&&A!==Ne.auto&&Ne.hasOwnProperty(A)?c=A:c=Kl[i]??Ne.fp32}let u=c;if(Ql.hasOwnProperty(u)){if(i==="webgpu"&&!ee.IS_NODE_ENV&&u===Ne.fp16&&!await Nw())throw new Error(`The device (${i}) does not support fp16.`)}else throw new Error(`Invalid dtype: ${u}. Should be one of: ${Object.keys(Ne).join(", ")}`);let p=n.kv_cache_dtype,d=p?typeof p=="string"?p:p[u]??"float32":void 0;if(d&&!["float32","float16"].includes(d))throw new Error(`Invalid kv_cache_dtype: ${d}. Should be one of: float32, float16`);let _=Ql[u],m={...s.session_options};m.executionProviders??=a;let h=n.free_dimension_overrides;h?m.freeDimensionOverrides??=h:i.startsWith("webnn")&&!m.freeDimensionOverrides&&console.warn(`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"]["${i}"]. When 'free_dimension_overrides' is not set, you may experience significant performance degradation.`);let x=sy(t,e,s,_),g=s.use_external_data_format??n.use_external_data_format,w=await ry(t,e,_,s,g,m);if(w.length>0&&!ee.IS_NODE_ENV&&(m.externalData=w),r&&i==="webgpu"&&p!==!1){let A=Ii(s.config,{prefix:"present"});if(Object.keys(A).length>0&&!ur()){let b={};for(let O in A)b[O]="gpu-buffer";m.preferredOutputLocation=b}}return{buffer_or_path:await x,session_options:m,session_config:{dtype:u,kv_cache_dtype:d,device:i}}}async function Fe(t,e,s,r=void 0){return Object.fromEntries(await Promise.all(Object.keys(e).map(async n=>{let{buffer_or_path:o,session_options:i,session_config:a}=await wv(t,e[n],s,n===r),l=await Qo(o,i,a);return[n,l]})))}function ny(t){for(let e in t)Yo(t[e])?t[e]=new S(t[e]):typeof t[e]=="object"&&ny(t[e]);return t}async function q(t,e){let s=yv(t,e);try{let r=Object.fromEntries(Object.entries(s).map(([o,i])=>{let a=i.ort_tensor;return ee.IS_NODE_ENV&&typeof Float16Array<"u"&&a.cpuData instanceof Float16Array&&(a.cpuData=new Uint16Array(a.cpuData.buffer)),[o,a]})),n=await Jo(t,r);return ny(n)}catch(r){let n=Object.fromEntries(Object.entries(s).map(([o,i])=>{let a={type:i.type,dims:i.dims,location:i.location};return a.location!=="gpu-buffer"&&(a.data=i.data),[o,a]}));throw console.error(`An error occurred during model execution: "${r}".`),console.error("Inputs given to model:",n),r}}function yv(t,e){let s=Object.create(null),r=[];for(let i of t.inputNames){let a=e[i];if(!(a instanceof S)){r.push(i);continue}s[i]=ur()?a.clone():a}if(r.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${r.join(", ")}.`);let n=Object.keys(e).length,o=t.inputNames.length;if(n>o){let i=Object.keys(e).filter(a=>!t.inputNames.includes(a));console.warn(`WARNING: Too many inputs were provided (${n} > ${o}). The following inputs will be ignored: "${i.join(", ")}".`)}return s}var ue=class{};var z=class extends ue{constructor({logits:e,...s}){super(),this.logits=e;let r=Object.values(s);r.length>0&&(this.attentions=r)}},K=class extends ue{constructor({logits:e}){super(),this.logits=e}},J=class extends ue{constructor({logits:e}){super(),this.logits=e}},oe=class extends ue{constructor({start_logits:e,end_logits:s}){super(),this.start_logits=e,this.end_logits=s}},$e=class extends ue{constructor({logits:e}){super(),this.logits=e}};var zi=class extends ue{constructor({alphas:e}){super(),this.alphas=e}};var Qe=class extends ke{_call(e,s){throw Error("`_call` should be implemented in a subclass")}},vr=class extends ke{_call(e,s){throw Error("`_call` should be implemented in a subclass")}},Zt=class extends ke{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,s){let r=s;for(let n of this.processors)r=n(e,r);return r}[Symbol.iterator](){return this.processors.values()}},Ti=class extends Qe{constructor(e){super(),this.bos_token_id=e}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length===1){let n=s[r].data;n.fill(-1/0),n[this.bos_token_id]=0}return s}},Pi=class extends Qe{constructor(e,s){super(),this.max_length=e,this.eos_token_id=Array.isArray(s)?s:[s]}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length===this.max_length-1){let n=s[r].data;n.fill(-1/0);for(let o of this.eos_token_id)n[o]=0}return s}},zs=class extends Qe{constructor(e,s){super(),this.begin_suppress_tokens=e,this.begin_index=s}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length===this.begin_index){let n=s[r].data;for(let o of this.begin_suppress_tokens)n[o]=-1/0}return s}},Ci=class extends Qe{constructor(e,s){super(),this.eos_token_id=Array.isArray(e.eos_token_id)?e.eos_token_id[0]:e.eos_token_id,this.no_timestamps_token_id=e.no_timestamps_token_id,this.timestamp_begin=this.no_timestamps_token_id+1,this.begin_index=s.length,s.at(-1)===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,s){for(let r=0;r<e.length;++r){let n=s[r].data;if(n[this.no_timestamps_token_id]=-1/0,e[r].length===this.begin_index-1){n.fill(-1/0),n[this.timestamp_begin]=0;continue}let o=e[r].slice(this.begin_index),i=o.length>=1&&o[o.length-1]>=this.timestamp_begin,a=o.length<2||o[o.length-2]>=this.timestamp_begin;if(i&&(a?n.subarray(this.timestamp_begin).fill(-1/0):n.subarray(0,this.eos_token_id).fill(-1/0)),e[r].length===this.begin_index&&this.max_initial_timestamp_index!==null){let p=this.timestamp_begin+this.max_initial_timestamp_index;n.subarray(p+1).fill(-1/0)}let l=Gl(n),c=Math.log(l.subarray(this.timestamp_begin).map(Math.exp).reduce((p,d)=>p+d)),u=ie(l.subarray(0,this.timestamp_begin))[0];c>u&&n.subarray(0,this.timestamp_begin).fill(-1/0)}return s}},Ni=class extends Qe{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){let s=e.length,r=[];for(let o=0;o<s+1-this.no_repeat_ngram_size;++o){let i=[];for(let a=0;a<this.no_repeat_ngram_size;++a)i.push(e[o+a]);r.push(i.map(Number))}let n=new Map;for(let o of r){let i=o.slice(0,o.length-1),a=JSON.stringify(i),l=n.get(a)??[];l.push(o[o.length-1]),n.set(a,l)}return n}getGeneratedNgrams(e,s){let r=s.slice(s.length+1-this.no_repeat_ngram_size,s.length);return e.get(JSON.stringify(r.map(Number)))??[]}calcBannedNgramTokens(e){let s=[];if(e.length+1<this.no_repeat_ngram_size)return s;{let r=this.getNgrams(e);return this.getGeneratedNgrams(r,e)}}_call(e,s){for(let r=0;r<e.length;++r){let n=s[r].data,o=this.calcBannedNgramTokens(e[r]);for(let i of o)n[i]=-1/0}return s}},Li=class extends Qe{constructor(e){super(),this.penalty=e}_call(e,s){for(let r=0;r<e.length;++r){let n=s[r].data;for(let o of new Set(e[r])){let i=Number(o);n[i]<0?n[i]*=this.penalty:n[i]/=this.penalty}}return s}},$i=class extends Qe{constructor(e,s){super(),this.min_length=e,this.eos_token_id=Array.isArray(s)?s:[s]}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length<this.min_length){let n=s[r].data;for(let o of this.eos_token_id)n[o]=-1/0}return s}},Ri=class extends Qe{constructor(e,s,r){super(),this.prompt_length_to_skip=e,this.min_new_tokens=s,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length-this.prompt_length_to_skip<this.min_new_tokens){let o=s[r].data;for(let i of this.eos_token_id)o[i]=-1/0}return s}},Fi=class extends Qe{constructor(e,s){super(),this.bad_words_ids=e,this.eos_token_id=Array.isArray(s)?s:[s]}_call(e,s){for(let r=0;r<e.length;++r){let n=s[r].data,o=e[r];for(let i of this.bad_words_ids){if(o.length<i.length-1)continue;let a=!0;for(let l=1;l<=i.length-1;++l)if(i.at(-l-1)!=o.at(-l)){a=!1;break}a&&(n[i.at(-1)]=-1/0)}}return s}},Di=class extends Qe{constructor(e){if(super(),e<=1)throw new Error(`Require guidance scale >1 to use the classifier free guidance processor, got guidance scale ${e}.`);this.guidance_scale=e}_call(e,s){if(s.dims[0]!==2*e.length)throw new Error(`Logits should have twice the batch size of the input ids, the first half of batches corresponding to the conditional inputs, and the second half of batches corresponding to the unconditional inputs. Got batch size ${s.dims[0]} for the logits and ${e.length} for the input ids.`);let r=e.length,n=s.slice([0,r],null),o=s.slice([r,s.dims[0]],null);for(let i=0;i<o.data.length;++i)o.data[i]+=(n.data[i]-o.data[i])*this.guidance_scale;return o}},ji=class extends vr{constructor(e){if(super(),typeof e!="number"||e<=0){let s=`\`temperature\` (=${e}) must be a strictly positive float, otherwise your next token scores will be invalid.`;e===0&&(s+=" If you're looking for greedy decoding strategies, set `do_sample=false`.")}this.temperature=e}_call(e,s){let r=s.data;for(let n=0;n<r.length;++n)r[n]/=this.temperature;return s}},oy=class extends vr{constructor(e,{filter_value:s=-1/0,min_tokens_to_keep:r=1}={}){if(super(),e<0||e>1)throw new Error(`\`top_p\` must be a float > 0 and < 1, but is ${e}`);if(!Number.isInteger(r)||r<1)throw new Error(`\`min_tokens_to_keep\` must be a positive integer, but is ${r}`);this.top_p=e,this.filter_value=s,this.min_tokens_to_keep=r}},iy=class extends vr{constructor(e,{filter_value:s=-1/0,min_tokens_to_keep:r=1}={}){if(super(),!Number.isInteger(e)||e<0)throw new Error(`\`top_k\` must be a positive integer, but is ${e}`);this.top_k=Math.max(e,r),this.filter_value=s}};var Ts=class{max_length=20;max_new_tokens=null;min_length=0;min_new_tokens=null;early_stopping=!1;max_time=null;do_sample=!1;num_beams=1;num_beam_groups=1;penalty_alpha=null;use_cache=!0;temperature=1;top_k=50;top_p=1;typical_p=1;epsilon_cutoff=0;eta_cutoff=0;diversity_penalty=0;repetition_penalty=1;encoder_repetition_penalty=1;length_penalty=1;no_repeat_ngram_size=0;bad_words_ids=null;force_words_ids=null;renormalize_logits=!1;constraints=null;forced_bos_token_id=null;forced_eos_token_id=null;remove_invalid_values=!1;exponential_decay_length_penalty=null;suppress_tokens=null;streamer=null;begin_suppress_tokens=null;forced_decoder_ids=null;guidance_scale=null;num_return_sequences=1;output_attentions=!1;output_hidden_states=!1;output_scores=!1;return_dict_in_generate=!1;pad_token_id=null;bos_token_id=null;eos_token_id=null;encoder_no_repeat_ngram_size=0;decoder_start_token_id=null;generation_kwargs={};constructor(e){Object.assign(this,Me(e,Object.getOwnPropertyNames(this)))}};var Ps=class extends ke{_call(e,s){throw Error("StoppingCriteria needs to be subclassed")}},Bi=class t extends ke{constructor(){super(),this.criteria=[]}push(e){this.criteria.push(e)}extend(e){e instanceof t?e=e.criteria:e instanceof Ps&&(e=[e]),this.criteria.push(...e)}_call(e,s){let r=new Array(e.length).fill(!1);for(let n of this.criteria){let o=n(e,s);for(let i=0;i<r.length;++i)r[i]||=o[i]}return r}[Symbol.iterator](){return this.criteria.values()}},Ui=class extends Ps{constructor(e,s=null){super(),this.max_length=e,this.max_position_embeddings=s}_call(e){return e.map(s=>s.length>=this.max_length)}},qi=class extends Ps{constructor(e){super(),Array.isArray(e)||(e=[e]),this.eos_token_id=e}_call(e,s){return e.map(r=>{let n=r.at(-1);return this.eos_token_id.some(o=>n==o)})}},ay=class extends Ps{constructor(){super(),this.interrupted=!1}interrupt(){this.interrupted=!0}reset(){this.interrupted=!1}_call(e,s){return new Array(e.length).fill(this.interrupted)}};var es=class extends ke{constructor(e){super(),this.generation_config=e}async _call(e){return this.sample(e)}async sample(e){throw Error("sample should be implemented in subclasses.")}getLogits(e,s){let r=e.dims.at(-1),n=e.data;if(s===-1)n=n.slice(-r);else{let o=s*r;n=n.slice(o,o+r)}return n}randomSelect(e){let s=0;for(let n=0;n<e.length;++n)s+=e[n];let r=Math.random()*s;for(let n=0;n<e.length;++n)if(r-=e[n],r<=0)return n;return 0}static getSampler(e){if(e.do_sample)return new kp(e);if(e.num_beams>1)return new vp(e);if(e.num_return_sequences>1)throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${e.num_return_sequences}.`);return new bp(e)}},bp=class extends es{async sample(e){let s=ie(e.data)[1];return[[BigInt(s),0]]}},kp=class extends es{async sample(e){let s=e.dims.at(-1);this.generation_config.top_k>0&&(s=Math.min(this.generation_config.top_k,s));let[r,n]=await ot(e,s),o=ce(r.data);return Array.from({length:this.generation_config.num_beams},()=>{let i=this.randomSelect(o);return[n.data[i],Math.log(o[i])]})}},vp=class extends es{async sample(e){let s=e.dims.at(-1);this.generation_config.top_k>0&&(s=Math.min(this.generation_config.top_k,s));let[r,n]=await ot(e,s),o=ce(r.data);return Array.from({length:this.generation_config.num_beams},(i,a)=>[n.data[a],Math.log(o[a])])}};var Er=null;function cy(t){Er=t}function Ep(t){if(t instanceof S)return t;if(t.length===0)throw Error("items must be non-empty");if(Array.isArray(t[0])){if(t.some(e=>e.length!==t[0].length))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.");return new S("int64",BigInt64Array.from(t.flat().map(e=>BigInt(e))),[t.length,t[0].length])}else return new S("int64",BigInt64Array.from(t.map(e=>BigInt(e))),[1,t.length])}function Ap(t){return new S("bool",[t],[1])}var C={EncoderOnly:0,EncoderDecoder:1,Seq2Seq:2,Vision2Seq:3,DecoderOnly:4,DecoderOnlyWithoutHead:5,MaskGeneration:6,ImageTextToText:7,Musicgen:8,MultiModality:9,Phi3V:10,AudioTextToText:11,AutoEncoder:12,ImageAudioTextToText:13,Supertonic:14,Chatterbox:15},ly={[C.DecoderOnly]:{can_generate:!0,forward:Ue,prepare_inputs:Ar},[C.DecoderOnlyWithoutHead]:{can_generate:!1,forward:Ue,prepare_inputs:Ar},[C.Seq2Seq]:{can_generate:!0,forward:Gi,prepare_inputs:Mr},[C.Vision2Seq]:{can_generate:!0,forward:Gi,prepare_inputs:Mr},[C.Musicgen]:{can_generate:!0,forward:Gi},[C.EncoderDecoder]:{can_generate:!1,forward:Gi},[C.ImageTextToText]:{can_generate:!0,forward:vv,prepare_inputs:Wi},[C.AudioTextToText]:{can_generate:!0,forward:kv,prepare_inputs:Wi},[C.Phi3V]:{can_generate:!0,prepare_inputs:Wi},[C.ImageAudioTextToText]:{can_generate:!0,prepare_inputs:Wi},[C.MultiModality]:{can_generate:!0},[C.AutoEncoder]:{can_generate:!1,forward:bv},[C.Chatterbox]:{can_generate:!0,forward:Je},default:{can_generate:!1,forward:Je}},ss=new Map,Vi=new Map,ts=new Map,f=class extends ke{main_input_name="input_ids";forward_params=["input_ids","attention_mask"];_return_dict_in_generate_keys=null;constructor(e,s,r){super(),this.config=e,this.sessions=s,this.configs=r;let n=ts.get(this.constructor),o=ss.get(n),i=ly[o]??ly.default;this.can_generate=i.can_generate,this._forward=i.forward,this._prepare_inputs_for_generation=i.prepare_inputs,this.can_generate&&this.forward_params.push("past_key_values"),this.custom_config=this.config["transformers.js_config"]??{}}async dispose(){let e=[];for(let s of Object.values(this.sessions))e.push(s.release?.());return await Promise.all(e)}static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main",model_file_name:a=null,subfolder:l="onnx",device:c=null,dtype:u=null,use_external_data_format:p=null,session_options:d={}}={}){let _={progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:u,use_external_data_format:p,session_options:d},m=ts.get(this),h=ss.get(m);r=_.config=await Yt.from_pretrained(e,_);let x;if(h===C.DecoderOnly)x=await Promise.all([Fe(e,{model:_.model_file_name??"model"},_,"model"),bt(e,{generation_config:"generation_config.json"},_)]);else if(h===C.Seq2Seq||h===C.Vision2Seq)x=await Promise.all([Fe(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_,"decoder_model_merged"),bt(e,{generation_config:"generation_config.json"},_)]);else if(h===C.MaskGeneration)x=await Promise.all([Fe(e,{model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"},_)]);else if(h===C.EncoderDecoder)x=await Promise.all([Fe(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_,"decoder_model_merged")]);else if(h===C.ImageTextToText){let g={embed_tokens:"embed_tokens",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};r.is_encoder_decoder&&(g.model="encoder_model"),x=await Promise.all([Fe(e,g,_,"decoder_model_merged"),bt(e,{generation_config:"generation_config.json"},_)])}else if(h===C.AudioTextToText){let g={embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",decoder_model_merged:"decoder_model_merged"};x=await Promise.all([Fe(e,g,_,"decoder_model_merged"),bt(e,{generation_config:"generation_config.json"},_)])}else if(h===C.ImageAudioTextToText){let g={embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};x=await Promise.all([Fe(e,g,_),bt(e,{generation_config:"generation_config.json"},_)])}else if(h===C.Musicgen)x=await Promise.all([Fe(e,{model:"text_encoder",decoder_model_merged:"decoder_model_merged",encodec_decode:"encodec_decode"},_,"decoder_model_merged"),bt(e,{generation_config:"generation_config.json"},_)]);else if(h===C.MultiModality)x=await Promise.all([Fe(e,{prepare_inputs_embeds:"prepare_inputs_embeds",model:"language_model",lm_head:"lm_head",gen_head:"gen_head",gen_img_embeds:"gen_img_embeds",image_decode:"image_decode"},_,"model"),bt(e,{generation_config:"generation_config.json"},_)]);else if(h===C.Phi3V)x=await Promise.all([Fe(e,{prepare_inputs_embeds:"prepare_inputs_embeds",model:"model",vision_encoder:"vision_encoder"},_,"model"),bt(e,{generation_config:"generation_config.json"},_)]);else if(h===C.Chatterbox)x=await Promise.all([Fe(e,{embed_tokens:"embed_tokens",speech_encoder:"speech_encoder",model:"language_model",conditional_decoder:"conditional_decoder"},_,"model"),bt(e,{generation_config:"generation_config.json"},_)]);else if(h===C.AutoEncoder)x=await Promise.all([Fe(e,{encoder_model:"encoder_model",decoder_model:"decoder_model"},_)]);else if(h===C.Supertonic)x=await Promise.all([Fe(e,{text_encoder:"text_encoder",latent_denoiser:"latent_denoiser",voice_decoder:"voice_decoder"},_)]);else{if(h===void 0){let g=m??r?.model_type;g!=="custom"&&console.warn(`Model type for '${g}' not found, assuming encoder-only architecture. Please report this at ${bs}.`)}x=await Promise.all([Fe(e,{model:_.model_file_name??"model"},_)])}return new this(r,...x)}async _call(e){return await this.forward(e)}async forward(e){return await this._forward(this,e)}get generation_config(){return this.configs?.generation_config??null}_get_logits_processor(e,s,r=null){let n=new Zt;if(e.repetition_penalty!==null&&e.repetition_penalty!==1&&n.push(new Li(e.repetition_penalty)),e.no_repeat_ngram_size!==null&&e.no_repeat_ngram_size>0&&n.push(new Ni(e.no_repeat_ngram_size)),e.bad_words_ids!==null&&n.push(new Fi(e.bad_words_ids,e.eos_token_id)),e.min_length!==null&&e.eos_token_id!==null&&e.min_length>0&&n.push(new $i(e.min_length,e.eos_token_id)),e.min_new_tokens!==null&&e.eos_token_id!==null&&e.min_new_tokens>0&&n.push(new Ri(s,e.min_new_tokens,e.eos_token_id)),e.forced_bos_token_id!==null&&n.push(new Ti(e.forced_bos_token_id)),e.forced_eos_token_id!==null&&n.push(new Pi(e.max_length,e.forced_eos_token_id)),e.begin_suppress_tokens!==null){let o=s>1||e.forced_bos_token_id===null?s:s+1;n.push(new zs(e.begin_suppress_tokens,o))}return e.guidance_scale!==null&&e.guidance_scale>1&&n.push(new Di(e.guidance_scale)),e.temperature===0&&e.do_sample&&(console.warn("`do_sample` changed to false because `temperature: 0` implies greedy sampling (always selecting the most likely token), which is incompatible with `do_sample: true`."),e.do_sample=!1),e.do_sample&&e.temperature!==null&&e.temperature!==1&&n.push(new ji(e.temperature)),r!==null&&n.extend(r),n}_prepare_generation_config(e,s,r=Ts){let n={...this.config};for(let i of["decoder","generator","text_config"])i in n&&Object.assign(n,n[i]);let o=new r(n);return Object.assign(o,this.generation_config??{}),e&&Object.assign(o,e),s&&Object.assign(o,Me(s,Object.getOwnPropertyNames(o))),o}_get_stopping_criteria(e,s=null){let r=new Bi;return e.max_length!==null&&r.push(new Ui(e.max_length,this.config.max_position_embeddings??null)),e.eos_token_id!==null&&r.push(new qi(e.eos_token_id)),s&&r.extend(s),r}_validate_model_class(){if(!this.can_generate){let e=[Er.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,Er.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,Er.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,Er.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES].filter(Boolean),s=ts.get(this.constructor),r=new Set,n=this.config.model_type;for(let i of e){let a=i?.get(n);a&&r.add(a)}let o=`The current model class (${s}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw r.size>0&&(o+=` Please use the following class instead: ${[...r].join(", ")}`),Error(o)}}prepare_inputs_for_generation(...e){if(!this._prepare_inputs_for_generation)throw new Error("prepare_inputs_for_generation is not implemented for this model.");return this._prepare_inputs_for_generation(this,...e)}_update_model_kwargs_for_generation({generated_input_ids:e,outputs:s,model_inputs:r,is_encoder_decoder:n}){return r.past_key_values=this.getPastKeyValues(s,r.past_key_values),r.input_ids=new S("int64",e.flat(),[e.length,1]),n?"decoder_attention_mask"in r:r.attention_mask=ne([r.attention_mask,Oe([r.attention_mask.dims[0],1])],1),r.position_ids=null,r}_prepare_model_inputs({inputs:e,bos_token_id:s,model_kwargs:r}){let n=Me(r,this.forward_params),o=this.main_input_name;if(o in n){if(e)throw new Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else n[o]=e;return{inputs_tensor:n[o],model_inputs:n,model_input_name:o}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:e,model_inputs:s,model_input_name:r,generation_config:n}){if(this.sessions.model.inputNames.includes("inputs_embeds")&&!s.inputs_embeds&&"_prepare_inputs_embeds"in this){let{input_ids:i,pixel_values:a,attention_mask:l,...c}=s,u=await this._prepare_inputs_embeds(s);s={...c,...Me(u,["inputs_embeds","attention_mask"])}}let{last_hidden_state:o}=await Je(this,s);if(n.guidance_scale!==null&&n.guidance_scale>1)o=ne([o,dr(o,0)],0),"attention_mask"in s&&(s.attention_mask=ne([s.attention_mask,sc(s.attention_mask)],0));else if(s.decoder_input_ids){let i=Ep(s.decoder_input_ids).dims[0];if(i!==o.dims[0]){if(o.dims[0]!==1)throw new Error(`The encoder outputs have a different batch size (${o.dims[0]}) than the decoder inputs (${i}).`);o=ne(Array.from({length:i},()=>o),0)}}return s.encoder_outputs=o,s}_prepare_decoder_input_ids_for_generation({batch_size:e,model_input_name:s,model_kwargs:r,decoder_start_token_id:n,bos_token_id:o,generation_config:i}){let{decoder_input_ids:a,...l}=r;if(!(a instanceof S)){if(a)Array.isArray(a[0])||(a=Array.from({length:e},()=>a));else if(n??=o,this.config.model_type==="musicgen")a=Array.from({length:e*this.config.decoder.num_codebooks},()=>[n]);else if(Array.isArray(n)){if(n.length!==e)throw new Error(`\`decoder_start_token_id\` expcted to have length ${e} but got ${n.length}`);a=n}else a=Array.from({length:e},()=>[n]);a=Ep(a)}return r.decoder_attention_mask=si(a),{input_ids:a,model_inputs:l}}async generate({inputs:e=null,generation_config:s=null,logits_processor:r=null,stopping_criteria:n=null,streamer:o=null,...i}){this._validate_model_class(),s=this._prepare_generation_config(s,i);let{inputs_tensor:a,model_inputs:l,model_input_name:c}=this._prepare_model_inputs({inputs:e,model_kwargs:i}),u=this.config.is_encoder_decoder;u&&("encoder_outputs"in l||(l=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:a,model_inputs:l,model_input_name:c,generation_config:s})));let p;u?{input_ids:p,model_inputs:l}=this._prepare_decoder_input_ids_for_generation({batch_size:l[c].dims.at(0),model_input_name:c,model_kwargs:l,decoder_start_token_id:s.decoder_start_token_id,bos_token_id:s.bos_token_id,generation_config:s}):p=l[c];let d=p.dims.at(-1);s.max_new_tokens!==null&&(s.max_length=d+s.max_new_tokens);let _=this._get_logits_processor(s,d,r),m=this._get_stopping_criteria(s,n),h=l[c].dims.at(0),x=es.getSampler(s),g=new Array(h).fill(0),w=p.tolist();o&&o.put(w);let y,E={},A={};for(;;){if(l=this.prepare_inputs_for_generation(w,l,s),y=await this.forward(l),s.return_dict_in_generate)if(s.output_attentions){let G=this.getAttentions(y);for(let D in G)D in E||(E[D]=[]),E[D].push(G[D])}else this._return_dict_in_generate_keys&&Object.assign(A,Me(y,this._return_dict_in_generate_keys));let N=y.logits.slice(null,-1,null).to("float32"),F=_(w,N),R=[];for(let G=0;G<F.dims.at(0);++G){let D=F[G],X=await x(D);for(let[V,re]of X){let Y=BigInt(V);g[G]+=re,w[G].push(Y),R.push([Y]);break}}if(o&&o.put(R),m(w).every(G=>G))break;l=this._update_model_kwargs_for_generation({generated_input_ids:R,outputs:y,model_inputs:l,is_encoder_decoder:u})}o&&o.end();let b=this.getPastKeyValues(y,l.past_key_values,!0),O=new S("int64",w.flat(),[w.length,w[0].length]);if(s.return_dict_in_generate)return{sequences:O,past_key_values:b,...E,...A};for(let N of Object.values(y))N.location==="gpu-buffer"&&N.dispose();return O}getPastKeyValues(e,s,r=!1){let n=Object.create(null);for(let o in e)if(o.startsWith("present")){let i=o.replace("present_ssm","past_ssm").replace("present_conv","past_conv").replace("present","past_key_values"),a=o.includes("encoder");if(a&&s?n[i]=s[i]:n[i]=e[o],s&&(!a||r)){let l=s[i];l.location==="gpu-buffer"&&l.dispose()}}return n}getAttentions(e){let s={};for(let r of["cross_attentions","encoder_attentions","decoder_attentions"])for(let n in e)n.startsWith(r)&&(r in s||(s[r]=[]),s[r].push(e[n]));return s}addPastKeyValues(e,s){if(s)Object.assign(e,s);else{let r=this.sessions.decoder_model_merged??this.sessions.model,n=(e[this.main_input_name]??e.attention_mask)?.dims?.[0]??1,o=r?.config?.kv_cache_dtype??"float32",i=o==="float16"?ws.float16:ws.float32,a=Ii(this.config,{batch_size:n});for(let l in a){let c=a[l].reduce((u,p)=>u*p,1);e[l]=new S(o,new i(c),a[l])}}}async encode_image({pixel_values:e}){return(await q(this.sessions.vision_encoder,{pixel_values:e})).image_features}async encode_text({input_ids:e}){return(await q(this.sessions.embed_tokens,{input_ids:e})).inputs_embeds}async encode_audio({audio_values:e}){return(await q(this.sessions.audio_encoder,{audio_values:e})).audio_features}};async function Gi(t,e){let{encoder_outputs:s,input_ids:r,decoder_input_ids:n,...o}=e;if(!s){let i=Me(e,t.sessions.model.inputNames);s=(await Je(t,i)).last_hidden_state}return o.input_ids=n,o.encoder_hidden_states=s,t.sessions.decoder_model_merged.inputNames.includes("encoder_attention_mask")&&(o.encoder_attention_mask=e.attention_mask),await Ue(t,o,!0)}async function Je(t,e){let s=t.sessions.model,r=Me(e,s.inputNames);if(s.inputNames.includes("inputs_embeds")&&!r.inputs_embeds){if(!e.input_ids)throw new Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");r.inputs_embeds=await t.encode_text({input_ids:e.input_ids})}if(s.inputNames.includes("token_type_ids")&&!r.token_type_ids){if(!r.input_ids)throw new Error("Both `input_ids` and `token_type_ids` are missing in the model inputs.");r.token_type_ids=sc(r.input_ids)}if(s.inputNames.includes("pixel_mask")&&!r.pixel_mask){if(!r.pixel_values)throw new Error("Both `pixel_values` and `pixel_mask` are missing in the model inputs.");let n=r.pixel_values.dims;r.pixel_mask=Oe([n[0],n[2],n[3]])}return await q(s,r)}async function bv(t,e){let s=await t.encode(e);return await t.decode(s)}async function Ue(t,e,s=!1){let r=t.sessions[s?"decoder_model_merged":"model"],{past_key_values:n,...o}=e;if(r.inputNames.includes("use_cache_branch")&&(o.use_cache_branch=Ap(!!n)),r.inputNames.includes("position_ids")&&o.attention_mask&&!o.position_ids){let a=["paligemma","gemma3_text","gemma3"].includes(t.config.model_type)?1:0;o.position_ids=Ev(o,n,a)}t.addPastKeyValues(o,n);let i=Me(o,r.inputNames);return await q(r,i)}async function uy(t,{encode_function:e,merge_function:s,modality_input_name:r,modality_output_name:n,input_ids:o=null,attention_mask:i=null,position_ids:a=null,inputs_embeds:l=null,past_key_values:c=null,generation_config:u=null,logits_processor:p=null,...d}){let _=d[r];if(!l){if(l=await t.encode_text({input_ids:o,...d}),_&&o.dims[1]!==1){let h=await e({[r]:_,...d});({inputs_embeds:l,attention_mask:i}=s({[n]:h,inputs_embeds:l,input_ids:o,attention_mask:i}))}else if(c&&_&&o.dims[1]===1){let h=o.dims[1],x=Object.values(c)[0].dims.at(-2);i=ne([Oe([o.dims[0],x]),i.slice(null,[i.dims[1]-h,i.dims[1]])],1)}}if(!a&&t.config.model_type==="qwen2_vl"){let{image_grid_thw:h,video_grid_thw:x}=d;[a]=t.get_rope_index(o,h,x,i)}return await Ue(t,{inputs_embeds:l,past_key_values:c,attention_mask:i,position_ids:a,generation_config:u,logits_processor:p},!0)}async function kv(t,e){return await uy(t,{...e,modality_input_name:"audio_values",modality_output_name:"audio_features",encode_function:t.encode_audio.bind(t),merge_function:t._merge_input_ids_with_audio_features.bind(t)})}async function vv(t,e){return await uy(t,{...e,modality_input_name:"pixel_values",modality_output_name:"image_features",encode_function:t.encode_image.bind(t),merge_function:t._merge_input_ids_with_image_features.bind(t)})}function Mp(t,e=0){let[s,r]=t.dims,n=t.data,o=new BigInt64Array(n.length);for(let i=0;i<s;++i){let a=i*r,l=BigInt(e);for(let c=0;c<r;++c){let u=a+c;n[u]===0n?o[u]=BigInt(1):(o[u]=l,l+=n[u])}}return{data:o,dims:t.dims}}function Ev(t,e=null,s=0){let{input_ids:r,inputs_embeds:n,attention_mask:o}=t,{data:i,dims:a}=Mp(o,s),l=new S("int64",i,a);if(e){let c=-(r??n).dims.at(1);l=l.slice(null,[c,null])}return l}function Ar(t,e,s,r){let n=s.past_key_values?Object.values(s.past_key_values)[0].dims.at(-2):0;if(!s.attention_mask){let o;for(let i of["input_ids","inputs_embeds","position_ids"])if(s[i]){o=s[i].dims;break}if(!o)throw new Error("attention_mask is not provided, and unable to infer its shape from model inputs.");s.attention_mask=Oe([o[0],n+o[1]])}if(s.past_key_values){let{input_ids:o,attention_mask:i}=s;i&&i.dims[1]>o.dims[1]||n<o.dims[1]&&(s.input_ids=o.slice(null,[n,null]))}return s}function Mr(t,e,s,r){return s.past_key_values&&(e=e.map(n=>[n.at(-1)])),{...s,decoder_input_ids:Ep(e)}}function Wi(t,...e){return t.config.is_encoder_decoder?Mr(t,...e):Ar(t,...e)}function py({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n}){let o=r.tolist().map(c=>c.reduce((u,p,d)=>(p==t&&u.push(d),u),[])),i=o.reduce((c,u)=>c+u.length,0),a=s.dims[0];if(i!==a)throw new Error(`Number of tokens and features do not match: tokens: ${i}, features ${a}`);let l=0;for(let c=0;c<o.length;++c){let u=o[c],p=e[c];for(let d=0;d<u.length;++d)p[u[d]].data.set(s[l++].data)}return{inputs_embeds:e,attention_mask:n}}function _t({image_token_id:t,inputs_embeds:e,image_features:s,input_ids:r,attention_mask:n}){return py({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n})}function Hi({audio_token_id:t,inputs_embeds:e,audio_features:s,input_ids:r,attention_mask:n}){return py({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n})}async function bt(t,e,s){return Object.fromEntries(await Promise.all(Object.keys(e).map(async r=>{let n=await Se(t,e[r],!1,s);return[r,n]})))}var Io={};us(Io,{ASTForAudioClassification:()=>$p,ASTModel:()=>Lp,ASTPreTrainedModel:()=>Ir,AlbertForMaskedLM:()=>zp,AlbertForQuestionAnswering:()=>Ip,AlbertForSequenceClassification:()=>Op,AlbertModel:()=>Sp,AlbertPreTrainedModel:()=>rs,ApertusForCausalLM:()=>Pp,ApertusModel:()=>Tp,ApertusPreTrainedModel:()=>Sr,ArceeForCausalLM:()=>Np,ArceeModel:()=>Cp,ArceePreTrainedModel:()=>Or,BartForConditionalGeneration:()=>Fp,BartForSequenceClassification:()=>Dp,BartModel:()=>Rp,BartPretrainedModel:()=>Cs,BeitForImageClassification:()=>Bp,BeitModel:()=>jp,BeitPreTrainedModel:()=>zr,BertForMaskedLM:()=>qp,BertForQuestionAnswering:()=>Vp,BertForSequenceClassification:()=>Gp,BertForTokenClassification:()=>Wp,BertModel:()=>Up,BertPreTrainedModel:()=>Ot,BlenderbotForConditionalGeneration:()=>Xp,BlenderbotModel:()=>Hp,BlenderbotPreTrainedModel:()=>Tr,BlenderbotSmallForConditionalGeneration:()=>Qp,BlenderbotSmallModel:()=>Kp,BlenderbotSmallPreTrainedModel:()=>Pr,BloomForCausalLM:()=>Yp,BloomModel:()=>Jp,BloomPreTrainedModel:()=>Cr,CLIPModel:()=>id,CLIPPreTrainedModel:()=>ft,CLIPSegForImageSegmentation:()=>pd,CLIPSegModel:()=>ud,CLIPSegPreTrainedModel:()=>Fr,CLIPTextModel:()=>ad,CLIPTextModelWithProjection:()=>Rr,CLIPVisionModel:()=>ld,CLIPVisionModelWithProjection:()=>cd,CamembertForMaskedLM:()=>ed,CamembertForQuestionAnswering:()=>rd,CamembertForSequenceClassification:()=>td,CamembertForTokenClassification:()=>sd,CamembertModel:()=>Zp,CamembertPreTrainedModel:()=>It,ChatterboxModel:()=>Nr,ChatterboxPreTrainedModel:()=>Xi,ChineseCLIPModel:()=>nd,ChineseCLIPPreTrainedModel:()=>Ki,ClapAudioModelWithProjection:()=>$r,ClapModel:()=>od,ClapPreTrainedModel:()=>Ns,ClapTextModelWithProjection:()=>Lr,CodeGenForCausalLM:()=>_d,CodeGenModel:()=>dd,CodeGenPreTrainedModel:()=>Dr,Cohere2ForCausalLM:()=>xd,Cohere2Model:()=>hd,Cohere2PreTrainedModel:()=>Br,CohereForCausalLM:()=>md,CohereModel:()=>fd,CoherePreTrainedModel:()=>jr,ConvBertForMaskedLM:()=>wd,ConvBertForQuestionAnswering:()=>kd,ConvBertForSequenceClassification:()=>yd,ConvBertForTokenClassification:()=>bd,ConvBertModel:()=>gd,ConvBertPreTrainedModel:()=>zt,ConvNextForImageClassification:()=>Ed,ConvNextModel:()=>vd,ConvNextPreTrainedModel:()=>Ur,ConvNextV2ForImageClassification:()=>Md,ConvNextV2Model:()=>Ad,ConvNextV2PreTrainedModel:()=>qr,DFineForObjectDetection:()=>zd,DFineModel:()=>Id,DFinePreTrainedModel:()=>Wr,DINOv3ConvNextModel:()=>e_,DINOv3ConvNextPreTrainedModel:()=>sa,DINOv3ViTModel:()=>t_,DINOv3ViTPreTrainedModel:()=>ra,DPTForDepthEstimation:()=>c_,DPTModel:()=>l_,DPTPreTrainedModel:()=>Jr,DacDecoderModel:()=>Hr,DacDecoderOutput:()=>Ji,DacEncoderModel:()=>Vr,DacEncoderOutput:()=>Qi,DacModel:()=>Td,DacPreTrainedModel:()=>Ls,DebertaForMaskedLM:()=>Cd,DebertaForQuestionAnswering:()=>$d,DebertaForSequenceClassification:()=>Nd,DebertaForTokenClassification:()=>Ld,DebertaModel:()=>Pd,DebertaPreTrainedModel:()=>Tt,DebertaV2ForMaskedLM:()=>Fd,DebertaV2ForQuestionAnswering:()=>Bd,DebertaV2ForSequenceClassification:()=>Dd,DebertaV2ForTokenClassification:()=>jd,DebertaV2Model:()=>Rd,DebertaV2PreTrainedModel:()=>Pt,DecisionTransformerModel:()=>Ud,DecisionTransformerPreTrainedModel:()=>Yi,DeiTForImageClassification:()=>Gd,DeiTModel:()=>qd,DeiTPreTrainedModel:()=>Xr,DepthAnythingForDepthEstimation:()=>Wd,DepthAnythingPreTrainedModel:()=>Zi,DepthProForDepthEstimation:()=>Vd,DepthProPreTrainedModel:()=>ea,DetrForObjectDetection:()=>Xd,DetrForSegmentation:()=>Kd,DetrModel:()=>Hd,DetrObjectDetectionOutput:()=>Rs,DetrPreTrainedModel:()=>$s,DetrSegmentationOutput:()=>ta,Dinov2ForImageClassification:()=>Jd,Dinov2Model:()=>Qd,Dinov2PreTrainedModel:()=>Kr,Dinov2WithRegistersForImageClassification:()=>Zd,Dinov2WithRegistersModel:()=>Yd,Dinov2WithRegistersPreTrainedModel:()=>Qr,DistilBertForMaskedLM:()=>i_,DistilBertForQuestionAnswering:()=>o_,DistilBertForSequenceClassification:()=>r_,DistilBertForTokenClassification:()=>n_,DistilBertModel:()=>s_,DistilBertPreTrainedModel:()=>Ct,DonutSwinModel:()=>a_,DonutSwinPreTrainedModel:()=>na,EdgeTamModel:()=>Hh,EfficientNetForImageClassification:()=>p_,EfficientNetModel:()=>u_,EfficientNetPreTrainedModel:()=>Yr,ElectraForMaskedLM:()=>__,ElectraForQuestionAnswering:()=>h_,ElectraForSequenceClassification:()=>f_,ElectraForTokenClassification:()=>m_,ElectraModel:()=>d_,ElectraPreTrainedModel:()=>Nt,Ernie4_5ForCausalLM:()=>g_,Ernie4_5Model:()=>x_,Ernie4_5PretrainedModel:()=>Zr,EsmForMaskedLM:()=>y_,EsmForSequenceClassification:()=>b_,EsmForTokenClassification:()=>k_,EsmModel:()=>w_,EsmPreTrainedModel:()=>ns,ExaoneForCausalLM:()=>E_,ExaoneModel:()=>v_,ExaonePreTrainedModel:()=>en,FalconForCausalLM:()=>M_,FalconH1ForCausalLM:()=>O_,FalconH1Model:()=>S_,FalconH1PreTrainedModel:()=>sn,FalconModel:()=>A_,FalconPreTrainedModel:()=>tn,FastViTForImageClassification:()=>z_,FastViTModel:()=>I_,FastViTPreTrainedModel:()=>rn,Florence2ForConditionalGeneration:()=>T_,Florence2PreTrainedModel:()=>oa,GLPNForDepthEstimation:()=>B_,GLPNModel:()=>j_,GLPNPreTrainedModel:()=>un,GPT2LMHeadModel:()=>J_,GPT2Model:()=>Q_,GPT2PreTrainedModel:()=>mn,GPTBigCodeForCausalLM:()=>q_,GPTBigCodeModel:()=>U_,GPTBigCodePreTrainedModel:()=>pn,GPTJForCausalLM:()=>Z_,GPTJModel:()=>Y_,GPTJPreTrainedModel:()=>hn,GPTNeoForCausalLM:()=>W_,GPTNeoModel:()=>G_,GPTNeoPreTrainedModel:()=>dn,GPTNeoXForCausalLM:()=>H_,GPTNeoXModel:()=>V_,GPTNeoXPreTrainedModel:()=>_n,Gemma2ForCausalLM:()=>L_,Gemma2Model:()=>N_,Gemma2PreTrainedModel:()=>on,Gemma3ForCausalLM:()=>R_,Gemma3Model:()=>$_,Gemma3PreTrainedModel:()=>an,Gemma3nForConditionalGeneration:()=>ln,Gemma3nPreTrainedModel:()=>ia,GemmaForCausalLM:()=>C_,GemmaModel:()=>P_,GemmaPreTrainedModel:()=>nn,GlmForCausalLM:()=>D_,GlmModel:()=>F_,GlmPreTrainedModel:()=>cn,GptOssForCausalLM:()=>K_,GptOssModel:()=>X_,GptOssPreTrainedModel:()=>fn,GraniteForCausalLM:()=>tf,GraniteModel:()=>ef,GraniteMoeHybridForCausalLM:()=>rf,GraniteMoeHybridModel:()=>sf,GraniteMoeHybridPreTrainedModel:()=>gn,GranitePreTrainedModel:()=>xn,GroundingDinoForObjectDetection:()=>nf,GroundingDinoPreTrainedModel:()=>aa,GroupViTModel:()=>of,GroupViTPreTrainedModel:()=>la,HeliumForCausalLM:()=>lf,HeliumModel:()=>af,HeliumPreTrainedModel:()=>wn,HieraForImageClassification:()=>uf,HieraModel:()=>cf,HieraPreTrainedModel:()=>yn,HubertForCTC:()=>xf,HubertForSequenceClassification:()=>gf,HubertModel:()=>hf,HubertPreTrainedModel:()=>mf,HunYuanDenseV1ForCausalLM:()=>yf,HunYuanDenseV1Model:()=>wf,HunYuanDenseV1PreTrainedModel:()=>bn,IJepaForImageClassification:()=>vf,IJepaModel:()=>kf,IJepaPreTrainedModel:()=>kn,Idefics3ForConditionalGeneration:()=>ua,Idefics3PreTrainedModel:()=>ca,JAISLMHeadModel:()=>Af,JAISModel:()=>Ef,JAISPreTrainedModel:()=>vn,JinaCLIPModel:()=>Mf,JinaCLIPPreTrainedModel:()=>Fs,JinaCLIPTextModel:()=>En,JinaCLIPVisionModel:()=>Sf,Lfm2ForCausalLM:()=>If,Lfm2Model:()=>Of,Lfm2MoeForCausalLM:()=>Tf,Lfm2MoeModel:()=>zf,Lfm2MoePreTrainedModel:()=>Mn,Lfm2PreTrainedModel:()=>An,LiteWhisperForConditionalGeneration:()=>ng,Llama4ForCausalLM:()=>Nf,Llama4PreTrainedModel:()=>pa,LlamaForCausalLM:()=>Cf,LlamaModel:()=>Pf,LlamaPreTrainedModel:()=>Sn,LlavaForConditionalGeneration:()=>Ds,LlavaOnevisionForConditionalGeneration:()=>Ds,LlavaPreTrainedModel:()=>da,LlavaQwen2ForCausalLM:()=>$f,LongT5ForConditionalGeneration:()=>Ff,LongT5Model:()=>Rf,LongT5PreTrainedModel:()=>On,M2M100ForConditionalGeneration:()=>jf,M2M100Model:()=>Df,M2M100PreTrainedModel:()=>In,MBartForCausalLM:()=>Xf,MBartForConditionalGeneration:()=>Vf,MBartForSequenceClassification:()=>Hf,MBartModel:()=>Wf,MBartPreTrainedModel:()=>os,MPNetForMaskedLM:()=>Pm,MPNetForQuestionAnswering:()=>Lm,MPNetForSequenceClassification:()=>Cm,MPNetForTokenClassification:()=>Nm,MPNetModel:()=>Tm,MPNetPreTrainedModel:()=>Lt,MT5ForConditionalGeneration:()=>Dm,MT5Model:()=>Fm,MT5PreTrainedModel:()=>Bn,MarianMTModel:()=>Uf,MarianModel:()=>Bf,MarianPreTrainedModel:()=>zn,MaskFormerForInstanceSegmentation:()=>Gf,MaskFormerModel:()=>qf,MaskFormerPreTrainedModel:()=>Tn,Metric3DForDepthEstimation:()=>Kf,Metric3DPreTrainedModel:()=>_a,Metric3Dv2ForDepthEstimation:()=>Qf,Metric3Dv2PreTrainedModel:()=>fa,MgpstrForSceneTextRecognition:()=>Jf,MgpstrModelOutput:()=>ma,MgpstrPreTrainedModel:()=>ha,MimiDecoderModel:()=>Cn,MimiDecoderOutput:()=>ga,MimiEncoderModel:()=>Pn,MimiEncoderOutput:()=>xa,MimiModel:()=>Yf,MimiPreTrainedModel:()=>js,MistralForCausalLM:()=>em,MistralModel:()=>Zf,MistralPreTrainedModel:()=>Nn,MobileBertForMaskedLM:()=>sm,MobileBertForQuestionAnswering:()=>nm,MobileBertForSequenceClassification:()=>rm,MobileBertModel:()=>tm,MobileBertPreTrainedModel:()=>is,MobileLLMForCausalLM:()=>im,MobileLLMModel:()=>om,MobileLLMPreTrainedModel:()=>Ln,MobileNetV1ForImageClassification:()=>lm,MobileNetV1ForSemanticSegmentation:()=>cm,MobileNetV1Model:()=>am,MobileNetV1PreTrainedModel:()=>Bs,MobileNetV2ForImageClassification:()=>pm,MobileNetV2ForSemanticSegmentation:()=>dm,MobileNetV2Model:()=>um,MobileNetV2PreTrainedModel:()=>Us,MobileNetV3ForImageClassification:()=>fm,MobileNetV3ForSemanticSegmentation:()=>mm,MobileNetV3Model:()=>_m,MobileNetV3PreTrainedModel:()=>qs,MobileNetV4ForImageClassification:()=>xm,MobileNetV4ForSemanticSegmentation:()=>gm,MobileNetV4Model:()=>hm,MobileNetV4PreTrainedModel:()=>Gs,MobileViTForImageClassification:()=>ym,MobileViTModel:()=>wm,MobileViTPreTrainedModel:()=>$n,MobileViTV2ForImageClassification:()=>km,MobileViTV2Model:()=>bm,MobileViTV2PreTrainedModel:()=>Rn,ModernBertDecoderForCausalLM:()=>Om,ModernBertDecoderModel:()=>Sm,ModernBertDecoderPreTrainedModel:()=>Fn,ModernBertForMaskedLM:()=>Em,ModernBertForSequenceClassification:()=>Am,ModernBertForTokenClassification:()=>Mm,ModernBertModel:()=>vm,ModernBertPreTrainedModel:()=>as,Moondream1ForConditionalGeneration:()=>Lf,MoonshineForConditionalGeneration:()=>zm,MoonshineModel:()=>Im,MoonshinePreTrainedModel:()=>Dn,MptForCausalLM:()=>Rm,MptModel:()=>$m,MptPreTrainedModel:()=>jn,MultiModalityCausalLM:()=>jm,MultiModalityPreTrainedModel:()=>wa,MusicgenForCausalLM:()=>Um,MusicgenForConditionalGeneration:()=>qn,MusicgenModel:()=>Bm,MusicgenPreTrainedModel:()=>Un,NanoChatForCausalLM:()=>Gm,NanoChatModel:()=>qm,NanoChatPreTrainedModel:()=>Gn,NeoBertForMaskedLM:()=>Vm,NeoBertForQuestionAnswering:()=>Km,NeoBertForSequenceClassification:()=>Hm,NeoBertForTokenClassification:()=>Xm,NeoBertModel:()=>Wm,NeoBertPreTrainedModel:()=>$t,NomicBertModel:()=>Qm,NomicBertPreTrainedModel:()=>ya,OPTForCausalLM:()=>ih,OPTModel:()=>oh,OPTPreTrainedModel:()=>Kn,Olmo2ForCausalLM:()=>eh,Olmo2Model:()=>Zm,Olmo2PreTrainedModel:()=>Vn,Olmo3ForCausalLM:()=>sh,Olmo3Model:()=>th,Olmo3PreTrainedModel:()=>Hn,OlmoForCausalLM:()=>Ym,OlmoModel:()=>Jm,OlmoPreTrainedModel:()=>Wn,OpenELMForCausalLM:()=>nh,OpenELMModel:()=>rh,OpenELMPreTrainedModel:()=>Xn,OwlViTForObjectDetection:()=>uh,OwlViTModel:()=>ch,OwlViTPreTrainedModel:()=>Jn,Owlv2ForObjectDetection:()=>lh,Owlv2Model:()=>ah,Owlv2PreTrainedModel:()=>Qn,PaliGemmaForConditionalGeneration:()=>ph,PaliGemmaPreTrainedModel:()=>ba,ParakeetForCTC:()=>dh,ParakeetPreTrainedModel:()=>ka,PatchTSMixerForPrediction:()=>fh,PatchTSMixerModel:()=>_h,PatchTSMixerPreTrainedModel:()=>Yn,PatchTSTForPrediction:()=>hh,PatchTSTModel:()=>mh,PatchTSTPreTrainedModel:()=>Zn,Phi3ForCausalLM:()=>yh,Phi3Model:()=>wh,Phi3PreTrainedModel:()=>to,Phi3VForCausalLM:()=>so,Phi3VPreTrainedModel:()=>va,PhiForCausalLM:()=>gh,PhiModel:()=>xh,PhiPreTrainedModel:()=>eo,PreTrainedModel:()=>f,PvtForImageClassification:()=>kh,PvtModel:()=>bh,PvtPreTrainedModel:()=>ro,PyAnnoteForAudioFrameClassification:()=>Eh,PyAnnoteModel:()=>vh,PyAnnotePreTrainedModel:()=>no,Qwen2ForCausalLM:()=>Mh,Qwen2Model:()=>Ah,Qwen2PreTrainedModel:()=>oo,Qwen2VLForConditionalGeneration:()=>Sh,Qwen2VLPreTrainedModel:()=>Ea,Qwen3ForCausalLM:()=>Ih,Qwen3Model:()=>Oh,Qwen3PreTrainedModel:()=>io,RFDetrForObjectDetection:()=>Ch,RFDetrModel:()=>Ph,RFDetrObjectDetectionOutput:()=>Aa,RFDetrPreTrainedModel:()=>lo,RTDetrForObjectDetection:()=>Od,RTDetrModel:()=>Sd,RTDetrObjectDetectionOutput:()=>mt,RTDetrPreTrainedModel:()=>Gr,RTDetrV2ForObjectDetection:()=>Wh,RTDetrV2Model:()=>Gh,RTDetrV2ObjectDetectionOutput:()=>Ma,RTDetrV2PreTrainedModel:()=>co,ResNetForImageClassification:()=>Th,ResNetModel:()=>zh,ResNetPreTrainedModel:()=>ao,RoFormerForMaskedLM:()=>jh,RoFormerForQuestionAnswering:()=>qh,RoFormerForSequenceClassification:()=>Bh,RoFormerForTokenClassification:()=>Uh,RoFormerModel:()=>Dh,RoFormerPreTrainedModel:()=>Ft,RobertaForMaskedLM:()=>Lh,RobertaForQuestionAnswering:()=>Fh,RobertaForSequenceClassification:()=>$h,RobertaForTokenClassification:()=>Rh,RobertaModel:()=>Nh,RobertaPreTrainedModel:()=>Rt,Sam2ImageSegmentationOutput:()=>Ia,Sam2Model:()=>uo,Sam2PreTrainedModel:()=>za,Sam3TrackerModel:()=>Xh,SamImageSegmentationOutput:()=>Sa,SamModel:()=>Vh,SamPreTrainedModel:()=>Oa,SapiensForDepthEstimation:()=>Qh,SapiensForNormalEstimation:()=>Jh,SapiensForSemanticSegmentation:()=>Kh,SapiensPreTrainedModel:()=>Ws,SegformerForImageClassification:()=>Zh,SegformerForSemanticSegmentation:()=>ex,SegformerModel:()=>Yh,SegformerPreTrainedModel:()=>Vs,SiglipModel:()=>tx,SiglipPreTrainedModel:()=>po,SiglipTextModel:()=>_o,SiglipVisionModel:()=>sx,SmolLM3ForCausalLM:()=>nx,SmolLM3Model:()=>rx,SmolLM3PreTrainedModel:()=>fo,SmolVLMForConditionalGeneration:()=>bf,SnacDecoderModel:()=>ho,SnacEncoderModel:()=>mo,SnacModel:()=>ox,SnacPreTrainedModel:()=>Hs,SpeechT5ForSpeechToText:()=>ax,SpeechT5ForTextToSpeech:()=>lx,SpeechT5HifiGan:()=>cx,SpeechT5Model:()=>ix,SpeechT5PreTrainedModel:()=>Xs,SqueezeBertForMaskedLM:()=>px,SqueezeBertForQuestionAnswering:()=>_x,SqueezeBertForSequenceClassification:()=>dx,SqueezeBertModel:()=>ux,SqueezeBertPreTrainedModel:()=>ls,StableLmForCausalLM:()=>mx,StableLmModel:()=>fx,StableLmPreTrainedModel:()=>xo,Starcoder2ForCausalLM:()=>xx,Starcoder2Model:()=>hx,Starcoder2PreTrainedModel:()=>go,StyleTextToSpeech2Model:()=>gx,StyleTextToSpeech2PreTrainedModel:()=>Ta,SupertonicForConditionalGeneration:()=>wo,SupertonicPreTrainedModel:()=>Pa,Swin2SRForImageSuperResolution:()=>vx,Swin2SRModel:()=>kx,Swin2SRPreTrainedModel:()=>yo,SwinForImageClassification:()=>yx,SwinForSemanticSegmentation:()=>bx,SwinModel:()=>wx,SwinPreTrainedModel:()=>Ks,T5ForConditionalGeneration:()=>Ax,T5Model:()=>Ex,T5PreTrainedModel:()=>bo,TableTransformerForObjectDetection:()=>Sx,TableTransformerModel:()=>Mx,TableTransformerObjectDetectionOutput:()=>Ca,TableTransformerPreTrainedModel:()=>ko,TrOCRForCausalLM:()=>Ox,TrOCRPreTrainedModel:()=>Na,UltravoxModel:()=>$a,UltravoxPreTrainedModel:()=>La,UniSpeechForCTC:()=>Tx,UniSpeechForSequenceClassification:()=>Px,UniSpeechModel:()=>zx,UniSpeechPreTrainedModel:()=>Qs,UniSpeechSatForAudioFrameClassification:()=>$x,UniSpeechSatForCTC:()=>Nx,UniSpeechSatForSequenceClassification:()=>Lx,UniSpeechSatModel:()=>Cx,UniSpeechSatPreTrainedModel:()=>cs,VaultGemmaForCausalLM:()=>Fx,VaultGemmaModel:()=>Rx,VaultGemmaPreTrainedModel:()=>vo,ViTForImageClassification:()=>Bx,ViTMAEModel:()=>Ux,ViTMAEPreTrainedModel:()=>Ra,ViTMSNForImageClassification:()=>Gx,ViTMSNModel:()=>qx,ViTMSNPreTrainedModel:()=>Ao,ViTModel:()=>jx,ViTPreTrainedModel:()=>Eo,VisionEncoderDecoderModel:()=>Dx,VitMatteForImageMatting:()=>Wx,VitMattePreTrainedModel:()=>Fa,VitPoseForPoseEstimation:()=>Vx,VitPosePreTrainedModel:()=>Da,VitsModel:()=>Hx,VitsModelOutput:()=>ja,VitsPreTrainedModel:()=>Ba,VoxtralForConditionalGeneration:()=>Ix,Wav2Vec2BertForCTC:()=>Kx,Wav2Vec2BertForSequenceClassification:()=>Qx,Wav2Vec2BertModel:()=>Xx,Wav2Vec2BertPreTrainedModel:()=>Js,Wav2Vec2ForAudioFrameClassification:()=>ff,Wav2Vec2ForCTC:()=>df,Wav2Vec2ForSequenceClassification:()=>_f,Wav2Vec2Model:()=>pf,Wav2Vec2PreTrainedModel:()=>at,WavLMForAudioFrameClassification:()=>tg,WavLMForCTC:()=>Yx,WavLMForSequenceClassification:()=>Zx,WavLMForXVector:()=>eg,WavLMModel:()=>Jx,WavLMPreTrainedModel:()=>Dt,WeSpeakerResNetModel:()=>sg,WeSpeakerResNetPreTrainedModel:()=>qa,WhisperForConditionalGeneration:()=>Wa,WhisperModel:()=>rg,WhisperPreTrainedModel:()=>Mo,XLMForQuestionAnswering:()=>cg,XLMForSequenceClassification:()=>ag,XLMForTokenClassification:()=>lg,XLMModel:()=>og,XLMPreTrainedModel:()=>jt,XLMRobertaForMaskedLM:()=>pg,XLMRobertaForQuestionAnswering:()=>fg,XLMRobertaForSequenceClassification:()=>dg,XLMRobertaForTokenClassification:()=>_g,XLMRobertaModel:()=>ug,XLMRobertaPreTrainedModel:()=>Bt,XLMWithLMHeadModel:()=>ig,XVectorOutput:()=>Ua,YolosForObjectDetection:()=>hg,YolosModel:()=>mg,YolosObjectDetectionOutput:()=>Va,YolosPreTrainedModel:()=>So,YoutuForCausalLM:()=>gg,YoutuModel:()=>xg,YoutuPreTrainedModel:()=>Oo});var rs=class extends f{},Sp=class extends rs{},Op=class extends rs{async _call(e){return new z(await super._call(e))}},Ip=class extends rs{async _call(e){return new oe(await super._call(e))}},zp=class extends rs{async _call(e){return new J(await super._call(e))}};var Sr=class extends f{},Tp=class extends Sr{},Pp=class extends Sr{};var Or=class extends f{},Cp=class extends Or{},Np=class extends Or{};var Ir=class extends f{},Lp=class extends Ir{},$p=class extends Ir{};var Cs=class extends f{},Rp=class extends Cs{},Fp=class extends Cs{},Dp=class extends Cs{async _call(e){return new z(await super._call(e))}};var zr=class extends f{},jp=class extends zr{},Bp=class extends zr{async _call(e){return new z(await super._call(e))}};var Ot=class extends f{},Up=class extends Ot{},qp=class extends Ot{async _call(e){return new J(await super._call(e))}},Gp=class extends Ot{async _call(e){return new z(await super._call(e))}},Wp=class extends Ot{async _call(e){return new K(await super._call(e))}},Vp=class extends Ot{async _call(e){return new oe(await super._call(e))}};var Tr=class extends f{},Hp=class extends Tr{},Xp=class extends Tr{};var Pr=class extends f{},Kp=class extends Pr{},Qp=class extends Pr{};var Cr=class extends f{},Jp=class extends Cr{},Yp=class extends Cr{};var It=class extends f{},Zp=class extends It{},ed=class extends It{async _call(e){return new J(await super._call(e))}},td=class extends It{async _call(e){return new z(await super._call(e))}},sd=class extends It{async _call(e){return new K(await super._call(e))}},rd=class extends It{async _call(e){return new oe(await super._call(e))}};var Av=4299n,dy=6561n,Xi=class extends f{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","audio_values","exaggeration","audio_features","audio_tokens","speaker_embeddings","speaker_features","past_key_values"];main_input_name="input_ids";_return_dict_in_generate_keys=["audio_tokens","speaker_embeddings","speaker_features"]},Nr=class extends Xi{async encode_speech(e){return q(this.sessions.speech_encoder,{audio_values:e})}async forward({input_ids:e=null,attention_mask:s=null,audio_values:r=null,exaggeration:n=null,position_ids:o=null,inputs_embeds:i=null,past_key_values:a=null,generation_config:l=null,logits_processor:c=null,audio_features:u=null,audio_tokens:p=null,speaker_embeddings:d=null,speaker_features:_=null,...m}){let h;if(!i){let g=this.sessions.embed_tokens.inputNames,w={input_ids:e};if(g.includes("exaggeration")){if(!(n instanceof S)){let y=e.dims[0];if(n==null)n=xe([y],.5);else if(typeof n=="number")n=xe([y],n);else if(Array.isArray(n))n=new S("float32",n,[y]);else throw new Error("Unsupported type for `exaggeration` input")}w.exaggeration=n}if(g.includes("position_ids")&&(w.position_ids=o),{inputs_embeds:i}=await q(this.sessions.embed_tokens,w),u&&p&&d&&_&&(h={audio_features:u,audio_tokens:p,speaker_embeddings:d,speaker_features:_}),h||r)h??=await this.encode_speech(r),i=ne([h.audio_features,i],1),s=Oe([i.dims[0],i.dims[1]]);else{let y=i.dims[1];if(!a||y!==1)throw new Error("Incorrect state encountered during generation.");let E=Object.values(a)[0].dims.at(-2);s=Oe([i.dims[0],E+y])}}return{...await Ue(this,{inputs_embeds:i,past_key_values:a,attention_mask:s,generation_config:l,logits_processor:c},!1),...h}}prepare_inputs_for_generation(e,s,r){if(!s.position_ids&&this.sessions.embed_tokens.inputNames.includes("position_ids"))if(s.input_ids.dims[1]===1){let n=Array.from({length:e.length},(o,i)=>e[i].length-e[i].findLastIndex(a=>a==dy)-1);s.position_ids=new S("int64",n,[e.length,1])}else{let o=s.input_ids.tolist().map(i=>{let a=0;return i.map(l=>l>=dy?0:a++)});s.position_ids=new S("int64",o.flat(),s.input_ids.dims)}return s.input_ids.dims[1]===1&&(delete s.audio_values,delete s.audio_features,delete s.audio_tokens,delete s.speaker_embeddings,delete s.speaker_features),Ar(this,e,s,r)}async generate(e){let{sequences:s,audio_tokens:r,speaker_embeddings:n,speaker_features:o}=await super.generate({...e,return_dict_in_generate:!0}),i=s.slice(null,[e.input_ids.dims[1],-1]),a=xe([i.dims[0],3],Av),l=ne([r,i,a],1),{waveform:c}=await q(this.sessions.conditional_decoder,{speech_tokens:l,speaker_features:o,speaker_embeddings:n});return c}};var Ki=class extends f{},nd=class extends Ki{};var Ns=class extends f{},od=class extends Ns{},Lr=class extends Ns{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},$r=class extends Ns{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"audio_model"})}};var ft=class extends f{},id=class extends ft{},ad=class extends ft{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},Rr=class extends ft{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},ld=class extends ft{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}},cd=class extends ft{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var Fr=class extends f{},ud=class extends Fr{},pd=class extends Fr{};var Dr=class extends f{},dd=class extends Dr{},_d=class extends Dr{};var jr=class extends f{},fd=class extends jr{},md=class extends jr{};var Br=class extends f{},hd=class extends Br{},xd=class extends Br{};var zt=class extends f{},gd=class extends zt{},wd=class extends zt{async _call(e){return new J(await super._call(e))}},yd=class extends zt{async _call(e){return new z(await super._call(e))}},bd=class extends zt{async _call(e){return new K(await super._call(e))}},kd=class extends zt{async _call(e){return new oe(await super._call(e))}};var Ur=class extends f{},vd=class extends Ur{},Ed=class extends Ur{async _call(e){return new z(await super._call(e))}};var qr=class extends f{},Ad=class extends qr{},Md=class extends qr{async _call(e){return new z(await super._call(e))}};var Gr=class extends f{},Sd=class extends Gr{},Od=class extends Gr{async _call(e){return new mt(await super._call(e))}},mt=class extends ue{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}};var Wr=class extends f{},Id=class extends Wr{},zd=class extends Wr{async _call(e){return new mt(await super._call(e))}};var Qi=class extends ue{constructor({audio_codes:e}){super(),this.audio_codes=e}},Ji=class extends ue{constructor({audio_values:e}){super(),this.audio_values=e}},Ls=class extends f{main_input_name="input_values";forward_params=["input_values"]},Td=class extends Ls{async encode(e){return new Qi(await q(this.sessions.encoder_model,e))}async decode(e){return new Ji(await q(this.sessions.decoder_model,e))}},Vr=class extends Ls{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},Hr=class extends Ls{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var Tt=class extends f{},Pd=class extends Tt{},Cd=class extends Tt{async _call(e){return new J(await super._call(e))}},Nd=class extends Tt{async _call(e){return new z(await super._call(e))}},Ld=class extends Tt{async _call(e){return new K(await super._call(e))}},$d=class extends Tt{async _call(e){return new oe(await super._call(e))}};var Pt=class extends f{},Rd=class extends Pt{},Fd=class extends Pt{async _call(e){return new J(await super._call(e))}},Dd=class extends Pt{async _call(e){return new z(await super._call(e))}},jd=class extends Pt{async _call(e){return new K(await super._call(e))}},Bd=class extends Pt{async _call(e){return new oe(await super._call(e))}};var Yi=class extends f{},Ud=class extends Yi{};var Xr=class extends f{},qd=class extends Xr{},Gd=class extends Xr{async _call(e){return new z(await super._call(e))}};var Zi=class extends f{},Wd=class extends Zi{};var ea=class extends f{},Vd=class extends ea{};var $s=class extends f{},Hd=class extends $s{},Xd=class extends $s{async _call(e){return new Rs(await super._call(e))}},Kd=class extends $s{async _call(e){return new ta(await super._call(e))}},Rs=class extends ue{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}},ta=class extends ue{constructor({logits:e,pred_boxes:s,pred_masks:r}){super(),this.logits=e,this.pred_boxes=s,this.pred_masks=r}};var Kr=class extends f{},Qd=class extends Kr{},Jd=class extends Kr{async _call(e){return new z(await super._call(e))}};var Qr=class extends f{},Yd=class extends Qr{},Zd=class extends Qr{async _call(e){return new z(await super._call(e))}};var sa=class extends f{},e_=class extends sa{};var ra=class extends f{},t_=class extends ra{};var Ct=class extends f{},s_=class extends Ct{},r_=class extends Ct{async _call(e){return new z(await super._call(e))}},n_=class extends Ct{async _call(e){return new K(await super._call(e))}},o_=class extends Ct{async _call(e){return new oe(await super._call(e))}},i_=class extends Ct{async _call(e){return new J(await super._call(e))}};var na=class extends f{},a_=class extends na{};var Jr=class extends f{},l_=class extends Jr{},c_=class extends Jr{};var Yr=class extends f{},u_=class extends Yr{},p_=class extends Yr{async _call(e){return new z(await super._call(e))}};var Nt=class extends f{},d_=class extends Nt{},__=class extends Nt{async _call(e){return new J(await super._call(e))}},f_=class extends Nt{async _call(e){return new z(await super._call(e))}},m_=class extends Nt{async _call(e){return new K(await super._call(e))}},h_=class extends Nt{async _call(e){return new oe(await super._call(e))}};var Zr=class extends f{},x_=class extends Zr{},g_=class extends Zr{};var ns=class extends f{},w_=class extends ns{},y_=class extends ns{async _call(e){return new J(await super._call(e))}},b_=class extends ns{async _call(e){return new z(await super._call(e))}},k_=class extends ns{async _call(e){return new K(await super._call(e))}};var en=class extends f{},v_=class extends en{},E_=class extends en{};var tn=class extends f{},A_=class extends tn{},M_=class extends tn{};var sn=class extends f{},S_=class extends sn{},O_=class extends sn{};var rn=class extends f{},I_=class extends rn{},z_=class extends rn{async _call(e){return new z(await super._call(e))}};var oa=class extends f{forward_params=["input_ids","inputs_embeds","attention_mask","pixel_values","encoder_outputs","decoder_input_ids","decoder_inputs_embeds","decoder_attention_mask","past_key_values"];main_input_name="inputs_embeds"},T_=class extends oa{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:s,input_ids:r,attention_mask:n}){return{inputs_embeds:ne([s,e],1),attention_mask:ne([Oe(s.dims.slice(0,2)),n],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:s,inputs_embeds:r,attention_mask:n}){if(!e&&!s)throw new Error("Either `input_ids` or `pixel_values` should be provided.");let o,i;return e&&(o=await this.encode_text({input_ids:e})),s&&(i=await this.encode_image({pixel_values:s})),o&&i?{inputs_embeds:r,attention_mask:n}=this._merge_input_ids_with_image_features({inputs_embeds:o,image_features:i,input_ids:e,attention_mask:n}):r=o||i,{inputs_embeds:r,attention_mask:n}}async forward({input_ids:e,pixel_values:s,attention_mask:r,decoder_input_ids:n,decoder_attention_mask:o,encoder_outputs:i,past_key_values:a,inputs_embeds:l,decoder_inputs_embeds:c}){if(l||({inputs_embeds:l,attention_mask:r}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:s,inputs_embeds:l,attention_mask:r})),!i){let{last_hidden_state:p}=await Je(this,{inputs_embeds:l,attention_mask:r});i=p}if(!c){if(!n)throw new Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");c=await this.encode_text({input_ids:n})}return await Ue(this,{inputs_embeds:c,attention_mask:o,encoder_attention_mask:r,encoder_hidden_states:i,past_key_values:a},!0)}};var nn=class extends f{},P_=class extends nn{},C_=class extends nn{};var on=class extends f{},N_=class extends on{},L_=class extends on{};var an=class extends f{},$_=class extends an{},R_=class extends an{};var ia=class extends f{forward_params=["input_ids","attention_mask","inputs_embeds","per_layer_inputs","position_ids","pixel_values","input_features","input_features_mask","past_key_values"]},ln=class extends ia{async forward({input_ids:e=null,attention_mask:s=null,pixel_values:r=null,input_features:n=null,input_features_mask:o=null,position_ids:i=null,inputs_embeds:a=null,per_layer_inputs:l=null,past_key_values:c=null,generation_config:u=null,logits_processor:p=null,...d}){if((!a||!l)&&({inputs_embeds:a,per_layer_inputs:l}=await q(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(r){let{image_features:m}=await q(this.sessions.vision_encoder,{pixel_values:r});({inputs_embeds:a,attention_mask:s}=this._merge_input_ids_with_image_features({image_features:m,inputs_embeds:a,input_ids:e,attention_mask:s}))}if(n){let{audio_features:m}=await q(this.sessions.audio_encoder,{input_features:n,input_features_mask:o});({inputs_embeds:a,attention_mask:s}=this._merge_input_ids_with_audio_features({audio_features:m,inputs_embeds:a,input_ids:e,attention_mask:s}))}}return await Ue(this,{inputs_embeds:a,per_layer_inputs:l,past_key_values:c,attention_mask:s,position_ids:i,generation_config:u,logits_processor:p},!0)}_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return _t({image_token_id:this.config.image_token_id,...e,image_features:r})}_merge_input_ids_with_audio_features(e){let s=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,s);return Hi({audio_token_id:this.config.audio_token_id,...e,audio_features:r})}};var cn=class extends f{},F_=class extends cn{},D_=class extends cn{};var un=class extends f{},j_=class extends un{},B_=class extends un{};var pn=class extends f{},U_=class extends pn{},q_=class extends pn{};var dn=class extends f{},G_=class extends dn{},W_=class extends dn{};var _n=class extends f{},V_=class extends _n{},H_=class extends _n{};var fn=class extends f{},X_=class extends fn{},K_=class extends fn{};var mn=class extends f{},Q_=class extends mn{},J_=class extends mn{};var hn=class extends f{},Y_=class extends hn{},Z_=class extends hn{};var xn=class extends f{},ef=class extends xn{},tf=class extends xn{};var gn=class extends f{},sf=class extends gn{},rf=class extends gn{};var aa=class extends f{},nf=class extends aa{};var la=class extends f{},of=class extends la{};var wn=class extends f{},af=class extends wn{},lf=class extends wn{};var yn=class extends f{},cf=class extends yn{},uf=class extends yn{async _call(e){return new z(await super._call(e))}};var at=class extends f{},pf=class extends at{},df=class extends at{async _call(e){return new $e(await super._call(e))}},_f=class extends at{async _call(e){return new z(await super._call(e))}},ff=class extends at{async _call(e){return new K(await super._call(e))}};var mf=class extends f{},hf=class extends at{},xf=class extends at{async _call(e){return new $e(await super._call(e))}},gf=class extends at{async _call(e){return new z(await super._call(e))}};var bn=class extends f{},wf=class extends bn{},yf=class extends bn{};var ca=class extends f{forward_params=["input_ids","attention_mask","pixel_values","pixel_attention_mask","position_ids","past_key_values"]},ua=class extends ca{async encode_image({pixel_values:e,pixel_attention_mask:s}){return(await q(this.sessions.vision_encoder,{pixel_values:e,pixel_attention_mask:s})).image_features}_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return _t({image_token_id:this.config.image_token_id,...e,image_features:r})}},bf=class extends ua{};var kn=class extends f{},kf=class extends kn{},vf=class extends kn{async _call(e){return new z(await super._call(e))}};var vn=class extends f{},Ef=class extends vn{},Af=class extends vn{};var Fs=class extends f{},Mf=class extends Fs{async forward(e){let s=!e.input_ids,r=!e.pixel_values;if(s&&r)throw new Error("Either `input_ids` or `pixel_values` should be provided.");if(s&&(e.input_ids=Oe([e.pixel_values.dims[0],1])),r){let{image_size:c}=this.config.vision_config;e.pixel_values=xe([0,3,c,c],0)}let{text_embeddings:n,image_embeddings:o,l2norm_text_embeddings:i,l2norm_image_embeddings:a}=await super.forward(e),l={};return s||(l.text_embeddings=n,l.l2norm_text_embeddings=i),r||(l.image_embeddings=o,l.l2norm_image_embeddings=a),l}},En=class extends Fs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},Sf=class extends Fs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var An=class extends f{},Of=class extends An{},If=class extends An{};var Mn=class extends f{},zf=class extends Mn{},Tf=class extends Mn{};var Sn=class extends f{},Pf=class extends Sn{},Cf=class extends Sn{};var pa=class extends f{},Nf=class extends pa{};var da=class extends f{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},Ds=class extends da{_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return _t({image_token_id:this.config.image_token_index,...e,image_features:r})}},Lf=class extends Ds{},$f=class extends Ds{};var On=class extends f{},Rf=class extends On{},Ff=class extends On{};var In=class extends f{},Df=class extends In{},jf=class extends In{};var zn=class extends f{},Bf=class extends zn{},Uf=class extends zn{};var Tn=class extends f{},qf=class extends Tn{},Gf=class extends Tn{};var os=class extends f{},Wf=class extends os{},Vf=class extends os{},Hf=class extends os{async _call(e){return new z(await super._call(e))}},Xf=class extends os{};var _a=class extends f{},Kf=class extends _a{};var fa=class extends f{},Qf=class extends fa{};var ma=class extends ue{constructor({char_logits:e,bpe_logits:s,wp_logits:r}){super(),this.char_logits=e,this.bpe_logits=s,this.wp_logits=r}get logits(){return[this.char_logits,this.bpe_logits,this.wp_logits]}},ha=class extends f{},Jf=class extends ha{async _call(e){return new ma(await super._call(e))}};var xa=class extends ue{constructor({audio_codes:e}){super(),this.audio_codes=e}},ga=class extends ue{constructor({audio_values:e}){super(),this.audio_values=e}},js=class extends f{main_input_name="input_values";forward_params=["input_values"]},Yf=class extends js{async encode(e){return new xa(await q(this.sessions.encoder_model,e))}async decode(e){return new ga(await q(this.sessions.decoder_model,e))}},Pn=class extends js{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},Cn=class extends js{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var Nn=class extends f{},Zf=class extends Nn{},em=class extends Nn{};var is=class extends f{},tm=class extends is{},sm=class extends is{async _call(e){return new J(await super._call(e))}},rm=class extends is{async _call(e){return new z(await super._call(e))}},nm=class extends is{async _call(e){return new oe(await super._call(e))}};var Ln=class extends f{},om=class extends Ln{},im=class extends Ln{};var Bs=class extends f{},am=class extends Bs{},lm=class extends Bs{async _call(e){return new z(await super._call(e))}},cm=class extends Bs{};var Us=class extends f{},um=class extends Us{},pm=class extends Us{async _call(e){return new z(await super._call(e))}},dm=class extends Us{};var qs=class extends f{},_m=class extends qs{},fm=class extends qs{async _call(e){return new z(await super._call(e))}},mm=class extends qs{};var Gs=class extends f{},hm=class extends Gs{},xm=class extends Gs{async _call(e){return new z(await super._call(e))}},gm=class extends Gs{};var $n=class extends f{},wm=class extends $n{},ym=class extends $n{async _call(e){return new z(await super._call(e))}};var Rn=class extends f{},bm=class extends Rn{},km=class extends Rn{async _call(e){return new z(await super._call(e))}};var as=class extends f{},vm=class extends as{},Em=class extends as{async _call(e){return new J(await super._call(e))}},Am=class extends as{async _call(e){return new z(await super._call(e))}},Mm=class extends as{async _call(e){return new K(await super._call(e))}};var Fn=class extends f{},Sm=class extends Fn{},Om=class extends Fn{};var Dn=class extends f{requires_attention_mask=!1;main_input_name="input_values";forward_params=["input_values","decoder_input_ids","past_key_values"]},Im=class extends Dn{},zm=class extends Dn{};var Lt=class extends f{},Tm=class extends Lt{},Pm=class extends Lt{async _call(e){return new J(await super._call(e))}},Cm=class extends Lt{async _call(e){return new z(await super._call(e))}},Nm=class extends Lt{async _call(e){return new K(await super._call(e))}},Lm=class extends Lt{async _call(e){return new oe(await super._call(e))}};var jn=class extends f{},$m=class extends jn{},Rm=class extends jn{};var Bn=class extends f{},Fm=class extends Bn{},Dm=class extends Bn{};var wa=class extends f{},jm=class extends wa{forward_params=["input_ids","pixel_values","images_seq_mask","images_emb_mask","attention_mask","position_ids","past_key_values"];constructor(...e){super(...e),this._generation_mode="text"}async forward(e){let s=this._generation_mode??"text",r;if(s==="text"||!e.past_key_values){let l=this.sessions.prepare_inputs_embeds,c=Me(e,l.inputNames);r=await q(l,c)}else{let l=this.sessions.gen_img_embeds,c=Me({image_ids:e.input_ids},l.inputNames);r=await q(l,c)}let n={...e,...r},o=await Ue(this,n),i=this.sessions[s==="text"?"lm_head":"gen_head"];if(!i)throw new Error(`Unable to find "${i}" generation head`);let a=await q(i,Me(o,i.inputNames));return{...r,...o,...a}}prepare_inputs_for_generation(e,s,r){let n=!!s.past_key_values;return r.guidance_scale!==null&&r.guidance_scale>1&&(n?s.input_ids=ne([s.input_ids,s.input_ids],0):(s.input_ids=ne([s.input_ids,dr(s.input_ids,BigInt(r.pad_token_id))],0),s.attention_mask=ne([s.attention_mask,dr(s.attention_mask,0n)],0))),(n||!s.pixel_values)&&(s.pixel_values=xe([0,0,3,384,384],1)),n&&(s.images_seq_mask=new S("bool",new Array(1).fill(!0).fill(!1,0,1),[1,1]),s.images_emb_mask=new S("bool",new Array(0).fill(!1),[1,1,0])),s}async generate(e){return this._generation_mode="text",super.generate(e)}async generate_images(e){this._generation_mode="image";let s=(e.inputs??e[this.main_input_name]).dims[1],n=(await super.generate(e)).slice(null,[s,null]),o=this.sessions.image_decode,{decoded_image:i}=await q(o,{generated_tokens:n}),a=i.add_(1).mul_(255/2).clamp_(0,255).to("uint8"),l=[];for(let c of a){let u=we.fromTensor(c);l.push(u)}return l}};var Un=class extends f{},Bm=class extends Un{},Um=class extends Un{},qn=class extends f{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"];_apply_and_filter_by_delay_pattern_mask(e){let[s,r]=e.dims,n=this.config.decoder.num_codebooks,o=r-n,i=0;for(let c=0;c<e.size;++c){if(e.data[c]==this.config.decoder.pad_token_id)continue;let u=c%r,p=Math.floor(c/r)%n,d=u-p;d>0&&d<=o&&(e.data[i++]=e.data[c])}let a=Math.floor(s/n),l=i/(a*n);return new S(e.type,e.data.slice(0,i),[a,n,l])}prepare_inputs_for_generation(e,s,r){let n=BigInt(this.config.decoder.pad_token_id),o=structuredClone(e);for(let i=0;i<o.length;++i)for(let a=0;a<o[i].length;++a)i%this.config.decoder.num_codebooks>=a&&(o[i][a]=n);return r.guidance_scale!==null&&r.guidance_scale>1&&(o=o.concat(o)),Mr(this,o,s,r)}async generate(e){let s=await super.generate(e),r=this._apply_and_filter_by_delay_pattern_mask(s).unsqueeze_(0),{audio_values:n}=await q(this.sessions.encodec_decode,{audio_codes:r});return n}};var Gn=class extends f{},qm=class extends Gn{},Gm=class extends Gn{};var $t=class extends f{},Wm=class extends $t{},Vm=class extends $t{async _call(e){return new J(await super._call(e))}},Hm=class extends $t{async _call(e){return new z(await super._call(e))}},Xm=class extends $t{async _call(e){return new K(await super._call(e))}},Km=class extends $t{async _call(e){return new oe(await super._call(e))}};var ya=class extends f{},Qm=class extends ya{};var Wn=class extends f{},Jm=class extends Wn{},Ym=class extends Wn{};var Vn=class extends f{},Zm=class extends Vn{},eh=class extends Vn{};var Hn=class extends f{},th=class extends Hn{},sh=class extends Hn{};var Xn=class extends f{},rh=class extends Xn{},nh=class extends Xn{};var Kn=class extends f{},oh=class extends Kn{},ih=class extends Kn{};var Qn=class extends f{},ah=class extends Qn{},lh=class extends Qn{};var Jn=class extends f{},ch=class extends Jn{},uh=class extends Jn{};var ba=class extends f{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},ph=class extends ba{_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return _t({image_token_id:this.config.image_token_index,...e,image_features:r})}};var ka=class extends f{},dh=class extends ka{async _call(e){return new $e(await super._call(e))}};var Yn=class extends f{},_h=class extends Yn{},fh=class extends Yn{};var Zn=class extends f{},mh=class extends Zn{},hh=class extends Zn{};var eo=class extends f{},xh=class extends eo{},gh=class extends eo{};var to=class extends f{},wh=class extends to{},yh=class extends to{};var va=class extends f{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","pixel_values","image_sizes","past_key_values"]},so=class extends va{async forward({input_ids:e=null,attention_mask:s=null,pixel_values:r=null,image_sizes:n=null,position_ids:o=null,inputs_embeds:i=null,past_key_values:a=null,generation_config:l=null,logits_processor:c=null,...u}){if(!i){let d;if(r&&e.dims[1]!==1){if(!n)throw new Error("`image_sizes` must be provided when `pixel_values` is provided.");({image_features:d}=await q(this.sessions.vision_encoder,{pixel_values:r,image_sizes:n}))}else{let _=this.config.normalized_config.hidden_size;d=new S("float32",[],[0,_])}({inputs_embeds:i}=await q(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:d}))}return await Ue(this,{inputs_embeds:i,past_key_values:a,attention_mask:s,position_ids:o,generation_config:l,logits_processor:c},!1)}};var ro=class extends f{},bh=class extends ro{},kh=class extends ro{async _call(e){return new z(await super._call(e))}};var no=class extends f{},vh=class extends no{},Eh=class extends no{async _call(e){return new K(await super._call(e))}};var oo=class extends f{},Ah=class extends oo{},Mh=class extends oo{};var Ea=class extends f{forward_params=["input_ids","attention_mask","position_ids","past_key_values","pixel_values","image_grid_thw"]},Sh=class extends Ea{get_rope_index(e,s,r,n){let{vision_config:o,image_token_id:i,video_token_id:a,vision_start_token_id:l}=this.config,c=o.spatial_merge_size??2,u=[];if(s||r){let p=e.tolist();n||(n=si(e));let d=n.tolist(),_=Array.from({length:3},w=>Array.from({length:e.dims[0]},y=>Array.from({length:e.dims[1]},E=>1))),m=s?s.tolist():[],h=r?r.tolist():[],x=0,g=0;for(let w=0;w<p.length;++w){let y=p[w].filter((k,v)=>d[w][v]==1),A=y.reduce((k,v,I)=>(v==l&&k.push(I),k),[]).map(k=>y[k+1]),b=A.filter(k=>k==i).length,O=A.filter(k=>k==a).length,N=[],F=0,R=b,B=O;for(let k=0;k<A.length;++k){let v=y.findIndex((ct,Ze)=>Ze>F&&ct==i),I=y.findIndex((ct,Ze)=>Ze>F&&ct==a),Q=R>0&&v!==-1?v:y.length+1,Z=B>0&&I!==-1?I:y.length+1,Ie,Ee,ht,xt;Q<Z?([Ee,ht,xt]=m[x],++x,--R,Ie=Q):([Ee,ht,xt]=h[g],++g,--B,Ie=Z);let[Gt,lt,Ye]=[Number(Ee),Math.floor(Number(ht)/c),Math.floor(Number(xt)/c)],gt=Ie-F,vt=N.length>0?ie(N.at(-1))[0]+1:0;N.push(Array.from({length:3*gt},(ct,Ze)=>vt+Ze%gt));let Wt=gt+vt,Et=Gt*lt*Ye,$o=Array.from({length:Et},(ct,Ze)=>Wt+Math.floor(Ze/(lt*Ye))),Ro=Array.from({length:Et},(ct,Ze)=>Wt+Math.floor(Ze/Ye)%lt),Fo=Array.from({length:Et},(ct,Ze)=>Wt+Ze%Ye);N.push([$o,Ro,Fo].flat()),F=Ie+Et}if(F<y.length){let k=N.length>0?ie(N.at(-1))[0]+1:0,v=y.length-F;N.push(Array.from({length:3*v},(I,Q)=>k+Q%v))}let G=N.reduce((k,v)=>k+v.length,0),D=new Array(G),X=0;for(let k=0;k<3;++k)for(let v=0;v<N.length;++v){let I=N[v],Q=I.length/3;for(let Z=k*Q;Z<(k+1)*Q;++Z)D[X++]=I[Z]}let V=0,re=d[w];for(let k=0;k<re.length;++k)if(re[k]==1){for(let v=0;v<3;++v)_[v][w][k]=D[v*G/3+V];++V}let Y=ie(D)[0];u.push(Y+1-p[w].length)}return[new S("int64",_.flat(1/0),[3,e.dims[0],e.dims[1]]),new S("int64",u,[u.length,1])]}else if(n){let{data:p,dims:d}=Mp(n),_=BigInt64Array.from({length:3*p.length},(h,x)=>p[x%p.length]),m=Array.from({length:d[0]},(h,x)=>ie(p.subarray(d[1]*x,d[1]*(x+1)))[0]+1n+BigInt(d[1]));return[new S("int64",_,[3,...d]),new S("int64",m,[m.length,1])]}else{let[p,d]=e.dims,_=BigInt64Array.from({length:3*p*d},(m,h)=>BigInt(Math.floor(h%d/p)));return[new S("int64",_,[3,...e.dims]),tc([p,1])]}}async encode_image({pixel_values:e,image_grid_thw:s}){return(await q(this.sessions.vision_encoder,{pixel_values:e,grid_thw:s})).image_features}_merge_input_ids_with_image_features(e){return _t({image_token_id:this.config.image_token_id,...e})}prepare_inputs_for_generation(e,s,r){if(s.attention_mask&&!s.position_ids)if(!s.past_key_values)[s.position_ids,s.rope_deltas]=this.get_rope_index(s.input_ids,s.image_grid_thw,s.video_grid_thw,s.attention_mask);else{s.pixel_values=null;let n=BigInt(Object.values(s.past_key_values)[0].dims.at(-2)),o=s.rope_deltas.map(i=>n+i);s.position_ids=Ke([o,o,o],0)}return s}};var io=class extends f{},Oh=class extends io{},Ih=class extends io{};var ao=class extends f{},zh=class extends ao{},Th=class extends ao{async _call(e){return new z(await super._call(e))}};var lo=class extends f{},Ph=class extends lo{},Ch=class extends lo{async _call(e){return new Aa(await super._call(e))}},Aa=class extends mt{};var Rt=class extends f{},Nh=class extends Rt{},Lh=class extends Rt{async _call(e){return new J(await super._call(e))}},$h=class extends Rt{async _call(e){return new z(await super._call(e))}},Rh=class extends Rt{async _call(e){return new K(await super._call(e))}},Fh=class extends Rt{async _call(e){return new oe(await super._call(e))}};var Ft=class extends f{},Dh=class extends Ft{},jh=class extends Ft{async _call(e){return new J(await super._call(e))}},Bh=class extends Ft{async _call(e){return new z(await super._call(e))}},Uh=class extends Ft{async _call(e){return new K(await super._call(e))}},qh=class extends Ft{async _call(e){return new oe(await super._call(e))}};var co=class extends f{},Gh=class extends co{},Wh=class extends co{async _call(e){return new Ma(await super._call(e))}},Ma=class extends mt{};var Sa=class extends ue{constructor({iou_scores:e,pred_masks:s}){super(),this.iou_scores=e,this.pred_masks=s}},Oa=class extends f{},Vh=class extends Oa{async get_image_embeddings({pixel_values:e}){return await Je(this,{pixel_values:e})}async forward(e){!e.image_embeddings||!e.image_positional_embeddings?e={...e,...await this.get_image_embeddings(e)}:e={...e},e.input_labels??=Oe(e.input_points.dims.slice(0,-1));let s={image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings};return e.input_points&&(s.input_points=e.input_points),e.input_labels&&(s.input_labels=e.input_labels),e.input_boxes&&(s.input_boxes=e.input_boxes),await q(this.sessions.prompt_encoder_mask_decoder,s)}async _call(e){return new Sa(await super._call(e))}};var Ia=class extends ue{constructor({iou_scores:e,pred_masks:s,object_score_logits:r}){super(),this.iou_scores=e,this.pred_masks=s,this.object_score_logits=r}},za=class extends f{},uo=class extends za{async get_image_embeddings({pixel_values:e}){return await Je(this,{pixel_values:e})}async forward(e){let{num_feature_levels:s}=this.config.vision_config;if(Array.from({length:s},(i,a)=>`image_embeddings.${a}`).some(i=>!e[i])?e={...e,...await this.get_image_embeddings(e)}:e={...e},e.input_points){if(e.input_boxes&&e.input_boxes.dims[1]!==1)throw new Error("When both `input_points` and `input_boxes` are provided, the number of boxes per image must be 1.");let i=e.input_points.dims;e.input_labels??=Oe(i.slice(0,-1)),e.input_boxes??=xe([i[0],0,4],0)}else if(e.input_boxes){let i=e.input_boxes.dims;e.input_labels=xe([i[0],i[1],0],-1n),e.input_points=xe([i[0],1,0,2],0)}else throw new Error("At least one of `input_points` or `input_boxes` must be provided.");let n=this.sessions.prompt_encoder_mask_decoder,o=Me(e,n.inputNames);return await q(n,o)}async _call(e){return new Ia(await super._call(e))}},Hh=class extends uo{},Xh=class extends uo{};var Ws=class extends f{},Kh=class extends Ws{},Qh=class extends Ws{},Jh=class extends Ws{};var Vs=class extends f{},Yh=class extends Vs{},Zh=class extends Vs{},ex=class extends Vs{};var po=class extends f{},tx=class extends po{},_o=class extends po{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},sx=class extends ft{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var fo=class extends f{},rx=class extends fo{},nx=class extends fo{};var Hs=class extends f{main_input_name="input_values";forward_params=["input_values"]},ox=class extends Hs{async encode(e){return await q(this.sessions.encoder_model,e)}async decode(e){return await q(this.sessions.decoder_model,e)}},mo=class extends Hs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},ho=class extends Hs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var Xs=class extends f{},ix=class extends Xs{},ax=class extends Xs{},lx=class extends Xs{async generate_speech(e,s,{threshold:r=.5,minlenratio:n=0,maxlenratio:o=20,vocoder:i=null}={}){let a={input_ids:e},{encoder_outputs:l,encoder_attention_mask:c}=await Je(this,a),u=l.dims[1]/this.config.reduction_factor,p=Math.floor(u*o),d=Math.floor(u*n),_=this.config.num_mel_bins,m=[],h=null,x=null,g=0;for(;;){++g;let E=Ap(!!x),A;x?A=x.output_sequence_out:A=new S("float32",new Float32Array(_),[1,1,_]);let b={use_cache_branch:E,output_sequence:A,encoder_attention_mask:c,speaker_embeddings:s,encoder_hidden_states:l};this.addPastKeyValues(b,h),x=await q(this.sessions.decoder_model_merged,b),h=this.getPastKeyValues(x,h);let{prob:O,spectrum:N}=x;if(m.push(N),g>=d&&(Array.from(O.data).filter(F=>F>=r).length>0||g>=p))break}let w=ne(m),{waveform:y}=await q(i.sessions.model,{spectrogram:w});return{spectrogram:w,waveform:y}}},cx=class extends f{main_input_name="spectrogram"};var ls=class extends f{},ux=class extends ls{},px=class extends ls{async _call(e){return new J(await super._call(e))}},dx=class extends ls{async _call(e){return new z(await super._call(e))}},_x=class extends ls{async _call(e){return new oe(await super._call(e))}};var xo=class extends f{},fx=class extends xo{},mx=class extends xo{};var go=class extends f{},hx=class extends go{},xx=class extends go{};var Ta=class extends f{},gx=class extends Ta{};var Pa=class extends f{},wo=class extends Pa{async generate_speech({input_ids:e,attention_mask:s,style:r,num_inference_steps:n=5,speed:o=1.05}){let{sampling_rate:i,chunk_compress_factor:a,base_chunk_size:l,latent_dim:c}=this.config,{last_hidden_state:u,durations:p}=await q(this.sessions.text_encoder,{input_ids:e,attention_mask:s,style:r}),d=p.div(o).mul_(i),_=l*a,m=d.data,h=Int32Array.from(m,R=>Math.ceil(R/_)),x=Math.max(...h),g=e.dims[0],w=new BigInt64Array(g*x);for(let R=0;R<g;++R)w.fill(1n,R*x,R*x+h[R]);let y=new S("int64",w,[g,x]),E=c*a,A=E*x,b=Dw([g,E,x]),O=b.data;for(let R=0;R<g;++R)if(h[R]!==x)for(let B=0;B<E;++B)O.fill(0,R*A+B*x+h[R],R*A+(B+1)*x);let N=xe([g],n);for(let R=0;R<n;++R){let B=xe([g],R);({denoised_latents:b}=await q(this.sessions.latent_denoiser,{style:r,noisy_latents:b,latent_mask:y,encoder_outputs:u,attention_mask:s,timestep:B,num_inference_steps:N}))}let{waveform:F}=await q(this.sessions.voice_decoder,{latents:b});return{waveform:F,durations:d}}};var Ks=class extends f{},wx=class extends Ks{},yx=class extends Ks{async _call(e){return new z(await super._call(e))}},bx=class extends Ks{};var yo=class extends f{},kx=class extends yo{},vx=class extends yo{};var bo=class extends f{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"]},Ex=class extends bo{},Ax=class extends bo{};var ko=class extends f{},Mx=class extends ko{},Sx=class extends ko{async _call(e){return new Ca(await super._call(e))}},Ca=class extends Rs{};var Na=class extends f{},Ox=class extends Na{};var La=class extends f{forward_params=["input_ids","attention_mask","position_ids","audio_values","past_key_values"]},$a=class extends La{_merge_input_ids_with_audio_features(e){let s=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,s);return Hi({audio_token_id:this.config.ignore_index??this.config.audio_token_id,...e,audio_features:r})}},Ix=class extends $a{};var Qs=class extends f{},zx=class extends Qs{},Tx=class extends Qs{async _call(e){return new $e(await super._call(e))}},Px=class extends Qs{async _call(e){return new z(await super._call(e))}};var cs=class extends f{},Cx=class extends cs{},Nx=class extends cs{async _call(e){return new $e(await super._call(e))}},Lx=class extends cs{async _call(e){return new z(await super._call(e))}},$x=class extends cs{async _call(e){return new K(await super._call(e))}};var vo=class extends f{},Rx=class extends vo{},Fx=class extends vo{};var Dx=class extends f{main_input_name="pixel_values";forward_params=["pixel_values","decoder_input_ids","encoder_hidden_states","past_key_values"]};var Eo=class extends f{},jx=class extends Eo{},Bx=class extends Eo{async _call(e){return new z(await super._call(e))}};var Ra=class extends f{},Ux=class extends Ra{};var Ao=class extends f{},qx=class extends Ao{},Gx=class extends Ao{async _call(e){return new z(await super._call(e))}};var Fa=class extends f{},Wx=class extends Fa{async _call(e){return new zi(await super._call(e))}};var Da=class extends f{},Vx=class extends Da{};var ja=class extends ue{constructor({waveform:e,spectrogram:s}){super(),this.waveform=e,this.spectrogram=s}},Ba=class extends f{},Hx=class extends Ba{async _call(e){return new ja(await super._call(e))}};var Js=class extends f{},Xx=class extends Js{},Kx=class extends Js{async _call(e){return new $e(await super._call(e))}},Qx=class extends Js{async _call(e){return new z(await super._call(e))}};var Ua=class extends ue{constructor({logits:e,embeddings:s}){super(),this.logits=e,this.embeddings=s}},Dt=class extends f{},Jx=class extends Dt{},Yx=class extends Dt{async _call(e){return new $e(await super._call(e))}},Zx=class extends Dt{async _call(e){return new z(await super._call(e))}},eg=class extends Dt{async _call(e){return new Ua(await super._call(e))}},tg=class extends Dt{async _call(e){return new K(await super._call(e))}};var qa=class extends f{},sg=class extends qa{};var Ga=class extends Ts{return_timestamps=null;return_token_timestamps=null;num_frames=null;alignment_heads=null;task=null;language=null;no_timestamps_token_id=null;prompt_ids=null;is_multilingual=null;lang_to_id=null;task_to_id=null;max_initial_timestamp_index=1};var Mo=class extends f{requires_attention_mask=!1;main_input_name="input_features";forward_params=["input_features","attention_mask","decoder_input_ids","decoder_attention_mask","past_key_values"]},rg=class extends Mo{},Wa=class extends Mo{_prepare_generation_config(e,s){return super._prepare_generation_config(e,s,Ga)}_retrieve_init_tokens(e){let s=[e.decoder_start_token_id],r=e.language,n=e.task;if(e.is_multilingual){r||(console.warn("No language specified - defaulting to English (en)."),r="en");let i=`<|${Uw(r)}|>`;s.push(e.lang_to_id[i]),s.push(e.task_to_id[n??"transcribe"])}else if(r||n)throw new Error("Cannot specify `task` or `language` for an English-only model. If the model is intended to be multilingual, pass `is_multilingual=true` to generate, or update the generation config.");return!e.return_timestamps&&e.no_timestamps_token_id&&s.at(-1)!==e.no_timestamps_token_id?s.push(e.no_timestamps_token_id):e.return_timestamps&&s.at(-1)===e.no_timestamps_token_id&&(console.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),s.pop()),s.filter(o=>o!=null)}async generate({inputs:e=null,generation_config:s=null,logits_processor:r=null,stopping_criteria:n=null,...o}){s=this._prepare_generation_config(s,o);let i=o.decoder_input_ids??this._retrieve_init_tokens(s);if(s.return_timestamps&&(r??=new Zt,r.push(new Ci(s,i))),s.begin_suppress_tokens&&(r??=new Zt,r.push(new zs(s.begin_suppress_tokens,i.length))),s.return_token_timestamps){if(!s.alignment_heads)throw new Error("Model generation config has no `alignment_heads`, token-level timestamps not available. See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config.");s.task==="translate"&&console.warn("Token-level timestamps may not be reliable for task 'translate'."),s.output_attentions=!0,s.return_dict_in_generate=!0}let a=await super.generate({inputs:e,generation_config:s,logits_processor:r,decoder_input_ids:i,...o});return s.return_token_timestamps&&(a.token_timestamps=this._extract_token_timestamps(a,s.alignment_heads,s.num_frames)),a}_extract_token_timestamps(e,s,r=null,n=.02){if(!e.cross_attentions)throw new Error("Model outputs must contain cross attentions to extract timestamps. This is most likely because the model was not exported with `output_attentions=True`.");r==null&&console.warn("`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).");let o=this.config.median_filter_width;o===void 0&&(console.warn("Model config has no `median_filter_width`, using default value of 7."),o=7);let i=e.cross_attentions,a=Array.from({length:this.config.decoder_layers},(h,x)=>ne(i.map(g=>g[x]),2)),l=Ke(s.map(([h,x])=>{if(h>=a.length)throw new Error(`Layer index ${h} is out of bounds for cross attentions (length ${a.length}).`);return r?a[h].slice(null,x,null,[0,r]):a[h].slice(null,x)})).transpose(1,0,2,3),[c,u]=Zl(l,-2,0,!0),p=l.clone();for(let h=0;h<p.dims[0];++h){let x=p[h];for(let g=0;g<x.dims[0];++g){let w=x[g],y=c[h][g][0].data,E=u[h][g][0].data;for(let A=0;A<w.dims[0];++A){let b=w[A].data;for(let O=0;O<b.length;++O)b[O]=(b[O]-E[O])/y[O];b.set(ww(b,o))}}}let d=[ti(p,1)],_=e.sequences.dims,m=new S("float32",new Float32Array(_[0]*_[1]),_);for(let h=0;h<_[0];++h){let x=d[h].neg().squeeze_(0),[g,w]=bw(x.tolist()),y=Array.from({length:g.length-1},(b,O)=>g[O+1]-g[O]),E=Pe([1],y).map(b=>!!b),A=[];for(let b=0;b<E.length;++b)E[b]&&A.push(w[b]*n);m[h].data.set(A,1)}return m}},ng=class extends Wa{};var jt=class extends f{},og=class extends jt{},ig=class extends jt{async _call(e){return new J(await super._call(e))}},ag=class extends jt{async _call(e){return new z(await super._call(e))}},lg=class extends jt{async _call(e){return new K(await super._call(e))}},cg=class extends jt{async _call(e){return new oe(await super._call(e))}};var Bt=class extends f{},ug=class extends Bt{},pg=class extends Bt{async _call(e){return new J(await super._call(e))}},dg=class extends Bt{async _call(e){return new z(await super._call(e))}},_g=class extends Bt{async _call(e){return new K(await super._call(e))}},fg=class extends Bt{async _call(e){return new oe(await super._call(e))}};var So=class extends f{},mg=class extends So{},hg=class extends So{async _call(e){return new Va(await super._call(e))}},Va=class extends ue{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}};var Oo=class extends f{},xg=class extends Oo{},gg=class extends Oo{};var Mv=new Map([["bert","BertModel"],["neobert","NeoBertModel"],["modernbert","ModernBertModel"],["nomic_bert","NomicBertModel"],["roformer","RoFormerModel"],["electra","ElectraModel"],["esm","EsmModel"],["convbert","ConvBertModel"],["camembert","CamembertModel"],["deberta","DebertaModel"],["deberta-v2","DebertaV2Model"],["mpnet","MPNetModel"],["albert","AlbertModel"],["distilbert","DistilBertModel"],["roberta","RobertaModel"],["xlm","XLMModel"],["xlm-roberta","XLMRobertaModel"],["clap","ClapModel"],["clip","CLIPModel"],["clipseg","CLIPSegModel"],["chinese_clip","ChineseCLIPModel"],["siglip","SiglipModel"],["jina_clip","JinaCLIPModel"],["mobilebert","MobileBertModel"],["squeezebert","SqueezeBertModel"],["wav2vec2","Wav2Vec2Model"],["wav2vec2-bert","Wav2Vec2BertModel"],["unispeech","UniSpeechModel"],["unispeech-sat","UniSpeechSatModel"],["hubert","HubertModel"],["wavlm","WavLMModel"],["audio-spectrogram-transformer","ASTModel"],["vits","VitsModel"],["pyannote","PyAnnoteModel"],["wespeaker-resnet","WeSpeakerResNetModel"],["detr","DetrModel"],["rt_detr","RTDetrModel"],["rt_detr_v2","RTDetrV2Model"],["rf_detr","RFDetrModel"],["d_fine","DFineModel"],["table-transformer","TableTransformerModel"],["vit","ViTModel"],["ijepa","IJepaModel"],["pvt","PvtModel"],["vit_msn","ViTMSNModel"],["vit_mae","ViTMAEModel"],["groupvit","GroupViTModel"],["fastvit","FastViTModel"],["mobilevit","MobileViTModel"],["mobilevitv2","MobileViTV2Model"],["owlvit","OwlViTModel"],["owlv2","Owlv2Model"],["beit","BeitModel"],["deit","DeiTModel"],["hiera","HieraModel"],["convnext","ConvNextModel"],["convnextv2","ConvNextV2Model"],["dinov2","Dinov2Model"],["dinov2_with_registers","Dinov2WithRegistersModel"],["dinov3_vit","DINOv3ViTModel"],["dinov3_convnext","DINOv3ConvNextModel"],["resnet","ResNetModel"],["swin","SwinModel"],["swin2sr","Swin2SRModel"],["donut-swin","DonutSwinModel"],["yolos","YolosModel"],["dpt","DPTModel"],["glpn","GLPNModel"],["hifigan","SpeechT5HifiGan"],["efficientnet","EfficientNetModel"],["decision_transformer","DecisionTransformerModel"],["patchtst","PatchTSTModel"],["patchtsmixer","PatchTSMixerModel"],["mobilenet_v1","MobileNetV1Model"],["mobilenet_v2","MobileNetV2Model"],["mobilenet_v3","MobileNetV3Model"],["mobilenet_v4","MobileNetV4Model"],["maskformer","MaskFormerModel"],["mgp-str","MgpstrForSceneTextRecognition"],["style_text_to_speech_2","StyleTextToSpeech2Model"]]),Sv=new Map([["t5","T5Model"],["longt5","LongT5Model"],["mt5","MT5Model"],["bart","BartModel"],["mbart","MBartModel"],["marian","MarianModel"],["whisper","WhisperModel"],["m2m_100","M2M100Model"],["blenderbot","BlenderbotModel"],["blenderbot-small","BlenderbotSmallModel"]]),Ov=new Map([["mimi","MimiModel"],["dac","DacModel"],["snac","SnacModel"]]),Iv=new Map([["bloom","BloomModel"],["jais","JAISModel"],["gpt2","GPT2Model"],["gpt_oss","GptOssModel"],["gptj","GPTJModel"],["gpt_bigcode","GPTBigCodeModel"],["gpt_neo","GPTNeoModel"],["gpt_neox","GPTNeoXModel"],["codegen","CodeGenModel"],["llama","LlamaModel"],["apertus","ApertusModel"],["nanochat","NanoChatModel"],["arcee","ArceeModel"],["lfm2","Lfm2Model"],["lfm2_moe","Lfm2MoeModel"],["smollm3","SmolLM3Model"],["exaone","ExaoneModel"],["olmo","OlmoModel"],["olmo2","Olmo2Model"],["olmo3","Olmo3Model"],["mobilellm","MobileLLMModel"],["granite","GraniteModel"],["granitemoehybrid","GraniteMoeHybridModel"],["cohere","CohereModel"],["cohere2","Cohere2Model"],["gemma","GemmaModel"],["gemma2","Gemma2Model"],["vaultgemma","VaultGemmaModel"],["gemma3_text","Gemma3Model"],["helium","HeliumModel"],["glm","GlmModel"],["openelm","OpenELMModel"],["qwen2","Qwen2Model"],["qwen3","Qwen3Model"],["phi","PhiModel"],["phi3","Phi3Model"],["mpt","MptModel"],["opt","OPTModel"],["mistral","MistralModel"],["ministral","MinistralModel"],["ministral3","Ministral3Model"],["ernie4_5","Ernie4_5_Model"],["starcoder2","Starcoder2Model"],["falcon","FalconModel"],["falcon_h1","FalconH1Model"],["stablelm","StableLmModel"],["modernbert-decoder","ModernBertDecoderModel"],["hunyuan_v1_dense","HunYuanDenseV1Model"],["youtu","YoutuModel"]]),_y=new Map([["speecht5","SpeechT5ForSpeechToText"],["whisper","WhisperForConditionalGeneration"],["lite-whisper","LiteWhisperForConditionalGeneration"],["moonshine","MoonshineForConditionalGeneration"]]),fy=new Map([["speecht5","SpeechT5ForTextToSpeech"]]),my=new Map([["vits","VitsModel"],["musicgen","MusicgenForConditionalGeneration"],["supertonic","SupertonicForConditionalGeneration"]]),hy=new Map([["bert","BertForSequenceClassification"],["neobert","NeoBertForSequenceClassification"],["modernbert","ModernBertForSequenceClassification"],["roformer","RoFormerForSequenceClassification"],["electra","ElectraForSequenceClassification"],["esm","EsmForSequenceClassification"],["convbert","ConvBertForSequenceClassification"],["camembert","CamembertForSequenceClassification"],["deberta","DebertaForSequenceClassification"],["deberta-v2","DebertaV2ForSequenceClassification"],["mpnet","MPNetForSequenceClassification"],["albert","AlbertForSequenceClassification"],["distilbert","DistilBertForSequenceClassification"],["roberta","RobertaForSequenceClassification"],["xlm","XLMForSequenceClassification"],["xlm-roberta","XLMRobertaForSequenceClassification"],["bart","BartForSequenceClassification"],["mbart","MBartForSequenceClassification"],["mobilebert","MobileBertForSequenceClassification"],["squeezebert","SqueezeBertForSequenceClassification"]]),xy=new Map([["bert","BertForTokenClassification"],["neobert","NeoBertForTokenClassification"],["modernbert","ModernBertForTokenClassification"],["roformer","RoFormerForTokenClassification"],["electra","ElectraForTokenClassification"],["esm","EsmForTokenClassification"],["convbert","ConvBertForTokenClassification"],["camembert","CamembertForTokenClassification"],["deberta","DebertaForTokenClassification"],["deberta-v2","DebertaV2ForTokenClassification"],["mpnet","MPNetForTokenClassification"],["distilbert","DistilBertForTokenClassification"],["roberta","RobertaForTokenClassification"],["xlm","XLMForTokenClassification"],["xlm-roberta","XLMRobertaForTokenClassification"]]),gy=new Map([["t5","T5ForConditionalGeneration"],["longt5","LongT5ForConditionalGeneration"],["mt5","MT5ForConditionalGeneration"],["bart","BartForConditionalGeneration"],["mbart","MBartForConditionalGeneration"],["marian","MarianMTModel"],["m2m_100","M2M100ForConditionalGeneration"],["blenderbot","BlenderbotForConditionalGeneration"],["blenderbot-small","BlenderbotSmallForConditionalGeneration"]]),wy=new Map([["bloom","BloomForCausalLM"],["gpt2","GPT2LMHeadModel"],["gpt_oss","GptOssForCausalLM"],["jais","JAISLMHeadModel"],["gptj","GPTJForCausalLM"],["gpt_bigcode","GPTBigCodeForCausalLM"],["gpt_neo","GPTNeoForCausalLM"],["gpt_neox","GPTNeoXForCausalLM"],["codegen","CodeGenForCausalLM"],["llama","LlamaForCausalLM"],["nanochat","NanoChatForCausalLM"],["apertus","ApertusForCausalLM"],["llama4_text","Llama4ForCausalLM"],["arcee","ArceeForCausalLM"],["lfm2","Lfm2ForCausalLM"],["lfm2_moe","Lfm2MoeForCausalLM"],["smollm3","SmolLM3ForCausalLM"],["exaone","ExaoneForCausalLM"],["olmo","OlmoForCausalLM"],["olmo2","Olmo2ForCausalLM"],["olmo3","Olmo3ForCausalLM"],["mobilellm","MobileLLMForCausalLM"],["granite","GraniteForCausalLM"],["granitemoehybrid","GraniteMoeHybridForCausalLM"],["cohere","CohereForCausalLM"],["cohere2","Cohere2ForCausalLM"],["gemma","GemmaForCausalLM"],["gemma2","Gemma2ForCausalLM"],["vaultgemma","VaultGemmaForCausalLM"],["gemma3_text","Gemma3ForCausalLM"],["helium","HeliumForCausalLM"],["glm","GlmForCausalLM"],["openelm","OpenELMForCausalLM"],["qwen2","Qwen2ForCausalLM"],["qwen3","Qwen3ForCausalLM"],["phi","PhiForCausalLM"],["phi3","Phi3ForCausalLM"],["mpt","MptForCausalLM"],["opt","OPTForCausalLM"],["mbart","MBartForCausalLM"],["mistral","MistralForCausalLM"],["ministral","MinistralForCausalLM"],["ministral3","Ministral3ForCausalLM"],["ernie4_5","Ernie4_5_ForCausalLM"],["starcoder2","Starcoder2ForCausalLM"],["falcon","FalconForCausalLM"],["falcon_h1","FalconH1ForCausalLM"],["trocr","TrOCRForCausalLM"],["stablelm","StableLmForCausalLM"],["modernbert-decoder","ModernBertDecoderForCausalLM"],["hunyuan_v1_dense","HunYuanDenseV1ForCausalLM"],["youtu","YoutuForCausalLM"],["phi3_v","Phi3VForCausalLM"]]),zv=new Map([["multi_modality","MultiModalityCausalLM"]]),yy=new Map([["bert","BertForMaskedLM"],["neobert","NeoBertForMaskedLM"],["modernbert","ModernBertForMaskedLM"],["roformer","RoFormerForMaskedLM"],["electra","ElectraForMaskedLM"],["esm","EsmForMaskedLM"],["convbert","ConvBertForMaskedLM"],["camembert","CamembertForMaskedLM"],["deberta","DebertaForMaskedLM"],["deberta-v2","DebertaV2ForMaskedLM"],["mpnet","MPNetForMaskedLM"],["albert","AlbertForMaskedLM"],["distilbert","DistilBertForMaskedLM"],["roberta","RobertaForMaskedLM"],["xlm","XLMWithLMHeadModel"],["xlm-roberta","XLMRobertaForMaskedLM"],["mobilebert","MobileBertForMaskedLM"],["squeezebert","SqueezeBertForMaskedLM"]]),by=new Map([["bert","BertForQuestionAnswering"],["neobert","NeoBertForQuestionAnswering"],["roformer","RoFormerForQuestionAnswering"],["electra","ElectraForQuestionAnswering"],["convbert","ConvBertForQuestionAnswering"],["camembert","CamembertForQuestionAnswering"],["deberta","DebertaForQuestionAnswering"],["deberta-v2","DebertaV2ForQuestionAnswering"],["mpnet","MPNetForQuestionAnswering"],["albert","AlbertForQuestionAnswering"],["distilbert","DistilBertForQuestionAnswering"],["roberta","RobertaForQuestionAnswering"],["xlm","XLMForQuestionAnswering"],["xlm-roberta","XLMRobertaForQuestionAnswering"],["mobilebert","MobileBertForQuestionAnswering"],["squeezebert","SqueezeBertForQuestionAnswering"]]),ky=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"]]),vy=new Map([["llava","LlavaForConditionalGeneration"],["llava_onevision","LlavaOnevisionForConditionalGeneration"],["moondream1","Moondream1ForConditionalGeneration"],["florence2","Florence2ForConditionalGeneration"],["qwen2-vl","Qwen2VLForConditionalGeneration"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"],["paligemma","PaliGemmaForConditionalGeneration"],["llava_qwen2","LlavaQwen2ForCausalLM"],["gemma3n","Gemma3nForConditionalGeneration"],["mistral3","Mistral3ForConditionalGeneration"]]),Ey=new Map([["ultravox","UltravoxModel"],["voxtral","VoxtralForConditionalGeneration"]]),Tv=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"]]),Ay=new Map([["vit","ViTForImageClassification"],["ijepa","IJepaForImageClassification"],["pvt","PvtForImageClassification"],["vit_msn","ViTMSNForImageClassification"],["fastvit","FastViTForImageClassification"],["mobilevit","MobileViTForImageClassification"],["mobilevitv2","MobileViTV2ForImageClassification"],["beit","BeitForImageClassification"],["deit","DeiTForImageClassification"],["hiera","HieraForImageClassification"],["convnext","ConvNextForImageClassification"],["convnextv2","ConvNextV2ForImageClassification"],["dinov2","Dinov2ForImageClassification"],["dinov2_with_registers","Dinov2WithRegistersForImageClassification"],["resnet","ResNetForImageClassification"],["swin","SwinForImageClassification"],["segformer","SegformerForImageClassification"],["efficientnet","EfficientNetForImageClassification"],["mobilenet_v1","MobileNetV1ForImageClassification"],["mobilenet_v2","MobileNetV2ForImageClassification"],["mobilenet_v3","MobileNetV3ForImageClassification"],["mobilenet_v4","MobileNetV4ForImageClassification"]]),My=new Map([["detr","DetrForObjectDetection"],["rt_detr","RTDetrForObjectDetection"],["rt_detr_v2","RTDetrV2ForObjectDetection"],["rf_detr","RFDetrForObjectDetection"],["d_fine","DFineForObjectDetection"],["table-transformer","TableTransformerForObjectDetection"],["yolos","YolosForObjectDetection"]]),Sy=new Map([["owlvit","OwlViTForObjectDetection"],["owlv2","Owlv2ForObjectDetection"],["grounding-dino","GroundingDinoForObjectDetection"]]),Ys=new Map([["detr","DetrForSegmentation"],["clipseg","CLIPSegForImageSegmentation"]]),Oy=new Map([["segformer","SegformerForSemanticSegmentation"],["sapiens","SapiensForSemanticSegmentation"],["swin","SwinForSemanticSegmentation"],["mobilenet_v1","MobileNetV1ForSemanticSegmentation"],["mobilenet_v2","MobileNetV2ForSemanticSegmentation"],["mobilenet_v3","MobileNetV3ForSemanticSegmentation"],["mobilenet_v4","MobileNetV4ForSemanticSegmentation"]]),Iy=new Map([["detr","DetrForSegmentation"],["maskformer","MaskFormerForInstanceSegmentation"]]),zy=new Map([["sam","SamModel"],["sam2","Sam2Model"],["edgetam","EdgeTamModel"],["sam3_tracker","Sam3TrackerModel"]]),Ty=new Map([["wav2vec2","Wav2Vec2ForCTC"],["wav2vec2-bert","Wav2Vec2BertForCTC"],["unispeech","UniSpeechForCTC"],["unispeech-sat","UniSpeechSatForCTC"],["wavlm","WavLMForCTC"],["hubert","HubertForCTC"],["parakeet_ctc","ParakeetForCTC"]]),Py=new Map([["wav2vec2","Wav2Vec2ForSequenceClassification"],["wav2vec2-bert","Wav2Vec2BertForSequenceClassification"],["unispeech","UniSpeechForSequenceClassification"],["unispeech-sat","UniSpeechSatForSequenceClassification"],["wavlm","WavLMForSequenceClassification"],["hubert","HubertForSequenceClassification"],["audio-spectrogram-transformer","ASTForAudioClassification"]]),Cy=new Map([["wavlm","WavLMForXVector"]]),Ny=new Map([["unispeech-sat","UniSpeechSatForAudioFrameClassification"],["wavlm","WavLMForAudioFrameClassification"],["wav2vec2","Wav2Vec2ForAudioFrameClassification"],["pyannote","PyAnnoteForAudioFrameClassification"]]),Ly=new Map([["vitmatte","VitMatteForImageMatting"]]),Pv=new Map([["patchtst","PatchTSTForPrediction"],["patchtsmixer","PatchTSMixerForPrediction"]]),$y=new Map([["swin2sr","Swin2SRForImageSuperResolution"]]),Ry=new Map([["dpt","DPTForDepthEstimation"],["depth_anything","DepthAnythingForDepthEstimation"],["glpn","GLPNForDepthEstimation"],["sapiens","SapiensForDepthEstimation"],["depth_pro","DepthProForDepthEstimation"],["metric3d","Metric3DForDepthEstimation"],["metric3dv2","Metric3Dv2ForDepthEstimation"]]),Fy=new Map([["sapiens","SapiensForNormalEstimation"]]),Dy=new Map([["vitpose","VitPoseForPoseEstimation"]]),jy=new Map([["clip","CLIPVisionModelWithProjection"],["siglip","SiglipVisionModel"],["jina_clip","JinaCLIPVisionModel"]]),wg=[[Mv,C.EncoderOnly],[Sv,C.EncoderDecoder],[Iv,C.DecoderOnlyWithoutHead],[Ov,C.AutoEncoder],[hy,C.EncoderOnly],[xy,C.EncoderOnly],[gy,C.Seq2Seq],[_y,C.Seq2Seq],[wy,C.DecoderOnly],[zv,C.MultiModality],[yy,C.EncoderOnly],[by,C.EncoderOnly],[ky,C.Vision2Seq],[vy,C.ImageTextToText],[Ey,C.AudioTextToText],[Ay,C.EncoderOnly],[Ys,C.EncoderOnly],[Iy,C.EncoderOnly],[Oy,C.EncoderOnly],[Ly,C.EncoderOnly],[Pv,C.EncoderOnly],[$y,C.EncoderOnly],[Ry,C.EncoderOnly],[Fy,C.EncoderOnly],[Dy,C.EncoderOnly],[My,C.EncoderOnly],[Sy,C.EncoderOnly],[zy,C.MaskGeneration],[Ty,C.EncoderOnly],[Py,C.EncoderOnly],[fy,C.Seq2Seq],[my,C.EncoderOnly],[Cy,C.EncoderOnly],[Ny,C.EncoderOnly],[jy,C.EncoderOnly]];for(let[t,e]of wg)for(let s of t.values()){ss.set(s,e);let r=Io[s];ts.set(r,s),Vi.set(s,r)}var Cv=[["MusicgenForConditionalGeneration",qn,C.Musicgen],["Phi3VForCausalLM",so,C.Phi3V],["CLIPTextModelWithProjection",Rr,C.EncoderOnly],["SiglipTextModel",_o,C.EncoderOnly],["JinaCLIPTextModel",En,C.EncoderOnly],["ClapTextModelWithProjection",Lr,C.EncoderOnly],["ClapAudioModelWithProjection",$r,C.EncoderOnly],["DacEncoderModel",Vr,C.EncoderOnly],["DacDecoderModel",Hr,C.EncoderOnly],["MimiEncoderModel",Pn,C.EncoderOnly],["MimiDecoderModel",Cn,C.EncoderOnly],["SnacEncoderModel",mo,C.EncoderOnly],["SnacDecoderModel",ho,C.EncoderOnly],["Gemma3nForConditionalGeneration",ln,C.ImageAudioTextToText],["SupertonicForConditionalGeneration",wo,C.Supertonic],["ChatterboxModel",Nr,C.Chatterbox]];for(let[t,e,s]of Cv)ss.set(t,s),ts.set(e,t),Vi.set(t,e);var yg=new Map([["modnet",Ys],["birefnet",Ys],["isnet",Ys],["ben",Ys]]);for(let[t,e]of yg.entries())e.set(t,"PreTrainedModel"),ss.set(t,C.EncoderOnly),Vi.set(t,f);ss.set("PreTrainedModel",C.EncoderOnly);ts.set(f,"PreTrainedModel");var le={MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES:hy,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES:xy,MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES:fy,MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES:my,MODEL_FOR_MASKED_LM_MAPPING_NAMES:yy,MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES:by,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES:Ay,MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES:Ys,MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES:Oy,MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES:Iy,MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES:My,MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES:Sy,MODEL_FOR_MASK_GENERATION_MAPPING_NAMES:zy,MODEL_FOR_CTC_MAPPING_NAMES:Ty,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES:Py,MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES:Cy,MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES:Ny,MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES:Tv,MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES:Ly,MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES:$y,MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES:Ry,MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES:Fy,MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES:Dy,MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES:jy,MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES:vy,MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES:Ey,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES:gy,MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES:_y,MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:wy,MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES:ky};cy(le);var ae=class{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main",model_file_name:a=null,subfolder:l="onnx",device:c=null,dtype:u=null,use_external_data_format:p=null,session_options:d={}}={}){let _={progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:u,use_external_data_format:p,session_options:d};if(_.config=await Yt.from_pretrained(e,_),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);let m=_.config.model_type;for(let h of this.MODEL_CLASS_MAPPINGS){let x=h.get(m);if(!x){for(let g of h.values())if(g[0]===m){x=g;break}if(!x)continue}return await Io[x].from_pretrained(e,_)}if(this.BASE_IF_FAIL)return yg.has(m)||console.warn(`Unknown model class "${m}", attempting to construct from base class.`),await f.from_pretrained(e,_);throw Error(`Unsupported model type: ${m}`)}},kt=class extends ae{static MODEL_CLASS_MAPPINGS=wg.map(e=>e[0]);static BASE_IF_FAIL=!0},zo=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]},Ha=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]},Zs=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]},Xa=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]},Ka=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]},Qa=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]},Ja=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES]},Ya=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_MASKED_LM_MAPPING_NAMES]},Za=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]},el=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]},tl=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]},To=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]},Po=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]},Co=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES]},sl=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]},rl=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]},By=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]},nl=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_CTC_MAPPING_NAMES]},ol=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]},Uy=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]},qy=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]},il=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]},Gy=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]},al=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]},ll=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]},Wy=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES]},Vy=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES]},cl=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]},Hy=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES]},Xy=class extends ae{static MODEL_CLASS_MAPPINGS=[le.MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES]};async function be(t){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(e=>we.read(e)))}async function Ut(t,e){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(s=>typeof s=="string"||s instanceof URL?Jc(s,e):s instanceof Float64Array?new Float32Array(s):s))}function No(t,e){e&&(t=t.map(i=>i|0));let[s,r,n,o]=t;return{xmin:s,ymin:r,xmax:n,ymax:o}}var W=class extends ke{constructor({task:e,model:s,tokenizer:r=null,processor:n=null}){super(),this.task=e,this.model=s,this.tokenizer=r,this.processor=n}async dispose(){await this.model.dispose()}};var ul=class extends W{async _call(e,{top_k:s=1}={}){let r=this.tokenizer(e,{padding:!0,truncation:!0}),n=await this.model(r),{problem_type:o,id2label:i}=this.model.config,a=o==="multi_label_classification"?c=>c.sigmoid():c=>new S("float32",ce(c.data),c.dims),l=[];for(let c of n.logits){let u=a(c),p=await ot(u,s),d=p[0].tolist(),m=p[1].tolist().map((h,x)=>({label:i?i[h]:`LABEL_${h}`,score:d[x]}));s===1?l.push(...m):l.push(m)}return Array.isArray(e)||s===1?l:l[0]}};var pl=class extends W{async _call(e,{ignore_labels:s=["O"]}={}){let r=Array.isArray(e),n=this.tokenizer(r?e:[e],{padding:!0,truncation:!0}),i=(await this.model(n)).logits,a=this.model.config.id2label,l=[];for(let c=0;c<i.dims[0];++c){let u=n.input_ids[c],p=i[c],d=[];for(let _=0;_<p.dims[0];++_){let m=p[_],h=ie(m.data)[1],x=a?a[h]:`LABEL_${h}`;if(s.includes(x))continue;let g=this.tokenizer.decode([u[_].item()],{skip_special_tokens:!0});if(g==="")continue;let w=ce(m.data);d.push({entity:x,score:w[h],index:_,word:g})}l.push(d)}return r?l:l[0]}};var dl=class extends W{async _call(e,s,{top_k:r=1}={}){let n=this.tokenizer(e,{text_pair:s,padding:!0,truncation:!0}),o=Array.isArray(e),{start_logits:i,end_logits:a}=await this.model(n),l=n.input_ids.tolist(),c=n.attention_mask.tolist(),{all_special_ids:u,sep_token_id:p}=this.tokenizer,d=[];for(let _=0;_<i.dims[0];++_){let m=l[_],h=m.findIndex(b=>b==p),x=i[_].tolist(),g=a[_].tolist();for(let b=1;b<x.length;++b)(c[_]==0||b<=h||u.findIndex(O=>O==m[b])!==-1)&&(x[b]=-1/0,g[b]=-1/0);let w=ce(x).map((b,O)=>[b,O]),y=ce(g).map((b,O)=>[b,O]);w[0][0]=0,y[0][0]=0;let E=iw(w,y).filter(b=>b[0][1]<=b[1][1]).map(b=>[b[0][1],b[1][1],b[0][0]*b[1][0]]).sort((b,O)=>O[2]-b[2]),A=[];for(let b=0;b<Math.min(E.length,r);++b){let[O,N,F]=E[b],R=m.slice(O,N+1),B=this.tokenizer.decode(R,{skip_special_tokens:!0});A.push({answer:B,score:F})}r===1?d.push(...A):d.push(A)}return o?d:d[0]}};var _l=class extends W{async _call(e,{top_k:s=5}={}){let{mask_token_id:r,mask_token:n}=this.tokenizer,o=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:i}=await this.model(o),a=[],l=o.input_ids.tolist();for(let c=0;c<l.length;++c){let u=l[c],p=u.findIndex(x=>x==r);if(p===-1)throw Error(`Mask token (${n}) not found in text.`);let d=i[c][p],_=await ot(new S("float32",ce(d.data),d.dims),s),m=_[0].tolist(),h=_[1].tolist();a.push(h.map((x,g)=>{let w=u.slice();return w[p]=x,{score:m[g],token:Number(x),token_str:this.tokenizer.decode([x]),sequence:this.tokenizer.decode(w,{skip_special_tokens:!0})}}))}return Array.isArray(e)?a:a[0]}};var qt=class extends W{_key="generated_text";async _call(e,s={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map(l=>this.model.config.prefix+l));let r=this.model.config.task_specific_params;r&&r[this.task]&&r[this.task].prefix&&(e=e.map(l=>r[this.task].prefix+l));let n=this.tokenizer,o={padding:!0,truncation:!0},i;this.task==="translation"&&"_build_translation_inputs"in n?i=n._build_translation_inputs(e,o,s):i=n(e,o);let a=await this.model.generate({...i,...s});return n.batch_decode(a,{skip_special_tokens:!0}).map(l=>({[this._key]:l}))}};var fl=class extends qt{_key="summary_text"};var ml=class extends qt{_key="translation_text"};function Ky(t){return Array.isArray(t)&&t.every(e=>"role"in e&&"content"in e)}var hl=class extends W{async _call(e,s={}){let r=!1,n=!1,o=s.add_special_tokens??(this.tokenizer.add_bos_token||this.tokenizer.add_eos_token)??!1,i=s.tokenizer_encode_kwargs,a;if(typeof e=="string")a=e=[e];else if(Array.isArray(e)&&e.every(m=>typeof m=="string"))r=!0,a=e;else{if(Ky(e))e=[e];else if(Array.isArray(e)&&e.every(Ky))r=!0;else throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");n=!0,a=e.map(m=>this.tokenizer.apply_chat_template(m,{tokenize:!1,add_generation_prompt:!0,...i})),o=!1,i=void 0}let l=n?!1:s.return_full_text??!0;this.tokenizer.padding_side="left";let c=this.tokenizer(a,{add_special_tokens:o,padding:!0,truncation:!0,...i}),u=await this.model.generate({...c,...s}),p=this.tokenizer.batch_decode(u,{skip_special_tokens:!0}),d;!l&&c.input_ids.dims.at(-1)>0&&(d=this.tokenizer.batch_decode(c.input_ids,{skip_special_tokens:!0}).map(m=>m.length));let _=Array.from({length:e.length},m=>[]);for(let m=0;m<p.length;++m){let h=Math.floor(m/u.dims[0]*e.length);d&&(p[m]=p[m].slice(d[h])),_[h].push({generated_text:n?[...e[h],{role:"assistant",content:p[m]}]:p[m]})}return!r&&_.length===1?_[0]:_}};var xl=class extends W{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([s,r])=>[s.toLowerCase(),r])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,this.contradiction_id===void 0&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,s,{hypothesis_template:r="This example is {}.",multi_label:n=!1}={}){let o=Array.isArray(e);o||(e=[e]),Array.isArray(s)||(s=[s]);let i=s.map(c=>r.replace("{}",c)),a=n||s.length===1,l=[];for(let c of e){let u=[];for(let _ of i){let m=this.tokenizer(c,{text_pair:_,padding:!0,truncation:!0}),h=await this.model(m);a?u.push([h.logits.data[this.contradiction_id],h.logits.data[this.entailment_id]]):u.push(h.logits.data[this.entailment_id])}let d=(a?u.map(_=>ce(_)[1]):ce(u)).map((_,m)=>[_,m]).sort((_,m)=>m[0]-_[0]);l.push({sequence:c,labels:d.map(_=>s[_[1]]),scores:d.map(_=>_[0])})}return o?l:l[0]}};var gl=class extends W{async _call(e,{top_k:s=5}={}){let r=this.processor.feature_extractor.config.sampling_rate,n=await Ut(e,r),o=this.model.config.id2label,i=[];for(let a of n){let l=await this.processor(a),u=(await this.model(l)).logits[0],p=await ot(new S("float32",ce(u.data),u.dims),s),d=p[0].tolist(),m=p[1].tolist().map((h,x)=>({label:o?o[h]:`LABEL_${h}`,score:d[x]}));i.push(m)}return Array.isArray(e)?i:i[0]}};var wl=class extends W{async _call(e,s,{hypothesis_template:r="This is a sound of {}."}={}){let n=!Array.isArray(e);n&&(e=[e]);let o=s.map(u=>r.replace("{}",u)),i=this.tokenizer(o,{padding:!0,truncation:!0}),a=this.processor.feature_extractor.config.sampling_rate,l=await Ut(e,a),c=[];for(let u of l){let p=await this.processor(u),d=await this.model({...i,...p}),_=ce(d.logits_per_audio.data);c.push([..._].map((m,h)=>({score:m,label:s[h]})))}return n?c[0]:c}};var yl=class extends W{async _call(e,s={}){switch(this.model.config.model_type){case"whisper":case"lite-whisper":return this._call_whisper(e,s);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":case"parakeet_ctc":return this._call_wav2vec2(e,s);case"moonshine":return this._call_moonshine(e,s);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,s){s.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),s.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');let r=!Array.isArray(e),n=r?[e]:e,o=this.processor.feature_extractor.config.sampling_rate,i=await Ut(n,o),a=[];for(let l of i){let c=await this.processor(l),p=(await this.model(c)).logits[0],d=[];for(let m of p)d.push(ie(m.data)[1]);let _=this.tokenizer.decode(d,{skip_special_tokens:!0}).trim();a.push({text:_})}return r?a[0]:a}async _call_whisper(e,s){let r=s.return_timestamps??!1,n=s.chunk_length_s??0,o=s.force_full_sequences??!1,i=s.stride_length_s??null,a={...s};r==="word"&&(a.return_token_timestamps=!0,a.return_timestamps=!1);let l=!Array.isArray(e),c=l?[e]:e,u=this.processor.feature_extractor.config,p=u.chunk_length/this.model.config.max_source_positions,d=u.hop_length,_=u.sampling_rate,m=await Ut(c,_),h=[];for(let x of m){let g=[];if(n>0){if(i===null)i=n/6;else if(n<=i)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");let E=_*n,A=_*i,b=E-2*A,O=0;for(;;){let N=O+E,F=x.subarray(O,N),R=await this.processor(F),B=O===0,G=N>=x.length;if(g.push({stride:[F.length,B?0:A,G?0:A],input_features:R.input_features,is_last:G}),G)break;O+=b}}else g=[{stride:[x.length,0,0],input_features:(await this.processor(x)).input_features,is_last:!0}];for(let E of g){a.num_frames=Math.floor(E.stride[0]/d);let A=await this.model.generate({inputs:E.input_features,...a});r==="word"?(E.tokens=A.sequences.tolist()[0],E.token_timestamps=A.token_timestamps.tolist()[0].map(b=>Kt(b,2))):E.tokens=A[0].tolist(),E.stride=E.stride.map(b=>b/_)}let[w,y]=this.tokenizer._decode_asr(g,{time_precision:p,return_timestamps:r,force_full_sequences:o});h.push({text:w,...y})}return l?h[0]:h}async _call_moonshine(e,s){let r=!Array.isArray(e),n=r?[e]:e,o=this.processor.feature_extractor.config.sampling_rate,i=await Ut(n,o),a=[];for(let l of i){let c=await this.processor(l),u=Math.floor(l.length/o)*6,p=await this.model.generate({max_new_tokens:u,...s,...c}),d=this.processor.batch_decode(p,{skip_special_tokens:!0})[0];a.push({text:d})}return r?a[0]:a}};var bl=class extends W{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(e){super(e),this.vocoder=e.vocoder??null}async _prepare_speaker_embeddings(e,s){if((typeof e=="string"||e instanceof URL)&&(e=new Float32Array(await(await fetch(e)).arrayBuffer())),e instanceof Float32Array)e=new S("float32",e,[e.length]);else if(!(e instanceof S))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");if(s>1){if(e.dims[0]===1)e=e.repeat(s,1);else if(e.dims[0]!==s)throw new Error(`Expected speaker embeddings batch size to be 1 or ${s}, but got ${e.dims[0]}.`)}return e}_postprocess_waveform(e,s,r,n=null){let o=s.data,[i,a]=s.dims,l=n?n.data:null,c=[];for(let u=0;u<i;++u){let p=l?Math.min(Math.ceil(l[u]),a):a,d=u*a;c.push(new hr(o.slice(d,d+p),r))}return Array.isArray(e)?c:c[0]}async _call(e,s){return this.processor?this._call_text_to_spectrogram(e,s):this.model.config.model_type==="supertonic"?this._call_supertonic(e,s):this._call_text_to_waveform(e)}async _call_supertonic(e,{speaker_embeddings:s,num_inference_steps:r,speed:n}){if(!s)throw new Error("Speaker embeddings must be provided for Supertonic models.");let{sampling_rate:o,style_dim:i}=this.model.config,a=this.tokenizer(e,{padding:!0,truncation:!0}),l=a.input_ids.dims[0];s=await this._prepare_speaker_embeddings(s,l),s=s.view(l,-1,i);let{waveform:c,durations:u}=await this.model.generate_speech({...a,style:s,num_inference_steps:r,speed:n});return this._postprocess_waveform(e,c,o,u)}async _call_text_to_waveform(e){let s=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:r}=await this.model(s),n=this.model.config.sampling_rate;return this._postprocess_waveform(e,r,n)}async _call_text_to_spectrogram(e,{speaker_embeddings:s}){this.vocoder||(console.log("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await kt.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"}));let{input_ids:r}=this.tokenizer(e,{padding:!0,truncation:!0}),n=r.dims[0];s=await this._prepare_speaker_embeddings(s,n),s=s.view(n,-1);let{waveform:o}=await this.model.generate_speech(r,s,{vocoder:this.vocoder}),i=this.processor.feature_extractor.config.sampling_rate;return this._postprocess_waveform(e,o,i)}};var kl=class extends W{async _call(e,s={}){let r=Array.isArray(e),n=await be(e),{pixel_values:o}=await this.processor(n),i=[];for(let a of o){a.dims=[1,...a.dims];let l=await this.model.generate({inputs:a,...s}),c=this.tokenizer.batch_decode(l,{skip_special_tokens:!0}).map(u=>({generated_text:u.trim()}));i.push(c)}return r?i:i[0]}};var vl=class extends W{async _call(e,{top_k:s=5}={}){let r=await be(e),{pixel_values:n}=await this.processor(r),o=await this.model({pixel_values:n}),{id2label:i}=this.model.config,a=[];for(let l of o.logits){let c=await ot(new S("float32",ce(l.data),l.dims),s),u=c[0].tolist(),d=c[1].tolist().map((_,m)=>({label:i?i[_]:`LABEL_${_}`,score:u[m]}));a.push(d)}return Array.isArray(e)?a:a[0]}};var Qy={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"},er=class extends W{async _call(e,{threshold:s=.5,mask_threshold:r=.5,overlap_mask_area_threshold:n=.8,label_ids_to_fuse:o=null,target_sizes:i=null,subtask:a=null}={}){if(Array.isArray(e)&&e.length!==1)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");let c=await be(e),u=c.map(w=>[w.height,w.width]),p=await this.processor(c),{inputNames:d,outputNames:_}=this.model.sessions.model;if(!d.includes("pixel_values")){if(d.length!==1)throw Error(`Expected a single input name, but got ${d.length} inputs: ${d}.`);let w=d[0];if(w in p)throw Error(`Input name ${w} already exists in the inputs.`);p[w]=p.pixel_values}let m=await this.model(p),h=null;if(a!==null)h=Qy[a];else if(this.processor.image_processor){for(let[w,y]of Object.entries(Qy))if(y in this.processor.image_processor){h=this.processor.image_processor[y].bind(this.processor.image_processor),a=w;break}}let x=this.model.config.id2label,g=[];if(a)if(a==="panoptic"||a==="instance"){let w=h(m,s,r,n,o,i??u)[0],y=w.segmentation;for(let E of w.segments_info){let A=new Uint8ClampedArray(y.data.length);for(let O=0;O<y.data.length;++O)y.data[O]===E.id&&(A[O]=255);let b=new we(A,y.dims[1],y.dims[0],1);g.push({score:E.score,label:x[E.label_id],mask:b})}}else if(a==="semantic"){let{segmentation:w,labels:y}=h(m,i??u)[0];for(let E of y){let A=new Uint8ClampedArray(w.data.length);for(let O=0;O<w.data.length;++O)w.data[O]===E&&(A[O]=255);let b=new we(A,w.dims[1],w.dims[0],1);g.push({score:null,label:x[E],mask:b})}}else throw Error(`Subtask ${a} not supported.`);else{let y=m[_[0]];for(let E=0;E<u.length;++E){let A=u[E],b=y[E];b.data.some(N=>N<-1e-5||N>1+1e-5)&&b.sigmoid_();let O=await we.fromTensor(b.mul_(255).to("uint8")).resize(A[1],A[0]);g.push({label:null,score:null,mask:O})}}return g}};var El=class extends er{async _call(e,s={}){let r=await be(e),n=await super._call(e,s),o=r.map((i,a)=>{let l=i.clone();return l.putAlpha(n[a].mask),l});return Array.isArray(e)?o:o[0]}};var Al=class extends W{async _call(e,s,{hypothesis_template:r="This is a photo of {}"}={}){let n=Array.isArray(e),o=await be(e),i=s.map(d=>r.replace("{}",d)),a=this.tokenizer(i,{padding:this.model.config.model_type==="siglip"?"max_length":!0,truncation:!0}),{pixel_values:l}=await this.processor(o),c=await this.model({...a,pixel_values:l}),u=this.model.config.model_type==="siglip"?d=>d.sigmoid().data:d=>ce(d.data),p=[];for(let d of c.logits_per_image){let m=[...u(d)].map((h,x)=>({score:h,label:s[x]}));m.sort((h,x)=>x.score-h.score),p.push(m)}return n?p:p[0]}};var Ml=class extends W{async _call(e,{threshold:s=.9,percentage:r=!1}={}){let n=Array.isArray(e);if(n&&e.length!==1)throw Error("Object detection pipeline currently only supports a batch size of 1.");let o=await be(e),i=r?null:o.map(_=>[_.height,_.width]),{pixel_values:a,pixel_mask:l}=await this.processor(o),c=await this.model({pixel_values:a,pixel_mask:l}),u=this.processor.image_processor.post_process_object_detection(c,s,i),{id2label:p}=this.model.config,d=u.map(_=>_.boxes.map((m,h)=>({score:_.scores[h],label:p[_.classes[h]],box:No(m,!r)})));return n?d:d[0]}};var Sl=class extends W{async _call(e,s,{threshold:r=.1,top_k:n=null,percentage:o=!1}={}){let i=Array.isArray(e),a=await be(e),l=this.tokenizer(s,{padding:!0,truncation:!0}),c=await this.processor(a),u=[];for(let p=0;p<a.length;++p){let d=a[p],_=o?null:[[d.height,d.width]],m=c.pixel_values[p].unsqueeze_(0),h=await this.model({...l,pixel_values:m}),x;if("post_process_grounded_object_detection"in this.processor){let g=this.processor.post_process_grounded_object_detection(h,l.input_ids,{box_threshold:r,text_threshold:r,target_sizes:_})[0];x=g.boxes.map((w,y)=>({score:g.scores[y],label:g.labels[y],box:No(w,!o)}))}else{let g=this.processor.image_processor.post_process_object_detection(h,r,_,!0)[0];x=g.boxes.map((w,y)=>({score:g.scores[y],label:s[g.classes[y]],box:No(w,!o)}))}x.sort((g,w)=>w.score-g.score),n!==null&&(x=x.slice(0,n)),u.push(x)}return i?u:u[0]}};var Ol=class extends W{async _call(e,s,r={}){if(Array.isArray(e)){if(e.length!==1)throw Error("Document Question Answering pipeline currently only supports a batch size of 1.");e=e[0]}let n=(await be(e))[0],{pixel_values:o}=await this.processor(n),i=`<s_docvqa><s_question>${s}</s_question><s_answer>`,a=this.tokenizer(i,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,l=await this.model.generate({inputs:o,max_length:this.model.config.decoder.max_position_embeddings,decoder_input_ids:a,...r}),u=this.tokenizer.batch_decode(l)[0].match(/<s_answer>(.*?)<\/s_answer>/),p=null;return u&&u.length>=2&&(p=u[1].trim()),[{answer:p}]}};var Il=class extends W{async _call(e){let s=await be(e),r=await this.processor(s),n=await this.model(r),o=[];for(let i of n.reconstruction){let a=i.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");o.push(we.fromTensor(a))}return Array.isArray(e)?o:o[0]}};var zl=class extends W{async _call(e){let s=await be(e),r=await this.processor(s),{predicted_depth:n}=await this.model(r),o=[];for(let i=0;i<s.length;++i){let a=n[i],[l,c]=a.dims.slice(-2),[u,p]=s[i].size,d=(await Xe(a.view(1,1,l,c),{size:[p,u],mode:"bilinear"})).view(p,u),_=d.min().item(),m=d.max().item(),h=d.sub(_).div_(m-_).mul_(255).to("uint8").unsqueeze(0),x=we.fromTensor(h);o.push({predicted_depth:d,depth:x})}return Array.isArray(e)?o:o[0]}};var Tl=class extends W{async _call(e,{pooling:s="none",normalize:r=!1,quantize:n=!1,precision:o="binary"}={}){let i=this.tokenizer(e,{padding:!0,truncation:!0}),a=await this.model(i),l=a.last_hidden_state??a.logits??a.token_embeddings;switch(s){case"none":break;case"mean":l=Fw(l,i.attention_mask);break;case"first_token":case"cls":l=l.slice(null,0);break;case"last_token":case"eos":l=l.slice(null,-1);break;default:throw Error(`Pooling method '${s}' not supported.`)}return r&&(l=l.normalize(2,-1)),n&&(l=jw(l,o)),l}};var Pl=class extends W{async _call(e,{pool:s=null}={}){let r=await be(e),{pixel_values:n}=await this.processor(r),o=await this.model({pixel_values:n}),i;if(s){if(!("pooler_output"in o))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");i=o.pooler_output}else i=o.last_hidden_state??o.logits??o.image_embeds;return i}};var Jy=Object.freeze({"text-classification":{tokenizer:L,pipeline:ul,model:zo,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:L,pipeline:pl,model:Ha,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:L,pipeline:dl,model:Za,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:L,pipeline:_l,model:Ya,default:{model:"onnx-community/ettin-encoder-32m-ONNX",dtype:"fp32"},type:"text"},summarization:{tokenizer:L,pipeline:fl,model:Zs,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:L,pipeline:ml,model:Zs,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:L,pipeline:qt,model:Zs,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:L,pipeline:hl,model:Ja,default:{model:"onnx-community/Qwen3-0.6B-ONNX",dtype:"q4"},type:"text"},"zero-shot-classification":{tokenizer:L,pipeline:xl,model:zo,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:gl,model:ol,processor:ze,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:L,pipeline:wl,model:kt,processor:ze,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:L,pipeline:yl,model:[Xa,nl],processor:ze,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:L,pipeline:bl,model:[Qa,Ka],processor:[ze,null],default:{model:"onnx-community/Supertonic-TTS-ONNX",dtype:"fp32"},type:"text"},"image-to-text":{tokenizer:L,pipeline:kl,model:el,processor:ze,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:vl,model:tl,processor:ze,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:er,model:[To,Po,Co],processor:ze,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:El,model:[To,Po,Co],processor:ze,default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{tokenizer:L,pipeline:Al,model:kt,processor:ze,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:Ml,model:sl,processor:ze,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:L,pipeline:Sl,model:rl,processor:ze,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:L,pipeline:Ol,model:il,processor:ze,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:Il,model:al,processor:ze,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:zl,model:ll,processor:ze,default:{model:"onnx-community/depth-anything-v2-small"},type:"image"},"feature-extraction":{tokenizer:L,pipeline:Tl,model:kt,default:{model:"onnx-community/all-MiniLM-L6-v2-ONNX",dtype:"fp32"},type:"text"},"image-feature-extraction":{processor:ze,pipeline:Pl,model:[cl,kt],default:{model:"onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX",dtype:"fp32"},type:"image"}}),Nv=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function c9(t,e=null,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main",device:a=null,dtype:l=null,subfolder:c="onnx",use_external_data_format:u=null,model_file_name:p=null,session_options:d={}}={}){t=Nv[t]??t;let _=Jy[t.split("_",1)[0]];if(!_)throw Error(`Unsupported pipeline: ${t}. Must be one of [${Object.keys(Jy)}]`);e||(e=_.default.model,console.log(`No model specified. Using default model: "${e}".`),!l&&_.default.dtype&&(l=_.default.dtype));let m={progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i,device:a,dtype:l,subfolder:c,use_external_data_format:u,model_file_name:p,session_options:d},h=new Map([["tokenizer",_.tokenizer],["model",_.model],["processor",_.processor]]),x=await Lv(h,e,m);x.task=t,yt(s,{status:"ready",task:t,model:e});let g=_.pipeline;return new g(x)}async function Lv(t,e,s){let r=Object.create(null),n=[];for(let[o,i]of t.entries()){if(!i)continue;let a;Array.isArray(i)?a=new Promise(async(l,c)=>{let u;for(let p of i){if(p===null){l(null);return}try{l(await p.from_pretrained(e,s));return}catch(d){if(d.message?.includes("Unsupported model type"))u=d;else if(d.message?.includes("Could not locate file"))u=d;else{c(d);return}}}c(u)}):a=i.from_pretrained(e,s),r[o]=a,n.push(a)}await Promise.all(n);for(let[o,i]of Object.entries(r))r[o]=await i;return r}var $v=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,bg=class{put(e){throw Error("Not implemented")}end(){throw Error("Not implemented")}},Yy=ee.IS_PROCESS_AVAILABLE?t=>process.stdout.write(t):t=>console.log(t),kg=class extends bg{constructor(e,{skip_prompt:s=!1,callback_function:r=null,token_callback_function:n=null,skip_special_tokens:o=!0,decode_kwargs:i={},...a}={}){super(),this.tokenizer=e,this.skip_prompt=s,this.callback_function=r??Yy,this.token_callback_function=n,this.decode_kwargs={skip_special_tokens:o,...i,...a},this.token_cache=[],this.print_len=0,this.next_tokens_are_prompt=!0,this.special_ids=new Set(this.tokenizer.all_special_ids.map(BigInt))}put(e){if(e.length>1)throw Error("TextStreamer only supports batch size of 1");let s=this.next_tokens_are_prompt;if(s&&(this.next_tokens_are_prompt=!1,this.skip_prompt))return;let r=e[0];if(this.token_callback_function?.(r),r.length===1&&this.special_ids.has(r[0])){if(this.decode_kwargs.skip_special_tokens)return;if(this.token_cache.length>0){let l=this.tokenizer.decode(this.token_cache,this.decode_kwargs).slice(this.print_len);this.on_finalized_text(l,!1),this.token_cache=[],this.print_len=0}let i=this.tokenizer.decode(r,this.decode_kwargs);this.on_finalized_text(i,!1);return}this.token_cache=Pe(this.token_cache,r);let n=this.tokenizer.decode(this.token_cache,this.decode_kwargs),o;s||n.endsWith(`
23
- `)?(o=n.slice(this.print_len),this.token_cache=[],this.print_len=0):n.length>0&&$v(n.charCodeAt(n.length-1))?(o=n.slice(this.print_len),this.print_len+=o.length):(o=n.slice(this.print_len,n.lastIndexOf(" ")+1),this.print_len+=o.length),this.on_finalized_text(o,!1)}end(){let e;this.token_cache.length>0?(e=this.tokenizer.decode(this.token_cache,this.decode_kwargs).slice(this.print_len),this.token_cache=[],this.print_len=0):e="",this.next_tokens_are_prompt=!0,this.on_finalized_text(e,!0)}on_finalized_text(e,s){e.length>0&&this.callback_function?.(e),s&&this.callback_function===Yy&&ee.IS_PROCESS_AVAILABLE&&this.callback_function?.(`
24
- `)}},Zy=class extends kg{constructor(e,{skip_prompt:s=!1,callback_function:r=null,token_callback_function:n=null,on_chunk_start:o=null,on_chunk_end:i=null,on_finalize:a=null,time_precision:l=.02,skip_special_tokens:c=!0,decode_kwargs:u={}}={}){super(e,{skip_prompt:s,skip_special_tokens:c,callback_function:r,token_callback_function:n,decode_kwargs:u}),this.timestamp_begin=e.timestamp_begin,this.on_chunk_start=o,this.on_chunk_end=i,this.on_finalize=a,this.time_precision=l,this.waiting_for_timestamp=!1}put(e){if(e.length>1)throw Error("WhisperTextStreamer only supports batch size of 1");let s=e[0];if(s.length===1){let r=Number(s[0])-this.timestamp_begin;if(r>=0){let n=r*this.time_precision;this.waiting_for_timestamp?this.on_chunk_end?.(n):this.on_chunk_start?.(n),this.waiting_for_timestamp=!this.waiting_for_timestamp,this.token_callback_function?.(s);return}}return super.put(e)}end(){super.end(),this.on_finalize?.()}};var Lo=class{constructor(e,s){this.image=e,this.timestamp=s}},Cl=class{constructor(e,s){e.length>0&&e[0]instanceof we&&(e=e.map((r,n)=>new Lo(r,(n+1)/(e.length+1)*s))),this.frames=e,this.duration=s}get width(){return this.frames[0].image.width}get height(){return this.frames[0].image.height}get fps(){return this.frames.length/this.duration}};async function Rv(t,{num_frames:e=null,fps:s=null}={}){if(!ee.IS_BROWSER_ENV)throw new Error("`load_video` is currently only supported in browser environments.");if(e==null&&s==null)throw new Error("Either num_frames or fps must be provided.");let r=[],n=document.createElement("video");if(n.crossOrigin="anonymous",n.muted=!0,typeof t=="string")n.src=t;else if(t instanceof Blob)n.src=URL.createObjectURL(t);else if(t instanceof HTMLVideoElement)n.src=t.src;else throw new Error("Invalid URL or video element provided.");if(await new Promise(p=>n.onloadedmetadata=p),n.seekable.start(0)===n.seekable.end(0)){let d=await(await fetch(n.src)).blob();n.src=URL.createObjectURL(d),await new Promise(_=>n.onloadedmetadata=_)}let o=n.duration,i,a;e!=null?(i=e,a=e===1?0:o/(e-1)):(a=1/s,i=Math.floor(o/a));let l=[];for(let p=0;p<i;++p)l.push(e===1?o/2:p*a);let c=document.createElement("canvas");c.width=n.videoWidth,c.height=n.videoHeight;let u=c.getContext("2d",{willReadFrequently:!0});for(let p of l){n.currentTime=p,await new Promise(h=>{n.onseeked=h}),u.drawImage(n,0,0,c.width,c.height);let d=u.getImageData(0,0,c.width,c.height),_=new we(d.data,c.width,c.height,4),m=new Lo(_,p);r.push(m)}return n.remove(),new Cl(r,o)}export{Yc as ASTFeatureExtractor,$p as ASTForAudioClassification,Lp as ASTModel,Ir as ASTPreTrainedModel,zp as AlbertForMaskedLM,Ip as AlbertForQuestionAnswering,Op as AlbertForSequenceClassification,Sp as AlbertModel,rs as AlbertPreTrainedModel,oc as AlbertTokenizer,Pp as ApertusForCausalLM,Tp as ApertusModel,Sr as ApertusPreTrainedModel,Np as ArceeForCausalLM,Cp as ArceeModel,Or as ArceePreTrainedModel,gl as AudioClassificationPipeline,Yt as AutoConfig,ve as AutoFeatureExtractor,de as AutoImageProcessor,kt as AutoModel,ol as AutoModelForAudioClassification,qy as AutoModelForAudioFrameClassification,Xy as AutoModelForAudioTextToText,nl as AutoModelForCTC,Ja as AutoModelForCausalLM,ll as AutoModelForDepthEstimation,il as AutoModelForDocumentQuestionAnswering,tl as AutoModelForImageClassification,cl as AutoModelForImageFeatureExtraction,Gy as AutoModelForImageMatting,To as AutoModelForImageSegmentation,Hy as AutoModelForImageTextToText,al as AutoModelForImageToImage,By as AutoModelForMaskGeneration,Ya as AutoModelForMaskedLM,Wy as AutoModelForNormalEstimation,sl as AutoModelForObjectDetection,Vy as AutoModelForPoseEstimation,Za as AutoModelForQuestionAnswering,Po as AutoModelForSemanticSegmentation,Zs as AutoModelForSeq2SeqLM,zo as AutoModelForSequenceClassification,Xa as AutoModelForSpeechSeq2Seq,Ka as AutoModelForTextToSpectrogram,Qa as AutoModelForTextToWaveform,Ha as AutoModelForTokenClassification,Co as AutoModelForUniversalSegmentation,el as AutoModelForVision2Seq,Uy as AutoModelForXVector,rl as AutoModelForZeroShotObjectDetection,ze as AutoProcessor,L as AutoTokenizer,yl as AutomaticSpeechRecognitionPipeline,El as BackgroundRemovalPipeline,Fp as BartForConditionalGeneration,Dp as BartForSequenceClassification,Rp as BartModel,Cs as BartPretrainedModel,ic as BartTokenizer,bg as BaseStreamer,_u as BeitFeatureExtractor,Bp as BeitForImageClassification,jp as BeitModel,zr as BeitPreTrainedModel,qp as BertForMaskedLM,Vp as BertForQuestionAnswering,Gp as BertForSequenceClassification,Wp as BertForTokenClassification,Up as BertModel,Ot as BertPreTrainedModel,ac as BertTokenizer,fu as BitImageProcessor,Xp as BlenderbotForConditionalGeneration,Hp as BlenderbotModel,Tr as BlenderbotPreTrainedModel,Qp as BlenderbotSmallForConditionalGeneration,Kp as BlenderbotSmallModel,Pr as BlenderbotSmallPreTrainedModel,lc as BlenderbotSmallTokenizer,cc as BlenderbotTokenizer,Yp as BloomForCausalLM,Jp as BloomModel,Cr as BloomPreTrainedModel,uc as BloomTokenizer,hu as CLIPFeatureExtractor,ci as CLIPImageProcessor,id as CLIPModel,ft as CLIPPreTrainedModel,pd as CLIPSegForImageSegmentation,ud as CLIPSegModel,Fr as CLIPSegPreTrainedModel,ad as CLIPTextModel,Rr as CLIPTextModelWithProjection,dc as CLIPTokenizer,ld as CLIPVisionModel,cd as CLIPVisionModelWithProjection,ed as CamembertForMaskedLM,rd as CamembertForQuestionAnswering,td as CamembertForSequenceClassification,sd as CamembertForTokenClassification,Zp as CamembertModel,It as CamembertPreTrainedModel,pc as CamembertTokenizer,Zc as ChatterboxFeatureExtractor,Nr as ChatterboxModel,Xi as ChatterboxPreTrainedModel,uu as ChatterboxProcessor,mu as ChineseCLIPFeatureExtractor,nd as ChineseCLIPModel,Ki as ChineseCLIPPreTrainedModel,$r as ClapAudioModelWithProjection,eu as ClapFeatureExtractor,od as ClapModel,Ns as ClapPreTrainedModel,Lr as ClapTextModelWithProjection,Di as ClassifierFreeGuidanceLogitsProcessor,_d as CodeGenForCausalLM,dd as CodeGenModel,Dr as CodeGenPreTrainedModel,fc as CodeGenTokenizer,_c as CodeLlamaTokenizer,xd as Cohere2ForCausalLM,hd as Cohere2Model,Br as Cohere2PreTrainedModel,md as CohereForCausalLM,fd as CohereModel,jr as CoherePreTrainedModel,mc as CohereTokenizer,wd as ConvBertForMaskedLM,kd as ConvBertForQuestionAnswering,yd as ConvBertForSequenceClassification,bd as ConvBertForTokenClassification,gd as ConvBertModel,zt as ConvBertPreTrainedModel,hc as ConvBertTokenizer,xu as ConvNextFeatureExtractor,Ed as ConvNextForImageClassification,ui as ConvNextImageProcessor,vd as ConvNextModel,Ur as ConvNextPreTrainedModel,Md as ConvNextV2ForImageClassification,Ad as ConvNextV2Model,qr as ConvNextV2PreTrainedModel,zd as DFineForObjectDetection,Id as DFineModel,Wr as DFinePreTrainedModel,e_ as DINOv3ConvNextModel,sa as DINOv3ConvNextPreTrainedModel,yu as DINOv3ViTImageProcessor,t_ as DINOv3ViTModel,ra as DINOv3ViTPreTrainedModel,ku as DPTFeatureExtractor,c_ as DPTForDepthEstimation,_i as DPTImageProcessor,l_ as DPTModel,Jr as DPTPreTrainedModel,Hr as DacDecoderModel,Ji as DacDecoderOutput,Vr as DacEncoderModel,Qi as DacEncoderOutput,gr as DacFeatureExtractor,Td as DacModel,Ls as DacPreTrainedModel,Cd as DebertaForMaskedLM,$d as DebertaForQuestionAnswering,Nd as DebertaForSequenceClassification,Ld as DebertaForTokenClassification,Pd as DebertaModel,Tt as DebertaPreTrainedModel,gc as DebertaTokenizer,Fd as DebertaV2ForMaskedLM,Bd as DebertaV2ForQuestionAnswering,Dd as DebertaV2ForSequenceClassification,jd as DebertaV2ForTokenClassification,Rd as DebertaV2Model,Pt as DebertaV2PreTrainedModel,xc as DebertaV2Tokenizer,Ud as DecisionTransformerModel,Yi as DecisionTransformerPreTrainedModel,gu as DeiTFeatureExtractor,Gd as DeiTForImageClassification,pi as DeiTImageProcessor,qd as DeiTModel,Xr as DeiTPreTrainedModel,Wd as DepthAnythingForDepthEstimation,Zi as DepthAnythingPreTrainedModel,zl as DepthEstimationPipeline,Vd as DepthProForDepthEstimation,ea as DepthProPreTrainedModel,wu as DetrFeatureExtractor,Xd as DetrForObjectDetection,Kd as DetrForSegmentation,di as DetrImageProcessor,Hd as DetrModel,Rs as DetrObjectDetectionOutput,$s as DetrPreTrainedModel,ta as DetrSegmentationOutput,Jd as Dinov2ForImageClassification,Qd as Dinov2Model,Kr as Dinov2PreTrainedModel,Zd as Dinov2WithRegistersForImageClassification,Yd as Dinov2WithRegistersModel,Qr as Dinov2WithRegistersPreTrainedModel,i_ as DistilBertForMaskedLM,o_ as DistilBertForQuestionAnswering,r_ as DistilBertForSequenceClassification,n_ as DistilBertForTokenClassification,s_ as DistilBertModel,Ct as DistilBertPreTrainedModel,wc as DistilBertTokenizer,Ol as DocumentQuestionAnsweringPipeline,bu as DonutFeatureExtractor,vs as DonutImageProcessor,a_ as DonutSwinModel,na as DonutSwinPreTrainedModel,Hh as EdgeTamModel,p_ as EfficientNetForImageClassification,vu as EfficientNetImageProcessor,u_ as EfficientNetModel,Yr as EfficientNetPreTrainedModel,__ as ElectraForMaskedLM,h_ as ElectraForQuestionAnswering,f_ as ElectraForSequenceClassification,m_ as ElectraForTokenClassification,d_ as ElectraModel,Nt as ElectraPreTrainedModel,yc as ElectraTokenizer,xr as EncodecFeatureExtractor,qi as EosTokenCriteria,g_ as Ernie4_5ForCausalLM,x_ as Ernie4_5Model,Zr as Ernie4_5PretrainedModel,y_ as EsmForMaskedLM,b_ as EsmForSequenceClassification,k_ as EsmForTokenClassification,w_ as EsmModel,ns as EsmPreTrainedModel,bc as EsmTokenizer,E_ as ExaoneForCausalLM,v_ as ExaoneModel,en as ExaonePreTrainedModel,M_ as FalconForCausalLM,O_ as FalconH1ForCausalLM,S_ as FalconH1Model,sn as FalconH1PreTrainedModel,A_ as FalconModel,tn as FalconPreTrainedModel,kc as FalconTokenizer,z_ as FastViTForImageClassification,I_ as FastViTModel,rn as FastViTPreTrainedModel,Tl as FeatureExtractionPipeline,pe as FeatureExtractor,_l as FillMaskPipeline,T_ as Florence2ForConditionalGeneration,oa as Florence2PreTrainedModel,ep as Florence2Processor,Ti as ForcedBOSTokenLogitsProcessor,Pi as ForcedEOSTokenLogitsProcessor,Eu as GLPNFeatureExtractor,B_ as GLPNForDepthEstimation,j_ as GLPNModel,un as GLPNPreTrainedModel,J_ as GPT2LMHeadModel,Q_ as GPT2Model,mn as GPT2PreTrainedModel,Ac as GPT2Tokenizer,q_ as GPTBigCodeForCausalLM,U_ as GPTBigCodeModel,pn as GPTBigCodePreTrainedModel,Z_ as GPTJForCausalLM,Y_ as GPTJModel,hn as GPTJPreTrainedModel,W_ as GPTNeoForCausalLM,G_ as GPTNeoModel,dn as GPTNeoPreTrainedModel,H_ as GPTNeoXForCausalLM,V_ as GPTNeoXModel,_n as GPTNeoXPreTrainedModel,Ec as GPTNeoXTokenizer,L_ as Gemma2ForCausalLM,N_ as Gemma2Model,on as Gemma2PreTrainedModel,R_ as Gemma3ForCausalLM,$_ as Gemma3Model,an as Gemma3PreTrainedModel,tu as Gemma3nAudioFeatureExtractor,ln as Gemma3nForConditionalGeneration,ia as Gemma3nPreTrainedModel,tp as Gemma3nProcessor,C_ as GemmaForCausalLM,P_ as GemmaModel,nn as GemmaPreTrainedModel,vc as GemmaTokenizer,D_ as GlmForCausalLM,F_ as GlmModel,cn as GlmPreTrainedModel,K_ as GptOssForCausalLM,X_ as GptOssModel,fn as GptOssPreTrainedModel,tf as GraniteForCausalLM,ef as GraniteModel,rf as GraniteMoeHybridForCausalLM,sf as GraniteMoeHybridModel,gn as GraniteMoeHybridPreTrainedModel,xn as GranitePreTrainedModel,nf as GroundingDinoForObjectDetection,Au as GroundingDinoImageProcessor,aa as GroundingDinoPreTrainedModel,sp as GroundingDinoProcessor,of as GroupViTModel,la as GroupViTPreTrainedModel,lf as HeliumForCausalLM,af as HeliumModel,wn as HeliumPreTrainedModel,Mc as HerbertTokenizer,uf as HieraForImageClassification,cf as HieraModel,yn as HieraPreTrainedModel,xf as HubertForCTC,gf as HubertForSequenceClassification,hf as HubertModel,mf as HubertPreTrainedModel,yf as HunYuanDenseV1ForCausalLM,wf as HunYuanDenseV1Model,bn as HunYuanDenseV1PreTrainedModel,vf as IJepaForImageClassification,kf as IJepaModel,kn as IJepaPreTrainedModel,ua as Idefics3ForConditionalGeneration,fi as Idefics3ImageProcessor,ca as Idefics3PreTrainedModel,Ei as Idefics3Processor,vl as ImageClassificationPipeline,Pl as ImageFeatureExtractionPipeline,P as ImageFeatureExtractor,P as ImageProcessor,er as ImageSegmentationPipeline,Il as ImageToImagePipeline,kl as ImageToTextPipeline,ay as InterruptableStoppingCriteria,Af as JAISLMHeadModel,Ef as JAISModel,vn as JAISPreTrainedModel,Su as JinaCLIPImageProcessor,Mf as JinaCLIPModel,Fs as JinaCLIPPreTrainedModel,np as JinaCLIPProcessor,En as JinaCLIPTextModel,Sf as JinaCLIPVisionModel,If as Lfm2ForCausalLM,Of as Lfm2Model,Tf as Lfm2MoeForCausalLM,zf as Lfm2MoeModel,Mn as Lfm2MoePreTrainedModel,An as Lfm2PreTrainedModel,ng as LiteWhisperForConditionalGeneration,Nf as Llama4ForCausalLM,pa as Llama4PreTrainedModel,Cf as LlamaForCausalLM,Pf as LlamaModel,Sn as LlamaPreTrainedModel,Sc as LlamaTokenizer,Ds as LlavaForConditionalGeneration,Ds as LlavaOnevisionForConditionalGeneration,Ou as LlavaOnevisionImageProcessor,da as LlavaPreTrainedModel,op as LlavaProcessor,$f as LlavaQwen2ForCausalLM,Qe as LogitsProcessor,Zt as LogitsProcessorList,vr as LogitsWarper,Ff as LongT5ForConditionalGeneration,Rf as LongT5Model,On as LongT5PreTrainedModel,jf as M2M100ForConditionalGeneration,Df as M2M100Model,In as M2M100PreTrainedModel,Oc as M2M100Tokenizer,zc as MBart50Tokenizer,Xf as MBartForCausalLM,Vf as MBartForConditionalGeneration,Hf as MBartForSequenceClassification,Wf as MBartModel,os as MBartPreTrainedModel,_r as MBartTokenizer,Pm as MPNetForMaskedLM,Lm as MPNetForQuestionAnswering,Cm as MPNetForSequenceClassification,Nm as MPNetForTokenClassification,Tm as MPNetModel,Lt as MPNetPreTrainedModel,Cc as MPNetTokenizer,Dm as MT5ForConditionalGeneration,Fm as MT5Model,Bn as MT5PreTrainedModel,Uf as MarianMTModel,Bf as MarianModel,zn as MarianPreTrainedModel,Ic as MarianTokenizer,zu as Mask2FormerImageProcessor,Iu as MaskFormerFeatureExtractor,Gf as MaskFormerForInstanceSegmentation,Es as MaskFormerImageProcessor,qf as MaskFormerModel,Tn as MaskFormerPreTrainedModel,Ui as MaxLengthCriteria,Kf as Metric3DForDepthEstimation,_a as Metric3DPreTrainedModel,Qf as Metric3Dv2ForDepthEstimation,fa as Metric3Dv2PreTrainedModel,Jf as MgpstrForSceneTextRecognition,ma as MgpstrModelOutput,ha as MgpstrPreTrainedModel,ip as MgpstrProcessor,Tc as MgpstrTokenizer,Cn as MimiDecoderModel,ga as MimiDecoderOutput,Pn as MimiEncoderModel,xa as MimiEncoderOutput,Yf as MimiModel,js as MimiPreTrainedModel,$i as MinLengthLogitsProcessor,Ri as MinNewTokensLengthLogitsProcessor,em as MistralForCausalLM,Zf as MistralModel,Nn as MistralPreTrainedModel,sm as MobileBertForMaskedLM,nm as MobileBertForQuestionAnswering,rm as MobileBertForSequenceClassification,tm as MobileBertModel,is as MobileBertPreTrainedModel,Pc as MobileBertTokenizer,im as MobileLLMForCausalLM,om as MobileLLMModel,Ln as MobileLLMPreTrainedModel,Tu as MobileNetV1FeatureExtractor,lm as MobileNetV1ForImageClassification,cm as MobileNetV1ForSemanticSegmentation,mi as MobileNetV1ImageProcessor,am as MobileNetV1Model,Bs as MobileNetV1PreTrainedModel,Pu as MobileNetV2FeatureExtractor,pm as MobileNetV2ForImageClassification,dm as MobileNetV2ForSemanticSegmentation,hi as MobileNetV2ImageProcessor,um as MobileNetV2Model,Us as MobileNetV2PreTrainedModel,Cu as MobileNetV3FeatureExtractor,fm as MobileNetV3ForImageClassification,mm as MobileNetV3ForSemanticSegmentation,xi as MobileNetV3ImageProcessor,_m as MobileNetV3Model,qs as MobileNetV3PreTrainedModel,Nu as MobileNetV4FeatureExtractor,xm as MobileNetV4ForImageClassification,gm as MobileNetV4ForSemanticSegmentation,gi as MobileNetV4ImageProcessor,hm as MobileNetV4Model,Gs as MobileNetV4PreTrainedModel,Lu as MobileViTFeatureExtractor,ym as MobileViTForImageClassification,wi as MobileViTImageProcessor,wm as MobileViTModel,$n as MobileViTPreTrainedModel,km as MobileViTV2ForImageClassification,bm as MobileViTV2Model,Rn as MobileViTV2PreTrainedModel,Om as ModernBertDecoderForCausalLM,Sm as ModernBertDecoderModel,Fn as ModernBertDecoderPreTrainedModel,Em as ModernBertForMaskedLM,Am as ModernBertForSequenceClassification,Mm as ModernBertForTokenClassification,vm as ModernBertModel,as as ModernBertPreTrainedModel,Lf as Moondream1ForConditionalGeneration,su as MoonshineFeatureExtractor,zm as MoonshineForConditionalGeneration,Im as MoonshineModel,Dn as MoonshinePreTrainedModel,ap as MoonshineProcessor,Rm as MptForCausalLM,$m as MptModel,jn as MptPreTrainedModel,jm as MultiModalityCausalLM,wa as MultiModalityPreTrainedModel,Um as MusicgenForCausalLM,qn as MusicgenForConditionalGeneration,Bm as MusicgenModel,Un as MusicgenPreTrainedModel,Gm as NanoChatForCausalLM,qm as NanoChatModel,Gn as NanoChatPreTrainedModel,Vm as NeoBertForMaskedLM,Km as NeoBertForQuestionAnswering,Hm as NeoBertForSequenceClassification,Xm as NeoBertForTokenClassification,Wm as NeoBertModel,$t as NeoBertPreTrainedModel,Nc as NllbTokenizer,Fi as NoBadWordsLogitsProcessor,Ni as NoRepeatNGramLogitsProcessor,Qm as NomicBertModel,ya as NomicBertPreTrainedModel,$u as NougatImageProcessor,Lc as NougatTokenizer,ih as OPTForCausalLM,oh as OPTModel,Kn as OPTPreTrainedModel,Ml as ObjectDetectionPipeline,eh as Olmo2ForCausalLM,Zm as Olmo2Model,Vn as Olmo2PreTrainedModel,sh as Olmo3ForCausalLM,th as Olmo3Model,Hn as Olmo3PreTrainedModel,Ym as OlmoForCausalLM,Jm as OlmoModel,Wn as OlmoPreTrainedModel,nh as OpenELMForCausalLM,rh as OpenELMModel,Xn as OpenELMPreTrainedModel,Ru as OwlViTFeatureExtractor,uh as OwlViTForObjectDetection,As as OwlViTImageProcessor,ch as OwlViTModel,Jn as OwlViTPreTrainedModel,lp as OwlViTProcessor,lh as Owlv2ForObjectDetection,Fu as Owlv2ImageProcessor,ah as Owlv2Model,Qn as Owlv2PreTrainedModel,ph as PaliGemmaForConditionalGeneration,ba as PaliGemmaPreTrainedModel,cp as PaliGemmaProcessor,ru as ParakeetFeatureExtractor,dh as ParakeetForCTC,ka as ParakeetPreTrainedModel,fh as PatchTSMixerForPrediction,_h as PatchTSMixerModel,Yn as PatchTSMixerPreTrainedModel,hh as PatchTSTForPrediction,mh as PatchTSTModel,Zn as PatchTSTPreTrainedModel,yh as Phi3ForCausalLM,wh as Phi3Model,to as Phi3PreTrainedModel,so as Phi3VForCausalLM,Bu as Phi3VImageProcessor,va as Phi3VPreTrainedModel,up as Phi3VProcessor,gh as PhiForCausalLM,xh as PhiModel,eo as PhiPreTrainedModel,Uu as PixtralImageProcessor,pp as PixtralProcessor,f as PreTrainedModel,T as PreTrainedTokenizer,Oi as PretrainedConfig,j as Processor,kh as PvtForImageClassification,qu as PvtImageProcessor,bh as PvtModel,ro as PvtPreTrainedModel,wr as PyAnnoteFeatureExtractor,Eh as PyAnnoteForAudioFrameClassification,vh as PyAnnoteModel,no as PyAnnotePreTrainedModel,dp as PyAnnoteProcessor,dl as QuestionAnsweringPipeline,Mh as Qwen2ForCausalLM,Ah as Qwen2Model,oo as Qwen2PreTrainedModel,$c as Qwen2Tokenizer,Sh as Qwen2VLForConditionalGeneration,Gu as Qwen2VLImageProcessor,Ea as Qwen2VLPreTrainedModel,_p as Qwen2VLProcessor,Ih as Qwen3ForCausalLM,Oh as Qwen3Model,io as Qwen3PreTrainedModel,Ch as RFDetrForObjectDetection,Ph as RFDetrModel,Aa as RFDetrObjectDetectionOutput,lo as RFDetrPreTrainedModel,Od as RTDetrForObjectDetection,Wu as RTDetrImageProcessor,Sd as RTDetrModel,mt as RTDetrObjectDetectionOutput,Gr as RTDetrPreTrainedModel,Wh as RTDetrV2ForObjectDetection,Gh as RTDetrV2Model,Ma as RTDetrV2ObjectDetectionOutput,co as RTDetrV2PreTrainedModel,hr as RawAudio,we as RawImage,Cl as RawVideo,Lo as RawVideoFrame,Li as RepetitionPenaltyLogitsProcessor,Th as ResNetForImageClassification,zh as ResNetModel,ao as ResNetPreTrainedModel,jh as RoFormerForMaskedLM,qh as RoFormerForQuestionAnswering,Bh as RoFormerForSequenceClassification,Uh as RoFormerForTokenClassification,Dh as RoFormerModel,Ft as RoFormerPreTrainedModel,Fc as RoFormerTokenizer,Lh as RobertaForMaskedLM,Fh as RobertaForQuestionAnswering,$h as RobertaForSequenceClassification,Rh as RobertaForTokenClassification,Nh as RobertaModel,Rt as RobertaPreTrainedModel,Rc as RobertaTokenizer,br as Sam2ImageProcessor,Ia as Sam2ImageSegmentationOutput,uo as Sam2Model,za as Sam2PreTrainedModel,Ai as Sam2Processor,fp as Sam2VideoProcessor,br as Sam3ImageProcessor,Xh as Sam3TrackerModel,br as SamImageProcessor,Sa as SamImageSegmentationOutput,Vh as SamModel,Oa as SamPreTrainedModel,kr as SamProcessor,Vu as SapiensFeatureExtractor,Qh as SapiensForDepthEstimation,Jh as SapiensForNormalEstimation,Kh as SapiensForSemanticSegmentation,yi as SapiensImageProcessor,Ws as SapiensPreTrainedModel,nu as SeamlessM4TFeatureExtractor,Hu as SegformerFeatureExtractor,Zh as SegformerForImageClassification,ex as SegformerForSemanticSegmentation,bi as SegformerImageProcessor,Yh as SegformerModel,Vs as SegformerPreTrainedModel,Xu as SiglipImageProcessor,tx as SiglipModel,po as SiglipPreTrainedModel,_o as SiglipTextModel,Dc as SiglipTokenizer,sx as SiglipVisionModel,nx as SmolLM3ForCausalLM,rx as SmolLM3Model,fo as SmolLM3PreTrainedModel,bf as SmolVLMForConditionalGeneration,fi as SmolVLMImageProcessor,Ei as SmolVLMProcessor,ho as SnacDecoderModel,mo as SnacEncoderModel,ou as SnacFeatureExtractor,ox as SnacModel,Hs as SnacPreTrainedModel,iu as SpeechT5FeatureExtractor,ax as SpeechT5ForSpeechToText,lx as SpeechT5ForTextToSpeech,cx as SpeechT5HifiGan,ix as SpeechT5Model,Xs as SpeechT5PreTrainedModel,mp as SpeechT5Processor,jc as SpeechT5Tokenizer,px as SqueezeBertForMaskedLM,_x as SqueezeBertForQuestionAnswering,dx as SqueezeBertForSequenceClassification,ux as SqueezeBertModel,ls as SqueezeBertPreTrainedModel,Bc as SqueezeBertTokenizer,mx as StableLmForCausalLM,fx as StableLmModel,xo as StableLmPreTrainedModel,xx as Starcoder2ForCausalLM,hx as Starcoder2Model,go as Starcoder2PreTrainedModel,Ps as StoppingCriteria,Bi as StoppingCriteriaList,gx as StyleTextToSpeech2Model,Ta as StyleTextToSpeech2PreTrainedModel,fl as SummarizationPipeline,wo as SupertonicForConditionalGeneration,Pa as SupertonicPreTrainedModel,zs as SuppressTokensAtBeginLogitsProcessor,vx as Swin2SRForImageSuperResolution,Ku as Swin2SRImageProcessor,kx as Swin2SRModel,yo as Swin2SRPreTrainedModel,yx as SwinForImageClassification,bx as SwinForSemanticSegmentation,wx as SwinModel,Ks as SwinPreTrainedModel,Ax as T5ForConditionalGeneration,Ex as T5Model,bo as T5PreTrainedModel,Uc as T5Tokenizer,Sx as TableTransformerForObjectDetection,Mx as TableTransformerModel,Ca as TableTransformerObjectDetectionOutput,ko as TableTransformerPreTrainedModel,ji as TemperatureLogitsWarper,S as Tensor,qt as Text2TextGenerationPipeline,ul as TextClassificationPipeline,hl as TextGenerationPipeline,kg as TextStreamer,bl as TextToAudioPipeline,pl as TokenClassificationPipeline,T as TokenizersBackend,iy as TopKLogitsWarper,oy as TopPLogitsWarper,Ox as TrOCRForCausalLM,Na as TrOCRPreTrainedModel,ml as TranslationPipeline,$a as UltravoxModel,La as UltravoxPreTrainedModel,hp as UltravoxProcessor,Tx as UniSpeechForCTC,Px as UniSpeechForSequenceClassification,zx as UniSpeechModel,Qs as UniSpeechPreTrainedModel,$x as UniSpeechSatForAudioFrameClassification,Nx as UniSpeechSatForCTC,Lx as UniSpeechSatForSequenceClassification,Cx as UniSpeechSatModel,cs as UniSpeechSatPreTrainedModel,rp as VLChatProcessor,Mu as VLMImageProcessor,Fx as VaultGemmaForCausalLM,Rx as VaultGemmaModel,vo as VaultGemmaPreTrainedModel,Qu as ViTFeatureExtractor,Bx as ViTForImageClassification,ki as ViTImageProcessor,Ux as ViTMAEModel,Ra as ViTMAEPreTrainedModel,Gx as ViTMSNForImageClassification,qx as ViTMSNModel,Ao as ViTMSNPreTrainedModel,jx as ViTModel,Eo as ViTPreTrainedModel,Dx as VisionEncoderDecoderModel,Wx as VitMatteForImageMatting,Ju as VitMatteImageProcessor,Fa as VitMattePreTrainedModel,Vx as VitPoseForPoseEstimation,Yu as VitPoseImageProcessor,Da as VitPosePreTrainedModel,Hx as VitsModel,ja as VitsModelOutput,Ba as VitsPreTrainedModel,Gc as VitsTokenizer,Ix as VoxtralForConditionalGeneration,xp as VoxtralProcessor,Kx as Wav2Vec2BertForCTC,Qx as Wav2Vec2BertForSequenceClassification,Xx as Wav2Vec2BertModel,Js as Wav2Vec2BertPreTrainedModel,Wc as Wav2Vec2CTCTokenizer,au as Wav2Vec2FeatureExtractor,ff as Wav2Vec2ForAudioFrameClassification,df as Wav2Vec2ForCTC,_f as Wav2Vec2ForSequenceClassification,pf as Wav2Vec2Model,at as Wav2Vec2PreTrainedModel,gp as Wav2Vec2Processor,wp as Wav2Vec2ProcessorWithLM,tg as WavLMForAudioFrameClassification,Yx as WavLMForCTC,Zx as WavLMForSequenceClassification,eg as WavLMForXVector,Jx as WavLMModel,Dt as WavLMPreTrainedModel,lu as WeSpeakerFeatureExtractor,sg as WeSpeakerResNetModel,qa as WeSpeakerResNetPreTrainedModel,cu as WhisperFeatureExtractor,Wa as WhisperForConditionalGeneration,rg as WhisperModel,Mo as WhisperPreTrainedModel,yp as WhisperProcessor,Zy as WhisperTextStreamer,Ci as WhisperTimeStampLogitsProcessor,Vc as WhisperTokenizer,cg as XLMForQuestionAnswering,ag as XLMForSequenceClassification,lg as XLMForTokenClassification,og as XLMModel,jt as XLMPreTrainedModel,pg as XLMRobertaForMaskedLM,fg as XLMRobertaForQuestionAnswering,dg as XLMRobertaForSequenceClassification,_g as XLMRobertaForTokenClassification,ug as XLMRobertaModel,Bt as XLMRobertaPreTrainedModel,Hc as XLMRobertaTokenizer,Xc as XLMTokenizer,ig as XLMWithLMHeadModel,Ua as XVectorOutput,Zu as YolosFeatureExtractor,hg as YolosForObjectDetection,vi as YolosImageProcessor,mg as YolosModel,Va as YolosObjectDetectionOutput,So as YolosPreTrainedModel,gg as YoutuForCausalLM,xg as YoutuModel,Oo as YoutuPreTrainedModel,wl as ZeroShotAudioClassificationPipeline,xl as ZeroShotClassificationPipeline,Al as ZeroShotImageClassificationPipeline,Sl as ZeroShotObjectDetectionPipeline,ne as cat,bk as cos_sim,xw as dot,_e as env,xe as full,dr as full_like,Yl as interpolate,Xe as interpolate_4d,TM as layer_norm,sv as load_image,Rv as load_video,Gl as log_softmax,Rw as matmul,ti as mean,Fw as mean_pooling,Oe as ones,si as ones_like,Nk as permute,c9 as pipeline,jw as quantize_embeddings,PM as rand,Dw as randn,Jc as read_audio,zM as rfft,ei as slice,ce as softmax,Ke as stack,Zl as std_mean,ot as topk,tc as zeros,sc as zeros_like};
20
+ ${r}${o}`+n.repeat(t)+`${r}`,i}function qv(t,e,s,r){return`${e}${r}`+s.repeat(t)+`${e}`}function Gv(t,e,s,r,n,o){return t===0&&e===0?qv(s,r,n,o):Bv(s,t,e,r,n,o)}var ma=class extends U{static image_processor_class=fe;static tokenizer_class=$;static uses_processor_config=!0;fake_image_token="<fake_token_around_image>";image_token="<image>";global_img_token="<global-img>";async _call(e,s=null,r={}){r.return_row_col_info??=!0;let n;s&&(n=await this.image_processor(s,r)),Array.isArray(e)||(e=[e]);let o=n.rows??[new Array(e.length).fill(0)],i=n.cols??[new Array(e.length).fill(0)],a=this.config.image_seq_len,l=[],c=[];for(let p=0;p<e.length;++p){let d=e[p],_=o[p],f=i[p];l.push(uw(d,this.image_token));let h=_.map((w,y)=>Gv(w,f[y],a,this.fake_image_token,this.image_token,this.global_img_token)),x=d.split(this.image_token);if(x.length===0)throw new Error("The image token should be present in the text.");let g=x[0];for(let w=0;w<h.length;++w)g+=h[w]+x[w+1];c.push(g)}return{...this.tokenizer(c),...n}}};var Sp=class extends U{static image_processor_class=fe;static tokenizer_class=$;static uses_processor_config=!0;constructor(e,s,r){super(e,s,r),this.image_tag=this.config.image_tag,this.image_start_tag=this.config.image_start_tag,this.image_end_tag=this.config.image_end_tag,this.num_image_tokens=this.config.num_image_tokens}async _call(e,{images:s=null,chat_template:r="default"}={}){s?Array.isArray(s)||(s=[s]):s=await Promise.all(e.filter(x=>x.images).flatMap(x=>x.images).map(x=>ye.read(x)));let n=this.tokenizer,o=n.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0,chat_template:r}),i=x=>n.encode(x,{add_special_tokens:!1}),a=o.split(this.image_tag),l=a.length-1;if(s.length!==l)throw new Error(`Number of images provided (${s.length}) does not match number of "${this.image_tag}" image tags (${l})`);let[c,u,p]=n.convert_tokens_to_ids([this.image_tag,this.image_start_tag,this.image_end_tag]),d=i(a[0]),_=new Array(d.length).fill(!1);for(let x=1;x<a.length;++x){let g=new Array(this.num_image_tokens).fill(c),w=i(a[x]);d=Pe(d,[u],g,[p],w);let y=new Array(this.num_image_tokens).fill(!0);_=Pe(_,[!1],y,[!1],new Array(w.length).fill(!1))}let f=[1,d.length],h={input_ids:new S("int64",d,f),attention_mask:new S("int64",new Array(d.length).fill(1),f),images_seq_mask:new S("bool",_,f),images_emb_mask:new S("bool",new Array(l*this.num_image_tokens).fill(!0),[1,l,this.num_image_tokens])};if(s&&s.length>0){let x=await this.image_processor(s);return x.pixel_values.unsqueeze_(0),{...h,...x}}return h}};var Op=class extends U{static tokenizer_class=$;static image_processor_class=fe;async _call(e=null,s=null,r={}){if(!e&&!s)throw new Error("Either text or images must be provided");let n=e?this.tokenizer(e,r):{},o=s?await this.image_processor(s,r):{};return{...n,...o}}};var Ip=class extends U{static tokenizer_class=$;static image_processor_class=fe;static uses_processor_config=!0;async _call(e,s=null,r={}){let n=await this.image_processor(e,r);if(s){let[i,a]=n.pixel_values.dims.slice(-2),{image_token:l,patch_size:c,num_additional_image_tokens:u}=this.config,p=Math.floor(i/c)*Math.floor(a/c)+u;s=structuredClone(s),Array.isArray(s)||(s=[s]);for(let d=0;d<s.length;++d)s[d]=s[d].replace(l,l.repeat(p))}let o=s?this.tokenizer(s,r):{};return{...n,...o}}};var $y={char:["char_decode",1],bpe:["bpe_decode",2],wp:["wp_decode",102]},Tp=class extends U{static tokenizer_class=$;static image_processor_class=fe;get char_tokenizer(){return this.components.char_tokenizer}get bpe_tokenizer(){return this.components.bpe_tokenizer}get wp_tokenizer(){return this.components.wp_tokenizer}_decode_helper(e,s){if(!$y.hasOwnProperty(s))throw new Error(`Format ${s} is not supported.`);let[r,n]=$y[s],o=this[r].bind(this),[i,a]=e.dims,l=[],c=[],u=e.tolist();for(let d=0;d<i;++d){let _=u[d],f=[],h=[];for(let g=1;g<a;++g){let[w,y]=le(pe(_[g]));if(h.push(w),y==n)break;f.push(y)}let x=h.length>0?h.reduce((g,w)=>g*w,1):0;c.push(f),l.push(x)}return[o(c),l]}char_decode(e){return this.char_tokenizer.batch_decode(e).map(s=>s.replaceAll(" ",""))}bpe_decode(e){return this.bpe_tokenizer.batch_decode(e)}wp_decode(e){return this.wp_tokenizer.batch_decode(e).map(s=>s.replaceAll(" ",""))}batch_decode([e,s,r]){let[n,o]=this._decode_helper(e,"char"),[i,a]=this._decode_helper(s,"bpe"),[l,c]=this._decode_helper(r,"wp"),u=[],p=[];for(let d=0;d<n.length;++d){let[_,f]=le([o[d],a[d],c[d]]);u.push([n[d],i[d],l[d]][f]),p.push(_)}return{generated_text:u,scores:p,char_preds:n,bpe_preds:i,wp_preds:l}}static async from_pretrained(...e){let s=await super.from_pretrained(...e),r=await $.from_pretrained("Xenova/gpt2"),n=await $.from_pretrained("Xenova/bert-base-uncased");return s.components={image_processor:s.image_processor,char_tokenizer:s.tokenizer,bpe_tokenizer:r,wp_tokenizer:n},s}async _call(e,s=null){let r=await this.image_processor(e);return s&&(r.labels=this.tokenizer(s).input_ids),r}};var zp=class extends U{static tokenizer_class=$;static feature_extractor_class=Ee;async _call(e){return await this.feature_extractor(e)}};var Pp=class extends U{static tokenizer_class=$;static image_processor_class=fe};var Us="<image>";function Wv(t,e,s,r,n){return`${r.repeat(s*n)}${e}${t}
21
+ `}var Cp=class extends U{static tokenizer_class=$;static image_processor_class=fe;static uses_processor_config=!1;async _call(e,s=null,r={}){s||(L.warn("You are using PaliGemma without a text prefix. It will perform as a picture-captioning model."),s=""),Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);let n=this.tokenizer.bos_token,o=this.image_processor.config.image_seq_length,i;s.some(c=>c.includes(Us))?i=s.map(c=>{let u=c.replaceAll(Us,Us.repeat(o)),p=u.lastIndexOf(Us),d=p===-1?0:p+Us.length;return u.slice(0,d)+n+u.slice(d)+`
22
+ `}):(L.warn("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."),i=s.map(c=>Wv(c,n,o,Us,e.length)));let a=this.tokenizer(i,r);return{...await this.image_processor(e,r),...a}}};var Ry="<|image|>",Vv=/<\|image_\d+\|>/g,Np=class extends U{static image_processor_class=fe;static tokenizer_class=$;async _call(e,s=null,{padding:r=!0,truncation:n=!0,num_crops:o=null}={}){Array.isArray(e)||(e=[e]);let i,a;if(s){a=await this.image_processor(s,{num_crops:o});let{num_img_tokens:l}=a,c=e.map((p,d)=>p.split(Vv).join(Ry.repeat(l[d])));i=this.tokenizer(c,{padding:r,truncation:n});let u=this.tokenizer._tokenizer.token_to_id(Ry);i.input_ids.map_(p=>p==u?-p:p)}else i=this.tokenizer(e);return{...i,...a}}};var Lp=class extends U{static tokenizer_class=$;static image_processor_class=fe;static uses_processor_config=!0;async _call(e,s=null,r={}){let n=await this.image_processor(e,r);if(s){let[i,a]=n.pixel_values.dims.slice(-2),{image_token:l,image_break_token:c,image_end_token:u,patch_size:p,spatial_merge_size:d}=this.config,_=p*d,f=Math.floor(i/_),h=Math.floor(a/_);s=structuredClone(s),Array.isArray(s)||(s=[s]);for(let x=0;x<s.length;++x){let g=l.repeat(h),w=g+c,y=g+u,b=w.repeat(f-1)+y;s[x]=s[x].replace(l,b)}}let o=s?this.tokenizer(s,r):{};return{...n,...o}}};var $p=class extends U{static feature_extractor_class=Pr;async _call(e){return await this.feature_extractor(e)}post_process_speaker_diarization(...e){return this.feature_extractor.post_process_speaker_diarization(...e)}get sampling_rate(){return this.feature_extractor.config.sampling_rate}};var Lr=class extends U{static image_processor_class=fe;static tokenizer_class=$;async _call(e,s=null,...r){Array.isArray(e)||(e=[e]);let n,o;if(s&&(n=await this.image_processor(s),o=n.image_grid_thw),o){let a=this.image_processor.config.merge_size**2,l=0,c=o.tolist();e=e.map(u=>{for(;u.includes("<|image_pad|>");){let p=Number(c[l++].reduce((d,_)=>d*_,1n));u=u.replace("<|image_pad|>","<|placeholder|>".repeat(Math.floor(p/a)))}return u.replaceAll("<|placeholder|>","<|image_pad|>")})}return{...this.tokenizer(e),...n}}};var $r=class extends Lr{};var Rp=class extends $r{};var Rr=class extends U{static image_processor_class=fe;async _call(...e){return await this.image_processor(...e)}post_process_masks(...e){return this.image_processor.post_process_masks(...e)}reshape_input_points(...e){return this.image_processor.reshape_input_points(...e)}};var ha=class extends Rr{},Fp=class extends ha{};var Dp=class extends U{static tokenizer_class=$;static feature_extractor_class=Ee;async _call(e){return await this.feature_extractor(e)}};var jp=class extends U{static tokenizer_class=$;static feature_extractor_class=Ee;static uses_processor_config=!0;async _call(e,s=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(s){let i=s.length,{input_features:a}=await this.feature_extractor(s,{...r,max_length:i}),l=Math.round(i/this.config.encoder_ds_factor+1e-4),c=1+Math.ceil(l/this.config.stack_factor);n.audio_token_len=[c],n.audio_values=a;let u=this.config.audio_placeholder;if(!e.includes(u))throw new Error(`The input text does not contain the image token ${u}.`);e=e.replaceAll(u,u.repeat(c))}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};var xa="[AUDIO]",Hv="[BEGIN_AUDIO]",Kv=375;function Xv(t,e){let s=[];for(let r=0;r<t.length;r+=e)s.push(t.subarray(r,Math.min(r+e,t.length)));return s}var Up=class extends U{static tokenizer_class=$;static feature_extractor_class=Ee;static uses_processor_config=!1;async _call(e,s=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(s){if(!e.includes(xa))throw new Error(`The input text does not contain the audio token ${xa}.`);Array.isArray(s)||(s=[s]);let i=e.split(xa),a=i.length-1;if(a!==s.length)throw new Error(`The number of audio inputs (${s.length}) does not match the number of audio tokens in the text (${a}).`);let l=this.feature_extractor.config.n_samples,c=s.map(f=>Xv(f,l)),u=c.map(f=>f.length),p=c.flat(),d=(await Promise.all(p.map(f=>this.feature_extractor(f,r)))).map(f=>f.input_features);n.audio_values=d.length>1?ie(d,0):d[0];let _=i[0];for(let f=0;f<u.length;++f){_+=Hv;for(let h=0;h<u[f];++h)_+=xa.repeat(Kv);_+=i[f+1]}e=_}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};var Bp=class extends U{static tokenizer_class=$;static feature_extractor_class=Ee;async _call(e){return await this.feature_extractor(e)}};var qp=class extends U{static tokenizer_class=$;static feature_extractor_class=Ee;async _call(e){return await this.feature_extractor(e)}};var Gp=class extends U{static tokenizer_class=$;static feature_extractor_class=Ee;async _call(e){return await this.feature_extractor(e)}};var ze=class{static async from_pretrained(e,s={}){let r=await Te(e,Ot,!0,s),{image_processor_type:n,feature_extractor_type:o,processor_class:i}=r;if(i&&ga[i])return ga[i].from_pretrained(e,s);if(!n&&!o)throw new Error("No `image_processor_type` or `feature_extractor_type` found in the config.");let a={};if(n){let c=js[n.replace(/Fast$/,"")];if(!c)throw new Error(`Unknown image_processor_type: '${n}'.`);a.image_processor=new c(r)}if(o){let c=js[o];if(c)a.image_processor=new c(r);else{let u=Cr[o];if(!u)throw new Error(`Unknown feature_extractor_type: '${o}'.`);a.feature_extractor=new u(r)}}let l={};return new U(l,a,null)}};async function Qv(t,e){return await Te(t,"config.json",!0,e)}function Bs(t){let e={},s={};switch(t.model_type){case"llava":case"paligemma":case"gemma3":case"florence2":case"llava_onevision":case"idefics3":case"ultravox":case"voxtral":case"smolvlm":case"gemma3n":case"chatterbox":case"mistral3":case"qwen2_5_vl":case"qwen3_vl":s=Bs(t.text_config);break;case"moondream1":s=Bs(t.phi_config);break;case"musicgen":s=Bs(t.decoder);break;case"multi_modality":s=Bs(t.language_config);break;case"gpt2":case"gptj":case"jais":case"codegen":case"gpt_bigcode":e.num_heads="n_head",e.num_layers="n_layer",e.hidden_size="n_embd";break;case"gpt_neox":case"stablelm":case"opt":case"falcon":case"modernbert-decoder":e.num_heads="num_attention_heads",e.num_layers="num_hidden_layers",e.hidden_size="hidden_size";break;case"gpt_oss":case"llama":case"llama4_text":case"nanochat":case"apertus":case"arcee":case"afmoe":case"lfm2":case"lfm2_moe":case"smollm3":case"olmo":case"olmo2":case"olmo3":case"mobilellm":case"granite":case"granitemoehybrid":case"cohere":case"cohere2":case"mistral":case"starcoder2":case"qwen2":case"qwen2_vl":case"qwen2_5_vl_text":case"qwen3_vl_text":case"phi":case"phi3":case"phi3_v":case"llava_qwen2":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.hidden_size="hidden_size",e.num_attention_heads="num_attention_heads",e.dim_kv="head_dim";break;case"qwen3":case"gemma":case"gemma2":case"vaultgemma":case"gemma3_text":case"gemma3n_text":case"glm":case"helium":case"ernie4_5":case"hunyuan_v1_dense":case"falcon_h1":case"ministral":case"ministral3":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.dim_kv="head_dim";break;case"openelm":e.num_heads="num_kv_heads",e.num_layers="num_transformer_layers",e.dim_kv="head_dim";break;case"gpt_neo":case"donut-swin":e.num_heads="num_heads",e.num_layers="num_layers",e.hidden_size="hidden_size";break;case"bloom":e.num_heads="n_head",e.num_layers="n_layer",e.hidden_size="hidden_size";break;case"mpt":e.num_heads="n_heads",e.num_layers="n_layers",e.hidden_size="d_model";break;case"exaone":e.num_heads="num_key_value_heads",e.num_layers="num_layers",e.dim_kv="head_dim",e.num_attention_heads="num_attention_heads";break;case"youtu":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.dim_kv="qk_head_dim",e.num_attention_heads="num_attention_heads";break;case"t5":case"mt5":case"longt5":e.num_decoder_layers="num_decoder_layers",e.num_decoder_heads="num_heads",e.decoder_dim_kv="d_kv",e.num_encoder_layers="num_layers",e.num_encoder_heads="num_heads",e.encoder_dim_kv="d_kv";break;case"bart":case"mbart":case"marian":case"whisper":case"lite-whisper":case"m2m_100":case"blenderbot":case"blenderbot-small":case"florence2_language":e.num_decoder_layers="decoder_layers",e.num_decoder_heads="decoder_attention_heads",e.decoder_hidden_size="d_model",e.num_encoder_layers="encoder_layers",e.num_encoder_heads="encoder_attention_heads",e.encoder_hidden_size="d_model";break;case"speecht5":e.num_decoder_layers="decoder_layers",e.num_decoder_heads="decoder_attention_heads",e.decoder_hidden_size="hidden_size",e.num_encoder_layers="encoder_layers",e.num_encoder_heads="encoder_attention_heads",e.encoder_hidden_size="hidden_size";break;case"trocr":e.num_encoder_layers=e.num_decoder_layers="decoder_layers",e.num_encoder_heads=e.num_decoder_heads="decoder_attention_heads",e.encoder_hidden_size=e.decoder_hidden_size="d_model";break;case"musicgen_decoder":e.num_encoder_layers=e.num_decoder_layers="num_hidden_layers",e.num_encoder_heads=e.num_decoder_heads="num_attention_heads",e.encoder_hidden_size=e.decoder_hidden_size="hidden_size";break;case"moonshine":e.num_decoder_layers="decoder_num_hidden_layers",e.num_decoder_heads="decoder_num_key_value_heads",e.num_encoder_layers="encoder_num_hidden_layers",e.num_encoder_heads="encoder_num_key_value_heads",e.encoder_hidden_size=e.decoder_hidden_size="hidden_size";break;case"vision-encoder-decoder":let n=Bs(t.decoder),o="num_decoder_layers"in n,i=Me(t,["model_type","is_encoder_decoder"]);return o?(i.num_decoder_layers=n.num_decoder_layers,i.num_decoder_heads=n.num_decoder_heads,i.decoder_hidden_size=n.decoder_hidden_size,i.num_encoder_layers=n.num_encoder_layers,i.num_encoder_heads=n.num_encoder_heads,i.encoder_hidden_size=n.encoder_hidden_size):(i.num_layers=n.num_layers,i.num_heads=n.num_heads,i.hidden_size=n.hidden_size),i}let r={...s,...Me(t,["model_type","multi_query","is_encoder_decoder"])};for(let n in e)r[n]=t[e[n]];return r}function ya(t,e){if(["lfm2","lfm2_moe"].includes(t.model_type)){let s=e?.prefix??"past_key_values",r=s==="present"?"present":"past",n={},{layer_types:o,num_attention_heads:i,num_key_value_heads:a,hidden_size:l,conv_L_cache:c}=t,u=l/i,p=e?.batch_size??1;for(let d=0;d<o.length;++d)if(o[d]==="full_attention")for(let _ of["key","value"])n[`${s}.${d}.${_}`]=[p,a,0,u];else if(o[d]==="conv")n[`${r}_conv.${d}`]=[p,l,c];else throw new Error(`Unsupported layer type: ${o[d]}`);return n}else if(["granitemoehybrid","falcon_h1"].includes(t.model_type)){let s=e?.prefix??"past_key_values",r=s==="present"?"present":"past",n={},{layer_types:o,num_hidden_layers:i,num_attention_heads:a,num_key_value_heads:l,hidden_size:c,mamba_d_conv:u,mamba_n_heads:p,mamba_d_head:d,mamba_d_state:_,mamba_n_groups:f,mamba_expand:h,mamba_d_ssm:x}=t,g=c/a,w=e?.batch_size??1,y=(x??h*c)+2*f*_;for(let b=0;b<i;++b)if((!o||o[b]==="mamba")&&(n[`${r}_conv.${b}`]=[w,y,u],n[`${r}_ssm.${b}`]=[w,p,d,_]),!o||o[b]==="attention")for(let A of["key","value"])n[`${s}.${b}.${A}`]=[w,l,0,g];return n}else if(["qwen3_5","qwen3_5_moe"].includes(t.model_type)){let s=e?.prefix??"past_key_values",r=s==="present"?"present":"past",n={},{head_dim:o,layer_types:i,num_attention_heads:a,num_key_value_heads:l,hidden_size:c,linear_num_value_heads:u,linear_num_key_heads:p,linear_key_head_dim:d,linear_value_head_dim:_,linear_conv_kernel_dim:f}=t.text_config,h=d*p,x=_*u,g=h*2+x,w=o??c/a,y=e?.batch_size??1;for(let b=0;b<i.length;++b)if(i[b]==="full_attention")for(let A of["key","value"])n[`${s}.${b}.${A}`]=[y,l,0,w];else if(i[b]==="linear_attention")n[`${r}_conv.${b}`]=[y,g,f],n[`${r}_recurrent.${b}`]=[y,u,d,_];else throw new Error(`Unsupported layer type: ${i[b]}`);return n}return Yv(t,e)}function Yv(t,{prefix:e="past_key_values",batch_size:s=1}={}){let r={},n=t.normalized_config;if(n.is_encoder_decoder&&"num_encoder_heads"in n&&"num_decoder_heads"in n){let o=n.encoder_dim_kv??n.encoder_hidden_size/n.num_encoder_heads,i=n.decoder_dim_kv??n.decoder_hidden_size/n.num_decoder_heads,a=[s,n.num_encoder_heads,0,o],l=[s,n.num_decoder_heads,0,i];for(let c=0;c<n.num_decoder_layers;++c)r[`${e}.${c}.encoder.key`]=a,r[`${e}.${c}.encoder.value`]=a,r[`${e}.${c}.decoder.key`]=l,r[`${e}.${c}.decoder.value`]=l}else{let o=n.num_heads,i=n.num_layers,a=n.dim_kv??n.hidden_size/(n.num_attention_heads??o);if(n.model_type==="falcon"){let l=[s*o,0,a];for(let c=0;c<i;++c)r[`${e}.${c}.key`]=l,r[`${e}.${c}.value`]=l}else if(n.multi_query){let l=[s*o,0,2*a];for(let c=0;c<i;++c)r[`${e}.${c}.key_value`]=l}else if(n.model_type==="bloom"){let l=[s*o,a,0],c=[s*o,0,a];for(let u=0;u<i;++u)r[`${e}.${u}.key`]=l,r[`${e}.${u}.value`]=c}else if(n.model_type==="openelm")for(let l=0;l<i;++l){let c=[s,o[l],0,a];r[`${e}.${l}.key`]=c,r[`${e}.${l}.value`]=c}else{let l=[s,o,0,a];for(let c=0;c<i;++c)r[`${e}.${c}.key`]=l,r[`${e}.${c}.value`]=l}}return r}var wa=class t{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=Bs(this)}static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main"}={}){r&&!(r instanceof t)&&(r=new t(r));let a=r??await Qv(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i});return new this(a)}},It=class{static async from_pretrained(...e){return wa.from_pretrained(...e)}};function Wp(t,e,s){return t?typeof t=="object"&&t!==null?t.hasOwnProperty(e)?+t[e]:t.hasOwnProperty(s)?+t[s]:0:+t:0}function Vp(t,e){let s=[];for(let r=0;r<e;++r)s.push(`${t}_data${r===0?"":"_"+r}`);return s}async function Fy(t,e,s,r){let n=`${e}${r}.onnx`,o=`${s.subfolder??""}/${n}`;return await yr(t,o,!0,s,Z.IS_NODE_ENV)}async function Dy(t,e,s,r,n,o={}){let i=`${e}${s}.onnx`,a=Z.IS_NODE_ENV,l=[],c=Wp(n,i,e);if(c>0){if(c>Li)throw new Error(`The number of external data chunks (${c}) exceeds the maximum allowed value (${Li}).`);let u=Vp(i,c);for(let p of u){let d=`${r.subfolder??""}/${p}`;l.push(new Promise(async(_,f)=>{let h=await yr(t,d,!0,r,a);_(h instanceof Uint8Array?{path:p,data:h}:p)}))}}else o.externalData!==void 0&&(l=o.externalData.map(async u=>{if(typeof u.data=="string"){let p=await yr(t,u.data,!0,r);return{...u,data:p}}return u}));return Promise.all(l)}async function Jv(t,e,s,r=!1){let n=s.config?.["transformers.js_config"]??{},o=Ui(s.device??n.device,e,{warn:y=>L.info(y)}),i=ay(o),a=n.device_config??{};a.hasOwnProperty(o)&&(n={...n,...a[o]});let l=Bi(s.dtype??n.dtype,e,o,{configDtype:n.dtype,warn:y=>L.info(y)});if(vr.hasOwnProperty(l)){if(o==="webgpu"&&!Z.IS_NODE_ENV&&l===Le.fp16&&!await fy())throw new Error(`The device (${o}) does not support fp16.`)}else throw new Error(`Invalid dtype: ${l}. Should be one of: ${Object.keys(Le).join(", ")}`);let c=n.kv_cache_dtype,u=c?typeof c=="string"?c:c[l]??"float32":void 0;if(u&&!["float32","float16"].includes(u))throw new Error(`Invalid kv_cache_dtype: ${u}. Should be one of: float32, float16`);let p=vr[l],d={...s.session_options};d.executionProviders??=i;let _=n.free_dimension_overrides;_?d.freeDimensionOverrides??=_:o.startsWith("webnn")&&!d.freeDimensionOverrides&&L.warn(`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"]["${o}"]. When 'free_dimension_overrides' is not set, you may experience significant performance degradation.`);let f=Fy(t,e,s,p),h=s.use_external_data_format??n.use_external_data_format,x=await Dy(t,e,p,s,h,d);if(x.length>0&&!Z.IS_NODE_ENV&&(d.externalData=x),r&&o==="webgpu"&&c!==!1){let y=ya(s.config,{prefix:"present"});if(Object.keys(y).length>0&&!kr()){let b={};for(let A in y)b[A]="gpu-buffer";d.preferredOutputLocation=b}}return{buffer_or_path:await f,session_options:d,session_config:{dtype:l,kv_cache_dtype:u,device:o}}}async function je(t,e,s,r=void 0){return Object.fromEntries(await Promise.all(Object.keys(e).map(async n=>{let{buffer_or_path:o,session_options:i,session_config:a}=await Jv(t,e[n],s,n===r),l=await Fi(o,i,a);return[n,l]})))}function jy(t){for(let e in t)ji(t[e])?t[e]=new S(t[e]):typeof t[e]=="object"&&jy(t[e]);return t}async function G(t,e){let s=Zv(t,e);try{let r=Object.fromEntries(Object.entries(s).map(([o,i])=>{let a=i.ort_tensor;return Z.IS_NODE_ENV&&typeof Float16Array<"u"&&a.cpuData instanceof Float16Array&&(a.cpuData=new Uint16Array(a.cpuData.buffer)),[o,a]})),n=await Di(t,r);return jy(n)}catch(r){let n=Object.fromEntries(Object.entries(s).map(([o,i])=>{let a={type:i.type,dims:i.dims,location:i.location};return a.location!=="gpu-buffer"&&(a.data=i.data),[o,a]}));throw L.error(`An error occurred during model execution: "${r}".`),L.error("Inputs given to model:",n),r}}function Zv(t,e){let s=Object.create(null),r=[];for(let i of t.inputNames){let a=e[i];if(!(a instanceof S)){r.push(i);continue}s[i]=kr()?a.clone():a}if(r.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${r.join(", ")}.`);let n=Object.keys(e).length,o=t.inputNames.length;if(n>o){let i=Object.keys(e).filter(a=>!t.inputNames.includes(a));L.warn(`WARNING: Too many inputs were provided (${n} > ${o}). The following inputs will be ignored: "${i.join(", ")}".`)}return s}var de=class{};var z=class extends de{constructor({logits:e,...s}){super(),this.logits=e;let r=Object.values(s);r.length>0&&(this.attentions=r)}},Y=class extends de{constructor({logits:e}){super(),this.logits=e}},ee=class extends de{constructor({logits:e}){super(),this.logits=e}},ae=class extends de{constructor({start_logits:e,end_logits:s}){super(),this.start_logits=e,this.end_logits=s}},Re=class extends de{constructor({logits:e}){super(),this.logits=e}};var ba=class extends de{constructor({alphas:e}){super(),this.alphas=e}};var Ze=class extends ve{_call(e,s){throw Error("`_call` should be implemented in a subclass")}},Fr=class extends ve{_call(e,s){throw Error("`_call` should be implemented in a subclass")}},fs=class extends ve{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,s){let r=s;for(let n of this.processors)r=n(e,r);return r}[Symbol.iterator](){return this.processors.values()}},ka=class extends Ze{constructor(e){super(),this.bos_token_id=e}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length===1){let n=s[r].data;n.fill(-1/0),n[this.bos_token_id]=0}return s}},va=class extends Ze{constructor(e,s){super(),this.max_length=e,this.eos_token_id=Array.isArray(s)?s:[s]}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length===this.max_length-1){let n=s[r].data;n.fill(-1/0);for(let o of this.eos_token_id)n[o]=0}return s}},qs=class extends Ze{constructor(e,s){super(),this.begin_suppress_tokens=e,this.begin_index=s}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length===this.begin_index){let n=s[r].data;for(let o of this.begin_suppress_tokens)n[o]=-1/0}return s}},Ea=class extends Ze{constructor(e,s){super(),this.eos_token_id=Array.isArray(e.eos_token_id)?e.eos_token_id[0]:e.eos_token_id,this.no_timestamps_token_id=e.no_timestamps_token_id,this.timestamp_begin=this.no_timestamps_token_id+1,this.begin_index=s.length,s.at(-1)===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,s){for(let r=0;r<e.length;++r){let n=s[r].data;if(n[this.no_timestamps_token_id]=-1/0,e[r].length===this.begin_index-1){n.fill(-1/0),n[this.timestamp_begin]=0;continue}let o=e[r].slice(this.begin_index),i=o.length>=1&&o[o.length-1]>=this.timestamp_begin,a=o.length<2||o[o.length-2]>=this.timestamp_begin;if(i&&(a?n.subarray(this.timestamp_begin).fill(-1/0):n.subarray(0,this.eos_token_id).fill(-1/0)),e[r].length===this.begin_index&&this.max_initial_timestamp_index!==null){let p=this.timestamp_begin+this.max_initial_timestamp_index;n.subarray(p+1).fill(-1/0)}let l=mc(n),c=Math.log(l.subarray(this.timestamp_begin).map(Math.exp).reduce((p,d)=>p+d)),u=le(l.subarray(0,this.timestamp_begin))[0];c>u&&n.subarray(0,this.timestamp_begin).fill(-1/0)}return s}},Aa=class extends Ze{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){let s=e.length,r=[];for(let o=0;o<s+1-this.no_repeat_ngram_size;++o){let i=[];for(let a=0;a<this.no_repeat_ngram_size;++a)i.push(e[o+a]);r.push(i.map(Number))}let n=new Map;for(let o of r){let i=o.slice(0,o.length-1),a=JSON.stringify(i),l=n.get(a)??[];l.push(o[o.length-1]),n.set(a,l)}return n}getGeneratedNgrams(e,s){let r=s.slice(s.length+1-this.no_repeat_ngram_size,s.length);return e.get(JSON.stringify(r.map(Number)))??[]}calcBannedNgramTokens(e){let s=[];if(e.length+1<this.no_repeat_ngram_size)return s;{let r=this.getNgrams(e);return this.getGeneratedNgrams(r,e)}}_call(e,s){for(let r=0;r<e.length;++r){let n=s[r].data,o=this.calcBannedNgramTokens(e[r]);for(let i of o)n[i]=-1/0}return s}},Ma=class extends Ze{constructor(e){super(),this.penalty=e}_call(e,s){for(let r=0;r<e.length;++r){let n=s[r].data;for(let o of new Set(e[r])){let i=Number(o);n[i]<0?n[i]*=this.penalty:n[i]/=this.penalty}}return s}},Sa=class extends Ze{constructor(e,s){super(),this.min_length=e,this.eos_token_id=Array.isArray(s)?s:[s]}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length<this.min_length){let n=s[r].data;for(let o of this.eos_token_id)n[o]=-1/0}return s}},Oa=class extends Ze{constructor(e,s,r){super(),this.prompt_length_to_skip=e,this.min_new_tokens=s,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,s){for(let r=0;r<e.length;++r)if(e[r].length-this.prompt_length_to_skip<this.min_new_tokens){let o=s[r].data;for(let i of this.eos_token_id)o[i]=-1/0}return s}},Ia=class extends Ze{constructor(e,s){super(),this.bad_words_ids=e,this.eos_token_id=Array.isArray(s)?s:[s]}_call(e,s){for(let r=0;r<e.length;++r){let n=s[r].data,o=e[r];for(let i of this.bad_words_ids){if(o.length<i.length-1)continue;let a=!0;for(let l=1;l<=i.length-1;++l)if(i.at(-l-1)!=o.at(-l)){a=!1;break}a&&(n[i.at(-1)]=-1/0)}}return s}},Ta=class extends Ze{constructor(e){if(super(),e<=1)throw new Error(`Require guidance scale >1 to use the classifier free guidance processor, got guidance scale ${e}.`);this.guidance_scale=e}_call(e,s){if(s.dims[0]!==2*e.length)throw new Error(`Logits should have twice the batch size of the input ids, the first half of batches corresponding to the conditional inputs, and the second half of batches corresponding to the unconditional inputs. Got batch size ${s.dims[0]} for the logits and ${e.length} for the input ids.`);let r=e.length,n=s.slice([0,r],null),o=s.slice([r,s.dims[0]],null);for(let i=0;i<o.data.length;++i)o.data[i]+=(n.data[i]-o.data[i])*this.guidance_scale;return o}},za=class extends Fr{constructor(e){if(super(),typeof e!="number"||e<=0){let s=`\`temperature\` (=${e}) must be a strictly positive float, otherwise your next token scores will be invalid.`;e===0&&(s+=" If you're looking for greedy decoding strategies, set `do_sample=false`.")}this.temperature=e}_call(e,s){let r=s.data;for(let n=0;n<r.length;++n)r[n]/=this.temperature;return s}},Uy=class extends Fr{constructor(e,{filter_value:s=-1/0,min_tokens_to_keep:r=1}={}){if(super(),e<0||e>1)throw new Error(`\`top_p\` must be a float > 0 and < 1, but is ${e}`);if(!Number.isInteger(r)||r<1)throw new Error(`\`min_tokens_to_keep\` must be a positive integer, but is ${r}`);this.top_p=e,this.filter_value=s,this.min_tokens_to_keep=r}},By=class extends Fr{constructor(e,{filter_value:s=-1/0,min_tokens_to_keep:r=1}={}){if(super(),!Number.isInteger(e)||e<0)throw new Error(`\`top_k\` must be a positive integer, but is ${e}`);this.top_k=Math.max(e,r),this.filter_value=s}};var Gs=class{max_length=20;max_new_tokens=null;min_length=0;min_new_tokens=null;early_stopping=!1;max_time=null;do_sample=!1;num_beams=1;num_beam_groups=1;penalty_alpha=null;use_cache=!0;temperature=1;top_k=50;top_p=1;typical_p=1;epsilon_cutoff=0;eta_cutoff=0;diversity_penalty=0;repetition_penalty=1;encoder_repetition_penalty=1;length_penalty=1;no_repeat_ngram_size=0;bad_words_ids=null;force_words_ids=null;renormalize_logits=!1;constraints=null;forced_bos_token_id=null;forced_eos_token_id=null;remove_invalid_values=!1;exponential_decay_length_penalty=null;suppress_tokens=null;streamer=null;begin_suppress_tokens=null;forced_decoder_ids=null;guidance_scale=null;num_return_sequences=1;output_attentions=!1;output_hidden_states=!1;output_scores=!1;return_dict_in_generate=!1;pad_token_id=null;bos_token_id=null;eos_token_id=null;encoder_no_repeat_ngram_size=0;decoder_start_token_id=null;generation_kwargs={};constructor(e){Object.assign(this,Me(e,Object.getOwnPropertyNames(this)))}};var Ws=class extends ve{_call(e,s){throw Error("StoppingCriteria needs to be subclassed")}},Pa=class t extends ve{constructor(){super(),this.criteria=[]}push(e){this.criteria.push(e)}extend(e){e instanceof t?e=e.criteria:e instanceof Ws&&(e=[e]),this.criteria.push(...e)}_call(e,s){let r=new Array(e.length).fill(!1);for(let n of this.criteria){let o=n(e,s);for(let i=0;i<r.length;++i)r[i]||=o[i]}return r}[Symbol.iterator](){return this.criteria.values()}},Ca=class extends Ws{constructor(e,s=null){super(),this.max_length=e,this.max_position_embeddings=s}_call(e){return e.map(s=>s.length>=this.max_length)}},Na=class extends Ws{constructor(e){super(),Array.isArray(e)||(e=[e]),this.eos_token_id=e}_call(e,s){return e.map(r=>{let n=r.at(-1);return this.eos_token_id.some(o=>n==o)})}},qy=class extends Ws{constructor(){super(),this.interrupted=!1}interrupt(){this.interrupted=!0}reset(){this.interrupted=!1}_call(e,s){return new Array(e.length).fill(this.interrupted)}};var ms=class extends ve{constructor(e){super(),this.generation_config=e}async _call(e){return this.sample(e)}async sample(e){throw Error("sample should be implemented in subclasses.")}getLogits(e,s){let r=e.dims.at(-1),n=e.data;if(s===-1)n=n.slice(-r);else{let o=s*r;n=n.slice(o,o+r)}return n}randomSelect(e){return hy(e)}static getSampler(e){if(e.do_sample)return new Kp(e);if(e.num_beams>1)return new Xp(e);if(e.num_return_sequences>1)throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${e.num_return_sequences}.`);return new Hp(e)}},Hp=class extends ms{async sample(e){let s=le(e.data)[1];return[[BigInt(s),0]]}},Kp=class extends ms{async sample(e){let s=e.dims.at(-1);this.generation_config.top_k>0&&(s=Math.min(this.generation_config.top_k,s));let[r,n]=await at(e,s),o=pe(r.data);return Array.from({length:this.generation_config.num_beams},()=>{let i=this.randomSelect(o);return[n.data[i],Math.log(o[i])]})}},Xp=class extends ms{async sample(e){let s=e.dims.at(-1);this.generation_config.top_k>0&&(s=Math.min(this.generation_config.top_k,s));let[r,n]=await at(e,s),o=pe(r.data);return Array.from({length:this.generation_config.num_beams},(i,a)=>[n.data[a],Math.log(o[a])])}};var Dr=null;function Wy(t){Dr=t}function Qp(t){if(t instanceof S)return t;if(t.length===0)throw Error("items must be non-empty");if(Array.isArray(t[0])){if(t.some(e=>e.length!==t[0].length))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.");return new S("int64",BigInt64Array.from(t.flat().map(e=>BigInt(e))),[t.length,t[0].length])}else return new S("int64",BigInt64Array.from(t.map(e=>BigInt(e))),[1,t.length])}function Yp(t){return new S("bool",[t],[1])}var I={EncoderOnly:0,EncoderDecoder:1,Seq2Seq:2,Vision2Seq:3,DecoderOnly:4,DecoderOnlyWithoutHead:5,MaskGeneration:6,ImageTextToText:7,Musicgen:8,MultiModality:9,Phi3V:10,AudioTextToText:11,AutoEncoder:12,ImageAudioTextToText:13,Supertonic:14,Chatterbox:15},Gy={[I.DecoderOnly]:{can_generate:!0,forward:Ge,prepare_inputs:jr},[I.DecoderOnlyWithoutHead]:{can_generate:!1,forward:Ge,prepare_inputs:jr},[I.Seq2Seq]:{can_generate:!0,forward:La,prepare_inputs:Ur},[I.Vision2Seq]:{can_generate:!0,forward:La,prepare_inputs:Ur},[I.Musicgen]:{can_generate:!0,forward:La},[I.EncoderDecoder]:{can_generate:!1,forward:La},[I.ImageTextToText]:{can_generate:!0,forward:sE,prepare_inputs:$a},[I.AudioTextToText]:{can_generate:!0,forward:tE,prepare_inputs:$a},[I.Phi3V]:{can_generate:!0,prepare_inputs:$a},[I.ImageAudioTextToText]:{can_generate:!0,prepare_inputs:$a},[I.MultiModality]:{can_generate:!0},[I.AutoEncoder]:{can_generate:!1,forward:eE},[I.Chatterbox]:{can_generate:!0,forward:et},default:{can_generate:!1,forward:et}},gt=new Map,Ra=new Map,hs=new Map,m=class extends ve{main_input_name="input_ids";forward_params=["input_ids","attention_mask"];_return_dict_in_generate_keys=null;constructor(e,s,r){super(),this.config=e,this.sessions=s,this.configs=r;let n=hs.get(this.constructor),o=gt.get(n),i=Gy[o]??Gy.default;this.can_generate=i.can_generate,this._forward=i.forward,this._prepare_inputs_for_generation=i.prepare_inputs,this.can_generate&&this.forward_params.push("past_key_values"),this.custom_config=this.config["transformers.js_config"]??{}}async dispose(){let e=[];for(let s of Object.values(this.sessions))e.push(s.release?.());return await Promise.all(e)}static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main",model_file_name:a=null,subfolder:l="onnx",device:c=null,dtype:u=null,use_external_data_format:p=null,session_options:d={}}={}){let _={progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:u,use_external_data_format:p,session_options:d},f=hs.get(this),h=gt.get(f);r=_.config=await It.from_pretrained(e,_);let x;if(h===I.DecoderOnly)x=await Promise.all([je(e,{model:_.model_file_name??"model"},_,"model"),Tt(e,{generation_config:"generation_config.json"},_)]);else if(h===I.Seq2Seq||h===I.Vision2Seq)x=await Promise.all([je(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_,"decoder_model_merged"),Tt(e,{generation_config:"generation_config.json"},_)]);else if(h===I.MaskGeneration)x=await Promise.all([je(e,{model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"},_)]);else if(h===I.EncoderDecoder)x=await Promise.all([je(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_,"decoder_model_merged")]);else if(h===I.ImageTextToText){let g={embed_tokens:"embed_tokens",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};r.is_encoder_decoder&&(g.model="encoder_model"),x=await Promise.all([je(e,g,_,"decoder_model_merged"),Tt(e,{generation_config:"generation_config.json"},_)])}else if(h===I.AudioTextToText){let g={embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",decoder_model_merged:"decoder_model_merged"};x=await Promise.all([je(e,g,_,"decoder_model_merged"),Tt(e,{generation_config:"generation_config.json"},_)])}else if(h===I.ImageAudioTextToText){let g={embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};x=await Promise.all([je(e,g,_),Tt(e,{generation_config:"generation_config.json"},_)])}else if(h===I.Musicgen)x=await Promise.all([je(e,{model:"text_encoder",decoder_model_merged:"decoder_model_merged",encodec_decode:"encodec_decode"},_,"decoder_model_merged"),Tt(e,{generation_config:"generation_config.json"},_)]);else if(h===I.MultiModality)x=await Promise.all([je(e,{prepare_inputs_embeds:"prepare_inputs_embeds",model:"language_model",lm_head:"lm_head",gen_head:"gen_head",gen_img_embeds:"gen_img_embeds",image_decode:"image_decode"},_,"model"),Tt(e,{generation_config:"generation_config.json"},_)]);else if(h===I.Phi3V)x=await Promise.all([je(e,{prepare_inputs_embeds:"prepare_inputs_embeds",model:"model",vision_encoder:"vision_encoder"},_,"model"),Tt(e,{generation_config:"generation_config.json"},_)]);else if(h===I.Chatterbox)x=await Promise.all([je(e,{embed_tokens:"embed_tokens",speech_encoder:"speech_encoder",model:"language_model",conditional_decoder:"conditional_decoder"},_,"model"),Tt(e,{generation_config:"generation_config.json"},_)]);else if(h===I.AutoEncoder)x=await Promise.all([je(e,{encoder_model:"encoder_model",decoder_model:"decoder_model"},_)]);else if(h===I.Supertonic)x=await Promise.all([je(e,{text_encoder:"text_encoder",latent_denoiser:"latent_denoiser",voice_decoder:"voice_decoder"},_)]);else{if(h===void 0){let g=f??r?.model_type;g!=="custom"&&L.warn(`Model type for '${g}' not found, assuming encoder-only architecture. Please report this at ${Rt}.`)}x=await Promise.all([je(e,{model:_.model_file_name??"model"},_)])}return new this(r,...x)}async _call(e){return await this.forward(e)}async forward(e){return await this._forward(this,e)}get generation_config(){return this.configs?.generation_config??null}_get_logits_processor(e,s,r=null){let n=new fs;if(e.repetition_penalty!==null&&e.repetition_penalty!==1&&n.push(new Ma(e.repetition_penalty)),e.no_repeat_ngram_size!==null&&e.no_repeat_ngram_size>0&&n.push(new Aa(e.no_repeat_ngram_size)),e.bad_words_ids!==null&&n.push(new Ia(e.bad_words_ids,e.eos_token_id)),e.min_length!==null&&e.eos_token_id!==null&&e.min_length>0&&n.push(new Sa(e.min_length,e.eos_token_id)),e.min_new_tokens!==null&&e.eos_token_id!==null&&e.min_new_tokens>0&&n.push(new Oa(s,e.min_new_tokens,e.eos_token_id)),e.forced_bos_token_id!==null&&n.push(new ka(e.forced_bos_token_id)),e.forced_eos_token_id!==null&&n.push(new va(e.max_length,e.forced_eos_token_id)),e.begin_suppress_tokens!==null){let o=s>1||e.forced_bos_token_id===null?s:s+1;n.push(new qs(e.begin_suppress_tokens,o))}return e.guidance_scale!==null&&e.guidance_scale>1&&n.push(new Ta(e.guidance_scale)),e.temperature===0&&e.do_sample&&(L.warn("`do_sample` changed to false because `temperature: 0` implies greedy sampling (always selecting the most likely token), which is incompatible with `do_sample: true`."),e.do_sample=!1),e.do_sample&&e.temperature!==null&&e.temperature!==1&&n.push(new za(e.temperature)),r!==null&&n.extend(r),n}_prepare_generation_config(e,s,r=Gs){let n={...this.config};for(let i of["decoder","generator","text_config"])i in n&&Object.assign(n,n[i]);let o=new r(n);return Object.assign(o,this.generation_config??{}),e&&Object.assign(o,e),s&&Object.assign(o,Me(s,Object.getOwnPropertyNames(o))),o}_get_stopping_criteria(e,s=null){let r=new Pa;return e.max_length!==null&&r.push(new Ca(e.max_length,this.config.max_position_embeddings??null)),e.eos_token_id!==null&&r.push(new Na(e.eos_token_id)),s&&r.extend(s),r}_validate_model_class(){if(!this.can_generate){let e=[Dr.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,Dr.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,Dr.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,Dr.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES].filter(Boolean),s=hs.get(this.constructor),r=new Set,n=this.config.model_type;for(let i of e){let a=i?.get(n);a&&r.add(a)}let o=`The current model class (${s}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw r.size>0&&(o+=` Please use the following class instead: ${[...r].join(", ")}`),Error(o)}}prepare_inputs_for_generation(...e){if(!this._prepare_inputs_for_generation)throw new Error("prepare_inputs_for_generation is not implemented for this model.");return this._prepare_inputs_for_generation(this,...e)}_update_model_kwargs_for_generation({generated_input_ids:e,outputs:s,model_inputs:r,is_encoder_decoder:n}){return r.past_key_values=this.getPastKeyValues(s,r.past_key_values),r.input_ids=new S("int64",e.flat(),[e.length,1]),n?"decoder_attention_mask"in r:r.attention_mask=ie([r.attention_mask,Oe([r.attention_mask.dims[0],1])],1),r.position_ids=null,r}_prepare_model_inputs({inputs:e,bos_token_id:s,model_kwargs:r}){let n=Me(r,this.forward_params),o=this.main_input_name;if(o in n){if(e)throw new Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else n[o]=e;return{inputs_tensor:n[o],model_inputs:n,model_input_name:o}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:e,model_inputs:s,model_input_name:r,generation_config:n}){if(this.sessions.model.inputNames.includes("inputs_embeds")&&!s.inputs_embeds&&"_prepare_inputs_embeds"in this){let{input_ids:i,pixel_values:a,attention_mask:l,...c}=s,u=await this._prepare_inputs_embeds(s);s={...c,...Me(u,["inputs_embeds","attention_mask"])}}let{last_hidden_state:o}=await et(this,s);if(n.guidance_scale!==null&&n.guidance_scale>1)o=ie([o,Ar(o,0)],0),"attention_mask"in s&&(s.attention_mask=ie([s.attention_mask,Mc(s.attention_mask)],0));else if(s.decoder_input_ids){let i=Qp(s.decoder_input_ids).dims[0];if(i!==o.dims[0]){if(o.dims[0]!==1)throw new Error(`The encoder outputs have a different batch size (${o.dims[0]}) than the decoder inputs (${i}).`);o=ie(Array.from({length:i},()=>o),0)}}return s.encoder_outputs=o,s}_prepare_decoder_input_ids_for_generation({batch_size:e,model_input_name:s,model_kwargs:r,decoder_start_token_id:n,bos_token_id:o,generation_config:i}){let{decoder_input_ids:a,...l}=r;if(!(a instanceof S)){if(a)Array.isArray(a[0])||(a=Array.from({length:e},()=>a));else if(n??=o,this.config.model_type==="musicgen")a=Array.from({length:e*this.config.decoder.num_codebooks},()=>[n]);else if(Array.isArray(n)){if(n.length!==e)throw new Error(`\`decoder_start_token_id\` expcted to have length ${e} but got ${n.length}`);a=n}else a=Array.from({length:e},()=>[n]);a=Qp(a)}return r.decoder_attention_mask=Hi(a),{input_ids:a,model_inputs:l}}async generate({inputs:e=null,generation_config:s=null,logits_processor:r=null,stopping_criteria:n=null,streamer:o=null,...i}){this._validate_model_class(),s=this._prepare_generation_config(s,i);let{inputs_tensor:a,model_inputs:l,model_input_name:c}=this._prepare_model_inputs({inputs:e,model_kwargs:i}),u=this.config.is_encoder_decoder;u&&("encoder_outputs"in l||(l=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:a,model_inputs:l,model_input_name:c,generation_config:s})));let p;u?{input_ids:p,model_inputs:l}=this._prepare_decoder_input_ids_for_generation({batch_size:l[c].dims.at(0),model_input_name:c,model_kwargs:l,decoder_start_token_id:s.decoder_start_token_id,bos_token_id:s.bos_token_id,generation_config:s}):p=l[c];let d=p.dims.at(-1);s.max_new_tokens!==null&&(s.max_length=d+s.max_new_tokens);let _=this._get_logits_processor(s,d,r),f=this._get_stopping_criteria(s,n),h=l[c].dims.at(0),x=ms.getSampler(s),g=new Array(h).fill(0),w=p.tolist();o&&o.put(w);let y,b={},A={};for(;;){if(l=this.prepare_inputs_for_generation(w,l,s),y=await this.forward(l),s.return_dict_in_generate)if(s.output_attentions){let W=this.getAttentions(y);for(let j in W)j in b||(b[j]=[]),b[j].push(W[j])}else this._return_dict_in_generate_keys&&Object.assign(A,Me(y,this._return_dict_in_generate_keys));let N=y.logits.slice(null,-1,null).to("float32"),D=_(w,N),F=[];for(let W=0;W<D.dims.at(0);++W){let j=D[W],Q=await x(j);for(let[K,oe]of Q){let te=BigInt(K);g[W]+=oe,w[W].push(te),F.push([te]);break}}if(o&&o.put(F),f(w).every(W=>W))break;l=this._update_model_kwargs_for_generation({generated_input_ids:F,outputs:y,model_inputs:l,is_encoder_decoder:u})}o&&o.end();let k=this.getPastKeyValues(y,l.past_key_values,!0),O=new S("int64",w.flat(),[w.length,w[0].length]);if(s.return_dict_in_generate)return{sequences:O,past_key_values:k,...b,...A};for(let N of Object.values(y))N.location==="gpu-buffer"&&N.dispose();return O}getPastKeyValues(e,s,r=!1){let n=Object.create(null);for(let o in e)if(o.startsWith("present")){let i=o.replace("present_ssm","past_ssm").replace("present_conv","past_conv").replace("present_recurrent","past_recurrent").replace("present","past_key_values"),a=o.includes("encoder");if(a&&s?n[i]=s[i]:n[i]=e[o],s&&(!a||r)){let l=s[i];l.location==="gpu-buffer"&&l.dispose()}}return n}getAttentions(e){let s={};for(let r of["cross_attentions","encoder_attentions","decoder_attentions"])for(let n in e)n.startsWith(r)&&(r in s||(s[r]=[]),s[r].push(e[n]));return s}addPastKeyValues(e,s){if(s)Object.assign(e,s);else{let r=this.sessions.decoder_model_merged??this.sessions.model,n=(e[this.main_input_name]??e.attention_mask)?.dims?.[0]??1,o=r?.config?.kv_cache_dtype??"float32",i=o==="float16"?Cs.float16:Cs.float32,a=ya(this.config,{batch_size:n});for(let l in a){let c=a[l].reduce((u,p)=>u*p,1);e[l]=new S(o,new i(c),a[l])}}}async encode_image({pixel_values:e}){return(await G(this.sessions.vision_encoder,{pixel_values:e})).image_features}async encode_text({input_ids:e}){return(await G(this.sessions.embed_tokens,{input_ids:e})).inputs_embeds}async encode_audio({audio_values:e}){return(await G(this.sessions.audio_encoder,{audio_values:e})).audio_features}};async function La(t,e){let{encoder_outputs:s,input_ids:r,decoder_input_ids:n,...o}=e;if(!s){let i=Me(e,t.sessions.model.inputNames);s=(await et(t,i)).last_hidden_state}return o.input_ids=n,o.encoder_hidden_states=s,t.sessions.decoder_model_merged.inputNames.includes("encoder_attention_mask")&&(o.encoder_attention_mask=e.attention_mask),await Ge(t,o,!0)}async function et(t,e){let s=t.sessions.model,r=Me(e,s.inputNames);if(s.inputNames.includes("inputs_embeds")&&!r.inputs_embeds){if(!e.input_ids)throw new Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");r.inputs_embeds=await t.encode_text({input_ids:e.input_ids})}if(s.inputNames.includes("token_type_ids")&&!r.token_type_ids){if(!r.input_ids)throw new Error("Both `input_ids` and `token_type_ids` are missing in the model inputs.");r.token_type_ids=Mc(r.input_ids)}if(s.inputNames.includes("pixel_mask")&&!r.pixel_mask){if(!r.pixel_values)throw new Error("Both `pixel_values` and `pixel_mask` are missing in the model inputs.");let n=r.pixel_values.dims;r.pixel_mask=Oe([n[0],n[2],n[3]])}return await G(s,r)}async function eE(t,e){let s=await t.encode(e);return await t.decode(s)}async function Ge(t,e,s=!1){let r=t.sessions[s?"decoder_model_merged":"model"],{past_key_values:n,...o}=e;if(r.inputNames.includes("use_cache_branch")&&(o.use_cache_branch=Yp(!!n)),r.inputNames.includes("position_ids")&&o.attention_mask&&!o.position_ids){let a=["paligemma","gemma3_text","gemma3"].includes(t.config.model_type)?1:0;o.position_ids=rE(o,n,a)}t.addPastKeyValues(o,n);let i=Me(o,r.inputNames);return await G(r,i)}async function Vy(t,{encode_function:e,merge_function:s,modality_input_name:r,modality_output_name:n,input_ids:o=null,attention_mask:i=null,position_ids:a=null,inputs_embeds:l=null,past_key_values:c=null,generation_config:u=null,logits_processor:p=null,...d}){let _=d[r];if(!l){if(l=await t.encode_text({input_ids:o,...d}),_&&o.dims[1]!==1){let h=await e({[r]:_,...d});({inputs_embeds:l,attention_mask:i}=s({[n]:h,inputs_embeds:l,input_ids:o,attention_mask:i}))}else if(c&&_&&o.dims[1]===1){let h=o.dims[1],x=Object.values(c)[0].dims.at(-2);i=ie([Oe([o.dims[0],x]),i.slice(null,[i.dims[1]-h,i.dims[1]])],1)}}if(!a&&["qwen2_vl","qwen2_5_vl_text","qwen3_vl_text","qwen3_5_text","qwen3_5_moe_text"].includes(t.config.model_type)){let{image_grid_thw:h,video_grid_thw:x}=d;[a]=t.get_rope_index(o,h,x,i)}return await Ge(t,{inputs_embeds:l,past_key_values:c,attention_mask:i,position_ids:a,generation_config:u,logits_processor:p},!0)}async function tE(t,e){return await Vy(t,{...e,modality_input_name:"audio_values",modality_output_name:"audio_features",encode_function:t.encode_audio.bind(t),merge_function:t._merge_input_ids_with_audio_features.bind(t)})}async function sE(t,e){return await Vy(t,{...e,modality_input_name:"pixel_values",modality_output_name:"image_features",encode_function:t.encode_image.bind(t),merge_function:t._merge_input_ids_with_image_features.bind(t)})}function Jp(t,e=0){let[s,r]=t.dims,n=t.data,o=new BigInt64Array(n.length);for(let i=0;i<s;++i){let a=i*r,l=BigInt(e);for(let c=0;c<r;++c){let u=a+c;n[u]===0n?o[u]=BigInt(1):(o[u]=l,l+=n[u])}}return{data:o,dims:t.dims}}function rE(t,e=null,s=0){let{input_ids:r,inputs_embeds:n,attention_mask:o}=t,{data:i,dims:a}=Jp(o,s),l=new S("int64",i,a);if(e){let c=-(r??n).dims.at(1);l=l.slice(null,[c,null])}return l}function jr(t,e,s,r){let n=s.past_key_values?Object.values(s.past_key_values)[0].dims.at(-2):0;if(!s.attention_mask){let o;for(let i of["input_ids","inputs_embeds","position_ids"])if(s[i]){o=s[i].dims;break}if(!o)throw new Error("attention_mask is not provided, and unable to infer its shape from model inputs.");s.attention_mask=Oe([o[0],n+o[1]])}if(s.past_key_values){let{input_ids:o,attention_mask:i}=s;i&&i.dims[1]>o.dims[1]||n<o.dims[1]&&(s.input_ids=o.slice(null,[n,null]))}return s}function Ur(t,e,s,r){return s.past_key_values&&(e=e.map(n=>[n.at(-1)])),{...s,decoder_input_ids:Qp(e)}}function $a(t,...e){return t.config.is_encoder_decoder?Ur(t,...e):jr(t,...e)}function Hy({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n}){let o=r.tolist().map(c=>c.reduce((u,p,d)=>(p==t&&u.push(d),u),[])),i=o.reduce((c,u)=>c+u.length,0),a=s.dims[0];if(i!==a)throw new Error(`Number of tokens and features do not match: tokens: ${i}, features ${a}`);let l=0;for(let c=0;c<o.length;++c){let u=o[c],p=e[c];for(let d=0;d<u.length;++d)p[u[d]].data.set(s[l++].data)}return{inputs_embeds:e,attention_mask:n}}function wt({image_token_id:t,inputs_embeds:e,image_features:s,input_ids:r,attention_mask:n}){return Hy({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n})}function Fa({audio_token_id:t,inputs_embeds:e,audio_features:s,input_ids:r,attention_mask:n}){return Hy({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n})}async function Tt(t,e,s){return Object.fromEntries(await Promise.all(Object.keys(e).map(async r=>{let n=await Te(t,e[r],!1,s);return[r,n]})))}var Xo={};As(Xo,{ASTForAudioClassification:()=>ud,ASTModel:()=>cd,ASTPreTrainedModel:()=>Wr,AfmoeForCausalLM:()=>id,AfmoeModel:()=>od,AfmoePreTrainedModel:()=>qr,AlbertForMaskedLM:()=>sd,AlbertForQuestionAnswering:()=>td,AlbertForSequenceClassification:()=>ed,AlbertModel:()=>Zp,AlbertPreTrainedModel:()=>xs,ApertusForCausalLM:()=>nd,ApertusModel:()=>rd,ApertusPreTrainedModel:()=>Br,ArceeForCausalLM:()=>ld,ArceeModel:()=>ad,ArceePreTrainedModel:()=>Gr,BartForConditionalGeneration:()=>dd,BartForSequenceClassification:()=>_d,BartModel:()=>pd,BartPretrainedModel:()=>Vs,BeitForImageClassification:()=>md,BeitModel:()=>fd,BeitPreTrainedModel:()=>Vr,BertForMaskedLM:()=>xd,BertForQuestionAnswering:()=>yd,BertForSequenceClassification:()=>gd,BertForTokenClassification:()=>wd,BertModel:()=>hd,BertPreTrainedModel:()=>jt,BlenderbotForConditionalGeneration:()=>kd,BlenderbotModel:()=>bd,BlenderbotPreTrainedModel:()=>Hr,BlenderbotSmallForConditionalGeneration:()=>Ed,BlenderbotSmallModel:()=>vd,BlenderbotSmallPreTrainedModel:()=>Kr,BloomForCausalLM:()=>Md,BloomModel:()=>Ad,BloomPreTrainedModel:()=>Xr,CLIPModel:()=>Nd,CLIPPreTrainedModel:()=>yt,CLIPSegForImageSegmentation:()=>Dd,CLIPSegModel:()=>Fd,CLIPSegPreTrainedModel:()=>en,CLIPTextModel:()=>Ld,CLIPTextModelWithProjection:()=>Zr,CLIPVisionModel:()=>$d,CLIPVisionModelWithProjection:()=>Rd,CamembertForMaskedLM:()=>Od,CamembertForQuestionAnswering:()=>zd,CamembertForSequenceClassification:()=>Id,CamembertForTokenClassification:()=>Td,CamembertModel:()=>Sd,CamembertPreTrainedModel:()=>Ut,ChatterboxModel:()=>Qr,ChatterboxPreTrainedModel:()=>Da,ChineseCLIPModel:()=>Pd,ChineseCLIPPreTrainedModel:()=>ja,ClapAudioModelWithProjection:()=>Jr,ClapModel:()=>Cd,ClapPreTrainedModel:()=>Hs,ClapTextModelWithProjection:()=>Yr,CodeGenForCausalLM:()=>Ud,CodeGenModel:()=>jd,CodeGenPreTrainedModel:()=>tn,Cohere2ForCausalLM:()=>Wd,Cohere2Model:()=>Gd,Cohere2PreTrainedModel:()=>rn,CohereForCausalLM:()=>qd,CohereModel:()=>Bd,CoherePreTrainedModel:()=>sn,ConvBertForMaskedLM:()=>Hd,ConvBertForQuestionAnswering:()=>Qd,ConvBertForSequenceClassification:()=>Kd,ConvBertForTokenClassification:()=>Xd,ConvBertModel:()=>Vd,ConvBertPreTrainedModel:()=>Bt,ConvNextForImageClassification:()=>Jd,ConvNextModel:()=>Yd,ConvNextPreTrainedModel:()=>nn,ConvNextV2ForImageClassification:()=>e_,ConvNextV2Model:()=>Zd,ConvNextV2PreTrainedModel:()=>on,DFineForObjectDetection:()=>n_,DFineModel:()=>r_,DFinePreTrainedModel:()=>ln,DINOv3ConvNextModel:()=>O_,DINOv3ConvNextPreTrainedModel:()=>Ha,DINOv3ViTModel:()=>I_,DINOv3ViTPreTrainedModel:()=>Ka,DPTForDepthEstimation:()=>R_,DPTModel:()=>$_,DPTPreTrainedModel:()=>fn,DacDecoderModel:()=>un,DacDecoderOutput:()=>Ba,DacEncoderModel:()=>cn,DacEncoderOutput:()=>Ua,DacModel:()=>o_,DacPreTrainedModel:()=>Ks,DebertaForMaskedLM:()=>a_,DebertaForQuestionAnswering:()=>u_,DebertaForSequenceClassification:()=>l_,DebertaForTokenClassification:()=>c_,DebertaModel:()=>i_,DebertaPreTrainedModel:()=>qt,DebertaV2ForMaskedLM:()=>d_,DebertaV2ForQuestionAnswering:()=>m_,DebertaV2ForSequenceClassification:()=>__,DebertaV2ForTokenClassification:()=>f_,DebertaV2Model:()=>p_,DebertaV2PreTrainedModel:()=>Gt,DecisionTransformerModel:()=>h_,DecisionTransformerPreTrainedModel:()=>qa,DeiTForImageClassification:()=>g_,DeiTModel:()=>x_,DeiTPreTrainedModel:()=>pn,DepthAnythingForDepthEstimation:()=>w_,DepthAnythingPreTrainedModel:()=>Ga,DepthProForDepthEstimation:()=>y_,DepthProPreTrainedModel:()=>Wa,DetrForObjectDetection:()=>k_,DetrForSegmentation:()=>v_,DetrModel:()=>b_,DetrObjectDetectionOutput:()=>Qs,DetrPreTrainedModel:()=>Xs,DetrSegmentationOutput:()=>Va,Dinov2ForImageClassification:()=>A_,Dinov2Model:()=>E_,Dinov2PreTrainedModel:()=>dn,Dinov2WithRegistersForImageClassification:()=>S_,Dinov2WithRegistersModel:()=>M_,Dinov2WithRegistersPreTrainedModel:()=>_n,DistilBertForMaskedLM:()=>N_,DistilBertForQuestionAnswering:()=>C_,DistilBertForSequenceClassification:()=>z_,DistilBertForTokenClassification:()=>P_,DistilBertModel:()=>T_,DistilBertPreTrainedModel:()=>Wt,DonutSwinModel:()=>L_,DonutSwinPreTrainedModel:()=>Xa,EdgeTamModel:()=>bx,EfficientNetForImageClassification:()=>D_,EfficientNetModel:()=>F_,EfficientNetPreTrainedModel:()=>mn,ElectraForMaskedLM:()=>U_,ElectraForQuestionAnswering:()=>G_,ElectraForSequenceClassification:()=>B_,ElectraForTokenClassification:()=>q_,ElectraModel:()=>j_,ElectraPreTrainedModel:()=>Vt,Ernie4_5ForCausalLM:()=>V_,Ernie4_5Model:()=>W_,Ernie4_5PretrainedModel:()=>hn,EsmForMaskedLM:()=>K_,EsmForSequenceClassification:()=>X_,EsmForTokenClassification:()=>Q_,EsmModel:()=>H_,EsmPreTrainedModel:()=>gs,ExaoneForCausalLM:()=>J_,ExaoneModel:()=>Y_,ExaonePreTrainedModel:()=>xn,FalconForCausalLM:()=>ef,FalconH1ForCausalLM:()=>sf,FalconH1Model:()=>tf,FalconH1PreTrainedModel:()=>wn,FalconModel:()=>Z_,FalconPreTrainedModel:()=>gn,FastViTForImageClassification:()=>nf,FastViTModel:()=>rf,FastViTPreTrainedModel:()=>yn,Florence2ForConditionalGeneration:()=>of,Florence2PreTrainedModel:()=>Qa,GLPNForDepthEstimation:()=>hf,GLPNModel:()=>mf,GLPNPreTrainedModel:()=>Mn,GPT2LMHeadModel:()=>Mf,GPT2Model:()=>Af,GPT2PreTrainedModel:()=>zn,GPTBigCodeForCausalLM:()=>gf,GPTBigCodeModel:()=>xf,GPTBigCodePreTrainedModel:()=>Sn,GPTJForCausalLM:()=>Of,GPTJModel:()=>Sf,GPTJPreTrainedModel:()=>Pn,GPTNeoForCausalLM:()=>yf,GPTNeoModel:()=>wf,GPTNeoPreTrainedModel:()=>On,GPTNeoXForCausalLM:()=>kf,GPTNeoXModel:()=>bf,GPTNeoXPreTrainedModel:()=>In,Gemma2ForCausalLM:()=>uf,Gemma2Model:()=>cf,Gemma2PreTrainedModel:()=>kn,Gemma3ForCausalLM:()=>df,Gemma3Model:()=>pf,Gemma3PreTrainedModel:()=>vn,Gemma3nForConditionalGeneration:()=>En,Gemma3nPreTrainedModel:()=>Ya,GemmaForCausalLM:()=>lf,GemmaModel:()=>af,GemmaPreTrainedModel:()=>bn,GlmForCausalLM:()=>ff,GlmModel:()=>_f,GlmPreTrainedModel:()=>An,GptOssForCausalLM:()=>Ef,GptOssModel:()=>vf,GptOssPreTrainedModel:()=>Tn,GraniteForCausalLM:()=>Tf,GraniteModel:()=>If,GraniteMoeHybridForCausalLM:()=>Pf,GraniteMoeHybridModel:()=>zf,GraniteMoeHybridPreTrainedModel:()=>Nn,GranitePreTrainedModel:()=>Cn,GroundingDinoForObjectDetection:()=>Cf,GroundingDinoPreTrainedModel:()=>Ja,GroupViTModel:()=>Nf,GroupViTPreTrainedModel:()=>Za,HeliumForCausalLM:()=>$f,HeliumModel:()=>Lf,HeliumPreTrainedModel:()=>Ln,HieraForImageClassification:()=>Ff,HieraModel:()=>Rf,HieraPreTrainedModel:()=>$n,HubertForCTC:()=>Wf,HubertForSequenceClassification:()=>Vf,HubertModel:()=>Gf,HubertPreTrainedModel:()=>qf,HunYuanDenseV1ForCausalLM:()=>Kf,HunYuanDenseV1Model:()=>Hf,HunYuanDenseV1PreTrainedModel:()=>Rn,IJepaForImageClassification:()=>Yf,IJepaModel:()=>Qf,IJepaPreTrainedModel:()=>Fn,Idefics3ForConditionalGeneration:()=>tl,Idefics3PreTrainedModel:()=>el,JAISLMHeadModel:()=>Zf,JAISModel:()=>Jf,JAISPreTrainedModel:()=>Dn,JinaCLIPModel:()=>em,JinaCLIPPreTrainedModel:()=>Ys,JinaCLIPTextModel:()=>jn,JinaCLIPVisionModel:()=>tm,Lfm2ForCausalLM:()=>rm,Lfm2Model:()=>sm,Lfm2MoeForCausalLM:()=>om,Lfm2MoeModel:()=>nm,Lfm2MoePreTrainedModel:()=>Bn,Lfm2PreTrainedModel:()=>Un,LiteWhisperForConditionalGeneration:()=>Pg,Llama4ForCausalLM:()=>lm,Llama4PreTrainedModel:()=>sl,LlamaForCausalLM:()=>am,LlamaModel:()=>im,LlamaPreTrainedModel:()=>qn,LlavaForConditionalGeneration:()=>Js,LlavaOnevisionForConditionalGeneration:()=>Js,LlavaPreTrainedModel:()=>rl,LlavaQwen2ForCausalLM:()=>um,LongT5ForConditionalGeneration:()=>dm,LongT5Model:()=>pm,LongT5PreTrainedModel:()=>Gn,M2M100ForConditionalGeneration:()=>fm,M2M100Model:()=>_m,M2M100PreTrainedModel:()=>Wn,MBartForCausalLM:()=>km,MBartForConditionalGeneration:()=>ym,MBartForSequenceClassification:()=>bm,MBartModel:()=>wm,MBartPreTrainedModel:()=>ws,MPNetForMaskedLM:()=>ih,MPNetForQuestionAnswering:()=>ch,MPNetForSequenceClassification:()=>ah,MPNetForTokenClassification:()=>lh,MPNetModel:()=>oh,MPNetPreTrainedModel:()=>Ht,MT5ForConditionalGeneration:()=>_h,MT5Model:()=>dh,MT5PreTrainedModel:()=>ro,MarianMTModel:()=>hm,MarianModel:()=>mm,MarianPreTrainedModel:()=>Vn,MaskFormerForInstanceSegmentation:()=>gm,MaskFormerModel:()=>xm,MaskFormerPreTrainedModel:()=>Hn,Metric3DForDepthEstimation:()=>vm,Metric3DPreTrainedModel:()=>nl,Metric3Dv2ForDepthEstimation:()=>Em,Metric3Dv2PreTrainedModel:()=>ol,MgpstrForSceneTextRecognition:()=>Am,MgpstrModelOutput:()=>il,MgpstrPreTrainedModel:()=>al,MimiDecoderModel:()=>Xn,MimiDecoderOutput:()=>cl,MimiEncoderModel:()=>Kn,MimiEncoderOutput:()=>ll,MimiModel:()=>Mm,MimiPreTrainedModel:()=>Zs,MistralForCausalLM:()=>Om,MistralModel:()=>Sm,MistralPreTrainedModel:()=>Qn,MobileBertForMaskedLM:()=>Tm,MobileBertForQuestionAnswering:()=>Pm,MobileBertForSequenceClassification:()=>zm,MobileBertModel:()=>Im,MobileBertPreTrainedModel:()=>ys,MobileLLMForCausalLM:()=>Nm,MobileLLMModel:()=>Cm,MobileLLMPreTrainedModel:()=>Yn,MobileNetV1ForImageClassification:()=>$m,MobileNetV1ForSemanticSegmentation:()=>Rm,MobileNetV1Model:()=>Lm,MobileNetV1PreTrainedModel:()=>er,MobileNetV2ForImageClassification:()=>Dm,MobileNetV2ForSemanticSegmentation:()=>jm,MobileNetV2Model:()=>Fm,MobileNetV2PreTrainedModel:()=>tr,MobileNetV3ForImageClassification:()=>Bm,MobileNetV3ForSemanticSegmentation:()=>qm,MobileNetV3Model:()=>Um,MobileNetV3PreTrainedModel:()=>sr,MobileNetV4ForImageClassification:()=>Wm,MobileNetV4ForSemanticSegmentation:()=>Vm,MobileNetV4Model:()=>Gm,MobileNetV4PreTrainedModel:()=>rr,MobileViTForImageClassification:()=>Km,MobileViTModel:()=>Hm,MobileViTPreTrainedModel:()=>Jn,MobileViTV2ForImageClassification:()=>Qm,MobileViTV2Model:()=>Xm,MobileViTV2PreTrainedModel:()=>Zn,ModernBertDecoderForCausalLM:()=>sh,ModernBertDecoderModel:()=>th,ModernBertDecoderPreTrainedModel:()=>eo,ModernBertForMaskedLM:()=>Jm,ModernBertForSequenceClassification:()=>Zm,ModernBertForTokenClassification:()=>eh,ModernBertModel:()=>Ym,ModernBertPreTrainedModel:()=>bs,Moondream1ForConditionalGeneration:()=>cm,MoonshineForConditionalGeneration:()=>nh,MoonshineModel:()=>rh,MoonshinePreTrainedModel:()=>to,MptForCausalLM:()=>ph,MptModel:()=>uh,MptPreTrainedModel:()=>so,MultiModalityCausalLM:()=>fh,MultiModalityPreTrainedModel:()=>ul,MusicgenForCausalLM:()=>hh,MusicgenForConditionalGeneration:()=>oo,MusicgenModel:()=>mh,MusicgenPreTrainedModel:()=>no,NanoChatForCausalLM:()=>gh,NanoChatModel:()=>xh,NanoChatPreTrainedModel:()=>io,NeoBertForMaskedLM:()=>yh,NeoBertForQuestionAnswering:()=>vh,NeoBertForSequenceClassification:()=>bh,NeoBertForTokenClassification:()=>kh,NeoBertModel:()=>wh,NeoBertPreTrainedModel:()=>Kt,NomicBertModel:()=>Eh,NomicBertPreTrainedModel:()=>pl,OPTForCausalLM:()=>Nh,OPTModel:()=>Ch,OPTPreTrainedModel:()=>po,Olmo2ForCausalLM:()=>Oh,Olmo2Model:()=>Sh,Olmo2PreTrainedModel:()=>lo,Olmo3ForCausalLM:()=>Th,Olmo3Model:()=>Ih,Olmo3PreTrainedModel:()=>co,OlmoForCausalLM:()=>Mh,OlmoModel:()=>Ah,OlmoPreTrainedModel:()=>ao,OpenELMForCausalLM:()=>Ph,OpenELMModel:()=>zh,OpenELMPreTrainedModel:()=>uo,OwlViTForObjectDetection:()=>Fh,OwlViTModel:()=>Rh,OwlViTPreTrainedModel:()=>fo,Owlv2ForObjectDetection:()=>$h,Owlv2Model:()=>Lh,Owlv2PreTrainedModel:()=>_o,PaliGemmaForConditionalGeneration:()=>Dh,PaliGemmaPreTrainedModel:()=>dl,ParakeetForCTC:()=>jh,ParakeetPreTrainedModel:()=>_l,PatchTSMixerForPrediction:()=>Bh,PatchTSMixerModel:()=>Uh,PatchTSMixerPreTrainedModel:()=>mo,PatchTSTForPrediction:()=>Gh,PatchTSTModel:()=>qh,PatchTSTPreTrainedModel:()=>ho,Phi3ForCausalLM:()=>Kh,Phi3Model:()=>Hh,Phi3PreTrainedModel:()=>go,Phi3VForCausalLM:()=>wo,Phi3VPreTrainedModel:()=>fl,PhiForCausalLM:()=>Vh,PhiModel:()=>Wh,PhiPreTrainedModel:()=>xo,PreTrainedModel:()=>m,PvtForImageClassification:()=>Qh,PvtModel:()=>Xh,PvtPreTrainedModel:()=>yo,PyAnnoteForAudioFrameClassification:()=>Jh,PyAnnoteModel:()=>Yh,PyAnnotePreTrainedModel:()=>bo,Qwen2ForCausalLM:()=>ex,Qwen2Model:()=>Zh,Qwen2PreTrainedModel:()=>ko,Qwen2VLForConditionalGeneration:()=>vo,Qwen2VLPreTrainedModel:()=>ml,Qwen2_5_VLForConditionalGeneration:()=>Eo,Qwen3ForCausalLM:()=>sx,Qwen3Model:()=>tx,Qwen3PreTrainedModel:()=>Ao,Qwen3VLForConditionalGeneration:()=>Mo,Qwen3_5ForConditionalGeneration:()=>So,Qwen3_5MoeForConditionalGeneration:()=>rx,RFDetrForObjectDetection:()=>ax,RFDetrModel:()=>ix,RFDetrObjectDetectionOutput:()=>hl,RFDetrPreTrainedModel:()=>Io,RTDetrForObjectDetection:()=>s_,RTDetrModel:()=>t_,RTDetrObjectDetectionOutput:()=>bt,RTDetrPreTrainedModel:()=>an,RTDetrV2ForObjectDetection:()=>wx,RTDetrV2Model:()=>gx,RTDetrV2ObjectDetectionOutput:()=>xl,RTDetrV2PreTrainedModel:()=>To,ResNetForImageClassification:()=>ox,ResNetModel:()=>nx,ResNetPreTrainedModel:()=>Oo,RoFormerForMaskedLM:()=>fx,RoFormerForQuestionAnswering:()=>xx,RoFormerForSequenceClassification:()=>mx,RoFormerForTokenClassification:()=>hx,RoFormerModel:()=>_x,RoFormerPreTrainedModel:()=>Qt,RobertaForMaskedLM:()=>cx,RobertaForQuestionAnswering:()=>dx,RobertaForSequenceClassification:()=>ux,RobertaForTokenClassification:()=>px,RobertaModel:()=>lx,RobertaPreTrainedModel:()=>Xt,Sam2ImageSegmentationOutput:()=>yl,Sam2Model:()=>zo,Sam2PreTrainedModel:()=>bl,Sam3TrackerModel:()=>kx,SamImageSegmentationOutput:()=>gl,SamModel:()=>yx,SamPreTrainedModel:()=>wl,SapiensForDepthEstimation:()=>Ex,SapiensForNormalEstimation:()=>Ax,SapiensForSemanticSegmentation:()=>vx,SapiensPreTrainedModel:()=>nr,SegformerForImageClassification:()=>Sx,SegformerForSemanticSegmentation:()=>Ox,SegformerModel:()=>Mx,SegformerPreTrainedModel:()=>or,SiglipModel:()=>Ix,SiglipPreTrainedModel:()=>Po,SiglipTextModel:()=>Co,SiglipVisionModel:()=>Tx,SmolLM3ForCausalLM:()=>Px,SmolLM3Model:()=>zx,SmolLM3PreTrainedModel:()=>No,SmolVLMForConditionalGeneration:()=>Xf,SnacDecoderModel:()=>$o,SnacEncoderModel:()=>Lo,SnacModel:()=>Cx,SnacPreTrainedModel:()=>ir,SpeechT5ForSpeechToText:()=>Lx,SpeechT5ForTextToSpeech:()=>$x,SpeechT5HifiGan:()=>Rx,SpeechT5Model:()=>Nx,SpeechT5PreTrainedModel:()=>ar,SqueezeBertForMaskedLM:()=>Dx,SqueezeBertForQuestionAnswering:()=>Ux,SqueezeBertForSequenceClassification:()=>jx,SqueezeBertModel:()=>Fx,SqueezeBertPreTrainedModel:()=>ks,StableLmForCausalLM:()=>qx,StableLmModel:()=>Bx,StableLmPreTrainedModel:()=>Ro,Starcoder2ForCausalLM:()=>Wx,Starcoder2Model:()=>Gx,Starcoder2PreTrainedModel:()=>Fo,StyleTextToSpeech2Model:()=>Vx,StyleTextToSpeech2PreTrainedModel:()=>kl,SupertonicForConditionalGeneration:()=>Do,SupertonicPreTrainedModel:()=>vl,Swin2SRForImageSuperResolution:()=>Yx,Swin2SRModel:()=>Qx,Swin2SRPreTrainedModel:()=>jo,SwinForImageClassification:()=>Kx,SwinForSemanticSegmentation:()=>Xx,SwinModel:()=>Hx,SwinPreTrainedModel:()=>lr,T5ForConditionalGeneration:()=>Zx,T5Model:()=>Jx,T5PreTrainedModel:()=>Uo,TableTransformerForObjectDetection:()=>tg,TableTransformerModel:()=>eg,TableTransformerObjectDetectionOutput:()=>El,TableTransformerPreTrainedModel:()=>Bo,TrOCRForCausalLM:()=>sg,TrOCRPreTrainedModel:()=>Al,UltravoxModel:()=>Sl,UltravoxPreTrainedModel:()=>Ml,UniSpeechForCTC:()=>og,UniSpeechForSequenceClassification:()=>ig,UniSpeechModel:()=>ng,UniSpeechPreTrainedModel:()=>cr,UniSpeechSatForAudioFrameClassification:()=>ug,UniSpeechSatForCTC:()=>lg,UniSpeechSatForSequenceClassification:()=>cg,UniSpeechSatModel:()=>ag,UniSpeechSatPreTrainedModel:()=>vs,VaultGemmaForCausalLM:()=>dg,VaultGemmaModel:()=>pg,VaultGemmaPreTrainedModel:()=>qo,ViTForImageClassification:()=>mg,ViTMAEModel:()=>hg,ViTMAEPreTrainedModel:()=>Ol,ViTMSNForImageClassification:()=>gg,ViTMSNModel:()=>xg,ViTMSNPreTrainedModel:()=>Wo,ViTModel:()=>fg,ViTPreTrainedModel:()=>Go,VisionEncoderDecoderModel:()=>_g,VitMatteForImageMatting:()=>wg,VitMattePreTrainedModel:()=>Il,VitPoseForPoseEstimation:()=>yg,VitPosePreTrainedModel:()=>Tl,VitsModel:()=>bg,VitsModelOutput:()=>zl,VitsPreTrainedModel:()=>Pl,VoxtralForConditionalGeneration:()=>rg,Wav2Vec2BertForCTC:()=>vg,Wav2Vec2BertForSequenceClassification:()=>Eg,Wav2Vec2BertModel:()=>kg,Wav2Vec2BertPreTrainedModel:()=>ur,Wav2Vec2ForAudioFrameClassification:()=>Bf,Wav2Vec2ForCTC:()=>jf,Wav2Vec2ForSequenceClassification:()=>Uf,Wav2Vec2Model:()=>Df,Wav2Vec2PreTrainedModel:()=>ct,WavLMForAudioFrameClassification:()=>Ig,WavLMForCTC:()=>Mg,WavLMForSequenceClassification:()=>Sg,WavLMForXVector:()=>Og,WavLMModel:()=>Ag,WavLMPreTrainedModel:()=>Yt,WeSpeakerResNetModel:()=>Tg,WeSpeakerResNetPreTrainedModel:()=>Nl,WhisperForConditionalGeneration:()=>$l,WhisperModel:()=>zg,WhisperPreTrainedModel:()=>Vo,XLMForQuestionAnswering:()=>Rg,XLMForSequenceClassification:()=>Lg,XLMForTokenClassification:()=>$g,XLMModel:()=>Cg,XLMPreTrainedModel:()=>Jt,XLMRobertaForMaskedLM:()=>Dg,XLMRobertaForQuestionAnswering:()=>Bg,XLMRobertaForSequenceClassification:()=>jg,XLMRobertaForTokenClassification:()=>Ug,XLMRobertaModel:()=>Fg,XLMRobertaPreTrainedModel:()=>Zt,XLMWithLMHeadModel:()=>Ng,XVectorOutput:()=>Cl,YolosForObjectDetection:()=>Gg,YolosModel:()=>qg,YolosObjectDetectionOutput:()=>Rl,YolosPreTrainedModel:()=>Ho,YoutuForCausalLM:()=>Vg,YoutuModel:()=>Wg,YoutuPreTrainedModel:()=>Ko});var xs=class extends m{},Zp=class extends xs{},ed=class extends xs{async _call(e){return new z(await super._call(e))}},td=class extends xs{async _call(e){return new ae(await super._call(e))}},sd=class extends xs{async _call(e){return new ee(await super._call(e))}};var Br=class extends m{},rd=class extends Br{},nd=class extends Br{};var qr=class extends m{},od=class extends qr{},id=class extends qr{};var Gr=class extends m{},ad=class extends Gr{},ld=class extends Gr{};var Wr=class extends m{},cd=class extends Wr{},ud=class extends Wr{};var Vs=class extends m{},pd=class extends Vs{},dd=class extends Vs{},_d=class extends Vs{async _call(e){return new z(await super._call(e))}};var Vr=class extends m{},fd=class extends Vr{},md=class extends Vr{async _call(e){return new z(await super._call(e))}};var jt=class extends m{},hd=class extends jt{},xd=class extends jt{async _call(e){return new ee(await super._call(e))}},gd=class extends jt{async _call(e){return new z(await super._call(e))}},wd=class extends jt{async _call(e){return new Y(await super._call(e))}},yd=class extends jt{async _call(e){return new ae(await super._call(e))}};var Hr=class extends m{},bd=class extends Hr{},kd=class extends Hr{};var Kr=class extends m{},vd=class extends Kr{},Ed=class extends Kr{};var Xr=class extends m{},Ad=class extends Xr{},Md=class extends Xr{};var Ut=class extends m{},Sd=class extends Ut{},Od=class extends Ut{async _call(e){return new ee(await super._call(e))}},Id=class extends Ut{async _call(e){return new z(await super._call(e))}},Td=class extends Ut{async _call(e){return new Y(await super._call(e))}},zd=class extends Ut{async _call(e){return new ae(await super._call(e))}};var nE=4299n,Ky=6561n,Da=class extends m{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","audio_values","exaggeration","audio_features","audio_tokens","speaker_embeddings","speaker_features","past_key_values"];main_input_name="input_ids";_return_dict_in_generate_keys=["audio_tokens","speaker_embeddings","speaker_features"]},Qr=class extends Da{async encode_speech(e){return G(this.sessions.speech_encoder,{audio_values:e})}async forward({input_ids:e=null,attention_mask:s=null,audio_values:r=null,exaggeration:n=null,position_ids:o=null,inputs_embeds:i=null,past_key_values:a=null,generation_config:l=null,logits_processor:c=null,audio_features:u=null,audio_tokens:p=null,speaker_embeddings:d=null,speaker_features:_=null,...f}){let h;if(!i){let g=this.sessions.embed_tokens.inputNames,w={input_ids:e};if(g.includes("exaggeration")){if(!(n instanceof S)){let y=e.dims[0];if(n==null)n=ge([y],.5);else if(typeof n=="number")n=ge([y],n);else if(Array.isArray(n))n=new S("float32",n,[y]);else throw new Error("Unsupported type for `exaggeration` input")}w.exaggeration=n}if(g.includes("position_ids")&&(w.position_ids=o),{inputs_embeds:i}=await G(this.sessions.embed_tokens,w),u&&p&&d&&_&&(h={audio_features:u,audio_tokens:p,speaker_embeddings:d,speaker_features:_}),h||r)h??=await this.encode_speech(r),i=ie([h.audio_features,i],1),s=Oe([i.dims[0],i.dims[1]]);else{let y=i.dims[1];if(!a||y!==1)throw new Error("Incorrect state encountered during generation.");let b=Object.values(a)[0].dims.at(-2);s=Oe([i.dims[0],b+y])}}return{...await Ge(this,{inputs_embeds:i,past_key_values:a,attention_mask:s,generation_config:l,logits_processor:c},!1),...h}}prepare_inputs_for_generation(e,s,r){if(!s.position_ids&&this.sessions.embed_tokens.inputNames.includes("position_ids"))if(s.input_ids.dims[1]===1){let n=Array.from({length:e.length},(o,i)=>e[i].length-e[i].findLastIndex(a=>a==Ky)-1);s.position_ids=new S("int64",n,[e.length,1])}else{let o=s.input_ids.tolist().map(i=>{let a=0;return i.map(l=>l>=Ky?0:a++)});s.position_ids=new S("int64",o.flat(),s.input_ids.dims)}return s.input_ids.dims[1]===1&&(delete s.audio_values,delete s.audio_features,delete s.audio_tokens,delete s.speaker_embeddings,delete s.speaker_features),jr(this,e,s,r)}async generate(e){let{sequences:s,audio_tokens:r,speaker_embeddings:n,speaker_features:o}=await super.generate({...e,return_dict_in_generate:!0}),i=s.slice(null,[e.input_ids.dims[1],-1]),a=ge([i.dims[0],3],nE),l=ie([r,i,a],1),{waveform:c}=await G(this.sessions.conditional_decoder,{speech_tokens:l,speaker_features:o,speaker_embeddings:n});return c}};var ja=class extends m{},Pd=class extends ja{};var Hs=class extends m{},Cd=class extends Hs{},Yr=class extends Hs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},Jr=class extends Hs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"audio_model"})}};var yt=class extends m{},Nd=class extends yt{},Ld=class extends yt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},Zr=class extends yt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},$d=class extends yt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}},Rd=class extends yt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var en=class extends m{},Fd=class extends en{},Dd=class extends en{};var tn=class extends m{},jd=class extends tn{},Ud=class extends tn{};var sn=class extends m{},Bd=class extends sn{},qd=class extends sn{};var rn=class extends m{},Gd=class extends rn{},Wd=class extends rn{};var Bt=class extends m{},Vd=class extends Bt{},Hd=class extends Bt{async _call(e){return new ee(await super._call(e))}},Kd=class extends Bt{async _call(e){return new z(await super._call(e))}},Xd=class extends Bt{async _call(e){return new Y(await super._call(e))}},Qd=class extends Bt{async _call(e){return new ae(await super._call(e))}};var nn=class extends m{},Yd=class extends nn{},Jd=class extends nn{async _call(e){return new z(await super._call(e))}};var on=class extends m{},Zd=class extends on{},e_=class extends on{async _call(e){return new z(await super._call(e))}};var an=class extends m{},t_=class extends an{},s_=class extends an{async _call(e){return new bt(await super._call(e))}},bt=class extends de{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}};var ln=class extends m{},r_=class extends ln{},n_=class extends ln{async _call(e){return new bt(await super._call(e))}};var Ua=class extends de{constructor({audio_codes:e}){super(),this.audio_codes=e}},Ba=class extends de{constructor({audio_values:e}){super(),this.audio_values=e}},Ks=class extends m{main_input_name="input_values";forward_params=["input_values"]},o_=class extends Ks{async encode(e){return new Ua(await G(this.sessions.encoder_model,e))}async decode(e){return new Ba(await G(this.sessions.decoder_model,e))}},cn=class extends Ks{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},un=class extends Ks{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var qt=class extends m{},i_=class extends qt{},a_=class extends qt{async _call(e){return new ee(await super._call(e))}},l_=class extends qt{async _call(e){return new z(await super._call(e))}},c_=class extends qt{async _call(e){return new Y(await super._call(e))}},u_=class extends qt{async _call(e){return new ae(await super._call(e))}};var Gt=class extends m{},p_=class extends Gt{},d_=class extends Gt{async _call(e){return new ee(await super._call(e))}},__=class extends Gt{async _call(e){return new z(await super._call(e))}},f_=class extends Gt{async _call(e){return new Y(await super._call(e))}},m_=class extends Gt{async _call(e){return new ae(await super._call(e))}};var qa=class extends m{},h_=class extends qa{};var pn=class extends m{},x_=class extends pn{},g_=class extends pn{async _call(e){return new z(await super._call(e))}};var Ga=class extends m{},w_=class extends Ga{};var Wa=class extends m{},y_=class extends Wa{};var Xs=class extends m{},b_=class extends Xs{},k_=class extends Xs{async _call(e){return new Qs(await super._call(e))}},v_=class extends Xs{async _call(e){return new Va(await super._call(e))}},Qs=class extends de{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}},Va=class extends de{constructor({logits:e,pred_boxes:s,pred_masks:r}){super(),this.logits=e,this.pred_boxes=s,this.pred_masks=r}};var dn=class extends m{},E_=class extends dn{},A_=class extends dn{async _call(e){return new z(await super._call(e))}};var _n=class extends m{},M_=class extends _n{},S_=class extends _n{async _call(e){return new z(await super._call(e))}};var Ha=class extends m{},O_=class extends Ha{};var Ka=class extends m{},I_=class extends Ka{};var Wt=class extends m{},T_=class extends Wt{},z_=class extends Wt{async _call(e){return new z(await super._call(e))}},P_=class extends Wt{async _call(e){return new Y(await super._call(e))}},C_=class extends Wt{async _call(e){return new ae(await super._call(e))}},N_=class extends Wt{async _call(e){return new ee(await super._call(e))}};var Xa=class extends m{},L_=class extends Xa{};var fn=class extends m{},$_=class extends fn{},R_=class extends fn{};var mn=class extends m{},F_=class extends mn{},D_=class extends mn{async _call(e){return new z(await super._call(e))}};var Vt=class extends m{},j_=class extends Vt{},U_=class extends Vt{async _call(e){return new ee(await super._call(e))}},B_=class extends Vt{async _call(e){return new z(await super._call(e))}},q_=class extends Vt{async _call(e){return new Y(await super._call(e))}},G_=class extends Vt{async _call(e){return new ae(await super._call(e))}};var hn=class extends m{},W_=class extends hn{},V_=class extends hn{};var gs=class extends m{},H_=class extends gs{},K_=class extends gs{async _call(e){return new ee(await super._call(e))}},X_=class extends gs{async _call(e){return new z(await super._call(e))}},Q_=class extends gs{async _call(e){return new Y(await super._call(e))}};var xn=class extends m{},Y_=class extends xn{},J_=class extends xn{};var gn=class extends m{},Z_=class extends gn{},ef=class extends gn{};var wn=class extends m{},tf=class extends wn{},sf=class extends wn{};var yn=class extends m{},rf=class extends yn{},nf=class extends yn{async _call(e){return new z(await super._call(e))}};var Qa=class extends m{forward_params=["input_ids","inputs_embeds","attention_mask","pixel_values","encoder_outputs","decoder_input_ids","decoder_inputs_embeds","decoder_attention_mask","past_key_values"];main_input_name="inputs_embeds"},of=class extends Qa{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:s,input_ids:r,attention_mask:n}){return{inputs_embeds:ie([s,e],1),attention_mask:ie([Oe(s.dims.slice(0,2)),n],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:s,inputs_embeds:r,attention_mask:n}){if(!e&&!s)throw new Error("Either `input_ids` or `pixel_values` should be provided.");let o,i;return e&&(o=await this.encode_text({input_ids:e})),s&&(i=await this.encode_image({pixel_values:s})),o&&i?{inputs_embeds:r,attention_mask:n}=this._merge_input_ids_with_image_features({inputs_embeds:o,image_features:i,input_ids:e,attention_mask:n}):r=o||i,{inputs_embeds:r,attention_mask:n}}async forward({input_ids:e,pixel_values:s,attention_mask:r,decoder_input_ids:n,decoder_attention_mask:o,encoder_outputs:i,past_key_values:a,inputs_embeds:l,decoder_inputs_embeds:c}){if(l||({inputs_embeds:l,attention_mask:r}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:s,inputs_embeds:l,attention_mask:r})),!i){let{last_hidden_state:p}=await et(this,{inputs_embeds:l,attention_mask:r});i=p}if(!c){if(!n)throw new Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");c=await this.encode_text({input_ids:n})}return await Ge(this,{inputs_embeds:c,attention_mask:o,encoder_attention_mask:r,encoder_hidden_states:i,past_key_values:a},!0)}};var bn=class extends m{},af=class extends bn{},lf=class extends bn{};var kn=class extends m{},cf=class extends kn{},uf=class extends kn{};var vn=class extends m{},pf=class extends vn{},df=class extends vn{};var Ya=class extends m{forward_params=["input_ids","attention_mask","inputs_embeds","per_layer_inputs","position_ids","pixel_values","input_features","input_features_mask","past_key_values"]},En=class extends Ya{async forward({input_ids:e=null,attention_mask:s=null,pixel_values:r=null,input_features:n=null,input_features_mask:o=null,position_ids:i=null,inputs_embeds:a=null,per_layer_inputs:l=null,past_key_values:c=null,generation_config:u=null,logits_processor:p=null,...d}){if((!a||!l)&&({inputs_embeds:a,per_layer_inputs:l}=await G(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(r){let{image_features:f}=await G(this.sessions.vision_encoder,{pixel_values:r});({inputs_embeds:a,attention_mask:s}=this._merge_input_ids_with_image_features({image_features:f,inputs_embeds:a,input_ids:e,attention_mask:s}))}if(n){let{audio_features:f}=await G(this.sessions.audio_encoder,{input_features:n,input_features_mask:o});({inputs_embeds:a,attention_mask:s}=this._merge_input_ids_with_audio_features({audio_features:f,inputs_embeds:a,input_ids:e,attention_mask:s}))}}return await Ge(this,{inputs_embeds:a,per_layer_inputs:l,past_key_values:c,attention_mask:s,position_ids:i,generation_config:u,logits_processor:p},!0)}_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return wt({image_token_id:this.config.image_token_id,...e,image_features:r})}_merge_input_ids_with_audio_features(e){let s=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,s);return Fa({audio_token_id:this.config.audio_token_id,...e,audio_features:r})}};var An=class extends m{},_f=class extends An{},ff=class extends An{};var Mn=class extends m{},mf=class extends Mn{},hf=class extends Mn{};var Sn=class extends m{},xf=class extends Sn{},gf=class extends Sn{};var On=class extends m{},wf=class extends On{},yf=class extends On{};var In=class extends m{},bf=class extends In{},kf=class extends In{};var Tn=class extends m{},vf=class extends Tn{},Ef=class extends Tn{};var zn=class extends m{},Af=class extends zn{},Mf=class extends zn{};var Pn=class extends m{},Sf=class extends Pn{},Of=class extends Pn{};var Cn=class extends m{},If=class extends Cn{},Tf=class extends Cn{};var Nn=class extends m{},zf=class extends Nn{},Pf=class extends Nn{};var Ja=class extends m{},Cf=class extends Ja{};var Za=class extends m{},Nf=class extends Za{};var Ln=class extends m{},Lf=class extends Ln{},$f=class extends Ln{};var $n=class extends m{},Rf=class extends $n{},Ff=class extends $n{async _call(e){return new z(await super._call(e))}};var ct=class extends m{},Df=class extends ct{},jf=class extends ct{async _call(e){return new Re(await super._call(e))}},Uf=class extends ct{async _call(e){return new z(await super._call(e))}},Bf=class extends ct{async _call(e){return new Y(await super._call(e))}};var qf=class extends m{},Gf=class extends ct{},Wf=class extends ct{async _call(e){return new Re(await super._call(e))}},Vf=class extends ct{async _call(e){return new z(await super._call(e))}};var Rn=class extends m{},Hf=class extends Rn{},Kf=class extends Rn{};var el=class extends m{forward_params=["input_ids","attention_mask","pixel_values","pixel_attention_mask","position_ids","past_key_values"]},tl=class extends el{async encode_image({pixel_values:e,pixel_attention_mask:s}){return(await G(this.sessions.vision_encoder,{pixel_values:e,pixel_attention_mask:s})).image_features}_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return wt({image_token_id:this.config.image_token_id,...e,image_features:r})}},Xf=class extends tl{};var Fn=class extends m{},Qf=class extends Fn{},Yf=class extends Fn{async _call(e){return new z(await super._call(e))}};var Dn=class extends m{},Jf=class extends Dn{},Zf=class extends Dn{};var Ys=class extends m{},em=class extends Ys{async forward(e){let s=!e.input_ids,r=!e.pixel_values;if(s&&r)throw new Error("Either `input_ids` or `pixel_values` should be provided.");if(s&&(e.input_ids=Oe([e.pixel_values.dims[0],1])),r){let{image_size:c}=this.config.vision_config;e.pixel_values=ge([0,3,c,c],0)}let{text_embeddings:n,image_embeddings:o,l2norm_text_embeddings:i,l2norm_image_embeddings:a}=await super.forward(e),l={};return s||(l.text_embeddings=n,l.l2norm_text_embeddings=i),r||(l.image_embeddings=o,l.l2norm_image_embeddings=a),l}},jn=class extends Ys{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},tm=class extends Ys{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var Un=class extends m{},sm=class extends Un{},rm=class extends Un{};var Bn=class extends m{},nm=class extends Bn{},om=class extends Bn{};var qn=class extends m{},im=class extends qn{},am=class extends qn{};var sl=class extends m{},lm=class extends sl{};var rl=class extends m{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},Js=class extends rl{_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return wt({image_token_id:this.config.image_token_index,...e,image_features:r})}},cm=class extends Js{},um=class extends Js{};var Gn=class extends m{},pm=class extends Gn{},dm=class extends Gn{};var Wn=class extends m{},_m=class extends Wn{},fm=class extends Wn{};var Vn=class extends m{},mm=class extends Vn{},hm=class extends Vn{};var Hn=class extends m{},xm=class extends Hn{},gm=class extends Hn{};var ws=class extends m{},wm=class extends ws{},ym=class extends ws{},bm=class extends ws{async _call(e){return new z(await super._call(e))}},km=class extends ws{};var nl=class extends m{},vm=class extends nl{};var ol=class extends m{},Em=class extends ol{};var il=class extends de{constructor({char_logits:e,bpe_logits:s,wp_logits:r}){super(),this.char_logits=e,this.bpe_logits=s,this.wp_logits=r}get logits(){return[this.char_logits,this.bpe_logits,this.wp_logits]}},al=class extends m{},Am=class extends al{async _call(e){return new il(await super._call(e))}};var ll=class extends de{constructor({audio_codes:e}){super(),this.audio_codes=e}},cl=class extends de{constructor({audio_values:e}){super(),this.audio_values=e}},Zs=class extends m{main_input_name="input_values";forward_params=["input_values"]},Mm=class extends Zs{async encode(e){return new ll(await G(this.sessions.encoder_model,e))}async decode(e){return new cl(await G(this.sessions.decoder_model,e))}},Kn=class extends Zs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},Xn=class extends Zs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var Qn=class extends m{},Sm=class extends Qn{},Om=class extends Qn{};var ys=class extends m{},Im=class extends ys{},Tm=class extends ys{async _call(e){return new ee(await super._call(e))}},zm=class extends ys{async _call(e){return new z(await super._call(e))}},Pm=class extends ys{async _call(e){return new ae(await super._call(e))}};var Yn=class extends m{},Cm=class extends Yn{},Nm=class extends Yn{};var er=class extends m{},Lm=class extends er{},$m=class extends er{async _call(e){return new z(await super._call(e))}},Rm=class extends er{};var tr=class extends m{},Fm=class extends tr{},Dm=class extends tr{async _call(e){return new z(await super._call(e))}},jm=class extends tr{};var sr=class extends m{},Um=class extends sr{},Bm=class extends sr{async _call(e){return new z(await super._call(e))}},qm=class extends sr{};var rr=class extends m{},Gm=class extends rr{},Wm=class extends rr{async _call(e){return new z(await super._call(e))}},Vm=class extends rr{};var Jn=class extends m{},Hm=class extends Jn{},Km=class extends Jn{async _call(e){return new z(await super._call(e))}};var Zn=class extends m{},Xm=class extends Zn{},Qm=class extends Zn{async _call(e){return new z(await super._call(e))}};var bs=class extends m{},Ym=class extends bs{},Jm=class extends bs{async _call(e){return new ee(await super._call(e))}},Zm=class extends bs{async _call(e){return new z(await super._call(e))}},eh=class extends bs{async _call(e){return new Y(await super._call(e))}};var eo=class extends m{},th=class extends eo{},sh=class extends eo{};var to=class extends m{requires_attention_mask=!1;main_input_name="input_values";forward_params=["input_values","decoder_input_ids","past_key_values"]},rh=class extends to{},nh=class extends to{};var Ht=class extends m{},oh=class extends Ht{},ih=class extends Ht{async _call(e){return new ee(await super._call(e))}},ah=class extends Ht{async _call(e){return new z(await super._call(e))}},lh=class extends Ht{async _call(e){return new Y(await super._call(e))}},ch=class extends Ht{async _call(e){return new ae(await super._call(e))}};var so=class extends m{},uh=class extends so{},ph=class extends so{};var ro=class extends m{},dh=class extends ro{},_h=class extends ro{};var ul=class extends m{},fh=class extends ul{forward_params=["input_ids","pixel_values","images_seq_mask","images_emb_mask","attention_mask","position_ids","past_key_values"];constructor(...e){super(...e),this._generation_mode="text"}async forward(e){let s=this._generation_mode??"text",r;if(s==="text"||!e.past_key_values){let l=this.sessions.prepare_inputs_embeds,c=Me(e,l.inputNames);r=await G(l,c)}else{let l=this.sessions.gen_img_embeds,c=Me({image_ids:e.input_ids},l.inputNames);r=await G(l,c)}let n={...e,...r},o=await Ge(this,n),i=this.sessions[s==="text"?"lm_head":"gen_head"];if(!i)throw new Error(`Unable to find "${i}" generation head`);let a=await G(i,Me(o,i.inputNames));return{...r,...o,...a}}prepare_inputs_for_generation(e,s,r){let n=!!s.past_key_values;return r.guidance_scale!==null&&r.guidance_scale>1&&(n?s.input_ids=ie([s.input_ids,s.input_ids],0):(s.input_ids=ie([s.input_ids,Ar(s.input_ids,BigInt(r.pad_token_id))],0),s.attention_mask=ie([s.attention_mask,Ar(s.attention_mask,0n)],0))),(n||!s.pixel_values)&&(s.pixel_values=ge([0,0,3,384,384],1)),n&&(s.images_seq_mask=new S("bool",new Array(1).fill(!0).fill(!1,0,1),[1,1]),s.images_emb_mask=new S("bool",new Array(0).fill(!1),[1,1,0])),s}async generate(e){return this._generation_mode="text",super.generate(e)}async generate_images(e){this._generation_mode="image";let s=(e.inputs??e[this.main_input_name]).dims[1],n=(await super.generate(e)).slice(null,[s,null]),o=this.sessions.image_decode,{decoded_image:i}=await G(o,{generated_tokens:n}),a=i.add_(1).mul_(255/2).clamp_(0,255).to("uint8"),l=[];for(let c of a){let u=ye.fromTensor(c);l.push(u)}return l}};var no=class extends m{},mh=class extends no{},hh=class extends no{},oo=class extends m{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"];_apply_and_filter_by_delay_pattern_mask(e){let[s,r]=e.dims,n=this.config.decoder.num_codebooks,o=r-n,i=0;for(let c=0;c<e.size;++c){if(e.data[c]==this.config.decoder.pad_token_id)continue;let u=c%r,p=Math.floor(c/r)%n,d=u-p;d>0&&d<=o&&(e.data[i++]=e.data[c])}let a=Math.floor(s/n),l=i/(a*n);return new S(e.type,e.data.slice(0,i),[a,n,l])}prepare_inputs_for_generation(e,s,r){let n=BigInt(this.config.decoder.pad_token_id),o=structuredClone(e);for(let i=0;i<o.length;++i)for(let a=0;a<o[i].length;++a)i%this.config.decoder.num_codebooks>=a&&(o[i][a]=n);return r.guidance_scale!==null&&r.guidance_scale>1&&(o=o.concat(o)),Ur(this,o,s,r)}async generate(e){let s=await super.generate(e),r=this._apply_and_filter_by_delay_pattern_mask(s).unsqueeze_(0),{audio_values:n}=await G(this.sessions.encodec_decode,{audio_codes:r});return n}};var io=class extends m{},xh=class extends io{},gh=class extends io{};var Kt=class extends m{},wh=class extends Kt{},yh=class extends Kt{async _call(e){return new ee(await super._call(e))}},bh=class extends Kt{async _call(e){return new z(await super._call(e))}},kh=class extends Kt{async _call(e){return new Y(await super._call(e))}},vh=class extends Kt{async _call(e){return new ae(await super._call(e))}};var pl=class extends m{},Eh=class extends pl{};var ao=class extends m{},Ah=class extends ao{},Mh=class extends ao{};var lo=class extends m{},Sh=class extends lo{},Oh=class extends lo{};var co=class extends m{},Ih=class extends co{},Th=class extends co{};var uo=class extends m{},zh=class extends uo{},Ph=class extends uo{};var po=class extends m{},Ch=class extends po{},Nh=class extends po{};var _o=class extends m{},Lh=class extends _o{},$h=class extends _o{};var fo=class extends m{},Rh=class extends fo{},Fh=class extends fo{};var dl=class extends m{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},Dh=class extends dl{_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return wt({image_token_id:this.config.image_token_index,...e,image_features:r})}};var _l=class extends m{},jh=class extends _l{async _call(e){return new Re(await super._call(e))}};var mo=class extends m{},Uh=class extends mo{},Bh=class extends mo{};var ho=class extends m{},qh=class extends ho{},Gh=class extends ho{};var xo=class extends m{},Wh=class extends xo{},Vh=class extends xo{};var go=class extends m{},Hh=class extends go{},Kh=class extends go{};var fl=class extends m{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","pixel_values","image_sizes","past_key_values"]},wo=class extends fl{async forward({input_ids:e=null,attention_mask:s=null,pixel_values:r=null,image_sizes:n=null,position_ids:o=null,inputs_embeds:i=null,past_key_values:a=null,generation_config:l=null,logits_processor:c=null,...u}){if(!i){let d;if(r&&e.dims[1]!==1){if(!n)throw new Error("`image_sizes` must be provided when `pixel_values` is provided.");({image_features:d}=await G(this.sessions.vision_encoder,{pixel_values:r,image_sizes:n}))}else{let _=this.config.normalized_config.hidden_size;d=new S("float32",[],[0,_])}({inputs_embeds:i}=await G(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:d}))}return await Ge(this,{inputs_embeds:i,past_key_values:a,attention_mask:s,position_ids:o,generation_config:l,logits_processor:c},!1)}};var yo=class extends m{},Xh=class extends yo{},Qh=class extends yo{async _call(e){return new z(await super._call(e))}};var bo=class extends m{},Yh=class extends bo{},Jh=class extends bo{async _call(e){return new Y(await super._call(e))}};var ko=class extends m{},Zh=class extends ko{},ex=class extends ko{};var ml=class extends m{forward_params=["input_ids","attention_mask","position_ids","past_key_values","pixel_values","image_grid_thw"]},vo=class extends ml{image_grid_thw_name="grid_thw";get_rope_index(e,s,r,n){let{vision_config:o,image_token_id:i,video_token_id:a,vision_start_token_id:l}=this.config,c=o.spatial_merge_size??2,u=[];if(s||r){let p=e.tolist();n||(n=Hi(e));let d=n.tolist(),_=Array.from({length:3},w=>Array.from({length:e.dims[0]},y=>Array.from({length:e.dims[1]},b=>1))),f=s?s.tolist():[],h=r?r.tolist():[],x=0,g=0;for(let w=0;w<p.length;++w){let y=p[w].filter((v,E)=>d[w][E]==1),A=y.reduce((v,E,T)=>(E==l&&v.push(T),v),[]).map(v=>y[v+1]),k=A.filter(v=>v==i).length,O=A.filter(v=>v==a).length,N=[],D=0,F=k,B=O;for(let v=0;v<A.length;++v){let E=y.findIndex((pt,st)=>st>D&&pt==i),T=y.findIndex((pt,st)=>st>D&&pt==a),J=F>0&&E!==-1?E:y.length+1,se=B>0&&T!==-1?T:y.length+1,Ie,Ae,kt,vt;J<se?([Ae,kt,vt]=f[x],++x,--F,Ie=J):([Ae,kt,vt]=h[g],++g,--B,Ie=se);let[rs,ut,tt]=[Number(Ae),Math.floor(Number(kt)/c),Math.floor(Number(vt)/c)],Et=Ie-D,Ct=N.length>0?le(N.at(-1))[0]+1:0;N.push(Array.from({length:3*Et},(pt,st)=>Ct+st%Et));let ns=Et+Ct,Nt=rs*ut*tt,Ai=Array.from({length:Nt},(pt,st)=>ns+Math.floor(st/(ut*tt))),Mi=Array.from({length:Nt},(pt,st)=>ns+Math.floor(st/tt)%ut),Si=Array.from({length:Nt},(pt,st)=>ns+st%tt);N.push([Ai,Mi,Si].flat()),D=Ie+Nt}if(D<y.length){let v=N.length>0?le(N.at(-1))[0]+1:0,E=y.length-D;N.push(Array.from({length:3*E},(T,J)=>v+J%E))}let W=N.reduce((v,E)=>v+E.length,0),j=new Array(W),Q=0;for(let v=0;v<3;++v)for(let E=0;E<N.length;++E){let T=N[E],J=T.length/3;for(let se=v*J;se<(v+1)*J;++se)j[Q++]=T[se]}let K=0,oe=d[w];for(let v=0;v<oe.length;++v)if(oe[v]==1){for(let E=0;E<3;++E)_[E][w][v]=j[E*W/3+K];++K}let te=le(j)[0];u.push(te+1-p[w].length)}return[new S("int64",_.flat(1/0),[3,e.dims[0],e.dims[1]]),new S("int64",u,[u.length,1])]}else if(n){let{data:p,dims:d}=Jp(n),_=BigInt64Array.from({length:3*p.length},(h,x)=>p[x%p.length]),f=Array.from({length:d[0]},(h,x)=>le(p.subarray(d[1]*x,d[1]*(x+1)))[0]+1n+BigInt(d[1]));return[new S("int64",_,[3,...d]),new S("int64",f,[f.length,1])]}else{let[p,d]=e.dims,_=BigInt64Array.from({length:3*p*d},(f,h)=>BigInt(Math.floor(h%d/p)));return[new S("int64",_,[3,...e.dims]),Ac([p,1])]}}async encode_image({pixel_values:e,image_grid_thw:s}){return(await G(this.sessions.vision_encoder,{pixel_values:e,[this.image_grid_thw_name]:s})).image_features}_merge_input_ids_with_image_features(e){return wt({image_token_id:this.config.image_token_id,...e})}prepare_inputs_for_generation(e,s,r){if(s.attention_mask&&!s.position_ids)if(!s.past_key_values)[s.position_ids,s.rope_deltas]=this.get_rope_index(s.input_ids,s.image_grid_thw,s.video_grid_thw,s.attention_mask);else{s.pixel_values=null;let n=BigInt(Object.values(s.past_key_values)[0].dims.at(-2)),o=s.rope_deltas.map(i=>n+i);s.position_ids=Je([o,o,o],0)}return s}};var Eo=class extends vo{image_grid_thw_name="image_grid_thw"};var Ao=class extends m{},tx=class extends Ao{},sx=class extends Ao{};var Mo=class extends Eo{};var So=class extends Mo{};var rx=class extends So{};var Oo=class extends m{},nx=class extends Oo{},ox=class extends Oo{async _call(e){return new z(await super._call(e))}};var Io=class extends m{},ix=class extends Io{},ax=class extends Io{async _call(e){return new hl(await super._call(e))}},hl=class extends bt{};var Xt=class extends m{},lx=class extends Xt{},cx=class extends Xt{async _call(e){return new ee(await super._call(e))}},ux=class extends Xt{async _call(e){return new z(await super._call(e))}},px=class extends Xt{async _call(e){return new Y(await super._call(e))}},dx=class extends Xt{async _call(e){return new ae(await super._call(e))}};var Qt=class extends m{},_x=class extends Qt{},fx=class extends Qt{async _call(e){return new ee(await super._call(e))}},mx=class extends Qt{async _call(e){return new z(await super._call(e))}},hx=class extends Qt{async _call(e){return new Y(await super._call(e))}},xx=class extends Qt{async _call(e){return new ae(await super._call(e))}};var To=class extends m{},gx=class extends To{},wx=class extends To{async _call(e){return new xl(await super._call(e))}},xl=class extends bt{};var gl=class extends de{constructor({iou_scores:e,pred_masks:s}){super(),this.iou_scores=e,this.pred_masks=s}},wl=class extends m{},yx=class extends wl{async get_image_embeddings({pixel_values:e}){return await et(this,{pixel_values:e})}async forward(e){!e.image_embeddings||!e.image_positional_embeddings?e={...e,...await this.get_image_embeddings(e)}:e={...e},e.input_labels??=Oe(e.input_points.dims.slice(0,-1));let s={image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings};return e.input_points&&(s.input_points=e.input_points),e.input_labels&&(s.input_labels=e.input_labels),e.input_boxes&&(s.input_boxes=e.input_boxes),await G(this.sessions.prompt_encoder_mask_decoder,s)}async _call(e){return new gl(await super._call(e))}};var yl=class extends de{constructor({iou_scores:e,pred_masks:s,object_score_logits:r}){super(),this.iou_scores=e,this.pred_masks=s,this.object_score_logits=r}},bl=class extends m{},zo=class extends bl{async get_image_embeddings({pixel_values:e}){return await et(this,{pixel_values:e})}async forward(e){let{num_feature_levels:s}=this.config.vision_config;if(Array.from({length:s},(i,a)=>`image_embeddings.${a}`).some(i=>!e[i])?e={...e,...await this.get_image_embeddings(e)}:e={...e},e.input_points){if(e.input_boxes&&e.input_boxes.dims[1]!==1)throw new Error("When both `input_points` and `input_boxes` are provided, the number of boxes per image must be 1.");let i=e.input_points.dims;e.input_labels??=Oe(i.slice(0,-1)),e.input_boxes??=ge([i[0],0,4],0)}else if(e.input_boxes){let i=e.input_boxes.dims;e.input_labels=ge([i[0],i[1],0],-1n),e.input_points=ge([i[0],1,0,2],0)}else throw new Error("At least one of `input_points` or `input_boxes` must be provided.");let n=this.sessions.prompt_encoder_mask_decoder,o=Me(e,n.inputNames);return await G(n,o)}async _call(e){return new yl(await super._call(e))}},bx=class extends zo{},kx=class extends zo{};var nr=class extends m{},vx=class extends nr{},Ex=class extends nr{},Ax=class extends nr{};var or=class extends m{},Mx=class extends or{},Sx=class extends or{},Ox=class extends or{};var Po=class extends m{},Ix=class extends Po{},Co=class extends Po{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},Tx=class extends yt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var No=class extends m{},zx=class extends No{},Px=class extends No{};var ir=class extends m{main_input_name="input_values";forward_params=["input_values"]},Cx=class extends ir{async encode(e){return await G(this.sessions.encoder_model,e)}async decode(e){return await G(this.sessions.decoder_model,e)}},Lo=class extends ir{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},$o=class extends ir{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var ar=class extends m{},Nx=class extends ar{},Lx=class extends ar{},$x=class extends ar{async generate_speech(e,s,{threshold:r=.5,minlenratio:n=0,maxlenratio:o=20,vocoder:i=null}={}){let a={input_ids:e},{encoder_outputs:l,encoder_attention_mask:c}=await et(this,a),u=l.dims[1]/this.config.reduction_factor,p=Math.floor(u*o),d=Math.floor(u*n),_=this.config.num_mel_bins,f=[],h=null,x=null,g=0;for(;;){++g;let b=Yp(!!x),A;x?A=x.output_sequence_out:A=new S("float32",new Float32Array(_),[1,1,_]);let k={use_cache_branch:b,output_sequence:A,encoder_attention_mask:c,speaker_embeddings:s,encoder_hidden_states:l};this.addPastKeyValues(k,h),x=await G(this.sessions.decoder_model_merged,k),h=this.getPastKeyValues(x,h);let{prob:O,spectrum:N}=x;if(f.push(N),g>=d&&(Array.from(O.data).filter(D=>D>=r).length>0||g>=p))break}let w=ie(f),{waveform:y}=await G(i.sessions.model,{spectrogram:w});return{spectrogram:w,waveform:y}}},Rx=class extends m{main_input_name="spectrogram"};var ks=class extends m{},Fx=class extends ks{},Dx=class extends ks{async _call(e){return new ee(await super._call(e))}},jx=class extends ks{async _call(e){return new z(await super._call(e))}},Ux=class extends ks{async _call(e){return new ae(await super._call(e))}};var Ro=class extends m{},Bx=class extends Ro{},qx=class extends Ro{};var Fo=class extends m{},Gx=class extends Fo{},Wx=class extends Fo{};var kl=class extends m{},Vx=class extends kl{};var vl=class extends m{},Do=class extends vl{async generate_speech({input_ids:e,attention_mask:s,style:r,num_inference_steps:n=5,speed:o=1.05}){let{sampling_rate:i,chunk_compress_factor:a,base_chunk_size:l,latent_dim:c}=this.config,{last_hidden_state:u,durations:p}=await G(this.sessions.text_encoder,{input_ids:e,attention_mask:s,style:r}),d=p.div(o).mul_(i),_=l*a,f=d.data,h=Int32Array.from(f,F=>Math.ceil(F/_)),x=Math.max(...h),g=e.dims[0],w=new BigInt64Array(g*x);for(let F=0;F<g;++F)w.fill(1n,F*x,F*x+h[F]);let y=new S("int64",w,[g,x]),b=c*a,A=b*x,k=by([g,b,x]),O=k.data;for(let F=0;F<g;++F)if(h[F]!==x)for(let B=0;B<b;++B)O.fill(0,F*A+B*x+h[F],F*A+(B+1)*x);let N=ge([g],n);for(let F=0;F<n;++F){let B=ge([g],F);({denoised_latents:k}=await G(this.sessions.latent_denoiser,{style:r,noisy_latents:k,latent_mask:y,encoder_outputs:u,attention_mask:s,timestep:B,num_inference_steps:N}))}let{waveform:D}=await G(this.sessions.voice_decoder,{latents:k});return{waveform:D,durations:d}}};var lr=class extends m{},Hx=class extends lr{},Kx=class extends lr{async _call(e){return new z(await super._call(e))}},Xx=class extends lr{};var jo=class extends m{},Qx=class extends jo{},Yx=class extends jo{};var Uo=class extends m{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"]},Jx=class extends Uo{},Zx=class extends Uo{};var Bo=class extends m{},eg=class extends Bo{},tg=class extends Bo{async _call(e){return new El(await super._call(e))}},El=class extends Qs{};var Al=class extends m{},sg=class extends Al{};var Ml=class extends m{forward_params=["input_ids","attention_mask","position_ids","audio_values","past_key_values"]},Sl=class extends Ml{_merge_input_ids_with_audio_features(e){let s=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,s);return Fa({audio_token_id:this.config.ignore_index??this.config.audio_token_id,...e,audio_features:r})}},rg=class extends Sl{};var cr=class extends m{},ng=class extends cr{},og=class extends cr{async _call(e){return new Re(await super._call(e))}},ig=class extends cr{async _call(e){return new z(await super._call(e))}};var vs=class extends m{},ag=class extends vs{},lg=class extends vs{async _call(e){return new Re(await super._call(e))}},cg=class extends vs{async _call(e){return new z(await super._call(e))}},ug=class extends vs{async _call(e){return new Y(await super._call(e))}};var qo=class extends m{},pg=class extends qo{},dg=class extends qo{};var _g=class extends m{main_input_name="pixel_values";forward_params=["pixel_values","decoder_input_ids","encoder_hidden_states","past_key_values"]};var Go=class extends m{},fg=class extends Go{},mg=class extends Go{async _call(e){return new z(await super._call(e))}};var Ol=class extends m{},hg=class extends Ol{};var Wo=class extends m{},xg=class extends Wo{},gg=class extends Wo{async _call(e){return new z(await super._call(e))}};var Il=class extends m{},wg=class extends Il{async _call(e){return new ba(await super._call(e))}};var Tl=class extends m{},yg=class extends Tl{};var zl=class extends de{constructor({waveform:e,spectrogram:s}){super(),this.waveform=e,this.spectrogram=s}},Pl=class extends m{},bg=class extends Pl{async _call(e){return new zl(await super._call(e))}};var ur=class extends m{},kg=class extends ur{},vg=class extends ur{async _call(e){return new Re(await super._call(e))}},Eg=class extends ur{async _call(e){return new z(await super._call(e))}};var Cl=class extends de{constructor({logits:e,embeddings:s}){super(),this.logits=e,this.embeddings=s}},Yt=class extends m{},Ag=class extends Yt{},Mg=class extends Yt{async _call(e){return new Re(await super._call(e))}},Sg=class extends Yt{async _call(e){return new z(await super._call(e))}},Og=class extends Yt{async _call(e){return new Cl(await super._call(e))}},Ig=class extends Yt{async _call(e){return new Y(await super._call(e))}};var Nl=class extends m{},Tg=class extends Nl{};var Ll=class extends Gs{return_timestamps=null;return_token_timestamps=null;num_frames=null;alignment_heads=null;task=null;language=null;no_timestamps_token_id=null;prompt_ids=null;is_multilingual=null;lang_to_id=null;task_to_id=null;max_initial_timestamp_index=1};var Vo=class extends m{requires_attention_mask=!1;main_input_name="input_features";forward_params=["input_features","attention_mask","decoder_input_ids","decoder_attention_mask","past_key_values"]},zg=class extends Vo{},$l=class extends Vo{_prepare_generation_config(e,s){return super._prepare_generation_config(e,s,Ll)}_retrieve_init_tokens(e){let s=[e.decoder_start_token_id],r=e.language,n=e.task;if(e.is_multilingual){r||(L.warn("No language specified - defaulting to English (en)."),r="en");let i=`<|${Ey(r)}|>`;s.push(e.lang_to_id[i]),s.push(e.task_to_id[n??"transcribe"])}else if(r||n)throw new Error("Cannot specify `task` or `language` for an English-only model. If the model is intended to be multilingual, pass `is_multilingual=true` to generate, or update the generation config.");return!e.return_timestamps&&e.no_timestamps_token_id&&s.at(-1)!==e.no_timestamps_token_id?s.push(e.no_timestamps_token_id):e.return_timestamps&&s.at(-1)===e.no_timestamps_token_id&&(L.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),s.pop()),s.filter(o=>o!=null)}async generate({inputs:e=null,generation_config:s=null,logits_processor:r=null,stopping_criteria:n=null,...o}){s=this._prepare_generation_config(s,o);let i=o.decoder_input_ids??this._retrieve_init_tokens(s);if(s.return_timestamps&&(r??=new fs,r.push(new Ea(s,i))),s.begin_suppress_tokens&&(r??=new fs,r.push(new qs(s.begin_suppress_tokens,i.length))),s.return_token_timestamps){if(!s.alignment_heads)throw new Error("Model generation config has no `alignment_heads`, token-level timestamps not available. See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config.");s.task==="translate"&&L.warn("Token-level timestamps may not be reliable for task 'translate'."),s.output_attentions=!0,s.return_dict_in_generate=!0}let a=await super.generate({inputs:e,generation_config:s,logits_processor:r,decoder_input_ids:i,...o});return s.return_token_timestamps&&(a.token_timestamps=this._extract_token_timestamps(a,s.alignment_heads,s.num_frames)),a}_extract_token_timestamps(e,s,r=null,n=.02){if(!e.cross_attentions)throw new Error("Model outputs must contain cross attentions to extract timestamps. This is most likely because the model was not exported with `output_attentions=True`.");r==null&&L.warn("`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).");let o=this.config.median_filter_width;o===void 0&&(L.warn("Model config has no `median_filter_width`, using default value of 7."),o=7);let i=e.cross_attentions,a=Array.from({length:this.config.decoder_layers},(h,x)=>ie(i.map(g=>g[x]),2)),l=Je(s.map(([h,x])=>{if(h>=a.length)throw new Error(`Layer index ${h} is out of bounds for cross attentions (length ${a.length}).`);return r?a[h].slice(null,x,null,[0,r]):a[h].slice(null,x)})).transpose(1,0,2,3),[c,u]=vc(l,-2,0,!0),p=l.clone();for(let h=0;h<p.dims[0];++h){let x=p[h];for(let g=0;g<x.dims[0];++g){let w=x[g],y=c[h][g][0].data,b=u[h][g][0].data;for(let A=0;A<w.dims[0];++A){let k=w[A].data;for(let O=0;O<k.length;++O)k[O]=(k[O]-b[O])/y[O];k.set(Qw(k,o))}}}let d=[Vi(p,1)],_=e.sequences.dims,f=new S("float32",new Float32Array(_[0]*_[1]),_);for(let h=0;h<_[0];++h){let x=d[h].neg().squeeze_(0),[g,w]=Jw(x.tolist()),y=Array.from({length:g.length-1},(k,O)=>g[O+1]-g[O]),b=Pe([1],y).map(k=>!!k),A=[];for(let k=0;k<b.length;++k)b[k]&&A.push(w[k]*n);f[h].data.set(A,1)}return f}},Pg=class extends $l{};var Jt=class extends m{},Cg=class extends Jt{},Ng=class extends Jt{async _call(e){return new ee(await super._call(e))}},Lg=class extends Jt{async _call(e){return new z(await super._call(e))}},$g=class extends Jt{async _call(e){return new Y(await super._call(e))}},Rg=class extends Jt{async _call(e){return new ae(await super._call(e))}};var Zt=class extends m{},Fg=class extends Zt{},Dg=class extends Zt{async _call(e){return new ee(await super._call(e))}},jg=class extends Zt{async _call(e){return new z(await super._call(e))}},Ug=class extends Zt{async _call(e){return new Y(await super._call(e))}},Bg=class extends Zt{async _call(e){return new ae(await super._call(e))}};var Ho=class extends m{},qg=class extends Ho{},Gg=class extends Ho{async _call(e){return new Rl(await super._call(e))}},Rl=class extends de{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}};var Ko=class extends m{},Wg=class extends Ko{},Vg=class extends Ko{};var oE=new Map([["bert","BertModel"],["neobert","NeoBertModel"],["modernbert","ModernBertModel"],["nomic_bert","NomicBertModel"],["roformer","RoFormerModel"],["electra","ElectraModel"],["esm","EsmModel"],["convbert","ConvBertModel"],["camembert","CamembertModel"],["deberta","DebertaModel"],["deberta-v2","DebertaV2Model"],["mpnet","MPNetModel"],["albert","AlbertModel"],["distilbert","DistilBertModel"],["roberta","RobertaModel"],["xlm","XLMModel"],["xlm-roberta","XLMRobertaModel"],["clap","ClapModel"],["clip","CLIPModel"],["clipseg","CLIPSegModel"],["chinese_clip","ChineseCLIPModel"],["siglip","SiglipModel"],["jina_clip","JinaCLIPModel"],["mobilebert","MobileBertModel"],["squeezebert","SqueezeBertModel"],["wav2vec2","Wav2Vec2Model"],["wav2vec2-bert","Wav2Vec2BertModel"],["unispeech","UniSpeechModel"],["unispeech-sat","UniSpeechSatModel"],["hubert","HubertModel"],["wavlm","WavLMModel"],["audio-spectrogram-transformer","ASTModel"],["vits","VitsModel"],["pyannote","PyAnnoteModel"],["wespeaker-resnet","WeSpeakerResNetModel"],["detr","DetrModel"],["rt_detr","RTDetrModel"],["rt_detr_v2","RTDetrV2Model"],["rf_detr","RFDetrModel"],["d_fine","DFineModel"],["table-transformer","TableTransformerModel"],["vit","ViTModel"],["ijepa","IJepaModel"],["pvt","PvtModel"],["vit_msn","ViTMSNModel"],["vit_mae","ViTMAEModel"],["groupvit","GroupViTModel"],["fastvit","FastViTModel"],["mobilevit","MobileViTModel"],["mobilevitv2","MobileViTV2Model"],["owlvit","OwlViTModel"],["owlv2","Owlv2Model"],["beit","BeitModel"],["deit","DeiTModel"],["hiera","HieraModel"],["convnext","ConvNextModel"],["convnextv2","ConvNextV2Model"],["dinov2","Dinov2Model"],["dinov2_with_registers","Dinov2WithRegistersModel"],["dinov3_vit","DINOv3ViTModel"],["dinov3_convnext","DINOv3ConvNextModel"],["resnet","ResNetModel"],["swin","SwinModel"],["swin2sr","Swin2SRModel"],["donut-swin","DonutSwinModel"],["yolos","YolosModel"],["dpt","DPTModel"],["glpn","GLPNModel"],["hifigan","SpeechT5HifiGan"],["efficientnet","EfficientNetModel"],["decision_transformer","DecisionTransformerModel"],["patchtst","PatchTSTModel"],["patchtsmixer","PatchTSMixerModel"],["mobilenet_v1","MobileNetV1Model"],["mobilenet_v2","MobileNetV2Model"],["mobilenet_v3","MobileNetV3Model"],["mobilenet_v4","MobileNetV4Model"],["maskformer","MaskFormerModel"],["mgp-str","MgpstrForSceneTextRecognition"],["style_text_to_speech_2","StyleTextToSpeech2Model"]]),iE=new Map([["t5","T5Model"],["longt5","LongT5Model"],["mt5","MT5Model"],["bart","BartModel"],["mbart","MBartModel"],["marian","MarianModel"],["whisper","WhisperModel"],["m2m_100","M2M100Model"],["blenderbot","BlenderbotModel"],["blenderbot-small","BlenderbotSmallModel"]]),aE=new Map([["mimi","MimiModel"],["dac","DacModel"],["snac","SnacModel"]]),lE=new Map([["bloom","BloomModel"],["jais","JAISModel"],["gpt2","GPT2Model"],["gpt_oss","GptOssModel"],["gptj","GPTJModel"],["gpt_bigcode","GPTBigCodeModel"],["gpt_neo","GPTNeoModel"],["gpt_neox","GPTNeoXModel"],["codegen","CodeGenModel"],["llama","LlamaModel"],["apertus","ApertusModel"],["nanochat","NanoChatModel"],["arcee","ArceeModel"],["afmoe","AfmoeModel"],["lfm2","Lfm2Model"],["lfm2_moe","Lfm2MoeModel"],["smollm3","SmolLM3Model"],["exaone","ExaoneModel"],["olmo","OlmoModel"],["olmo2","Olmo2Model"],["olmo3","Olmo3Model"],["mobilellm","MobileLLMModel"],["granite","GraniteModel"],["granitemoehybrid","GraniteMoeHybridModel"],["cohere","CohereModel"],["cohere2","Cohere2Model"],["gemma","GemmaModel"],["gemma2","Gemma2Model"],["vaultgemma","VaultGemmaModel"],["gemma3_text","Gemma3Model"],["helium","HeliumModel"],["glm","GlmModel"],["openelm","OpenELMModel"],["qwen2","Qwen2Model"],["qwen3","Qwen3Model"],["phi","PhiModel"],["phi3","Phi3Model"],["mpt","MptModel"],["opt","OPTModel"],["mistral","MistralModel"],["ministral","MinistralModel"],["ministral3","Ministral3Model"],["ernie4_5","Ernie4_5_Model"],["starcoder2","Starcoder2Model"],["falcon","FalconModel"],["falcon_h1","FalconH1Model"],["stablelm","StableLmModel"],["modernbert-decoder","ModernBertDecoderModel"],["hunyuan_v1_dense","HunYuanDenseV1Model"],["youtu","YoutuModel"]]),Xy=new Map([["speecht5","SpeechT5ForSpeechToText"],["whisper","WhisperForConditionalGeneration"],["lite-whisper","LiteWhisperForConditionalGeneration"],["moonshine","MoonshineForConditionalGeneration"]]),Qy=new Map([["speecht5","SpeechT5ForTextToSpeech"]]),Yy=new Map([["vits","VitsModel"],["musicgen","MusicgenForConditionalGeneration"],["supertonic","SupertonicForConditionalGeneration"]]),Jy=new Map([["bert","BertForSequenceClassification"],["neobert","NeoBertForSequenceClassification"],["modernbert","ModernBertForSequenceClassification"],["roformer","RoFormerForSequenceClassification"],["electra","ElectraForSequenceClassification"],["esm","EsmForSequenceClassification"],["convbert","ConvBertForSequenceClassification"],["camembert","CamembertForSequenceClassification"],["deberta","DebertaForSequenceClassification"],["deberta-v2","DebertaV2ForSequenceClassification"],["mpnet","MPNetForSequenceClassification"],["albert","AlbertForSequenceClassification"],["distilbert","DistilBertForSequenceClassification"],["roberta","RobertaForSequenceClassification"],["xlm","XLMForSequenceClassification"],["xlm-roberta","XLMRobertaForSequenceClassification"],["bart","BartForSequenceClassification"],["mbart","MBartForSequenceClassification"],["mobilebert","MobileBertForSequenceClassification"],["squeezebert","SqueezeBertForSequenceClassification"]]),Zy=new Map([["bert","BertForTokenClassification"],["neobert","NeoBertForTokenClassification"],["modernbert","ModernBertForTokenClassification"],["roformer","RoFormerForTokenClassification"],["electra","ElectraForTokenClassification"],["esm","EsmForTokenClassification"],["convbert","ConvBertForTokenClassification"],["camembert","CamembertForTokenClassification"],["deberta","DebertaForTokenClassification"],["deberta-v2","DebertaV2ForTokenClassification"],["mpnet","MPNetForTokenClassification"],["distilbert","DistilBertForTokenClassification"],["roberta","RobertaForTokenClassification"],["xlm","XLMForTokenClassification"],["xlm-roberta","XLMRobertaForTokenClassification"]]),e0=new Map([["t5","T5ForConditionalGeneration"],["longt5","LongT5ForConditionalGeneration"],["mt5","MT5ForConditionalGeneration"],["bart","BartForConditionalGeneration"],["mbart","MBartForConditionalGeneration"],["marian","MarianMTModel"],["m2m_100","M2M100ForConditionalGeneration"],["blenderbot","BlenderbotForConditionalGeneration"],["blenderbot-small","BlenderbotSmallForConditionalGeneration"]]),t0=new Map([["bloom","BloomForCausalLM"],["gpt2","GPT2LMHeadModel"],["gpt_oss","GptOssForCausalLM"],["jais","JAISLMHeadModel"],["gptj","GPTJForCausalLM"],["gpt_bigcode","GPTBigCodeForCausalLM"],["gpt_neo","GPTNeoForCausalLM"],["gpt_neox","GPTNeoXForCausalLM"],["codegen","CodeGenForCausalLM"],["llama","LlamaForCausalLM"],["nanochat","NanoChatForCausalLM"],["apertus","ApertusForCausalLM"],["llama4_text","Llama4ForCausalLM"],["arcee","ArceeForCausalLM"],["afmoe","AfmoeForCausalLM"],["lfm2","Lfm2ForCausalLM"],["lfm2_moe","Lfm2MoeForCausalLM"],["smollm3","SmolLM3ForCausalLM"],["exaone","ExaoneForCausalLM"],["olmo","OlmoForCausalLM"],["olmo2","Olmo2ForCausalLM"],["olmo3","Olmo3ForCausalLM"],["mobilellm","MobileLLMForCausalLM"],["granite","GraniteForCausalLM"],["granitemoehybrid","GraniteMoeHybridForCausalLM"],["cohere","CohereForCausalLM"],["cohere2","Cohere2ForCausalLM"],["gemma","GemmaForCausalLM"],["gemma2","Gemma2ForCausalLM"],["vaultgemma","VaultGemmaForCausalLM"],["gemma3_text","Gemma3ForCausalLM"],["helium","HeliumForCausalLM"],["glm","GlmForCausalLM"],["openelm","OpenELMForCausalLM"],["qwen2","Qwen2ForCausalLM"],["qwen3","Qwen3ForCausalLM"],["phi","PhiForCausalLM"],["phi3","Phi3ForCausalLM"],["mpt","MptForCausalLM"],["opt","OPTForCausalLM"],["mbart","MBartForCausalLM"],["mistral","MistralForCausalLM"],["ministral","MinistralForCausalLM"],["ministral3","Ministral3ForCausalLM"],["ernie4_5","Ernie4_5_ForCausalLM"],["starcoder2","Starcoder2ForCausalLM"],["falcon","FalconForCausalLM"],["falcon_h1","FalconH1ForCausalLM"],["trocr","TrOCRForCausalLM"],["stablelm","StableLmForCausalLM"],["modernbert-decoder","ModernBertDecoderForCausalLM"],["hunyuan_v1_dense","HunYuanDenseV1ForCausalLM"],["youtu","YoutuForCausalLM"],["phi3_v","Phi3VForCausalLM"]]),cE=new Map([["multi_modality","MultiModalityCausalLM"]]),s0=new Map([["bert","BertForMaskedLM"],["neobert","NeoBertForMaskedLM"],["modernbert","ModernBertForMaskedLM"],["roformer","RoFormerForMaskedLM"],["electra","ElectraForMaskedLM"],["esm","EsmForMaskedLM"],["convbert","ConvBertForMaskedLM"],["camembert","CamembertForMaskedLM"],["deberta","DebertaForMaskedLM"],["deberta-v2","DebertaV2ForMaskedLM"],["mpnet","MPNetForMaskedLM"],["albert","AlbertForMaskedLM"],["distilbert","DistilBertForMaskedLM"],["roberta","RobertaForMaskedLM"],["xlm","XLMWithLMHeadModel"],["xlm-roberta","XLMRobertaForMaskedLM"],["mobilebert","MobileBertForMaskedLM"],["squeezebert","SqueezeBertForMaskedLM"]]),r0=new Map([["bert","BertForQuestionAnswering"],["neobert","NeoBertForQuestionAnswering"],["roformer","RoFormerForQuestionAnswering"],["electra","ElectraForQuestionAnswering"],["convbert","ConvBertForQuestionAnswering"],["camembert","CamembertForQuestionAnswering"],["deberta","DebertaForQuestionAnswering"],["deberta-v2","DebertaV2ForQuestionAnswering"],["mpnet","MPNetForQuestionAnswering"],["albert","AlbertForQuestionAnswering"],["distilbert","DistilBertForQuestionAnswering"],["roberta","RobertaForQuestionAnswering"],["xlm","XLMForQuestionAnswering"],["xlm-roberta","XLMRobertaForQuestionAnswering"],["mobilebert","MobileBertForQuestionAnswering"],["squeezebert","SqueezeBertForQuestionAnswering"]]),n0=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"]]),o0=new Map([["llava","LlavaForConditionalGeneration"],["llava_onevision","LlavaOnevisionForConditionalGeneration"],["moondream1","Moondream1ForConditionalGeneration"],["florence2","Florence2ForConditionalGeneration"],["qwen2_vl","Qwen2VLForConditionalGeneration"],["qwen2_5_vl","Qwen2_5_VLForConditionalGeneration"],["qwen3_vl","Qwen3VLForConditionalGeneration"],["qwen3_5","Qwen3_5ForConditionalGeneration"],["qwen3_5_moe","Qwen3_5MoeForConditionalGeneration"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"],["paligemma","PaliGemmaForConditionalGeneration"],["llava_qwen2","LlavaQwen2ForCausalLM"],["gemma3n","Gemma3nForConditionalGeneration"],["mistral3","Mistral3ForConditionalGeneration"]]),i0=new Map([["ultravox","UltravoxModel"],["voxtral","VoxtralForConditionalGeneration"]]),uE=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"]]),a0=new Map([["vit","ViTForImageClassification"],["ijepa","IJepaForImageClassification"],["pvt","PvtForImageClassification"],["vit_msn","ViTMSNForImageClassification"],["fastvit","FastViTForImageClassification"],["mobilevit","MobileViTForImageClassification"],["mobilevitv2","MobileViTV2ForImageClassification"],["beit","BeitForImageClassification"],["deit","DeiTForImageClassification"],["hiera","HieraForImageClassification"],["convnext","ConvNextForImageClassification"],["convnextv2","ConvNextV2ForImageClassification"],["dinov2","Dinov2ForImageClassification"],["dinov2_with_registers","Dinov2WithRegistersForImageClassification"],["resnet","ResNetForImageClassification"],["swin","SwinForImageClassification"],["segformer","SegformerForImageClassification"],["efficientnet","EfficientNetForImageClassification"],["mobilenet_v1","MobileNetV1ForImageClassification"],["mobilenet_v2","MobileNetV2ForImageClassification"],["mobilenet_v3","MobileNetV3ForImageClassification"],["mobilenet_v4","MobileNetV4ForImageClassification"]]),l0=new Map([["detr","DetrForObjectDetection"],["rt_detr","RTDetrForObjectDetection"],["rt_detr_v2","RTDetrV2ForObjectDetection"],["rf_detr","RFDetrForObjectDetection"],["d_fine","DFineForObjectDetection"],["table-transformer","TableTransformerForObjectDetection"],["yolos","YolosForObjectDetection"]]),c0=new Map([["owlvit","OwlViTForObjectDetection"],["owlv2","Owlv2ForObjectDetection"],["grounding-dino","GroundingDinoForObjectDetection"]]),pr=new Map([["detr","DetrForSegmentation"],["clipseg","CLIPSegForImageSegmentation"]]),u0=new Map([["segformer","SegformerForSemanticSegmentation"],["sapiens","SapiensForSemanticSegmentation"],["swin","SwinForSemanticSegmentation"],["mobilenet_v1","MobileNetV1ForSemanticSegmentation"],["mobilenet_v2","MobileNetV2ForSemanticSegmentation"],["mobilenet_v3","MobileNetV3ForSemanticSegmentation"],["mobilenet_v4","MobileNetV4ForSemanticSegmentation"]]),p0=new Map([["detr","DetrForSegmentation"],["maskformer","MaskFormerForInstanceSegmentation"]]),d0=new Map([["sam","SamModel"],["sam2","Sam2Model"],["edgetam","EdgeTamModel"],["sam3_tracker","Sam3TrackerModel"]]),_0=new Map([["wav2vec2","Wav2Vec2ForCTC"],["wav2vec2-bert","Wav2Vec2BertForCTC"],["unispeech","UniSpeechForCTC"],["unispeech-sat","UniSpeechSatForCTC"],["wavlm","WavLMForCTC"],["hubert","HubertForCTC"],["parakeet_ctc","ParakeetForCTC"]]),f0=new Map([["wav2vec2","Wav2Vec2ForSequenceClassification"],["wav2vec2-bert","Wav2Vec2BertForSequenceClassification"],["unispeech","UniSpeechForSequenceClassification"],["unispeech-sat","UniSpeechSatForSequenceClassification"],["wavlm","WavLMForSequenceClassification"],["hubert","HubertForSequenceClassification"],["audio-spectrogram-transformer","ASTForAudioClassification"]]),m0=new Map([["wavlm","WavLMForXVector"]]),h0=new Map([["unispeech-sat","UniSpeechSatForAudioFrameClassification"],["wavlm","WavLMForAudioFrameClassification"],["wav2vec2","Wav2Vec2ForAudioFrameClassification"],["pyannote","PyAnnoteForAudioFrameClassification"]]),x0=new Map([["vitmatte","VitMatteForImageMatting"]]),pE=new Map([["patchtst","PatchTSTForPrediction"],["patchtsmixer","PatchTSMixerForPrediction"]]),g0=new Map([["swin2sr","Swin2SRForImageSuperResolution"]]),w0=new Map([["dpt","DPTForDepthEstimation"],["depth_anything","DepthAnythingForDepthEstimation"],["glpn","GLPNForDepthEstimation"],["sapiens","SapiensForDepthEstimation"],["depth_pro","DepthProForDepthEstimation"],["metric3d","Metric3DForDepthEstimation"],["metric3dv2","Metric3Dv2ForDepthEstimation"]]),y0=new Map([["sapiens","SapiensForNormalEstimation"]]),b0=new Map([["vitpose","VitPoseForPoseEstimation"]]),k0=new Map([["clip","CLIPVisionModelWithProjection"],["siglip","SiglipVisionModel"],["jina_clip","JinaCLIPVisionModel"]]),Hg=[[oE,I.EncoderOnly],[iE,I.EncoderDecoder],[lE,I.DecoderOnlyWithoutHead],[aE,I.AutoEncoder],[Jy,I.EncoderOnly],[Zy,I.EncoderOnly],[e0,I.Seq2Seq],[Xy,I.Seq2Seq],[t0,I.DecoderOnly],[cE,I.MultiModality],[s0,I.EncoderOnly],[r0,I.EncoderOnly],[n0,I.Vision2Seq],[o0,I.ImageTextToText],[i0,I.AudioTextToText],[a0,I.EncoderOnly],[pr,I.EncoderOnly],[p0,I.EncoderOnly],[u0,I.EncoderOnly],[x0,I.EncoderOnly],[pE,I.EncoderOnly],[g0,I.EncoderOnly],[w0,I.EncoderOnly],[y0,I.EncoderOnly],[b0,I.EncoderOnly],[l0,I.EncoderOnly],[c0,I.EncoderOnly],[d0,I.MaskGeneration],[_0,I.EncoderOnly],[f0,I.EncoderOnly],[Qy,I.Seq2Seq],[Yy,I.EncoderOnly],[m0,I.EncoderOnly],[h0,I.EncoderOnly],[k0,I.EncoderOnly]];for(let[t,e]of Hg)for(let s of t.values()){gt.set(s,e);let r=Xo[s];hs.set(r,s),Ra.set(s,r)}var dE=[["MusicgenForConditionalGeneration",oo,I.Musicgen],["Phi3VForCausalLM",wo,I.Phi3V],["CLIPTextModelWithProjection",Zr,I.EncoderOnly],["SiglipTextModel",Co,I.EncoderOnly],["JinaCLIPTextModel",jn,I.EncoderOnly],["ClapTextModelWithProjection",Yr,I.EncoderOnly],["ClapAudioModelWithProjection",Jr,I.EncoderOnly],["DacEncoderModel",cn,I.EncoderOnly],["DacDecoderModel",un,I.EncoderOnly],["MimiEncoderModel",Kn,I.EncoderOnly],["MimiDecoderModel",Xn,I.EncoderOnly],["SnacEncoderModel",Lo,I.EncoderOnly],["SnacDecoderModel",$o,I.EncoderOnly],["Gemma3nForConditionalGeneration",En,I.ImageAudioTextToText],["SupertonicForConditionalGeneration",Do,I.Supertonic],["ChatterboxModel",Qr,I.Chatterbox]];for(let[t,e,s]of dE)gt.set(t,s),hs.set(e,t),Ra.set(t,e);var Kg=new Map([["modnet",pr],["birefnet",pr],["isnet",pr],["ben",pr]]);for(let[t,e]of Kg.entries())e.set(t,"PreTrainedModel"),gt.set(t,I.EncoderOnly),Ra.set(t,m);gt.set("PreTrainedModel",I.EncoderOnly);hs.set(m,"PreTrainedModel");var ue={MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES:Jy,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES:Zy,MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES:Qy,MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES:Yy,MODEL_FOR_MASKED_LM_MAPPING_NAMES:s0,MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES:r0,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES:a0,MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES:pr,MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES:u0,MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES:p0,MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES:l0,MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES:c0,MODEL_FOR_MASK_GENERATION_MAPPING_NAMES:d0,MODEL_FOR_CTC_MAPPING_NAMES:_0,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES:f0,MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES:m0,MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES:h0,MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES:uE,MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES:x0,MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES:g0,MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES:w0,MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES:y0,MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES:b0,MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES:k0,MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES:o0,MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES:i0,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES:e0,MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES:Xy,MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:t0,MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES:n0};Wy(ue);var ce=class{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main",model_file_name:a=null,subfolder:l="onnx",device:c=null,dtype:u=null,use_external_data_format:p=null,session_options:d={}}={}){let _={progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:u,use_external_data_format:p,session_options:d};if(_.config=await It.from_pretrained(e,_),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);let f=_.config.model_type;for(let h of this.MODEL_CLASS_MAPPINGS){let x=h.get(f);if(!x){for(let g of h.values())if(g[0]===f){x=g;break}if(!x)continue}return await Xo[x].from_pretrained(e,_)}if(this.BASE_IF_FAIL)return Kg.has(f)||L.warn(`Unknown model class "${f}", attempting to construct from base class.`),await m.from_pretrained(e,_);throw Error(`Unsupported model type: ${f}`)}},zt=class extends ce{static MODEL_CLASS_MAPPINGS=Hg.map(e=>e[0]);static BASE_IF_FAIL=!0},Qo=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]},Fl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]},dr=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]},Dl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]},jl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]},Ul=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]},Bl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES]},ql=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_MASKED_LM_MAPPING_NAMES]},Gl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]},Wl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]},Vl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]},Yo=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]},Jo=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]},Zo=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES]},Hl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]},Kl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]},v0=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]},Xl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_CTC_MAPPING_NAMES]},Ql=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]},E0=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]},A0=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]},Yl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]},M0=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]},Jl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]},Zl=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]},S0=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES]},O0=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES]},ec=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]},I0=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES]},T0=class extends ce{static MODEL_CLASS_MAPPINGS=[ue.MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES]};async function ke(t){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(e=>ye.read(e)))}async function es(t,e){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(s=>typeof s=="string"||s instanceof URL?bu(s,e):s instanceof Float64Array?new Float32Array(s):s))}function ei(t,e){e&&(t=t.map(i=>i|0));let[s,r,n,o]=t;return{xmin:s,ymin:r,xmax:n,ymax:o}}var V=class extends ve{constructor({task:e,model:s,tokenizer:r=null,processor:n=null}){super(),this.task=e,this.model=s,this.tokenizer=r,this.processor=n}async dispose(){await this.model.dispose()}};var ti=class extends V{async _call(e,{top_k:s=1}={}){let r=this.tokenizer(e,{padding:!0,truncation:!0}),n=await this.model(r),{problem_type:o,id2label:i}=this.model.config,a=o==="multi_label_classification"?c=>c.sigmoid():c=>new S("float32",pe(c.data),c.dims),l=[];for(let c of n.logits){let u=a(c),p=await at(u,s),d=p[0].tolist(),f=p[1].tolist().map((h,x)=>({label:i?i[h]:`LABEL_${h}`,score:d[x]}));s===1?l.push(...f):l.push(f)}return Array.isArray(e)||s===1?l:l[0]}};var si=class extends V{async _call(e,{ignore_labels:s=["O"]}={}){let r=Array.isArray(e),n=this.tokenizer(r?e:[e],{padding:!0,truncation:!0}),i=(await this.model(n)).logits,a=this.model.config.id2label,l=[];for(let c=0;c<i.dims[0];++c){let u=n.input_ids[c],p=i[c],d=[];for(let _=0;_<p.dims[0];++_){let f=p[_],h=le(f.data)[1],x=a?a[h]:`LABEL_${h}`;if(s.includes(x))continue;let g=this.tokenizer.decode([u[_].item()],{skip_special_tokens:!0});if(g==="")continue;let w=pe(f.data);d.push({entity:x,score:w[h],index:_,word:g})}l.push(d)}return r?l:l[0]}};var ri=class extends V{async _call(e,s,{top_k:r=1}={}){let n=this.tokenizer(e,{text_pair:s,padding:!0,truncation:!0}),o=Array.isArray(e),{start_logits:i,end_logits:a}=await this.model(n),l=n.input_ids.tolist(),c=n.attention_mask.tolist(),{all_special_ids:u,sep_token_id:p}=this.tokenizer,d=[];for(let _=0;_<i.dims[0];++_){let f=l[_],h=f.findIndex(k=>k==p),x=i[_].tolist(),g=a[_].tolist();for(let k=1;k<x.length;++k)(c[_]==0||k<=h||u.findIndex(O=>O==f[k])!==-1)&&(x[k]=-1/0,g[k]=-1/0);let w=pe(x).map((k,O)=>[k,O]),y=pe(g).map((k,O)=>[k,O]);w[0][0]=0,y[0][0]=0;let b=cw(w,y).filter(k=>k[0][1]<=k[1][1]).map(k=>[k[0][1],k[1][1],k[0][0]*k[1][0]]).sort((k,O)=>O[2]-k[2]),A=[];for(let k=0;k<Math.min(b.length,r);++k){let[O,N,D]=b[k],F=f.slice(O,N+1),B=this.tokenizer.decode(F,{skip_special_tokens:!0});A.push({answer:B,score:D})}r===1?d.push(...A):d.push(A)}return o?d:d[0]}};var ni=class extends V{async _call(e,{top_k:s=5}={}){let{mask_token_id:r,mask_token:n}=this.tokenizer,o=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:i}=await this.model(o),a=[],l=o.input_ids.tolist();for(let c=0;c<l.length;++c){let u=l[c],p=u.findIndex(x=>x==r);if(p===-1)throw Error(`Mask token (${n}) not found in text.`);let d=i[c][p],_=await at(new S("float32",pe(d.data),d.dims),s),f=_[0].tolist(),h=_[1].tolist();a.push(h.map((x,g)=>{let w=u.slice();return w[p]=x,{score:f[g],token:Number(x),token_str:this.tokenizer.decode([x]),sequence:this.tokenizer.decode(w,{skip_special_tokens:!0})}}))}return Array.isArray(e)?a:a[0]}};var Pt=class extends V{_key="generated_text";async _call(e,s={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map(l=>this.model.config.prefix+l));let r=this.model.config.task_specific_params;r&&r[this.task]&&r[this.task].prefix&&(e=e.map(l=>r[this.task].prefix+l));let n=this.tokenizer,o={padding:!0,truncation:!0},i;this.task==="translation"&&"_build_translation_inputs"in n?i=n._build_translation_inputs(e,o,s):i=n(e,o);let a=await this.model.generate({...i,...s});return n.batch_decode(a,{skip_special_tokens:!0}).map(l=>({[this._key]:l}))}};var oi=class extends Pt{_key="summary_text"};var ii=class extends Pt{_key="translation_text"};function z0(t){return Array.isArray(t)&&t.every(e=>"role"in e&&"content"in e)}var ai=class extends V{async _call(e,s={}){let r=!1,n=!1,o=s.add_special_tokens??(this.tokenizer.add_bos_token||this.tokenizer.add_eos_token)??!1,i=s.tokenizer_encode_kwargs,a;if(typeof e=="string")a=e=[e];else if(Array.isArray(e)&&e.every(f=>typeof f=="string"))r=!0,a=e;else{if(z0(e))e=[e];else if(Array.isArray(e)&&e.every(z0))r=!0;else throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");n=!0,a=e.map(f=>this.tokenizer.apply_chat_template(f,{tokenize:!1,add_generation_prompt:!0,...i})),o=!1,i=void 0}let l=n?!1:s.return_full_text??!0;this.tokenizer.padding_side="left";let c=this.tokenizer(a,{add_special_tokens:o,padding:!0,truncation:!0,...i}),u=await this.model.generate({...c,...s}),p=this.tokenizer.batch_decode(u,{skip_special_tokens:!0}),d;!l&&c.input_ids.dims.at(-1)>0&&(d=this.tokenizer.batch_decode(c.input_ids,{skip_special_tokens:!0}).map(f=>f.length));let _=Array.from({length:e.length},f=>[]);for(let f=0;f<p.length;++f){let h=Math.floor(f/u.dims[0]*e.length);d&&(p[f]=p[f].slice(d[h])),_[h].push({generated_text:n?[...e[h],{role:"assistant",content:p[f]}]:p[f]})}return!r&&_.length===1?_[0]:_}};var li=class extends V{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([s,r])=>[s.toLowerCase(),r])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(L.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,this.contradiction_id===void 0&&(L.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,s,{hypothesis_template:r="This example is {}.",multi_label:n=!1}={}){let o=Array.isArray(e);o||(e=[e]),Array.isArray(s)||(s=[s]);let i=s.map(c=>r.replace("{}",c)),a=n||s.length===1,l=[];for(let c of e){let u=[];for(let _ of i){let f=this.tokenizer(c,{text_pair:_,padding:!0,truncation:!0}),h=await this.model(f);a?u.push([h.logits.data[this.contradiction_id],h.logits.data[this.entailment_id]]):u.push(h.logits.data[this.entailment_id])}let d=(a?u.map(_=>pe(_)[1]):pe(u)).map((_,f)=>[_,f]).sort((_,f)=>f[0]-_[0]);l.push({sequence:c,labels:d.map(_=>s[_[1]]),scores:d.map(_=>_[0])})}return o?l:l[0]}};var ci=class extends V{async _call(e,{top_k:s=5}={}){let r=this.processor.feature_extractor.config.sampling_rate,n=await es(e,r),o=this.model.config.id2label,i=[];for(let a of n){let l=await this.processor(a),u=(await this.model(l)).logits[0],p=await at(new S("float32",pe(u.data),u.dims),s),d=p[0].tolist(),f=p[1].tolist().map((h,x)=>({label:o?o[h]:`LABEL_${h}`,score:d[x]}));i.push(f)}return Array.isArray(e)?i:i[0]}};var ui=class extends V{async _call(e,s,{hypothesis_template:r="This is a sound of {}."}={}){let n=!Array.isArray(e);n&&(e=[e]);let o=s.map(u=>r.replace("{}",u)),i=this.tokenizer(o,{padding:!0,truncation:!0}),a=this.processor.feature_extractor.config.sampling_rate,l=await es(e,a),c=[];for(let u of l){let p=await this.processor(u),d=await this.model({...i,...p}),_=pe(d.logits_per_audio.data);c.push([..._].map((f,h)=>({score:f,label:s[h]})))}return n?c[0]:c}};var pi=class extends V{async _call(e,s={}){switch(this.model.config.model_type){case"whisper":case"lite-whisper":return this._call_whisper(e,s);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":case"parakeet_ctc":return this._call_wav2vec2(e,s);case"moonshine":return this._call_moonshine(e,s);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,s){s.language&&L.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),s.task&&L.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');let r=!Array.isArray(e),n=r?[e]:e,o=this.processor.feature_extractor.config.sampling_rate,i=await es(n,o),a=[];for(let l of i){let c=await this.processor(l),p=(await this.model(c)).logits[0],d=[];for(let f of p)d.push(le(f.data)[1]);let _=this.tokenizer.decode(d,{skip_special_tokens:!0}).trim();a.push({text:_})}return r?a[0]:a}async _call_whisper(e,s){let r=s.return_timestamps??!1,n=s.chunk_length_s??0,o=s.force_full_sequences??!1,i=s.stride_length_s??null,a={...s};r==="word"&&(a.return_token_timestamps=!0,a.return_timestamps=!1);let l=!Array.isArray(e),c=l?[e]:e,u=this.processor.feature_extractor.config,p=u.chunk_length/this.model.config.max_source_positions,d=u.hop_length,_=u.sampling_rate,f=await es(c,_),h=[];for(let x of f){let g=[];if(n>0){if(i===null)i=n/6;else if(n<=i)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");let b=_*n,A=_*i,k=b-2*A,O=0;for(;;){let N=O+b,D=x.subarray(O,N),F=await this.processor(D),B=O===0,W=N>=x.length;if(g.push({stride:[D.length,B?0:A,W?0:A],input_features:F.input_features,is_last:W}),W)break;O+=k}}else g=[{stride:[x.length,0,0],input_features:(await this.processor(x)).input_features,is_last:!0}];for(let b of g){a.num_frames=Math.floor(b.stride[0]/d);let A=await this.model.generate({inputs:b.input_features,...a});r==="word"?(b.tokens=A.sequences.tolist()[0],b.token_timestamps=A.token_timestamps.tolist()[0].map(k=>us(k,2))):b.tokens=A[0].tolist(),b.stride=b.stride.map(k=>k/_)}let[w,y]=this.tokenizer._decode_asr(g,{time_precision:p,return_timestamps:r,force_full_sequences:o});h.push({text:w,...y})}return l?h[0]:h}async _call_moonshine(e,s){let r=!Array.isArray(e),n=r?[e]:e,o=this.processor.feature_extractor.config.sampling_rate,i=await es(n,o),a=[];for(let l of i){let c=await this.processor(l),u=Math.floor(l.length/o)*6,p=await this.model.generate({max_new_tokens:u,...s,...c}),d=this.processor.batch_decode(p,{skip_special_tokens:!0})[0];a.push({text:d})}return r?a[0]:a}};var di=class extends V{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(e){super(e),this.vocoder=e.vocoder??null}async _prepare_speaker_embeddings(e,s){if((typeof e=="string"||e instanceof URL)&&(e=new Float32Array(await(await H.fetch(e)).arrayBuffer())),e instanceof Float32Array)e=new S("float32",e,[e.length]);else if(!(e instanceof S))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");if(s>1){if(e.dims[0]===1)e=e.repeat(s,1);else if(e.dims[0]!==s)throw new Error(`Expected speaker embeddings batch size to be 1 or ${s}, but got ${e.dims[0]}.`)}return e}_postprocess_waveform(e,s,r,n=null){let o=s.data,[i,a]=s.dims,l=n?n.data:null,c=[];for(let u=0;u<i;++u){let p=l?Math.min(Math.ceil(l[u]),a):a,d=u*a;c.push(new Ir(o.slice(d,d+p),r))}return Array.isArray(e)?c:c[0]}async _call(e,s){return this.processor?this._call_text_to_spectrogram(e,s):this.model.config.model_type==="supertonic"?this._call_supertonic(e,s):this._call_text_to_waveform(e)}async _call_supertonic(e,{speaker_embeddings:s,num_inference_steps:r,speed:n}){if(!s)throw new Error("Speaker embeddings must be provided for Supertonic models.");let{sampling_rate:o,style_dim:i}=this.model.config,a=this.tokenizer(e,{padding:!0,truncation:!0}),l=a.input_ids.dims[0];s=await this._prepare_speaker_embeddings(s,l),s=s.view(l,-1,i);let{waveform:c,durations:u}=await this.model.generate_speech({...a,style:s,num_inference_steps:r,speed:n});return this._postprocess_waveform(e,c,o,u)}async _call_text_to_waveform(e){let s=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:r}=await this.model(s),n=this.model.config.sampling_rate;return this._postprocess_waveform(e,r,n)}async _call_text_to_spectrogram(e,{speaker_embeddings:s}){this.vocoder||(L.info("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await zt.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"}));let{input_ids:r}=this.tokenizer(e,{padding:!0,truncation:!0}),n=r.dims[0];s=await this._prepare_speaker_embeddings(s,n),s=s.view(n,-1);let{waveform:o}=await this.model.generate_speech(r,s,{vocoder:this.vocoder}),i=this.processor.feature_extractor.config.sampling_rate;return this._postprocess_waveform(e,o,i)}};var _i=class extends V{async _call(e,s={}){let r=Array.isArray(e),n=await ke(e),{pixel_values:o}=await this.processor(n),i=[];for(let a of o){a.dims=[1,...a.dims];let l=await this.model.generate({inputs:a,...s}),c=this.tokenizer.batch_decode(l,{skip_special_tokens:!0}).map(u=>({generated_text:u.trim()}));i.push(c)}return r?i:i[0]}};var fi=class extends V{async _call(e,{top_k:s=5}={}){let r=await ke(e),{pixel_values:n}=await this.processor(r),o=await this.model({pixel_values:n}),{id2label:i}=this.model.config,a=[];for(let l of o.logits){let c=await at(new S("float32",pe(l.data),l.dims),s),u=c[0].tolist(),d=c[1].tolist().map((_,f)=>({label:i?i[_]:`LABEL_${_}`,score:u[f]}));a.push(d)}return Array.isArray(e)?a:a[0]}};var P0={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"},Es=class extends V{async _call(e,{threshold:s=.5,mask_threshold:r=.5,overlap_mask_area_threshold:n=.8,label_ids_to_fuse:o=null,target_sizes:i=null,subtask:a=null}={}){if(Array.isArray(e)&&e.length!==1)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");let c=await ke(e),u=c.map(w=>[w.height,w.width]),p=await this.processor(c),{inputNames:d,outputNames:_}=this.model.sessions.model;if(!d.includes("pixel_values")){if(d.length!==1)throw Error(`Expected a single input name, but got ${d.length} inputs: ${d}.`);let w=d[0];if(w in p)throw Error(`Input name ${w} already exists in the inputs.`);p[w]=p.pixel_values}let f=await this.model(p),h=null;if(a!==null)h=P0[a];else if(this.processor.image_processor){for(let[w,y]of Object.entries(P0))if(y in this.processor.image_processor){h=this.processor.image_processor[y].bind(this.processor.image_processor),a=w;break}}let x=this.model.config.id2label,g=[];if(a)if(a==="panoptic"||a==="instance"){let w=h(f,s,r,n,o,i??u)[0],y=w.segmentation;for(let b of w.segments_info){let A=new Uint8ClampedArray(y.data.length);for(let O=0;O<y.data.length;++O)y.data[O]===b.id&&(A[O]=255);let k=new ye(A,y.dims[1],y.dims[0],1);g.push({score:b.score,label:x[b.label_id],mask:k})}}else if(a==="semantic"){let{segmentation:w,labels:y}=h(f,i??u)[0];for(let b of y){let A=new Uint8ClampedArray(w.data.length);for(let O=0;O<w.data.length;++O)w.data[O]===b&&(A[O]=255);let k=new ye(A,w.dims[1],w.dims[0],1);g.push({score:null,label:x[b],mask:k})}}else throw Error(`Subtask ${a} not supported.`);else{let y=f[_[0]];for(let b=0;b<u.length;++b){let A=u[b],k=y[b];k.data.some(N=>N<-1e-5||N>1+1e-5)&&k.sigmoid_();let O=await ye.fromTensor(k.mul_(255).to("uint8")).resize(A[1],A[0]);g.push({label:null,score:null,mask:O})}}return g}};var mi=class extends Es{async _call(e,s={}){let r=await ke(e),n=await super._call(e,s),o=r.map((i,a)=>{let l=i.clone();return l.putAlpha(n[a].mask),l});return Array.isArray(e)?o:o[0]}};var hi=class extends V{async _call(e,s,{hypothesis_template:r="This is a photo of {}"}={}){let n=Array.isArray(e),o=await ke(e),i=s.map(d=>r.replace("{}",d)),a=this.tokenizer(i,{padding:this.model.config.model_type==="siglip"?"max_length":!0,truncation:!0}),{pixel_values:l}=await this.processor(o),c=await this.model({...a,pixel_values:l}),u=this.model.config.model_type==="siglip"?d=>d.sigmoid().data:d=>pe(d.data),p=[];for(let d of c.logits_per_image){let f=[...u(d)].map((h,x)=>({score:h,label:s[x]}));f.sort((h,x)=>x.score-h.score),p.push(f)}return n?p:p[0]}};var xi=class extends V{async _call(e,{threshold:s=.9,percentage:r=!1}={}){let n=Array.isArray(e);if(n&&e.length!==1)throw Error("Object detection pipeline currently only supports a batch size of 1.");let o=await ke(e),i=r?null:o.map(_=>[_.height,_.width]),{pixel_values:a,pixel_mask:l}=await this.processor(o),c=await this.model({pixel_values:a,pixel_mask:l}),u=this.processor.image_processor.post_process_object_detection(c,s,i),{id2label:p}=this.model.config,d=u.map(_=>_.boxes.map((f,h)=>({score:_.scores[h],label:p[_.classes[h]],box:ei(f,!r)})));return n?d:d[0]}};var gi=class extends V{async _call(e,s,{threshold:r=.1,top_k:n=null,percentage:o=!1}={}){let i=Array.isArray(e),a=await ke(e),l=this.tokenizer(s,{padding:!0,truncation:!0}),c=await this.processor(a),u=[];for(let p=0;p<a.length;++p){let d=a[p],_=o?null:[[d.height,d.width]],f=c.pixel_values[p].unsqueeze_(0),h=await this.model({...l,pixel_values:f}),x;if("post_process_grounded_object_detection"in this.processor){let g=this.processor.post_process_grounded_object_detection(h,l.input_ids,{box_threshold:r,text_threshold:r,target_sizes:_})[0];x=g.boxes.map((w,y)=>({score:g.scores[y],label:g.labels[y],box:ei(w,!o)}))}else{let g=this.processor.image_processor.post_process_object_detection(h,r,_,!0)[0];x=g.boxes.map((w,y)=>({score:g.scores[y],label:s[g.classes[y]],box:ei(w,!o)}))}x.sort((g,w)=>w.score-g.score),n!==null&&(x=x.slice(0,n)),u.push(x)}return i?u:u[0]}};var wi=class extends V{async _call(e,s,r={}){if(Array.isArray(e)){if(e.length!==1)throw Error("Document Question Answering pipeline currently only supports a batch size of 1.");e=e[0]}let n=(await ke(e))[0],{pixel_values:o}=await this.processor(n),i=`<s_docvqa><s_question>${s}</s_question><s_answer>`,a=this.tokenizer(i,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,l=await this.model.generate({inputs:o,max_length:this.model.config.decoder.max_position_embeddings,decoder_input_ids:a,...r}),u=this.tokenizer.batch_decode(l)[0].match(/<s_answer>(.*?)<\/s_answer>/),p=null;return u&&u.length>=2&&(p=u[1].trim()),[{answer:p}]}};var yi=class extends V{async _call(e){let s=await ke(e),r=await this.processor(s),n=await this.model(r),o=[];for(let i of n.reconstruction){let a=i.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");o.push(ye.fromTensor(a))}return Array.isArray(e)?o:o[0]}};var bi=class extends V{async _call(e){let s=await ke(e),r=await this.processor(s),{predicted_depth:n}=await this.model(r),o=[];for(let i=0;i<s.length;++i){let a=n[i],[l,c]=a.dims.slice(-2),[u,p]=s[i].size,d=(await Ye(a.view(1,1,l,c),{size:[p,u],mode:"bilinear"})).view(p,u),_=d.min().item(),f=d.max().item(),h=d.sub(_).div_(f-_).mul_(255).to("uint8").unsqueeze(0),x=ye.fromTensor(h);o.push({predicted_depth:d,depth:x})}return Array.isArray(e)?o:o[0]}};var ki=class extends V{async _call(e,{pooling:s="none",normalize:r=!1,quantize:n=!1,precision:o="binary"}={}){let i=this.tokenizer(e,{padding:!0,truncation:!0}),a=await this.model(i),l=a.last_hidden_state??a.logits??a.token_embeddings;switch(s){case"none":break;case"mean":l=yy(l,i.attention_mask);break;case"first_token":case"cls":l=l.slice(null,0);break;case"last_token":case"eos":l=l.slice(null,-1);break;default:throw Error(`Pooling method '${s}' not supported.`)}return r&&(l=l.normalize(2,-1)),n&&(l=ky(l,o)),l}};var vi=class extends V{async _call(e,{pool:s=null}={}){let r=await ke(e),{pixel_values:n}=await this.processor(r),o=await this.model({pixel_values:n}),i;if(s){if(!("pooler_output"in o))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");i=o.pooler_output}else i=o.last_hidden_state??o.logits??o.image_embeds;return i}};var _r=Object.freeze({"text-classification":{tokenizer:$,pipeline:ti,model:Qo,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:$,pipeline:si,model:Fl,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:$,pipeline:ri,model:Gl,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:$,pipeline:ni,model:ql,default:{model:"onnx-community/ettin-encoder-32m-ONNX",dtype:"fp32"},type:"text"},summarization:{tokenizer:$,pipeline:oi,model:dr,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:$,pipeline:ii,model:dr,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:$,pipeline:Pt,model:dr,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:$,pipeline:ai,model:Bl,default:{model:"onnx-community/Qwen3-0.6B-ONNX",dtype:"q4"},type:"text"},"zero-shot-classification":{tokenizer:$,pipeline:li,model:Qo,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:ci,model:Ql,processor:ze,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:$,pipeline:ui,model:zt,processor:ze,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:$,pipeline:pi,model:[Dl,Xl],processor:ze,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:$,pipeline:di,model:[Ul,jl],processor:[ze,null],default:{model:"onnx-community/Supertonic-TTS-ONNX",dtype:"fp32"},type:"text"},"image-to-text":{tokenizer:$,pipeline:_i,model:Wl,processor:ze,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:fi,model:Vl,processor:ze,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:Es,model:[Yo,Jo,Zo],processor:ze,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:mi,model:[Yo,Jo,Zo],processor:ze,default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{tokenizer:$,pipeline:hi,model:zt,processor:ze,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:xi,model:Hl,processor:ze,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:$,pipeline:gi,model:Kl,processor:ze,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:$,pipeline:wi,model:Yl,processor:ze,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:yi,model:Jl,processor:ze,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:bi,model:Zl,processor:ze,default:{model:"onnx-community/depth-anything-v2-small"},type:"image"},"feature-extraction":{tokenizer:$,pipeline:ki,model:zt,default:{model:"onnx-community/all-MiniLM-L6-v2-ONNX",dtype:"fp32"},type:"text"},"image-feature-extraction":{processor:ze,pipeline:vi,model:[ec,zt],default:{model:"onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX",dtype:"fp32"},type:"image"}}),tc=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function sc(t,{config:e=null,dtype:s=null,device:r=null,model_file_name:n=null}={}){e=await It.from_pretrained(t,{config:e});let o=["config.json"],i=e["transformers.js_config"]??{},a=i.use_external_data_format,l="onnx",c=r??i.device,u=s??i.dtype,p,d=e.architectures||[],_=!1;for(let x of d){let g=gt.get(x);if(g!==void 0){p=g,_=!0;break}}if(!_&&e.model_type){let x=gt.get(e.model_type);x!==void 0&&(p=x,_=!0)}if(!_){let x=d.length>0?d.join(", "):"(none)";L.warn(`[get_model_files] Architecture(s) not found in MODEL_TYPE_MAPPING: [${x}] for model type '${e.model_type}'. Falling back to EncoderOnly (single model.onnx file). If you encounter issues, please report at: ${Rt}`),p=I.EncoderOnly}let f=(x,g=null)=>{g=g??x;let w=Ui(c,x),y=Bi(u,x,w),b=vr[y]??"",A=`${g}${b}.onnx`,k=l?`${l}/${A}`:A;o.push(k);let O=Wp(a,A,x);for(let N of Vp(A,O)){let D=l?`${l}/${N}`:N;o.push(D)}},h=n??"model";return p===I.DecoderOnly?(f("model",h),o.push("generation_config.json")):p===I.DecoderOnlyWithoutHead?f("model",h):p===I.Seq2Seq||p===I.Vision2Seq?(f("model","encoder_model"),f("decoder_model_merged"),o.push("generation_config.json")):p===I.MaskGeneration?(f("model","vision_encoder"),f("prompt_encoder_mask_decoder")):p===I.EncoderDecoder?(f("model","encoder_model"),f("decoder_model_merged")):p===I.ImageTextToText?(f("embed_tokens"),f("vision_encoder"),f("decoder_model_merged"),e.is_encoder_decoder&&f("model","encoder_model"),o.push("generation_config.json")):p===I.AudioTextToText?(f("embed_tokens"),f("audio_encoder"),f("decoder_model_merged"),o.push("generation_config.json")):p===I.ImageAudioTextToText?(f("embed_tokens"),f("audio_encoder"),f("vision_encoder"),f("decoder_model_merged"),o.push("generation_config.json")):p===I.Musicgen?(f("model","text_encoder"),f("decoder_model_merged"),f("encodec_decode"),o.push("generation_config.json")):p===I.MultiModality?(f("prepare_inputs_embeds"),f("model","language_model"),f("lm_head"),f("gen_head"),f("gen_img_embeds"),f("image_decode"),o.push("generation_config.json")):p===I.Phi3V?(f("prepare_inputs_embeds"),f("model"),f("vision_encoder"),o.push("generation_config.json")):p===I.Chatterbox?(f("embed_tokens"),f("speech_encoder"),f("model","language_model"),f("conditional_decoder"),o.push("generation_config.json")):p===I.AutoEncoder?(f("encoder_model"),f("decoder_model")):p===I.Supertonic?(f("text_encoder"),f("latent_denoiser"),f("voice_decoder")):f("model",h),o}async function rc(t){if(!t)throw new Error("modelId is required");return(await ft(t,Ot,{})).exists?[Ot]:[]}async function ts(t,{config:e=null,dtype:s=null,device:r=null,model_file_name:n=null,include_tokenizer:o=!0,include_processor:i=!0}={}){let a=await sc(t,{config:e,dtype:s,device:r,model_file_name:n});if(o){let l=await Ns(t);a.push(...l)}if(i){let l=await rc(t);a.push(...l)}return a}function _E(t){let e=_r[t];return e?{tokenizer:!!e.tokenizer,processor:!!e.processor}:null}async function ss(t,e,s={}){t=tc[t]??t;let r=_E(t);if(!r)throw new Error(`Unsupported pipeline task: ${t}. Must be one of [${Object.keys(_r).join(", ")}]`);return ts(e,{...s,include_tokenizer:r.tokenizer,include_processor:r.processor})}async function b7(t,e=null,{progress_callback:s=null,config:r=null,cache_dir:n=null,local_files_only:o=!1,revision:i="main",device:a=null,dtype:l=null,subfolder:c="onnx",use_external_data_format:u=null,model_file_name:p=null,session_options:d={}}={}){t=tc[t]??t;let _=_r[t.split("_",1)[0]];if(!_)throw Error(`Unsupported pipeline: ${t}. Must be one of [${Object.keys(_r)}]`);e||(e=_.default.model,L.info(`No model specified. Using default model: "${e}".`),!l&&_.default.dtype&&(l=_.default.dtype));let f={};if(s){let y=await ss(t,e,{device:a,dtype:l});(await Promise.all(y.map(async A=>ft(e,A)))).forEach((A,k)=>{A.exists&&(f[y[k]]={loaded:0,total:A.size??0})})}let h={progress_callback:s?y=>{if(y.status==="progress"){f[y.file]={loaded:y.loaded,total:y.total};let b=Object.values(f).reduce((O,N)=>O+N.loaded,0),A=Object.values(f).reduce((O,N)=>O+N.total,0),k=A>0?b/A*100:0;s({status:"progress_total",name:y.name,progress:k,loaded:b,total:A,files:structuredClone(f)})}s(y)}:void 0,config:r,cache_dir:n,local_files_only:o,revision:i,device:a,dtype:l,subfolder:c,use_external_data_format:u,model_file_name:p,session_options:d},x=new Map([["tokenizer",_.tokenizer],["model",_.model],["processor",_.processor]]),g=await fE(x,e,h);g.task=t,At(s,{status:"ready",task:t,model:e});let w=_.pipeline;return new w(g)}async function fE(t,e,s){let r=Object.create(null),n=[];for(let[o,i]of t.entries()){if(!i)continue;let a;Array.isArray(i)?a=new Promise(async(l,c)=>{let u;for(let p of i){if(p===null){l(null);return}try{l(await p.from_pretrained(e,s));return}catch(d){if(d.message?.includes("Unsupported model type"))u=d;else if(d.message?.includes("Could not locate file"))u=d;else{c(d);return}}}c(u)}):a=i.from_pretrained(e,s),r[o]=a,n.push(a)}await Promise.all(n);for(let[o,i]of Object.entries(r))r[o]=await i;return r}var mE=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,Xg=class{put(e){throw Error("Not implemented")}end(){throw Error("Not implemented")}},C0=Z.IS_PROCESS_AVAILABLE?t=>process.stdout.write(t):t=>console.log(t),Qg=class extends Xg{constructor(e,{skip_prompt:s=!1,callback_function:r=null,token_callback_function:n=null,skip_special_tokens:o=!0,decode_kwargs:i={},...a}={}){super(),this.tokenizer=e,this.skip_prompt=s,this.callback_function=r??C0,this.token_callback_function=n,this.decode_kwargs={skip_special_tokens:o,...i,...a},this.token_cache=[],this.print_len=0,this.next_tokens_are_prompt=!0,this.special_ids=new Set(this.tokenizer.all_special_ids.map(BigInt))}put(e){if(e.length>1)throw Error("TextStreamer only supports batch size of 1");let s=this.next_tokens_are_prompt;if(s&&(this.next_tokens_are_prompt=!1,this.skip_prompt))return;let r=e[0];if(this.token_callback_function?.(r),r.length===1&&this.special_ids.has(r[0])){if(this.decode_kwargs.skip_special_tokens)return;if(this.token_cache.length>0){let l=this.tokenizer.decode(this.token_cache,this.decode_kwargs).slice(this.print_len);this.on_finalized_text(l,!1),this.token_cache=[],this.print_len=0}let i=this.tokenizer.decode(r,this.decode_kwargs);this.on_finalized_text(i,!1);return}this.token_cache=Pe(this.token_cache,r);let n=this.tokenizer.decode(this.token_cache,this.decode_kwargs),o;s||n.endsWith(`
23
+ `)?(o=n.slice(this.print_len),this.token_cache=[],this.print_len=0):n.length>0&&mE(n.charCodeAt(n.length-1))?(o=n.slice(this.print_len),this.print_len+=o.length):(o=n.slice(this.print_len,n.lastIndexOf(" ")+1),this.print_len+=o.length),this.on_finalized_text(o,!1)}end(){let e;this.token_cache.length>0?(e=this.tokenizer.decode(this.token_cache,this.decode_kwargs).slice(this.print_len),this.token_cache=[],this.print_len=0):e="",this.next_tokens_are_prompt=!0,this.on_finalized_text(e,!0)}on_finalized_text(e,s){e.length>0&&this.callback_function?.(e),s&&this.callback_function===C0&&Z.IS_PROCESS_AVAILABLE&&this.callback_function?.(`
24
+ `)}},N0=class extends Qg{constructor(e,{skip_prompt:s=!1,callback_function:r=null,token_callback_function:n=null,on_chunk_start:o=null,on_chunk_end:i=null,on_finalize:a=null,time_precision:l=.02,skip_special_tokens:c=!0,decode_kwargs:u={}}={}){super(e,{skip_prompt:s,skip_special_tokens:c,callback_function:r,token_callback_function:n,decode_kwargs:u}),this.timestamp_begin=e.timestamp_begin,this.on_chunk_start=o,this.on_chunk_end=i,this.on_finalize=a,this.time_precision=l,this.waiting_for_timestamp=!1}put(e){if(e.length>1)throw Error("WhisperTextStreamer only supports batch size of 1");let s=e[0];if(s.length===1){let r=Number(s[0])-this.timestamp_begin;if(r>=0){let n=r*this.time_precision;this.waiting_for_timestamp?this.on_chunk_end?.(n):this.on_chunk_start?.(n),this.waiting_for_timestamp=!this.waiting_for_timestamp,this.token_callback_function?.(s);return}}return super.put(e)}end(){super.end(),this.on_finalize?.()}};var Ei=class{constructor(e,s){this.image=e,this.timestamp=s}},nc=class{constructor(e,s){e.length>0&&e[0]instanceof ye&&(e=e.map((r,n)=>new Ei(r,(n+1)/(e.length+1)*s))),this.frames=e,this.duration=s}get width(){return this.frames[0].image.width}get height(){return this.frames[0].image.height}get fps(){return this.frames.length/this.duration}};async function hE(t,{num_frames:e=null,fps:s=null}={}){if(!Z.IS_BROWSER_ENV)throw new Error("`load_video` is currently only supported in browser environments.");if(e==null&&s==null)throw new Error("Either num_frames or fps must be provided.");let r=[],n=document.createElement("video");if(n.crossOrigin="anonymous",n.muted=!0,typeof t=="string")n.src=t;else if(t instanceof Blob)n.src=URL.createObjectURL(t);else if(t instanceof HTMLVideoElement)n.src=t.src;else throw new Error("Invalid URL or video element provided.");if(await new Promise(p=>n.onloadedmetadata=p),n.seekable.start(0)===n.seekable.end(0)){let d=await(await H.fetch(n.src)).blob();n.src=URL.createObjectURL(d),await new Promise(_=>n.onloadedmetadata=_)}let o=n.duration,i,a;e!=null?(i=e,a=e===1?0:o/(e-1)):(a=1/s,i=Math.floor(o/a));let l=[];for(let p=0;p<i;++p)l.push(e===1?o/2:p*a);let c=document.createElement("canvas");c.width=n.videoWidth,c.height=n.videoHeight;let u=c.getContext("2d",{willReadFrequently:!0});for(let p of l){n.currentTime=p,await new Promise(h=>{n.onseeked=h}),u.drawImage(n,0,0,c.width,c.height);let d=u.getImageData(0,0,c.width,c.height),_=new ye(d.data,c.width,c.height,4),f=new Ei(_,p);r.push(f)}return n.remove(),new nc(r,o)}async function L0(t,e,s={}){let r=await _t(s?.cache_dir);if(!r)return{allCached:!1,files:e.map(i=>({file:i,cached:!1}))};let n=await Promise.all(e.map(async o=>{let{localPath:i,proposedCacheKey:a}=ls(t,o,s,r),l=await cs(r,i,a);return{file:o,cached:!!l}}));return{allCached:n.every(o=>o.cached),files:n}}async function $0(t,e={}){if(!t)throw new Error("modelId is required");let s=await ts(t,e);return await L0(t,s,e)}async function R0(t,e,s={}){if(!t)throw new Error("task is required");if(!e)throw new Error("modelId is required");let r=await ss(t,e,s);return await L0(e,r,s)}async function F0(t,e,s={}){let r=await _t(s?.cache_dir);if(!r)return{filesDeleted:0,filesCached:0,files:e.map(o=>({file:o,deleted:!1,wasCached:!1}))};if(!r.delete)throw new Error("Cache does not support delete operation");let n=await Promise.all(e.map(async o=>{let{localPath:i,proposedCacheKey:a}=ls(t,o,s,r),c=!!await cs(r,i,a),u=!1;if(c){let p=await r.delete(a),d=!p&&a!==i?await r.delete(i):!1;u=p||d}return{file:o,deleted:u,wasCached:c}}));return{filesDeleted:n.filter(o=>o.deleted).length,filesCached:n.filter(o=>o.wasCached).length,files:n}}async function D0(t,e={}){if(!t)throw new Error("modelId is required");let s=await ts(t,e);return await F0(t,s,e)}async function j0(t,e,s={}){if(!t)throw new Error("task is required");if(!e)throw new Error("modelId is required");let r=await ss(t,e,s);return await F0(e,r,s)}var Yg=class{static async get_files(e,s={}){return ts(e,s)}static async get_pipeline_files(e,s,r={}){return ss(e,s,r)}static async get_model_files(e,s={}){return sc(e,s)}static async get_tokenizer_files(e){return Ns(e)}static async get_processor_files(e){return rc(e)}static async is_cached(e,s={}){return $0(e,s)}static async is_pipeline_cached(e,s,r={}){return R0(e,s,r)}static async get_file_metadata(e,s,r={}){return ft(e,s,r)}static async clear_cache(e,s={}){return D0(e,s)}static async clear_pipeline_cache(e,s,r={}){return j0(e,s,r)}};export{ku as ASTFeatureExtractor,ud as ASTForAudioClassification,cd as ASTModel,Wr as ASTPreTrainedModel,id as AfmoeForCausalLM,od as AfmoeModel,qr as AfmoePreTrainedModel,sd as AlbertForMaskedLM,td as AlbertForQuestionAnswering,ed as AlbertForSequenceClassification,Zp as AlbertModel,xs as AlbertPreTrainedModel,Ic as AlbertTokenizer,nd as ApertusForCausalLM,rd as ApertusModel,Br as ApertusPreTrainedModel,ld as ArceeForCausalLM,ad as ArceeModel,Gr as ArceePreTrainedModel,ci as AudioClassificationPipeline,It as AutoConfig,Ee as AutoFeatureExtractor,fe as AutoImageProcessor,zt as AutoModel,Ql as AutoModelForAudioClassification,A0 as AutoModelForAudioFrameClassification,T0 as AutoModelForAudioTextToText,Xl as AutoModelForCTC,Bl as AutoModelForCausalLM,Zl as AutoModelForDepthEstimation,Yl as AutoModelForDocumentQuestionAnswering,Vl as AutoModelForImageClassification,ec as AutoModelForImageFeatureExtraction,M0 as AutoModelForImageMatting,Yo as AutoModelForImageSegmentation,I0 as AutoModelForImageTextToText,Jl as AutoModelForImageToImage,v0 as AutoModelForMaskGeneration,ql as AutoModelForMaskedLM,S0 as AutoModelForNormalEstimation,Hl as AutoModelForObjectDetection,O0 as AutoModelForPoseEstimation,Gl as AutoModelForQuestionAnswering,Jo as AutoModelForSemanticSegmentation,dr as AutoModelForSeq2SeqLM,Qo as AutoModelForSequenceClassification,Dl as AutoModelForSpeechSeq2Seq,jl as AutoModelForTextToSpectrogram,Ul as AutoModelForTextToWaveform,Fl as AutoModelForTokenClassification,Zo as AutoModelForUniversalSegmentation,Wl as AutoModelForVision2Seq,E0 as AutoModelForXVector,Kl as AutoModelForZeroShotObjectDetection,ze as AutoProcessor,$ as AutoTokenizer,pi as AutomaticSpeechRecognitionPipeline,mi as BackgroundRemovalPipeline,dd as BartForConditionalGeneration,_d as BartForSequenceClassification,pd as BartModel,Vs as BartPretrainedModel,Tc as BartTokenizer,Xg as BaseStreamer,Ru as BeitFeatureExtractor,md as BeitForImageClassification,fd as BeitModel,Vr as BeitPreTrainedModel,xd as BertForMaskedLM,yd as BertForQuestionAnswering,gd as BertForSequenceClassification,wd as BertForTokenClassification,hd as BertModel,jt as BertPreTrainedModel,zc as BertTokenizer,Fu as BitImageProcessor,kd as BlenderbotForConditionalGeneration,bd as BlenderbotModel,Hr as BlenderbotPreTrainedModel,Ed as BlenderbotSmallForConditionalGeneration,vd as BlenderbotSmallModel,Kr as BlenderbotSmallPreTrainedModel,Pc as BlenderbotSmallTokenizer,Cc as BlenderbotTokenizer,Md as BloomForCausalLM,Ad as BloomModel,Xr as BloomPreTrainedModel,Nc as BloomTokenizer,ju as CLIPFeatureExtractor,ea as CLIPImageProcessor,Nd as CLIPModel,yt as CLIPPreTrainedModel,Dd as CLIPSegForImageSegmentation,Fd as CLIPSegModel,en as CLIPSegPreTrainedModel,Ld as CLIPTextModel,Zr as CLIPTextModelWithProjection,$c as CLIPTokenizer,$d as CLIPVisionModel,Rd as CLIPVisionModelWithProjection,Od as CamembertForMaskedLM,zd as CamembertForQuestionAnswering,Id as CamembertForSequenceClassification,Td as CamembertForTokenClassification,Sd as CamembertModel,Ut as CamembertPreTrainedModel,Lc as CamembertTokenizer,vu as ChatterboxFeatureExtractor,Qr as ChatterboxModel,Da as ChatterboxPreTrainedModel,Nu as ChatterboxProcessor,Du as ChineseCLIPFeatureExtractor,Pd as ChineseCLIPModel,ja as ChineseCLIPPreTrainedModel,Jr as ClapAudioModelWithProjection,Eu as ClapFeatureExtractor,Cd as ClapModel,Hs as ClapPreTrainedModel,Yr as ClapTextModelWithProjection,Ta as ClassifierFreeGuidanceLogitsProcessor,Ud as CodeGenForCausalLM,jd as CodeGenModel,tn as CodeGenPreTrainedModel,Fc as CodeGenTokenizer,Rc as CodeLlamaTokenizer,Wd as Cohere2ForCausalLM,Gd as Cohere2Model,rn as Cohere2PreTrainedModel,qd as CohereForCausalLM,Bd as CohereModel,sn as CoherePreTrainedModel,Dc as CohereTokenizer,Hd as ConvBertForMaskedLM,Qd as ConvBertForQuestionAnswering,Kd as ConvBertForSequenceClassification,Xd as ConvBertForTokenClassification,Vd as ConvBertModel,Bt as ConvBertPreTrainedModel,jc as ConvBertTokenizer,Uu as ConvNextFeatureExtractor,Jd as ConvNextForImageClassification,ta as ConvNextImageProcessor,Yd as ConvNextModel,nn as ConvNextPreTrainedModel,e_ as ConvNextV2ForImageClassification,Zd as ConvNextV2Model,on as ConvNextV2PreTrainedModel,n_ as DFineForObjectDetection,r_ as DFineModel,ln as DFinePreTrainedModel,O_ as DINOv3ConvNextModel,Ha as DINOv3ConvNextPreTrainedModel,Gu as DINOv3ViTImageProcessor,I_ as DINOv3ViTModel,Ka as DINOv3ViTPreTrainedModel,Vu as DPTFeatureExtractor,R_ as DPTForDepthEstimation,na as DPTImageProcessor,$_ as DPTModel,fn as DPTPreTrainedModel,un as DacDecoderModel,Ba as DacDecoderOutput,cn as DacEncoderModel,Ua as DacEncoderOutput,zr as DacFeatureExtractor,o_ as DacModel,Ks as DacPreTrainedModel,a_ as DebertaForMaskedLM,u_ as DebertaForQuestionAnswering,l_ as DebertaForSequenceClassification,c_ as DebertaForTokenClassification,i_ as DebertaModel,qt as DebertaPreTrainedModel,Bc as DebertaTokenizer,d_ as DebertaV2ForMaskedLM,m_ as DebertaV2ForQuestionAnswering,__ as DebertaV2ForSequenceClassification,f_ as DebertaV2ForTokenClassification,p_ as DebertaV2Model,Gt as DebertaV2PreTrainedModel,Uc as DebertaV2Tokenizer,h_ as DecisionTransformerModel,qa as DecisionTransformerPreTrainedModel,Bu as DeiTFeatureExtractor,g_ as DeiTForImageClassification,sa as DeiTImageProcessor,x_ as DeiTModel,pn as DeiTPreTrainedModel,w_ as DepthAnythingForDepthEstimation,Ga as DepthAnythingPreTrainedModel,bi as DepthEstimationPipeline,y_ as DepthProForDepthEstimation,Wa as DepthProPreTrainedModel,qu as DetrFeatureExtractor,k_ as DetrForObjectDetection,v_ as DetrForSegmentation,ra as DetrImageProcessor,b_ as DetrModel,Qs as DetrObjectDetectionOutput,Xs as DetrPreTrainedModel,Va as DetrSegmentationOutput,A_ as Dinov2ForImageClassification,E_ as Dinov2Model,dn as Dinov2PreTrainedModel,S_ as Dinov2WithRegistersForImageClassification,M_ as Dinov2WithRegistersModel,_n as Dinov2WithRegistersPreTrainedModel,N_ as DistilBertForMaskedLM,C_ as DistilBertForQuestionAnswering,z_ as DistilBertForSequenceClassification,P_ as DistilBertForTokenClassification,T_ as DistilBertModel,Wt as DistilBertPreTrainedModel,qc as DistilBertTokenizer,wi as DocumentQuestionAnsweringPipeline,Wu as DonutFeatureExtractor,$s as DonutImageProcessor,L_ as DonutSwinModel,Xa as DonutSwinPreTrainedModel,bx as EdgeTamModel,D_ as EfficientNetForImageClassification,Hu as EfficientNetImageProcessor,F_ as EfficientNetModel,mn as EfficientNetPreTrainedModel,U_ as ElectraForMaskedLM,G_ as ElectraForQuestionAnswering,B_ as ElectraForSequenceClassification,q_ as ElectraForTokenClassification,j_ as ElectraModel,Vt as ElectraPreTrainedModel,Gc as ElectraTokenizer,Tr as EncodecFeatureExtractor,Na as EosTokenCriteria,V_ as Ernie4_5ForCausalLM,W_ as Ernie4_5Model,hn as Ernie4_5PretrainedModel,K_ as EsmForMaskedLM,X_ as EsmForSequenceClassification,Q_ as EsmForTokenClassification,H_ as EsmModel,gs as EsmPreTrainedModel,Wc as EsmTokenizer,J_ as ExaoneForCausalLM,Y_ as ExaoneModel,xn as ExaonePreTrainedModel,ef as FalconForCausalLM,sf as FalconH1ForCausalLM,tf as FalconH1Model,wn as FalconH1PreTrainedModel,Z_ as FalconModel,gn as FalconPreTrainedModel,Vc as FalconTokenizer,nf as FastViTForImageClassification,rf as FastViTModel,yn as FastViTPreTrainedModel,ki as FeatureExtractionPipeline,_e as FeatureExtractor,ni as FillMaskPipeline,of as Florence2ForConditionalGeneration,Qa as Florence2PreTrainedModel,Ep as Florence2Processor,ka as ForcedBOSTokenLogitsProcessor,va as ForcedEOSTokenLogitsProcessor,Ku as GLPNFeatureExtractor,hf as GLPNForDepthEstimation,mf as GLPNModel,Mn as GLPNPreTrainedModel,Mf as GPT2LMHeadModel,Af as GPT2Model,zn as GPT2PreTrainedModel,Xc as GPT2Tokenizer,gf as GPTBigCodeForCausalLM,xf as GPTBigCodeModel,Sn as GPTBigCodePreTrainedModel,Of as GPTJForCausalLM,Sf as GPTJModel,Pn as GPTJPreTrainedModel,yf as GPTNeoForCausalLM,wf as GPTNeoModel,On as GPTNeoPreTrainedModel,kf as GPTNeoXForCausalLM,bf as GPTNeoXModel,In as GPTNeoXPreTrainedModel,Kc as GPTNeoXTokenizer,uf as Gemma2ForCausalLM,cf as Gemma2Model,kn as Gemma2PreTrainedModel,df as Gemma3ForCausalLM,pf as Gemma3Model,vn as Gemma3PreTrainedModel,Au as Gemma3nAudioFeatureExtractor,En as Gemma3nForConditionalGeneration,Ya as Gemma3nPreTrainedModel,Ap as Gemma3nProcessor,lf as GemmaForCausalLM,af as GemmaModel,bn as GemmaPreTrainedModel,Hc as GemmaTokenizer,ff as GlmForCausalLM,_f as GlmModel,An as GlmPreTrainedModel,Ef as GptOssForCausalLM,vf as GptOssModel,Tn as GptOssPreTrainedModel,Tf as GraniteForCausalLM,If as GraniteModel,Pf as GraniteMoeHybridForCausalLM,zf as GraniteMoeHybridModel,Nn as GraniteMoeHybridPreTrainedModel,Cn as GranitePreTrainedModel,Cf as GroundingDinoForObjectDetection,Xu as GroundingDinoImageProcessor,Ja as GroundingDinoPreTrainedModel,Mp as GroundingDinoProcessor,Nf as GroupViTModel,Za as GroupViTPreTrainedModel,$f as HeliumForCausalLM,Lf as HeliumModel,Ln as HeliumPreTrainedModel,Qc as HerbertTokenizer,Ff as HieraForImageClassification,Rf as HieraModel,$n as HieraPreTrainedModel,Wf as HubertForCTC,Vf as HubertForSequenceClassification,Gf as HubertModel,qf as HubertPreTrainedModel,Kf as HunYuanDenseV1ForCausalLM,Hf as HunYuanDenseV1Model,Rn as HunYuanDenseV1PreTrainedModel,Yf as IJepaForImageClassification,Qf as IJepaModel,Fn as IJepaPreTrainedModel,tl as Idefics3ForConditionalGeneration,oa as Idefics3ImageProcessor,el as Idefics3PreTrainedModel,ma as Idefics3Processor,fi as ImageClassificationPipeline,vi as ImageFeatureExtractionPipeline,C as ImageFeatureExtractor,C as ImageProcessor,Es as ImageSegmentationPipeline,yi as ImageToImagePipeline,_i as ImageToTextPipeline,qy as InterruptableStoppingCriteria,Zf as JAISLMHeadModel,Jf as JAISModel,Dn as JAISPreTrainedModel,Yu as JinaCLIPImageProcessor,em as JinaCLIPModel,Ys as JinaCLIPPreTrainedModel,Op as JinaCLIPProcessor,jn as JinaCLIPTextModel,tm as JinaCLIPVisionModel,rm as Lfm2ForCausalLM,sm as Lfm2Model,om as Lfm2MoeForCausalLM,nm as Lfm2MoeModel,Bn as Lfm2MoePreTrainedModel,Un as Lfm2PreTrainedModel,Pg as LiteWhisperForConditionalGeneration,lm as Llama4ForCausalLM,sl as Llama4PreTrainedModel,am as LlamaForCausalLM,im as LlamaModel,qn as LlamaPreTrainedModel,Yc as LlamaTokenizer,Js as LlavaForConditionalGeneration,Js as LlavaOnevisionForConditionalGeneration,Ju as LlavaOnevisionImageProcessor,rl as LlavaPreTrainedModel,Ip as LlavaProcessor,um as LlavaQwen2ForCausalLM,Ue as LogLevel,Ze as LogitsProcessor,fs as LogitsProcessorList,Fr as LogitsWarper,dm as LongT5ForConditionalGeneration,pm as LongT5Model,Gn as LongT5PreTrainedModel,fm as M2M100ForConditionalGeneration,_m as M2M100Model,Wn as M2M100PreTrainedModel,Jc as M2M100Tokenizer,eu as MBart50Tokenizer,km as MBartForCausalLM,ym as MBartForConditionalGeneration,bm as MBartForSequenceClassification,wm as MBartModel,ws as MBartPreTrainedModel,Mr as MBartTokenizer,ih as MPNetForMaskedLM,ch as MPNetForQuestionAnswering,ah as MPNetForSequenceClassification,lh as MPNetForTokenClassification,oh as MPNetModel,Ht as MPNetPreTrainedModel,ru as MPNetTokenizer,_h as MT5ForConditionalGeneration,dh as MT5Model,ro as MT5PreTrainedModel,hm as MarianMTModel,mm as MarianModel,Vn as MarianPreTrainedModel,Zc as MarianTokenizer,ep as Mask2FormerImageProcessor,Zu as MaskFormerFeatureExtractor,gm as MaskFormerForInstanceSegmentation,Rs as MaskFormerImageProcessor,xm as MaskFormerModel,Hn as MaskFormerPreTrainedModel,Ca as MaxLengthCriteria,vm as Metric3DForDepthEstimation,nl as Metric3DPreTrainedModel,Em as Metric3Dv2ForDepthEstimation,ol as Metric3Dv2PreTrainedModel,Am as MgpstrForSceneTextRecognition,il as MgpstrModelOutput,al as MgpstrPreTrainedModel,Tp as MgpstrProcessor,tu as MgpstrTokenizer,Xn as MimiDecoderModel,cl as MimiDecoderOutput,Kn as MimiEncoderModel,ll as MimiEncoderOutput,Mm as MimiModel,Zs as MimiPreTrainedModel,Sa as MinLengthLogitsProcessor,Oa as MinNewTokensLengthLogitsProcessor,Om as MistralForCausalLM,Sm as MistralModel,Qn as MistralPreTrainedModel,Tm as MobileBertForMaskedLM,Pm as MobileBertForQuestionAnswering,zm as MobileBertForSequenceClassification,Im as MobileBertModel,ys as MobileBertPreTrainedModel,su as MobileBertTokenizer,Nm as MobileLLMForCausalLM,Cm as MobileLLMModel,Yn as MobileLLMPreTrainedModel,tp as MobileNetV1FeatureExtractor,$m as MobileNetV1ForImageClassification,Rm as MobileNetV1ForSemanticSegmentation,ia as MobileNetV1ImageProcessor,Lm as MobileNetV1Model,er as MobileNetV1PreTrainedModel,sp as MobileNetV2FeatureExtractor,Dm as MobileNetV2ForImageClassification,jm as MobileNetV2ForSemanticSegmentation,aa as MobileNetV2ImageProcessor,Fm as MobileNetV2Model,tr as MobileNetV2PreTrainedModel,rp as MobileNetV3FeatureExtractor,Bm as MobileNetV3ForImageClassification,qm as MobileNetV3ForSemanticSegmentation,la as MobileNetV3ImageProcessor,Um as MobileNetV3Model,sr as MobileNetV3PreTrainedModel,np as MobileNetV4FeatureExtractor,Wm as MobileNetV4ForImageClassification,Vm as MobileNetV4ForSemanticSegmentation,ca as MobileNetV4ImageProcessor,Gm as MobileNetV4Model,rr as MobileNetV4PreTrainedModel,op as MobileViTFeatureExtractor,Km as MobileViTForImageClassification,ua as MobileViTImageProcessor,Hm as MobileViTModel,Jn as MobileViTPreTrainedModel,Qm as MobileViTV2ForImageClassification,Xm as MobileViTV2Model,Zn as MobileViTV2PreTrainedModel,Yg as ModelRegistry,sh as ModernBertDecoderForCausalLM,th as ModernBertDecoderModel,eo as ModernBertDecoderPreTrainedModel,Jm as ModernBertForMaskedLM,Zm as ModernBertForSequenceClassification,eh as ModernBertForTokenClassification,Ym as ModernBertModel,bs as ModernBertPreTrainedModel,cm as Moondream1ForConditionalGeneration,Mu as MoonshineFeatureExtractor,nh as MoonshineForConditionalGeneration,rh as MoonshineModel,to as MoonshinePreTrainedModel,zp as MoonshineProcessor,ph as MptForCausalLM,uh as MptModel,so as MptPreTrainedModel,fh as MultiModalityCausalLM,ul as MultiModalityPreTrainedModel,hh as MusicgenForCausalLM,oo as MusicgenForConditionalGeneration,mh as MusicgenModel,no as MusicgenPreTrainedModel,gh as NanoChatForCausalLM,xh as NanoChatModel,io as NanoChatPreTrainedModel,yh as NeoBertForMaskedLM,vh as NeoBertForQuestionAnswering,bh as NeoBertForSequenceClassification,kh as NeoBertForTokenClassification,wh as NeoBertModel,Kt as NeoBertPreTrainedModel,nu as NllbTokenizer,Ia as NoBadWordsLogitsProcessor,Aa as NoRepeatNGramLogitsProcessor,Eh as NomicBertModel,pl as NomicBertPreTrainedModel,ip as NougatImageProcessor,ou as NougatTokenizer,Nh as OPTForCausalLM,Ch as OPTModel,po as OPTPreTrainedModel,xi as ObjectDetectionPipeline,Oh as Olmo2ForCausalLM,Sh as Olmo2Model,lo as Olmo2PreTrainedModel,Th as Olmo3ForCausalLM,Ih as Olmo3Model,co as Olmo3PreTrainedModel,Mh as OlmoForCausalLM,Ah as OlmoModel,ao as OlmoPreTrainedModel,Ph as OpenELMForCausalLM,zh as OpenELMModel,uo as OpenELMPreTrainedModel,ap as OwlViTFeatureExtractor,Fh as OwlViTForObjectDetection,Fs as OwlViTImageProcessor,Rh as OwlViTModel,fo as OwlViTPreTrainedModel,Pp as OwlViTProcessor,$h as Owlv2ForObjectDetection,lp as Owlv2ImageProcessor,Lh as Owlv2Model,_o as Owlv2PreTrainedModel,Dh as PaliGemmaForConditionalGeneration,dl as PaliGemmaPreTrainedModel,Cp as PaliGemmaProcessor,Su as ParakeetFeatureExtractor,jh as ParakeetForCTC,_l as ParakeetPreTrainedModel,Bh as PatchTSMixerForPrediction,Uh as PatchTSMixerModel,mo as PatchTSMixerPreTrainedModel,Gh as PatchTSTForPrediction,qh as PatchTSTModel,ho as PatchTSTPreTrainedModel,Kh as Phi3ForCausalLM,Hh as Phi3Model,go as Phi3PreTrainedModel,wo as Phi3VForCausalLM,pp as Phi3VImageProcessor,fl as Phi3VPreTrainedModel,Np as Phi3VProcessor,Vh as PhiForCausalLM,Wh as PhiModel,xo as PhiPreTrainedModel,dp as PixtralImageProcessor,Lp as PixtralProcessor,m as PreTrainedModel,P as PreTrainedTokenizer,wa as PretrainedConfig,U as Processor,Qh as PvtForImageClassification,_p as PvtImageProcessor,Xh as PvtModel,yo as PvtPreTrainedModel,Pr as PyAnnoteFeatureExtractor,Jh as PyAnnoteForAudioFrameClassification,Yh as PyAnnoteModel,bo as PyAnnotePreTrainedModel,$p as PyAnnoteProcessor,ri as QuestionAnsweringPipeline,ex as Qwen2ForCausalLM,Zh as Qwen2Model,ko as Qwen2PreTrainedModel,iu as Qwen2Tokenizer,vo as Qwen2VLForConditionalGeneration,fp as Qwen2VLImageProcessor,ml as Qwen2VLPreTrainedModel,Lr as Qwen2VLProcessor,Eo as Qwen2_5_VLForConditionalGeneration,$r as Qwen2_5_VLProcessor,sx as Qwen3ForCausalLM,tx as Qwen3Model,Ao as Qwen3PreTrainedModel,Mo as Qwen3VLForConditionalGeneration,Rp as Qwen3VLProcessor,So as Qwen3_5ForConditionalGeneration,rx as Qwen3_5MoeForConditionalGeneration,ax as RFDetrForObjectDetection,ix as RFDetrModel,hl as RFDetrObjectDetectionOutput,Io as RFDetrPreTrainedModel,s_ as RTDetrForObjectDetection,mp as RTDetrImageProcessor,t_ as RTDetrModel,bt as RTDetrObjectDetectionOutput,an as RTDetrPreTrainedModel,wx as RTDetrV2ForObjectDetection,gx as RTDetrV2Model,xl as RTDetrV2ObjectDetectionOutput,To as RTDetrV2PreTrainedModel,Ir as RawAudio,ye as RawImage,nc as RawVideo,Ei as RawVideoFrame,Ma as RepetitionPenaltyLogitsProcessor,ox as ResNetForImageClassification,nx as ResNetModel,Oo as ResNetPreTrainedModel,fx as RoFormerForMaskedLM,xx as RoFormerForQuestionAnswering,mx as RoFormerForSequenceClassification,hx as RoFormerForTokenClassification,_x as RoFormerModel,Qt as RoFormerPreTrainedModel,lu as RoFormerTokenizer,cx as RobertaForMaskedLM,dx as RobertaForQuestionAnswering,ux as RobertaForSequenceClassification,px as RobertaForTokenClassification,lx as RobertaModel,Xt as RobertaPreTrainedModel,au as RobertaTokenizer,Nr as Sam2ImageProcessor,yl as Sam2ImageSegmentationOutput,zo as Sam2Model,bl as Sam2PreTrainedModel,ha as Sam2Processor,Fp as Sam2VideoProcessor,Nr as Sam3ImageProcessor,kx as Sam3TrackerModel,Nr as SamImageProcessor,gl as SamImageSegmentationOutput,yx as SamModel,wl as SamPreTrainedModel,Rr as SamProcessor,hp as SapiensFeatureExtractor,Ex as SapiensForDepthEstimation,Ax as SapiensForNormalEstimation,vx as SapiensForSemanticSegmentation,pa as SapiensImageProcessor,nr as SapiensPreTrainedModel,Ou as SeamlessM4TFeatureExtractor,xp as SegformerFeatureExtractor,Sx as SegformerForImageClassification,Ox as SegformerForSemanticSegmentation,da as SegformerImageProcessor,Mx as SegformerModel,or as SegformerPreTrainedModel,gp as SiglipImageProcessor,Ix as SiglipModel,Po as SiglipPreTrainedModel,Co as SiglipTextModel,cu as SiglipTokenizer,Tx as SiglipVisionModel,Px as SmolLM3ForCausalLM,zx as SmolLM3Model,No as SmolLM3PreTrainedModel,Xf as SmolVLMForConditionalGeneration,oa as SmolVLMImageProcessor,ma as SmolVLMProcessor,$o as SnacDecoderModel,Lo as SnacEncoderModel,Iu as SnacFeatureExtractor,Cx as SnacModel,ir as SnacPreTrainedModel,Tu as SpeechT5FeatureExtractor,Lx as SpeechT5ForSpeechToText,$x as SpeechT5ForTextToSpeech,Rx as SpeechT5HifiGan,Nx as SpeechT5Model,ar as SpeechT5PreTrainedModel,Dp as SpeechT5Processor,uu as SpeechT5Tokenizer,Dx as SqueezeBertForMaskedLM,Ux as SqueezeBertForQuestionAnswering,jx as SqueezeBertForSequenceClassification,Fx as SqueezeBertModel,ks as SqueezeBertPreTrainedModel,pu as SqueezeBertTokenizer,qx as StableLmForCausalLM,Bx as StableLmModel,Ro as StableLmPreTrainedModel,Wx as Starcoder2ForCausalLM,Gx as Starcoder2Model,Fo as Starcoder2PreTrainedModel,Ws as StoppingCriteria,Pa as StoppingCriteriaList,Vx as StyleTextToSpeech2Model,kl as StyleTextToSpeech2PreTrainedModel,oi as SummarizationPipeline,Do as SupertonicForConditionalGeneration,vl as SupertonicPreTrainedModel,qs as SuppressTokensAtBeginLogitsProcessor,Yx as Swin2SRForImageSuperResolution,wp as Swin2SRImageProcessor,Qx as Swin2SRModel,jo as Swin2SRPreTrainedModel,Kx as SwinForImageClassification,Xx as SwinForSemanticSegmentation,Hx as SwinModel,lr as SwinPreTrainedModel,Zx as T5ForConditionalGeneration,Jx as T5Model,Uo as T5PreTrainedModel,du as T5Tokenizer,tg as TableTransformerForObjectDetection,eg as TableTransformerModel,El as TableTransformerObjectDetectionOutput,Bo as TableTransformerPreTrainedModel,za as TemperatureLogitsWarper,S as Tensor,Pt as Text2TextGenerationPipeline,ti as TextClassificationPipeline,ai as TextGenerationPipeline,Qg as TextStreamer,di as TextToAudioPipeline,si as TokenClassificationPipeline,P as TokenizersBackend,By as TopKLogitsWarper,Uy as TopPLogitsWarper,sg as TrOCRForCausalLM,Al as TrOCRPreTrainedModel,ii as TranslationPipeline,Sl as UltravoxModel,Ml as UltravoxPreTrainedModel,jp as UltravoxProcessor,og as UniSpeechForCTC,ig as UniSpeechForSequenceClassification,ng as UniSpeechModel,cr as UniSpeechPreTrainedModel,ug as UniSpeechSatForAudioFrameClassification,lg as UniSpeechSatForCTC,cg as UniSpeechSatForSequenceClassification,ag as UniSpeechSatModel,vs as UniSpeechSatPreTrainedModel,Sp as VLChatProcessor,Qu as VLMImageProcessor,dg as VaultGemmaForCausalLM,pg as VaultGemmaModel,qo as VaultGemmaPreTrainedModel,yp as ViTFeatureExtractor,mg as ViTForImageClassification,_a as ViTImageProcessor,hg as ViTMAEModel,Ol as ViTMAEPreTrainedModel,gg as ViTMSNForImageClassification,xg as ViTMSNModel,Wo as ViTMSNPreTrainedModel,fg as ViTModel,Go as ViTPreTrainedModel,_g as VisionEncoderDecoderModel,wg as VitMatteForImageMatting,bp as VitMatteImageProcessor,Il as VitMattePreTrainedModel,yg as VitPoseForPoseEstimation,kp as VitPoseImageProcessor,Tl as VitPosePreTrainedModel,bg as VitsModel,zl as VitsModelOutput,Pl as VitsPreTrainedModel,fu as VitsTokenizer,rg as VoxtralForConditionalGeneration,Up as VoxtralProcessor,vg as Wav2Vec2BertForCTC,Eg as Wav2Vec2BertForSequenceClassification,kg as Wav2Vec2BertModel,ur as Wav2Vec2BertPreTrainedModel,mu as Wav2Vec2CTCTokenizer,zu as Wav2Vec2FeatureExtractor,Bf as Wav2Vec2ForAudioFrameClassification,jf as Wav2Vec2ForCTC,Uf as Wav2Vec2ForSequenceClassification,Df as Wav2Vec2Model,ct as Wav2Vec2PreTrainedModel,Bp as Wav2Vec2Processor,qp as Wav2Vec2ProcessorWithLM,Ig as WavLMForAudioFrameClassification,Mg as WavLMForCTC,Sg as WavLMForSequenceClassification,Og as WavLMForXVector,Ag as WavLMModel,Yt as WavLMPreTrainedModel,Pu as WeSpeakerFeatureExtractor,Tg as WeSpeakerResNetModel,Nl as WeSpeakerResNetPreTrainedModel,Cu as WhisperFeatureExtractor,$l as WhisperForConditionalGeneration,zg as WhisperModel,Vo as WhisperPreTrainedModel,Gp as WhisperProcessor,N0 as WhisperTextStreamer,Ea as WhisperTimeStampLogitsProcessor,hu as WhisperTokenizer,Rg as XLMForQuestionAnswering,Lg as XLMForSequenceClassification,$g as XLMForTokenClassification,Cg as XLMModel,Jt as XLMPreTrainedModel,Dg as XLMRobertaForMaskedLM,Bg as XLMRobertaForQuestionAnswering,jg as XLMRobertaForSequenceClassification,Ug as XLMRobertaForTokenClassification,Fg as XLMRobertaModel,Zt as XLMRobertaPreTrainedModel,xu as XLMRobertaTokenizer,gu as XLMTokenizer,Ng as XLMWithLMHeadModel,Cl as XVectorOutput,vp as YolosFeatureExtractor,Gg as YolosForObjectDetection,fa as YolosImageProcessor,qg as YolosModel,Rl as YolosObjectDetectionOutput,Ho as YolosPreTrainedModel,Vg as YoutuForCausalLM,Wg as YoutuModel,Ko as YoutuPreTrainedModel,ui as ZeroShotAudioClassificationPipeline,li as ZeroShotClassificationPipeline,hi as ZeroShotImageClassificationPipeline,gi as ZeroShotObjectDetectionPipeline,ie as cat,iv as cos_sim,Kw as dot,H as env,ge as full,Ar as full_like,kc as interpolate,Ye as interpolate_4d,IS as layer_norm,Lv as load_image,hE as load_video,mc as log_softmax,wy as matmul,Vi as mean,yy as mean_pooling,Oe as ones,Hi as ones_like,fv as permute,b7 as pipeline,ky as quantize_embeddings,TS as rand,by as randn,ps as random,bu as read_audio,OS as rfft,Wi as slice,pe as softmax,Je as stack,vc as std_mean,at as topk,Ac as zeros,Mc as zeros_like};