@huggingface/transformers 4.0.0-next.7 → 4.0.0-next.8

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 (79) hide show
  1. package/README.md +13 -2
  2. package/dist/transformers.js +689 -382
  3. package/dist/transformers.min.js +19 -19
  4. package/dist/transformers.node.cjs +716 -382
  5. package/dist/transformers.node.min.cjs +19 -19
  6. package/dist/transformers.node.min.mjs +19 -19
  7. package/dist/transformers.node.mjs +689 -382
  8. package/dist/transformers.web.js +697 -390
  9. package/dist/transformers.web.min.js +17 -17
  10. package/package.json +2 -2
  11. package/src/configs.js +28 -22
  12. package/src/env.js +1 -1
  13. package/src/image_processors_utils.js +25 -15
  14. package/src/models/chmv2/image_processing_chmv2.js +3 -0
  15. package/src/models/chmv2/modeling_chmv2.js +4 -0
  16. package/src/models/deepseek_v3/modeling_deepseek_v3.js +5 -0
  17. package/src/models/eurobert/modeling_eurobert.js +41 -0
  18. package/src/models/glm46v/image_processing_glm46v.js +12 -0
  19. package/src/models/glm46v/processing_glm46v.js +5 -0
  20. package/src/models/glm_moe_dsa/modeling_glm_moe_dsa.js +5 -0
  21. package/src/models/glm_ocr/modeling_glm_ocr.js +78 -0
  22. package/src/models/image_processors.js +2 -0
  23. package/src/models/lfm2_vl/image_processing_lfm2_vl.js +1 -1
  24. package/src/models/lighton_ocr/modeling_lighton_ocr.js +3 -0
  25. package/src/models/mistral4/modeling_mistral4.js +5 -0
  26. package/src/models/modeling_utils.js +2 -0
  27. package/src/models/models.js +10 -1
  28. package/src/models/nemotron_h/modeling_nemotron_h.js +5 -0
  29. package/src/models/processors.js +1 -0
  30. package/src/models/qwen2_vl/modeling_qwen2_vl.js +187 -136
  31. package/src/models/qwen2_vl/processing_qwen2_vl.js +5 -4
  32. package/src/models/registry.js +17 -0
  33. package/src/models/solar_open/modeling_solar_open.js +5 -0
  34. package/src/pipelines.js +1 -0
  35. package/src/utils/hub.js +4 -1
  36. package/src/utils/model_registry/get_file_metadata.js +1 -0
  37. package/types/configs.d.ts.map +1 -1
  38. package/types/image_processors_utils.d.ts +3 -2
  39. package/types/image_processors_utils.d.ts.map +1 -1
  40. package/types/models/{ast/modeling_ast.d.ts → audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.d.ts} +1 -1
  41. package/types/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.d.ts.map +1 -0
  42. package/types/models/chmv2/image_processing_chmv2.d.ts +4 -0
  43. package/types/models/chmv2/image_processing_chmv2.d.ts.map +1 -0
  44. package/types/models/chmv2/modeling_chmv2.d.ts +6 -0
  45. package/types/models/chmv2/modeling_chmv2.d.ts.map +1 -0
  46. package/types/models/deepseek_v3/modeling_deepseek_v3.d.ts +8 -0
  47. package/types/models/deepseek_v3/modeling_deepseek_v3.d.ts.map +1 -0
  48. package/types/models/eurobert/modeling_eurobert.d.ts +36 -0
  49. package/types/models/eurobert/modeling_eurobert.d.ts.map +1 -0
  50. package/types/models/glm46v/image_processing_glm46v.d.ts +4 -0
  51. package/types/models/glm46v/image_processing_glm46v.d.ts.map +1 -0
  52. package/types/models/glm46v/processing_glm46v.d.ts +4 -0
  53. package/types/models/glm46v/processing_glm46v.d.ts.map +1 -0
  54. package/types/models/glm_moe_dsa/modeling_glm_moe_dsa.d.ts +8 -0
  55. package/types/models/glm_moe_dsa/modeling_glm_moe_dsa.d.ts.map +1 -0
  56. package/types/models/glm_ocr/modeling_glm_ocr.d.ts +26 -0
  57. package/types/models/glm_ocr/modeling_glm_ocr.d.ts.map +1 -0
  58. package/types/models/image_processors.d.ts +2 -0
  59. package/types/models/lighton_ocr/modeling_lighton_ocr.d.ts +4 -0
  60. package/types/models/lighton_ocr/modeling_lighton_ocr.d.ts.map +1 -0
  61. package/types/models/mistral4/modeling_mistral4.d.ts +8 -0
  62. package/types/models/mistral4/modeling_mistral4.d.ts.map +1 -0
  63. package/types/models/modeling_utils.d.ts.map +1 -1
  64. package/types/models/models.d.ts +10 -1
  65. package/types/models/nemotron_h/modeling_nemotron_h.d.ts +8 -0
  66. package/types/models/nemotron_h/modeling_nemotron_h.d.ts.map +1 -0
  67. package/types/models/processors.d.ts +1 -0
  68. package/types/models/qwen2_vl/modeling_qwen2_vl.d.ts +41 -6
  69. package/types/models/qwen2_vl/modeling_qwen2_vl.d.ts.map +1 -1
  70. package/types/models/qwen2_vl/processing_qwen2_vl.d.ts +1 -0
  71. package/types/models/qwen2_vl/processing_qwen2_vl.d.ts.map +1 -1
  72. package/types/models/registry.d.ts.map +1 -1
  73. package/types/models/solar_open/modeling_solar_open.d.ts +8 -0
  74. package/types/models/solar_open/modeling_solar_open.d.ts.map +1 -0
  75. package/types/pipelines.d.ts +1 -0
  76. package/types/pipelines.d.ts.map +1 -1
  77. package/types/utils/hub.d.ts.map +1 -1
  78. package/types/models/ast/modeling_ast.d.ts.map +0 -1
  79. /package/src/models/{ast/modeling_ast.js → audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.js} +0 -0
@@ -1,24 +1,24 @@
1
- var Pb=Object.defineProperty;var Ts=(t,e)=>{for(var s in e)Pb(t,s,{get:e[s],enumerable:!0})};var Fe={};var Ke={};var Rw={};var Lb="4.0.0-next.7",bc=typeof self<"u",Cs=!Gw(Fe),Bw=!Gw(Ke),Wi=bc&&"caches"in self,Nb=typeof globalThis.Deno<"u",CA=typeof globalThis.Bun<"u",Hi=Nb&&Wi&&!Cs,qw=typeof process<"u",Uw=qw&&process?.release?.name==="node"&&!Hi,kc=typeof window<"u"&&typeof window.document<"u",vc=bc&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),Fb=kc||vc||Hi,$b=Uw||typeof navigator<"u"&&"gpu"in navigator,Rb=typeof navigator<"u"&&"ml"in navigator,Db=typeof crypto<"u"&&typeof crypto.getRandomValues=="function",jb=typeof chrome<"u"&&typeof chrome.runtime<"u"&&typeof chrome.runtime.id=="string",Bb=typeof ServiceWorkerGlobalScope<"u"&&bc&&self instanceof ServiceWorkerGlobalScope,qb=()=>{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},Ub=qb(),V=Object.freeze({IS_BROWSER_ENV:kc,IS_WEBWORKER_ENV:vc,IS_WEB_ENV:Fb,IS_SERVICE_WORKER_ENV:Bb,IS_DENO_WEB_RUNTIME:Hi,IS_WEB_CACHE_AVAILABLE:Wi,IS_WEBGPU_AVAILABLE:$b,IS_WEBNN_AVAILABLE:Rb,IS_SAFARI:Ub,IS_PROCESS_AVAILABLE:qw,IS_NODE_ENV:Uw,IS_FS_AVAILABLE:Cs,IS_PATH_AVAILABLE:Bw,IS_CRYPTO_AVAILABLE:Db,IS_CHROME_AVAILABLE:jb}),Ec=Cs&&Bw,Vi="./";if(Ec){let t=Object(import.meta).url;t?Vi=Ke.dirname(Ke.dirname(Rw.fileURLToPath(t))):typeof __dirname<"u"&&(Vi=Ke.dirname(__dirname))}var Gb=Ec?Ke.join(Vi,"/.cache/"):null,Dw="/models/",Wb=Ec?Ke.join(Vi,Dw):Dw,Vb=typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0,Ue=Object.freeze({DEBUG:10,INFO:20,WARNING:30,ERROR:40,NONE:50}),jw=Ue.WARNING,J={version:Lb,backends:{onnx:{}},get logLevel(){return jw},set logLevel(t){jw=t,J.backends.onnx?.setLogLevel?.(t)},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(kc||vc||Hi),localModelPath:Wb,useFS:Cs,useBrowserCache:Wi,useFSCache:Cs,cacheDir:Gb,useCustomCache:!1,customCache:null,useWasmCache:Wi||Cs,cacheKey:"transformers-cache",experimental_useCrossOriginStorage:!1,fetch:Vb};function Gw(t){return Object.keys(t).length===0}function vt(t,e){t&&t(e)}function Ww(t){return Number.isInteger(t)||typeof t=="bigint"}function Ac(t){return t==null||t===-1}function Mc(t){let e=[],s=t;for(;Array.isArray(s);)e.push(s.length),s=s[0];return e}function $e(...t){return Array.prototype.concat.apply([],t)}function Vw(...t){return t.reduce((e,s)=>e.flatMap(r=>s.map(n=>[r,n])))}function Ps(t,e){return Math.abs((t+e)%(2*e)-e)}function ke(t,e){return Object.assign({},...e.map(s=>{if(t[s]!==void 0)return{[s]:t[s]}}))}function Hw(t,e){let s=0;for(let r of t)r===e&&++s;return s}var F={error(...t){J.logLevel<=Ue.ERROR&&console.error(...t)},warn(...t){J.logLevel<=Ue.WARNING&&console.warn(...t)},info(...t){J.logLevel<=Ue.INFO&&console.log(...t)},debug(...t){J.logLevel<=Ue.DEBUG&&console.log(...t)},log(...t){this.info(...t)}};var Hb=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}},Kw=Hb,Kb=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}},Xb=Kb,ty=(()=>{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]]))})(),Qb=t=>Object.fromEntries(Object.entries(t).map(([e,s])=>[s,e])),Yb=Qb(ty),Xw=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",Jb=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|[${Xw}])]+`,` ?[^\\s${Xw}]+`]]),Ki="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",Oc=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"),Xi=(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 Jb)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=Zb(t.String);return new RegExp(e?s:`(${s})`,"gu")}else return console.warn("Unknown pattern type:",t),null},Zb=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),e1=(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},t1=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,s1=t=>Number.isInteger(t)||typeof t=="bigint",r1=t=>{let e=0;for(let s of t)++e;return e},n1=t=>sy(t.toLowerCase()),nt=(...t)=>Array.prototype.concat.apply([],t),Ic=t=>new Map(Object.entries(t)),o1=(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},sy=t=>t.replace(/\p{M}/gu,""),Qw=(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},i1=t=>t.match(/\S+/g)||[],a1=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},Mr=a1,l1=class extends Mr{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},Et=l1,c1=class extends Et{tokenize_chinese_chars(t){let e=[];for(let s=0;s<t.length;++s){let r=t[s],n=r.charCodeAt(0);t1(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}},u1=c1,p1=class extends Et{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}},_1=p1,d1=class extends Et{constructor(t){super(t),this.normalizers=(t.normalizers??[]).map(e=>ry(e))}normalize(t){return this.normalizers.reduce((e,s)=>s?s.normalize(e):e,t)}},f1=d1,m1=class extends Et{normalize(t){let e=Xi(this.config.pattern??{});return e===null?t:t.replaceAll(e,this.config.content??"")}},h1=m1,g1=class extends Et{constructor(){super(...arguments),this.form="NFC"}normalize(t){return t=t.normalize(this.form),t}},Qi=g1,x1=class extends Qi{constructor(){super(...arguments),this.form="NFC"}},w1=x1,y1=class extends Qi{constructor(){super(...arguments),this.form="NFD"}},b1=y1,k1=class extends Qi{constructor(){super(...arguments),this.form="NFKC"}},v1=k1,E1=class extends Qi{constructor(){super(...arguments),this.form="NFKD"}},A1=E1,M1=class extends Et{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}},S1=M1,O1=class extends Et{normalize(t){return sy(t)}},I1=O1,z1=class extends Et{normalize(t){return t.toLowerCase()}},T1=z1,C1=class extends Et{normalize(t){return t=this.config.prepend+t,t}},P1=C1;function L1(t){if(t===null)return null;switch(t.type){case"BertNormalizer":return new u1(t);case"Precompiled":return new _1(t);case"Sequence":return new f1(t);case"Replace":return new h1(t);case"NFC":return new w1(t);case"NFD":return new b1(t);case"NFKC":return new v1(t);case"NFKD":return new A1(t);case"Strip":return new S1(t);case"StripAccents":return new I1(t);case"Lowercase":return new T1(t);case"Prepend":return new P1(t);default:throw new Error(`Unknown Normalizer type: ${t.type}`)}}var ry=L1,N1=class extends Mr{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)}},ot=N1,F1=class extends ot{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=ty,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(""))}},$1=F1,R1=class extends ot{pre_tokenize_text(t,e){return t.match(/\w+|[^\w\s]+/g)||[]}},D1=R1,j1=class extends ot{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]}},B1=j1,q1=class extends ot{constructor(t){super(),this.config=t,this.pattern=Xi(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):o1(t,this.pattern)}},U1=q1,G1=class extends ot{constructor(t){super(),this.config=t,this.pattern=new RegExp(`[^${Ki}]+|[${Ki}]+`,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},W1=G1,V1=class extends ot{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)||[]}},H1=V1,K1=class extends ot{constructor(){super(),this.pattern=new RegExp(`[^\\s${Ki}]+|[${Ki}]`,"gu")}pre_tokenize_text(t,e){return t.trim().match(this.pattern)||[]}},X1=K1,Q1=class extends ot{constructor(t){super(),this.config=t,this.pattern=Xi(this.config.pattern??{}),this.content=this.config.content??""}pre_tokenize_text(t){return this.pattern===null?[t]:[t.replaceAll(this.pattern,this.config.content??"")]}},Y1=Q1,J1=class extends ot{constructor(t){super(),this.tokenizers=(t.pretokenizers??[]).map(e=>ny(e))}pre_tokenize_text(t,e){return this.tokenizers.reduce((s,r)=>r?r.pre_tokenize(s,e):s,[t])}},Z1=J1,ek=class extends ot{pre_tokenize_text(t){return i1(t)}},tk=ek,sk=class extends ot{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}},rk=sk;function nk(t){if(t===null)return null;switch(t.type){case"BertPreTokenizer":return new X1;case"Sequence":return new Z1(t);case"Whitespace":return new D1;case"WhitespaceSplit":return new tk;case"Metaspace":return new B1(t);case"ByteLevel":return new $1(t);case"Split":return new U1(t);case"Punctuation":return new W1(t);case"Digits":return new H1(t);case"Replace":return new Y1(t);case"FixedLength":return new rk(t);default:throw new Error(`Unknown PreTokenizer type: ${t.type}`)}}var ny=nk,ok=class extends Mr{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=e1(e,this.tokens_to_ids,this.unk_token_id)),e}},Yi=ok,ik=class extends Yi{constructor(t){super(t),this.max_input_chars_per_word=100,this.tokens_to_ids=Ic(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}},Yw=ik,Jw=class oy{constructor(e,s){this.is_leaf=e,this.children=s}static default(){return new oy(!1,new Map)}},ak=class{constructor(){this.root=Jw.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=Jw.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)}}},lk=ak,Sc=class iy{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 iy(this.token_id,this.node_id,this.pos,this.length,this.score);return e.prev=this.prev,e.backtrace_score=this.backtrace_score,e}},ck=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 Sc(this.bos_token_id??0,0,0,0,0),n=new Sc(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 Sc(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)}},uk=ck;function pk(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 _k=class extends Yi{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=pk(this.scores)[0],this.unk_score=this.min_score-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new lk,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=r1(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 uk(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}},Zw=_k,dk=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}},fk=dk,mk=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()}},hk=mk,gk=class extends Yi{constructor(t){super(t),this.tokens_to_ids=Ic(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 hk(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 fk((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}},ey=gk,xk=class extends Yi{constructor(t,e){super(t);let s=t.vocab;this.tokens_to_ids=Ic(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}},wk=xk;function yk(t,e){switch(t.type){case"WordPiece":return new Yw(t);case"Unigram":return new Zw(t,e.eos_token);case"BPE":return new ey(t);default:if(t.vocab)return Array.isArray(t.vocab)?new Zw(t,e.eos_token):Object.hasOwn(t,"continuing_subword_prefix")&&Object.hasOwn(t,"unk_token")?Object.hasOwn(t,"merges")?new ey(t):new Yw(t):new wk(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 bk=yk,kk=class extends Mr{constructor(t){super(),this.config=t}_call(t,...e){return this.post_process(t,...e)}},Sr=kk,vk=class extends Sr{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=nt(n,t),o=nt(o,new Array(t.length).fill(i.Sequence.type_id))):i.Sequence.id==="B"&&(n=nt(n,e),o=nt(o,new Array(e.length).fill(i.Sequence.type_id))));return{tokens:n,token_type_ids:o}}},Ek=vk,Ak=class extends Sr{post_process(t,e=null){return{tokens:t,tokens_pair:e}}},Mk=Ak,Sk=class extends Sr{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e=null,s=!0){s&&(t=nt([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=nt(t,n,e,o),r=nt(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},Ok=Sk,Ik=class extends Sr{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e,s=!0){s&&(t=nt([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=nt(t,n,e,o),r=nt(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},zk=Ik,Tk=class extends Sr{constructor(t){super(t),this.processors=(t.processors??[]).map(e=>ay(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}},Ck=Tk;function Pk(t){if(t===null)return null;switch(t.type){case"TemplateProcessing":return new Ek(t);case"ByteLevel":return new Mk(t);case"BertProcessing":return new Ok(t);case"RobertaProcessing":return new zk(t);case"Sequence":return new Ck(t);default:throw new Error(`Unknown PostProcessor type: ${t.type}`)}}var ay=Pk,Lk=class extends Mr{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("")}},Xe=Lk,Nk=class extends Xe{constructor(t){super(t),this.byte_decoder=Yb,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}},Fk=Nk,$k=class extends Xe{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=Oc(e)),e})}},Rk=$k,Dk=class extends Xe{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}},jk=Dk,Bk=class extends Xe{constructor(t){super(t),this.suffix=t.suffix??""}decode_chain(t){return t.map((e,s)=>e.replaceAll(this.suffix,s===t.length-1?"":" "))}},qk=Bk,Uk=class extends Xe{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=Oc(r).replaceAll(this.word_delimiter_token," ").trim()),r}decode_chain(t){return[this.convert_tokens_to_string(t)]}},Gk=Uk,Wk=class extends Xe{constructor(t){super(t),this.decoders=(t.decoders??[]).map(e=>ly(e))}decode_chain(t){return this.decoders.reduce((e,s)=>s.decode_chain(e),t)}},Vk=Wk,Hk=class extends Xe{decode_chain(t){let e=Xi(this.config.pattern),s=this.config.content??"";return e===null?t:t.map(r=>r.replaceAll(e,s))}},Kk=Hk,Xk=class extends Xe{decode_chain(t){return[t.join("")]}},Qk=Xk,Yk=class extends Xe{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)})}},Jk=Yk,Zk=class extends Xe{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}},ev=Zk;function tv(t){if(t===null)return null;switch(t.type){case"ByteLevel":return new Fk(t);case"WordPiece":return new Rk(t);case"Metaspace":return new jk(t);case"BPEDecoder":return new qk(t);case"CTC":return new Gk(t);case"Sequence":return new Vk(t);case"Replace":return new Kk(t);case"Fuse":return new Qk(t);case"Strip":return new Jk(t);case"ByteFallback":return new ev(t);default:throw new Error(`Unknown Decoder type: ${t.type}`)}}var ly=tv,sv=class{constructor(t,e){let s=Qw(t,"Tokenizer",["model","decoder","post_processor","pre_tokenizer","normalizer"]);if(s)throw new Error(s);let r=Qw(e,"Config");if(r)throw new Error(r);this.tokenizer=t,this.config=e,this.normalizer=ry(this.tokenizer.normalizer),this.pre_tokenizer=ny(this.tokenizer.pre_tokenizer),this.model=bk(this.tokenizer.model,this.config),this.post_processor=ay(this.tokenizer.post_processor),this.decoder=ly(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 Xb(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 Kw(n),this.splitter_normalized=new Kw(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||!s1(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=Oc(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=n1(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:nt(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}},cy=sv;var S=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"}),Qe=class{constructor(t,e){this.value=t,this.type=e}};function uy(t){return/\w/.test(t)}function Or(t){return/[0-9]/.test(t)}function py(t){return/\s/.test(t)}var rv=[["{%",S.OpenStatement],["%}",S.CloseStatement],["{{",S.OpenExpression],["}}",S.CloseExpression],["(",S.OpenParen],[")",S.CloseParen],["{",S.OpenCurlyBracket],["}",S.CloseCurlyBracket],["[",S.OpenSquareBracket],["]",S.CloseSquareBracket],[",",S.Comma],[".",S.Dot],[":",S.Colon],["|",S.Pipe],["<=",S.ComparisonBinaryOperator],[">=",S.ComparisonBinaryOperator],["==",S.ComparisonBinaryOperator],["!=",S.ComparisonBinaryOperator],["<",S.ComparisonBinaryOperator],[">",S.ComparisonBinaryOperator],["+",S.AdditiveBinaryOperator],["-",S.AdditiveBinaryOperator],["~",S.AdditiveBinaryOperator],["*",S.MultiplicativeBinaryOperator],["/",S.MultiplicativeBinaryOperator],["%",S.MultiplicativeBinaryOperator],["=",S.Equals]],nv=new Map([["n",`
3
- `],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function ov(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 iv(t,e={}){let s=[],r=ov(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++],_=nv.get(p);if(_===void 0)throw new SyntaxError(`Unexpected escaped character: ${p}`);u+=_;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===S.Text&&(c.value=c.value.trimEnd(),c.value===""&&s.pop())},l=()=>{for(;n<r.length&&py(r[n]);)++n};e:for(;n<r.length;){let c=s.at(-1)?.type;if(c===void 0||c===S.CloseStatement||c===S.CloseExpression||c===S.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 Qe(p,S.Text));continue}}if(r[n]==="{"&&r[n+1]==="#"){n+=2;let p=r[n]==="-";p&&++n;let _="";for(;r[n]!=="#"||r[n+1]!=="}";){if(n+2>=r.length)throw new SyntaxError("Missing end of comment tag");_+=r[n++]}let d=_.endsWith("-");d&&(_=_.slice(0,-1)),p&&a(),s.push(new Qe(_,S.Comment)),n+=2,d&&l();continue}if(r.slice(n,n+3)==="{%-"){a(),s.push(new Qe("{%",S.OpenStatement)),n+=3;continue}if(r.slice(n,n+3)==="{{-"){a(),s.push(new Qe("{{",S.OpenExpression)),o=0,n+=3;continue}if(i(py),r.slice(n,n+3)==="-%}"){s.push(new Qe("%}",S.CloseStatement)),n+=3,l();continue}if(r.slice(n,n+3)==="-}}"){s.push(new Qe("}}",S.CloseExpression)),n+=3,l();continue}let u=r[n];if(u==="-"||u==="+"){let p=s.at(-1)?.type;if(p===S.Text||p===void 0)throw new SyntaxError(`Unexpected character: ${u}`);switch(p){case S.Identifier:case S.NumericLiteral:case S.StringLiteral:case S.CloseParen:case S.CloseSquareBracket:break;default:{++n;let _=i(Or);s.push(new Qe(`${u}${_}`,_.length>0?S.NumericLiteral:S.UnaryOperator));continue}}}for(let[p,_]of rv){if(p==="}}"&&o>0)continue;if(r.slice(n,n+p.length)===p){s.push(new Qe(p,_)),_===S.OpenExpression?o=0:_===S.OpenCurlyBracket?++o:_===S.CloseCurlyBracket&&--o,n+=p.length;continue e}}if(u==="'"||u==='"'){++n;let p=i(_=>_!==u);s.push(new Qe(p,S.StringLiteral)),++n;continue}if(Or(u)){let p=i(Or);if(r[n]==="."&&Or(r[n+1])){++n;let _=i(Or);p=`${p}.${_}`}s.push(new Qe(p,S.NumericLiteral));continue}if(uy(u)){let p=i(uy);s.push(new Qe(p,S.Identifier));continue}throw new SyntaxError(`Unexpected character: ${u}`)}return s}var at=class{type="Statement"},av=class extends at{constructor(t){super(),this.body=t}type="Program"},lv=class extends at{constructor(t,e,s){super(),this.test=t,this.body=e,this.alternate=s}type="If"},cv=class extends at{constructor(t,e,s,r){super(),this.loopvar=t,this.iterable=e,this.body=s,this.defaultBlock=r}type="For"},uv=class extends at{type="Break"},pv=class extends at{type="Continue"},_v=class extends at{constructor(t,e,s){super(),this.assignee=t,this.value=e,this.body=s}type="Set"},dv=class extends at{constructor(t,e,s){super(),this.name=t,this.args=e,this.body=s}type="Macro"},fv=class extends at{constructor(t){super(),this.value=t}type="Comment"},Ve=class extends at{type="Expression"},mv=class extends Ve{constructor(t,e,s){super(),this.object=t,this.property=e,this.computed=s}type="MemberExpression"},_y=class extends Ve{constructor(t,e){super(),this.callee=t,this.args=e}type="CallExpression"},Ls=class extends Ve{constructor(t){super(),this.value=t}type="Identifier"},Ns=class extends Ve{constructor(t){super(),this.value=t}type="Literal"},hv=class extends Ns{type="IntegerLiteral"},gv=class extends Ns{type="FloatLiteral"},dy=class extends Ns{type="StringLiteral"},xv=class extends Ns{type="ArrayLiteral"},fy=class extends Ns{type="TupleLiteral"},wv=class extends Ns{type="ObjectLiteral"},Ir=class extends Ve{constructor(t,e,s){super(),this.operator=t,this.left=e,this.right=s}type="BinaryExpression"},yv=class extends Ve{constructor(t,e){super(),this.operand=t,this.filter=e}type="FilterExpression"},bv=class extends at{constructor(t,e){super(),this.filter=t,this.body=e}type="FilterStatement"},kv=class extends Ve{constructor(t,e){super(),this.lhs=t,this.test=e}type="SelectExpression"},vv=class extends Ve{constructor(t,e,s){super(),this.operand=t,this.negate=e,this.test=s}type="TestExpression"},Ev=class extends Ve{constructor(t,e){super(),this.operator=t,this.argument=e}type="UnaryExpression"},Av=class extends Ve{constructor(t=void 0,e=void 0,s=void 0){super(),this.start=t,this.stop=e,this.step=s}type="SliceExpression"},Mv=class extends Ve{constructor(t,e){super(),this.key=t,this.value=e}type="KeywordArgumentExpression"},Sv=class extends Ve{constructor(t){super(),this.argument=t}type="SpreadExpression"},Ov=class extends at{constructor(t,e,s){super(),this.call=t,this.callerArgs=e,this.body=s}type="CallStatement"},Iv=class extends Ve{constructor(t,e,s){super(),this.condition=t,this.trueExpr=e,this.falseExpr=s}type="Ternary"};function zv(t){let e=new av([]),s=0;function r(v,E){let I=t[s++];if(!I||I.type!==v)throw new Error(`Parser Error: ${E}. ${I.type} !== ${v}.`);return I}function n(v){if(!l(v))throw new SyntaxError(`Expected ${v}`);++s}function o(){switch(t[s].type){case S.Comment:return new fv(t[s++].value);case S.Text:return c();case S.OpenStatement:return u();case S.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,I)=>E===t[s+I].type)}function a(...v){return t[s]?.type===S.OpenStatement&&t[s+1]?.type===S.Identifier&&v.includes(t[s+1]?.value)}function l(...v){return s+v.length<=t.length&&v.every((E,I)=>t[s+I].type==="Identifier"&&E===t[s+I].value)}function c(){return new dy(r(S.Text,"Expected text token").value)}function u(){if(r(S.OpenStatement,"Expected opening statement token"),t[s].type!==S.Identifier)throw new SyntaxError(`Unknown statement, got ${t[s].type}`);let v=t[s].value,E;switch(v){case"set":++s,E=_();break;case"if":++s,E=d(),r(S.OpenStatement,"Expected {% token"),n("endif"),r(S.CloseStatement,"Expected %} token");break;case"macro":++s,E=m(),r(S.OpenStatement,"Expected {% token"),n("endmacro"),r(S.CloseStatement,"Expected %} token");break;case"for":++s,E=g(),r(S.OpenStatement,"Expected {% token"),n("endfor"),r(S.CloseStatement,"Expected %} token");break;case"call":{++s;let I=null;i(S.OpenParen)&&(I=C());let H=se();if(H.type!=="Identifier")throw new SyntaxError("Expected identifier following call statement");let be=C();r(S.CloseStatement,"Expected closing statement token");let Q=[];for(;!a("endcall");)Q.push(o());r(S.OpenStatement,"Expected '{%'"),n("endcall"),r(S.CloseStatement,"Expected closing statement token");let je=new _y(H,be);E=new Ov(je,I,Q);break}case"break":++s,r(S.CloseStatement,"Expected closing statement token"),E=new uv;break;case"continue":++s,r(S.CloseStatement,"Expected closing statement token"),E=new pv;break;case"filter":{++s;let I=se();I instanceof Ls&&i(S.OpenParen)&&(I=R(I)),r(S.CloseStatement,"Expected closing statement token");let H=[];for(;!a("endfilter");)H.push(o());r(S.OpenStatement,"Expected '{%'"),n("endfilter"),r(S.CloseStatement,"Expected '%}'"),E=new bv(I,H);break}default:throw new SyntaxError(`Unknown statement type: ${v}`)}return E}function p(){r(S.OpenExpression,"Expected opening expression token");let v=x();return r(S.CloseExpression,"Expected closing expression token"),v}function _(){let v=h(),E=null,I=[];if(i(S.Equals))++s,E=h();else{for(r(S.CloseStatement,"Expected %} token");!a("endset");)I.push(o());r(S.OpenStatement,"Expected {% token"),n("endset")}return r(S.CloseStatement,"Expected closing statement token"),new _v(v,E,I)}function d(){let v=x();r(S.CloseStatement,"Expected closing statement token");let E=[],I=[];for(;!a("elif","else","endif");)E.push(o());if(a("elif")){++s,++s;let H=d();I.push(H)}else if(a("else"))for(++s,++s,r(S.CloseStatement,"Expected closing statement token");!a("endif");)I.push(o());return new lv(v,E,I)}function m(){let v=se();if(v.type!=="Identifier")throw new SyntaxError("Expected identifier following macro statement");let E=C();r(S.CloseStatement,"Expected closing statement token");let I=[];for(;!a("endmacro");)I.push(o());return new dv(v,E,I)}function h(v=!1){let E=v?se:x,I=[E()],H=i(S.Comma);for(;H&&(++s,I.push(E()),!!i(S.Comma)););return H?new fy(I):I[0]}function g(){let v=h(!0);if(!(v instanceof Ls||v instanceof fy))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=x();r(S.CloseStatement,"Expected closing statement token");let I=[];for(;!a("endfor","else");)I.push(o());let H=[];if(a("else"))for(++s,++s,r(S.CloseStatement,"Expected closing statement token");!a("endfor");)H.push(o());return new cv(v,E,I,H)}function x(){return w()}function w(){let v=y();if(l("if")){++s;let E=y();if(l("else")){++s;let I=w();return new Iv(E,v,I)}else return new kv(v,E)}return v}function y(){let v=b();for(;l("or");){let E=t[s];++s;let I=b();v=new Ir(E,v,I)}return v}function b(){let v=M();for(;l("and");){let E=t[s];++s;let I=M();v=new Ir(E,v,I)}return v}function M(){let v;for(;l("not");){let E=t[s];++s;let I=M();v=new Ev(E,I)}return v??k()}function k(){let v=O();for(;;){let E;if(l("not","in"))E=new Qe("not in",S.Identifier),s+=2;else if(l("in"))E=t[s++];else if(i(S.ComparisonBinaryOperator))E=t[s++];else break;let I=O();v=new Ir(E,v,I)}return v}function O(){let v=B();for(;i(S.AdditiveBinaryOperator);){let E=t[s];++s;let I=B();v=new Ir(E,v,I)}return v}function N(){let v=q(se());return i(S.OpenParen)?R(v):v}function R(v){let E=new _y(v,C());return E=q(E),i(S.OpenParen)&&(E=R(E)),E}function C(){r(S.OpenParen,"Expected opening parenthesis for arguments list");let v=D();return r(S.CloseParen,"Expected closing parenthesis for arguments list"),v}function D(){let v=[];for(;!i(S.CloseParen);){let E;if(t[s].type===S.MultiplicativeBinaryOperator&&t[s].value==="*"){++s;let I=x();E=new Sv(I)}else if(E=x(),i(S.Equals)){if(++s,!(E instanceof Ls))throw new SyntaxError("Expected identifier for keyword argument");let I=x();E=new Mv(E,I)}v.push(E),i(S.Comma)&&++s}return v}function $(){let v=[],E=!1;for(;!i(S.CloseSquareBracket);)i(S.Colon)?(v.push(void 0),++s,E=!0):(v.push(x()),i(S.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 Av(...v)}return v[0]}function q(v){for(;i(S.Dot)||i(S.OpenSquareBracket);){let E=t[s];++s;let I,H=E.type===S.OpenSquareBracket;if(H)I=$(),r(S.CloseSquareBracket,"Expected closing square bracket");else if(I=se(),I.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");v=new mv(v,I,H)}return v}function B(){let v=G();for(;i(S.MultiplicativeBinaryOperator);){let E=t[s++],I=G();v=new Ir(E,v,I)}return v}function G(){let v=ee();for(;l("is");){++s;let E=l("not");E&&++s;let I=se();if(!(I instanceof Ls))throw new SyntaxError("Expected identifier for the test");v=new vv(v,E,I)}return v}function ee(){let v=N();for(;i(S.Pipe);){++s;let E=se();if(!(E instanceof Ls))throw new SyntaxError("Expected identifier for the filter");i(S.OpenParen)&&(E=R(E)),v=new yv(v,E)}return v}function se(){let v=t[s++];switch(v.type){case S.NumericLiteral:{let E=v.value;return E.includes(".")?new gv(Number(E)):new hv(Number(E))}case S.StringLiteral:{let E=v.value;for(;i(S.StringLiteral);)E+=t[s++].value;return new dy(E)}case S.Identifier:return new Ls(v.value);case S.OpenParen:{let E=h();return r(S.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),E}case S.OpenSquareBracket:{let E=[];for(;!i(S.CloseSquareBracket);)E.push(x()),i(S.Comma)&&++s;return++s,new xv(E)}case S.OpenCurlyBracket:{let E=new Map;for(;!i(S.CloseCurlyBracket);){let I=x();r(S.Colon,"Expected colon between key and value in object literal");let H=x();E.set(I,H),i(S.Comma)&&++s}return++s,new wv(E)}default:throw new SyntaxError(`Unexpected token: ${v.type}`)}}for(;s<t.length;)e.body.push(o());return e}function Tv(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 my(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 Cv(t){return t.replace(/\b\w/g,e=>e.toUpperCase())}function Pv(t){return Lv(new Date,t)}function Lv(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 Nv(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Fv(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(Nv(e),"gu");return t.replaceAll(o,i=>n>0?(--n,s):i)}var hy=class extends Error{},gy=class extends Error{},ft=class{type="RuntimeValue";value;builtins=new Map;constructor(t=void 0){this.value=t}__bool__(){return new K(!!this.value)}toString(){return String(this.value)}},Z=class extends ft{type="IntegerValue"},Ee=class extends ft{type="FloatValue";toString(){return this.value%1===0?this.value.toFixed(1):this.value.toString()}},j=class extends ft{type="StringValue";builtins=new Map([["upper",new ge(()=>new j(this.value.toUpperCase()))],["lower",new ge(()=>new j(this.value.toLowerCase()))],["strip",new ge(()=>new j(this.value.trim()))],["title",new ge(()=>new j(Cv(this.value)))],["capitalize",new ge(()=>new j(this.value.charAt(0).toUpperCase()+this.value.slice(1)))],["length",new Z(this.value.length)],["rstrip",new ge(()=>new j(this.value.trimEnd()))],["lstrip",new ge(()=>new j(this.value.trimStart()))],["startswith",new ge(t=>{if(t.length===0)throw new Error("startswith() requires at least one argument");let e=t[0];if(e instanceof j)return new K(this.value.startsWith(e.value));if(e instanceof ne){for(let s of e.value){if(!(s instanceof j))throw new Error("startswith() tuple elements must be strings");if(this.value.startsWith(s.value))return new K(!0)}return new K(!1)}throw new Error("startswith() argument must be a string or tuple of strings")})],["endswith",new ge(t=>{if(t.length===0)throw new Error("endswith() requires at least one argument");let e=t[0];if(e instanceof j)return new K(this.value.endsWith(e.value));if(e instanceof ne){for(let s of e.value){if(!(s instanceof j))throw new Error("endswith() tuple elements must be strings");if(this.value.endsWith(s.value))return new K(!0)}return new K(!1)}throw new Error("endswith() argument must be a string or tuple of strings")})],["split",new ge(t=>{let e=t[0]??new xe;if(!(e instanceof j||e instanceof xe))throw new Error("sep argument must be a string or null");let s=t[1]??new Z(-1);if(!(s instanceof Z))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 ne(r.map(n=>new j(n)))})],["replace",new ge(t=>{if(t.length<2)throw new Error("replace() requires at least two arguments");let e=t[0],s=t[1];if(!(e instanceof j&&s instanceof j))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 Z||r instanceof xe))throw new Error("replace() count argument must be a number or null");return new j(Fv(this.value,e.value,s.value,r.value))})]])},K=class extends ft{type="BooleanValue"},$v=/[\x7f-\uffff]/g;function xy(t){return t.replace($v,e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0"))}function as(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=xy(u)),u}case"ArrayValue":case"ObjectValue":{let u=n?" ".repeat(n):"",p=`
5
- `+u.repeat(s),_=p+u;if(t.type==="ArrayValue"){let d=t.value.map(m=>as(m,e,s+1,r));return n?`[${_}${d.join(`${l}${_}`)}${p}]`:`[${d.join(l)}]`}else{let d=Array.from(t.value.entries());a&&(d=d.sort(([h],[g])=>h.localeCompare(g)));let m=d.map(([h,g])=>{let x=JSON.stringify(h);o&&(x=xy(x));let w=`${x}${c}${as(g,e,s+1,r)}`;return n?`${_}${w}`:w});return n?`{${m.join(l)}${p}}`:`{${m.join(l)}}`}}default:throw new Error(`Cannot convert to JSON: ${t.type}`)}}var Te=class extends ft{type="ObjectValue";__bool__(){return new K(this.value.size>0)}builtins=new Map([["get",new ge(([t,e])=>{if(!(t instanceof j))throw new Error(`Object key must be a string: got ${t.type}`);return this.value.get(t.value)??e??new xe})],["items",new ge(()=>this.items())],["keys",new ge(()=>this.keys())],["values",new ge(()=>this.values())],["dictsort",new ge(t=>{let e=new Map,s=t.filter(a=>a instanceof zr?(e=a.value,!1):!0),r=s.at(0)??e.get("case_sensitive")??new K(!1);if(!(r instanceof K))throw new Error("case_sensitive must be a boolean");let n=s.at(1)??e.get("by")??new j("key");if(!(n instanceof j))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 K(!1);if(!(o instanceof K))throw new Error("reverse must be a boolean");let i=Array.from(this.value.entries()).map(([a,l])=>new ne([new j(a),l])).sort((a,l)=>{let c=n.value==="key"?0:1,u=a.value[c],p=l.value[c],_=zc(u,p,r.value);return o.value?-_:_});return new ne(i)})]]);items(){return new ne(Array.from(this.value.entries()).map(([t,e])=>new ne([new j(t),e])))}keys(){return new ne(Array.from(this.value.keys()).map(t=>new j(t)))}values(){return new ne(Array.from(this.value.values()))}toString(){return as(this,{},0,!1)}},zr=class extends Te{type="KeywordArgumentsValue"},ne=class extends ft{type="ArrayValue";builtins=new Map([["length",new Z(this.value.length)]]);__bool__(){return new K(this.value.length>0)}toString(){return as(this,{},0,!1)}},wy=class extends ne{type="TupleValue"},ge=class extends ft{type="FunctionValue"},xe=class extends ft{type="NullValue"},he=class extends ft{type="UndefinedValue"},is=class{constructor(t){this.parent=t}variables=new Map([["namespace",new ge(t=>{if(t.length===0)return new Te(new Map);if(t.length!==1||!(t[0]instanceof Te))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 ge],["odd",t=>{if(!(t instanceof Z))throw new Error(`cannot odd on ${t.type}`);return t.value%2!==0}],["even",t=>{if(!(t instanceof Z))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 Z||t instanceof Ee],["integer",t=>t instanceof Z],["iterable",t=>t.type==="ArrayValue"||t.type==="StringValue"],["mapping",t=>t instanceof Te],["sequence",t=>t instanceof ne||t instanceof Te||t instanceof j],["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,Ji(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 he}catch{return new he}}};function Rv(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",Tv),t.set("strftime_now",Pv),t.set("True",!0),t.set("False",!1),t.set("None",null)}function yy(t,e){let s=e.split("."),r=t;for(let n of s)if(r instanceof Te)r=r.value.get(n)??new he;else if(r instanceof ne){let o=parseInt(n,10);if(!isNaN(o)&&o>=0&&o<r.value.length)r=r.value[o];else return new he}else return new he;return r}function zc(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 he&&e instanceof he)return 0;if(t instanceof he||e instanceof he)throw new Error(`Cannot compare ${t.type} with ${e.type}`);let r=o=>o instanceof Z||o instanceof Ee||o instanceof K,n=o=>o instanceof K?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 Dv=class{global;constructor(t){this.global=t??new is}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 K(s.value==r.value);case"!=":return new K(s.value!=r.value)}if(s instanceof he||r instanceof he){if(r instanceof he&&["in","not in"].includes(t.operator.value))return new K(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 j(s.value.toString()+r.value.toString());if((s instanceof Z||s instanceof Ee)&&(r instanceof Z||r instanceof Ee)){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 Ee||r instanceof Ee?new Ee(i):new Z(i)}case"/":return new Ee(n/o);case"%":{let i=n%o;return s instanceof Ee||r instanceof Ee?new Ee(i):new Z(i)}case"<":return new K(n<o);case">":return new K(n>o);case">=":return new K(n>=o);case"<=":return new K(n<=o)}}else if(s instanceof ne&&r instanceof ne){if(t.operator.value==="+")return new ne(s.value.concat(r.value))}else if(r instanceof ne){let n=r.value.find(o=>o.value===s.value)!==void 0;switch(t.operator.value){case"in":return new K(n);case"not in":return new K(!n)}}}if((s instanceof j||r instanceof j)&&t.operator.value==="+")return new j(s.value.toString()+r.value.toString());if(s instanceof j&&r instanceof j)switch(t.operator.value){case"in":return new K(r.value.includes(s.value));case"not in":return new K(!r.value.includes(s.value))}if(s instanceof j&&r instanceof Te)switch(t.operator.value){case"in":return new K(r.value.has(s.value));case"not in":return new K(!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 ne))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==="safe")return t;if(r.value==="tojson")return new j(as(t,{}));if(t instanceof ne)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 Z(t.value.length);case"reverse":return new ne(t.value.slice().reverse());case"sort":return new ne(t.value.slice().sort((n,o)=>zc(n,o,!1)));case"join":return new j(t.value.map(n=>n.value).join(""));case"string":return new j(as(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 ne(o)}default:throw new Error(`Unknown ArrayValue filter: ${r.value}`)}else if(t instanceof j)switch(r.value){case"length":case"upper":case"lower":case"title":case"capitalize":{let n=t.builtins.get(r.value);if(n instanceof ge)return n.value([],s);if(n instanceof Z)return n;throw new Error(`Unknown StringValue filter: ${r.value}`)}case"trim":return new j(t.value.trim());case"indent":return new j(t.value.split(`
1
+ var o1=Object.defineProperty;var Ms=(t,e)=>{for(var s in e)o1(t,s,{get:e[s],enumerable:!0})};var Ne={};var Xe={};var cy={};var i1="4.0.0-next.8",Ec=typeof self<"u",Ss=!my(Ne),_y=!my(Xe),Vi=Ec&&"caches"in self,a1=typeof globalThis.Deno<"u",nM=typeof globalThis.Bun<"u",Ki=a1&&Vi&&!Ss,dy=typeof process<"u",fy=dy&&process?.release?.name==="node"&&!Ki,Ac=typeof window<"u"&&typeof window.document<"u",Mc=Ec&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),l1=Ac||Mc||Ki,c1=fy||typeof navigator<"u"&&"gpu"in navigator,p1=typeof navigator<"u"&&"ml"in navigator,u1=typeof crypto<"u"&&typeof crypto.getRandomValues=="function",_1=typeof chrome<"u"&&typeof chrome.runtime<"u"&&typeof chrome.runtime.id=="string",d1=typeof ServiceWorkerGlobalScope<"u"&&Ec&&self instanceof ServiceWorkerGlobalScope,f1=()=>{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},m1=f1(),V=Object.freeze({IS_BROWSER_ENV:Ac,IS_WEBWORKER_ENV:Mc,IS_WEB_ENV:l1,IS_SERVICE_WORKER_ENV:d1,IS_DENO_WEB_RUNTIME:Ki,IS_WEB_CACHE_AVAILABLE:Vi,IS_WEBGPU_AVAILABLE:c1,IS_WEBNN_AVAILABLE:p1,IS_SAFARI:m1,IS_PROCESS_AVAILABLE:dy,IS_NODE_ENV:fy,IS_FS_AVAILABLE:Ss,IS_PATH_AVAILABLE:_y,IS_CRYPTO_AVAILABLE:u1,IS_CHROME_AVAILABLE:_1}),Sc=Ss&&_y,Hi="./";if(Sc){let t=Object(import.meta).url;t?Hi=Xe.dirname(Xe.dirname(cy.fileURLToPath(t))):typeof __dirname<"u"&&(Hi=Xe.dirname(__dirname))}var h1=Sc?Xe.join(Hi,"/.cache/"):null,py="/models/",g1=Sc?Xe.join(Hi,py):py,x1=typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0,Be=Object.freeze({DEBUG:10,INFO:20,WARNING:30,ERROR:40,NONE:50}),uy=Be.WARNING,Y={version:i1,backends:{onnx:{}},get logLevel(){return uy},set logLevel(t){uy=t,Y.backends.onnx?.setLogLevel?.(t)},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(Ac||Mc||Ki),localModelPath:g1,useFS:Ss,useBrowserCache:Vi,useFSCache:Ss,cacheDir:h1,useCustomCache:!1,customCache:null,useWasmCache:Vi||Ss,cacheKey:"transformers-cache",experimental_useCrossOriginStorage:!1,fetch:x1};function my(t){return Object.keys(t).length===0}function gt(t,e){t&&t(e)}function hy(t){return Number.isInteger(t)||typeof t=="bigint"}function Oc(t){return t==null||t===-1}function Ic(t){let e=[],s=t;for(;Array.isArray(s);)e.push(s.length),s=s[0];return e}function Fe(...t){return Array.prototype.concat.apply([],t)}function gy(...t){return t.reduce((e,s)=>e.flatMap(r=>s.map(n=>[r,n])))}function Os(t,e){return Math.abs((t+e)%(2*e)-e)}function ke(t,e){return Object.assign({},...e.map(s=>{if(t[s]!==void 0)return{[s]:t[s]}}))}function xy(t,e){let s=0;for(let r of t)r===e&&++s;return s}var F={error(...t){Y.logLevel<=Be.ERROR&&console.error(...t)},warn(...t){Y.logLevel<=Be.WARNING&&console.warn(...t)},info(...t){Y.logLevel<=Be.INFO&&console.log(...t)},debug(...t){Y.logLevel<=Be.DEBUG&&console.log(...t)},log(...t){this.info(...t)}};var w1=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}},wy=w1,y1=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}},b1=y1,My=(()=>{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]]))})(),k1=t=>Object.fromEntries(Object.entries(t).map(([e,s])=>[s,e])),v1=k1(My),yy=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",E1=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|[${yy}])]+`,` ?[^\\s${yy}]+`]]),Xi="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",Tc=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"),Qi=(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 E1)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=A1(t.String);return new RegExp(e?s:`(${s})`,"gu")}else return console.warn("Unknown pattern type:",t),null},A1=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),M1=(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},S1=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,O1=t=>Number.isInteger(t)||typeof t=="bigint",I1=t=>{let e=0;for(let s of t)++e;return e},z1=t=>Sy(t.toLowerCase()),st=(...t)=>Array.prototype.concat.apply([],t),Cc=t=>new Map(Object.entries(t)),T1=(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},Sy=t=>t.replace(/\p{M}/gu,""),by=(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},C1=t=>t.match(/\S+/g)||[],P1=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},Mr=P1,L1=class extends Mr{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},xt=L1,N1=class extends xt{tokenize_chinese_chars(t){let e=[];for(let s=0;s<t.length;++s){let r=t[s],n=r.charCodeAt(0);S1(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}},F1=N1,$1=class extends xt{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}},R1=$1,D1=class extends xt{constructor(t){super(t),this.normalizers=(t.normalizers??[]).map(e=>Oy(e))}normalize(t){return this.normalizers.reduce((e,s)=>s?s.normalize(e):e,t)}},j1=D1,B1=class extends xt{normalize(t){let e=Qi(this.config.pattern??{});return e===null?t:t.replaceAll(e,this.config.content??"")}},q1=B1,U1=class extends xt{constructor(){super(...arguments),this.form="NFC"}normalize(t){return t=t.normalize(this.form),t}},Yi=U1,G1=class extends Yi{constructor(){super(...arguments),this.form="NFC"}},W1=G1,V1=class extends Yi{constructor(){super(...arguments),this.form="NFD"}},H1=V1,K1=class extends Yi{constructor(){super(...arguments),this.form="NFKC"}},X1=K1,Q1=class extends Yi{constructor(){super(...arguments),this.form="NFKD"}},Y1=Q1,J1=class extends xt{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}},Z1=J1,ek=class extends xt{normalize(t){return Sy(t)}},tk=ek,sk=class extends xt{normalize(t){return t.toLowerCase()}},rk=sk,nk=class extends xt{normalize(t){return t=this.config.prepend+t,t}},ok=nk;function ik(t){if(t===null)return null;switch(t.type){case"BertNormalizer":return new F1(t);case"Precompiled":return new R1(t);case"Sequence":return new j1(t);case"Replace":return new q1(t);case"NFC":return new W1(t);case"NFD":return new H1(t);case"NFKC":return new X1(t);case"NFKD":return new Y1(t);case"Strip":return new Z1(t);case"StripAccents":return new tk(t);case"Lowercase":return new rk(t);case"Prepend":return new ok(t);default:throw new Error(`Unknown Normalizer type: ${t.type}`)}}var Oy=ik,ak=class extends Mr{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)}},rt=ak,lk=class extends rt{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=My,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(""))}},ck=lk,pk=class extends rt{pre_tokenize_text(t,e){return t.match(/\w+|[^\w\s]+/g)||[]}},uk=pk,_k=class extends rt{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]}},dk=_k,fk=class extends rt{constructor(t){super(),this.config=t,this.pattern=Qi(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):T1(t,this.pattern)}},mk=fk,hk=class extends rt{constructor(t){super(),this.config=t,this.pattern=new RegExp(`[^${Xi}]+|[${Xi}]+`,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},gk=hk,xk=class extends rt{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)||[]}},wk=xk,yk=class extends rt{constructor(){super(),this.pattern=new RegExp(`[^\\s${Xi}]+|[${Xi}]`,"gu")}pre_tokenize_text(t,e){return t.trim().match(this.pattern)||[]}},bk=yk,kk=class extends rt{constructor(t){super(),this.config=t,this.pattern=Qi(this.config.pattern??{}),this.content=this.config.content??""}pre_tokenize_text(t){return this.pattern===null?[t]:[t.replaceAll(this.pattern,this.config.content??"")]}},vk=kk,Ek=class extends rt{constructor(t){super(),this.tokenizers=(t.pretokenizers??[]).map(e=>Iy(e))}pre_tokenize_text(t,e){return this.tokenizers.reduce((s,r)=>r?r.pre_tokenize(s,e):s,[t])}},Ak=Ek,Mk=class extends rt{pre_tokenize_text(t){return C1(t)}},Sk=Mk,Ok=class extends rt{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}},Ik=Ok;function zk(t){if(t===null)return null;switch(t.type){case"BertPreTokenizer":return new bk;case"Sequence":return new Ak(t);case"Whitespace":return new uk;case"WhitespaceSplit":return new Sk;case"Metaspace":return new dk(t);case"ByteLevel":return new ck(t);case"Split":return new mk(t);case"Punctuation":return new gk(t);case"Digits":return new wk(t);case"Replace":return new vk(t);case"FixedLength":return new Ik(t);default:throw new Error(`Unknown PreTokenizer type: ${t.type}`)}}var Iy=zk,Tk=class extends Mr{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=M1(e,this.tokens_to_ids,this.unk_token_id)),e}},Ji=Tk,Ck=class extends Ji{constructor(t){super(t),this.max_input_chars_per_word=100,this.tokens_to_ids=Cc(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}},ky=Ck,vy=class zy{constructor(e,s){this.is_leaf=e,this.children=s}static default(){return new zy(!1,new Map)}},Pk=class{constructor(){this.root=vy.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=vy.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)}}},Lk=Pk,zc=class Ty{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 Ty(this.token_id,this.node_id,this.pos,this.length,this.score);return e.prev=this.prev,e.backtrace_score=this.backtrace_score,e}},Nk=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 zc(this.bos_token_id??0,0,0,0,0),n=new zc(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 zc(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 p=c.backtrace_score+i.score;(l===null||p>a)&&(l=c.clone(),a=p)}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)}},Fk=Nk;function $k(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 Rk=class extends Ji{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=$k(this.scores)[0],this.unk_score=this.min_score-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new Lk,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),p=this.scores[c],u=I1(l);t.insert(r,u,p,c),!n&&u===s&&(n=!0)}n||t.insert(r,s,this.unk_score,this.unk_token_id),r+=s}}tokenize(t){let e=new Fk(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}},Ey=Rk,Dk=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}},jk=Dk,Bk=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()}},qk=Bk,Uk=class extends Ji{constructor(t){super(t),this.tokens_to_ids=Cc(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 qk(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 jk((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):this.unk_token!=null&&e.push(this.unk_token)}else this.unk_token!=null&&e.push(this.unk_token)}return e}},Ay=Uk,Gk=class extends Ji{constructor(t,e){super(t);let s=t.vocab;this.tokens_to_ids=Cc(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}},Wk=Gk;function Vk(t,e){switch(t.type){case"WordPiece":return new ky(t);case"Unigram":return new Ey(t,e.eos_token);case"BPE":return new Ay(t);default:if(t.vocab)return Array.isArray(t.vocab)?new Ey(t,e.eos_token):Object.hasOwn(t,"continuing_subword_prefix")&&Object.hasOwn(t,"unk_token")?Object.hasOwn(t,"merges")?new Ay(t):new ky(t):new Wk(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 Hk=Vk,Kk=class extends Mr{constructor(t){super(),this.config=t}_call(t,...e){return this.post_process(t,...e)}},Sr=Kk,Xk=class extends Sr{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=st(n,t),o=st(o,new Array(t.length).fill(i.Sequence.type_id))):i.Sequence.id==="B"&&(n=st(n,e),o=st(o,new Array(e.length).fill(i.Sequence.type_id))));return{tokens:n,token_type_ids:o}}},Qk=Xk,Yk=class extends Sr{post_process(t,e=null){return{tokens:t,tokens_pair:e}}},Jk=Yk,Zk=class extends Sr{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e=null,s=!0){s&&(t=st([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=st(t,n,e,o),r=st(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},ev=Zk,tv=class extends Sr{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e,s=!0){s&&(t=st([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=st(t,n,e,o),r=st(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},sv=tv,rv=class extends Sr{constructor(t){super(t),this.processors=(t.processors??[]).map(e=>Cy(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}},nv=rv;function ov(t){if(t===null)return null;switch(t.type){case"TemplateProcessing":return new Qk(t);case"ByteLevel":return new Jk(t);case"BertProcessing":return new ev(t);case"RobertaProcessing":return new sv(t);case"Sequence":return new nv(t);default:throw new Error(`Unknown PostProcessor type: ${t.type}`)}}var Cy=ov,iv=class extends Mr{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("")}},Qe=iv,av=class extends Qe{constructor(t){super(t),this.byte_decoder=v1,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}},lv=av,cv=class extends Qe{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=Tc(e)),e})}},pv=cv,uv=class extends Qe{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}},_v=uv,dv=class extends Qe{constructor(t){super(t),this.suffix=t.suffix??""}decode_chain(t){return t.map((e,s)=>e.replaceAll(this.suffix,s===t.length-1?"":" "))}},fv=dv,mv=class extends Qe{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=Tc(r).replaceAll(this.word_delimiter_token," ").trim()),r}decode_chain(t){return[this.convert_tokens_to_string(t)]}},hv=mv,gv=class extends Qe{constructor(t){super(t),this.decoders=(t.decoders??[]).map(e=>Py(e))}decode_chain(t){return this.decoders.reduce((e,s)=>s.decode_chain(e),t)}},xv=gv,wv=class extends Qe{decode_chain(t){let e=Qi(this.config.pattern),s=this.config.content??"";return e===null?t:t.map(r=>r.replaceAll(e,s))}},yv=wv,bv=class extends Qe{decode_chain(t){return[t.join("")]}},kv=bv,vv=class extends Qe{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)})}},Ev=vv,Av=class extends Qe{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}},Mv=Av;function Sv(t){if(t===null)return null;switch(t.type){case"ByteLevel":return new lv(t);case"WordPiece":return new pv(t);case"Metaspace":return new _v(t);case"BPEDecoder":return new fv(t);case"CTC":return new hv(t);case"Sequence":return new xv(t);case"Replace":return new yv(t);case"Fuse":return new kv(t);case"Strip":return new Ev(t);case"ByteFallback":return new Mv(t);default:throw new Error(`Unknown Decoder type: ${t.type}`)}}var Py=Sv,Ov=class{constructor(t,e){let s=by(t,"Tokenizer",["model","decoder","post_processor","pre_tokenizer","normalizer"]);if(s)throw new Error(s);let r=by(e,"Config");if(r)throw new Error(r);this.tokenizer=t,this.config=e,this.normalizer=Oy(this.tokenizer.normalizer),this.pre_tokenizer=Iy(this.tokenizer.pre_tokenizer),this.model=Hk(this.tokenizer.model,this.config),this.post_processor=Cy(this.tokenizer.post_processor),this.decoder=Py(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 b1(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 wy(n),this.splitter_normalized=new wy(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||!O1(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=Tc(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=z1(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:st(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}},Ly=Ov;var A=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"}),Ye=class{constructor(t,e){this.value=t,this.type=e}};function Ny(t){return/\w/.test(t)}function Or(t){return/[0-9]/.test(t)}function Fy(t){return/\s/.test(t)}var Iv=[["{%",A.OpenStatement],["%}",A.CloseStatement],["{{",A.OpenExpression],["}}",A.CloseExpression],["(",A.OpenParen],[")",A.CloseParen],["{",A.OpenCurlyBracket],["}",A.CloseCurlyBracket],["[",A.OpenSquareBracket],["]",A.CloseSquareBracket],[",",A.Comma],[".",A.Dot],[":",A.Colon],["|",A.Pipe],["<=",A.ComparisonBinaryOperator],[">=",A.ComparisonBinaryOperator],["==",A.ComparisonBinaryOperator],["!=",A.ComparisonBinaryOperator],["<",A.ComparisonBinaryOperator],[">",A.ComparisonBinaryOperator],["+",A.AdditiveBinaryOperator],["-",A.AdditiveBinaryOperator],["~",A.AdditiveBinaryOperator],["*",A.MultiplicativeBinaryOperator],["/",A.MultiplicativeBinaryOperator],["%",A.MultiplicativeBinaryOperator],["=",A.Equals]],zv=new Map([["n",`
3
+ `],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function Tv(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 Cv(t,e={}){let s=[],r=Tv(t,e),n=0,o=0,i=c=>{let p="";for(;c(r[n]);){if(r[n]==="\\"){if(++n,n>=r.length)throw new SyntaxError("Unexpected end of input");let u=r[n++],_=zv.get(u);if(_===void 0)throw new SyntaxError(`Unexpected escaped character: ${u}`);p+=_;continue}if(p+=r[n++],n>=r.length)throw new SyntaxError("Unexpected end of input")}return p},a=()=>{let c=s.at(-1);c&&c.type===A.Text&&(c.value=c.value.trimEnd(),c.value===""&&s.pop())},l=()=>{for(;n<r.length&&Fy(r[n]);)++n};e:for(;n<r.length;){let c=s.at(-1)?.type;if(c===void 0||c===A.CloseStatement||c===A.CloseExpression||c===A.Comment){let u="";for(;n<r.length&&!(r[n]==="{"&&(r[n+1]==="%"||r[n+1]==="{"||r[n+1]==="#"));)u+=r[n++];if(u.length>0){s.push(new Ye(u,A.Text));continue}}if(r[n]==="{"&&r[n+1]==="#"){n+=2;let u=r[n]==="-";u&&++n;let _="";for(;r[n]!=="#"||r[n+1]!=="}";){if(n+2>=r.length)throw new SyntaxError("Missing end of comment tag");_+=r[n++]}let d=_.endsWith("-");d&&(_=_.slice(0,-1)),u&&a(),s.push(new Ye(_,A.Comment)),n+=2,d&&l();continue}if(r.slice(n,n+3)==="{%-"){a(),s.push(new Ye("{%",A.OpenStatement)),n+=3;continue}if(r.slice(n,n+3)==="{{-"){a(),s.push(new Ye("{{",A.OpenExpression)),o=0,n+=3;continue}if(i(Fy),r.slice(n,n+3)==="-%}"){s.push(new Ye("%}",A.CloseStatement)),n+=3,l();continue}if(r.slice(n,n+3)==="-}}"){s.push(new Ye("}}",A.CloseExpression)),n+=3,l();continue}let p=r[n];if(p==="-"||p==="+"){let u=s.at(-1)?.type;if(u===A.Text||u===void 0)throw new SyntaxError(`Unexpected character: ${p}`);switch(u){case A.Identifier:case A.NumericLiteral:case A.StringLiteral:case A.CloseParen:case A.CloseSquareBracket:break;default:{++n;let _=i(Or);s.push(new Ye(`${p}${_}`,_.length>0?A.NumericLiteral:A.UnaryOperator));continue}}}for(let[u,_]of Iv){if(u==="}}"&&o>0)continue;if(r.slice(n,n+u.length)===u){s.push(new Ye(u,_)),_===A.OpenExpression?o=0:_===A.OpenCurlyBracket?++o:_===A.CloseCurlyBracket&&--o,n+=u.length;continue e}}if(p==="'"||p==='"'){++n;let u=i(_=>_!==p);s.push(new Ye(u,A.StringLiteral)),++n;continue}if(Or(p)){let u=i(Or);if(r[n]==="."&&Or(r[n+1])){++n;let _=i(Or);u=`${u}.${_}`}s.push(new Ye(u,A.NumericLiteral));continue}if(Ny(p)){let u=i(Ny);s.push(new Ye(u,A.Identifier));continue}throw new SyntaxError(`Unexpected character: ${p}`)}return s}var ot=class{type="Statement"},Pv=class extends ot{constructor(t){super(),this.body=t}type="Program"},Lv=class extends ot{constructor(t,e,s){super(),this.test=t,this.body=e,this.alternate=s}type="If"},Nv=class extends ot{constructor(t,e,s,r){super(),this.loopvar=t,this.iterable=e,this.body=s,this.defaultBlock=r}type="For"},Fv=class extends ot{type="Break"},$v=class extends ot{type="Continue"},Rv=class extends ot{constructor(t,e,s){super(),this.assignee=t,this.value=e,this.body=s}type="Set"},Dv=class extends ot{constructor(t,e,s){super(),this.name=t,this.args=e,this.body=s}type="Macro"},jv=class extends ot{constructor(t){super(),this.value=t}type="Comment"},Ve=class extends ot{type="Expression"},Bv=class extends Ve{constructor(t,e,s){super(),this.object=t,this.property=e,this.computed=s}type="MemberExpression"},$y=class extends Ve{constructor(t,e){super(),this.callee=t,this.args=e}type="CallExpression"},Is=class extends Ve{constructor(t){super(),this.value=t}type="Identifier"},zs=class extends Ve{constructor(t){super(),this.value=t}type="Literal"},qv=class extends zs{type="IntegerLiteral"},Uv=class extends zs{type="FloatLiteral"},Ry=class extends zs{type="StringLiteral"},Gv=class extends zs{type="ArrayLiteral"},Dy=class extends zs{type="TupleLiteral"},Wv=class extends zs{type="ObjectLiteral"},Ir=class extends Ve{constructor(t,e,s){super(),this.operator=t,this.left=e,this.right=s}type="BinaryExpression"},Vv=class extends Ve{constructor(t,e){super(),this.operand=t,this.filter=e}type="FilterExpression"},Hv=class extends ot{constructor(t,e){super(),this.filter=t,this.body=e}type="FilterStatement"},Kv=class extends Ve{constructor(t,e){super(),this.lhs=t,this.test=e}type="SelectExpression"},Xv=class extends Ve{constructor(t,e,s){super(),this.operand=t,this.negate=e,this.test=s}type="TestExpression"},Qv=class extends Ve{constructor(t,e){super(),this.operator=t,this.argument=e}type="UnaryExpression"},Yv=class extends Ve{constructor(t=void 0,e=void 0,s=void 0){super(),this.start=t,this.stop=e,this.step=s}type="SliceExpression"},Jv=class extends Ve{constructor(t,e){super(),this.key=t,this.value=e}type="KeywordArgumentExpression"},Zv=class extends Ve{constructor(t){super(),this.argument=t}type="SpreadExpression"},eE=class extends ot{constructor(t,e,s){super(),this.call=t,this.callerArgs=e,this.body=s}type="CallStatement"},tE=class extends Ve{constructor(t,e,s){super(),this.condition=t,this.trueExpr=e,this.falseExpr=s}type="Ternary"};function sE(t){let e=new Pv([]),s=0;function r(M,S){let z=t[s++];if(!z||z.type!==M)throw new Error(`Parser Error: ${S}. ${z.type} !== ${M}.`);return z}function n(M){if(!l(M))throw new SyntaxError(`Expected ${M}`);++s}function o(){switch(t[s].type){case A.Comment:return new jv(t[s++].value);case A.Text:return c();case A.OpenStatement:return p();case A.OpenExpression:return u();default:throw new SyntaxError(`Unexpected token type: ${t[s].type}`)}}function i(...M){return s+M.length<=t.length&&M.every((S,z)=>S===t[s+z].type)}function a(...M){return t[s]?.type===A.OpenStatement&&t[s+1]?.type===A.Identifier&&M.includes(t[s+1]?.value)}function l(...M){return s+M.length<=t.length&&M.every((S,z)=>t[s+z].type==="Identifier"&&S===t[s+z].value)}function c(){return new Ry(r(A.Text,"Expected text token").value)}function p(){if(r(A.OpenStatement,"Expected opening statement token"),t[s].type!==A.Identifier)throw new SyntaxError(`Unknown statement, got ${t[s].type}`);let M=t[s].value,S;switch(M){case"set":++s,S=_();break;case"if":++s,S=d(),r(A.OpenStatement,"Expected {% token"),n("endif"),r(A.CloseStatement,"Expected %} token");break;case"macro":++s,S=m(),r(A.OpenStatement,"Expected {% token"),n("endmacro"),r(A.CloseStatement,"Expected %} token");break;case"for":++s,S=g(),r(A.OpenStatement,"Expected {% token"),n("endfor"),r(A.CloseStatement,"Expected %} token");break;case"call":{++s;let z=null;i(A.OpenParen)&&(z=C());let H=te();if(H.type!=="Identifier")throw new SyntaxError("Expected identifier following call statement");let he=C();r(A.CloseStatement,"Expected closing statement token");let se=[];for(;!a("endcall");)se.push(o());r(A.OpenStatement,"Expected '{%'"),n("endcall"),r(A.CloseStatement,"Expected closing statement token");let Ke=new $y(H,he);S=new eE(Ke,z,se);break}case"break":++s,r(A.CloseStatement,"Expected closing statement token"),S=new Fv;break;case"continue":++s,r(A.CloseStatement,"Expected closing statement token"),S=new $v;break;case"filter":{++s;let z=te();z instanceof Is&&i(A.OpenParen)&&(z=j(z)),r(A.CloseStatement,"Expected closing statement token");let H=[];for(;!a("endfilter");)H.push(o());r(A.OpenStatement,"Expected '{%'"),n("endfilter"),r(A.CloseStatement,"Expected '%}'"),S=new Hv(z,H);break}default:throw new SyntaxError(`Unknown statement type: ${M}`)}return S}function u(){r(A.OpenExpression,"Expected opening expression token");let M=x();return r(A.CloseExpression,"Expected closing expression token"),M}function _(){let M=h(),S=null,z=[];if(i(A.Equals))++s,S=h();else{for(r(A.CloseStatement,"Expected %} token");!a("endset");)z.push(o());r(A.OpenStatement,"Expected {% token"),n("endset")}return r(A.CloseStatement,"Expected closing statement token"),new Rv(M,S,z)}function d(){let M=x();r(A.CloseStatement,"Expected closing statement token");let S=[],z=[];for(;!a("elif","else","endif");)S.push(o());if(a("elif")){++s,++s;let H=d();z.push(H)}else if(a("else"))for(++s,++s,r(A.CloseStatement,"Expected closing statement token");!a("endif");)z.push(o());return new Lv(M,S,z)}function m(){let M=te();if(M.type!=="Identifier")throw new SyntaxError("Expected identifier following macro statement");let S=C();r(A.CloseStatement,"Expected closing statement token");let z=[];for(;!a("endmacro");)z.push(o());return new Dv(M,S,z)}function h(M=!1){let S=M?te:x,z=[S()],H=i(A.Comma);for(;H&&(++s,z.push(S()),!!i(A.Comma)););return H?new Dy(z):z[0]}function g(){let M=h(!0);if(!(M instanceof Is||M instanceof Dy))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${M.type} instead`);if(!l("in"))throw new SyntaxError("Expected `in` keyword following loop variable");++s;let S=x();r(A.CloseStatement,"Expected closing statement token");let z=[];for(;!a("endfor","else");)z.push(o());let H=[];if(a("else"))for(++s,++s,r(A.CloseStatement,"Expected closing statement token");!a("endfor");)H.push(o());return new Nv(M,S,z,H)}function x(){return w()}function w(){let M=y();if(l("if")){++s;let S=y();if(l("else")){++s;let z=w();return new tE(S,M,z)}else return new Kv(M,S)}return M}function y(){let M=b();for(;l("or");){let S=t[s];++s;let z=b();M=new Ir(S,M,z)}return M}function b(){let M=E();for(;l("and");){let S=t[s];++s;let z=E();M=new Ir(S,M,z)}return M}function E(){let M;for(;l("not");){let S=t[s];++s;let z=E();M=new Qv(S,z)}return M??k()}function k(){let M=O();for(;;){let S;if(l("not","in"))S=new Ye("not in",A.Identifier),s+=2;else if(l("in"))S=t[s++];else if(i(A.ComparisonBinaryOperator))S=t[s++];else break;let z=O();M=new Ir(S,M,z)}return M}function O(){let M=B();for(;i(A.AdditiveBinaryOperator);){let S=t[s];++s;let z=B();M=new Ir(S,M,z)}return M}function N(){let M=q(te());return i(A.OpenParen)?j(M):M}function j(M){let S=new $y(M,C());return S=q(S),i(A.OpenParen)&&(S=j(S)),S}function C(){r(A.OpenParen,"Expected opening parenthesis for arguments list");let M=R();return r(A.CloseParen,"Expected closing parenthesis for arguments list"),M}function R(){let M=[];for(;!i(A.CloseParen);){let S;if(t[s].type===A.MultiplicativeBinaryOperator&&t[s].value==="*"){++s;let z=x();S=new Zv(z)}else if(S=x(),i(A.Equals)){if(++s,!(S instanceof Is))throw new SyntaxError("Expected identifier for keyword argument");let z=x();S=new Jv(S,z)}M.push(S),i(A.Comma)&&++s}return M}function $(){let M=[],S=!1;for(;!i(A.CloseSquareBracket);)i(A.Colon)?(M.push(void 0),++s,S=!0):(M.push(x()),i(A.Colon)&&(++s,S=!0));if(M.length===0)throw new SyntaxError("Expected at least one argument for member/slice expression");if(S){if(M.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new Yv(...M)}return M[0]}function q(M){for(;i(A.Dot)||i(A.OpenSquareBracket);){let S=t[s];++s;let z,H=S.type===A.OpenSquareBracket;if(H)z=$(),r(A.CloseSquareBracket,"Expected closing square bracket");else if(z=te(),z.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");M=new Bv(M,z,H)}return M}function B(){let M=G();for(;i(A.MultiplicativeBinaryOperator);){let S=t[s++],z=G();M=new Ir(S,M,z)}return M}function G(){let M=Z();for(;l("is");){++s;let S=l("not");S&&++s;let z=te();if(!(z instanceof Is))throw new SyntaxError("Expected identifier for the test");M=new Xv(M,S,z)}return M}function Z(){let M=N();for(;i(A.Pipe);){++s;let S=te();if(!(S instanceof Is))throw new SyntaxError("Expected identifier for the filter");i(A.OpenParen)&&(S=j(S)),M=new Vv(M,S)}return M}function te(){let M=t[s++];switch(M.type){case A.NumericLiteral:{let S=M.value;return S.includes(".")?new Uv(Number(S)):new qv(Number(S))}case A.StringLiteral:{let S=M.value;for(;i(A.StringLiteral);)S+=t[s++].value;return new Ry(S)}case A.Identifier:return new Is(M.value);case A.OpenParen:{let S=h();return r(A.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),S}case A.OpenSquareBracket:{let S=[];for(;!i(A.CloseSquareBracket);)S.push(x()),i(A.Comma)&&++s;return++s,new Gv(S)}case A.OpenCurlyBracket:{let S=new Map;for(;!i(A.CloseCurlyBracket);){let z=x();r(A.Colon,"Expected colon between key and value in object literal");let H=x();S.set(z,H),i(A.Comma)&&++s}return++s,new Wv(S)}default:throw new SyntaxError(`Unexpected token: ${M.type}`)}}for(;s<t.length;)e.body.push(o());return e}function rE(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 jy(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 nE(t){return t.replace(/\b\w/g,e=>e.toUpperCase())}function oE(t){return iE(new Date,t)}function iE(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 aE(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function lE(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(aE(e),"gu");return t.replaceAll(o,i=>n>0?(--n,s):i)}var By=class extends Error{},qy=class extends Error{},pt=class{type="RuntimeValue";value;builtins=new Map;constructor(t=void 0){this.value=t}__bool__(){return new K(!!this.value)}toString(){return String(this.value)}},J=class extends pt{type="IntegerValue"},Ee=class extends pt{type="FloatValue";toString(){return this.value%1===0?this.value.toFixed(1):this.value.toString()}},D=class extends pt{type="StringValue";builtins=new Map([["upper",new xe(()=>new D(this.value.toUpperCase()))],["lower",new xe(()=>new D(this.value.toLowerCase()))],["strip",new xe(()=>new D(this.value.trim()))],["title",new xe(()=>new D(nE(this.value)))],["capitalize",new xe(()=>new D(this.value.charAt(0).toUpperCase()+this.value.slice(1)))],["length",new J(this.value.length)],["rstrip",new xe(()=>new D(this.value.trimEnd()))],["lstrip",new xe(()=>new D(this.value.trimStart()))],["startswith",new xe(t=>{if(t.length===0)throw new Error("startswith() requires at least one argument");let e=t[0];if(e instanceof D)return new K(this.value.startsWith(e.value));if(e instanceof ne){for(let s of e.value){if(!(s instanceof D))throw new Error("startswith() tuple elements must be strings");if(this.value.startsWith(s.value))return new K(!0)}return new K(!1)}throw new Error("startswith() argument must be a string or tuple of strings")})],["endswith",new xe(t=>{if(t.length===0)throw new Error("endswith() requires at least one argument");let e=t[0];if(e instanceof D)return new K(this.value.endsWith(e.value));if(e instanceof ne){for(let s of e.value){if(!(s instanceof D))throw new Error("endswith() tuple elements must be strings");if(this.value.endsWith(s.value))return new K(!0)}return new K(!1)}throw new Error("endswith() argument must be a string or tuple of strings")})],["split",new xe(t=>{let e=t[0]??new we;if(!(e instanceof D||e instanceof we))throw new Error("sep argument must be a string or null");let s=t[1]??new J(-1);if(!(s instanceof J))throw new Error("maxsplit argument must be a number");let r=[];if(e instanceof we){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 ne(r.map(n=>new D(n)))})],["replace",new xe(t=>{if(t.length<2)throw new Error("replace() requires at least two arguments");let e=t[0],s=t[1];if(!(e instanceof D&&s instanceof D))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 we:r=t[2]:r=new we,!(r instanceof J||r instanceof we))throw new Error("replace() count argument must be a number or null");return new D(lE(this.value,e.value,s.value,r.value))})]])},K=class extends pt{type="BooleanValue"},cE=/[\x7f-\uffff]/g;function Uy(t){return t.replace(cE,e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0"))}function Yt(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 p=JSON.stringify(t.value);return o&&(p=Uy(p)),p}case"ArrayValue":case"ObjectValue":{let p=n?" ".repeat(n):"",u=`
5
+ `+p.repeat(s),_=u+p;if(t.type==="ArrayValue"){let d=t.value.map(m=>Yt(m,e,s+1,r));return n?`[${_}${d.join(`${l}${_}`)}${u}]`:`[${d.join(l)}]`}else{let d=Array.from(t.value.entries());a&&(d=d.sort(([h],[g])=>h.localeCompare(g)));let m=d.map(([h,g])=>{let x=JSON.stringify(h);o&&(x=Uy(x));let w=`${x}${c}${Yt(g,e,s+1,r)}`;return n?`${_}${w}`:w});return n?`{${m.join(l)}${u}}`:`{${m.join(l)}}`}}default:throw new Error(`Cannot convert to JSON: ${t.type}`)}}var Te=class extends pt{type="ObjectValue";__bool__(){return new K(this.value.size>0)}builtins=new Map([["get",new xe(([t,e])=>{if(!(t instanceof D))throw new Error(`Object key must be a string: got ${t.type}`);return this.value.get(t.value)??e??new we})],["items",new xe(()=>this.items())],["keys",new xe(()=>this.keys())],["values",new xe(()=>this.values())],["dictsort",new xe(t=>{let e=new Map,s=t.filter(a=>a instanceof zr?(e=a.value,!1):!0),r=s.at(0)??e.get("case_sensitive")??new K(!1);if(!(r instanceof K))throw new Error("case_sensitive must be a boolean");let n=s.at(1)??e.get("by")??new D("key");if(!(n instanceof D))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 K(!1);if(!(o instanceof K))throw new Error("reverse must be a boolean");let i=Array.from(this.value.entries()).map(([a,l])=>new ne([new D(a),l])).sort((a,l)=>{let c=n.value==="key"?0:1,p=a.value[c],u=l.value[c],_=Pc(p,u,r.value);return o.value?-_:_});return new ne(i)})]]);items(){return new ne(Array.from(this.value.entries()).map(([t,e])=>new ne([new D(t),e])))}keys(){return new ne(Array.from(this.value.keys()).map(t=>new D(t)))}values(){return new ne(Array.from(this.value.values()))}toString(){return Yt(this,{},0,!1)}},zr=class extends Te{type="KeywordArgumentsValue"},ne=class extends pt{type="ArrayValue";builtins=new Map([["length",new J(this.value.length)]]);__bool__(){return new K(this.value.length>0)}toString(){return Yt(this,{},0,!1)}},Gy=class extends ne{type="TupleValue"},xe=class extends pt{type="FunctionValue"},we=class extends pt{type="NullValue"},ge=class extends pt{type="UndefinedValue"},Qt=class{constructor(t){this.parent=t}variables=new Map([["namespace",new xe(t=>{if(t.length===0)return new Te(new Map);if(t.length!==1||!(t[0]instanceof Te))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 xe],["odd",t=>{if(!(t instanceof J))throw new Error(`cannot odd on ${t.type}`);return t.value%2!==0}],["even",t=>{if(!(t instanceof J))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 J||t instanceof Ee],["integer",t=>t instanceof J],["iterable",t=>t.type==="ArrayValue"||t.type==="StringValue"],["mapping",t=>t instanceof Te],["sequence",t=>t instanceof ne||t instanceof Te||t instanceof D],["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,Zi(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 ge}catch{return new ge}}};function pE(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",rE),t.set("strftime_now",oE),t.set("True",!0),t.set("False",!1),t.set("None",null)}function Wy(t,e){let s=e.split("."),r=t;for(let n of s)if(r instanceof Te)r=r.value.get(n)??new ge;else if(r instanceof ne){let o=parseInt(n,10);if(!isNaN(o)&&o>=0&&o<r.value.length)r=r.value[o];else return new ge}else return new ge;return r}function Pc(t,e,s=!1){if(t instanceof we&&e instanceof we)return 0;if(t instanceof we||e instanceof we)throw new Error(`Cannot compare ${t.type} with ${e.type}`);if(t instanceof ge&&e instanceof ge)return 0;if(t instanceof ge||e instanceof ge)throw new Error(`Cannot compare ${t.type} with ${e.type}`);let r=o=>o instanceof J||o instanceof Ee||o instanceof K,n=o=>o instanceof K?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 uE=class{global;constructor(t){this.global=t??new Qt}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 K(s.value==r.value);case"!=":return new K(s.value!=r.value)}if(s instanceof ge||r instanceof ge){if(r instanceof ge&&["in","not in"].includes(t.operator.value))return new K(t.operator.value==="not in");throw new Error(`Cannot perform operation ${t.operator.value} on undefined values`)}else{if(s instanceof we||r instanceof we)throw new Error("Cannot perform operation on null values");if(t.operator.value==="~")return new D(s.value.toString()+r.value.toString());if((s instanceof J||s instanceof Ee)&&(r instanceof J||r instanceof Ee)){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 Ee||r instanceof Ee?new Ee(i):new J(i)}case"/":return new Ee(n/o);case"%":{let i=n%o;return s instanceof Ee||r instanceof Ee?new Ee(i):new J(i)}case"<":return new K(n<o);case">":return new K(n>o);case">=":return new K(n>=o);case"<=":return new K(n<=o)}}else if(s instanceof ne&&r instanceof ne){if(t.operator.value==="+")return new ne(s.value.concat(r.value))}else if(r instanceof ne){let n=r.value.find(o=>o.value===s.value)!==void 0;switch(t.operator.value){case"in":return new K(n);case"not in":return new K(!n)}}}if((s instanceof D||r instanceof D)&&t.operator.value==="+")return new D(s.value.toString()+r.value.toString());if(s instanceof D&&r instanceof D)switch(t.operator.value){case"in":return new K(r.value.includes(s.value));case"not in":return new K(!r.value.includes(s.value))}if(s instanceof D&&r instanceof Te)switch(t.operator.value){case"in":return new K(r.value.has(s.value));case"not in":return new K(!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 ne))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==="safe")return t;if(r.value==="tojson")return new D(Yt(t,{}));if(t instanceof ne)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 J(t.value.length);case"reverse":return new ne(t.value.slice().reverse());case"sort":return new ne(t.value.slice().sort((n,o)=>Pc(n,o,!1)));case"join":return new D(t.value.map(n=>n.value).join(""));case"string":return new D(Yt(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 ne(o)}default:throw new Error(`Unknown ArrayValue filter: ${r.value}`)}else if(t instanceof D)switch(r.value){case"length":case"upper":case"lower":case"title":case"capitalize":{let n=t.builtins.get(r.value);if(n instanceof xe)return n.value([],s);if(n instanceof J)return n;throw new Error(`Unknown StringValue filter: ${r.value}`)}case"trim":return new D(t.value.trim());case"indent":return new D(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 Z(isNaN(n)?0:n)}case"float":{let n=parseFloat(t.value);return new Ee(isNaN(n)?0:n)}default:throw new Error(`Unknown StringValue filter: ${r.value}`)}else if(t instanceof Z||t instanceof Ee)switch(r.value){case"abs":return t instanceof Z?new Z(Math.abs(t.value)):new Ee(Math.abs(t.value));case"int":return new Z(Math.floor(t.value));case"float":return new Ee(t.value);case"string":return new j(t.toString());default:throw new Error(`Unknown NumericValue filter: ${r.value}`)}else if(t instanceof Te)switch(r.value){case"items":return new ne(Array.from(t.value.entries()).map(([n,o])=>new ne([new j(n),o])));case"length":return new Z(t.value.size);default:{let n=t.builtins.get(r.value);if(n)return n instanceof ge?n.value([],s):n;throw new Error(`Unknown ObjectValue filter: ${r.value}`)}}else if(t instanceof K)switch(r.value){case"bool":return new K(t.value);case"int":return new Z(t.value?1:0);case"float":return new Ee(t.value?1:0);case"string":return new j(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 Z||i instanceof xe))throw new Error("If set, indent must be a number");let a=o.get("ensure_ascii")??new K(!1);if(!(a instanceof K))throw new Error("If set, ensure_ascii must be a boolean");let l=o.get("sort_keys")??new K(!1);if(!(l instanceof K))throw new Error("If set, sort_keys must be a boolean");let c=o.get("separators")??new xe,u=null;if(c instanceof ne||c instanceof wy){if(c.value.length!==2)throw new Error("separators must be a tuple of two strings");let[p,_]=c.value;if(!(p instanceof j)||!(_ instanceof j))throw new Error("separators must be a tuple of two strings");u=[p.value,_.value]}else if(!(c instanceof xe))throw new Error("If set, separators must be a tuple of two strings");return new j(as(t,{indent:i.value,ensureAscii:a.value,sortKeys:l.value,separators:u}))}else if(n==="join"){let o;if(t instanceof j)o=Array.from(t.value);else if(t instanceof ne)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 j("");if(!(l instanceof j))throw new Error("separator must be a string");return new j(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 Z(0):new Ee(0));if(t instanceof j){let l=n==="int"?parseInt(t.value,10):parseFloat(t.value);return isNaN(l)?a:n==="int"?new Z(l):new Ee(l)}else{if(t instanceof Z||t instanceof Ee)return t;if(t instanceof K)return n==="int"?new Z(t.value?1:0):new Ee(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 j(""),l=o[1]??i.get("boolean")??new K(!1);if(!(l instanceof K))throw new Error("`default` filter flag must be a boolean");return t instanceof he||l.value&&!t.__bool__().value?a:t}if(t instanceof ne){switch(n){case"sort":{let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("reverse")??new K(!1);if(!(a instanceof K))throw new Error("reverse must be a boolean");let l=o.at(1)??i.get("case_sensitive")??new K(!1);if(!(l instanceof K))throw new Error("case_sensitive must be a boolean");let c=o.at(2)??i.get("attribute")??new xe;if(!(c instanceof j||c instanceof Z||c instanceof xe))throw new Error("attribute must be a string, integer, or null");let u=p=>{if(c instanceof xe)return p;let _=c instanceof Z?String(c.value):c.value;return yy(p,_)};return new ne(t.value.slice().sort((p,_)=>{let d=u(p),m=u(_),h=zc(d,m,l.value);return a.value?-h:h}))}case"selectattr":case"rejectattr":{let o=n==="selectattr";if(t.value.some(p=>!(p instanceof Te)))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 _=p.value.get(i.value),d=_?c(_,l):!1;return o?d:!d});return new ne(u)}case"map":{let[,o]=this.evaluateArguments(r.args,s);if(o.has("attribute")){let i=o.get("attribute");if(!(i instanceof j))throw new Error("attribute must be a string");let a=o.get("default"),l=t.value.map(c=>{if(!(c instanceof Te))throw new Error("items in map must be an object");let u=yy(c,i.value);return u instanceof he?a??new he:u});return new ne(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 j){switch(n){case"indent":{let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("width")??new Z(4);if(!(a instanceof Z))throw new Error("width must be a number");let l=o.at(1)??i.get("first")??new K(!1),c=o.at(2)??i.get("blank")??new K(!1),u=t.value.split(`
8
- `),p=" ".repeat(a.value),_=u.map((d,m)=>!l.value&&m===0||!c.value&&d.length===0?d:p+d);return new j(_.join(`
9
- `))}case"replace":{let o=t.builtins.get("replace");if(!(o instanceof ge))throw new Error("replace filter not available");let[i,a]=this.evaluateArguments(r.args,s);return o.value([...i,new zr(a)],s)}}throw new Error(`Unknown StringValue filter: ${n}`)}else if(t instanceof Te){let o=t.builtins.get(n);if(o&&o instanceof ge){let[i,a]=this.evaluateArguments(r.args,s);return a.size>0&&i.push(new zr(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 K(t.negate?!n:n)}evaluateSelectExpression(t,e){return this.evaluate(t.test,e).__bool__().value?this.evaluate(t.lhs,e):new he}evaluateUnaryExpression(t,e){let s=this.evaluate(t.argument,e);if(t.operator.value==="not")return new K(!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 j(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 zr(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 ne||t instanceof j))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 Z||r instanceof he))throw new Error("Slice start must be numeric or undefined");if(!(n instanceof Z||n instanceof he))throw new Error("Slice stop must be numeric or undefined");if(!(o instanceof Z||o instanceof he))throw new Error("Slice step must be numeric or undefined");return t instanceof ne?new ne(my(t.value,r.value,n.value,o.value)):new j(my(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 j(t.property.value);let n;if(s instanceof Te){if(!(r instanceof j))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 ne||s instanceof j)if(r instanceof Z)n=s.value.at(r.value),s instanceof j&&(n=new j(s.value.at(r.value)));else if(r instanceof j)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 j))throw new Error(`Cannot access property with non-string: got ${r.type}`);n=s.builtins.get(r.value)}return n instanceof ft?n:new he}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 ne))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 Te))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 is(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 ne||n instanceof Te))throw new Error(`Expected iterable or object type in for loop: got ${n.type}`);n instanceof Te&&(n=n.keys());let o=[],i=[];for(let c=0;c<n.value.length;++c){let u=new is(s),p=n.value[c],_;if(t.loopvar.type==="Identifier")_=d=>d.setVariable(t.loopvar.value,p);else if(t.loopvar.type==="TupleLiteral"){let d=t.loopvar;if(p.type!=="ArrayValue")throw new Error(`Cannot unpack non-iterable type: ${p.type}`);let m=p;if(d.value.length!==m.value.length)throw new Error(`Too ${d.value.length>m.value.length?"few":"many"} items to unpack`);_=h=>{for(let g=0;g<d.value.length;++g){if(d.value[g].type!=="Identifier")throw new Error(`Cannot unpack non-identifier type: ${d.value[g].type}`);h.setVariable(d.value[g].value,m.value[g])}}}else throw new Error(`Invalid loop variable(s): ${t.loopvar.type}`);r&&(_(u),!this.evaluate(r,u).__bool__().value)||(o.push(p),i.push(_))}let a="",l=!0;for(let c=0;c<o.length;++c){let u=new Map([["index",new Z(c+1)],["index0",new Z(c)],["revindex",new Z(o.length-c)],["revindex0",new Z(o.length-c-1)],["first",new K(c===0)],["last",new K(c===o.length-1)],["length",new Z(o.length)],["previtem",c>0?o[c-1]:new he],["nextitem",c<o.length-1?o[c+1]:new he]]);s.setVariable("loop",new Te(u)),i[c](s);try{let p=this.evaluateBlock(t.body,s);a+=p.value}catch(p){if(p instanceof gy)continue;if(p instanceof hy)break;throw p}l=!1}if(l){let c=this.evaluateBlock(t.defaultBlock,s);a+=c.value}return new j(a)}evaluateMacro(t,e){return e.setVariable(t.name.value,new ge((s,r)=>{let n=new is(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 ge((a,l)=>{let c=new is(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 he)}return this.evaluateBlock(t.body,c)}),[r,n]=this.evaluateArguments(t.call.args,e);r.push(new zr(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 is(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 he;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 hy;case"Continue":throw new gy;case"IntegerLiteral":return new Z(t.value);case"FloatLiteral":return new Ee(t.value);case"StringLiteral":return new j(t.value);case"ArrayLiteral":return new ne(t.value.map(s=>this.evaluate(s,e)));case"TupleLiteral":return new wy(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 j))throw new Error(`Object keys must be strings: got ${o.type}`);s.set(o.value,this.evaluate(n,e))}return new Te(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 Ji(t){switch(typeof t){case"number":return Number.isInteger(t)?new Z(t):new Ee(t);case"string":return new j(t);case"boolean":return new K(t);case"undefined":return new he;case"object":return t===null?new xe:Array.isArray(t)?new ne(t.map(Ji)):new Te(new Map(Object.entries(t).map(([e,s])=>[e,Ji(s)])));case"function":return new ge((e,s)=>{let r=t(...e.map(n=>n.value))??null;return Ji(r)});default:throw new Error(`Cannot convert to runtime value: ${t}`)}}var Oe=`
10
- `,jv="{%- ",Bv=" -%}";function qv(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 Uv(t,e=" "){let s=typeof e=="number"?" ".repeat(e):e;return it(t.body,0,s).replace(/\n$/,"")}function Re(...t){return jv+t.join(" ")+Bv}function it(t,e,s){return t.map(r=>Gv(r,e,s)).join(Oe)}function Gv(t,e,s){let r=s.repeat(e);switch(t.type){case"Program":return it(t.body,e,s);case"If":return Wv(t,e,s);case"For":return Vv(t,e,s);case"Set":return Hv(t,e,s);case"Macro":return Kv(t,e,s);case"Break":return r+Re("break");case"Continue":return r+Re("continue");case"CallStatement":return Xv(t,e,s);case"FilterStatement":return Qv(t,e,s);case"Comment":return r+"{# "+t.value+" #}";default:return r+"{{- "+oe(t)+" -}}"}}function Wv(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+Re("if",oe(n[0].test))+Oe+it(n[0].body,e+1,s);for(let a=1;a<n.length;++a)i+=Oe+r+Re("elif",oe(n[a].test))+Oe+it(n[a].body,e+1,s);return o&&o.alternate.length>0&&(i+=Oe+r+Re("else")+Oe+it(o.alternate,e+1,s)),i+=Oe+r+Re("endif"),i}function Vv(t,e,s){let r=s.repeat(e),n="";if(t.iterable.type==="SelectExpression"){let i=t.iterable;n=`${oe(i.lhs)} if ${oe(i.test)}`}else n=oe(t.iterable);let o=r+Re("for",oe(t.loopvar),"in",n)+Oe+it(t.body,e+1,s);return t.defaultBlock.length>0&&(o+=Oe+r+Re("else")+Oe+it(t.defaultBlock,e+1,s)),o+=Oe+r+Re("endfor"),o}function Hv(t,e,s){let r=s.repeat(e),n=oe(t.assignee),o=t.value?oe(t.value):"",i=r+Re("set",`${n}${t.value?" = "+o:""}`);return t.body.length===0?i:i+Oe+it(t.body,e+1,s)+Oe+r+Re("endset")}function Kv(t,e,s){let r=s.repeat(e),n=t.args.map(oe).join(", ");return r+Re("macro",`${t.name.value}(${n})`)+Oe+it(t.body,e+1,s)+Oe+r+Re("endmacro")}function Xv(t,e,s){let r=s.repeat(e),n=t.callerArgs&&t.callerArgs.length>0?`(${t.callerArgs.map(oe).join(", ")})`:"",o=oe(t.call),i=r+Re(`call${n}`,o)+Oe;return i+=it(t.body,e+1,s)+Oe,i+=r+Re("endcall"),i}function Qv(t,e,s){let r=s.repeat(e),n=t.filter.type==="Identifier"?t.filter.value:oe(t.filter),o=r+Re("filter",n)+Oe;return o+=it(t.body,e+1,s)+Oe,o+=r+Re("endfilter"),o}function oe(t,e=-1){switch(t.type){case"SpreadExpression":return`*${oe(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=qv(s),n=oe(s.left,r),o=oe(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"?" ":"")+oe(s.argument,1/0)}case"CallExpression":{let s=t,r=s.args.map(oe).join(", ");return`${oe(s.callee)}(${r})`}case"MemberExpression":{let s=t,r=oe(s.object);["Identifier","MemberExpression","CallExpression","StringLiteral","IntegerLiteral","FloatLiteral","ArrayLiteral","TupleLiteral","ObjectLiteral"].includes(s.object.type)||(r=`(${r})`);let n=oe(s.property);return!s.computed&&s.property.type!=="Identifier"&&(n=`(${n})`),s.computed?`${r}[${n}]`:`${r}.${n}`}case"FilterExpression":{let s=t,r=oe(s.operand,1/0);return s.filter.type==="CallExpression"?`${r} | ${oe(s.filter)}`:`${r} | ${s.filter.value}`}case"SelectExpression":{let s=t;return`${oe(s.lhs)} if ${oe(s.test)}`}case"TestExpression":{let s=t;return`${oe(s.operand)} is${s.negate?" not":""} ${s.test.value}`}case"ArrayLiteral":case"TupleLiteral":{let s=t.value.map(oe),r=t.type==="ArrayLiteral"?"[]":"()";return`${r[0]}${s.join(", ")}${r[1]}`}case"ObjectLiteral":return`{${Array.from(t.value.entries()).map(([r,n])=>`${oe(r)}: ${oe(n)}`).join(", ")}}`;case"SliceExpression":{let s=t,r=s.start?oe(s.start):"",n=s.stop?oe(s.stop):"",o=s.step?`:${oe(s.step)}`:"";return`${r}:${n}${o}`}case"KeywordArgumentExpression":{let s=t;return`${s.key.value}=${oe(s.value)}`}case"Ternary":{let s=t,r=`${oe(s.trueExpr)} if ${oe(s.condition,0)} else ${oe(s.falseExpr)}`;return e>-1?`(${r})`:r}default:throw new Error(`Unknown expression type: ${t.type}`)}}var by=class{parsed;constructor(t){let e=iv(t,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=zv(e)}render(t){let e=new is;if(Rv(e),t)for(let[n,o]of Object.entries(t))e.set(n,o);return new Dv(e).run(this.parsed).value}format(t){return Uv(this.parsed,t?.indent||" ")}};var Me=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 Yv={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"},Pt=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",Yv[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())}};var Fs=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(V.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[ky(this._random_fn,s)]}};function ky(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 mt=new Fs,ls=Object.freeze({Random:Fs,seed:mt.seed.bind(mt),random:mt.random.bind(mt),gauss:mt.gauss.bind(mt),shuffle:mt.shuffle.bind(mt),choices:mt.choices.bind(mt)}),vy=t=>ky(ls.random,t);var Jv=new Fs,$s=class{constructor(e){this.path=e}async match(e){let s=Ke.join(this.path,e),r=new Pt(s);if(r.exists)return r}async put(e,s,r=void 0){let n=Ke.join(this.path,e),o=V.IS_PROCESS_AVAILABLE?process.pid:Date.now(),i=Jv._int32().toString(36),a=n+`.tmp.${o}.${i}`;try{let l=s.headers.get("Content-Length"),c=parseInt(l??"0"),u=0;await Fe.promises.mkdir(Ke.dirname(n),{recursive:!0});let p=Fe.createWriteStream(a),_=s.body.getReader();for(;;){let{done:d,value:m}=await _.read();if(d)break;await new Promise((g,x)=>{p.write(m,w=>{if(w){x(w);return}g()})}),u+=m.length;let h=c?u/c*100:0;r?.({progress:h,loaded:u,total:c})}await new Promise((d,m)=>{p.close(h=>h?m(h):d())}),await Fe.promises.rename(a,n)}catch(l){try{await Fe.promises.unlink(a)}catch{}throw l}}async delete(e){let s=Ke.join(this.path,e);try{return await Fe.promises.unlink(s),!0}catch{return!1}}};var Ey={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"},Zi=100,Ay=/^(\b[\w\-.]+\b\/)?\b[\w\-.]{1,96}\b$/;function Tr(...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 Lt(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 My(t){return!(!Ay.test(t)||t.includes("..")||t.includes("--")||t.endsWith(".git")||t.endsWith(".ipynb"))}function Sy(t,e,s){if(!s)return null;let r=Ey[t]??`Error (${t}) occurred while trying to load file`;throw Error(`${r}: "${e}".`)}async function Oy(t,e,s){let r=t.headers.get("Content-Length"),n=r?parseInt(r,10):s??0;r===null&&!s&&F.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 d=new Uint8Array(n);d.set(o),o=d}o.set(u,i),i=p;let _=i/n*100;return e({progress:_,loaded:i,total:n}),l()}return await l(),o}function Tc(t){return Lt(t,["blob:"])}function Cc(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}var zy="SHA-256",Zv="experimental_transformers-hash-cache",Iy=t=>({algorithm:zy,value:t}),Cr=class{#t=null;_getHashCache=()=>(this.#t??=caches.open(Zv),this.#t);static isAvailable=()=>typeof navigator<"u"&&"crossOriginStorage"in navigator;match=async e=>{let s=await this._getFileHash(e);if(s)try{let[r]=await navigator.crossOriginStorage.requestFileHandles([Iy(s)]),n=await r.getFile();return new Response(n,{headers:{"Content-Length":String(n.size)}})}catch{return}};put=async(e,s)=>{let r=await this._getFileHash(e);if(r){let n=await s.blob();await this._storeBlobInCOS(n,r)}else this._processAndStore(e,s.body)};_storeBlobInCOS=async(e,s)=>{let[r]=await navigator.crossOriginStorage.requestFileHandles([Iy(s)],{create:!0}),n=await r.createWritable();await n.write(e),await n.close()};_processAndStore=async(e,s)=>{try{let r=[];for await(let i of s)r.push(i);let n=new Blob(r),o=await this._getBlobHash(n);await this._storeBlobInCOS(n,o);try{await(await this._getHashCache()).put(e,new Response(o))}catch{}}catch{}};delete=async e=>{try{return await(await this._getHashCache()).delete(e)}catch{return!1}};_getFileHash=async e=>{try{let s=await this._getHashCache(),r=await s.match(e);if(r)return r.text();let n=await this._getLfsFileHash(e);return n?(await s.put(e,new Response(n)),n):null}catch{return null}};_getLfsFileHash=async e=>{if(!e.includes("/resolve/"))return null;let s=e.replace("/resolve/","/raw/");try{let n=(await fetch(s).then(o=>o.text())).match(/^oid sha256:([0-9a-f]+)$/m);return n?n[1]:null}catch{return null}};_getBlobHash=async e=>{let s=await e.arrayBuffer(),r=await crypto.subtle.digest(zy,s);return Array.from(new Uint8Array(r)).map(o=>o.toString(16).padStart(2,"0")).join("")}};async function lt(t=null){let e=null;if(J.useCustomCache){if(!J.customCache)throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");if(!J.customCache.match||!J.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=J.customCache}if(!e&&J.experimental_useCrossOriginStorage&&Cr.isAvailable()&&(e=new Cr),!e&&J.useBrowserCache){if(typeof caches>"u")throw Error("Browser cache is not available in this environment.");try{e=await caches.open(J.cacheKey)}catch(s){F.warn("An error occurred while opening the browser cache:",s)}}if(!e&&J.useFSCache){if(!V.IS_FS_AVAILABLE)throw Error("File System Cache is not available in this environment.");e=new $s(t??J.cacheDir)}return e}async function Ty(t,...e){for(let s of e)try{let r=await t.match(s);if(r)return r}catch{continue}}var ea=class{#t;#e;constructor(e){this.#t=e,this.#e=new Map}get(e){if(!this.#e.has(e))return;let s=this.#e.get(e);return this.#e.delete(e),this.#e.set(e,s),s}put(e,s){this.#e.has(e)&&this.#e.delete(e),this.#e.set(e,s),this.#e.size>this.#t&&this.#e.delete(this.#e.keys().next().value)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}};var eE=100,Pc=new ea(eE);function ta(t,e){let s=Pc.get(t);if(s!==void 0)return s;let r=e().then(n=>n,n=>(Pc.delete(t),Promise.reject(n)));return Pc.put(t,r),r}async function tE(t){if(!Lt(t,["http:","https:"]))return null;let e=Lc(t);return e.set("Range","bytes=0-0"),J.fetch(t,{method:"GET",headers:e,cache:"no-store"})}function ht(t,e,s={}){let r=JSON.stringify([t,e,s?.revision,s?.cache_dir,s?.local_files_only]);return ta(r,()=>sE(t,e,s))}async function sE(t,e,s){let r=await lt(s?.cache_dir),{localPath:n,remoteURL:o,proposedCacheKey:i,validModelId:a}=Ft(t,e,s,r),l=await $t(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(J.allowLocalModels&&!Lt(n,["http:","https:"]))try{let u=await Nt(n);if(typeof u!="string"&&u.status!==404){let p=u.headers.get("content-length"),_=u.headers.get("content-type");return{exists:!0,size:p?parseInt(p,10):void 0,contentType:_||void 0,fromCache:!1}}}catch{}if(J.allowRemoteModels&&!s.local_files_only&&a)try{let c=await tE(o);if(c&&c.status>=200&&c.status<300){let u,p=c.headers.get("content-type");if(c.status===206){let _=c.headers.get("content-range");if(_){let d=_.match(/bytes \d+-\d+\/(\d+)/);d&&(u=parseInt(d[1],10))}}else if(c.status===200)try{await c.body?.cancel()}catch{}if(u===void 0){let _=c.headers.get("content-length");u=_?parseInt(_,10):void 0}return{exists:!0,size:u,contentType:p||void 0,fromCache:!1}}}catch(c){F.warn(`Unable to fetch file metadata for "${o}": ${c}`)}return{exists:!1,fromCache:!1}}async function Nt(t){return J.useFS&&!Lt(t,["http:","https:","blob:"])?new Pt(t instanceof URL?t.protocol==="file:"?t.pathname:t.toString():t):J.fetch(t,{headers:Lc(t)})}function Lc(t){let e=typeof process<"u"&&process?.release?.name==="node",s=new Headers;if(e){let r=!!process.env?.TESTING_REMOTELY,n=J.version;if(s.set("User-Agent",`transformers.js/${n}; is_ci/${r};`),Lt(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 Ft(t,e,s={},r=null){let n=s.revision??"main",o=Tr(t,e),i=My(t),a=i?Tr(J.localModelPath,o):o,l=Tr(J.remoteHost,J.remotePathTemplate.replaceAll("{model}",t).replaceAll("{revision}",encodeURIComponent(n)),e),c=r instanceof $s?n==="main"?o:Tr(t,n,e):l;return{requestURL:o,localPath:a,remoteURL:l,proposedCacheKey:c,validModelId:i}}async function $t(t,e,s){if(t)return await Ty(t,e,s)}async function rE(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=>{F.warn(`Unable to add response to browser cache: ${a}.`)});else{let a=i.progress_callback?l=>vt(i.progress_callback,{status:"progress",name:t,file:e,...l}):void 0;await s.put(r,n,a)}}async function nE(t,e,s=!0,r={},n=!1,o=null){let{requestURL:i,localPath:a,remoteURL:l,proposedCacheKey:c,validModelId:u}=Ft(t,e,r,o),p,_=!1,d;d=await $t(o,a,c);let m=d!==void 0;if(!m){if(J.allowLocalModels)if(Lt(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(!J.allowRemoteModels)throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${i}.`)}else try{d=await Nt(a),p=a}catch(w){F.warn(`Unable to load from local path "${a}": "${w}"`)}if(d===void 0||typeof d!="string"&&d.status===404){if(r.local_files_only||!J.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(d=await Nt(l),d.status!==200)return Sy(d.status,l,s);p=c}_=o&&typeof Response<"u"&&d instanceof Response&&d.status===200}vt(r.progress_callback,{status:"download",name:t,file:e});let h;if(!(V.IS_NODE_ENV&&n)){let x;if(typeof d!="string")if(!r.progress_callback)x=new Uint8Array(await d.arrayBuffer());else if(m&&typeof navigator<"u"&&/firefox/i.test(navigator.userAgent))x=new Uint8Array(await d.arrayBuffer()),vt(r.progress_callback,{status:"progress",name:t,file:e,progress:100,loaded:x.length,total:x.length});else{let w,y=d.headers.get("content-length");if(y)w=parseInt(y,10);else try{let b=await ht(t,e,r);b.size&&(w=b.size)}catch{}x=await Oy(d,b=>{vt(r.progress_callback,{status:"progress",name:t,file:e,...b})},w)}h=x}if(_&&p&&typeof d!="string"&&await rE(t,e,o,p,d,h,r),vt(r.progress_callback,{status:"done",name:t,file:e}),h){if(!V.IS_NODE_ENV&&n)throw new Error("Cannot return path in a browser environment.");return h}if(d instanceof Pt)return d.filePath;let g=await o?.match(p);if(g instanceof Pt)return g.filePath;if(g instanceof Response)return new Uint8Array(await g.arrayBuffer());if(typeof g=="string")return g;throw new Error("Unable to get model file path or buffer.")}async function Pr(t,e,s=!0,r={},n=!1){if(!J.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(!J.allowRemoteModels)throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.")}vt(r.progress_callback,{status:"initiate",name:t,file:e});let o=await lt(r?.cache_dir);return await nE(t,e,s,r,n,o)}async function Nc(t,e,s=!0,r={}){let n=await Pr(t,e,s,r,!1);return n===null?null:new TextDecoder("utf-8").decode(n)}async function Ce(t,e,s=!0,r={}){let n=await Nc(t,e,s,r);return n===null?{}:JSON.parse(n)}function Py(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,_=n*o;for(let d=0;d<n;++d)for(let m=0;m<o;++m){let h=d*o+m,g=(m+.5)/l-.5,x=(d+.5)/c-.5,w=Math.floor(g),y=Math.floor(x),b=Math.min(w+1,r-1),M=Math.min(y+1,s-1);w=Math.max(w,0),y=Math.max(y,0);let k=g-w,O=x-y,N=(1-k)*(1-O),R=k*(1-O),C=(1-k)*O,D=k*O,$=y*r,q=M*r,B=$+w,G=$+b,ee=q+w,se=q+b;for(let v=0;v<e;++v){let E=v*p;u[v*_+h]=N*t[E+B]+R*t[E+G]+C*t[E+ee]+D*t[E+se]}}return u}function Ly(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 de(t){let e=ue(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 $c(t){let e=ue(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 Ny(t,e){let s=0;for(let r=0;r<t.length;++r)s+=t[r]*e[r];return s}function oE(t,e){let s=Ny(t,e),r=Cy(t),n=Cy(e);return s/(r*n)}function Cy(t){return Math.sqrt(t.reduce((e,s)=>e+s*s,0))}function Lr(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 ue(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 Fy(t){return t>0&&(t&t-1)===0}var sa=class{constructor(e){if(this.size=e|0,this.size<=1||!Fy(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 _=u[c];this._singleTransform2(s,e,l,_,i)}else for(l=0,c=0;l<n;l+=a,++c){let _=u[c];this._singleTransform4(s,e,l,_,i,r)}let p=this.table;for(i>>=2;i>=2;i>>=2){a=n/i<<1;let _=a>>>2;for(l=0;l<n;l+=a){let d=l+_-1;for(let m=l,h=0;m<d;m+=2,h+=i){let g=m,x=g+_,w=x+_,y=w+_,b=e[g],M=e[g+1],k=e[x],O=e[x+1],N=e[w],R=e[w+1],C=e[y],D=e[y+1],$=p[h],q=r*p[h+1],B=k*$-O*q,G=k*q+O*$,ee=p[2*h],se=r*p[2*h+1],v=N*ee-R*se,E=N*se+R*ee,I=p[3*h],H=r*p[3*h+1],be=C*I-D*H,Q=C*H+D*I,je=b+v,Ne=M+E,bt=b-v,ns=M-E,_t=B+be,st=G+Q,kt=r*(B-be),Tt=r*(G-Q);e[g]=je+_t,e[g+1]=Ne+st,e[x]=bt+Tt,e[x+1]=ns-kt,e[w]=je-_t,e[w+1]=Ne-st,e[y]=bt-Tt,e[y+1]=ns+kt}}}}_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],_=e[n+o+1],d=e[n+a],m=e[n+a+1],h=e[n+l],g=e[n+l+1],x=c+d,w=u+m,y=c-d,b=u-m,M=p+h,k=_+g,O=i*(p-h),N=i*(_-g);s[r]=x+M,s[r+1]=w+k,s[r+2]=y+N,s[r+3]=b-O,s[r+4]=x-M,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 d=u[c];this._singleRealTransform2(s,e,l,d>>>1,i>>>1)}else for(l=0,c=0;l<n;l+=a,++c){let d=u[c];this._singleRealTransform4(s,e,l,d>>>1,i>>>1,r)}let p=this.table;for(i>>=2;i>=2;i>>=2){a=n/i<<1;let d=a>>>1,m=d>>>1,h=m>>>1;for(l=0;l<n;l+=a)for(let g=0,x=0;g<=h;g+=2,x+=i){let w=l+g,y=w+m,b=y+m,M=b+m,k=e[w],O=e[w+1],N=e[y],R=e[y+1],C=e[b],D=e[b+1],$=e[M],q=e[M+1],B=k,G=O,ee=p[x],se=r*p[x+1],v=N*ee-R*se,E=N*se+R*ee,I=p[2*x],H=r*p[2*x+1],be=C*I-D*H,Q=C*H+D*I,je=p[3*x],Ne=r*p[3*x+1],bt=$*je-q*Ne,ns=$*Ne+q*je,_t=B+be,st=G+Q,kt=B-be,Tt=G-Q,os=v+bt,Ct=E+ns,qi=r*(v-bt),Ui=r*(E-ns);if(e[w]=_t+os,e[w+1]=st+Ct,e[y]=kt+Ui,e[y+1]=Tt-qi,g===0){e[b]=_t-os,e[b+1]=st-Ct;continue}if(g===h)continue;let Gi=l+m-g,dt=l+d-g;e[Gi]=kt-r*Ui,e[Gi+1]=-Tt-r*qi,e[dt]=_t-r*os,e[dt+1]=-st+r*Ct}}let _=n>>>1;for(let d=2;d<_;d+=2)e[n-d]=e[d],e[n-d+1]=-e[d+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],_=e[n+l],d=c+p,m=c-p,h=u+_,g=i*(u-_);s[r]=d+h,s[r+1]=0,s[r+2]=m,s[r+3]=-g,s[r+4]=d-h,s[r+5]=0,s[r+6]=m,s[r+7]=g}},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,_=Math.sqrt(l**2+c**2)**p,d=p*Math.atan2(c,l),m=2*u;o[m]=_*Math.cos(d),o[m+1]=_*Math.sin(d),i[m]=o[m],i[m+1]=-o[m+1]}this._slicedChirpBuffer=o.subarray(s,r),this._f=new sa(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 _=p+1,d=p>>1,m=s[d];n[p]=m*c[p],n[_]=m*c[_]}else for(let p=0;p<c.length;p+=2){let _=p+1;n[p]=s[p]*c[p]-s[_]*c[_],n[_]=s[p]*c[_]+s[_]*c[p]}this._f.transform(i,n);for(let p=0;p<l.length;p+=2){let _=p+1;o[p]=i[p]*l[p]-i[_]*l[_],o[_]=i[p]*l[_]+i[_]*l[p]}this._f.inverseTransform(a,o);for(let p=0;p<a.length;p+=2){let _=a[p+u],d=a[p+u+1],m=c[p],h=c[p+1];e[p]=_*m-d*h,e[p+1]=_*h+d*m}}transform(e,s){this._transform(e,s,!1)}realTransform(e,s){this._transform(e,s,!0)}},ra=class{constructor(e){this.fft_length=e,this.isPowerOfTwo=Fy(e),this.isPowerOfTwo?(this.fft=new sa(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 $y(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 cs(t,e){let s=Math.pow(10,e);return Math.round(t*s)/s}function Ry(t){let e=Math.round(t);return Math.abs(t)%1===.5?e%2===0?e:e-1:e}function Dy(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 _=n[p-1][u-1],d=n[p-1][u],m=n[p][u-1],h,g;_<d&&_<m?(h=_,g=0):d<_&&d<m?(h=d,g=1):(h=m,g=2),n[p][u]=t[p-1][u-1]+h,o[p][u]=g}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 jy=(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,_=l&1023;if(p===31)c=u|2139095040|_<<13;else if(p===0)if(_===0)c=u;else{let d=113;for(;(_&1024)===0;)_<<=1,--d;_&=-1025,c=u|d<<23|_<<13}else c=u|p+112<<23|_<<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 Rc={};Ts(Rc,{default:()=>iE});var iE={};import*as aE from"onnxruntime-web/webgpu";async function By(t){let e=t.split("/").pop(),s;try{if(s=await lt(),s){let n=await s.match(t);if(n)return n}}catch(n){F.warn(`Failed to load ${e} from cache:`,n)}let r=await J.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){F.warn(`Failed to cache ${e}:`,n)}return r}async function qy(t){let e=await By(t);if(!e||typeof e=="string")return null;try{return await e.arrayBuffer()}catch(s){return F.warn("Failed to read WASM binary:",s),null}}async function Uy(t){if(V.IS_SERVICE_WORKER_ENV||V.IS_CHROME_AVAILABLE)return t;let e=await By(t);if(!e||typeof e=="string")return null;try{let s=await e.text();s=s.replaceAll("globalThis.process?.versions?.node","false");let r=new Blob([s],{type:"text/javascript"});return URL.createObjectURL(r)}catch(s){return F.warn("Failed to read WASM factory:",s),null}}import{Tensor as Xy}from"onnxruntime-common";var lE=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 Hy(t){return t<=Ue.DEBUG?0:t<=Ue.INFO?2:t<=Ue.WARNING||t<=Ue.ERROR?3:4}var cE={0:"verbose",1:"info",2:"warning",3:"error",4:"fatal"},Ye=[],Dc,Ds,Gy=Symbol.for("onnxruntime");if(Gy in globalThis)Ds=globalThis[Gy];else if(V.IS_NODE_ENV){switch(Ds=Rc,process.platform){case"win32":Ye.push("dml");break;case"linux":process.arch==="x64"&&Ye.push("cuda");break;case"darwin":Ye.push("coreml");break}Ye.push("webgpu"),Ye.push("cpu"),Dc=["cpu"]}else Ds=aE,V.IS_WEBNN_AVAILABLE&&Ye.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),V.IS_WEBGPU_AVAILABLE&&Ye.push("webgpu"),Ye.push("wasm"),Dc=["wasm"];var uE=Ds.InferenceSession;function Ky(t=null){if(!t)return Dc;switch(t){case"auto":return Ye;case"gpu":return Ye.filter(e=>["webgpu","cuda","dml","webnn-gpu"].includes(e))}if(Ye.includes(t))return[lE[t]??t];throw new Error(`Unsupported device: "${t}". Should be one of: ${Ye.join(", ")}.`)}var Wy=Promise.resolve(),Rs=null;async function pE(){if(Rs)return Rs;if(!(J.useWasmCache&&typeof Ie?.wasm?.wasmPaths=="object"&&Ie?.wasm?.wasmPaths?.wasm&&Ie?.wasm?.wasmPaths?.mjs)){if(V.IS_DENO_WEB_RUNTIME)throw new Error("env.useWasmCache=false is not supported in Deno's web runtime. Remove the useWasmCache override.");return Rs=Promise.resolve(),Rs}return Rs=(async()=>{let e=Ie.wasm.wasmPaths,s=!1;await Promise.all([e.wasm&&!Tc(e.wasm)?(async()=>{try{let r=await qy(Cc(e.wasm));r&&(Ie.wasm.wasmBinary=r,s=!0)}catch(r){F.warn("Failed to pre-load WASM binary:",r)}})():Promise.resolve(),e.mjs&&!Tc(e.mjs)?(async()=>{try{let r=await Uy(Cc(e.mjs));r&&(Ie.wasm.wasmPaths.mjs=r)}catch(r){F.warn("Failed to pre-load WASM factory:",r)}})():Promise.resolve()]),s||(Ie.wasm.wasmPaths.mjs=e.mjs)})(),Rs}async function na(t,e,s){await pE();let r=Hy(J.logLevel??Ue.WARNING),n=()=>uE.create(t,{logSeverityLevel:r,...e}),o=await(V.IS_WEB_ENV?Wy=Wy.then(n):n());return o.config=s,o}var Vy=Promise.resolve();async function oa(t,e){let s=()=>t.run(e);return V.IS_WEB_ENV?Vy=Vy.then(s):s()}function ia(t){return t instanceof Ds.Tensor}var Ie=Ds?.env;function Nr(){return Ie?.wasm?.proxy}if(Ie){let t=function(e){let s=Hy(e);Ie.logLevel=cE[s]};if(Ie.wasm){if(!(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope)&&Ie.versions?.web&&!Ie.wasm.wasmPaths){let e=`https://cdn.jsdelivr.net/npm/onnxruntime-web@${Ie.versions.web}/dist/`;Ie.wasm.wasmPaths=V.IS_SAFARI?{mjs:`${e}ort-wasm-simd-threaded.mjs`,wasm:`${e}ort-wasm-simd-threaded.wasm`}:{mjs:`${e}ort-wasm-simd-threaded.asyncify.mjs`,wasm:`${e}ort-wasm-simd-threaded.asyncify.wasm`}}Ie.wasm.proxy=!1}Ie.webgpu&&(Ie.webgpu.powerPreference="high-performance"),t(J.logLevel??Ue.WARNING),J.backends.onnx={...Ie,setLogLevel:t}}var Rt=async(t,e,s)=>{let r=await na(new Uint8Array(t),e);return(async n=>{let o=Nr(),i=Object.fromEntries(Object.entries(n).map(([l,c])=>[l,(o?c.clone():c).ort_tensor])),a=await oa(r,i);return Array.isArray(s)?s.map(l=>new A(a[l])):new A(a[s])})},gt=class{static session_options={};static get nearest_interpolate_4d(){return this._nearest_interpolate_4d||(this._nearest_interpolate_4d=Rt([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=Rt([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=Rt([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=Rt([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=Rt([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=Rt([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=Rt([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=Rt([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 Qy=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"}),jc=V.IS_NODE_ENV?"cpu":"wasm";function aa(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 (${jc}).`),jc):jc}var Zy=(function(){let t;return async function(){if(t===void 0)if(!V.IS_WEBGPU_AVAILABLE)t=!1;else try{t=(await navigator.gpu.requestAdapter()).features.has("shader-f16")}catch{t=!1}return t}})(),De=Object.freeze({auto:"auto",fp32:"fp32",fp16:"fp16",q8:"q8",int8:"int8",uint8:"uint8",q4:"q4",bnb4:"bnb4",q4f16:"q4f16"}),Yy=De.fp32,Jy=Object.freeze({[Qy.wasm]:De.q8}),Fr=Object.freeze({[De.fp32]:"",[De.fp16]:"_fp16",[De.int8]:"_int8",[De.uint8]:"_uint8",[De.q8]:"_quantized",[De.q4]:"_q4",[De.q4f16]:"_q4f16",[De.bnb4]:"_bnb4"});function la(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===De.auto){if(r){let l=typeof r=="string"?r:r?.[e];if(l&&l!==De.auto&&De.hasOwnProperty(l))return l}a=Jy[s]??Yy}else o&&De.hasOwnProperty(o)?a=o:a=Jy[s]??Yy;return i&&n&&n(`dtype not specified for "${e}". Using the default dtype (${a}) for this device (${s}).`),a}var At=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 A=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 ia(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new Xy(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 _E(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(_=_===null?0:xt(_,this.dims[u],u,!1),d=d===null?this.dims[u]:xt(d,this.dims[u],u,!1),_>d)throw new Error(`Invalid slice: ${p}`);let m=[Math.max(_,0),Math.min(d,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 _=i.slice(u,p);for(let d=0;d<_.length;++d)a[d]=_[d]}else throw new Error("Unsupported data type for slicing")}else for(let u=0;u<o;++u){let p=0;for(let _=n.length-1,d=u;_>=0;--_){let m=n[_];p+=(d%m+r[_][0])*l[_],d=Math.floor(d/m)}a[u]=i[p]}return new t(this.type,a,s)}permute(...e){return dE(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=n instanceof BigInt64Array||n instanceof BigUint64Array;if(o&&e!==1)throw Error(`Expected a floating point tensor as input. Got ${this.type}`);let i,a;if(o?(i=(p,_)=>p+_,a=0n):(i=(p,_)=>p+_**e,a=0),s===null){let p=n.reduce(i,a);return e!==1&&(p=p**(1/e)),new t(this.type,[p],[])}let[l,c,u]=$r(i,this,s,r);if(e!==1)for(let p=0;p<c.length;++p)c[p]=c[p]**(1/e);return new t(l,c,u)}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 _=c%p;a+=_*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,e0(this.dims,e))}squeeze_(e=null){return this.dims=e0(this.dims,e),this}unsqueeze(e){return new t(this.type,this.data,t0(this.dims,e))}unsqueeze_(e){return this.dims=t0(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 pa(this,e,s)}min(e=null,s=!1){if(e===null){let i=Lr(this.data)[0];return new t(this.type,[i],[])}let[r,n,o]=$r((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=ue(this.data)[0];return new t(this.type,[i],[])}let[r,n,o]=$r((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=Lr(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=ue(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,_=0;for(let d=0;d<n.length;++d){let m=Math.floor(p/c[d]);p=p%c[d];let h=m%r[d];_+=h*l[d]}a[u]=i[_]}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(!At.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,jy(this.data),this.dims);return new t(e,At[e].from(this.data,s),this.dims)}};function _E(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 dE(t,e){let[s,r]=Ly(t.data,t.dims,e);return new A(t.type,s,r)}function qc(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=Py(t.data,[o,i,a],[e,s],r,n);return new A(t.type,l,[o,e,s])}async function Be(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 gt.nearest_interpolate_4d;else if(s==="bilinear")n=await gt.bilinear_interpolate_4d;else if(s==="bicubic")n=await gt.bicubic_interpolate_4d;else throw new Error(`Unsupported mode: ${s}`);let o=new A("int64",new BigInt64Array(r.map(BigInt)),[r.length]);return await n({x:t,s:o})}async function s0(t,e){return await(await gt.matmul)({a:t,b:e})}async function KO(t,e){return await(await gt.rfft)({x:t,a:e})}async function ct(t,e){let s=await gt.top_k;return e==null?e=t.dims.at(-1):e=Math.min(e,t.dims.at(-1)),await s({x:t,k:new A("int64",[BigInt(e)],[1])})}var ca=t=>new A("int64",t,[t.length]);async function ua(t,e,s,r,n){return await(await gt.slice)({x:t,s:ca(e),e:ca(s),a:ca(r),t:ca(n??new Array(r.length).fill(1))})}function r0(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 _=0;_<l;++_){let d=0,m=0,h=u*a,g=p+_;for(let w=0;w<a;++w){let y=Number(r[h+w]);m+=y,d+=s[g+w*l]*y}let x=d/m;o[c++]=x}}return new A(t.type,o,n)}function XO(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]=Uc(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 _=p*n;for(let d=0;d<n;++d){let m=_+d;u[m]=(c[m]-l[p])/(a[p]+s)}}return new A(t.type,u,t.dims)}function e0(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 t0(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 _=c.length-1,d=u,m=1;_>=0;--_){let h=c[_],g=d%h;_===e&&(g+=i),p+=g*m,m*=s[_],d=Math.floor(d/h)}n[p]=l[u]}i+=c[e]}}return new A(o,n,s)}function Ge(t,e=0){return ie(t.map(s=>s.unsqueeze(e)),e)}function $r(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,_=c,d=1;p>=0;--p){let m=i[p];if(p!==s){let h=_%m;u+=h*d,d*=a[p]}_=Math.floor(_/m)}l[u]=t(l[u],o[c],c,u)}return r||a.splice(s,1),[e.type,l,a]}function Uc(t,e=null,s=1,r=!1){let n=t.data,o=t.dims;if(e===null){let d=n.reduce((x,w)=>x+w,0)/n.length,m=Math.sqrt(n.reduce((x,w)=>x+(w-d)**2,0)/(n.length-s)),h=new A(t.type,[d],[]);return[new A(t.type,[m],[]),h]}e=xt(e,o.length);let i=pa(t,e,r),a=i.data,[l,c,u]=$r((_,d,m,h)=>_+(d-a[h])**2,t,e,r);for(let _=0;_<c.length;++_)c[_]=Math.sqrt(c[_]/(o[e]-s));return[new A(l,c,u),i]}function pa(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 A(t.type,[l/n.length],[])}e=xt(e,r.length);let[o,i,a]=$r((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 A(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 Gc(t,e,s,r){let n=t.reduce((o,i)=>o*i,1);return new A(s,new r(n).fill(e),t)}function we(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 Gc(t,e,s,r)}function Rr(t,e){return we(t.dims,e)}function Se(t){return Gc(t,1n,"int64",BigInt64Array)}function _a(t){return Se(t.dims)}function Wc(t){return Gc(t,0n,"int64",BigInt64Array)}function Vc(t){return Wc(t.dims)}function QO(t){let e=t.reduce((s,r)=>s*r,1);return new A("float32",Float32Array.from({length:e},()=>ls.random()),t)}function n0(t){let e=t.reduce((s,r)=>s*r,1);return new A("float32",Float32Array.from({length:e},()=>ls.gauss()),t)}function o0(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 A(r,i,[t.dims[0],t.dims[1]/8])}async function js(t){if(!t)throw new Error("modelId is required for get_tokenizer_files");return(await ht(t,"tokenizer_config.json",{})).exists?["tokenizer.json","tokenizer_config.json"]:[]}async function Hc(t,e){let s=await js(t);return await Promise.all(s.map(r=>Ce(t,r,!0,e)))}function Kc(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 fE=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function mE(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"?$e(t[n],a):$e(a,t[n])}}function hE(t,e){for(let s of Object.keys(t))t[s].length=e}function us(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 gE(t){let e=[];for(let s of t.get_added_tokens_decoder().values())s.special&&e.push(s);return e}var T=class extends Me{return_token_type_ids=!1;padding_side="right";constructor(e,s){if(super(),this._tokenizerJSON=e,this._tokenizerConfig=s,this._tokenizer=new cy(e,s),this.config=s,this.padding_side=s.padding_side??this.padding_side,this.mask_token=us(s,"mask_token"),this.mask_token_id=this._tokenizer.token_to_id(this.mask_token),this.pad_token=us(s,"pad_token","eos_token"),this.pad_token_id=this._tokenizer.token_to_id(this.pad_token),this.sep_token=us(s,"sep_token"),this.sep_token_id=this._tokenizer.token_to_id(this.sep_token),this.unk_token=us(s,"unk_token"),this.unk_token_id=this._tokenizer.token_to_id(this.unk_token),this.bos_token=us(s,"bos_token"),this.bos_token_id=this._tokenizer.token_to_id(this.bos_token),this.eos_token=us(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=gE(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 Hc(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(_,{text_pair:s[d],add_special_tokens:r,return_token_type_ids:l}))}else u=e.map(_=>this._encode_plus(_,{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?(F.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&&(F.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(ue(u.map(_=>_.input_ids.length))[0],i??1/0)),i=Math.min(i,this.model_max_length??1/0),n||o)for(let _=0;_<u.length;++_)u[_].input_ids.length!==i&&(u[_].input_ids.length>i?o&&hE(u[_],i):n&&mE(u[_],i,d=>d==="input_ids"?this.pad_token_id:0,this.padding_side));let p={};if(a){if(!(n&&o)&&u.some(d=>{for(let m of Object.keys(d))if(d[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 _=[u.length,u[0].input_ids.length];for(let d of Object.keys(u[0]))p[d]=new A("int64",BigInt64Array.from(u.flatMap(m=>m[d]).map(BigInt)),_)}else{for(let _ of Object.keys(u[0]))p[_]=u.map(d=>d[_]);if(!c)for(let _ of Object.keys(p))p[_]=p[_][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 A&&(e=e.tolist()),e.map(r=>this.decode(r,s))}decode(e,s={}){if(e instanceof A&&(e=Kc(e)),!Array.isArray(e)||e.length===0||!Ww(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 by(n),this._compiled_template_cache.set(n,m));let h=Object.create(null);for(let x of fE){let w=us(this.config,x);w&&(h[x]=w)}let g=m.render({messages:e,add_generation_prompt:o,tools:s,documents:r,...h,...d});if(i){let x=this._call(g,{add_special_tokens:!1,padding:a,truncation:l,max_length:c,return_tensor:u,..._});return p?x:x.input_ids}return g}};function Bs(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 Du={};Ts(Du,{AlbertTokenizer:()=>Xc,AutoTokenizer:()=>W,BartTokenizer:()=>Qc,BertTokenizer:()=>Yc,BlenderbotSmallTokenizer:()=>Jc,BlenderbotTokenizer:()=>Zc,BloomTokenizer:()=>eu,CLIPTokenizer:()=>su,CamembertTokenizer:()=>tu,CodeGenTokenizer:()=>nu,CodeLlamaTokenizer:()=>ru,CohereTokenizer:()=>ou,ConvBertTokenizer:()=>iu,DebertaTokenizer:()=>lu,DebertaV2Tokenizer:()=>au,DistilBertTokenizer:()=>cu,ElectraTokenizer:()=>uu,EsmTokenizer:()=>pu,FalconTokenizer:()=>_u,GPT2Tokenizer:()=>mu,GPTNeoXTokenizer:()=>fu,GemmaTokenizer:()=>du,HerbertTokenizer:()=>hu,LlamaTokenizer:()=>gu,M2M100Tokenizer:()=>xu,MBart50Tokenizer:()=>yu,MBartTokenizer:()=>Dr,MPNetTokenizer:()=>vu,MarianTokenizer:()=>wu,MgpstrTokenizer:()=>bu,MobileBertTokenizer:()=>ku,NllbTokenizer:()=>Eu,NougatTokenizer:()=>Au,PreTrainedTokenizer:()=>T,Qwen2Tokenizer:()=>Mu,RoFormerTokenizer:()=>Ou,RobertaTokenizer:()=>Su,SiglipTokenizer:()=>Iu,SpeechT5Tokenizer:()=>zu,SqueezeBertTokenizer:()=>Tu,T5Tokenizer:()=>Cu,TokenizersBackend:()=>T,VitsTokenizer:()=>Lu,Wav2Vec2CTCTokenizer:()=>Nu,WhisperTokenizer:()=>Fu,XLMRobertaTokenizer:()=>$u,XLMTokenizer:()=>Ru});var Xc=class extends T{return_token_type_ids=!0};var Qc=class extends T{};var Yc=class extends T{return_token_type_ids=!0};var Jc=class extends T{};var Zc=class extends T{};var eu=class extends T{};var tu=class extends T{};var su=class extends T{};var ru=class extends T{};var nu=class extends T{};var ou=class extends T{};var iu=class extends T{return_token_type_ids=!0};var au=class extends T{return_token_type_ids=!0};var lu=class extends T{return_token_type_ids=!0};var cu=class extends T{};var uu=class extends T{return_token_type_ids=!0};var pu=class extends T{};var _u=class extends T{};var du=class extends T{};var fu=class extends T{};var mu=class extends T{};var hu=class extends T{return_token_type_ids=!0};var gu=class extends T{padding_side="left"};var xu=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 Bs(this,e,s,r)}};var wu=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)),F.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)||F.warn(`Unsupported language code "${n}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),$e([n],super._encode_text(o))}}};var Dr=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 Bs(this,e,s,r)}};var yu=class extends Dr{};var bu=class extends T{};var ku=class extends T{return_token_type_ids=!0};var vu=class extends T{};var Eu=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 Bs(this,e,s,r)}};var Au=class extends T{};var Mu=class extends T{};var Su=class extends T{};var Ou=class extends T{return_token_type_ids=!0};var Iu=class extends T{};var zu=class extends T{};var Tu=class extends T{return_token_type_ids=!0};var Cu=class extends T{};var Pu=class extends Xe{decode_chain(e){let s="";for(let r=1;r<e.length;r+=2)s+=e[r];return[s]}},Lu=class extends T{constructor(e,s){super(e,s),this._tokenizer.decoder=new Pu({type:"VitsDecoder"})}};var Nu=class extends T{};var i0=[["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"]],jr=new Map(i0),xE=new Map([...i0.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 a0(t){t=t.toLowerCase();let e=xE.get(t);if(e===void 0){let s=t.match(/^<\|([a-z]{2})\|>$/);if(s&&(t=s[1]),jr.has(t))e=t;else{let n=t.length===2?jr.keys():jr.values();throw new Error(`Language "${t}" is not supported. Must be one of: ${JSON.stringify(Array.from(n))}`)}}return e}var wE="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",l0=new RegExp(`^[${wE}]+$`,"gu"),Fu=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,_=this.timestamp_begin,m=_+1500,h=[],g=[],x=!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,R=null,C=_;if("stride"in k){let[q,B,G]=k.stride;if(p-=B,w=q-G,B&&(C=B/n+_),G)for(let ee=O.length-1;ee>=0;--ee){let se=Number(O[ee]);if(se>=_){if(R!==null&&(se-_)*n<w)break;R=se}}}let D=[],$=[];for(let q=0;q<O.length;++q){let B=Number(O[q]);if(y.has(B)){let G=this.decode([B]),ee=jr.get(G.slice(2,-2));if(ee!==void 0){if(i!==null&&ee!==i&&!s){h.push(D);let se=this.findLongestCommonSequence(h)[0],v=this.decode(se);u.text=v,c.push(u),h=[],D=[],u=l()}i=u.language=ee}}else if(B>=_&&B<=m){let G=(B-_)*n+p,ee=cs(G,2);if(R!==null&&B>=R)x=!0;else if(x||h.length>0&&B<C)x=!1;else if(u.timestamp[0]===null)u.timestamp[0]=ee;else if(ee!==u.timestamp[0]){u.timestamp[1]=ee,h.push(D),a&&g.push($);let[se,v]=this.findLongestCommonSequence(h,g),E=this.decode(se);u.text=E,a&&(u.words=this.collateWordTimestamps(se,v,i)),c.push(u),h=[],D=[],g=[],$=[],u=l()}}else if(D.push(B),a){let G=cs(N[q]+p,2),ee;if(q+1<N.length){ee=cs(N[q+1]+p,2);let se=this.decode([B]);l0.test(se)&&(ee=cs(Math.min(G+n,ee),2))}else ee=null;$.push([G,ee])}}if("stride"in k){let[q,B,G]=k.stride;p+=q-G}D.length>0?(h.push(D),a&&g.push($)):h.every(q=>q.length===0)&&(u=l(),h=[],D=[],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[k,O]=this.findLongestCommonSequence(h,g),N=this.decode(k);u.text=N,a&&(u.words=this.collateWordTimestamps(k,O,i)),c.push(u)}let b=Object.create(null),M=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[M,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,_=[n,n,0,0],d=u.length;for(let b=1;b<n+d;++b){let M=Math.max(0,n-b),k=Math.min(n,n+d-b),O=r.slice(M,k),N=Math.max(0,b-n),R=Math.min(d,b),C=u.slice(N,R);if(O.length!==C.length)throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let D;i?D=O.filter((B,G)=>B===C[G]&&l[M+G]<=s[c][N+G]).length:D=O.filter((B,G)=>B===C[G]).length;let $=b/1e4,q=D/b+$;D>1&&q>p&&(p=q,_=[M,k,N,R])}let[m,h,g,x]=_,w=Math.floor((h+m)/2),y=Math.floor((x+g)/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 A&&(e=Kc(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 _=this.decode(a,{decode_with_timestamps:!0});(!_.includes(r)||s[c+_.indexOf(r)]===r)&&(n.push(_),o.push(a),i.push(l),a=[],l=[],c+=_.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],_=u[0]>=this._tokenizer.token_to_id("<|endoftext|>"),d=c.startsWith(" "),m=c.trim(),h=l0.test(m);if(_||d||h||o.length===0)o.push(c),i.push(u),a.push(p);else{let g=o.length-1;o[g]+=c,i[g].push(...u),a[g].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]=$e(a[c],a[u]),l[u]=$e(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]=$e(a[c],a[u]),l[c]=$e(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 $u=class extends T{};var Ru=class extends T{return_token_type_ids=!0;constructor(e,s){super(e,s),F.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}};var W=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 Hc(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i}),c=l.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer",u=Du[c];return u||(F.warn(`Unknown tokenizer class "${c}", attempting to construct from base class.`),u=T),new u(a,l)}};var Dt="https://github.com/huggingface/transformers.js/issues/new/choose";var Br="preprocessor_config.json",Mt=Br,c0="processor_config.json",u0="chat_template.jinja";var U=class extends Me{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?Ce(e,c0,!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?Nc(e,u0,!0,s):null]);return new this(r,n,o)}};var Da={};Ts(Da,{ChatterboxProcessor:()=>sp,Florence2Processor:()=>Hp,Gemma3nProcessor:()=>Kp,GraniteSpeechProcessor:()=>Xp,GroundingDinoProcessor:()=>Qp,Idefics3Processor:()=>Na,JinaCLIPProcessor:()=>Jp,Lfm2VlProcessor:()=>Zp,LlavaProcessor:()=>e_,MgpstrProcessor:()=>t_,MoonshineProcessor:()=>s_,OwlViTProcessor:()=>r_,PaliGemmaProcessor:()=>n_,Phi3VProcessor:()=>o_,PixtralProcessor:()=>i_,Processor:()=>U,PyAnnoteProcessor:()=>a_,Qwen2VLProcessor:()=>Kr,Qwen2_5_VLProcessor:()=>Xr,Qwen3VLProcessor:()=>l_,Sam2Processor:()=>Fa,Sam2VideoProcessor:()=>c_,SamProcessor:()=>Qr,SmolVLMProcessor:()=>Na,SpeechT5Processor:()=>u_,UltravoxProcessor:()=>p_,VLChatProcessor:()=>Yp,VoxtralProcessor:()=>__,VoxtralRealtimeProcessor:()=>f_,Wav2Vec2Processor:()=>m_,Wav2Vec2ProcessorWithLM:()=>h_,WhisperProcessor:()=>g_});var ae=class extends Me{constructor(e){super(),this.config=e}static async from_pretrained(e,s={}){let r=await Ce(e,Br,!0,s);return new this(r)}};function me(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 Vr={};Ts(Vr,{ASTFeatureExtractor:()=>qu,ChatterboxFeatureExtractor:()=>Uu,ClapFeatureExtractor:()=>Gu,DacFeatureExtractor:()=>Gr,EncodecFeatureExtractor:()=>Ur,FeatureExtractor:()=>ae,Gemma3nAudioFeatureExtractor:()=>Wu,GraniteSpeechFeatureExtractor:()=>Vu,MoonshineFeatureExtractor:()=>Hu,ParakeetFeatureExtractor:()=>Ku,PyAnnoteFeatureExtractor:()=>Wr,SeamlessM4TFeatureExtractor:()=>Xu,SnacFeatureExtractor:()=>Qu,SpeechT5FeatureExtractor:()=>Yu,VoxtralRealtimeFeatureExtractor:()=>ep,Wav2Vec2FeatureExtractor:()=>Ju,WeSpeakerFeatureExtractor:()=>Zu,WhisperFeatureExtractor:()=>tp});var yE=()=>{};var p0={fromWeb:yE};var bE=()=>{};var _0=bE;async function da(t,e){if(V.IS_BROWSER_ENV){if(V.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(V.IS_FS_AVAILABLE){let s=e.stream(),r=p0.fromWeb(s),n=Fe.createWriteStream(t);await _0(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 Nt(t)).arrayBuffer(),r=new AudioContext({sampleRate:e});typeof e>"u"&&F.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 m0(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 d0(t){return m0(t,.5)}function kE(t){return m0(t,.54)}var vE={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 ju(t,e="htk"){let s=vE[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 EE={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 AE(t,e="htk"){let s=EE[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 ME(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 f0(t,e,s){let r=(e-t)/(s-1);return Float64Array.from({length:s},(n,o)=>t+r*o)}function ze(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=ju(s,i),c=ju(r,i),u=f0(l,c,e+2),p=AE(u,i),_;if(a){let m=n/((t-1)*2);_=ju(Float64Array.from({length:t},(h,g)=>g*m),i),p=u}else _=f0(0,Math.floor(n/2),t);let d=ME(_,p);if(o!==null&&o==="slaney")for(let m=0;m<e;++m){let h=d[m],g=2/(p[m+2]-p[m]);for(let x=0;x<t;++x)h[x]*=g}return d}function SE(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[Ps(o,n)];for(let o=1;o<=s;++o)r[n+e+o]=t[Ps(n-o,n)];return r}function h0(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=ue(t)[0]-n;for(let a=0;a<t.length;++a)t[a]=Math.max(t[a],i)}return t}function OE(t,e=1,s=1e-5,r=null){return h0(t,20,e,s,r)}function IE(t,e=1,s=1e-10,r=null){return h0(t,10,e,s,r)}async function Pe(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:_=1e-10,log_mel:d=null,max_log_mel:m=null,reference:h=1,min_value:g=1e-10,db_range:x=null,remove_dc_offset:w=null,min_num_frames:y=null,max_num_frames:b=null,do_pad:M=!0,transpose:k=!1,mel_offset:O=0}={}){let N=e.length;if(n===null&&(n=s),s>n)throw Error(`frame_length (${s}) may not be larger than fft_length (${n})`);if(N!==s)throw new Error(`Length of the window (${N}) 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 I=Math.floor((n-1)/2)+1;t=SE(t,I,I);break}case"constant":{let I=Math.floor(n/2),H=new t.constructor(t.length+2*I);H.set(t,I),t=H;break}default:throw new Error(`pad_mode="${a}" not implemented yet.`)}let R=Math.floor(1+Math.floor((t.length-s)/r));y!==null&&R<y&&(R=y);let C=l?Math.floor(n/2)+1:n,D=R,$=R;b!==null&&(b>R?M&&($=b):$=D=b);let q=new ra(n),B=new Float64Array(n),G=new Float64Array(q.outputBufferSize),ee=new Float32Array(C*$);for(let I=0;I<D;++I){let H=I*r,be=Math.min(t.length-H,s);be!==s&&B.fill(0,0,s);for(let Q=0;Q<be;++Q)B[Q]=t[H+Q];if(w){let Q=0;for(let Ne=0;Ne<be;++Ne)Q+=B[Ne];let je=Q/be;for(let Ne=0;Ne<be;++Ne)B[Ne]-=je}if(c!==null){for(let Q=be-1;Q>=1;--Q)B[Q]-=c*B[Q-1];B[0]*=1-c}for(let Q=0;Q<e.length;++Q)B[Q]*=e[Q];q.realTransform(G,B);for(let Q=0;Q<C;++Q){let je=Q<<1;ee[Q*$+I]=G[je]**2+G[je+1]**2}}if(o!==null&&o!==2){let I=o/2;for(let H=0;H<ee.length;++H)ee[H]**=I}let se=p.length,v=await s0(new A("float32",p.flat(),[se,C]),new A("float32",ee,[C,$]));k&&(v=v.transpose(1,0));let E=v.data;for(let I=0;I<E.length;++I)E[I]=O+Math.max(_,E[I]);if(o!==null&&d!==null){let I=Math.min(E.length,D*se);switch(d){case"log":for(let H=0;H<I;++H)E[H]=Math.log(E[H]);break;case"log10":for(let H=0;H<I;++H)E[H]=Math.log10(E[H]);break;case"log10_max_norm":{for(let Q=0;Q<I;++Q)E[Q]=Math.log10(E[Q]);let be=(m??ue(E)[0])-8;for(let Q=0;Q<I;++Q)E[Q]=(Math.max(E[Q],be)+4)/4;break}case"dB":if(o===1)OE(E,h,g,x);else if(o===2)IE(E,h,g,x);else throw new Error(`Cannot use log_mel option '${d}' with power ${o}`);break;default:throw new Error(`log_mel must be one of null, 'log', 'log10', 'log10_max_norm', or 'dB'. Got '${d}'`)}}return v}function Le(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=d0(o);break;case"hamming":i=kE(o);break;case"povey":i=d0(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 zE(t,e){let s=t.reduce((o,i)=>o+i.length,0),r=new ArrayBuffer(44),n=new DataView(r);return fa(n,0,"RIFF"),n.setUint32(4,36+s*4,!0),fa(n,8,"WAVE"),fa(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),fa(n,36,"data"),n.setUint32(40,s*4,!0),new Blob([r,...t.map(o=>o.buffer)],{type:"audio/wav"})}function fa(t,e,s){for(let r=0;r<s.length;++r)t.setUint8(e+r,s.charCodeAt(r))}var qr=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]),zE(e,this.sampling_rate)}async save(e){return da(e,this.toBlob())}};var qu=class extends ae{constructor(e){super(e);let s=this.config.sampling_rate,r=ze(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Le(400,"hann",{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,s){return Pe(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){me(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 Ur=class extends ae{async _call(e){me(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 A("float32",e,r)}}};var Uu=class extends ae{async _call(e){me(e,"ChatterboxFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,e.length];return{input_values:new A("float32",e,s)}}};var Gu=class extends ae{constructor(e){super(e),this.mel_filters=ze(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=ze(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=Le(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(ls.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 Pe(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 me(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 Ur{};var Wu=class extends ae{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=ze(Math.floor(1+s/2),r,n,o,i,null,"htk",!1);this.mel_filters=l,this.window=Le(a,"hann")}async _extract_fbank_features(e,s){return Pe(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(me(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=we([1,i.dims[0]],!0);return{input_features:i.unsqueeze_(0),input_features_mask:a}}};var Vu=class extends ae{constructor(e){super(e);let{n_fft:s,win_length:r,n_mels:n,sample_rate:o}=e.melspec_kwargs;this.mel_filters=ze(Math.floor(1+s/2),n,0,o/2,o,null,"htk");let i=Le(r,"hann");this.window=new Float64Array(s);let a=Math.floor((s-r)/2);this.window.set(i,a)}async _call(e){me(e,"GraniteSpeechFeatureExtractor");let{n_fft:s,hop_length:r,n_mels:n}=this.config.melspec_kwargs,o=1+Math.floor((e.length-1)/r),i=o-o%2;return{input_features:(await Pe(e,this.window,s,r,{power:2,mel_filters:this.mel_filters,log_mel:"log10_max_norm",transpose:!0,max_num_frames:i,do_pad:!1})).view(-1,2*n).unsqueeze_(0)}}};var Hu=class extends ae{async _call(e){me(e,"MoonshineFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,e.length];return{input_values:new A("float32",e,s)}}};var TE=1e-5,Ku=class extends ae{constructor(e){super(e),this.config.mel_filters??=ze(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=Le(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 Pe(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){me(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 _=p*i;for(let d=0;d<i;++d){let m=n[_+d];a[d]+=m,l[d]+=m*m}}let c=r>1?r-1:1;for(let p=0;p<i;++p){let _=a[p]/r,d=(l[p]-r*_*_)/c,h=1/(Math.sqrt(d)+TE);for(let g=0;g<r;++g){let x=g*i+p;n[x]=(n[x]-_)*h}}let u=new BigInt64Array(o);return u.fill(1n,0,r),{input_features:s.unsqueeze_(0),attention_mask:new A("int64",u,[1,o])}}};var Wr=class extends ae{async _call(e){me(e,"PyAnnoteFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,1,e.length];return{input_values:new A("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=de(o[l]),[u,p]=ue(c),[_,d]=[l,l+1];p!==a?(a=p,i.push({id:p,start:_,end:d,score:u})):(i.at(-1).end=d,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 Xu=class extends ae{constructor(e){super(e);let s=this.config.sampling_rate,r=ze(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Le(400,"povey",{periodic:!1})}async _extract_fbank_features(e,s){return e=e.map(r=>r*32768),Pe(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}={}){me(e,"SeamlessM4TFeatureExtractor");let i=await this._extract_fbank_features(e,this.config.max_length);if(n){let[m,h]=i.dims,g=i.data;for(let x=0;x<h;++x){let w=0;for(let k=0;k<m;++k)w+=g[k*h+x];let y=w/m,b=0;for(let k=0;k<m;++k)b+=(g[k*h+x]-y)**2;b/=m-1;let M=Math.sqrt(b+1e-7);for(let k=0;k<m;++k){let O=k*h+x;g[O]=(g[O]-y)/M}}}let a;if(s){let[m,h]=i.dims,g=i.data,x=m%r;if(x>0){let w=new Float32Array(h*(m+x));w.set(g),w.fill(this.config.padding_value,g.length);let y=m+x;i=new A(i.type,w,[y,h]),o&&(a=new A("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 _=i.view(1,Math.floor(l/u),c*u),d={input_features:_};if(o){let m=_.dims[1],h=new BigInt64Array(m);if(a){let g=a.data;for(let x=1,w=0;x<l;x+=u,++w)h[w]=g[x]}else h.fill(1n);d.attention_mask=new A("int64",h,[1,m])}return d}};var Qu=class extends Gr{};var Yu=class extends ae{};var Ju=class extends ae{_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){me(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 A("float32",s,r),attention_mask:new A("int64",new BigInt64Array(s.length).fill(1n),r)}}};var Zu=class extends ae{constructor(e){super(e);let s=this.config.sampling_rate,r=ze(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Le(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),Pe(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){me(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 _=c+p*a;for(let d=0;d<a;++d)n[_+d]-=r[u+d]}}}return{input_features:s}}};var ep=class extends ae{constructor(e){super(e),this.config.mel_filters??=ze(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=Le(this.config.n_fft,"hann")}async _extract_fbank_features(e,{center:s=!0}={}){let{n_fft:r,hop_length:n,mel_filters:o,global_log_mel_max:i}=this.config,a=Math.floor(s?e.length/n:(e.length-r)/n);return await Pe(e,this.window,r,n,{power:2,mel_filters:o,log_mel:"log10_max_norm",max_log_mel:i,center:s,max_num_frames:a,do_pad:!1})}async _call(e,{center:s=!0}={}){return me(e,"VoxtralRealtimeFeatureExtractor"),{input_features:(await this._extract_fbank_features(e,{center:s})).unsqueeze_(0)}}};var tp=class extends ae{constructor(e){super(e),this.config.mel_filters??=ze(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=Le(this.config.n_fft,"hann")}async _extract_fbank_features(e){return await Pe(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10_max_norm",max_num_frames:Math.min(Math.floor(e.length/this.config.hop_length),this.config.nb_max_frames)})}async _call(e,{max_length:s=null}={}){me(e,"WhisperFeatureExtractor");let r,n=s??this.config.n_samples;return e.length>n?(e.length>this.config.n_samples&&F.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 ye=class{static async from_pretrained(e,s={}){let r=await Ce(e,Br,!0,s),n=r.feature_extractor_type,o=Vr[n];if(!o)throw new Error(`Unknown feature_extractor_type: '${n}'. Please report this at ${Dt}.`);return new o(r)}};var sp=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;async _call(e,s=null){let r=this.tokenizer(e),n=s?await this.feature_extractor(s):{};return{...r,...n}}};var ma={};var ps,g0,jt;if(V.IS_WEB_ENV)ps=(t,e)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this environment.");return new self.OffscreenCanvas(t,e)},jt=self.createImageBitmap,g0=self.ImageData;else if(ma)jt=async t=>{let s=(await t.metadata()).channels,{data:r,info:n}=await t.rotate().raw().toBuffer({resolveWithObject:!0}),o=new ve(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 CE={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},PE=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]),ve=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(!V.IS_WEB_ENV)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 Nt(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(V.IS_WEB_ENV){let s=await jt(e),r=ps(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=ma(await e.arrayBuffer());return await jt(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=CE[r]??r,o=Ac(e),i=Ac(s);if(o&&i)return this;if(o?e=s/this.height*this.width:i&&(s=e/this.width*this.height),V.IS_WEB_ENV){let a=this.channels,l=this.toCanvas(),c=ps(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")&&(F.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 jt(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(V.IS_WEB_ENV){let o=this.channels,i=this.toCanvas(),a=this.width+e+s,l=this.height+r+n,c=ps(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 jt(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(V.IS_WEB_ENV){let a=this.channels,l=this.toCanvas(),c=ps(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 jt(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(V.IS_WEB_ENV){let o=this.channels,i=this.toCanvas(),a=ps(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 jt(o)}}async toBlob(e="image/png",s=1){if(!V.IS_WEB_ENV)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 A("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(!V.IS_WEB_ENV)throw new Error("toCanvas() is only supported in browser environments.");let e=this.clone().rgba(),s=ps(e.width,e.height),r=new g0(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(V.IS_WEB_ENV){if(V.IS_WEBWORKER_ENV)throw new Error("Unable to save an image from a Web Worker.");let s=e.split(".").pop().toLowerCase(),r=PE.get(s)??"image/png",n=await this.toBlob(r);return da(e,n)}else if(V.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(V.IS_WEB_ENV)throw new Error("toSharp() is only supported in server-side environments.");return ma(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}},LE=ve.read.bind(ve);function x0(t,e,s=0,r=null){let n=t/e,o=Ry(n)*e;return r!==null&&o>r&&(o=Math.floor(n)*e),o<s&&(o=Math.ceil(n)*e),o}function rp([t,e],s){return[Math.max(Math.floor(t/s),1)*s,Math.max(Math.floor(e/s),1)*s]}function np([t,e,s,r]){return[t-s/2,e-r/2,t+s/2,e+r/2]}function Bt(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,_={boxes:[],classes:[],scores:[]},d=n[u],m=o[u];for(let h=0;h<a;++h){let g=d[h],x=[],w;if(r){w=g.sigmoid().data;for(let y=0;y<w.length;++y)w[y]>e&&x.push(y)}else{let y=ue(g.data)[1];if(y===l-1||(w=de(g.data),w[y]<e))continue;x.push(y)}for(let y of x){let b=m[h].data;b=np(b),p!==null&&(b=b.map((M,k)=>M*p[(k+1)%2])),_.boxes.push(b),_.classes.push(y),_.scores.push(w[y])}}c.push(_)}return c}function ha(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=qc(a,i,"bilinear",!1));let[l,c]=i??a.dims.slice(-2),u=new A("int32",new Int32Array(l*c),[l,c]),p=a[0].data,_=u.data;for(let h=1;h<a.dims[0];++h){let g=a[h].data;for(let x=0;x<g.length;++x)g[x]>p[x]&&(p[x]=g[x],_[x]=h)}let d=new Array(a.dims[0]);for(let h=0;h<_.length;++h){let g=_[h];d[g]=g}let m=d.filter(h=>h!==void 0);n.push({segmentation:u,labels:m})}return n}function NE(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=ue(l.data)[1];if(u===r)continue;let _=de(l.data)[u];_>s&&(n.push(c),o.push(_),i.push(u))}return[n,o,i]}function FE(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 $E(t,e,s,r,n,o=null,i=null){let[a,l]=i??t[0].dims,c=new A("int32",new Int32Array(a*l),[a,l]),u=[];if(i!==null)for(let h=0;h<t.length;++h)t[h]=qc(t[h],i,"bilinear",!1);let p=new Int32Array(t[0].data.length),_=new Float32Array(t[0].data.length);for(let h=0;h<t.length;++h){let g=e[h],x=t[h].data;for(let w=0;w<x.length;++w)x[w]*=g,x[w]>_[w]&&(p[w]=h,_[w]=x[w])}let d=0,m=c.data;for(let h=0;h<s.length;++h){let g=s[h],[x,w]=FE(p,t,h,r,n);if(x){++d;for(let y of w)m[y]=d;u.push({id:d,label_id:g,score:e[h]})}}return[c,u]}function ga(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 xa(t,e=.5,s=.5,r=.8,n=null,o=null){n===null&&(F.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 _=[];for(let d=0;d<c;++d){let m=o!==null?o[d]:null,h=i[d],g=l[d],[x,w,y]=NE(h,g,e,p);if(y.length===0){let[k,O]=m??g.dims.slice(-2),N=new A("int32",new Int32Array(k*O).fill(-1),[k,O]);_.push({segmentation:N,segments_info:[]});continue}let[b,M]=$E(x,w,y,s,r,n,m);_.push({segmentation:b,segments_info:M})}return _}function wa(t,e=.5,s=null){throw new Error("`post_process_instance_segmentation` is not yet implemented.")}var P=class extends Me{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=Lr(r.data)[0],i=ue(r.data)[0]-n;if(i===0)return e;let a=s/255,l=r.width,c=r.height,u=0,p=0,_=r.data;for(let d=0;d<r.height;++d){let m=d*r.width;for(let h=0;h<r.width;++h)(_[m+h]-n)/i<a&&(l=Math.min(l,h),c=Math.min(c,d),u=Math.max(u,h),p=Math.max(p,d))}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 _=new Float32Array(u*p*c);if(Array.isArray(i))for(let h=0;h<_.length;++h)_[h]=i[h%c];else i!==0&&_.fill(i);let[d,m]=o?[Math.floor((u-l)/2),Math.floor((p-a)/2)]:[0,0];for(let h=0;h<a;++h){let g=(h+m)*u,x=h*l;for(let w=0;w<l;++w){let y=(g+w+d)*c,b=(x+w)*c;for(let M=0;M<c;++M)_[y+M]=e[b+M]}}if(n==="symmetric"){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");let h=a-1,g=l-1;for(let x=0;x<p;++x){let w=x*u,y=Ps(x,h)*l;for(let b=0;b<u;++b){if(x<a&&b<l)continue;let M=(w+b)*c,k=(y+Ps(b,g))*c;for(let O=0;O<c;++O)_[M+O]=e[k+O]}}}e=_,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))),_=Math.floor(Number((c*u).toFixed(2)));return this.size_divisibility!==void 0&&([p,_]=rp([p,_],this.size_divisibility)),[p,_]}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=x0(c*n,this.config.ensure_multiple_of),a=x0(u*r,this.config.ensure_multiple_of)}return[a,l]}else{if(this.size_divisibility!==void 0)return rp([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 d,m;Number.isInteger(this.crop_size)?(d=this.crop_size,m=this.crop_size):(d=this.crop_size.width,m=this.crop_size.height),e=await e.center_crop(d,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 d=this.image_mean;Array.isArray(this.image_mean)||(d=new Array(e.channels).fill(d));let m=this.image_std;if(Array.isArray(this.image_std)||(m=new Array(e.channels).fill(m)),d.length!==e.channels||m.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${d.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 g=0;g<e.channels;++g)u[h+g]=(u[h+g]-d[g])/m[g]}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[d,m]=rp([p[1],p[0]],this.size_divisibility);[u,p]=this.pad_image(u,p,{width:d,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 d=0;d<u.length;d+=3){let m=u[d];u[d]=u[d+2],u[d+2]=m}}let _=new A("float32",u,p).permute(2,0,1);return{original_size:[l,a],reshaped_input_size:c,pixel_values:_}}async _call(e,...s){Array.isArray(e)||(e=[e]);let r=await Promise.all(e.map(o=>this.preprocess(o)));return{pixel_values:Ge(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 Ce(e,Mt,!0,s);return new this(r)}};var Vs={};Ts(Vs,{BeitFeatureExtractor:()=>op,BitImageProcessor:()=>ip,CLIPFeatureExtractor:()=>lp,CLIPImageProcessor:()=>ya,ChineseCLIPFeatureExtractor:()=>ap,ConvNextFeatureExtractor:()=>cp,ConvNextImageProcessor:()=>ba,DINOv3ViTImageProcessor:()=>_p,DPTFeatureExtractor:()=>fp,DPTImageProcessor:()=>Ea,DeiTFeatureExtractor:()=>up,DeiTImageProcessor:()=>ka,DetrFeatureExtractor:()=>pp,DetrImageProcessor:()=>va,DonutFeatureExtractor:()=>dp,DonutImageProcessor:()=>qs,EfficientNetImageProcessor:()=>mp,GLPNFeatureExtractor:()=>hp,GroundingDinoImageProcessor:()=>gp,Idefics3ImageProcessor:()=>Aa,ImageFeatureExtractor:()=>P,ImageProcessor:()=>P,JinaCLIPImageProcessor:()=>wp,Lfm2VlImageProcessor:()=>yp,LlavaOnevisionImageProcessor:()=>bp,Mask2FormerImageProcessor:()=>vp,MaskFormerFeatureExtractor:()=>kp,MaskFormerImageProcessor:()=>Us,MobileNetV1FeatureExtractor:()=>Ep,MobileNetV1ImageProcessor:()=>Ma,MobileNetV2FeatureExtractor:()=>Ap,MobileNetV2ImageProcessor:()=>Sa,MobileNetV3FeatureExtractor:()=>Mp,MobileNetV3ImageProcessor:()=>Oa,MobileNetV4FeatureExtractor:()=>Sp,MobileNetV4ImageProcessor:()=>Ia,MobileViTFeatureExtractor:()=>Op,MobileViTImageProcessor:()=>za,NougatImageProcessor:()=>Ip,OwlViTFeatureExtractor:()=>zp,OwlViTImageProcessor:()=>Gs,Owlv2ImageProcessor:()=>Tp,Phi3VImageProcessor:()=>Lp,PixtralImageProcessor:()=>Np,PvtImageProcessor:()=>Fp,Qwen2VLImageProcessor:()=>$p,RTDetrImageProcessor:()=>Rp,Sam2ImageProcessor:()=>Hr,Sam3ImageProcessor:()=>Hr,SamImageProcessor:()=>Hr,SapiensFeatureExtractor:()=>Dp,SapiensImageProcessor:()=>Ta,SegformerFeatureExtractor:()=>jp,SegformerImageProcessor:()=>Ca,SiglipImageProcessor:()=>Bp,SmolVLMImageProcessor:()=>Aa,Swin2SRImageProcessor:()=>qp,VLMImageProcessor:()=>xp,ViTFeatureExtractor:()=>Up,ViTImageProcessor:()=>Pa,VitMatteImageProcessor:()=>Gp,VitPoseImageProcessor:()=>Wp,YolosFeatureExtractor:()=>Vp,YolosImageProcessor:()=>La});var op=class extends P{};var ip=class extends P{};var ap=class extends P{};var ya=class extends P{},lp=class extends ya{};var ba=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}},cp=class extends ba{};var ka=class extends P{},up=class extends ka{};var va=class extends P{async _call(e){let s=await super._call(e),r=[s.pixel_values.dims[0],64,64],n=we(r,1n);return{...s,pixel_mask:n}}post_process_object_detection(...e){return Bt(...e)}post_process_panoptic_segmentation(...e){return xa(...e)}post_process_instance_segmentation(...e){return wa(...e)}},pp=class extends va{};var _p=class extends P{};var qs=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,_)=>-p/c[_]);return super.pad_image(e,s,r,{center:!0,constant_values:u,...n})}},dp=class extends qs{};var Ea=class extends P{},fp=class extends Ea{};var mp=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 hp=class extends P{};var gp=class extends P{async _call(e){let s=await super._call(e),r=s.pixel_values.dims,n=Se([r[0],r[2],r[3]]);return{...s,pixel_mask:n}}};var Aa=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 x of n){let w=await Promise.all(x.map(M=>this.preprocess(M)));l.push(...w.map(M=>M.original_size)),c.push(...w.map(M=>M.reshaped_input_size)),w.forEach(M=>M.pixel_values.unsqueeze_(0));let{longest_edge:y}=this.max_image_size,b;if(s??this.do_image_splitting){let M=new Array(w.length),k=new Array(w.length);b=await Promise.all(w.map(async(O,N)=>{let R=this.get_resize_for_vision_encoder(O.pixel_values,y),C=await Be(O.pixel_values,{size:[R.height,R.width]}),{frames:D,num_splits_h:$,num_splits_w:q}=await this.split_image(C,this.max_image_size);return M[N]=$,k[N]=q,ie(D,0)})),i.push(M),a.push(k)}else{let M=[y,y];b=await Promise.all(w.map(k=>Be(k.pixel_values,{size:M}))),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,m]=o[0].dims,h,g;if(u===1)h=o[0].unsqueeze_(0),g=we([u,p,d,m],!0);else{let x=Math.max(...o.map(b=>b.dims.at(0)));g=we([u,x,d,m],!0);let w=g.data,y=x*d*m;for(let b=0;b<u;++b){let M=o[b].dims[0];if(M<x){o[b]=ie([o[b],we([x-M,_,d,m],0)],0);let k=b*y+M*d*m,O=(b+1)*y;w.fill(!1,k,O)}}h=Ge(o,0)}return{pixel_values:h,pixel_attention_mask:g,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 g,x,w,y;m===l-1?(x=i-u,y=i):(x=m*u,y=(m+1)*u),h===c-1?(g=a-p,w=a):(g=h*p,w=(h+1)*p);let k=await ua(e,[x,g],[y,w],[2,3]);o.push(k)}let _=r,d=n;(i!==_||a!==d)&&(e=await Be(e,{size:[_,d]}))}return o.push(e),{frames:o,num_splits_h:l,num_splits_w:c}}};var xp=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 wp=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})}};function w0(t,e){return Math.round(t/e)*e}function RE(t,e,s,r,n){let o=1/0,i=[1,1],a=s*r;for(let l of e){let c=Math.abs(t-l[0]/l[1]);c<o?(o=c,i=l):c===o&&a>.5*n*n*l[0]*l[1]&&(i=l)}return i}function DE(t,e){let s=[],r=new Set;for(let n=t;n<=e;++n)for(let o=1;o<=n;++o)for(let i=1;i<=n;++i){let a=o*i;if(a>=t&&a<=e){let l=o<<16|i;r.has(l)||(r.add(l),s.push([o,i]))}}return s.sort((n,o)=>n[0]*n[1]-o[0]*o[1])}function jE(t,e){let[s,r,n,o]=t.dims,i=Math.floor(n/e),a=Math.floor(o/e),l=e*e*r,c=t.data,u=new Float32Array(s*i*a*l),p=n*o;for(let _=0;_<s;++_){let d=_*r*p,m=_*i*a*l;for(let h=0;h<i;++h)for(let g=0;g<a;++g){let x=m+(h*a+g)*l;for(let w=0;w<e;++w){let y=(h*e+w)*o+g*e;for(let b=0;b<e;++b){let M=y+b;for(let k=0;k<r;++k)u[x++]=c[d+k*p+M]}}}}return new A("float32",u,[s,i*a,l])}function BE(t,e){let[,s,r]=t.dims,n=new BigInt64Array(e);n.fill(1n,0,s);let o=t;if(s<e){let i=new Float32Array(e*r);i.set(t.data),o=new A("float32",i,[1,e,r])}return{padded:o,mask:new A("int64",n,[e])}}var yp=class extends P{constructor(e){super(e),this.downsample_factor=e.downsample_factor??2,this.do_image_splitting=e.do_image_splitting??!0,this.min_tiles=e.min_tiles??2,this.max_tiles=e.max_tiles??10,this.use_thumbnail=e.use_thumbnail??!0,this.min_image_tokens=e.min_image_tokens??64,this.max_image_tokens=e.max_image_tokens??256,this.encoder_patch_size=e.encoder_patch_size??e.patch_size??16,this.tile_size=e.tile_size??512,this.max_pixels_tolerance=e.max_pixels_tolerance??2,this.return_row_col_info=e.return_row_col_info??!1;let s=this.max_image_tokens*this.downsample_factor**2,r=this.do_image_splitting?(this.tile_size/this.encoder_patch_size)**2:0;this.max_num_patches=Math.max(s,r)}_is_image_too_large(e,s){let r=this.encoder_patch_size*this.downsample_factor,n=Math.max(this.encoder_patch_size,w0(e,r)),o=Math.max(this.encoder_patch_size,w0(s,r));return n*o>this.max_image_tokens*(this.encoder_patch_size*this.downsample_factor)**2*this.max_pixels_tolerance}_get_grid_layout(e,s){let r=DE(this.min_tiles,this.max_tiles),[n,o]=RE(s/e,r,s,e,this.tile_size);return{grid_width:n,grid_height:o,target_width:this.tile_size*n,target_height:this.tile_size*o}}async _call(e,{return_row_col_info:s=null}={}){let r;Array.isArray(e)?Array.isArray(e[0])?r=e:r=[e]:r=[[e]];let n=[],o=[],i=[],a=[],l=[],c=[];for(let p of r){let _=await Promise.all(p.map(d=>this.preprocess(d,{do_pad:!1})));for(let{pixel_values:d}of _){let[,m,h]=d.dims,g=d.unsqueeze_(0),x=this.encoder_patch_size*this.downsample_factor,w=x**2,[y,b]=ga(Math.max(x,m),Math.max(x,h),x,this.min_image_tokens*w,this.max_image_tokens*w).map(C=>Math.max(x,C)),M,k=1,O=1,N=this._is_image_too_large(m,h),R=this.do_image_splitting&&!(this.min_tiles===1&&this.max_tiles===1);if(N&&R){let{grid_width:C,grid_height:D,target_width:$,target_height:q}=this._get_grid_layout(m,h);k=D,O=C;let B=await Be(g,{size:[q,$]});M=[];for(let G=0;G<D;++G)for(let ee=0;ee<C;++ee){let se=G*this.tile_size,v=ee*this.tile_size;M.push(B.slice(null,null,[se,se+this.tile_size],[v,v+this.tile_size]))}this.use_thumbnail&&C*D!==1&&M.push(await Be(g,{size:[y,b]}))}else M=[await Be(g,{size:[y,b]})];for(let C of M){let[,,D,$]=C.dims,q=jE(C,this.encoder_patch_size),{padded:B,mask:G}=BE(q,this.max_num_patches);n.push(B),o.push(G),i.push([Math.floor(D/this.encoder_patch_size),Math.floor($/this.encoder_patch_size)])}a.push(k),l.push(O),c.push([y,b])}}let u={pixel_values:ie(n,0),pixel_attention_mask:Ge(o,0),spatial_shapes:new A("int64",BigInt64Array.from(i.flat(),BigInt),[i.length,2])};return(s??this.return_row_col_info)&&(u.image_rows=a,u.image_cols=l,u.image_sizes=c),u}};var bp=class extends P{};var Us=class extends P{post_process_panoptic_segmentation(...e){return xa(...e)}post_process_instance_segmentation(...e){return wa(...e)}},kp=class extends Us{};var vp=class extends Us{};var Ma=class extends P{},Ep=class extends Ma{};var Sa=class extends P{},Ap=class extends Sa{};var Oa=class extends P{},Mp=class extends Oa{};var Ia=class extends P{},Sp=class extends Ia{};var za=class extends P{},Op=class extends za{};var Ip=class extends qs{};var Gs=class extends P{post_process_object_detection(...e){return Bt(...e)}},zp=class extends Gs{};var Tp=class extends Gs{};var He=336,qE=[2,3],{ceil:Cp,floor:Ws,sqrt:Pp}=Math,Lp=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 Ws((Ws(s/He)*Ws(e/He)+1)*r+1+(Ws(s/He)+1)*Pp(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=He*Cp(o/He),l=He*Cp(i/He),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||Pp(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(_=>this.preprocess(_))),o=n.map(_=>_.original_size),i=n.map(_=>_.reshaped_input_size),a=[];for(let{pixel_values:_}of n){_.unsqueeze_(0);let[d,m]=_.dims.slice(-2),h=await Be(_,{size:[He,He],mode:"bicubic"});if(s>0){let g=[],x=Pp(s),w=Ws(m/x),y=Ws(d/x);for(let M=0;M<x;++M)for(let k=0;k<x;++k){let O,N,R,C;M===x-1?(N=d-y,C=d):(N=M*y,C=(M+1)*y),k===x-1?(O=m-w,R=m):(O=k*w,R=(k+1)*w);let q=await ua(_,[N,O],[C,R],qE);g.push(q)}let b=await Be(ie(g,0),{size:[He,He],mode:"bicubic"});a.push(ie([h,b],0))}else a.push(h)}let l=Ge(a,0),c=i.map(_=>_.map(d=>He*Cp(d/He))),u=new A("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 Np=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,_=Math.floor((a-1)/p)+1,d=Math.floor((l-1)/p)+1;return[_*p,d*p]}};var Fp=class extends P{};var $p=class extends P{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 ga(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],_=Math.floor(i.dims[2]/c),d=Math.floor(i.dims[3]/c),m=i.view(u,a,p,Math.floor(_/l),l,c,Math.floor(d/l),l,c).permute(0,3,6,4,7,2,1,5,8).view(u*_*d,p*a*c*c),h=new A("int64",[u,_,d],[1,3]);return{pixel_values:m,image_grid_thw:h,original_sizes:n,reshaped_input_sizes:o}}};var Rp=class extends P{post_process_object_detection(...e){return Bt(...e)}};var Hr=class extends P{reshape_input_points(e,s,r,n=!1){e=structuredClone(e);let o=Mc(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 _=0;_<e[i].length;++_)for(let d=0;d<e[i][_].length;++d)for(let m=0;m<e[i][_][d].length;++m)e[i][_][d][m]*=p[m%2]}return new A("float32",Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,s){let r=Mc(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 A("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],_=await Be(e[c],{mode:"bilinear",size:l});if(_=_.slice(null,null,[0,p[0]],[0,p[1]]),_=await Be(_,{mode:"bilinear",size:u}),o){let d=_.data,m=new Uint8Array(d.length);for(let h=0;h<d.length;++h)d[h]>n&&(m[h]=1);_=new A("bool",m,_.dims)}a.push(_)}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 Ta=class extends P{post_process_semantic_segmentation(...e){return ha(...e)}},Dp=class extends Ta{};var Ca=class extends P{post_process_semantic_segmentation(...e){return ha(...e)}},jp=class extends Ca{};var Bp=class extends P{};var qp=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 Pa=class extends P{},Up=class extends Pa{};var Gp=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:Ge(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 Wp=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],_=s[u],d=[];for(let m=0;m<_.length;++m){let h=_[m],g=[],x=[],w=[],y=h.at(-2)/l,b=h.at(-1)/a;for(let M=0;M<p.length;++M){let[k,O]=[0,0],N=0,R=-1/0,C=p[M];for(let $=0;$<C.length;++$){let q=C[$];for(let B=0;B<q.length;++B){let G=q[B];N+=G,R=Math.max(R,G),k+=(B+.5)*G,O+=$*G}}if(r!=null&&R<r)continue;let D=[y*k/N,b*O/N];g.push(D),w.push(M),x.push(R)}d.push({bbox:h,scores:x,labels:w,keypoints:g})}c.push(d)}return c}};var La=class extends P{post_process_object_detection(...e){return Bt(...e)}},Vp=class extends La{};var pe=class{static async from_pretrained(e,s={}){let r=await Ce(e,Mt,!0,s),n=r.image_processor_type??r.feature_extractor_type,o=Vs[n?.replace(/Fast$/,"")];return o||(n!==void 0&&F.warn(`Image processor type '${n}' not found, assuming base ImageProcessor. Please report this at ${Dt}.`),o=P),new o(r)}};var Hp=class extends U{static tokenizer_class=W;static image_processor_class=pe;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,..._]of a)l.push(p?p.trim():l.at(-1)??""),c.push(_.map((d,m)=>(Number(d)+.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 Kp=class extends U{static image_processor_class=pe;static feature_extractor_class=ye;static tokenizer_class=W;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 _=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 J(isNaN(n)?0:n)}case"float":{let n=parseFloat(t.value);return new Ee(isNaN(n)?0:n)}default:throw new Error(`Unknown StringValue filter: ${r.value}`)}else if(t instanceof J||t instanceof Ee)switch(r.value){case"abs":return t instanceof J?new J(Math.abs(t.value)):new Ee(Math.abs(t.value));case"int":return new J(Math.floor(t.value));case"float":return new Ee(t.value);case"string":return new D(t.toString());default:throw new Error(`Unknown NumericValue filter: ${r.value}`)}else if(t instanceof Te)switch(r.value){case"items":return new ne(Array.from(t.value.entries()).map(([n,o])=>new ne([new D(n),o])));case"length":return new J(t.value.size);default:{let n=t.builtins.get(r.value);if(n)return n instanceof xe?n.value([],s):n;throw new Error(`Unknown ObjectValue filter: ${r.value}`)}}else if(t instanceof K)switch(r.value){case"bool":return new K(t.value);case"int":return new J(t.value?1:0);case"float":return new Ee(t.value?1:0);case"string":return new D(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 we;if(!(i instanceof J||i instanceof we))throw new Error("If set, indent must be a number");let a=o.get("ensure_ascii")??new K(!1);if(!(a instanceof K))throw new Error("If set, ensure_ascii must be a boolean");let l=o.get("sort_keys")??new K(!1);if(!(l instanceof K))throw new Error("If set, sort_keys must be a boolean");let c=o.get("separators")??new we,p=null;if(c instanceof ne||c instanceof Gy){if(c.value.length!==2)throw new Error("separators must be a tuple of two strings");let[u,_]=c.value;if(!(u instanceof D)||!(_ instanceof D))throw new Error("separators must be a tuple of two strings");p=[u.value,_.value]}else if(!(c instanceof we))throw new Error("If set, separators must be a tuple of two strings");return new D(Yt(t,{indent:i.value,ensureAscii:a.value,sortKeys:l.value,separators:p}))}else if(n==="join"){let o;if(t instanceof D)o=Array.from(t.value);else if(t instanceof ne)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 D("");if(!(l instanceof D))throw new Error("separator must be a string");return new D(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 J(0):new Ee(0));if(t instanceof D){let l=n==="int"?parseInt(t.value,10):parseFloat(t.value);return isNaN(l)?a:n==="int"?new J(l):new Ee(l)}else{if(t instanceof J||t instanceof Ee)return t;if(t instanceof K)return n==="int"?new J(t.value?1:0):new Ee(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 D(""),l=o[1]??i.get("boolean")??new K(!1);if(!(l instanceof K))throw new Error("`default` filter flag must be a boolean");return t instanceof ge||l.value&&!t.__bool__().value?a:t}if(t instanceof ne){switch(n){case"sort":{let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("reverse")??new K(!1);if(!(a instanceof K))throw new Error("reverse must be a boolean");let l=o.at(1)??i.get("case_sensitive")??new K(!1);if(!(l instanceof K))throw new Error("case_sensitive must be a boolean");let c=o.at(2)??i.get("attribute")??new we;if(!(c instanceof D||c instanceof J||c instanceof we))throw new Error("attribute must be a string, integer, or null");let p=u=>{if(c instanceof we)return u;let _=c instanceof J?String(c.value):c.value;return Wy(u,_)};return new ne(t.value.slice().sort((u,_)=>{let d=p(u),m=p(_),h=Pc(d,m,l.value);return a.value?-h:h}))}case"selectattr":case"rejectattr":{let o=n==="selectattr";if(t.value.some(u=>!(u instanceof Te)))throw new Error(`\`${n}\` can only be applied to array of objects`);if(r.args.some(u=>u.type!=="StringLiteral"))throw new Error(`arguments of \`${n}\` must be strings`);let[i,a,l]=r.args.map(u=>this.evaluate(u,s)),c;if(a){let u=s.tests.get(a.value);if(!u)throw new Error(`Unknown test: ${a.value}`);c=u}else c=(...u)=>u[0].__bool__().value;let p=t.value.filter(u=>{let _=u.value.get(i.value),d=_?c(_,l):!1;return o?d:!d});return new ne(p)}case"map":{let[,o]=this.evaluateArguments(r.args,s);if(o.has("attribute")){let i=o.get("attribute");if(!(i instanceof D))throw new Error("attribute must be a string");let a=o.get("default"),l=t.value.map(c=>{if(!(c instanceof Te))throw new Error("items in map must be an object");let p=Wy(c,i.value);return p instanceof ge?a??new ge:p});return new ne(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 D){switch(n){case"indent":{let[o,i]=this.evaluateArguments(r.args,s),a=o.at(0)??i.get("width")??new J(4);if(!(a instanceof J))throw new Error("width must be a number");let l=o.at(1)??i.get("first")??new K(!1),c=o.at(2)??i.get("blank")??new K(!1),p=t.value.split(`
8
+ `),u=" ".repeat(a.value),_=p.map((d,m)=>!l.value&&m===0||!c.value&&d.length===0?d:u+d);return new D(_.join(`
9
+ `))}case"replace":{let o=t.builtins.get("replace");if(!(o instanceof xe))throw new Error("replace filter not available");let[i,a]=this.evaluateArguments(r.args,s);return o.value([...i,new zr(a)],s)}}throw new Error(`Unknown StringValue filter: ${n}`)}else if(t instanceof Te){let o=t.builtins.get(n);if(o&&o instanceof xe){let[i,a]=this.evaluateArguments(r.args,s);return a.size>0&&i.push(new zr(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 K(t.negate?!n:n)}evaluateSelectExpression(t,e){return this.evaluate(t.test,e).__bool__().value?this.evaluate(t.lhs,e):new ge}evaluateUnaryExpression(t,e){let s=this.evaluate(t.argument,e);if(t.operator.value==="not")return new K(!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 D(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 zr(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 ne||t instanceof D))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 J||r instanceof ge))throw new Error("Slice start must be numeric or undefined");if(!(n instanceof J||n instanceof ge))throw new Error("Slice stop must be numeric or undefined");if(!(o instanceof J||o instanceof ge))throw new Error("Slice step must be numeric or undefined");return t instanceof ne?new ne(jy(t.value,r.value,n.value,o.value)):new D(jy(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 D(t.property.value);let n;if(s instanceof Te){if(!(r instanceof D))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 ne||s instanceof D)if(r instanceof J)n=s.value.at(r.value),s instanceof D&&(n=new D(s.value.at(r.value)));else if(r instanceof D)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 D))throw new Error(`Cannot access property with non-string: got ${r.type}`);n=s.builtins.get(r.value)}return n instanceof pt?n:new ge}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 ne))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 Te))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 we}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 Qt(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 ne||n instanceof Te))throw new Error(`Expected iterable or object type in for loop: got ${n.type}`);n instanceof Te&&(n=n.keys());let o=[],i=[];for(let c=0;c<n.value.length;++c){let p=new Qt(s),u=n.value[c],_;if(t.loopvar.type==="Identifier")_=d=>d.setVariable(t.loopvar.value,u);else if(t.loopvar.type==="TupleLiteral"){let d=t.loopvar;if(u.type!=="ArrayValue")throw new Error(`Cannot unpack non-iterable type: ${u.type}`);let m=u;if(d.value.length!==m.value.length)throw new Error(`Too ${d.value.length>m.value.length?"few":"many"} items to unpack`);_=h=>{for(let g=0;g<d.value.length;++g){if(d.value[g].type!=="Identifier")throw new Error(`Cannot unpack non-identifier type: ${d.value[g].type}`);h.setVariable(d.value[g].value,m.value[g])}}}else throw new Error(`Invalid loop variable(s): ${t.loopvar.type}`);r&&(_(p),!this.evaluate(r,p).__bool__().value)||(o.push(u),i.push(_))}let a="",l=!0;for(let c=0;c<o.length;++c){let p=new Map([["index",new J(c+1)],["index0",new J(c)],["revindex",new J(o.length-c)],["revindex0",new J(o.length-c-1)],["first",new K(c===0)],["last",new K(c===o.length-1)],["length",new J(o.length)],["previtem",c>0?o[c-1]:new ge],["nextitem",c<o.length-1?o[c+1]:new ge]]);s.setVariable("loop",new Te(p)),i[c](s);try{let u=this.evaluateBlock(t.body,s);a+=u.value}catch(u){if(u instanceof qy)continue;if(u instanceof By)break;throw u}l=!1}if(l){let c=this.evaluateBlock(t.defaultBlock,s);a+=c.value}return new D(a)}evaluateMacro(t,e){return e.setVariable(t.name.value,new xe((s,r)=>{let n=new Qt(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,p=l??o?.value.get(c.key.value)??this.evaluate(c.value,n);n.setVariable(c.key.value,p)}else throw new Error(`Unknown argument type: ${a.type}`)}return this.evaluateBlock(t.body,n)})),new we}evaluateCallStatement(t,e){let s=new xe((a,l)=>{let c=new Qt(l);if(t.callerArgs)for(let p=0;p<t.callerArgs.length;++p){let u=t.callerArgs[p];if(u.type!=="Identifier")throw new Error(`Caller parameter must be an identifier, got ${u.type}`);c.setVariable(u.value,a[p]??new ge)}return this.evaluateBlock(t.body,c)}),[r,n]=this.evaluateArguments(t.call.args,e);r.push(new zr(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 Qt(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 ge;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 By;case"Continue":throw new qy;case"IntegerLiteral":return new J(t.value);case"FloatLiteral":return new Ee(t.value);case"StringLiteral":return new D(t.value);case"ArrayLiteral":return new ne(t.value.map(s=>this.evaluate(s,e)));case"TupleLiteral":return new Gy(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 D))throw new Error(`Object keys must be strings: got ${o.type}`);s.set(o.value,this.evaluate(n,e))}return new Te(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 we;default:throw new SyntaxError(`Unknown node type: ${t.type}`)}}};function Zi(t){switch(typeof t){case"number":return Number.isInteger(t)?new J(t):new Ee(t);case"string":return new D(t);case"boolean":return new K(t);case"undefined":return new ge;case"object":return t===null?new we:Array.isArray(t)?new ne(t.map(Zi)):new Te(new Map(Object.entries(t).map(([e,s])=>[e,Zi(s)])));case"function":return new xe((e,s)=>{let r=t(...e.map(n=>n.value))??null;return Zi(r)});default:throw new Error(`Cannot convert to runtime value: ${t}`)}}var Oe=`
10
+ `,_E="{%- ",dE=" -%}";function fE(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 mE(t,e=" "){let s=typeof e=="number"?" ".repeat(e):e;return nt(t.body,0,s).replace(/\n$/,"")}function $e(...t){return _E+t.join(" ")+dE}function nt(t,e,s){return t.map(r=>hE(r,e,s)).join(Oe)}function hE(t,e,s){let r=s.repeat(e);switch(t.type){case"Program":return nt(t.body,e,s);case"If":return gE(t,e,s);case"For":return xE(t,e,s);case"Set":return wE(t,e,s);case"Macro":return yE(t,e,s);case"Break":return r+$e("break");case"Continue":return r+$e("continue");case"CallStatement":return bE(t,e,s);case"FilterStatement":return kE(t,e,s);case"Comment":return r+"{# "+t.value+" #}";default:return r+"{{- "+oe(t)+" -}}"}}function gE(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+$e("if",oe(n[0].test))+Oe+nt(n[0].body,e+1,s);for(let a=1;a<n.length;++a)i+=Oe+r+$e("elif",oe(n[a].test))+Oe+nt(n[a].body,e+1,s);return o&&o.alternate.length>0&&(i+=Oe+r+$e("else")+Oe+nt(o.alternate,e+1,s)),i+=Oe+r+$e("endif"),i}function xE(t,e,s){let r=s.repeat(e),n="";if(t.iterable.type==="SelectExpression"){let i=t.iterable;n=`${oe(i.lhs)} if ${oe(i.test)}`}else n=oe(t.iterable);let o=r+$e("for",oe(t.loopvar),"in",n)+Oe+nt(t.body,e+1,s);return t.defaultBlock.length>0&&(o+=Oe+r+$e("else")+Oe+nt(t.defaultBlock,e+1,s)),o+=Oe+r+$e("endfor"),o}function wE(t,e,s){let r=s.repeat(e),n=oe(t.assignee),o=t.value?oe(t.value):"",i=r+$e("set",`${n}${t.value?" = "+o:""}`);return t.body.length===0?i:i+Oe+nt(t.body,e+1,s)+Oe+r+$e("endset")}function yE(t,e,s){let r=s.repeat(e),n=t.args.map(oe).join(", ");return r+$e("macro",`${t.name.value}(${n})`)+Oe+nt(t.body,e+1,s)+Oe+r+$e("endmacro")}function bE(t,e,s){let r=s.repeat(e),n=t.callerArgs&&t.callerArgs.length>0?`(${t.callerArgs.map(oe).join(", ")})`:"",o=oe(t.call),i=r+$e(`call${n}`,o)+Oe;return i+=nt(t.body,e+1,s)+Oe,i+=r+$e("endcall"),i}function kE(t,e,s){let r=s.repeat(e),n=t.filter.type==="Identifier"?t.filter.value:oe(t.filter),o=r+$e("filter",n)+Oe;return o+=nt(t.body,e+1,s)+Oe,o+=r+$e("endfilter"),o}function oe(t,e=-1){switch(t.type){case"SpreadExpression":return`*${oe(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=fE(s),n=oe(s.left,r),o=oe(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"?" ":"")+oe(s.argument,1/0)}case"CallExpression":{let s=t,r=s.args.map(oe).join(", ");return`${oe(s.callee)}(${r})`}case"MemberExpression":{let s=t,r=oe(s.object);["Identifier","MemberExpression","CallExpression","StringLiteral","IntegerLiteral","FloatLiteral","ArrayLiteral","TupleLiteral","ObjectLiteral"].includes(s.object.type)||(r=`(${r})`);let n=oe(s.property);return!s.computed&&s.property.type!=="Identifier"&&(n=`(${n})`),s.computed?`${r}[${n}]`:`${r}.${n}`}case"FilterExpression":{let s=t,r=oe(s.operand,1/0);return s.filter.type==="CallExpression"?`${r} | ${oe(s.filter)}`:`${r} | ${s.filter.value}`}case"SelectExpression":{let s=t;return`${oe(s.lhs)} if ${oe(s.test)}`}case"TestExpression":{let s=t;return`${oe(s.operand)} is${s.negate?" not":""} ${s.test.value}`}case"ArrayLiteral":case"TupleLiteral":{let s=t.value.map(oe),r=t.type==="ArrayLiteral"?"[]":"()";return`${r[0]}${s.join(", ")}${r[1]}`}case"ObjectLiteral":return`{${Array.from(t.value.entries()).map(([r,n])=>`${oe(r)}: ${oe(n)}`).join(", ")}}`;case"SliceExpression":{let s=t,r=s.start?oe(s.start):"",n=s.stop?oe(s.stop):"",o=s.step?`:${oe(s.step)}`:"";return`${r}:${n}${o}`}case"KeywordArgumentExpression":{let s=t;return`${s.key.value}=${oe(s.value)}`}case"Ternary":{let s=t,r=`${oe(s.trueExpr)} if ${oe(s.condition,0)} else ${oe(s.falseExpr)}`;return e>-1?`(${r})`:r}default:throw new Error(`Unknown expression type: ${t.type}`)}}var Vy=class{parsed;constructor(t){let e=Cv(t,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=sE(e)}render(t){let e=new Qt;if(pE(e),t)for(let[n,o]of Object.entries(t))e.set(n,o);return new uE(e).run(this.parsed).value}format(t){return mE(this.parsed,t?.indent||" ")}};var Me=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 vE={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"},At=class t{constructor(e){if(this.filePath=e,this.headers=new Headers,this.exists=Ne.existsSync(e),this.exists){this.status=200,this.statusText="OK";let s=Ne.statSync(e);this.headers.set("content-length",s.size.toString()),this.updateContentType();let r=Ne.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",vE[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 Ne.promises.readFile(this.filePath)).buffer}async blob(){let e=await Ne.promises.readFile(this.filePath);return new Blob([e],{type:this.headers.get("content-type")})}async text(){return await Ne.promises.readFile(this.filePath,"utf8")}async json(){return JSON.parse(await this.text())}};var Ts=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(V.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[Hy(this._random_fn,s)]}};function Hy(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 ut=new Ts,Jt=Object.freeze({Random:Ts,seed:ut.seed.bind(ut),random:ut.random.bind(ut),gauss:ut.gauss.bind(ut),shuffle:ut.shuffle.bind(ut),choices:ut.choices.bind(ut)}),Ky=t=>Hy(Jt.random,t);var EE=new Ts,Cs=class{constructor(e){this.path=e}async match(e){let s=Xe.join(this.path,e),r=new At(s);if(r.exists)return r}async put(e,s,r=void 0){let n=Xe.join(this.path,e),o=V.IS_PROCESS_AVAILABLE?process.pid:Date.now(),i=EE._int32().toString(36),a=n+`.tmp.${o}.${i}`;try{let l=s.headers.get("Content-Length"),c=parseInt(l??"0"),p=0;await Ne.promises.mkdir(Xe.dirname(n),{recursive:!0});let u=Ne.createWriteStream(a),_=s.body.getReader();for(;;){let{done:d,value:m}=await _.read();if(d)break;await new Promise((g,x)=>{u.write(m,w=>{if(w){x(w);return}g()})}),p+=m.length;let h=c?p/c*100:0;r?.({progress:h,loaded:p,total:c})}await new Promise((d,m)=>{u.close(h=>h?m(h):d())}),await Ne.promises.rename(a,n)}catch(l){try{await Ne.promises.unlink(a)}catch{}throw l}}async delete(e){let s=Xe.join(this.path,e);try{return await Ne.promises.unlink(s),!0}catch{return!1}}};var Xy={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"},ea=100,Qy=/^(\b[\w\-.]+\b\/)?\b[\w\-.]{1,96}\b$/;function Tr(...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 Mt(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 Yy(t){return!(!Qy.test(t)||t.includes("..")||t.includes("--")||t.endsWith(".git")||t.endsWith(".ipynb"))}function Jy(t,e,s){if(!s)return null;let r=Xy[t]??`Error (${t}) occurred while trying to load file`;throw Error(`${r}: "${e}".`)}async function Zy(t,e,s){let r=t.headers.get("Content-Length"),n=r?parseInt(r,10):s??0;r===null&&!s&&F.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:p}=await a.read();if(c)return;let u=i+p.length;if(u>n){n=u;let d=new Uint8Array(n);d.set(o),o=d}o.set(p,i),i=u;let _=i/n*100;return e({progress:_,loaded:i,total:n}),l()}return await l(),o}function Lc(t){return Mt(t,["blob:"])}function Nc(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}var t0="SHA-256",AE="experimental_transformers-hash-cache",e0=t=>({algorithm:t0,value:t}),Cr=class{#t=null;_getHashCache=()=>(this.#t??=caches.open(AE),this.#t);static isAvailable=()=>typeof navigator<"u"&&"crossOriginStorage"in navigator;match=async e=>{let s=await this._getFileHash(e);if(s)try{let[r]=await navigator.crossOriginStorage.requestFileHandles([e0(s)]),n=await r.getFile();return new Response(n,{headers:{"Content-Length":String(n.size)}})}catch{return}};put=async(e,s)=>{let r=await this._getFileHash(e);if(r){let n=await s.blob();await this._storeBlobInCOS(n,r)}else this._processAndStore(e,s.body)};_storeBlobInCOS=async(e,s)=>{let[r]=await navigator.crossOriginStorage.requestFileHandles([e0(s)],{create:!0}),n=await r.createWritable();await n.write(e),await n.close()};_processAndStore=async(e,s)=>{try{let r=[];for await(let i of s)r.push(i);let n=new Blob(r),o=await this._getBlobHash(n);await this._storeBlobInCOS(n,o);try{await(await this._getHashCache()).put(e,new Response(o))}catch{}}catch{}};delete=async e=>{try{return await(await this._getHashCache()).delete(e)}catch{return!1}};_getFileHash=async e=>{try{let s=await this._getHashCache(),r=await s.match(e);if(r)return r.text();let n=await this._getLfsFileHash(e);return n?(await s.put(e,new Response(n)),n):null}catch{return null}};_getLfsFileHash=async e=>{if(!e.includes("/resolve/"))return null;let s=e.replace("/resolve/","/raw/");try{let n=(await fetch(s).then(o=>o.text())).match(/^oid sha256:([0-9a-f]+)$/m);return n?n[1]:null}catch{return null}};_getBlobHash=async e=>{let s=await e.arrayBuffer(),r=await crypto.subtle.digest(t0,s);return Array.from(new Uint8Array(r)).map(o=>o.toString(16).padStart(2,"0")).join("")}};async function it(t=null){let e=null;if(Y.useCustomCache){if(!Y.customCache)throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");if(!Y.customCache.match||!Y.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=Y.customCache}if(!e&&Y.experimental_useCrossOriginStorage&&Cr.isAvailable()&&(e=new Cr),!e&&Y.useBrowserCache){if(typeof caches>"u")throw Error("Browser cache is not available in this environment.");try{e=await caches.open(Y.cacheKey)}catch(s){F.warn("An error occurred while opening the browser cache:",s)}}if(!e&&Y.useFSCache){if(!V.IS_FS_AVAILABLE)throw Error("File System Cache is not available in this environment.");e=new Cs(t??Y.cacheDir)}return e}async function s0(t,...e){for(let s of e)try{let r=await t.match(s);if(r)return r}catch{continue}}var ta=class{#t;#e;constructor(e){this.#t=e,this.#e=new Map}get(e){if(!this.#e.has(e))return;let s=this.#e.get(e);return this.#e.delete(e),this.#e.set(e,s),s}put(e,s){this.#e.has(e)&&this.#e.delete(e),this.#e.set(e,s),this.#e.size>this.#t&&this.#e.delete(this.#e.keys().next().value)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}};var ME=100,Fc=new ta(ME);function sa(t,e){let s=Fc.get(t);if(s!==void 0)return s;let r=e().then(n=>n,n=>(Fc.delete(t),Promise.reject(n)));return Fc.put(t,r),r}async function SE(t){if(!Mt(t,["http:","https:"]))return null;let e=$c(t);return e.set("Range","bytes=0-0"),Y.fetch(t,{method:"GET",headers:e,cache:"no-store"})}function _t(t,e,s={}){let r=JSON.stringify([t,e,s?.revision,s?.cache_dir,s?.local_files_only]);return sa(r,()=>OE(t,e,s))}async function OE(t,e,s){let r=await it(s?.cache_dir),{localPath:n,remoteURL:o,proposedCacheKey:i,validModelId:a}=Ot(t,e,s,r),l=await It(r,n,i);if(l!==void 0&&typeof l!="string"){let c=l.headers.get("content-length"),p=l.headers.get("content-type");return{exists:!0,size:c?parseInt(c,10):void 0,contentType:p||void 0,fromCache:!0}}if(Y.allowLocalModels&&!Mt(n,["http:","https:"]))try{let p=await St(n);if(typeof p!="string"&&p.status!==404){let u=p.headers.get("content-length"),_=p.headers.get("content-type");return{exists:!0,size:u?parseInt(u,10):void 0,contentType:_||void 0,fromCache:!1}}}catch{}if(Y.allowRemoteModels&&!s.local_files_only&&a)try{let c=await SE(o);if(c&&c.status>=200&&c.status<300){let p,u=c.headers.get("content-type");if(c.status===206){let _=c.headers.get("content-range");if(_){let d=_.match(/bytes \d+-\d+\/(\d+)/);d&&(p=parseInt(d[1],10))}}else if(c.status===200)try{await c.body?.cancel()}catch{}if(p===void 0){let _=c.headers.get("content-length");p=_?parseInt(_,10):void 0}return{exists:!0,size:p,contentType:u||void 0,fromCache:!1}}}catch(c){F.warn(`Unable to fetch file metadata for "${o}": ${c}`)}return{exists:!1,fromCache:!1}}async function St(t){return Y.useFS&&!Mt(t,["http:","https:","blob:"])?new At(t instanceof URL?t.protocol==="file:"?t.pathname:t.toString():t):Y.fetch(t,{headers:$c(t)})}function $c(t){let e=typeof process<"u"&&process?.release?.name==="node",s=new Headers;if(e){let r=!!process.env?.TESTING_REMOTELY,n=Y.version;if(s.set("User-Agent",`transformers.js/${n}; is_ci/${r};`),Mt(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 Ot(t,e,s={},r=null){let n=s.revision??"main",o=Tr(t,e),i=Yy(t),a=i?Tr(Y.localModelPath,o):o,l=Tr(Y.remoteHost,Y.remotePathTemplate.replaceAll("{model}",t).replaceAll("{revision}",encodeURIComponent(n)),e),c=r instanceof Cs?n==="main"?o:Tr(t,n,e):l;return{requestURL:o,localPath:a,remoteURL:l,proposedCacheKey:c,validModelId:i}}async function It(t,e,s){if(t)return await s0(t,e,s)}async function IE(t,e,s,r,n,o,i={}){if(await s.match(r)===void 0)if(o){if(typeof n!="string"){let a=new Headers(n.headers);a.set("content-length",o.byteLength.toString()),await s.put(r,new Response(o,{headers:a})).catch(l=>{F.warn(`Unable to add response to browser cache: ${l}.`)})}}else{let a=i.progress_callback?l=>gt(i.progress_callback,{status:"progress",name:t,file:e,...l}):void 0;await s.put(r,n,a)}}async function zE(t,e,s=!0,r={},n=!1,o=null){let{requestURL:i,localPath:a,remoteURL:l,proposedCacheKey:c,validModelId:p}=Ot(t,e,r,o),u,_=!1,d;d=await It(o,a,c);let m=d!==void 0;if(!m){if(Y.allowLocalModels)if(Mt(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(!Y.allowRemoteModels)throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${i}.`)}else try{d=await St(a),u=a}catch(w){F.warn(`Unable to load from local path "${a}": "${w}"`)}if(d===void 0||typeof d!="string"&&d.status===404){if(r.local_files_only||!Y.allowRemoteModels){if(s)throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${a}".`);return null}if(!p)throw Error(`Local file missing at "${a}" and download aborted due to invalid model ID "${t}".`);if(d=await St(l),d.status!==200)return Jy(d.status,l,s);u=c}_=o&&typeof Response<"u"&&d instanceof Response&&d.status===200}gt(r.progress_callback,{status:"download",name:t,file:e});let h;if(!(V.IS_NODE_ENV&&n)){let x;if(typeof d!="string")if(!r.progress_callback)x=new Uint8Array(await d.arrayBuffer());else if(m&&typeof navigator<"u"&&/firefox/i.test(navigator.userAgent))x=new Uint8Array(await d.arrayBuffer()),gt(r.progress_callback,{status:"progress",name:t,file:e,progress:100,loaded:x.length,total:x.length});else{let w,y=d.headers.get("content-length");if(y)w=parseInt(y,10);else try{let b=await _t(t,e,r);b.size&&(w=b.size)}catch{}x=await Zy(d,b=>{gt(r.progress_callback,{status:"progress",name:t,file:e,...b})},w)}h=x}if(_&&u&&typeof d!="string"&&await IE(t,e,o,u,d,h,r),gt(r.progress_callback,{status:"done",name:t,file:e}),h){if(!V.IS_NODE_ENV&&n)throw new Error("Cannot return path in a browser environment.");return h}if(d instanceof At)return d.filePath;let g=await o?.match(u);if(g instanceof At)return g.filePath;if(g instanceof Response)return new Uint8Array(await g.arrayBuffer());if(typeof g=="string")return g;throw new Error("Unable to get model file path or buffer.")}async function Pr(t,e,s=!0,r={},n=!1){if(!Y.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(!Y.allowRemoteModels)throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.")}gt(r.progress_callback,{status:"initiate",name:t,file:e});let o=await it(r?.cache_dir);return await zE(t,e,s,r,n,o)}async function Rc(t,e,s=!0,r={}){let n=await Pr(t,e,s,r,!1);return n===null?null:new TextDecoder("utf-8").decode(n)}async function Ce(t,e,s=!0,r={}){let n=await Rc(t,e,s,r);return n===null?{}:JSON.parse(n)}function n0(t,[e,s,r],[n,o],i="bilinear",a=!1){let l=o/r,c=n/s,p=new t.constructor(n*o*e),u=s*r,_=n*o;for(let d=0;d<n;++d)for(let m=0;m<o;++m){let h=d*o+m,g=(m+.5)/l-.5,x=(d+.5)/c-.5,w=Math.floor(g),y=Math.floor(x),b=Math.min(w+1,r-1),E=Math.min(y+1,s-1);w=Math.max(w,0),y=Math.max(y,0);let k=g-w,O=x-y,N=(1-k)*(1-O),j=k*(1-O),C=(1-k)*O,R=k*O,$=y*r,q=E*r,B=$+w,G=$+b,Z=q+w,te=q+b;for(let M=0;M<e;++M){let S=M*u;p[M*_+h]=N*t[S+B]+j*t[S+G]+C*t[S+Z]+R*t[S+te]}}return p}function o0(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,p=a;c>=0;--c)l+=p%e[c]*o[c],p=Math.floor(p/e[c]);i[l]=t[a]}return[i,r]}function de(t){let e=pe(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 jc(t){let e=pe(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 i0(t,e){let s=0;for(let r=0;r<t.length;++r)s+=t[r]*e[r];return s}function TE(t,e){let s=i0(t,e),r=r0(t),n=r0(e);return s/(r*n)}function r0(t){return Math.sqrt(t.reduce((e,s)=>e+s*s,0))}function Lr(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 pe(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 a0(t){return t>0&&(t&t-1)===0}var ra=class{constructor(e){if(this.size=e|0,this.size<=1||!a0(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,p=this._bitrev;if(a===4)for(l=0,c=0;l<n;l+=a,++c){let _=p[c];this._singleTransform2(s,e,l,_,i)}else for(l=0,c=0;l<n;l+=a,++c){let _=p[c];this._singleTransform4(s,e,l,_,i,r)}let u=this.table;for(i>>=2;i>=2;i>>=2){a=n/i<<1;let _=a>>>2;for(l=0;l<n;l+=a){let d=l+_-1;for(let m=l,h=0;m<d;m+=2,h+=i){let g=m,x=g+_,w=x+_,y=w+_,b=e[g],E=e[g+1],k=e[x],O=e[x+1],N=e[w],j=e[w+1],C=e[y],R=e[y+1],$=u[h],q=r*u[h+1],B=k*$-O*q,G=k*q+O*$,Z=u[2*h],te=r*u[2*h+1],M=N*Z-j*te,S=N*te+j*Z,z=u[3*h],H=r*u[3*h+1],he=C*z-R*H,se=C*H+R*z,Ke=b+M,We=E+S,kr=b-M,vr=E-S,Es=B+he,As=G+se,Er=r*(B-he),Ar=r*(G-se);e[g]=Ke+Es,e[g+1]=We+As,e[x]=kr+Ar,e[x+1]=vr-Er,e[w]=Ke-Es,e[w+1]=We-As,e[y]=kr-Ar,e[y+1]=vr+Er}}}}_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],p=e[n+1],u=e[n+o],_=e[n+o+1],d=e[n+a],m=e[n+a+1],h=e[n+l],g=e[n+l+1],x=c+d,w=p+m,y=c-d,b=p-m,E=u+h,k=_+g,O=i*(u-h),N=i*(_-g);s[r]=x+E,s[r+1]=w+k,s[r+2]=y+N,s[r+3]=b-O,s[r+4]=x-E,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,p=this._bitrev;if(a===4)for(l=0,c=0;l<n;l+=a,++c){let d=p[c];this._singleRealTransform2(s,e,l,d>>>1,i>>>1)}else for(l=0,c=0;l<n;l+=a,++c){let d=p[c];this._singleRealTransform4(s,e,l,d>>>1,i>>>1,r)}let u=this.table;for(i>>=2;i>=2;i>>=2){a=n/i<<1;let d=a>>>1,m=d>>>1,h=m>>>1;for(l=0;l<n;l+=a)for(let g=0,x=0;g<=h;g+=2,x+=i){let w=l+g,y=w+m,b=y+m,E=b+m,k=e[w],O=e[w+1],N=e[y],j=e[y+1],C=e[b],R=e[b+1],$=e[E],q=e[E+1],B=k,G=O,Z=u[x],te=r*u[x+1],M=N*Z-j*te,S=N*te+j*Z,z=u[2*x],H=r*u[2*x+1],he=C*z-R*H,se=C*H+R*z,Ke=u[3*x],We=r*u[3*x+1],kr=$*Ke-q*We,vr=$*We+q*Ke,Es=B+he,As=G+se,Er=B-he,Ar=G-se,kc=M+kr,vc=S+vr,oy=r*(M-kr),iy=r*(S-vr);if(e[w]=Es+kc,e[w+1]=As+vc,e[y]=Er+iy,e[y+1]=Ar-oy,g===0){e[b]=Es-kc,e[b+1]=As-vc;continue}if(g===h)continue;let ay=l+m-g,ly=l+d-g;e[ay]=Er-r*iy,e[ay+1]=-Ar-r*oy,e[ly]=Es-r*kc,e[ly+1]=-As+r*vc}}let _=n>>>1;for(let d=2;d<_;d+=2)e[n-d]=e[d],e[n-d+1]=-e[d+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],p=e[n+o],u=e[n+a],_=e[n+l],d=c+u,m=c-u,h=p+_,g=i*(p-_);s[r]=d+h,s[r+1]=0,s[r+2]=m,s[r+3]=-g,s[r+4]=d-h,s[r+5]=0,s[r+6]=m,s[r+7]=g}},Dc=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 p=0;p<r>>1;++p){let u=(p+1-e)**2/2,_=Math.sqrt(l**2+c**2)**u,d=u*Math.atan2(c,l),m=2*p;o[m]=_*Math.cos(d),o[m+1]=_*Math.sin(d),i[m]=o[m],i[m+1]=-o[m+1]}this._slicedChirpBuffer=o.subarray(s,r),this._f=new ra(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,p=this._a;if(r)for(let u=0;u<c.length;u+=2){let _=u+1,d=u>>1,m=s[d];n[u]=m*c[u],n[_]=m*c[_]}else for(let u=0;u<c.length;u+=2){let _=u+1;n[u]=s[u]*c[u]-s[_]*c[_],n[_]=s[u]*c[_]+s[_]*c[u]}this._f.transform(i,n);for(let u=0;u<l.length;u+=2){let _=u+1;o[u]=i[u]*l[u]-i[_]*l[_],o[_]=i[u]*l[_]+i[_]*l[u]}this._f.inverseTransform(a,o);for(let u=0;u<a.length;u+=2){let _=a[u+p],d=a[u+p+1],m=c[u],h=c[u+1];e[u]=_*m-d*h,e[u+1]=_*h+d*m}}transform(e,s){this._transform(e,s,!1)}realTransform(e,s){this._transform(e,s,!0)}},na=class{constructor(e){this.fft_length=e,this.isPowerOfTwo=a0(e),this.isPowerOfTwo?(this.fft=new ra(e),this.outputBufferSize=2*e):(this.fft=new Dc(e),this.outputBufferSize=this.fft.bufferSize)}realTransform(e,s){this.fft.realTransform(e,s)}transform(e,s){this.fft.transform(e,s)}};function l0(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 Zt(t,e){let s=Math.pow(10,e);return Math.round(t*s)/s}function c0(t){let e=Math.round(t);return Math.abs(t)%1===.5?e%2===0?e:e-1:e}function p0(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 p=1;p<r[1];++p)for(let u=1;u<r[0];++u){let _=n[u-1][p-1],d=n[u-1][p],m=n[u][p-1],h,g;_<d&&_<m?(h=_,g=0):d<_&&d<m?(h=d,g=1):(h=m,g=2),n[u][p]=t[u-1][p-1]+h,o[u][p]=g}for(let p=0;p<r[1];++p)o[0][p]=2;for(let p=0;p<r[0];++p)o[p][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 u0=(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,p=(l&32768)<<16,u=(l&31744)>>10,_=l&1023;if(u===31)c=p|2139095040|_<<13;else if(u===0)if(_===0)c=p;else{let d=113;for(;(_&1024)===0;)_<<=1,--d;_&=-1025,c=p|d<<23|_<<13}else c=p|u+112<<23|_<<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 Bc={};Ms(Bc,{default:()=>CE});var CE={};import*as PE from"onnxruntime-web/webgpu";async function _0(t){let e=t.split("/").pop(),s;try{if(s=await it(),s){let n=await s.match(t);if(n)return n}}catch(n){F.warn(`Failed to load ${e} from cache:`,n)}let r=await Y.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){F.warn(`Failed to cache ${e}:`,n)}return r}async function d0(t){let e=await _0(t);if(!e||typeof e=="string")return null;try{return await e.arrayBuffer()}catch(s){return F.warn("Failed to read WASM binary:",s),null}}async function f0(t){if(V.IS_SERVICE_WORKER_ENV||V.IS_CHROME_AVAILABLE)return t;let e=await _0(t);if(!e||typeof e=="string")return null;try{let s=await e.text();s=s.replaceAll("globalThis.process?.versions?.node","false");let r=new Blob([s],{type:"text/javascript"});return URL.createObjectURL(r)}catch(s){return F.warn("Failed to read WASM factory:",s),null}}import{Tensor as y0}from"onnxruntime-common";var LE=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 x0(t){return t<=Be.DEBUG?0:t<=Be.INFO?2:t<=Be.WARNING||t<=Be.ERROR?3:4}var NE={0:"verbose",1:"info",2:"warning",3:"error",4:"fatal"},Je=[],qc,Ls,m0=Symbol.for("onnxruntime");if(m0 in globalThis)Ls=globalThis[m0];else if(V.IS_NODE_ENV){switch(Ls=Bc,process.platform){case"win32":Je.push("dml");break;case"linux":process.arch==="x64"&&Je.push("cuda");break;case"darwin":Je.push("coreml");break}Je.push("webgpu"),Je.push("cpu"),qc=["cpu"]}else Ls=PE,V.IS_WEBNN_AVAILABLE&&Je.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),V.IS_WEBGPU_AVAILABLE&&Je.push("webgpu"),Je.push("wasm"),qc=["wasm"];var FE=Ls.InferenceSession;function w0(t=null){if(!t)return qc;switch(t){case"auto":return Je;case"gpu":return Je.filter(e=>["webgpu","cuda","dml","webnn-gpu"].includes(e))}if(Je.includes(t))return[LE[t]??t];throw new Error(`Unsupported device: "${t}". Should be one of: ${Je.join(", ")}.`)}var h0=Promise.resolve(),Ps=null;async function $E(){if(Ps)return Ps;if(!(Y.useWasmCache&&typeof Ie?.wasm?.wasmPaths=="object"&&Ie?.wasm?.wasmPaths?.wasm&&Ie?.wasm?.wasmPaths?.mjs)){if(V.IS_DENO_WEB_RUNTIME)throw new Error("env.useWasmCache=false is not supported in Deno's web runtime. Remove the useWasmCache override.");return Ps=Promise.resolve(),Ps}return Ps=(async()=>{let e=Ie.wasm.wasmPaths,s=!1;await Promise.all([e.wasm&&!Lc(e.wasm)?(async()=>{try{let r=await d0(Nc(e.wasm));r&&(Ie.wasm.wasmBinary=r,s=!0)}catch(r){F.warn("Failed to pre-load WASM binary:",r)}})():Promise.resolve(),e.mjs&&!Lc(e.mjs)?(async()=>{try{let r=await f0(Nc(e.mjs));r&&(Ie.wasm.wasmPaths.mjs=r)}catch(r){F.warn("Failed to pre-load WASM factory:",r)}})():Promise.resolve()]),s||(Ie.wasm.wasmPaths.mjs=e.mjs)})(),Ps}async function oa(t,e,s){await $E();let r=x0(Y.logLevel??Be.WARNING),n=()=>FE.create(t,{logSeverityLevel:r,...e}),o=await(V.IS_WEB_ENV?h0=h0.then(n):n());return o.config=s,o}var g0=Promise.resolve();async function ia(t,e){let s=()=>t.run(e);return V.IS_WEB_ENV?g0=g0.then(s):s()}function aa(t){return t instanceof Ls.Tensor}var Ie=Ls?.env;function Nr(){return Ie?.wasm?.proxy}if(Ie){let t=function(e){let s=x0(e);Ie.logLevel=NE[s]};if(Ie.wasm){if(!(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope)&&Ie.versions?.web&&!Ie.wasm.wasmPaths){let e=`https://cdn.jsdelivr.net/npm/onnxruntime-web@${Ie.versions.web}/dist/`;Ie.wasm.wasmPaths=V.IS_SAFARI?{mjs:`${e}ort-wasm-simd-threaded.mjs`,wasm:`${e}ort-wasm-simd-threaded.wasm`}:{mjs:`${e}ort-wasm-simd-threaded.asyncify.mjs`,wasm:`${e}ort-wasm-simd-threaded.asyncify.wasm`}}Ie.wasm.proxy=!1}Ie.webgpu&&(Ie.webgpu.powerPreference="high-performance"),t(Y.logLevel??Be.WARNING),Y.backends.onnx={...Ie,setLogLevel:t}}var zt=async(t,e,s)=>{let r=await oa(new Uint8Array(t),e);return(async n=>{let o=Nr(),i=Object.fromEntries(Object.entries(n).map(([l,c])=>[l,(o?c.clone():c).ort_tensor])),a=await ia(r,i);return Array.isArray(s)?s.map(l=>new v(a[l])):new v(a[s])})},dt=class{static session_options={};static get nearest_interpolate_4d(){return this._nearest_interpolate_4d||(this._nearest_interpolate_4d=zt([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=zt([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=zt([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=zt([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=zt([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=zt([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=zt([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=zt([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 b0=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"}),Uc=V.IS_NODE_ENV?"cpu":"wasm";function la(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 (${Uc}).`),Uc):Uc}var E0=(function(){let t;return async function(){if(t===void 0)if(!V.IS_WEBGPU_AVAILABLE)t=!1;else try{t=(await navigator.gpu.requestAdapter()).features.has("shader-f16")}catch{t=!1}return t}})(),Re=Object.freeze({auto:"auto",fp32:"fp32",fp16:"fp16",q8:"q8",int8:"int8",uint8:"uint8",q4:"q4",bnb4:"bnb4",q4f16:"q4f16"}),k0=Re.fp32,v0=Object.freeze({[b0.wasm]:Re.q8}),Fr=Object.freeze({[Re.fp32]:"",[Re.fp16]:"_fp16",[Re.int8]:"_int8",[Re.uint8]:"_uint8",[Re.q8]:"_quantized",[Re.q4]:"_q4",[Re.q4f16]:"_q4f16",[Re.bnb4]:"_bnb4"});function ca(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===Re.auto){if(r){let l=typeof r=="string"?r:r?.[e];if(l&&l!==Re.auto&&Re.hasOwnProperty(l))return l}a=v0[s]??k0}else o&&Re.hasOwnProperty(o)?a=o:a=v0[s]??k0;return i&&n&&n(`dtype not specified for "${e}". Using the default dtype (${a}) for this device (${s}).`),a}var wt=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 v=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 aa(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new y0(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=ft(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 RE(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 p=0;p<this.dims.length;++p){let u=e[p];if(u==null)r.push([0,this.dims[p]]),s.push(this.dims[p]);else if(typeof u=="number")u=ft(u,this.dims[p],p),r.push([u,u+1]);else if(Array.isArray(u)&&u.length===2){let[_,d]=u;if(_=_===null?0:ft(_,this.dims[p],p,!1),d=d===null?this.dims[p]:ft(d,this.dims[p],p,!1),_>d)throw new Error(`Invalid slice: ${u}`);let m=[Math.max(_,0),Math.min(d,this.dims[p])];r.push(m),s.push(m[1]-m[0])}else throw new Error(`Invalid slice: ${u}`)}let n=r.map(([p,u])=>u-p),o=n.reduce((p,u)=>p*u),i=this.data,a=new i.constructor(o),l=this.stride(),c=!0;for(let p=1;p<n.length;++p)if(r[p][0]!==0||r[p][1]!==this.dims[p]){c=!1;break}if(c){let p=r[0][0]*l[0],u=r[0][1]*l[0];if(ArrayBuffer.isView(i))a.set(i.subarray(p,u));else if(Array.isArray(i)){let _=i.slice(p,u);for(let d=0;d<_.length;++d)a[d]=_[d]}else throw new Error("Unsupported data type for slicing")}else for(let p=0;p<o;++p){let u=0;for(let _=n.length-1,d=p;_>=0;--_){let m=n[_];u+=(d%m+r[_][0])*l[_],d=Math.floor(d/m)}a[p]=i[u]}return new t(this.type,a,s)}permute(...e){return DE(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=n instanceof BigInt64Array||n instanceof BigUint64Array;if(o&&e!==1)throw Error(`Expected a floating point tensor as input. Got ${this.type}`);let i,a;if(o?(i=(u,_)=>u+_,a=0n):(i=(u,_)=>u+_**e,a=0),s===null){let u=n.reduce(i,a);return e!==1&&(u=u**(1/e)),new t(this.type,[u],[])}let[l,c,p]=$r(i,this,s,r);if(e!==1)for(let u=0;u<c.length;++u)c[u]=c[u]**(1/e);return new t(l,c,p)}normalize_(e=2,s=1){s=ft(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,p=1;l>=0;--l){let u=this.dims[l];if(l!==s){let _=c%u;a+=_*p,p*=this.dims[l]}c=Math.floor(c/u)}n[i]/=o[a]}return this}normalize(e=2,s=1){return this.clone().normalize_(e,s)}stride(){return Gc(this.dims)}squeeze(e=null){return new t(this.type,this.data,A0(this.dims,e))}squeeze_(e=null){return this.dims=A0(this.dims,e),this}unsqueeze(e){return new t(this.type,this.data,M0(this.dims,e))}unsqueeze_(e){return this.dims=M0(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 _a(this,e,s)}min(e=null,s=!1){if(e===null){let i=Lr(this.data)[0];return new t(this.type,[i],[])}let[r,n,o]=$r((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=pe(this.data)[0];return new t(this.type,[i],[])}let[r,n,o]=$r((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=Lr(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=pe(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(p=>p===1)){if(e.length===this.dims.length)return this.clone();let p=e.length-this.dims.length,u=Array(p).fill(1).concat(this.dims);return new t(this.type,this.data.slice(),u)}let s=e.length-this.dims.length,r=Array(s).fill(1).concat(this.dims),n=r.map((p,u)=>p*e[u]),o=n.reduce((p,u)=>p*u,1),i=this.data,a=new i.constructor(o),l=Gc(r),c=Gc(n);for(let p=0;p<o;++p){let u=p,_=0;for(let d=0;d<n.length;++d){let m=Math.floor(u/c[d]);u=u%c[d];let h=m%r[d];_+=h*l[d]}a[p]=i[_]}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(!wt.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,u0(this.data),this.dims);return new t(e,wt[e].from(this.data,s),this.dims)}};function RE(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 DE(t,e){let[s,r]=o0(t.data,t.dims,e);return new v(t.type,s,r)}function Wc(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=n0(t.data,[o,i,a],[e,s],r,n);return new v(t.type,l,[o,e,s])}async function De(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 dt.nearest_interpolate_4d;else if(s==="bilinear")n=await dt.bilinear_interpolate_4d;else if(s==="bicubic")n=await dt.bicubic_interpolate_4d;else throw new Error(`Unsupported mode: ${s}`);let o=new v("int64",new BigInt64Array(r.map(BigInt)),[r.length]);return await n({x:t,s:o})}async function S0(t,e){return await(await dt.matmul)({a:t,b:e})}async function y2(t,e){return await(await dt.rfft)({x:t,a:e})}async function at(t,e){let s=await dt.top_k;return e==null?e=t.dims.at(-1):e=Math.min(e,t.dims.at(-1)),await s({x:t,k:new v("int64",[BigInt(e)],[1])})}var pa=t=>new v("int64",t,[t.length]);async function ua(t,e,s,r,n){return await(await dt.slice)({x:t,s:pa(e),e:pa(s),a:pa(r),t:pa(n??new Array(r.length).fill(1))})}function O0(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 p=0;p<i;++p){let u=p*l*a;for(let _=0;_<l;++_){let d=0,m=0,h=p*a,g=u+_;for(let w=0;w<a;++w){let y=Number(r[h+w]);m+=y,d+=s[g+w*l]*y}let x=d/m;o[c++]=x}}return new v(t.type,o,n)}function b2(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,p=new c.constructor(c.length);for(let u=0;u<r;++u){let _=u*n;for(let d=0;d<n;++d){let m=_+d;p[m]=(c[m]-l[u])/(a[u]+s)}}return new v(t.type,p,t.dims)}function A0(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 M0(t,e){return e=ft(e,t.length+1),t=t.slice(),t.splice(e,0,1),t}function ft(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=ft(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 p=0;p<l.length;++p){let u=0;for(let _=c.length-1,d=p,m=1;_>=0;--_){let h=c[_],g=d%h;_===e&&(g+=i),u+=g*m,m*=s[_],d=Math.floor(d/h)}n[u]=l[p]}i+=c[e]}}return new v(o,n,s)}function qe(t,e=0){return ie(t.map(s=>s.unsqueeze(e)),e)}function $r(t,e,s,r=!1,n=null){let o=e.data,i=e.dims;s=ft(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 p=0;for(let u=i.length-1,_=c,d=1;u>=0;--u){let m=i[u];if(u!==s){let h=_%m;p+=h*d,d*=a[u]}_=Math.floor(_/m)}l[p]=t(l[p],o[c],c,p)}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 d=n.reduce((x,w)=>x+w,0)/n.length,m=Math.sqrt(n.reduce((x,w)=>x+(w-d)**2,0)/(n.length-s)),h=new v(t.type,[d],[]);return[new v(t.type,[m],[]),h]}e=ft(e,o.length);let i=_a(t,e,r),a=i.data,[l,c,p]=$r((_,d,m,h)=>_+(d-a[h])**2,t,e,r);for(let _=0;_<c.length;++_)c[_]=Math.sqrt(c[_]/(o[e]-s));return[new v(l,c,p),i]}function _a(t,e=null,s=!1){let r=t.dims,n=t.data;if(e===null){let l=n.reduce((c,p)=>c+p,0);return new v(t.type,[l/n.length],[])}e=ft(e,r.length);let[o,i,a]=$r((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 v(o,i,a)}function Gc(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 Hc(t,e,s,r){let n=t.reduce((o,i)=>o*i,1);return new v(s,new r(n).fill(e),t)}function ye(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 Hc(t,e,s,r)}function Rr(t,e){return ye(t.dims,e)}function Se(t){return Hc(t,1n,"int64",BigInt64Array)}function da(t){return Se(t.dims)}function Kc(t){return Hc(t,0n,"int64",BigInt64Array)}function Xc(t){return Kc(t.dims)}function k2(t){let e=t.reduce((s,r)=>s*r,1);return new v("float32",Float32Array.from({length:e},()=>Jt.random()),t)}function I0(t){let e=t.reduce((s,r)=>s*r,1);return new v("float32",Float32Array.from({length:e},()=>Jt.gauss()),t)}function z0(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),p=a%8;i[c]|=l<<7-p,s&&p===0&&(i[c]-=128)}return new v(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 _t(t,"tokenizer_config.json",{})).exists?["tokenizer.json","tokenizer_config.json"]:[]}async function Qc(t,e){let s=await Ns(t);return await Promise.all(s.map(r=>Ce(t,r,!0,e)))}function Yc(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 jE=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function BE(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"?Fe(t[n],a):Fe(a,t[n])}}function qE(t,e){for(let s of Object.keys(t))t[s].length=e}function es(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 UE(t){let e=[];for(let s of t.get_added_tokens_decoder().values())s.special&&e.push(s);return e}var T=class extends Me{return_token_type_ids=!1;padding_side="right";constructor(e,s){if(super(),this._tokenizerJSON=e,this._tokenizerConfig=s,this._tokenizer=new Ly(e,s),this.config=s,this.padding_side=s.padding_side??this.padding_side,this.mask_token=es(s,"mask_token"),this.mask_token_id=this._tokenizer.token_to_id(this.mask_token),this.pad_token=es(s,"pad_token","eos_token"),this.pad_token_id=this._tokenizer.token_to_id(this.pad_token),this.sep_token=es(s,"sep_token"),this.sep_token_id=this._tokenizer.token_to_id(this.sep_token),this.unk_token=es(s,"unk_token"),this.unk_token_id=this._tokenizer.token_to_id(this.unk_token),this.bos_token=es(s,"bos_token"),this.bos_token_id=this._tokenizer.token_to_id(this.bos_token),this.eos_token=es(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=UE(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 Qc(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),p;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");p=e.map((_,d)=>this._encode_plus(_,{text_pair:s[d],add_special_tokens:r,return_token_type_ids:l}))}else p=e.map(_=>this._encode_plus(_,{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).");p=[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?(F.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&&(F.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(pe(p.map(_=>_.input_ids.length))[0],i??1/0)),i=Math.min(i,this.model_max_length??1/0),n||o)for(let _=0;_<p.length;++_)p[_].input_ids.length!==i&&(p[_].input_ids.length>i?o&&qE(p[_],i):n&&BE(p[_],i,d=>d==="input_ids"?this.pad_token_id:0,this.padding_side));let u={};if(a){if(!(n&&o)&&p.some(d=>{for(let m of Object.keys(d))if(d[m].length!==p[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 _=[p.length,p[0].input_ids.length];for(let d of Object.keys(p[0]))u[d]=new v("int64",BigInt64Array.from(p.flatMap(m=>m[d]).map(BigInt)),_)}else{for(let _ of Object.keys(p[0]))u[_]=p.map(d=>d[_]);if(!c)for(let _ of Object.keys(u))u[_]=u[_][0]}return u}_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 v&&(e=e.tolist()),e.map(r=>this.decode(r,s))}decode(e,s={}){if(e instanceof v&&(e=Yc(e)),!Array.isArray(e)||e.length===0||!hy(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:p=!0,return_dict:u=!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 Vy(n),this._compiled_template_cache.set(n,m));let h=Object.create(null);for(let x of jE){let w=es(this.config,x);w&&(h[x]=w)}let g=m.render({messages:e,add_generation_prompt:o,tools:s,documents:r,...h,...d});if(i){let x=this._call(g,{add_special_tokens:!1,padding:a,truncation:l,max_length:c,return_tensor:p,..._});return u?x:x.input_ids}return g}};function Fs(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 qp={};Ms(qp,{AlbertTokenizer:()=>Jc,AutoTokenizer:()=>W,BartTokenizer:()=>Zc,BertTokenizer:()=>ep,BlenderbotSmallTokenizer:()=>tp,BlenderbotTokenizer:()=>sp,BloomTokenizer:()=>rp,CLIPTokenizer:()=>op,CamembertTokenizer:()=>np,CodeGenTokenizer:()=>ap,CodeLlamaTokenizer:()=>ip,CohereTokenizer:()=>lp,ConvBertTokenizer:()=>cp,DebertaTokenizer:()=>up,DebertaV2Tokenizer:()=>pp,DistilBertTokenizer:()=>_p,ElectraTokenizer:()=>dp,EsmTokenizer:()=>fp,FalconTokenizer:()=>mp,GPT2Tokenizer:()=>xp,GPTNeoXTokenizer:()=>gp,GemmaTokenizer:()=>hp,HerbertTokenizer:()=>wp,LlamaTokenizer:()=>yp,M2M100Tokenizer:()=>bp,MBart50Tokenizer:()=>vp,MBartTokenizer:()=>Dr,MPNetTokenizer:()=>Mp,MarianTokenizer:()=>kp,MgpstrTokenizer:()=>Ep,MobileBertTokenizer:()=>Ap,NllbTokenizer:()=>Sp,NougatTokenizer:()=>Op,PreTrainedTokenizer:()=>T,Qwen2Tokenizer:()=>Ip,RoFormerTokenizer:()=>Tp,RobertaTokenizer:()=>zp,SiglipTokenizer:()=>Cp,SpeechT5Tokenizer:()=>Pp,SqueezeBertTokenizer:()=>Lp,T5Tokenizer:()=>Np,TokenizersBackend:()=>T,VitsTokenizer:()=>$p,Wav2Vec2CTCTokenizer:()=>Rp,WhisperTokenizer:()=>Dp,XLMRobertaTokenizer:()=>jp,XLMTokenizer:()=>Bp});var Jc=class extends T{return_token_type_ids=!0};var Zc=class extends T{};var ep=class extends T{return_token_type_ids=!0};var tp=class extends T{};var sp=class extends T{};var rp=class extends T{};var np=class extends T{};var op=class extends T{};var ip=class extends T{};var ap=class extends T{};var lp=class extends T{};var cp=class extends T{return_token_type_ids=!0};var pp=class extends T{return_token_type_ids=!0};var up=class extends T{return_token_type_ids=!0};var _p=class extends T{};var dp=class extends T{return_token_type_ids=!0};var fp=class extends T{};var mp=class extends T{};var hp=class extends T{};var gp=class extends T{};var xp=class extends T{};var wp=class extends T{return_token_type_ids=!0};var yp=class extends T{padding_side="left"};var bp=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 Fs(this,e,s,r)}};var kp=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)),F.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)||F.warn(`Unsupported language code "${n}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),Fe([n],super._encode_text(o))}}};var Dr=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 Fs(this,e,s,r)}};var vp=class extends Dr{};var Ep=class extends T{};var Ap=class extends T{return_token_type_ids=!0};var Mp=class extends T{};var Sp=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 Fs(this,e,s,r)}};var Op=class extends T{};var Ip=class extends T{};var zp=class extends T{};var Tp=class extends T{return_token_type_ids=!0};var Cp=class extends T{};var Pp=class extends T{};var Lp=class extends T{return_token_type_ids=!0};var Np=class extends T{};var Fp=class extends Qe{decode_chain(e){let s="";for(let r=1;r<e.length;r+=2)s+=e[r];return[s]}},$p=class extends T{constructor(e,s){super(e,s),this._tokenizer.decoder=new Fp({type:"VitsDecoder"})}};var Rp=class extends T{};var T0=[["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"]],jr=new Map(T0),GE=new Map([...T0.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 C0(t){t=t.toLowerCase();let e=GE.get(t);if(e===void 0){let s=t.match(/^<\|([a-z]{2})\|>$/);if(s&&(t=s[1]),jr.has(t))e=t;else{let n=t.length===2?jr.keys():jr.values();throw new Error(`Language "${t}" is not supported. Must be one of: ${JSON.stringify(Array.from(n))}`)}}return e}var WE="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",P0=new RegExp(`^[${WE}]+$`,"gu"),Dp=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=[],p=l(),u=0,_=this.timestamp_begin,m=_+1500,h=[],g=[],x=!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,j=null,C=_;if("stride"in k){let[q,B,G]=k.stride;if(u-=B,w=q-G,B&&(C=B/n+_),G)for(let Z=O.length-1;Z>=0;--Z){let te=Number(O[Z]);if(te>=_){if(j!==null&&(te-_)*n<w)break;j=te}}}let R=[],$=[];for(let q=0;q<O.length;++q){let B=Number(O[q]);if(y.has(B)){let G=this.decode([B]),Z=jr.get(G.slice(2,-2));if(Z!==void 0){if(i!==null&&Z!==i&&!s){h.push(R);let te=this.findLongestCommonSequence(h)[0],M=this.decode(te);p.text=M,c.push(p),h=[],R=[],p=l()}i=p.language=Z}}else if(B>=_&&B<=m){let G=(B-_)*n+u,Z=Zt(G,2);if(j!==null&&B>=j)x=!0;else if(x||h.length>0&&B<C)x=!1;else if(p.timestamp[0]===null)p.timestamp[0]=Z;else if(Z!==p.timestamp[0]){p.timestamp[1]=Z,h.push(R),a&&g.push($);let[te,M]=this.findLongestCommonSequence(h,g),S=this.decode(te);p.text=S,a&&(p.words=this.collateWordTimestamps(te,M,i)),c.push(p),h=[],R=[],g=[],$=[],p=l()}}else if(R.push(B),a){let G=Zt(N[q]+u,2),Z;if(q+1<N.length){Z=Zt(N[q+1]+u,2);let te=this.decode([B]);P0.test(te)&&(Z=Zt(Math.min(G+n,Z),2))}else Z=null;$.push([G,Z])}}if("stride"in k){let[q,B,G]=k.stride;u+=q-G}R.length>0?(h.push(R),a&&g.push($)):h.every(q=>q.length===0)&&(p=l(),h=[],R=[],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[k,O]=this.findLongestCommonSequence(h,g),N=this.decode(k);p.text=N,a&&(p.words=this.collateWordTimestamps(k,O,i)),c.push(p)}let b=Object.create(null),E=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[E,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 p=e[c],u=0,_=[n,n,0,0],d=p.length;for(let b=1;b<n+d;++b){let E=Math.max(0,n-b),k=Math.min(n,n+d-b),O=r.slice(E,k),N=Math.max(0,b-n),j=Math.min(d,b),C=p.slice(N,j);if(O.length!==C.length)throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let R;i?R=O.filter((B,G)=>B===C[G]&&l[E+G]<=s[c][N+G]).length:R=O.filter((B,G)=>B===C[G]).length;let $=b/1e4,q=R/b+$;R>1&&q>u&&(u=q,_=[E,k,N,j])}let[m,h,g,x]=_,w=Math.floor((h+m)/2),y=Math.floor((x+g)/2);o.push(...r.slice(0,w)),r=p.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 v&&(e=Yc(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 p=0;p<e.length;++p){let u=e[p];a.push(u),l.push(p);let _=this.decode(a,{decode_with_timestamps:!0});(!_.includes(r)||s[c+_.indexOf(r)]===r)&&(n.push(_),o.push(a),i.push(l),a=[],l=[],c+=_.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],p=r[l],u=n[l],_=p[0]>=this._tokenizer.token_to_id("<|endoftext|>"),d=c.startsWith(" "),m=c.trim(),h=P0.test(m);if(_||d||h||o.length===0)o.push(c),i.push(p),a.push(u);else{let g=o.length-1;o[g]+=c,i[g].push(...p),a[g].push(...u)}}return[o,i,a]}mergePunctuations(e,s,r,n,o){let i=structuredClone(e),a=structuredClone(s),l=structuredClone(r),c=i.length-2,p=i.length-1;for(;c>=0;)i[c].startsWith(" ")&&n.includes(i[c].trim())?(i[p]=i[c]+i[p],a[p]=Fe(a[c],a[p]),l[p]=Fe(l[c],l[p]),i[c]="",a[c]=[],l[c]=[]):p=c,--c;for(c=0,p=1;p<i.length;)!i[c].endsWith(" ")&&o.includes(i[p])?(i[c]+=i[p],a[c]=Fe(a[c],a[p]),l[c]=Fe(l[c],l[p]),i[p]="",a[p]=[],l[p]=[]):c=p,++p;return[i.filter(u=>u),a.filter(u=>u.length>0),l.filter(u=>u.length>0)]}};var jp=class extends T{};var Bp=class extends T{return_token_type_ids=!0;constructor(e,s){super(e,s),F.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}};var W=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 Qc(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i}),c=l.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer",p=qp[c];return p||(F.warn(`Unknown tokenizer class "${c}", attempting to construct from base class.`),p=T),new p(a,l)}};var Tt="https://github.com/huggingface/transformers.js/issues/new/choose";var Br="preprocessor_config.json",yt=Br,L0="processor_config.json",N0="chat_template.jinja";var U=class extends Me{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?Ce(e,L0,!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?Rc(e,N0,!0,s):null]);return new this(r,n,o)}};var Da={};Ms(Da,{ChatterboxProcessor:()=>ou,Florence2Processor:()=>Qu,Gemma3nProcessor:()=>Yu,Glm46VProcessor:()=>Ju,GraniteSpeechProcessor:()=>Zu,GroundingDinoProcessor:()=>e_,Idefics3Processor:()=>Na,JinaCLIPProcessor:()=>s_,Lfm2VlProcessor:()=>r_,LlavaProcessor:()=>n_,MgpstrProcessor:()=>o_,MoonshineProcessor:()=>i_,OwlViTProcessor:()=>a_,PaliGemmaProcessor:()=>l_,Phi3VProcessor:()=>c_,PixtralProcessor:()=>p_,Processor:()=>U,PyAnnoteProcessor:()=>u_,Qwen2VLProcessor:()=>ss,Qwen2_5_VLProcessor:()=>Xr,Qwen3VLProcessor:()=>__,Sam2Processor:()=>Fa,Sam2VideoProcessor:()=>d_,SamProcessor:()=>Qr,SmolVLMProcessor:()=>Na,SpeechT5Processor:()=>f_,UltravoxProcessor:()=>m_,VLChatProcessor:()=>t_,VoxtralProcessor:()=>h_,VoxtralRealtimeProcessor:()=>x_,Wav2Vec2Processor:()=>w_,Wav2Vec2ProcessorWithLM:()=>y_,WhisperProcessor:()=>b_});var ae=class extends Me{constructor(e){super(),this.config=e}static async from_pretrained(e,s={}){let r=await Ce(e,Br,!0,s);return new this(r)}};function me(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 Vr={};Ms(Vr,{ASTFeatureExtractor:()=>Wp,ChatterboxFeatureExtractor:()=>Vp,ClapFeatureExtractor:()=>Hp,DacFeatureExtractor:()=>Gr,EncodecFeatureExtractor:()=>Ur,FeatureExtractor:()=>ae,Gemma3nAudioFeatureExtractor:()=>Kp,GraniteSpeechFeatureExtractor:()=>Xp,MoonshineFeatureExtractor:()=>Qp,ParakeetFeatureExtractor:()=>Yp,PyAnnoteFeatureExtractor:()=>Wr,SeamlessM4TFeatureExtractor:()=>Jp,SnacFeatureExtractor:()=>Zp,SpeechT5FeatureExtractor:()=>eu,VoxtralRealtimeFeatureExtractor:()=>ru,Wav2Vec2FeatureExtractor:()=>tu,WeSpeakerFeatureExtractor:()=>su,WhisperFeatureExtractor:()=>nu});var VE=()=>{};var F0={fromWeb:VE};var HE=()=>{};var $0=HE;async function fa(t,e){if(V.IS_BROWSER_ENV){if(V.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(V.IS_FS_AVAILABLE){let s=e.stream(),r=F0.fromWeb(s),n=Ne.createWriteStream(t);await $0(r,n)}else throw new Error("Unable to save because filesystem is disabled in this environment.")}async function Gp(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 St(t)).arrayBuffer(),r=new AudioContext({sampleRate:e});typeof e>"u"&&F.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 j0(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 R0(t){return j0(t,.5)}function KE(t){return j0(t,.54)}var XE={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 Up(t,e="htk"){let s=XE[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 QE={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 YE(t,e="htk"){let s=QE[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 JE(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],p=a[l+2]/s[l+1];o[l][i]=Math.max(0,Math.min(c,p))}}return o}function D0(t,e,s){let r=(e-t)/(s-1);return Float64Array.from({length:s},(n,o)=>t+r*o)}function ze(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=Up(s,i),c=Up(r,i),p=D0(l,c,e+2),u=YE(p,i),_;if(a){let m=n/((t-1)*2);_=Up(Float64Array.from({length:t},(h,g)=>g*m),i),u=p}else _=D0(0,Math.floor(n/2),t);let d=JE(_,u);if(o!==null&&o==="slaney")for(let m=0;m<e;++m){let h=d[m],g=2/(u[m+2]-u[m]);for(let x=0;x<t;++x)h[x]*=g}return d}function ZE(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[Os(o,n)];for(let o=1;o<=s;++o)r[n+e+o]=t[Os(n-o,n)];return r}function B0(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=pe(t)[0]-n;for(let a=0;a<t.length;++a)t[a]=Math.max(t[a],i)}return t}function eA(t,e=1,s=1e-5,r=null){return B0(t,20,e,s,r)}function tA(t,e=1,s=1e-10,r=null){return B0(t,10,e,s,r)}async function Pe(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:p=!0,mel_filters:u=null,mel_floor:_=1e-10,log_mel:d=null,max_log_mel:m=null,reference:h=1,min_value:g=1e-10,db_range:x=null,remove_dc_offset:w=null,min_num_frames:y=null,max_num_frames:b=null,do_pad:E=!0,transpose:k=!1,mel_offset:O=0}={}){let N=e.length;if(n===null&&(n=s),s>n)throw Error(`frame_length (${s}) may not be larger than fft_length (${n})`);if(N!==s)throw new Error(`Length of the window (${N}) must equal frame_length (${s})`);if(r<=0)throw new Error("hop_length must be greater than zero");if(o===null&&u!==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(!p)throw new Error("`preemphasis_htk_flavor=false` is not currently supported.");if(i)switch(a){case"reflect":{let z=Math.floor((n-1)/2)+1;t=ZE(t,z,z);break}case"constant":{let z=Math.floor(n/2),H=new t.constructor(t.length+2*z);H.set(t,z),t=H;break}default:throw new Error(`pad_mode="${a}" not implemented yet.`)}let j=Math.floor(1+Math.floor((t.length-s)/r));y!==null&&j<y&&(j=y);let C=l?Math.floor(n/2)+1:n,R=j,$=j;b!==null&&(b>j?E&&($=b):$=R=b);let q=new na(n),B=new Float64Array(n),G=new Float64Array(q.outputBufferSize),Z=new Float32Array(C*$);for(let z=0;z<R;++z){let H=z*r,he=Math.min(t.length-H,s);he!==s&&B.fill(0,0,s);for(let se=0;se<he;++se)B[se]=t[H+se];if(w){let se=0;for(let We=0;We<he;++We)se+=B[We];let Ke=se/he;for(let We=0;We<he;++We)B[We]-=Ke}if(c!==null){for(let se=he-1;se>=1;--se)B[se]-=c*B[se-1];B[0]*=1-c}for(let se=0;se<e.length;++se)B[se]*=e[se];q.realTransform(G,B);for(let se=0;se<C;++se){let Ke=se<<1;Z[se*$+z]=G[Ke]**2+G[Ke+1]**2}}if(o!==null&&o!==2){let z=o/2;for(let H=0;H<Z.length;++H)Z[H]**=z}let te=u.length,M=await S0(new v("float32",u.flat(),[te,C]),new v("float32",Z,[C,$]));k&&(M=M.transpose(1,0));let S=M.data;for(let z=0;z<S.length;++z)S[z]=O+Math.max(_,S[z]);if(o!==null&&d!==null){let z=Math.min(S.length,R*te);switch(d){case"log":for(let H=0;H<z;++H)S[H]=Math.log(S[H]);break;case"log10":for(let H=0;H<z;++H)S[H]=Math.log10(S[H]);break;case"log10_max_norm":{for(let se=0;se<z;++se)S[se]=Math.log10(S[se]);let he=(m??pe(S)[0])-8;for(let se=0;se<z;++se)S[se]=(Math.max(S[se],he)+4)/4;break}case"dB":if(o===1)eA(S,h,g,x);else if(o===2)tA(S,h,g,x);else throw new Error(`Cannot use log_mel option '${d}' with power ${o}`);break;default:throw new Error(`log_mel must be one of null, 'log', 'log10', 'log10_max_norm', or 'dB'. Got '${d}'`)}}return M}function Le(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=R0(o);break;case"hamming":i=KE(o);break;case"povey":i=R0(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 sA(t,e){let s=t.reduce((o,i)=>o+i.length,0),r=new ArrayBuffer(44),n=new DataView(r);return ma(n,0,"RIFF"),n.setUint32(4,36+s*4,!0),ma(n,8,"WAVE"),ma(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),ma(n,36,"data"),n.setUint32(40,s*4,!0),new Blob([r,...t.map(o=>o.buffer)],{type:"audio/wav"})}function ma(t,e,s){for(let r=0;r<s.length;++r)t.setUint8(e+r,s.charCodeAt(r))}var qr=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]),sA(e,this.sampling_rate)}async save(e){return fa(e,this.toBlob())}};var Wp=class extends ae{constructor(e){super(e);let s=this.config.sampling_rate,r=ze(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Le(400,"hann",{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,s){return Pe(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){me(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 Ur=class extends ae{async _call(e){me(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 v("float32",e,r)}}};var Vp=class extends ae{async _call(e){me(e,"ChatterboxFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,e.length];return{input_values:new v("float32",e,s)}}};var Hp=class extends ae{constructor(e){super(e),this.mel_filters=ze(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=ze(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=Le(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(Jt.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 Pe(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 me(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 Ur{};var Kp=class extends ae{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=ze(Math.floor(1+s/2),r,n,o,i,null,"htk",!1);this.mel_filters=l,this.window=Le(a,"hann")}async _extract_fbank_features(e,s){return Pe(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(me(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=ye([1,i.dims[0]],!0);return{input_features:i.unsqueeze_(0),input_features_mask:a}}};var Xp=class extends ae{constructor(e){super(e);let{n_fft:s,win_length:r,n_mels:n,sample_rate:o}=e.melspec_kwargs;this.mel_filters=ze(Math.floor(1+s/2),n,0,o/2,o,null,"htk");let i=Le(r,"hann");this.window=new Float64Array(s);let a=Math.floor((s-r)/2);this.window.set(i,a)}async _call(e){me(e,"GraniteSpeechFeatureExtractor");let{n_fft:s,hop_length:r,n_mels:n}=this.config.melspec_kwargs,o=1+Math.floor((e.length-1)/r),i=o-o%2;return{input_features:(await Pe(e,this.window,s,r,{power:2,mel_filters:this.mel_filters,log_mel:"log10_max_norm",transpose:!0,max_num_frames:i,do_pad:!1})).view(-1,2*n).unsqueeze_(0)}}};var Qp=class extends ae{async _call(e){me(e,"MoonshineFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,e.length];return{input_values:new v("float32",e,s)}}};var rA=1e-5,Yp=class extends ae{constructor(e){super(e),this.config.mel_filters??=ze(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=Le(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 Pe(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){me(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 u=0;u<r;++u){let _=u*i;for(let d=0;d<i;++d){let m=n[_+d];a[d]+=m,l[d]+=m*m}}let c=r>1?r-1:1;for(let u=0;u<i;++u){let _=a[u]/r,d=(l[u]-r*_*_)/c,h=1/(Math.sqrt(d)+rA);for(let g=0;g<r;++g){let x=g*i+u;n[x]=(n[x]-_)*h}}let p=new BigInt64Array(o);return p.fill(1n,0,r),{input_features:s.unsqueeze_(0),attention_mask:new v("int64",p,[1,o])}}};var Wr=class extends ae{async _call(e){me(e,"PyAnnoteFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let s=[1,1,e.length];return{input_values:new v("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=de(o[l]),[p,u]=pe(c),[_,d]=[l,l+1];u!==a?(a=u,i.push({id:u,start:_,end:d,score:p})):(i.at(-1).end=d,i.at(-1).score+=p)}n.push(i.map(({id:l,start:c,end:p,score:u})=>({id:l,start:c*r,end:p*r,confidence:u/(p-c)})))}return n}};var Jp=class extends ae{constructor(e){super(e);let s=this.config.sampling_rate,r=ze(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Le(400,"povey",{periodic:!1})}async _extract_fbank_features(e,s){return e=e.map(r=>r*32768),Pe(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}={}){me(e,"SeamlessM4TFeatureExtractor");let i=await this._extract_fbank_features(e,this.config.max_length);if(n){let[m,h]=i.dims,g=i.data;for(let x=0;x<h;++x){let w=0;for(let k=0;k<m;++k)w+=g[k*h+x];let y=w/m,b=0;for(let k=0;k<m;++k)b+=(g[k*h+x]-y)**2;b/=m-1;let E=Math.sqrt(b+1e-7);for(let k=0;k<m;++k){let O=k*h+x;g[O]=(g[O]-y)/E}}}let a;if(s){let[m,h]=i.dims,g=i.data,x=m%r;if(x>0){let w=new Float32Array(h*(m+x));w.set(g),w.fill(this.config.padding_value,g.length);let y=m+x;i=new v(i.type,w,[y,h]),o&&(a=new v("int64",new BigInt64Array(y),[1,y]),a.data.fill(1n,0,m))}}let[l,c]=i.dims,p=this.config.stride;if(l%p!==0)throw new Error(`The number of frames (${l}) must be a multiple of the stride (${p}).`);let _=i.view(1,Math.floor(l/p),c*p),d={input_features:_};if(o){let m=_.dims[1],h=new BigInt64Array(m);if(a){let g=a.data;for(let x=1,w=0;x<l;x+=p,++w)h[w]=g[x]}else h.fill(1n);d.attention_mask=new v("int64",h,[1,m])}return d}};var Zp=class extends Gr{};var eu=class extends ae{};var tu=class extends ae{_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){me(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 v("float32",s,r),attention_mask:new v("int64",new BigInt64Array(s.length).fill(1n),r)}}};var su=class extends ae{constructor(e){super(e);let s=this.config.sampling_rate,r=ze(257,this.config.num_mel_bins,20,Math.floor(s/2),s,null,"kaldi",!0);this.mel_filters=r,this.window=Le(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),Pe(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){me(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,p=l*a;for(let u=0;u<i;++u){let _=c+u*a;for(let d=0;d<a;++d)n[_+d]-=r[p+d]}}}return{input_features:s}}};var ru=class extends ae{constructor(e){super(e),this.config.mel_filters??=ze(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=Le(this.config.n_fft,"hann")}async _extract_fbank_features(e,{center:s=!0}={}){let{n_fft:r,hop_length:n,mel_filters:o,global_log_mel_max:i}=this.config,a=Math.floor(s?e.length/n:(e.length-r)/n);return await Pe(e,this.window,r,n,{power:2,mel_filters:o,log_mel:"log10_max_norm",max_log_mel:i,center:s,max_num_frames:a,do_pad:!1})}async _call(e,{center:s=!0}={}){return me(e,"VoxtralRealtimeFeatureExtractor"),{input_features:(await this._extract_fbank_features(e,{center:s})).unsqueeze_(0)}}};var nu=class extends ae{constructor(e){super(e),this.config.mel_filters??=ze(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=Le(this.config.n_fft,"hann")}async _extract_fbank_features(e){return await Pe(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10_max_norm",max_num_frames:Math.min(Math.floor(e.length/this.config.hop_length),this.config.nb_max_frames)})}async _call(e,{max_length:s=null}={}){me(e,"WhisperFeatureExtractor");let r,n=s??this.config.n_samples;return e.length>n?(e.length>this.config.n_samples&&F.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 be=class{static async from_pretrained(e,s={}){let r=await Ce(e,Br,!0,s),n=r.feature_extractor_type,o=Vr[n];if(!o)throw new Error(`Unknown feature_extractor_type: '${n}'. Please report this at ${Tt}.`);return new o(r)}};var ou=class extends U{static tokenizer_class=W;static feature_extractor_class=be;async _call(e,s=null){let r=this.tokenizer(e),n=s?await this.feature_extractor(s):{};return{...r,...n}}};var ha={};var ts,q0,Ct;if(V.IS_WEB_ENV)ts=(t,e)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this environment.");return new self.OffscreenCanvas(t,e)},Ct=self.createImageBitmap,q0=self.ImageData;else if(ha)Ct=async t=>{let s=(await t.metadata()).channels,{data:r,info:n}=await t.rotate().raw().toBuffer({resolveWithObject:!0}),o=new ve(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 nA={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},oA=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]),ve=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(!V.IS_WEB_ENV)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 St(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(V.IS_WEB_ENV){let s=await Ct(e),r=ts(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=ha(await e.arrayBuffer());return await Ct(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=nA[r]??r,o=Oc(e),i=Oc(s);if(o&&i)return this;if(o?e=s/this.height*this.width:i&&(s=e/this.width*this.height),V.IS_WEB_ENV){let a=this.channels,l=this.toCanvas(),c=ts(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")&&(F.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 Ct(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(V.IS_WEB_ENV){let o=this.channels,i=this.toCanvas(),a=this.width+e+s,l=this.height+r+n,c=ts(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 Ct(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(V.IS_WEB_ENV){let a=this.channels,l=this.toCanvas(),c=ts(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 Ct(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(V.IS_WEB_ENV){let o=this.channels,i=this.toCanvas(),a=ts(e,s).getContext("2d"),l=0,c=0,p=0,u=0;return r>=0?l=r:p=-r,n>=0?c=n:u=-n,a.drawImage(i,l,c,e,s,p,u,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 Ct(o)}}async toBlob(e="image/png",s=1){if(!V.IS_WEB_ENV)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 v("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(!V.IS_WEB_ENV)throw new Error("toCanvas() is only supported in browser environments.");let e=this.clone().rgba(),s=ts(e.width,e.height),r=new q0(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 p=0;p<n;++p)a[p][l]=e[c+p]}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(V.IS_WEB_ENV){if(V.IS_WEBWORKER_ENV)throw new Error("Unable to save an image from a Web Worker.");let s=e.split(".").pop().toLowerCase(),r=oA.get(s)??"image/png",n=await this.toBlob(r);return fa(e,n)}else if(V.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(V.IS_WEB_ENV)throw new Error("toSharp() is only supported in server-side environments.");return ha(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}},iA=ve.read.bind(ve);function U0(t,e,s=0,r=null){let n=t/e,o=c0(n)*e;return r!==null&&o>r&&(o=Math.floor(n)*e),o<s&&(o=Math.ceil(n)*e),o}function G0([t,e],s){return[Math.max(Math.floor(t/s),1)*s,Math.max(Math.floor(e/s),1)*s]}function iu([t,e,s,r]){return[t-s/2,e-r/2,t+s/2,e+r/2]}function Pt(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 p=0;p<i;++p){let u=s!==null?s[p]:null,_={boxes:[],classes:[],scores:[]},d=n[p],m=o[p];for(let h=0;h<a;++h){let g=d[h],x=[],w;if(r){w=g.sigmoid().data;for(let y=0;y<w.length;++y)w[y]>e&&x.push(y)}else{let y=pe(g.data)[1];if(y===l-1||(w=de(g.data),w[y]<e))continue;x.push(y)}for(let y of x){let b=m[h].data;b=iu(b),u!==null&&(b=b.map((E,k)=>E*u[(k+1)%2])),_.boxes.push(b),_.classes.push(y),_.scores.push(w[y])}}c.push(_)}return c}function ga(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=Wc(a,i,"bilinear",!1));let[l,c]=i??a.dims.slice(-2),p=new v("int32",new Int32Array(l*c),[l,c]),u=a[0].data,_=p.data;for(let h=1;h<a.dims[0];++h){let g=a[h].data;for(let x=0;x<g.length;++x)g[x]>u[x]&&(u[x]=g[x],_[x]=h)}let d=new Array(a.dims[0]);for(let h=0;h<_.length;++h){let g=_[h];d[g]=g}let m=d.filter(h=>h!==void 0);n.push({segmentation:p,labels:m})}return n}function aA(t,e,s,r){let n=[],o=[],i=[];for(let a=0;a<t.dims[0];++a){let l=t[a],c=e[a],p=pe(l.data)[1];if(p===r)continue;let _=de(l.data)[p];_>s&&(n.push(c),o.push(_),i.push(p))}return[n,o,i]}function lA(t,e,s,r=.5,n=.8){let o=[],i=0,a=0,l=e[s].data;for(let p=0;p<t.length;++p)t[p]===s&&(o.push(p),++i),l[p]>=r&&++a;let c=i>0&&a>0;return c&&(c=i/a>n),[c,o]}function cA(t,e,s,r,n,o=null,i=null){let[a,l]=i??t[0].dims,c=new v("int32",new Int32Array(a*l),[a,l]),p=[];if(i!==null)for(let h=0;h<t.length;++h)t[h]=Wc(t[h],i,"bilinear",!1);let u=new Int32Array(t[0].data.length),_=new Float32Array(t[0].data.length);for(let h=0;h<t.length;++h){let g=e[h],x=t[h].data;for(let w=0;w<x.length;++w)x[w]*=g,x[w]>_[w]&&(u[w]=h,_[w]=x[w])}let d=0,m=c.data;for(let h=0;h<s.length;++h){let g=s[h],[x,w]=lA(u,t,h,r,n);if(x){++d;for(let y of w)m[y]=d;p.push({id:d,label_id:g,score:e[h]})}}return[c,p]}function $s(t,e,s=28,r=3136,n=784*1280,o=1){if(t<s||e<s){let l=Math.max(s/t,s/e);t=Math.round(t*l),e=Math.round(e*l)}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 i=Math.round(t/s)*s,a=Math.round(e/s)*s;if(o*i*a>n){let l=Math.sqrt(o*t*e/n);i=Math.max(s,Math.floor(t/l/s)*s),a=Math.max(s,Math.floor(e/l/s)*s)}else if(o*i*a<r){let l=Math.sqrt(r/(o*t*e));i=Math.ceil(t*l/s)*s,a=Math.ceil(e*l/s)*s}return[a,i]}function xa(t,e=.5,s=.5,r=.8,n=null,o=null){n===null&&(F.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,p,u]=i.dims;if(u-=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 _=[];for(let d=0;d<c;++d){let m=o!==null?o[d]:null,h=i[d],g=l[d],[x,w,y]=aA(h,g,e,u);if(y.length===0){let[k,O]=m??g.dims.slice(-2),N=new v("int32",new Int32Array(k*O).fill(-1),[k,O]);_.push({segmentation:N,segments_info:[]});continue}let[b,E]=cA(x,w,y,s,r,n,m);_.push({segmentation:b,segments_info:E})}return _}function wa(t,e=.5,s=null){throw new Error("`post_process_instance_segmentation` is not yet implemented.")}var P=class extends Me{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_divisibility&&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=Lr(r.data)[0],i=pe(r.data)[0]-n;if(i===0)return e;let a=s/255,l=r.width,c=r.height,p=0,u=0,_=r.data;for(let d=0;d<r.height;++d){let m=d*r.width;for(let h=0;h<r.width;++h)(_[m+h]-n)/i<a&&(l=Math.min(l,h),c=Math.min(c,d),p=Math.max(p,h),u=Math.max(u,d))}return e=await e.crop([l,c,p,u]),e}pad_image(e,s,r,{mode:n="constant",center:o=!1,constant_values:i=0}={}){let[a,l,c]=s,p,u;if(typeof r=="number"?(p=r,u=r):r==="square"?p=u=Math.max(a,l):(p=r.width,u=r.height),p!==l||u!==a){let _=new Float32Array(p*u*c);if(Array.isArray(i))for(let h=0;h<_.length;++h)_[h]=i[h%c];else i!==0&&_.fill(i);let[d,m]=o?[Math.floor((p-l)/2),Math.floor((u-a)/2)]:[0,0];for(let h=0;h<a;++h){let g=(h+m)*p,x=h*l;for(let w=0;w<l;++w){let y=(g+w+d)*c,b=(x+w)*c;for(let E=0;E<c;++E)_[y+E]=e[b+E]}}if(n==="symmetric"){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");let h=a-1,g=l-1;for(let x=0;x<u;++x){let w=x*p,y=Os(x,h)*l;for(let b=0;b<p;++b){if(x<a&&b<l)continue;let E=(w+b)*c,k=(y+Os(b,g))*c;for(let O=0;O<c;++O)_[E+O]=e[k+O]}}}e=_,s=[u,p,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,p=i===void 0?1:Math.min(i/l,i/c),u=Math.floor(Number((l*p).toFixed(2))),_=Math.floor(Number((c*p).toFixed(2)));return this.size_divisibility!==void 0&&([u,_]=G0([u,_],this.size_divisibility)),[u,_]}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,p=a/r;Math.abs(1-p)<Math.abs(1-c)?c=p:p=c,l=U0(c*n,this.config.ensure_multiple_of),a=U0(p*r,this.config.ensure_multiple_of)}return[a,l]}else{if(this.size_divisibility!==void 0)return G0([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 d,m;Number.isInteger(this.crop_size)?(d=this.crop_size,m=this.crop_size):(d=this.crop_size.width,m=this.crop_size.height),e=await e.center_crop(d,m)}let c=[e.height,e.width],p=Float32Array.from(e.data),u=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(p),s??this.do_normalize){let d=this.image_mean;Array.isArray(this.image_mean)||(d=new Array(e.channels).fill(d));let m=this.image_std;if(Array.isArray(this.image_std)||(m=new Array(e.channels).fill(m)),d.length!==e.channels||m.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${d.length}) and \`image_std\` (${m.length}) must match the number of channels in the image (${e.channels}).`);for(let h=0;h<p.length;h+=e.channels)for(let g=0;g<e.channels;++g)p[h+g]=(p[h+g]-d[g])/m[g]}if(r??this.do_pad){if(this.pad_size)[p,u]=this.pad_image(p,[e.height,e.width,e.channels],this.pad_size);else if(this.size_divisibility){let d=Math.ceil(u[1]/this.size_divisibility)*this.size_divisibility,m=Math.ceil(u[0]/this.size_divisibility)*this.size_divisibility;[p,u]=this.pad_image(p,u,{width:d,height:m})}}if(i??this.do_flip_channel_order){if(u[2]!==3)throw new Error("Flipping channel order is only supported for RGB images.");for(let d=0;d<p.length;d+=3){let m=p[d];p[d]=p[d+2],p[d+2]=m}}let _=new v("float32",p,u).permute(2,0,1);return{original_size:[l,a],reshaped_input_size:c,pixel_values:_}}async _call(e,...s){Array.isArray(e)||(e=[e]);let r=await Promise.all(e.map(o=>this.preprocess(o)));return{pixel_values:qe(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 Ce(e,yt,!0,s);return new this(r)}};var qs={};Ms(qs,{BeitFeatureExtractor:()=>au,BitImageProcessor:()=>lu,CHMv2ImageProcessor:()=>pu,CLIPFeatureExtractor:()=>uu,CLIPImageProcessor:()=>ya,ChineseCLIPFeatureExtractor:()=>cu,ConvNextFeatureExtractor:()=>_u,ConvNextImageProcessor:()=>ba,DINOv3ViTImageProcessor:()=>mu,DPTFeatureExtractor:()=>gu,DPTImageProcessor:()=>Ea,DeiTFeatureExtractor:()=>du,DeiTImageProcessor:()=>ka,DetrFeatureExtractor:()=>fu,DetrImageProcessor:()=>va,DonutFeatureExtractor:()=>hu,DonutImageProcessor:()=>Rs,EfficientNetImageProcessor:()=>xu,GLPNFeatureExtractor:()=>yu,Glm46VImageProcessor:()=>wu,GroundingDinoImageProcessor:()=>bu,Idefics3ImageProcessor:()=>Aa,ImageFeatureExtractor:()=>P,ImageProcessor:()=>P,JinaCLIPImageProcessor:()=>vu,Lfm2VlImageProcessor:()=>Eu,LlavaOnevisionImageProcessor:()=>Au,Mask2FormerImageProcessor:()=>Su,MaskFormerFeatureExtractor:()=>Mu,MaskFormerImageProcessor:()=>Ds,MobileNetV1FeatureExtractor:()=>Ou,MobileNetV1ImageProcessor:()=>Ma,MobileNetV2FeatureExtractor:()=>Iu,MobileNetV2ImageProcessor:()=>Sa,MobileNetV3FeatureExtractor:()=>zu,MobileNetV3ImageProcessor:()=>Oa,MobileNetV4FeatureExtractor:()=>Tu,MobileNetV4ImageProcessor:()=>Ia,MobileViTFeatureExtractor:()=>Cu,MobileViTImageProcessor:()=>za,NougatImageProcessor:()=>Pu,OwlViTFeatureExtractor:()=>Lu,OwlViTImageProcessor:()=>js,Owlv2ImageProcessor:()=>Nu,Phi3VImageProcessor:()=>Ru,PixtralImageProcessor:()=>Du,PvtImageProcessor:()=>ju,Qwen2VLImageProcessor:()=>Hr,RTDetrImageProcessor:()=>Bu,Sam2ImageProcessor:()=>Kr,Sam3ImageProcessor:()=>Kr,SamImageProcessor:()=>Kr,SapiensFeatureExtractor:()=>qu,SapiensImageProcessor:()=>Ta,SegformerFeatureExtractor:()=>Uu,SegformerImageProcessor:()=>Ca,SiglipImageProcessor:()=>Gu,SmolVLMImageProcessor:()=>Aa,Swin2SRImageProcessor:()=>Wu,VLMImageProcessor:()=>ku,ViTFeatureExtractor:()=>Vu,ViTImageProcessor:()=>Pa,VitMatteImageProcessor:()=>Hu,VitPoseImageProcessor:()=>Ku,YolosFeatureExtractor:()=>Xu,YolosImageProcessor:()=>La});var au=class extends P{};var lu=class extends P{};var cu=class extends P{};var pu=class extends P{};var ya=class extends P{},uu=class extends ya{};var ba=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}},_u=class extends ba{};var ka=class extends P{},du=class extends ka{};var va=class extends P{async _call(e){let s=await super._call(e),r=[s.pixel_values.dims[0],64,64],n=ye(r,1n);return{...s,pixel_mask:n}}post_process_object_detection(...e){return Pt(...e)}post_process_panoptic_segmentation(...e){return xa(...e)}post_process_instance_segmentation(...e){return wa(...e)}},fu=class extends va{};var mu=class extends P{};var Rs=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 p=l.map((u,_)=>-u/c[_]);return super.pad_image(e,s,r,{center:!0,constant_values:p,...n})}},hu=class extends Rs{};var Ea=class extends P{},gu=class extends Ea{};var xu=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 Hr=class extends P{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 $s(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 p=i.dims[0]/a,u=i.dims[1],_=Math.floor(i.dims[2]/c),d=Math.floor(i.dims[3]/c),m=i.view(p,a,u,Math.floor(_/l),l,c,Math.floor(d/l),l,c).permute(0,3,6,4,7,2,1,5,8).view(p*_*d,u*a*c*c),h=new v("int64",[p,_,d],[1,3]);return{pixel_values:m,image_grid_thw:h,original_sizes:n,reshaped_input_sizes:o}}};var wu=class extends Hr{get_resize_output_image_size(e,s){let r=this.patch_size*this.merge_size,n=this.config.temporal_patch_size??2;return $s(e.height,e.width,r,this.min_pixels,this.max_pixels,n)}};var yu=class extends P{};var bu=class extends P{async _call(e){let s=await super._call(e),r=s.pixel_values.dims,n=Se([r[0],r[2],r[3]]);return{...s,pixel_mask:n}}};var Aa=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 x of n){let w=await Promise.all(x.map(E=>this.preprocess(E)));l.push(...w.map(E=>E.original_size)),c.push(...w.map(E=>E.reshaped_input_size)),w.forEach(E=>E.pixel_values.unsqueeze_(0));let{longest_edge:y}=this.max_image_size,b;if(s??this.do_image_splitting){let E=new Array(w.length),k=new Array(w.length);b=await Promise.all(w.map(async(O,N)=>{let j=this.get_resize_for_vision_encoder(O.pixel_values,y),C=await De(O.pixel_values,{size:[j.height,j.width]}),{frames:R,num_splits_h:$,num_splits_w:q}=await this.split_image(C,this.max_image_size);return E[N]=$,k[N]=q,ie(R,0)})),i.push(E),a.push(k)}else{let E=[y,y];b=await Promise.all(w.map(k=>De(k.pixel_values,{size:E}))),i.push(new Array(w.length).fill(0)),a.push(new Array(w.length).fill(0))}o.push(ie(b,0))}let p=o.length,[u,_,d,m]=o[0].dims,h,g;if(p===1)h=o[0].unsqueeze_(0),g=ye([p,u,d,m],!0);else{let x=Math.max(...o.map(b=>b.dims.at(0)));g=ye([p,x,d,m],!0);let w=g.data,y=x*d*m;for(let b=0;b<p;++b){let E=o[b].dims[0];if(E<x){o[b]=ie([o[b],ye([x-E,_,d,m],0)],0);let k=b*y+E*d*m,O=(b+1)*y;w.fill(!1,k,O)}}h=qe(o,0)}return{pixel_values:h,pixel_attention_mask:g,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 p=Math.ceil(i/l),u=Math.ceil(a/c);for(let m=0;m<l;++m)for(let h=0;h<c;++h){let g,x,w,y;m===l-1?(x=i-p,y=i):(x=m*p,y=(m+1)*p),h===c-1?(g=a-u,w=a):(g=h*u,w=(h+1)*u);let k=await ua(e,[x,g],[y,w],[2,3]);o.push(k)}let _=r,d=n;(i!==_||a!==d)&&(e=await De(e,{size:[_,d]}))}return o.push(e),{frames:o,num_splits_h:l,num_splits_w:c}}};var ku=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 vu=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})}};function W0(t,e){return Math.round(t/e)*e}function pA(t,e,s,r,n){let o=1/0,i=[1,1],a=s*r;for(let l of e){let c=Math.abs(t-l[0]/l[1]);c<o?(o=c,i=l):c===o&&a>.5*n*n*l[0]*l[1]&&(i=l)}return i}function uA(t,e){let s=[],r=new Set;for(let n=t;n<=e;++n)for(let o=1;o<=n;++o)for(let i=1;i<=n;++i){let a=o*i;if(a>=t&&a<=e){let l=o<<16|i;r.has(l)||(r.add(l),s.push([o,i]))}}return s.sort((n,o)=>n[0]*n[1]-o[0]*o[1])}function _A(t,e){let[s,r,n,o]=t.dims,i=Math.floor(n/e),a=Math.floor(o/e),l=e*e*r,c=t.data,p=new Float32Array(s*i*a*l),u=n*o;for(let _=0;_<s;++_){let d=_*r*u,m=_*i*a*l;for(let h=0;h<i;++h)for(let g=0;g<a;++g){let x=m+(h*a+g)*l;for(let w=0;w<e;++w){let y=(h*e+w)*o+g*e;for(let b=0;b<e;++b){let E=y+b;for(let k=0;k<r;++k)p[x++]=c[d+k*u+E]}}}}return new v("float32",p,[s,i*a,l])}function dA(t,e){let[,s,r]=t.dims,n=new BigInt64Array(e);n.fill(1n,0,s);let o=t;if(s<e){let i=new Float32Array(e*r);i.set(t.data),o=new v("float32",i,[1,e,r])}return{padded:o,mask:new v("int64",n,[e])}}var Eu=class extends P{constructor(e){super(e),this.downsample_factor=e.downsample_factor??2,this.do_image_splitting=e.do_image_splitting??!0,this.min_tiles=e.min_tiles??2,this.max_tiles=e.max_tiles??10,this.use_thumbnail=e.use_thumbnail??!0,this.min_image_tokens=e.min_image_tokens??64,this.max_image_tokens=e.max_image_tokens??256,this.encoder_patch_size=e.encoder_patch_size??e.patch_size??16,this.tile_size=e.tile_size??512,this.max_pixels_tolerance=e.max_pixels_tolerance??2,this.return_row_col_info=e.return_row_col_info??!1;let s=this.max_image_tokens*this.downsample_factor**2,r=this.do_image_splitting?(this.tile_size/this.encoder_patch_size)**2:0;this.max_num_patches=Math.max(s,r)}_is_image_too_large(e,s){let r=this.encoder_patch_size*this.downsample_factor,n=Math.max(this.encoder_patch_size,W0(e,r)),o=Math.max(this.encoder_patch_size,W0(s,r));return n*o>this.max_image_tokens*(this.encoder_patch_size*this.downsample_factor)**2*this.max_pixels_tolerance}_get_grid_layout(e,s){let r=uA(this.min_tiles,this.max_tiles),[n,o]=pA(s/e,r,s,e,this.tile_size);return{grid_width:n,grid_height:o,target_width:this.tile_size*n,target_height:this.tile_size*o}}async _call(e,{return_row_col_info:s=null}={}){let r;Array.isArray(e)?Array.isArray(e[0])?r=e:r=[e]:r=[[e]];let n=[],o=[],i=[],a=[],l=[],c=[];for(let u of r){let _=await Promise.all(u.map(d=>this.preprocess(d,{do_pad:!1})));for(let{pixel_values:d}of _){let[,m,h]=d.dims,g=d.unsqueeze_(0),x=this.encoder_patch_size*this.downsample_factor,w=x**2,[y,b]=$s(Math.max(x,m),Math.max(x,h),x,this.min_image_tokens*w,this.max_image_tokens*w).map(C=>Math.max(x,C)),E,k=1,O=1,N=this._is_image_too_large(m,h),j=this.do_image_splitting&&!(this.min_tiles===1&&this.max_tiles===1);if(N&&j){let{grid_width:C,grid_height:R,target_width:$,target_height:q}=this._get_grid_layout(m,h);k=R,O=C;let B=await De(g,{size:[q,$]});E=[];for(let G=0;G<R;++G)for(let Z=0;Z<C;++Z){let te=G*this.tile_size,M=Z*this.tile_size;E.push(B.slice(null,null,[te,te+this.tile_size],[M,M+this.tile_size]))}this.use_thumbnail&&C*R!==1&&E.push(await De(g,{size:[b,y]}))}else E=[await De(g,{size:[b,y]})];for(let C of E){let[,,R,$]=C.dims,q=_A(C,this.encoder_patch_size),{padded:B,mask:G}=dA(q,this.max_num_patches);n.push(B),o.push(G),i.push([Math.floor(R/this.encoder_patch_size),Math.floor($/this.encoder_patch_size)])}a.push(k),l.push(O),c.push([b,y])}}let p={pixel_values:ie(n,0),pixel_attention_mask:qe(o,0),spatial_shapes:new v("int64",BigInt64Array.from(i.flat(),BigInt),[i.length,2])};return(s??this.return_row_col_info)&&(p.image_rows=a,p.image_cols=l,p.image_sizes=c),p}};var Au=class extends P{};var Ds=class extends P{post_process_panoptic_segmentation(...e){return xa(...e)}post_process_instance_segmentation(...e){return wa(...e)}},Mu=class extends Ds{};var Su=class extends Ds{};var Ma=class extends P{},Ou=class extends Ma{};var Sa=class extends P{},Iu=class extends Sa{};var Oa=class extends P{},zu=class extends Oa{};var Ia=class extends P{},Tu=class extends Ia{};var za=class extends P{},Cu=class extends za{};var Pu=class extends Rs{};var js=class extends P{post_process_object_detection(...e){return Pt(...e)}},Lu=class extends js{};var Nu=class extends js{};var He=336,fA=[2,3],{ceil:Fu,floor:Bs,sqrt:$u}=Math,Ru=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 Bs((Bs(s/He)*Bs(e/He)+1)*r+1+(Bs(s/He)+1)*$u(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=He*Fu(o/He),l=He*Fu(i/He),c=[1,1,1].map((p,u)=>(p-this.image_mean[u])/this.image_std[u]);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||$u(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(_=>this.preprocess(_))),o=n.map(_=>_.original_size),i=n.map(_=>_.reshaped_input_size),a=[];for(let{pixel_values:_}of n){_.unsqueeze_(0);let[d,m]=_.dims.slice(-2),h=await De(_,{size:[He,He],mode:"bicubic"});if(s>0){let g=[],x=$u(s),w=Bs(m/x),y=Bs(d/x);for(let E=0;E<x;++E)for(let k=0;k<x;++k){let O,N,j,C;E===x-1?(N=d-y,C=d):(N=E*y,C=(E+1)*y),k===x-1?(O=m-w,j=m):(O=k*w,j=(k+1)*w);let q=await ua(_,[N,O],[C,j],fA);g.push(q)}let b=await De(ie(g,0),{size:[He,He],mode:"bicubic"});a.push(ie([h,b],0))}else a.push(h)}let l=qe(a,0),c=i.map(_=>_.map(d=>He*Fu(d/He))),p=new v("int64",c.flat(),[r,2]),u=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:p,num_img_tokens:u}}};var Du=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:p}=this.config;if(!p)throw new Error("config must contain 'spatial_merge_size'");let u=c*p,_=Math.floor((a-1)/u)+1,d=Math.floor((l-1)/u)+1;return[_*u,d*u]}};var ju=class extends P{};var Bu=class extends P{post_process_object_detection(...e){return Pt(...e)}};var Kr=class extends P{reshape_input_points(e,s,r,n=!1){e=structuredClone(e);let o=Ic(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,p]=r[i],u=[p/l,c/a];for(let _=0;_<e[i].length;++_)for(let d=0;d<e[i][_].length;++d)for(let m=0;m<e[i][_][d].length;++m)e[i][_][d][m]*=u[m%2]}return new v("float32",Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,s){let r=Ic(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 v("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 p=s[c],u=r[c],_=await De(e[c],{mode:"bilinear",size:l});if(_=_.slice(null,null,[0,u[0]],[0,u[1]]),_=await De(_,{mode:"bilinear",size:p}),o){let d=_.data,m=new Uint8Array(d.length);for(let h=0;h<d.length;++h)d[h]>n&&(m[h]=1);_=new v("bool",m,_.dims)}a.push(_)}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 Ta=class extends P{post_process_semantic_segmentation(...e){return ga(...e)}},qu=class extends Ta{};var Ca=class extends P{post_process_semantic_segmentation(...e){return ga(...e)}},Uu=class extends Ca{};var Gu=class extends P{};var Wu=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 Pa=class extends P{},Vu=class extends Pa{};var Hu=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:qe(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 Ku=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 p=0;p<o;++p){let u=n[p],_=s[p],d=[];for(let m=0;m<_.length;++m){let h=_[m],g=[],x=[],w=[],y=h.at(-2)/l,b=h.at(-1)/a;for(let E=0;E<u.length;++E){let[k,O]=[0,0],N=0,j=-1/0,C=u[E];for(let $=0;$<C.length;++$){let q=C[$];for(let B=0;B<q.length;++B){let G=q[B];N+=G,j=Math.max(j,G),k+=(B+.5)*G,O+=$*G}}if(r!=null&&j<r)continue;let R=[y*k/N,b*O/N];g.push(R),w.push(E),x.push(j)}d.push({bbox:h,scores:x,labels:w,keypoints:g})}c.push(d)}return c}};var La=class extends P{post_process_object_detection(...e){return Pt(...e)}},Xu=class extends La{};var ue=class{static async from_pretrained(e,s={}){let r=await Ce(e,yt,!0,s),n=r.image_processor_type??r.feature_extractor_type,o=qs[n?.replace(/Fast$/,"")];return o||(n!==void 0&&F.warn(`Image processor type '${n}' not found, assuming base ImageProcessor. Please report this at ${Tt}.`),o=P),new o(r)}};var Qu=class extends U{static tokenizer_class=W;static image_processor_class=ue;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[p,u,..._]of a)l.push(u?u.trim():l.at(-1)??""),c.push(_.map((d,m)=>(Number(d)+.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 Yu=class extends U{static image_processor_class=ue;static feature_extractor_class=be;static tokenizer_class=W;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:p,eoi_token:u}=this.tokenizer.config;this.audio_token_id=n,this.boa_token=o,this.audio_token=i;let _=i.repeat(this.audio_seq_length);this.full_audio_sequence=`
11
11
 
12
12
  ${o}${_}${a}
13
13
 
14
- `,this.image_token_id=l,this.boi_token=c,this.image_token=u;let d=u.repeat(this.image_seq_length);this.full_image_sequence=`
14
+ `,this.image_token_id=l,this.boi_token=c,this.image_token=p;let d=p.repeat(this.image_seq_length);this.full_image_sequence=`
15
15
 
16
- ${c}${d}${p}
16
+ ${c}${d}${u}
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}}};var Xp=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;static uses_processor_config=!0;_get_num_audio_features(e){let{hop_length:s}=this.feature_extractor.config.melspec_kwargs,{projector_window_size:r,projector_downsample_rate:n}=this.feature_extractor.config,o=Math.floor(r/n),i=Math.floor(e/s)+1,a=Math.floor(i/2);return Math.ceil(a/r)*o}async _call(e,s=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(s){let{input_features:i}=await this.feature_extractor(s);n.input_features=i;let a=this._get_num_audio_features(s.length),l=new Uint8Array(a).fill(1);n.input_features_mask=new A("bool",l,[1,a]);let c=this.config.audio_token??"<|audio|>";if(!e.includes(c))throw new Error(`The input text does not contain the audio token ${c}.`);e=e.replaceAll(c,c.repeat(a))}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};function UE(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 Qp=class extends U{static tokenizer_class=W;static image_processor_class=pe;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(),_=a.tolist().map(m=>m.map(h=>np(h))),d=[];for(let m=0;m<l;++m){let h=o!==null?o[m]:null;h!==null&&(_[m]=_[m].map(b=>b.map((M,k)=>M*h[(k+1)%2])));let g=p[m],x=[],w=[],y=[];for(let b=0;b<c;++b){let M=g[b];if(M<=r)continue;let k=_[m][b],O=u[m][b];x.push(M),y.push(k);let N=UE(O.gt(n),s[m]);w.push(N)}d.push({scores:x,boxes:y,labels:this.batch_decode(w)})}return d}};function GE(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}}};var ss=class extends U{static image_processor_class=ue;static tokenizer_class=W;static image_token="<|image_pad|>";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=this.constructor.image_token,p=o.tolist();e=e.map(u=>{for(;u.includes(c);){let _=Number(p[l++].reduce((d,m)=>d*m,1n));u=u.replace(c,"<|placeholder|>".repeat(Math.floor(_/a)))}return u.replaceAll("<|placeholder|>",c)})}return{...this.tokenizer(e),...n}}};var Ju=class extends ss{static image_token="<|image|>"};var Zu=class extends U{static tokenizer_class=W;static feature_extractor_class=be;static uses_processor_config=!0;_get_num_audio_features(e){let{hop_length:s}=this.feature_extractor.config.melspec_kwargs,{projector_window_size:r,projector_downsample_rate:n}=this.feature_extractor.config,o=Math.floor(r/n),i=Math.floor(e/s)+1,a=Math.floor(i/2);return Math.ceil(a/r)*o}async _call(e,s=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(s){let{input_features:i}=await this.feature_extractor(s);n.input_features=i;let a=this._get_num_audio_features(s.length),l=new Uint8Array(a).fill(1);n.input_features_mask=new v("bool",l,[1,a]);let c=this.config.audio_token??"<|audio|>";if(!e.includes(c))throw new Error(`The input text does not contain the audio token ${c}.`);e=e.replaceAll(c,c.repeat(a))}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};function mA(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 e_=class extends U{static tokenizer_class=W;static image_processor_class=ue;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),p=i.sigmoid(),u=p.max(-1).tolist(),_=a.tolist().map(m=>m.map(h=>iu(h))),d=[];for(let m=0;m<l;++m){let h=o!==null?o[m]:null;h!==null&&(_[m]=_[m].map(b=>b.map((E,k)=>E*h[(k+1)%2])));let g=u[m],x=[],w=[],y=[];for(let b=0;b<c;++b){let E=g[b];if(E<=r)continue;let k=_[m][b],O=p[m][b];x.push(E),y.push(k);let N=mA(O.gt(n),s[m]);w.push(N)}d.push({scores:x,boxes:y,labels:this.batch_decode(w)})}return d}};function hA(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 WE(t,e,s,r){return`${e}${r}`+s.repeat(t)+`${e}`}function VE(t,e,s,r,n,o){return t===0&&e===0?WE(s,r,n,o):GE(s,t,e,r,n,o)}var Na=class extends U{static image_processor_class=pe;static tokenizer_class=W;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 _=e[p],d=o[p],m=i[p];l.push(Hw(_,this.image_token));let h=d.map((w,y)=>VE(w,m[y],a,this.fake_image_token,this.image_token,this.global_img_token)),g=_.split(this.image_token);if(g.length===0)throw new Error("The image token should be present in the text.");let x=g[0];for(let w=0;w<h.length;++w)x+=h[w]+g[w+1];c.push(x)}return{...this.tokenizer(c),...n}}};var Yp=class extends U{static image_processor_class=pe;static tokenizer_class=W;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(g=>g.images).flatMap(g=>g.images).map(g=>ve.read(g)));let n=this.tokenizer,o=n.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0,chat_template:r}),i=g=>n.encode(g,{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]),_=i(a[0]),d=new Array(_.length).fill(!1);for(let g=1;g<a.length;++g){let x=new Array(this.num_image_tokens).fill(c),w=i(a[g]);_=$e(_,[u],x,[p],w);let y=new Array(this.num_image_tokens).fill(!0);d=$e(d,[!1],y,[!1],new Array(w.length).fill(!1))}let m=[1,_.length],h={input_ids:new A("int64",_,m),attention_mask:new A("int64",new Array(_.length).fill(1),m),images_seq_mask:new A("bool",d,m),images_emb_mask:new A("bool",new Array(l*this.num_image_tokens).fill(!0),[1,l,this.num_image_tokens])};if(s&&s.length>0){let g=await this.image_processor(s);return g.pixel_values.unsqueeze_(0),{...h,...g}}return h}};var Jp=class extends U{static tokenizer_class=W;static image_processor_class=pe;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 Zp=class extends U{static tokenizer_class=W;static image_processor_class=pe;async _call(e,s=null,r={}){let{image_rows:n,image_cols:o,image_sizes:i,...a}=await this.image_processor(e,{...r,return_row_col_info:!0});if(s){let l=this.config.image_token??"<image>",{tile_size:c=512,downsample_factor:u=2,encoder_patch_size:p=16,use_thumbnail:_=!0}=this.image_processor.config,d=y=>Math.ceil(Math.floor(y/p)/u),m=d(c)**2,h=this.config.image_start_token??"<|image_start|>",g=this.config.image_end_token??"<|image_end|>",x=this.config.image_thumbnail??"<|img_thumbnail|>";Array.isArray(s)||(s=[s]);let w=0;s=s.map(y=>{let b=y.split(l);return b[0]+b.slice(1).map(M=>{let k=w++,[O,N]=i[k],R=n[k],C=o[k],D=d(O)*d(N),$=h;if(R>1||C>1){let q=l.repeat(m);for(let B=0;B<R;++B)for(let G=0;G<C;++G)$+=`<|img_row_${B+1}_col_${G+1}|>`+q;_&&($+=x+l.repeat(D))}else $+=l.repeat(D);return $+g+M}).join("")})}return{...a,...s?this.tokenizer(s,r):{}}}};var e_=class extends U{static tokenizer_class=W;static image_processor_class=pe;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 _=0;_<s.length;++_)s[_]=s[_].replace(l,l.repeat(p))}let o=s?this.tokenizer(s,r):{};return{...n,...o}}};var y0={char:["char_decode",1],bpe:["bpe_decode",2],wp:["wp_decode",102]},t_=class extends U{static tokenizer_class=W;static image_processor_class=pe;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(!y0.hasOwnProperty(s))throw new Error(`Format ${s} is not supported.`);let[r,n]=y0[s],o=this[r].bind(this),[i,a]=e.dims,l=[],c=[],u=e.tolist();for(let _=0;_<i;++_){let d=u[_],m=[],h=[];for(let x=1;x<a;++x){let[w,y]=ue(de(d[x]));if(h.push(w),y==n)break;m.push(y)}let g=h.length>0?h.reduce((x,w)=>x*w,1):0;c.push(m),l.push(g)}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 _=0;_<n.length;++_){let[d,m]=ue([o[_],a[_],c[_]]);u.push([n[_],i[_],l[_]][m]),p.push(d)}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 W.from_pretrained("Xenova/gpt2"),n=await W.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 s_=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;async _call(e){return await this.feature_extractor(e)}};var r_=class extends U{static tokenizer_class=W;static image_processor_class=pe};var Hs="<image>";function HE(t,e,s,r,n){return`${r.repeat(s*n)}${e}${t}
21
- `}var n_=class extends U{static tokenizer_class=W;static image_processor_class=pe;static uses_processor_config=!1;async _call(e,s=null,r={}){s||(F.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(Hs))?i=s.map(c=>{let u=c.replaceAll(Hs,Hs.repeat(o)),p=u.lastIndexOf(Hs),_=p===-1?0:p+Hs.length;return u.slice(0,_)+n+u.slice(_)+`
22
- `}):(F.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=>HE(c,n,o,Hs,e.length)));let a=this.tokenizer(i,r);return{...await this.image_processor(e,r),...a}}};var b0="<|image|>",KE=/<\|image_\d+\|>/g,o_=class extends U{static image_processor_class=pe;static tokenizer_class=W;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,_)=>p.split(KE).join(b0.repeat(l[_])));i=this.tokenizer(c,{padding:r,truncation:n});let u=this.tokenizer._tokenizer.token_to_id(b0);i.input_ids.map_(p=>p==u?-p:p)}else i=this.tokenizer(e);return{...i,...a}}};var i_=class extends U{static tokenizer_class=W;static image_processor_class=pe;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:_}=this.config,d=p*_,m=Math.floor(i/d),h=Math.floor(a/d);s=structuredClone(s),Array.isArray(s)||(s=[s]);for(let g=0;g<s.length;++g){let x=l.repeat(h),w=x+c,y=x+u,b=w.repeat(m-1)+y;s[g]=s[g].replace(l,b)}}let o=s?this.tokenizer(s,r):{};return{...n,...o}}};var a_=class extends U{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 Kr=class extends U{static image_processor_class=pe;static tokenizer_class=W;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 Xr=class extends Kr{};var l_=class extends Xr{};var Qr=class extends U{static image_processor_class=pe;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 Fa=class extends Qr{},c_=class extends Fa{};var u_=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;async _call(e){return await this.feature_extractor(e)}};var p_=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;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 $a="[AUDIO]",XE="[BEGIN_AUDIO]",QE=375;function YE(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 __=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;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($a))throw new Error(`The input text does not contain the audio token ${$a}.`);Array.isArray(s)||(s=[s]);let i=e.split($a),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=>YE(m,l)),u=c.map(m=>m.length),p=c.flat(),_=(await Promise.all(p.map(m=>this.feature_extractor(m,r)))).map(m=>m.input_features);n.audio_values=_.length>1?ie(_,0):_[0];let d=i[0];for(let m=0;m<u.length;++m){d+=XE;for(let h=0;h<u[m];++h)d+=$a.repeat(QE);d+=i[m+1]}e=d}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};var k0=32,d_=6,Ra=8,JE=10,ZE=32,f_=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;static uses_processor_config=!1;get num_mel_frames_first_audio_chunk(){return(d_+1)*Ra}get num_samples_first_audio_chunk(){let{hop_length:e,n_fft:s}=this.feature_extractor.config;return(this.num_mel_frames_first_audio_chunk-1)*e+Math.floor(s/2)}get num_samples_per_audio_chunk(){let{hop_length:e,n_fft:s}=this.feature_extractor.config;return Ra*e+s}get num_right_pad_tokens(){return d_+1+JE}get audio_length_per_tok(){return Ra}get raw_audio_length_per_tok(){return Ra*this.feature_extractor.config.hop_length}async _call(e,{is_streaming:s=!1,is_first_audio_chunk:r=!0}={}){if(me(e,"VoxtralRealtimeProcessor"),!s&&!r)throw new Error("In non-streaming mode (`is_streaming=false`), `is_first_audio_chunk` must be `true`.");if(r)if(s){let n=k0*this.raw_audio_length_per_tok,o=new Float32Array(n+e.length);o.set(e,n);let i=await this.feature_extractor(o,{center:!0}),l=1+(k0+d_),c=new BigInt64Array(l).fill(BigInt(ZE));return c[0]=1n,{input_ids:new A("int64",c,[1,l]),...i}}else{let n=this.num_right_pad_tokens*this.raw_audio_length_per_tok,o=new Float32Array(e.length+n);return o.set(e),await this.feature_extractor(o,{center:!0})}else return await this.feature_extractor(e,{center:!1})}};var m_=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;async _call(e){return await this.feature_extractor(e)}};var h_=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;async _call(e){return await this.feature_extractor(e)}};var g_=class extends U{static tokenizer_class=W;static feature_extractor_class=ye;async _call(e){return await this.feature_extractor(e)}};var ja=class{static async from_pretrained(e,s={}){let r=await Ce(e,Mt,!0,s),{image_processor_type:n,feature_extractor_type:o,processor_class:i}=r;if(i&&Da[i])return Da[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=Vs[n.replace(/Fast$/,"")];if(!c)throw new Error(`Unknown image_processor_type: '${n}'.`);a.image_processor=new c(r)}if(o){let c=Vs[o];if(c)a.image_processor=new c(r);else{let u=Vr[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 eA(t,e){return await Ce(t,"config.json",!0,e)}function Ks(t){let e={},s={};switch(t.model_type){case"llava":case"paligemma":case"gemma3":case"florence2":case"llava_onevision":case"idefics3":case"granite_speech":case"ultravox":case"voxtral":case"voxtral_realtime":case"smolvlm":case"gemma3n":case"lfm2_vl":case"chatterbox":case"mistral3":case"qwen2_5_vl":case"qwen3_vl":case"qwen3_vl_moe":s=Ks(t.text_config);break;case"moondream1":s=Ks(t.phi_config);break;case"musicgen":s=Ks(t.decoder);break;case"multi_modality":s=Ks(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"voxtral_realtime_text":case"voxtral_realtime_encoder":case"starcoder2":case"qwen2":case"qwen2_moe":case"qwen2_vl":case"qwen2_vl_text":case"qwen2_5_vl_text":case"qwen3_moe":case"qwen3_vl_text":case"qwen3_vl_moe_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=Ks(t.decoder),o="num_decoder_layers"in n,i=ke(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,...ke(t,["model_type","multi_query","is_encoder_decoder"])};for(let n in e)r[n]=t[e[n]];return r}function _s(t,e){if(t instanceof Xs||(t=new Xs(t)),["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 _=0;_<o.length;++_)if(o[_]==="full_attention")for(let d of["key","value"])n[`${s}.${_}.${d}`]=[p,a,0,u];else if(o[_]==="conv")n[`${r}_conv.${_}`]=[p,l,c];else throw new Error(`Unsupported layer type: ${o[_]}`);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:_,mamba_d_state:d,mamba_n_groups:m,mamba_expand:h,mamba_d_ssm:g}=t,x=c/a,w=e?.batch_size??1,y=(g??h*c)+2*m*d;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 M of["key","value"])n[`${s}.${b}.${M}`]=[w,l,0,x];return n}else if(["qwen3_next","qwen3_5_text","qwen3_5_moe_text","olmo_hybrid"].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:_,linear_value_head_dim:d,linear_conv_kernel_dim:m}=t,h=_*p,g=d*u,x=o??c/a,w=e?.batch_size??1;for(let y=0;y<i.length;++y)if(i[y]==="full_attention")for(let b of["key","value"])n[`${s}.${y}.${b}`]=[w,l,0,x];else if(i[y]==="linear_attention"){if(t.model_type==="olmo_hybrid")n[`${r}_conv.${y}.key`]=[w,h,m],n[`${r}_conv.${y}.value`]=[w,g,m],n[`${r}_conv.${y}.query`]=[w,h,m];else{let b=h*2+g;n[`${r}_conv.${y}`]=[w,b,m]}n[`${r}_recurrent.${y}`]=[w,u,_,d]}else throw new Error(`Unsupported layer type: ${i[y]}`);return n}else if(["lfm2_vl","qwen3_5","qwen3_5_moe","voxtral_realtime"].includes(t.model_type)){let s;return t.model_type==="voxtral_realtime"&&e?.session_name==="audio_encoder"?s=t.audio_config:s=t.text_config,_s(s,e)}return tA(t,e)}function tA(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 Xs=class t{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=Ks(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 eA(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i});return new this(a)}},Je=class{static async from_pretrained(...e){return Xs.from_pretrained(...e)}};function x_(t,e,s){return t?typeof t=="object"&&t!==null?t.hasOwnProperty(e)?+t[e]:t.hasOwnProperty(s)?+t[s]:0:+t:0}function w_(t,e){let s=[];for(let r=0;r<e;++r)s.push(`${t}_data${r===0?"":"_"+r}`);return s}async function v0(t,e,s,r){let n=`${e}${r}.onnx`,o=`${s.subfolder??""}/${n}`;return await Pr(t,o,!0,s,V.IS_NODE_ENV)}async function E0(t,e,s,r,n,o={}){let i=`${e}${s}.onnx`,a=V.IS_NODE_ENV,l=[],c=x_(n,i,e);if(c>0){if(c>Zi)throw new Error(`The number of external data chunks (${c}) exceeds the maximum allowed value (${Zi}).`);let u=w_(i,c);for(let p of u){let _=`${r.subfolder??""}/${p}`;l.push(new Promise(async(d,m)=>{let h=await Pr(t,_,!0,r,a);d(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 Pr(t,u.data,!0,r);return{...u,data:p}}return u}));return Promise.all(l)}async function sA(t,e,s,r=!1,n=void 0){let o=s.config?.["transformers.js_config"]??{},i=aa(s.device??o.device,e,{warn:b=>F.info(b)}),a=Ky(i),l=o.device_config??{};l.hasOwnProperty(i)&&(o={...o,...l[i]});let c=la(s.dtype??o.dtype,e,i,{configDtype:o.dtype,warn:b=>F.info(b)});if(Fr.hasOwnProperty(c)){if(i==="webgpu"&&!V.IS_NODE_ENV&&c===De.fp16&&!await Zy())throw new Error(`The device (${i}) does not support fp16.`)}else throw new Error(`Invalid dtype: ${c}. Should be one of: ${Object.keys(De).join(", ")}`);let u=o.kv_cache_dtype,p=u?typeof u=="string"?u:u[c]??"float32":void 0;if(p&&!["float32","float16"].includes(p))throw new Error(`Invalid kv_cache_dtype: ${p}. Should be one of: float32, float16`);let _=Fr[c],d={...s.session_options};d.executionProviders??=a;let m=o.free_dimension_overrides;m?d.freeDimensionOverrides??=m:i.startsWith("webnn")&&!d.freeDimensionOverrides&&F.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 h=v0(t,e,s,_),g=s.use_external_data_format??o.use_external_data_format,x=await E0(t,e,_,s,g,d);if(x.length>0&&!V.IS_NODE_ENV&&(d.externalData=x),r&&i==="webgpu"&&u!==!1){let b=_s(s.config,{prefix:"present",session_name:n});if(Object.keys(b).length>0&&!Nr()){let M={};for(let k in b)M[k]="gpu-buffer";d.preferredOutputLocation=M}}return{buffer_or_path:await h,session_options:d,session_config:{dtype:c,kv_cache_dtype:p,device:i}}}async function A0(t,e,s,r=void 0){return Object.fromEntries(await Promise.all(Object.keys(e).map(async n=>{let o=r?.[n]??!1,{buffer_or_path:i,session_options:a,session_config:l}=await sA(t,e[n],s,o,n),c=await na(i,a,l);return[n,c]})))}function M0(t){for(let e in t)ia(t[e])?t[e]=new A(t[e]):typeof t[e]=="object"&&M0(t[e]);return t}async function X(t,e){let s=rA(t,e);try{let r=Object.fromEntries(Object.entries(s).map(([o,i])=>{let a=i.ort_tensor;return V.IS_NODE_ENV&&typeof Float16Array<"u"&&a.cpuData instanceof Float16Array&&(a.cpuData=new Uint16Array(a.cpuData.buffer)),[o,a]})),n=await oa(t,r);return M0(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 F.error(`An error occurred during model execution: "${r}".`),F.error("Inputs given to model:",n),r}}function rA(t,e){let s=Object.create(null),r=[];for(let i of t.inputNames){let a=e[i];if(!(a instanceof A)){r.push(i);continue}s[i]=Nr()?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));F.warn(`WARNING: Too many inputs were provided (${n} > ${o}). The following inputs will be ignored: "${i.join(", ")}".`)}return s}var fe=class{};var z=class extends fe{constructor({logits:e,...s}){super(),this.logits=e;let r=Object.values(s);r.length>0&&(this.attentions=r)}},te=class extends fe{constructor({logits:e}){super(),this.logits=e}},re=class extends fe{constructor({logits:e}){super(),this.logits=e}},le=class extends fe{constructor({start_logits:e,end_logits:s}){super(),this.start_logits=e,this.end_logits=s}},qe=class extends fe{constructor({logits:e}){super(),this.logits=e}};var Ba=class extends fe{constructor({alphas:e}){super(),this.alphas=e}};var Ze=class extends Me{_call(e,s){throw Error("`_call` should be implemented in a subclass")}},Yr=class extends Me{_call(e,s){throw Error("`_call` should be implemented in a subclass")}},ds=class extends Me{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()}},qa=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}},Ua=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}},Ga=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=$c(n),c=Math.log(l.subarray(this.timestamp_begin).map(Math.exp).reduce((p,_)=>p+_)),u=ue(l.subarray(0,this.timestamp_begin))[0];c>u&&n.subarray(0,this.timestamp_begin).fill(-1/0)}return s}},Wa=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}},Va=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}},Ha=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}},Ka=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}},Xa=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}},Qa=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}},Ya=class extends Yr{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}},S0=class extends Yr{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}},O0=class extends Yr{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 Ys=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,ke(e,Object.getOwnPropertyNames(this)))}};var qt=class extends Me{_call(e,s){throw Error("StoppingCriteria needs to be subclassed")}},Js=class t extends Me{constructor(){super(),this.criteria=[]}push(e){this.criteria.push(e)}extend(e){e instanceof t?e=e.criteria:e instanceof qt&&(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()}},Ja=class extends qt{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)}},Za=class extends qt{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)})}},I0=class extends qt{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 fs=class extends Me{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 vy(e)}static getSampler(e){if(e.do_sample)return new b_(e);if(e.num_beams>1)return new k_(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 y_(e)}},y_=class extends fs{async sample(e){let s=ue(e.data)[1];return[[BigInt(s),0]]}},b_=class extends fs{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 ct(e,s),o=de(r.data);return Array.from({length:this.generation_config.num_beams},()=>{let i=this.randomSelect(o);return[n.data[i],Math.log(o[i])]})}},k_=class extends fs{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 ct(e,s),o=de(r.data);return Array.from({length:this.generation_config.num_beams},(i,a)=>[n.data[a],Math.log(o[a])])}};var v_=class{constructor(e){if(e)for(let s in e){if(s in this)throw new TypeError(`Key "${s}" conflicts with an existing property on DynamicCache`);let r=e[s];if(!(r instanceof A))throw new TypeError(`Expected a Tensor for key "${s}", got ${typeof r}`);this[s]=r}}get_seq_length(){let e=this;for(let s in e)if(s.startsWith("past_key_values."))return e[s].dims.at(-2);throw new Error("Unable to determine sequence length from the cache.")}async dispose(){let e=[];for(let s of Object.values(this))s.location==="gpu-buffer"&&e.push(s.dispose());await Promise.all(e)}},Jr=v_;var ms=null;function T0(t){ms=t}function E_(t){if(t instanceof A)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 A("int64",BigInt64Array.from(t.flat().map(e=>BigInt(e))),[t.length,t[0].length])}else return new A("int64",BigInt64Array.from(t.map(e=>BigInt(e))),[1,t.length])}function A_(t){return new A("bool",[t],[1])}var L={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,MultimodalLanguageModelOnly:16,VoxtralRealtime:17},Zs={[L.DecoderOnly]:{can_generate:!0,forward:We,prepare_inputs:er,sessions:(t,e)=>({model:e.model_file_name??"model"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[L.DecoderOnlyWithoutHead]:{can_generate:!1,forward:We,prepare_inputs:er,sessions:(t,e)=>({model:e.model_file_name??"model"})},[L.Seq2Seq]:{can_generate:!0,forward:el,prepare_inputs:en,sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.Vision2Seq]:{can_generate:!0,forward:el,prepare_inputs:en,sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.Musicgen]:{can_generate:!0,forward:el,sessions:()=>({model:"text_encoder",decoder_model_merged:"decoder_model_merged",encodec_decode:"encodec_decode"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.EncoderDecoder]:{can_generate:!1,forward:el,sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0}},[L.MaskGeneration]:{sessions:()=>({model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"})},[L.ImageTextToText]:{can_generate:!0,forward:z0,prepare_inputs:Zr,sessions:t=>{let e={embed_tokens:"embed_tokens",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};return t.is_encoder_decoder&&(e.model="encoder_model"),e},cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.AudioTextToText]:{can_generate:!0,forward:oA,prepare_inputs:Zr,sessions:()=>({embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.ImageAudioTextToText]:{can_generate:!0,prepare_inputs:Zr,sessions:()=>({embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"}),optional_configs:{generation_config:"generation_config.json"}},[L.Phi3V]:{can_generate:!0,prepare_inputs:Zr,sessions:()=>({prepare_inputs_embeds:"prepare_inputs_embeds",model:"model",vision_encoder:"vision_encoder"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[L.MultiModality]:{can_generate:!0,sessions:()=>({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"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[L.AutoEncoder]:{can_generate:!1,forward:nA,sessions:()=>({encoder_model:"encoder_model",decoder_model:"decoder_model"})},[L.Supertonic]:{sessions:()=>({text_encoder:"text_encoder",latent_denoiser:"latent_denoiser",voice_decoder:"voice_decoder"})},[L.Chatterbox]:{can_generate:!0,forward:et,sessions:()=>({embed_tokens:"embed_tokens",speech_encoder:"speech_encoder",model:"language_model",conditional_decoder:"conditional_decoder"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[L.MultimodalLanguageModelOnly]:{can_generate:!0,forward:z0,prepare_inputs:Zr,sessions:()=>({embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.VoxtralRealtime]:{can_generate:!0,prepare_inputs:er,sessions:()=>({embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0,audio_encoder:!0},optional_configs:{generation_config:"generation_config.json"}},default:{can_generate:!1,forward:et,sessions:(t,e)=>({model:e.model_file_name??"model"})}};function C0(t,e,s={}){let r=Zs[t]??Zs.default;return{sessions:r.sessions(e,s),cache_sessions:r.cache_sessions,optional_configs:r.optional_configs}}var ut=new Map,tl=new Map,hs=new Map,f=class extends Me{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=ut.get(n),i=Zs[o]??Zs.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:_={}}={}){let d={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:_},m=hs.get(this),h=ut.get(m);r=d.config=await Je.from_pretrained(e,d);let g=Zs[h]??Zs.default;if(h===void 0){let b=m??r?.model_type;b!=="custom"&&F.warn(`Model type for '${b}' not found, assuming encoder-only architecture. Please report this at ${Dt}.`)}let x=g.sessions(r,d),w=[A0(e,x,d,g.cache_sessions)];g.optional_configs&&w.push(aA(e,g.optional_configs,d));let y=await Promise.all(w);return new this(r,...y)}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 ds;if(e.repetition_penalty!==null&&e.repetition_penalty!==1&&n.push(new Va(e.repetition_penalty)),e.no_repeat_ngram_size!==null&&e.no_repeat_ngram_size>0&&n.push(new Wa(e.no_repeat_ngram_size)),e.bad_words_ids!==null&&n.push(new Xa(e.bad_words_ids,e.eos_token_id)),e.min_length!==null&&e.eos_token_id!==null&&e.min_length>0&&n.push(new Ha(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 Ka(s,e.min_new_tokens,e.eos_token_id)),e.forced_bos_token_id!==null&&n.push(new qa(e.forced_bos_token_id)),e.forced_eos_token_id!==null&&n.push(new Ua(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 Qa(e.guidance_scale)),e.temperature===0&&e.do_sample&&(F.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 Ya(e.temperature)),r!==null&&n.extend(r),n}_prepare_generation_config(e,s,r=Ys){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,ke(s,Object.getOwnPropertyNames(o))),o}_get_stopping_criteria(e,s=null){let r=new Js;return e.max_length!==null&&r.push(new Ja(e.max_length,this.config.max_position_embeddings??null)),e.eos_token_id!==null&&r.push(new Za(e.eos_token_id)),s&&r.extend(s),r}_validate_model_class(){if(!this.can_generate){let e=[ms.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,ms.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,ms.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,ms.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 A("int64",e.flat(),[e.length,1]),n?"decoder_attention_mask"in r:r.attention_mask=ie([r.attention_mask,Se([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=ke(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,...ke(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,Rr(o,0)],0),"attention_mask"in s&&(s.attention_mask=ie([s.attention_mask,Vc(s.attention_mask)],0));else if(s.decoder_input_ids){let i=E_(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 A)){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=E_(a)}return r.decoder_attention_mask=_a(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 _=p.dims.at(-1);s.max_new_tokens!==null&&(s.max_length=_+s.max_new_tokens);let d=this._get_logits_processor(s,_,r),m=this._get_stopping_criteria(s,n),h=l[c].dims.at(0),g=fs.getSampler(s),x=new Array(h).fill(0),w=p.tolist();o&&o.put(w);let y,b={},M={};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 $=this.getAttentions(y);for(let q in $)q in b||(b[q]=[]),b[q].push($[q])}else this._return_dict_in_generate_keys&&Object.assign(M,ke(y,this._return_dict_in_generate_keys));let N=y.logits.slice(null,-1,null).to("float32"),R=d(w,N),C=[];for(let $=0;$<R.dims.at(0);++$){let q=R[$],B=await g(q);for(let[G,ee]of B){let se=BigInt(G);x[$]+=ee,w[$].push(se),C.push([se]);break}}if(o&&o.put(C),m(w).every($=>$))break;l=this._update_model_kwargs_for_generation({generated_input_ids:C,outputs:y,model_inputs:l,is_encoder_decoder:u})}o&&o.end();let k=this.getPastKeyValues(y,l.past_key_values,!0),O=new A("int64",w.flat(),[w.length,w[0].length]);if(s.return_dict_in_generate)return{sequences:O,past_key_values:k,...b,...M};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 new Jr(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"?At.float16:At.float32,a=_s(this.config,{batch_size:n});for(let l in a){let c=a[l].reduce((u,p)=>u*p,1);e[l]=new A(o,new i(c),a[l])}}}async _encode_input(e,s,r){if(!Object.hasOwn(this.sessions,e))throw new Error(`Model does not have a ${e} session.`);let n=this.sessions[e];return(await X(n,ke(s,n.inputNames)))[r]}async encode_image(e){return this._encode_input("vision_encoder",e,"image_features")}async encode_text(e){return this._encode_input("embed_tokens",e,"inputs_embeds")}async encode_audio(e){return this._encode_input("audio_encoder",e,"audio_features")}};async function el(t,e){let{encoder_outputs:s,input_ids:r,decoder_input_ids:n,...o}=e;if(!s){let i=ke(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 We(t,o,!0)}async function et(t,e){let s=t.sessions.model,r=ke(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=Vc(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=Se([n[0],n[2],n[3]])}return await X(s,r)}async function nA(t,e){let s=await t.encode(e);return await t.decode(s)}async function We(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=A_(!!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=iA(o,n,a)}r.inputNames.includes("num_logits_to_keep")&&!o.num_logits_to_keep&&(o.num_logits_to_keep=new A("int64",[0n],[])),t.addPastKeyValues(o,n);let i=ke(o,r.inputNames);return await X(r,i)}async function P0(t,{encode_function:e,merge_function:s,modality_input_names: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,..._}){if(!l){l=await t.encode_text({input_ids:o,..._});let m=ke(_,r);if(Object.keys(m).length>0){if(o.dims[1]!==1){let h=await e({...m,..._});({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],g=c.get_seq_length();i=ie([Se([o.dims[0],g]),i.slice(null,[i.dims[1]-h,i.dims[1]])],1)}}}if(!a&&["qwen2_vl","qwen2_vl_text","qwen2_5_vl","qwen2_5_vl_text","qwen3_vl","qwen3_vl_text","qwen3_vl_moe","qwen3_vl_moe_text","qwen3_5","qwen3_5_text","qwen3_5_moe","qwen3_5_moe_text"].includes(t.config.model_type)){let{image_grid_thw:m,video_grid_thw:h}=_;[a]=t.get_rope_index(o,m,h,i)}return await We(t,{inputs_embeds:l,past_key_values:c,attention_mask:i,position_ids:a,generation_config:u,logits_processor:p},!0)}async function oA(t,e){return await P0(t,{...e,modality_input_names:["audio_values","input_features"],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 z0(t,e){return await P0(t,{...e,modality_input_names:["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 M_(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 iA(t,e=null,s=0){let{input_ids:r,inputs_embeds:n,attention_mask:o}=t,{data:i,dims:a}=M_(o,s),l=new A("int64",i,a);if(e){let c=-(r??n).dims.at(1);l=l.slice(null,[c,null])}return l}function er(t,e,s,r){let n=s.past_key_values?s.past_key_values.get_seq_length():0;if((t.sessions.decoder_model_merged??t.sessions.model)?.inputNames.includes("num_logits_to_keep")&&!s.num_logits_to_keep&&(s.num_logits_to_keep=new A("int64",[1n],[])),!s.attention_mask){let i;for(let a of["input_ids","inputs_embeds","position_ids"])if(s[a]){i=s[a].dims;break}if(!i)throw new Error("attention_mask is not provided, and unable to infer its shape from model inputs.");s.attention_mask=Se([i[0],n+i[1]])}if(s.past_key_values){let{input_ids:i,attention_mask:a}=s;a&&a.dims[1]>i.dims[1]||n<i.dims[1]&&(s.input_ids=i.slice(null,[n,null]))}return s}function en(t,e,s,r){return s.past_key_values&&(e=e.map(n=>[n.at(-1)])),{...s,decoder_input_ids:E_(e)}}function Zr(t,...e){return t.config.is_encoder_decoder?en(t,...e):er(t,...e)}function L0({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,_)=>(p==t&&u.push(_),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 _=0;_<u.length;++_)p[u[_]].data.set(s[l++].data)}return{inputs_embeds:e,attention_mask:n}}function tr({image_token_id:t,inputs_embeds:e,image_features:s,input_ids:r,attention_mask:n}){return L0({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n})}function sl({audio_token_id:t,inputs_embeds:e,audio_features:s,input_ids:r,attention_mask:n}){return L0({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n})}async function aA(t,e,s){return Object.fromEntries(await Promise.all(Object.keys(e).map(async r=>{let n=await Ce(t,e[r],!1,s);return[r,n]})))}var _i={};Ts(_i,{ASTForAudioClassification:()=>R_,ASTModel:()=>$_,ASTPreTrainedModel:()=>nn,AfmoeForCausalLM:()=>L_,AfmoeModel:()=>P_,AfmoePreTrainedModel:()=>sn,AlbertForMaskedLM:()=>z_,AlbertForQuestionAnswering:()=>I_,AlbertForSequenceClassification:()=>O_,AlbertModel:()=>S_,AlbertPreTrainedModel:()=>gs,ApertusForCausalLM:()=>C_,ApertusModel:()=>T_,ApertusPreTrainedModel:()=>tn,ArceeForCausalLM:()=>F_,ArceeModel:()=>N_,ArceePreTrainedModel:()=>rn,BartForConditionalGeneration:()=>j_,BartForSequenceClassification:()=>B_,BartModel:()=>D_,BartPretrainedModel:()=>sr,BeitForImageClassification:()=>U_,BeitModel:()=>q_,BeitPreTrainedModel:()=>on,BertForMaskedLM:()=>W_,BertForQuestionAnswering:()=>K_,BertForSequenceClassification:()=>V_,BertForTokenClassification:()=>H_,BertModel:()=>G_,BertPreTrainedModel:()=>Ut,BlenderbotForConditionalGeneration:()=>Q_,BlenderbotModel:()=>X_,BlenderbotPreTrainedModel:()=>an,BlenderbotSmallForConditionalGeneration:()=>J_,BlenderbotSmallModel:()=>Y_,BlenderbotSmallPreTrainedModel:()=>ln,BloomForCausalLM:()=>ed,BloomModel:()=>Z_,BloomPreTrainedModel:()=>cn,CLIPModel:()=>ld,CLIPPreTrainedModel:()=>wt,CLIPSegForImageSegmentation:()=>dd,CLIPSegModel:()=>_d,CLIPSegPreTrainedModel:()=>fn,CLIPTextModel:()=>cd,CLIPTextModelWithProjection:()=>dn,CLIPVisionModel:()=>ud,CLIPVisionModelWithProjection:()=>pd,CamembertForMaskedLM:()=>sd,CamembertForQuestionAnswering:()=>od,CamembertForSequenceClassification:()=>rd,CamembertForTokenClassification:()=>nd,CamembertModel:()=>td,CamembertPreTrainedModel:()=>Gt,ChatterboxModel:()=>un,ChatterboxPreTrainedModel:()=>rl,ChineseCLIPModel:()=>id,ChineseCLIPPreTrainedModel:()=>nl,ClapAudioModelWithProjection:()=>_n,ClapModel:()=>ad,ClapPreTrainedModel:()=>rr,ClapTextModelWithProjection:()=>pn,CodeGenForCausalLM:()=>md,CodeGenModel:()=>fd,CodeGenPreTrainedModel:()=>mn,Cohere2ForCausalLM:()=>wd,Cohere2Model:()=>xd,Cohere2PreTrainedModel:()=>gn,CohereForCausalLM:()=>gd,CohereModel:()=>hd,CoherePreTrainedModel:()=>hn,ConvBertForMaskedLM:()=>bd,ConvBertForQuestionAnswering:()=>Ed,ConvBertForSequenceClassification:()=>kd,ConvBertForTokenClassification:()=>vd,ConvBertModel:()=>yd,ConvBertPreTrainedModel:()=>Wt,ConvNextForImageClassification:()=>Md,ConvNextModel:()=>Ad,ConvNextPreTrainedModel:()=>xn,ConvNextV2ForImageClassification:()=>Od,ConvNextV2Model:()=>Sd,ConvNextV2PreTrainedModel:()=>wn,DFineForObjectDetection:()=>Cd,DFineModel:()=>Td,DFinePreTrainedModel:()=>bn,DINOv3ConvNextModel:()=>sf,DINOv3ConvNextPreTrainedModel:()=>pl,DINOv3ViTModel:()=>rf,DINOv3ViTPreTrainedModel:()=>_l,DPTForDepthEstimation:()=>_f,DPTModel:()=>pf,DPTPreTrainedModel:()=>Sn,DacDecoderModel:()=>vn,DacDecoderOutput:()=>il,DacEncoderModel:()=>kn,DacEncoderOutput:()=>ol,DacModel:()=>Pd,DacPreTrainedModel:()=>nr,DebertaForMaskedLM:()=>Nd,DebertaForQuestionAnswering:()=>Rd,DebertaForSequenceClassification:()=>Fd,DebertaForTokenClassification:()=>$d,DebertaModel:()=>Ld,DebertaPreTrainedModel:()=>Vt,DebertaV2ForMaskedLM:()=>jd,DebertaV2ForQuestionAnswering:()=>Ud,DebertaV2ForSequenceClassification:()=>Bd,DebertaV2ForTokenClassification:()=>qd,DebertaV2Model:()=>Dd,DebertaV2PreTrainedModel:()=>Ht,DecisionTransformerModel:()=>Gd,DecisionTransformerPreTrainedModel:()=>al,DeiTForImageClassification:()=>Vd,DeiTModel:()=>Wd,DeiTPreTrainedModel:()=>En,DepthAnythingForDepthEstimation:()=>Hd,DepthAnythingPreTrainedModel:()=>ll,DepthProForDepthEstimation:()=>Kd,DepthProPreTrainedModel:()=>cl,DetrForObjectDetection:()=>Qd,DetrForSegmentation:()=>Yd,DetrModel:()=>Xd,DetrObjectDetectionOutput:()=>ir,DetrPreTrainedModel:()=>or,DetrSegmentationOutput:()=>ul,Dinov2ForImageClassification:()=>Zd,Dinov2Model:()=>Jd,Dinov2PreTrainedModel:()=>An,Dinov2WithRegistersForImageClassification:()=>tf,Dinov2WithRegistersModel:()=>ef,Dinov2WithRegistersPreTrainedModel:()=>Mn,DistilBertForMaskedLM:()=>cf,DistilBertForQuestionAnswering:()=>lf,DistilBertForSequenceClassification:()=>of,DistilBertForTokenClassification:()=>af,DistilBertModel:()=>nf,DistilBertPreTrainedModel:()=>Kt,DonutSwinModel:()=>uf,DonutSwinPreTrainedModel:()=>dl,EdgeTamModel:()=>ix,EfficientNetForImageClassification:()=>ff,EfficientNetModel:()=>df,EfficientNetPreTrainedModel:()=>On,ElectraForMaskedLM:()=>hf,ElectraForQuestionAnswering:()=>wf,ElectraForSequenceClassification:()=>gf,ElectraForTokenClassification:()=>xf,ElectraModel:()=>mf,ElectraPreTrainedModel:()=>Xt,Ernie4_5ForCausalLM:()=>bf,Ernie4_5Model:()=>yf,Ernie4_5PretrainedModel:()=>In,EsmForMaskedLM:()=>vf,EsmForSequenceClassification:()=>Ef,EsmForTokenClassification:()=>Af,EsmModel:()=>kf,EsmPreTrainedModel:()=>xs,ExaoneForCausalLM:()=>Sf,ExaoneModel:()=>Mf,ExaonePreTrainedModel:()=>zn,FalconForCausalLM:()=>If,FalconH1ForCausalLM:()=>Tf,FalconH1Model:()=>zf,FalconH1PreTrainedModel:()=>Cn,FalconModel:()=>Of,FalconPreTrainedModel:()=>Tn,FastViTForImageClassification:()=>Pf,FastViTModel:()=>Cf,FastViTPreTrainedModel:()=>Pn,Florence2ForConditionalGeneration:()=>Lf,Florence2PreTrainedModel:()=>fl,GLPNForDepthEstimation:()=>Gf,GLPNModel:()=>Uf,GLPNPreTrainedModel:()=>Dn,GPT2LMHeadModel:()=>em,GPT2Model:()=>Zf,GPT2PreTrainedModel:()=>Gn,GPTBigCodeForCausalLM:()=>Vf,GPTBigCodeModel:()=>Wf,GPTBigCodePreTrainedModel:()=>jn,GPTJForCausalLM:()=>sm,GPTJModel:()=>tm,GPTJPreTrainedModel:()=>Wn,GPTNeoForCausalLM:()=>Kf,GPTNeoModel:()=>Hf,GPTNeoPreTrainedModel:()=>Bn,GPTNeoXForCausalLM:()=>Qf,GPTNeoXModel:()=>Xf,GPTNeoXPreTrainedModel:()=>qn,Gemma2ForCausalLM:()=>Rf,Gemma2Model:()=>$f,Gemma2PreTrainedModel:()=>Nn,Gemma3ForCausalLM:()=>jf,Gemma3Model:()=>Df,Gemma3PreTrainedModel:()=>Fn,Gemma3nForCausalLM:()=>$n,Gemma3nForConditionalGeneration:()=>ar,Gemma3nPreTrainedModel:()=>ml,GemmaForCausalLM:()=>Ff,GemmaModel:()=>Nf,GemmaPreTrainedModel:()=>Ln,GlmForCausalLM:()=>qf,GlmModel:()=>Bf,GlmPreTrainedModel:()=>Rn,GptOssForCausalLM:()=>Jf,GptOssModel:()=>Yf,GptOssPreTrainedModel:()=>Un,GraniteForCausalLM:()=>nm,GraniteModel:()=>rm,GraniteMoeHybridForCausalLM:()=>im,GraniteMoeHybridModel:()=>om,GraniteMoeHybridPreTrainedModel:()=>Hn,GranitePreTrainedModel:()=>Vn,GraniteSpeechForConditionalGeneration:()=>am,GroundingDinoForObjectDetection:()=>lm,GroundingDinoPreTrainedModel:()=>gl,GroupViTModel:()=>cm,GroupViTPreTrainedModel:()=>xl,HeliumForCausalLM:()=>pm,HeliumModel:()=>um,HeliumPreTrainedModel:()=>Kn,HieraForImageClassification:()=>dm,HieraModel:()=>_m,HieraPreTrainedModel:()=>Xn,HubertForCTC:()=>ym,HubertForSequenceClassification:()=>bm,HubertModel:()=>wm,HubertPreTrainedModel:()=>xm,HunYuanDenseV1ForCausalLM:()=>vm,HunYuanDenseV1Model:()=>km,HunYuanDenseV1PreTrainedModel:()=>Qn,IJepaForImageClassification:()=>Om,IJepaModel:()=>Sm,IJepaPreTrainedModel:()=>Yn,Idefics3ForConditionalGeneration:()=>Mm,JAISLMHeadModel:()=>zm,JAISModel:()=>Im,JAISPreTrainedModel:()=>Jn,JinaCLIPModel:()=>Tm,JinaCLIPPreTrainedModel:()=>lr,JinaCLIPTextModel:()=>Zn,JinaCLIPVisionModel:()=>Cm,Lfm2ForCausalLM:()=>Lm,Lfm2Model:()=>Pm,Lfm2MoeForCausalLM:()=>Fm,Lfm2MoeModel:()=>Nm,Lfm2MoePreTrainedModel:()=>to,Lfm2PreTrainedModel:()=>eo,Lfm2VlForConditionalGeneration:()=>$m,LiteWhisperForConditionalGeneration:()=>ww,Llama4ForCausalLM:()=>jm,Llama4PreTrainedModel:()=>yl,LlamaForCausalLM:()=>Dm,LlamaModel:()=>Rm,LlamaPreTrainedModel:()=>so,LlavaForConditionalGeneration:()=>tt,LlavaOnevisionForConditionalGeneration:()=>tt,LlavaPreTrainedModel:()=>wl,LlavaQwen2ForCausalLM:()=>Am,LongT5ForConditionalGeneration:()=>qm,LongT5Model:()=>Bm,LongT5PreTrainedModel:()=>ro,M2M100ForConditionalGeneration:()=>Gm,M2M100Model:()=>Um,M2M100PreTrainedModel:()=>no,MBartForCausalLM:()=>Jm,MBartForConditionalGeneration:()=>Qm,MBartForSequenceClassification:()=>Ym,MBartModel:()=>Xm,MBartPreTrainedModel:()=>ys,MPNetForMaskedLM:()=>Fh,MPNetForQuestionAnswering:()=>Dh,MPNetForSequenceClassification:()=>$h,MPNetForTokenClassification:()=>Rh,MPNetModel:()=>Nh,MPNetPreTrainedModel:()=>Qt,MT5ForConditionalGeneration:()=>Uh,MT5Model:()=>qh,MT5PreTrainedModel:()=>go,MarianMTModel:()=>Vm,MarianModel:()=>Wm,MarianPreTrainedModel:()=>oo,MaskFormerForInstanceSegmentation:()=>Km,MaskFormerModel:()=>Hm,MaskFormerPreTrainedModel:()=>io,Metric3DForDepthEstimation:()=>Zm,Metric3DPreTrainedModel:()=>bl,Metric3Dv2ForDepthEstimation:()=>eh,Metric3Dv2PreTrainedModel:()=>kl,MgpstrForSceneTextRecognition:()=>th,MgpstrModelOutput:()=>vl,MgpstrPreTrainedModel:()=>El,MimiDecoderModel:()=>lo,MimiDecoderOutput:()=>Ml,MimiEncoderModel:()=>ao,MimiEncoderOutput:()=>Al,MimiModel:()=>sh,MimiPreTrainedModel:()=>cr,MistralForCausalLM:()=>nh,MistralModel:()=>rh,MistralPreTrainedModel:()=>co,MobileBertForMaskedLM:()=>ih,MobileBertForQuestionAnswering:()=>lh,MobileBertForSequenceClassification:()=>ah,MobileBertModel:()=>oh,MobileBertPreTrainedModel:()=>bs,MobileLLMForCausalLM:()=>uh,MobileLLMModel:()=>ch,MobileLLMPreTrainedModel:()=>uo,MobileNetV1ForImageClassification:()=>_h,MobileNetV1ForSemanticSegmentation:()=>dh,MobileNetV1Model:()=>ph,MobileNetV1PreTrainedModel:()=>ur,MobileNetV2ForImageClassification:()=>mh,MobileNetV2ForSemanticSegmentation:()=>hh,MobileNetV2Model:()=>fh,MobileNetV2PreTrainedModel:()=>pr,MobileNetV3ForImageClassification:()=>xh,MobileNetV3ForSemanticSegmentation:()=>wh,MobileNetV3Model:()=>gh,MobileNetV3PreTrainedModel:()=>_r,MobileNetV4ForImageClassification:()=>bh,MobileNetV4ForSemanticSegmentation:()=>kh,MobileNetV4Model:()=>yh,MobileNetV4PreTrainedModel:()=>dr,MobileViTForImageClassification:()=>Eh,MobileViTModel:()=>vh,MobileViTPreTrainedModel:()=>po,MobileViTV2ForImageClassification:()=>Mh,MobileViTV2Model:()=>Ah,MobileViTV2PreTrainedModel:()=>_o,ModernBertDecoderForCausalLM:()=>Ch,ModernBertDecoderModel:()=>Th,ModernBertDecoderPreTrainedModel:()=>fo,ModernBertForMaskedLM:()=>Oh,ModernBertForSequenceClassification:()=>Ih,ModernBertForTokenClassification:()=>zh,ModernBertModel:()=>Sh,ModernBertPreTrainedModel:()=>ks,Moondream1ForConditionalGeneration:()=>Em,MoonshineForConditionalGeneration:()=>Lh,MoonshineModel:()=>Ph,MoonshinePreTrainedModel:()=>mo,MptForCausalLM:()=>Bh,MptModel:()=>jh,MptPreTrainedModel:()=>ho,MultiModalityCausalLM:()=>Gh,MultiModalityPreTrainedModel:()=>Sl,MusicgenForCausalLM:()=>Vh,MusicgenForConditionalGeneration:()=>wo,MusicgenModel:()=>Wh,MusicgenPreTrainedModel:()=>xo,NanoChatForCausalLM:()=>Kh,NanoChatModel:()=>Hh,NanoChatPreTrainedModel:()=>yo,NeoBertForMaskedLM:()=>Qh,NeoBertForQuestionAnswering:()=>Zh,NeoBertForSequenceClassification:()=>Yh,NeoBertForTokenClassification:()=>Jh,NeoBertModel:()=>Xh,NeoBertPreTrainedModel:()=>Yt,NomicBertModel:()=>eg,NomicBertPreTrainedModel:()=>Ol,OPTForCausalLM:()=>_g,OPTModel:()=>pg,OPTPreTrainedModel:()=>Mo,Olmo2ForCausalLM:()=>ng,Olmo2Model:()=>rg,Olmo2PreTrainedModel:()=>ko,Olmo3ForCausalLM:()=>ig,Olmo3Model:()=>og,Olmo3PreTrainedModel:()=>vo,OlmoForCausalLM:()=>sg,OlmoHybridForCausalLM:()=>lg,OlmoHybridModel:()=>ag,OlmoHybridPreTrainedModel:()=>Eo,OlmoModel:()=>tg,OlmoPreTrainedModel:()=>bo,OpenELMForCausalLM:()=>ug,OpenELMModel:()=>cg,OpenELMPreTrainedModel:()=>Ao,OwlViTForObjectDetection:()=>hg,OwlViTModel:()=>mg,OwlViTPreTrainedModel:()=>Oo,Owlv2ForObjectDetection:()=>fg,Owlv2Model:()=>dg,Owlv2PreTrainedModel:()=>So,PaliGemmaForConditionalGeneration:()=>gg,ParakeetForCTC:()=>xg,ParakeetPreTrainedModel:()=>Il,PatchTSMixerForPrediction:()=>yg,PatchTSMixerModel:()=>wg,PatchTSMixerPreTrainedModel:()=>Io,PatchTSTForPrediction:()=>kg,PatchTSTModel:()=>bg,PatchTSTPreTrainedModel:()=>zo,Phi3ForCausalLM:()=>Mg,Phi3Model:()=>Ag,Phi3PreTrainedModel:()=>Co,Phi3VForCausalLM:()=>Po,Phi3VPreTrainedModel:()=>zl,PhiForCausalLM:()=>Eg,PhiModel:()=>vg,PhiPreTrainedModel:()=>To,PreTrainedModel:()=>f,PvtForImageClassification:()=>Og,PvtModel:()=>Sg,PvtPreTrainedModel:()=>Lo,PyAnnoteForAudioFrameClassification:()=>zg,PyAnnoteModel:()=>Ig,PyAnnotePreTrainedModel:()=>No,Qwen2ForCausalLM:()=>Cg,Qwen2Model:()=>Tg,Qwen2MoeForCausalLM:()=>Lg,Qwen2MoeModel:()=>Pg,Qwen2MoePreTrainedModel:()=>$o,Qwen2PreTrainedModel:()=>Fo,Qwen2VLForCausalLM:()=>vs,Qwen2VLForConditionalGeneration:()=>fr,Qwen2VLPreTrainedModel:()=>Tl,Qwen2_5_VLForCausalLM:()=>Es,Qwen2_5_VLForConditionalGeneration:()=>Ro,Qwen3ForCausalLM:()=>Fg,Qwen3Model:()=>Ng,Qwen3MoeForCausalLM:()=>Rg,Qwen3MoeModel:()=>$g,Qwen3MoePreTrainedModel:()=>jo,Qwen3NextForCausalLM:()=>jg,Qwen3NextModel:()=>Dg,Qwen3NextPreTrainedModel:()=>Bo,Qwen3PreTrainedModel:()=>Do,Qwen3VLForCausalLM:()=>Ms,Qwen3VLForConditionalGeneration:()=>As,Qwen3VLMoeForCausalLM:()=>qo,Qwen3VLMoeForConditionalGeneration:()=>Bg,Qwen3_5ForCausalLM:()=>Ss,Qwen3_5ForConditionalGeneration:()=>mr,Qwen3_5MoeForCausalLM:()=>Uo,Qwen3_5MoeForConditionalGeneration:()=>qg,RFDetrForObjectDetection:()=>Vg,RFDetrModel:()=>Wg,RFDetrObjectDetectionOutput:()=>Cl,RFDetrPreTrainedModel:()=>Wo,RTDetrForObjectDetection:()=>zd,RTDetrModel:()=>Id,RTDetrObjectDetectionOutput:()=>yt,RTDetrPreTrainedModel:()=>yn,RTDetrV2ForObjectDetection:()=>nx,RTDetrV2Model:()=>rx,RTDetrV2ObjectDetectionOutput:()=>Pl,RTDetrV2PreTrainedModel:()=>Vo,ResNetForImageClassification:()=>Gg,ResNetModel:()=>Ug,ResNetPreTrainedModel:()=>Go,RoFormerForMaskedLM:()=>Zg,RoFormerForQuestionAnswering:()=>sx,RoFormerForSequenceClassification:()=>ex,RoFormerForTokenClassification:()=>tx,RoFormerModel:()=>Jg,RoFormerPreTrainedModel:()=>Zt,RobertaForMaskedLM:()=>Kg,RobertaForQuestionAnswering:()=>Yg,RobertaForSequenceClassification:()=>Xg,RobertaForTokenClassification:()=>Qg,RobertaModel:()=>Hg,RobertaPreTrainedModel:()=>Jt,Sam2ImageSegmentationOutput:()=>Fl,Sam2Model:()=>Ho,Sam2PreTrainedModel:()=>$l,Sam3TrackerModel:()=>ax,SamImageSegmentationOutput:()=>Ll,SamModel:()=>ox,SamPreTrainedModel:()=>Nl,SapiensForDepthEstimation:()=>cx,SapiensForNormalEstimation:()=>ux,SapiensForSemanticSegmentation:()=>lx,SapiensPreTrainedModel:()=>hr,SegformerForImageClassification:()=>_x,SegformerForSemanticSegmentation:()=>dx,SegformerModel:()=>px,SegformerPreTrainedModel:()=>gr,SiglipModel:()=>fx,SiglipPreTrainedModel:()=>Ko,SiglipTextModel:()=>Xo,SiglipVisionModel:()=>mx,SmolLM3ForCausalLM:()=>gx,SmolLM3Model:()=>hx,SmolLM3PreTrainedModel:()=>Qo,SnacDecoderModel:()=>Jo,SnacEncoderModel:()=>Yo,SnacModel:()=>xx,SnacPreTrainedModel:()=>xr,SpeechT5ForSpeechToText:()=>yx,SpeechT5ForTextToSpeech:()=>bx,SpeechT5HifiGan:()=>kx,SpeechT5Model:()=>wx,SpeechT5PreTrainedModel:()=>wr,SqueezeBertForMaskedLM:()=>Ex,SqueezeBertForQuestionAnswering:()=>Mx,SqueezeBertForSequenceClassification:()=>Ax,SqueezeBertModel:()=>vx,SqueezeBertPreTrainedModel:()=>Os,StableLmForCausalLM:()=>Ox,StableLmModel:()=>Sx,StableLmPreTrainedModel:()=>Zo,Starcoder2ForCausalLM:()=>zx,Starcoder2Model:()=>Ix,Starcoder2PreTrainedModel:()=>ei,StyleTextToSpeech2Model:()=>Tx,StyleTextToSpeech2PreTrainedModel:()=>Rl,SupertonicForConditionalGeneration:()=>ti,SupertonicPreTrainedModel:()=>Dl,Swin2SRForImageSuperResolution:()=>Fx,Swin2SRModel:()=>Nx,Swin2SRPreTrainedModel:()=>si,SwinForImageClassification:()=>Px,SwinForSemanticSegmentation:()=>Lx,SwinModel:()=>Cx,SwinPreTrainedModel:()=>yr,T5ForConditionalGeneration:()=>Rx,T5Model:()=>$x,T5PreTrainedModel:()=>ri,TableTransformerForObjectDetection:()=>jx,TableTransformerModel:()=>Dx,TableTransformerObjectDetectionOutput:()=>jl,TableTransformerPreTrainedModel:()=>ni,TrOCRForCausalLM:()=>Bx,TrOCRPreTrainedModel:()=>Bl,UltravoxModel:()=>ws,UltravoxPreTrainedModel:()=>hl,UniSpeechForCTC:()=>Ux,UniSpeechForSequenceClassification:()=>Gx,UniSpeechModel:()=>qx,UniSpeechPreTrainedModel:()=>br,UniSpeechSatForAudioFrameClassification:()=>Kx,UniSpeechSatForCTC:()=>Vx,UniSpeechSatForSequenceClassification:()=>Hx,UniSpeechSatModel:()=>Wx,UniSpeechSatPreTrainedModel:()=>Is,VaultGemmaForCausalLM:()=>Qx,VaultGemmaModel:()=>Xx,VaultGemmaPreTrainedModel:()=>oi,ViTForImageClassification:()=>Zx,ViTMAEModel:()=>ew,ViTMAEPreTrainedModel:()=>ql,ViTMSNForImageClassification:()=>sw,ViTMSNModel:()=>tw,ViTMSNPreTrainedModel:()=>ai,ViTModel:()=>Jx,ViTPreTrainedModel:()=>ii,VisionEncoderDecoderModel:()=>Yx,VitMatteForImageMatting:()=>rw,VitMattePreTrainedModel:()=>Ul,VitPoseForPoseEstimation:()=>nw,VitPosePreTrainedModel:()=>Gl,VitsModel:()=>ow,VitsModelOutput:()=>Wl,VitsPreTrainedModel:()=>Vl,VoxtralForConditionalGeneration:()=>iw,VoxtralRealtimeForConditionalGeneration:()=>li,VoxtralRealtimePreTrainedModel:()=>Hl,Wav2Vec2BertForCTC:()=>uw,Wav2Vec2BertForSequenceClassification:()=>pw,Wav2Vec2BertModel:()=>cw,Wav2Vec2BertPreTrainedModel:()=>kr,Wav2Vec2ForAudioFrameClassification:()=>gm,Wav2Vec2ForCTC:()=>mm,Wav2Vec2ForSequenceClassification:()=>hm,Wav2Vec2Model:()=>fm,Wav2Vec2PreTrainedModel:()=>pt,WavLMForAudioFrameClassification:()=>hw,WavLMForCTC:()=>dw,WavLMForSequenceClassification:()=>fw,WavLMForXVector:()=>mw,WavLMModel:()=>_w,WavLMPreTrainedModel:()=>es,WeSpeakerResNetModel:()=>gw,WeSpeakerResNetPreTrainedModel:()=>Xl,WhisperForConditionalGeneration:()=>Yl,WhisperModel:()=>xw,WhisperPreTrainedModel:()=>ci,XLMForQuestionAnswering:()=>Ew,XLMForSequenceClassification:()=>kw,XLMForTokenClassification:()=>vw,XLMModel:()=>yw,XLMPreTrainedModel:()=>ts,XLMRobertaForMaskedLM:()=>Mw,XLMRobertaForQuestionAnswering:()=>Iw,XLMRobertaForSequenceClassification:()=>Sw,XLMRobertaForTokenClassification:()=>Ow,XLMRobertaModel:()=>Aw,XLMRobertaPreTrainedModel:()=>ss,XLMWithLMHeadModel:()=>bw,XVectorOutput:()=>Kl,YolosForObjectDetection:()=>Tw,YolosModel:()=>zw,YolosObjectDetectionOutput:()=>Jl,YolosPreTrainedModel:()=>ui,YoutuForCausalLM:()=>Pw,YoutuModel:()=>Cw,YoutuPreTrainedModel:()=>pi});var gs=class extends f{},S_=class extends gs{},O_=class extends gs{async _call(e){return new z(await super._call(e))}},I_=class extends gs{async _call(e){return new le(await super._call(e))}},z_=class extends gs{async _call(e){return new re(await super._call(e))}};var tn=class extends f{},T_=class extends tn{},C_=class extends tn{};var sn=class extends f{},P_=class extends sn{},L_=class extends sn{};var rn=class extends f{},N_=class extends rn{},F_=class extends rn{};var nn=class extends f{},$_=class extends nn{},R_=class extends nn{};var sr=class extends f{},D_=class extends sr{},j_=class extends sr{},B_=class extends sr{async _call(e){return new z(await super._call(e))}};var on=class extends f{},q_=class extends on{},U_=class extends on{async _call(e){return new z(await super._call(e))}};var Ut=class extends f{},G_=class extends Ut{},W_=class extends Ut{async _call(e){return new re(await super._call(e))}},V_=class extends Ut{async _call(e){return new z(await super._call(e))}},H_=class extends Ut{async _call(e){return new te(await super._call(e))}},K_=class extends Ut{async _call(e){return new le(await super._call(e))}};var an=class extends f{},X_=class extends an{},Q_=class extends an{};var ln=class extends f{},Y_=class extends ln{},J_=class extends ln{};var cn=class extends f{},Z_=class extends cn{},ed=class extends cn{};var Gt=class extends f{},td=class extends Gt{},sd=class extends Gt{async _call(e){return new re(await super._call(e))}},rd=class extends Gt{async _call(e){return new z(await super._call(e))}},nd=class extends Gt{async _call(e){return new te(await super._call(e))}},od=class extends Gt{async _call(e){return new le(await super._call(e))}};var lA=4299n,N0=6561n,rl=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"]},un=class extends rl{async encode_speech(e){return X(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:_=null,speaker_features:d=null,...m}){let h;if(!i){let x=this.sessions.embed_tokens.inputNames,w={input_ids:e};if(x.includes("exaggeration")){if(!(n instanceof A)){let y=e.dims[0];if(n==null)n=we([y],.5);else if(typeof n=="number")n=we([y],n);else if(Array.isArray(n))n=new A("float32",n,[y]);else throw new Error("Unsupported type for `exaggeration` input")}w.exaggeration=n}if(x.includes("position_ids")&&(w.position_ids=o),{inputs_embeds:i}=await X(this.sessions.embed_tokens,w),u&&p&&_&&d&&(h={audio_features:u,audio_tokens:p,speaker_embeddings:_,speaker_features:d}),h||r)h??=await this.encode_speech(r),i=ie([h.audio_features,i],1),s=Se([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=a.get_seq_length();s=Se([i.dims[0],b+y])}}return{...await We(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==N0)-1);s.position_ids=new A("int64",n,[e.length,1])}else{let o=s.input_ids.tolist().map(i=>{let a=0;return i.map(l=>l>=N0?0:a++)});s.position_ids=new A("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),er(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=we([i.dims[0],3],lA),l=ie([r,i,a],1),{waveform:c}=await X(this.sessions.conditional_decoder,{speech_tokens:l,speaker_features:o,speaker_embeddings:n});return c}};var nl=class extends f{},id=class extends nl{};var rr=class extends f{},ad=class extends rr{},pn=class extends rr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},_n=class extends rr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"audio_model"})}};var wt=class extends f{},ld=class extends wt{},cd=class extends wt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},dn=class extends wt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},ud=class extends wt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}},pd=class extends wt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var fn=class extends f{},_d=class extends fn{},dd=class extends fn{};var mn=class extends f{},fd=class extends mn{},md=class extends mn{};var hn=class extends f{},hd=class extends hn{},gd=class extends hn{};var gn=class extends f{},xd=class extends gn{},wd=class extends gn{};var Wt=class extends f{},yd=class extends Wt{},bd=class extends Wt{async _call(e){return new re(await super._call(e))}},kd=class extends Wt{async _call(e){return new z(await super._call(e))}},vd=class extends Wt{async _call(e){return new te(await super._call(e))}},Ed=class extends Wt{async _call(e){return new le(await super._call(e))}};var xn=class extends f{},Ad=class extends xn{},Md=class extends xn{async _call(e){return new z(await super._call(e))}};var wn=class extends f{},Sd=class extends wn{},Od=class extends wn{async _call(e){return new z(await super._call(e))}};var yn=class extends f{},Id=class extends yn{},zd=class extends yn{async _call(e){return new yt(await super._call(e))}},yt=class extends fe{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}};var bn=class extends f{},Td=class extends bn{},Cd=class extends bn{async _call(e){return new yt(await super._call(e))}};var ol=class extends fe{constructor({audio_codes:e}){super(),this.audio_codes=e}},il=class extends fe{constructor({audio_values:e}){super(),this.audio_values=e}},nr=class extends f{main_input_name="input_values";forward_params=["input_values"]},Pd=class extends nr{async encode(e){return new ol(await X(this.sessions.encoder_model,e))}async decode(e){return new il(await X(this.sessions.decoder_model,e))}},kn=class extends nr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},vn=class extends nr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var Vt=class extends f{},Ld=class extends Vt{},Nd=class extends Vt{async _call(e){return new re(await super._call(e))}},Fd=class extends Vt{async _call(e){return new z(await super._call(e))}},$d=class extends Vt{async _call(e){return new te(await super._call(e))}},Rd=class extends Vt{async _call(e){return new le(await super._call(e))}};var Ht=class extends f{},Dd=class extends Ht{},jd=class extends Ht{async _call(e){return new re(await super._call(e))}},Bd=class extends Ht{async _call(e){return new z(await super._call(e))}},qd=class extends Ht{async _call(e){return new te(await super._call(e))}},Ud=class extends Ht{async _call(e){return new le(await super._call(e))}};var al=class extends f{},Gd=class extends al{};var En=class extends f{},Wd=class extends En{},Vd=class extends En{async _call(e){return new z(await super._call(e))}};var ll=class extends f{},Hd=class extends ll{};var cl=class extends f{},Kd=class extends cl{};var or=class extends f{},Xd=class extends or{},Qd=class extends or{async _call(e){return new ir(await super._call(e))}},Yd=class extends or{async _call(e){return new ul(await super._call(e))}},ir=class extends fe{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}},ul=class extends fe{constructor({logits:e,pred_boxes:s,pred_masks:r}){super(),this.logits=e,this.pred_boxes=s,this.pred_masks=r}};var An=class extends f{},Jd=class extends An{},Zd=class extends An{async _call(e){return new z(await super._call(e))}};var Mn=class extends f{},ef=class extends Mn{},tf=class extends Mn{async _call(e){return new z(await super._call(e))}};var pl=class extends f{},sf=class extends pl{};var _l=class extends f{},rf=class extends _l{};var Kt=class extends f{},nf=class extends Kt{},of=class extends Kt{async _call(e){return new z(await super._call(e))}},af=class extends Kt{async _call(e){return new te(await super._call(e))}},lf=class extends Kt{async _call(e){return new le(await super._call(e))}},cf=class extends Kt{async _call(e){return new re(await super._call(e))}};var dl=class extends f{},uf=class extends dl{};var Sn=class extends f{},pf=class extends Sn{},_f=class extends Sn{};var On=class extends f{},df=class extends On{},ff=class extends On{async _call(e){return new z(await super._call(e))}};var Xt=class extends f{},mf=class extends Xt{},hf=class extends Xt{async _call(e){return new re(await super._call(e))}},gf=class extends Xt{async _call(e){return new z(await super._call(e))}},xf=class extends Xt{async _call(e){return new te(await super._call(e))}},wf=class extends Xt{async _call(e){return new le(await super._call(e))}};var In=class extends f{},yf=class extends In{},bf=class extends In{};var xs=class extends f{},kf=class extends xs{},vf=class extends xs{async _call(e){return new re(await super._call(e))}},Ef=class extends xs{async _call(e){return new z(await super._call(e))}},Af=class extends xs{async _call(e){return new te(await super._call(e))}};var zn=class extends f{},Mf=class extends zn{},Sf=class extends zn{};var Tn=class extends f{},Of=class extends Tn{},If=class extends Tn{};var Cn=class extends f{},zf=class extends Cn{},Tf=class extends Cn{};var Pn=class extends f{},Cf=class extends Pn{},Pf=class extends Pn{async _call(e){return new z(await super._call(e))}};var fl=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"},Lf=class extends fl{_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([Se(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 We(this,{inputs_embeds:c,attention_mask:o,encoder_attention_mask:r,encoder_hidden_states:i,past_key_values:a},!0)}};var Ln=class extends f{},Nf=class extends Ln{},Ff=class extends Ln{};var Nn=class extends f{},$f=class extends Nn{},Rf=class extends Nn{};var Fn=class extends f{},Df=class extends Fn{},jf=class extends Fn{};var ml=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"]},ar=class extends ml{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,..._}){if((!a||!l)&&({inputs_embeds:a,per_layer_inputs:l}=await X(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(r){let{image_features:m}=await X(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 X(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 We(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 tr({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 sl({audio_token_id:this.config.audio_token_id,...e,audio_features:r})}},$n=class extends ar{};var Rn=class extends f{},Bf=class extends Rn{},qf=class extends Rn{};var Dn=class extends f{},Uf=class extends Dn{},Gf=class extends Dn{};var jn=class extends f{},Wf=class extends jn{},Vf=class extends jn{};var Bn=class extends f{},Hf=class extends Bn{},Kf=class extends Bn{};var qn=class extends f{},Xf=class extends qn{},Qf=class extends qn{};var Un=class extends f{},Yf=class extends Un{},Jf=class extends Un{};var Gn=class extends f{},Zf=class extends Gn{},em=class extends Gn{};var Wn=class extends f{},tm=class extends Wn{},sm=class extends Wn{};var Vn=class extends f{},rm=class extends Vn{},nm=class extends Vn{};var Hn=class extends f{},om=class extends Hn{},im=class extends Hn{};var hl=class extends f{forward_params=["input_ids","attention_mask","position_ids","audio_values","past_key_values"]},ws=class extends hl{_merge_input_ids_with_audio_features(e){let s=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,s);return sl({audio_token_id:this.config.ignore_index??this.config.audio_token_id??this.config.audio_token_index,...e,audio_features:r})}};var am=class extends ws{forward_params=["input_ids","attention_mask","input_features","past_key_values"]};var gl=class extends f{},lm=class extends gl{};var xl=class extends f{},cm=class extends xl{};var Kn=class extends f{},um=class extends Kn{},pm=class extends Kn{};var Xn=class extends f{},_m=class extends Xn{},dm=class extends Xn{async _call(e){return new z(await super._call(e))}};var pt=class extends f{},fm=class extends pt{},mm=class extends pt{async _call(e){return new qe(await super._call(e))}},hm=class extends pt{async _call(e){return new z(await super._call(e))}},gm=class extends pt{async _call(e){return new te(await super._call(e))}};var xm=class extends f{},wm=class extends pt{},ym=class extends pt{async _call(e){return new qe(await super._call(e))}},bm=class extends pt{async _call(e){return new z(await super._call(e))}};var Qn=class extends f{},km=class extends Qn{},vm=class extends Qn{};var wl=class extends f{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},tt=class extends wl{_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return tr({image_token_id:this.config.image_token_index??this.config.image_token_id,...e,image_features:r})}},Em=class extends tt{},Am=class extends tt{};var Mm=class extends tt{forward_params=["input_ids","attention_mask","pixel_values","pixel_attention_mask","position_ids","past_key_values"]};var Yn=class extends f{},Sm=class extends Yn{},Om=class extends Yn{async _call(e){return new z(await super._call(e))}};var Jn=class extends f{},Im=class extends Jn{},zm=class extends Jn{};var lr=class extends f{},Tm=class extends lr{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=Se([e.pixel_values.dims[0],1])),r){let{image_size:c}=this.config.vision_config;e.pixel_values=we([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}},Zn=class extends lr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},Cm=class extends lr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var eo=class extends f{},Pm=class extends eo{},Lm=class extends eo{};var to=class extends f{},Nm=class extends to{},Fm=class extends to{};var $m=class extends tt{forward_params=["input_ids","attention_mask","pixel_values","pixel_attention_mask","spatial_shapes","position_ids","past_key_values"]};var so=class extends f{},Rm=class extends so{},Dm=class extends so{};var yl=class extends f{},jm=class extends yl{};var ro=class extends f{},Bm=class extends ro{},qm=class extends ro{};var no=class extends f{},Um=class extends no{},Gm=class extends no{};var oo=class extends f{},Wm=class extends oo{},Vm=class extends oo{};var io=class extends f{},Hm=class extends io{},Km=class extends io{};var ys=class extends f{},Xm=class extends ys{},Qm=class extends ys{},Ym=class extends ys{async _call(e){return new z(await super._call(e))}},Jm=class extends ys{};var bl=class extends f{},Zm=class extends bl{};var kl=class extends f{},eh=class extends kl{};var vl=class extends fe{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]}},El=class extends f{},th=class extends El{async _call(e){return new vl(await super._call(e))}};var Al=class extends fe{constructor({audio_codes:e}){super(),this.audio_codes=e}},Ml=class extends fe{constructor({audio_values:e}){super(),this.audio_values=e}},cr=class extends f{main_input_name="input_values";forward_params=["input_values"]},sh=class extends cr{async encode(e){return new Al(await X(this.sessions.encoder_model,e))}async decode(e){return new Ml(await X(this.sessions.decoder_model,e))}},ao=class extends cr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},lo=class extends cr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var co=class extends f{},rh=class extends co{},nh=class extends co{};var bs=class extends f{},oh=class extends bs{},ih=class extends bs{async _call(e){return new re(await super._call(e))}},ah=class extends bs{async _call(e){return new z(await super._call(e))}},lh=class extends bs{async _call(e){return new le(await super._call(e))}};var uo=class extends f{},ch=class extends uo{},uh=class extends uo{};var ur=class extends f{},ph=class extends ur{},_h=class extends ur{async _call(e){return new z(await super._call(e))}},dh=class extends ur{};var pr=class extends f{},fh=class extends pr{},mh=class extends pr{async _call(e){return new z(await super._call(e))}},hh=class extends pr{};var _r=class extends f{},gh=class extends _r{},xh=class extends _r{async _call(e){return new z(await super._call(e))}},wh=class extends _r{};var dr=class extends f{},yh=class extends dr{},bh=class extends dr{async _call(e){return new z(await super._call(e))}},kh=class extends dr{};var po=class extends f{},vh=class extends po{},Eh=class extends po{async _call(e){return new z(await super._call(e))}};var _o=class extends f{},Ah=class extends _o{},Mh=class extends _o{async _call(e){return new z(await super._call(e))}};var ks=class extends f{},Sh=class extends ks{},Oh=class extends ks{async _call(e){return new re(await super._call(e))}},Ih=class extends ks{async _call(e){return new z(await super._call(e))}},zh=class extends ks{async _call(e){return new te(await super._call(e))}};var fo=class extends f{},Th=class extends fo{},Ch=class extends fo{};var mo=class extends f{requires_attention_mask=!1;main_input_name="input_values";forward_params=["input_values","decoder_input_ids","past_key_values"]},Ph=class extends mo{},Lh=class extends mo{};var Qt=class extends f{},Nh=class extends Qt{},Fh=class extends Qt{async _call(e){return new re(await super._call(e))}},$h=class extends Qt{async _call(e){return new z(await super._call(e))}},Rh=class extends Qt{async _call(e){return new te(await super._call(e))}},Dh=class extends Qt{async _call(e){return new le(await super._call(e))}};var ho=class extends f{},jh=class extends ho{},Bh=class extends ho{};var go=class extends f{},qh=class extends go{},Uh=class extends go{};var Sl=class extends f{},Gh=class extends Sl{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=ke(e,l.inputNames);r=await X(l,c)}else{let l=this.sessions.gen_img_embeds,c=ke({image_ids:e.input_ids},l.inputNames);r=await X(l,c)}let n={...e,...r},o=await We(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 X(i,ke(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,Rr(s.input_ids,BigInt(r.pad_token_id))],0),s.attention_mask=ie([s.attention_mask,Rr(s.attention_mask,0n)],0))),(n||!s.pixel_values)&&(s.pixel_values=we([0,0,3,384,384],1)),n&&(s.images_seq_mask=new A("bool",new Array(1).fill(!0).fill(!1,0,1),[1,1]),s.images_emb_mask=new A("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 X(o,{generated_tokens:n}),a=i.add_(1).mul_(255/2).clamp_(0,255).to("uint8"),l=[];for(let c of a){let u=ve.fromTensor(c);l.push(u)}return l}};var xo=class extends f{},Wh=class extends xo{},Vh=class extends xo{},wo=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,_=u-p;_>0&&_<=o&&(e.data[i++]=e.data[c])}let a=Math.floor(s/n),l=i/(a*n);return new A(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)),en(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 X(this.sessions.encodec_decode,{audio_codes:r});return n}};var yo=class extends f{},Hh=class extends yo{},Kh=class extends yo{};var Yt=class extends f{},Xh=class extends Yt{},Qh=class extends Yt{async _call(e){return new re(await super._call(e))}},Yh=class extends Yt{async _call(e){return new z(await super._call(e))}},Jh=class extends Yt{async _call(e){return new te(await super._call(e))}},Zh=class extends Yt{async _call(e){return new le(await super._call(e))}};var Ol=class extends f{},eg=class extends Ol{};var bo=class extends f{},tg=class extends bo{},sg=class extends bo{};var ko=class extends f{},rg=class extends ko{},ng=class extends ko{};var vo=class extends f{},og=class extends vo{},ig=class extends vo{};var Eo=class extends f{},ag=class extends Eo{},lg=class extends Eo{};var Ao=class extends f{},cg=class extends Ao{},ug=class extends Ao{};var Mo=class extends f{},pg=class extends Mo{},_g=class extends Mo{};var So=class extends f{},dg=class extends So{},fg=class extends So{};var Oo=class extends f{},mg=class extends Oo{},hg=class extends Oo{};var gg=class extends tt{};var Il=class extends f{},xg=class extends Il{async _call(e){return new qe(await super._call(e))}};var Io=class extends f{},wg=class extends Io{},yg=class extends Io{};var zo=class extends f{},bg=class extends zo{},kg=class extends zo{};var To=class extends f{},vg=class extends To{},Eg=class extends To{};var Co=class extends f{},Ag=class extends Co{},Mg=class extends Co{};var zl=class extends f{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","pixel_values","image_sizes","past_key_values"]},Po=class extends zl{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 _;if(r&&e.dims[1]!==1){if(!n)throw new Error("`image_sizes` must be provided when `pixel_values` is provided.");({image_features:_}=await X(this.sessions.vision_encoder,{pixel_values:r,image_sizes:n}))}else{let d=this.config.normalized_config.hidden_size;_=new A("float32",[],[0,d])}({inputs_embeds:i}=await X(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:_}))}return await We(this,{inputs_embeds:i,past_key_values:a,attention_mask:s,position_ids:o,generation_config:l,logits_processor:c},!1)}};var Lo=class extends f{},Sg=class extends Lo{},Og=class extends Lo{async _call(e){return new z(await super._call(e))}};var No=class extends f{},Ig=class extends No{},zg=class extends No{async _call(e){return new te(await super._call(e))}};var Fo=class extends f{},Tg=class extends Fo{},Cg=class extends Fo{};var $o=class extends f{},Pg=class extends $o{},Lg=class extends $o{};var Tl=class extends f{forward_params=["input_ids","attention_mask","position_ids","past_key_values","pixel_values","image_grid_thw"]},fr=class extends Tl{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=_a(e));let _=n.tolist(),d=Array.from({length:3},w=>Array.from({length:e.dims[0]},y=>Array.from({length:e.dims[1]},b=>1))),m=s?s.tolist():[],h=r?r.tolist():[],g=0,x=0;for(let w=0;w<p.length;++w){let y=p[w].filter((v,E)=>_[w][E]==1),M=y.reduce((v,E,I)=>(E==l&&v.push(I),v),[]).map(v=>y[v+1]),k=M.filter(v=>v==i).length,O=M.filter(v=>v==a).length,N=[],R=0,C=k,D=O;for(let v=0;v<M.length;++v){let E=y.findIndex((dt,rt)=>rt>R&&dt==i),I=y.findIndex((dt,rt)=>rt>R&&dt==a),H=C>0&&E!==-1?E:y.length+1,be=D>0&&I!==-1?I:y.length+1,Q,je,Ne,bt;H<be?([je,Ne,bt]=m[g],++g,--C,Q=H):([je,Ne,bt]=h[x],++x,--D,Q=be);let[ns,_t,st]=[Number(je),Math.floor(Number(Ne)/c),Math.floor(Number(bt)/c)],kt=Q-R,Tt=N.length>0?ue(N.at(-1))[0]+1:0;N.push(Array.from({length:3*kt},(dt,rt)=>Tt+rt%kt));let os=kt+Tt,Ct=ns*_t*st,qi=Array.from({length:Ct},(dt,rt)=>os+Math.floor(rt/(_t*st))),Ui=Array.from({length:Ct},(dt,rt)=>os+Math.floor(rt/st)%_t),Gi=Array.from({length:Ct},(dt,rt)=>os+rt%st);N.push([qi,Ui,Gi].flat()),R=Q+Ct}if(R<y.length){let v=N.length>0?ue(N.at(-1))[0]+1:0,E=y.length-R;N.push(Array.from({length:3*E},(I,H)=>v+H%E))}let $=N.reduce((v,E)=>v+E.length,0),q=new Array($),B=0;for(let v=0;v<3;++v)for(let E=0;E<N.length;++E){let I=N[E],H=I.length/3;for(let be=v*H;be<(v+1)*H;++be)q[B++]=I[be]}let G=0,ee=_[w];for(let v=0;v<ee.length;++v)if(ee[v]==1){for(let E=0;E<3;++E)d[E][w][v]=q[E*$/3+G];++G}let se=ue(q)[0];u.push(se+1-p[w].length)}return[new A("int64",d.flat(1/0),[3,e.dims[0],e.dims[1]]),new A("int64",u,[u.length,1])]}else if(n){let{data:p,dims:_}=M_(n),d=BigInt64Array.from({length:3*p.length},(h,g)=>p[g%p.length]),m=Array.from({length:_[0]},(h,g)=>ue(p.subarray(_[1]*g,_[1]*(g+1)))[0]+1n+BigInt(_[1]));return[new A("int64",d,[3,..._]),new A("int64",m,[m.length,1])]}else{let[p,_]=e.dims,d=BigInt64Array.from({length:3*p*_},(m,h)=>BigInt(Math.floor(h%_/p)));return[new A("int64",d,[3,...e.dims]),Wc([p,1])]}}async encode_image({pixel_values:e,image_grid_thw:s}){return(await X(this.sessions.vision_encoder,{pixel_values:e,[this.image_grid_thw_name]:s})).image_features}_merge_input_ids_with_image_features(e){return tr({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=s.past_key_values.get_seq_length();if(n<s.input_ids.dims[1]){let[o,i]=this.get_rope_index(s.input_ids,s.image_grid_thw,s.video_grid_thw,s.attention_mask);s.rope_deltas=i,s.position_ids=o.slice(null,null,[n,null]),s.input_ids=s.input_ids.slice(null,[n,null])}else{s.rope_deltas||([,s.rope_deltas]=this.get_rope_index(s.input_ids,s.image_grid_thw,s.video_grid_thw,s.attention_mask));let o=BigInt(n),i=s.rope_deltas.map(a=>o+a);s.position_ids=Ge([i,i,i],0)}}return s}},vs=class extends fr{};var Ro=class extends fr{image_grid_thw_name="image_grid_thw"},Es=class extends vs{image_grid_thw_name="image_grid_thw"};var Do=class extends f{},Ng=class extends Do{},Fg=class extends Do{};var jo=class extends f{},$g=class extends jo{},Rg=class extends jo{};var Bo=class extends f{},Dg=class extends Bo{},jg=class extends Bo{};var As=class extends Ro{},Ms=class extends Es{};var Bg=class extends As{},qo=class extends Ms{};var mr=class extends As{},Ss=class extends mr{};var qg=class extends mr{},Uo=class extends Ss{};var Go=class extends f{},Ug=class extends Go{},Gg=class extends Go{async _call(e){return new z(await super._call(e))}};var Wo=class extends f{},Wg=class extends Wo{},Vg=class extends Wo{async _call(e){return new Cl(await super._call(e))}},Cl=class extends yt{};var Jt=class extends f{},Hg=class extends Jt{},Kg=class extends Jt{async _call(e){return new re(await super._call(e))}},Xg=class extends Jt{async _call(e){return new z(await super._call(e))}},Qg=class extends Jt{async _call(e){return new te(await super._call(e))}},Yg=class extends Jt{async _call(e){return new le(await super._call(e))}};var Zt=class extends f{},Jg=class extends Zt{},Zg=class extends Zt{async _call(e){return new re(await super._call(e))}},ex=class extends Zt{async _call(e){return new z(await super._call(e))}},tx=class extends Zt{async _call(e){return new te(await super._call(e))}},sx=class extends Zt{async _call(e){return new le(await super._call(e))}};var Vo=class extends f{},rx=class extends Vo{},nx=class extends Vo{async _call(e){return new Pl(await super._call(e))}},Pl=class extends yt{};var Ll=class extends fe{constructor({iou_scores:e,pred_masks:s}){super(),this.iou_scores=e,this.pred_masks=s}},Nl=class extends f{},ox=class extends Nl{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??=Se(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 X(this.sessions.prompt_encoder_mask_decoder,s)}async _call(e){return new Ll(await super._call(e))}};var Fl=class extends fe{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}},$l=class extends f{},Ho=class extends $l{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??=Se(i.slice(0,-1)),e.input_boxes??=we([i[0],0,4],0)}else if(e.input_boxes){let i=e.input_boxes.dims;e.input_labels=we([i[0],i[1],0],-1n),e.input_points=we([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=ke(e,n.inputNames);return await X(n,o)}async _call(e){return new Fl(await super._call(e))}},ix=class extends Ho{},ax=class extends Ho{};var hr=class extends f{},lx=class extends hr{},cx=class extends hr{},ux=class extends hr{};var gr=class extends f{},px=class extends gr{},_x=class extends gr{},dx=class extends gr{};var Ko=class extends f{},fx=class extends Ko{},Xo=class extends Ko{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},mx=class extends wt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var Qo=class extends f{},hx=class extends Qo{},gx=class extends Qo{};var xr=class extends f{main_input_name="input_values";forward_params=["input_values"]},xx=class extends xr{async encode(e){return await X(this.sessions.encoder_model,e)}async decode(e){return await X(this.sessions.decoder_model,e)}},Yo=class extends xr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},Jo=class extends xr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var wr=class extends f{},wx=class extends wr{},yx=class extends wr{},bx=class extends wr{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),_=Math.floor(u*n),d=this.config.num_mel_bins,m=[],h=null,g=null,x=0;for(;;){++x;let b=A_(!!g),M;g?M=g.output_sequence_out:M=new A("float32",new Float32Array(d),[1,1,d]);let k={use_cache_branch:b,output_sequence:M,encoder_attention_mask:c,speaker_embeddings:s,encoder_hidden_states:l};this.addPastKeyValues(k,h),g=await X(this.sessions.decoder_model_merged,k),h=this.getPastKeyValues(g,h);let{prob:O,spectrum:N}=g;if(m.push(N),x>=_&&(Array.from(O.data).filter(R=>R>=r).length>0||x>=p))break}let w=ie(m),{waveform:y}=await X(i.sessions.model,{spectrogram:w});return{spectrogram:w,waveform:y}}},kx=class extends f{main_input_name="spectrogram"};var Os=class extends f{},vx=class extends Os{},Ex=class extends Os{async _call(e){return new re(await super._call(e))}},Ax=class extends Os{async _call(e){return new z(await super._call(e))}},Mx=class extends Os{async _call(e){return new le(await super._call(e))}};var Zo=class extends f{},Sx=class extends Zo{},Ox=class extends Zo{};var ei=class extends f{},Ix=class extends ei{},zx=class extends ei{};var Rl=class extends f{},Tx=class extends Rl{};var Dl=class extends f{},ti=class extends Dl{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 X(this.sessions.text_encoder,{input_ids:e,attention_mask:s,style:r}),_=p.div(o).mul_(i),d=l*a,m=_.data,h=Int32Array.from(m,C=>Math.ceil(C/d)),g=Math.max(...h),x=e.dims[0],w=new BigInt64Array(x*g);for(let C=0;C<x;++C)w.fill(1n,C*g,C*g+h[C]);let y=new A("int64",w,[x,g]),b=c*a,M=b*g,k=n0([x,b,g]),O=k.data;for(let C=0;C<x;++C)if(h[C]!==g)for(let D=0;D<b;++D)O.fill(0,C*M+D*g+h[C],C*M+(D+1)*g);let N=we([x],n);for(let C=0;C<n;++C){let D=we([x],C);({denoised_latents:k}=await X(this.sessions.latent_denoiser,{style:r,noisy_latents:k,latent_mask:y,encoder_outputs:u,attention_mask:s,timestep:D,num_inference_steps:N}))}let{waveform:R}=await X(this.sessions.voice_decoder,{latents:k});return{waveform:R,durations:_}}};var yr=class extends f{},Cx=class extends yr{},Px=class extends yr{async _call(e){return new z(await super._call(e))}},Lx=class extends yr{};var si=class extends f{},Nx=class extends si{},Fx=class extends si{};var ri=class extends f{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"]},$x=class extends ri{},Rx=class extends ri{};var ni=class extends f{},Dx=class extends ni{},jx=class extends ni{async _call(e){return new jl(await super._call(e))}},jl=class extends ir{};var Bl=class extends f{},Bx=class extends Bl{};var br=class extends f{},qx=class extends br{},Ux=class extends br{async _call(e){return new qe(await super._call(e))}},Gx=class extends br{async _call(e){return new z(await super._call(e))}};var Is=class extends f{},Wx=class extends Is{},Vx=class extends Is{async _call(e){return new qe(await super._call(e))}},Hx=class extends Is{async _call(e){return new z(await super._call(e))}},Kx=class extends Is{async _call(e){return new te(await super._call(e))}};var oi=class extends f{},Xx=class extends oi{},Qx=class extends oi{};var Yx=class extends f{main_input_name="pixel_values";forward_params=["pixel_values","decoder_input_ids","encoder_hidden_states","past_key_values"]};var ii=class extends f{},Jx=class extends ii{},Zx=class extends ii{async _call(e){return new z(await super._call(e))}};var ql=class extends f{},ew=class extends ql{};var ai=class extends f{},tw=class extends ai{},sw=class extends ai{async _call(e){return new z(await super._call(e))}};var Ul=class extends f{},rw=class extends Ul{async _call(e){return new Ba(await super._call(e))}};var Gl=class extends f{},nw=class extends Gl{};var Wl=class extends fe{constructor({waveform:e,spectrogram:s}){super(),this.waveform=e,this.spectrogram=s}},Vl=class extends f{},ow=class extends Vl{async _call(e){return new Wl(await super._call(e))}};var iw=class extends ws{};var F0=2,cA=1,aw=new WeakMap;function uA(t,e){let{text_config:s,audio_config:r}=t.config,n=t.sessions.audio_encoder,{num_mel_bins:o,hidden_size:i}=r,a=o+i,l=new Jr,c=n?.config?.kv_cache_dtype??"float32",u=c==="float16"?At.float16:At.float32,p=_s(r,{batch_size:1});for(let m in p){let h=p[m].reduce((g,x)=>g*x,1);l[m]=new A(c,new u(h),p[m])}let _=new A(c,new u(a*F0),[1,a,F0]),d=e[Symbol.asyncIterator]?.()??e[Symbol.iterator]?.();if(!d)throw new Error("input_features must be iterable or async iterable");return{encoder_session:n,enc_kv_cache:l,enc_padding_cache:_,enc_past_seq_len:0,audio_embed_queue:[],audio_embed_total_tokens:0,audio_queue_offset:0,audio_consumed:0,stream_exhausted:!1,chunks_iter:d,text_hidden_size:s.hidden_size}}async function pA(t,e){let s=e.dims[2],r=Math.floor((cA+s-3)/2)+1,n=new A("int64",BigInt64Array.from({length:r},(u,p)=>BigInt(t.enc_past_seq_len+p)),[1,r]),o=t.enc_past_seq_len+r,i=Se([1,o]),{audio_embeds:a,present_padding_cache:l,...c}=await X(t.encoder_session,{input_features:e,attention_mask:i,position_ids:n,past_padding_cache:t.enc_padding_cache,...t.enc_kv_cache});t.enc_padding_cache.location==="gpu-buffer"&&t.enc_padding_cache.dispose(),t.enc_padding_cache=l;for(let u in c)if(u.startsWith("present.")){let p=u.replace("present","past_key_values"),_=t.enc_kv_cache[p];_?.location==="gpu-buffer"&&_.dispose(),t.enc_kv_cache[p]=c[u]}return t.enc_past_seq_len=o,a}async function _A(t,e){for(;t.audio_embed_total_tokens<e&&!t.stream_exhausted;){let s=await t.chunks_iter.next();if(s.done){t.stream_exhausted=!0;break}let r=await pA(t,s.value);t.audio_embed_queue.push({data:r.data,tokens:r.dims[1]}),t.audio_embed_total_tokens+=r.dims[1]}}function dA(t,e,s){if(t.audio_embed_queue.length===0)return;let r=e.data,n=0,o=s;for(;o>0&&t.audio_embed_queue.length>0;){let i=t.audio_embed_queue[0],a=i.tokens-t.audio_queue_offset,l=Math.min(o,a),c=t.audio_queue_offset*t.text_hidden_size;for(let u=0;u<l*t.text_hidden_size;++u)r[n*t.text_hidden_size+u]+=i.data[c+u];n+=l,o-=l,t.audio_queue_offset+=l,t.audio_queue_offset>=i.tokens&&(t.audio_embed_queue.shift(),t.audio_queue_offset=0)}t.audio_consumed+=s-o}var lw=class extends qt{constructor(e){super(),this._s=e}_call(e){let s=this._s.stream_exhausted&&this._s.audio_embed_queue.length===0;return e.map(()=>s)}},Hl=class extends f{forward_params=["input_ids","attention_mask","position_ids","past_key_values"]},li=class extends Hl{async forward({input_ids:e,past_key_values:s,...r}){let n=e.dims[1],o=aw.get(this);o&&await _A(o,o.audio_consumed+n);let{inputs_embeds:i}=await X(this.sessions.embed_tokens,{input_ids:e});o&&dA(o,i,n);let a={inputs_embeds:i,...r};this.addPastKeyValues(a,s);let l=this.sessions.decoder_model_merged,c=ke(a,l.inputNames);return await X(l,c)}async generate({input_features:e,stopping_criteria:s,...r}){if(!e)throw new Error("input_features (generator/iterable) must be provided");let n=uA(this,e);aw.set(this,n);let o=new Js;o.push(new lw(n)),s&&o.extend(s);try{return await super.generate({...r,stopping_criteria:o})}finally{n.enc_kv_cache.dispose(),aw.delete(this)}}};var kr=class extends f{},cw=class extends kr{},uw=class extends kr{async _call(e){return new qe(await super._call(e))}},pw=class extends kr{async _call(e){return new z(await super._call(e))}};var Kl=class extends fe{constructor({logits:e,embeddings:s}){super(),this.logits=e,this.embeddings=s}},es=class extends f{},_w=class extends es{},dw=class extends es{async _call(e){return new qe(await super._call(e))}},fw=class extends es{async _call(e){return new z(await super._call(e))}},mw=class extends es{async _call(e){return new Kl(await super._call(e))}},hw=class extends es{async _call(e){return new te(await super._call(e))}};var Xl=class extends f{},gw=class extends Xl{};var Ql=class extends Ys{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 ci=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"]},xw=class extends ci{},Yl=class extends ci{_prepare_generation_config(e,s){return super._prepare_generation_config(e,s,Ql)}_retrieve_init_tokens(e){let s=[e.decoder_start_token_id],r=e.language,n=e.task;if(e.is_multilingual){r||(F.warn("No language specified - defaulting to English (en)."),r="en");let i=`<|${a0(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&&(F.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 ds,r.push(new Ga(s,i))),s.begin_suppress_tokens&&(r??=new ds,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"&&F.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&&F.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&&(F.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,g)=>ie(i.map(x=>x[g]),2)),l=Ge(s.map(([h,g])=>{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,g,null,[0,r]):a[h].slice(null,g)})).transpose(1,0,2,3),[c,u]=Uc(l,-2,0,!0),p=l.clone();for(let h=0;h<p.dims[0];++h){let g=p[h];for(let x=0;x<g.dims[0];++x){let w=g[x],y=c[h][x][0].data,b=u[h][x][0].data;for(let M=0;M<w.dims[0];++M){let k=w[M].data;for(let O=0;O<k.length;++O)k[O]=(k[O]-b[O])/y[O];k.set($y(k,o))}}}let _=[pa(p,1)],d=e.sequences.dims,m=new A("float32",new Float32Array(d[0]*d[1]),d);for(let h=0;h<d[0];++h){let g=_[h].neg().squeeze_(0),[x,w]=Dy(g.tolist()),y=Array.from({length:x.length-1},(k,O)=>x[O+1]-x[O]),b=$e([1],y).map(k=>!!k),M=[];for(let k=0;k<b.length;++k)b[k]&&M.push(w[k]*n);m[h].data.set(M,1)}return m}},ww=class extends Yl{};var ts=class extends f{},yw=class extends ts{},bw=class extends ts{async _call(e){return new re(await super._call(e))}},kw=class extends ts{async _call(e){return new z(await super._call(e))}},vw=class extends ts{async _call(e){return new te(await super._call(e))}},Ew=class extends ts{async _call(e){return new le(await super._call(e))}};var ss=class extends f{},Aw=class extends ss{},Mw=class extends ss{async _call(e){return new re(await super._call(e))}},Sw=class extends ss{async _call(e){return new z(await super._call(e))}},Ow=class extends ss{async _call(e){return new te(await super._call(e))}},Iw=class extends ss{async _call(e){return new le(await super._call(e))}};var ui=class extends f{},zw=class extends ui{},Tw=class extends ui{async _call(e){return new Jl(await super._call(e))}},Jl=class extends fe{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}};var pi=class extends f{},Cw=class extends pi{},Pw=class extends pi{};var fA=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"]]),mA=new Map([["t5","T5Model"],["longt5","LongT5Model"],["mt5","MT5Model"],["bart","BartModel"],["mbart","MBartModel"],["marian","MarianModel"],["whisper","WhisperModel"],["m2m_100","M2M100Model"],["blenderbot","BlenderbotModel"],["blenderbot-small","BlenderbotSmallModel"]]),hA=new Map([["mimi","MimiModel"],["dac","DacModel"],["snac","SnacModel"]]),gA=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"],["olmo_hybrid","OlmoHybridModel"],["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"],["qwen2_moe","Qwen2MoeModel"],["qwen3","Qwen3Model"],["qwen3_moe","Qwen3MoeModel"],["qwen3_next","Qwen3NextModel"],["phi","PhiModel"],["phi3","Phi3Model"],["mpt","MptModel"],["opt","OPTModel"],["mistral","MistralModel"],["ministral","MinistralModel"],["ministral3","Ministral3Model"],["ernie4_5","Ernie4_5ForCausalLM"],["starcoder2","Starcoder2Model"],["falcon","FalconModel"],["falcon_h1","FalconH1Model"],["stablelm","StableLmModel"],["modernbert-decoder","ModernBertDecoderModel"],["hunyuan_v1_dense","HunYuanDenseV1Model"],["youtu","YoutuModel"]]),$0=new Map([["speecht5","SpeechT5ForSpeechToText"],["whisper","WhisperForConditionalGeneration"],["lite-whisper","LiteWhisperForConditionalGeneration"],["moonshine","MoonshineForConditionalGeneration"]]),R0=new Map([["speecht5","SpeechT5ForTextToSpeech"]]),D0=new Map([["vits","VitsModel"],["musicgen","MusicgenForConditionalGeneration"],["supertonic","SupertonicForConditionalGeneration"]]),j0=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"]]),B0=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"]]),q0=new Map([["t5","T5ForConditionalGeneration"],["longt5","LongT5ForConditionalGeneration"],["mt5","MT5ForConditionalGeneration"],["bart","BartForConditionalGeneration"],["mbart","MBartForConditionalGeneration"],["marian","MarianMTModel"],["m2m_100","M2M100ForConditionalGeneration"],["blenderbot","BlenderbotForConditionalGeneration"],["blenderbot-small","BlenderbotSmallForConditionalGeneration"]]),U0=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"],["olmo_hybrid","OlmoHybridForCausalLM"],["mobilellm","MobileLLMForCausalLM"],["granite","GraniteForCausalLM"],["granitemoehybrid","GraniteMoeHybridForCausalLM"],["cohere","CohereForCausalLM"],["cohere2","Cohere2ForCausalLM"],["gemma","GemmaForCausalLM"],["gemma2","Gemma2ForCausalLM"],["vaultgemma","VaultGemmaForCausalLM"],["gemma3_text","Gemma3ForCausalLM"],["gemma3","Gemma3ForCausalLM"],["helium","HeliumForCausalLM"],["glm","GlmForCausalLM"],["openelm","OpenELMForCausalLM"],["qwen2","Qwen2ForCausalLM"],["qwen2_moe","Qwen2MoeForCausalLM"],["qwen3","Qwen3ForCausalLM"],["qwen3_moe","Qwen3MoeForCausalLM"],["qwen3_next","Qwen3NextForCausalLM"],["qwen2_vl","Qwen2VLForCausalLM"],["qwen2_5_vl","Qwen2_5_VLForCausalLM"],["qwen3_vl","Qwen3VLForCausalLM"],["qwen3_vl_moe","Qwen3VLMoeForCausalLM"],["qwen3_5","Qwen3_5ForCausalLM"],["qwen3_5_moe","Qwen3_5MoeForCausalLM"],["gemma3n","Gemma3nForCausalLM"],["phi","PhiForCausalLM"],["phi3","Phi3ForCausalLM"],["mpt","MptForCausalLM"],["opt","OPTForCausalLM"],["mbart","MBartForCausalLM"],["mistral","MistralForCausalLM"],["ministral","MinistralForCausalLM"],["ministral3","Ministral3ForCausalLM"],["ernie4_5","Ernie4_5ForCausalLM"],["starcoder2","Starcoder2ForCausalLM"],["falcon","FalconForCausalLM"],["falcon_h1","FalconH1ForCausalLM"],["trocr","TrOCRForCausalLM"],["stablelm","StableLmForCausalLM"],["modernbert-decoder","ModernBertDecoderForCausalLM"],["hunyuan_v1_dense","HunYuanDenseV1ForCausalLM"],["youtu","YoutuForCausalLM"],["phi3_v","Phi3VForCausalLM"]]),xA=new Map([["multi_modality","MultiModalityCausalLM"]]),G0=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"]]),W0=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"]]),V0=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"]]),H0=new Map([["llava","LlavaForConditionalGeneration"],["llava_onevision","LlavaOnevisionForConditionalGeneration"],["moondream1","Moondream1ForConditionalGeneration"],["florence2","Florence2ForConditionalGeneration"],["qwen2_vl","Qwen2VLForConditionalGeneration"],["qwen2_5_vl","Qwen2_5_VLForConditionalGeneration"],["qwen3_vl","Qwen3VLForConditionalGeneration"],["qwen3_vl_moe","Qwen3VLMoeForConditionalGeneration"],["qwen3_5","Qwen3_5ForConditionalGeneration"],["qwen3_5_moe","Qwen3_5MoeForConditionalGeneration"],["lfm2_vl","Lfm2VlForConditionalGeneration"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"],["paligemma","PaliGemmaForConditionalGeneration"],["llava_qwen2","LlavaQwen2ForCausalLM"],["gemma3n","Gemma3nForConditionalGeneration"],["mistral3","Mistral3ForConditionalGeneration"]]),K0=new Map([["granite_speech","GraniteSpeechForConditionalGeneration"],["ultravox","UltravoxModel"],["voxtral","VoxtralForConditionalGeneration"],["voxtral_realtime","VoxtralRealtimeForConditionalGeneration"]]),wA=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"]]),X0=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"]]),Q0=new Map([["detr","DetrForObjectDetection"],["rt_detr","RTDetrForObjectDetection"],["rt_detr_v2","RTDetrV2ForObjectDetection"],["rf_detr","RFDetrForObjectDetection"],["d_fine","DFineForObjectDetection"],["table-transformer","TableTransformerForObjectDetection"],["yolos","YolosForObjectDetection"]]),Y0=new Map([["owlvit","OwlViTForObjectDetection"],["owlv2","Owlv2ForObjectDetection"],["grounding-dino","GroundingDinoForObjectDetection"]]),vr=new Map([["detr","DetrForSegmentation"],["clipseg","CLIPSegForImageSegmentation"]]),J0=new Map([["segformer","SegformerForSemanticSegmentation"],["sapiens","SapiensForSemanticSegmentation"],["swin","SwinForSemanticSegmentation"],["mobilenet_v1","MobileNetV1ForSemanticSegmentation"],["mobilenet_v2","MobileNetV2ForSemanticSegmentation"],["mobilenet_v3","MobileNetV3ForSemanticSegmentation"],["mobilenet_v4","MobileNetV4ForSemanticSegmentation"]]),Z0=new Map([["detr","DetrForSegmentation"],["maskformer","MaskFormerForInstanceSegmentation"]]),eb=new Map([["sam","SamModel"],["sam2","Sam2Model"],["edgetam","EdgeTamModel"],["sam3_tracker","Sam3TrackerModel"]]),tb=new Map([["wav2vec2","Wav2Vec2ForCTC"],["wav2vec2-bert","Wav2Vec2BertForCTC"],["unispeech","UniSpeechForCTC"],["unispeech-sat","UniSpeechSatForCTC"],["wavlm","WavLMForCTC"],["hubert","HubertForCTC"],["parakeet_ctc","ParakeetForCTC"]]),sb=new Map([["wav2vec2","Wav2Vec2ForSequenceClassification"],["wav2vec2-bert","Wav2Vec2BertForSequenceClassification"],["unispeech","UniSpeechForSequenceClassification"],["unispeech-sat","UniSpeechSatForSequenceClassification"],["wavlm","WavLMForSequenceClassification"],["hubert","HubertForSequenceClassification"],["audio-spectrogram-transformer","ASTForAudioClassification"]]),rb=new Map([["wavlm","WavLMForXVector"]]),nb=new Map([["unispeech-sat","UniSpeechSatForAudioFrameClassification"],["wavlm","WavLMForAudioFrameClassification"],["wav2vec2","Wav2Vec2ForAudioFrameClassification"],["pyannote","PyAnnoteForAudioFrameClassification"]]),ob=new Map([["vitmatte","VitMatteForImageMatting"]]),yA=new Map([["patchtst","PatchTSTForPrediction"],["patchtsmixer","PatchTSMixerForPrediction"]]),ib=new Map([["swin2sr","Swin2SRForImageSuperResolution"]]),ab=new Map([["dpt","DPTForDepthEstimation"],["depth_anything","DepthAnythingForDepthEstimation"],["glpn","GLPNForDepthEstimation"],["sapiens","SapiensForDepthEstimation"],["depth_pro","DepthProForDepthEstimation"],["metric3d","Metric3DForDepthEstimation"],["metric3dv2","Metric3Dv2ForDepthEstimation"]]),lb=new Map([["sapiens","SapiensForNormalEstimation"]]),cb=new Map([["vitpose","VitPoseForPoseEstimation"]]),ub=new Map([["clip","CLIPVisionModelWithProjection"],["siglip","SiglipVisionModel"],["jina_clip","JinaCLIPVisionModel"]]),Lw=[[fA,L.EncoderOnly],[mA,L.EncoderDecoder],[gA,L.DecoderOnlyWithoutHead],[hA,L.AutoEncoder],[j0,L.EncoderOnly],[B0,L.EncoderOnly],[q0,L.Seq2Seq],[$0,L.Seq2Seq],[U0,L.DecoderOnly],[xA,L.MultiModality],[G0,L.EncoderOnly],[W0,L.EncoderOnly],[V0,L.Vision2Seq],[H0,L.ImageTextToText],[K0,L.AudioTextToText],[X0,L.EncoderOnly],[vr,L.EncoderOnly],[Z0,L.EncoderOnly],[J0,L.EncoderOnly],[ob,L.EncoderOnly],[yA,L.EncoderOnly],[ib,L.EncoderOnly],[ab,L.EncoderOnly],[lb,L.EncoderOnly],[cb,L.EncoderOnly],[Q0,L.EncoderOnly],[Y0,L.EncoderOnly],[eb,L.MaskGeneration],[tb,L.EncoderOnly],[sb,L.EncoderOnly],[R0,L.Seq2Seq],[D0,L.EncoderOnly],[rb,L.EncoderOnly],[nb,L.EncoderOnly],[ub,L.EncoderOnly]];for(let[t,e]of Lw)for(let s of t.values()){ut.set(s,e);let r=_i[s];hs.set(r,s),tl.set(s,r)}var bA=[["MusicgenForConditionalGeneration",wo,L.Musicgen],["Phi3VForCausalLM",Po,L.Phi3V],["CLIPTextModelWithProjection",dn,L.EncoderOnly],["SiglipTextModel",Xo,L.EncoderOnly],["JinaCLIPTextModel",Zn,L.EncoderOnly],["ClapTextModelWithProjection",pn,L.EncoderOnly],["ClapAudioModelWithProjection",_n,L.EncoderOnly],["DacEncoderModel",kn,L.EncoderOnly],["DacDecoderModel",vn,L.EncoderOnly],["MimiEncoderModel",ao,L.EncoderOnly],["MimiDecoderModel",lo,L.EncoderOnly],["SnacEncoderModel",Yo,L.EncoderOnly],["SnacDecoderModel",Jo,L.EncoderOnly],["Gemma3nForConditionalGeneration",ar,L.ImageAudioTextToText],["SupertonicForConditionalGeneration",ti,L.Supertonic],["ChatterboxModel",un,L.Chatterbox],["Qwen2VLForCausalLM",vs,L.MultimodalLanguageModelOnly],["Qwen2_5_VLForCausalLM",Es,L.MultimodalLanguageModelOnly],["Qwen3VLForCausalLM",Ms,L.MultimodalLanguageModelOnly],["Qwen3VLMoeForCausalLM",qo,L.MultimodalLanguageModelOnly],["Qwen3_5ForCausalLM",Ss,L.MultimodalLanguageModelOnly],["Qwen3_5MoeForCausalLM",Uo,L.MultimodalLanguageModelOnly],["Gemma3nForCausalLM",$n,L.MultimodalLanguageModelOnly],["VoxtralRealtimeForConditionalGeneration",li,L.VoxtralRealtime]];for(let[t,e,s]of bA)ut.set(t,s),hs.set(e,t),tl.set(t,e);var pb=new Map([["modnet",vr],["birefnet",vr],["isnet",vr],["ben",vr]]);for(let[t,e]of pb.entries())e.set(t,"PreTrainedModel"),ut.set(t,L.EncoderOnly),tl.set(t,f);var _b=new Set(pb.keys());ut.set("PreTrainedModel",L.EncoderOnly);hs.set(f,"PreTrainedModel");var _e={MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES:j0,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES:B0,MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES:R0,MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES:D0,MODEL_FOR_MASKED_LM_MAPPING_NAMES:G0,MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES:W0,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES:X0,MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES:vr,MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES:J0,MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES:Z0,MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES:Q0,MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES:Y0,MODEL_FOR_MASK_GENERATION_MAPPING_NAMES:eb,MODEL_FOR_CTC_MAPPING_NAMES:tb,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES:sb,MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES:rb,MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES:nb,MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES:wA,MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES:ob,MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES:ib,MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES:ab,MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES:lb,MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES:cb,MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES:ub,MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES:H0,MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES:K0,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES:q0,MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES:$0,MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:U0,MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES:V0};T0(_e);var ce=class{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static supports(e){if(!this.MODEL_CLASS_MAPPINGS)return!1;for(let s of this.MODEL_CLASS_MAPPINGS)if(s.has(e))return!0;return this.BASE_IF_FAIL}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:_={}}={}){let d={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:_};if(d.config=await Je.from_pretrained(e,d),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);let{model_type:m}=d.config;for(let h of this.MODEL_CLASS_MAPPINGS){let g=h.get(m);if(!g){for(let x of h.values())if(x[0]===m){g=x;break}if(!g)continue}return await _i[g].from_pretrained(e,d)}if(this.BASE_IF_FAIL)return _b.has(m)||F.warn(`Unknown model class "${m}", attempting to construct from base class.`),await f.from_pretrained(e,d);throw Error(`Unsupported model type: ${m}`)}},St=class extends ce{static MODEL_CLASS_MAPPINGS=Lw.map(e=>e[0]);static BASE_IF_FAIL=!0},di=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]},Zl=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]},Er=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]},ec=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]},tc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]},sc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]},rc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES]},nc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_MASKED_LM_MAPPING_NAMES]},oc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]},ic=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]},ac=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]},fi=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]},mi=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]},hi=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES]},lc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]},cc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]},db=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]},uc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_CTC_MAPPING_NAMES]},pc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]},fb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]},mb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]},_c=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]},hb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]},dc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]},fc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]},gb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES]},xb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES]},mc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]},wb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES]},yb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES]};async function Ae(t){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(e=>ve.read(e)))}async function rs(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 gi(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 Y=class extends Me{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 xi=class extends Y{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 A("float32",de(c.data),c.dims),l=[];for(let c of n.logits){let u=a(c),p=await ct(u,s),_=p[0].tolist(),m=p[1].tolist().map((h,g)=>({label:i?i[h]:`LABEL_${h}`,score:_[g]}));s===1?l.push(...m):l.push(m)}return Array.isArray(e)||s===1?l:l[0]}};var wi=class extends Y{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],_=[];for(let d=0;d<p.dims[0];++d){let m=p[d],h=ue(m.data)[1],g=a?a[h]:`LABEL_${h}`;if(s.includes(g))continue;let x=this.tokenizer.decode([u[d].item()],{skip_special_tokens:!0});if(x==="")continue;let w=de(m.data);_.push({entity:g,score:w[h],index:d,word:x})}l.push(_)}return r?l:l[0]}};var yi=class extends Y{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,_=[];for(let d=0;d<i.dims[0];++d){let m=l[d],h=m.findIndex(k=>k==p),g=i[d].tolist(),x=a[d].tolist();for(let k=1;k<g.length;++k)(c[d]==0||k<=h||u.findIndex(O=>O==m[k])!==-1)&&(g[k]=-1/0,x[k]=-1/0);let w=de(g).map((k,O)=>[k,O]),y=de(x).map((k,O)=>[k,O]);w[0][0]=0,y[0][0]=0;let b=Vw(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]),M=[];for(let k=0;k<Math.min(b.length,r);++k){let[O,N,R]=b[k],C=m.slice(O,N+1),D=this.tokenizer.decode(C,{skip_special_tokens:!0});M.push({answer:D,score:R})}r===1?_.push(...M):_.push(M)}return o?_:_[0]}};var bi=class extends Y{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(g=>g==r);if(p===-1)throw Error(`Mask token (${n}) not found in text.`);let _=i[c][p],d=await ct(new A("float32",de(_.data),_.dims),s),m=d[0].tolist(),h=d[1].tolist();a.push(h.map((g,x)=>{let w=u.slice();return w[p]=g,{score:m[x],token:Number(g),token_str:this.tokenizer.decode([g]),sequence:this.tokenizer.decode(w,{skip_special_tokens:!0})}}))}return Array.isArray(e)?a:a[0]}};var Ot=class extends Y{_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 ki=class extends Ot{_key="summary_text"};var vi=class extends Ot{_key="translation_text"};function bb(t){return Array.isArray(t)&&t.every(e=>"role"in e&&"content"in e)}var Ei=class extends Y{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(bb(e))e=[e];else if(Array.isArray(e)&&e.every(bb))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}),_;!l&&c.input_ids.dims.at(-1)>0&&(_=this.tokenizer.batch_decode(c.input_ids,{skip_special_tokens:!0}).map(m=>m.length));let d=Array.from({length:e.length},m=>[]);for(let m=0;m<p.length;++m){let h=Math.floor(m/u.dims[0]*e.length);_&&(p[m]=p[m].slice(_[h])),d[h].push({generated_text:n?[...e[h],{role:"assistant",content:p[m]}]:p[m]})}return!r&&d.length===1?d[0]:d}};var Ai=class extends Y{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&&(F.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&&(F.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 d of i){let m=this.tokenizer(c,{text_pair:d,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 _=(a?u.map(d=>de(d)[1]):de(u)).map((d,m)=>[d,m]).sort((d,m)=>m[0]-d[0]);l.push({sequence:c,labels:_.map(d=>s[d[1]]),scores:_.map(d=>d[0])})}return o?l:l[0]}};var Mi=class extends Y{async _call(e,{top_k:s=5}={}){let r=this.processor.feature_extractor.config.sampling_rate,n=await rs(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 ct(new A("float32",de(u.data),u.dims),s),_=p[0].tolist(),m=p[1].tolist().map((h,g)=>({label:o?o[h]:`LABEL_${h}`,score:_[g]}));i.push(m)}return Array.isArray(e)?i:i[0]}};var Si=class extends Y{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 rs(e,a),c=[];for(let u of l){let p=await this.processor(u),_=await this.model({...i,...p}),d=de(_.logits_per_audio.data);c.push([...d].map((m,h)=>({score:m,label:s[h]})))}return n?c[0]:c}};var Oi=class extends Y{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&&F.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),s.task&&F.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 rs(n,o),a=[];for(let l of i){let c=await this.processor(l),p=(await this.model(c)).logits[0],_=[];for(let m of p)_.push(ue(m.data)[1]);let d=this.tokenizer.decode(_,{skip_special_tokens:!0}).trim();a.push({text:d})}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,_=u.hop_length,d=u.sampling_rate,m=await rs(c,d),h=[];for(let g of m){let x=[];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=d*n,M=d*i,k=b-2*M,O=0;for(;;){let N=O+b,R=g.subarray(O,N),C=await this.processor(R),D=O===0,$=N>=g.length;if(x.push({stride:[R.length,D?0:M,$?0:M],input_features:C.input_features,is_last:$}),$)break;O+=k}}else x=[{stride:[g.length,0,0],input_features:(await this.processor(g)).input_features,is_last:!0}];for(let b of x){a.num_frames=Math.floor(b.stride[0]/_);let M=await this.model.generate({inputs:b.input_features,...a});r==="word"?(b.tokens=M.sequences.tolist()[0],b.token_timestamps=M.token_timestamps.tolist()[0].map(k=>cs(k,2))):b.tokens=M[0].tolist(),b.stride=b.stride.map(k=>k/d)}let[w,y]=this.tokenizer._decode_asr(x,{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 rs(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}),_=this.processor.batch_decode(p,{skip_special_tokens:!0})[0];a.push({text:_})}return r?a[0]:a}};var Ii=class extends Y{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 J.fetch(e)).arrayBuffer())),e instanceof Float32Array)e=new A("float32",e,[e.length]);else if(!(e instanceof A))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,_=u*a;c.push(new qr(o.slice(_,_+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||(F.info("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await St.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 zi=class extends Y{async _call(e,s={}){let r=Array.isArray(e),n=await Ae(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 Ti=class extends Y{async _call(e,{top_k:s=5}={}){let r=await Ae(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 ct(new A("float32",de(l.data),l.dims),s),u=c[0].tolist(),_=c[1].tolist().map((d,m)=>({label:i?i[d]:`LABEL_${d}`,score:u[m]}));a.push(_)}return Array.isArray(e)?a:a[0]}};var kb={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"},zs=class extends Y{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 Ae(e),u=c.map(w=>[w.height,w.width]),p=await this.processor(c),{inputNames:_,outputNames:d}=this.model.sessions.model;if(!_.includes("pixel_values")){if(_.length!==1)throw Error(`Expected a single input name, but got ${_.length} inputs: ${_}.`);let w=_[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=kb[a];else if(this.processor.image_processor){for(let[w,y]of Object.entries(kb))if(y in this.processor.image_processor){h=this.processor.image_processor[y].bind(this.processor.image_processor),a=w;break}}let g=this.model.config.id2label,x=[];if(a)if(a==="panoptic"||a==="instance"){let w=h(m,s,r,n,o,i??u)[0],y=w.segmentation;for(let b of w.segments_info){let M=new Uint8ClampedArray(y.data.length);for(let O=0;O<y.data.length;++O)y.data[O]===b.id&&(M[O]=255);let k=new ve(M,y.dims[1],y.dims[0],1);x.push({score:b.score,label:g[b.label_id],mask:k})}}else if(a==="semantic"){let{segmentation:w,labels:y}=h(m,i??u)[0];for(let b of y){let M=new Uint8ClampedArray(w.data.length);for(let O=0;O<w.data.length;++O)w.data[O]===b&&(M[O]=255);let k=new ve(M,w.dims[1],w.dims[0],1);x.push({score:null,label:g[b],mask:k})}}else throw Error(`Subtask ${a} not supported.`);else{let y=m[d[0]];for(let b=0;b<u.length;++b){let M=u[b],k=y[b];k.data.some(N=>N<-1e-5||N>1+1e-5)&&k.sigmoid_();let O=await ve.fromTensor(k.mul_(255).to("uint8")).resize(M[1],M[0]);x.push({label:null,score:null,mask:O})}}return x}};var Ci=class extends zs{async _call(e,s={}){let r=await Ae(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 Pi=class extends Y{async _call(e,s,{hypothesis_template:r="This is a photo of {}"}={}){let n=Array.isArray(e),o=await Ae(e),i=s.map(_=>r.replace("{}",_)),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"?_=>_.sigmoid().data:_=>de(_.data),p=[];for(let _ of c.logits_per_image){let m=[...u(_)].map((h,g)=>({score:h,label:s[g]}));m.sort((h,g)=>g.score-h.score),p.push(m)}return n?p:p[0]}};var Li=class extends Y{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 Ae(e),i=r?null:o.map(d=>[d.height,d.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,_=u.map(d=>d.boxes.map((m,h)=>({score:d.scores[h],label:p[d.classes[h]],box:gi(m,!r)})));return n?_:_[0]}};var Ni=class extends Y{async _call(e,s,{threshold:r=.1,top_k:n=null,percentage:o=!1}={}){let i=Array.isArray(e),a=await Ae(e),l=this.tokenizer(s,{padding:!0,truncation:!0}),c=await this.processor(a),u=[];for(let p=0;p<a.length;++p){let _=a[p],d=o?null:[[_.height,_.width]],m=c.pixel_values[p].unsqueeze_(0),h=await this.model({...l,pixel_values:m}),g;if("post_process_grounded_object_detection"in this.processor){let x=this.processor.post_process_grounded_object_detection(h,l.input_ids,{box_threshold:r,text_threshold:r,target_sizes:d})[0];g=x.boxes.map((w,y)=>({score:x.scores[y],label:x.labels[y],box:gi(w,!o)}))}else{let x=this.processor.image_processor.post_process_object_detection(h,r,d,!0)[0];g=x.boxes.map((w,y)=>({score:x.scores[y],label:s[x.classes[y]],box:gi(w,!o)}))}g.sort((x,w)=>w.score-x.score),n!==null&&(g=g.slice(0,n)),u.push(g)}return i?u:u[0]}};var Fi=class extends Y{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 Ae(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 $i=class extends Y{async _call(e){let s=await Ae(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(ve.fromTensor(a))}return Array.isArray(e)?o:o[0]}};var Ri=class extends Y{async _call(e){let s=await Ae(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,_=(await Be(a.view(1,1,l,c),{size:[p,u],mode:"bilinear"})).view(p,u),d=_.min().item(),m=_.max().item(),h=_.sub(d).div_(m-d).mul_(255).to("uint8").unsqueeze(0),g=ve.fromTensor(h);o.push({predicted_depth:_,depth:g})}return Array.isArray(e)?o:o[0]}};var Di=class extends Y{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=r0(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=o0(l,o)),l}};var ji=class extends Y{async _call(e,{pool:s=null}={}){let r=await Ae(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 Ar=Object.freeze({"text-classification":{pipeline:xi,model:di,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{pipeline:wi,model:Zl,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{pipeline:yi,model:oc,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{pipeline:bi,model:nc,default:{model:"onnx-community/ettin-encoder-32m-ONNX",dtype:"fp32"},type:"text"},summarization:{pipeline:ki,model:Er,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{pipeline:vi,model:Er,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{pipeline:Ot,model:Er,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{pipeline:Ei,model:rc,default:{model:"onnx-community/Qwen3-0.6B-ONNX",dtype:"q4"},type:"text"},"zero-shot-classification":{pipeline:Ai,model:di,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:Mi,model:pc,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{pipeline:Si,model:St,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{pipeline:Oi,model:[ec,uc],default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{pipeline:Ii,model:[sc,tc],default:{model:"onnx-community/Supertonic-TTS-ONNX",dtype:"fp32"},type:"text"},"image-to-text":{pipeline:zi,model:ic,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:Ti,model:ac,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:zs,model:[fi,mi,hi],default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:Ci,model:[fi,mi,hi],default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{pipeline:Pi,model:St,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:Li,model:lc,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{pipeline:Ni,model:cc,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{pipeline:Fi,model:_c,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:$i,model:dc,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:Ri,model:fc,default:{model:"onnx-community/depth-anything-v2-small"},type:"image"},"feature-extraction":{pipeline:Di,model:St,default:{model:"onnx-community/all-MiniLM-L6-v2-ONNX",dtype:"fp32"},type:"text"},"image-feature-extraction":{pipeline:ji,model:[mc,St],default:{model:"onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX",dtype:"fp32"},type:"image"}}),hc=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});function kA(t,{config:e=null,cache_dir:s=null,local_files_only:r=!1,revision:n="main"}={}){if(e!==null)return Je.from_pretrained(t,{config:e,cache_dir:s,local_files_only:r,revision:n});let o=JSON.stringify([t,s,r,n]);return ta(o,()=>Je.from_pretrained(t,{config:e,cache_dir:s,local_files_only:r,revision:n}))}async function gc(t,{config:e=null,dtype:s=null,device:r=null,model_file_name:n=null}={}){e=await kA(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,_=e.architectures||[],d=!1;for(let x of _){let w=ut.get(x);if(w!==void 0){p=w,d=!0;break}}if(!d&&e.model_type){let x=ut.get(e.model_type);if(x!==void 0&&(p=x,d=!0),!d){for(let w of Object.values(ms))if(w.has(e.model_type)){p=ut.get(w.get(e.model_type)),d=!0;break}}}if(!d){let x=_.length>0?_.join(", "):"(none)";F.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: ${Dt}`),p=L.EncoderOnly}let m=(x,w=null)=>{w=w??x;let y=aa(c,x),b=la(u,x,y),M=Fr[b]??"",k=`${w}${M}.onnx`,O=l?`${l}/${k}`:k;o.push(O);let N=x_(a,k,x);for(let R of w_(k,N)){let C=l?`${l}/${R}`:R;o.push(C)}},{sessions:h,optional_configs:g}=C0(p,e,{model_file_name:n});for(let[x,w]of Object.entries(h))m(x,w);if(g)for(let x of Object.values(g))o.push(x);return o}async function xc(t){if(!t)throw new Error("modelId is required");return(await ht(t,Mt,{})).exists?[Mt]:[]}async function It(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 gc(t,{config:e,dtype:s,device:r,model_file_name:n});if(o){let l=await js(t);a.push(...l)}if(i){let l=await xc(t);a.push(...l)}return a}async function zt(t,e,s={}){t=hc[t]??t;let r=Ar[t];if(!r)throw new Error(`Unsupported pipeline task: ${t}. Must be one of [${Object.keys(Ar).join(", ")}]`);let{type:n}=r;return It(e,{...s,include_tokenizer:n!=="audio"&&n!=="image",include_processor:n!=="text"})}async function sX(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:_={}}={}){t=hc[t]??t;let d=Ar[t.split("_",1)[0]];if(!d)throw Error(`Unsupported pipeline: ${t}. Must be one of [${Object.keys(Ar)}]`);e||(e=d.default.model,F.info(`No model specified. Using default model: "${e}".`),!l&&d.default.dtype&&(l=d.default.dtype));let m=await zt(t,e,{device:a,dtype:l}),h={};s&&(await Promise.all(m.map(async D=>ht(e,D)))).forEach((D,$)=>{D.exists&&(h[m[$]]={loaded:0,total:D.size??0})});let g={progress_callback:s?C=>{if(C.status==="progress"){h[C.file]={loaded:C.loaded,total:C.total};let D=Object.values(h).reduce((B,G)=>B+G.loaded,0),$=Object.values(h).reduce((B,G)=>B+G.total,0),q=$>0?D/$*100:0;s({status:"progress_total",name:C.name,progress:q,loaded:D,total:$,files:structuredClone(h)})}s(C)}: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:_},x=m.includes("tokenizer.json"),w=m.includes("preprocessor_config.json"),y=d.model,b;if(Array.isArray(y)){let C=r??await Je.from_pretrained(e,g),{model_type:D}=C,$=y.find(q=>q.supports(D));if(!$)throw Error(`Unsupported model type "${D}" for task "${t}". None of the candidate model classes support this type.`);b=$.from_pretrained(e,{...g,config:C})}else b=y.from_pretrained(e,g);let[M,k,O]=await Promise.all([x?W.from_pretrained(e,g):null,w?ja.from_pretrained(e,g):null,b]),N={task:t,model:O};M&&(N.tokenizer=M),k&&(N.processor=k),vt(s,{status:"ready",task:t,model:e});let R=d.pipeline;return new R(N)}var vA=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,Nw=class{put(e){throw Error("Not implemented")}end(){throw Error("Not implemented")}},vb=V.IS_PROCESS_AVAILABLE?t=>process.stdout.write(t):t=>console.log(t),Fw=class extends Nw{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??vb,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=$e(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&&vA(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===vb&&V.IS_PROCESS_AVAILABLE&&this.callback_function?.(`
24
- `)}},Eb=class extends Fw{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 Bi=class{constructor(e,s){this.image=e,this.timestamp=s}},wc=class{constructor(e,s){e.length>0&&e[0]instanceof ve&&(e=e.map((r,n)=>new Bi(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 EA(t,{num_frames:e=null,fps:s=null}={}){if(!V.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 _=await(await J.fetch(n.src)).blob();n.src=URL.createObjectURL(_),await new Promise(d=>n.onloadedmetadata=d)}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 _=u.getImageData(0,0,c.width,c.height),d=new ve(_.data,c.width,c.height,4),m=new Bi(d,p);r.push(m)}return n.remove(),new wc(r,o)}async function yc(t,e,s={}){let r=await lt(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}=Ft(t,o,s,r),l=await $t(r,i,a);return{file:o,cached:!!l}}));return{allCached:n.every(o=>o.cached),files:n}}async function Ab(t,e,s={}){let r=await lt(s?.cache_dir);if(!r)return!1;let{localPath:n,proposedCacheKey:o}=Ft(t,e,s,r);return!!await $t(r,n,o)}async function Mb(t,e={}){if(!t)throw new Error("modelId is required");if(!await Ab(t,"config.json",e))return!1;let s=await It(t,e);return(await yc(t,s,e)).allCached}async function Sb(t,e={}){if(!t)throw new Error("modelId is required");let s=await It(t,e);return await yc(t,s,e)}async function Ob(t,e,s={}){if(!t)throw new Error("task is required");if(!e)throw new Error("modelId is required");if(!await Ab(e,"config.json",s))return!1;let r=await zt(t,e,s);return(await yc(e,r,s)).allCached}async function Ib(t,e,s={}){if(!t)throw new Error("task is required");if(!e)throw new Error("modelId is required");let r=await zt(t,e,s);return await yc(e,r,s)}async function zb(t,e,s={}){let r=await lt(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}=Ft(t,o,s,r),c=!!await $t(r,i,a),u=!1;if(c){let p=await r.delete(a),_=!p&&a!==i?await r.delete(i):!1;u=p||_}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 Tb(t,e={}){if(!t)throw new Error("modelId is required");let s=await It(t,e);return await zb(t,s,e)}async function Cb(t,e,s={}){if(!t)throw new Error("task is required");if(!e)throw new Error("modelId is required");let r=await zt(t,e,s);return await zb(e,r,s)}var $w=class{static async get_files(e,s={}){return It(e,s)}static async get_pipeline_files(e,s,r={}){return zt(e,s,r)}static async get_model_files(e,s={}){return gc(e,s)}static async get_tokenizer_files(e){return js(e)}static async get_processor_files(e){return xc(e)}static async is_cached(e,s={}){return Mb(e,s)}static async is_cached_files(e,s={}){return Sb(e,s)}static async is_pipeline_cached(e,s,r={}){return Ob(e,s,r)}static async is_pipeline_cached_files(e,s,r={}){return Ib(e,s,r)}static async get_file_metadata(e,s,r={}){return ht(e,s,r)}static async clear_cache(e,s={}){return Tb(e,s)}static async clear_pipeline_cache(e,s,r={}){return Cb(e,s,r)}};export{qu as ASTFeatureExtractor,R_ as ASTForAudioClassification,$_ as ASTModel,nn as ASTPreTrainedModel,L_ as AfmoeForCausalLM,P_ as AfmoeModel,sn as AfmoePreTrainedModel,z_ as AlbertForMaskedLM,I_ as AlbertForQuestionAnswering,O_ as AlbertForSequenceClassification,S_ as AlbertModel,gs as AlbertPreTrainedModel,Xc as AlbertTokenizer,C_ as ApertusForCausalLM,T_ as ApertusModel,tn as ApertusPreTrainedModel,F_ as ArceeForCausalLM,N_ as ArceeModel,rn as ArceePreTrainedModel,Mi as AudioClassificationPipeline,Je as AutoConfig,ye as AutoFeatureExtractor,pe as AutoImageProcessor,St as AutoModel,pc as AutoModelForAudioClassification,mb as AutoModelForAudioFrameClassification,yb as AutoModelForAudioTextToText,uc as AutoModelForCTC,rc as AutoModelForCausalLM,fc as AutoModelForDepthEstimation,_c as AutoModelForDocumentQuestionAnswering,ac as AutoModelForImageClassification,mc as AutoModelForImageFeatureExtraction,hb as AutoModelForImageMatting,fi as AutoModelForImageSegmentation,wb as AutoModelForImageTextToText,dc as AutoModelForImageToImage,db as AutoModelForMaskGeneration,nc as AutoModelForMaskedLM,gb as AutoModelForNormalEstimation,lc as AutoModelForObjectDetection,xb as AutoModelForPoseEstimation,oc as AutoModelForQuestionAnswering,mi as AutoModelForSemanticSegmentation,Er as AutoModelForSeq2SeqLM,di as AutoModelForSequenceClassification,ec as AutoModelForSpeechSeq2Seq,tc as AutoModelForTextToSpectrogram,sc as AutoModelForTextToWaveform,Zl as AutoModelForTokenClassification,hi as AutoModelForUniversalSegmentation,ic as AutoModelForVision2Seq,fb as AutoModelForXVector,cc as AutoModelForZeroShotObjectDetection,ja as AutoProcessor,W as AutoTokenizer,Oi as AutomaticSpeechRecognitionPipeline,Ci as BackgroundRemovalPipeline,j_ as BartForConditionalGeneration,B_ as BartForSequenceClassification,D_ as BartModel,sr as BartPretrainedModel,Qc as BartTokenizer,Nw as BaseStreamer,op as BeitFeatureExtractor,U_ as BeitForImageClassification,q_ as BeitModel,on as BeitPreTrainedModel,W_ as BertForMaskedLM,K_ as BertForQuestionAnswering,V_ as BertForSequenceClassification,H_ as BertForTokenClassification,G_ as BertModel,Ut as BertPreTrainedModel,Yc as BertTokenizer,ip as BitImageProcessor,Q_ as BlenderbotForConditionalGeneration,X_ as BlenderbotModel,an as BlenderbotPreTrainedModel,J_ as BlenderbotSmallForConditionalGeneration,Y_ as BlenderbotSmallModel,ln as BlenderbotSmallPreTrainedModel,Jc as BlenderbotSmallTokenizer,Zc as BlenderbotTokenizer,ed as BloomForCausalLM,Z_ as BloomModel,cn as BloomPreTrainedModel,eu as BloomTokenizer,lp as CLIPFeatureExtractor,ya as CLIPImageProcessor,ld as CLIPModel,wt as CLIPPreTrainedModel,dd as CLIPSegForImageSegmentation,_d as CLIPSegModel,fn as CLIPSegPreTrainedModel,cd as CLIPTextModel,dn as CLIPTextModelWithProjection,su as CLIPTokenizer,ud as CLIPVisionModel,pd as CLIPVisionModelWithProjection,sd as CamembertForMaskedLM,od as CamembertForQuestionAnswering,rd as CamembertForSequenceClassification,nd as CamembertForTokenClassification,td as CamembertModel,Gt as CamembertPreTrainedModel,tu as CamembertTokenizer,Uu as ChatterboxFeatureExtractor,un as ChatterboxModel,rl as ChatterboxPreTrainedModel,sp as ChatterboxProcessor,ap as ChineseCLIPFeatureExtractor,id as ChineseCLIPModel,nl as ChineseCLIPPreTrainedModel,_n as ClapAudioModelWithProjection,Gu as ClapFeatureExtractor,ad as ClapModel,rr as ClapPreTrainedModel,pn as ClapTextModelWithProjection,Qa as ClassifierFreeGuidanceLogitsProcessor,md as CodeGenForCausalLM,fd as CodeGenModel,mn as CodeGenPreTrainedModel,nu as CodeGenTokenizer,ru as CodeLlamaTokenizer,wd as Cohere2ForCausalLM,xd as Cohere2Model,gn as Cohere2PreTrainedModel,gd as CohereForCausalLM,hd as CohereModel,hn as CoherePreTrainedModel,ou as CohereTokenizer,bd as ConvBertForMaskedLM,Ed as ConvBertForQuestionAnswering,kd as ConvBertForSequenceClassification,vd as ConvBertForTokenClassification,yd as ConvBertModel,Wt as ConvBertPreTrainedModel,iu as ConvBertTokenizer,cp as ConvNextFeatureExtractor,Md as ConvNextForImageClassification,ba as ConvNextImageProcessor,Ad as ConvNextModel,xn as ConvNextPreTrainedModel,Od as ConvNextV2ForImageClassification,Sd as ConvNextV2Model,wn as ConvNextV2PreTrainedModel,Cd as DFineForObjectDetection,Td as DFineModel,bn as DFinePreTrainedModel,sf as DINOv3ConvNextModel,pl as DINOv3ConvNextPreTrainedModel,_p as DINOv3ViTImageProcessor,rf as DINOv3ViTModel,_l as DINOv3ViTPreTrainedModel,fp as DPTFeatureExtractor,_f as DPTForDepthEstimation,Ea as DPTImageProcessor,pf as DPTModel,Sn as DPTPreTrainedModel,vn as DacDecoderModel,il as DacDecoderOutput,kn as DacEncoderModel,ol as DacEncoderOutput,Gr as DacFeatureExtractor,Pd as DacModel,nr as DacPreTrainedModel,Nd as DebertaForMaskedLM,Rd as DebertaForQuestionAnswering,Fd as DebertaForSequenceClassification,$d as DebertaForTokenClassification,Ld as DebertaModel,Vt as DebertaPreTrainedModel,lu as DebertaTokenizer,jd as DebertaV2ForMaskedLM,Ud as DebertaV2ForQuestionAnswering,Bd as DebertaV2ForSequenceClassification,qd as DebertaV2ForTokenClassification,Dd as DebertaV2Model,Ht as DebertaV2PreTrainedModel,au as DebertaV2Tokenizer,Gd as DecisionTransformerModel,al as DecisionTransformerPreTrainedModel,up as DeiTFeatureExtractor,Vd as DeiTForImageClassification,ka as DeiTImageProcessor,Wd as DeiTModel,En as DeiTPreTrainedModel,Hd as DepthAnythingForDepthEstimation,ll as DepthAnythingPreTrainedModel,Ri as DepthEstimationPipeline,Kd as DepthProForDepthEstimation,cl as DepthProPreTrainedModel,pp as DetrFeatureExtractor,Qd as DetrForObjectDetection,Yd as DetrForSegmentation,va as DetrImageProcessor,Xd as DetrModel,ir as DetrObjectDetectionOutput,or as DetrPreTrainedModel,ul as DetrSegmentationOutput,Zd as Dinov2ForImageClassification,Jd as Dinov2Model,An as Dinov2PreTrainedModel,tf as Dinov2WithRegistersForImageClassification,ef as Dinov2WithRegistersModel,Mn as Dinov2WithRegistersPreTrainedModel,cf as DistilBertForMaskedLM,lf as DistilBertForQuestionAnswering,of as DistilBertForSequenceClassification,af as DistilBertForTokenClassification,nf as DistilBertModel,Kt as DistilBertPreTrainedModel,cu as DistilBertTokenizer,Fi as DocumentQuestionAnsweringPipeline,dp as DonutFeatureExtractor,qs as DonutImageProcessor,uf as DonutSwinModel,dl as DonutSwinPreTrainedModel,Jr as DynamicCache,ix as EdgeTamModel,ff as EfficientNetForImageClassification,mp as EfficientNetImageProcessor,df as EfficientNetModel,On as EfficientNetPreTrainedModel,hf as ElectraForMaskedLM,wf as ElectraForQuestionAnswering,gf as ElectraForSequenceClassification,xf as ElectraForTokenClassification,mf as ElectraModel,Xt as ElectraPreTrainedModel,uu as ElectraTokenizer,Ur as EncodecFeatureExtractor,Za as EosTokenCriteria,bf as Ernie4_5ForCausalLM,yf as Ernie4_5Model,In as Ernie4_5PretrainedModel,vf as EsmForMaskedLM,Ef as EsmForSequenceClassification,Af as EsmForTokenClassification,kf as EsmModel,xs as EsmPreTrainedModel,pu as EsmTokenizer,Sf as ExaoneForCausalLM,Mf as ExaoneModel,zn as ExaonePreTrainedModel,If as FalconForCausalLM,Tf as FalconH1ForCausalLM,zf as FalconH1Model,Cn as FalconH1PreTrainedModel,Of as FalconModel,Tn as FalconPreTrainedModel,_u as FalconTokenizer,Pf as FastViTForImageClassification,Cf as FastViTModel,Pn as FastViTPreTrainedModel,Di as FeatureExtractionPipeline,ae as FeatureExtractor,bi as FillMaskPipeline,Lf as Florence2ForConditionalGeneration,fl as Florence2PreTrainedModel,Hp as Florence2Processor,qa as ForcedBOSTokenLogitsProcessor,Ua as ForcedEOSTokenLogitsProcessor,hp as GLPNFeatureExtractor,Gf as GLPNForDepthEstimation,Uf as GLPNModel,Dn as GLPNPreTrainedModel,em as GPT2LMHeadModel,Zf as GPT2Model,Gn as GPT2PreTrainedModel,mu as GPT2Tokenizer,Vf as GPTBigCodeForCausalLM,Wf as GPTBigCodeModel,jn as GPTBigCodePreTrainedModel,sm as GPTJForCausalLM,tm as GPTJModel,Wn as GPTJPreTrainedModel,Kf as GPTNeoForCausalLM,Hf as GPTNeoModel,Bn as GPTNeoPreTrainedModel,Qf as GPTNeoXForCausalLM,Xf as GPTNeoXModel,qn as GPTNeoXPreTrainedModel,fu as GPTNeoXTokenizer,Rf as Gemma2ForCausalLM,$f as Gemma2Model,Nn as Gemma2PreTrainedModel,jf as Gemma3ForCausalLM,Df as Gemma3Model,Fn as Gemma3PreTrainedModel,Wu as Gemma3nAudioFeatureExtractor,$n as Gemma3nForCausalLM,ar as Gemma3nForConditionalGeneration,ml as Gemma3nPreTrainedModel,Kp as Gemma3nProcessor,Ff as GemmaForCausalLM,Nf as GemmaModel,Ln as GemmaPreTrainedModel,du as GemmaTokenizer,qf as GlmForCausalLM,Bf as GlmModel,Rn as GlmPreTrainedModel,Jf as GptOssForCausalLM,Yf as GptOssModel,Un as GptOssPreTrainedModel,nm as GraniteForCausalLM,rm as GraniteModel,im as GraniteMoeHybridForCausalLM,om as GraniteMoeHybridModel,Hn as GraniteMoeHybridPreTrainedModel,Vn as GranitePreTrainedModel,Vu as GraniteSpeechFeatureExtractor,am as GraniteSpeechForConditionalGeneration,Xp as GraniteSpeechProcessor,lm as GroundingDinoForObjectDetection,gp as GroundingDinoImageProcessor,gl as GroundingDinoPreTrainedModel,Qp as GroundingDinoProcessor,cm as GroupViTModel,xl as GroupViTPreTrainedModel,pm as HeliumForCausalLM,um as HeliumModel,Kn as HeliumPreTrainedModel,hu as HerbertTokenizer,dm as HieraForImageClassification,_m as HieraModel,Xn as HieraPreTrainedModel,ym as HubertForCTC,bm as HubertForSequenceClassification,wm as HubertModel,xm as HubertPreTrainedModel,vm as HunYuanDenseV1ForCausalLM,km as HunYuanDenseV1Model,Qn as HunYuanDenseV1PreTrainedModel,Om as IJepaForImageClassification,Sm as IJepaModel,Yn as IJepaPreTrainedModel,Mm as Idefics3ForConditionalGeneration,Aa as Idefics3ImageProcessor,Na as Idefics3Processor,Ti as ImageClassificationPipeline,ji as ImageFeatureExtractionPipeline,P as ImageFeatureExtractor,P as ImageProcessor,zs as ImageSegmentationPipeline,$i as ImageToImagePipeline,zi as ImageToTextPipeline,I0 as InterruptableStoppingCriteria,zm as JAISLMHeadModel,Im as JAISModel,Jn as JAISPreTrainedModel,wp as JinaCLIPImageProcessor,Tm as JinaCLIPModel,lr as JinaCLIPPreTrainedModel,Jp as JinaCLIPProcessor,Zn as JinaCLIPTextModel,Cm as JinaCLIPVisionModel,Lm as Lfm2ForCausalLM,Pm as Lfm2Model,Fm as Lfm2MoeForCausalLM,Nm as Lfm2MoeModel,to as Lfm2MoePreTrainedModel,eo as Lfm2PreTrainedModel,$m as Lfm2VlForConditionalGeneration,yp as Lfm2VlImageProcessor,Zp as Lfm2VlProcessor,ww as LiteWhisperForConditionalGeneration,jm as Llama4ForCausalLM,yl as Llama4PreTrainedModel,Dm as LlamaForCausalLM,Rm as LlamaModel,so as LlamaPreTrainedModel,gu as LlamaTokenizer,tt as LlavaForConditionalGeneration,tt as LlavaOnevisionForConditionalGeneration,bp as LlavaOnevisionImageProcessor,wl as LlavaPreTrainedModel,e_ as LlavaProcessor,Am as LlavaQwen2ForCausalLM,Ue as LogLevel,Ze as LogitsProcessor,ds as LogitsProcessorList,Yr as LogitsWarper,qm as LongT5ForConditionalGeneration,Bm as LongT5Model,ro as LongT5PreTrainedModel,Gm as M2M100ForConditionalGeneration,Um as M2M100Model,no as M2M100PreTrainedModel,xu as M2M100Tokenizer,yu as MBart50Tokenizer,Jm as MBartForCausalLM,Qm as MBartForConditionalGeneration,Ym as MBartForSequenceClassification,Xm as MBartModel,ys as MBartPreTrainedModel,Dr as MBartTokenizer,Fh as MPNetForMaskedLM,Dh as MPNetForQuestionAnswering,$h as MPNetForSequenceClassification,Rh as MPNetForTokenClassification,Nh as MPNetModel,Qt as MPNetPreTrainedModel,vu as MPNetTokenizer,Uh as MT5ForConditionalGeneration,qh as MT5Model,go as MT5PreTrainedModel,Vm as MarianMTModel,Wm as MarianModel,oo as MarianPreTrainedModel,wu as MarianTokenizer,vp as Mask2FormerImageProcessor,kp as MaskFormerFeatureExtractor,Km as MaskFormerForInstanceSegmentation,Us as MaskFormerImageProcessor,Hm as MaskFormerModel,io as MaskFormerPreTrainedModel,Ja as MaxLengthCriteria,Zm as Metric3DForDepthEstimation,bl as Metric3DPreTrainedModel,eh as Metric3Dv2ForDepthEstimation,kl as Metric3Dv2PreTrainedModel,th as MgpstrForSceneTextRecognition,vl as MgpstrModelOutput,El as MgpstrPreTrainedModel,t_ as MgpstrProcessor,bu as MgpstrTokenizer,lo as MimiDecoderModel,Ml as MimiDecoderOutput,ao as MimiEncoderModel,Al as MimiEncoderOutput,sh as MimiModel,cr as MimiPreTrainedModel,Ha as MinLengthLogitsProcessor,Ka as MinNewTokensLengthLogitsProcessor,nh as MistralForCausalLM,rh as MistralModel,co as MistralPreTrainedModel,ih as MobileBertForMaskedLM,lh as MobileBertForQuestionAnswering,ah as MobileBertForSequenceClassification,oh as MobileBertModel,bs as MobileBertPreTrainedModel,ku as MobileBertTokenizer,uh as MobileLLMForCausalLM,ch as MobileLLMModel,uo as MobileLLMPreTrainedModel,Ep as MobileNetV1FeatureExtractor,_h as MobileNetV1ForImageClassification,dh as MobileNetV1ForSemanticSegmentation,Ma as MobileNetV1ImageProcessor,ph as MobileNetV1Model,ur as MobileNetV1PreTrainedModel,Ap as MobileNetV2FeatureExtractor,mh as MobileNetV2ForImageClassification,hh as MobileNetV2ForSemanticSegmentation,Sa as MobileNetV2ImageProcessor,fh as MobileNetV2Model,pr as MobileNetV2PreTrainedModel,Mp as MobileNetV3FeatureExtractor,xh as MobileNetV3ForImageClassification,wh as MobileNetV3ForSemanticSegmentation,Oa as MobileNetV3ImageProcessor,gh as MobileNetV3Model,_r as MobileNetV3PreTrainedModel,Sp as MobileNetV4FeatureExtractor,bh as MobileNetV4ForImageClassification,kh as MobileNetV4ForSemanticSegmentation,Ia as MobileNetV4ImageProcessor,yh as MobileNetV4Model,dr as MobileNetV4PreTrainedModel,Op as MobileViTFeatureExtractor,Eh as MobileViTForImageClassification,za as MobileViTImageProcessor,vh as MobileViTModel,po as MobileViTPreTrainedModel,Mh as MobileViTV2ForImageClassification,Ah as MobileViTV2Model,_o as MobileViTV2PreTrainedModel,$w as ModelRegistry,Ch as ModernBertDecoderForCausalLM,Th as ModernBertDecoderModel,fo as ModernBertDecoderPreTrainedModel,Oh as ModernBertForMaskedLM,Ih as ModernBertForSequenceClassification,zh as ModernBertForTokenClassification,Sh as ModernBertModel,ks as ModernBertPreTrainedModel,Em as Moondream1ForConditionalGeneration,Hu as MoonshineFeatureExtractor,Lh as MoonshineForConditionalGeneration,Ph as MoonshineModel,mo as MoonshinePreTrainedModel,s_ as MoonshineProcessor,Bh as MptForCausalLM,jh as MptModel,ho as MptPreTrainedModel,Gh as MultiModalityCausalLM,Sl as MultiModalityPreTrainedModel,Vh as MusicgenForCausalLM,wo as MusicgenForConditionalGeneration,Wh as MusicgenModel,xo as MusicgenPreTrainedModel,Kh as NanoChatForCausalLM,Hh as NanoChatModel,yo as NanoChatPreTrainedModel,Qh as NeoBertForMaskedLM,Zh as NeoBertForQuestionAnswering,Yh as NeoBertForSequenceClassification,Jh as NeoBertForTokenClassification,Xh as NeoBertModel,Yt as NeoBertPreTrainedModel,Eu as NllbTokenizer,Xa as NoBadWordsLogitsProcessor,Wa as NoRepeatNGramLogitsProcessor,eg as NomicBertModel,Ol as NomicBertPreTrainedModel,Ip as NougatImageProcessor,Au as NougatTokenizer,_g as OPTForCausalLM,pg as OPTModel,Mo as OPTPreTrainedModel,Li as ObjectDetectionPipeline,ng as Olmo2ForCausalLM,rg as Olmo2Model,ko as Olmo2PreTrainedModel,ig as Olmo3ForCausalLM,og as Olmo3Model,vo as Olmo3PreTrainedModel,sg as OlmoForCausalLM,lg as OlmoHybridForCausalLM,ag as OlmoHybridModel,Eo as OlmoHybridPreTrainedModel,tg as OlmoModel,bo as OlmoPreTrainedModel,ug as OpenELMForCausalLM,cg as OpenELMModel,Ao as OpenELMPreTrainedModel,zp as OwlViTFeatureExtractor,hg as OwlViTForObjectDetection,Gs as OwlViTImageProcessor,mg as OwlViTModel,Oo as OwlViTPreTrainedModel,r_ as OwlViTProcessor,fg as Owlv2ForObjectDetection,Tp as Owlv2ImageProcessor,dg as Owlv2Model,So as Owlv2PreTrainedModel,gg as PaliGemmaForConditionalGeneration,n_ as PaliGemmaProcessor,Ku as ParakeetFeatureExtractor,xg as ParakeetForCTC,Il as ParakeetPreTrainedModel,yg as PatchTSMixerForPrediction,wg as PatchTSMixerModel,Io as PatchTSMixerPreTrainedModel,kg as PatchTSTForPrediction,bg as PatchTSTModel,zo as PatchTSTPreTrainedModel,Mg as Phi3ForCausalLM,Ag as Phi3Model,Co as Phi3PreTrainedModel,Po as Phi3VForCausalLM,Lp as Phi3VImageProcessor,zl as Phi3VPreTrainedModel,o_ as Phi3VProcessor,Eg as PhiForCausalLM,vg as PhiModel,To as PhiPreTrainedModel,Np as PixtralImageProcessor,i_ as PixtralProcessor,f as PreTrainedModel,T as PreTrainedTokenizer,Xs as PretrainedConfig,U as Processor,Og as PvtForImageClassification,Fp as PvtImageProcessor,Sg as PvtModel,Lo as PvtPreTrainedModel,Wr as PyAnnoteFeatureExtractor,zg as PyAnnoteForAudioFrameClassification,Ig as PyAnnoteModel,No as PyAnnotePreTrainedModel,a_ as PyAnnoteProcessor,yi as QuestionAnsweringPipeline,Cg as Qwen2ForCausalLM,Tg as Qwen2Model,Lg as Qwen2MoeForCausalLM,Pg as Qwen2MoeModel,$o as Qwen2MoePreTrainedModel,Fo as Qwen2PreTrainedModel,Mu as Qwen2Tokenizer,vs as Qwen2VLForCausalLM,fr as Qwen2VLForConditionalGeneration,$p as Qwen2VLImageProcessor,Tl as Qwen2VLPreTrainedModel,Kr as Qwen2VLProcessor,Es as Qwen2_5_VLForCausalLM,Ro as Qwen2_5_VLForConditionalGeneration,Xr as Qwen2_5_VLProcessor,Fg as Qwen3ForCausalLM,Ng as Qwen3Model,Rg as Qwen3MoeForCausalLM,$g as Qwen3MoeModel,jo as Qwen3MoePreTrainedModel,jg as Qwen3NextForCausalLM,Dg as Qwen3NextModel,Bo as Qwen3NextPreTrainedModel,Do as Qwen3PreTrainedModel,Ms as Qwen3VLForCausalLM,As as Qwen3VLForConditionalGeneration,qo as Qwen3VLMoeForCausalLM,Bg as Qwen3VLMoeForConditionalGeneration,l_ as Qwen3VLProcessor,Ss as Qwen3_5ForCausalLM,mr as Qwen3_5ForConditionalGeneration,Uo as Qwen3_5MoeForCausalLM,qg as Qwen3_5MoeForConditionalGeneration,Vg as RFDetrForObjectDetection,Wg as RFDetrModel,Cl as RFDetrObjectDetectionOutput,Wo as RFDetrPreTrainedModel,zd as RTDetrForObjectDetection,Rp as RTDetrImageProcessor,Id as RTDetrModel,yt as RTDetrObjectDetectionOutput,yn as RTDetrPreTrainedModel,nx as RTDetrV2ForObjectDetection,rx as RTDetrV2Model,Pl as RTDetrV2ObjectDetectionOutput,Vo as RTDetrV2PreTrainedModel,qr as RawAudio,ve as RawImage,wc as RawVideo,Bi as RawVideoFrame,Va as RepetitionPenaltyLogitsProcessor,Gg as ResNetForImageClassification,Ug as ResNetModel,Go as ResNetPreTrainedModel,Zg as RoFormerForMaskedLM,sx as RoFormerForQuestionAnswering,ex as RoFormerForSequenceClassification,tx as RoFormerForTokenClassification,Jg as RoFormerModel,Zt as RoFormerPreTrainedModel,Ou as RoFormerTokenizer,Kg as RobertaForMaskedLM,Yg as RobertaForQuestionAnswering,Xg as RobertaForSequenceClassification,Qg as RobertaForTokenClassification,Hg as RobertaModel,Jt as RobertaPreTrainedModel,Su as RobertaTokenizer,Hr as Sam2ImageProcessor,Fl as Sam2ImageSegmentationOutput,Ho as Sam2Model,$l as Sam2PreTrainedModel,Fa as Sam2Processor,c_ as Sam2VideoProcessor,Hr as Sam3ImageProcessor,ax as Sam3TrackerModel,Hr as SamImageProcessor,Ll as SamImageSegmentationOutput,ox as SamModel,Nl as SamPreTrainedModel,Qr as SamProcessor,Dp as SapiensFeatureExtractor,cx as SapiensForDepthEstimation,ux as SapiensForNormalEstimation,lx as SapiensForSemanticSegmentation,Ta as SapiensImageProcessor,hr as SapiensPreTrainedModel,Xu as SeamlessM4TFeatureExtractor,jp as SegformerFeatureExtractor,_x as SegformerForImageClassification,dx as SegformerForSemanticSegmentation,Ca as SegformerImageProcessor,px as SegformerModel,gr as SegformerPreTrainedModel,Bp as SiglipImageProcessor,fx as SiglipModel,Ko as SiglipPreTrainedModel,Xo as SiglipTextModel,Iu as SiglipTokenizer,mx as SiglipVisionModel,gx as SmolLM3ForCausalLM,hx as SmolLM3Model,Qo as SmolLM3PreTrainedModel,Aa as SmolVLMImageProcessor,Na as SmolVLMProcessor,Jo as SnacDecoderModel,Yo as SnacEncoderModel,Qu as SnacFeatureExtractor,xx as SnacModel,xr as SnacPreTrainedModel,Yu as SpeechT5FeatureExtractor,yx as SpeechT5ForSpeechToText,bx as SpeechT5ForTextToSpeech,kx as SpeechT5HifiGan,wx as SpeechT5Model,wr as SpeechT5PreTrainedModel,u_ as SpeechT5Processor,zu as SpeechT5Tokenizer,Ex as SqueezeBertForMaskedLM,Mx as SqueezeBertForQuestionAnswering,Ax as SqueezeBertForSequenceClassification,vx as SqueezeBertModel,Os as SqueezeBertPreTrainedModel,Tu as SqueezeBertTokenizer,Ox as StableLmForCausalLM,Sx as StableLmModel,Zo as StableLmPreTrainedModel,zx as Starcoder2ForCausalLM,Ix as Starcoder2Model,ei as Starcoder2PreTrainedModel,qt as StoppingCriteria,Js as StoppingCriteriaList,Tx as StyleTextToSpeech2Model,Rl as StyleTextToSpeech2PreTrainedModel,ki as SummarizationPipeline,ti as SupertonicForConditionalGeneration,Dl as SupertonicPreTrainedModel,Qs as SuppressTokensAtBeginLogitsProcessor,Fx as Swin2SRForImageSuperResolution,qp as Swin2SRImageProcessor,Nx as Swin2SRModel,si as Swin2SRPreTrainedModel,Px as SwinForImageClassification,Lx as SwinForSemanticSegmentation,Cx as SwinModel,yr as SwinPreTrainedModel,Rx as T5ForConditionalGeneration,$x as T5Model,ri as T5PreTrainedModel,Cu as T5Tokenizer,jx as TableTransformerForObjectDetection,Dx as TableTransformerModel,jl as TableTransformerObjectDetectionOutput,ni as TableTransformerPreTrainedModel,Ya as TemperatureLogitsWarper,A as Tensor,Ot as Text2TextGenerationPipeline,xi as TextClassificationPipeline,Ei as TextGenerationPipeline,Fw as TextStreamer,Ii as TextToAudioPipeline,wi as TokenClassificationPipeline,T as TokenizersBackend,O0 as TopKLogitsWarper,S0 as TopPLogitsWarper,Bx as TrOCRForCausalLM,Bl as TrOCRPreTrainedModel,vi as TranslationPipeline,ws as UltravoxModel,hl as UltravoxPreTrainedModel,p_ as UltravoxProcessor,Ux as UniSpeechForCTC,Gx as UniSpeechForSequenceClassification,qx as UniSpeechModel,br as UniSpeechPreTrainedModel,Kx as UniSpeechSatForAudioFrameClassification,Vx as UniSpeechSatForCTC,Hx as UniSpeechSatForSequenceClassification,Wx as UniSpeechSatModel,Is as UniSpeechSatPreTrainedModel,Yp as VLChatProcessor,xp as VLMImageProcessor,Qx as VaultGemmaForCausalLM,Xx as VaultGemmaModel,oi as VaultGemmaPreTrainedModel,Up as ViTFeatureExtractor,Zx as ViTForImageClassification,Pa as ViTImageProcessor,ew as ViTMAEModel,ql as ViTMAEPreTrainedModel,sw as ViTMSNForImageClassification,tw as ViTMSNModel,ai as ViTMSNPreTrainedModel,Jx as ViTModel,ii as ViTPreTrainedModel,Yx as VisionEncoderDecoderModel,rw as VitMatteForImageMatting,Gp as VitMatteImageProcessor,Ul as VitMattePreTrainedModel,nw as VitPoseForPoseEstimation,Wp as VitPoseImageProcessor,Gl as VitPosePreTrainedModel,ow as VitsModel,Wl as VitsModelOutput,Vl as VitsPreTrainedModel,Lu as VitsTokenizer,iw as VoxtralForConditionalGeneration,__ as VoxtralProcessor,ep as VoxtralRealtimeFeatureExtractor,li as VoxtralRealtimeForConditionalGeneration,Hl as VoxtralRealtimePreTrainedModel,f_ as VoxtralRealtimeProcessor,uw as Wav2Vec2BertForCTC,pw as Wav2Vec2BertForSequenceClassification,cw as Wav2Vec2BertModel,kr as Wav2Vec2BertPreTrainedModel,Nu as Wav2Vec2CTCTokenizer,Ju as Wav2Vec2FeatureExtractor,gm as Wav2Vec2ForAudioFrameClassification,mm as Wav2Vec2ForCTC,hm as Wav2Vec2ForSequenceClassification,fm as Wav2Vec2Model,pt as Wav2Vec2PreTrainedModel,m_ as Wav2Vec2Processor,h_ as Wav2Vec2ProcessorWithLM,hw as WavLMForAudioFrameClassification,dw as WavLMForCTC,fw as WavLMForSequenceClassification,mw as WavLMForXVector,_w as WavLMModel,es as WavLMPreTrainedModel,Zu as WeSpeakerFeatureExtractor,gw as WeSpeakerResNetModel,Xl as WeSpeakerResNetPreTrainedModel,tp as WhisperFeatureExtractor,Yl as WhisperForConditionalGeneration,xw as WhisperModel,ci as WhisperPreTrainedModel,g_ as WhisperProcessor,Eb as WhisperTextStreamer,Ga as WhisperTimeStampLogitsProcessor,Fu as WhisperTokenizer,Ew as XLMForQuestionAnswering,kw as XLMForSequenceClassification,vw as XLMForTokenClassification,yw as XLMModel,ts as XLMPreTrainedModel,Mw as XLMRobertaForMaskedLM,Iw as XLMRobertaForQuestionAnswering,Sw as XLMRobertaForSequenceClassification,Ow as XLMRobertaForTokenClassification,Aw as XLMRobertaModel,ss as XLMRobertaPreTrainedModel,$u as XLMRobertaTokenizer,Ru as XLMTokenizer,bw as XLMWithLMHeadModel,Kl as XVectorOutput,Vp as YolosFeatureExtractor,Tw as YolosForObjectDetection,La as YolosImageProcessor,zw as YolosModel,Jl as YolosObjectDetectionOutput,ui as YolosPreTrainedModel,Pw as YoutuForCausalLM,Cw as YoutuModel,pi as YoutuPreTrainedModel,Si as ZeroShotAudioClassificationPipeline,Ai as ZeroShotClassificationPipeline,Pi as ZeroShotImageClassificationPipeline,Ni as ZeroShotObjectDetectionPipeline,ie as cat,oE as cos_sim,Ny as dot,J as env,we as full,Rr as full_like,qc as interpolate,Be as interpolate_4d,XO as layer_norm,LE as load_image,EA as load_video,$c as log_softmax,s0 as matmul,pa as mean,r0 as mean_pooling,Se as ones,_a as ones_like,dE as permute,sX as pipeline,o0 as quantize_embeddings,QO as rand,n0 as randn,ls as random,Bu as read_audio,KO as rfft,ua as slice,de as softmax,Ge as stack,Uc as std_mean,ct as topk,Wc as zeros,Vc as zeros_like};
20
+ ${r}${o}`+n.repeat(t)+`${r}`,i}function gA(t,e,s,r){return`${e}${r}`+s.repeat(t)+`${e}`}function xA(t,e,s,r,n,o){return t===0&&e===0?gA(s,r,n,o):hA(s,t,e,r,n,o)}var Na=class extends U{static image_processor_class=ue;static tokenizer_class=W;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 u=0;u<e.length;++u){let _=e[u],d=o[u],m=i[u];l.push(xy(_,this.image_token));let h=d.map((w,y)=>xA(w,m[y],a,this.fake_image_token,this.image_token,this.global_img_token)),g=_.split(this.image_token);if(g.length===0)throw new Error("The image token should be present in the text.");let x=g[0];for(let w=0;w<h.length;++w)x+=h[w]+g[w+1];c.push(x)}return{...this.tokenizer(c),...n}}};var t_=class extends U{static image_processor_class=ue;static tokenizer_class=W;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(g=>g.images).flatMap(g=>g.images).map(g=>ve.read(g)));let n=this.tokenizer,o=n.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0,chat_template:r}),i=g=>n.encode(g,{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,p,u]=n.convert_tokens_to_ids([this.image_tag,this.image_start_tag,this.image_end_tag]),_=i(a[0]),d=new Array(_.length).fill(!1);for(let g=1;g<a.length;++g){let x=new Array(this.num_image_tokens).fill(c),w=i(a[g]);_=Fe(_,[p],x,[u],w);let y=new Array(this.num_image_tokens).fill(!0);d=Fe(d,[!1],y,[!1],new Array(w.length).fill(!1))}let m=[1,_.length],h={input_ids:new v("int64",_,m),attention_mask:new v("int64",new Array(_.length).fill(1),m),images_seq_mask:new v("bool",d,m),images_emb_mask:new v("bool",new Array(l*this.num_image_tokens).fill(!0),[1,l,this.num_image_tokens])};if(s&&s.length>0){let g=await this.image_processor(s);return g.pixel_values.unsqueeze_(0),{...h,...g}}return h}};var s_=class extends U{static tokenizer_class=W;static image_processor_class=ue;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 r_=class extends U{static tokenizer_class=W;static image_processor_class=ue;async _call(e,s=null,r={}){let{image_rows:n,image_cols:o,image_sizes:i,...a}=await this.image_processor(e,{...r,return_row_col_info:!0});if(s){let l=this.config.image_token??"<image>",{tile_size:c=512,downsample_factor:p=2,encoder_patch_size:u=16,use_thumbnail:_=!0}=this.image_processor.config,d=y=>Math.ceil(Math.floor(y/u)/p),m=d(c)**2,h=this.config.image_start_token??"<|image_start|>",g=this.config.image_end_token??"<|image_end|>",x=this.config.image_thumbnail??"<|img_thumbnail|>";Array.isArray(s)||(s=[s]);let w=0;s=s.map(y=>{let b=y.split(l);return b[0]+b.slice(1).map(E=>{let k=w++,[O,N]=i[k],j=n[k],C=o[k],R=d(O)*d(N),$=h;if(j>1||C>1){let q=l.repeat(m);for(let B=0;B<j;++B)for(let G=0;G<C;++G)$+=`<|img_row_${B+1}_col_${G+1}|>`+q;_&&($+=x+l.repeat(R))}else $+=l.repeat(R);return $+g+E}).join("")})}return{...a,...s?this.tokenizer(s,r):{}}}};var n_=class extends U{static tokenizer_class=W;static image_processor_class=ue;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:p}=this.config,u=Math.floor(i/c)*Math.floor(a/c)+p;s=structuredClone(s),Array.isArray(s)||(s=[s]);for(let _=0;_<s.length;++_)s[_]=s[_].replace(l,l.repeat(u))}let o=s?this.tokenizer(s,r):{};return{...n,...o}}};var V0={char:["char_decode",1],bpe:["bpe_decode",2],wp:["wp_decode",102]},o_=class extends U{static tokenizer_class=W;static image_processor_class=ue;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(!V0.hasOwnProperty(s))throw new Error(`Format ${s} is not supported.`);let[r,n]=V0[s],o=this[r].bind(this),[i,a]=e.dims,l=[],c=[],p=e.tolist();for(let _=0;_<i;++_){let d=p[_],m=[],h=[];for(let x=1;x<a;++x){let[w,y]=pe(de(d[x]));if(h.push(w),y==n)break;m.push(y)}let g=h.length>0?h.reduce((x,w)=>x*w,1):0;c.push(m),l.push(g)}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"),p=[],u=[];for(let _=0;_<n.length;++_){let[d,m]=pe([o[_],a[_],c[_]]);p.push([n[_],i[_],l[_]][m]),u.push(d)}return{generated_text:p,scores:u,char_preds:n,bpe_preds:i,wp_preds:l}}static async from_pretrained(...e){let s=await super.from_pretrained(...e),r=await W.from_pretrained("Xenova/gpt2"),n=await W.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 i_=class extends U{static tokenizer_class=W;static feature_extractor_class=be;async _call(e){return await this.feature_extractor(e)}};var a_=class extends U{static tokenizer_class=W;static image_processor_class=ue};var Us="<image>";function wA(t,e,s,r,n){return`${r.repeat(s*n)}${e}${t}
21
+ `}var l_=class extends U{static tokenizer_class=W;static image_processor_class=ue;static uses_processor_config=!1;async _call(e,s=null,r={}){s||(F.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 p=c.replaceAll(Us,Us.repeat(o)),u=p.lastIndexOf(Us),_=u===-1?0:u+Us.length;return p.slice(0,_)+n+p.slice(_)+`
22
+ `}):(F.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=>wA(c,n,o,Us,e.length)));let a=this.tokenizer(i,r);return{...await this.image_processor(e,r),...a}}};var H0="<|image|>",yA=/<\|image_\d+\|>/g,c_=class extends U{static image_processor_class=ue;static tokenizer_class=W;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((u,_)=>u.split(yA).join(H0.repeat(l[_])));i=this.tokenizer(c,{padding:r,truncation:n});let p=this.tokenizer._tokenizer.token_to_id(H0);i.input_ids.map_(u=>u==p?-u:u)}else i=this.tokenizer(e);return{...i,...a}}};var p_=class extends U{static tokenizer_class=W;static image_processor_class=ue;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:p,patch_size:u,spatial_merge_size:_}=this.config,d=u*_,m=Math.floor(i/d),h=Math.floor(a/d);s=structuredClone(s),Array.isArray(s)||(s=[s]);for(let g=0;g<s.length;++g){let x=l.repeat(h),w=x+c,y=x+p,b=w.repeat(m-1)+y;s[g]=s[g].replace(l,b)}}let o=s?this.tokenizer(s,r):{};return{...n,...o}}};var u_=class extends U{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 Xr=class extends ss{};var __=class extends Xr{};var Qr=class extends U{static image_processor_class=ue;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 Fa=class extends Qr{},d_=class extends Fa{};var f_=class extends U{static tokenizer_class=W;static feature_extractor_class=be;async _call(e){return await this.feature_extractor(e)}};var m_=class extends U{static tokenizer_class=W;static feature_extractor_class=be;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 p=this.config.audio_placeholder;if(!e.includes(p))throw new Error(`The input text does not contain the image token ${p}.`);e=e.replaceAll(p,p.repeat(c))}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};var $a="[AUDIO]",bA="[BEGIN_AUDIO]",kA=375;function vA(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 h_=class extends U{static tokenizer_class=W;static feature_extractor_class=be;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($a))throw new Error(`The input text does not contain the audio token ${$a}.`);Array.isArray(s)||(s=[s]);let i=e.split($a),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=>vA(m,l)),p=c.map(m=>m.length),u=c.flat(),_=(await Promise.all(u.map(m=>this.feature_extractor(m,r)))).map(m=>m.input_features);n.audio_values=_.length>1?ie(_,0):_[0];let d=i[0];for(let m=0;m<p.length;++m){d+=bA;for(let h=0;h<p[m];++h)d+=$a.repeat(kA);d+=i[m+1]}e=d}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}};var K0=32,g_=6,Ra=8,EA=10,AA=32,x_=class extends U{static tokenizer_class=W;static feature_extractor_class=be;static uses_processor_config=!1;get num_mel_frames_first_audio_chunk(){return(g_+1)*Ra}get num_samples_first_audio_chunk(){let{hop_length:e,n_fft:s}=this.feature_extractor.config;return(this.num_mel_frames_first_audio_chunk-1)*e+Math.floor(s/2)}get num_samples_per_audio_chunk(){let{hop_length:e,n_fft:s}=this.feature_extractor.config;return Ra*e+s}get num_right_pad_tokens(){return g_+1+EA}get audio_length_per_tok(){return Ra}get raw_audio_length_per_tok(){return Ra*this.feature_extractor.config.hop_length}async _call(e,{is_streaming:s=!1,is_first_audio_chunk:r=!0}={}){if(me(e,"VoxtralRealtimeProcessor"),!s&&!r)throw new Error("In non-streaming mode (`is_streaming=false`), `is_first_audio_chunk` must be `true`.");if(r)if(s){let n=K0*this.raw_audio_length_per_tok,o=new Float32Array(n+e.length);o.set(e,n);let i=await this.feature_extractor(o,{center:!0}),l=1+(K0+g_),c=new BigInt64Array(l).fill(BigInt(AA));return c[0]=1n,{input_ids:new v("int64",c,[1,l]),...i}}else{let n=this.num_right_pad_tokens*this.raw_audio_length_per_tok,o=new Float32Array(e.length+n);return o.set(e),await this.feature_extractor(o,{center:!0})}else return await this.feature_extractor(e,{center:!1})}};var w_=class extends U{static tokenizer_class=W;static feature_extractor_class=be;async _call(e){return await this.feature_extractor(e)}};var y_=class extends U{static tokenizer_class=W;static feature_extractor_class=be;async _call(e){return await this.feature_extractor(e)}};var b_=class extends U{static tokenizer_class=W;static feature_extractor_class=be;async _call(e){return await this.feature_extractor(e)}};var ja=class{static async from_pretrained(e,s={}){let r=await Ce(e,yt,!0,s),{image_processor_type:n,feature_extractor_type:o,processor_class:i}=r;if(i&&Da[i])return Da[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=qs[n.replace(/Fast$/,"")];if(!c)throw new Error(`Unknown image_processor_type: '${n}'.`);a.image_processor=new c(r)}if(o){let c=qs[o];if(c)a.image_processor=new c(r);else{let p=Vr[o];if(!p)throw new Error(`Unknown feature_extractor_type: '${o}'.`);a.feature_extractor=new p(r)}}let l={};return new U(l,a,null)}};async function MA(t,e){return await Ce(t,"config.json",!0,e)}function Gs(t){let e={},s={};switch(t.model_type){case"llava":case"paligemma":case"gemma3":case"florence2":case"llava_onevision":case"idefics3":case"granite_speech":case"ultravox":case"voxtral":case"voxtral_realtime":case"smolvlm":case"gemma3n":case"lfm2_vl":case"chatterbox":case"lighton_ocr":case"glm_ocr":case"mistral3":case"qwen2_5_vl":case"qwen3_vl":case"qwen3_vl_moe":s=Gs(t.text_config);break;case"moondream1":s=Gs(t.phi_config);break;case"musicgen":s=Gs(t.decoder);break;case"multi_modality":s=Gs(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"voxtral_realtime_text":case"voxtral_realtime_encoder":case"starcoder2":case"qwen2":case"qwen2_moe":case"qwen2_vl":case"qwen2_vl_text":case"qwen2_5_vl_text":case"qwen3_moe":case"qwen3_vl_text":case"qwen3_vl_moe_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"solar_open":case"glm_ocr_text":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"nemotron_h":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":case"deepseek_v3":case"glm_moe_dsa":case"mistral4":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=Gs(t.decoder),o="num_decoder_layers"in n,i=ke(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,...ke(t,["model_type","multi_query","is_encoder_decoder"])};for(let n in e)r[n]=t[e[n]];return r}function rs(t,e){t instanceof Ws||(t=new Ws(t));let s=e?.batch_size??1;if(["lfm2","lfm2_moe"].includes(t.model_type)){let r=e?.prefix??"past_key_values",n=r==="present"?"present":"past",o={},{layer_types:i,num_attention_heads:a,num_key_value_heads:l,hidden_size:c,conv_L_cache:p}=t,u=c/a;for(let _=0;_<i.length;++_)if(i[_]==="full_attention")for(let d of["key","value"])o[`${r}.${_}.${d}`]=[s,l,0,u];else if(i[_]==="conv")o[`${n}_conv.${_}`]=[s,c,p];else throw new Error(`Unsupported layer type: ${i[_]}`);return o}else if(["granitemoehybrid","falcon_h1","nemotron_h"].includes(t.model_type)){let r=e?.prefix??"past_key_values",n=r==="present"?"present":"past",o=t,i=o.layer_types??o.layers_block_type,a=o.num_hidden_layers??i?.length,l=o.num_key_value_heads,c=o.head_dim??o.hidden_size/o.num_attention_heads,p=o.mamba_n_heads??o.mamba_num_heads,u=o.mamba_d_head??o.mamba_head_dim,_=o.mamba_d_state??o.ssm_state_size,d=o.mamba_n_groups??o.n_groups,m=o.mamba_d_conv??o.conv_kernel,g=(o.mamba_d_ssm??(o.mamba_expand?o.mamba_expand*o.hidden_size:p*u))+2*d*_,x={};for(let w=0;w<a;++w)if((!i||i[w]==="mamba")&&(x[`${n}_conv.${w}`]=[s,g,m],x[`${n}_ssm.${w}`]=[s,p,u,_]),!i||i[w]==="attention")for(let y of["key","value"])x[`${r}.${w}.${y}`]=[s,l,0,c];return x}else if(["qwen3_next","qwen3_5_text","qwen3_5_moe_text","olmo_hybrid"].includes(t.model_type)){let r=e?.prefix??"past_key_values",n=r==="present"?"present":"past",o={},{head_dim:i,layer_types:a,num_attention_heads:l,num_key_value_heads:c,hidden_size:p,linear_num_value_heads:u,linear_num_key_heads:_,linear_key_head_dim:d,linear_value_head_dim:m,linear_conv_kernel_dim:h}=t,g=d*_,x=m*u,w=i??p/l;for(let y=0;y<a.length;++y)if(a[y]==="full_attention")for(let b of["key","value"])o[`${r}.${y}.${b}`]=[s,c,0,w];else if(a[y]==="linear_attention"){if(t.model_type==="olmo_hybrid")o[`${n}_conv.${y}.key`]=[s,g,h],o[`${n}_conv.${y}.value`]=[s,x,h],o[`${n}_conv.${y}.query`]=[s,g,h];else{let b=g*2+x;o[`${n}_conv.${y}`]=[s,b,h]}o[`${n}_recurrent.${y}`]=[s,u,d,m]}else throw new Error(`Unsupported layer type: ${a[y]}`);return o}else if(["lfm2_vl","qwen3_5","qwen3_5_moe","voxtral_realtime"].includes(t.model_type)){let r;return t.model_type==="voxtral_realtime"&&e?.session_name==="audio_encoder"?r=t.audio_config:r=t.text_config,rs(r,e)}return SA(t,e)}function SA(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 p=0;p<i;++p)r[`${e}.${p}.key`]=l,r[`${e}.${p}.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 Ws=class t{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=Gs(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 MA(e,{progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i});return new this(a)}},Ze=class{static async from_pretrained(...e){return Ws.from_pretrained(...e)}};function k_(t,e,s){return t?typeof t=="object"&&t!==null?t.hasOwnProperty(e)?+t[e]:t.hasOwnProperty(s)?+t[s]:0:+t:0}function v_(t,e){let s=[];for(let r=0;r<e;++r)s.push(`${t}_data${r===0?"":"_"+r}`);return s}async function X0(t,e,s,r){let n=`${e}${r}.onnx`,o=`${s.subfolder??""}/${n}`;return await Pr(t,o,!0,s,V.IS_NODE_ENV)}async function Q0(t,e,s,r,n,o={}){let i=`${e}${s}.onnx`,a=V.IS_NODE_ENV,l=[],c=k_(n,i,e);if(c>0){if(c>ea)throw new Error(`The number of external data chunks (${c}) exceeds the maximum allowed value (${ea}).`);let p=v_(i,c);for(let u of p){let _=`${r.subfolder??""}/${u}`;l.push(new Promise(async(d,m)=>{let h=await Pr(t,_,!0,r,a);d(h instanceof Uint8Array?{path:u,data:h}:u)}))}}else o.externalData!==void 0&&(l=o.externalData.map(async p=>{if(typeof p.data=="string"){let u=await Pr(t,p.data,!0,r);return{...p,data:u}}return p}));return Promise.all(l)}async function OA(t,e,s,r=!1,n=void 0){let o=s.config?.["transformers.js_config"]??{},i=la(s.device??o.device,e,{warn:b=>F.info(b)}),a=w0(i),l=o.device_config??{};l.hasOwnProperty(i)&&(o={...o,...l[i]});let c=ca(s.dtype??o.dtype,e,i,{configDtype:o.dtype,warn:b=>F.info(b)});if(Fr.hasOwnProperty(c)){if(i==="webgpu"&&!V.IS_NODE_ENV&&c===Re.fp16&&!await E0())throw new Error(`The device (${i}) does not support fp16.`)}else throw new Error(`Invalid dtype: ${c}. Should be one of: ${Object.keys(Re).join(", ")}`);let p=o.kv_cache_dtype,u=p?typeof p=="string"?p:p[c]??"float32":void 0;if(u&&!["float32","float16"].includes(u))throw new Error(`Invalid kv_cache_dtype: ${u}. Should be one of: float32, float16`);let _=Fr[c],d={...s.session_options};d.executionProviders??=a;let m=o.free_dimension_overrides;m?d.freeDimensionOverrides??=m:i.startsWith("webnn")&&!d.freeDimensionOverrides&&F.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 h=X0(t,e,s,_),g=s.use_external_data_format??o.use_external_data_format,x=await Q0(t,e,_,s,g,d);if(x.length>0&&!V.IS_NODE_ENV&&(d.externalData=x),r&&i==="webgpu"&&p!==!1){let b=rs(s.config,{prefix:"present",session_name:n});if(Object.keys(b).length>0&&!Nr()){let E={};for(let k in b)E[k]="gpu-buffer";d.preferredOutputLocation=E}}return{buffer_or_path:await h,session_options:d,session_config:{dtype:c,kv_cache_dtype:u,device:i}}}async function Y0(t,e,s,r=void 0){return Object.fromEntries(await Promise.all(Object.keys(e).map(async n=>{let o=r?.[n]??!1,{buffer_or_path:i,session_options:a,session_config:l}=await OA(t,e[n],s,o,n),c=await oa(i,a,l);return[n,c]})))}function J0(t){for(let e in t)aa(t[e])?t[e]=new v(t[e]):typeof t[e]=="object"&&J0(t[e]);return t}async function X(t,e){let s=IA(t,e);try{let r=Object.fromEntries(Object.entries(s).map(([o,i])=>{let a=i.ort_tensor;return V.IS_NODE_ENV&&typeof Float16Array<"u"&&a.cpuData instanceof Float16Array&&(a.cpuData=new Uint16Array(a.cpuData.buffer)),[o,a]})),n=await ia(t,r);return J0(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 F.error(`An error occurred during model execution: "${r}".`),F.error("Inputs given to model:",n),r}}function IA(t,e){let s=Object.create(null),r=[];for(let i of t.inputNames){let a=e[i];if(!(a instanceof v)){r.push(i);continue}s[i]=Nr()?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));F.warn(`WARNING: Too many inputs were provided (${n} > ${o}). The following inputs will be ignored: "${i.join(", ")}".`)}return s}var fe=class{};var I=class extends fe{constructor({logits:e,...s}){super(),this.logits=e;let r=Object.values(s);r.length>0&&(this.attentions=r)}},ee=class extends fe{constructor({logits:e}){super(),this.logits=e}},re=class extends fe{constructor({logits:e}){super(),this.logits=e}},le=class extends fe{constructor({start_logits:e,end_logits:s}){super(),this.start_logits=e,this.end_logits=s}},je=class extends fe{constructor({logits:e}){super(),this.logits=e}};var Ba=class extends fe{constructor({alphas:e}){super(),this.alphas=e}};var et=class extends Me{_call(e,s){throw Error("`_call` should be implemented in a subclass")}},Yr=class extends Me{_call(e,s){throw Error("`_call` should be implemented in a subclass")}},ns=class extends Me{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()}},qa=class extends et{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}},Ua=class extends et{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}},Vs=class extends et{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}},Ga=class extends et{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 u=this.timestamp_begin+this.max_initial_timestamp_index;n.subarray(u+1).fill(-1/0)}let l=jc(n),c=Math.log(l.subarray(this.timestamp_begin).map(Math.exp).reduce((u,_)=>u+_)),p=pe(l.subarray(0,this.timestamp_begin))[0];c>p&&n.subarray(0,this.timestamp_begin).fill(-1/0)}return s}},Wa=class extends et{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}},Va=class extends et{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}},Ha=class extends et{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}},Ka=class extends et{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}},Xa=class extends et{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}},Qa=class extends et{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}},Ya=class extends Yr{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}},Z0=class extends Yr{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}},eb=class extends Yr{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 Hs=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,ke(e,Object.getOwnPropertyNames(this)))}};var Lt=class extends Me{_call(e,s){throw Error("StoppingCriteria needs to be subclassed")}},Ks=class t extends Me{constructor(){super(),this.criteria=[]}push(e){this.criteria.push(e)}extend(e){e instanceof t?e=e.criteria:e instanceof Lt&&(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()}},Ja=class extends Lt{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)}},Za=class extends Lt{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)})}},tb=class extends Lt{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 os=class extends Me{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 Ky(e)}static getSampler(e){if(e.do_sample)return new A_(e);if(e.num_beams>1)return new M_(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 E_(e)}},E_=class extends os{async sample(e){let s=pe(e.data)[1];return[[BigInt(s),0]]}},A_=class extends os{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=de(r.data);return Array.from({length:this.generation_config.num_beams},()=>{let i=this.randomSelect(o);return[n.data[i],Math.log(o[i])]})}},M_=class extends os{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=de(r.data);return Array.from({length:this.generation_config.num_beams},(i,a)=>[n.data[a],Math.log(o[a])])}};var S_=class{constructor(e){if(e)for(let s in e){if(s in this)throw new TypeError(`Key "${s}" conflicts with an existing property on DynamicCache`);let r=e[s];if(!(r instanceof v))throw new TypeError(`Expected a Tensor for key "${s}", got ${typeof r}`);this[s]=r}}get_seq_length(){let e=this;for(let s in e)if(s.startsWith("past_key_values."))return e[s].dims.at(-2);throw new Error("Unable to determine sequence length from the cache.")}async dispose(){let e=[];for(let s of Object.values(this))s.location==="gpu-buffer"&&e.push(s.dispose());await Promise.all(e)}},Jr=S_;var is=null;function rb(t){is=t}function O_(t){if(t instanceof v)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 v("int64",BigInt64Array.from(t.flat().map(e=>BigInt(e))),[t.length,t[0].length])}else return new v("int64",BigInt64Array.from(t.map(e=>BigInt(e))),[1,t.length])}function I_(t){return new v("bool",[t],[1])}var L={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,MultimodalLanguageModelOnly:16,VoxtralRealtime:17},Xs={[L.DecoderOnly]:{can_generate:!0,forward:Ue,prepare_inputs:Qs,sessions:(t,e)=>({model:e.model_file_name??"model"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[L.DecoderOnlyWithoutHead]:{can_generate:!1,forward:Ue,prepare_inputs:Qs,sessions:(t,e)=>({model:e.model_file_name??"model"})},[L.Seq2Seq]:{can_generate:!0,forward:el,prepare_inputs:en,sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.Vision2Seq]:{can_generate:!0,forward:el,prepare_inputs:en,sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.Musicgen]:{can_generate:!0,forward:el,sessions:()=>({model:"text_encoder",decoder_model_merged:"decoder_model_merged",encodec_decode:"encodec_decode"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.EncoderDecoder]:{can_generate:!1,forward:el,sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0}},[L.MaskGeneration]:{sessions:()=>({model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"})},[L.ImageTextToText]:{can_generate:!0,forward:sb,prepare_inputs:Zr,sessions:t=>{let e={embed_tokens:"embed_tokens",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};return t.is_encoder_decoder&&(e.model="encoder_model"),e},cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.AudioTextToText]:{can_generate:!0,forward:TA,prepare_inputs:Zr,sessions:()=>({embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.ImageAudioTextToText]:{can_generate:!0,prepare_inputs:Zr,sessions:()=>({embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"}),optional_configs:{generation_config:"generation_config.json"}},[L.Phi3V]:{can_generate:!0,prepare_inputs:Zr,sessions:()=>({prepare_inputs_embeds:"prepare_inputs_embeds",model:"model",vision_encoder:"vision_encoder"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[L.MultiModality]:{can_generate:!0,sessions:()=>({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"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[L.AutoEncoder]:{can_generate:!1,forward:zA,sessions:()=>({encoder_model:"encoder_model",decoder_model:"decoder_model"})},[L.Supertonic]:{sessions:()=>({text_encoder:"text_encoder",latent_denoiser:"latent_denoiser",voice_decoder:"voice_decoder"})},[L.Chatterbox]:{can_generate:!0,forward:tt,sessions:()=>({embed_tokens:"embed_tokens",speech_encoder:"speech_encoder",model:"language_model",conditional_decoder:"conditional_decoder"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[L.MultimodalLanguageModelOnly]:{can_generate:!0,forward:sb,prepare_inputs:Zr,sessions:()=>({embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[L.VoxtralRealtime]:{can_generate:!0,prepare_inputs:Qs,sessions:()=>({embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0,audio_encoder:!0},optional_configs:{generation_config:"generation_config.json"}},default:{can_generate:!1,forward:tt,sessions:(t,e)=>({model:e.model_file_name??"model"})}};function nb(t,e,s={}){let r=Xs[t]??Xs.default;return{sessions:r.sessions(e,s),cache_sessions:r.cache_sessions,optional_configs:r.optional_configs}}var lt=new Map,tl=new Map,as=new Map,f=class extends Me{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=as.get(this.constructor),o=lt.get(n),i=Xs[o]??Xs.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:p=null,use_external_data_format:u=null,session_options:_={}}={}){let d={progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:p,use_external_data_format:u,session_options:_},m=as.get(this),h=lt.get(m);r=d.config=await Ze.from_pretrained(e,d);let g=Xs[h]??Xs.default;if(h===void 0){let b=m??r?.model_type;b!=="custom"&&F.warn(`Model type for '${b}' not found, assuming encoder-only architecture. Please report this at ${Tt}.`)}let x=g.sessions(r,d),w=[Y0(e,x,d,g.cache_sessions)];g.optional_configs&&w.push(PA(e,g.optional_configs,d));let y=await Promise.all(w);return new this(r,...y)}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 ns;if(e.repetition_penalty!==null&&e.repetition_penalty!==1&&n.push(new Va(e.repetition_penalty)),e.no_repeat_ngram_size!==null&&e.no_repeat_ngram_size>0&&n.push(new Wa(e.no_repeat_ngram_size)),e.bad_words_ids!==null&&n.push(new Xa(e.bad_words_ids,e.eos_token_id)),e.min_length!==null&&e.eos_token_id!==null&&e.min_length>0&&n.push(new Ha(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 Ka(s,e.min_new_tokens,e.eos_token_id)),e.forced_bos_token_id!==null&&n.push(new qa(e.forced_bos_token_id)),e.forced_eos_token_id!==null&&n.push(new Ua(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 Vs(e.begin_suppress_tokens,o))}return e.guidance_scale!==null&&e.guidance_scale>1&&n.push(new Qa(e.guidance_scale)),e.temperature===0&&e.do_sample&&(F.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 Ya(e.temperature)),r!==null&&n.extend(r),n}_prepare_generation_config(e,s,r=Hs){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,ke(s,Object.getOwnPropertyNames(o))),o}_get_stopping_criteria(e,s=null){let r=new Ks;return e.max_length!==null&&r.push(new Ja(e.max_length,this.config.max_position_embeddings??null)),e.eos_token_id!==null&&r.push(new Za(e.eos_token_id)),s&&r.extend(s),r}_validate_model_class(){if(!this.can_generate){let e=[is.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,is.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,is.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,is.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES].filter(Boolean),s=as.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 v("int64",e.flat(),[e.length,1]),n?"decoder_attention_mask"in r:r.attention_mask=ie([r.attention_mask,Se([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=ke(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,p=await this._prepare_inputs_embeds(s);s={...c,...ke(p,["inputs_embeds","attention_mask"])}}let{last_hidden_state:o}=await tt(this,s);if(n.guidance_scale!==null&&n.guidance_scale>1)o=ie([o,Rr(o,0)],0),"attention_mask"in s&&(s.attention_mask=ie([s.attention_mask,Xc(s.attention_mask)],0));else if(s.decoder_input_ids){let i=O_(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 v)){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=O_(a)}return r.decoder_attention_mask=da(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}),p=this.config.is_encoder_decoder;p&&("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 u;p?{input_ids:u,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}):u=l[c];let _=u.dims.at(-1);s.max_new_tokens!==null&&(s.max_length=_+s.max_new_tokens);let d=this._get_logits_processor(s,_,r),m=this._get_stopping_criteria(s,n),h=l[c].dims.at(0),g=os.getSampler(s),x=new Array(h).fill(0),w=u.tolist();o&&o.put(w);let y,b={},E={};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 $=this.getAttentions(y);for(let q in $)q in b||(b[q]=[]),b[q].push($[q])}else this._return_dict_in_generate_keys&&Object.assign(E,ke(y,this._return_dict_in_generate_keys));let N=y.logits.slice(null,-1,null).to("float32"),j=d(w,N),C=[];for(let $=0;$<j.dims.at(0);++$){let q=j[$],B=await g(q);for(let[G,Z]of B){let te=BigInt(G);x[$]+=Z,w[$].push(te),C.push([te]);break}}if(o&&o.put(C),m(w).every($=>$))break;l=this._update_model_kwargs_for_generation({generated_input_ids:C,outputs:y,model_inputs:l,is_encoder_decoder:p})}o&&o.end();let k=this.getPastKeyValues(y,l.past_key_values,!0),O=new v("int64",w.flat(),[w.length,w[0].length]);if(s.return_dict_in_generate)return{sequences:O,past_key_values:k,...b,...E};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 new Jr(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"?wt.float16:wt.float32,a=rs(this.config,{batch_size:n});for(let l in a){let c=a[l].reduce((p,u)=>p*u,1);e[l]=new v(o,new i(c),a[l])}}}async _encode_input(e,s,r){if(!Object.hasOwn(this.sessions,e))throw new Error(`Model does not have a ${e} session.`);let n=this.sessions[e];return(await X(n,ke(s,n.inputNames)))[r]}async encode_image(e){return this._encode_input("vision_encoder",e,"image_features")}async encode_text(e){return this._encode_input("embed_tokens",e,"inputs_embeds")}async encode_audio(e){return this._encode_input("audio_encoder",e,"audio_features")}};async function el(t,e){let{encoder_outputs:s,input_ids:r,decoder_input_ids:n,...o}=e;if(!s){let i=ke(e,t.sessions.model.inputNames);s=(await tt(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 tt(t,e){let s=t.sessions.model,r=ke(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=Xc(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=Se([n[0],n[2],n[3]])}return await X(s,r)}async function zA(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=I_(!!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=CA(o,n,a)}r.inputNames.includes("num_logits_to_keep")&&!o.num_logits_to_keep&&(o.num_logits_to_keep=new v("int64",[0n],[])),t.addPastKeyValues(o,n);let i=ke(o,r.inputNames);return await X(r,i)}async function ob(t,{encode_function:e,merge_function:s,modality_input_names: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:p=null,logits_processor:u=null,..._}){if(!l){l=await t.encode_text({input_ids:o,..._});let m=ke(_,r);if(Object.keys(m).length>0){if(o.dims[1]!==1){let h=await e({...m,..._});({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],g=c.get_seq_length();i=ie([Se([o.dims[0],g]),i.slice(null,[i.dims[1]-h,i.dims[1]])],1)}}}if(!a&&["qwen2_vl","qwen2_vl_text","qwen2_5_vl","qwen2_5_vl_text","qwen3_vl","qwen3_vl_text","qwen3_vl_moe","qwen3_vl_moe_text","qwen3_5","qwen3_5_text","qwen3_5_moe","qwen3_5_moe_text","glm_ocr","glm_ocr_text"].includes(t.config.model_type)){let{image_grid_thw:m,video_grid_thw:h}=_;[a]=t.get_rope_index(o,m,h,i)}return await Ue(t,{inputs_embeds:l,past_key_values:c,attention_mask:i,position_ids:a,generation_config:p,logits_processor:u},!0)}async function TA(t,e){return await ob(t,{...e,modality_input_names:["audio_values","input_features"],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 sb(t,e){return await ob(t,{...e,modality_input_names:["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 z_(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 p=a+c;n[p]===0n?o[p]=BigInt(1):(o[p]=l,l+=n[p])}}return{data:o,dims:t.dims}}function CA(t,e=null,s=0){let{input_ids:r,inputs_embeds:n,attention_mask:o}=t,{data:i,dims:a}=z_(o,s),l=new v("int64",i,a);if(e){let c=-(r??n).dims.at(1);l=l.slice(null,[c,null])}return l}function Qs(t,e,s,r){let n=s.past_key_values?s.past_key_values.get_seq_length():0;if((t.sessions.decoder_model_merged??t.sessions.model)?.inputNames.includes("num_logits_to_keep")&&!s.num_logits_to_keep&&(s.num_logits_to_keep=new v("int64",[1n],[])),!s.attention_mask){let i;for(let a of["input_ids","inputs_embeds","position_ids"])if(s[a]){i=s[a].dims;break}if(!i)throw new Error("attention_mask is not provided, and unable to infer its shape from model inputs.");s.attention_mask=Se([i[0],n+i[1]])}if(s.past_key_values){let{input_ids:i,attention_mask:a}=s;a&&a.dims[1]>i.dims[1]||n<i.dims[1]&&(s.input_ids=i.slice(null,[n,null]))}return s}function en(t,e,s,r){return s.past_key_values&&(e=e.map(n=>[n.at(-1)])),{...s,decoder_input_ids:O_(e)}}function Zr(t,...e){return t.config.is_encoder_decoder?en(t,...e):Qs(t,...e)}function ib({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n}){let o=r.tolist().map(c=>c.reduce((p,u,_)=>(u==t&&p.push(_),p),[])),i=o.reduce((c,p)=>c+p.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 p=o[c],u=e[c];for(let _=0;_<p.length;++_)u[p[_]].data.set(s[l++].data)}return{inputs_embeds:e,attention_mask:n}}function Ys({image_token_id:t,inputs_embeds:e,image_features:s,input_ids:r,attention_mask:n}){return ib({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n})}function sl({audio_token_id:t,inputs_embeds:e,audio_features:s,input_ids:r,attention_mask:n}){return ib({modality_token_id:t,inputs_embeds:e,modality_features:s,input_ids:r,attention_mask:n})}async function PA(t,e,s){return Object.fromEntries(await Promise.all(Object.keys(e).map(async r=>{let n=await Ce(t,e[r],!1,s);return[r,n]})))}var hi={};Ms(hi,{ASTForAudioClassification:()=>q_,ASTModel:()=>B_,ASTPreTrainedModel:()=>nn,AfmoeForCausalLM:()=>R_,AfmoeModel:()=>$_,AfmoePreTrainedModel:()=>sn,AlbertForMaskedLM:()=>L_,AlbertForQuestionAnswering:()=>P_,AlbertForSequenceClassification:()=>C_,AlbertModel:()=>T_,AlbertPreTrainedModel:()=>ls,ApertusForCausalLM:()=>F_,ApertusModel:()=>N_,ApertusPreTrainedModel:()=>tn,ArceeForCausalLM:()=>j_,ArceeModel:()=>D_,ArceePreTrainedModel:()=>rn,BartForConditionalGeneration:()=>G_,BartForSequenceClassification:()=>W_,BartModel:()=>U_,BartPretrainedModel:()=>Js,BeitForImageClassification:()=>H_,BeitModel:()=>V_,BeitPreTrainedModel:()=>on,BertForMaskedLM:()=>X_,BertForQuestionAnswering:()=>J_,BertForSequenceClassification:()=>Q_,BertForTokenClassification:()=>Y_,BertModel:()=>K_,BertPreTrainedModel:()=>Nt,BlenderbotForConditionalGeneration:()=>ed,BlenderbotModel:()=>Z_,BlenderbotPreTrainedModel:()=>an,BlenderbotSmallForConditionalGeneration:()=>sd,BlenderbotSmallModel:()=>td,BlenderbotSmallPreTrainedModel:()=>ln,BloomForCausalLM:()=>nd,BloomModel:()=>rd,BloomPreTrainedModel:()=>cn,CHMv2ForDepthEstimation:()=>ud,CHMv2PreTrainedModel:()=>ol,CLIPModel:()=>dd,CLIPPreTrainedModel:()=>mt,CLIPSegForImageSegmentation:()=>xd,CLIPSegModel:()=>gd,CLIPSegPreTrainedModel:()=>fn,CLIPTextModel:()=>fd,CLIPTextModelWithProjection:()=>dn,CLIPVisionModel:()=>md,CLIPVisionModelWithProjection:()=>hd,CamembertForMaskedLM:()=>id,CamembertForQuestionAnswering:()=>cd,CamembertForSequenceClassification:()=>ad,CamembertForTokenClassification:()=>ld,CamembertModel:()=>od,CamembertPreTrainedModel:()=>Ft,ChatterboxModel:()=>pn,ChatterboxPreTrainedModel:()=>rl,ChineseCLIPModel:()=>pd,ChineseCLIPPreTrainedModel:()=>nl,ClapAudioModelWithProjection:()=>_n,ClapModel:()=>_d,ClapPreTrainedModel:()=>Zs,ClapTextModelWithProjection:()=>un,CodeGenForCausalLM:()=>yd,CodeGenModel:()=>wd,CodeGenPreTrainedModel:()=>mn,Cohere2ForCausalLM:()=>Ed,Cohere2Model:()=>vd,Cohere2PreTrainedModel:()=>gn,CohereForCausalLM:()=>kd,CohereModel:()=>bd,CoherePreTrainedModel:()=>hn,ConvBertForMaskedLM:()=>Md,ConvBertForQuestionAnswering:()=>Id,ConvBertForSequenceClassification:()=>Sd,ConvBertForTokenClassification:()=>Od,ConvBertModel:()=>Ad,ConvBertPreTrainedModel:()=>$t,ConvNextForImageClassification:()=>Td,ConvNextModel:()=>zd,ConvNextPreTrainedModel:()=>xn,ConvNextV2ForImageClassification:()=>Pd,ConvNextV2Model:()=>Cd,ConvNextV2PreTrainedModel:()=>wn,DFineForObjectDetection:()=>$d,DFineModel:()=>Fd,DFinePreTrainedModel:()=>bn,DINOv3ConvNextModel:()=>pf,DINOv3ConvNextPreTrainedModel:()=>_l,DINOv3ViTModel:()=>uf,DINOv3ViTPreTrainedModel:()=>dl,DPTForDepthEstimation:()=>wf,DPTModel:()=>xf,DPTPreTrainedModel:()=>On,DacDecoderModel:()=>vn,DacDecoderOutput:()=>al,DacEncoderModel:()=>kn,DacEncoderOutput:()=>il,DacModel:()=>Rd,DacPreTrainedModel:()=>er,DebertaForMaskedLM:()=>jd,DebertaForQuestionAnswering:()=>Ud,DebertaForSequenceClassification:()=>Bd,DebertaForTokenClassification:()=>qd,DebertaModel:()=>Dd,DebertaPreTrainedModel:()=>Rt,DebertaV2ForMaskedLM:()=>Hd,DebertaV2ForQuestionAnswering:()=>Qd,DebertaV2ForSequenceClassification:()=>Kd,DebertaV2ForTokenClassification:()=>Xd,DebertaV2Model:()=>Vd,DebertaV2PreTrainedModel:()=>Dt,DecisionTransformerModel:()=>Yd,DecisionTransformerPreTrainedModel:()=>ll,DeepseekV3ForCausalLM:()=>Wd,DeepseekV3Model:()=>Gd,DeepseekV3PreTrainedModel:()=>En,DeiTForImageClassification:()=>Zd,DeiTModel:()=>Jd,DeiTPreTrainedModel:()=>An,DepthAnythingForDepthEstimation:()=>ef,DepthAnythingPreTrainedModel:()=>cl,DepthProForDepthEstimation:()=>tf,DepthProPreTrainedModel:()=>pl,DetrForObjectDetection:()=>rf,DetrForSegmentation:()=>nf,DetrModel:()=>sf,DetrObjectDetectionOutput:()=>sr,DetrPreTrainedModel:()=>tr,DetrSegmentationOutput:()=>ul,Dinov2ForImageClassification:()=>af,Dinov2Model:()=>of,Dinov2PreTrainedModel:()=>Mn,Dinov2WithRegistersForImageClassification:()=>cf,Dinov2WithRegistersModel:()=>lf,Dinov2WithRegistersPreTrainedModel:()=>Sn,DistilBertForMaskedLM:()=>hf,DistilBertForQuestionAnswering:()=>mf,DistilBertForSequenceClassification:()=>df,DistilBertForTokenClassification:()=>ff,DistilBertModel:()=>_f,DistilBertPreTrainedModel:()=>jt,DonutSwinModel:()=>gf,DonutSwinPreTrainedModel:()=>fl,EdgeTamModel:()=>Ax,EfficientNetForImageClassification:()=>bf,EfficientNetModel:()=>yf,EfficientNetPreTrainedModel:()=>In,ElectraForMaskedLM:()=>vf,ElectraForQuestionAnswering:()=>Mf,ElectraForSequenceClassification:()=>Ef,ElectraForTokenClassification:()=>Af,ElectraModel:()=>kf,ElectraPreTrainedModel:()=>Bt,Ernie4_5ForCausalLM:()=>Of,Ernie4_5Model:()=>Sf,Ernie4_5PretrainedModel:()=>zn,EsmForMaskedLM:()=>zf,EsmForSequenceClassification:()=>Tf,EsmForTokenClassification:()=>Cf,EsmModel:()=>If,EsmPreTrainedModel:()=>cs,EuroBertForMaskedLM:()=>Lf,EuroBertForSequenceClassification:()=>Nf,EuroBertForTokenClassification:()=>Ff,EuroBertModel:()=>Pf,EuroBertPreTrainedModel:()=>ps,ExaoneForCausalLM:()=>Rf,ExaoneModel:()=>$f,ExaonePreTrainedModel:()=>Tn,FalconForCausalLM:()=>jf,FalconH1ForCausalLM:()=>qf,FalconH1Model:()=>Bf,FalconH1PreTrainedModel:()=>Pn,FalconModel:()=>Df,FalconPreTrainedModel:()=>Cn,FastViTForImageClassification:()=>Gf,FastViTModel:()=>Uf,FastViTPreTrainedModel:()=>Ln,Florence2ForConditionalGeneration:()=>Wf,Florence2PreTrainedModel:()=>ml,GLPNForDepthEstimation:()=>nm,GLPNModel:()=>rm,GLPNPreTrainedModel:()=>Bn,GPT2LMHeadModel:()=>fm,GPT2Model:()=>dm,GPT2PreTrainedModel:()=>Vn,GPTBigCodeForCausalLM:()=>im,GPTBigCodeModel:()=>om,GPTBigCodePreTrainedModel:()=>qn,GPTJForCausalLM:()=>hm,GPTJModel:()=>mm,GPTJPreTrainedModel:()=>Hn,GPTNeoForCausalLM:()=>lm,GPTNeoModel:()=>am,GPTNeoPreTrainedModel:()=>Un,GPTNeoXForCausalLM:()=>pm,GPTNeoXModel:()=>cm,GPTNeoXPreTrainedModel:()=>Gn,Gemma2ForCausalLM:()=>Xf,Gemma2Model:()=>Kf,Gemma2PreTrainedModel:()=>Fn,Gemma3ForCausalLM:()=>Yf,Gemma3Model:()=>Qf,Gemma3PreTrainedModel:()=>$n,Gemma3nForCausalLM:()=>Rn,Gemma3nForConditionalGeneration:()=>rr,Gemma3nPreTrainedModel:()=>hl,GemmaForCausalLM:()=>Hf,GemmaModel:()=>Vf,GemmaPreTrainedModel:()=>Nn,GlmForCausalLM:()=>Zf,GlmModel:()=>Jf,GlmMoeDsaForCausalLM:()=>tm,GlmMoeDsaModel:()=>em,GlmMoeDsaPreTrainedModel:()=>jn,GlmOcrForConditionalGeneration:()=>sm,GlmPreTrainedModel:()=>Dn,GptOssForCausalLM:()=>_m,GptOssModel:()=>um,GptOssPreTrainedModel:()=>Wn,GraniteForCausalLM:()=>xm,GraniteModel:()=>gm,GraniteMoeHybridForCausalLM:()=>ym,GraniteMoeHybridModel:()=>wm,GraniteMoeHybridPreTrainedModel:()=>Xn,GranitePreTrainedModel:()=>Kn,GraniteSpeechForConditionalGeneration:()=>bm,GroundingDinoForObjectDetection:()=>km,GroundingDinoPreTrainedModel:()=>wl,GroupViTModel:()=>vm,GroupViTPreTrainedModel:()=>yl,HeliumForCausalLM:()=>Am,HeliumModel:()=>Em,HeliumPreTrainedModel:()=>Qn,HieraForImageClassification:()=>Sm,HieraModel:()=>Mm,HieraPreTrainedModel:()=>Yn,HubertForCTC:()=>Lm,HubertForSequenceClassification:()=>Nm,HubertModel:()=>Pm,HubertPreTrainedModel:()=>Cm,HunYuanDenseV1ForCausalLM:()=>$m,HunYuanDenseV1Model:()=>Fm,HunYuanDenseV1PreTrainedModel:()=>Jn,IJepaForImageClassification:()=>qm,IJepaModel:()=>Bm,IJepaPreTrainedModel:()=>Zn,Idefics3ForConditionalGeneration:()=>jm,JAISLMHeadModel:()=>Gm,JAISModel:()=>Um,JAISPreTrainedModel:()=>eo,JinaCLIPModel:()=>Wm,JinaCLIPPreTrainedModel:()=>or,JinaCLIPTextModel:()=>to,JinaCLIPVisionModel:()=>Vm,Lfm2ForCausalLM:()=>Km,Lfm2Model:()=>Hm,Lfm2MoeForCausalLM:()=>Ym,Lfm2MoeModel:()=>Qm,Lfm2MoePreTrainedModel:()=>ro,Lfm2PreTrainedModel:()=>so,Lfm2VlForConditionalGeneration:()=>Jm,LightOnOcrForConditionalGeneration:()=>Xm,LiteWhisperForConditionalGeneration:()=>jw,Llama4ForCausalLM:()=>th,Llama4PreTrainedModel:()=>kl,LlamaForCausalLM:()=>eh,LlamaModel:()=>Zm,LlamaPreTrainedModel:()=>no,LlavaForConditionalGeneration:()=>Ge,LlavaOnevisionForConditionalGeneration:()=>Ge,LlavaPreTrainedModel:()=>bl,LlavaQwen2ForCausalLM:()=>Dm,LongT5ForConditionalGeneration:()=>rh,LongT5Model:()=>sh,LongT5PreTrainedModel:()=>oo,M2M100ForConditionalGeneration:()=>oh,M2M100Model:()=>nh,M2M100PreTrainedModel:()=>io,MBartForCausalLM:()=>dh,MBartForConditionalGeneration:()=>uh,MBartForSequenceClassification:()=>_h,MBartModel:()=>ph,MBartPreTrainedModel:()=>ms,MPNetForMaskedLM:()=>Zh,MPNetForQuestionAnswering:()=>sg,MPNetForSequenceClassification:()=>eg,MPNetForTokenClassification:()=>tg,MPNetModel:()=>Jh,MPNetPreTrainedModel:()=>qt,MT5ForConditionalGeneration:()=>ig,MT5Model:()=>og,MT5PreTrainedModel:()=>yo,MarianMTModel:()=>ah,MarianModel:()=>ih,MarianPreTrainedModel:()=>ao,MaskFormerForInstanceSegmentation:()=>ch,MaskFormerModel:()=>lh,MaskFormerPreTrainedModel:()=>lo,Metric3DForDepthEstimation:()=>fh,Metric3DPreTrainedModel:()=>vl,Metric3Dv2ForDepthEstimation:()=>mh,Metric3Dv2PreTrainedModel:()=>El,MgpstrForSceneTextRecognition:()=>hh,MgpstrModelOutput:()=>Al,MgpstrPreTrainedModel:()=>Ml,MimiDecoderModel:()=>po,MimiDecoderOutput:()=>Ol,MimiEncoderModel:()=>co,MimiEncoderOutput:()=>Sl,MimiModel:()=>gh,MimiPreTrainedModel:()=>ir,Mistral4ForCausalLM:()=>bh,Mistral4Model:()=>yh,Mistral4PreTrainedModel:()=>_o,MistralForCausalLM:()=>wh,MistralModel:()=>xh,MistralPreTrainedModel:()=>uo,MobileBertForMaskedLM:()=>vh,MobileBertForQuestionAnswering:()=>Ah,MobileBertForSequenceClassification:()=>Eh,MobileBertModel:()=>kh,MobileBertPreTrainedModel:()=>hs,MobileLLMForCausalLM:()=>Sh,MobileLLMModel:()=>Mh,MobileLLMPreTrainedModel:()=>fo,MobileNetV1ForImageClassification:()=>Ih,MobileNetV1ForSemanticSegmentation:()=>zh,MobileNetV1Model:()=>Oh,MobileNetV1PreTrainedModel:()=>ar,MobileNetV2ForImageClassification:()=>Ch,MobileNetV2ForSemanticSegmentation:()=>Ph,MobileNetV2Model:()=>Th,MobileNetV2PreTrainedModel:()=>lr,MobileNetV3ForImageClassification:()=>Nh,MobileNetV3ForSemanticSegmentation:()=>Fh,MobileNetV3Model:()=>Lh,MobileNetV3PreTrainedModel:()=>cr,MobileNetV4ForImageClassification:()=>Rh,MobileNetV4ForSemanticSegmentation:()=>Dh,MobileNetV4Model:()=>$h,MobileNetV4PreTrainedModel:()=>pr,MobileViTForImageClassification:()=>Bh,MobileViTModel:()=>jh,MobileViTPreTrainedModel:()=>mo,MobileViTV2ForImageClassification:()=>Uh,MobileViTV2Model:()=>qh,MobileViTV2PreTrainedModel:()=>ho,ModernBertDecoderForCausalLM:()=>Xh,ModernBertDecoderModel:()=>Kh,ModernBertDecoderPreTrainedModel:()=>go,ModernBertForMaskedLM:()=>Wh,ModernBertForSequenceClassification:()=>Vh,ModernBertForTokenClassification:()=>Hh,ModernBertModel:()=>Gh,ModernBertPreTrainedModel:()=>gs,Moondream1ForConditionalGeneration:()=>Rm,MoonshineForConditionalGeneration:()=>Yh,MoonshineModel:()=>Qh,MoonshinePreTrainedModel:()=>xo,MptForCausalLM:()=>ng,MptModel:()=>rg,MptPreTrainedModel:()=>wo,MultiModalityCausalLM:()=>ag,MultiModalityPreTrainedModel:()=>Il,MusicgenForCausalLM:()=>cg,MusicgenForConditionalGeneration:()=>ko,MusicgenModel:()=>lg,MusicgenPreTrainedModel:()=>bo,NanoChatForCausalLM:()=>ug,NanoChatModel:()=>pg,NanoChatPreTrainedModel:()=>vo,NemotronHForCausalLM:()=>dg,NemotronHModel:()=>_g,NemotronHPreTrainedModel:()=>Eo,NeoBertForMaskedLM:()=>mg,NeoBertForQuestionAnswering:()=>xg,NeoBertForSequenceClassification:()=>hg,NeoBertForTokenClassification:()=>gg,NeoBertModel:()=>fg,NeoBertPreTrainedModel:()=>Ut,NomicBertModel:()=>wg,NomicBertPreTrainedModel:()=>zl,OPTForCausalLM:()=>Tg,OPTModel:()=>zg,OPTPreTrainedModel:()=>zo,Olmo2ForCausalLM:()=>vg,Olmo2Model:()=>kg,Olmo2PreTrainedModel:()=>Mo,Olmo3ForCausalLM:()=>Ag,Olmo3Model:()=>Eg,Olmo3PreTrainedModel:()=>So,OlmoForCausalLM:()=>bg,OlmoHybridForCausalLM:()=>Sg,OlmoHybridModel:()=>Mg,OlmoHybridPreTrainedModel:()=>Oo,OlmoModel:()=>yg,OlmoPreTrainedModel:()=>Ao,OpenELMForCausalLM:()=>Ig,OpenELMModel:()=>Og,OpenELMPreTrainedModel:()=>Io,OwlViTForObjectDetection:()=>Ng,OwlViTModel:()=>Lg,OwlViTPreTrainedModel:()=>Co,Owlv2ForObjectDetection:()=>Pg,Owlv2Model:()=>Cg,Owlv2PreTrainedModel:()=>To,PaliGemmaForConditionalGeneration:()=>Fg,ParakeetForCTC:()=>$g,ParakeetPreTrainedModel:()=>Tl,PatchTSMixerForPrediction:()=>Dg,PatchTSMixerModel:()=>Rg,PatchTSMixerPreTrainedModel:()=>Po,PatchTSTForPrediction:()=>Bg,PatchTSTModel:()=>jg,PatchTSTPreTrainedModel:()=>Lo,Phi3ForCausalLM:()=>Wg,Phi3Model:()=>Gg,Phi3PreTrainedModel:()=>Fo,Phi3VForCausalLM:()=>$o,Phi3VPreTrainedModel:()=>Cl,PhiForCausalLM:()=>Ug,PhiModel:()=>qg,PhiPreTrainedModel:()=>No,PreTrainedModel:()=>f,PvtForImageClassification:()=>Hg,PvtModel:()=>Vg,PvtPreTrainedModel:()=>Ro,PyAnnoteForAudioFrameClassification:()=>Xg,PyAnnoteModel:()=>Kg,PyAnnotePreTrainedModel:()=>Do,Qwen2ForCausalLM:()=>Yg,Qwen2Model:()=>Qg,Qwen2MoeForCausalLM:()=>Zg,Qwen2MoeModel:()=>Jg,Qwen2MoePreTrainedModel:()=>Bo,Qwen2PreTrainedModel:()=>jo,Qwen2VLForCausalLM:()=>us,Qwen2VLForConditionalGeneration:()=>nr,Qwen2VLPreTrainedModel:()=>gl,Qwen2_5_VLForCausalLM:()=>ds,Qwen2_5_VLForConditionalGeneration:()=>_s,Qwen3ForCausalLM:()=>tx,Qwen3Model:()=>ex,Qwen3MoeForCausalLM:()=>rx,Qwen3MoeModel:()=>sx,Qwen3MoePreTrainedModel:()=>Uo,Qwen3NextForCausalLM:()=>ox,Qwen3NextModel:()=>nx,Qwen3NextPreTrainedModel:()=>Go,Qwen3PreTrainedModel:()=>qo,Qwen3VLForCausalLM:()=>ws,Qwen3VLForConditionalGeneration:()=>xs,Qwen3VLMoeForCausalLM:()=>Wo,Qwen3VLMoeForConditionalGeneration:()=>ix,Qwen3_5ForCausalLM:()=>ys,Qwen3_5ForConditionalGeneration:()=>ur,Qwen3_5MoeForCausalLM:()=>Vo,Qwen3_5MoeForConditionalGeneration:()=>ax,RFDetrForObjectDetection:()=>ux,RFDetrModel:()=>px,RFDetrObjectDetectionOutput:()=>Pl,RFDetrPreTrainedModel:()=>Ko,RTDetrForObjectDetection:()=>Nd,RTDetrModel:()=>Ld,RTDetrObjectDetectionOutput:()=>ht,RTDetrPreTrainedModel:()=>yn,RTDetrV2ForObjectDetection:()=>vx,RTDetrV2Model:()=>kx,RTDetrV2ObjectDetectionOutput:()=>Ll,RTDetrV2PreTrainedModel:()=>Xo,ResNetForImageClassification:()=>cx,ResNetModel:()=>lx,ResNetPreTrainedModel:()=>Ho,RoFormerForMaskedLM:()=>xx,RoFormerForQuestionAnswering:()=>bx,RoFormerForSequenceClassification:()=>wx,RoFormerForTokenClassification:()=>yx,RoFormerModel:()=>gx,RoFormerPreTrainedModel:()=>Wt,RobertaForMaskedLM:()=>dx,RobertaForQuestionAnswering:()=>hx,RobertaForSequenceClassification:()=>fx,RobertaForTokenClassification:()=>mx,RobertaModel:()=>_x,RobertaPreTrainedModel:()=>Gt,Sam2ImageSegmentationOutput:()=>$l,Sam2Model:()=>Qo,Sam2PreTrainedModel:()=>Rl,Sam3TrackerModel:()=>Mx,SamImageSegmentationOutput:()=>Nl,SamModel:()=>Ex,SamPreTrainedModel:()=>Fl,SapiensForDepthEstimation:()=>Ox,SapiensForNormalEstimation:()=>Ix,SapiensForSemanticSegmentation:()=>Sx,SapiensPreTrainedModel:()=>_r,SegformerForImageClassification:()=>Tx,SegformerForSemanticSegmentation:()=>Cx,SegformerModel:()=>zx,SegformerPreTrainedModel:()=>dr,SiglipModel:()=>Px,SiglipPreTrainedModel:()=>Yo,SiglipTextModel:()=>Jo,SiglipVisionModel:()=>Lx,SmolLM3ForCausalLM:()=>Fx,SmolLM3Model:()=>Nx,SmolLM3PreTrainedModel:()=>Zo,SnacDecoderModel:()=>ti,SnacEncoderModel:()=>ei,SnacModel:()=>$x,SnacPreTrainedModel:()=>fr,SolarOpenForCausalLM:()=>Dx,SolarOpenModel:()=>Rx,SolarOpenPreTrainedModel:()=>si,SpeechT5ForSpeechToText:()=>Bx,SpeechT5ForTextToSpeech:()=>qx,SpeechT5HifiGan:()=>Ux,SpeechT5Model:()=>jx,SpeechT5PreTrainedModel:()=>mr,SqueezeBertForMaskedLM:()=>Wx,SqueezeBertForQuestionAnswering:()=>Hx,SqueezeBertForSequenceClassification:()=>Vx,SqueezeBertModel:()=>Gx,SqueezeBertPreTrainedModel:()=>bs,StableLmForCausalLM:()=>Xx,StableLmModel:()=>Kx,StableLmPreTrainedModel:()=>ri,Starcoder2ForCausalLM:()=>Yx,Starcoder2Model:()=>Qx,Starcoder2PreTrainedModel:()=>ni,StyleTextToSpeech2Model:()=>Jx,StyleTextToSpeech2PreTrainedModel:()=>Dl,SupertonicForConditionalGeneration:()=>oi,SupertonicPreTrainedModel:()=>jl,Swin2SRForImageSuperResolution:()=>rw,Swin2SRModel:()=>sw,Swin2SRPreTrainedModel:()=>ii,SwinForImageClassification:()=>ew,SwinForSemanticSegmentation:()=>tw,SwinModel:()=>Zx,SwinPreTrainedModel:()=>hr,T5ForConditionalGeneration:()=>ow,T5Model:()=>nw,T5PreTrainedModel:()=>ai,TableTransformerForObjectDetection:()=>aw,TableTransformerModel:()=>iw,TableTransformerObjectDetectionOutput:()=>Bl,TableTransformerPreTrainedModel:()=>li,TrOCRForCausalLM:()=>lw,TrOCRPreTrainedModel:()=>ql,UltravoxModel:()=>fs,UltravoxPreTrainedModel:()=>xl,UniSpeechForCTC:()=>pw,UniSpeechForSequenceClassification:()=>uw,UniSpeechModel:()=>cw,UniSpeechPreTrainedModel:()=>gr,UniSpeechSatForAudioFrameClassification:()=>mw,UniSpeechSatForCTC:()=>dw,UniSpeechSatForSequenceClassification:()=>fw,UniSpeechSatModel:()=>_w,UniSpeechSatPreTrainedModel:()=>ks,VaultGemmaForCausalLM:()=>gw,VaultGemmaModel:()=>hw,VaultGemmaPreTrainedModel:()=>ci,ViTForImageClassification:()=>yw,ViTMAEModel:()=>bw,ViTMAEPreTrainedModel:()=>Ul,ViTMSNForImageClassification:()=>vw,ViTMSNModel:()=>kw,ViTMSNPreTrainedModel:()=>ui,ViTModel:()=>ww,ViTPreTrainedModel:()=>pi,VisionEncoderDecoderModel:()=>xw,VitMatteForImageMatting:()=>Ew,VitMattePreTrainedModel:()=>Gl,VitPoseForPoseEstimation:()=>Aw,VitPosePreTrainedModel:()=>Wl,VitsModel:()=>Mw,VitsModelOutput:()=>Vl,VitsPreTrainedModel:()=>Hl,VoxtralForConditionalGeneration:()=>Sw,VoxtralRealtimeForConditionalGeneration:()=>_i,VoxtralRealtimePreTrainedModel:()=>Kl,Wav2Vec2BertForCTC:()=>Tw,Wav2Vec2BertForSequenceClassification:()=>Cw,Wav2Vec2BertModel:()=>zw,Wav2Vec2BertPreTrainedModel:()=>xr,Wav2Vec2ForAudioFrameClassification:()=>Tm,Wav2Vec2ForCTC:()=>Im,Wav2Vec2ForSequenceClassification:()=>zm,Wav2Vec2Model:()=>Om,Wav2Vec2PreTrainedModel:()=>ct,WavLMForAudioFrameClassification:()=>$w,WavLMForCTC:()=>Lw,WavLMForSequenceClassification:()=>Nw,WavLMForXVector:()=>Fw,WavLMModel:()=>Pw,WavLMPreTrainedModel:()=>Vt,WeSpeakerResNetModel:()=>Rw,WeSpeakerResNetPreTrainedModel:()=>Ql,WhisperForConditionalGeneration:()=>Jl,WhisperModel:()=>Dw,WhisperPreTrainedModel:()=>di,XLMForQuestionAnswering:()=>Ww,XLMForSequenceClassification:()=>Uw,XLMForTokenClassification:()=>Gw,XLMModel:()=>Bw,XLMPreTrainedModel:()=>Ht,XLMRobertaForMaskedLM:()=>Hw,XLMRobertaForQuestionAnswering:()=>Qw,XLMRobertaForSequenceClassification:()=>Kw,XLMRobertaForTokenClassification:()=>Xw,XLMRobertaModel:()=>Vw,XLMRobertaPreTrainedModel:()=>Kt,XLMWithLMHeadModel:()=>qw,XVectorOutput:()=>Xl,YolosForObjectDetection:()=>Jw,YolosModel:()=>Yw,YolosObjectDetectionOutput:()=>Zl,YolosPreTrainedModel:()=>fi,YoutuForCausalLM:()=>ey,YoutuModel:()=>Zw,YoutuPreTrainedModel:()=>mi});var ls=class extends f{},T_=class extends ls{},C_=class extends ls{async _call(e){return new I(await super._call(e))}},P_=class extends ls{async _call(e){return new le(await super._call(e))}},L_=class extends ls{async _call(e){return new re(await super._call(e))}};var tn=class extends f{},N_=class extends tn{},F_=class extends tn{};var sn=class extends f{},$_=class extends sn{},R_=class extends sn{};var rn=class extends f{},D_=class extends rn{},j_=class extends rn{};var nn=class extends f{},B_=class extends nn{},q_=class extends nn{};var Js=class extends f{},U_=class extends Js{},G_=class extends Js{},W_=class extends Js{async _call(e){return new I(await super._call(e))}};var on=class extends f{},V_=class extends on{},H_=class extends on{async _call(e){return new I(await super._call(e))}};var Nt=class extends f{},K_=class extends Nt{},X_=class extends Nt{async _call(e){return new re(await super._call(e))}},Q_=class extends Nt{async _call(e){return new I(await super._call(e))}},Y_=class extends Nt{async _call(e){return new ee(await super._call(e))}},J_=class extends Nt{async _call(e){return new le(await super._call(e))}};var an=class extends f{},Z_=class extends an{},ed=class extends an{};var ln=class extends f{},td=class extends ln{},sd=class extends ln{};var cn=class extends f{},rd=class extends cn{},nd=class extends cn{};var Ft=class extends f{},od=class extends Ft{},id=class extends Ft{async _call(e){return new re(await super._call(e))}},ad=class extends Ft{async _call(e){return new I(await super._call(e))}},ld=class extends Ft{async _call(e){return new ee(await super._call(e))}},cd=class extends Ft{async _call(e){return new le(await super._call(e))}};var LA=4299n,ab=6561n,rl=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"]},pn=class extends rl{async encode_speech(e){return X(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:p=null,audio_tokens:u=null,speaker_embeddings:_=null,speaker_features:d=null,...m}){let h;if(!i){let x=this.sessions.embed_tokens.inputNames,w={input_ids:e};if(x.includes("exaggeration")){if(!(n instanceof v)){let y=e.dims[0];if(n==null)n=ye([y],.5);else if(typeof n=="number")n=ye([y],n);else if(Array.isArray(n))n=new v("float32",n,[y]);else throw new Error("Unsupported type for `exaggeration` input")}w.exaggeration=n}if(x.includes("position_ids")&&(w.position_ids=o),{inputs_embeds:i}=await X(this.sessions.embed_tokens,w),p&&u&&_&&d&&(h={audio_features:p,audio_tokens:u,speaker_embeddings:_,speaker_features:d}),h||r)h??=await this.encode_speech(r),i=ie([h.audio_features,i],1),s=Se([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=a.get_seq_length();s=Se([i.dims[0],b+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==ab)-1);s.position_ids=new v("int64",n,[e.length,1])}else{let o=s.input_ids.tolist().map(i=>{let a=0;return i.map(l=>l>=ab?0:a++)});s.position_ids=new v("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),Qs(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=ye([i.dims[0],3],LA),l=ie([r,i,a],1),{waveform:c}=await X(this.sessions.conditional_decoder,{speech_tokens:l,speaker_features:o,speaker_embeddings:n});return c}};var nl=class extends f{},pd=class extends nl{};var ol=class extends f{},ud=class extends ol{};var Zs=class extends f{},_d=class extends Zs{},un=class extends Zs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},_n=class extends Zs{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"audio_model"})}};var mt=class extends f{},dd=class extends mt{},fd=class extends mt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},dn=class extends mt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},md=class extends mt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}},hd=class extends mt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var fn=class extends f{},gd=class extends fn{},xd=class extends fn{};var mn=class extends f{},wd=class extends mn{},yd=class extends mn{};var hn=class extends f{},bd=class extends hn{},kd=class extends hn{};var gn=class extends f{},vd=class extends gn{},Ed=class extends gn{};var $t=class extends f{},Ad=class extends $t{},Md=class extends $t{async _call(e){return new re(await super._call(e))}},Sd=class extends $t{async _call(e){return new I(await super._call(e))}},Od=class extends $t{async _call(e){return new ee(await super._call(e))}},Id=class extends $t{async _call(e){return new le(await super._call(e))}};var xn=class extends f{},zd=class extends xn{},Td=class extends xn{async _call(e){return new I(await super._call(e))}};var wn=class extends f{},Cd=class extends wn{},Pd=class extends wn{async _call(e){return new I(await super._call(e))}};var yn=class extends f{},Ld=class extends yn{},Nd=class extends yn{async _call(e){return new ht(await super._call(e))}},ht=class extends fe{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}};var bn=class extends f{},Fd=class extends bn{},$d=class extends bn{async _call(e){return new ht(await super._call(e))}};var il=class extends fe{constructor({audio_codes:e}){super(),this.audio_codes=e}},al=class extends fe{constructor({audio_values:e}){super(),this.audio_values=e}},er=class extends f{main_input_name="input_values";forward_params=["input_values"]},Rd=class extends er{async encode(e){return new il(await X(this.sessions.encoder_model,e))}async decode(e){return new al(await X(this.sessions.decoder_model,e))}},kn=class extends er{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},vn=class extends er{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var Rt=class extends f{},Dd=class extends Rt{},jd=class extends Rt{async _call(e){return new re(await super._call(e))}},Bd=class extends Rt{async _call(e){return new I(await super._call(e))}},qd=class extends Rt{async _call(e){return new ee(await super._call(e))}},Ud=class extends Rt{async _call(e){return new le(await super._call(e))}};var En=class extends f{},Gd=class extends En{},Wd=class extends En{};var Dt=class extends f{},Vd=class extends Dt{},Hd=class extends Dt{async _call(e){return new re(await super._call(e))}},Kd=class extends Dt{async _call(e){return new I(await super._call(e))}},Xd=class extends Dt{async _call(e){return new ee(await super._call(e))}},Qd=class extends Dt{async _call(e){return new le(await super._call(e))}};var ll=class extends f{},Yd=class extends ll{};var An=class extends f{},Jd=class extends An{},Zd=class extends An{async _call(e){return new I(await super._call(e))}};var cl=class extends f{},ef=class extends cl{};var pl=class extends f{},tf=class extends pl{};var tr=class extends f{},sf=class extends tr{},rf=class extends tr{async _call(e){return new sr(await super._call(e))}},nf=class extends tr{async _call(e){return new ul(await super._call(e))}},sr=class extends fe{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}},ul=class extends fe{constructor({logits:e,pred_boxes:s,pred_masks:r}){super(),this.logits=e,this.pred_boxes=s,this.pred_masks=r}};var Mn=class extends f{},of=class extends Mn{},af=class extends Mn{async _call(e){return new I(await super._call(e))}};var Sn=class extends f{},lf=class extends Sn{},cf=class extends Sn{async _call(e){return new I(await super._call(e))}};var _l=class extends f{},pf=class extends _l{};var dl=class extends f{},uf=class extends dl{};var jt=class extends f{},_f=class extends jt{},df=class extends jt{async _call(e){return new I(await super._call(e))}},ff=class extends jt{async _call(e){return new ee(await super._call(e))}},mf=class extends jt{async _call(e){return new le(await super._call(e))}},hf=class extends jt{async _call(e){return new re(await super._call(e))}};var fl=class extends f{},gf=class extends fl{};var On=class extends f{},xf=class extends On{},wf=class extends On{};var In=class extends f{},yf=class extends In{},bf=class extends In{async _call(e){return new I(await super._call(e))}};var Bt=class extends f{},kf=class extends Bt{},vf=class extends Bt{async _call(e){return new re(await super._call(e))}},Ef=class extends Bt{async _call(e){return new I(await super._call(e))}},Af=class extends Bt{async _call(e){return new ee(await super._call(e))}},Mf=class extends Bt{async _call(e){return new le(await super._call(e))}};var zn=class extends f{},Sf=class extends zn{},Of=class extends zn{};var cs=class extends f{},If=class extends cs{},zf=class extends cs{async _call(e){return new re(await super._call(e))}},Tf=class extends cs{async _call(e){return new I(await super._call(e))}},Cf=class extends cs{async _call(e){return new ee(await super._call(e))}};var ps=class extends f{},Pf=class extends ps{},Lf=class extends ps{async _call(e){return new re(await super._call(e))}},Nf=class extends ps{async _call(e){return new I(await super._call(e))}},Ff=class extends ps{async _call(e){return new ee(await super._call(e))}};var Tn=class extends f{},$f=class extends Tn{},Rf=class extends Tn{};var Cn=class extends f{},Df=class extends Cn{},jf=class extends Cn{};var Pn=class extends f{},Bf=class extends Pn{},qf=class extends Pn{};var Ln=class extends f{},Uf=class extends Ln{},Gf=class extends Ln{async _call(e){return new I(await super._call(e))}};var ml=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"},Wf=class extends ml{_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([Se(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:u}=await tt(this,{inputs_embeds:l,attention_mask:r});i=u}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{},Vf=class extends Nn{},Hf=class extends Nn{};var Fn=class extends f{},Kf=class extends Fn{},Xf=class extends Fn{};var $n=class extends f{},Qf=class extends $n{},Yf=class extends $n{};var hl=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"]},rr=class extends hl{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:p=null,logits_processor:u=null,..._}){if((!a||!l)&&({inputs_embeds:a,per_layer_inputs:l}=await X(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(r){let{image_features:m}=await X(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 X(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:p,logits_processor:u},!0)}_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return Ys({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 sl({audio_token_id:this.config.audio_token_id,...e,audio_features:r})}},Rn=class extends rr{};var Dn=class extends f{},Jf=class extends Dn{},Zf=class extends Dn{};var jn=class extends f{},em=class extends jn{},tm=class extends jn{};var gl=class extends f{forward_params=["input_ids","attention_mask","position_ids","past_key_values","pixel_values","image_grid_thw"]},nr=class extends gl{image_grid_thw_name="grid_thw";_get_text_only_rope_index(e,s){if(s){let{data:r,dims:n}=z_(s),o=BigInt64Array.from({length:3*r.length},(a,l)=>r[l%r.length]),i=Array.from({length:n[0]},(a,l)=>pe(r.subarray(n[1]*l,n[1]*(l+1)))[0]+1n+BigInt(n[1]));return[new v("int64",o,[3,...n]),new v("int64",i,[i.length,1])]}else{let[r,n]=e.dims,o=BigInt64Array.from({length:3*r*n},(i,a)=>BigInt(Math.floor(a%n/r)));return[new v("int64",o,[3,...e.dims]),Kc([r,1])]}}_reorder_and_write_positions(e,s,r,n){let o=e.reduce((c,p)=>c+p.length,0),i=new Array(o),a=0;for(let c=0;c<3;++c)for(let p of e){let u=p.length/3;for(let _=c*u;_<(c+1)*u;++_)i[a++]=p[_]}let l=0;for(let c=0;c<s.length;++c)if(s[c]==1){for(let p=0;p<3;++p)r[p][n][c]=i[p*o/3+l];++l}return i}_get_multimodal_rope_positions({filtered_ids:e,image_grid_thw_list:s,video_grid_thw_list:r,spatial_merge_size:n,state:o}){let{image_token_id:i,video_token_id:a,vision_start_token_id:l}=this.config,c=e,u=c.reduce((w,y,b)=>(y==l&&w.push(b),w),[]).map(w=>c[w+1]),_=u.filter(w=>w==i).length,d=u.filter(w=>w==a).length,m=[],h=0,g=_,x=d;for(let w=0;w<u.length;++w){let y=c.findIndex((H,he)=>he>h&&H==i),b=c.findIndex((H,he)=>he>h&&H==a),E=g>0&&y!==-1?y:c.length+1,k=x>0&&b!==-1?b:c.length+1,O,N,j,C;E<k?([N,j,C]=s[o.image_index],++o.image_index,--g,O=E):([N,j,C]=r[o.video_index],++o.video_index,--x,O=k);let[R,$,q]=[Number(N),Math.floor(Number(j)/n),Math.floor(Number(C)/n)],B=O-h,G=m.length>0?pe(m.at(-1))[0]+1:0;m.push(Array.from({length:3*B},(H,he)=>G+he%B));let Z=B+G,te=R*$*q,M=Array.from({length:te},(H,he)=>Z+Math.floor(he/($*q))),S=Array.from({length:te},(H,he)=>Z+Math.floor(he/q)%$),z=Array.from({length:te},(H,he)=>Z+he%q);m.push([M,S,z].flat()),h=O+te}if(h<c.length){let w=m.length>0?pe(m.at(-1))[0]+1:0,y=c.length-h;m.push(Array.from({length:3*y},(b,E)=>w+E%y))}return m}get_rope_index(e,s,r,n){let{vision_config:o}=this.config,i=o.spatial_merge_size??2;if(s||r){let a=e.tolist();n||(n=da(e));let l=n.tolist(),c=Array.from({length:3},()=>Array.from({length:e.dims[0]},()=>Array.from({length:e.dims[1]},()=>0))),p=s?s.tolist():[],u=r?r.tolist():[],_={image_index:0,video_index:0},d=[];for(let m=0;m<a.length;++m){let h=a[m].filter((w,y)=>l[m][y]==1),g=this._get_multimodal_rope_positions({filtered_ids:h,image_grid_thw_list:p,video_grid_thw_list:u,spatial_merge_size:i,state:_}),x=this._reorder_and_write_positions(g,l[m],c,m);d.push(pe(x)[0]+1-a[m].length)}return[new v("int64",c.flat(1/0),[3,e.dims[0],e.dims[1]]),new v("int64",d,[d.length,1])]}else return this._get_text_only_rope_index(e,n)}async encode_image({pixel_values:e,image_grid_thw:s}){return(await X(this.sessions.vision_encoder,{pixel_values:e,[this.image_grid_thw_name]:s})).image_features}_merge_input_ids_with_image_features(e){return Ys({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=s.past_key_values.get_seq_length();if(n<s.input_ids.dims[1]){let[o,i]=this.get_rope_index(s.input_ids,s.image_grid_thw,s.video_grid_thw,s.attention_mask);s.rope_deltas=i,s.position_ids=o.slice(null,null,[n,null]),s.input_ids=s.input_ids.slice(null,[n,null])}else{s.rope_deltas||([,s.rope_deltas]=this.get_rope_index(s.input_ids,s.image_grid_thw,s.video_grid_thw,s.attention_mask));let o=BigInt(n),i=s.rope_deltas.map(a=>o+a);s.position_ids=qe([i,i,i],0)}}return s}},us=class extends nr{};var _s=class extends nr{image_grid_thw_name="image_grid_thw"},ds=class extends us{image_grid_thw_name="image_grid_thw"};var sm=class extends _s{get_vision_position_ids(e,s,r,n){let o=Math.floor(s[0]/r),i=Math.floor(s[1]/n),a=Math.floor(s[2]/n),l=i*a*o,c=Array.from({length:l},()=>e),p=Array.from({length:l},(_,d)=>e+Math.floor(d/(a*o))),u=Array.from({length:l},(_,d)=>e+d%a);return[...c,...p,...u]}_get_multimodal_rope_positions({filtered_ids:e,image_grid_thw_list:s,video_grid_thw_list:r,spatial_merge_size:n,state:o}){let{image_token_id:i}=this.config,a=[],l=0,c=e[0]==i?1:0;for(let _=1;_<=e.length;++_){let d=_<e.length?e[_]==i?1:0:-1;d!==c&&(a.push([c,l,_]),l=_,c=d)}let p=0,u=[];for(let[_,d,m]of a)if(_===0){let h=m-d;u.push(Array.from({length:3*h},(g,x)=>p+x%h)),p+=h}else{let h=s[o.image_index++].map(Number),g=h[0];u.push(this.get_vision_position_ids(p,h,g,n)),p+=Math.max(h[1],h[2])/n}return u}};var Bn=class extends f{},rm=class extends Bn{},nm=class extends Bn{};var qn=class extends f{},om=class extends qn{},im=class extends qn{};var Un=class extends f{},am=class extends Un{},lm=class extends Un{};var Gn=class extends f{},cm=class extends Gn{},pm=class extends Gn{};var Wn=class extends f{},um=class extends Wn{},_m=class extends Wn{};var Vn=class extends f{},dm=class extends Vn{},fm=class extends Vn{};var Hn=class extends f{},mm=class extends Hn{},hm=class extends Hn{};var Kn=class extends f{},gm=class extends Kn{},xm=class extends Kn{};var Xn=class extends f{},wm=class extends Xn{},ym=class extends Xn{};var xl=class extends f{forward_params=["input_ids","attention_mask","position_ids","audio_values","past_key_values"]},fs=class extends xl{_merge_input_ids_with_audio_features(e){let s=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,s);return sl({audio_token_id:this.config.ignore_index??this.config.audio_token_id??this.config.audio_token_index,...e,audio_features:r})}};var bm=class extends fs{forward_params=["input_ids","attention_mask","input_features","past_key_values"]};var wl=class extends f{},km=class extends wl{};var yl=class extends f{},vm=class extends yl{};var Qn=class extends f{},Em=class extends Qn{},Am=class extends Qn{};var Yn=class extends f{},Mm=class extends Yn{},Sm=class extends Yn{async _call(e){return new I(await super._call(e))}};var ct=class extends f{},Om=class extends ct{},Im=class extends ct{async _call(e){return new je(await super._call(e))}},zm=class extends ct{async _call(e){return new I(await super._call(e))}},Tm=class extends ct{async _call(e){return new ee(await super._call(e))}};var Cm=class extends f{},Pm=class extends ct{},Lm=class extends ct{async _call(e){return new je(await super._call(e))}},Nm=class extends ct{async _call(e){return new I(await super._call(e))}};var Jn=class extends f{},Fm=class extends Jn{},$m=class extends Jn{};var bl=class extends f{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},Ge=class extends bl{_merge_input_ids_with_image_features(e){let s=e.image_features.dims.at(-1),r=e.image_features.view(-1,s);return Ys({image_token_id:this.config.image_token_index??this.config.image_token_id,...e,image_features:r})}},Rm=class extends Ge{},Dm=class extends Ge{};var jm=class extends Ge{forward_params=["input_ids","attention_mask","pixel_values","pixel_attention_mask","position_ids","past_key_values"]};var Zn=class extends f{},Bm=class extends Zn{},qm=class extends Zn{async _call(e){return new I(await super._call(e))}};var eo=class extends f{},Um=class extends eo{},Gm=class extends eo{};var or=class extends f{},Wm=class extends or{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=Se([e.pixel_values.dims[0],1])),r){let{image_size:c}=this.config.vision_config;e.pixel_values=ye([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}},to=class extends or{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},Vm=class extends or{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var so=class extends f{},Hm=class extends so{},Km=class extends so{};var Xm=class extends Ge{};var ro=class extends f{},Qm=class extends ro{},Ym=class extends ro{};var Jm=class extends Ge{forward_params=["input_ids","attention_mask","pixel_values","pixel_attention_mask","spatial_shapes","position_ids","past_key_values"]};var no=class extends f{},Zm=class extends no{},eh=class extends no{};var kl=class extends f{},th=class extends kl{};var oo=class extends f{},sh=class extends oo{},rh=class extends oo{};var io=class extends f{},nh=class extends io{},oh=class extends io{};var ao=class extends f{},ih=class extends ao{},ah=class extends ao{};var lo=class extends f{},lh=class extends lo{},ch=class extends lo{};var ms=class extends f{},ph=class extends ms{},uh=class extends ms{},_h=class extends ms{async _call(e){return new I(await super._call(e))}},dh=class extends ms{};var vl=class extends f{},fh=class extends vl{};var El=class extends f{},mh=class extends El{};var Al=class extends fe{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]}},Ml=class extends f{},hh=class extends Ml{async _call(e){return new Al(await super._call(e))}};var Sl=class extends fe{constructor({audio_codes:e}){super(),this.audio_codes=e}},Ol=class extends fe{constructor({audio_values:e}){super(),this.audio_values=e}},ir=class extends f{main_input_name="input_values";forward_params=["input_values"]},gh=class extends ir{async encode(e){return new Sl(await X(this.sessions.encoder_model,e))}async decode(e){return new Ol(await X(this.sessions.decoder_model,e))}},co=class extends ir{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},po=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 uo=class extends f{},xh=class extends uo{},wh=class extends uo{};var _o=class extends f{},yh=class extends _o{},bh=class extends _o{};var hs=class extends f{},kh=class extends hs{},vh=class extends hs{async _call(e){return new re(await super._call(e))}},Eh=class extends hs{async _call(e){return new I(await super._call(e))}},Ah=class extends hs{async _call(e){return new le(await super._call(e))}};var fo=class extends f{},Mh=class extends fo{},Sh=class extends fo{};var ar=class extends f{},Oh=class extends ar{},Ih=class extends ar{async _call(e){return new I(await super._call(e))}},zh=class extends ar{};var lr=class extends f{},Th=class extends lr{},Ch=class extends lr{async _call(e){return new I(await super._call(e))}},Ph=class extends lr{};var cr=class extends f{},Lh=class extends cr{},Nh=class extends cr{async _call(e){return new I(await super._call(e))}},Fh=class extends cr{};var pr=class extends f{},$h=class extends pr{},Rh=class extends pr{async _call(e){return new I(await super._call(e))}},Dh=class extends pr{};var mo=class extends f{},jh=class extends mo{},Bh=class extends mo{async _call(e){return new I(await super._call(e))}};var ho=class extends f{},qh=class extends ho{},Uh=class extends ho{async _call(e){return new I(await super._call(e))}};var gs=class extends f{},Gh=class extends gs{},Wh=class extends gs{async _call(e){return new re(await super._call(e))}},Vh=class extends gs{async _call(e){return new I(await super._call(e))}},Hh=class extends gs{async _call(e){return new ee(await super._call(e))}};var go=class extends f{},Kh=class extends go{},Xh=class extends go{};var xo=class extends f{requires_attention_mask=!1;main_input_name="input_values";forward_params=["input_values","decoder_input_ids","past_key_values"]},Qh=class extends xo{},Yh=class extends xo{};var qt=class extends f{},Jh=class extends qt{},Zh=class extends qt{async _call(e){return new re(await super._call(e))}},eg=class extends qt{async _call(e){return new I(await super._call(e))}},tg=class extends qt{async _call(e){return new ee(await super._call(e))}},sg=class extends qt{async _call(e){return new le(await super._call(e))}};var wo=class extends f{},rg=class extends wo{},ng=class extends wo{};var yo=class extends f{},og=class extends yo{},ig=class extends yo{};var Il=class extends f{},ag=class extends Il{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=ke(e,l.inputNames);r=await X(l,c)}else{let l=this.sessions.gen_img_embeds,c=ke({image_ids:e.input_ids},l.inputNames);r=await X(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 X(i,ke(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,Rr(s.input_ids,BigInt(r.pad_token_id))],0),s.attention_mask=ie([s.attention_mask,Rr(s.attention_mask,0n)],0))),(n||!s.pixel_values)&&(s.pixel_values=ye([0,0,3,384,384],1)),n&&(s.images_seq_mask=new v("bool",new Array(1).fill(!0).fill(!1,0,1),[1,1]),s.images_emb_mask=new v("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 X(o,{generated_tokens:n}),a=i.add_(1).mul_(255/2).clamp_(0,255).to("uint8"),l=[];for(let c of a){let p=ve.fromTensor(c);l.push(p)}return l}};var bo=class extends f{},lg=class extends bo{},cg=class extends bo{},ko=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 p=c%r,u=Math.floor(c/r)%n,_=p-u;_>0&&_<=o&&(e.data[i++]=e.data[c])}let a=Math.floor(s/n),l=i/(a*n);return new v(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)),en(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 X(this.sessions.encodec_decode,{audio_codes:r});return n}};var vo=class extends f{},pg=class extends vo{},ug=class extends vo{};var Eo=class extends f{},_g=class extends Eo{},dg=class extends Eo{};var Ut=class extends f{},fg=class extends Ut{},mg=class extends Ut{async _call(e){return new re(await super._call(e))}},hg=class extends Ut{async _call(e){return new I(await super._call(e))}},gg=class extends Ut{async _call(e){return new ee(await super._call(e))}},xg=class extends Ut{async _call(e){return new le(await super._call(e))}};var zl=class extends f{},wg=class extends zl{};var Ao=class extends f{},yg=class extends Ao{},bg=class extends Ao{};var Mo=class extends f{},kg=class extends Mo{},vg=class extends Mo{};var So=class extends f{},Eg=class extends So{},Ag=class extends So{};var Oo=class extends f{},Mg=class extends Oo{},Sg=class extends Oo{};var Io=class extends f{},Og=class extends Io{},Ig=class extends Io{};var zo=class extends f{},zg=class extends zo{},Tg=class extends zo{};var To=class extends f{},Cg=class extends To{},Pg=class extends To{};var Co=class extends f{},Lg=class extends Co{},Ng=class extends Co{};var Fg=class extends Ge{};var Tl=class extends f{},$g=class extends Tl{async _call(e){return new je(await super._call(e))}};var Po=class extends f{},Rg=class extends Po{},Dg=class extends Po{};var Lo=class extends f{},jg=class extends Lo{},Bg=class extends Lo{};var No=class extends f{},qg=class extends No{},Ug=class extends No{};var Fo=class extends f{},Gg=class extends Fo{},Wg=class extends Fo{};var Cl=class extends f{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","pixel_values","image_sizes","past_key_values"]},$o=class extends Cl{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,...p}){if(!i){let _;if(r&&e.dims[1]!==1){if(!n)throw new Error("`image_sizes` must be provided when `pixel_values` is provided.");({image_features:_}=await X(this.sessions.vision_encoder,{pixel_values:r,image_sizes:n}))}else{let d=this.config.normalized_config.hidden_size;_=new v("float32",[],[0,d])}({inputs_embeds:i}=await X(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:_}))}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{},Vg=class extends Ro{},Hg=class extends Ro{async _call(e){return new I(await super._call(e))}};var Do=class extends f{},Kg=class extends Do{},Xg=class extends Do{async _call(e){return new ee(await super._call(e))}};var jo=class extends f{},Qg=class extends jo{},Yg=class extends jo{};var Bo=class extends f{},Jg=class extends Bo{},Zg=class extends Bo{};var qo=class extends f{},ex=class extends qo{},tx=class extends qo{};var Uo=class extends f{},sx=class extends Uo{},rx=class extends Uo{};var Go=class extends f{},nx=class extends Go{},ox=class extends Go{};var xs=class extends _s{},ws=class extends ds{};var ix=class extends xs{},Wo=class extends ws{};var ur=class extends xs{},ys=class extends ur{};var ax=class extends ur{},Vo=class extends ys{};var Ho=class extends f{},lx=class extends Ho{},cx=class extends Ho{async _call(e){return new I(await super._call(e))}};var Ko=class extends f{},px=class extends Ko{},ux=class extends Ko{async _call(e){return new Pl(await super._call(e))}},Pl=class extends ht{};var Gt=class extends f{},_x=class extends Gt{},dx=class extends Gt{async _call(e){return new re(await super._call(e))}},fx=class extends Gt{async _call(e){return new I(await super._call(e))}},mx=class extends Gt{async _call(e){return new ee(await super._call(e))}},hx=class extends Gt{async _call(e){return new le(await super._call(e))}};var Wt=class extends f{},gx=class extends Wt{},xx=class extends Wt{async _call(e){return new re(await super._call(e))}},wx=class extends Wt{async _call(e){return new I(await super._call(e))}},yx=class extends Wt{async _call(e){return new ee(await super._call(e))}},bx=class extends Wt{async _call(e){return new le(await super._call(e))}};var Xo=class extends f{},kx=class extends Xo{},vx=class extends Xo{async _call(e){return new Ll(await super._call(e))}},Ll=class extends ht{};var Nl=class extends fe{constructor({iou_scores:e,pred_masks:s}){super(),this.iou_scores=e,this.pred_masks=s}},Fl=class extends f{},Ex=class extends Fl{async get_image_embeddings({pixel_values:e}){return await tt(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??=Se(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 X(this.sessions.prompt_encoder_mask_decoder,s)}async _call(e){return new Nl(await super._call(e))}};var $l=class extends fe{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}},Rl=class extends f{},Qo=class extends Rl{async get_image_embeddings({pixel_values:e}){return await tt(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??=Se(i.slice(0,-1)),e.input_boxes??=ye([i[0],0,4],0)}else if(e.input_boxes){let i=e.input_boxes.dims;e.input_labels=ye([i[0],i[1],0],-1n),e.input_points=ye([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=ke(e,n.inputNames);return await X(n,o)}async _call(e){return new $l(await super._call(e))}},Ax=class extends Qo{},Mx=class extends Qo{};var _r=class extends f{},Sx=class extends _r{},Ox=class extends _r{},Ix=class extends _r{};var dr=class extends f{},zx=class extends dr{},Tx=class extends dr{},Cx=class extends dr{};var Yo=class extends f{},Px=class extends Yo{},Jo=class extends Yo{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"text_model"})}},Lx=class extends mt{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"vision_model"})}};var Zo=class extends f{},Nx=class extends Zo{},Fx=class extends Zo{};var fr=class extends f{main_input_name="input_values";forward_params=["input_values"]},$x=class extends fr{async encode(e){return await X(this.sessions.encoder_model,e)}async decode(e){return await X(this.sessions.decoder_model,e)}},ei=class extends fr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"encoder_model"})}},ti=class extends fr{static async from_pretrained(e,s={}){return super.from_pretrained(e,{...s,model_file_name:s.model_file_name??"decoder_model"})}};var si=class extends f{},Rx=class extends si{},Dx=class extends si{};var mr=class extends f{},jx=class extends mr{},Bx=class extends mr{},qx=class extends mr{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 tt(this,a),p=l.dims[1]/this.config.reduction_factor,u=Math.floor(p*o),_=Math.floor(p*n),d=this.config.num_mel_bins,m=[],h=null,g=null,x=0;for(;;){++x;let b=I_(!!g),E;g?E=g.output_sequence_out:E=new v("float32",new Float32Array(d),[1,1,d]);let k={use_cache_branch:b,output_sequence:E,encoder_attention_mask:c,speaker_embeddings:s,encoder_hidden_states:l};this.addPastKeyValues(k,h),g=await X(this.sessions.decoder_model_merged,k),h=this.getPastKeyValues(g,h);let{prob:O,spectrum:N}=g;if(m.push(N),x>=_&&(Array.from(O.data).filter(j=>j>=r).length>0||x>=u))break}let w=ie(m),{waveform:y}=await X(i.sessions.model,{spectrogram:w});return{spectrogram:w,waveform:y}}},Ux=class extends f{main_input_name="spectrogram"};var bs=class extends f{},Gx=class extends bs{},Wx=class extends bs{async _call(e){return new re(await super._call(e))}},Vx=class extends bs{async _call(e){return new I(await super._call(e))}},Hx=class extends bs{async _call(e){return new le(await super._call(e))}};var ri=class extends f{},Kx=class extends ri{},Xx=class extends ri{};var ni=class extends f{},Qx=class extends ni{},Yx=class extends ni{};var Dl=class extends f{},Jx=class extends Dl{};var jl=class extends f{},oi=class extends jl{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:p,durations:u}=await X(this.sessions.text_encoder,{input_ids:e,attention_mask:s,style:r}),_=u.div(o).mul_(i),d=l*a,m=_.data,h=Int32Array.from(m,C=>Math.ceil(C/d)),g=Math.max(...h),x=e.dims[0],w=new BigInt64Array(x*g);for(let C=0;C<x;++C)w.fill(1n,C*g,C*g+h[C]);let y=new v("int64",w,[x,g]),b=c*a,E=b*g,k=I0([x,b,g]),O=k.data;for(let C=0;C<x;++C)if(h[C]!==g)for(let R=0;R<b;++R)O.fill(0,C*E+R*g+h[C],C*E+(R+1)*g);let N=ye([x],n);for(let C=0;C<n;++C){let R=ye([x],C);({denoised_latents:k}=await X(this.sessions.latent_denoiser,{style:r,noisy_latents:k,latent_mask:y,encoder_outputs:p,attention_mask:s,timestep:R,num_inference_steps:N}))}let{waveform:j}=await X(this.sessions.voice_decoder,{latents:k});return{waveform:j,durations:_}}};var hr=class extends f{},Zx=class extends hr{},ew=class extends hr{async _call(e){return new I(await super._call(e))}},tw=class extends hr{};var ii=class extends f{},sw=class extends ii{},rw=class extends ii{};var ai=class extends f{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"]},nw=class extends ai{},ow=class extends ai{};var li=class extends f{},iw=class extends li{},aw=class extends li{async _call(e){return new Bl(await super._call(e))}},Bl=class extends sr{};var ql=class extends f{},lw=class extends ql{};var gr=class extends f{},cw=class extends gr{},pw=class extends gr{async _call(e){return new je(await super._call(e))}},uw=class extends gr{async _call(e){return new I(await super._call(e))}};var ks=class extends f{},_w=class extends ks{},dw=class extends ks{async _call(e){return new je(await super._call(e))}},fw=class extends ks{async _call(e){return new I(await super._call(e))}},mw=class extends ks{async _call(e){return new ee(await super._call(e))}};var ci=class extends f{},hw=class extends ci{},gw=class extends ci{};var xw=class extends f{main_input_name="pixel_values";forward_params=["pixel_values","decoder_input_ids","encoder_hidden_states","past_key_values"]};var pi=class extends f{},ww=class extends pi{},yw=class extends pi{async _call(e){return new I(await super._call(e))}};var Ul=class extends f{},bw=class extends Ul{};var ui=class extends f{},kw=class extends ui{},vw=class extends ui{async _call(e){return new I(await super._call(e))}};var Gl=class extends f{},Ew=class extends Gl{async _call(e){return new Ba(await super._call(e))}};var Wl=class extends f{},Aw=class extends Wl{};var Vl=class extends fe{constructor({waveform:e,spectrogram:s}){super(),this.waveform=e,this.spectrogram=s}},Hl=class extends f{},Mw=class extends Hl{async _call(e){return new Vl(await super._call(e))}};var Sw=class extends fs{};var lb=2,NA=1,Ow=new WeakMap;function FA(t,e){let{text_config:s,audio_config:r}=t.config,n=t.sessions.audio_encoder,{num_mel_bins:o,hidden_size:i}=r,a=o+i,l=new Jr,c=n?.config?.kv_cache_dtype??"float32",p=c==="float16"?wt.float16:wt.float32,u=rs(r,{batch_size:1});for(let m in u){let h=u[m].reduce((g,x)=>g*x,1);l[m]=new v(c,new p(h),u[m])}let _=new v(c,new p(a*lb),[1,a,lb]),d=e[Symbol.asyncIterator]?.()??e[Symbol.iterator]?.();if(!d)throw new Error("input_features must be iterable or async iterable");return{encoder_session:n,enc_kv_cache:l,enc_padding_cache:_,enc_past_seq_len:0,audio_embed_queue:[],audio_embed_total_tokens:0,audio_queue_offset:0,audio_consumed:0,stream_exhausted:!1,chunks_iter:d,text_hidden_size:s.hidden_size}}async function $A(t,e){let s=e.dims[2],r=Math.floor((NA+s-3)/2)+1,n=new v("int64",BigInt64Array.from({length:r},(p,u)=>BigInt(t.enc_past_seq_len+u)),[1,r]),o=t.enc_past_seq_len+r,i=Se([1,o]),{audio_embeds:a,present_padding_cache:l,...c}=await X(t.encoder_session,{input_features:e,attention_mask:i,position_ids:n,past_padding_cache:t.enc_padding_cache,...t.enc_kv_cache});t.enc_padding_cache.location==="gpu-buffer"&&t.enc_padding_cache.dispose(),t.enc_padding_cache=l;for(let p in c)if(p.startsWith("present.")){let u=p.replace("present","past_key_values"),_=t.enc_kv_cache[u];_?.location==="gpu-buffer"&&_.dispose(),t.enc_kv_cache[u]=c[p]}return t.enc_past_seq_len=o,a}async function RA(t,e){for(;t.audio_embed_total_tokens<e&&!t.stream_exhausted;){let s=await t.chunks_iter.next();if(s.done){t.stream_exhausted=!0;break}let r=await $A(t,s.value);t.audio_embed_queue.push({data:r.data,tokens:r.dims[1]}),t.audio_embed_total_tokens+=r.dims[1]}}function DA(t,e,s){if(t.audio_embed_queue.length===0)return;let r=e.data,n=0,o=s;for(;o>0&&t.audio_embed_queue.length>0;){let i=t.audio_embed_queue[0],a=i.tokens-t.audio_queue_offset,l=Math.min(o,a),c=t.audio_queue_offset*t.text_hidden_size;for(let p=0;p<l*t.text_hidden_size;++p)r[n*t.text_hidden_size+p]+=i.data[c+p];n+=l,o-=l,t.audio_queue_offset+=l,t.audio_queue_offset>=i.tokens&&(t.audio_embed_queue.shift(),t.audio_queue_offset=0)}t.audio_consumed+=s-o}var Iw=class extends Lt{constructor(e){super(),this._s=e}_call(e){let s=this._s.stream_exhausted&&this._s.audio_embed_queue.length===0;return e.map(()=>s)}},Kl=class extends f{forward_params=["input_ids","attention_mask","position_ids","past_key_values"]},_i=class extends Kl{async forward({input_ids:e,past_key_values:s,...r}){let n=e.dims[1],o=Ow.get(this);o&&await RA(o,o.audio_consumed+n);let{inputs_embeds:i}=await X(this.sessions.embed_tokens,{input_ids:e});o&&DA(o,i,n);let a={inputs_embeds:i,...r};this.addPastKeyValues(a,s);let l=this.sessions.decoder_model_merged,c=ke(a,l.inputNames);return await X(l,c)}async generate({input_features:e,stopping_criteria:s,...r}){if(!e)throw new Error("input_features (generator/iterable) must be provided");let n=FA(this,e);Ow.set(this,n);let o=new Ks;o.push(new Iw(n)),s&&o.extend(s);try{return await super.generate({...r,stopping_criteria:o})}finally{n.enc_kv_cache.dispose(),Ow.delete(this)}}};var xr=class extends f{},zw=class extends xr{},Tw=class extends xr{async _call(e){return new je(await super._call(e))}},Cw=class extends xr{async _call(e){return new I(await super._call(e))}};var Xl=class extends fe{constructor({logits:e,embeddings:s}){super(),this.logits=e,this.embeddings=s}},Vt=class extends f{},Pw=class extends Vt{},Lw=class extends Vt{async _call(e){return new je(await super._call(e))}},Nw=class extends Vt{async _call(e){return new I(await super._call(e))}},Fw=class extends Vt{async _call(e){return new Xl(await super._call(e))}},$w=class extends Vt{async _call(e){return new ee(await super._call(e))}};var Ql=class extends f{},Rw=class extends Ql{};var Yl=class extends Hs{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 di=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"]},Dw=class extends di{},Jl=class extends di{_prepare_generation_config(e,s){return super._prepare_generation_config(e,s,Yl)}_retrieve_init_tokens(e){let s=[e.decoder_start_token_id],r=e.language,n=e.task;if(e.is_multilingual){r||(F.warn("No language specified - defaulting to English (en)."),r="en");let i=`<|${C0(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&&(F.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 ns,r.push(new Ga(s,i))),s.begin_suppress_tokens&&(r??=new ns,r.push(new Vs(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"&&F.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&&F.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&&(F.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,g)=>ie(i.map(x=>x[g]),2)),l=qe(s.map(([h,g])=>{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,g,null,[0,r]):a[h].slice(null,g)})).transpose(1,0,2,3),[c,p]=Vc(l,-2,0,!0),u=l.clone();for(let h=0;h<u.dims[0];++h){let g=u[h];for(let x=0;x<g.dims[0];++x){let w=g[x],y=c[h][x][0].data,b=p[h][x][0].data;for(let E=0;E<w.dims[0];++E){let k=w[E].data;for(let O=0;O<k.length;++O)k[O]=(k[O]-b[O])/y[O];k.set(l0(k,o))}}}let _=[_a(u,1)],d=e.sequences.dims,m=new v("float32",new Float32Array(d[0]*d[1]),d);for(let h=0;h<d[0];++h){let g=_[h].neg().squeeze_(0),[x,w]=p0(g.tolist()),y=Array.from({length:x.length-1},(k,O)=>x[O+1]-x[O]),b=Fe([1],y).map(k=>!!k),E=[];for(let k=0;k<b.length;++k)b[k]&&E.push(w[k]*n);m[h].data.set(E,1)}return m}},jw=class extends Jl{};var Ht=class extends f{},Bw=class extends Ht{},qw=class extends Ht{async _call(e){return new re(await super._call(e))}},Uw=class extends Ht{async _call(e){return new I(await super._call(e))}},Gw=class extends Ht{async _call(e){return new ee(await super._call(e))}},Ww=class extends Ht{async _call(e){return new le(await super._call(e))}};var Kt=class extends f{},Vw=class extends Kt{},Hw=class extends Kt{async _call(e){return new re(await super._call(e))}},Kw=class extends Kt{async _call(e){return new I(await super._call(e))}},Xw=class extends Kt{async _call(e){return new ee(await super._call(e))}},Qw=class extends Kt{async _call(e){return new le(await super._call(e))}};var fi=class extends f{},Yw=class extends fi{},Jw=class extends fi{async _call(e){return new Zl(await super._call(e))}},Zl=class extends fe{constructor({logits:e,pred_boxes:s}){super(),this.logits=e,this.pred_boxes=s}};var mi=class extends f{},Zw=class extends mi{},ey=class extends mi{};var jA=new Map([["bert","BertModel"],["eurobert","EuroBertModel"],["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"]]),BA=new Map([["t5","T5Model"],["longt5","LongT5Model"],["mt5","MT5Model"],["bart","BartModel"],["mbart","MBartModel"],["marian","MarianModel"],["whisper","WhisperModel"],["m2m_100","M2M100Model"],["blenderbot","BlenderbotModel"],["blenderbot-small","BlenderbotSmallModel"]]),qA=new Map([["mimi","MimiModel"],["dac","DacModel"],["snac","SnacModel"]]),UA=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"],["olmo_hybrid","OlmoHybridModel"],["mobilellm","MobileLLMModel"],["granite","GraniteModel"],["granitemoehybrid","GraniteMoeHybridModel"],["cohere","CohereModel"],["cohere2","Cohere2Model"],["gemma","GemmaModel"],["gemma2","Gemma2Model"],["vaultgemma","VaultGemmaModel"],["gemma3_text","Gemma3Model"],["helium","HeliumModel"],["glm","GlmModel"],["glm_moe_dsa","GlmMoeDsaModel"],["openelm","OpenELMModel"],["qwen2","Qwen2Model"],["qwen2_moe","Qwen2MoeModel"],["qwen3","Qwen3Model"],["qwen3_moe","Qwen3MoeModel"],["qwen3_next","Qwen3NextModel"],["phi","PhiModel"],["phi3","Phi3Model"],["mpt","MptModel"],["opt","OPTModel"],["mistral","MistralModel"],["mistral4","Mistral4Model"],["ministral","MinistralModel"],["ministral3","Ministral3Model"],["ernie4_5","Ernie4_5ForCausalLM"],["starcoder2","Starcoder2Model"],["deepseek_v3","DeepseekV3Model"],["falcon","FalconModel"],["falcon_h1","FalconH1Model"],["nemotron_h","NemotronHModel"],["solar_open","SolarOpenModel"],["stablelm","StableLmModel"],["modernbert-decoder","ModernBertDecoderModel"],["hunyuan_v1_dense","HunYuanDenseV1Model"],["youtu","YoutuModel"]]),cb=new Map([["speecht5","SpeechT5ForSpeechToText"],["whisper","WhisperForConditionalGeneration"],["lite-whisper","LiteWhisperForConditionalGeneration"],["moonshine","MoonshineForConditionalGeneration"]]),pb=new Map([["speecht5","SpeechT5ForTextToSpeech"]]),ub=new Map([["vits","VitsModel"],["musicgen","MusicgenForConditionalGeneration"],["supertonic","SupertonicForConditionalGeneration"]]),_b=new Map([["bert","BertForSequenceClassification"],["eurobert","EuroBertForSequenceClassification"],["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"]]),db=new Map([["bert","BertForTokenClassification"],["eurobert","EuroBertForTokenClassification"],["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"]]),fb=new Map([["t5","T5ForConditionalGeneration"],["longt5","LongT5ForConditionalGeneration"],["mt5","MT5ForConditionalGeneration"],["bart","BartForConditionalGeneration"],["mbart","MBartForConditionalGeneration"],["marian","MarianMTModel"],["m2m_100","M2M100ForConditionalGeneration"],["blenderbot","BlenderbotForConditionalGeneration"],["blenderbot-small","BlenderbotSmallForConditionalGeneration"]]),mb=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"],["olmo_hybrid","OlmoHybridForCausalLM"],["mobilellm","MobileLLMForCausalLM"],["granite","GraniteForCausalLM"],["granitemoehybrid","GraniteMoeHybridForCausalLM"],["cohere","CohereForCausalLM"],["cohere2","Cohere2ForCausalLM"],["gemma","GemmaForCausalLM"],["gemma2","Gemma2ForCausalLM"],["vaultgemma","VaultGemmaForCausalLM"],["gemma3_text","Gemma3ForCausalLM"],["gemma3","Gemma3ForCausalLM"],["helium","HeliumForCausalLM"],["glm","GlmForCausalLM"],["glm_moe_dsa","GlmMoeDsaForCausalLM"],["openelm","OpenELMForCausalLM"],["qwen2","Qwen2ForCausalLM"],["qwen2_moe","Qwen2MoeForCausalLM"],["qwen3","Qwen3ForCausalLM"],["qwen3_moe","Qwen3MoeForCausalLM"],["qwen3_next","Qwen3NextForCausalLM"],["qwen2_vl","Qwen2VLForCausalLM"],["qwen2_5_vl","Qwen2_5_VLForCausalLM"],["qwen3_vl","Qwen3VLForCausalLM"],["qwen3_vl_moe","Qwen3VLMoeForCausalLM"],["qwen3_5","Qwen3_5ForCausalLM"],["qwen3_5_moe","Qwen3_5MoeForCausalLM"],["gemma3n","Gemma3nForCausalLM"],["phi","PhiForCausalLM"],["phi3","Phi3ForCausalLM"],["mpt","MptForCausalLM"],["opt","OPTForCausalLM"],["mbart","MBartForCausalLM"],["mistral","MistralForCausalLM"],["mistral4","Mistral4ForCausalLM"],["ministral","MinistralForCausalLM"],["ministral3","Ministral3ForCausalLM"],["ernie4_5","Ernie4_5ForCausalLM"],["starcoder2","Starcoder2ForCausalLM"],["deepseek_v3","DeepseekV3ForCausalLM"],["falcon","FalconForCausalLM"],["falcon_h1","FalconH1ForCausalLM"],["nemotron_h","NemotronHForCausalLM"],["trocr","TrOCRForCausalLM"],["solar_open","SolarOpenForCausalLM"],["stablelm","StableLmForCausalLM"],["modernbert-decoder","ModernBertDecoderForCausalLM"],["hunyuan_v1_dense","HunYuanDenseV1ForCausalLM"],["youtu","YoutuForCausalLM"],["phi3_v","Phi3VForCausalLM"]]),GA=new Map([["multi_modality","MultiModalityCausalLM"]]),hb=new Map([["bert","BertForMaskedLM"],["eurobert","EuroBertForMaskedLM"],["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"]]),gb=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"]]),xb=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"]]),wb=new Map([["llava","LlavaForConditionalGeneration"],["llava_onevision","LlavaOnevisionForConditionalGeneration"],["moondream1","Moondream1ForConditionalGeneration"],["florence2","Florence2ForConditionalGeneration"],["qwen2_vl","Qwen2VLForConditionalGeneration"],["qwen2_5_vl","Qwen2_5_VLForConditionalGeneration"],["qwen3_vl","Qwen3VLForConditionalGeneration"],["qwen3_vl_moe","Qwen3VLMoeForConditionalGeneration"],["qwen3_5","Qwen3_5ForConditionalGeneration"],["qwen3_5_moe","Qwen3_5MoeForConditionalGeneration"],["lfm2_vl","Lfm2VlForConditionalGeneration"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"],["paligemma","PaliGemmaForConditionalGeneration"],["llava_qwen2","LlavaQwen2ForCausalLM"],["gemma3n","Gemma3nForConditionalGeneration"],["mistral3","Mistral3ForConditionalGeneration"],["lighton_ocr","LightOnOcrForConditionalGeneration"],["glm_ocr","GlmOcrForConditionalGeneration"]]),yb=new Map([["granite_speech","GraniteSpeechForConditionalGeneration"],["ultravox","UltravoxModel"],["voxtral","VoxtralForConditionalGeneration"],["voxtral_realtime","VoxtralRealtimeForConditionalGeneration"]]),WA=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"]]),bb=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"]]),kb=new Map([["detr","DetrForObjectDetection"],["rt_detr","RTDetrForObjectDetection"],["rt_detr_v2","RTDetrV2ForObjectDetection"],["rf_detr","RFDetrForObjectDetection"],["d_fine","DFineForObjectDetection"],["table-transformer","TableTransformerForObjectDetection"],["yolos","YolosForObjectDetection"]]),vb=new Map([["owlvit","OwlViTForObjectDetection"],["owlv2","Owlv2ForObjectDetection"],["grounding-dino","GroundingDinoForObjectDetection"]]),wr=new Map([["detr","DetrForSegmentation"],["clipseg","CLIPSegForImageSegmentation"]]),Eb=new Map([["segformer","SegformerForSemanticSegmentation"],["sapiens","SapiensForSemanticSegmentation"],["swin","SwinForSemanticSegmentation"],["mobilenet_v1","MobileNetV1ForSemanticSegmentation"],["mobilenet_v2","MobileNetV2ForSemanticSegmentation"],["mobilenet_v3","MobileNetV3ForSemanticSegmentation"],["mobilenet_v4","MobileNetV4ForSemanticSegmentation"]]),Ab=new Map([["detr","DetrForSegmentation"],["maskformer","MaskFormerForInstanceSegmentation"]]),Mb=new Map([["sam","SamModel"],["sam2","Sam2Model"],["edgetam","EdgeTamModel"],["sam3_tracker","Sam3TrackerModel"]]),Sb=new Map([["wav2vec2","Wav2Vec2ForCTC"],["wav2vec2-bert","Wav2Vec2BertForCTC"],["unispeech","UniSpeechForCTC"],["unispeech-sat","UniSpeechSatForCTC"],["wavlm","WavLMForCTC"],["hubert","HubertForCTC"],["parakeet_ctc","ParakeetForCTC"]]),Ob=new Map([["wav2vec2","Wav2Vec2ForSequenceClassification"],["wav2vec2-bert","Wav2Vec2BertForSequenceClassification"],["unispeech","UniSpeechForSequenceClassification"],["unispeech-sat","UniSpeechSatForSequenceClassification"],["wavlm","WavLMForSequenceClassification"],["hubert","HubertForSequenceClassification"],["audio-spectrogram-transformer","ASTForAudioClassification"]]),Ib=new Map([["wavlm","WavLMForXVector"]]),zb=new Map([["unispeech-sat","UniSpeechSatForAudioFrameClassification"],["wavlm","WavLMForAudioFrameClassification"],["wav2vec2","Wav2Vec2ForAudioFrameClassification"],["pyannote","PyAnnoteForAudioFrameClassification"]]),Tb=new Map([["vitmatte","VitMatteForImageMatting"]]),VA=new Map([["patchtst","PatchTSTForPrediction"],["patchtsmixer","PatchTSMixerForPrediction"]]),Cb=new Map([["swin2sr","Swin2SRForImageSuperResolution"]]),Pb=new Map([["chmv2","CHMv2ForDepthEstimation"],["dpt","DPTForDepthEstimation"],["depth_anything","DepthAnythingForDepthEstimation"],["glpn","GLPNForDepthEstimation"],["sapiens","SapiensForDepthEstimation"],["depth_pro","DepthProForDepthEstimation"],["metric3d","Metric3DForDepthEstimation"],["metric3dv2","Metric3Dv2ForDepthEstimation"]]),Lb=new Map([["sapiens","SapiensForNormalEstimation"]]),Nb=new Map([["vitpose","VitPoseForPoseEstimation"]]),Fb=new Map([["clip","CLIPVisionModelWithProjection"],["siglip","SiglipVisionModel"],["jina_clip","JinaCLIPVisionModel"]]),ty=[[jA,L.EncoderOnly],[BA,L.EncoderDecoder],[UA,L.DecoderOnlyWithoutHead],[qA,L.AutoEncoder],[_b,L.EncoderOnly],[db,L.EncoderOnly],[fb,L.Seq2Seq],[cb,L.Seq2Seq],[mb,L.DecoderOnly],[GA,L.MultiModality],[hb,L.EncoderOnly],[gb,L.EncoderOnly],[xb,L.Vision2Seq],[wb,L.ImageTextToText],[yb,L.AudioTextToText],[bb,L.EncoderOnly],[wr,L.EncoderOnly],[Ab,L.EncoderOnly],[Eb,L.EncoderOnly],[Tb,L.EncoderOnly],[VA,L.EncoderOnly],[Cb,L.EncoderOnly],[Pb,L.EncoderOnly],[Lb,L.EncoderOnly],[Nb,L.EncoderOnly],[kb,L.EncoderOnly],[vb,L.EncoderOnly],[Mb,L.MaskGeneration],[Sb,L.EncoderOnly],[Ob,L.EncoderOnly],[pb,L.Seq2Seq],[ub,L.EncoderOnly],[Ib,L.EncoderOnly],[zb,L.EncoderOnly],[Fb,L.EncoderOnly]];for(let[t,e]of ty)for(let s of t.values()){lt.set(s,e);let r=hi[s];as.set(r,s),tl.set(s,r)}var HA=[["MusicgenForConditionalGeneration",ko,L.Musicgen],["Phi3VForCausalLM",$o,L.Phi3V],["CLIPTextModelWithProjection",dn,L.EncoderOnly],["SiglipTextModel",Jo,L.EncoderOnly],["JinaCLIPTextModel",to,L.EncoderOnly],["ClapTextModelWithProjection",un,L.EncoderOnly],["ClapAudioModelWithProjection",_n,L.EncoderOnly],["DacEncoderModel",kn,L.EncoderOnly],["DacDecoderModel",vn,L.EncoderOnly],["MimiEncoderModel",co,L.EncoderOnly],["MimiDecoderModel",po,L.EncoderOnly],["SnacEncoderModel",ei,L.EncoderOnly],["SnacDecoderModel",ti,L.EncoderOnly],["Gemma3nForConditionalGeneration",rr,L.ImageAudioTextToText],["SupertonicForConditionalGeneration",oi,L.Supertonic],["ChatterboxModel",pn,L.Chatterbox],["Qwen2VLForCausalLM",us,L.MultimodalLanguageModelOnly],["Qwen2_5_VLForCausalLM",ds,L.MultimodalLanguageModelOnly],["Qwen3VLForCausalLM",ws,L.MultimodalLanguageModelOnly],["Qwen3VLMoeForCausalLM",Wo,L.MultimodalLanguageModelOnly],["Qwen3_5ForCausalLM",ys,L.MultimodalLanguageModelOnly],["Qwen3_5MoeForCausalLM",Vo,L.MultimodalLanguageModelOnly],["Gemma3nForCausalLM",Rn,L.MultimodalLanguageModelOnly],["VoxtralRealtimeForConditionalGeneration",_i,L.VoxtralRealtime]];for(let[t,e,s]of HA)lt.set(t,s),as.set(e,t),tl.set(t,e);var $b=new Map([["modnet",wr],["birefnet",wr],["isnet",wr],["ben",wr]]);for(let[t,e]of $b.entries())e.set(t,"PreTrainedModel"),lt.set(t,L.EncoderOnly),tl.set(t,f);var Rb=new Set($b.keys());lt.set("PreTrainedModel",L.EncoderOnly);as.set(f,"PreTrainedModel");var _e={MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES:_b,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES:db,MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES:pb,MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES:ub,MODEL_FOR_MASKED_LM_MAPPING_NAMES:hb,MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES:gb,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES:bb,MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES:wr,MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES:Eb,MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES:Ab,MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES:kb,MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES:vb,MODEL_FOR_MASK_GENERATION_MAPPING_NAMES:Mb,MODEL_FOR_CTC_MAPPING_NAMES:Sb,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES:Ob,MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES:Ib,MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES:zb,MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES:WA,MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES:Tb,MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES:Cb,MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES:Pb,MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES:Lb,MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES:Nb,MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES:Fb,MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES:wb,MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES:yb,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES:fb,MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES:cb,MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:mb,MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES:xb};rb(_e);var ce=class{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static supports(e){if(!this.MODEL_CLASS_MAPPINGS)return!1;for(let s of this.MODEL_CLASS_MAPPINGS)if(s.has(e))return!0;return this.BASE_IF_FAIL}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:p=null,use_external_data_format:u=null,session_options:_={}}={}){let d={progress_callback:s,config:r,cache_dir:n,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:p,use_external_data_format:u,session_options:_};if(d.config=await Ze.from_pretrained(e,d),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);let{model_type:m}=d.config;for(let h of this.MODEL_CLASS_MAPPINGS){let g=h.get(m);if(!g){for(let x of h.values())if(x[0]===m){g=x;break}if(!g)continue}return await hi[g].from_pretrained(e,d)}if(this.BASE_IF_FAIL)return Rb.has(m)||F.warn(`Unknown model class "${m}", attempting to construct from base class.`),await f.from_pretrained(e,d);throw Error(`Unsupported model type: ${m}`)}},bt=class extends ce{static MODEL_CLASS_MAPPINGS=ty.map(e=>e[0]);static BASE_IF_FAIL=!0},gi=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]},ec=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]},yr=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]},tc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]},sc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]},rc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]},nc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES]},oc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_MASKED_LM_MAPPING_NAMES]},ic=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]},ac=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]},lc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]},xi=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]},wi=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]},yi=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES]},cc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]},pc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]},Db=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]},uc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_CTC_MAPPING_NAMES]},_c=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]},jb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]},Bb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]},dc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]},qb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]},fc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]},mc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]},Ub=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES]},Gb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES]},hc=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]},Wb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES]},Vb=class extends ce{static MODEL_CLASS_MAPPINGS=[_e.MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES]};async function Ae(t){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(e=>ve.read(e)))}async function Xt(t,e){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(s=>typeof s=="string"||s instanceof URL?Gp(s,e):s instanceof Float64Array?new Float32Array(s):s))}function bi(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 Q=class extends Me{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 ki=class extends Q{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 v("float32",de(c.data),c.dims),l=[];for(let c of n.logits){let p=a(c),u=await at(p,s),_=u[0].tolist(),m=u[1].tolist().map((h,g)=>({label:i?i[h]:`LABEL_${h}`,score:_[g]}));s===1?l.push(...m):l.push(m)}return Array.isArray(e)||s===1?l:l[0]}};var vi=class extends Q{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 p=n.input_ids[c],u=i[c],_=[];for(let d=0;d<u.dims[0];++d){let m=u[d],h=pe(m.data)[1],g=a?a[h]:`LABEL_${h}`;if(s.includes(g))continue;let x=this.tokenizer.decode([p[d].item()],{skip_special_tokens:!0});if(x==="")continue;let w=de(m.data);_.push({entity:g,score:w[h],index:d,word:x})}l.push(_)}return r?l:l[0]}};var Ei=class extends Q{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:p,sep_token_id:u}=this.tokenizer,_=[];for(let d=0;d<i.dims[0];++d){let m=l[d],h=m.findIndex(k=>k==u),g=i[d].tolist(),x=a[d].tolist();for(let k=1;k<g.length;++k)(c[d]==0||k<=h||p.findIndex(O=>O==m[k])!==-1)&&(g[k]=-1/0,x[k]=-1/0);let w=de(g).map((k,O)=>[k,O]),y=de(x).map((k,O)=>[k,O]);w[0][0]=0,y[0][0]=0;let b=gy(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]),E=[];for(let k=0;k<Math.min(b.length,r);++k){let[O,N,j]=b[k],C=m.slice(O,N+1),R=this.tokenizer.decode(C,{skip_special_tokens:!0});E.push({answer:R,score:j})}r===1?_.push(...E):_.push(E)}return o?_:_[0]}};var Ai=class extends Q{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 p=l[c],u=p.findIndex(g=>g==r);if(u===-1)throw Error(`Mask token (${n}) not found in text.`);let _=i[c][u],d=await at(new v("float32",de(_.data),_.dims),s),m=d[0].tolist(),h=d[1].tolist();a.push(h.map((g,x)=>{let w=p.slice();return w[u]=g,{score:m[x],token:Number(g),token_str:this.tokenizer.decode([g]),sequence:this.tokenizer.decode(w,{skip_special_tokens:!0})}}))}return Array.isArray(e)?a:a[0]}};var kt=class extends Q{_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 Mi=class extends kt{_key="summary_text"};var Si=class extends kt{_key="translation_text"};function Hb(t){return Array.isArray(t)&&t.every(e=>"role"in e&&"content"in e)}var Oi=class extends Q{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(Hb(e))e=[e];else if(Array.isArray(e)&&e.every(Hb))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}),p=await this.model.generate({...c,...s}),u=this.tokenizer.batch_decode(p,{skip_special_tokens:!0}),_;!l&&c.input_ids.dims.at(-1)>0&&(_=this.tokenizer.batch_decode(c.input_ids,{skip_special_tokens:!0}).map(m=>m.length));let d=Array.from({length:e.length},m=>[]);for(let m=0;m<u.length;++m){let h=Math.floor(m/p.dims[0]*e.length);_&&(u[m]=u[m].slice(_[h])),d[h].push({generated_text:n?[...e[h],{role:"assistant",content:u[m]}]:u[m]})}return!r&&d.length===1?d[0]:d}};var Ii=class extends Q{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&&(F.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&&(F.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 p=[];for(let d of i){let m=this.tokenizer(c,{text_pair:d,padding:!0,truncation:!0}),h=await this.model(m);a?p.push([h.logits.data[this.contradiction_id],h.logits.data[this.entailment_id]]):p.push(h.logits.data[this.entailment_id])}let _=(a?p.map(d=>de(d)[1]):de(p)).map((d,m)=>[d,m]).sort((d,m)=>m[0]-d[0]);l.push({sequence:c,labels:_.map(d=>s[d[1]]),scores:_.map(d=>d[0])})}return o?l:l[0]}};var zi=class extends Q{async _call(e,{top_k:s=5}={}){let r=this.processor.feature_extractor.config.sampling_rate,n=await Xt(e,r),o=this.model.config.id2label,i=[];for(let a of n){let l=await this.processor(a),p=(await this.model(l)).logits[0],u=await at(new v("float32",de(p.data),p.dims),s),_=u[0].tolist(),m=u[1].tolist().map((h,g)=>({label:o?o[h]:`LABEL_${h}`,score:_[g]}));i.push(m)}return Array.isArray(e)?i:i[0]}};var Ti=class extends Q{async _call(e,s,{hypothesis_template:r="This is a sound of {}."}={}){let n=!Array.isArray(e);n&&(e=[e]);let o=s.map(p=>r.replace("{}",p)),i=this.tokenizer(o,{padding:!0,truncation:!0}),a=this.processor.feature_extractor.config.sampling_rate,l=await Xt(e,a),c=[];for(let p of l){let u=await this.processor(p),_=await this.model({...i,...u}),d=de(_.logits_per_audio.data);c.push([...d].map((m,h)=>({score:m,label:s[h]})))}return n?c[0]:c}};var Ci=class extends Q{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&&F.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),s.task&&F.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 Xt(n,o),a=[];for(let l of i){let c=await this.processor(l),u=(await this.model(c)).logits[0],_=[];for(let m of u)_.push(pe(m.data)[1]);let d=this.tokenizer.decode(_,{skip_special_tokens:!0}).trim();a.push({text:d})}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,p=this.processor.feature_extractor.config,u=p.chunk_length/this.model.config.max_source_positions,_=p.hop_length,d=p.sampling_rate,m=await Xt(c,d),h=[];for(let g of m){let x=[];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=d*n,E=d*i,k=b-2*E,O=0;for(;;){let N=O+b,j=g.subarray(O,N),C=await this.processor(j),R=O===0,$=N>=g.length;if(x.push({stride:[j.length,R?0:E,$?0:E],input_features:C.input_features,is_last:$}),$)break;O+=k}}else x=[{stride:[g.length,0,0],input_features:(await this.processor(g)).input_features,is_last:!0}];for(let b of x){a.num_frames=Math.floor(b.stride[0]/_);let E=await this.model.generate({inputs:b.input_features,...a});r==="word"?(b.tokens=E.sequences.tolist()[0],b.token_timestamps=E.token_timestamps.tolist()[0].map(k=>Zt(k,2))):b.tokens=E[0].tolist(),b.stride=b.stride.map(k=>k/d)}let[w,y]=this.tokenizer._decode_asr(x,{time_precision:u,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 Xt(n,o),a=[];for(let l of i){let c=await this.processor(l),p=Math.floor(l.length/o)*6,u=await this.model.generate({max_new_tokens:p,...s,...c}),_=this.processor.batch_decode(u,{skip_special_tokens:!0})[0];a.push({text:_})}return r?a[0]:a}};var Pi=class extends Q{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 Y.fetch(e)).arrayBuffer())),e instanceof Float32Array)e=new v("float32",e,[e.length]);else if(!(e instanceof v))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 p=0;p<i;++p){let u=l?Math.min(Math.ceil(l[p]),a):a,_=p*a;c.push(new qr(o.slice(_,_+u),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:p}=await this.model.generate_speech({...a,style:s,num_inference_steps:r,speed:n});return this._postprocess_waveform(e,c,o,p)}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||(F.info("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await bt.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 Li=class extends Q{async _call(e,s={}){let r=Array.isArray(e),n=await Ae(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(p=>({generated_text:p.trim()}));i.push(c)}return r?i:i[0]}};var Ni=class extends Q{async _call(e,{top_k:s=5}={}){let r=await Ae(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 v("float32",de(l.data),l.dims),s),p=c[0].tolist(),_=c[1].tolist().map((d,m)=>({label:i?i[d]:`LABEL_${d}`,score:p[m]}));a.push(_)}return Array.isArray(e)?a:a[0]}};var Kb={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"},vs=class extends Q{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 Ae(e),p=c.map(w=>[w.height,w.width]),u=await this.processor(c),{inputNames:_,outputNames:d}=this.model.sessions.model;if(!_.includes("pixel_values")){if(_.length!==1)throw Error(`Expected a single input name, but got ${_.length} inputs: ${_}.`);let w=_[0];if(w in u)throw Error(`Input name ${w} already exists in the inputs.`);u[w]=u.pixel_values}let m=await this.model(u),h=null;if(a!==null)h=Kb[a];else if(this.processor.image_processor){for(let[w,y]of Object.entries(Kb))if(y in this.processor.image_processor){h=this.processor.image_processor[y].bind(this.processor.image_processor),a=w;break}}let g=this.model.config.id2label,x=[];if(a)if(a==="panoptic"||a==="instance"){let w=h(m,s,r,n,o,i??p)[0],y=w.segmentation;for(let b of w.segments_info){let E=new Uint8ClampedArray(y.data.length);for(let O=0;O<y.data.length;++O)y.data[O]===b.id&&(E[O]=255);let k=new ve(E,y.dims[1],y.dims[0],1);x.push({score:b.score,label:g[b.label_id],mask:k})}}else if(a==="semantic"){let{segmentation:w,labels:y}=h(m,i??p)[0];for(let b of y){let E=new Uint8ClampedArray(w.data.length);for(let O=0;O<w.data.length;++O)w.data[O]===b&&(E[O]=255);let k=new ve(E,w.dims[1],w.dims[0],1);x.push({score:null,label:g[b],mask:k})}}else throw Error(`Subtask ${a} not supported.`);else{let y=m[d[0]];for(let b=0;b<p.length;++b){let E=p[b],k=y[b];k.data.some(N=>N<-1e-5||N>1+1e-5)&&k.sigmoid_();let O=await ve.fromTensor(k.mul_(255).to("uint8")).resize(E[1],E[0]);x.push({label:null,score:null,mask:O})}}return x}};var Fi=class extends vs{async _call(e,s={}){let r=await Ae(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 $i=class extends Q{async _call(e,s,{hypothesis_template:r="This is a photo of {}"}={}){let n=Array.isArray(e),o=await Ae(e),i=s.map(_=>r.replace("{}",_)),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}),p=this.model.config.model_type==="siglip"?_=>_.sigmoid().data:_=>de(_.data),u=[];for(let _ of c.logits_per_image){let m=[...p(_)].map((h,g)=>({score:h,label:s[g]}));m.sort((h,g)=>g.score-h.score),u.push(m)}return n?u:u[0]}};var Ri=class extends Q{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 Ae(e),i=r?null:o.map(d=>[d.height,d.width]),{pixel_values:a,pixel_mask:l}=await this.processor(o),c=await this.model({pixel_values:a,pixel_mask:l}),p=this.processor.image_processor.post_process_object_detection(c,s,i),{id2label:u}=this.model.config,_=p.map(d=>d.boxes.map((m,h)=>({score:d.scores[h],label:u[d.classes[h]],box:bi(m,!r)})));return n?_:_[0]}};var Di=class extends Q{async _call(e,s,{threshold:r=.1,top_k:n=null,percentage:o=!1}={}){let i=Array.isArray(e),a=await Ae(e),l=this.tokenizer(s,{padding:!0,truncation:!0}),c=await this.processor(a),p=[];for(let u=0;u<a.length;++u){let _=a[u],d=o?null:[[_.height,_.width]],m=c.pixel_values[u].unsqueeze_(0),h=await this.model({...l,pixel_values:m}),g;if("post_process_grounded_object_detection"in this.processor){let x=this.processor.post_process_grounded_object_detection(h,l.input_ids,{box_threshold:r,text_threshold:r,target_sizes:d})[0];g=x.boxes.map((w,y)=>({score:x.scores[y],label:x.labels[y],box:bi(w,!o)}))}else{let x=this.processor.image_processor.post_process_object_detection(h,r,d,!0)[0];g=x.boxes.map((w,y)=>({score:x.scores[y],label:s[x.classes[y]],box:bi(w,!o)}))}g.sort((x,w)=>w.score-x.score),n!==null&&(g=g.slice(0,n)),p.push(g)}return i?p:p[0]}};var ji=class extends Q{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 Ae(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}),p=this.tokenizer.batch_decode(l)[0].match(/<s_answer>(.*?)<\/s_answer>/),u=null;return p&&p.length>=2&&(u=p[1].trim()),[{answer:u}]}};var Bi=class extends Q{async _call(e){let s=await Ae(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(ve.fromTensor(a))}return Array.isArray(e)?o:o[0]}};var qi=class extends Q{async _call(e){let s=await Ae(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),[p,u]=s[i].size,_=(await De(a.view(1,1,l,c),{size:[u,p],mode:"bilinear"})).view(u,p),d=_.min().item(),m=_.max().item(),h=_.sub(d).div_(m-d).mul_(255).to("uint8").unsqueeze(0),g=ve.fromTensor(h);o.push({predicted_depth:_,depth:g})}return Array.isArray(e)?o:o[0]}};var Ui=class extends Q{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=O0(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=z0(l,o)),l}};var Gi=class extends Q{async _call(e,{pool:s=null}={}){let r=await Ae(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 br=Object.freeze({"text-classification":{pipeline:ki,model:gi,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{pipeline:vi,model:ec,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{pipeline:Ei,model:ic,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{pipeline:Ai,model:oc,default:{model:"onnx-community/ettin-encoder-32m-ONNX",dtype:"fp32"},type:"text"},summarization:{pipeline:Mi,model:yr,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{pipeline:Si,model:yr,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{pipeline:kt,model:yr,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{pipeline:Oi,model:nc,default:{model:"onnx-community/Qwen3-0.6B-ONNX",dtype:"q4"},type:"text"},"zero-shot-classification":{pipeline:Ii,model:gi,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:zi,model:_c,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{pipeline:Ti,model:bt,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{pipeline:Ci,model:[tc,uc],default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{pipeline:Pi,model:[rc,sc],default:{model:"onnx-community/Supertonic-TTS-ONNX",dtype:"fp32"},type:"text"},"image-to-text":{pipeline:Li,model:ac,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:Ni,model:lc,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:vs,model:[xi,wi,yi],default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:Fi,model:[xi,wi,yi],default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{pipeline:$i,model:bt,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:Ri,model:cc,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{pipeline:Di,model:pc,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{pipeline:ji,model:dc,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:Bi,model:fc,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:qi,model:mc,default:{model:"onnx-community/depth-anything-v2-small"},type:"image"},"feature-extraction":{pipeline:Ui,model:bt,default:{model:"onnx-community/all-MiniLM-L6-v2-ONNX",dtype:"fp32"},type:"text"},"image-feature-extraction":{pipeline:Gi,model:[hc,bt],default:{model:"onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX",dtype:"fp32"},type:"image"}}),gc=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});function KA(t,{config:e=null,cache_dir:s=null,local_files_only:r=!1,revision:n="main"}={}){if(e!==null)return Ze.from_pretrained(t,{config:e,cache_dir:s,local_files_only:r,revision:n});let o=JSON.stringify([t,s,r,n]);return sa(o,()=>Ze.from_pretrained(t,{config:e,cache_dir:s,local_files_only:r,revision:n}))}async function xc(t,{config:e=null,dtype:s=null,device:r=null,model_file_name:n=null}={}){e=await KA(t,{config:e});let o=["config.json"],i=e["transformers.js_config"]??{},a=i.use_external_data_format,l="onnx",c=r??i.device,p=s??i.dtype,u,_=e.architectures||[],d=!1;for(let x of _){let w=lt.get(x);if(w!==void 0){u=w,d=!0;break}}if(!d&&e.model_type){let x=lt.get(e.model_type);if(x!==void 0&&(u=x,d=!0),!d){for(let w of Object.values(is))if(w.has(e.model_type)){u=lt.get(w.get(e.model_type)),d=!0;break}}}if(!d){let x=_.length>0?_.join(", "):"(none)";F.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: ${Tt}`),u=L.EncoderOnly}let m=(x,w=null)=>{w=w??x;let y=la(c,x),b=ca(p,x,y),E=Fr[b]??"",k=`${w}${E}.onnx`,O=l?`${l}/${k}`:k;o.push(O);let N=k_(a,k,x);for(let j of v_(k,N)){let C=l?`${l}/${j}`:j;o.push(C)}},{sessions:h,optional_configs:g}=nb(u,e,{model_file_name:n});for(let[x,w]of Object.entries(h))m(x,w);if(g)for(let x of Object.values(g))o.push(x);return o}async function wc(t){if(!t)throw new Error("modelId is required");return(await _t(t,yt,{})).exists?[yt]:[]}async function vt(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 xc(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 wc(t);a.push(...l)}return a}async function Et(t,e,s={}){t=gc[t]??t;let r=br[t];if(!r)throw new Error(`Unsupported pipeline task: ${t}. Must be one of [${Object.keys(br).join(", ")}]`);let{type:n}=r;return vt(e,{...s,include_tokenizer:n!=="audio"&&n!=="image",include_processor:n!=="text"})}async function _Q(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:p=null,model_file_name:u=null,session_options:_={}}={}){t=gc[t]??t;let d=br[t.split("_",1)[0]];if(!d)throw Error(`Unsupported pipeline: ${t}. Must be one of [${Object.keys(br)}]`);e||(e=d.default.model,F.info(`No model specified. Using default model: "${e}".`),!l&&d.default.dtype&&(l=d.default.dtype));let m=await Et(t,e,{device:a,dtype:l}),h={};s&&(await Promise.all(m.map(async R=>_t(e,R)))).forEach((R,$)=>{R.exists&&(h[m[$]]={loaded:0,total:R.size??0})});let g={progress_callback:s?C=>{if(C.status==="progress"){h[C.file]={loaded:C.loaded,total:C.total};let R=Object.values(h).reduce((B,G)=>B+G.loaded,0),$=Object.values(h).reduce((B,G)=>B+G.total,0),q=$>0?R/$*100:0;s({status:"progress_total",name:C.name,progress:q,loaded:R,total:$,files:structuredClone(h)})}s(C)}:void 0,config:r,cache_dir:n,local_files_only:o,revision:i,device:a,dtype:l,subfolder:c,use_external_data_format:p,model_file_name:u,session_options:_},x=m.includes("tokenizer.json"),w=m.includes("preprocessor_config.json"),y=d.model,b;if(Array.isArray(y)){let C=r??await Ze.from_pretrained(e,g),{model_type:R}=C,$=y.find(q=>q.supports(R));if(!$)throw Error(`Unsupported model type "${R}" for task "${t}". None of the candidate model classes support this type.`);b=$.from_pretrained(e,{...g,config:C})}else b=y.from_pretrained(e,g);let[E,k,O]=await Promise.all([x?W.from_pretrained(e,g):null,w?ja.from_pretrained(e,g):null,b]),N={task:t,model:O};E&&(N.tokenizer=E),k&&(N.processor=k),gt(s,{status:"ready",task:t,model:e});let j=d.pipeline;return new j(N)}var XA=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,sy=class{put(e){throw Error("Not implemented")}end(){throw Error("Not implemented")}},Xb=V.IS_PROCESS_AVAILABLE?t=>process.stdout.write(t):t=>console.log(t),ry=class extends sy{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??Xb,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=Fe(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&&XA(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===Xb&&V.IS_PROCESS_AVAILABLE&&this.callback_function?.(`
24
+ `)}},Qb=class extends ry{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:p={}}={}){super(e,{skip_prompt:s,skip_special_tokens:c,callback_function:r,token_callback_function:n,decode_kwargs:p}),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 Wi=class{constructor(e,s){this.image=e,this.timestamp=s}},yc=class{constructor(e,s){e.length>0&&e[0]instanceof ve&&(e=e.map((r,n)=>new Wi(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 QA(t,{num_frames:e=null,fps:s=null}={}){if(!V.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(u=>n.onloadedmetadata=u),n.seekable.start(0)===n.seekable.end(0)){let _=await(await Y.fetch(n.src)).blob();n.src=URL.createObjectURL(_),await new Promise(d=>n.onloadedmetadata=d)}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 u=0;u<i;++u)l.push(e===1?o/2:u*a);let c=document.createElement("canvas");c.width=n.videoWidth,c.height=n.videoHeight;let p=c.getContext("2d",{willReadFrequently:!0});for(let u of l){n.currentTime=u,await new Promise(h=>{n.onseeked=h}),p.drawImage(n,0,0,c.width,c.height);let _=p.getImageData(0,0,c.width,c.height),d=new ve(_.data,c.width,c.height,4),m=new Wi(d,u);r.push(m)}return n.remove(),new yc(r,o)}async function bc(t,e,s={}){let r=await it(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}=Ot(t,o,s,r),l=await It(r,i,a);return{file:o,cached:!!l}}));return{allCached:n.every(o=>o.cached),files:n}}async function Yb(t,e,s={}){let r=await it(s?.cache_dir);if(!r)return!1;let{localPath:n,proposedCacheKey:o}=Ot(t,e,s,r);return!!await It(r,n,o)}async function Jb(t,e={}){if(!t)throw new Error("modelId is required");if(!await Yb(t,"config.json",e))return!1;let s=await vt(t,e);return(await bc(t,s,e)).allCached}async function Zb(t,e={}){if(!t)throw new Error("modelId is required");let s=await vt(t,e);return await bc(t,s,e)}async function e1(t,e,s={}){if(!t)throw new Error("task is required");if(!e)throw new Error("modelId is required");if(!await Yb(e,"config.json",s))return!1;let r=await Et(t,e,s);return(await bc(e,r,s)).allCached}async function t1(t,e,s={}){if(!t)throw new Error("task is required");if(!e)throw new Error("modelId is required");let r=await Et(t,e,s);return await bc(e,r,s)}async function s1(t,e,s={}){let r=await it(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}=Ot(t,o,s,r),c=!!await It(r,i,a),p=!1;if(c){let u=await r.delete(a),_=!u&&a!==i?await r.delete(i):!1;p=u||_}return{file:o,deleted:p,wasCached:c}}));return{filesDeleted:n.filter(o=>o.deleted).length,filesCached:n.filter(o=>o.wasCached).length,files:n}}async function r1(t,e={}){if(!t)throw new Error("modelId is required");let s=await vt(t,e);return await s1(t,s,e)}async function n1(t,e,s={}){if(!t)throw new Error("task is required");if(!e)throw new Error("modelId is required");let r=await Et(t,e,s);return await s1(e,r,s)}var ny=class{static async get_files(e,s={}){return vt(e,s)}static async get_pipeline_files(e,s,r={}){return Et(e,s,r)}static async get_model_files(e,s={}){return xc(e,s)}static async get_tokenizer_files(e){return Ns(e)}static async get_processor_files(e){return wc(e)}static async is_cached(e,s={}){return Jb(e,s)}static async is_cached_files(e,s={}){return Zb(e,s)}static async is_pipeline_cached(e,s,r={}){return e1(e,s,r)}static async is_pipeline_cached_files(e,s,r={}){return t1(e,s,r)}static async get_file_metadata(e,s,r={}){return _t(e,s,r)}static async clear_cache(e,s={}){return r1(e,s)}static async clear_pipeline_cache(e,s,r={}){return n1(e,s,r)}};export{Wp as ASTFeatureExtractor,q_ as ASTForAudioClassification,B_ as ASTModel,nn as ASTPreTrainedModel,R_ as AfmoeForCausalLM,$_ as AfmoeModel,sn as AfmoePreTrainedModel,L_ as AlbertForMaskedLM,P_ as AlbertForQuestionAnswering,C_ as AlbertForSequenceClassification,T_ as AlbertModel,ls as AlbertPreTrainedModel,Jc as AlbertTokenizer,F_ as ApertusForCausalLM,N_ as ApertusModel,tn as ApertusPreTrainedModel,j_ as ArceeForCausalLM,D_ as ArceeModel,rn as ArceePreTrainedModel,zi as AudioClassificationPipeline,Ze as AutoConfig,be as AutoFeatureExtractor,ue as AutoImageProcessor,bt as AutoModel,_c as AutoModelForAudioClassification,Bb as AutoModelForAudioFrameClassification,Vb as AutoModelForAudioTextToText,uc as AutoModelForCTC,nc as AutoModelForCausalLM,mc as AutoModelForDepthEstimation,dc as AutoModelForDocumentQuestionAnswering,lc as AutoModelForImageClassification,hc as AutoModelForImageFeatureExtraction,qb as AutoModelForImageMatting,xi as AutoModelForImageSegmentation,Wb as AutoModelForImageTextToText,fc as AutoModelForImageToImage,Db as AutoModelForMaskGeneration,oc as AutoModelForMaskedLM,Ub as AutoModelForNormalEstimation,cc as AutoModelForObjectDetection,Gb as AutoModelForPoseEstimation,ic as AutoModelForQuestionAnswering,wi as AutoModelForSemanticSegmentation,yr as AutoModelForSeq2SeqLM,gi as AutoModelForSequenceClassification,tc as AutoModelForSpeechSeq2Seq,sc as AutoModelForTextToSpectrogram,rc as AutoModelForTextToWaveform,ec as AutoModelForTokenClassification,yi as AutoModelForUniversalSegmentation,ac as AutoModelForVision2Seq,jb as AutoModelForXVector,pc as AutoModelForZeroShotObjectDetection,ja as AutoProcessor,W as AutoTokenizer,Ci as AutomaticSpeechRecognitionPipeline,Fi as BackgroundRemovalPipeline,G_ as BartForConditionalGeneration,W_ as BartForSequenceClassification,U_ as BartModel,Js as BartPretrainedModel,Zc as BartTokenizer,sy as BaseStreamer,au as BeitFeatureExtractor,H_ as BeitForImageClassification,V_ as BeitModel,on as BeitPreTrainedModel,X_ as BertForMaskedLM,J_ as BertForQuestionAnswering,Q_ as BertForSequenceClassification,Y_ as BertForTokenClassification,K_ as BertModel,Nt as BertPreTrainedModel,ep as BertTokenizer,lu as BitImageProcessor,ed as BlenderbotForConditionalGeneration,Z_ as BlenderbotModel,an as BlenderbotPreTrainedModel,sd as BlenderbotSmallForConditionalGeneration,td as BlenderbotSmallModel,ln as BlenderbotSmallPreTrainedModel,tp as BlenderbotSmallTokenizer,sp as BlenderbotTokenizer,nd as BloomForCausalLM,rd as BloomModel,cn as BloomPreTrainedModel,rp as BloomTokenizer,ud as CHMv2ForDepthEstimation,pu as CHMv2ImageProcessor,ol as CHMv2PreTrainedModel,uu as CLIPFeatureExtractor,ya as CLIPImageProcessor,dd as CLIPModel,mt as CLIPPreTrainedModel,xd as CLIPSegForImageSegmentation,gd as CLIPSegModel,fn as CLIPSegPreTrainedModel,fd as CLIPTextModel,dn as CLIPTextModelWithProjection,op as CLIPTokenizer,md as CLIPVisionModel,hd as CLIPVisionModelWithProjection,id as CamembertForMaskedLM,cd as CamembertForQuestionAnswering,ad as CamembertForSequenceClassification,ld as CamembertForTokenClassification,od as CamembertModel,Ft as CamembertPreTrainedModel,np as CamembertTokenizer,Vp as ChatterboxFeatureExtractor,pn as ChatterboxModel,rl as ChatterboxPreTrainedModel,ou as ChatterboxProcessor,cu as ChineseCLIPFeatureExtractor,pd as ChineseCLIPModel,nl as ChineseCLIPPreTrainedModel,_n as ClapAudioModelWithProjection,Hp as ClapFeatureExtractor,_d as ClapModel,Zs as ClapPreTrainedModel,un as ClapTextModelWithProjection,Qa as ClassifierFreeGuidanceLogitsProcessor,yd as CodeGenForCausalLM,wd as CodeGenModel,mn as CodeGenPreTrainedModel,ap as CodeGenTokenizer,ip as CodeLlamaTokenizer,Ed as Cohere2ForCausalLM,vd as Cohere2Model,gn as Cohere2PreTrainedModel,kd as CohereForCausalLM,bd as CohereModel,hn as CoherePreTrainedModel,lp as CohereTokenizer,Md as ConvBertForMaskedLM,Id as ConvBertForQuestionAnswering,Sd as ConvBertForSequenceClassification,Od as ConvBertForTokenClassification,Ad as ConvBertModel,$t as ConvBertPreTrainedModel,cp as ConvBertTokenizer,_u as ConvNextFeatureExtractor,Td as ConvNextForImageClassification,ba as ConvNextImageProcessor,zd as ConvNextModel,xn as ConvNextPreTrainedModel,Pd as ConvNextV2ForImageClassification,Cd as ConvNextV2Model,wn as ConvNextV2PreTrainedModel,$d as DFineForObjectDetection,Fd as DFineModel,bn as DFinePreTrainedModel,pf as DINOv3ConvNextModel,_l as DINOv3ConvNextPreTrainedModel,mu as DINOv3ViTImageProcessor,uf as DINOv3ViTModel,dl as DINOv3ViTPreTrainedModel,gu as DPTFeatureExtractor,wf as DPTForDepthEstimation,Ea as DPTImageProcessor,xf as DPTModel,On as DPTPreTrainedModel,vn as DacDecoderModel,al as DacDecoderOutput,kn as DacEncoderModel,il as DacEncoderOutput,Gr as DacFeatureExtractor,Rd as DacModel,er as DacPreTrainedModel,jd as DebertaForMaskedLM,Ud as DebertaForQuestionAnswering,Bd as DebertaForSequenceClassification,qd as DebertaForTokenClassification,Dd as DebertaModel,Rt as DebertaPreTrainedModel,up as DebertaTokenizer,Hd as DebertaV2ForMaskedLM,Qd as DebertaV2ForQuestionAnswering,Kd as DebertaV2ForSequenceClassification,Xd as DebertaV2ForTokenClassification,Vd as DebertaV2Model,Dt as DebertaV2PreTrainedModel,pp as DebertaV2Tokenizer,Yd as DecisionTransformerModel,ll as DecisionTransformerPreTrainedModel,Wd as DeepseekV3ForCausalLM,Gd as DeepseekV3Model,En as DeepseekV3PreTrainedModel,du as DeiTFeatureExtractor,Zd as DeiTForImageClassification,ka as DeiTImageProcessor,Jd as DeiTModel,An as DeiTPreTrainedModel,ef as DepthAnythingForDepthEstimation,cl as DepthAnythingPreTrainedModel,qi as DepthEstimationPipeline,tf as DepthProForDepthEstimation,pl as DepthProPreTrainedModel,fu as DetrFeatureExtractor,rf as DetrForObjectDetection,nf as DetrForSegmentation,va as DetrImageProcessor,sf as DetrModel,sr as DetrObjectDetectionOutput,tr as DetrPreTrainedModel,ul as DetrSegmentationOutput,af as Dinov2ForImageClassification,of as Dinov2Model,Mn as Dinov2PreTrainedModel,cf as Dinov2WithRegistersForImageClassification,lf as Dinov2WithRegistersModel,Sn as Dinov2WithRegistersPreTrainedModel,hf as DistilBertForMaskedLM,mf as DistilBertForQuestionAnswering,df as DistilBertForSequenceClassification,ff as DistilBertForTokenClassification,_f as DistilBertModel,jt as DistilBertPreTrainedModel,_p as DistilBertTokenizer,ji as DocumentQuestionAnsweringPipeline,hu as DonutFeatureExtractor,Rs as DonutImageProcessor,gf as DonutSwinModel,fl as DonutSwinPreTrainedModel,Jr as DynamicCache,Ax as EdgeTamModel,bf as EfficientNetForImageClassification,xu as EfficientNetImageProcessor,yf as EfficientNetModel,In as EfficientNetPreTrainedModel,vf as ElectraForMaskedLM,Mf as ElectraForQuestionAnswering,Ef as ElectraForSequenceClassification,Af as ElectraForTokenClassification,kf as ElectraModel,Bt as ElectraPreTrainedModel,dp as ElectraTokenizer,Ur as EncodecFeatureExtractor,Za as EosTokenCriteria,Of as Ernie4_5ForCausalLM,Sf as Ernie4_5Model,zn as Ernie4_5PretrainedModel,zf as EsmForMaskedLM,Tf as EsmForSequenceClassification,Cf as EsmForTokenClassification,If as EsmModel,cs as EsmPreTrainedModel,fp as EsmTokenizer,Lf as EuroBertForMaskedLM,Nf as EuroBertForSequenceClassification,Ff as EuroBertForTokenClassification,Pf as EuroBertModel,ps as EuroBertPreTrainedModel,Rf as ExaoneForCausalLM,$f as ExaoneModel,Tn as ExaonePreTrainedModel,jf as FalconForCausalLM,qf as FalconH1ForCausalLM,Bf as FalconH1Model,Pn as FalconH1PreTrainedModel,Df as FalconModel,Cn as FalconPreTrainedModel,mp as FalconTokenizer,Gf as FastViTForImageClassification,Uf as FastViTModel,Ln as FastViTPreTrainedModel,Ui as FeatureExtractionPipeline,ae as FeatureExtractor,Ai as FillMaskPipeline,Wf as Florence2ForConditionalGeneration,ml as Florence2PreTrainedModel,Qu as Florence2Processor,qa as ForcedBOSTokenLogitsProcessor,Ua as ForcedEOSTokenLogitsProcessor,yu as GLPNFeatureExtractor,nm as GLPNForDepthEstimation,rm as GLPNModel,Bn as GLPNPreTrainedModel,fm as GPT2LMHeadModel,dm as GPT2Model,Vn as GPT2PreTrainedModel,xp as GPT2Tokenizer,im as GPTBigCodeForCausalLM,om as GPTBigCodeModel,qn as GPTBigCodePreTrainedModel,hm as GPTJForCausalLM,mm as GPTJModel,Hn as GPTJPreTrainedModel,lm as GPTNeoForCausalLM,am as GPTNeoModel,Un as GPTNeoPreTrainedModel,pm as GPTNeoXForCausalLM,cm as GPTNeoXModel,Gn as GPTNeoXPreTrainedModel,gp as GPTNeoXTokenizer,Xf as Gemma2ForCausalLM,Kf as Gemma2Model,Fn as Gemma2PreTrainedModel,Yf as Gemma3ForCausalLM,Qf as Gemma3Model,$n as Gemma3PreTrainedModel,Kp as Gemma3nAudioFeatureExtractor,Rn as Gemma3nForCausalLM,rr as Gemma3nForConditionalGeneration,hl as Gemma3nPreTrainedModel,Yu as Gemma3nProcessor,Hf as GemmaForCausalLM,Vf as GemmaModel,Nn as GemmaPreTrainedModel,hp as GemmaTokenizer,wu as Glm46VImageProcessor,Ju as Glm46VProcessor,Zf as GlmForCausalLM,Jf as GlmModel,tm as GlmMoeDsaForCausalLM,em as GlmMoeDsaModel,jn as GlmMoeDsaPreTrainedModel,sm as GlmOcrForConditionalGeneration,Dn as GlmPreTrainedModel,_m as GptOssForCausalLM,um as GptOssModel,Wn as GptOssPreTrainedModel,xm as GraniteForCausalLM,gm as GraniteModel,ym as GraniteMoeHybridForCausalLM,wm as GraniteMoeHybridModel,Xn as GraniteMoeHybridPreTrainedModel,Kn as GranitePreTrainedModel,Xp as GraniteSpeechFeatureExtractor,bm as GraniteSpeechForConditionalGeneration,Zu as GraniteSpeechProcessor,km as GroundingDinoForObjectDetection,bu as GroundingDinoImageProcessor,wl as GroundingDinoPreTrainedModel,e_ as GroundingDinoProcessor,vm as GroupViTModel,yl as GroupViTPreTrainedModel,Am as HeliumForCausalLM,Em as HeliumModel,Qn as HeliumPreTrainedModel,wp as HerbertTokenizer,Sm as HieraForImageClassification,Mm as HieraModel,Yn as HieraPreTrainedModel,Lm as HubertForCTC,Nm as HubertForSequenceClassification,Pm as HubertModel,Cm as HubertPreTrainedModel,$m as HunYuanDenseV1ForCausalLM,Fm as HunYuanDenseV1Model,Jn as HunYuanDenseV1PreTrainedModel,qm as IJepaForImageClassification,Bm as IJepaModel,Zn as IJepaPreTrainedModel,jm as Idefics3ForConditionalGeneration,Aa as Idefics3ImageProcessor,Na as Idefics3Processor,Ni as ImageClassificationPipeline,Gi as ImageFeatureExtractionPipeline,P as ImageFeatureExtractor,P as ImageProcessor,vs as ImageSegmentationPipeline,Bi as ImageToImagePipeline,Li as ImageToTextPipeline,tb as InterruptableStoppingCriteria,Gm as JAISLMHeadModel,Um as JAISModel,eo as JAISPreTrainedModel,vu as JinaCLIPImageProcessor,Wm as JinaCLIPModel,or as JinaCLIPPreTrainedModel,s_ as JinaCLIPProcessor,to as JinaCLIPTextModel,Vm as JinaCLIPVisionModel,Km as Lfm2ForCausalLM,Hm as Lfm2Model,Ym as Lfm2MoeForCausalLM,Qm as Lfm2MoeModel,ro as Lfm2MoePreTrainedModel,so as Lfm2PreTrainedModel,Jm as Lfm2VlForConditionalGeneration,Eu as Lfm2VlImageProcessor,r_ as Lfm2VlProcessor,Xm as LightOnOcrForConditionalGeneration,jw as LiteWhisperForConditionalGeneration,th as Llama4ForCausalLM,kl as Llama4PreTrainedModel,eh as LlamaForCausalLM,Zm as LlamaModel,no as LlamaPreTrainedModel,yp as LlamaTokenizer,Ge as LlavaForConditionalGeneration,Ge as LlavaOnevisionForConditionalGeneration,Au as LlavaOnevisionImageProcessor,bl as LlavaPreTrainedModel,n_ as LlavaProcessor,Dm as LlavaQwen2ForCausalLM,Be as LogLevel,et as LogitsProcessor,ns as LogitsProcessorList,Yr as LogitsWarper,rh as LongT5ForConditionalGeneration,sh as LongT5Model,oo as LongT5PreTrainedModel,oh as M2M100ForConditionalGeneration,nh as M2M100Model,io as M2M100PreTrainedModel,bp as M2M100Tokenizer,vp as MBart50Tokenizer,dh as MBartForCausalLM,uh as MBartForConditionalGeneration,_h as MBartForSequenceClassification,ph as MBartModel,ms as MBartPreTrainedModel,Dr as MBartTokenizer,Zh as MPNetForMaskedLM,sg as MPNetForQuestionAnswering,eg as MPNetForSequenceClassification,tg as MPNetForTokenClassification,Jh as MPNetModel,qt as MPNetPreTrainedModel,Mp as MPNetTokenizer,ig as MT5ForConditionalGeneration,og as MT5Model,yo as MT5PreTrainedModel,ah as MarianMTModel,ih as MarianModel,ao as MarianPreTrainedModel,kp as MarianTokenizer,Su as Mask2FormerImageProcessor,Mu as MaskFormerFeatureExtractor,ch as MaskFormerForInstanceSegmentation,Ds as MaskFormerImageProcessor,lh as MaskFormerModel,lo as MaskFormerPreTrainedModel,Ja as MaxLengthCriteria,fh as Metric3DForDepthEstimation,vl as Metric3DPreTrainedModel,mh as Metric3Dv2ForDepthEstimation,El as Metric3Dv2PreTrainedModel,hh as MgpstrForSceneTextRecognition,Al as MgpstrModelOutput,Ml as MgpstrPreTrainedModel,o_ as MgpstrProcessor,Ep as MgpstrTokenizer,po as MimiDecoderModel,Ol as MimiDecoderOutput,co as MimiEncoderModel,Sl as MimiEncoderOutput,gh as MimiModel,ir as MimiPreTrainedModel,Ha as MinLengthLogitsProcessor,Ka as MinNewTokensLengthLogitsProcessor,bh as Mistral4ForCausalLM,yh as Mistral4Model,_o as Mistral4PreTrainedModel,wh as MistralForCausalLM,xh as MistralModel,uo as MistralPreTrainedModel,vh as MobileBertForMaskedLM,Ah as MobileBertForQuestionAnswering,Eh as MobileBertForSequenceClassification,kh as MobileBertModel,hs as MobileBertPreTrainedModel,Ap as MobileBertTokenizer,Sh as MobileLLMForCausalLM,Mh as MobileLLMModel,fo as MobileLLMPreTrainedModel,Ou as MobileNetV1FeatureExtractor,Ih as MobileNetV1ForImageClassification,zh as MobileNetV1ForSemanticSegmentation,Ma as MobileNetV1ImageProcessor,Oh as MobileNetV1Model,ar as MobileNetV1PreTrainedModel,Iu as MobileNetV2FeatureExtractor,Ch as MobileNetV2ForImageClassification,Ph as MobileNetV2ForSemanticSegmentation,Sa as MobileNetV2ImageProcessor,Th as MobileNetV2Model,lr as MobileNetV2PreTrainedModel,zu as MobileNetV3FeatureExtractor,Nh as MobileNetV3ForImageClassification,Fh as MobileNetV3ForSemanticSegmentation,Oa as MobileNetV3ImageProcessor,Lh as MobileNetV3Model,cr as MobileNetV3PreTrainedModel,Tu as MobileNetV4FeatureExtractor,Rh as MobileNetV4ForImageClassification,Dh as MobileNetV4ForSemanticSegmentation,Ia as MobileNetV4ImageProcessor,$h as MobileNetV4Model,pr as MobileNetV4PreTrainedModel,Cu as MobileViTFeatureExtractor,Bh as MobileViTForImageClassification,za as MobileViTImageProcessor,jh as MobileViTModel,mo as MobileViTPreTrainedModel,Uh as MobileViTV2ForImageClassification,qh as MobileViTV2Model,ho as MobileViTV2PreTrainedModel,ny as ModelRegistry,Xh as ModernBertDecoderForCausalLM,Kh as ModernBertDecoderModel,go as ModernBertDecoderPreTrainedModel,Wh as ModernBertForMaskedLM,Vh as ModernBertForSequenceClassification,Hh as ModernBertForTokenClassification,Gh as ModernBertModel,gs as ModernBertPreTrainedModel,Rm as Moondream1ForConditionalGeneration,Qp as MoonshineFeatureExtractor,Yh as MoonshineForConditionalGeneration,Qh as MoonshineModel,xo as MoonshinePreTrainedModel,i_ as MoonshineProcessor,ng as MptForCausalLM,rg as MptModel,wo as MptPreTrainedModel,ag as MultiModalityCausalLM,Il as MultiModalityPreTrainedModel,cg as MusicgenForCausalLM,ko as MusicgenForConditionalGeneration,lg as MusicgenModel,bo as MusicgenPreTrainedModel,ug as NanoChatForCausalLM,pg as NanoChatModel,vo as NanoChatPreTrainedModel,dg as NemotronHForCausalLM,_g as NemotronHModel,Eo as NemotronHPreTrainedModel,mg as NeoBertForMaskedLM,xg as NeoBertForQuestionAnswering,hg as NeoBertForSequenceClassification,gg as NeoBertForTokenClassification,fg as NeoBertModel,Ut as NeoBertPreTrainedModel,Sp as NllbTokenizer,Xa as NoBadWordsLogitsProcessor,Wa as NoRepeatNGramLogitsProcessor,wg as NomicBertModel,zl as NomicBertPreTrainedModel,Pu as NougatImageProcessor,Op as NougatTokenizer,Tg as OPTForCausalLM,zg as OPTModel,zo as OPTPreTrainedModel,Ri as ObjectDetectionPipeline,vg as Olmo2ForCausalLM,kg as Olmo2Model,Mo as Olmo2PreTrainedModel,Ag as Olmo3ForCausalLM,Eg as Olmo3Model,So as Olmo3PreTrainedModel,bg as OlmoForCausalLM,Sg as OlmoHybridForCausalLM,Mg as OlmoHybridModel,Oo as OlmoHybridPreTrainedModel,yg as OlmoModel,Ao as OlmoPreTrainedModel,Ig as OpenELMForCausalLM,Og as OpenELMModel,Io as OpenELMPreTrainedModel,Lu as OwlViTFeatureExtractor,Ng as OwlViTForObjectDetection,js as OwlViTImageProcessor,Lg as OwlViTModel,Co as OwlViTPreTrainedModel,a_ as OwlViTProcessor,Pg as Owlv2ForObjectDetection,Nu as Owlv2ImageProcessor,Cg as Owlv2Model,To as Owlv2PreTrainedModel,Fg as PaliGemmaForConditionalGeneration,l_ as PaliGemmaProcessor,Yp as ParakeetFeatureExtractor,$g as ParakeetForCTC,Tl as ParakeetPreTrainedModel,Dg as PatchTSMixerForPrediction,Rg as PatchTSMixerModel,Po as PatchTSMixerPreTrainedModel,Bg as PatchTSTForPrediction,jg as PatchTSTModel,Lo as PatchTSTPreTrainedModel,Wg as Phi3ForCausalLM,Gg as Phi3Model,Fo as Phi3PreTrainedModel,$o as Phi3VForCausalLM,Ru as Phi3VImageProcessor,Cl as Phi3VPreTrainedModel,c_ as Phi3VProcessor,Ug as PhiForCausalLM,qg as PhiModel,No as PhiPreTrainedModel,Du as PixtralImageProcessor,p_ as PixtralProcessor,f as PreTrainedModel,T as PreTrainedTokenizer,Ws as PretrainedConfig,U as Processor,Hg as PvtForImageClassification,ju as PvtImageProcessor,Vg as PvtModel,Ro as PvtPreTrainedModel,Wr as PyAnnoteFeatureExtractor,Xg as PyAnnoteForAudioFrameClassification,Kg as PyAnnoteModel,Do as PyAnnotePreTrainedModel,u_ as PyAnnoteProcessor,Ei as QuestionAnsweringPipeline,Yg as Qwen2ForCausalLM,Qg as Qwen2Model,Zg as Qwen2MoeForCausalLM,Jg as Qwen2MoeModel,Bo as Qwen2MoePreTrainedModel,jo as Qwen2PreTrainedModel,Ip as Qwen2Tokenizer,us as Qwen2VLForCausalLM,nr as Qwen2VLForConditionalGeneration,Hr as Qwen2VLImageProcessor,gl as Qwen2VLPreTrainedModel,ss as Qwen2VLProcessor,ds as Qwen2_5_VLForCausalLM,_s as Qwen2_5_VLForConditionalGeneration,Xr as Qwen2_5_VLProcessor,tx as Qwen3ForCausalLM,ex as Qwen3Model,rx as Qwen3MoeForCausalLM,sx as Qwen3MoeModel,Uo as Qwen3MoePreTrainedModel,ox as Qwen3NextForCausalLM,nx as Qwen3NextModel,Go as Qwen3NextPreTrainedModel,qo as Qwen3PreTrainedModel,ws as Qwen3VLForCausalLM,xs as Qwen3VLForConditionalGeneration,Wo as Qwen3VLMoeForCausalLM,ix as Qwen3VLMoeForConditionalGeneration,__ as Qwen3VLProcessor,ys as Qwen3_5ForCausalLM,ur as Qwen3_5ForConditionalGeneration,Vo as Qwen3_5MoeForCausalLM,ax as Qwen3_5MoeForConditionalGeneration,ux as RFDetrForObjectDetection,px as RFDetrModel,Pl as RFDetrObjectDetectionOutput,Ko as RFDetrPreTrainedModel,Nd as RTDetrForObjectDetection,Bu as RTDetrImageProcessor,Ld as RTDetrModel,ht as RTDetrObjectDetectionOutput,yn as RTDetrPreTrainedModel,vx as RTDetrV2ForObjectDetection,kx as RTDetrV2Model,Ll as RTDetrV2ObjectDetectionOutput,Xo as RTDetrV2PreTrainedModel,qr as RawAudio,ve as RawImage,yc as RawVideo,Wi as RawVideoFrame,Va as RepetitionPenaltyLogitsProcessor,cx as ResNetForImageClassification,lx as ResNetModel,Ho as ResNetPreTrainedModel,xx as RoFormerForMaskedLM,bx as RoFormerForQuestionAnswering,wx as RoFormerForSequenceClassification,yx as RoFormerForTokenClassification,gx as RoFormerModel,Wt as RoFormerPreTrainedModel,Tp as RoFormerTokenizer,dx as RobertaForMaskedLM,hx as RobertaForQuestionAnswering,fx as RobertaForSequenceClassification,mx as RobertaForTokenClassification,_x as RobertaModel,Gt as RobertaPreTrainedModel,zp as RobertaTokenizer,Kr as Sam2ImageProcessor,$l as Sam2ImageSegmentationOutput,Qo as Sam2Model,Rl as Sam2PreTrainedModel,Fa as Sam2Processor,d_ as Sam2VideoProcessor,Kr as Sam3ImageProcessor,Mx as Sam3TrackerModel,Kr as SamImageProcessor,Nl as SamImageSegmentationOutput,Ex as SamModel,Fl as SamPreTrainedModel,Qr as SamProcessor,qu as SapiensFeatureExtractor,Ox as SapiensForDepthEstimation,Ix as SapiensForNormalEstimation,Sx as SapiensForSemanticSegmentation,Ta as SapiensImageProcessor,_r as SapiensPreTrainedModel,Jp as SeamlessM4TFeatureExtractor,Uu as SegformerFeatureExtractor,Tx as SegformerForImageClassification,Cx as SegformerForSemanticSegmentation,Ca as SegformerImageProcessor,zx as SegformerModel,dr as SegformerPreTrainedModel,Gu as SiglipImageProcessor,Px as SiglipModel,Yo as SiglipPreTrainedModel,Jo as SiglipTextModel,Cp as SiglipTokenizer,Lx as SiglipVisionModel,Fx as SmolLM3ForCausalLM,Nx as SmolLM3Model,Zo as SmolLM3PreTrainedModel,Aa as SmolVLMImageProcessor,Na as SmolVLMProcessor,ti as SnacDecoderModel,ei as SnacEncoderModel,Zp as SnacFeatureExtractor,$x as SnacModel,fr as SnacPreTrainedModel,Dx as SolarOpenForCausalLM,Rx as SolarOpenModel,si as SolarOpenPreTrainedModel,eu as SpeechT5FeatureExtractor,Bx as SpeechT5ForSpeechToText,qx as SpeechT5ForTextToSpeech,Ux as SpeechT5HifiGan,jx as SpeechT5Model,mr as SpeechT5PreTrainedModel,f_ as SpeechT5Processor,Pp as SpeechT5Tokenizer,Wx as SqueezeBertForMaskedLM,Hx as SqueezeBertForQuestionAnswering,Vx as SqueezeBertForSequenceClassification,Gx as SqueezeBertModel,bs as SqueezeBertPreTrainedModel,Lp as SqueezeBertTokenizer,Xx as StableLmForCausalLM,Kx as StableLmModel,ri as StableLmPreTrainedModel,Yx as Starcoder2ForCausalLM,Qx as Starcoder2Model,ni as Starcoder2PreTrainedModel,Lt as StoppingCriteria,Ks as StoppingCriteriaList,Jx as StyleTextToSpeech2Model,Dl as StyleTextToSpeech2PreTrainedModel,Mi as SummarizationPipeline,oi as SupertonicForConditionalGeneration,jl as SupertonicPreTrainedModel,Vs as SuppressTokensAtBeginLogitsProcessor,rw as Swin2SRForImageSuperResolution,Wu as Swin2SRImageProcessor,sw as Swin2SRModel,ii as Swin2SRPreTrainedModel,ew as SwinForImageClassification,tw as SwinForSemanticSegmentation,Zx as SwinModel,hr as SwinPreTrainedModel,ow as T5ForConditionalGeneration,nw as T5Model,ai as T5PreTrainedModel,Np as T5Tokenizer,aw as TableTransformerForObjectDetection,iw as TableTransformerModel,Bl as TableTransformerObjectDetectionOutput,li as TableTransformerPreTrainedModel,Ya as TemperatureLogitsWarper,v as Tensor,kt as Text2TextGenerationPipeline,ki as TextClassificationPipeline,Oi as TextGenerationPipeline,ry as TextStreamer,Pi as TextToAudioPipeline,vi as TokenClassificationPipeline,T as TokenizersBackend,eb as TopKLogitsWarper,Z0 as TopPLogitsWarper,lw as TrOCRForCausalLM,ql as TrOCRPreTrainedModel,Si as TranslationPipeline,fs as UltravoxModel,xl as UltravoxPreTrainedModel,m_ as UltravoxProcessor,pw as UniSpeechForCTC,uw as UniSpeechForSequenceClassification,cw as UniSpeechModel,gr as UniSpeechPreTrainedModel,mw as UniSpeechSatForAudioFrameClassification,dw as UniSpeechSatForCTC,fw as UniSpeechSatForSequenceClassification,_w as UniSpeechSatModel,ks as UniSpeechSatPreTrainedModel,t_ as VLChatProcessor,ku as VLMImageProcessor,gw as VaultGemmaForCausalLM,hw as VaultGemmaModel,ci as VaultGemmaPreTrainedModel,Vu as ViTFeatureExtractor,yw as ViTForImageClassification,Pa as ViTImageProcessor,bw as ViTMAEModel,Ul as ViTMAEPreTrainedModel,vw as ViTMSNForImageClassification,kw as ViTMSNModel,ui as ViTMSNPreTrainedModel,ww as ViTModel,pi as ViTPreTrainedModel,xw as VisionEncoderDecoderModel,Ew as VitMatteForImageMatting,Hu as VitMatteImageProcessor,Gl as VitMattePreTrainedModel,Aw as VitPoseForPoseEstimation,Ku as VitPoseImageProcessor,Wl as VitPosePreTrainedModel,Mw as VitsModel,Vl as VitsModelOutput,Hl as VitsPreTrainedModel,$p as VitsTokenizer,Sw as VoxtralForConditionalGeneration,h_ as VoxtralProcessor,ru as VoxtralRealtimeFeatureExtractor,_i as VoxtralRealtimeForConditionalGeneration,Kl as VoxtralRealtimePreTrainedModel,x_ as VoxtralRealtimeProcessor,Tw as Wav2Vec2BertForCTC,Cw as Wav2Vec2BertForSequenceClassification,zw as Wav2Vec2BertModel,xr as Wav2Vec2BertPreTrainedModel,Rp as Wav2Vec2CTCTokenizer,tu as Wav2Vec2FeatureExtractor,Tm as Wav2Vec2ForAudioFrameClassification,Im as Wav2Vec2ForCTC,zm as Wav2Vec2ForSequenceClassification,Om as Wav2Vec2Model,ct as Wav2Vec2PreTrainedModel,w_ as Wav2Vec2Processor,y_ as Wav2Vec2ProcessorWithLM,$w as WavLMForAudioFrameClassification,Lw as WavLMForCTC,Nw as WavLMForSequenceClassification,Fw as WavLMForXVector,Pw as WavLMModel,Vt as WavLMPreTrainedModel,su as WeSpeakerFeatureExtractor,Rw as WeSpeakerResNetModel,Ql as WeSpeakerResNetPreTrainedModel,nu as WhisperFeatureExtractor,Jl as WhisperForConditionalGeneration,Dw as WhisperModel,di as WhisperPreTrainedModel,b_ as WhisperProcessor,Qb as WhisperTextStreamer,Ga as WhisperTimeStampLogitsProcessor,Dp as WhisperTokenizer,Ww as XLMForQuestionAnswering,Uw as XLMForSequenceClassification,Gw as XLMForTokenClassification,Bw as XLMModel,Ht as XLMPreTrainedModel,Hw as XLMRobertaForMaskedLM,Qw as XLMRobertaForQuestionAnswering,Kw as XLMRobertaForSequenceClassification,Xw as XLMRobertaForTokenClassification,Vw as XLMRobertaModel,Kt as XLMRobertaPreTrainedModel,jp as XLMRobertaTokenizer,Bp as XLMTokenizer,qw as XLMWithLMHeadModel,Xl as XVectorOutput,Xu as YolosFeatureExtractor,Jw as YolosForObjectDetection,La as YolosImageProcessor,Yw as YolosModel,Zl as YolosObjectDetectionOutput,fi as YolosPreTrainedModel,ey as YoutuForCausalLM,Zw as YoutuModel,mi as YoutuPreTrainedModel,Ti as ZeroShotAudioClassificationPipeline,Ii as ZeroShotClassificationPipeline,$i as ZeroShotImageClassificationPipeline,Di as ZeroShotObjectDetectionPipeline,ie as cat,TE as cos_sim,i0 as dot,Y as env,ye as full,Rr as full_like,Wc as interpolate,De as interpolate_4d,b2 as layer_norm,iA as load_image,QA as load_video,jc as log_softmax,S0 as matmul,_a as mean,O0 as mean_pooling,Se as ones,da as ones_like,DE as permute,_Q as pipeline,z0 as quantize_embeddings,k2 as rand,I0 as randn,Jt as random,Gp as read_audio,y2 as rfft,ua as slice,de as softmax,qe as stack,Vc as std_mean,at as topk,Kc as zeros,Xc as zeros_like};