@infekted11/stillnote 1.4.0 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{index-DjzwetQo.js → index-BoJuh0AQ.js} +225 -231
- package/dist/assets/{index-CDsStAt1.css → index-CrLtSFMC.css} +1 -1
- package/dist/assets/{whisper-worker-DcYN39bN.js → whisper-worker-CKCkC8xV.js} +1 -1
- package/dist/index.html +2 -2
- package/electron/main.cjs +9 -0
- package/electron/preload.cjs +5 -0
- package/package.json +1 -1
|
@@ -41,4 +41,4 @@ ${l}${_}${d}
|
|
|
41
41
|
`}return o+=`
|
|
42
42
|
${n}${a}`+s.repeat(e)+`${n}`,o}function jE(e,t,r,n){return`${t}${n}`+r.repeat(e)+`${t}`}function WE(e,t,r,n,s,a){return e===0&&t===0?jE(r,n,s,a):UE(r,e,t,n,s,a)}var Bp=(Ls=class extends Ee{constructor(){super(...arguments);T(this,"fake_image_token","<fake_token_around_image>");T(this,"image_token","<image>");T(this,"global_img_token","<global-img>")}async _call(t,r=null,n={}){n.return_row_col_info??(n.return_row_col_info=!0);let s;r&&(s=await this.image_processor(r,n)),Array.isArray(t)||(t=[t]);const a=s.rows??[new Array(t.length).fill(0)],o=s.cols??[new Array(t.length).fill(0)],i=this.config.image_seq_len,l=[],c=[];for(let h=0;h<t.length;++h){const _=t[h],p=a[h],w=o[h];l.push(jb(_,this.image_token));const v=p.map((k,A)=>WE(k,w[A],i,this.fake_image_token,this.image_token,this.global_img_token)),y=_.split(this.image_token);if(y.length===0)throw new Error("The image token should be present in the text.");let x=y[0];for(let k=0;k<v.length;++k)x+=v[k]+y[k+1];c.push(x)}return{...this.tokenizer(c),...s}}},T(Ls,"image_processor_class",ft),T(Ls,"tokenizer_class",Te),T(Ls,"uses_processor_config",!0),Ls),qE=(Os=class extends Ee{constructor(e,t,r){super(e,t,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:t=null,chat_template:r="default"}={}){t?Array.isArray(t)||(t=[t]):t=await Promise.all(e.filter(v=>v.images).flatMap(v=>v.images).map(v=>Ht.read(v)));const n=this.tokenizer,s=n.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0,chat_template:r}),a=v=>n.encode(v,{add_special_tokens:!1}),o=s.split(this.image_tag),i=o.length-1;if(t.length!==i)throw new Error(`Number of images provided (${t.length}) does not match number of "${this.image_tag}" image tags (${i})`);const[l,c,d]=n.convert_tokens_to_ids([this.image_tag,this.image_start_tag,this.image_end_tag]);let h=a(o[0]),_=new Array(h.length).fill(!1);for(let v=1;v<o.length;++v){const y=new Array(this.num_image_tokens).fill(l),x=a(o[v]);h=er(h,[c],y,[d],x);const k=new Array(this.num_image_tokens).fill(!0);_=er(_,[!1],k,[!1],new Array(x.length).fill(!1))}const p=[1,h.length],w={input_ids:new j("int64",h,p),attention_mask:new j("int64",new Array(h.length).fill(1),p),images_seq_mask:new j("bool",_,p),images_emb_mask:new j("bool",new Array(i*this.num_image_tokens).fill(!0),[1,i,this.num_image_tokens])};if(t&&t.length>0){const v=await this.image_processor(t);return v.pixel_values.unsqueeze_(0),{...w,...v}}return w}},T(Os,"image_processor_class",ft),T(Os,"tokenizer_class",Te),T(Os,"uses_processor_config",!0),Os),HE=(co=class extends Ee{async _call(e=null,t=null,r={}){if(!e&&!t)throw new Error("Either text or images must be provided");const n=e?this.tokenizer(e,r):{},s=t?await this.image_processor(t,r):{};return{...n,...s}}},T(co,"tokenizer_class",Te),T(co,"image_processor_class",ft),co),QE=(uo=class extends Ee{async _call(e,t=null,r={}){const{image_rows:n,image_cols:s,image_sizes:a,...o}=await this.image_processor(e,{...r,return_row_col_info:!0});if(t){const i=this.config.image_token??"<image>",{tile_size:l=512,downsample_factor:c=2,encoder_patch_size:d=16,use_thumbnail:h=!0}=this.image_processor.config,_=k=>Math.ceil(Math.floor(k/d)/c),p=_(l)**2,w=this.config.image_start_token??"<|image_start|>",v=this.config.image_end_token??"<|image_end|>",y=this.config.image_thumbnail??"<|img_thumbnail|>";Array.isArray(t)||(t=[t]);let x=0;t=t.map(k=>{const A=k.split(i);return A[0]+A.slice(1).map(S=>{const C=x++,[O,M]=a[C],V=n[C],G=s[C],U=_(O)*_(M);let J=w;if(V>1||G>1){const Q=i.repeat(p);for(let B=0;B<V;++B)for(let L=0;L<G;++L)J+=`<|img_row_${B+1}_col_${L+1}|>`+Q;h&&(J+=y+i.repeat(U))}else J+=i.repeat(U);return J+v+S}).join("")})}return{...o,...t?this.tokenizer(t,r):{}}}},T(uo,"tokenizer_class",Te),T(uo,"image_processor_class",ft),uo),XE=(Ns=class extends Ee{async _call(e,t=null,r={}){const n=await this.image_processor(e,r);if(t){const[a,o]=n.pixel_values.dims.slice(-2),{image_token:i,patch_size:l,num_additional_image_tokens:c}=this.config,d=Math.floor(a/l)*Math.floor(o/l)+c;t=structuredClone(t),Array.isArray(t)||(t=[t]);for(let h=0;h<t.length;++h)t[h]=t[h].replace(i,i.repeat(d))}const s=t?this.tokenizer(t,r):{};return{...n,...s}}},T(Ns,"tokenizer_class",Te),T(Ns,"image_processor_class",ft),T(Ns,"uses_processor_config",!0),Ns),Rp={char:["char_decode",1],bpe:["bpe_decode",2],wp:["wp_decode",102]},YE=(ho=class extends Ee{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,t){if(!Rp.hasOwnProperty(t))throw new Error(`Format ${t} is not supported.`);const[r,n]=Rp[t],s=this[r].bind(this),[a,o]=e.dims,i=[],l=[],c=e.tolist();for(let h=0;h<a;++h){const _=c[h],p=[],w=[];for(let y=1;y<o;++y){const[x,k]=Qe(at(_[y]));if(w.push(x),k==n)break;p.push(k)}const v=w.length>0?w.reduce((y,x)=>y*x,1):0;l.push(p),i.push(v)}return[s(l),i]}char_decode(e){return this.char_tokenizer.batch_decode(e).map(t=>t.replaceAll(" ",""))}bpe_decode(e){return this.bpe_tokenizer.batch_decode(e)}wp_decode(e){return this.wp_tokenizer.batch_decode(e).map(t=>t.replaceAll(" ",""))}batch_decode([e,t,r]){const[n,s]=this._decode_helper(e,"char"),[a,o]=this._decode_helper(t,"bpe"),[i,l]=this._decode_helper(r,"wp"),c=[],d=[];for(let h=0;h<n.length;++h){const[_,p]=Qe([s[h],o[h],l[h]]);c.push([n[h],a[h],i[h]][p]),d.push(_)}return{generated_text:c,scores:d,char_preds:n,bpe_preds:a,wp_preds:i}}static async from_pretrained(...e){const t=await super.from_pretrained(...e),r=await Te.from_pretrained("Xenova/gpt2"),n=await Te.from_pretrained("Xenova/bert-base-uncased");return t.components={image_processor:t.image_processor,char_tokenizer:t.tokenizer,bpe_tokenizer:r,wp_tokenizer:n},t}async _call(e,t=null){const r=await this.image_processor(e);return t&&(r.labels=this.tokenizer(t).input_ids),r}},T(ho,"tokenizer_class",Te),T(ho,"image_processor_class",ft),ho),JE=(fo=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(fo,"tokenizer_class",Te),T(fo,"feature_extractor_class",Lt),fo),KE=(_o=class extends Ee{},T(_o,"tokenizer_class",Te),T(_o,"image_processor_class",ft),_o),kn="<image>";function ZE(e,t,r,n,s){return`${n.repeat(r*s)}${t}${e}
|
|
43
43
|
`}var e2=(Ds=class extends Ee{async _call(e,t=null,r={}){t||(he.warn("You are using PaliGemma without a text prefix. It will perform as a picture-captioning model."),t=""),Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]);const n=this.tokenizer.bos_token,s=this.image_processor.config.image_seq_length;let a;t.some(l=>l.includes(kn))?a=t.map(l=>{const c=l.replaceAll(kn,kn.repeat(s)),d=c.lastIndexOf(kn),h=d===-1?0:d+kn.length;return c.slice(0,h)+n+c.slice(h)+`
|
|
44
|
-
`}):(he.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."),a=t.map(l=>ZE(l,n,s,kn,e.length)));const o=this.tokenizer(a,r);return{...await this.image_processor(e,r),...o}}},T(Ds,"tokenizer_class",Te),T(Ds,"image_processor_class",ft),T(Ds,"uses_processor_config",!1),Ds),$p="<|image|>",t2=/<\|image_\d+\|>/g,r2=(po=class extends Ee{async _call(e,t=null,{padding:r=!0,truncation:n=!0,num_crops:s=null}={}){Array.isArray(e)||(e=[e]);let a,o;if(t){o=await this.image_processor(t,{num_crops:s});const{num_img_tokens:i}=o,l=e.map((d,h)=>d.split(t2).join($p.repeat(i[h])));a=this.tokenizer(l,{padding:r,truncation:n});const c=this.tokenizer._tokenizer.token_to_id($p);a.input_ids.map_(d=>d==c?-d:d)}else a=this.tokenizer(e);return{...a,...o}}},T(po,"image_processor_class",ft),T(po,"tokenizer_class",Te),po),n2=(zs=class extends Ee{async _call(e,t=null,r={}){const n=await this.image_processor(e,r);if(t){const[a,o]=n.pixel_values.dims.slice(-2),{image_token:i,image_break_token:l,image_end_token:c,patch_size:d,spatial_merge_size:h}=this.config,_=d*h,p=Math.floor(a/_),w=Math.floor(o/_);t=structuredClone(t),Array.isArray(t)||(t=[t]);for(let v=0;v<t.length;++v){const y=i.repeat(w),x=y+l,k=y+c,A=x.repeat(p-1)+k;t[v]=t[v].replace(i,A)}}const s=t?this.tokenizer(t,r):{};return{...n,...s}}},T(zs,"tokenizer_class",Te),T(zs,"image_processor_class",ft),T(zs,"uses_processor_config",!0),zs),s2=(Vu=class extends Ee{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}},T(Vu,"feature_extractor_class",dp),Vu),Gp=class extends gl{},a2=class extends Gp{},Vp=(Uu=class extends Ee{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)}},T(Uu,"image_processor_class",ft),Uu),Up=class extends Vp{},o2=class extends Up{},i2=(mo=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(mo,"tokenizer_class",Te),T(mo,"feature_extractor_class",Lt),mo),l2=(Bs=class extends Ee{async _call(e,t=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(t){const a=t.length,{input_features:o}=await this.feature_extractor(t,{...r,max_length:a}),i=Math.round(a/this.config.encoder_ds_factor+1e-4),l=1+Math.ceil(i/this.config.stack_factor);n.audio_token_len=[l],n.audio_values=o;const c=this.config.audio_placeholder;if(!e.includes(c))throw new Error(`The input text does not contain the image token ${c}.`);e=e.replaceAll(c,c.repeat(l))}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}},T(Bs,"tokenizer_class",Te),T(Bs,"feature_extractor_class",Lt),T(Bs,"uses_processor_config",!0),Bs),Fa="[AUDIO]",c2="[BEGIN_AUDIO]",u2=375;function d2(e,t){const r=[];for(let n=0;n<e.length;n+=t)r.push(e.subarray(n,Math.min(n+t,e.length)));return r}var h2=(Rs=class extends Ee{async _call(e,t=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");const n={};if(t){if(!e.includes(Fa))throw new Error(`The input text does not contain the audio token ${Fa}.`);Array.isArray(t)||(t=[t]);const a=e.split(Fa),o=a.length-1;if(o!==t.length)throw new Error(`The number of audio inputs (${t.length}) does not match the number of audio tokens in the text (${o}).`);const i=this.feature_extractor.config.n_samples,l=t.map(p=>d2(p,i)),c=l.map(p=>p.length),d=l.flat(),h=(await Promise.all(d.map(p=>this.feature_extractor(p,r)))).map(p=>p.input_features);n.audio_values=h.length>1?Re(h,0):h[0];let _=a[0];for(let p=0;p<c.length;++p){_+=c2;for(let w=0;w<c[p];++w)_+=Fa.repeat(u2);_+=a[p+1]}e=_}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}},T(Rs,"tokenizer_class",Te),T(Rs,"feature_extractor_class",Lt),T(Rs,"uses_processor_config",!1),Rs),jp=32,wl=6,Ia=8,f2=10,_2=32,p2=($s=class extends Ee{get num_mel_frames_first_audio_chunk(){return(wl+1)*Ia}get num_samples_first_audio_chunk(){const{hop_length:e,n_fft:t}=this.feature_extractor.config;return(this.num_mel_frames_first_audio_chunk-1)*e+Math.floor(t/2)}get num_samples_per_audio_chunk(){const{hop_length:e,n_fft:t}=this.feature_extractor.config;return Ia*e+t}get num_right_pad_tokens(){return wl+1+f2}get audio_length_per_tok(){return Ia}get raw_audio_length_per_tok(){return Ia*this.feature_extractor.config.hop_length}async _call(e,{is_streaming:t=!1,is_first_audio_chunk:r=!0}={}){if(ot(e,"VoxtralRealtimeProcessor"),!t&&!r)throw new Error("In non-streaming mode (`is_streaming=false`), `is_first_audio_chunk` must be `true`.");if(r)if(t){const n=jp*this.raw_audio_length_per_tok,s=new Float32Array(n+e.length);s.set(e,n);const a=await this.feature_extractor(s,{center:!0}),i=1+(jp+wl),l=new BigInt64Array(i).fill(BigInt(_2));return l[0]=1n,{input_ids:new j("int64",l,[1,i]),...a}}else{const n=this.num_right_pad_tokens*this.raw_audio_length_per_tok,s=new Float32Array(e.length+n);return s.set(e),await this.feature_extractor(s,{center:!0})}else return await this.feature_extractor(e,{center:!1})}},T($s,"tokenizer_class",Te),T($s,"feature_extractor_class",Lt),T($s,"uses_processor_config",!1),$s),m2=(go=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(go,"tokenizer_class",Te),T(go,"feature_extractor_class",Lt),go),g2=(wo=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(wo,"tokenizer_class",Te),T(wo,"feature_extractor_class",Lt),wo),w2=(vo=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(vo,"tokenizer_class",Te),T(vo,"feature_extractor_class",Lt),vo),v2=class{static async from_pretrained(e,t={}){const r=await nr(e,_s,!0,t),{image_processor_type:n,feature_extractor_type:s,processor_class:a}=r;if(a&&sl[a])return sl[a].from_pretrained(e,t);if(!n&&!s)throw new Error("No `image_processor_type` or `feature_extractor_type` found in the config.");const o={};if(n){const l=Pa[n.replace(/Fast$/,"")];if(!l)throw new Error(`Unknown image_processor_type: '${n}'.`);o.image_processor=new l(r)}if(s){const l=Pa[s];if(l)o.image_processor=new l(r);else{const c=al[s];if(!c)throw new Error(`Unknown feature_extractor_type: '${s}'.`);o.feature_extractor=new c(r)}}const i={};return new Ee(i,o,null)}};async function y2(e,t){return await nr(e,"config.json",!0,t)}function Tn(e){const t={};let r={};switch(e.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"gemma4":case"lfm2_vl":case"chatterbox":case"lighton_ocr":case"glm_ocr":case"mistral3":case"qwen2_5_vl":case"qwen3_vl":case"qwen3_vl_moe":r=Tn(e.text_config);break;case"moondream1":r=Tn(e.phi_config);break;case"musicgen":r=Tn(e.decoder);break;case"multi_modality":r=Tn(e.language_config);break;case"gpt2":case"gptj":case"jais":case"codegen":case"gpt_bigcode":t.num_heads="n_head",t.num_layers="n_layer",t.hidden_size="n_embd";break;case"gpt_neox":case"stablelm":case"opt":case"falcon":case"modernbert-decoder":t.num_heads="num_attention_heads",t.num_layers="num_hidden_layers",t.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":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size",t.num_attention_heads="num_attention_heads",t.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"gemma4_text":case"glm":case"helium":case"ernie4_5":case"hunyuan_v1_dense":case"falcon_h1":case"nemotron_h":case"ministral":case"ministral3":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.dim_kv="head_dim";break;case"openelm":t.num_heads="num_kv_heads",t.num_layers="num_transformer_layers",t.dim_kv="head_dim";break;case"gpt_neo":case"donut-swin":t.num_heads="num_heads",t.num_layers="num_layers",t.hidden_size="hidden_size";break;case"bloom":t.num_heads="n_head",t.num_layers="n_layer",t.hidden_size="hidden_size";break;case"mpt":t.num_heads="n_heads",t.num_layers="n_layers",t.hidden_size="d_model";break;case"exaone":t.num_heads="num_key_value_heads",t.num_layers="num_layers",t.dim_kv="head_dim",t.num_attention_heads="num_attention_heads";break;case"youtu":case"deepseek_v3":case"deepseek_v4":case"glm_moe_dsa":case"mistral4":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.dim_kv=e.model_type==="deepseek_v4"?"head_dim":"qk_head_dim",t.num_attention_heads="num_attention_heads";break;case"zaya":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size",t.dim_kv="head_dim",t.num_attention_heads="num_attention_heads";break;case"hrm_text":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size",t.dim_kv="head_dim",t.num_attention_heads="num_attention_heads";break;case"t5":case"mt5":case"longt5":t.num_decoder_layers="num_decoder_layers",t.num_decoder_heads="num_heads",t.decoder_dim_kv="d_kv",t.num_encoder_layers="num_layers",t.num_encoder_heads="num_heads",t.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":t.num_decoder_layers="decoder_layers",t.num_decoder_heads="decoder_attention_heads",t.decoder_hidden_size="d_model",t.num_encoder_layers="encoder_layers",t.num_encoder_heads="encoder_attention_heads",t.encoder_hidden_size="d_model";break;case"speecht5":t.num_decoder_layers="decoder_layers",t.num_decoder_heads="decoder_attention_heads",t.decoder_hidden_size="hidden_size",t.num_encoder_layers="encoder_layers",t.num_encoder_heads="encoder_attention_heads",t.encoder_hidden_size="hidden_size";break;case"trocr":t.num_encoder_layers=t.num_decoder_layers="decoder_layers",t.num_encoder_heads=t.num_decoder_heads="decoder_attention_heads",t.encoder_hidden_size=t.decoder_hidden_size="d_model";break;case"musicgen_decoder":t.num_encoder_layers=t.num_decoder_layers="num_hidden_layers",t.num_encoder_heads=t.num_decoder_heads="num_attention_heads",t.encoder_hidden_size=t.decoder_hidden_size="hidden_size";break;case"moonshine":t.num_decoder_layers="decoder_num_hidden_layers",t.num_decoder_heads="decoder_num_key_value_heads",t.num_encoder_layers="encoder_num_hidden_layers",t.num_encoder_heads="encoder_num_key_value_heads",t.encoder_hidden_size=t.decoder_hidden_size="hidden_size";break;case"cohere_asr":t.num_decoder_layers="num_hidden_layers",t.num_decoder_heads="num_key_value_heads",t.decoder_hidden_size="hidden_size",t.decoder_dim_kv="head_dim";const{num_hidden_layers:s,num_attention_heads:a,hidden_size:o}=e.encoder_config;r={num_encoder_layers:s,num_encoder_heads:a,encoder_hidden_size:o,encoder_dim_kv:e.head_dim};break;case"vision-encoder-decoder":const i=Tn(e.decoder),l="num_decoder_layers"in i,c=rt(e,["model_type","is_encoder_decoder"]);return l?(c.num_decoder_layers=i.num_decoder_layers,c.num_decoder_heads=i.num_decoder_heads,c.decoder_hidden_size=i.decoder_hidden_size,c.num_encoder_layers=i.num_encoder_layers,c.num_encoder_heads=i.num_encoder_heads,c.encoder_hidden_size=i.encoder_hidden_size):(c.num_layers=i.num_layers,c.num_heads=i.num_heads,c.hidden_size=i.hidden_size),c}const n={...r,...rt(e,["model_type","multi_query","is_encoder_decoder"])};for(const s in t)n[s]=e[t[s]];return n}function La(e,t){e instanceof vl||(e=new vl(e));const r=(t==null?void 0:t.prefix)??"past_key_values",n=r==="present"?"present":"past",s=new Set;if(["lfm2","lfm2_moe"].includes(e.model_type)){const{layer_types:a}=e;for(let o=0;o<a.length;++o)if(a[o]==="full_attention")s.add(`${r}.${o}.key`),s.add(`${r}.${o}.value`);else if(a[o]==="conv")s.add(`${n}_conv.${o}`);else throw new Error(`Unsupported layer type: ${a[o]}`);return s}else if(["granitemoehybrid","falcon_h1","nemotron_h"].includes(e.model_type)){const a=e,o=a.layer_types??a.layers_block_type,i=a.num_hidden_layers??(o==null?void 0:o.length);for(let l=0;l<i;++l)(!o||o[l]==="mamba")&&(s.add(`${n}_conv.${l}`),s.add(`${n}_ssm.${l}`)),(!o||o[l]==="attention")&&(s.add(`${r}.${l}.key`),s.add(`${r}.${l}.value`));return s}else if(["qwen3_next","qwen3_5_text","qwen3_5_moe_text","olmo_hybrid"].includes(e.model_type)){const{layer_types:a}=e;for(let o=0;o<a.length;++o)if(a[o]==="full_attention")s.add(`${r}.${o}.key`),s.add(`${r}.${o}.value`);else if(a[o]==="linear_attention")e.model_type==="olmo_hybrid"?(s.add(`${n}_conv.${o}.key`),s.add(`${n}_conv.${o}.value`),s.add(`${n}_conv.${o}.query`)):s.add(`${n}_conv.${o}`),s.add(`${n}_recurrent.${o}`);else throw new Error(`Unsupported layer type: ${a[o]}`);return s}else if(["gemma4","gemma4_text"].includes(e.model_type)){const a=e.model_type==="gemma4"?e.text_config:e,o=a.num_hidden_layers,i=a.num_kv_shared_layers??0,l=o-i;for(let c=0;c<l;++c)s.add(`${r}.${c}.key`),s.add(`${r}.${c}.value`);return s}else if(e.model_type==="deepseek_v4"){const{layer_types:a,num_hidden_layers:o}=e;for(let i=0;i<o;++i){s.add(`${r}.${i}.key`),s.add(`${r}.${i}.value`);const l=a[i];if(l==="compressed_sparse_attention")s.add(`${n}_compressor.${i}.kv`),s.add(`${n}_compressor.${i}.gate`),s.add(`${n}_indexer.${i}.kv`),s.add(`${n}_indexer.${i}.gate`);else if(l==="heavily_compressed_attention")s.add(`${n}_compressor.${i}.kv`),s.add(`${n}_compressor.${i}.gate`);else if(l&&l!=="sliding_attention")throw new Error(`Unsupported layer type: ${l}`)}return s}else if(e.model_type==="zaya"){const{num_hidden_layers:a,cca_time1:o}=e,i=o??1;for(let l=0;l<a;l+=i)s.add(`${r}.${l}.key`),s.add(`${r}.${l}.value`),s.add(`${r}.${l}.conv_state`),s.add(`${r}.${l}.shift_state`);return s}else if(["lfm2_vl","qwen3_5","qwen3_5_moe","voxtral_realtime"].includes(e.model_type)){let a;return e.model_type==="voxtral_realtime"&&(t==null?void 0:t.session_name)==="audio_encoder"?a=e.audio_config:a=e.text_config,La(a,t)}return b2(e,{prefix:r})}function b2(e,{prefix:t="past_key_values"}={}){const r=new Set,n=e.normalized_config;if(n.is_encoder_decoder&&"num_encoder_heads"in n&&"num_decoder_heads"in n)for(let s=0;s<n.num_decoder_layers;++s)r.add(`${t}.${s}.encoder.key`),r.add(`${t}.${s}.encoder.value`),r.add(`${t}.${s}.decoder.key`),r.add(`${t}.${s}.decoder.value`);else if(n.multi_query)for(let s=0;s<n.num_layers;++s)r.add(`${t}.${s}.key_value`);else for(let s=0;s<n.num_layers;++s)r.add(`${t}.${s}.key`),r.add(`${t}.${s}.value`);return r}var vl=class Qd{constructor(t){T(this,"model_type",null);T(this,"is_encoder_decoder",!1);T(this,"max_position_embeddings");T(this,"transformers.js_config");Object.assign(this,t),this.normalized_config=Tn(this)}static async from_pretrained(t,{progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:a=!1,revision:o="main"}={}){n&&!(n instanceof Qd)&&(n=new Qd(n));const i=n??await y2(t,{progress_callback:r,config:n,cache_dir:s,local_files_only:a,revision:o});return new this(i)}},ps=class{static async from_pretrained(...e){return vl.from_pretrained(...e)}};function Wp(e,t,r){return e?typeof e=="object"&&e!==null?e.hasOwnProperty(t)?+e[t]:e.hasOwnProperty(r)?+e[r]:0:+e:0}function qp(e,t){const r=[];for(let n=0;n<t;++n)r.push(`${e}_data${n===0?"":"_"+n}`);return r}async function M2(e,t,r,n){const s=`${t}${n}.onnx`,a=`${r.subfolder??""}/${s}`;return await ka(e,a,!0,r,pe.IS_NODE_ENV)}async function x2(e,t,r,n,s,a={}){const o=`${t}${r}.onnx`,i=pe.IS_NODE_ENV;let l=[];const c=Wp(s,o,t);if(c>0){if(c>g_)throw new Error(`The number of external data chunks (${c}) exceeds the maximum allowed value (${g_}).`);const d=qp(o,c);for(const h of d){const _=`${n.subfolder??""}/${h}`;l.push(new Promise(async(p,w)=>{const v=await ka(e,_,!0,n,i);p(v instanceof Uint8Array?{path:h,data:v}:h)}))}}else a.externalData!==void 0&&(l=a.externalData.map(async d=>{if(typeof d.data=="string"){const h=await ka(e,d.data,!0,n);return{...d,data:h}}return d}));return Promise.all(l)}async function k2(e,t,r,n=!1,s=void 0){var k;let a=((k=r.config)==null?void 0:k["transformers.js_config"])??{};const o=z_(r.device??a.device,t,{warn:A=>he.info(A)}),i=H1(o),l=a.device_config??{};l.hasOwnProperty(o)&&(a={...a,...l[o]});const c=$_(r.dtype??a.dtype,t,o,{configDtype:a.dtype,warn:A=>he.info(A)});if(Xi.hasOwnProperty(c)){if(o==="webgpu"&&!pe.IS_NODE_ENV&&c===Ye.fp16&&!await Y1())throw new Error(`The device (${o}) does not support fp16.`)}else throw new Error(`Invalid dtype: ${c}. Should be one of: ${Object.keys(Ye).join(", ")}`);const d=Xi[c],h={...r.session_options};h.executionProviders??(h.executionProviders=i);const _=a.free_dimension_overrides;_?h.freeDimensionOverrides??(h.freeDimensionOverrides=_):o.startsWith("webnn")&&!h.freeDimensionOverrides&&he.warn(`WebNN does not currently support dynamic shapes and requires 'free_dimension_overrides' to be set in config.json, preferably as a field within config["transformers.js_config"]["device_config"]["${o}"]. When 'free_dimension_overrides' is not set, you may experience significant performance degradation.`);const p=M2(e,t,r,d),w=r.use_external_data_format??a.use_external_data_format,v=await x2(e,t,d,r,w,h);if(v.length>0&&(!pe.IS_NODE_ENV||v.some(A=>typeof A!="string"))&&(h.externalData=v),n&&o==="webgpu"){const A=La(r.config,{prefix:"present",session_name:s});if(A.size>0&&!Hi()){const S={};for(const C of A)S[C]="gpu-buffer";h.preferredOutputLocation=S}}return{buffer_or_path:await p,session_options:h,session_config:{dtype:c,device:o}}}async function T2(e,t,r,n=void 0){return Object.fromEntries(await Promise.all(Object.keys(t).map(async s=>{const a=(n==null?void 0:n[s])??!1,{buffer_or_path:o,session_options:i,session_config:l}=await k2(e,t[s],r,a,s),c=await L_(o,i,l);return[s,c]})))}function Hp(e){for(let t in e)D_(e[t])?e[t]=new j(e[t]):typeof e[t]=="object"&&Hp(e[t]);return e}async function ye(e,t){const r=E2(e,t);try{const n=Object.fromEntries(Object.entries(r).map(([a,o])=>{const i=o.ort_tensor;return pe.IS_NODE_ENV&&typeof Float16Array<"u"&&i.cpuData instanceof Float16Array&&(i.cpuData=new Uint16Array(i.cpuData.buffer)),[a,i]})),s=await N_(e,n);return Hp(s)}catch(n){const s=Object.fromEntries(Object.entries(r).map(([a,o])=>{const i={type:o.type,dims:o.dims,location:o.location};return i.location!=="gpu-buffer"&&(i.data=o.data),[a,i]}));throw he.error(`An error occurred during model execution: "${n}".`),he.error("Inputs given to model:",s),n}}function E2(e,t){const r=Object.create(null),n=[];for(const o of e.inputNames){const i=t[o];if(!(i instanceof j)){n.push(o);continue}r[o]=Hi()?i.clone():i}if(n.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${n.join(", ")}.`);const s=Object.keys(t).length,a=e.inputNames.length;if(s>a){let o=Object.keys(t).filter(i=>!e.inputNames.includes(i));he.warn(`WARNING: Too many inputs were provided (${s} > ${a}). The following inputs will be ignored: "${o.join(", ")}".`)}return r}var je=class{},A2=class extends je{constructor({last_hidden_state:e,hidden_states:t=null,attentions:r=null}){super(),this.last_hidden_state=e,this.hidden_states=t,this.attentions=r}},le=class extends je{constructor({logits:e,...t}){super(),this.logits=e;const r=Object.values(t);r.length>0&&(this.attentions=r)}},Xe=class extends je{constructor({logits:e}){super(),this.logits=e}},Je=class extends je{constructor({logits:e}){super(),this.logits=e}},it=class extends je{constructor({start_logits:e,end_logits:t}){super(),this.start_logits=e,this.end_logits=t}},Br=class extends je{constructor({logits:e}){super(),this.logits=e}},C2=class extends je{constructor({logits:e,past_key_values:t}){super(),this.logits=e,this.past_key_values=t}},S2=class extends je{constructor({logits:e,past_key_values:t,encoder_outputs:r,decoder_attentions:n=null,cross_attentions:s=null}){super(),this.logits=e,this.past_key_values=t,this.encoder_outputs=r,this.decoder_attentions=n,this.cross_attentions=s}},Qp=class extends je{constructor({alphas:e}){super(),this.alphas=e}},Qt=class extends gt{_call(e,t){throw Error("`_call` should be implemented in a subclass")}},P2=class extends gt{_call(e,t){throw Error("`_call` should be implemented in a subclass")}},yl=class extends gt{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,t){let r=t;for(const n of this.processors)r=n(e,r);return r}[Symbol.iterator](){return this.processors.values()}},F2=class extends Qt{constructor(e){super(),this.bos_token_id=e}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length===1){const n=t[r].data;n.fill(-1/0),n[this.bos_token_id]=0}return t}},I2=class extends Qt{constructor(e,t){super(),this.max_length=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length===this.max_length-1){const n=t[r].data;n.fill(-1/0);for(const s of this.eos_token_id)n[s]=0}return t}},L2=class extends Qt{constructor(e){super(),this.suppress_tokens=e}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data;for(const s of this.suppress_tokens)n[s]=-1/0}return t}},Xp=class extends Qt{constructor(e,t){super(),this.begin_suppress_tokens=e,this.begin_index=t}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length===this.begin_index){const n=t[r].data;for(const s of this.begin_suppress_tokens)n[s]=-1/0}return t}},O2=class extends Qt{constructor(e,t){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=t.length,t.at(-1)===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data;if(n[this.no_timestamps_token_id]=-1/0,e[r].length===this.begin_index){n.subarray(0,this.timestamp_begin).fill(-1/0);continue}const s=e[r].slice(this.begin_index),a=s.length>=1&&s[s.length-1]>=this.timestamp_begin,o=s.length<2||s[s.length-2]>=this.timestamp_begin;if(a&&(o?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){const d=this.timestamp_begin+this.max_initial_timestamp_index;n.subarray(d+1).fill(-1/0)}const i=O1(n),l=Math.log(i.subarray(this.timestamp_begin).map(Math.exp).reduce((d,h)=>d+h)),c=Qe(i.subarray(0,this.timestamp_begin))[0];l>c&&n.subarray(0,this.timestamp_begin).fill(-1/0)}return t}},N2=class extends Qt{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){const t=e.length,r=[];for(let s=0;s<t+1-this.no_repeat_ngram_size;++s){const a=[];for(let o=0;o<this.no_repeat_ngram_size;++o)a.push(e[s+o]);r.push(a.map(Number))}const n=new Map;for(const s of r){const a=s.slice(0,s.length-1),o=JSON.stringify(a),i=n.get(o)??[];i.push(s[s.length-1]),n.set(o,i)}return n}getGeneratedNgrams(e,t){const r=t.slice(t.length+1-this.no_repeat_ngram_size,t.length);return e.get(JSON.stringify(r.map(Number)))??[]}calcBannedNgramTokens(e){const t=[];if(e.length+1<this.no_repeat_ngram_size)return t;{const r=this.getNgrams(e);return this.getGeneratedNgrams(r,e)}}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data,s=this.calcBannedNgramTokens(e[r]);for(const a of s)n[a]=-1/0}return t}},D2=class extends Qt{constructor(e){super(),this.penalty=e}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data;for(const s of new Set(e[r])){const a=Number(s);n[a]<0?n[a]*=this.penalty:n[a]/=this.penalty}}return t}},z2=class extends Qt{constructor(e,t){super(),this.min_length=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length<this.min_length){const n=t[r].data;for(const s of this.eos_token_id)n[s]=-1/0}return t}},B2=class extends Qt{constructor(e,t,r){super(),this.prompt_length_to_skip=e,this.min_new_tokens=t,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length-this.prompt_length_to_skip<this.min_new_tokens){const s=t[r].data;for(const a of this.eos_token_id)s[a]=-1/0}return t}},R2=class extends Qt{constructor(e,t){super(),this.bad_words_ids=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data,s=e[r];for(const a of this.bad_words_ids){if(s.length<a.length-1)continue;let o=!0;for(let i=1;i<=a.length-1;++i)if(a.at(-i-1)!=s.at(-i)){o=!1;break}o&&(n[a.at(-1)]=-1/0)}}return t}},$2=class extends Qt{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,t){if(t.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 ${t.dims[0]} for the logits and ${e.length} for the input ids.`);const r=e.length,n=t.slice([0,r],null),s=t.slice([r,t.dims[0]],null);for(let a=0;a<s.data.length;++a)s.data[a]+=(n.data[a]-s.data[a])*this.guidance_scale;return s}},G2=class extends P2{constructor(e){super(),this.temperature=e}_call(e,t){const r=t.data;for(let n=0;n<r.length;++n)r[n]/=this.temperature;return t}},Yp=class{constructor(e){T(this,"max_length",20);T(this,"max_new_tokens",null);T(this,"min_length",0);T(this,"min_new_tokens",null);T(this,"early_stopping",!1);T(this,"max_time",null);T(this,"do_sample",!1);T(this,"num_beams",1);T(this,"num_beam_groups",1);T(this,"penalty_alpha",null);T(this,"use_cache",!0);T(this,"temperature",1);T(this,"top_k",50);T(this,"top_p",1);T(this,"typical_p",1);T(this,"epsilon_cutoff",0);T(this,"eta_cutoff",0);T(this,"diversity_penalty",0);T(this,"repetition_penalty",1);T(this,"encoder_repetition_penalty",1);T(this,"length_penalty",1);T(this,"no_repeat_ngram_size",0);T(this,"bad_words_ids",null);T(this,"force_words_ids",null);T(this,"renormalize_logits",!1);T(this,"constraints",null);T(this,"forced_bos_token_id",null);T(this,"forced_eos_token_id",null);T(this,"remove_invalid_values",!1);T(this,"exponential_decay_length_penalty",null);T(this,"suppress_tokens",null);T(this,"streamer",null);T(this,"begin_suppress_tokens",null);T(this,"forced_decoder_ids",null);T(this,"guidance_scale",null);T(this,"num_return_sequences",1);T(this,"output_attentions",!1);T(this,"output_hidden_states",!1);T(this,"output_scores",!1);T(this,"return_dict_in_generate",!1);T(this,"pad_token_id",null);T(this,"bos_token_id",null);T(this,"eos_token_id",null);T(this,"encoder_no_repeat_ngram_size",0);T(this,"decoder_start_token_id",null);T(this,"generation_kwargs",{});Object.assign(this,rt(e,Object.getOwnPropertyNames(this)))}},Oa=class extends gt{_call(e,t){throw Error("StoppingCriteria needs to be subclassed")}},Jp=class Vy extends gt{constructor(){super(),this.criteria=[]}push(t){this.criteria.push(t)}extend(t){t instanceof Vy?t=t.criteria:t instanceof Oa&&(t=[t]),this.criteria.push(...t)}_call(t,r){const n=new Array(t.length).fill(!1);for(const s of this.criteria){const a=s(t,r);for(let o=0;o<n.length;++o)n[o]||(n[o]=a[o])}return n}[Symbol.iterator](){return this.criteria.values()}},V2=class extends Oa{constructor(e,t=null){super(),this.max_length=e,this.max_position_embeddings=t}_call(e){return e.map(t=>t.length>=this.max_length)}},U2=class extends Oa{constructor(e){super(),Array.isArray(e)||(e=[e]),this.eos_token_id=e}_call(e,t){return e.map(r=>{const n=r.at(-1);return this.eos_token_id.some(s=>n==s)})}},Na=class extends gt{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,t){let r=e.dims.at(-1),n=e.data;if(t===-1)n=n.slice(-r);else{let s=t*r;n=n.slice(s,s+r)}return n}randomSelect(e){return g1(e)}static getSampler(e){if(e.do_sample)return new W2(e);if(e.num_beams>1)return new q2(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 j2(e)}},j2=class extends Na{async sample(e){const t=Qe(e.data)[1];return[[BigInt(t),0]]}},W2=class extends Na{async sample(e){let t=e.dims.at(-1);this.generation_config.top_k>0&&(t=Math.min(this.generation_config.top_k,t));const[r,n]=await Mn(e,t),s=at(r.data);return Array.from({length:this.generation_config.num_beams},()=>{const a=this.randomSelect(s);return[n.data[a],Math.log(s[a])]})}},q2=class extends Na{async sample(e){let t=e.dims.at(-1);this.generation_config.top_k>0&&(t=Math.min(this.generation_config.top_k,t));const[r,n]=await Mn(e,t),s=at(r.data);return Array.from({length:this.generation_config.num_beams},(a,o)=>[n.data[o],Math.log(s[o])])}},H2=class{constructor(e){if(e)for(const t in e){if(t in this)throw new TypeError(`Key "${t}" conflicts with an existing property on DynamicCache`);const r=e[t];if(!(r instanceof j))throw new TypeError(`Expected a Tensor for key "${t}", got ${typeof r}`);this[t]=r}}get_seq_length(){const e=this;if(Object.keys(e).length===0)return 0;for(const t in e)if(t.startsWith("past_key_values."))return e[t].dims.at(-2);throw new Error("Unable to determine sequence length from the cache.")}update(e){for(const t in e){const r=this[t],n=e[t];r&&r!==n&&r.location==="gpu-buffer"&&r.dispose(),this[t]=n}}async dispose(){const e=[];for(const t of Object.values(this))t.location==="gpu-buffer"&&e.push(t.dispose());await Promise.all(e)}},bl=H2,q={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,VoxtralRealtime:16,MultimodalEncoder:17},gr={[q.DecoderOnly]:{sessions:(e,t)=>({model:t.model_file_name??"model"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[q.DecoderOnlyWithoutHead]:{sessions:(e,t)=>({model:t.model_file_name??"model"})},[q.Seq2Seq]:{sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.Vision2Seq]:{sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.Musicgen]:{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"}},[q.EncoderDecoder]:{sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0}},[q.MaskGeneration]:{sessions:()=>({model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"})},[q.ImageTextToText]:{text_only_sessions:{embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"},sessions:(e,t,r)=>{const n={...gr[q.ImageTextToText].text_only_sessions};return r||(n.vision_encoder="vision_encoder"),e.is_encoder_decoder&&(n.model="encoder_model"),n},cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.AudioTextToText]:{text_only_sessions:{embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"},sessions:(e,t,r)=>{const n={...gr[q.AudioTextToText].text_only_sessions};return r||(n.audio_encoder="audio_encoder"),n},cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.ImageAudioTextToText]:{text_only_sessions:{embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"},sessions:(e,t,r)=>{const n={...gr[q.ImageAudioTextToText].text_only_sessions};return r||(n.audio_encoder="audio_encoder",n.vision_encoder="vision_encoder"),n},cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.Phi3V]:{sessions:()=>({prepare_inputs_embeds:"prepare_inputs_embeds",model:"model",vision_encoder:"vision_encoder"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[q.MultiModality]:{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"}},[q.AutoEncoder]:{sessions:()=>({encoder_model:"encoder_model",decoder_model:"decoder_model"})},[q.Supertonic]:{sessions:()=>({text_encoder:"text_encoder",latent_denoiser:"latent_denoiser",voice_decoder:"voice_decoder"})},[q.Chatterbox]:{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"}},[q.VoxtralRealtime]:{text_only_sessions:{embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"},sessions:(e,t,r)=>{const n={...gr[q.VoxtralRealtime].text_only_sessions};return r||(n.audio_encoder="audio_encoder"),n},cache_sessions:{decoder_model_merged:!0,audio_encoder:!0},optional_configs:{generation_config:"generation_config.json"}},[q.MultimodalEncoder]:{sessions:(e,t)=>({model:t.model_file_name??"model",...e.vision_config&&{vision_encoder:"vision_encoder"},...e.audio_config&&{audio_encoder:"audio_encoder"}})},default:{sessions:(e,t)=>({model:t.model_file_name??"model"})}};function Q2(e){const t=gr[e];return(t==null?void 0:t.text_only_sessions)??null}function X2(e,t,r={}){const n=gr[e]??gr.default;return{sessions:n.sessions(t,r,r.textOnly??!1),cache_sessions:n.cache_sessions,optional_configs:n.optional_configs}}function Kp(e,{warn:t=!0}={}){const r=e.architectures||[];for(const n of r){const s=wr.get(n);if(s!==void 0)return s}if(e.model_type){const n=wr.get(e.model_type);if(n!==void 0)return n;for(const s of Object.values(En))if(s.has(e.model_type)){const a=wr.get(s.get(e.model_type));if(a!==void 0)return a}}if(t){const n=r.length>0?r.join(", "):"(none)";he.warn(`[resolve_model_type] Architecture(s) not found in MODEL_TYPE_MAPPING: [${n}] for model type '${e.model_type}'. Falling back to EncoderOnly (single model.onnx file). If you encounter issues, please report at: ${Aa}`)}return q.EncoderOnly}function Zp(e,{config:t=null,cache_dir:r=null,local_files_only:n=!1,revision:s="main"}={}){if(t!==null)return ps.from_pretrained(e,{config:t,cache_dir:r,local_files_only:n,revision:s});const a=Bi(e,{cache_dir:r,local_files_only:n,revision:s});return x_(a,()=>ps.from_pretrained(e,{config:t,cache_dir:r,local_files_only:n,revision:s}))}async function em(e,{config:t=null,dtype:r=null,device:n=null,model_file_name:s=null}={}){t=await Zp(e,{config:t});const a=["config.json"],o=t["transformers.js_config"]??{},i=o.use_external_data_format,l="onnx",c=n??o.device;let d=r??o.dtype;const h=Kp(t),_=(v,y=null)=>{y=y??v;const x=z_(c,v),k=$_(d,v,x),A=Xi[k]??"",S=`${y}${A}.onnx`,C=`${l}/${S}`;a.push(C);const O=Wp(i,S,v);for(const M of qp(S,O)){const V=`${l}/${M}`;a.push(V)}},{sessions:p,optional_configs:w}=X2(h,t,{model_file_name:s});for(const[v,y]of Object.entries(p))_(v,y);if(w)for(const v of Object.values(w))a.push(v);return a}var En=null;function Y2(e){En=e}function Ml(e){if(e instanceof j)return e;if(e.length===0)throw Error("items must be non-empty");if(Array.isArray(e[0])){if(e.some(t=>t.length!==e[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 j("int64",BigInt64Array.from(e.flat().map(t=>BigInt(t))),[e.length,e[0].length])}else return new j("int64",BigInt64Array.from(e.map(t=>BigInt(t))),[1,e.length])}function tm(e){return new j("bool",[e],[1])}var rm={[q.DecoderOnly]:{can_generate:!0,forward:vr,prepare_inputs:Cn},[q.DecoderOnlyWithoutHead]:{can_generate:!1,forward:vr,prepare_inputs:Cn},[q.Seq2Seq]:{can_generate:!0,forward:Da,prepare_inputs:za},[q.Vision2Seq]:{can_generate:!0,forward:Da,prepare_inputs:za},[q.Musicgen]:{can_generate:!0,forward:Da},[q.EncoderDecoder]:{can_generate:!1,forward:Da},[q.ImageTextToText]:{can_generate:!0,forward:eA,prepare_inputs:Ba},[q.AudioTextToText]:{can_generate:!0,forward:Z2,prepare_inputs:Ba},[q.ImageAudioTextToText]:{can_generate:!0,prepare_inputs:Ba},[q.Phi3V]:{can_generate:!0,prepare_inputs:Ba},[q.MultiModality]:{can_generate:!0},[q.AutoEncoder]:{can_generate:!1,forward:J2},[q.Chatterbox]:{can_generate:!0,forward:Rr},[q.VoxtralRealtime]:{can_generate:!0,prepare_inputs:Cn},default:{can_generate:!1,forward:Rr}};function nm(e,t){var i;let r=wr.get(e),n=!1;const s=(i=t==null?void 0:t.architectures)==null?void 0:i[0];if(s&&s!==e&&(e!=null&&e.endsWith("ForCausalLM"))&&s.endsWith("ForConditionalGeneration")){const l=wr.get(s);l!==void 0&&(r=l,n=!0)}const a=rm[r]??rm.default,o=gr[r]??gr.default;return{typeConfig:{...a,...o},textOnly:n,modelType:r}}var wr=new Map,xl=new Map,An=new Map,I=class extends gt{constructor(t,r,n){super();T(this,"main_input_name","input_ids");T(this,"forward_params",["input_ids","attention_mask"]);T(this,"_return_dict_in_generate_keys",null);this.config=t,this.sessions=r,this.configs=n;const s=An.get(this.constructor),{typeConfig:a}=nm(s,t);this.can_generate=a.can_generate,this._forward=a.forward,this._prepare_inputs_for_generation=a.prepare_inputs,this.can_generate&&this.forward_params.push("past_key_values"),this.custom_config=this.config["transformers.js_config"]??{}}async dispose(){var r;const t=[];for(const n of Object.values(this.sessions))t.push((r=n.release)==null?void 0:r.call(n));return await Promise.all(t)}static async from_pretrained(t,{progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:a=!1,revision:o="main",model_file_name:i=null,subfolder:l="onnx",device:c=null,dtype:d=null,use_external_data_format:h=null,session_options:_={}}={}){const p={progress_callback:r,config:n,cache_dir:s,local_files_only:a,revision:o,model_file_name:i,subfolder:l,device:c,dtype:d,use_external_data_format:h,session_options:_},w=An.get(this);n=p.config=await ps.from_pretrained(t,p);const{typeConfig:v,textOnly:y,modelType:x}=nm(w,n);if(x===void 0){const C=w??(n==null?void 0:n.model_type);C!=="custom"&&he.warn(`Model type for '${C}' not found, assuming encoder-only architecture. Please report this at ${Aa}.`)}if(r&&!(r instanceof la)){const C={};try{const O=await em(t,{config:n,dtype:d,device:c,model_file_name:i});(await Promise.all(O.map(V=>cs(t,V,p)))).forEach((V,G)=>{if(V.exists){const U=O[G]==="config.json";C[O[G]]={loaded:U?V.size??0:0,total:V.size??0}}})}catch(O){he.warn(`Unable to fetch model file metadata for total progress tracking: ${O}`)}Object.keys(C).length>0&&(p.progress_callback=new la(r,C))}const k=v.sessions(n,p,y),A=[T2(t,k,p,v.cache_sessions)];v.optional_configs&&A.push(rA(t,v.optional_configs,p));const S=await Promise.all(A);return new this(n,...S)}async _call(t){return await this.forward(t)}async forward(t){return await this._forward(this,t)}get generation_config(){var t;return((t=this.configs)==null?void 0:t.generation_config)??null}_get_logits_processor(t,r,n=null){const s=new yl;if(t.repetition_penalty!==null&&t.repetition_penalty!==1&&s.push(new D2(t.repetition_penalty)),t.no_repeat_ngram_size!==null&&t.no_repeat_ngram_size>0&&s.push(new N2(t.no_repeat_ngram_size)),t.bad_words_ids!==null&&s.push(new R2(t.bad_words_ids,t.eos_token_id)),t.min_length!==null&&t.eos_token_id!==null&&t.min_length>0&&s.push(new z2(t.min_length,t.eos_token_id)),t.min_new_tokens!==null&&t.eos_token_id!==null&&t.min_new_tokens>0&&s.push(new B2(r,t.min_new_tokens,t.eos_token_id)),t.forced_bos_token_id!==null&&s.push(new F2(t.forced_bos_token_id)),t.forced_eos_token_id!==null&&s.push(new I2(t.max_length,t.forced_eos_token_id)),t.suppress_tokens!==null&&s.push(new L2(t.suppress_tokens)),t.begin_suppress_tokens!==null){const a=r>1||t.forced_bos_token_id===null?r:r+1;s.push(new Xp(t.begin_suppress_tokens,a))}return t.guidance_scale!==null&&t.guidance_scale>1&&s.push(new $2(t.guidance_scale)),t.temperature===0&&t.do_sample&&(he.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`."),t.do_sample=!1),t.do_sample&&t.temperature!==null&&t.temperature!==1&&s.push(new G2(t.temperature)),n!==null&&s.extend(n),s}_prepare_generation_config(t,r,n=Yp){const s={...this.config};for(const o of["decoder","generator","text_config"])o in s&&Object.assign(s,s[o]);const a=new n(s);return Object.assign(a,this.generation_config??{}),t&&Object.assign(a,t),r&&Object.assign(a,rt(r,Object.getOwnPropertyNames(a))),a}_get_stopping_criteria(t,r=null){const n=new Jp;return t.max_length!==null&&n.push(new V2(t.max_length,this.config.max_position_embeddings??null)),t.eos_token_id!==null&&n.push(new U2(t.eos_token_id)),r&&n.extend(r),n}_validate_model_class(){if(!this.can_generate){const t=[En.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,En.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,En.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,En.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES].filter(Boolean),r=An.get(this.constructor),n=new Set,s=this.config.model_type;for(const o of t){const i=o==null?void 0:o.get(s);i&&n.add(i)}let a=`The current model class (${r}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw n.size>0&&(a+=` Please use the following class instead: ${[...n].join(", ")}`),Error(a)}}prepare_inputs_for_generation(...t){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,...t)}_update_model_kwargs_for_generation({generated_input_ids:t,outputs:r,model_inputs:n,is_encoder_decoder:s}){return n.past_key_values=kl(r,n.past_key_values),n.input_ids=new j("int64",t.flat(),[t.length,1]),s?"decoder_attention_mask"in n&&(n.decoder_attention_mask=Re([n.decoder_attention_mask,xt([n.decoder_attention_mask.dims[0],1])],1)):n.attention_mask=Re([n.attention_mask,xt([n.attention_mask.dims[0],1])],1),n.position_ids=null,n}_prepare_model_inputs({inputs:t,bos_token_id:r,model_kwargs:n}){const s=rt(n,this.forward_params),a=this.main_input_name;if(a in s){if(t)throw new Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else s[a]=t;return{inputs_tensor:s[a],model_inputs:s,model_input_name:a}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:t,model_inputs:r,model_input_name:n,generation_config:s}){if(this.sessions.model.inputNames.includes("inputs_embeds")&&!r.inputs_embeds&&"_prepare_inputs_embeds"in this){const{input_ids:o,pixel_values:i,attention_mask:l,...c}=r,d=await this._prepare_inputs_embeds(r);r={...c,...rt(d,["inputs_embeds","attention_mask"])}}let{last_hidden_state:a}=await Rr(this,r);if(s.guidance_scale!==null&&s.guidance_scale>1)a=Re([a,Zi(a,0)],0),"attention_mask"in r&&(r.attention_mask=Re([r.attention_mask,tl(r.attention_mask)],0));else if(r.decoder_input_ids){const o=Ml(r.decoder_input_ids).dims[0];if(o!==a.dims[0]){if(a.dims[0]!==1)throw new Error(`The encoder outputs have a different batch size (${a.dims[0]}) than the decoder inputs (${o}).`);a=Re(Array.from({length:o},()=>a),0)}}return r.encoder_outputs=a,r}_prepare_decoder_input_ids_for_generation({batch_size:t,model_input_name:r,model_kwargs:n,decoder_start_token_id:s,bos_token_id:a,generation_config:o}){let{decoder_input_ids:i,...l}=n;if(!(i instanceof j)){if(i)Array.isArray(i[0])||(i=Array.from({length:t},()=>i));else if(s??(s=a),this.config.model_type==="musicgen")i=Array.from({length:t*this.config.decoder.num_codebooks},()=>[s]);else if(Array.isArray(s)){if(s.length!==t)throw new Error(`\`decoder_start_token_id\` expected to have length ${t} but got ${s.length}`);i=s}else i=Array.from({length:t},()=>[s]);i=Ml(i)}return l.decoder_attention_mask=el(i),{input_ids:i,model_inputs:l}}async generate({inputs:t=null,generation_config:r=null,logits_processor:n=null,stopping_criteria:s=null,streamer:a=null,...o}){this._validate_model_class(),r=this._prepare_generation_config(r,o);let{inputs_tensor:i,model_inputs:l,model_input_name:c}=this._prepare_model_inputs({inputs:t,model_kwargs:o});const d=this.config.is_encoder_decoder;d&&("encoder_outputs"in l||(l=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:i,model_inputs:l,model_input_name:c,generation_config:r})));let h;d?{input_ids:h,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:r.decoder_start_token_id,bos_token_id:r.bos_token_id,generation_config:r}):h=l[c];let _=h.dims.at(-1);r.max_new_tokens!==null&&(r.max_length=_+r.max_new_tokens);const p=this._get_logits_processor(r,_,n),w=this._get_stopping_criteria(r,s),v=l[c].dims.at(0),y=Na.getSampler(r),x=new Array(v).fill(0),k=h.tolist();a&&a.put(k);let A,S={},C={};for(;;){if(l=this.prepare_inputs_for_generation(k,l,r),A=await this.forward(l),r.return_dict_in_generate)if(r.output_attentions){const L=K2(A);for(const ee in L)ee in S||(S[ee]=[]),S[ee].push(L[ee])}else this._return_dict_in_generate_keys&&Object.assign(C,rt(A,this._return_dict_in_generate_keys));const U=A.logits.slice(null,-1,null).to("float32"),J=p(k,U),Q=[];for(let L=0;L<J.dims.at(0);++L){const ee=J[L],H=await y(ee);for(const[ne,Se]of H){const Y=BigInt(ne);x[L]+=Se,k[L].push(Y),Q.push([Y]);break}}if(a&&a.put(Q),w(k).every(L=>L))break;l=this._update_model_kwargs_for_generation({generated_input_ids:Q,outputs:A,model_inputs:l,is_encoder_decoder:d})}a&&a.end();const O=new j("int64",k.flat(),[k.length,k[0].length]),M=kl(A,l.past_key_values),V=new Set(Object.values(M));for(const U of Object.values(A))U.location==="gpu-buffer"&&!V.has(U)&&U.dispose();return"past_key_values"in o||r.return_dict_in_generate||await M.dispose(),r.return_dict_in_generate?{sequences:O,past_key_values:M,...S,...C}:O}async _encode_input(t,r,n){if(!Object.hasOwn(this.sessions,t))throw new Error(`Model does not have a ${t} session.`);const s=this.sessions[t];return(await ye(s,rt(r,s.inputNames)))[n]}async encode_image(t){return this._encode_input("vision_encoder",t,"image_features")}async encode_text(t){return this._encode_input("embed_tokens",t,"inputs_embeds")}async encode_audio(t){return this._encode_input("audio_encoder",t,"audio_features")}};async function Da(e,t){let{encoder_outputs:r,input_ids:n,decoder_input_ids:s,decoder_attention_mask:a,...o}=t;if(!r){const i=rt(t,e.sessions.model.inputNames);r=(await Rr(e,i)).last_hidden_state}return o.input_ids=s,o.encoder_hidden_states=r,e.sessions.decoder_model_merged.inputNames.includes("encoder_attention_mask")&&(o.encoder_attention_mask=t.attention_mask),a&&!o.attention_mask&&(o.attention_mask=a),await vr(e,o,!0)}async function Rr(e,t){const r=e.sessions.model,n=rt(t,r.inputNames);if(r.inputNames.includes("inputs_embeds")&&!n.inputs_embeds){if(!t.input_ids)throw new Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");n.inputs_embeds=await e.encode_text({input_ids:t.input_ids})}if(r.inputNames.includes("token_type_ids")&&!n.token_type_ids){if(!n.input_ids)throw new Error("Both `input_ids` and `token_type_ids` are missing in the model inputs.");n.token_type_ids=tl(n.input_ids)}if(r.inputNames.includes("pixel_mask")&&!n.pixel_mask){if(!n.pixel_values)throw new Error("Both `pixel_values` and `pixel_mask` are missing in the model inputs.");const s=n.pixel_values.dims;n.pixel_mask=xt([s[0],s[2],s[3]])}return await ye(r,n)}async function J2(e,t){const r=await e.encode(t);return await e.decode(r)}function kl(e,t){const r=Object.create(null);for(const n in e)if(n.startsWith("present")){const s=n.replace("present_ssm","past_ssm").replace("present_conv","past_conv").replace("present_recurrent","past_recurrent").replace("present_compressor","past_compressor").replace("present_indexer","past_indexer").replace("present","past_key_values");n.includes("encoder")&&t?r[s]=t[s]:r[s]=e[n]}return t?(t.update(r),t):new bl(r)}function K2(e){const t={};for(const r of["cross_attentions","encoder_attentions","decoder_attentions"])for(const n in e)n.startsWith(r)&&(r in t||(t[r]=[]),t[r].push(e[n]));return t}function sm(e,t){return e.map(r=>typeof r=="number"?r:t[r]??0)}function Tl(e,t,r){var c,d,h,_;if(r&&Object.keys(r).length>0)return Object.assign(t,r),r;const n=e.sessions.decoder_model_merged??e.sessions.model,s=((d=(c=t[e.main_input_name]??t.attention_mask)==null?void 0:c.dims)==null?void 0:d[0])??1,a=La(e.config),o=(_=(h=e.config)==null?void 0:h.normalized_config)==null?void 0:_.num_heads,i={batch_size:s};typeof o=="number"&&(i["batch_size x num_heads"]=s*o);const l=Object.create(null);for(const p of n.inputMetadata){if(!a.has(p.name))continue;const w=sm(p.shape,i),v=w.reduce((k,A)=>k*A,1),y=hs[p.type],x=new j(p.type,new y(v),w);t[p.name]=x,l[p.name]=x}return r?(r.update(l),r):new bl(l)}function ms(e,t,r){if(t.num_logits_to_keep)return;const n=e.sessions.decoder_model_merged??e.sessions.model;n!=null&&n.inputNames.includes("num_logits_to_keep")&&(t.num_logits_to_keep=new j("int64",[r],[]))}async function vr(e,t,r=!1){const n=e.sessions[r?"decoder_model_merged":"model"],{past_key_values:s,...a}=t;if(n.inputNames.includes("use_cache_branch")&&(a.use_cache_branch=tm(s!=null&&Object.keys(s).length>0)),n.inputNames.includes("position_ids")&&a.attention_mask&&!a.position_ids){const i=["paligemma","gemma3_text","gemma3"].includes(e.config.model_type)?1:0;a.position_ids=tA(a,s,i)}ms(e,a,0n),Tl(e,a,s);const o=rt(a,n.inputNames);return await ye(n,o)}async function am(e,{encode_function:t,merge_function:r,modality_input_names:n,modality_output_name:s,input_ids:a=null,attention_mask:o=null,position_ids:i=null,inputs_embeds:l=null,past_key_values:c=null,generation_config:d=null,logits_processor:h=null,num_logits_to_keep:_=null,...p}){if(!l){l=await e.encode_text({input_ids:a,...p});const v=rt(p,n);if(Object.keys(v).length>0){if(a.dims[1]!==1){const y=await t({...v,...p});({inputs_embeds:l,attention_mask:o}=r({[s]:y,inputs_embeds:l,input_ids:a,attention_mask:o}))}else if(c&&a.dims[1]===1){const y=a.dims[1],x=c.get_seq_length();o=Re([xt([a.dims[0],x]),o.slice(null,[o.dims[1]-y,o.dims[1]])],1)}}}if(!i&&["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(e.config.model_type)){const{image_grid_thw:v,video_grid_thw:y}=p;[i]=e.get_rope_index(a,v,y,o)}return await vr(e,{inputs_embeds:l,past_key_values:c,attention_mask:o,position_ids:i,generation_config:d,logits_processor:h,num_logits_to_keep:_},!0)}async function Z2(e,t){return await am(e,{...t,modality_input_names:["audio_values","input_features"],modality_output_name:"audio_features",encode_function:e.encode_audio.bind(e),merge_function:e._merge_input_ids_with_audio_features.bind(e)})}async function eA(e,t){return await am(e,{...t,modality_input_names:["pixel_values"],modality_output_name:"image_features",encode_function:e.encode_image.bind(e),merge_function:e._merge_input_ids_with_image_features.bind(e)})}function om(e,t=0){const[r,n]=e.dims,s=e.data,a=new BigInt64Array(s.length);for(let o=0;o<r;++o){const i=o*n;let l=BigInt(t);for(let c=0;c<n;++c){const d=i+c;s[d]===0n?a[d]=BigInt(1):(a[d]=l,l+=s[d])}}return{data:a,dims:e.dims}}function tA(e,t=null,r=0){const{input_ids:n,inputs_embeds:s,attention_mask:a}=e,{data:o,dims:i}=om(a,r);let l=new j("int64",o,i);if(t){const c=-(n??s).dims.at(1);l=l.slice(null,[c,null])}return l}function Cn(e,t,r,n){const s=r.past_key_values?r.past_key_values.get_seq_length():0;if(ms(e,r,1n),!r.attention_mask){let a;for(const o of["input_ids","inputs_embeds","position_ids"])if(r[o]){a=r[o].dims;break}if(!a)throw new Error("attention_mask is not provided, and unable to infer its shape from model inputs.");r.attention_mask=xt([a[0],s+a[1]])}if(r.past_key_values){const{input_ids:a,attention_mask:o}=r;o&&o.dims[1]>a.dims[1]||s<a.dims[1]&&(r.input_ids=a.slice(null,[s,null]))}return r}function za(e,t,r,n){return r.past_key_values&&(t=t.map(s=>[s.at(-1)])),ms(e,r,1n),{...r,decoder_input_ids:Ml(t)}}function Ba(e,...t){return e.config.is_encoder_decoder?za(e,...t):Cn(e,...t)}function im({modality_token_id:e,inputs_embeds:t,modality_features:r,input_ids:n,attention_mask:s}){const a=n.tolist().map(c=>c.reduce((d,h,_)=>(h==e&&d.push(_),d),[])),o=a.reduce((c,d)=>c+d.length,0),i=r.dims[0];if(o!==i)throw new Error(`Number of tokens and features do not match: tokens: ${o}, features ${i}`);let l=0;for(let c=0;c<a.length;++c){const d=a[c],h=t[c];for(let _=0;_<d.length;++_)h[d[_]].data.set(r[l++].data)}return{inputs_embeds:t,attention_mask:s}}function El({image_token_id:e,inputs_embeds:t,image_features:r,input_ids:n,attention_mask:s}){return im({modality_token_id:e,inputs_embeds:t,modality_features:r,input_ids:n,attention_mask:s})}function lm({audio_token_id:e,inputs_embeds:t,audio_features:r,input_ids:n,attention_mask:s}){return im({modality_token_id:e,inputs_embeds:t,modality_features:r,input_ids:n,attention_mask:s})}async function rA(e,t,r){return Object.fromEntries(await Promise.all(Object.keys(t).map(async n=>{const s=await nr(e,t[n],!1,r);return[n,s]})))}var Al={};as(Al,{ASTForAudioClassification:()=>_A,ASTModel:()=>fA,ASTPreTrainedModel:()=>Fl,AfmoeForCausalLM:()=>uA,AfmoeModel:()=>cA,AfmoePreTrainedModel:()=>Sl,AlbertForMaskedLM:()=>oA,AlbertForQuestionAnswering:()=>aA,AlbertForSequenceClassification:()=>sA,AlbertModel:()=>nA,AlbertPreTrainedModel:()=>gs,ApertusForCausalLM:()=>lA,ApertusModel:()=>iA,ApertusPreTrainedModel:()=>Cl,ArceeForCausalLM:()=>hA,ArceeModel:()=>dA,ArceePreTrainedModel:()=>Pl,BartForConditionalGeneration:()=>mA,BartForSequenceClassification:()=>gA,BartModel:()=>pA,BartPretrainedModel:()=>Ra,BaseModelOutput:()=>A2,BeitForImageClassification:()=>vA,BeitModel:()=>wA,BeitPreTrainedModel:()=>Il,BertForMaskedLM:()=>bA,BertForQuestionAnswering:()=>kA,BertForSequenceClassification:()=>MA,BertForTokenClassification:()=>xA,BertModel:()=>yA,BertPreTrainedModel:()=>Sn,BlenderbotForConditionalGeneration:()=>EA,BlenderbotModel:()=>TA,BlenderbotPreTrainedModel:()=>Ll,BlenderbotSmallForConditionalGeneration:()=>CA,BlenderbotSmallModel:()=>AA,BlenderbotSmallPreTrainedModel:()=>Ol,BloomForCausalLM:()=>PA,BloomModel:()=>SA,BloomPreTrainedModel:()=>Nl,CHMv2ForDepthEstimation:()=>BA,CHMv2PreTrainedModel:()=>fm,CLIPModel:()=>$A,CLIPPreTrainedModel:()=>nn,CLIPSegForImageSegmentation:()=>WA,CLIPSegModel:()=>jA,CLIPSegPreTrainedModel:()=>Dl,CLIPTextModel:()=>GA,CLIPTextModelWithProjection:()=>mm,CLIPVisionModel:()=>VA,CLIPVisionModelWithProjection:()=>UA,CamembertForMaskedLM:()=>IA,CamembertForQuestionAnswering:()=>NA,CamembertForSequenceClassification:()=>LA,CamembertForTokenClassification:()=>OA,CamembertModel:()=>FA,CamembertPreTrainedModel:()=>Pn,CausalLMOutput:()=>Br,CausalLMOutputWithPast:()=>C2,ChatterboxModel:()=>dm,ChatterboxPreTrainedModel:()=>um,ChineseCLIPModel:()=>zA,ChineseCLIPPreTrainedModel:()=>hm,ClapAudioModelWithProjection:()=>pm,ClapModel:()=>RA,ClapPreTrainedModel:()=>$a,ClapTextModelWithProjection:()=>_m,CodeGenForCausalLM:()=>HA,CodeGenModel:()=>qA,CodeGenPreTrainedModel:()=>zl,Cohere2ForCausalLM:()=>JA,Cohere2Model:()=>YA,Cohere2PreTrainedModel:()=>Rl,CohereAsrForConditionalGeneration:()=>ZA,CohereAsrModel:()=>KA,CohereAsrPreTrainedModel:()=>$l,CohereForCausalLM:()=>XA,CohereModel:()=>QA,CoherePreTrainedModel:()=>Bl,ConvBertForMaskedLM:()=>tC,ConvBertForQuestionAnswering:()=>sC,ConvBertForSequenceClassification:()=>rC,ConvBertForTokenClassification:()=>nC,ConvBertModel:()=>eC,ConvBertPreTrainedModel:()=>Fn,ConvNextForImageClassification:()=>oC,ConvNextModel:()=>aC,ConvNextPreTrainedModel:()=>Gl,ConvNextV2ForImageClassification:()=>lC,ConvNextV2Model:()=>iC,ConvNextV2PreTrainedModel:()=>Vl,DFineForObjectDetection:()=>hC,DFineModel:()=>dC,DFinePreTrainedModel:()=>jl,DINOv3ConvNextModel:()=>$C,DINOv3ConvNextPreTrainedModel:()=>Tm,DINOv3ViTModel:()=>GC,DINOv3ViTPreTrainedModel:()=>Em,DPTForDepthEstimation:()=>XC,DPTModel:()=>QC,DPTPreTrainedModel:()=>Jl,DacDecoderModel:()=>ym,DacDecoderOutput:()=>wm,DacEncoderModel:()=>vm,DacEncoderOutput:()=>gm,DacModel:()=>fC,DacPreTrainedModel:()=>Ga,DebertaForMaskedLM:()=>pC,DebertaForQuestionAnswering:()=>wC,DebertaForSequenceClassification:()=>mC,DebertaForTokenClassification:()=>gC,DebertaModel:()=>_C,DebertaPreTrainedModel:()=>In,DebertaV2ForMaskedLM:()=>kC,DebertaV2ForQuestionAnswering:()=>AC,DebertaV2ForSequenceClassification:()=>TC,DebertaV2ForTokenClassification:()=>EC,DebertaV2Model:()=>xC,DebertaV2PreTrainedModel:()=>Ln,DecisionTransformerModel:()=>CC,DecisionTransformerPreTrainedModel:()=>bm,DeepseekV3ForCausalLM:()=>yC,DeepseekV3Model:()=>vC,DeepseekV3PreTrainedModel:()=>Wl,DeepseekV4ForCausalLM:()=>MC,DeepseekV4Model:()=>bC,DeepseekV4PreTrainedModel:()=>ql,DeiTForImageClassification:()=>PC,DeiTModel:()=>SC,DeiTPreTrainedModel:()=>Hl,DepthAnythingForDepthEstimation:()=>FC,DepthAnythingPreTrainedModel:()=>Mm,DepthProForDepthEstimation:()=>IC,DepthProPreTrainedModel:()=>xm,DetrForObjectDetection:()=>OC,DetrForSegmentation:()=>NC,DetrModel:()=>LC,DetrObjectDetectionOutput:()=>Ql,DetrPreTrainedModel:()=>Va,DetrSegmentationOutput:()=>km,Dinov2ForImageClassification:()=>zC,Dinov2Model:()=>DC,Dinov2PreTrainedModel:()=>Xl,Dinov2WithRegistersForImageClassification:()=>RC,Dinov2WithRegistersModel:()=>BC,Dinov2WithRegistersPreTrainedModel:()=>Yl,DistilBertForMaskedLM:()=>qC,DistilBertForQuestionAnswering:()=>WC,DistilBertForSequenceClassification:()=>UC,DistilBertForTokenClassification:()=>jC,DistilBertModel:()=>VC,DistilBertPreTrainedModel:()=>On,DonutSwinModel:()=>HC,DonutSwinPreTrainedModel:()=>Am,EdgeTamModel:()=>fL,EfficientNetForImageClassification:()=>JC,EfficientNetModel:()=>YC,EfficientNetPreTrainedModel:()=>Kl,ElectraForMaskedLM:()=>ZC,ElectraForQuestionAnswering:()=>rS,ElectraForSequenceClassification:()=>eS,ElectraForTokenClassification:()=>tS,ElectraModel:()=>KC,ElectraPreTrainedModel:()=>Nn,EmbeddingGemma2Model:()=>Sm,EmbeddingGemma2PreTrainedModel:()=>Cm,Ernie4_5ForCausalLM:()=>sS,Ernie4_5Model:()=>nS,Ernie4_5PretrainedModel:()=>Zl,EsmForMaskedLM:()=>oS,EsmForSequenceClassification:()=>iS,EsmForTokenClassification:()=>lS,EsmModel:()=>aS,EsmPreTrainedModel:()=>vs,EuroBertForMaskedLM:()=>uS,EuroBertForSequenceClassification:()=>dS,EuroBertForTokenClassification:()=>hS,EuroBertModel:()=>cS,EuroBertPreTrainedModel:()=>ys,ExaoneForCausalLM:()=>_S,ExaoneModel:()=>fS,ExaonePreTrainedModel:()=>ec,FalconForCausalLM:()=>mS,FalconH1ForCausalLM:()=>wS,FalconH1Model:()=>gS,FalconH1PreTrainedModel:()=>rc,FalconModel:()=>pS,FalconPreTrainedModel:()=>tc,FastViTForImageClassification:()=>yS,FastViTModel:()=>vS,FastViTPreTrainedModel:()=>nc,Florence2ForConditionalGeneration:()=>bS,Florence2PreTrainedModel:()=>Pm,GLPNForDepthEstimation:()=>BS,GLPNModel:()=>zS,GLPNPreTrainedModel:()=>dc,GPT2LMHeadModel:()=>QS,GPT2Model:()=>HS,GPT2PreTrainedModel:()=>mc,GPTBigCodeForCausalLM:()=>$S,GPTBigCodeModel:()=>RS,GPTBigCodePreTrainedModel:()=>hc,GPTJForCausalLM:()=>YS,GPTJModel:()=>XS,GPTJPreTrainedModel:()=>gc,GPTNeoForCausalLM:()=>VS,GPTNeoModel:()=>GS,GPTNeoPreTrainedModel:()=>fc,GPTNeoXForCausalLM:()=>jS,GPTNeoXModel:()=>US,GPTNeoXPreTrainedModel:()=>_c,Gemma2ForCausalLM:()=>TS,Gemma2Model:()=>kS,Gemma2PreTrainedModel:()=>ac,Gemma3ForCausalLM:()=>SS,Gemma3ForConditionalGeneration:()=>Lm,Gemma3Model:()=>CS,Gemma3PreTrainedModel:()=>Im,Gemma3nForCausalLM:()=>PS,Gemma3nForConditionalGeneration:()=>Ua,Gemma3nPreTrainedModel:()=>Om,Gemma4ForCausalLM:()=>FS,Gemma4ForConditionalGeneration:()=>oc,GemmaForCausalLM:()=>xS,GemmaModel:()=>MS,GemmaPreTrainedModel:()=>sc,GlmForCausalLM:()=>LS,GlmModel:()=>IS,GlmMoeDsaForCausalLM:()=>NS,GlmMoeDsaModel:()=>OS,GlmMoeDsaPreTrainedModel:()=>lc,GlmOcrForConditionalGeneration:()=>DS,GlmPreTrainedModel:()=>ic,GptOssForCausalLM:()=>qS,GptOssModel:()=>WS,GptOssPreTrainedModel:()=>pc,GraniteForCausalLM:()=>KS,GraniteModel:()=>JS,GraniteMoeHybridForCausalLM:()=>eP,GraniteMoeHybridModel:()=>ZS,GraniteMoeHybridPreTrainedModel:()=>vc,GranitePreTrainedModel:()=>wc,GraniteSpeechForConditionalGeneration:()=>tP,GroundingDinoForObjectDetection:()=>rP,GroundingDinoPreTrainedModel:()=>Rm,GroupViTModel:()=>nP,GroupViTPreTrainedModel:()=>$m,HeliumForCausalLM:()=>aP,HeliumModel:()=>sP,HeliumPreTrainedModel:()=>bc,HieraForImageClassification:()=>iP,HieraModel:()=>oP,HieraPreTrainedModel:()=>Mc,HrmTextForCausalLM:()=>cP,HrmTextModel:()=>lP,HrmTextPreTrainedModel:()=>xc,HubertForCTC:()=>mP,HubertForSequenceClassification:()=>gP,HubertModel:()=>pP,HubertPreTrainedModel:()=>_P,HunYuanDenseV1ForCausalLM:()=>vP,HunYuanDenseV1Model:()=>wP,HunYuanDenseV1PreTrainedModel:()=>kc,IJepaForImageClassification:()=>bP,IJepaModel:()=>yP,IJepaPreTrainedModel:()=>Tc,Idefics3ForConditionalGeneration:()=>Gm,ImageMattingOutput:()=>Qp,JAISLMHeadModel:()=>xP,JAISModel:()=>MP,JAISPreTrainedModel:()=>Ec,JinaCLIPModel:()=>kP,JinaCLIPPreTrainedModel:()=>ja,JinaCLIPTextModel:()=>Vm,JinaCLIPVisionModel:()=>TP,Lfm2ForCausalLM:()=>AP,Lfm2Model:()=>EP,Lfm2MoeForCausalLM:()=>PP,Lfm2MoeModel:()=>SP,Lfm2MoePreTrainedModel:()=>Cc,Lfm2PreTrainedModel:()=>Ac,Lfm2VlForConditionalGeneration:()=>FP,LightOnOcrForConditionalGeneration:()=>CP,LiteWhisperForConditionalGeneration:()=>OO,Llama4ForCausalLM:()=>OP,Llama4PreTrainedModel:()=>Um,LlamaForCausalLM:()=>LP,LlamaModel:()=>IP,LlamaPreTrainedModel:()=>Sc,LlavaForConditionalGeneration:()=>ir,LlavaOnevisionForConditionalGeneration:()=>ir,LlavaPreTrainedModel:()=>Fm,LlavaQwen2ForCausalLM:()=>AS,LongT5ForConditionalGeneration:()=>DP,LongT5Model:()=>NP,LongT5PreTrainedModel:()=>Pc,M2M100ForConditionalGeneration:()=>BP,M2M100Model:()=>zP,M2M100PreTrainedModel:()=>Fc,MBartForCausalLM:()=>qP,MBartForConditionalGeneration:()=>jP,MBartForSequenceClassification:()=>WP,MBartModel:()=>UP,MBartPreTrainedModel:()=>bs,MPNetForMaskedLM:()=>zF,MPNetForQuestionAnswering:()=>$F,MPNetForSequenceClassification:()=>BF,MPNetForTokenClassification:()=>RF,MPNetModel:()=>DF,MPNetPreTrainedModel:()=>Dn,MT5ForConditionalGeneration:()=>jF,MT5Model:()=>UF,MT5PreTrainedModel:()=>jc,MarianMTModel:()=>$P,MarianModel:()=>RP,MarianPreTrainedModel:()=>Ic,MaskFormerForInstanceSegmentation:()=>VP,MaskFormerModel:()=>GP,MaskFormerPreTrainedModel:()=>Lc,MaskedLMOutput:()=>Je,Metric3DForDepthEstimation:()=>HP,Metric3DPreTrainedModel:()=>jm,Metric3Dv2ForDepthEstimation:()=>QP,Metric3Dv2PreTrainedModel:()=>Wm,MgpstrForSceneTextRecognition:()=>XP,MgpstrModelOutput:()=>qm,MgpstrPreTrainedModel:()=>Hm,MimiDecoderModel:()=>Jm,MimiDecoderOutput:()=>Xm,MimiEncoderModel:()=>Ym,MimiEncoderOutput:()=>Qm,MimiModel:()=>YP,MimiPreTrainedModel:()=>Wa,Ministral3ForCausalLM:()=>eF,Ministral3Model:()=>ZP,Ministral3PreTrainedModel:()=>Nc,MinistralForCausalLM:()=>KP,MinistralModel:()=>JP,MinistralPreTrainedModel:()=>Oc,Mistral3ForConditionalGeneration:()=>nF,Mistral4ForCausalLM:()=>aF,Mistral4Model:()=>sF,Mistral4PreTrainedModel:()=>zc,MistralForCausalLM:()=>rF,MistralModel:()=>tF,MistralPreTrainedModel:()=>Dc,MobileBertForMaskedLM:()=>iF,MobileBertForQuestionAnswering:()=>cF,MobileBertForSequenceClassification:()=>lF,MobileBertModel:()=>oF,MobileBertPreTrainedModel:()=>Ms,MobileLLMForCausalLM:()=>dF,MobileLLMModel:()=>uF,MobileLLMPreTrainedModel:()=>Bc,MobileNetV1ForImageClassification:()=>fF,MobileNetV1ForSemanticSegmentation:()=>_F,MobileNetV1Model:()=>hF,MobileNetV1PreTrainedModel:()=>qa,MobileNetV2ForImageClassification:()=>mF,MobileNetV2ForSemanticSegmentation:()=>gF,MobileNetV2Model:()=>pF,MobileNetV2PreTrainedModel:()=>Ha,MobileNetV3ForImageClassification:()=>vF,MobileNetV3ForSemanticSegmentation:()=>yF,MobileNetV3Model:()=>wF,MobileNetV3PreTrainedModel:()=>Qa,MobileNetV4ForImageClassification:()=>MF,MobileNetV4ForSemanticSegmentation:()=>xF,MobileNetV4Model:()=>bF,MobileNetV4PreTrainedModel:()=>Xa,MobileViTForImageClassification:()=>TF,MobileViTModel:()=>kF,MobileViTPreTrainedModel:()=>Rc,MobileViTV2ForImageClassification:()=>AF,MobileViTV2Model:()=>EF,MobileViTV2PreTrainedModel:()=>$c,ModelOutput:()=>je,ModernBertDecoderForCausalLM:()=>LF,ModernBertDecoderModel:()=>IF,ModernBertDecoderPreTrainedModel:()=>Gc,ModernBertForMaskedLM:()=>SF,ModernBertForSequenceClassification:()=>PF,ModernBertForTokenClassification:()=>FF,ModernBertModel:()=>CF,ModernBertPreTrainedModel:()=>xs,Moondream1ForConditionalGeneration:()=>ES,MoonshineForConditionalGeneration:()=>NF,MoonshineModel:()=>OF,MoonshinePreTrainedModel:()=>Vc,MptForCausalLM:()=>VF,MptModel:()=>GF,MptPreTrainedModel:()=>Uc,MultiModalityCausalLM:()=>WF,MultiModalityPreTrainedModel:()=>Km,MusicgenForCausalLM:()=>HF,MusicgenForConditionalGeneration:()=>Zm,MusicgenModel:()=>qF,MusicgenPreTrainedModel:()=>Wc,NanoChatForCausalLM:()=>XF,NanoChatModel:()=>QF,NanoChatPreTrainedModel:()=>qc,NemotronHForCausalLM:()=>JF,NemotronHModel:()=>YF,NemotronHPreTrainedModel:()=>Hc,NeoBertForMaskedLM:()=>ZF,NeoBertForQuestionAnswering:()=>rI,NeoBertForSequenceClassification:()=>eI,NeoBertForTokenClassification:()=>tI,NeoBertModel:()=>KF,NeoBertPreTrainedModel:()=>zn,NomicBertModel:()=>nI,NomicBertPreTrainedModel:()=>eg,OPTForCausalLM:()=>gI,OPTModel:()=>mI,OPTPreTrainedModel:()=>eu,Olmo2ForCausalLM:()=>iI,Olmo2Model:()=>oI,Olmo2PreTrainedModel:()=>Xc,Olmo3ForCausalLM:()=>cI,Olmo3Model:()=>lI,Olmo3PreTrainedModel:()=>Yc,OlmoForCausalLM:()=>aI,OlmoHybridForCausalLM:()=>dI,OlmoHybridModel:()=>uI,OlmoHybridPreTrainedModel:()=>Jc,OlmoModel:()=>sI,OlmoPreTrainedModel:()=>Qc,OpenAIPrivacyFilterForTokenClassification:()=>fI,OpenAIPrivacyFilterModel:()=>hI,OpenAIPrivacyFilterPreTrainedModel:()=>Kc,OpenELMForCausalLM:()=>pI,OpenELMModel:()=>_I,OpenELMPreTrainedModel:()=>Zc,OwlViTForObjectDetection:()=>bI,OwlViTModel:()=>yI,OwlViTPreTrainedModel:()=>ru,Owlv2ForObjectDetection:()=>vI,Owlv2Model:()=>wI,Owlv2PreTrainedModel:()=>tu,PaliGemmaForConditionalGeneration:()=>MI,ParakeetForCTC:()=>xI,ParakeetPreTrainedModel:()=>tg,PatchTSMixerForPrediction:()=>TI,PatchTSMixerModel:()=>kI,PatchTSMixerPreTrainedModel:()=>nu,PatchTSTForPrediction:()=>AI,PatchTSTModel:()=>EI,PatchTSTPreTrainedModel:()=>su,Phi3ForCausalLM:()=>FI,Phi3Model:()=>PI,Phi3PreTrainedModel:()=>ou,Phi3VForCausalLM:()=>ng,Phi3VPreTrainedModel:()=>rg,PhiForCausalLM:()=>SI,PhiModel:()=>CI,PhiPreTrainedModel:()=>au,PreTrainedModel:()=>I,PvtForImageClassification:()=>LI,PvtModel:()=>II,PvtPreTrainedModel:()=>iu,PyAnnoteForAudioFrameClassification:()=>NI,PyAnnoteModel:()=>OI,PyAnnotePreTrainedModel:()=>lu,QuestionAnsweringModelOutput:()=>it,Qwen2ForCausalLM:()=>zI,Qwen2Model:()=>DI,Qwen2MoeForCausalLM:()=>RI,Qwen2MoeModel:()=>BI,Qwen2MoePreTrainedModel:()=>uu,Qwen2PreTrainedModel:()=>cu,Qwen2VLForCausalLM:()=>Dm,Qwen2VLForConditionalGeneration:()=>cc,Qwen2VLPreTrainedModel:()=>Nm,Qwen2_5_VLForCausalLM:()=>zm,Qwen2_5_VLForConditionalGeneration:()=>uc,Qwen3ForCausalLM:()=>GI,Qwen3Model:()=>$I,Qwen3MoeForCausalLM:()=>UI,Qwen3MoeModel:()=>VI,Qwen3MoePreTrainedModel:()=>hu,Qwen3NextForCausalLM:()=>WI,Qwen3NextModel:()=>jI,Qwen3NextPreTrainedModel:()=>fu,Qwen3PreTrainedModel:()=>du,Qwen3VLForCausalLM:()=>sg,Qwen3VLForConditionalGeneration:()=>_u,Qwen3VLMoeForCausalLM:()=>HI,Qwen3VLMoeForConditionalGeneration:()=>qI,Qwen3_5ForCausalLM:()=>ag,Qwen3_5ForConditionalGeneration:()=>pu,Qwen3_5MoeForCausalLM:()=>XI,Qwen3_5MoeForConditionalGeneration:()=>QI,RFDetrForObjectDetection:()=>ZI,RFDetrModel:()=>KI,RFDetrObjectDetectionOutput:()=>og,RFDetrPreTrainedModel:()=>gu,RTDetrForObjectDetection:()=>uC,RTDetrModel:()=>cC,RTDetrObjectDetectionOutput:()=>ws,RTDetrPreTrainedModel:()=>Ul,RTDetrV2ForObjectDetection:()=>dL,RTDetrV2Model:()=>uL,RTDetrV2ObjectDetectionOutput:()=>ig,RTDetrV2PreTrainedModel:()=>wu,ResNetForImageClassification:()=>JI,ResNetModel:()=>YI,ResNetPreTrainedModel:()=>mu,RoFormerForMaskedLM:()=>oL,RoFormerForQuestionAnswering:()=>cL,RoFormerForSequenceClassification:()=>iL,RoFormerForTokenClassification:()=>lL,RoFormerModel:()=>aL,RoFormerPreTrainedModel:()=>Rn,RobertaForMaskedLM:()=>tL,RobertaForQuestionAnswering:()=>sL,RobertaForSequenceClassification:()=>rL,RobertaForTokenClassification:()=>nL,RobertaModel:()=>eL,RobertaPreTrainedModel:()=>Bn,Sam2ImageSegmentationOutput:()=>ug,Sam2Model:()=>vu,Sam2PreTrainedModel:()=>dg,Sam3TrackerModel:()=>_L,SamImageSegmentationOutput:()=>lg,SamModel:()=>hL,SamPreTrainedModel:()=>cg,SapiensForDepthEstimation:()=>mL,SapiensForNormalEstimation:()=>gL,SapiensForSemanticSegmentation:()=>pL,SapiensPreTrainedModel:()=>Ya,SegformerForImageClassification:()=>vL,SegformerForSemanticSegmentation:()=>yL,SegformerModel:()=>wL,SegformerPreTrainedModel:()=>Ja,Seq2SeqLMOutput:()=>S2,SequenceClassifierOutput:()=>le,SiglipModel:()=>bL,SiglipPreTrainedModel:()=>yu,SiglipTextModel:()=>hg,SiglipVisionModel:()=>ML,SmolLM3ForCausalLM:()=>kL,SmolLM3Model:()=>xL,SmolLM3PreTrainedModel:()=>bu,SmolVLMForConditionalGeneration:()=>TL,SnacDecoderModel:()=>_g,SnacEncoderModel:()=>fg,SnacModel:()=>EL,SnacPreTrainedModel:()=>Ka,SolarOpenForCausalLM:()=>CL,SolarOpenModel:()=>AL,SolarOpenPreTrainedModel:()=>Mu,SpeechT5ForSpeechToText:()=>PL,SpeechT5ForTextToSpeech:()=>FL,SpeechT5HifiGan:()=>IL,SpeechT5Model:()=>SL,SpeechT5PreTrainedModel:()=>Za,SqueezeBertForMaskedLM:()=>OL,SqueezeBertForQuestionAnswering:()=>DL,SqueezeBertForSequenceClassification:()=>NL,SqueezeBertModel:()=>LL,SqueezeBertPreTrainedModel:()=>ks,StableLmForCausalLM:()=>BL,StableLmModel:()=>zL,StableLmPreTrainedModel:()=>xu,Starcoder2ForCausalLM:()=>$L,Starcoder2Model:()=>RL,Starcoder2PreTrainedModel:()=>ku,StyleTextToSpeech2Model:()=>GL,StyleTextToSpeech2PreTrainedModel:()=>pg,SupertonicForConditionalGeneration:()=>gg,SupertonicPreTrainedModel:()=>mg,Swin2SRForImageSuperResolution:()=>qL,Swin2SRModel:()=>WL,Swin2SRPreTrainedModel:()=>Tu,SwinForImageClassification:()=>UL,SwinForSemanticSegmentation:()=>jL,SwinModel:()=>VL,SwinPreTrainedModel:()=>eo,T5ForConditionalGeneration:()=>QL,T5Model:()=>HL,T5PreTrainedModel:()=>Eu,TableTransformerForObjectDetection:()=>YL,TableTransformerModel:()=>XL,TableTransformerObjectDetectionOutput:()=>wg,TableTransformerPreTrainedModel:()=>Au,TokenClassifierOutput:()=>Xe,TrOCRForCausalLM:()=>JL,TrOCRPreTrainedModel:()=>vg,UltravoxModel:()=>yc,UltravoxPreTrainedModel:()=>Bm,UniSpeechForCTC:()=>ZL,UniSpeechForSequenceClassification:()=>eO,UniSpeechModel:()=>KL,UniSpeechPreTrainedModel:()=>to,UniSpeechSatForAudioFrameClassification:()=>sO,UniSpeechSatForCTC:()=>rO,UniSpeechSatForSequenceClassification:()=>nO,UniSpeechSatModel:()=>tO,UniSpeechSatPreTrainedModel:()=>Ts,VaultGemmaForCausalLM:()=>oO,VaultGemmaModel:()=>aO,VaultGemmaPreTrainedModel:()=>Cu,ViTForImageClassification:()=>cO,ViTMAEModel:()=>uO,ViTMAEPreTrainedModel:()=>yg,ViTMSNForImageClassification:()=>hO,ViTMSNModel:()=>dO,ViTMSNPreTrainedModel:()=>Pu,ViTModel:()=>lO,ViTPreTrainedModel:()=>Su,VisionEncoderDecoderModel:()=>iO,VitMatteForImageMatting:()=>fO,VitMattePreTrainedModel:()=>bg,VitPoseForPoseEstimation:()=>_O,VitPosePreTrainedModel:()=>Mg,VitsModel:()=>pO,VitsModelOutput:()=>xg,VitsPreTrainedModel:()=>kg,VoxtralForConditionalGeneration:()=>mO,VoxtralRealtimeForConditionalGeneration:()=>Ag,VoxtralRealtimePreTrainedModel:()=>Eg,Wav2Vec2BertForCTC:()=>kO,Wav2Vec2BertForSequenceClassification:()=>TO,Wav2Vec2BertModel:()=>xO,Wav2Vec2BertPreTrainedModel:()=>ro,Wav2Vec2ForAudioFrameClassification:()=>fP,Wav2Vec2ForCTC:()=>dP,Wav2Vec2ForSequenceClassification:()=>hP,Wav2Vec2Model:()=>uP,Wav2Vec2PreTrainedModel:()=>$r,WavLMForAudioFrameClassification:()=>PO,WavLMForCTC:()=>AO,WavLMForSequenceClassification:()=>CO,WavLMForXVector:()=>SO,WavLMModel:()=>EO,WavLMPreTrainedModel:()=>$n,WeSpeakerResNetModel:()=>FO,WeSpeakerResNetPreTrainedModel:()=>Sg,WhisperForConditionalGeneration:()=>Pg,WhisperModel:()=>LO,WhisperPreTrainedModel:()=>Iu,XLMForQuestionAnswering:()=>RO,XLMForSequenceClassification:()=>zO,XLMForTokenClassification:()=>BO,XLMModel:()=>NO,XLMPreTrainedModel:()=>Gn,XLMRobertaForMaskedLM:()=>GO,XLMRobertaForQuestionAnswering:()=>jO,XLMRobertaForSequenceClassification:()=>VO,XLMRobertaForTokenClassification:()=>UO,XLMRobertaModel:()=>$O,XLMRobertaPreTrainedModel:()=>Vn,XLMWithLMHeadModel:()=>DO,XVectorOutput:()=>Cg,YolosForObjectDetection:()=>qO,YolosModel:()=>WO,YolosObjectDetectionOutput:()=>Fg,YolosPreTrainedModel:()=>Lu,YoutuForCausalLM:()=>QO,YoutuModel:()=>HO,YoutuPreTrainedModel:()=>Ou,ZayaForCausalLM:()=>YO,ZayaModel:()=>XO,ZayaPreTrainedModel:()=>Nu});var gs=class extends I{},nA=class extends gs{},sA=class extends gs{async _call(e){return new le(await super._call(e))}},aA=class extends gs{async _call(e){return new it(await super._call(e))}},oA=class extends gs{async _call(e){return new Je(await super._call(e))}},Cl=class extends I{},iA=class extends Cl{},lA=class extends Cl{},Sl=class extends I{},cA=class extends Sl{},uA=class extends Sl{},Pl=class extends I{},dA=class extends Pl{},hA=class extends Pl{},Fl=class extends I{},fA=class extends Fl{},_A=class extends Fl{},Ra=class extends I{},pA=class extends Ra{},mA=class extends Ra{},gA=class extends Ra{async _call(e){return new le(await super._call(e))}},Il=class extends I{},wA=class extends Il{},vA=class extends Il{async _call(e){return new le(await super._call(e))}},Sn=class extends I{},yA=class extends Sn{},bA=class extends Sn{async _call(e){return new Je(await super._call(e))}},MA=class extends Sn{async _call(e){return new le(await super._call(e))}},xA=class extends Sn{async _call(e){return new Xe(await super._call(e))}},kA=class extends Sn{async _call(e){return new it(await super._call(e))}},Ll=class extends I{},TA=class extends Ll{},EA=class extends Ll{},Ol=class extends I{},AA=class extends Ol{},CA=class extends Ol{},Nl=class extends I{},SA=class extends Nl{},PA=class extends Nl{},Pn=class extends I{},FA=class extends Pn{},IA=class extends Pn{async _call(e){return new Je(await super._call(e))}},LA=class extends Pn{async _call(e){return new le(await super._call(e))}},OA=class extends Pn{async _call(e){return new Xe(await super._call(e))}},NA=class extends Pn{async _call(e){return new it(await super._call(e))}},DA=4299n,cm=6561n,um=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","inputs_embeds","attention_mask","position_ids","audio_values","exaggeration","audio_features","audio_tokens","speaker_embeddings","speaker_features","past_key_values"]);T(this,"main_input_name","input_ids");T(this,"_return_dict_in_generate_keys",["audio_tokens","speaker_embeddings","speaker_features"])}},dm=class extends um{async encode_speech(e){return ye(this.sessions.speech_encoder,{audio_values:e})}async forward({input_ids:e=null,attention_mask:t=null,audio_values:r=null,exaggeration:n=null,position_ids:s=null,inputs_embeds:a=null,past_key_values:o=null,generation_config:i=null,logits_processor:l=null,num_logits_to_keep:c=null,audio_features:d=null,audio_tokens:h=null,speaker_embeddings:_=null,speaker_features:p=null,...w}){let v;if(!a){const x=this.sessions.embed_tokens.inputNames,k={input_ids:e};if(x.includes("exaggeration")){if(!(n instanceof j)){const A=e.dims[0];if(n==null)n=dt([A],.5);else if(typeof n=="number")n=dt([A],n);else if(Array.isArray(n))n=new j("float32",n,[A]);else throw new Error("Unsupported type for `exaggeration` input")}k.exaggeration=n}if(x.includes("position_ids")&&(k.position_ids=s),{inputs_embeds:a}=await ye(this.sessions.embed_tokens,k),d&&h&&_&&p&&(v={audio_features:d,audio_tokens:h,speaker_embeddings:_,speaker_features:p}),v||r)v??(v=await this.encode_speech(r)),a=Re([v.audio_features,a],1),t=xt([a.dims[0],a.dims[1]]);else{const A=a.dims[1];if(!o||A!==1)throw new Error("Incorrect state encountered during generation.");const S=o.get_seq_length();t=xt([a.dims[0],S+A])}}return{...await vr(this,{inputs_embeds:a,past_key_values:o,attention_mask:t,generation_config:i,logits_processor:l,num_logits_to_keep:c},!1),...v}}prepare_inputs_for_generation(e,t,r){if(!t.position_ids&&this.sessions.embed_tokens.inputNames.includes("position_ids"))if(t.input_ids.dims[1]===1){const n=Array.from({length:e.length},(s,a)=>e[a].length-e[a].findLastIndex(o=>o==cm)-1);t.position_ids=new j("int64",n,[e.length,1])}else{const s=t.input_ids.tolist().map(a=>{let o=0;return a.map(i=>i>=cm?0:o++)});t.position_ids=new j("int64",s.flat(),t.input_ids.dims)}return t.input_ids.dims[1]===1&&(delete t.audio_values,delete t.audio_features,delete t.audio_tokens,delete t.speaker_embeddings,delete t.speaker_features),Cn(this,e,t)}async generate(e){const t=e.past_key_values,{sequences:r,audio_tokens:n,speaker_embeddings:s,speaker_features:a,past_key_values:o}=await super.generate({...e,return_dict_in_generate:!0});try{const i=r.slice(null,[e.input_ids.dims[1],-1]),l=dt([i.dims[0],3],DA),c=Re([n,i,l],1),{waveform:d}=await ye(this.sessions.conditional_decoder,{speech_tokens:c,speaker_features:a,speaker_embeddings:s});return d}finally{o!==t&&await(o==null?void 0:o.dispose())}}},hm=class extends I{},zA=class extends hm{},fm=class extends I{},BA=class extends fm{},$a=class extends I{},RA=class extends $a{},_m=class extends $a{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},pm=class extends $a{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"audio_model"})}},nn=class extends I{},$A=class extends nn{},GA=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},mm=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},VA=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"vision_model"})}},UA=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"vision_model"})}},Dl=class extends I{},jA=class extends Dl{},WA=class extends Dl{},zl=class extends I{},qA=class extends zl{},HA=class extends zl{},Bl=class extends I{},QA=class extends Bl{},XA=class extends Bl{},Rl=class extends I{},YA=class extends Rl{},JA=class extends Rl{},$l=class extends I{constructor(){super(...arguments);T(this,"requires_attention_mask",!1);T(this,"main_input_name","input_features");T(this,"forward_params",["input_features","decoder_input_ids","decoder_attention_mask","past_key_values"])}},KA=class extends $l{},ZA=class extends $l{},Fn=class extends I{},eC=class extends Fn{},tC=class extends Fn{async _call(e){return new Je(await super._call(e))}},rC=class extends Fn{async _call(e){return new le(await super._call(e))}},nC=class extends Fn{async _call(e){return new Xe(await super._call(e))}},sC=class extends Fn{async _call(e){return new it(await super._call(e))}},Gl=class extends I{},aC=class extends Gl{},oC=class extends Gl{async _call(e){return new le(await super._call(e))}},Vl=class extends I{},iC=class extends Vl{},lC=class extends Vl{async _call(e){return new le(await super._call(e))}},Ul=class extends I{},cC=class extends Ul{},uC=class extends Ul{async _call(e){return new ws(await super._call(e))}},ws=class extends je{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}},jl=class extends I{},dC=class extends jl{},hC=class extends jl{async _call(e){return new ws(await super._call(e))}},gm=class extends je{constructor({audio_codes:e}){super(),this.audio_codes=e}},wm=class extends je{constructor({audio_values:e}){super(),this.audio_values=e}},Ga=class extends I{constructor(){super(...arguments);T(this,"main_input_name","input_values");T(this,"forward_params",["input_values"])}},fC=class extends Ga{async encode(e){return new gm(await ye(this.sessions.encoder_model,e))}async decode(e){return new wm(await ye(this.sessions.decoder_model,e))}},vm=class extends Ga{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"encoder_model"})}},ym=class extends Ga{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"decoder_model"})}},In=class extends I{},_C=class extends In{},pC=class extends In{async _call(e){return new Je(await super._call(e))}},mC=class extends In{async _call(e){return new le(await super._call(e))}},gC=class extends In{async _call(e){return new Xe(await super._call(e))}},wC=class extends In{async _call(e){return new it(await super._call(e))}},Wl=class extends I{},vC=class extends Wl{},yC=class extends Wl{},ql=class extends I{},bC=class extends ql{},MC=class extends ql{},Ln=class extends I{},xC=class extends Ln{},kC=class extends Ln{async _call(e){return new Je(await super._call(e))}},TC=class extends Ln{async _call(e){return new le(await super._call(e))}},EC=class extends Ln{async _call(e){return new Xe(await super._call(e))}},AC=class extends Ln{async _call(e){return new it(await super._call(e))}},bm=class extends I{},CC=class extends bm{},Hl=class extends I{},SC=class extends Hl{},PC=class extends Hl{async _call(e){return new le(await super._call(e))}},Mm=class extends I{},FC=class extends Mm{},xm=class extends I{},IC=class extends xm{},Va=class extends I{},LC=class extends Va{},OC=class extends Va{async _call(e){return new Ql(await super._call(e))}},NC=class extends Va{async _call(e){return new km(await super._call(e))}},Ql=class extends je{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}},km=class extends je{constructor({logits:e,pred_boxes:t,pred_masks:r}){super(),this.logits=e,this.pred_boxes=t,this.pred_masks=r}},Xl=class extends I{},DC=class extends Xl{},zC=class extends Xl{async _call(e){return new le(await super._call(e))}},Yl=class extends I{},BC=class extends Yl{},RC=class extends Yl{async _call(e){return new le(await super._call(e))}},Tm=class extends I{},$C=class extends Tm{},Em=class extends I{},GC=class extends Em{},On=class extends I{},VC=class extends On{},UC=class extends On{async _call(e){return new le(await super._call(e))}},jC=class extends On{async _call(e){return new Xe(await super._call(e))}},WC=class extends On{async _call(e){return new it(await super._call(e))}},qC=class extends On{async _call(e){return new Je(await super._call(e))}},Am=class extends I{},HC=class extends Am{},Jl=class extends I{},QC=class extends Jl{},XC=class extends Jl{},Kl=class extends I{},YC=class extends Kl{},JC=class extends Kl{async _call(e){return new le(await super._call(e))}},Nn=class extends I{},KC=class extends Nn{},ZC=class extends Nn{async _call(e){return new Je(await super._call(e))}},eS=class extends Nn{async _call(e){return new le(await super._call(e))}},tS=class extends Nn{async _call(e){return new Xe(await super._call(e))}},rS=class extends Nn{async _call(e){return new it(await super._call(e))}},Cm=class extends I{},Sm=class extends Cm{async forward({input_ids:e,attention_mask:t,pixel_values:r=null,image_position_ids:n=null,pixel_values_videos:s=null,video_position_ids:a=null,input_features:o=null,input_features_mask:i=null}){const l={image_features:r&&await this.encode_image({pixel_values:r,pixel_position_ids:n}),video_features:s&&await this.encode_image({pixel_values:s,pixel_position_ids:a}),audio_features:o&&await this.encode_audio({input_features:o,input_features_mask:i})},{image_token_id:c,video_token_id:d,audio_token_id:h,text_config:_}=this.config,p={image:c,video:d,audio:h};for(const[w,v]of Object.entries(p)){const y=`${w}_features`;l[y]??(l[y]=new j("float32",new Float32Array(0),[0,_.hidden_size]));let x=0;for(const k of e.data)Number(k)===v&&++x;if(x!==l[y].dims[0])throw new Error(`The number of ${w} tokens (${x}) and ${w} features (${l[y].dims[0]}) do not match.`)}return await ye(this.sessions.model,{input_ids:e,attention_mask:t,...l})}},Zl=class extends I{},nS=class extends Zl{},sS=class extends Zl{},vs=class extends I{},aS=class extends vs{},oS=class extends vs{async _call(e){return new Je(await super._call(e))}},iS=class extends vs{async _call(e){return new le(await super._call(e))}},lS=class extends vs{async _call(e){return new Xe(await super._call(e))}},ys=class extends I{},cS=class extends ys{},uS=class extends ys{async _call(e){return new Je(await super._call(e))}},dS=class extends ys{async _call(e){return new le(await super._call(e))}},hS=class extends ys{async _call(e){return new Xe(await super._call(e))}},ec=class extends I{},fS=class extends ec{},_S=class extends ec{},tc=class extends I{},pS=class extends tc{},mS=class extends tc{},rc=class extends I{},gS=class extends rc{},wS=class extends rc{},nc=class extends I{},vS=class extends nc{},yS=class extends nc{async _call(e){return new le(await super._call(e))}},Pm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","inputs_embeds","attention_mask","pixel_values","encoder_outputs","decoder_input_ids","decoder_inputs_embeds","decoder_attention_mask","past_key_values"]);T(this,"main_input_name","inputs_embeds")}},bS=class extends Pm{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:t,input_ids:r,attention_mask:n}){return{inputs_embeds:Re([t,e],1),attention_mask:Re([xt(t.dims.slice(0,2)),n],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:r,attention_mask:n}){if(!e&&!t)throw new Error("Either `input_ids` or `pixel_values` should be provided.");let s,a;return e&&(s=await this.encode_text({input_ids:e})),t&&(a=await this.encode_image({pixel_values:t})),s&&a?{inputs_embeds:r,attention_mask:n}=this._merge_input_ids_with_image_features({inputs_embeds:s,image_features:a,input_ids:e,attention_mask:n}):r=s||a,{inputs_embeds:r,attention_mask:n}}async forward({input_ids:e,pixel_values:t,attention_mask:r,decoder_input_ids:n,decoder_attention_mask:s,encoder_outputs:a,past_key_values:o,inputs_embeds:i,decoder_inputs_embeds:l,num_logits_to_keep:c=null}){if(i||({inputs_embeds:i,attention_mask:r}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:i,attention_mask:r})),!a){let{last_hidden_state:h}=await Rr(this,{inputs_embeds:i,attention_mask:r});a=h}if(!l){if(!n)throw new Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");l=await this.encode_text({input_ids:n})}return await vr(this,{inputs_embeds:l,attention_mask:s,encoder_attention_mask:r,encoder_hidden_states:a,past_key_values:o,num_logits_to_keep:c},!0)}},sc=class extends I{},MS=class extends sc{},xS=class extends sc{},ac=class extends I{},kS=class extends ac{},TS=class extends ac{},Fm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","pixel_values","position_ids","past_key_values"])}},ir=class extends Fm{_merge_input_ids_with_image_features(e){const t=e.image_features.dims.at(-1),r=e.image_features.view(-1,t);return El({image_token_id:this.config.image_token_index??this.config.image_token_id,...e,image_features:r})}},ES=class extends ir{},AS=class extends ir{},Im=class extends I{},CS=class extends Im{},Lm=class extends ir{},SS=class extends Lm{},Om=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","inputs_embeds","per_layer_inputs","position_ids","pixel_values","input_features","input_features_mask","past_key_values"])}},Ua=class extends Om{async forward({input_ids:e=null,attention_mask:t=null,pixel_values:r=null,input_features:n=null,input_features_mask:s=null,position_ids:a=null,inputs_embeds:o=null,per_layer_inputs:i=null,past_key_values:l=null,generation_config:c=null,logits_processor:d=null,num_logits_to_keep:h=null,..._}){if((!o||!i)&&({inputs_embeds:o,per_layer_inputs:i}=await ye(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(r){const{image_features:w}=await this._encode_vision({pixel_values:r,..._});({inputs_embeds:o,attention_mask:t}=this._merge_input_ids_with_image_features({image_features:w,inputs_embeds:o,input_ids:e,attention_mask:t}))}if(n){const{audio_features:w}=await ye(this.sessions.audio_encoder,{input_features:n,input_features_mask:s});({inputs_embeds:o,attention_mask:t}=this._merge_input_ids_with_audio_features({audio_features:w,inputs_embeds:o,input_ids:e,attention_mask:t}))}}return await vr(this,{inputs_embeds:o,per_layer_inputs:i,past_key_values:l,attention_mask:t,position_ids:a,generation_config:c,logits_processor:d,num_logits_to_keep:h},!0)}_encode_vision(e){return ye(this.sessions.vision_encoder,{pixel_values:e.pixel_values})}_merge_input_ids_with_image_features(e){const t=e.image_features.dims.at(-1),r=e.image_features.view(-1,t);return El({image_token_id:this.config.image_token_id,...e,image_features:r})}_merge_input_ids_with_audio_features(e){const t=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,t);return lm({audio_token_id:this.config.audio_token_id,...e,audio_features:r})}},PS=class extends Ua{},oc=class extends Ua{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","inputs_embeds","per_layer_inputs","position_ids","pixel_values","image_position_ids","input_features","input_features_mask","past_key_values"])}_encode_vision(t){return ye(this.sessions.vision_encoder,{pixel_values:t.pixel_values,pixel_position_ids:t.image_position_ids})}},FS=class extends oc{},ic=class extends I{},IS=class extends ic{},LS=class extends ic{},lc=class extends I{},OS=class extends lc{},NS=class extends lc{},Nm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","position_ids","past_key_values","pixel_values","image_grid_thw"])}},cc=class extends Nm{constructor(){super(...arguments);T(this,"image_grid_thw_name","grid_thw")}_get_text_only_rope_index(t,r){if(r){const{data:n,dims:s}=om(r),a=BigInt64Array.from({length:3*n.length},(i,l)=>n[l%n.length]),o=Array.from({length:s[0]},(i,l)=>Qe(n.subarray(s[1]*l,s[1]*(l+1)))[0]+1n+BigInt(s[1]));return[new j("int64",a,[3,...s]),new j("int64",o,[o.length,1])]}else{const[n,s]=t.dims,a=BigInt64Array.from({length:3*n*s},(o,i)=>BigInt(Math.floor(i%s/n)));return[new j("int64",a,[3,...t.dims]),W_([n,1])]}}_reorder_and_write_positions(t,r,n,s){const a=t.reduce((c,d)=>c+d.length,0),o=new Array(a);let i=0;for(let c=0;c<3;++c)for(const d of t){const h=d.length/3;for(let _=c*h;_<(c+1)*h;++_)o[i++]=d[_]}let l=0;for(let c=0;c<r.length;++c)if(r[c]==1){for(let d=0;d<3;++d)n[d][s][c]=o[d*a/3+l];++l}return o}_get_multimodal_rope_positions({filtered_ids:t,image_grid_thw_list:r,video_grid_thw_list:n,spatial_merge_size:s,state:a}){const{image_token_id:o,video_token_id:i,vision_start_token_id:l}=this.config,c=t,h=c.reduce((k,A,S)=>(A==l&&k.push(S),k),[]).map(k=>c[k+1]),_=h.filter(k=>k==o).length,p=h.filter(k=>k==i).length,w=[];let v=0,y=_,x=p;for(let k=0;k<h.length;++k){const A=c.findIndex((D,R)=>R>v&&D==o),S=c.findIndex((D,R)=>R>v&&D==i),C=y>0&&A!==-1?A:c.length+1,O=x>0&&S!==-1?S:c.length+1;let M,V,G,U;C<O?([V,G,U]=r[a.image_index],++a.image_index,--y,M=C):([V,G,U]=n[a.video_index],++a.video_index,--x,M=O);const[J,Q,B]=[Number(V),Math.floor(Number(G)/s),Math.floor(Number(U)/s)],L=M-v,ee=w.length>0?Qe(w.at(-1))[0]+1:0;w.push(Array.from({length:3*L},(D,R)=>ee+R%L));const H=L+ee,ne=J*Q*B,Se=Array.from({length:ne},(D,R)=>H+Math.floor(R/(Q*B))),Y=Array.from({length:ne},(D,R)=>H+Math.floor(R/B)%Q),N=Array.from({length:ne},(D,R)=>H+R%B);w.push([Se,Y,N].flat()),v=M+ne}if(v<c.length){const k=w.length>0?Qe(w.at(-1))[0]+1:0,A=c.length-v;w.push(Array.from({length:3*A},(S,C)=>k+C%A))}return w}get_rope_index(t,r,n,s){const{vision_config:a}=this.config,o=a.spatial_merge_size??2;if(r||n){const i=t.tolist();s||(s=el(t));const l=s.tolist(),c=Array.from({length:3},()=>Array.from({length:t.dims[0]},()=>Array.from({length:t.dims[1]},()=>0))),d=r?r.tolist():[],h=n?n.tolist():[],_={image_index:0,video_index:0},p=[];for(let w=0;w<i.length;++w){const v=i[w].filter((k,A)=>l[w][A]==1),y=this._get_multimodal_rope_positions({filtered_ids:v,image_grid_thw_list:d,video_grid_thw_list:h,spatial_merge_size:o,state:_}),x=this._reorder_and_write_positions(y,l[w],c,w);p.push(Qe(x)[0]+1-i[w].length)}return[new j("int64",c.flat(1/0),[3,t.dims[0],t.dims[1]]),new j("int64",p,[p.length,1])]}else return this._get_text_only_rope_index(t,s)}async encode_image({pixel_values:t,image_grid_thw:r}){return(await ye(this.sessions.vision_encoder,{pixel_values:t,[this.image_grid_thw_name]:r})).image_features}_merge_input_ids_with_image_features(t){return El({image_token_id:this.config.image_token_id,...t})}prepare_inputs_for_generation(t,r,n){if(ms(this,r,1n),!r.attention_mask||r.position_ids||!(this.sessions.decoder_model_merged??this.sessions.model).inputNames.includes("position_ids"))return r;if(!r.past_key_values)[r.position_ids,r.rope_deltas]=this.get_rope_index(r.input_ids,r.image_grid_thw,r.video_grid_thw,r.attention_mask);else{r.pixel_values=null;const a=r.past_key_values.get_seq_length();if(a<r.input_ids.dims[1]){const[o,i]=this.get_rope_index(r.input_ids,r.image_grid_thw,r.video_grid_thw,r.attention_mask);r.rope_deltas=i,r.position_ids=o.slice(null,null,[a,null]),r.input_ids=r.input_ids.slice(null,[a,null])}else{r.rope_deltas||([,r.rope_deltas]=this.get_rope_index(r.input_ids,r.image_grid_thw,r.video_grid_thw,r.attention_mask));const o=BigInt(a),i=r.rope_deltas.map(l=>o+l);r.position_ids=pr([i,i,i],0)}}return r}},Dm=class extends cc{},uc=class extends cc{constructor(){super(...arguments);T(this,"image_grid_thw_name","image_grid_thw")}},zm=class extends Dm{constructor(){super(...arguments);T(this,"image_grid_thw_name","image_grid_thw")}},DS=class extends uc{get_vision_position_ids(e,t,r,n){const s=Math.floor(t[0]/r),a=Math.floor(t[1]/n),o=Math.floor(t[2]/n),i=a*o*s,l=Array.from({length:i},()=>e),c=Array.from({length:i},(h,_)=>e+Math.floor(_/(o*s))),d=Array.from({length:i},(h,_)=>e+_%o);return[...l,...c,...d]}_get_multimodal_rope_positions({filtered_ids:e,image_grid_thw_list:t,video_grid_thw_list:r,spatial_merge_size:n,state:s}){const{image_token_id:a}=this.config,o=[];let i=0,l=e[0]==a?1:0;for(let h=1;h<=e.length;++h){const _=h<e.length?e[h]==a?1:0:-1;_!==l&&(o.push([l,i,h]),i=h,l=_)}let c=0;const d=[];for(const[h,_,p]of o)if(h===0){const w=p-_;d.push(Array.from({length:3*w},(v,y)=>c+y%w)),c+=w}else{const w=t[s.image_index++].map(Number),v=w[0];d.push(this.get_vision_position_ids(c,w,v,n)),c+=Math.max(w[1],w[2])/n}return d}},dc=class extends I{},zS=class extends dc{},BS=class extends dc{},hc=class extends I{},RS=class extends hc{},$S=class extends hc{},fc=class extends I{},GS=class extends fc{},VS=class extends fc{},_c=class extends I{},US=class extends _c{},jS=class extends _c{},pc=class extends I{},WS=class extends pc{},qS=class extends pc{},mc=class extends I{},HS=class extends mc{},QS=class extends mc{},gc=class extends I{},XS=class extends gc{},YS=class extends gc{},wc=class extends I{},JS=class extends wc{},KS=class extends wc{},vc=class extends I{},ZS=class extends vc{},eP=class extends vc{},Bm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","position_ids","audio_values","past_key_values"])}},yc=class extends Bm{_merge_input_ids_with_audio_features(e){const t=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,t);return lm({audio_token_id:this.config.ignore_index??this.config.audio_token_id??this.config.audio_token_index,...e,audio_features:r})}},tP=class extends yc{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","input_features","past_key_values"])}},Rm=class extends I{},rP=class extends Rm{},$m=class extends I{},nP=class extends $m{},bc=class extends I{},sP=class extends bc{},aP=class extends bc{},Mc=class extends I{},oP=class extends Mc{},iP=class extends Mc{async _call(e){return new le(await super._call(e))}},xc=class extends I{},lP=class extends xc{},cP=class extends xc{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","token_type_ids","past_key_values"])}prepare_inputs_for_generation(t,r,n){const s=Cn(this,t,r);return s.token_type_ids=(s.past_key_values?tl:el)(s.input_ids),s}},$r=class extends I{},uP=class extends $r{},dP=class extends $r{async _call(e){return new Br(await super._call(e))}},hP=class extends $r{async _call(e){return new le(await super._call(e))}},fP=class extends $r{async _call(e){return new Xe(await super._call(e))}},_P=class extends I{},pP=class extends $r{},mP=class extends $r{async _call(e){return new Br(await super._call(e))}},gP=class extends $r{async _call(e){return new le(await super._call(e))}},kc=class extends I{},wP=class extends kc{},vP=class extends kc{},Gm=class extends ir{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","pixel_values","pixel_attention_mask","position_ids","past_key_values"])}},Tc=class extends I{},yP=class extends Tc{},bP=class extends Tc{async _call(e){return new le(await super._call(e))}},Ec=class extends I{},MP=class extends Ec{},xP=class extends Ec{},ja=class extends I{},kP=class extends ja{async forward(e){const t=!e.input_ids,r=!e.pixel_values;if(t&&r)throw new Error("Either `input_ids` or `pixel_values` should be provided.");if(t&&(e.input_ids=xt([e.pixel_values.dims[0],1])),r){const{image_size:l}=this.config.vision_config;e.pixel_values=dt([0,3,l,l],0)}const{text_embeddings:n,image_embeddings:s,l2norm_text_embeddings:a,l2norm_image_embeddings:o}=await super.forward(e),i={};return t||(i.text_embeddings=n,i.l2norm_text_embeddings=a),r||(i.image_embeddings=s,i.l2norm_image_embeddings=o),i}},Vm=class extends ja{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},TP=class extends ja{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"vision_model"})}},Ac=class extends I{},EP=class extends Ac{},AP=class extends Ac{},CP=class extends ir{},Cc=class extends I{},SP=class extends Cc{},PP=class extends Cc{},FP=class extends ir{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","pixel_values","pixel_attention_mask","spatial_shapes","position_ids","past_key_values"])}},Sc=class extends I{},IP=class extends Sc{},LP=class extends Sc{},Um=class extends I{},OP=class extends Um{},Pc=class extends I{},NP=class extends Pc{},DP=class extends Pc{},Fc=class extends I{},zP=class extends Fc{},BP=class extends Fc{},Ic=class extends I{},RP=class extends Ic{},$P=class extends Ic{},Lc=class extends I{},GP=class extends Lc{},VP=class extends Lc{},bs=class extends I{},UP=class extends bs{},jP=class extends bs{},WP=class extends bs{async _call(e){return new le(await super._call(e))}},qP=class extends bs{},jm=class extends I{},HP=class extends jm{},Wm=class extends I{},QP=class extends Wm{},qm=class extends je{constructor({char_logits:e,bpe_logits:t,wp_logits:r}){super(),this.char_logits=e,this.bpe_logits=t,this.wp_logits=r}get logits(){return[this.char_logits,this.bpe_logits,this.wp_logits]}},Hm=class extends I{},XP=class extends Hm{async _call(e){return new qm(await super._call(e))}},Qm=class extends je{constructor({audio_codes:e}){super(),this.audio_codes=e}},Xm=class extends je{constructor({audio_values:e}){super(),this.audio_values=e}},Wa=class extends I{constructor(){super(...arguments);T(this,"main_input_name","input_values");T(this,"forward_params",["input_values"])}},YP=class extends Wa{async encode(e){return new Qm(await ye(this.sessions.encoder_model,e))}async decode(e){return new Xm(await ye(this.sessions.decoder_model,e))}},Ym=class extends Wa{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"encoder_model"})}},Jm=class extends Wa{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"decoder_model"})}},Oc=class extends I{},JP=class extends Oc{},KP=class extends Oc{},Nc=class extends I{},ZP=class extends Nc{},eF=class extends Nc{},Dc=class extends I{},tF=class extends Dc{},rF=class extends Dc{},nF=class extends ir{},zc=class extends I{},sF=class extends zc{},aF=class extends zc{},Ms=class extends I{},oF=class extends Ms{},iF=class extends Ms{async _call(e){return new Je(await super._call(e))}},lF=class extends Ms{async _call(e){return new le(await super._call(e))}},cF=class extends Ms{async _call(e){return new it(await super._call(e))}},Bc=class extends I{},uF=class extends Bc{},dF=class extends Bc{},qa=class extends I{},hF=class extends qa{},fF=class extends qa{async _call(e){return new le(await super._call(e))}},_F=class extends qa{},Ha=class extends I{},pF=class extends Ha{},mF=class extends Ha{async _call(e){return new le(await super._call(e))}},gF=class extends Ha{},Qa=class extends I{},wF=class extends Qa{},vF=class extends Qa{async _call(e){return new le(await super._call(e))}},yF=class extends Qa{},Xa=class extends I{},bF=class extends Xa{},MF=class extends Xa{async _call(e){return new le(await super._call(e))}},xF=class extends Xa{},Rc=class extends I{},kF=class extends Rc{},TF=class extends Rc{async _call(e){return new le(await super._call(e))}},$c=class extends I{},EF=class extends $c{},AF=class extends $c{async _call(e){return new le(await super._call(e))}},xs=class extends I{},CF=class extends xs{},SF=class extends xs{async _call(e){return new Je(await super._call(e))}},PF=class extends xs{async _call(e){return new le(await super._call(e))}},FF=class extends xs{async _call(e){return new Xe(await super._call(e))}},Gc=class extends I{},IF=class extends Gc{},LF=class extends Gc{},Vc=class extends I{constructor(){super(...arguments);T(this,"requires_attention_mask",!1);T(this,"main_input_name","input_values");T(this,"forward_params",["input_values","decoder_input_ids","past_key_values"])}},OF=class extends Vc{},NF=class extends Vc{},Dn=class extends I{},DF=class extends Dn{},zF=class extends Dn{async _call(e){return new Je(await super._call(e))}},BF=class extends Dn{async _call(e){return new le(await super._call(e))}},RF=class extends Dn{async _call(e){return new Xe(await super._call(e))}},$F=class extends Dn{async _call(e){return new it(await super._call(e))}},Uc=class extends I{},GF=class extends Uc{},VF=class extends Uc{},jc=class extends I{},UF=class extends jc{},jF=class extends jc{},Km=class extends I{},WF=class extends Km{constructor(...t){super(...t);T(this,"forward_params",["input_ids","pixel_values","images_seq_mask","images_emb_mask","attention_mask","position_ids","past_key_values"]);this._generation_mode="text"}async forward(t){const r=this._generation_mode??"text";let n;if(r==="text"||!t.past_key_values){const l=this.sessions.prepare_inputs_embeds,c=rt(t,l.inputNames);n=await ye(l,c)}else{const l=this.sessions.gen_img_embeds,c=rt({image_ids:t.input_ids},l.inputNames);n=await ye(l,c)}const s={...t,...n},a=await vr(this,s),o=this.sessions[r==="text"?"lm_head":"gen_head"];if(!o)throw new Error(`Unable to find "${o}" generation head`);const i=await ye(o,rt(a,o.inputNames));return{...n,...a,...i}}prepare_inputs_for_generation(t,r,n){const s=!!r.past_key_values;return ms(this,r,1n),n.guidance_scale!==null&&n.guidance_scale>1&&(s?r.input_ids=Re([r.input_ids,r.input_ids],0):(r.input_ids=Re([r.input_ids,Zi(r.input_ids,BigInt(n.pad_token_id))],0),r.attention_mask=Re([r.attention_mask,Zi(r.attention_mask,0n)],0))),(s||!r.pixel_values)&&(r.pixel_values=dt([0,0,3,384,384],1)),s&&(r.images_seq_mask=new j("bool",new Array(1).fill(!0).fill(!1,0,1),[1,1]),r.images_emb_mask=new j("bool",new Array(0).fill(!1),[1,1,0])),r}async generate(t){return this._generation_mode="text",super.generate(t)}async generate_images(t){this._generation_mode="image";const r=(t.inputs??t[this.main_input_name]).dims[1],s=(await super.generate(t)).slice(null,[r,null]),a=this.sessions.image_decode,{decoded_image:o}=await ye(a,{generated_tokens:s}),i=o.add_(1).mul_(255/2).clamp_(0,255).to("uint8"),l=[];for(const c of i){const d=Ht.fromTensor(c);l.push(d)}return l}},Wc=class extends I{},qF=class extends Wc{},HF=class extends Wc{},Zm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"])}_apply_and_filter_by_delay_pattern_mask(t){const[r,n]=t.dims,s=this.config.decoder.num_codebooks,a=n-s;let o=0;for(let c=0;c<t.size;++c){if(t.data[c]==this.config.decoder.pad_token_id)continue;const d=c%n,h=Math.floor(c/n)%s,_=d-h;_>0&&_<=a&&(t.data[o++]=t.data[c])}const i=Math.floor(r/s),l=o/(i*s);return new j(t.type,t.data.slice(0,o),[i,s,l])}prepare_inputs_for_generation(t,r,n){const s=BigInt(this.config.decoder.pad_token_id);let a=structuredClone(t);for(let o=0;o<a.length;++o)for(let i=0;i<a[o].length;++i)o%this.config.decoder.num_codebooks>=i&&(a[o][i]=s);return n.guidance_scale!==null&&n.guidance_scale>1&&(a=a.concat(a)),za(this,a,r)}async generate(t){const r=await super.generate(t),n=this._apply_and_filter_by_delay_pattern_mask(r).unsqueeze_(0),{audio_values:s}=await ye(this.sessions.encodec_decode,{audio_codes:n});return s}},qc=class extends I{},QF=class extends qc{},XF=class extends qc{},Hc=class extends I{},YF=class extends Hc{},JF=class extends Hc{},zn=class extends I{},KF=class extends zn{},ZF=class extends zn{async _call(e){return new Je(await super._call(e))}},eI=class extends zn{async _call(e){return new le(await super._call(e))}},tI=class extends zn{async _call(e){return new Xe(await super._call(e))}},rI=class extends zn{async _call(e){return new it(await super._call(e))}},eg=class extends I{},nI=class extends eg{},Qc=class extends I{},sI=class extends Qc{},aI=class extends Qc{},Xc=class extends I{},oI=class extends Xc{},iI=class extends Xc{},Yc=class extends I{},lI=class extends Yc{},cI=class extends Yc{},Jc=class extends I{},uI=class extends Jc{},dI=class extends Jc{},Kc=class extends I{},hI=class extends Kc{},fI=class extends Kc{async _call(e){return new le(await super._call(e))}},Zc=class extends I{},_I=class extends Zc{},pI=class extends Zc{},eu=class extends I{},mI=class extends eu{},gI=class extends eu{},tu=class extends I{},wI=class extends tu{},vI=class extends tu{},ru=class extends I{},yI=class extends ru{},bI=class extends ru{},MI=class extends ir{},tg=class extends I{},xI=class extends tg{async _call(e){return new Br(await super._call(e))}},nu=class extends I{},kI=class extends nu{},TI=class extends nu{},su=class extends I{},EI=class extends su{},AI=class extends su{},au=class extends I{},CI=class extends au{},SI=class extends au{},ou=class extends I{},PI=class extends ou{},FI=class extends ou{},rg=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","inputs_embeds","attention_mask","position_ids","pixel_values","image_sizes","past_key_values"])}},ng=class extends rg{async forward({input_ids:e=null,attention_mask:t=null,pixel_values:r=null,image_sizes:n=null,position_ids:s=null,inputs_embeds:a=null,past_key_values:o=null,generation_config:i=null,logits_processor:l=null,num_logits_to_keep:c=null,...d}){if(!a){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 ye(this.sessions.vision_encoder,{pixel_values:r,image_sizes:n}))}else{const p=this.config.normalized_config.hidden_size;_=new j("float32",[],[0,p])}({inputs_embeds:a}=await ye(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:_}))}return await vr(this,{inputs_embeds:a,past_key_values:o,attention_mask:t,position_ids:s,generation_config:i,logits_processor:l,num_logits_to_keep:c},!1)}},iu=class extends I{},II=class extends iu{},LI=class extends iu{async _call(e){return new le(await super._call(e))}},lu=class extends I{},OI=class extends lu{},NI=class extends lu{async _call(e){return new Xe(await super._call(e))}},cu=class extends I{},DI=class extends cu{},zI=class extends cu{},uu=class extends I{},BI=class extends uu{},RI=class extends uu{},du=class extends I{},$I=class extends du{},GI=class extends du{},hu=class extends I{},VI=class extends hu{},UI=class extends hu{},fu=class extends I{},jI=class extends fu{},WI=class extends fu{},_u=class extends uc{},sg=class extends zm{},qI=class extends _u{},HI=class extends sg{},pu=class extends _u{},ag=class extends pu{},QI=class extends pu{},XI=class extends ag{},mu=class extends I{},YI=class extends mu{},JI=class extends mu{async _call(e){return new le(await super._call(e))}},gu=class extends I{},KI=class extends gu{},ZI=class extends gu{async _call(e){return new og(await super._call(e))}},og=class extends ws{},Bn=class extends I{},eL=class extends Bn{},tL=class extends Bn{async _call(e){return new Je(await super._call(e))}},rL=class extends Bn{async _call(e){return new le(await super._call(e))}},nL=class extends Bn{async _call(e){return new Xe(await super._call(e))}},sL=class extends Bn{async _call(e){return new it(await super._call(e))}},Rn=class extends I{},aL=class extends Rn{},oL=class extends Rn{async _call(e){return new Je(await super._call(e))}},iL=class extends Rn{async _call(e){return new le(await super._call(e))}},lL=class extends Rn{async _call(e){return new Xe(await super._call(e))}},cL=class extends Rn{async _call(e){return new it(await super._call(e))}},wu=class extends I{},uL=class extends wu{},dL=class extends wu{async _call(e){return new ig(await super._call(e))}},ig=class extends ws{},lg=class extends je{constructor({iou_scores:e,pred_masks:t}){super(),this.iou_scores=e,this.pred_masks=t}},cg=class extends I{},hL=class extends cg{async get_image_embeddings({pixel_values:e}){return await Rr(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??(e.input_labels=xt(e.input_points.dims.slice(0,-1)));const t={image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings};return e.input_points&&(t.input_points=e.input_points),e.input_labels&&(t.input_labels=e.input_labels),e.input_boxes&&(t.input_boxes=e.input_boxes),await ye(this.sessions.prompt_encoder_mask_decoder,t)}async _call(e){return new lg(await super._call(e))}},ug=class extends je{constructor({iou_scores:e,pred_masks:t,object_score_logits:r}){super(),this.iou_scores=e,this.pred_masks=t,this.object_score_logits=r}},dg=class extends I{},vu=class extends dg{async get_image_embeddings({pixel_values:e}){return await Rr(this,{pixel_values:e})}async forward(e){const{num_feature_levels:t}=this.config.vision_config;if(Array.from({length:t},(a,o)=>`image_embeddings.${o}`).some(a=>!e[a])?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.");const a=e.input_points.dims;e.input_labels??(e.input_labels=xt(a.slice(0,-1))),e.input_boxes??(e.input_boxes=dt([a[0],0,4],0))}else if(e.input_boxes){const a=e.input_boxes.dims;e.input_labels=dt([a[0],a[1],0],-1n),e.input_points=dt([a[0],1,0,2],0)}else throw new Error("At least one of `input_points` or `input_boxes` must be provided.");const n=this.sessions.prompt_encoder_mask_decoder,s=rt(e,n.inputNames);return await ye(n,s)}async _call(e){return new ug(await super._call(e))}},fL=class extends vu{},_L=class extends vu{},Ya=class extends I{},pL=class extends Ya{},mL=class extends Ya{},gL=class extends Ya{},Ja=class extends I{},wL=class extends Ja{},vL=class extends Ja{},yL=class extends Ja{},yu=class extends I{},bL=class extends yu{},hg=class extends yu{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},ML=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"vision_model"})}},bu=class extends I{},xL=class extends bu{},kL=class extends bu{},TL=class extends Gm{},Ka=class extends I{constructor(){super(...arguments);T(this,"main_input_name","input_values");T(this,"forward_params",["input_values"])}},EL=class extends Ka{async encode(e){return await ye(this.sessions.encoder_model,e)}async decode(e){return await ye(this.sessions.decoder_model,e)}},fg=class extends Ka{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"encoder_model"})}},_g=class extends Ka{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"decoder_model"})}},Mu=class extends I{},AL=class extends Mu{},CL=class extends Mu{},Za=class extends I{},SL=class extends Za{},PL=class extends Za{},FL=class extends Za{async generate_speech(e,t,{threshold:r=.5,minlenratio:n=0,maxlenratio:s=20,vocoder:a=null}={}){const o={input_ids:e},{encoder_outputs:i,encoder_attention_mask:l}=await Rr(this,o),c=i.dims[1]/this.config.reduction_factor,d=Math.floor(c*s),h=Math.floor(c*n),_=this.config.num_mel_bins;let p=[],w=null,v=null,y=0;for(;;){++y;const A=tm(!!v);let S;v?S=v.output_sequence_out:S=new j("float32",new Float32Array(_),[1,1,_]);let C={use_cache_branch:A,output_sequence:S,encoder_attention_mask:l,speaker_embeddings:t,encoder_hidden_states:i};Tl(this,C,w),v=await ye(this.sessions.decoder_model_merged,C),w=kl(v,w);const{prob:O,spectrum:M}=v;if(p.push(M),y>=h&&(Array.from(O.data).filter(V=>V>=r).length>0||y>=d))break}const x=Re(p),{waveform:k}=await ye(a.sessions.model,{spectrogram:x});return{spectrogram:x,waveform:k}}},IL=class extends I{constructor(){super(...arguments);T(this,"main_input_name","spectrogram")}},ks=class extends I{},LL=class extends ks{},OL=class extends ks{async _call(e){return new Je(await super._call(e))}},NL=class extends ks{async _call(e){return new le(await super._call(e))}},DL=class extends ks{async _call(e){return new it(await super._call(e))}},xu=class extends I{},zL=class extends xu{},BL=class extends xu{},ku=class extends I{},RL=class extends ku{},$L=class extends ku{},pg=class extends I{},GL=class extends pg{},mg=class extends I{},gg=class extends mg{async generate_speech({input_ids:e,attention_mask:t,style:r,num_inference_steps:n=5,speed:s=1.05}){const{sampling_rate:a,chunk_compress_factor:o,base_chunk_size:i,latent_dim:l}=this.config,{last_hidden_state:c,durations:d}=await ye(this.sessions.text_encoder,{input_ids:e,attention_mask:t,style:r}),h=d.div(s).mul_(a),_=i*o,p=h.data,w=Int32Array.from(p,G=>Math.ceil(G/_)),v=Math.max(...w),y=e.dims[0],x=new BigInt64Array(y*v);for(let G=0;G<y;++G)x.fill(1n,G*v,G*v+w[G]);const k=new j("int64",x,[y,v]),A=l*o,S=A*v;let C=rk([y,A,v]);const O=C.data;for(let G=0;G<y;++G)if(w[G]!==v)for(let U=0;U<A;++U)O.fill(0,G*S+U*v+w[G],G*S+(U+1)*v);const M=dt([y],n);for(let G=0;G<n;++G){const U=dt([y],G);({denoised_latents:C}=await ye(this.sessions.latent_denoiser,{style:r,noisy_latents:C,latent_mask:k,encoder_outputs:c,attention_mask:t,timestep:U,num_inference_steps:M}))}const{waveform:V}=await ye(this.sessions.voice_decoder,{latents:C});return{waveform:V,durations:h}}},eo=class extends I{},VL=class extends eo{},UL=class extends eo{async _call(e){return new le(await super._call(e))}},jL=class extends eo{},Tu=class extends I{},WL=class extends Tu{},qL=class extends Tu{},Eu=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"])}},HL=class extends Eu{},QL=class extends Eu{},Au=class extends I{},XL=class extends Au{},YL=class extends Au{async _call(e){return new wg(await super._call(e))}},wg=class extends Ql{},vg=class extends I{},JL=class extends vg{},to=class extends I{},KL=class extends to{},ZL=class extends to{async _call(e){return new Br(await super._call(e))}},eO=class extends to{async _call(e){return new le(await super._call(e))}},Ts=class extends I{},tO=class extends Ts{},rO=class extends Ts{async _call(e){return new Br(await super._call(e))}},nO=class extends Ts{async _call(e){return new le(await super._call(e))}},sO=class extends Ts{async _call(e){return new Xe(await super._call(e))}},Cu=class extends I{},aO=class extends Cu{},oO=class extends Cu{},iO=class extends I{constructor(){super(...arguments);T(this,"main_input_name","pixel_values");T(this,"forward_params",["pixel_values","decoder_input_ids","encoder_hidden_states","past_key_values"])}},Su=class extends I{},lO=class extends Su{},cO=class extends Su{async _call(e){return new le(await super._call(e))}},yg=class extends I{},uO=class extends yg{},Pu=class extends I{},dO=class extends Pu{},hO=class extends Pu{async _call(e){return new le(await super._call(e))}},bg=class extends I{},fO=class extends bg{async _call(e){return new Qp(await super._call(e))}},Mg=class extends I{},_O=class extends Mg{},xg=class extends je{constructor({waveform:e,spectrogram:t}){super(),this.waveform=e,this.spectrogram=t}},kg=class extends I{},pO=class extends kg{async _call(e){return new xg(await super._call(e))}},mO=class extends yc{},Tg=2,gO=1,Fu=new WeakMap;function wO(e,t){var v,y;const{text_config:r,audio_config:n}=e.config,s=e.sessions.audio_encoder,{num_mel_bins:a,hidden_size:o}=n,i=a+o,l=new bl,c=La(n),d={batch_size:1};let h="float32";for(const x of s.inputMetadata){if(x.name==="past_padding_cache"){h=x.type;continue}if(!c.has(x.name))continue;const k=sm(x.shape,d),A=k.reduce((C,O)=>C*O,1),S=hs[x.type];l[x.name]=new j(x.type,new S(A),k)}const _=hs[h],p=new j(h,new _(i*Tg),[1,i,Tg]),w=((v=t[Symbol.asyncIterator])==null?void 0:v.call(t))??((y=t[Symbol.iterator])==null?void 0:y.call(t));if(!w)throw new Error("input_features must be iterable or async iterable");return{encoder_session:s,enc_kv_cache:l,enc_padding_cache:p,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:w,text_hidden_size:r.hidden_size}}async function vO(e,t){const r=t.dims[2],n=Math.floor((gO+r-3)/2)+1,s=new j("int64",BigInt64Array.from({length:n},(d,h)=>BigInt(e.enc_past_seq_len+h)),[1,n]),a=e.enc_past_seq_len+n,o=xt([1,a]),{audio_embeds:i,present_padding_cache:l,...c}=await ye(e.encoder_session,{input_features:t,attention_mask:o,position_ids:s,past_padding_cache:e.enc_padding_cache,...e.enc_kv_cache});e.enc_padding_cache.location==="gpu-buffer"&&e.enc_padding_cache.dispose(),e.enc_padding_cache=l;for(const d in c)if(d.startsWith("present.")){const h=d.replace("present","past_key_values"),_=e.enc_kv_cache[h];(_==null?void 0:_.location)==="gpu-buffer"&&_.dispose(),e.enc_kv_cache[h]=c[d]}return e.enc_past_seq_len=a,i}async function yO(e,t){for(;e.audio_embed_total_tokens<t&&!e.stream_exhausted;){const r=await e.chunks_iter.next();if(r.done){e.stream_exhausted=!0;break}const n=await vO(e,r.value);e.audio_embed_queue.push({data:n.data,tokens:n.dims[1]}),e.audio_embed_total_tokens+=n.dims[1]}}function bO(e,t,r){if(e.audio_embed_queue.length===0)return;const n=t.data;let s=0,a=r;for(;a>0&&e.audio_embed_queue.length>0;){const o=e.audio_embed_queue[0],i=o.tokens-e.audio_queue_offset,l=Math.min(a,i),c=e.audio_queue_offset*e.text_hidden_size;for(let d=0;d<l*e.text_hidden_size;++d)n[s*e.text_hidden_size+d]+=o.data[c+d];s+=l,a-=l,e.audio_queue_offset+=l,e.audio_queue_offset>=o.tokens&&(e.audio_embed_queue.shift(),e.audio_queue_offset=0)}e.audio_consumed+=r-a}var MO=class extends Oa{constructor(e){super(),this._s=e}_call(e){const t=this._s.stream_exhausted&&this._s.audio_embed_queue.length===0;return e.map(()=>t)}},Eg=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","position_ids","past_key_values"])}},Ag=class extends Eg{async forward({input_ids:e,past_key_values:t,...r}){const n=e.dims[1],s=Fu.get(this);s&&await yO(s,s.audio_consumed+n);const{inputs_embeds:a}=await ye(this.sessions.embed_tokens,{input_ids:e});s&&bO(s,a,n);const o={inputs_embeds:a,...r};Tl(this,o,t);const i=this.sessions.decoder_model_merged,l=rt(o,i.inputNames);return await ye(i,l)}async generate({input_features:e,stopping_criteria:t,...r}){if(!e)throw new Error("input_features (generator/iterable) must be provided");const n=wO(this,e);Fu.set(this,n);const s=new Jp;s.push(new MO(n)),t&&s.extend(t);try{return await super.generate({...r,stopping_criteria:s})}finally{n.enc_kv_cache.dispose(),Fu.delete(this)}}},ro=class extends I{},xO=class extends ro{},kO=class extends ro{async _call(e){return new Br(await super._call(e))}},TO=class extends ro{async _call(e){return new le(await super._call(e))}},Cg=class extends je{constructor({logits:e,embeddings:t}){super(),this.logits=e,this.embeddings=t}},$n=class extends I{},EO=class extends $n{},AO=class extends $n{async _call(e){return new Br(await super._call(e))}},CO=class extends $n{async _call(e){return new le(await super._call(e))}},SO=class extends $n{async _call(e){return new Cg(await super._call(e))}},PO=class extends $n{async _call(e){return new Xe(await super._call(e))}},Sg=class extends I{},FO=class extends Sg{},IO=class extends Yp{constructor(){super(...arguments);T(this,"return_timestamps",null);T(this,"return_token_timestamps",null);T(this,"num_frames",null);T(this,"alignment_heads",null);T(this,"task",null);T(this,"language",null);T(this,"no_timestamps_token_id",null);T(this,"prompt_ids",null);T(this,"is_multilingual",null);T(this,"lang_to_id",null);T(this,"task_to_id",null);T(this,"max_initial_timestamp_index",1)}},Iu=class extends I{constructor(){super(...arguments);T(this,"requires_attention_mask",!1);T(this,"main_input_name","input_features");T(this,"forward_params",["input_features","attention_mask","decoder_input_ids","decoder_attention_mask","past_key_values"])}},LO=class extends Iu{},Pg=class extends Iu{_prepare_generation_config(e,t){return super._prepare_generation_config(e,t,IO)}_retrieve_init_tokens(e){const t=[e.decoder_start_token_id];let r=e.language;const n=e.task;if(e.is_multilingual){r||(he.warn("No language specified - defaulting to English (en)."),r="en");const a=`<|${Jk(r)}|>`;t.push(e.lang_to_id[a]),t.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&&t.at(-1)!==e.no_timestamps_token_id?t.push(e.no_timestamps_token_id):e.return_timestamps&&t.at(-1)===e.no_timestamps_token_id&&(he.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),t.pop()),t.filter(s=>s!=null)}async generate({inputs:e=null,generation_config:t=null,logits_processor:r=null,stopping_criteria:n=null,...s}){t=this._prepare_generation_config(t,s);const a=s.decoder_input_ids instanceof j?rl(s.decoder_input_ids):s.decoder_input_ids??this._retrieve_init_tokens(t);if(t.return_timestamps&&(r??(r=new yl),r.push(new O2(t,a))),t.begin_suppress_tokens&&(r??(r=new yl),r.push(new Xp(t.begin_suppress_tokens,a.length))),t.return_token_timestamps){if(!t.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.");t.task==="translate"&&he.warn("Token-level timestamps may not be reliable for task 'translate'."),t.output_attentions=!0,t.return_dict_in_generate=!0}if(t.return_timestamps&&!s.max_new_tokens)return this._generate_with_seek({inputs:e,generation_config:t,logits_processor:r,init_tokens:a,kwargs:s});const o=await super.generate({inputs:e,generation_config:t,logits_processor:r,decoder_input_ids:a,...s});return t.return_token_timestamps&&(o.token_timestamps=this._extract_token_timestamps(o,t.alignment_heads,t.num_frames,.02,a.length)),o}async _generate_with_seek({inputs:e,generation_config:t,logits_processor:r,init_tokens:n,kwargs:s}){const a=t.no_timestamps_token_id+1,o=Array.isArray(t.eos_token_id)?t.eos_token_id[0]:t.eos_token_id,i=t.return_token_timestamps,l=e,c=l.dims[2],d=2,h=this.config.max_source_positions,_=d*h;let p=0;const w=[],v=[];for(;p<c;){const x=Math.min(p+_,c),k=l.slice(null,null,[p,x]);let A;const S=k.dims[2];if(S<_){const H=l.dims[1],ne=new Float32Array(H*_),Se=k.data;for(let Y=0;Y<H;++Y)ne.set(Se.subarray(Y*S,(Y+1)*S),Y*_);A=new j("float32",ne,[1,H,_])}else A=k;if(r)for(const H of r)"begin_index"in H&&(H.begin_index=n.length);const C=await super.generate({inputs:A,generation_config:t,logits_processor:r,decoder_input_ids:n,...s}),M=(i?C.sequences:C)[0].tolist().map(Number).slice(n.length);let V;if(i){C.token_timestamps=this._extract_token_timestamps(C,t.alignment_heads,Math.floor((x-p)/d),.02,n.length);const H=p/d*.02;V=C.token_timestamps[0].tolist().slice(n.length).map(ne=>ne+H)}if(M.length>0&&M.at(-1)===o&&M.pop(),M.length===0)break;const G=M.map(H=>H>=a),U=M.length>=2&&G[M.length-1]&&!G[M.length-2],J=[];for(let H=0;H<M.length-1;++H)G[H]&&G[H+1]&&J.push(H+1);let Q,B=M.length;if(J.length>0)if(U)Q=x-p;else{const H=J.at(-1);Q=(M[H-1]-a)*d,B=H}else Q=x-p;const L=Math.floor(p/d),ee=a+1500;for(let H=0;H<B;++H)M[H]>=a&&(M[H]=Math.min(M[H]+L,ee));w.push(...M.slice(0,B)),V&&v.push(...V.slice(0,B)),p+=Q}w.push(o);const y=[...n,...w];if(i){const x=new j("int64",y.map(BigInt),[1,y.length]),k=[...new Array(n.length).fill(0),...v,0],A=new j("float32",new Float32Array(k),[1,k.length]);return{sequences:x,token_timestamps:A}}return new j("int64",y.map(BigInt),[1,y.length])}_extract_token_timestamps(e,t,r=null,n=.02,s=0){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&&he.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 a=this.config.median_filter_width;a===void 0&&(he.warn("Model config has no `median_filter_width`, using default value of 7."),a=7);const o=e.cross_attentions,i=Array.from({length:this.config.decoder_layers},(y,x)=>Re(o.map(k=>k[x]),2)),l=pr(t.map(([y,x])=>{if(y>=i.length)throw new Error(`Layer index ${y} is out of bounds for cross attentions (length ${i.length}).`);return r?i[y].slice(null,x,null,[0,r]):i[y].slice(null,x)})).permute(1,0,2,3),[c,d]=tk(l,-2,0,!0),h=l.clone();for(let y=0;y<h.dims[0];++y){const x=h[y];for(let k=0;k<x.dims[0];++k){const A=x[k],S=c[y][k][0].data,C=d[y][k][0].data;for(let O=0;O<A.dims[0];++O){let M=A[O].data;for(let V=0;V<M.length;++V)M[V]=(M[V]-C[V])/S[V];M.set(z1(M,a))}}}const _=s>0?h.slice(null,null,[s,h.dims[2]],null):h,p=[Yi(_,1)],w=e.sequences.dims,v=new j("float32",new Float32Array(w[0]*w[1]),w);for(let y=0;y<w[0];++y){const x=p[y].neg().squeeze_(0),[k,A]=R1(x.tolist()),S=Array.from({length:k.length-1},(V,G)=>k[G+1]-k[G]),C=er([1],S).map(V=>!!V),O=[];for(let V=0;V<C.length;++V)C[V]&&O.push(A[V]*n);const M=new Array(s).fill(0);M.push(...O),O.length>0&&M.push(O.at(-1)),v[y].data.set(M)}return v}},OO=class extends Pg{},Gn=class extends I{},NO=class extends Gn{},DO=class extends Gn{async _call(e){return new Je(await super._call(e))}},zO=class extends Gn{async _call(e){return new le(await super._call(e))}},BO=class extends Gn{async _call(e){return new Xe(await super._call(e))}},RO=class extends Gn{async _call(e){return new it(await super._call(e))}},Vn=class extends I{},$O=class extends Vn{},GO=class extends Vn{async _call(e){return new Je(await super._call(e))}},VO=class extends Vn{async _call(e){return new le(await super._call(e))}},UO=class extends Vn{async _call(e){return new Xe(await super._call(e))}},jO=class extends Vn{async _call(e){return new it(await super._call(e))}},Lu=class extends I{},WO=class extends Lu{},qO=class extends Lu{async _call(e){return new Fg(await super._call(e))}},Fg=class extends je{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}},Ou=class extends I{},HO=class extends Ou{},QO=class extends Ou{},Nu=class extends I{},XO=class extends Nu{},YO=class extends Nu{},JO=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"],["openai_privacy_filter","OpenAIPrivacyFilterModel"],["embedding_gemma2","EmbeddingGemma2Model"]]),KO=new Map([["t5","T5Model"],["longt5","LongT5Model"],["mt5","MT5Model"],["bart","BartModel"],["mbart","MBartModel"],["marian","MarianModel"],["whisper","WhisperModel"],["cohere_asr","CohereAsrModel"],["m2m_100","M2M100Model"],["blenderbot","BlenderbotModel"],["blenderbot-small","BlenderbotSmallModel"]]),ZO=new Map([["mimi","MimiModel"],["dac","DacModel"],["snac","SnacModel"]]),eN=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"],["deepseek_v4","DeepseekV4Model"],["falcon","FalconModel"],["falcon_h1","FalconH1Model"],["nemotron_h","NemotronHModel"],["solar_open","SolarOpenModel"],["stablelm","StableLmModel"],["modernbert-decoder","ModernBertDecoderModel"],["hunyuan_v1_dense","HunYuanDenseV1Model"],["youtu","YoutuModel"],["zaya","ZayaModel"],["hrm_text","HrmTextModel"]]),Ig=new Map([["speecht5","SpeechT5ForSpeechToText"],["whisper","WhisperForConditionalGeneration"],["lite-whisper","LiteWhisperForConditionalGeneration"],["moonshine","MoonshineForConditionalGeneration"],["cohere_asr","CohereAsrForConditionalGeneration"]]),Lg=new Map([["speecht5","SpeechT5ForTextToSpeech"]]),Og=new Map([["vits","VitsModel"],["musicgen","MusicgenForConditionalGeneration"],["supertonic","SupertonicForConditionalGeneration"]]),Ng=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"]]),Dg=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"],["openai_privacy_filter","OpenAIPrivacyFilterForTokenClassification"]]),zg=new Map([["t5","T5ForConditionalGeneration"],["longt5","LongT5ForConditionalGeneration"],["mt5","MT5ForConditionalGeneration"],["bart","BartForConditionalGeneration"],["mbart","MBartForConditionalGeneration"],["marian","MarianMTModel"],["m2m_100","M2M100ForConditionalGeneration"],["blenderbot","BlenderbotForConditionalGeneration"],["blenderbot-small","BlenderbotSmallForConditionalGeneration"]]),Bg=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_text","Qwen3_5ForCausalLM"],["qwen3_5_moe","Qwen3_5MoeForCausalLM"],["gemma3n","Gemma3nForCausalLM"],["gemma4","Gemma4ForCausalLM"],["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"],["deepseek_v4","DeepseekV4ForCausalLM"],["falcon","FalconForCausalLM"],["falcon_h1","FalconH1ForCausalLM"],["nemotron_h","NemotronHForCausalLM"],["trocr","TrOCRForCausalLM"],["solar_open","SolarOpenForCausalLM"],["stablelm","StableLmForCausalLM"],["modernbert-decoder","ModernBertDecoderForCausalLM"],["hunyuan_v1_dense","HunYuanDenseV1ForCausalLM"],["youtu","YoutuForCausalLM"],["zaya","ZayaForCausalLM"],["hrm_text","HrmTextForCausalLM"],["phi3_v","Phi3VForCausalLM"]]),tN=new Map([["multi_modality","MultiModalityCausalLM"]]),Rg=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"]]),$g=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"]]),Gg=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"]]),Vg=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"],["gemma3","Gemma3ForConditionalGeneration"],["gemma3n","Gemma3nForConditionalGeneration"],["gemma4","Gemma4ForConditionalGeneration"],["mistral3","Mistral3ForConditionalGeneration"],["lighton_ocr","LightOnOcrForConditionalGeneration"],["glm_ocr","GlmOcrForConditionalGeneration"]]),Ug=new Map([["granite_speech","GraniteSpeechForConditionalGeneration"],["ultravox","UltravoxModel"],["voxtral","VoxtralForConditionalGeneration"],["voxtral_realtime","VoxtralRealtimeForConditionalGeneration"]]),rN=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"]]),jg=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"]]),Wg=new Map([["detr","DetrForObjectDetection"],["rt_detr","RTDetrForObjectDetection"],["rt_detr_v2","RTDetrV2ForObjectDetection"],["rf_detr","RFDetrForObjectDetection"],["d_fine","DFineForObjectDetection"],["table-transformer","TableTransformerForObjectDetection"],["yolos","YolosForObjectDetection"]]),qg=new Map([["owlvit","OwlViTForObjectDetection"],["owlv2","Owlv2ForObjectDetection"],["grounding-dino","GroundingDinoForObjectDetection"]]),Un=new Map([["detr","DetrForSegmentation"],["clipseg","CLIPSegForImageSegmentation"]]),Hg=new Map([["segformer","SegformerForSemanticSegmentation"],["sapiens","SapiensForSemanticSegmentation"],["swin","SwinForSemanticSegmentation"],["mobilenet_v1","MobileNetV1ForSemanticSegmentation"],["mobilenet_v2","MobileNetV2ForSemanticSegmentation"],["mobilenet_v3","MobileNetV3ForSemanticSegmentation"],["mobilenet_v4","MobileNetV4ForSemanticSegmentation"]]),Qg=new Map([["detr","DetrForSegmentation"],["maskformer","MaskFormerForInstanceSegmentation"]]),Xg=new Map([["sam","SamModel"],["sam2","Sam2Model"],["edgetam","EdgeTamModel"],["sam3_tracker","Sam3TrackerModel"]]),Yg=new Map([["wav2vec2","Wav2Vec2ForCTC"],["wav2vec2-bert","Wav2Vec2BertForCTC"],["unispeech","UniSpeechForCTC"],["unispeech-sat","UniSpeechSatForCTC"],["wavlm","WavLMForCTC"],["hubert","HubertForCTC"],["parakeet_ctc","ParakeetForCTC"]]),Jg=new Map([["wav2vec2","Wav2Vec2ForSequenceClassification"],["wav2vec2-bert","Wav2Vec2BertForSequenceClassification"],["unispeech","UniSpeechForSequenceClassification"],["unispeech-sat","UniSpeechSatForSequenceClassification"],["wavlm","WavLMForSequenceClassification"],["hubert","HubertForSequenceClassification"],["audio-spectrogram-transformer","ASTForAudioClassification"]]),Kg=new Map([["wavlm","WavLMForXVector"]]),Zg=new Map([["unispeech-sat","UniSpeechSatForAudioFrameClassification"],["wavlm","WavLMForAudioFrameClassification"],["wav2vec2","Wav2Vec2ForAudioFrameClassification"],["pyannote","PyAnnoteForAudioFrameClassification"]]),ew=new Map([["vitmatte","VitMatteForImageMatting"]]),nN=new Map([["patchtst","PatchTSTForPrediction"],["patchtsmixer","PatchTSMixerForPrediction"]]),tw=new Map([["swin2sr","Swin2SRForImageSuperResolution"]]),rw=new Map([["chmv2","CHMv2ForDepthEstimation"],["dpt","DPTForDepthEstimation"],["depth_anything","DepthAnythingForDepthEstimation"],["glpn","GLPNForDepthEstimation"],["sapiens","SapiensForDepthEstimation"],["depth_pro","DepthProForDepthEstimation"],["metric3d","Metric3DForDepthEstimation"],["metric3dv2","Metric3Dv2ForDepthEstimation"]]),nw=new Map([["sapiens","SapiensForNormalEstimation"]]),sw=new Map([["vitpose","VitPoseForPoseEstimation"]]),aw=new Map([["clip","CLIPVisionModelWithProjection"],["siglip","SiglipVisionModel"],["jina_clip","JinaCLIPVisionModel"]]),ow=[[JO,q.EncoderOnly],[KO,q.EncoderDecoder],[eN,q.DecoderOnlyWithoutHead],[ZO,q.AutoEncoder],[Ng,q.EncoderOnly],[Dg,q.EncoderOnly],[zg,q.Seq2Seq],[Ig,q.Seq2Seq],[Bg,q.DecoderOnly],[tN,q.MultiModality],[Rg,q.EncoderOnly],[$g,q.EncoderOnly],[Gg,q.Vision2Seq],[Vg,q.ImageTextToText],[Ug,q.AudioTextToText],[jg,q.EncoderOnly],[Un,q.EncoderOnly],[Qg,q.EncoderOnly],[Hg,q.EncoderOnly],[ew,q.EncoderOnly],[nN,q.EncoderOnly],[tw,q.EncoderOnly],[rw,q.EncoderOnly],[nw,q.EncoderOnly],[sw,q.EncoderOnly],[Wg,q.EncoderOnly],[qg,q.EncoderOnly],[Xg,q.MaskGeneration],[Yg,q.EncoderOnly],[Jg,q.EncoderOnly],[Lg,q.Seq2Seq],[Og,q.EncoderOnly],[Kg,q.EncoderOnly],[Zg,q.EncoderOnly],[aw,q.EncoderOnly]];for(const[e,t]of ow)for(const r of e.values()){wr.set(r,t);const n=Al[r];An.set(n,r),xl.set(r,n)}var sN=[["MusicgenForConditionalGeneration",Zm,q.Musicgen],["Phi3VForCausalLM",ng,q.Phi3V],["CLIPTextModelWithProjection",mm,q.EncoderOnly],["SiglipTextModel",hg,q.EncoderOnly],["JinaCLIPTextModel",Vm,q.EncoderOnly],["ClapTextModelWithProjection",_m,q.EncoderOnly],["ClapAudioModelWithProjection",pm,q.EncoderOnly],["DacEncoderModel",vm,q.EncoderOnly],["DacDecoderModel",ym,q.EncoderOnly],["MimiEncoderModel",Ym,q.EncoderOnly],["MimiDecoderModel",Jm,q.EncoderOnly],["SnacEncoderModel",fg,q.EncoderOnly],["SnacDecoderModel",_g,q.EncoderOnly],["Gemma3nForConditionalGeneration",Ua,q.ImageAudioTextToText],["Gemma4ForConditionalGeneration",oc,q.ImageAudioTextToText],["SupertonicForConditionalGeneration",gg,q.Supertonic],["ChatterboxModel",dm,q.Chatterbox],["EmbeddingGemma2Model",Sm,q.MultimodalEncoder],["VoxtralRealtimeForConditionalGeneration",Ag,q.VoxtralRealtime]];for(const[e,t,r]of sN)wr.set(e,r),An.set(t,e),xl.set(e,t);var iw=new Map([["modnet",Un],["birefnet",Un],["isnet",Un],["ben",Un]]);for(const[e,t]of iw.entries())t.set(e,"PreTrainedModel"),wr.set(e,q.EncoderOnly),xl.set(e,I);var aN=new Set(iw.keys());wr.set("PreTrainedModel",q.EncoderOnly),An.set(I,"PreTrainedModel");var Ae={MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES:Ng,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES:Dg,MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES:Lg,MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES:Og,MODEL_FOR_MASKED_LM_MAPPING_NAMES:Rg,MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES:$g,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES:jg,MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES:Un,MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES:Hg,MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES:Qg,MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES:Wg,MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES:qg,MODEL_FOR_MASK_GENERATION_MAPPING_NAMES:Xg,MODEL_FOR_CTC_MAPPING_NAMES:Yg,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES:Jg,MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES:Kg,MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES:Zg,MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES:rN,MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES:ew,MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES:tw,MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES:rw,MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES:nw,MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES:sw,MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES:aw,MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES:Vg,MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES:Ug,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES:zg,MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES:Ig,MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:Bg,MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES:Gg};Y2(Ae);var Ce=(yo=class{static supports(e){if(!this.MODEL_CLASS_MAPPINGS)return!1;for(const t of this.MODEL_CLASS_MAPPINGS)if(t.has(e))return!0;return this.BASE_IF_FAIL}static async from_pretrained(e,{progress_callback:t=null,config:r=null,cache_dir:n=null,local_files_only:s=!1,revision:a="main",model_file_name:o=null,subfolder:i="onnx",device:l=null,dtype:c=null,use_external_data_format:d=null,session_options:h={}}={}){const _={progress_callback:t,config:r,cache_dir:n,local_files_only:s,revision:a,model_file_name:o,subfolder:i,device:l,dtype:c,use_external_data_format:d,session_options:h};if(_.config=await ps.from_pretrained(e,_),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);const{model_type:p}=_.config;for(const w of this.MODEL_CLASS_MAPPINGS){let v=w.get(p);if(!v){for(const y of w.values())if(y[0]===p){v=y;break}if(!v)continue}return await Al[v].from_pretrained(e,_)}if(this.BASE_IF_FAIL)return aN.has(p)||he.warn(`Unknown model class "${p}", attempting to construct from base class.`),await I.from_pretrained(e,_);throw Error(`Unsupported model type: ${p}`)}},T(yo,"MODEL_CLASS_MAPPINGS",null),T(yo,"BASE_IF_FAIL",!1),yo),Es=(bo=class extends Ce{},T(bo,"MODEL_CLASS_MAPPINGS",ow.map(e=>e[0])),T(bo,"BASE_IF_FAIL",!0),bo),lw=(ju=class extends Ce{},T(ju,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]),ju),oN=(Wu=class extends Ce{},T(Wu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]),Wu),Du=(qu=class extends Ce{},T(qu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]),qu),iN=(Hu=class extends Ce{},T(Hu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]),Hu),lN=(Qu=class extends Ce{},T(Qu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]),Qu),cN=(Xu=class extends Ce{},T(Xu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]),Xu),uN=(Yu=class extends Ce{},T(Yu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES]),Yu),dN=(Ju=class extends Ce{},T(Ju,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_MASKED_LM_MAPPING_NAMES]),Ju),hN=(Ku=class extends Ce{},T(Ku,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]),Ku),fN=(Zu=class extends Ce{},T(Zu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]),Zu),_N=(ed=class extends Ce{},T(ed,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]),ed),cw=(td=class extends Ce{},T(td,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]),td),uw=(rd=class extends Ce{},T(rd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]),rd),dw=(nd=class extends Ce{},T(nd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES]),nd),pN=(sd=class extends Ce{},T(sd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]),sd),mN=(ad=class extends Ce{},T(ad,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]),ad);od=class extends Ce{},T(od,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]);var gN=(id=class extends Ce{},T(id,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_CTC_MAPPING_NAMES]),id),wN=(ld=class extends Ce{},T(ld,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]),ld);cd=class extends Ce{},T(cd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]),ud=class extends Ce{},T(ud,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]);var vN=(dd=class extends Ce{},T(dd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]),dd);hd=class extends Ce{},T(hd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]);var yN=(fd=class extends Ce{},T(fd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]),fd),bN=(_d=class extends Ce{},T(_d,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]),_d);pd=class extends Ce{},T(pd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES]),md=class extends Ce{},T(md,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES]);var MN=(gd=class extends Ce{},T(gd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]),gd);wd=class extends Ce{},T(wd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES]),vd=class extends Ce{},T(vd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES]);async function Xt(e){return Array.isArray(e)||(e=[e]),await Promise.all(e.map(t=>Ht.read(t)))}async function jn(e,t){return Array.isArray(e)||(e=[e]),await Promise.all(e.map(r=>typeof r=="string"||r instanceof URL?oT(r,t):r instanceof Float64Array?new Float32Array(r):r))}function zu(e,t){t&&(e=e.map(o=>o|0));const[r,n,s,a]=e;return{xmin:r,ymin:n,xmax:s,ymax:a}}var qe=class extends gt{constructor({task:e,model:t,tokenizer:r=null,processor:n=null}){super(),this.task=e,this.model=t,this.tokenizer=r,this.processor=n}async dispose(){await this.model.dispose()}},xN=class extends qe{async _call(e,{top_k:t=1}={}){const r=this.tokenizer(e,{padding:!0,truncation:!0}),n=await this.model(r),{problem_type:s,id2label:a}=this.model.config,o=s==="multi_label_classification"?l=>l.sigmoid():l=>new j("float32",at(l.data),l.dims),i=[];for(const l of n.logits){const c=o(l),d=await Mn(c,t),h=d[0].tolist(),p=d[1].tolist().map((w,v)=>({label:a?a[w]:`LABEL_${w}`,score:h[v]}));t===1?i.push(...p):i.push(p)}return Array.isArray(e)||t===1?i:i[0]}},kN=class extends qe{async _call(e,{ignore_labels:t=["O"],aggregation_strategy:r="none"}={}){if(r!=="none"&&r!=="simple")throw new Error(`Invalid aggregation_strategy: "${r}". Must be one of "none" or "simple".`);const n=Array.isArray(e),s=this.tokenizer(n?e:[e],{padding:!0,truncation:!0}),o=(await this.model(s)).logits,i=this.model.config.id2label,l=[];for(let c=0;c<o.dims[0];++c){const d=s.input_ids[c].tolist(),h=o[c],_=[];for(let p=0;p<h.dims[0];++p){const w=h[p],v=Qe(w.data)[1],y=i?i[v]:`LABEL_${v}`;if(t.includes(y))continue;const x=this.tokenizer.decode([d[p]],{skip_special_tokens:!0});if(x==="")continue;const k=at(w.data);_.push({entity:y,score:k[v],index:p,word:x})}l.push(r==="simple"?EN(_,d,this.tokenizer):_)}return n?l:l[0]}};function TN(e){const t=e[0];return e[1]==="-"&&(t==="B"||t==="I"||t==="E"||t==="S")?[t,e.slice(2)]:["I",e]}function EN(e,t,r){const n=[];let s=null;for(let a=0;a<e.length;++a){const[o,i]=TN(e[a].entity);s===i&&o!=="B"&&o!=="S"?(n[n.length-1].end=a+1,o==="E"&&(s=null)):(n.push({tag:i,start:a,end:a+1}),s=o==="S"?null:i)}return n.map(({tag:a,start:o,end:i})=>{let l=0;const c=[];for(let d=o;d<i;++d)l+=e[d].score,c.push(t[e[d].index]);return{entity_group:a,score:l/(i-o),word:r.decode(c,{skip_special_tokens:!0})}})}var AN=class extends qe{async _call(e,t,{top_k:r=1}={}){const n=this.tokenizer(e,{text_pair:t,padding:!0,truncation:!0}),s=Array.isArray(e),{start_logits:a,end_logits:o}=await this.model(n),i=n.input_ids.tolist(),l=n.attention_mask.tolist(),{all_special_ids:c,sep_token_id:d}=this.tokenizer,h=[];for(let _=0;_<a.dims[0];++_){const p=i[_],w=p.findIndex(C=>C==d),v=a[_].tolist(),y=o[_].tolist();for(let C=1;C<v.length;++C)(l[_]==0||C<=w||c.findIndex(O=>O==p[C])!==-1)&&(v[C]=-1/0,y[C]=-1/0);const x=at(v).map((C,O)=>[C,O]),k=at(y).map((C,O)=>[C,O]);x[0][0]=0,k[0][0]=0;const A=Ub(x,k).filter(C=>C[0][1]<=C[1][1]).map(C=>[C[0][1],C[1][1],C[0][0]*C[1][0]]).sort((C,O)=>O[2]-C[2]),S=[];for(let C=0;C<Math.min(A.length,r);++C){const[O,M,V]=A[C],G=p.slice(O,M+1),U=this.tokenizer.decode(G,{skip_special_tokens:!0});S.push({answer:U,score:V})}r===1?h.push(...S):h.push(S)}return s?h:h[0]}},CN=class extends qe{async _call(e,{top_k:t=5}={}){const{mask_token_id:r,mask_token:n}=this.tokenizer,s=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:a}=await this.model(s),o=[],i=s.input_ids.tolist();for(let l=0;l<i.length;++l){const c=i[l],d=c.findIndex(v=>v==r);if(d===-1)throw Error(`Mask token (${n}) not found in text.`);const h=a[l][d],_=await Mn(new j("float32",at(h.data),h.dims),t),p=_[0].tolist(),w=_[1].tolist();o.push(w.map((v,y)=>{const x=c.slice();return x[d]=v,{score:p[y],token:Number(v),token_str:this.tokenizer.decode([v]),sequence:this.tokenizer.decode(x,{skip_special_tokens:!0})}}))}return Array.isArray(e)?o:o[0]}},Bu=class extends qe{constructor(){super(...arguments);T(this,"_default_generation_config",{max_new_tokens:256});T(this,"_key","generated_text")}async _call(t,r={}){Array.isArray(t)||(t=[t]),this.model.config.prefix&&(t=t.map(l=>this.model.config.prefix+l));const n=this.model.config.task_specific_params;n&&n[this.task]&&n[this.task].prefix&&(t=t.map(l=>n[this.task].prefix+l));const s=this.tokenizer,a={padding:!0,truncation:!0};let o;this.task==="translation"&&"_build_translation_inputs"in s?o=s._build_translation_inputs(t,a,r):o=s(t,a);const i=await this.model.generate({...o,...this._default_generation_config,...r});return s.batch_decode(i,{skip_special_tokens:!0}).map(l=>({[this._key]:l}))}},SN=class extends Bu{constructor(){super(...arguments);T(this,"_key","summary_text")}},PN=class extends Bu{constructor(){super(...arguments);T(this,"_key","translation_text")}};function hw(e){return Array.isArray(e)&&e.every(t=>"role"in t&&"content"in t)}var FN=class extends qe{constructor(){super(...arguments);T(this,"_default_generation_config",{max_new_tokens:256})}async _call(t,r={}){const{add_special_tokens:n,return_full_text:s,tools:a,documents:o,chat_template:i,tokenizer_encode_kwargs:l,...c}=r;let d=!1,h=!1,_=n??(this.tokenizer.add_bos_token||this.tokenizer.add_eos_token)??!1,p=l,w;if(typeof t=="string")w=t=[t];else if(Array.isArray(t)&&t.every(C=>typeof C=="string"))d=!0,w=t;else{if(hw(t))t=[t];else if(Array.isArray(t)&&t.every(hw))d=!0;else throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");h=!0;const C={tokenize:!1,add_generation_prompt:!0,...rt({tools:a,documents:o,chat_template:i},["tools","documents","chat_template"]),...p};w=t.map(O=>this.tokenizer.apply_chat_template(O,C)),_=!1,p=void 0}const v=h?!1:s??!0;this.tokenizer.padding_side="left";const y=this.tokenizer(w,{add_special_tokens:_,padding:!0,truncation:!0,...p}),x=await this.model.generate({...y,...this._default_generation_config,...c}),k=this.tokenizer.batch_decode(x,{skip_special_tokens:!0});let A;!v&&y.input_ids.dims.at(-1)>0&&(A=this.tokenizer.batch_decode(y.input_ids,{skip_special_tokens:!0}).map(C=>C.length));const S=Array.from({length:t.length},C=>[]);for(let C=0;C<k.length;++C){const O=Math.floor(C/x.dims[0]*t.length);A&&(k[C]=k[C].slice(A[O])),S[O].push({generated_text:h?[...t[O],{role:"assistant",content:k[C]}]:k[C]})}return!d&&S.length===1?S[0]:S}},IN=class extends qe{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([t,r])=>[t.toLowerCase(),r])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(he.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&&(he.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,t,{hypothesis_template:r="This example is {}.",multi_label:n=!1}={}){const s=Array.isArray(e);s||(e=[e]),Array.isArray(t)||(t=[t]);const a=t.map(l=>r.replace("{}",l)),o=n||t.length===1,i=[];for(const l of e){const c=[];for(const _ of a){const p=this.tokenizer(l,{text_pair:_,padding:!0,truncation:!0}),w=await this.model(p);o?c.push([w.logits.data[this.contradiction_id],w.logits.data[this.entailment_id]]):c.push(w.logits.data[this.entailment_id])}const h=(o?c.map(_=>at(_)[1]):at(c)).map((_,p)=>[_,p]).sort((_,p)=>p[0]-_[0]);i.push({sequence:l,labels:h.map(_=>t[_[1]]),scores:h.map(_=>_[0])})}return s?i:i[0]}},LN=class extends qe{async _call(e,{top_k:t=5}={}){const r=this.processor.feature_extractor.config.sampling_rate,n=await jn(e,r),s=this.model.config.id2label,a=[];for(const o of n){const i=await this.processor(o),c=(await this.model(i)).logits[0],d=await Mn(new j("float32",at(c.data),c.dims),t),h=d[0].tolist(),p=d[1].tolist().map((w,v)=>({label:s?s[w]:`LABEL_${w}`,score:h[v]}));a.push(p)}return Array.isArray(e)?a:a[0]}},ON=class extends qe{async _call(e,t,{hypothesis_template:r="This is a sound of {}."}={}){const n=!Array.isArray(e);n&&(e=[e]);const s=t.map(c=>r.replace("{}",c)),a=this.tokenizer(s,{padding:!0,truncation:!0}),o=this.processor.feature_extractor.config.sampling_rate,i=await jn(e,o),l=[];for(const c of i){const d=await this.processor(c),h=await this.model({...a,...d}),_=at(h.logits_per_audio.data);l.push([..._].map((p,w)=>({score:p,label:t[w]})))}return n?l[0]:l}},NN=class extends qe{constructor(){super(...arguments);T(this,"_default_generation_config",{})}async _call(t,r={}){switch(r={...this._default_generation_config,...r},this.model.config.model_type){case"whisper":case"lite-whisper":return this._call_whisper(t,r);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":case"parakeet_ctc":return this._call_wav2vec2(t,r);case"moonshine":return this._call_moonshine(t,r);case"cohere_asr":return this._call_cohere_asr(t,r);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(t,r){r.language&&he.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),r.task&&he.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');const n=!Array.isArray(t),s=n?[t]:t,a=this.processor.feature_extractor.config.sampling_rate,o=await jn(s,a),i=[];for(const l of o){const c=await this.processor(l),h=(await this.model(c)).logits[0],_=[];for(const w of h)_.push(Qe(w.data)[1]);const p=this.tokenizer.decode(_,{skip_special_tokens:!0}).trim();i.push({text:p})}return n?i[0]:i}async _call_whisper(t,r){const n=r.return_timestamps??!1,s=r.chunk_length_s??0,a=r.force_full_sequences??!1;let o=r.stride_length_s??null;const i={...r};n==="word"&&(i.return_token_timestamps=!0,i.return_timestamps=!0);const l=!Array.isArray(t),c=l?[t]:t,d=this.processor.feature_extractor.config,h=d.chunk_length/this.model.config.max_source_positions,_=d.hop_length,p=d.sampling_rate,w=await jn(c,p),v=[];for(const y of w){let x=[];if(s>0){if(o===null)o=s/6;else if(s<=o)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");const S=p*s,C=p*o,O=S-2*C;let M=0;for(;;){const V=M+S,G=y.subarray(M,V),U=await this.processor(G),J=M===0,Q=V>=y.length;if(x.push({stride:[G.length,J?0:C,Q?0:C],input_features:U.input_features,is_last:Q}),Q)break;M+=O}}else x=[{stride:[y.length,0,0],input_features:(await this.processor(y)).input_features,is_last:!0}];for(const S of x){i.num_frames=Math.floor(S.stride[0]/_);const C=await this.model.generate({inputs:S.input_features,...i});if(n==="word"){const O=C.sequences.tolist()[0],M=C.token_timestamps.tolist()[0],V=this.tokenizer.timestamp_begin,G=Math.max(O.findIndex(U=>Number(U)>=V),0);S.tokens=O.slice(G),S.token_timestamps=M.slice(G).map(U=>ds(U,2))}else S.tokens=C[0].tolist();S.stride=S.stride.map(O=>O/p)}const[k,A]=this.tokenizer._decode_asr(x,{time_precision:h,return_timestamps:n,force_full_sequences:a});v.push({text:k,...A})}return l?v[0]:v}async _call_moonshine(t,r){const n=!Array.isArray(t),s=n?[t]:t,a=this.processor.feature_extractor.config.sampling_rate,o=await jn(s,a),i=[];for(const l of o){const c=await this.processor(l),d=Math.floor(l.length/a)*6,h=await this.model.generate({max_new_tokens:d,...r,...c}),_=this.tokenizer.batch_decode(h,{skip_special_tokens:!0})[0];i.push({text:_})}return n?i[0]:i}async _call_cohere_asr(t,r){const n=!Array.isArray(t),s=n?[t]:t,a=this.processor.feature_extractor,o=a.config.sampling_rate,i=await jn(s,o),l=r.language??"en",c=this.processor.get_decoder_prompt_ids(l),d=[];for(const h of i){const _=a.split_audio(h),p=[];for(const v of _){const y=await this.processor(v),x=await this.model.generate({...y,decoder_input_ids:c,...r}),k=this.tokenizer.decode(x[0].tolist(),{skip_special_tokens:!0}).trim();p.push(k)}const w=this.processor.constructor.join_chunks(p,l);d.push({text:w})}return n?d[0]:d}},DN=class extends qe{constructor(t){super(t);T(this,"DEFAULT_VOCODER_ID","Xenova/speecht5_hifigan");this.vocoder=t.vocoder??null}async _prepare_speaker_embeddings(t,r){if((typeof t=="string"||t instanceof URL)&&(t=new Float32Array(await(await ve.fetch(t)).arrayBuffer())),t instanceof Float32Array)t=new j("float32",t,[t.length]);else if(!(t instanceof j))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");if(r>1){if(t.dims[0]===1)t=t.repeat(r,1);else if(t.dims[0]!==r)throw new Error(`Expected speaker embeddings batch size to be 1 or ${r}, but got ${t.dims[0]}.`)}return t}_postprocess_waveform(t,r,n,s=null){const a=r.data,[o,i]=r.dims,l=s?s.data:null,c=[];for(let d=0;d<o;++d){const h=l?Math.min(Math.ceil(l[d]),i):i,_=d*i;c.push(new mT(a.slice(_,_+h),n))}return Array.isArray(t)?c:c[0]}async _call(t,r){return this.processor?this._call_text_to_spectrogram(t,r):this.model.config.model_type==="supertonic"?this._call_supertonic(t,r):this._call_text_to_waveform(t)}async _call_supertonic(t,{speaker_embeddings:r,num_inference_steps:n,speed:s}){if(!r)throw new Error("Speaker embeddings must be provided for Supertonic models.");const{sampling_rate:a,style_dim:o}=this.model.config,i=this.tokenizer(t,{padding:!0,truncation:!0}),l=i.input_ids.dims[0];r=await this._prepare_speaker_embeddings(r,l),r=r.view(l,-1,o);const{waveform:c,durations:d}=await this.model.generate_speech({...i,style:r,num_inference_steps:n,speed:s});return this._postprocess_waveform(t,c,a,d)}async _call_text_to_waveform(t){const r=this.tokenizer(t,{padding:!0,truncation:!0}),{waveform:n}=await this.model(r),s=this.model.config.sampling_rate;return this._postprocess_waveform(t,n,s)}async _call_text_to_spectrogram(t,{speaker_embeddings:r}){this.vocoder||(he.info("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await Es.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"}));const{input_ids:n}=this.tokenizer(t,{padding:!0,truncation:!0}),s=n.dims[0];r=await this._prepare_speaker_embeddings(r,s),r=r.view(s,-1);const{waveform:a}=await this.model.generate_speech(n,r,{vocoder:this.vocoder}),o=this.processor.feature_extractor.config.sampling_rate;return this._postprocess_waveform(t,a,o)}},zN=class extends qe{async _call(e,t={}){const r=Array.isArray(e),n=await Xt(e),{pixel_values:s}=await this.processor(n),a=[];for(const o of s){o.dims=[1,...o.dims];const i=await this.model.generate({inputs:o,...t}),l=this.tokenizer.batch_decode(i,{skip_special_tokens:!0}).map(c=>({generated_text:c.trim()}));a.push(l)}return r?a:a[0]}},BN=class extends qe{async _call(e,{top_k:t=5}={}){const r=await Xt(e),{pixel_values:n}=await this.processor(r),s=await this.model({pixel_values:n}),{id2label:a}=this.model.config,o=[];for(const i of s.logits){const l=await Mn(new j("float32",at(i.data),i.dims),t),c=l[0].tolist(),h=l[1].tolist().map((_,p)=>({label:a?a[_]:`LABEL_${_}`,score:c[p]}));o.push(h)}return Array.isArray(e)?o:o[0]}},fw={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"},_w=class extends qe{async _call(e,{threshold:t=.5,mask_threshold:r=.5,overlap_mask_area_threshold:n=.8,label_ids_to_fuse:s=null,target_sizes:a=null,subtask:o=null}={}){if(Array.isArray(e)&&e.length!==1)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");const l=await Xt(e),c=l.map(x=>[x.height,x.width]),d=await this.processor(l),{inputNames:h,outputNames:_}=this.model.sessions.model;if(!h.includes("pixel_values")){if(h.length!==1)throw Error(`Expected a single input name, but got ${h.length} inputs: ${h}.`);const x=h[0];if(x in d)throw Error(`Input name ${x} already exists in the inputs.`);d[x]=d.pixel_values}const p=await this.model(d);let w=null;if(o!==null)w=fw[o];else if(this.processor.image_processor){for(const[x,k]of Object.entries(fw))if(k in this.processor.image_processor){w=this.processor.image_processor[k].bind(this.processor.image_processor),o=x;break}}const v=this.model.config.id2label,y=[];if(o)if(o==="panoptic"||o==="instance"){const x=w(p,t,r,n,s,a??c)[0],k=x.segmentation;for(const A of x.segments_info){const S=new Uint8ClampedArray(k.data.length);for(let O=0;O<k.data.length;++O)k.data[O]===A.id&&(S[O]=255);const C=new Ht(S,k.dims[1],k.dims[0],1);y.push({score:A.score,label:v[A.label_id],mask:C})}}else if(o==="semantic"){const{segmentation:x,labels:k}=w(p,a??c)[0];for(const A of k){const S=new Uint8ClampedArray(x.data.length);for(let O=0;O<x.data.length;++O)x.data[O]===A&&(S[O]=255);const C=new Ht(S,x.dims[1],x.dims[0],1);y.push({score:null,label:v[A],mask:C})}}else throw Error(`Subtask ${o} not supported.`);else{const k=p[_[0]];for(let A=0;A<c.length;++A){const S=c[A],C=k[A];C.data.some(M=>M<-1e-5||M>1+1e-5)&&C.sigmoid_();const O=await Ht.fromTensor(C.mul_(255).to("uint8")).resize(S[1],S[0]);y.push({label:null,score:null,mask:O})}}return y}},RN=class extends _w{async _call(e,t={}){const r=await Xt(e),n=await super._call(e,t),s=r.map((a,o)=>{const i=a.clone();return i.putAlpha(n[o].mask),i});return Array.isArray(e)?s:s[0]}},$N=class extends qe{async _call(e,t,{hypothesis_template:r="This is a photo of {}"}={}){const n=Array.isArray(e),s=await Xt(e),a=t.map(h=>r.replace("{}",h)),o=this.tokenizer(a,{padding:this.model.config.model_type==="siglip"?"max_length":!0,truncation:!0}),{pixel_values:i}=await this.processor(s),l=await this.model({...o,pixel_values:i}),c=this.model.config.model_type==="siglip"?h=>h.sigmoid().data:h=>at(h.data),d=[];for(const h of l.logits_per_image){const p=[...c(h)].map((w,v)=>({score:w,label:t[v]}));p.sort((w,v)=>v.score-w.score),d.push(p)}return n?d:d[0]}},GN=class extends qe{async _call(e,{threshold:t=.9,percentage:r=!1}={}){const n=Array.isArray(e);if(n&&e.length!==1)throw Error("Object detection pipeline currently only supports a batch size of 1.");const s=await Xt(e),a=r?null:s.map(_=>[_.height,_.width]),{pixel_values:o,pixel_mask:i}=await this.processor(s),l=await this.model({pixel_values:o,pixel_mask:i}),c=this.processor.image_processor.post_process_object_detection(l,t,a),{id2label:d}=this.model.config,h=c.map(_=>_.boxes.map((p,w)=>({score:_.scores[w],label:d[_.classes[w]],box:zu(p,!r)})));return n?h:h[0]}},VN=class extends qe{async _call(e,t,{threshold:r=.1,top_k:n=null,percentage:s=!1}={}){const a=Array.isArray(e),o=await Xt(e),i=this.tokenizer(t,{padding:!0,truncation:!0}),l=await this.processor(o),c=[];for(let d=0;d<o.length;++d){const h=o[d],_=s?null:[[h.height,h.width]],p=l.pixel_values[d].unsqueeze_(0),w=await this.model({...i,pixel_values:p});let v;if("post_process_grounded_object_detection"in this.processor){const y=this.processor.post_process_grounded_object_detection(w,i.input_ids,{box_threshold:r,text_threshold:r,target_sizes:_})[0];v=y.boxes.map((x,k)=>({score:y.scores[k],label:y.labels[k],box:zu(x,!s)}))}else{const y=this.processor.image_processor.post_process_object_detection(w,r,_,!0)[0];v=y.boxes.map((x,k)=>({score:y.scores[k],label:t[y.classes[k]],box:zu(x,!s)}))}v.sort((y,x)=>x.score-y.score),n!==null&&(v=v.slice(0,n)),c.push(v)}return a?c:c[0]}},UN=class extends qe{constructor(){super(...arguments);T(this,"_default_generation_config",{max_new_tokens:256})}async _call(t,r,n={}){if(Array.isArray(t)){if(t.length!==1)throw Error("Document Question Answering pipeline currently only supports a batch size of 1.");t=t[0]}const s=(await Xt(t))[0],{pixel_values:a}=await this.processor(s),o=`<s_docvqa><s_question>${r}</s_question><s_answer>`,i=this.tokenizer(o,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,l=await this.model.generate({inputs:a,max_length:this.model.config.decoder.max_position_embeddings,decoder_input_ids:i,...this._default_generation_config,...n}),d=this.tokenizer.batch_decode(l)[0].match(/<s_answer>(.*?)<\/s_answer>/);let h=null;return d&&d.length>=2&&(h=d[1].trim()),[{answer:h}]}},jN=class extends qe{async _call(e){const t=await Xt(e),r=await this.processor(t),n=await this.model(r),s=[];for(const a of n.reconstruction){const o=a.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");s.push(Ht.fromTensor(o))}return Array.isArray(e)?s:s[0]}},WN=class extends qe{async _call(e){const t=await Xt(e),r=await this.processor(t),{predicted_depth:n}=await this.model(r),s=[];for(let a=0;a<t.length;++a){const o=n[a],[i,l]=o.dims.slice(-2),[c,d]=t[a].size,h=(await qt(o.view(1,1,i,l),{size:[d,c],mode:"bilinear"})).view(d,c),_=h.min().item(),p=h.max().item(),w=h.sub(_).div_(p-_).mul_(255).to("uint8").unsqueeze(0),v=Ht.fromTensor(w);s.push({predicted_depth:h,depth:v})}return Array.isArray(e)?s:s[0]}},qN=class extends qe{async _call(e,{pooling:t="none",normalize:r=!1,quantize:n=!1,precision:s="binary"}={}){const a=this.tokenizer(e,{padding:!0,truncation:!0}),o=await this.model(a);let i=o.last_hidden_state??o.logits??o.token_embeddings;switch(t){case"none":break;case"mean":i=ek(i,a.attention_mask);break;case"first_token":case"cls":i=i.slice(null,0);break;case"last_token":case"eos":i=i.slice(null,-1);break;default:throw Error(`Pooling method '${t}' not supported.`)}return r&&(i=i.normalize(2,-1)),n&&(i=nk(i,s)),i}},HN=class extends qe{async _call(e,{pool:t=null}={}){const r=await Xt(e),{pixel_values:n}=await this.processor(r),s=await this.model({pixel_values:n});let a;if(t){if(!("pooler_output"in s))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");a=s.pooler_output}else a=s.last_hidden_state??s.logits??s.image_embeds;return a}},no=Object.freeze({"text-classification":{pipeline:xN,model:lw,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{pipeline:kN,model:oN,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{pipeline:AN,model:hN,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{pipeline:CN,model:dN,default:{model:"onnx-community/ettin-encoder-32m-ONNX",dtype:"fp32"},type:"text"},summarization:{pipeline:SN,model:Du,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{pipeline:PN,model:Du,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{pipeline:Bu,model:Du,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{pipeline:FN,model:uN,default:{model:"onnx-community/Qwen3-0.6B-ONNX",dtype:"q4"},type:"text"},"zero-shot-classification":{pipeline:IN,model:lw,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:LN,model:wN,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{pipeline:ON,model:Es,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{pipeline:NN,model:[iN,gN],default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{pipeline:DN,model:[cN,lN],default:{model:"onnx-community/Supertonic-TTS-ONNX",dtype:"fp32"},type:"text"},"image-to-text":{pipeline:zN,model:fN,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:BN,model:_N,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:_w,model:[cw,uw,dw],default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:RN,model:[cw,uw,dw],default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{pipeline:$N,model:Es,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:GN,model:pN,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{pipeline:VN,model:mN,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{pipeline:UN,model:vN,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:jN,model:yN,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:WN,model:bN,default:{model:"onnx-community/depth-anything-v2-small"},type:"image"},"feature-extraction":{pipeline:qN,model:Es,default:{model:"onnx-community/all-MiniLM-L6-v2-ONNX",dtype:"fp32"},type:"text"},"image-feature-extraction":{pipeline:HN,model:[MN,Es],default:{model:"onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX",dtype:"fp32"},type:"image"}}),pw=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function QN(e){if(!e)throw new Error("modelId is required");return(await cs(e,_s,{})).exists?[_s]:[]}async function XN(e,{config:t=null,dtype:r=null,device:n=null,model_file_name:s=null,include_tokenizer:a=!0,include_processor:o=!0}={}){const i=await em(e,{config:t,dtype:r,device:n,model_file_name:s});if(a){const l=await q_(e);i.push(...l)}if(o){const l=await QN(e);i.push(...l)}return i}async function YN(e,t,r={}){e=pw[e]??e;const n=no[e];if(!n)throw new Error(`Unsupported pipeline task: ${e}. Must be one of [${Object.keys(no).join(", ")}]`);const{type:s}=n,i=await XN(t,{...r,include_tokenizer:s!=="audio"&&s!=="image",include_processor:s!=="text"});if(e==="text-generation"){const l=await Zp(t,r),c=Kp(l),d=Q2(c);if(d){const h=Object.values(d).map(_=>`onnx/${_}`);return i.filter(_=>!_.startsWith("onnx/")||h.some(p=>_.startsWith(p)))}}return i}async function JN(e,t=null,{progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:a=!1,revision:o="main",device:i=null,dtype:l=null,subfolder:c="onnx",use_external_data_format:d=null,model_file_name:h=null,session_options:_={}}={}){e=pw[e]??e;const p=no[e.split("_",1)[0]];if(!p)throw Error(`Unsupported pipeline: ${e}. Must be one of [${Object.keys(no)}]`);t||(t=p.default.model,he.info(`No model specified. Using default model: "${t}".`),!l&&p.default.dtype&&(l=p.default.dtype));const w=await YN(e,t,{device:i,dtype:l});let v={};if(r)try{(await Promise.all(w.map(async J=>cs(t,J)))).forEach((J,Q)=>{J.exists&&(v[w[Q]]={loaded:0,total:J.size??0})})}catch(U){he.warn(`Unable to fetch model file metadata for total progress tracking: ${U}`)}const y={progress_callback:r?new la(r,v):void 0,config:n,cache_dir:s,local_files_only:a,revision:o,device:i,dtype:l,subfolder:c,use_external_data_format:d,model_file_name:h,session_options:_},x=w.includes("tokenizer.json"),k=w.includes("preprocessor_config.json"),A=p.model;let S;if(Array.isArray(A)){const U=n??await ps.from_pretrained(t,y),{model_type:J}=U,Q=A.find(B=>B.supports(J));if(!Q)throw Error(`Unsupported model type "${J}" for task "${e}". None of the candidate model classes support this type.`);S=Q.from_pretrained(t,{...y,config:U})}else S=A.from_pretrained(t,y);const[C,O,M]=await Promise.all([x?Te.from_pretrained(t,y):null,k?v2.from_pretrained(t,y):null,S]),V={task:e,model:M};C&&(V.tokenizer=C),O&&(V.processor=O),Pr(r,{status:"ready",task:e,model:t});const G=p.pipeline;return new G(V)}pe.IS_PROCESS_AVAILABLE;let so;self.addEventListener("message",async({data:e})=>{if((e==null?void 0:e.type)!=="transcribe")return;const{id:t,audio:r}=e;try{so||(so=JN("automatic-speech-recognition","onnx-community/whisper-small",{dtype:"q8",progress_callback:a=>self.postMessage({type:"progress",id:t,progress:{status:a.status,file:a.file,progress:a.progress}})}));const s=await(await so)(new Float32Array(r),{chunk_length_s:30,stride_length_s:5,num_beams:2});self.postMessage({type:"result",id:t,text:String((s==null?void 0:s.text)||"").trim()})}catch(n){so=null,self.postMessage({type:"error",id:t,message:(n==null?void 0:n.message)||"Local Whisper could not transcribe this audio."})}})})();
|
|
44
|
+
`}):(he.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."),a=t.map(l=>ZE(l,n,s,kn,e.length)));const o=this.tokenizer(a,r);return{...await this.image_processor(e,r),...o}}},T(Ds,"tokenizer_class",Te),T(Ds,"image_processor_class",ft),T(Ds,"uses_processor_config",!1),Ds),$p="<|image|>",t2=/<\|image_\d+\|>/g,r2=(po=class extends Ee{async _call(e,t=null,{padding:r=!0,truncation:n=!0,num_crops:s=null}={}){Array.isArray(e)||(e=[e]);let a,o;if(t){o=await this.image_processor(t,{num_crops:s});const{num_img_tokens:i}=o,l=e.map((d,h)=>d.split(t2).join($p.repeat(i[h])));a=this.tokenizer(l,{padding:r,truncation:n});const c=this.tokenizer._tokenizer.token_to_id($p);a.input_ids.map_(d=>d==c?-d:d)}else a=this.tokenizer(e);return{...a,...o}}},T(po,"image_processor_class",ft),T(po,"tokenizer_class",Te),po),n2=(zs=class extends Ee{async _call(e,t=null,r={}){const n=await this.image_processor(e,r);if(t){const[a,o]=n.pixel_values.dims.slice(-2),{image_token:i,image_break_token:l,image_end_token:c,patch_size:d,spatial_merge_size:h}=this.config,_=d*h,p=Math.floor(a/_),w=Math.floor(o/_);t=structuredClone(t),Array.isArray(t)||(t=[t]);for(let v=0;v<t.length;++v){const y=i.repeat(w),x=y+l,k=y+c,A=x.repeat(p-1)+k;t[v]=t[v].replace(i,A)}}const s=t?this.tokenizer(t,r):{};return{...n,...s}}},T(zs,"tokenizer_class",Te),T(zs,"image_processor_class",ft),T(zs,"uses_processor_config",!0),zs),s2=(Vu=class extends Ee{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}},T(Vu,"feature_extractor_class",dp),Vu),Gp=class extends gl{},a2=class extends Gp{},Vp=(Uu=class extends Ee{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)}},T(Uu,"image_processor_class",ft),Uu),Up=class extends Vp{},o2=class extends Up{},i2=(mo=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(mo,"tokenizer_class",Te),T(mo,"feature_extractor_class",Lt),mo),l2=(Bs=class extends Ee{async _call(e,t=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(t){const a=t.length,{input_features:o}=await this.feature_extractor(t,{...r,max_length:a}),i=Math.round(a/this.config.encoder_ds_factor+1e-4),l=1+Math.ceil(i/this.config.stack_factor);n.audio_token_len=[l],n.audio_values=o;const c=this.config.audio_placeholder;if(!e.includes(c))throw new Error(`The input text does not contain the image token ${c}.`);e=e.replaceAll(c,c.repeat(l))}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}},T(Bs,"tokenizer_class",Te),T(Bs,"feature_extractor_class",Lt),T(Bs,"uses_processor_config",!0),Bs),Fa="[AUDIO]",c2="[BEGIN_AUDIO]",u2=375;function d2(e,t){const r=[];for(let n=0;n<e.length;n+=t)r.push(e.subarray(n,Math.min(n+t,e.length)));return r}var h2=(Rs=class extends Ee{async _call(e,t=null,r={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");const n={};if(t){if(!e.includes(Fa))throw new Error(`The input text does not contain the audio token ${Fa}.`);Array.isArray(t)||(t=[t]);const a=e.split(Fa),o=a.length-1;if(o!==t.length)throw new Error(`The number of audio inputs (${t.length}) does not match the number of audio tokens in the text (${o}).`);const i=this.feature_extractor.config.n_samples,l=t.map(p=>d2(p,i)),c=l.map(p=>p.length),d=l.flat(),h=(await Promise.all(d.map(p=>this.feature_extractor(p,r)))).map(p=>p.input_features);n.audio_values=h.length>1?Re(h,0):h[0];let _=a[0];for(let p=0;p<c.length;++p){_+=c2;for(let w=0;w<c[p];++w)_+=Fa.repeat(u2);_+=a[p+1]}e=_}return{...this.tokenizer(e,{add_special_tokens:!1,...r}),...n}}},T(Rs,"tokenizer_class",Te),T(Rs,"feature_extractor_class",Lt),T(Rs,"uses_processor_config",!1),Rs),jp=32,wl=6,Ia=8,f2=10,_2=32,p2=($s=class extends Ee{get num_mel_frames_first_audio_chunk(){return(wl+1)*Ia}get num_samples_first_audio_chunk(){const{hop_length:e,n_fft:t}=this.feature_extractor.config;return(this.num_mel_frames_first_audio_chunk-1)*e+Math.floor(t/2)}get num_samples_per_audio_chunk(){const{hop_length:e,n_fft:t}=this.feature_extractor.config;return Ia*e+t}get num_right_pad_tokens(){return wl+1+f2}get audio_length_per_tok(){return Ia}get raw_audio_length_per_tok(){return Ia*this.feature_extractor.config.hop_length}async _call(e,{is_streaming:t=!1,is_first_audio_chunk:r=!0}={}){if(ot(e,"VoxtralRealtimeProcessor"),!t&&!r)throw new Error("In non-streaming mode (`is_streaming=false`), `is_first_audio_chunk` must be `true`.");if(r)if(t){const n=jp*this.raw_audio_length_per_tok,s=new Float32Array(n+e.length);s.set(e,n);const a=await this.feature_extractor(s,{center:!0}),i=1+(jp+wl),l=new BigInt64Array(i).fill(BigInt(_2));return l[0]=1n,{input_ids:new j("int64",l,[1,i]),...a}}else{const n=this.num_right_pad_tokens*this.raw_audio_length_per_tok,s=new Float32Array(e.length+n);return s.set(e),await this.feature_extractor(s,{center:!0})}else return await this.feature_extractor(e,{center:!1})}},T($s,"tokenizer_class",Te),T($s,"feature_extractor_class",Lt),T($s,"uses_processor_config",!1),$s),m2=(go=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(go,"tokenizer_class",Te),T(go,"feature_extractor_class",Lt),go),g2=(wo=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(wo,"tokenizer_class",Te),T(wo,"feature_extractor_class",Lt),wo),w2=(vo=class extends Ee{async _call(e){return await this.feature_extractor(e)}},T(vo,"tokenizer_class",Te),T(vo,"feature_extractor_class",Lt),vo),v2=class{static async from_pretrained(e,t={}){const r=await nr(e,_s,!0,t),{image_processor_type:n,feature_extractor_type:s,processor_class:a}=r;if(a&&sl[a])return sl[a].from_pretrained(e,t);if(!n&&!s)throw new Error("No `image_processor_type` or `feature_extractor_type` found in the config.");const o={};if(n){const l=Pa[n.replace(/Fast$/,"")];if(!l)throw new Error(`Unknown image_processor_type: '${n}'.`);o.image_processor=new l(r)}if(s){const l=Pa[s];if(l)o.image_processor=new l(r);else{const c=al[s];if(!c)throw new Error(`Unknown feature_extractor_type: '${s}'.`);o.feature_extractor=new c(r)}}const i={};return new Ee(i,o,null)}};async function y2(e,t){return await nr(e,"config.json",!0,t)}function Tn(e){const t={};let r={};switch(e.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"gemma4":case"lfm2_vl":case"chatterbox":case"lighton_ocr":case"glm_ocr":case"mistral3":case"qwen2_5_vl":case"qwen3_vl":case"qwen3_vl_moe":r=Tn(e.text_config);break;case"moondream1":r=Tn(e.phi_config);break;case"musicgen":r=Tn(e.decoder);break;case"multi_modality":r=Tn(e.language_config);break;case"gpt2":case"gptj":case"jais":case"codegen":case"gpt_bigcode":t.num_heads="n_head",t.num_layers="n_layer",t.hidden_size="n_embd";break;case"gpt_neox":case"stablelm":case"opt":case"falcon":case"modernbert-decoder":t.num_heads="num_attention_heads",t.num_layers="num_hidden_layers",t.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":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size",t.num_attention_heads="num_attention_heads",t.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"gemma4_text":case"glm":case"helium":case"ernie4_5":case"hunyuan_v1_dense":case"falcon_h1":case"nemotron_h":case"ministral":case"ministral3":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.dim_kv="head_dim";break;case"openelm":t.num_heads="num_kv_heads",t.num_layers="num_transformer_layers",t.dim_kv="head_dim";break;case"gpt_neo":case"donut-swin":t.num_heads="num_heads",t.num_layers="num_layers",t.hidden_size="hidden_size";break;case"bloom":t.num_heads="n_head",t.num_layers="n_layer",t.hidden_size="hidden_size";break;case"mpt":t.num_heads="n_heads",t.num_layers="n_layers",t.hidden_size="d_model";break;case"exaone":t.num_heads="num_key_value_heads",t.num_layers="num_layers",t.dim_kv="head_dim",t.num_attention_heads="num_attention_heads";break;case"youtu":case"deepseek_v3":case"deepseek_v4":case"glm_moe_dsa":case"mistral4":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.dim_kv=e.model_type==="deepseek_v4"?"head_dim":"qk_head_dim",t.num_attention_heads="num_attention_heads";break;case"zaya":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size",t.dim_kv="head_dim",t.num_attention_heads="num_attention_heads";break;case"hrm_text":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size",t.dim_kv="head_dim",t.num_attention_heads="num_attention_heads";break;case"t5":case"mt5":case"longt5":t.num_decoder_layers="num_decoder_layers",t.num_decoder_heads="num_heads",t.decoder_dim_kv="d_kv",t.num_encoder_layers="num_layers",t.num_encoder_heads="num_heads",t.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":t.num_decoder_layers="decoder_layers",t.num_decoder_heads="decoder_attention_heads",t.decoder_hidden_size="d_model",t.num_encoder_layers="encoder_layers",t.num_encoder_heads="encoder_attention_heads",t.encoder_hidden_size="d_model";break;case"speecht5":t.num_decoder_layers="decoder_layers",t.num_decoder_heads="decoder_attention_heads",t.decoder_hidden_size="hidden_size",t.num_encoder_layers="encoder_layers",t.num_encoder_heads="encoder_attention_heads",t.encoder_hidden_size="hidden_size";break;case"trocr":t.num_encoder_layers=t.num_decoder_layers="decoder_layers",t.num_encoder_heads=t.num_decoder_heads="decoder_attention_heads",t.encoder_hidden_size=t.decoder_hidden_size="d_model";break;case"musicgen_decoder":t.num_encoder_layers=t.num_decoder_layers="num_hidden_layers",t.num_encoder_heads=t.num_decoder_heads="num_attention_heads",t.encoder_hidden_size=t.decoder_hidden_size="hidden_size";break;case"moonshine":t.num_decoder_layers="decoder_num_hidden_layers",t.num_decoder_heads="decoder_num_key_value_heads",t.num_encoder_layers="encoder_num_hidden_layers",t.num_encoder_heads="encoder_num_key_value_heads",t.encoder_hidden_size=t.decoder_hidden_size="hidden_size";break;case"cohere_asr":t.num_decoder_layers="num_hidden_layers",t.num_decoder_heads="num_key_value_heads",t.decoder_hidden_size="hidden_size",t.decoder_dim_kv="head_dim";const{num_hidden_layers:s,num_attention_heads:a,hidden_size:o}=e.encoder_config;r={num_encoder_layers:s,num_encoder_heads:a,encoder_hidden_size:o,encoder_dim_kv:e.head_dim};break;case"vision-encoder-decoder":const i=Tn(e.decoder),l="num_decoder_layers"in i,c=rt(e,["model_type","is_encoder_decoder"]);return l?(c.num_decoder_layers=i.num_decoder_layers,c.num_decoder_heads=i.num_decoder_heads,c.decoder_hidden_size=i.decoder_hidden_size,c.num_encoder_layers=i.num_encoder_layers,c.num_encoder_heads=i.num_encoder_heads,c.encoder_hidden_size=i.encoder_hidden_size):(c.num_layers=i.num_layers,c.num_heads=i.num_heads,c.hidden_size=i.hidden_size),c}const n={...r,...rt(e,["model_type","multi_query","is_encoder_decoder"])};for(const s in t)n[s]=e[t[s]];return n}function La(e,t){e instanceof vl||(e=new vl(e));const r=(t==null?void 0:t.prefix)??"past_key_values",n=r==="present"?"present":"past",s=new Set;if(["lfm2","lfm2_moe"].includes(e.model_type)){const{layer_types:a}=e;for(let o=0;o<a.length;++o)if(a[o]==="full_attention")s.add(`${r}.${o}.key`),s.add(`${r}.${o}.value`);else if(a[o]==="conv")s.add(`${n}_conv.${o}`);else throw new Error(`Unsupported layer type: ${a[o]}`);return s}else if(["granitemoehybrid","falcon_h1","nemotron_h"].includes(e.model_type)){const a=e,o=a.layer_types??a.layers_block_type,i=a.num_hidden_layers??(o==null?void 0:o.length);for(let l=0;l<i;++l)(!o||o[l]==="mamba")&&(s.add(`${n}_conv.${l}`),s.add(`${n}_ssm.${l}`)),(!o||o[l]==="attention")&&(s.add(`${r}.${l}.key`),s.add(`${r}.${l}.value`));return s}else if(["qwen3_next","qwen3_5_text","qwen3_5_moe_text","olmo_hybrid"].includes(e.model_type)){const{layer_types:a}=e;for(let o=0;o<a.length;++o)if(a[o]==="full_attention")s.add(`${r}.${o}.key`),s.add(`${r}.${o}.value`);else if(a[o]==="linear_attention")e.model_type==="olmo_hybrid"?(s.add(`${n}_conv.${o}.key`),s.add(`${n}_conv.${o}.value`),s.add(`${n}_conv.${o}.query`)):s.add(`${n}_conv.${o}`),s.add(`${n}_recurrent.${o}`);else throw new Error(`Unsupported layer type: ${a[o]}`);return s}else if(["gemma4","gemma4_text"].includes(e.model_type)){const a=e.model_type==="gemma4"?e.text_config:e,o=a.num_hidden_layers,i=a.num_kv_shared_layers??0,l=o-i;for(let c=0;c<l;++c)s.add(`${r}.${c}.key`),s.add(`${r}.${c}.value`);return s}else if(e.model_type==="deepseek_v4"){const{layer_types:a,num_hidden_layers:o}=e;for(let i=0;i<o;++i){s.add(`${r}.${i}.key`),s.add(`${r}.${i}.value`);const l=a[i];if(l==="compressed_sparse_attention")s.add(`${n}_compressor.${i}.kv`),s.add(`${n}_compressor.${i}.gate`),s.add(`${n}_indexer.${i}.kv`),s.add(`${n}_indexer.${i}.gate`);else if(l==="heavily_compressed_attention")s.add(`${n}_compressor.${i}.kv`),s.add(`${n}_compressor.${i}.gate`);else if(l&&l!=="sliding_attention")throw new Error(`Unsupported layer type: ${l}`)}return s}else if(e.model_type==="zaya"){const{num_hidden_layers:a,cca_time1:o}=e,i=o??1;for(let l=0;l<a;l+=i)s.add(`${r}.${l}.key`),s.add(`${r}.${l}.value`),s.add(`${r}.${l}.conv_state`),s.add(`${r}.${l}.shift_state`);return s}else if(["lfm2_vl","qwen3_5","qwen3_5_moe","voxtral_realtime"].includes(e.model_type)){let a;return e.model_type==="voxtral_realtime"&&(t==null?void 0:t.session_name)==="audio_encoder"?a=e.audio_config:a=e.text_config,La(a,t)}return b2(e,{prefix:r})}function b2(e,{prefix:t="past_key_values"}={}){const r=new Set,n=e.normalized_config;if(n.is_encoder_decoder&&"num_encoder_heads"in n&&"num_decoder_heads"in n)for(let s=0;s<n.num_decoder_layers;++s)r.add(`${t}.${s}.encoder.key`),r.add(`${t}.${s}.encoder.value`),r.add(`${t}.${s}.decoder.key`),r.add(`${t}.${s}.decoder.value`);else if(n.multi_query)for(let s=0;s<n.num_layers;++s)r.add(`${t}.${s}.key_value`);else for(let s=0;s<n.num_layers;++s)r.add(`${t}.${s}.key`),r.add(`${t}.${s}.value`);return r}var vl=class Qd{constructor(t){T(this,"model_type",null);T(this,"is_encoder_decoder",!1);T(this,"max_position_embeddings");T(this,"transformers.js_config");Object.assign(this,t),this.normalized_config=Tn(this)}static async from_pretrained(t,{progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:a=!1,revision:o="main"}={}){n&&!(n instanceof Qd)&&(n=new Qd(n));const i=n??await y2(t,{progress_callback:r,config:n,cache_dir:s,local_files_only:a,revision:o});return new this(i)}},ps=class{static async from_pretrained(...e){return vl.from_pretrained(...e)}};function Wp(e,t,r){return e?typeof e=="object"&&e!==null?e.hasOwnProperty(t)?+e[t]:e.hasOwnProperty(r)?+e[r]:0:+e:0}function qp(e,t){const r=[];for(let n=0;n<t;++n)r.push(`${e}_data${n===0?"":"_"+n}`);return r}async function M2(e,t,r,n){const s=`${t}${n}.onnx`,a=`${r.subfolder??""}/${s}`;return await ka(e,a,!0,r,pe.IS_NODE_ENV)}async function x2(e,t,r,n,s,a={}){const o=`${t}${r}.onnx`,i=pe.IS_NODE_ENV;let l=[];const c=Wp(s,o,t);if(c>0){if(c>g_)throw new Error(`The number of external data chunks (${c}) exceeds the maximum allowed value (${g_}).`);const d=qp(o,c);for(const h of d){const _=`${n.subfolder??""}/${h}`;l.push(new Promise(async(p,w)=>{const v=await ka(e,_,!0,n,i);p(v instanceof Uint8Array?{path:h,data:v}:h)}))}}else a.externalData!==void 0&&(l=a.externalData.map(async d=>{if(typeof d.data=="string"){const h=await ka(e,d.data,!0,n);return{...d,data:h}}return d}));return Promise.all(l)}async function k2(e,t,r,n=!1,s=void 0){var k;let a=((k=r.config)==null?void 0:k["transformers.js_config"])??{};const o=z_(r.device??a.device,t,{warn:A=>he.info(A)}),i=H1(o),l=a.device_config??{};l.hasOwnProperty(o)&&(a={...a,...l[o]});const c=$_(r.dtype??a.dtype,t,o,{configDtype:a.dtype,warn:A=>he.info(A)});if(Xi.hasOwnProperty(c)){if(o==="webgpu"&&!pe.IS_NODE_ENV&&c===Ye.fp16&&!await Y1())throw new Error(`The device (${o}) does not support fp16.`)}else throw new Error(`Invalid dtype: ${c}. Should be one of: ${Object.keys(Ye).join(", ")}`);const d=Xi[c],h={...r.session_options};h.executionProviders??(h.executionProviders=i);const _=a.free_dimension_overrides;_?h.freeDimensionOverrides??(h.freeDimensionOverrides=_):o.startsWith("webnn")&&!h.freeDimensionOverrides&&he.warn(`WebNN does not currently support dynamic shapes and requires 'free_dimension_overrides' to be set in config.json, preferably as a field within config["transformers.js_config"]["device_config"]["${o}"]. When 'free_dimension_overrides' is not set, you may experience significant performance degradation.`);const p=M2(e,t,r,d),w=r.use_external_data_format??a.use_external_data_format,v=await x2(e,t,d,r,w,h);if(v.length>0&&(!pe.IS_NODE_ENV||v.some(A=>typeof A!="string"))&&(h.externalData=v),n&&o==="webgpu"){const A=La(r.config,{prefix:"present",session_name:s});if(A.size>0&&!Hi()){const S={};for(const C of A)S[C]="gpu-buffer";h.preferredOutputLocation=S}}return{buffer_or_path:await p,session_options:h,session_config:{dtype:c,device:o}}}async function T2(e,t,r,n=void 0){return Object.fromEntries(await Promise.all(Object.keys(t).map(async s=>{const a=(n==null?void 0:n[s])??!1,{buffer_or_path:o,session_options:i,session_config:l}=await k2(e,t[s],r,a,s),c=await L_(o,i,l);return[s,c]})))}function Hp(e){for(let t in e)D_(e[t])?e[t]=new j(e[t]):typeof e[t]=="object"&&Hp(e[t]);return e}async function ye(e,t){const r=E2(e,t);try{const n=Object.fromEntries(Object.entries(r).map(([a,o])=>{const i=o.ort_tensor;return pe.IS_NODE_ENV&&typeof Float16Array<"u"&&i.cpuData instanceof Float16Array&&(i.cpuData=new Uint16Array(i.cpuData.buffer)),[a,i]})),s=await N_(e,n);return Hp(s)}catch(n){const s=Object.fromEntries(Object.entries(r).map(([a,o])=>{const i={type:o.type,dims:o.dims,location:o.location};return i.location!=="gpu-buffer"&&(i.data=o.data),[a,i]}));throw he.error(`An error occurred during model execution: "${n}".`),he.error("Inputs given to model:",s),n}}function E2(e,t){const r=Object.create(null),n=[];for(const o of e.inputNames){const i=t[o];if(!(i instanceof j)){n.push(o);continue}r[o]=Hi()?i.clone():i}if(n.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${n.join(", ")}.`);const s=Object.keys(t).length,a=e.inputNames.length;if(s>a){let o=Object.keys(t).filter(i=>!e.inputNames.includes(i));he.warn(`WARNING: Too many inputs were provided (${s} > ${a}). The following inputs will be ignored: "${o.join(", ")}".`)}return r}var je=class{},A2=class extends je{constructor({last_hidden_state:e,hidden_states:t=null,attentions:r=null}){super(),this.last_hidden_state=e,this.hidden_states=t,this.attentions=r}},le=class extends je{constructor({logits:e,...t}){super(),this.logits=e;const r=Object.values(t);r.length>0&&(this.attentions=r)}},Xe=class extends je{constructor({logits:e}){super(),this.logits=e}},Je=class extends je{constructor({logits:e}){super(),this.logits=e}},it=class extends je{constructor({start_logits:e,end_logits:t}){super(),this.start_logits=e,this.end_logits=t}},Br=class extends je{constructor({logits:e}){super(),this.logits=e}},C2=class extends je{constructor({logits:e,past_key_values:t}){super(),this.logits=e,this.past_key_values=t}},S2=class extends je{constructor({logits:e,past_key_values:t,encoder_outputs:r,decoder_attentions:n=null,cross_attentions:s=null}){super(),this.logits=e,this.past_key_values=t,this.encoder_outputs=r,this.decoder_attentions=n,this.cross_attentions=s}},Qp=class extends je{constructor({alphas:e}){super(),this.alphas=e}},Qt=class extends gt{_call(e,t){throw Error("`_call` should be implemented in a subclass")}},P2=class extends gt{_call(e,t){throw Error("`_call` should be implemented in a subclass")}},yl=class extends gt{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,t){let r=t;for(const n of this.processors)r=n(e,r);return r}[Symbol.iterator](){return this.processors.values()}},F2=class extends Qt{constructor(e){super(),this.bos_token_id=e}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length===1){const n=t[r].data;n.fill(-1/0),n[this.bos_token_id]=0}return t}},I2=class extends Qt{constructor(e,t){super(),this.max_length=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length===this.max_length-1){const n=t[r].data;n.fill(-1/0);for(const s of this.eos_token_id)n[s]=0}return t}},L2=class extends Qt{constructor(e){super(),this.suppress_tokens=e}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data;for(const s of this.suppress_tokens)n[s]=-1/0}return t}},Xp=class extends Qt{constructor(e,t){super(),this.begin_suppress_tokens=e,this.begin_index=t}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length===this.begin_index){const n=t[r].data;for(const s of this.begin_suppress_tokens)n[s]=-1/0}return t}},O2=class extends Qt{constructor(e,t){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=t.length,t.at(-1)===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data;if(n[this.no_timestamps_token_id]=-1/0,e[r].length===this.begin_index){n.subarray(0,this.timestamp_begin).fill(-1/0);continue}const s=e[r].slice(this.begin_index),a=s.length>=1&&s[s.length-1]>=this.timestamp_begin,o=s.length<2||s[s.length-2]>=this.timestamp_begin;if(a&&(o?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){const d=this.timestamp_begin+this.max_initial_timestamp_index;n.subarray(d+1).fill(-1/0)}const i=O1(n),l=Math.log(i.subarray(this.timestamp_begin).map(Math.exp).reduce((d,h)=>d+h)),c=Qe(i.subarray(0,this.timestamp_begin))[0];l>c&&n.subarray(0,this.timestamp_begin).fill(-1/0)}return t}},N2=class extends Qt{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){const t=e.length,r=[];for(let s=0;s<t+1-this.no_repeat_ngram_size;++s){const a=[];for(let o=0;o<this.no_repeat_ngram_size;++o)a.push(e[s+o]);r.push(a.map(Number))}const n=new Map;for(const s of r){const a=s.slice(0,s.length-1),o=JSON.stringify(a),i=n.get(o)??[];i.push(s[s.length-1]),n.set(o,i)}return n}getGeneratedNgrams(e,t){const r=t.slice(t.length+1-this.no_repeat_ngram_size,t.length);return e.get(JSON.stringify(r.map(Number)))??[]}calcBannedNgramTokens(e){const t=[];if(e.length+1<this.no_repeat_ngram_size)return t;{const r=this.getNgrams(e);return this.getGeneratedNgrams(r,e)}}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data,s=this.calcBannedNgramTokens(e[r]);for(const a of s)n[a]=-1/0}return t}},D2=class extends Qt{constructor(e){super(),this.penalty=e}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data;for(const s of new Set(e[r])){const a=Number(s);n[a]<0?n[a]*=this.penalty:n[a]/=this.penalty}}return t}},z2=class extends Qt{constructor(e,t){super(),this.min_length=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length<this.min_length){const n=t[r].data;for(const s of this.eos_token_id)n[s]=-1/0}return t}},B2=class extends Qt{constructor(e,t,r){super(),this.prompt_length_to_skip=e,this.min_new_tokens=t,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,t){for(let r=0;r<e.length;++r)if(e[r].length-this.prompt_length_to_skip<this.min_new_tokens){const s=t[r].data;for(const a of this.eos_token_id)s[a]=-1/0}return t}},R2=class extends Qt{constructor(e,t){super(),this.bad_words_ids=e,this.eos_token_id=Array.isArray(t)?t:[t]}_call(e,t){for(let r=0;r<e.length;++r){const n=t[r].data,s=e[r];for(const a of this.bad_words_ids){if(s.length<a.length-1)continue;let o=!0;for(let i=1;i<=a.length-1;++i)if(a.at(-i-1)!=s.at(-i)){o=!1;break}o&&(n[a.at(-1)]=-1/0)}}return t}},$2=class extends Qt{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,t){if(t.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 ${t.dims[0]} for the logits and ${e.length} for the input ids.`);const r=e.length,n=t.slice([0,r],null),s=t.slice([r,t.dims[0]],null);for(let a=0;a<s.data.length;++a)s.data[a]+=(n.data[a]-s.data[a])*this.guidance_scale;return s}},G2=class extends P2{constructor(e){super(),this.temperature=e}_call(e,t){const r=t.data;for(let n=0;n<r.length;++n)r[n]/=this.temperature;return t}},Yp=class{constructor(e){T(this,"max_length",20);T(this,"max_new_tokens",null);T(this,"min_length",0);T(this,"min_new_tokens",null);T(this,"early_stopping",!1);T(this,"max_time",null);T(this,"do_sample",!1);T(this,"num_beams",1);T(this,"num_beam_groups",1);T(this,"penalty_alpha",null);T(this,"use_cache",!0);T(this,"temperature",1);T(this,"top_k",50);T(this,"top_p",1);T(this,"typical_p",1);T(this,"epsilon_cutoff",0);T(this,"eta_cutoff",0);T(this,"diversity_penalty",0);T(this,"repetition_penalty",1);T(this,"encoder_repetition_penalty",1);T(this,"length_penalty",1);T(this,"no_repeat_ngram_size",0);T(this,"bad_words_ids",null);T(this,"force_words_ids",null);T(this,"renormalize_logits",!1);T(this,"constraints",null);T(this,"forced_bos_token_id",null);T(this,"forced_eos_token_id",null);T(this,"remove_invalid_values",!1);T(this,"exponential_decay_length_penalty",null);T(this,"suppress_tokens",null);T(this,"streamer",null);T(this,"begin_suppress_tokens",null);T(this,"forced_decoder_ids",null);T(this,"guidance_scale",null);T(this,"num_return_sequences",1);T(this,"output_attentions",!1);T(this,"output_hidden_states",!1);T(this,"output_scores",!1);T(this,"return_dict_in_generate",!1);T(this,"pad_token_id",null);T(this,"bos_token_id",null);T(this,"eos_token_id",null);T(this,"encoder_no_repeat_ngram_size",0);T(this,"decoder_start_token_id",null);T(this,"generation_kwargs",{});Object.assign(this,rt(e,Object.getOwnPropertyNames(this)))}},Oa=class extends gt{_call(e,t){throw Error("StoppingCriteria needs to be subclassed")}},Jp=class Vy extends gt{constructor(){super(),this.criteria=[]}push(t){this.criteria.push(t)}extend(t){t instanceof Vy?t=t.criteria:t instanceof Oa&&(t=[t]),this.criteria.push(...t)}_call(t,r){const n=new Array(t.length).fill(!1);for(const s of this.criteria){const a=s(t,r);for(let o=0;o<n.length;++o)n[o]||(n[o]=a[o])}return n}[Symbol.iterator](){return this.criteria.values()}},V2=class extends Oa{constructor(e,t=null){super(),this.max_length=e,this.max_position_embeddings=t}_call(e){return e.map(t=>t.length>=this.max_length)}},U2=class extends Oa{constructor(e){super(),Array.isArray(e)||(e=[e]),this.eos_token_id=e}_call(e,t){return e.map(r=>{const n=r.at(-1);return this.eos_token_id.some(s=>n==s)})}},Na=class extends gt{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,t){let r=e.dims.at(-1),n=e.data;if(t===-1)n=n.slice(-r);else{let s=t*r;n=n.slice(s,s+r)}return n}randomSelect(e){return g1(e)}static getSampler(e){if(e.do_sample)return new W2(e);if(e.num_beams>1)return new q2(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 j2(e)}},j2=class extends Na{async sample(e){const t=Qe(e.data)[1];return[[BigInt(t),0]]}},W2=class extends Na{async sample(e){let t=e.dims.at(-1);this.generation_config.top_k>0&&(t=Math.min(this.generation_config.top_k,t));const[r,n]=await Mn(e,t),s=at(r.data);return Array.from({length:this.generation_config.num_beams},()=>{const a=this.randomSelect(s);return[n.data[a],Math.log(s[a])]})}},q2=class extends Na{async sample(e){let t=e.dims.at(-1);this.generation_config.top_k>0&&(t=Math.min(this.generation_config.top_k,t));const[r,n]=await Mn(e,t),s=at(r.data);return Array.from({length:this.generation_config.num_beams},(a,o)=>[n.data[o],Math.log(s[o])])}},H2=class{constructor(e){if(e)for(const t in e){if(t in this)throw new TypeError(`Key "${t}" conflicts with an existing property on DynamicCache`);const r=e[t];if(!(r instanceof j))throw new TypeError(`Expected a Tensor for key "${t}", got ${typeof r}`);this[t]=r}}get_seq_length(){const e=this;if(Object.keys(e).length===0)return 0;for(const t in e)if(t.startsWith("past_key_values."))return e[t].dims.at(-2);throw new Error("Unable to determine sequence length from the cache.")}update(e){for(const t in e){const r=this[t],n=e[t];r&&r!==n&&r.location==="gpu-buffer"&&r.dispose(),this[t]=n}}async dispose(){const e=[];for(const t of Object.values(this))t.location==="gpu-buffer"&&e.push(t.dispose());await Promise.all(e)}},bl=H2,q={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,VoxtralRealtime:16,MultimodalEncoder:17},gr={[q.DecoderOnly]:{sessions:(e,t)=>({model:t.model_file_name??"model"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[q.DecoderOnlyWithoutHead]:{sessions:(e,t)=>({model:t.model_file_name??"model"})},[q.Seq2Seq]:{sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.Vision2Seq]:{sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.Musicgen]:{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"}},[q.EncoderDecoder]:{sessions:()=>({model:"encoder_model",decoder_model_merged:"decoder_model_merged"}),cache_sessions:{decoder_model_merged:!0}},[q.MaskGeneration]:{sessions:()=>({model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"})},[q.ImageTextToText]:{text_only_sessions:{embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"},sessions:(e,t,r)=>{const n={...gr[q.ImageTextToText].text_only_sessions};return r||(n.vision_encoder="vision_encoder"),e.is_encoder_decoder&&(n.model="encoder_model"),n},cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.AudioTextToText]:{text_only_sessions:{embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"},sessions:(e,t,r)=>{const n={...gr[q.AudioTextToText].text_only_sessions};return r||(n.audio_encoder="audio_encoder"),n},cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.ImageAudioTextToText]:{text_only_sessions:{embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"},sessions:(e,t,r)=>{const n={...gr[q.ImageAudioTextToText].text_only_sessions};return r||(n.audio_encoder="audio_encoder",n.vision_encoder="vision_encoder"),n},cache_sessions:{decoder_model_merged:!0},optional_configs:{generation_config:"generation_config.json"}},[q.Phi3V]:{sessions:()=>({prepare_inputs_embeds:"prepare_inputs_embeds",model:"model",vision_encoder:"vision_encoder"}),cache_sessions:{model:!0},optional_configs:{generation_config:"generation_config.json"}},[q.MultiModality]:{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"}},[q.AutoEncoder]:{sessions:()=>({encoder_model:"encoder_model",decoder_model:"decoder_model"})},[q.Supertonic]:{sessions:()=>({text_encoder:"text_encoder",latent_denoiser:"latent_denoiser",voice_decoder:"voice_decoder"})},[q.Chatterbox]:{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"}},[q.VoxtralRealtime]:{text_only_sessions:{embed_tokens:"embed_tokens",decoder_model_merged:"decoder_model_merged"},sessions:(e,t,r)=>{const n={...gr[q.VoxtralRealtime].text_only_sessions};return r||(n.audio_encoder="audio_encoder"),n},cache_sessions:{decoder_model_merged:!0,audio_encoder:!0},optional_configs:{generation_config:"generation_config.json"}},[q.MultimodalEncoder]:{sessions:(e,t)=>({model:t.model_file_name??"model",...e.vision_config&&{vision_encoder:"vision_encoder"},...e.audio_config&&{audio_encoder:"audio_encoder"}})},default:{sessions:(e,t)=>({model:t.model_file_name??"model"})}};function Q2(e){const t=gr[e];return(t==null?void 0:t.text_only_sessions)??null}function X2(e,t,r={}){const n=gr[e]??gr.default;return{sessions:n.sessions(t,r,r.textOnly??!1),cache_sessions:n.cache_sessions,optional_configs:n.optional_configs}}function Kp(e,{warn:t=!0}={}){const r=e.architectures||[];for(const n of r){const s=wr.get(n);if(s!==void 0)return s}if(e.model_type){const n=wr.get(e.model_type);if(n!==void 0)return n;for(const s of Object.values(En))if(s.has(e.model_type)){const a=wr.get(s.get(e.model_type));if(a!==void 0)return a}}if(t){const n=r.length>0?r.join(", "):"(none)";he.warn(`[resolve_model_type] Architecture(s) not found in MODEL_TYPE_MAPPING: [${n}] for model type '${e.model_type}'. Falling back to EncoderOnly (single model.onnx file). If you encounter issues, please report at: ${Aa}`)}return q.EncoderOnly}function Zp(e,{config:t=null,cache_dir:r=null,local_files_only:n=!1,revision:s="main"}={}){if(t!==null)return ps.from_pretrained(e,{config:t,cache_dir:r,local_files_only:n,revision:s});const a=Bi(e,{cache_dir:r,local_files_only:n,revision:s});return x_(a,()=>ps.from_pretrained(e,{config:t,cache_dir:r,local_files_only:n,revision:s}))}async function em(e,{config:t=null,dtype:r=null,device:n=null,model_file_name:s=null}={}){t=await Zp(e,{config:t});const a=["config.json"],o=t["transformers.js_config"]??{},i=o.use_external_data_format,l="onnx",c=n??o.device;let d=r??o.dtype;const h=Kp(t),_=(v,y=null)=>{y=y??v;const x=z_(c,v),k=$_(d,v,x),A=Xi[k]??"",S=`${y}${A}.onnx`,C=`${l}/${S}`;a.push(C);const O=Wp(i,S,v);for(const M of qp(S,O)){const V=`${l}/${M}`;a.push(V)}},{sessions:p,optional_configs:w}=X2(h,t,{model_file_name:s});for(const[v,y]of Object.entries(p))_(v,y);if(w)for(const v of Object.values(w))a.push(v);return a}var En=null;function Y2(e){En=e}function Ml(e){if(e instanceof j)return e;if(e.length===0)throw Error("items must be non-empty");if(Array.isArray(e[0])){if(e.some(t=>t.length!==e[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 j("int64",BigInt64Array.from(e.flat().map(t=>BigInt(t))),[e.length,e[0].length])}else return new j("int64",BigInt64Array.from(e.map(t=>BigInt(t))),[1,e.length])}function tm(e){return new j("bool",[e],[1])}var rm={[q.DecoderOnly]:{can_generate:!0,forward:vr,prepare_inputs:Cn},[q.DecoderOnlyWithoutHead]:{can_generate:!1,forward:vr,prepare_inputs:Cn},[q.Seq2Seq]:{can_generate:!0,forward:Da,prepare_inputs:za},[q.Vision2Seq]:{can_generate:!0,forward:Da,prepare_inputs:za},[q.Musicgen]:{can_generate:!0,forward:Da},[q.EncoderDecoder]:{can_generate:!1,forward:Da},[q.ImageTextToText]:{can_generate:!0,forward:eA,prepare_inputs:Ba},[q.AudioTextToText]:{can_generate:!0,forward:Z2,prepare_inputs:Ba},[q.ImageAudioTextToText]:{can_generate:!0,prepare_inputs:Ba},[q.Phi3V]:{can_generate:!0,prepare_inputs:Ba},[q.MultiModality]:{can_generate:!0},[q.AutoEncoder]:{can_generate:!1,forward:J2},[q.Chatterbox]:{can_generate:!0,forward:Rr},[q.VoxtralRealtime]:{can_generate:!0,prepare_inputs:Cn},default:{can_generate:!1,forward:Rr}};function nm(e,t){var i;let r=wr.get(e),n=!1;const s=(i=t==null?void 0:t.architectures)==null?void 0:i[0];if(s&&s!==e&&(e!=null&&e.endsWith("ForCausalLM"))&&s.endsWith("ForConditionalGeneration")){const l=wr.get(s);l!==void 0&&(r=l,n=!0)}const a=rm[r]??rm.default,o=gr[r]??gr.default;return{typeConfig:{...a,...o},textOnly:n,modelType:r}}var wr=new Map,xl=new Map,An=new Map,I=class extends gt{constructor(t,r,n){super();T(this,"main_input_name","input_ids");T(this,"forward_params",["input_ids","attention_mask"]);T(this,"_return_dict_in_generate_keys",null);this.config=t,this.sessions=r,this.configs=n;const s=An.get(this.constructor),{typeConfig:a}=nm(s,t);this.can_generate=a.can_generate,this._forward=a.forward,this._prepare_inputs_for_generation=a.prepare_inputs,this.can_generate&&this.forward_params.push("past_key_values"),this.custom_config=this.config["transformers.js_config"]??{}}async dispose(){var r;const t=[];for(const n of Object.values(this.sessions))t.push((r=n.release)==null?void 0:r.call(n));return await Promise.all(t)}static async from_pretrained(t,{progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:a=!1,revision:o="main",model_file_name:i=null,subfolder:l="onnx",device:c=null,dtype:d=null,use_external_data_format:h=null,session_options:_={}}={}){const p={progress_callback:r,config:n,cache_dir:s,local_files_only:a,revision:o,model_file_name:i,subfolder:l,device:c,dtype:d,use_external_data_format:h,session_options:_},w=An.get(this);n=p.config=await ps.from_pretrained(t,p);const{typeConfig:v,textOnly:y,modelType:x}=nm(w,n);if(x===void 0){const C=w??(n==null?void 0:n.model_type);C!=="custom"&&he.warn(`Model type for '${C}' not found, assuming encoder-only architecture. Please report this at ${Aa}.`)}if(r&&!(r instanceof la)){const C={};try{const O=await em(t,{config:n,dtype:d,device:c,model_file_name:i});(await Promise.all(O.map(V=>cs(t,V,p)))).forEach((V,G)=>{if(V.exists){const U=O[G]==="config.json";C[O[G]]={loaded:U?V.size??0:0,total:V.size??0}}})}catch(O){he.warn(`Unable to fetch model file metadata for total progress tracking: ${O}`)}Object.keys(C).length>0&&(p.progress_callback=new la(r,C))}const k=v.sessions(n,p,y),A=[T2(t,k,p,v.cache_sessions)];v.optional_configs&&A.push(rA(t,v.optional_configs,p));const S=await Promise.all(A);return new this(n,...S)}async _call(t){return await this.forward(t)}async forward(t){return await this._forward(this,t)}get generation_config(){var t;return((t=this.configs)==null?void 0:t.generation_config)??null}_get_logits_processor(t,r,n=null){const s=new yl;if(t.repetition_penalty!==null&&t.repetition_penalty!==1&&s.push(new D2(t.repetition_penalty)),t.no_repeat_ngram_size!==null&&t.no_repeat_ngram_size>0&&s.push(new N2(t.no_repeat_ngram_size)),t.bad_words_ids!==null&&s.push(new R2(t.bad_words_ids,t.eos_token_id)),t.min_length!==null&&t.eos_token_id!==null&&t.min_length>0&&s.push(new z2(t.min_length,t.eos_token_id)),t.min_new_tokens!==null&&t.eos_token_id!==null&&t.min_new_tokens>0&&s.push(new B2(r,t.min_new_tokens,t.eos_token_id)),t.forced_bos_token_id!==null&&s.push(new F2(t.forced_bos_token_id)),t.forced_eos_token_id!==null&&s.push(new I2(t.max_length,t.forced_eos_token_id)),t.suppress_tokens!==null&&s.push(new L2(t.suppress_tokens)),t.begin_suppress_tokens!==null){const a=r>1||t.forced_bos_token_id===null?r:r+1;s.push(new Xp(t.begin_suppress_tokens,a))}return t.guidance_scale!==null&&t.guidance_scale>1&&s.push(new $2(t.guidance_scale)),t.temperature===0&&t.do_sample&&(he.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`."),t.do_sample=!1),t.do_sample&&t.temperature!==null&&t.temperature!==1&&s.push(new G2(t.temperature)),n!==null&&s.extend(n),s}_prepare_generation_config(t,r,n=Yp){const s={...this.config};for(const o of["decoder","generator","text_config"])o in s&&Object.assign(s,s[o]);const a=new n(s);return Object.assign(a,this.generation_config??{}),t&&Object.assign(a,t),r&&Object.assign(a,rt(r,Object.getOwnPropertyNames(a))),a}_get_stopping_criteria(t,r=null){const n=new Jp;return t.max_length!==null&&n.push(new V2(t.max_length,this.config.max_position_embeddings??null)),t.eos_token_id!==null&&n.push(new U2(t.eos_token_id)),r&&n.extend(r),n}_validate_model_class(){if(!this.can_generate){const t=[En.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,En.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,En.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,En.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES].filter(Boolean),r=An.get(this.constructor),n=new Set,s=this.config.model_type;for(const o of t){const i=o==null?void 0:o.get(s);i&&n.add(i)}let a=`The current model class (${r}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw n.size>0&&(a+=` Please use the following class instead: ${[...n].join(", ")}`),Error(a)}}prepare_inputs_for_generation(...t){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,...t)}_update_model_kwargs_for_generation({generated_input_ids:t,outputs:r,model_inputs:n,is_encoder_decoder:s}){return n.past_key_values=kl(r,n.past_key_values),n.input_ids=new j("int64",t.flat(),[t.length,1]),s?"decoder_attention_mask"in n&&(n.decoder_attention_mask=Re([n.decoder_attention_mask,xt([n.decoder_attention_mask.dims[0],1])],1)):n.attention_mask=Re([n.attention_mask,xt([n.attention_mask.dims[0],1])],1),n.position_ids=null,n}_prepare_model_inputs({inputs:t,bos_token_id:r,model_kwargs:n}){const s=rt(n,this.forward_params),a=this.main_input_name;if(a in s){if(t)throw new Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else s[a]=t;return{inputs_tensor:s[a],model_inputs:s,model_input_name:a}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:t,model_inputs:r,model_input_name:n,generation_config:s}){if(this.sessions.model.inputNames.includes("inputs_embeds")&&!r.inputs_embeds&&"_prepare_inputs_embeds"in this){const{input_ids:o,pixel_values:i,attention_mask:l,...c}=r,d=await this._prepare_inputs_embeds(r);r={...c,...rt(d,["inputs_embeds","attention_mask"])}}let{last_hidden_state:a}=await Rr(this,r);if(s.guidance_scale!==null&&s.guidance_scale>1)a=Re([a,Zi(a,0)],0),"attention_mask"in r&&(r.attention_mask=Re([r.attention_mask,tl(r.attention_mask)],0));else if(r.decoder_input_ids){const o=Ml(r.decoder_input_ids).dims[0];if(o!==a.dims[0]){if(a.dims[0]!==1)throw new Error(`The encoder outputs have a different batch size (${a.dims[0]}) than the decoder inputs (${o}).`);a=Re(Array.from({length:o},()=>a),0)}}return r.encoder_outputs=a,r}_prepare_decoder_input_ids_for_generation({batch_size:t,model_input_name:r,model_kwargs:n,decoder_start_token_id:s,bos_token_id:a,generation_config:o}){let{decoder_input_ids:i,...l}=n;if(!(i instanceof j)){if(i)Array.isArray(i[0])||(i=Array.from({length:t},()=>i));else if(s??(s=a),this.config.model_type==="musicgen")i=Array.from({length:t*this.config.decoder.num_codebooks},()=>[s]);else if(Array.isArray(s)){if(s.length!==t)throw new Error(`\`decoder_start_token_id\` expected to have length ${t} but got ${s.length}`);i=s}else i=Array.from({length:t},()=>[s]);i=Ml(i)}return l.decoder_attention_mask=el(i),{input_ids:i,model_inputs:l}}async generate({inputs:t=null,generation_config:r=null,logits_processor:n=null,stopping_criteria:s=null,streamer:a=null,...o}){this._validate_model_class(),r=this._prepare_generation_config(r,o);let{inputs_tensor:i,model_inputs:l,model_input_name:c}=this._prepare_model_inputs({inputs:t,model_kwargs:o});const d=this.config.is_encoder_decoder;d&&("encoder_outputs"in l||(l=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:i,model_inputs:l,model_input_name:c,generation_config:r})));let h;d?{input_ids:h,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:r.decoder_start_token_id,bos_token_id:r.bos_token_id,generation_config:r}):h=l[c];let _=h.dims.at(-1);r.max_new_tokens!==null&&(r.max_length=_+r.max_new_tokens);const p=this._get_logits_processor(r,_,n),w=this._get_stopping_criteria(r,s),v=l[c].dims.at(0),y=Na.getSampler(r),x=new Array(v).fill(0),k=h.tolist();a&&a.put(k);let A,S={},C={};for(;;){if(l=this.prepare_inputs_for_generation(k,l,r),A=await this.forward(l),r.return_dict_in_generate)if(r.output_attentions){const L=K2(A);for(const ee in L)ee in S||(S[ee]=[]),S[ee].push(L[ee])}else this._return_dict_in_generate_keys&&Object.assign(C,rt(A,this._return_dict_in_generate_keys));const U=A.logits.slice(null,-1,null).to("float32"),J=p(k,U),Q=[];for(let L=0;L<J.dims.at(0);++L){const ee=J[L],H=await y(ee);for(const[ne,Se]of H){const Y=BigInt(ne);x[L]+=Se,k[L].push(Y),Q.push([Y]);break}}if(a&&a.put(Q),w(k).every(L=>L))break;l=this._update_model_kwargs_for_generation({generated_input_ids:Q,outputs:A,model_inputs:l,is_encoder_decoder:d})}a&&a.end();const O=new j("int64",k.flat(),[k.length,k[0].length]),M=kl(A,l.past_key_values),V=new Set(Object.values(M));for(const U of Object.values(A))U.location==="gpu-buffer"&&!V.has(U)&&U.dispose();return"past_key_values"in o||r.return_dict_in_generate||await M.dispose(),r.return_dict_in_generate?{sequences:O,past_key_values:M,...S,...C}:O}async _encode_input(t,r,n){if(!Object.hasOwn(this.sessions,t))throw new Error(`Model does not have a ${t} session.`);const s=this.sessions[t];return(await ye(s,rt(r,s.inputNames)))[n]}async encode_image(t){return this._encode_input("vision_encoder",t,"image_features")}async encode_text(t){return this._encode_input("embed_tokens",t,"inputs_embeds")}async encode_audio(t){return this._encode_input("audio_encoder",t,"audio_features")}};async function Da(e,t){let{encoder_outputs:r,input_ids:n,decoder_input_ids:s,decoder_attention_mask:a,...o}=t;if(!r){const i=rt(t,e.sessions.model.inputNames);r=(await Rr(e,i)).last_hidden_state}return o.input_ids=s,o.encoder_hidden_states=r,e.sessions.decoder_model_merged.inputNames.includes("encoder_attention_mask")&&(o.encoder_attention_mask=t.attention_mask),a&&!o.attention_mask&&(o.attention_mask=a),await vr(e,o,!0)}async function Rr(e,t){const r=e.sessions.model,n=rt(t,r.inputNames);if(r.inputNames.includes("inputs_embeds")&&!n.inputs_embeds){if(!t.input_ids)throw new Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");n.inputs_embeds=await e.encode_text({input_ids:t.input_ids})}if(r.inputNames.includes("token_type_ids")&&!n.token_type_ids){if(!n.input_ids)throw new Error("Both `input_ids` and `token_type_ids` are missing in the model inputs.");n.token_type_ids=tl(n.input_ids)}if(r.inputNames.includes("pixel_mask")&&!n.pixel_mask){if(!n.pixel_values)throw new Error("Both `pixel_values` and `pixel_mask` are missing in the model inputs.");const s=n.pixel_values.dims;n.pixel_mask=xt([s[0],s[2],s[3]])}return await ye(r,n)}async function J2(e,t){const r=await e.encode(t);return await e.decode(r)}function kl(e,t){const r=Object.create(null);for(const n in e)if(n.startsWith("present")){const s=n.replace("present_ssm","past_ssm").replace("present_conv","past_conv").replace("present_recurrent","past_recurrent").replace("present_compressor","past_compressor").replace("present_indexer","past_indexer").replace("present","past_key_values");n.includes("encoder")&&t?r[s]=t[s]:r[s]=e[n]}return t?(t.update(r),t):new bl(r)}function K2(e){const t={};for(const r of["cross_attentions","encoder_attentions","decoder_attentions"])for(const n in e)n.startsWith(r)&&(r in t||(t[r]=[]),t[r].push(e[n]));return t}function sm(e,t){return e.map(r=>typeof r=="number"?r:t[r]??0)}function Tl(e,t,r){var c,d,h,_;if(r&&Object.keys(r).length>0)return Object.assign(t,r),r;const n=e.sessions.decoder_model_merged??e.sessions.model,s=((d=(c=t[e.main_input_name]??t.attention_mask)==null?void 0:c.dims)==null?void 0:d[0])??1,a=La(e.config),o=(_=(h=e.config)==null?void 0:h.normalized_config)==null?void 0:_.num_heads,i={batch_size:s};typeof o=="number"&&(i["batch_size x num_heads"]=s*o);const l=Object.create(null);for(const p of n.inputMetadata){if(!a.has(p.name))continue;const w=sm(p.shape,i),v=w.reduce((k,A)=>k*A,1),y=hs[p.type],x=new j(p.type,new y(v),w);t[p.name]=x,l[p.name]=x}return r?(r.update(l),r):new bl(l)}function ms(e,t,r){if(t.num_logits_to_keep)return;const n=e.sessions.decoder_model_merged??e.sessions.model;n!=null&&n.inputNames.includes("num_logits_to_keep")&&(t.num_logits_to_keep=new j("int64",[r],[]))}async function vr(e,t,r=!1){const n=e.sessions[r?"decoder_model_merged":"model"],{past_key_values:s,...a}=t;if(n.inputNames.includes("use_cache_branch")&&(a.use_cache_branch=tm(s!=null&&Object.keys(s).length>0)),n.inputNames.includes("position_ids")&&a.attention_mask&&!a.position_ids){const i=["paligemma","gemma3_text","gemma3"].includes(e.config.model_type)?1:0;a.position_ids=tA(a,s,i)}ms(e,a,0n),Tl(e,a,s);const o=rt(a,n.inputNames);return await ye(n,o)}async function am(e,{encode_function:t,merge_function:r,modality_input_names:n,modality_output_name:s,input_ids:a=null,attention_mask:o=null,position_ids:i=null,inputs_embeds:l=null,past_key_values:c=null,generation_config:d=null,logits_processor:h=null,num_logits_to_keep:_=null,...p}){if(!l){l=await e.encode_text({input_ids:a,...p});const v=rt(p,n);if(Object.keys(v).length>0){if(a.dims[1]!==1){const y=await t({...v,...p});({inputs_embeds:l,attention_mask:o}=r({[s]:y,inputs_embeds:l,input_ids:a,attention_mask:o}))}else if(c&&a.dims[1]===1){const y=a.dims[1],x=c.get_seq_length();o=Re([xt([a.dims[0],x]),o.slice(null,[o.dims[1]-y,o.dims[1]])],1)}}}if(!i&&["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(e.config.model_type)){const{image_grid_thw:v,video_grid_thw:y}=p;[i]=e.get_rope_index(a,v,y,o)}return await vr(e,{inputs_embeds:l,past_key_values:c,attention_mask:o,position_ids:i,generation_config:d,logits_processor:h,num_logits_to_keep:_},!0)}async function Z2(e,t){return await am(e,{...t,modality_input_names:["audio_values","input_features"],modality_output_name:"audio_features",encode_function:e.encode_audio.bind(e),merge_function:e._merge_input_ids_with_audio_features.bind(e)})}async function eA(e,t){return await am(e,{...t,modality_input_names:["pixel_values"],modality_output_name:"image_features",encode_function:e.encode_image.bind(e),merge_function:e._merge_input_ids_with_image_features.bind(e)})}function om(e,t=0){const[r,n]=e.dims,s=e.data,a=new BigInt64Array(s.length);for(let o=0;o<r;++o){const i=o*n;let l=BigInt(t);for(let c=0;c<n;++c){const d=i+c;s[d]===0n?a[d]=BigInt(1):(a[d]=l,l+=s[d])}}return{data:a,dims:e.dims}}function tA(e,t=null,r=0){const{input_ids:n,inputs_embeds:s,attention_mask:a}=e,{data:o,dims:i}=om(a,r);let l=new j("int64",o,i);if(t){const c=-(n??s).dims.at(1);l=l.slice(null,[c,null])}return l}function Cn(e,t,r,n){const s=r.past_key_values?r.past_key_values.get_seq_length():0;if(ms(e,r,1n),!r.attention_mask){let a;for(const o of["input_ids","inputs_embeds","position_ids"])if(r[o]){a=r[o].dims;break}if(!a)throw new Error("attention_mask is not provided, and unable to infer its shape from model inputs.");r.attention_mask=xt([a[0],s+a[1]])}if(r.past_key_values){const{input_ids:a,attention_mask:o}=r;o&&o.dims[1]>a.dims[1]||s<a.dims[1]&&(r.input_ids=a.slice(null,[s,null]))}return r}function za(e,t,r,n){return r.past_key_values&&(t=t.map(s=>[s.at(-1)])),ms(e,r,1n),{...r,decoder_input_ids:Ml(t)}}function Ba(e,...t){return e.config.is_encoder_decoder?za(e,...t):Cn(e,...t)}function im({modality_token_id:e,inputs_embeds:t,modality_features:r,input_ids:n,attention_mask:s}){const a=n.tolist().map(c=>c.reduce((d,h,_)=>(h==e&&d.push(_),d),[])),o=a.reduce((c,d)=>c+d.length,0),i=r.dims[0];if(o!==i)throw new Error(`Number of tokens and features do not match: tokens: ${o}, features ${i}`);let l=0;for(let c=0;c<a.length;++c){const d=a[c],h=t[c];for(let _=0;_<d.length;++_)h[d[_]].data.set(r[l++].data)}return{inputs_embeds:t,attention_mask:s}}function El({image_token_id:e,inputs_embeds:t,image_features:r,input_ids:n,attention_mask:s}){return im({modality_token_id:e,inputs_embeds:t,modality_features:r,input_ids:n,attention_mask:s})}function lm({audio_token_id:e,inputs_embeds:t,audio_features:r,input_ids:n,attention_mask:s}){return im({modality_token_id:e,inputs_embeds:t,modality_features:r,input_ids:n,attention_mask:s})}async function rA(e,t,r){return Object.fromEntries(await Promise.all(Object.keys(t).map(async n=>{const s=await nr(e,t[n],!1,r);return[n,s]})))}var Al={};as(Al,{ASTForAudioClassification:()=>_A,ASTModel:()=>fA,ASTPreTrainedModel:()=>Fl,AfmoeForCausalLM:()=>uA,AfmoeModel:()=>cA,AfmoePreTrainedModel:()=>Sl,AlbertForMaskedLM:()=>oA,AlbertForQuestionAnswering:()=>aA,AlbertForSequenceClassification:()=>sA,AlbertModel:()=>nA,AlbertPreTrainedModel:()=>gs,ApertusForCausalLM:()=>lA,ApertusModel:()=>iA,ApertusPreTrainedModel:()=>Cl,ArceeForCausalLM:()=>hA,ArceeModel:()=>dA,ArceePreTrainedModel:()=>Pl,BartForConditionalGeneration:()=>mA,BartForSequenceClassification:()=>gA,BartModel:()=>pA,BartPretrainedModel:()=>Ra,BaseModelOutput:()=>A2,BeitForImageClassification:()=>vA,BeitModel:()=>wA,BeitPreTrainedModel:()=>Il,BertForMaskedLM:()=>bA,BertForQuestionAnswering:()=>kA,BertForSequenceClassification:()=>MA,BertForTokenClassification:()=>xA,BertModel:()=>yA,BertPreTrainedModel:()=>Sn,BlenderbotForConditionalGeneration:()=>EA,BlenderbotModel:()=>TA,BlenderbotPreTrainedModel:()=>Ll,BlenderbotSmallForConditionalGeneration:()=>CA,BlenderbotSmallModel:()=>AA,BlenderbotSmallPreTrainedModel:()=>Ol,BloomForCausalLM:()=>PA,BloomModel:()=>SA,BloomPreTrainedModel:()=>Nl,CHMv2ForDepthEstimation:()=>BA,CHMv2PreTrainedModel:()=>fm,CLIPModel:()=>$A,CLIPPreTrainedModel:()=>nn,CLIPSegForImageSegmentation:()=>WA,CLIPSegModel:()=>jA,CLIPSegPreTrainedModel:()=>Dl,CLIPTextModel:()=>GA,CLIPTextModelWithProjection:()=>mm,CLIPVisionModel:()=>VA,CLIPVisionModelWithProjection:()=>UA,CamembertForMaskedLM:()=>IA,CamembertForQuestionAnswering:()=>NA,CamembertForSequenceClassification:()=>LA,CamembertForTokenClassification:()=>OA,CamembertModel:()=>FA,CamembertPreTrainedModel:()=>Pn,CausalLMOutput:()=>Br,CausalLMOutputWithPast:()=>C2,ChatterboxModel:()=>dm,ChatterboxPreTrainedModel:()=>um,ChineseCLIPModel:()=>zA,ChineseCLIPPreTrainedModel:()=>hm,ClapAudioModelWithProjection:()=>pm,ClapModel:()=>RA,ClapPreTrainedModel:()=>$a,ClapTextModelWithProjection:()=>_m,CodeGenForCausalLM:()=>HA,CodeGenModel:()=>qA,CodeGenPreTrainedModel:()=>zl,Cohere2ForCausalLM:()=>JA,Cohere2Model:()=>YA,Cohere2PreTrainedModel:()=>Rl,CohereAsrForConditionalGeneration:()=>ZA,CohereAsrModel:()=>KA,CohereAsrPreTrainedModel:()=>$l,CohereForCausalLM:()=>XA,CohereModel:()=>QA,CoherePreTrainedModel:()=>Bl,ConvBertForMaskedLM:()=>tC,ConvBertForQuestionAnswering:()=>sC,ConvBertForSequenceClassification:()=>rC,ConvBertForTokenClassification:()=>nC,ConvBertModel:()=>eC,ConvBertPreTrainedModel:()=>Fn,ConvNextForImageClassification:()=>oC,ConvNextModel:()=>aC,ConvNextPreTrainedModel:()=>Gl,ConvNextV2ForImageClassification:()=>lC,ConvNextV2Model:()=>iC,ConvNextV2PreTrainedModel:()=>Vl,DFineForObjectDetection:()=>hC,DFineModel:()=>dC,DFinePreTrainedModel:()=>jl,DINOv3ConvNextModel:()=>$C,DINOv3ConvNextPreTrainedModel:()=>Tm,DINOv3ViTModel:()=>GC,DINOv3ViTPreTrainedModel:()=>Em,DPTForDepthEstimation:()=>XC,DPTModel:()=>QC,DPTPreTrainedModel:()=>Jl,DacDecoderModel:()=>ym,DacDecoderOutput:()=>wm,DacEncoderModel:()=>vm,DacEncoderOutput:()=>gm,DacModel:()=>fC,DacPreTrainedModel:()=>Ga,DebertaForMaskedLM:()=>pC,DebertaForQuestionAnswering:()=>wC,DebertaForSequenceClassification:()=>mC,DebertaForTokenClassification:()=>gC,DebertaModel:()=>_C,DebertaPreTrainedModel:()=>In,DebertaV2ForMaskedLM:()=>kC,DebertaV2ForQuestionAnswering:()=>AC,DebertaV2ForSequenceClassification:()=>TC,DebertaV2ForTokenClassification:()=>EC,DebertaV2Model:()=>xC,DebertaV2PreTrainedModel:()=>Ln,DecisionTransformerModel:()=>CC,DecisionTransformerPreTrainedModel:()=>bm,DeepseekV3ForCausalLM:()=>yC,DeepseekV3Model:()=>vC,DeepseekV3PreTrainedModel:()=>Wl,DeepseekV4ForCausalLM:()=>MC,DeepseekV4Model:()=>bC,DeepseekV4PreTrainedModel:()=>ql,DeiTForImageClassification:()=>PC,DeiTModel:()=>SC,DeiTPreTrainedModel:()=>Hl,DepthAnythingForDepthEstimation:()=>FC,DepthAnythingPreTrainedModel:()=>Mm,DepthProForDepthEstimation:()=>IC,DepthProPreTrainedModel:()=>xm,DetrForObjectDetection:()=>OC,DetrForSegmentation:()=>NC,DetrModel:()=>LC,DetrObjectDetectionOutput:()=>Ql,DetrPreTrainedModel:()=>Va,DetrSegmentationOutput:()=>km,Dinov2ForImageClassification:()=>zC,Dinov2Model:()=>DC,Dinov2PreTrainedModel:()=>Xl,Dinov2WithRegistersForImageClassification:()=>RC,Dinov2WithRegistersModel:()=>BC,Dinov2WithRegistersPreTrainedModel:()=>Yl,DistilBertForMaskedLM:()=>qC,DistilBertForQuestionAnswering:()=>WC,DistilBertForSequenceClassification:()=>UC,DistilBertForTokenClassification:()=>jC,DistilBertModel:()=>VC,DistilBertPreTrainedModel:()=>On,DonutSwinModel:()=>HC,DonutSwinPreTrainedModel:()=>Am,EdgeTamModel:()=>fL,EfficientNetForImageClassification:()=>JC,EfficientNetModel:()=>YC,EfficientNetPreTrainedModel:()=>Kl,ElectraForMaskedLM:()=>ZC,ElectraForQuestionAnswering:()=>rS,ElectraForSequenceClassification:()=>eS,ElectraForTokenClassification:()=>tS,ElectraModel:()=>KC,ElectraPreTrainedModel:()=>Nn,EmbeddingGemma2Model:()=>Sm,EmbeddingGemma2PreTrainedModel:()=>Cm,Ernie4_5ForCausalLM:()=>sS,Ernie4_5Model:()=>nS,Ernie4_5PretrainedModel:()=>Zl,EsmForMaskedLM:()=>oS,EsmForSequenceClassification:()=>iS,EsmForTokenClassification:()=>lS,EsmModel:()=>aS,EsmPreTrainedModel:()=>vs,EuroBertForMaskedLM:()=>uS,EuroBertForSequenceClassification:()=>dS,EuroBertForTokenClassification:()=>hS,EuroBertModel:()=>cS,EuroBertPreTrainedModel:()=>ys,ExaoneForCausalLM:()=>_S,ExaoneModel:()=>fS,ExaonePreTrainedModel:()=>ec,FalconForCausalLM:()=>mS,FalconH1ForCausalLM:()=>wS,FalconH1Model:()=>gS,FalconH1PreTrainedModel:()=>rc,FalconModel:()=>pS,FalconPreTrainedModel:()=>tc,FastViTForImageClassification:()=>yS,FastViTModel:()=>vS,FastViTPreTrainedModel:()=>nc,Florence2ForConditionalGeneration:()=>bS,Florence2PreTrainedModel:()=>Pm,GLPNForDepthEstimation:()=>BS,GLPNModel:()=>zS,GLPNPreTrainedModel:()=>dc,GPT2LMHeadModel:()=>QS,GPT2Model:()=>HS,GPT2PreTrainedModel:()=>mc,GPTBigCodeForCausalLM:()=>$S,GPTBigCodeModel:()=>RS,GPTBigCodePreTrainedModel:()=>hc,GPTJForCausalLM:()=>YS,GPTJModel:()=>XS,GPTJPreTrainedModel:()=>gc,GPTNeoForCausalLM:()=>VS,GPTNeoModel:()=>GS,GPTNeoPreTrainedModel:()=>fc,GPTNeoXForCausalLM:()=>jS,GPTNeoXModel:()=>US,GPTNeoXPreTrainedModel:()=>_c,Gemma2ForCausalLM:()=>TS,Gemma2Model:()=>kS,Gemma2PreTrainedModel:()=>ac,Gemma3ForCausalLM:()=>SS,Gemma3ForConditionalGeneration:()=>Lm,Gemma3Model:()=>CS,Gemma3PreTrainedModel:()=>Im,Gemma3nForCausalLM:()=>PS,Gemma3nForConditionalGeneration:()=>Ua,Gemma3nPreTrainedModel:()=>Om,Gemma4ForCausalLM:()=>FS,Gemma4ForConditionalGeneration:()=>oc,GemmaForCausalLM:()=>xS,GemmaModel:()=>MS,GemmaPreTrainedModel:()=>sc,GlmForCausalLM:()=>LS,GlmModel:()=>IS,GlmMoeDsaForCausalLM:()=>NS,GlmMoeDsaModel:()=>OS,GlmMoeDsaPreTrainedModel:()=>lc,GlmOcrForConditionalGeneration:()=>DS,GlmPreTrainedModel:()=>ic,GptOssForCausalLM:()=>qS,GptOssModel:()=>WS,GptOssPreTrainedModel:()=>pc,GraniteForCausalLM:()=>KS,GraniteModel:()=>JS,GraniteMoeHybridForCausalLM:()=>eP,GraniteMoeHybridModel:()=>ZS,GraniteMoeHybridPreTrainedModel:()=>vc,GranitePreTrainedModel:()=>wc,GraniteSpeechForConditionalGeneration:()=>tP,GroundingDinoForObjectDetection:()=>rP,GroundingDinoPreTrainedModel:()=>Rm,GroupViTModel:()=>nP,GroupViTPreTrainedModel:()=>$m,HeliumForCausalLM:()=>aP,HeliumModel:()=>sP,HeliumPreTrainedModel:()=>bc,HieraForImageClassification:()=>iP,HieraModel:()=>oP,HieraPreTrainedModel:()=>Mc,HrmTextForCausalLM:()=>cP,HrmTextModel:()=>lP,HrmTextPreTrainedModel:()=>xc,HubertForCTC:()=>mP,HubertForSequenceClassification:()=>gP,HubertModel:()=>pP,HubertPreTrainedModel:()=>_P,HunYuanDenseV1ForCausalLM:()=>vP,HunYuanDenseV1Model:()=>wP,HunYuanDenseV1PreTrainedModel:()=>kc,IJepaForImageClassification:()=>bP,IJepaModel:()=>yP,IJepaPreTrainedModel:()=>Tc,Idefics3ForConditionalGeneration:()=>Gm,ImageMattingOutput:()=>Qp,JAISLMHeadModel:()=>xP,JAISModel:()=>MP,JAISPreTrainedModel:()=>Ec,JinaCLIPModel:()=>kP,JinaCLIPPreTrainedModel:()=>ja,JinaCLIPTextModel:()=>Vm,JinaCLIPVisionModel:()=>TP,Lfm2ForCausalLM:()=>AP,Lfm2Model:()=>EP,Lfm2MoeForCausalLM:()=>PP,Lfm2MoeModel:()=>SP,Lfm2MoePreTrainedModel:()=>Cc,Lfm2PreTrainedModel:()=>Ac,Lfm2VlForConditionalGeneration:()=>FP,LightOnOcrForConditionalGeneration:()=>CP,LiteWhisperForConditionalGeneration:()=>OO,Llama4ForCausalLM:()=>OP,Llama4PreTrainedModel:()=>Um,LlamaForCausalLM:()=>LP,LlamaModel:()=>IP,LlamaPreTrainedModel:()=>Sc,LlavaForConditionalGeneration:()=>ir,LlavaOnevisionForConditionalGeneration:()=>ir,LlavaPreTrainedModel:()=>Fm,LlavaQwen2ForCausalLM:()=>AS,LongT5ForConditionalGeneration:()=>DP,LongT5Model:()=>NP,LongT5PreTrainedModel:()=>Pc,M2M100ForConditionalGeneration:()=>BP,M2M100Model:()=>zP,M2M100PreTrainedModel:()=>Fc,MBartForCausalLM:()=>qP,MBartForConditionalGeneration:()=>jP,MBartForSequenceClassification:()=>WP,MBartModel:()=>UP,MBartPreTrainedModel:()=>bs,MPNetForMaskedLM:()=>zF,MPNetForQuestionAnswering:()=>$F,MPNetForSequenceClassification:()=>BF,MPNetForTokenClassification:()=>RF,MPNetModel:()=>DF,MPNetPreTrainedModel:()=>Dn,MT5ForConditionalGeneration:()=>jF,MT5Model:()=>UF,MT5PreTrainedModel:()=>jc,MarianMTModel:()=>$P,MarianModel:()=>RP,MarianPreTrainedModel:()=>Ic,MaskFormerForInstanceSegmentation:()=>VP,MaskFormerModel:()=>GP,MaskFormerPreTrainedModel:()=>Lc,MaskedLMOutput:()=>Je,Metric3DForDepthEstimation:()=>HP,Metric3DPreTrainedModel:()=>jm,Metric3Dv2ForDepthEstimation:()=>QP,Metric3Dv2PreTrainedModel:()=>Wm,MgpstrForSceneTextRecognition:()=>XP,MgpstrModelOutput:()=>qm,MgpstrPreTrainedModel:()=>Hm,MimiDecoderModel:()=>Jm,MimiDecoderOutput:()=>Xm,MimiEncoderModel:()=>Ym,MimiEncoderOutput:()=>Qm,MimiModel:()=>YP,MimiPreTrainedModel:()=>Wa,Ministral3ForCausalLM:()=>eF,Ministral3Model:()=>ZP,Ministral3PreTrainedModel:()=>Nc,MinistralForCausalLM:()=>KP,MinistralModel:()=>JP,MinistralPreTrainedModel:()=>Oc,Mistral3ForConditionalGeneration:()=>nF,Mistral4ForCausalLM:()=>aF,Mistral4Model:()=>sF,Mistral4PreTrainedModel:()=>zc,MistralForCausalLM:()=>rF,MistralModel:()=>tF,MistralPreTrainedModel:()=>Dc,MobileBertForMaskedLM:()=>iF,MobileBertForQuestionAnswering:()=>cF,MobileBertForSequenceClassification:()=>lF,MobileBertModel:()=>oF,MobileBertPreTrainedModel:()=>Ms,MobileLLMForCausalLM:()=>dF,MobileLLMModel:()=>uF,MobileLLMPreTrainedModel:()=>Bc,MobileNetV1ForImageClassification:()=>fF,MobileNetV1ForSemanticSegmentation:()=>_F,MobileNetV1Model:()=>hF,MobileNetV1PreTrainedModel:()=>qa,MobileNetV2ForImageClassification:()=>mF,MobileNetV2ForSemanticSegmentation:()=>gF,MobileNetV2Model:()=>pF,MobileNetV2PreTrainedModel:()=>Ha,MobileNetV3ForImageClassification:()=>vF,MobileNetV3ForSemanticSegmentation:()=>yF,MobileNetV3Model:()=>wF,MobileNetV3PreTrainedModel:()=>Qa,MobileNetV4ForImageClassification:()=>MF,MobileNetV4ForSemanticSegmentation:()=>xF,MobileNetV4Model:()=>bF,MobileNetV4PreTrainedModel:()=>Xa,MobileViTForImageClassification:()=>TF,MobileViTModel:()=>kF,MobileViTPreTrainedModel:()=>Rc,MobileViTV2ForImageClassification:()=>AF,MobileViTV2Model:()=>EF,MobileViTV2PreTrainedModel:()=>$c,ModelOutput:()=>je,ModernBertDecoderForCausalLM:()=>LF,ModernBertDecoderModel:()=>IF,ModernBertDecoderPreTrainedModel:()=>Gc,ModernBertForMaskedLM:()=>SF,ModernBertForSequenceClassification:()=>PF,ModernBertForTokenClassification:()=>FF,ModernBertModel:()=>CF,ModernBertPreTrainedModel:()=>xs,Moondream1ForConditionalGeneration:()=>ES,MoonshineForConditionalGeneration:()=>NF,MoonshineModel:()=>OF,MoonshinePreTrainedModel:()=>Vc,MptForCausalLM:()=>VF,MptModel:()=>GF,MptPreTrainedModel:()=>Uc,MultiModalityCausalLM:()=>WF,MultiModalityPreTrainedModel:()=>Km,MusicgenForCausalLM:()=>HF,MusicgenForConditionalGeneration:()=>Zm,MusicgenModel:()=>qF,MusicgenPreTrainedModel:()=>Wc,NanoChatForCausalLM:()=>XF,NanoChatModel:()=>QF,NanoChatPreTrainedModel:()=>qc,NemotronHForCausalLM:()=>JF,NemotronHModel:()=>YF,NemotronHPreTrainedModel:()=>Hc,NeoBertForMaskedLM:()=>ZF,NeoBertForQuestionAnswering:()=>rI,NeoBertForSequenceClassification:()=>eI,NeoBertForTokenClassification:()=>tI,NeoBertModel:()=>KF,NeoBertPreTrainedModel:()=>zn,NomicBertModel:()=>nI,NomicBertPreTrainedModel:()=>eg,OPTForCausalLM:()=>gI,OPTModel:()=>mI,OPTPreTrainedModel:()=>eu,Olmo2ForCausalLM:()=>iI,Olmo2Model:()=>oI,Olmo2PreTrainedModel:()=>Xc,Olmo3ForCausalLM:()=>cI,Olmo3Model:()=>lI,Olmo3PreTrainedModel:()=>Yc,OlmoForCausalLM:()=>aI,OlmoHybridForCausalLM:()=>dI,OlmoHybridModel:()=>uI,OlmoHybridPreTrainedModel:()=>Jc,OlmoModel:()=>sI,OlmoPreTrainedModel:()=>Qc,OpenAIPrivacyFilterForTokenClassification:()=>fI,OpenAIPrivacyFilterModel:()=>hI,OpenAIPrivacyFilterPreTrainedModel:()=>Kc,OpenELMForCausalLM:()=>pI,OpenELMModel:()=>_I,OpenELMPreTrainedModel:()=>Zc,OwlViTForObjectDetection:()=>bI,OwlViTModel:()=>yI,OwlViTPreTrainedModel:()=>ru,Owlv2ForObjectDetection:()=>vI,Owlv2Model:()=>wI,Owlv2PreTrainedModel:()=>tu,PaliGemmaForConditionalGeneration:()=>MI,ParakeetForCTC:()=>xI,ParakeetPreTrainedModel:()=>tg,PatchTSMixerForPrediction:()=>TI,PatchTSMixerModel:()=>kI,PatchTSMixerPreTrainedModel:()=>nu,PatchTSTForPrediction:()=>AI,PatchTSTModel:()=>EI,PatchTSTPreTrainedModel:()=>su,Phi3ForCausalLM:()=>FI,Phi3Model:()=>PI,Phi3PreTrainedModel:()=>ou,Phi3VForCausalLM:()=>ng,Phi3VPreTrainedModel:()=>rg,PhiForCausalLM:()=>SI,PhiModel:()=>CI,PhiPreTrainedModel:()=>au,PreTrainedModel:()=>I,PvtForImageClassification:()=>LI,PvtModel:()=>II,PvtPreTrainedModel:()=>iu,PyAnnoteForAudioFrameClassification:()=>NI,PyAnnoteModel:()=>OI,PyAnnotePreTrainedModel:()=>lu,QuestionAnsweringModelOutput:()=>it,Qwen2ForCausalLM:()=>zI,Qwen2Model:()=>DI,Qwen2MoeForCausalLM:()=>RI,Qwen2MoeModel:()=>BI,Qwen2MoePreTrainedModel:()=>uu,Qwen2PreTrainedModel:()=>cu,Qwen2VLForCausalLM:()=>Dm,Qwen2VLForConditionalGeneration:()=>cc,Qwen2VLPreTrainedModel:()=>Nm,Qwen2_5_VLForCausalLM:()=>zm,Qwen2_5_VLForConditionalGeneration:()=>uc,Qwen3ForCausalLM:()=>GI,Qwen3Model:()=>$I,Qwen3MoeForCausalLM:()=>UI,Qwen3MoeModel:()=>VI,Qwen3MoePreTrainedModel:()=>hu,Qwen3NextForCausalLM:()=>WI,Qwen3NextModel:()=>jI,Qwen3NextPreTrainedModel:()=>fu,Qwen3PreTrainedModel:()=>du,Qwen3VLForCausalLM:()=>sg,Qwen3VLForConditionalGeneration:()=>_u,Qwen3VLMoeForCausalLM:()=>HI,Qwen3VLMoeForConditionalGeneration:()=>qI,Qwen3_5ForCausalLM:()=>ag,Qwen3_5ForConditionalGeneration:()=>pu,Qwen3_5MoeForCausalLM:()=>XI,Qwen3_5MoeForConditionalGeneration:()=>QI,RFDetrForObjectDetection:()=>ZI,RFDetrModel:()=>KI,RFDetrObjectDetectionOutput:()=>og,RFDetrPreTrainedModel:()=>gu,RTDetrForObjectDetection:()=>uC,RTDetrModel:()=>cC,RTDetrObjectDetectionOutput:()=>ws,RTDetrPreTrainedModel:()=>Ul,RTDetrV2ForObjectDetection:()=>dL,RTDetrV2Model:()=>uL,RTDetrV2ObjectDetectionOutput:()=>ig,RTDetrV2PreTrainedModel:()=>wu,ResNetForImageClassification:()=>JI,ResNetModel:()=>YI,ResNetPreTrainedModel:()=>mu,RoFormerForMaskedLM:()=>oL,RoFormerForQuestionAnswering:()=>cL,RoFormerForSequenceClassification:()=>iL,RoFormerForTokenClassification:()=>lL,RoFormerModel:()=>aL,RoFormerPreTrainedModel:()=>Rn,RobertaForMaskedLM:()=>tL,RobertaForQuestionAnswering:()=>sL,RobertaForSequenceClassification:()=>rL,RobertaForTokenClassification:()=>nL,RobertaModel:()=>eL,RobertaPreTrainedModel:()=>Bn,Sam2ImageSegmentationOutput:()=>ug,Sam2Model:()=>vu,Sam2PreTrainedModel:()=>dg,Sam3TrackerModel:()=>_L,SamImageSegmentationOutput:()=>lg,SamModel:()=>hL,SamPreTrainedModel:()=>cg,SapiensForDepthEstimation:()=>mL,SapiensForNormalEstimation:()=>gL,SapiensForSemanticSegmentation:()=>pL,SapiensPreTrainedModel:()=>Ya,SegformerForImageClassification:()=>vL,SegformerForSemanticSegmentation:()=>yL,SegformerModel:()=>wL,SegformerPreTrainedModel:()=>Ja,Seq2SeqLMOutput:()=>S2,SequenceClassifierOutput:()=>le,SiglipModel:()=>bL,SiglipPreTrainedModel:()=>yu,SiglipTextModel:()=>hg,SiglipVisionModel:()=>ML,SmolLM3ForCausalLM:()=>kL,SmolLM3Model:()=>xL,SmolLM3PreTrainedModel:()=>bu,SmolVLMForConditionalGeneration:()=>TL,SnacDecoderModel:()=>_g,SnacEncoderModel:()=>fg,SnacModel:()=>EL,SnacPreTrainedModel:()=>Ka,SolarOpenForCausalLM:()=>CL,SolarOpenModel:()=>AL,SolarOpenPreTrainedModel:()=>Mu,SpeechT5ForSpeechToText:()=>PL,SpeechT5ForTextToSpeech:()=>FL,SpeechT5HifiGan:()=>IL,SpeechT5Model:()=>SL,SpeechT5PreTrainedModel:()=>Za,SqueezeBertForMaskedLM:()=>OL,SqueezeBertForQuestionAnswering:()=>DL,SqueezeBertForSequenceClassification:()=>NL,SqueezeBertModel:()=>LL,SqueezeBertPreTrainedModel:()=>ks,StableLmForCausalLM:()=>BL,StableLmModel:()=>zL,StableLmPreTrainedModel:()=>xu,Starcoder2ForCausalLM:()=>$L,Starcoder2Model:()=>RL,Starcoder2PreTrainedModel:()=>ku,StyleTextToSpeech2Model:()=>GL,StyleTextToSpeech2PreTrainedModel:()=>pg,SupertonicForConditionalGeneration:()=>gg,SupertonicPreTrainedModel:()=>mg,Swin2SRForImageSuperResolution:()=>qL,Swin2SRModel:()=>WL,Swin2SRPreTrainedModel:()=>Tu,SwinForImageClassification:()=>UL,SwinForSemanticSegmentation:()=>jL,SwinModel:()=>VL,SwinPreTrainedModel:()=>eo,T5ForConditionalGeneration:()=>QL,T5Model:()=>HL,T5PreTrainedModel:()=>Eu,TableTransformerForObjectDetection:()=>YL,TableTransformerModel:()=>XL,TableTransformerObjectDetectionOutput:()=>wg,TableTransformerPreTrainedModel:()=>Au,TokenClassifierOutput:()=>Xe,TrOCRForCausalLM:()=>JL,TrOCRPreTrainedModel:()=>vg,UltravoxModel:()=>yc,UltravoxPreTrainedModel:()=>Bm,UniSpeechForCTC:()=>ZL,UniSpeechForSequenceClassification:()=>eO,UniSpeechModel:()=>KL,UniSpeechPreTrainedModel:()=>to,UniSpeechSatForAudioFrameClassification:()=>sO,UniSpeechSatForCTC:()=>rO,UniSpeechSatForSequenceClassification:()=>nO,UniSpeechSatModel:()=>tO,UniSpeechSatPreTrainedModel:()=>Ts,VaultGemmaForCausalLM:()=>oO,VaultGemmaModel:()=>aO,VaultGemmaPreTrainedModel:()=>Cu,ViTForImageClassification:()=>cO,ViTMAEModel:()=>uO,ViTMAEPreTrainedModel:()=>yg,ViTMSNForImageClassification:()=>hO,ViTMSNModel:()=>dO,ViTMSNPreTrainedModel:()=>Pu,ViTModel:()=>lO,ViTPreTrainedModel:()=>Su,VisionEncoderDecoderModel:()=>iO,VitMatteForImageMatting:()=>fO,VitMattePreTrainedModel:()=>bg,VitPoseForPoseEstimation:()=>_O,VitPosePreTrainedModel:()=>Mg,VitsModel:()=>pO,VitsModelOutput:()=>xg,VitsPreTrainedModel:()=>kg,VoxtralForConditionalGeneration:()=>mO,VoxtralRealtimeForConditionalGeneration:()=>Ag,VoxtralRealtimePreTrainedModel:()=>Eg,Wav2Vec2BertForCTC:()=>kO,Wav2Vec2BertForSequenceClassification:()=>TO,Wav2Vec2BertModel:()=>xO,Wav2Vec2BertPreTrainedModel:()=>ro,Wav2Vec2ForAudioFrameClassification:()=>fP,Wav2Vec2ForCTC:()=>dP,Wav2Vec2ForSequenceClassification:()=>hP,Wav2Vec2Model:()=>uP,Wav2Vec2PreTrainedModel:()=>$r,WavLMForAudioFrameClassification:()=>PO,WavLMForCTC:()=>AO,WavLMForSequenceClassification:()=>CO,WavLMForXVector:()=>SO,WavLMModel:()=>EO,WavLMPreTrainedModel:()=>$n,WeSpeakerResNetModel:()=>FO,WeSpeakerResNetPreTrainedModel:()=>Sg,WhisperForConditionalGeneration:()=>Pg,WhisperModel:()=>LO,WhisperPreTrainedModel:()=>Iu,XLMForQuestionAnswering:()=>RO,XLMForSequenceClassification:()=>zO,XLMForTokenClassification:()=>BO,XLMModel:()=>NO,XLMPreTrainedModel:()=>Gn,XLMRobertaForMaskedLM:()=>GO,XLMRobertaForQuestionAnswering:()=>jO,XLMRobertaForSequenceClassification:()=>VO,XLMRobertaForTokenClassification:()=>UO,XLMRobertaModel:()=>$O,XLMRobertaPreTrainedModel:()=>Vn,XLMWithLMHeadModel:()=>DO,XVectorOutput:()=>Cg,YolosForObjectDetection:()=>qO,YolosModel:()=>WO,YolosObjectDetectionOutput:()=>Fg,YolosPreTrainedModel:()=>Lu,YoutuForCausalLM:()=>QO,YoutuModel:()=>HO,YoutuPreTrainedModel:()=>Ou,ZayaForCausalLM:()=>YO,ZayaModel:()=>XO,ZayaPreTrainedModel:()=>Nu});var gs=class extends I{},nA=class extends gs{},sA=class extends gs{async _call(e){return new le(await super._call(e))}},aA=class extends gs{async _call(e){return new it(await super._call(e))}},oA=class extends gs{async _call(e){return new Je(await super._call(e))}},Cl=class extends I{},iA=class extends Cl{},lA=class extends Cl{},Sl=class extends I{},cA=class extends Sl{},uA=class extends Sl{},Pl=class extends I{},dA=class extends Pl{},hA=class extends Pl{},Fl=class extends I{},fA=class extends Fl{},_A=class extends Fl{},Ra=class extends I{},pA=class extends Ra{},mA=class extends Ra{},gA=class extends Ra{async _call(e){return new le(await super._call(e))}},Il=class extends I{},wA=class extends Il{},vA=class extends Il{async _call(e){return new le(await super._call(e))}},Sn=class extends I{},yA=class extends Sn{},bA=class extends Sn{async _call(e){return new Je(await super._call(e))}},MA=class extends Sn{async _call(e){return new le(await super._call(e))}},xA=class extends Sn{async _call(e){return new Xe(await super._call(e))}},kA=class extends Sn{async _call(e){return new it(await super._call(e))}},Ll=class extends I{},TA=class extends Ll{},EA=class extends Ll{},Ol=class extends I{},AA=class extends Ol{},CA=class extends Ol{},Nl=class extends I{},SA=class extends Nl{},PA=class extends Nl{},Pn=class extends I{},FA=class extends Pn{},IA=class extends Pn{async _call(e){return new Je(await super._call(e))}},LA=class extends Pn{async _call(e){return new le(await super._call(e))}},OA=class extends Pn{async _call(e){return new Xe(await super._call(e))}},NA=class extends Pn{async _call(e){return new it(await super._call(e))}},DA=4299n,cm=6561n,um=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","inputs_embeds","attention_mask","position_ids","audio_values","exaggeration","audio_features","audio_tokens","speaker_embeddings","speaker_features","past_key_values"]);T(this,"main_input_name","input_ids");T(this,"_return_dict_in_generate_keys",["audio_tokens","speaker_embeddings","speaker_features"])}},dm=class extends um{async encode_speech(e){return ye(this.sessions.speech_encoder,{audio_values:e})}async forward({input_ids:e=null,attention_mask:t=null,audio_values:r=null,exaggeration:n=null,position_ids:s=null,inputs_embeds:a=null,past_key_values:o=null,generation_config:i=null,logits_processor:l=null,num_logits_to_keep:c=null,audio_features:d=null,audio_tokens:h=null,speaker_embeddings:_=null,speaker_features:p=null,...w}){let v;if(!a){const x=this.sessions.embed_tokens.inputNames,k={input_ids:e};if(x.includes("exaggeration")){if(!(n instanceof j)){const A=e.dims[0];if(n==null)n=dt([A],.5);else if(typeof n=="number")n=dt([A],n);else if(Array.isArray(n))n=new j("float32",n,[A]);else throw new Error("Unsupported type for `exaggeration` input")}k.exaggeration=n}if(x.includes("position_ids")&&(k.position_ids=s),{inputs_embeds:a}=await ye(this.sessions.embed_tokens,k),d&&h&&_&&p&&(v={audio_features:d,audio_tokens:h,speaker_embeddings:_,speaker_features:p}),v||r)v??(v=await this.encode_speech(r)),a=Re([v.audio_features,a],1),t=xt([a.dims[0],a.dims[1]]);else{const A=a.dims[1];if(!o||A!==1)throw new Error("Incorrect state encountered during generation.");const S=o.get_seq_length();t=xt([a.dims[0],S+A])}}return{...await vr(this,{inputs_embeds:a,past_key_values:o,attention_mask:t,generation_config:i,logits_processor:l,num_logits_to_keep:c},!1),...v}}prepare_inputs_for_generation(e,t,r){if(!t.position_ids&&this.sessions.embed_tokens.inputNames.includes("position_ids"))if(t.input_ids.dims[1]===1){const n=Array.from({length:e.length},(s,a)=>e[a].length-e[a].findLastIndex(o=>o==cm)-1);t.position_ids=new j("int64",n,[e.length,1])}else{const s=t.input_ids.tolist().map(a=>{let o=0;return a.map(i=>i>=cm?0:o++)});t.position_ids=new j("int64",s.flat(),t.input_ids.dims)}return t.input_ids.dims[1]===1&&(delete t.audio_values,delete t.audio_features,delete t.audio_tokens,delete t.speaker_embeddings,delete t.speaker_features),Cn(this,e,t)}async generate(e){const t=e.past_key_values,{sequences:r,audio_tokens:n,speaker_embeddings:s,speaker_features:a,past_key_values:o}=await super.generate({...e,return_dict_in_generate:!0});try{const i=r.slice(null,[e.input_ids.dims[1],-1]),l=dt([i.dims[0],3],DA),c=Re([n,i,l],1),{waveform:d}=await ye(this.sessions.conditional_decoder,{speech_tokens:c,speaker_features:a,speaker_embeddings:s});return d}finally{o!==t&&await(o==null?void 0:o.dispose())}}},hm=class extends I{},zA=class extends hm{},fm=class extends I{},BA=class extends fm{},$a=class extends I{},RA=class extends $a{},_m=class extends $a{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},pm=class extends $a{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"audio_model"})}},nn=class extends I{},$A=class extends nn{},GA=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},mm=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},VA=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"vision_model"})}},UA=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"vision_model"})}},Dl=class extends I{},jA=class extends Dl{},WA=class extends Dl{},zl=class extends I{},qA=class extends zl{},HA=class extends zl{},Bl=class extends I{},QA=class extends Bl{},XA=class extends Bl{},Rl=class extends I{},YA=class extends Rl{},JA=class extends Rl{},$l=class extends I{constructor(){super(...arguments);T(this,"requires_attention_mask",!1);T(this,"main_input_name","input_features");T(this,"forward_params",["input_features","decoder_input_ids","decoder_attention_mask","past_key_values"])}},KA=class extends $l{},ZA=class extends $l{},Fn=class extends I{},eC=class extends Fn{},tC=class extends Fn{async _call(e){return new Je(await super._call(e))}},rC=class extends Fn{async _call(e){return new le(await super._call(e))}},nC=class extends Fn{async _call(e){return new Xe(await super._call(e))}},sC=class extends Fn{async _call(e){return new it(await super._call(e))}},Gl=class extends I{},aC=class extends Gl{},oC=class extends Gl{async _call(e){return new le(await super._call(e))}},Vl=class extends I{},iC=class extends Vl{},lC=class extends Vl{async _call(e){return new le(await super._call(e))}},Ul=class extends I{},cC=class extends Ul{},uC=class extends Ul{async _call(e){return new ws(await super._call(e))}},ws=class extends je{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}},jl=class extends I{},dC=class extends jl{},hC=class extends jl{async _call(e){return new ws(await super._call(e))}},gm=class extends je{constructor({audio_codes:e}){super(),this.audio_codes=e}},wm=class extends je{constructor({audio_values:e}){super(),this.audio_values=e}},Ga=class extends I{constructor(){super(...arguments);T(this,"main_input_name","input_values");T(this,"forward_params",["input_values"])}},fC=class extends Ga{async encode(e){return new gm(await ye(this.sessions.encoder_model,e))}async decode(e){return new wm(await ye(this.sessions.decoder_model,e))}},vm=class extends Ga{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"encoder_model"})}},ym=class extends Ga{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"decoder_model"})}},In=class extends I{},_C=class extends In{},pC=class extends In{async _call(e){return new Je(await super._call(e))}},mC=class extends In{async _call(e){return new le(await super._call(e))}},gC=class extends In{async _call(e){return new Xe(await super._call(e))}},wC=class extends In{async _call(e){return new it(await super._call(e))}},Wl=class extends I{},vC=class extends Wl{},yC=class extends Wl{},ql=class extends I{},bC=class extends ql{},MC=class extends ql{},Ln=class extends I{},xC=class extends Ln{},kC=class extends Ln{async _call(e){return new Je(await super._call(e))}},TC=class extends Ln{async _call(e){return new le(await super._call(e))}},EC=class extends Ln{async _call(e){return new Xe(await super._call(e))}},AC=class extends Ln{async _call(e){return new it(await super._call(e))}},bm=class extends I{},CC=class extends bm{},Hl=class extends I{},SC=class extends Hl{},PC=class extends Hl{async _call(e){return new le(await super._call(e))}},Mm=class extends I{},FC=class extends Mm{},xm=class extends I{},IC=class extends xm{},Va=class extends I{},LC=class extends Va{},OC=class extends Va{async _call(e){return new Ql(await super._call(e))}},NC=class extends Va{async _call(e){return new km(await super._call(e))}},Ql=class extends je{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}},km=class extends je{constructor({logits:e,pred_boxes:t,pred_masks:r}){super(),this.logits=e,this.pred_boxes=t,this.pred_masks=r}},Xl=class extends I{},DC=class extends Xl{},zC=class extends Xl{async _call(e){return new le(await super._call(e))}},Yl=class extends I{},BC=class extends Yl{},RC=class extends Yl{async _call(e){return new le(await super._call(e))}},Tm=class extends I{},$C=class extends Tm{},Em=class extends I{},GC=class extends Em{},On=class extends I{},VC=class extends On{},UC=class extends On{async _call(e){return new le(await super._call(e))}},jC=class extends On{async _call(e){return new Xe(await super._call(e))}},WC=class extends On{async _call(e){return new it(await super._call(e))}},qC=class extends On{async _call(e){return new Je(await super._call(e))}},Am=class extends I{},HC=class extends Am{},Jl=class extends I{},QC=class extends Jl{},XC=class extends Jl{},Kl=class extends I{},YC=class extends Kl{},JC=class extends Kl{async _call(e){return new le(await super._call(e))}},Nn=class extends I{},KC=class extends Nn{},ZC=class extends Nn{async _call(e){return new Je(await super._call(e))}},eS=class extends Nn{async _call(e){return new le(await super._call(e))}},tS=class extends Nn{async _call(e){return new Xe(await super._call(e))}},rS=class extends Nn{async _call(e){return new it(await super._call(e))}},Cm=class extends I{},Sm=class extends Cm{async forward({input_ids:e,attention_mask:t,pixel_values:r=null,image_position_ids:n=null,pixel_values_videos:s=null,video_position_ids:a=null,input_features:o=null,input_features_mask:i=null}){const l={image_features:r&&await this.encode_image({pixel_values:r,pixel_position_ids:n}),video_features:s&&await this.encode_image({pixel_values:s,pixel_position_ids:a}),audio_features:o&&await this.encode_audio({input_features:o,input_features_mask:i})},{image_token_id:c,video_token_id:d,audio_token_id:h,text_config:_}=this.config,p={image:c,video:d,audio:h};for(const[w,v]of Object.entries(p)){const y=`${w}_features`;l[y]??(l[y]=new j("float32",new Float32Array(0),[0,_.hidden_size]));let x=0;for(const k of e.data)Number(k)===v&&++x;if(x!==l[y].dims[0])throw new Error(`The number of ${w} tokens (${x}) and ${w} features (${l[y].dims[0]}) do not match.`)}return await ye(this.sessions.model,{input_ids:e,attention_mask:t,...l})}},Zl=class extends I{},nS=class extends Zl{},sS=class extends Zl{},vs=class extends I{},aS=class extends vs{},oS=class extends vs{async _call(e){return new Je(await super._call(e))}},iS=class extends vs{async _call(e){return new le(await super._call(e))}},lS=class extends vs{async _call(e){return new Xe(await super._call(e))}},ys=class extends I{},cS=class extends ys{},uS=class extends ys{async _call(e){return new Je(await super._call(e))}},dS=class extends ys{async _call(e){return new le(await super._call(e))}},hS=class extends ys{async _call(e){return new Xe(await super._call(e))}},ec=class extends I{},fS=class extends ec{},_S=class extends ec{},tc=class extends I{},pS=class extends tc{},mS=class extends tc{},rc=class extends I{},gS=class extends rc{},wS=class extends rc{},nc=class extends I{},vS=class extends nc{},yS=class extends nc{async _call(e){return new le(await super._call(e))}},Pm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","inputs_embeds","attention_mask","pixel_values","encoder_outputs","decoder_input_ids","decoder_inputs_embeds","decoder_attention_mask","past_key_values"]);T(this,"main_input_name","inputs_embeds")}},bS=class extends Pm{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:t,input_ids:r,attention_mask:n}){return{inputs_embeds:Re([t,e],1),attention_mask:Re([xt(t.dims.slice(0,2)),n],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:r,attention_mask:n}){if(!e&&!t)throw new Error("Either `input_ids` or `pixel_values` should be provided.");let s,a;return e&&(s=await this.encode_text({input_ids:e})),t&&(a=await this.encode_image({pixel_values:t})),s&&a?{inputs_embeds:r,attention_mask:n}=this._merge_input_ids_with_image_features({inputs_embeds:s,image_features:a,input_ids:e,attention_mask:n}):r=s||a,{inputs_embeds:r,attention_mask:n}}async forward({input_ids:e,pixel_values:t,attention_mask:r,decoder_input_ids:n,decoder_attention_mask:s,encoder_outputs:a,past_key_values:o,inputs_embeds:i,decoder_inputs_embeds:l,num_logits_to_keep:c=null}){if(i||({inputs_embeds:i,attention_mask:r}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:i,attention_mask:r})),!a){let{last_hidden_state:h}=await Rr(this,{inputs_embeds:i,attention_mask:r});a=h}if(!l){if(!n)throw new Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");l=await this.encode_text({input_ids:n})}return await vr(this,{inputs_embeds:l,attention_mask:s,encoder_attention_mask:r,encoder_hidden_states:a,past_key_values:o,num_logits_to_keep:c},!0)}},sc=class extends I{},MS=class extends sc{},xS=class extends sc{},ac=class extends I{},kS=class extends ac{},TS=class extends ac{},Fm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","pixel_values","position_ids","past_key_values"])}},ir=class extends Fm{_merge_input_ids_with_image_features(e){const t=e.image_features.dims.at(-1),r=e.image_features.view(-1,t);return El({image_token_id:this.config.image_token_index??this.config.image_token_id,...e,image_features:r})}},ES=class extends ir{},AS=class extends ir{},Im=class extends I{},CS=class extends Im{},Lm=class extends ir{},SS=class extends Lm{},Om=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","inputs_embeds","per_layer_inputs","position_ids","pixel_values","input_features","input_features_mask","past_key_values"])}},Ua=class extends Om{async forward({input_ids:e=null,attention_mask:t=null,pixel_values:r=null,input_features:n=null,input_features_mask:s=null,position_ids:a=null,inputs_embeds:o=null,per_layer_inputs:i=null,past_key_values:l=null,generation_config:c=null,logits_processor:d=null,num_logits_to_keep:h=null,..._}){if((!o||!i)&&({inputs_embeds:o,per_layer_inputs:i}=await ye(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(r){const{image_features:w}=await this._encode_vision({pixel_values:r,..._});({inputs_embeds:o,attention_mask:t}=this._merge_input_ids_with_image_features({image_features:w,inputs_embeds:o,input_ids:e,attention_mask:t}))}if(n){const{audio_features:w}=await ye(this.sessions.audio_encoder,{input_features:n,input_features_mask:s});({inputs_embeds:o,attention_mask:t}=this._merge_input_ids_with_audio_features({audio_features:w,inputs_embeds:o,input_ids:e,attention_mask:t}))}}return await vr(this,{inputs_embeds:o,per_layer_inputs:i,past_key_values:l,attention_mask:t,position_ids:a,generation_config:c,logits_processor:d,num_logits_to_keep:h},!0)}_encode_vision(e){return ye(this.sessions.vision_encoder,{pixel_values:e.pixel_values})}_merge_input_ids_with_image_features(e){const t=e.image_features.dims.at(-1),r=e.image_features.view(-1,t);return El({image_token_id:this.config.image_token_id,...e,image_features:r})}_merge_input_ids_with_audio_features(e){const t=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,t);return lm({audio_token_id:this.config.audio_token_id,...e,audio_features:r})}},PS=class extends Ua{},oc=class extends Ua{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","inputs_embeds","per_layer_inputs","position_ids","pixel_values","image_position_ids","input_features","input_features_mask","past_key_values"])}_encode_vision(t){return ye(this.sessions.vision_encoder,{pixel_values:t.pixel_values,pixel_position_ids:t.image_position_ids})}},FS=class extends oc{},ic=class extends I{},IS=class extends ic{},LS=class extends ic{},lc=class extends I{},OS=class extends lc{},NS=class extends lc{},Nm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","position_ids","past_key_values","pixel_values","image_grid_thw"])}},cc=class extends Nm{constructor(){super(...arguments);T(this,"image_grid_thw_name","grid_thw")}_get_text_only_rope_index(t,r){if(r){const{data:n,dims:s}=om(r),a=BigInt64Array.from({length:3*n.length},(i,l)=>n[l%n.length]),o=Array.from({length:s[0]},(i,l)=>Qe(n.subarray(s[1]*l,s[1]*(l+1)))[0]+1n+BigInt(s[1]));return[new j("int64",a,[3,...s]),new j("int64",o,[o.length,1])]}else{const[n,s]=t.dims,a=BigInt64Array.from({length:3*n*s},(o,i)=>BigInt(Math.floor(i%s/n)));return[new j("int64",a,[3,...t.dims]),W_([n,1])]}}_reorder_and_write_positions(t,r,n,s){const a=t.reduce((c,d)=>c+d.length,0),o=new Array(a);let i=0;for(let c=0;c<3;++c)for(const d of t){const h=d.length/3;for(let _=c*h;_<(c+1)*h;++_)o[i++]=d[_]}let l=0;for(let c=0;c<r.length;++c)if(r[c]==1){for(let d=0;d<3;++d)n[d][s][c]=o[d*a/3+l];++l}return o}_get_multimodal_rope_positions({filtered_ids:t,image_grid_thw_list:r,video_grid_thw_list:n,spatial_merge_size:s,state:a}){const{image_token_id:o,video_token_id:i,vision_start_token_id:l}=this.config,c=t,h=c.reduce((k,A,S)=>(A==l&&k.push(S),k),[]).map(k=>c[k+1]),_=h.filter(k=>k==o).length,p=h.filter(k=>k==i).length,w=[];let v=0,y=_,x=p;for(let k=0;k<h.length;++k){const A=c.findIndex((D,R)=>R>v&&D==o),S=c.findIndex((D,R)=>R>v&&D==i),C=y>0&&A!==-1?A:c.length+1,O=x>0&&S!==-1?S:c.length+1;let M,V,G,U;C<O?([V,G,U]=r[a.image_index],++a.image_index,--y,M=C):([V,G,U]=n[a.video_index],++a.video_index,--x,M=O);const[J,Q,B]=[Number(V),Math.floor(Number(G)/s),Math.floor(Number(U)/s)],L=M-v,ee=w.length>0?Qe(w.at(-1))[0]+1:0;w.push(Array.from({length:3*L},(D,R)=>ee+R%L));const H=L+ee,ne=J*Q*B,Se=Array.from({length:ne},(D,R)=>H+Math.floor(R/(Q*B))),Y=Array.from({length:ne},(D,R)=>H+Math.floor(R/B)%Q),N=Array.from({length:ne},(D,R)=>H+R%B);w.push([Se,Y,N].flat()),v=M+ne}if(v<c.length){const k=w.length>0?Qe(w.at(-1))[0]+1:0,A=c.length-v;w.push(Array.from({length:3*A},(S,C)=>k+C%A))}return w}get_rope_index(t,r,n,s){const{vision_config:a}=this.config,o=a.spatial_merge_size??2;if(r||n){const i=t.tolist();s||(s=el(t));const l=s.tolist(),c=Array.from({length:3},()=>Array.from({length:t.dims[0]},()=>Array.from({length:t.dims[1]},()=>0))),d=r?r.tolist():[],h=n?n.tolist():[],_={image_index:0,video_index:0},p=[];for(let w=0;w<i.length;++w){const v=i[w].filter((k,A)=>l[w][A]==1),y=this._get_multimodal_rope_positions({filtered_ids:v,image_grid_thw_list:d,video_grid_thw_list:h,spatial_merge_size:o,state:_}),x=this._reorder_and_write_positions(y,l[w],c,w);p.push(Qe(x)[0]+1-i[w].length)}return[new j("int64",c.flat(1/0),[3,t.dims[0],t.dims[1]]),new j("int64",p,[p.length,1])]}else return this._get_text_only_rope_index(t,s)}async encode_image({pixel_values:t,image_grid_thw:r}){return(await ye(this.sessions.vision_encoder,{pixel_values:t,[this.image_grid_thw_name]:r})).image_features}_merge_input_ids_with_image_features(t){return El({image_token_id:this.config.image_token_id,...t})}prepare_inputs_for_generation(t,r,n){if(ms(this,r,1n),!r.attention_mask||r.position_ids||!(this.sessions.decoder_model_merged??this.sessions.model).inputNames.includes("position_ids"))return r;if(!r.past_key_values)[r.position_ids,r.rope_deltas]=this.get_rope_index(r.input_ids,r.image_grid_thw,r.video_grid_thw,r.attention_mask);else{r.pixel_values=null;const a=r.past_key_values.get_seq_length();if(a<r.input_ids.dims[1]){const[o,i]=this.get_rope_index(r.input_ids,r.image_grid_thw,r.video_grid_thw,r.attention_mask);r.rope_deltas=i,r.position_ids=o.slice(null,null,[a,null]),r.input_ids=r.input_ids.slice(null,[a,null])}else{r.rope_deltas||([,r.rope_deltas]=this.get_rope_index(r.input_ids,r.image_grid_thw,r.video_grid_thw,r.attention_mask));const o=BigInt(a),i=r.rope_deltas.map(l=>o+l);r.position_ids=pr([i,i,i],0)}}return r}},Dm=class extends cc{},uc=class extends cc{constructor(){super(...arguments);T(this,"image_grid_thw_name","image_grid_thw")}},zm=class extends Dm{constructor(){super(...arguments);T(this,"image_grid_thw_name","image_grid_thw")}},DS=class extends uc{get_vision_position_ids(e,t,r,n){const s=Math.floor(t[0]/r),a=Math.floor(t[1]/n),o=Math.floor(t[2]/n),i=a*o*s,l=Array.from({length:i},()=>e),c=Array.from({length:i},(h,_)=>e+Math.floor(_/(o*s))),d=Array.from({length:i},(h,_)=>e+_%o);return[...l,...c,...d]}_get_multimodal_rope_positions({filtered_ids:e,image_grid_thw_list:t,video_grid_thw_list:r,spatial_merge_size:n,state:s}){const{image_token_id:a}=this.config,o=[];let i=0,l=e[0]==a?1:0;for(let h=1;h<=e.length;++h){const _=h<e.length?e[h]==a?1:0:-1;_!==l&&(o.push([l,i,h]),i=h,l=_)}let c=0;const d=[];for(const[h,_,p]of o)if(h===0){const w=p-_;d.push(Array.from({length:3*w},(v,y)=>c+y%w)),c+=w}else{const w=t[s.image_index++].map(Number),v=w[0];d.push(this.get_vision_position_ids(c,w,v,n)),c+=Math.max(w[1],w[2])/n}return d}},dc=class extends I{},zS=class extends dc{},BS=class extends dc{},hc=class extends I{},RS=class extends hc{},$S=class extends hc{},fc=class extends I{},GS=class extends fc{},VS=class extends fc{},_c=class extends I{},US=class extends _c{},jS=class extends _c{},pc=class extends I{},WS=class extends pc{},qS=class extends pc{},mc=class extends I{},HS=class extends mc{},QS=class extends mc{},gc=class extends I{},XS=class extends gc{},YS=class extends gc{},wc=class extends I{},JS=class extends wc{},KS=class extends wc{},vc=class extends I{},ZS=class extends vc{},eP=class extends vc{},Bm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","position_ids","audio_values","past_key_values"])}},yc=class extends Bm{_merge_input_ids_with_audio_features(e){const t=e.audio_features.dims.at(-1),r=e.audio_features.view(-1,t);return lm({audio_token_id:this.config.ignore_index??this.config.audio_token_id??this.config.audio_token_index,...e,audio_features:r})}},tP=class extends yc{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","input_features","past_key_values"])}},Rm=class extends I{},rP=class extends Rm{},$m=class extends I{},nP=class extends $m{},bc=class extends I{},sP=class extends bc{},aP=class extends bc{},Mc=class extends I{},oP=class extends Mc{},iP=class extends Mc{async _call(e){return new le(await super._call(e))}},xc=class extends I{},lP=class extends xc{},cP=class extends xc{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","token_type_ids","past_key_values"])}prepare_inputs_for_generation(t,r,n){const s=Cn(this,t,r);return s.token_type_ids=(s.past_key_values?tl:el)(s.input_ids),s}},$r=class extends I{},uP=class extends $r{},dP=class extends $r{async _call(e){return new Br(await super._call(e))}},hP=class extends $r{async _call(e){return new le(await super._call(e))}},fP=class extends $r{async _call(e){return new Xe(await super._call(e))}},_P=class extends I{},pP=class extends $r{},mP=class extends $r{async _call(e){return new Br(await super._call(e))}},gP=class extends $r{async _call(e){return new le(await super._call(e))}},kc=class extends I{},wP=class extends kc{},vP=class extends kc{},Gm=class extends ir{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","pixel_values","pixel_attention_mask","position_ids","past_key_values"])}},Tc=class extends I{},yP=class extends Tc{},bP=class extends Tc{async _call(e){return new le(await super._call(e))}},Ec=class extends I{},MP=class extends Ec{},xP=class extends Ec{},ja=class extends I{},kP=class extends ja{async forward(e){const t=!e.input_ids,r=!e.pixel_values;if(t&&r)throw new Error("Either `input_ids` or `pixel_values` should be provided.");if(t&&(e.input_ids=xt([e.pixel_values.dims[0],1])),r){const{image_size:l}=this.config.vision_config;e.pixel_values=dt([0,3,l,l],0)}const{text_embeddings:n,image_embeddings:s,l2norm_text_embeddings:a,l2norm_image_embeddings:o}=await super.forward(e),i={};return t||(i.text_embeddings=n,i.l2norm_text_embeddings=a),r||(i.image_embeddings=s,i.l2norm_image_embeddings=o),i}},Vm=class extends ja{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},TP=class extends ja{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"vision_model"})}},Ac=class extends I{},EP=class extends Ac{},AP=class extends Ac{},CP=class extends ir{},Cc=class extends I{},SP=class extends Cc{},PP=class extends Cc{},FP=class extends ir{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","pixel_values","pixel_attention_mask","spatial_shapes","position_ids","past_key_values"])}},Sc=class extends I{},IP=class extends Sc{},LP=class extends Sc{},Um=class extends I{},OP=class extends Um{},Pc=class extends I{},NP=class extends Pc{},DP=class extends Pc{},Fc=class extends I{},zP=class extends Fc{},BP=class extends Fc{},Ic=class extends I{},RP=class extends Ic{},$P=class extends Ic{},Lc=class extends I{},GP=class extends Lc{},VP=class extends Lc{},bs=class extends I{},UP=class extends bs{},jP=class extends bs{},WP=class extends bs{async _call(e){return new le(await super._call(e))}},qP=class extends bs{},jm=class extends I{},HP=class extends jm{},Wm=class extends I{},QP=class extends Wm{},qm=class extends je{constructor({char_logits:e,bpe_logits:t,wp_logits:r}){super(),this.char_logits=e,this.bpe_logits=t,this.wp_logits=r}get logits(){return[this.char_logits,this.bpe_logits,this.wp_logits]}},Hm=class extends I{},XP=class extends Hm{async _call(e){return new qm(await super._call(e))}},Qm=class extends je{constructor({audio_codes:e}){super(),this.audio_codes=e}},Xm=class extends je{constructor({audio_values:e}){super(),this.audio_values=e}},Wa=class extends I{constructor(){super(...arguments);T(this,"main_input_name","input_values");T(this,"forward_params",["input_values"])}},YP=class extends Wa{async encode(e){return new Qm(await ye(this.sessions.encoder_model,e))}async decode(e){return new Xm(await ye(this.sessions.decoder_model,e))}},Ym=class extends Wa{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"encoder_model"})}},Jm=class extends Wa{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"decoder_model"})}},Oc=class extends I{},JP=class extends Oc{},KP=class extends Oc{},Nc=class extends I{},ZP=class extends Nc{},eF=class extends Nc{},Dc=class extends I{},tF=class extends Dc{},rF=class extends Dc{},nF=class extends ir{},zc=class extends I{},sF=class extends zc{},aF=class extends zc{},Ms=class extends I{},oF=class extends Ms{},iF=class extends Ms{async _call(e){return new Je(await super._call(e))}},lF=class extends Ms{async _call(e){return new le(await super._call(e))}},cF=class extends Ms{async _call(e){return new it(await super._call(e))}},Bc=class extends I{},uF=class extends Bc{},dF=class extends Bc{},qa=class extends I{},hF=class extends qa{},fF=class extends qa{async _call(e){return new le(await super._call(e))}},_F=class extends qa{},Ha=class extends I{},pF=class extends Ha{},mF=class extends Ha{async _call(e){return new le(await super._call(e))}},gF=class extends Ha{},Qa=class extends I{},wF=class extends Qa{},vF=class extends Qa{async _call(e){return new le(await super._call(e))}},yF=class extends Qa{},Xa=class extends I{},bF=class extends Xa{},MF=class extends Xa{async _call(e){return new le(await super._call(e))}},xF=class extends Xa{},Rc=class extends I{},kF=class extends Rc{},TF=class extends Rc{async _call(e){return new le(await super._call(e))}},$c=class extends I{},EF=class extends $c{},AF=class extends $c{async _call(e){return new le(await super._call(e))}},xs=class extends I{},CF=class extends xs{},SF=class extends xs{async _call(e){return new Je(await super._call(e))}},PF=class extends xs{async _call(e){return new le(await super._call(e))}},FF=class extends xs{async _call(e){return new Xe(await super._call(e))}},Gc=class extends I{},IF=class extends Gc{},LF=class extends Gc{},Vc=class extends I{constructor(){super(...arguments);T(this,"requires_attention_mask",!1);T(this,"main_input_name","input_values");T(this,"forward_params",["input_values","decoder_input_ids","past_key_values"])}},OF=class extends Vc{},NF=class extends Vc{},Dn=class extends I{},DF=class extends Dn{},zF=class extends Dn{async _call(e){return new Je(await super._call(e))}},BF=class extends Dn{async _call(e){return new le(await super._call(e))}},RF=class extends Dn{async _call(e){return new Xe(await super._call(e))}},$F=class extends Dn{async _call(e){return new it(await super._call(e))}},Uc=class extends I{},GF=class extends Uc{},VF=class extends Uc{},jc=class extends I{},UF=class extends jc{},jF=class extends jc{},Km=class extends I{},WF=class extends Km{constructor(...t){super(...t);T(this,"forward_params",["input_ids","pixel_values","images_seq_mask","images_emb_mask","attention_mask","position_ids","past_key_values"]);this._generation_mode="text"}async forward(t){const r=this._generation_mode??"text";let n;if(r==="text"||!t.past_key_values){const l=this.sessions.prepare_inputs_embeds,c=rt(t,l.inputNames);n=await ye(l,c)}else{const l=this.sessions.gen_img_embeds,c=rt({image_ids:t.input_ids},l.inputNames);n=await ye(l,c)}const s={...t,...n},a=await vr(this,s),o=this.sessions[r==="text"?"lm_head":"gen_head"];if(!o)throw new Error(`Unable to find "${o}" generation head`);const i=await ye(o,rt(a,o.inputNames));return{...n,...a,...i}}prepare_inputs_for_generation(t,r,n){const s=!!r.past_key_values;return ms(this,r,1n),n.guidance_scale!==null&&n.guidance_scale>1&&(s?r.input_ids=Re([r.input_ids,r.input_ids],0):(r.input_ids=Re([r.input_ids,Zi(r.input_ids,BigInt(n.pad_token_id))],0),r.attention_mask=Re([r.attention_mask,Zi(r.attention_mask,0n)],0))),(s||!r.pixel_values)&&(r.pixel_values=dt([0,0,3,384,384],1)),s&&(r.images_seq_mask=new j("bool",new Array(1).fill(!0).fill(!1,0,1),[1,1]),r.images_emb_mask=new j("bool",new Array(0).fill(!1),[1,1,0])),r}async generate(t){return this._generation_mode="text",super.generate(t)}async generate_images(t){this._generation_mode="image";const r=(t.inputs??t[this.main_input_name]).dims[1],s=(await super.generate(t)).slice(null,[r,null]),a=this.sessions.image_decode,{decoded_image:o}=await ye(a,{generated_tokens:s}),i=o.add_(1).mul_(255/2).clamp_(0,255).to("uint8"),l=[];for(const c of i){const d=Ht.fromTensor(c);l.push(d)}return l}},Wc=class extends I{},qF=class extends Wc{},HF=class extends Wc{},Zm=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"])}_apply_and_filter_by_delay_pattern_mask(t){const[r,n]=t.dims,s=this.config.decoder.num_codebooks,a=n-s;let o=0;for(let c=0;c<t.size;++c){if(t.data[c]==this.config.decoder.pad_token_id)continue;const d=c%n,h=Math.floor(c/n)%s,_=d-h;_>0&&_<=a&&(t.data[o++]=t.data[c])}const i=Math.floor(r/s),l=o/(i*s);return new j(t.type,t.data.slice(0,o),[i,s,l])}prepare_inputs_for_generation(t,r,n){const s=BigInt(this.config.decoder.pad_token_id);let a=structuredClone(t);for(let o=0;o<a.length;++o)for(let i=0;i<a[o].length;++i)o%this.config.decoder.num_codebooks>=i&&(a[o][i]=s);return n.guidance_scale!==null&&n.guidance_scale>1&&(a=a.concat(a)),za(this,a,r)}async generate(t){const r=await super.generate(t),n=this._apply_and_filter_by_delay_pattern_mask(r).unsqueeze_(0),{audio_values:s}=await ye(this.sessions.encodec_decode,{audio_codes:n});return s}},qc=class extends I{},QF=class extends qc{},XF=class extends qc{},Hc=class extends I{},YF=class extends Hc{},JF=class extends Hc{},zn=class extends I{},KF=class extends zn{},ZF=class extends zn{async _call(e){return new Je(await super._call(e))}},eI=class extends zn{async _call(e){return new le(await super._call(e))}},tI=class extends zn{async _call(e){return new Xe(await super._call(e))}},rI=class extends zn{async _call(e){return new it(await super._call(e))}},eg=class extends I{},nI=class extends eg{},Qc=class extends I{},sI=class extends Qc{},aI=class extends Qc{},Xc=class extends I{},oI=class extends Xc{},iI=class extends Xc{},Yc=class extends I{},lI=class extends Yc{},cI=class extends Yc{},Jc=class extends I{},uI=class extends Jc{},dI=class extends Jc{},Kc=class extends I{},hI=class extends Kc{},fI=class extends Kc{async _call(e){return new le(await super._call(e))}},Zc=class extends I{},_I=class extends Zc{},pI=class extends Zc{},eu=class extends I{},mI=class extends eu{},gI=class extends eu{},tu=class extends I{},wI=class extends tu{},vI=class extends tu{},ru=class extends I{},yI=class extends ru{},bI=class extends ru{},MI=class extends ir{},tg=class extends I{},xI=class extends tg{async _call(e){return new Br(await super._call(e))}},nu=class extends I{},kI=class extends nu{},TI=class extends nu{},su=class extends I{},EI=class extends su{},AI=class extends su{},au=class extends I{},CI=class extends au{},SI=class extends au{},ou=class extends I{},PI=class extends ou{},FI=class extends ou{},rg=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","inputs_embeds","attention_mask","position_ids","pixel_values","image_sizes","past_key_values"])}},ng=class extends rg{async forward({input_ids:e=null,attention_mask:t=null,pixel_values:r=null,image_sizes:n=null,position_ids:s=null,inputs_embeds:a=null,past_key_values:o=null,generation_config:i=null,logits_processor:l=null,num_logits_to_keep:c=null,...d}){if(!a){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 ye(this.sessions.vision_encoder,{pixel_values:r,image_sizes:n}))}else{const p=this.config.normalized_config.hidden_size;_=new j("float32",[],[0,p])}({inputs_embeds:a}=await ye(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:_}))}return await vr(this,{inputs_embeds:a,past_key_values:o,attention_mask:t,position_ids:s,generation_config:i,logits_processor:l,num_logits_to_keep:c},!1)}},iu=class extends I{},II=class extends iu{},LI=class extends iu{async _call(e){return new le(await super._call(e))}},lu=class extends I{},OI=class extends lu{},NI=class extends lu{async _call(e){return new Xe(await super._call(e))}},cu=class extends I{},DI=class extends cu{},zI=class extends cu{},uu=class extends I{},BI=class extends uu{},RI=class extends uu{},du=class extends I{},$I=class extends du{},GI=class extends du{},hu=class extends I{},VI=class extends hu{},UI=class extends hu{},fu=class extends I{},jI=class extends fu{},WI=class extends fu{},_u=class extends uc{},sg=class extends zm{},qI=class extends _u{},HI=class extends sg{},pu=class extends _u{},ag=class extends pu{},QI=class extends pu{},XI=class extends ag{},mu=class extends I{},YI=class extends mu{},JI=class extends mu{async _call(e){return new le(await super._call(e))}},gu=class extends I{},KI=class extends gu{},ZI=class extends gu{async _call(e){return new og(await super._call(e))}},og=class extends ws{},Bn=class extends I{},eL=class extends Bn{},tL=class extends Bn{async _call(e){return new Je(await super._call(e))}},rL=class extends Bn{async _call(e){return new le(await super._call(e))}},nL=class extends Bn{async _call(e){return new Xe(await super._call(e))}},sL=class extends Bn{async _call(e){return new it(await super._call(e))}},Rn=class extends I{},aL=class extends Rn{},oL=class extends Rn{async _call(e){return new Je(await super._call(e))}},iL=class extends Rn{async _call(e){return new le(await super._call(e))}},lL=class extends Rn{async _call(e){return new Xe(await super._call(e))}},cL=class extends Rn{async _call(e){return new it(await super._call(e))}},wu=class extends I{},uL=class extends wu{},dL=class extends wu{async _call(e){return new ig(await super._call(e))}},ig=class extends ws{},lg=class extends je{constructor({iou_scores:e,pred_masks:t}){super(),this.iou_scores=e,this.pred_masks=t}},cg=class extends I{},hL=class extends cg{async get_image_embeddings({pixel_values:e}){return await Rr(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??(e.input_labels=xt(e.input_points.dims.slice(0,-1)));const t={image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings};return e.input_points&&(t.input_points=e.input_points),e.input_labels&&(t.input_labels=e.input_labels),e.input_boxes&&(t.input_boxes=e.input_boxes),await ye(this.sessions.prompt_encoder_mask_decoder,t)}async _call(e){return new lg(await super._call(e))}},ug=class extends je{constructor({iou_scores:e,pred_masks:t,object_score_logits:r}){super(),this.iou_scores=e,this.pred_masks=t,this.object_score_logits=r}},dg=class extends I{},vu=class extends dg{async get_image_embeddings({pixel_values:e}){return await Rr(this,{pixel_values:e})}async forward(e){const{num_feature_levels:t}=this.config.vision_config;if(Array.from({length:t},(a,o)=>`image_embeddings.${o}`).some(a=>!e[a])?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.");const a=e.input_points.dims;e.input_labels??(e.input_labels=xt(a.slice(0,-1))),e.input_boxes??(e.input_boxes=dt([a[0],0,4],0))}else if(e.input_boxes){const a=e.input_boxes.dims;e.input_labels=dt([a[0],a[1],0],-1n),e.input_points=dt([a[0],1,0,2],0)}else throw new Error("At least one of `input_points` or `input_boxes` must be provided.");const n=this.sessions.prompt_encoder_mask_decoder,s=rt(e,n.inputNames);return await ye(n,s)}async _call(e){return new ug(await super._call(e))}},fL=class extends vu{},_L=class extends vu{},Ya=class extends I{},pL=class extends Ya{},mL=class extends Ya{},gL=class extends Ya{},Ja=class extends I{},wL=class extends Ja{},vL=class extends Ja{},yL=class extends Ja{},yu=class extends I{},bL=class extends yu{},hg=class extends yu{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"text_model"})}},ML=class extends nn{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"vision_model"})}},bu=class extends I{},xL=class extends bu{},kL=class extends bu{},TL=class extends Gm{},Ka=class extends I{constructor(){super(...arguments);T(this,"main_input_name","input_values");T(this,"forward_params",["input_values"])}},EL=class extends Ka{async encode(e){return await ye(this.sessions.encoder_model,e)}async decode(e){return await ye(this.sessions.decoder_model,e)}},fg=class extends Ka{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"encoder_model"})}},_g=class extends Ka{static async from_pretrained(e,t={}){return super.from_pretrained(e,{...t,model_file_name:t.model_file_name??"decoder_model"})}},Mu=class extends I{},AL=class extends Mu{},CL=class extends Mu{},Za=class extends I{},SL=class extends Za{},PL=class extends Za{},FL=class extends Za{async generate_speech(e,t,{threshold:r=.5,minlenratio:n=0,maxlenratio:s=20,vocoder:a=null}={}){const o={input_ids:e},{encoder_outputs:i,encoder_attention_mask:l}=await Rr(this,o),c=i.dims[1]/this.config.reduction_factor,d=Math.floor(c*s),h=Math.floor(c*n),_=this.config.num_mel_bins;let p=[],w=null,v=null,y=0;for(;;){++y;const A=tm(!!v);let S;v?S=v.output_sequence_out:S=new j("float32",new Float32Array(_),[1,1,_]);let C={use_cache_branch:A,output_sequence:S,encoder_attention_mask:l,speaker_embeddings:t,encoder_hidden_states:i};Tl(this,C,w),v=await ye(this.sessions.decoder_model_merged,C),w=kl(v,w);const{prob:O,spectrum:M}=v;if(p.push(M),y>=h&&(Array.from(O.data).filter(V=>V>=r).length>0||y>=d))break}const x=Re(p),{waveform:k}=await ye(a.sessions.model,{spectrogram:x});return{spectrogram:x,waveform:k}}},IL=class extends I{constructor(){super(...arguments);T(this,"main_input_name","spectrogram")}},ks=class extends I{},LL=class extends ks{},OL=class extends ks{async _call(e){return new Je(await super._call(e))}},NL=class extends ks{async _call(e){return new le(await super._call(e))}},DL=class extends ks{async _call(e){return new it(await super._call(e))}},xu=class extends I{},zL=class extends xu{},BL=class extends xu{},ku=class extends I{},RL=class extends ku{},$L=class extends ku{},pg=class extends I{},GL=class extends pg{},mg=class extends I{},gg=class extends mg{async generate_speech({input_ids:e,attention_mask:t,style:r,num_inference_steps:n=5,speed:s=1.05}){const{sampling_rate:a,chunk_compress_factor:o,base_chunk_size:i,latent_dim:l}=this.config,{last_hidden_state:c,durations:d}=await ye(this.sessions.text_encoder,{input_ids:e,attention_mask:t,style:r}),h=d.div(s).mul_(a),_=i*o,p=h.data,w=Int32Array.from(p,G=>Math.ceil(G/_)),v=Math.max(...w),y=e.dims[0],x=new BigInt64Array(y*v);for(let G=0;G<y;++G)x.fill(1n,G*v,G*v+w[G]);const k=new j("int64",x,[y,v]),A=l*o,S=A*v;let C=rk([y,A,v]);const O=C.data;for(let G=0;G<y;++G)if(w[G]!==v)for(let U=0;U<A;++U)O.fill(0,G*S+U*v+w[G],G*S+(U+1)*v);const M=dt([y],n);for(let G=0;G<n;++G){const U=dt([y],G);({denoised_latents:C}=await ye(this.sessions.latent_denoiser,{style:r,noisy_latents:C,latent_mask:k,encoder_outputs:c,attention_mask:t,timestep:U,num_inference_steps:M}))}const{waveform:V}=await ye(this.sessions.voice_decoder,{latents:C});return{waveform:V,durations:h}}},eo=class extends I{},VL=class extends eo{},UL=class extends eo{async _call(e){return new le(await super._call(e))}},jL=class extends eo{},Tu=class extends I{},WL=class extends Tu{},qL=class extends Tu{},Eu=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"])}},HL=class extends Eu{},QL=class extends Eu{},Au=class extends I{},XL=class extends Au{},YL=class extends Au{async _call(e){return new wg(await super._call(e))}},wg=class extends Ql{},vg=class extends I{},JL=class extends vg{},to=class extends I{},KL=class extends to{},ZL=class extends to{async _call(e){return new Br(await super._call(e))}},eO=class extends to{async _call(e){return new le(await super._call(e))}},Ts=class extends I{},tO=class extends Ts{},rO=class extends Ts{async _call(e){return new Br(await super._call(e))}},nO=class extends Ts{async _call(e){return new le(await super._call(e))}},sO=class extends Ts{async _call(e){return new Xe(await super._call(e))}},Cu=class extends I{},aO=class extends Cu{},oO=class extends Cu{},iO=class extends I{constructor(){super(...arguments);T(this,"main_input_name","pixel_values");T(this,"forward_params",["pixel_values","decoder_input_ids","encoder_hidden_states","past_key_values"])}},Su=class extends I{},lO=class extends Su{},cO=class extends Su{async _call(e){return new le(await super._call(e))}},yg=class extends I{},uO=class extends yg{},Pu=class extends I{},dO=class extends Pu{},hO=class extends Pu{async _call(e){return new le(await super._call(e))}},bg=class extends I{},fO=class extends bg{async _call(e){return new Qp(await super._call(e))}},Mg=class extends I{},_O=class extends Mg{},xg=class extends je{constructor({waveform:e,spectrogram:t}){super(),this.waveform=e,this.spectrogram=t}},kg=class extends I{},pO=class extends kg{async _call(e){return new xg(await super._call(e))}},mO=class extends yc{},Tg=2,gO=1,Fu=new WeakMap;function wO(e,t){var v,y;const{text_config:r,audio_config:n}=e.config,s=e.sessions.audio_encoder,{num_mel_bins:a,hidden_size:o}=n,i=a+o,l=new bl,c=La(n),d={batch_size:1};let h="float32";for(const x of s.inputMetadata){if(x.name==="past_padding_cache"){h=x.type;continue}if(!c.has(x.name))continue;const k=sm(x.shape,d),A=k.reduce((C,O)=>C*O,1),S=hs[x.type];l[x.name]=new j(x.type,new S(A),k)}const _=hs[h],p=new j(h,new _(i*Tg),[1,i,Tg]),w=((v=t[Symbol.asyncIterator])==null?void 0:v.call(t))??((y=t[Symbol.iterator])==null?void 0:y.call(t));if(!w)throw new Error("input_features must be iterable or async iterable");return{encoder_session:s,enc_kv_cache:l,enc_padding_cache:p,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:w,text_hidden_size:r.hidden_size}}async function vO(e,t){const r=t.dims[2],n=Math.floor((gO+r-3)/2)+1,s=new j("int64",BigInt64Array.from({length:n},(d,h)=>BigInt(e.enc_past_seq_len+h)),[1,n]),a=e.enc_past_seq_len+n,o=xt([1,a]),{audio_embeds:i,present_padding_cache:l,...c}=await ye(e.encoder_session,{input_features:t,attention_mask:o,position_ids:s,past_padding_cache:e.enc_padding_cache,...e.enc_kv_cache});e.enc_padding_cache.location==="gpu-buffer"&&e.enc_padding_cache.dispose(),e.enc_padding_cache=l;for(const d in c)if(d.startsWith("present.")){const h=d.replace("present","past_key_values"),_=e.enc_kv_cache[h];(_==null?void 0:_.location)==="gpu-buffer"&&_.dispose(),e.enc_kv_cache[h]=c[d]}return e.enc_past_seq_len=a,i}async function yO(e,t){for(;e.audio_embed_total_tokens<t&&!e.stream_exhausted;){const r=await e.chunks_iter.next();if(r.done){e.stream_exhausted=!0;break}const n=await vO(e,r.value);e.audio_embed_queue.push({data:n.data,tokens:n.dims[1]}),e.audio_embed_total_tokens+=n.dims[1]}}function bO(e,t,r){if(e.audio_embed_queue.length===0)return;const n=t.data;let s=0,a=r;for(;a>0&&e.audio_embed_queue.length>0;){const o=e.audio_embed_queue[0],i=o.tokens-e.audio_queue_offset,l=Math.min(a,i),c=e.audio_queue_offset*e.text_hidden_size;for(let d=0;d<l*e.text_hidden_size;++d)n[s*e.text_hidden_size+d]+=o.data[c+d];s+=l,a-=l,e.audio_queue_offset+=l,e.audio_queue_offset>=o.tokens&&(e.audio_embed_queue.shift(),e.audio_queue_offset=0)}e.audio_consumed+=r-a}var MO=class extends Oa{constructor(e){super(),this._s=e}_call(e){const t=this._s.stream_exhausted&&this._s.audio_embed_queue.length===0;return e.map(()=>t)}},Eg=class extends I{constructor(){super(...arguments);T(this,"forward_params",["input_ids","attention_mask","position_ids","past_key_values"])}},Ag=class extends Eg{async forward({input_ids:e,past_key_values:t,...r}){const n=e.dims[1],s=Fu.get(this);s&&await yO(s,s.audio_consumed+n);const{inputs_embeds:a}=await ye(this.sessions.embed_tokens,{input_ids:e});s&&bO(s,a,n);const o={inputs_embeds:a,...r};Tl(this,o,t);const i=this.sessions.decoder_model_merged,l=rt(o,i.inputNames);return await ye(i,l)}async generate({input_features:e,stopping_criteria:t,...r}){if(!e)throw new Error("input_features (generator/iterable) must be provided");const n=wO(this,e);Fu.set(this,n);const s=new Jp;s.push(new MO(n)),t&&s.extend(t);try{return await super.generate({...r,stopping_criteria:s})}finally{n.enc_kv_cache.dispose(),Fu.delete(this)}}},ro=class extends I{},xO=class extends ro{},kO=class extends ro{async _call(e){return new Br(await super._call(e))}},TO=class extends ro{async _call(e){return new le(await super._call(e))}},Cg=class extends je{constructor({logits:e,embeddings:t}){super(),this.logits=e,this.embeddings=t}},$n=class extends I{},EO=class extends $n{},AO=class extends $n{async _call(e){return new Br(await super._call(e))}},CO=class extends $n{async _call(e){return new le(await super._call(e))}},SO=class extends $n{async _call(e){return new Cg(await super._call(e))}},PO=class extends $n{async _call(e){return new Xe(await super._call(e))}},Sg=class extends I{},FO=class extends Sg{},IO=class extends Yp{constructor(){super(...arguments);T(this,"return_timestamps",null);T(this,"return_token_timestamps",null);T(this,"num_frames",null);T(this,"alignment_heads",null);T(this,"task",null);T(this,"language",null);T(this,"no_timestamps_token_id",null);T(this,"prompt_ids",null);T(this,"is_multilingual",null);T(this,"lang_to_id",null);T(this,"task_to_id",null);T(this,"max_initial_timestamp_index",1)}},Iu=class extends I{constructor(){super(...arguments);T(this,"requires_attention_mask",!1);T(this,"main_input_name","input_features");T(this,"forward_params",["input_features","attention_mask","decoder_input_ids","decoder_attention_mask","past_key_values"])}},LO=class extends Iu{},Pg=class extends Iu{_prepare_generation_config(e,t){return super._prepare_generation_config(e,t,IO)}_retrieve_init_tokens(e){const t=[e.decoder_start_token_id];let r=e.language;const n=e.task;if(e.is_multilingual){r||(he.warn("No language specified - defaulting to English (en)."),r="en");const a=`<|${Jk(r)}|>`;t.push(e.lang_to_id[a]),t.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&&t.at(-1)!==e.no_timestamps_token_id?t.push(e.no_timestamps_token_id):e.return_timestamps&&t.at(-1)===e.no_timestamps_token_id&&(he.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),t.pop()),t.filter(s=>s!=null)}async generate({inputs:e=null,generation_config:t=null,logits_processor:r=null,stopping_criteria:n=null,...s}){t=this._prepare_generation_config(t,s);const a=s.decoder_input_ids instanceof j?rl(s.decoder_input_ids):s.decoder_input_ids??this._retrieve_init_tokens(t);if(t.return_timestamps&&(r??(r=new yl),r.push(new O2(t,a))),t.begin_suppress_tokens&&(r??(r=new yl),r.push(new Xp(t.begin_suppress_tokens,a.length))),t.return_token_timestamps){if(!t.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.");t.task==="translate"&&he.warn("Token-level timestamps may not be reliable for task 'translate'."),t.output_attentions=!0,t.return_dict_in_generate=!0}if(t.return_timestamps&&!s.max_new_tokens)return this._generate_with_seek({inputs:e,generation_config:t,logits_processor:r,init_tokens:a,kwargs:s});const o=await super.generate({inputs:e,generation_config:t,logits_processor:r,decoder_input_ids:a,...s});return t.return_token_timestamps&&(o.token_timestamps=this._extract_token_timestamps(o,t.alignment_heads,t.num_frames,.02,a.length)),o}async _generate_with_seek({inputs:e,generation_config:t,logits_processor:r,init_tokens:n,kwargs:s}){const a=t.no_timestamps_token_id+1,o=Array.isArray(t.eos_token_id)?t.eos_token_id[0]:t.eos_token_id,i=t.return_token_timestamps,l=e,c=l.dims[2],d=2,h=this.config.max_source_positions,_=d*h;let p=0;const w=[],v=[];for(;p<c;){const x=Math.min(p+_,c),k=l.slice(null,null,[p,x]);let A;const S=k.dims[2];if(S<_){const H=l.dims[1],ne=new Float32Array(H*_),Se=k.data;for(let Y=0;Y<H;++Y)ne.set(Se.subarray(Y*S,(Y+1)*S),Y*_);A=new j("float32",ne,[1,H,_])}else A=k;if(r)for(const H of r)"begin_index"in H&&(H.begin_index=n.length);const C=await super.generate({inputs:A,generation_config:t,logits_processor:r,decoder_input_ids:n,...s}),M=(i?C.sequences:C)[0].tolist().map(Number).slice(n.length);let V;if(i){C.token_timestamps=this._extract_token_timestamps(C,t.alignment_heads,Math.floor((x-p)/d),.02,n.length);const H=p/d*.02;V=C.token_timestamps[0].tolist().slice(n.length).map(ne=>ne+H)}if(M.length>0&&M.at(-1)===o&&M.pop(),M.length===0)break;const G=M.map(H=>H>=a),U=M.length>=2&&G[M.length-1]&&!G[M.length-2],J=[];for(let H=0;H<M.length-1;++H)G[H]&&G[H+1]&&J.push(H+1);let Q,B=M.length;if(J.length>0)if(U)Q=x-p;else{const H=J.at(-1);Q=(M[H-1]-a)*d,B=H}else Q=x-p;const L=Math.floor(p/d),ee=a+1500;for(let H=0;H<B;++H)M[H]>=a&&(M[H]=Math.min(M[H]+L,ee));w.push(...M.slice(0,B)),V&&v.push(...V.slice(0,B)),p+=Q}w.push(o);const y=[...n,...w];if(i){const x=new j("int64",y.map(BigInt),[1,y.length]),k=[...new Array(n.length).fill(0),...v,0],A=new j("float32",new Float32Array(k),[1,k.length]);return{sequences:x,token_timestamps:A}}return new j("int64",y.map(BigInt),[1,y.length])}_extract_token_timestamps(e,t,r=null,n=.02,s=0){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&&he.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 a=this.config.median_filter_width;a===void 0&&(he.warn("Model config has no `median_filter_width`, using default value of 7."),a=7);const o=e.cross_attentions,i=Array.from({length:this.config.decoder_layers},(y,x)=>Re(o.map(k=>k[x]),2)),l=pr(t.map(([y,x])=>{if(y>=i.length)throw new Error(`Layer index ${y} is out of bounds for cross attentions (length ${i.length}).`);return r?i[y].slice(null,x,null,[0,r]):i[y].slice(null,x)})).permute(1,0,2,3),[c,d]=tk(l,-2,0,!0),h=l.clone();for(let y=0;y<h.dims[0];++y){const x=h[y];for(let k=0;k<x.dims[0];++k){const A=x[k],S=c[y][k][0].data,C=d[y][k][0].data;for(let O=0;O<A.dims[0];++O){let M=A[O].data;for(let V=0;V<M.length;++V)M[V]=(M[V]-C[V])/S[V];M.set(z1(M,a))}}}const _=s>0?h.slice(null,null,[s,h.dims[2]],null):h,p=[Yi(_,1)],w=e.sequences.dims,v=new j("float32",new Float32Array(w[0]*w[1]),w);for(let y=0;y<w[0];++y){const x=p[y].neg().squeeze_(0),[k,A]=R1(x.tolist()),S=Array.from({length:k.length-1},(V,G)=>k[G+1]-k[G]),C=er([1],S).map(V=>!!V),O=[];for(let V=0;V<C.length;++V)C[V]&&O.push(A[V]*n);const M=new Array(s).fill(0);M.push(...O),O.length>0&&M.push(O.at(-1)),v[y].data.set(M)}return v}},OO=class extends Pg{},Gn=class extends I{},NO=class extends Gn{},DO=class extends Gn{async _call(e){return new Je(await super._call(e))}},zO=class extends Gn{async _call(e){return new le(await super._call(e))}},BO=class extends Gn{async _call(e){return new Xe(await super._call(e))}},RO=class extends Gn{async _call(e){return new it(await super._call(e))}},Vn=class extends I{},$O=class extends Vn{},GO=class extends Vn{async _call(e){return new Je(await super._call(e))}},VO=class extends Vn{async _call(e){return new le(await super._call(e))}},UO=class extends Vn{async _call(e){return new Xe(await super._call(e))}},jO=class extends Vn{async _call(e){return new it(await super._call(e))}},Lu=class extends I{},WO=class extends Lu{},qO=class extends Lu{async _call(e){return new Fg(await super._call(e))}},Fg=class extends je{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}},Ou=class extends I{},HO=class extends Ou{},QO=class extends Ou{},Nu=class extends I{},XO=class extends Nu{},YO=class extends Nu{},JO=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"],["openai_privacy_filter","OpenAIPrivacyFilterModel"],["embedding_gemma2","EmbeddingGemma2Model"]]),KO=new Map([["t5","T5Model"],["longt5","LongT5Model"],["mt5","MT5Model"],["bart","BartModel"],["mbart","MBartModel"],["marian","MarianModel"],["whisper","WhisperModel"],["cohere_asr","CohereAsrModel"],["m2m_100","M2M100Model"],["blenderbot","BlenderbotModel"],["blenderbot-small","BlenderbotSmallModel"]]),ZO=new Map([["mimi","MimiModel"],["dac","DacModel"],["snac","SnacModel"]]),eN=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"],["deepseek_v4","DeepseekV4Model"],["falcon","FalconModel"],["falcon_h1","FalconH1Model"],["nemotron_h","NemotronHModel"],["solar_open","SolarOpenModel"],["stablelm","StableLmModel"],["modernbert-decoder","ModernBertDecoderModel"],["hunyuan_v1_dense","HunYuanDenseV1Model"],["youtu","YoutuModel"],["zaya","ZayaModel"],["hrm_text","HrmTextModel"]]),Ig=new Map([["speecht5","SpeechT5ForSpeechToText"],["whisper","WhisperForConditionalGeneration"],["lite-whisper","LiteWhisperForConditionalGeneration"],["moonshine","MoonshineForConditionalGeneration"],["cohere_asr","CohereAsrForConditionalGeneration"]]),Lg=new Map([["speecht5","SpeechT5ForTextToSpeech"]]),Og=new Map([["vits","VitsModel"],["musicgen","MusicgenForConditionalGeneration"],["supertonic","SupertonicForConditionalGeneration"]]),Ng=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"]]),Dg=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"],["openai_privacy_filter","OpenAIPrivacyFilterForTokenClassification"]]),zg=new Map([["t5","T5ForConditionalGeneration"],["longt5","LongT5ForConditionalGeneration"],["mt5","MT5ForConditionalGeneration"],["bart","BartForConditionalGeneration"],["mbart","MBartForConditionalGeneration"],["marian","MarianMTModel"],["m2m_100","M2M100ForConditionalGeneration"],["blenderbot","BlenderbotForConditionalGeneration"],["blenderbot-small","BlenderbotSmallForConditionalGeneration"]]),Bg=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_text","Qwen3_5ForCausalLM"],["qwen3_5_moe","Qwen3_5MoeForCausalLM"],["gemma3n","Gemma3nForCausalLM"],["gemma4","Gemma4ForCausalLM"],["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"],["deepseek_v4","DeepseekV4ForCausalLM"],["falcon","FalconForCausalLM"],["falcon_h1","FalconH1ForCausalLM"],["nemotron_h","NemotronHForCausalLM"],["trocr","TrOCRForCausalLM"],["solar_open","SolarOpenForCausalLM"],["stablelm","StableLmForCausalLM"],["modernbert-decoder","ModernBertDecoderForCausalLM"],["hunyuan_v1_dense","HunYuanDenseV1ForCausalLM"],["youtu","YoutuForCausalLM"],["zaya","ZayaForCausalLM"],["hrm_text","HrmTextForCausalLM"],["phi3_v","Phi3VForCausalLM"]]),tN=new Map([["multi_modality","MultiModalityCausalLM"]]),Rg=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"]]),$g=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"]]),Gg=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"]]),Vg=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"],["gemma3","Gemma3ForConditionalGeneration"],["gemma3n","Gemma3nForConditionalGeneration"],["gemma4","Gemma4ForConditionalGeneration"],["mistral3","Mistral3ForConditionalGeneration"],["lighton_ocr","LightOnOcrForConditionalGeneration"],["glm_ocr","GlmOcrForConditionalGeneration"]]),Ug=new Map([["granite_speech","GraniteSpeechForConditionalGeneration"],["ultravox","UltravoxModel"],["voxtral","VoxtralForConditionalGeneration"],["voxtral_realtime","VoxtralRealtimeForConditionalGeneration"]]),rN=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"]]),jg=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"]]),Wg=new Map([["detr","DetrForObjectDetection"],["rt_detr","RTDetrForObjectDetection"],["rt_detr_v2","RTDetrV2ForObjectDetection"],["rf_detr","RFDetrForObjectDetection"],["d_fine","DFineForObjectDetection"],["table-transformer","TableTransformerForObjectDetection"],["yolos","YolosForObjectDetection"]]),qg=new Map([["owlvit","OwlViTForObjectDetection"],["owlv2","Owlv2ForObjectDetection"],["grounding-dino","GroundingDinoForObjectDetection"]]),Un=new Map([["detr","DetrForSegmentation"],["clipseg","CLIPSegForImageSegmentation"]]),Hg=new Map([["segformer","SegformerForSemanticSegmentation"],["sapiens","SapiensForSemanticSegmentation"],["swin","SwinForSemanticSegmentation"],["mobilenet_v1","MobileNetV1ForSemanticSegmentation"],["mobilenet_v2","MobileNetV2ForSemanticSegmentation"],["mobilenet_v3","MobileNetV3ForSemanticSegmentation"],["mobilenet_v4","MobileNetV4ForSemanticSegmentation"]]),Qg=new Map([["detr","DetrForSegmentation"],["maskformer","MaskFormerForInstanceSegmentation"]]),Xg=new Map([["sam","SamModel"],["sam2","Sam2Model"],["edgetam","EdgeTamModel"],["sam3_tracker","Sam3TrackerModel"]]),Yg=new Map([["wav2vec2","Wav2Vec2ForCTC"],["wav2vec2-bert","Wav2Vec2BertForCTC"],["unispeech","UniSpeechForCTC"],["unispeech-sat","UniSpeechSatForCTC"],["wavlm","WavLMForCTC"],["hubert","HubertForCTC"],["parakeet_ctc","ParakeetForCTC"]]),Jg=new Map([["wav2vec2","Wav2Vec2ForSequenceClassification"],["wav2vec2-bert","Wav2Vec2BertForSequenceClassification"],["unispeech","UniSpeechForSequenceClassification"],["unispeech-sat","UniSpeechSatForSequenceClassification"],["wavlm","WavLMForSequenceClassification"],["hubert","HubertForSequenceClassification"],["audio-spectrogram-transformer","ASTForAudioClassification"]]),Kg=new Map([["wavlm","WavLMForXVector"]]),Zg=new Map([["unispeech-sat","UniSpeechSatForAudioFrameClassification"],["wavlm","WavLMForAudioFrameClassification"],["wav2vec2","Wav2Vec2ForAudioFrameClassification"],["pyannote","PyAnnoteForAudioFrameClassification"]]),ew=new Map([["vitmatte","VitMatteForImageMatting"]]),nN=new Map([["patchtst","PatchTSTForPrediction"],["patchtsmixer","PatchTSMixerForPrediction"]]),tw=new Map([["swin2sr","Swin2SRForImageSuperResolution"]]),rw=new Map([["chmv2","CHMv2ForDepthEstimation"],["dpt","DPTForDepthEstimation"],["depth_anything","DepthAnythingForDepthEstimation"],["glpn","GLPNForDepthEstimation"],["sapiens","SapiensForDepthEstimation"],["depth_pro","DepthProForDepthEstimation"],["metric3d","Metric3DForDepthEstimation"],["metric3dv2","Metric3Dv2ForDepthEstimation"]]),nw=new Map([["sapiens","SapiensForNormalEstimation"]]),sw=new Map([["vitpose","VitPoseForPoseEstimation"]]),aw=new Map([["clip","CLIPVisionModelWithProjection"],["siglip","SiglipVisionModel"],["jina_clip","JinaCLIPVisionModel"]]),ow=[[JO,q.EncoderOnly],[KO,q.EncoderDecoder],[eN,q.DecoderOnlyWithoutHead],[ZO,q.AutoEncoder],[Ng,q.EncoderOnly],[Dg,q.EncoderOnly],[zg,q.Seq2Seq],[Ig,q.Seq2Seq],[Bg,q.DecoderOnly],[tN,q.MultiModality],[Rg,q.EncoderOnly],[$g,q.EncoderOnly],[Gg,q.Vision2Seq],[Vg,q.ImageTextToText],[Ug,q.AudioTextToText],[jg,q.EncoderOnly],[Un,q.EncoderOnly],[Qg,q.EncoderOnly],[Hg,q.EncoderOnly],[ew,q.EncoderOnly],[nN,q.EncoderOnly],[tw,q.EncoderOnly],[rw,q.EncoderOnly],[nw,q.EncoderOnly],[sw,q.EncoderOnly],[Wg,q.EncoderOnly],[qg,q.EncoderOnly],[Xg,q.MaskGeneration],[Yg,q.EncoderOnly],[Jg,q.EncoderOnly],[Lg,q.Seq2Seq],[Og,q.EncoderOnly],[Kg,q.EncoderOnly],[Zg,q.EncoderOnly],[aw,q.EncoderOnly]];for(const[e,t]of ow)for(const r of e.values()){wr.set(r,t);const n=Al[r];An.set(n,r),xl.set(r,n)}var sN=[["MusicgenForConditionalGeneration",Zm,q.Musicgen],["Phi3VForCausalLM",ng,q.Phi3V],["CLIPTextModelWithProjection",mm,q.EncoderOnly],["SiglipTextModel",hg,q.EncoderOnly],["JinaCLIPTextModel",Vm,q.EncoderOnly],["ClapTextModelWithProjection",_m,q.EncoderOnly],["ClapAudioModelWithProjection",pm,q.EncoderOnly],["DacEncoderModel",vm,q.EncoderOnly],["DacDecoderModel",ym,q.EncoderOnly],["MimiEncoderModel",Ym,q.EncoderOnly],["MimiDecoderModel",Jm,q.EncoderOnly],["SnacEncoderModel",fg,q.EncoderOnly],["SnacDecoderModel",_g,q.EncoderOnly],["Gemma3nForConditionalGeneration",Ua,q.ImageAudioTextToText],["Gemma4ForConditionalGeneration",oc,q.ImageAudioTextToText],["SupertonicForConditionalGeneration",gg,q.Supertonic],["ChatterboxModel",dm,q.Chatterbox],["EmbeddingGemma2Model",Sm,q.MultimodalEncoder],["VoxtralRealtimeForConditionalGeneration",Ag,q.VoxtralRealtime]];for(const[e,t,r]of sN)wr.set(e,r),An.set(t,e),xl.set(e,t);var iw=new Map([["modnet",Un],["birefnet",Un],["isnet",Un],["ben",Un]]);for(const[e,t]of iw.entries())t.set(e,"PreTrainedModel"),wr.set(e,q.EncoderOnly),xl.set(e,I);var aN=new Set(iw.keys());wr.set("PreTrainedModel",q.EncoderOnly),An.set(I,"PreTrainedModel");var Ae={MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES:Ng,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES:Dg,MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES:Lg,MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES:Og,MODEL_FOR_MASKED_LM_MAPPING_NAMES:Rg,MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES:$g,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES:jg,MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES:Un,MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES:Hg,MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES:Qg,MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES:Wg,MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES:qg,MODEL_FOR_MASK_GENERATION_MAPPING_NAMES:Xg,MODEL_FOR_CTC_MAPPING_NAMES:Yg,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES:Jg,MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES:Kg,MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES:Zg,MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES:rN,MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES:ew,MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES:tw,MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES:rw,MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES:nw,MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES:sw,MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES:aw,MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES:Vg,MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES:Ug,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES:zg,MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES:Ig,MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:Bg,MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES:Gg};Y2(Ae);var Ce=(yo=class{static supports(e){if(!this.MODEL_CLASS_MAPPINGS)return!1;for(const t of this.MODEL_CLASS_MAPPINGS)if(t.has(e))return!0;return this.BASE_IF_FAIL}static async from_pretrained(e,{progress_callback:t=null,config:r=null,cache_dir:n=null,local_files_only:s=!1,revision:a="main",model_file_name:o=null,subfolder:i="onnx",device:l=null,dtype:c=null,use_external_data_format:d=null,session_options:h={}}={}){const _={progress_callback:t,config:r,cache_dir:n,local_files_only:s,revision:a,model_file_name:o,subfolder:i,device:l,dtype:c,use_external_data_format:d,session_options:h};if(_.config=await ps.from_pretrained(e,_),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);const{model_type:p}=_.config;for(const w of this.MODEL_CLASS_MAPPINGS){let v=w.get(p);if(!v){for(const y of w.values())if(y[0]===p){v=y;break}if(!v)continue}return await Al[v].from_pretrained(e,_)}if(this.BASE_IF_FAIL)return aN.has(p)||he.warn(`Unknown model class "${p}", attempting to construct from base class.`),await I.from_pretrained(e,_);throw Error(`Unsupported model type: ${p}`)}},T(yo,"MODEL_CLASS_MAPPINGS",null),T(yo,"BASE_IF_FAIL",!1),yo),Es=(bo=class extends Ce{},T(bo,"MODEL_CLASS_MAPPINGS",ow.map(e=>e[0])),T(bo,"BASE_IF_FAIL",!0),bo),lw=(ju=class extends Ce{},T(ju,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]),ju),oN=(Wu=class extends Ce{},T(Wu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]),Wu),Du=(qu=class extends Ce{},T(qu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]),qu),iN=(Hu=class extends Ce{},T(Hu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]),Hu),lN=(Qu=class extends Ce{},T(Qu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]),Qu),cN=(Xu=class extends Ce{},T(Xu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]),Xu),uN=(Yu=class extends Ce{},T(Yu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES]),Yu),dN=(Ju=class extends Ce{},T(Ju,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_MASKED_LM_MAPPING_NAMES]),Ju),hN=(Ku=class extends Ce{},T(Ku,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]),Ku),fN=(Zu=class extends Ce{},T(Zu,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]),Zu),_N=(ed=class extends Ce{},T(ed,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]),ed),cw=(td=class extends Ce{},T(td,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]),td),uw=(rd=class extends Ce{},T(rd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]),rd),dw=(nd=class extends Ce{},T(nd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES]),nd),pN=(sd=class extends Ce{},T(sd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]),sd),mN=(ad=class extends Ce{},T(ad,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]),ad);od=class extends Ce{},T(od,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]);var gN=(id=class extends Ce{},T(id,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_CTC_MAPPING_NAMES]),id),wN=(ld=class extends Ce{},T(ld,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]),ld);cd=class extends Ce{},T(cd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]),ud=class extends Ce{},T(ud,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]);var vN=(dd=class extends Ce{},T(dd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]),dd);hd=class extends Ce{},T(hd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]);var yN=(fd=class extends Ce{},T(fd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]),fd),bN=(_d=class extends Ce{},T(_d,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]),_d);pd=class extends Ce{},T(pd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES]),md=class extends Ce{},T(md,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES]);var MN=(gd=class extends Ce{},T(gd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]),gd);wd=class extends Ce{},T(wd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES]),vd=class extends Ce{},T(vd,"MODEL_CLASS_MAPPINGS",[Ae.MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES]);async function Xt(e){return Array.isArray(e)||(e=[e]),await Promise.all(e.map(t=>Ht.read(t)))}async function jn(e,t){return Array.isArray(e)||(e=[e]),await Promise.all(e.map(r=>typeof r=="string"||r instanceof URL?oT(r,t):r instanceof Float64Array?new Float32Array(r):r))}function zu(e,t){t&&(e=e.map(o=>o|0));const[r,n,s,a]=e;return{xmin:r,ymin:n,xmax:s,ymax:a}}var qe=class extends gt{constructor({task:e,model:t,tokenizer:r=null,processor:n=null}){super(),this.task=e,this.model=t,this.tokenizer=r,this.processor=n}async dispose(){await this.model.dispose()}},xN=class extends qe{async _call(e,{top_k:t=1}={}){const r=this.tokenizer(e,{padding:!0,truncation:!0}),n=await this.model(r),{problem_type:s,id2label:a}=this.model.config,o=s==="multi_label_classification"?l=>l.sigmoid():l=>new j("float32",at(l.data),l.dims),i=[];for(const l of n.logits){const c=o(l),d=await Mn(c,t),h=d[0].tolist(),p=d[1].tolist().map((w,v)=>({label:a?a[w]:`LABEL_${w}`,score:h[v]}));t===1?i.push(...p):i.push(p)}return Array.isArray(e)||t===1?i:i[0]}},kN=class extends qe{async _call(e,{ignore_labels:t=["O"],aggregation_strategy:r="none"}={}){if(r!=="none"&&r!=="simple")throw new Error(`Invalid aggregation_strategy: "${r}". Must be one of "none" or "simple".`);const n=Array.isArray(e),s=this.tokenizer(n?e:[e],{padding:!0,truncation:!0}),o=(await this.model(s)).logits,i=this.model.config.id2label,l=[];for(let c=0;c<o.dims[0];++c){const d=s.input_ids[c].tolist(),h=o[c],_=[];for(let p=0;p<h.dims[0];++p){const w=h[p],v=Qe(w.data)[1],y=i?i[v]:`LABEL_${v}`;if(t.includes(y))continue;const x=this.tokenizer.decode([d[p]],{skip_special_tokens:!0});if(x==="")continue;const k=at(w.data);_.push({entity:y,score:k[v],index:p,word:x})}l.push(r==="simple"?EN(_,d,this.tokenizer):_)}return n?l:l[0]}};function TN(e){const t=e[0];return e[1]==="-"&&(t==="B"||t==="I"||t==="E"||t==="S")?[t,e.slice(2)]:["I",e]}function EN(e,t,r){const n=[];let s=null;for(let a=0;a<e.length;++a){const[o,i]=TN(e[a].entity);s===i&&o!=="B"&&o!=="S"?(n[n.length-1].end=a+1,o==="E"&&(s=null)):(n.push({tag:i,start:a,end:a+1}),s=o==="S"?null:i)}return n.map(({tag:a,start:o,end:i})=>{let l=0;const c=[];for(let d=o;d<i;++d)l+=e[d].score,c.push(t[e[d].index]);return{entity_group:a,score:l/(i-o),word:r.decode(c,{skip_special_tokens:!0})}})}var AN=class extends qe{async _call(e,t,{top_k:r=1}={}){const n=this.tokenizer(e,{text_pair:t,padding:!0,truncation:!0}),s=Array.isArray(e),{start_logits:a,end_logits:o}=await this.model(n),i=n.input_ids.tolist(),l=n.attention_mask.tolist(),{all_special_ids:c,sep_token_id:d}=this.tokenizer,h=[];for(let _=0;_<a.dims[0];++_){const p=i[_],w=p.findIndex(C=>C==d),v=a[_].tolist(),y=o[_].tolist();for(let C=1;C<v.length;++C)(l[_]==0||C<=w||c.findIndex(O=>O==p[C])!==-1)&&(v[C]=-1/0,y[C]=-1/0);const x=at(v).map((C,O)=>[C,O]),k=at(y).map((C,O)=>[C,O]);x[0][0]=0,k[0][0]=0;const A=Ub(x,k).filter(C=>C[0][1]<=C[1][1]).map(C=>[C[0][1],C[1][1],C[0][0]*C[1][0]]).sort((C,O)=>O[2]-C[2]),S=[];for(let C=0;C<Math.min(A.length,r);++C){const[O,M,V]=A[C],G=p.slice(O,M+1),U=this.tokenizer.decode(G,{skip_special_tokens:!0});S.push({answer:U,score:V})}r===1?h.push(...S):h.push(S)}return s?h:h[0]}},CN=class extends qe{async _call(e,{top_k:t=5}={}){const{mask_token_id:r,mask_token:n}=this.tokenizer,s=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:a}=await this.model(s),o=[],i=s.input_ids.tolist();for(let l=0;l<i.length;++l){const c=i[l],d=c.findIndex(v=>v==r);if(d===-1)throw Error(`Mask token (${n}) not found in text.`);const h=a[l][d],_=await Mn(new j("float32",at(h.data),h.dims),t),p=_[0].tolist(),w=_[1].tolist();o.push(w.map((v,y)=>{const x=c.slice();return x[d]=v,{score:p[y],token:Number(v),token_str:this.tokenizer.decode([v]),sequence:this.tokenizer.decode(x,{skip_special_tokens:!0})}}))}return Array.isArray(e)?o:o[0]}},Bu=class extends qe{constructor(){super(...arguments);T(this,"_default_generation_config",{max_new_tokens:256});T(this,"_key","generated_text")}async _call(t,r={}){Array.isArray(t)||(t=[t]),this.model.config.prefix&&(t=t.map(l=>this.model.config.prefix+l));const n=this.model.config.task_specific_params;n&&n[this.task]&&n[this.task].prefix&&(t=t.map(l=>n[this.task].prefix+l));const s=this.tokenizer,a={padding:!0,truncation:!0};let o;this.task==="translation"&&"_build_translation_inputs"in s?o=s._build_translation_inputs(t,a,r):o=s(t,a);const i=await this.model.generate({...o,...this._default_generation_config,...r});return s.batch_decode(i,{skip_special_tokens:!0}).map(l=>({[this._key]:l}))}},SN=class extends Bu{constructor(){super(...arguments);T(this,"_key","summary_text")}},PN=class extends Bu{constructor(){super(...arguments);T(this,"_key","translation_text")}};function hw(e){return Array.isArray(e)&&e.every(t=>"role"in t&&"content"in t)}var FN=class extends qe{constructor(){super(...arguments);T(this,"_default_generation_config",{max_new_tokens:256})}async _call(t,r={}){const{add_special_tokens:n,return_full_text:s,tools:a,documents:o,chat_template:i,tokenizer_encode_kwargs:l,...c}=r;let d=!1,h=!1,_=n??(this.tokenizer.add_bos_token||this.tokenizer.add_eos_token)??!1,p=l,w;if(typeof t=="string")w=t=[t];else if(Array.isArray(t)&&t.every(C=>typeof C=="string"))d=!0,w=t;else{if(hw(t))t=[t];else if(Array.isArray(t)&&t.every(hw))d=!0;else throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");h=!0;const C={tokenize:!1,add_generation_prompt:!0,...rt({tools:a,documents:o,chat_template:i},["tools","documents","chat_template"]),...p};w=t.map(O=>this.tokenizer.apply_chat_template(O,C)),_=!1,p=void 0}const v=h?!1:s??!0;this.tokenizer.padding_side="left";const y=this.tokenizer(w,{add_special_tokens:_,padding:!0,truncation:!0,...p}),x=await this.model.generate({...y,...this._default_generation_config,...c}),k=this.tokenizer.batch_decode(x,{skip_special_tokens:!0});let A;!v&&y.input_ids.dims.at(-1)>0&&(A=this.tokenizer.batch_decode(y.input_ids,{skip_special_tokens:!0}).map(C=>C.length));const S=Array.from({length:t.length},C=>[]);for(let C=0;C<k.length;++C){const O=Math.floor(C/x.dims[0]*t.length);A&&(k[C]=k[C].slice(A[O])),S[O].push({generated_text:h?[...t[O],{role:"assistant",content:k[C]}]:k[C]})}return!d&&S.length===1?S[0]:S}},IN=class extends qe{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([t,r])=>[t.toLowerCase(),r])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(he.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&&(he.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,t,{hypothesis_template:r="This example is {}.",multi_label:n=!1}={}){const s=Array.isArray(e);s||(e=[e]),Array.isArray(t)||(t=[t]);const a=t.map(l=>r.replace("{}",l)),o=n||t.length===1,i=[];for(const l of e){const c=[];for(const _ of a){const p=this.tokenizer(l,{text_pair:_,padding:!0,truncation:!0}),w=await this.model(p);o?c.push([w.logits.data[this.contradiction_id],w.logits.data[this.entailment_id]]):c.push(w.logits.data[this.entailment_id])}const h=(o?c.map(_=>at(_)[1]):at(c)).map((_,p)=>[_,p]).sort((_,p)=>p[0]-_[0]);i.push({sequence:l,labels:h.map(_=>t[_[1]]),scores:h.map(_=>_[0])})}return s?i:i[0]}},LN=class extends qe{async _call(e,{top_k:t=5}={}){const r=this.processor.feature_extractor.config.sampling_rate,n=await jn(e,r),s=this.model.config.id2label,a=[];for(const o of n){const i=await this.processor(o),c=(await this.model(i)).logits[0],d=await Mn(new j("float32",at(c.data),c.dims),t),h=d[0].tolist(),p=d[1].tolist().map((w,v)=>({label:s?s[w]:`LABEL_${w}`,score:h[v]}));a.push(p)}return Array.isArray(e)?a:a[0]}},ON=class extends qe{async _call(e,t,{hypothesis_template:r="This is a sound of {}."}={}){const n=!Array.isArray(e);n&&(e=[e]);const s=t.map(c=>r.replace("{}",c)),a=this.tokenizer(s,{padding:!0,truncation:!0}),o=this.processor.feature_extractor.config.sampling_rate,i=await jn(e,o),l=[];for(const c of i){const d=await this.processor(c),h=await this.model({...a,...d}),_=at(h.logits_per_audio.data);l.push([..._].map((p,w)=>({score:p,label:t[w]})))}return n?l[0]:l}},NN=class extends qe{constructor(){super(...arguments);T(this,"_default_generation_config",{})}async _call(t,r={}){switch(r={...this._default_generation_config,...r},this.model.config.model_type){case"whisper":case"lite-whisper":return this._call_whisper(t,r);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":case"parakeet_ctc":return this._call_wav2vec2(t,r);case"moonshine":return this._call_moonshine(t,r);case"cohere_asr":return this._call_cohere_asr(t,r);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(t,r){r.language&&he.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),r.task&&he.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');const n=!Array.isArray(t),s=n?[t]:t,a=this.processor.feature_extractor.config.sampling_rate,o=await jn(s,a),i=[];for(const l of o){const c=await this.processor(l),h=(await this.model(c)).logits[0],_=[];for(const w of h)_.push(Qe(w.data)[1]);const p=this.tokenizer.decode(_,{skip_special_tokens:!0}).trim();i.push({text:p})}return n?i[0]:i}async _call_whisper(t,r){const n=r.return_timestamps??!1,s=r.chunk_length_s??0,a=r.force_full_sequences??!1;let o=r.stride_length_s??null;const i={...r};n==="word"&&(i.return_token_timestamps=!0,i.return_timestamps=!0);const l=!Array.isArray(t),c=l?[t]:t,d=this.processor.feature_extractor.config,h=d.chunk_length/this.model.config.max_source_positions,_=d.hop_length,p=d.sampling_rate,w=await jn(c,p),v=[];for(const y of w){let x=[];if(s>0){if(o===null)o=s/6;else if(s<=o)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");const S=p*s,C=p*o,O=S-2*C;let M=0;for(;;){const V=M+S,G=y.subarray(M,V),U=await this.processor(G),J=M===0,Q=V>=y.length;if(x.push({stride:[G.length,J?0:C,Q?0:C],input_features:U.input_features,is_last:Q}),Q)break;M+=O}}else x=[{stride:[y.length,0,0],input_features:(await this.processor(y)).input_features,is_last:!0}];for(const S of x){i.num_frames=Math.floor(S.stride[0]/_);const C=await this.model.generate({inputs:S.input_features,...i});if(n==="word"){const O=C.sequences.tolist()[0],M=C.token_timestamps.tolist()[0],V=this.tokenizer.timestamp_begin,G=Math.max(O.findIndex(U=>Number(U)>=V),0);S.tokens=O.slice(G),S.token_timestamps=M.slice(G).map(U=>ds(U,2))}else S.tokens=C[0].tolist();S.stride=S.stride.map(O=>O/p)}const[k,A]=this.tokenizer._decode_asr(x,{time_precision:h,return_timestamps:n,force_full_sequences:a});v.push({text:k,...A})}return l?v[0]:v}async _call_moonshine(t,r){const n=!Array.isArray(t),s=n?[t]:t,a=this.processor.feature_extractor.config.sampling_rate,o=await jn(s,a),i=[];for(const l of o){const c=await this.processor(l),d=Math.floor(l.length/a)*6,h=await this.model.generate({max_new_tokens:d,...r,...c}),_=this.tokenizer.batch_decode(h,{skip_special_tokens:!0})[0];i.push({text:_})}return n?i[0]:i}async _call_cohere_asr(t,r){const n=!Array.isArray(t),s=n?[t]:t,a=this.processor.feature_extractor,o=a.config.sampling_rate,i=await jn(s,o),l=r.language??"en",c=this.processor.get_decoder_prompt_ids(l),d=[];for(const h of i){const _=a.split_audio(h),p=[];for(const v of _){const y=await this.processor(v),x=await this.model.generate({...y,decoder_input_ids:c,...r}),k=this.tokenizer.decode(x[0].tolist(),{skip_special_tokens:!0}).trim();p.push(k)}const w=this.processor.constructor.join_chunks(p,l);d.push({text:w})}return n?d[0]:d}},DN=class extends qe{constructor(t){super(t);T(this,"DEFAULT_VOCODER_ID","Xenova/speecht5_hifigan");this.vocoder=t.vocoder??null}async _prepare_speaker_embeddings(t,r){if((typeof t=="string"||t instanceof URL)&&(t=new Float32Array(await(await ve.fetch(t)).arrayBuffer())),t instanceof Float32Array)t=new j("float32",t,[t.length]);else if(!(t instanceof j))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");if(r>1){if(t.dims[0]===1)t=t.repeat(r,1);else if(t.dims[0]!==r)throw new Error(`Expected speaker embeddings batch size to be 1 or ${r}, but got ${t.dims[0]}.`)}return t}_postprocess_waveform(t,r,n,s=null){const a=r.data,[o,i]=r.dims,l=s?s.data:null,c=[];for(let d=0;d<o;++d){const h=l?Math.min(Math.ceil(l[d]),i):i,_=d*i;c.push(new mT(a.slice(_,_+h),n))}return Array.isArray(t)?c:c[0]}async _call(t,r){return this.processor?this._call_text_to_spectrogram(t,r):this.model.config.model_type==="supertonic"?this._call_supertonic(t,r):this._call_text_to_waveform(t)}async _call_supertonic(t,{speaker_embeddings:r,num_inference_steps:n,speed:s}){if(!r)throw new Error("Speaker embeddings must be provided for Supertonic models.");const{sampling_rate:a,style_dim:o}=this.model.config,i=this.tokenizer(t,{padding:!0,truncation:!0}),l=i.input_ids.dims[0];r=await this._prepare_speaker_embeddings(r,l),r=r.view(l,-1,o);const{waveform:c,durations:d}=await this.model.generate_speech({...i,style:r,num_inference_steps:n,speed:s});return this._postprocess_waveform(t,c,a,d)}async _call_text_to_waveform(t){const r=this.tokenizer(t,{padding:!0,truncation:!0}),{waveform:n}=await this.model(r),s=this.model.config.sampling_rate;return this._postprocess_waveform(t,n,s)}async _call_text_to_spectrogram(t,{speaker_embeddings:r}){this.vocoder||(he.info("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await Es.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"}));const{input_ids:n}=this.tokenizer(t,{padding:!0,truncation:!0}),s=n.dims[0];r=await this._prepare_speaker_embeddings(r,s),r=r.view(s,-1);const{waveform:a}=await this.model.generate_speech(n,r,{vocoder:this.vocoder}),o=this.processor.feature_extractor.config.sampling_rate;return this._postprocess_waveform(t,a,o)}},zN=class extends qe{async _call(e,t={}){const r=Array.isArray(e),n=await Xt(e),{pixel_values:s}=await this.processor(n),a=[];for(const o of s){o.dims=[1,...o.dims];const i=await this.model.generate({inputs:o,...t}),l=this.tokenizer.batch_decode(i,{skip_special_tokens:!0}).map(c=>({generated_text:c.trim()}));a.push(l)}return r?a:a[0]}},BN=class extends qe{async _call(e,{top_k:t=5}={}){const r=await Xt(e),{pixel_values:n}=await this.processor(r),s=await this.model({pixel_values:n}),{id2label:a}=this.model.config,o=[];for(const i of s.logits){const l=await Mn(new j("float32",at(i.data),i.dims),t),c=l[0].tolist(),h=l[1].tolist().map((_,p)=>({label:a?a[_]:`LABEL_${_}`,score:c[p]}));o.push(h)}return Array.isArray(e)?o:o[0]}},fw={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"},_w=class extends qe{async _call(e,{threshold:t=.5,mask_threshold:r=.5,overlap_mask_area_threshold:n=.8,label_ids_to_fuse:s=null,target_sizes:a=null,subtask:o=null}={}){if(Array.isArray(e)&&e.length!==1)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");const l=await Xt(e),c=l.map(x=>[x.height,x.width]),d=await this.processor(l),{inputNames:h,outputNames:_}=this.model.sessions.model;if(!h.includes("pixel_values")){if(h.length!==1)throw Error(`Expected a single input name, but got ${h.length} inputs: ${h}.`);const x=h[0];if(x in d)throw Error(`Input name ${x} already exists in the inputs.`);d[x]=d.pixel_values}const p=await this.model(d);let w=null;if(o!==null)w=fw[o];else if(this.processor.image_processor){for(const[x,k]of Object.entries(fw))if(k in this.processor.image_processor){w=this.processor.image_processor[k].bind(this.processor.image_processor),o=x;break}}const v=this.model.config.id2label,y=[];if(o)if(o==="panoptic"||o==="instance"){const x=w(p,t,r,n,s,a??c)[0],k=x.segmentation;for(const A of x.segments_info){const S=new Uint8ClampedArray(k.data.length);for(let O=0;O<k.data.length;++O)k.data[O]===A.id&&(S[O]=255);const C=new Ht(S,k.dims[1],k.dims[0],1);y.push({score:A.score,label:v[A.label_id],mask:C})}}else if(o==="semantic"){const{segmentation:x,labels:k}=w(p,a??c)[0];for(const A of k){const S=new Uint8ClampedArray(x.data.length);for(let O=0;O<x.data.length;++O)x.data[O]===A&&(S[O]=255);const C=new Ht(S,x.dims[1],x.dims[0],1);y.push({score:null,label:v[A],mask:C})}}else throw Error(`Subtask ${o} not supported.`);else{const k=p[_[0]];for(let A=0;A<c.length;++A){const S=c[A],C=k[A];C.data.some(M=>M<-1e-5||M>1+1e-5)&&C.sigmoid_();const O=await Ht.fromTensor(C.mul_(255).to("uint8")).resize(S[1],S[0]);y.push({label:null,score:null,mask:O})}}return y}},RN=class extends _w{async _call(e,t={}){const r=await Xt(e),n=await super._call(e,t),s=r.map((a,o)=>{const i=a.clone();return i.putAlpha(n[o].mask),i});return Array.isArray(e)?s:s[0]}},$N=class extends qe{async _call(e,t,{hypothesis_template:r="This is a photo of {}"}={}){const n=Array.isArray(e),s=await Xt(e),a=t.map(h=>r.replace("{}",h)),o=this.tokenizer(a,{padding:this.model.config.model_type==="siglip"?"max_length":!0,truncation:!0}),{pixel_values:i}=await this.processor(s),l=await this.model({...o,pixel_values:i}),c=this.model.config.model_type==="siglip"?h=>h.sigmoid().data:h=>at(h.data),d=[];for(const h of l.logits_per_image){const p=[...c(h)].map((w,v)=>({score:w,label:t[v]}));p.sort((w,v)=>v.score-w.score),d.push(p)}return n?d:d[0]}},GN=class extends qe{async _call(e,{threshold:t=.9,percentage:r=!1}={}){const n=Array.isArray(e);if(n&&e.length!==1)throw Error("Object detection pipeline currently only supports a batch size of 1.");const s=await Xt(e),a=r?null:s.map(_=>[_.height,_.width]),{pixel_values:o,pixel_mask:i}=await this.processor(s),l=await this.model({pixel_values:o,pixel_mask:i}),c=this.processor.image_processor.post_process_object_detection(l,t,a),{id2label:d}=this.model.config,h=c.map(_=>_.boxes.map((p,w)=>({score:_.scores[w],label:d[_.classes[w]],box:zu(p,!r)})));return n?h:h[0]}},VN=class extends qe{async _call(e,t,{threshold:r=.1,top_k:n=null,percentage:s=!1}={}){const a=Array.isArray(e),o=await Xt(e),i=this.tokenizer(t,{padding:!0,truncation:!0}),l=await this.processor(o),c=[];for(let d=0;d<o.length;++d){const h=o[d],_=s?null:[[h.height,h.width]],p=l.pixel_values[d].unsqueeze_(0),w=await this.model({...i,pixel_values:p});let v;if("post_process_grounded_object_detection"in this.processor){const y=this.processor.post_process_grounded_object_detection(w,i.input_ids,{box_threshold:r,text_threshold:r,target_sizes:_})[0];v=y.boxes.map((x,k)=>({score:y.scores[k],label:y.labels[k],box:zu(x,!s)}))}else{const y=this.processor.image_processor.post_process_object_detection(w,r,_,!0)[0];v=y.boxes.map((x,k)=>({score:y.scores[k],label:t[y.classes[k]],box:zu(x,!s)}))}v.sort((y,x)=>x.score-y.score),n!==null&&(v=v.slice(0,n)),c.push(v)}return a?c:c[0]}},UN=class extends qe{constructor(){super(...arguments);T(this,"_default_generation_config",{max_new_tokens:256})}async _call(t,r,n={}){if(Array.isArray(t)){if(t.length!==1)throw Error("Document Question Answering pipeline currently only supports a batch size of 1.");t=t[0]}const s=(await Xt(t))[0],{pixel_values:a}=await this.processor(s),o=`<s_docvqa><s_question>${r}</s_question><s_answer>`,i=this.tokenizer(o,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,l=await this.model.generate({inputs:a,max_length:this.model.config.decoder.max_position_embeddings,decoder_input_ids:i,...this._default_generation_config,...n}),d=this.tokenizer.batch_decode(l)[0].match(/<s_answer>(.*?)<\/s_answer>/);let h=null;return d&&d.length>=2&&(h=d[1].trim()),[{answer:h}]}},jN=class extends qe{async _call(e){const t=await Xt(e),r=await this.processor(t),n=await this.model(r),s=[];for(const a of n.reconstruction){const o=a.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");s.push(Ht.fromTensor(o))}return Array.isArray(e)?s:s[0]}},WN=class extends qe{async _call(e){const t=await Xt(e),r=await this.processor(t),{predicted_depth:n}=await this.model(r),s=[];for(let a=0;a<t.length;++a){const o=n[a],[i,l]=o.dims.slice(-2),[c,d]=t[a].size,h=(await qt(o.view(1,1,i,l),{size:[d,c],mode:"bilinear"})).view(d,c),_=h.min().item(),p=h.max().item(),w=h.sub(_).div_(p-_).mul_(255).to("uint8").unsqueeze(0),v=Ht.fromTensor(w);s.push({predicted_depth:h,depth:v})}return Array.isArray(e)?s:s[0]}},qN=class extends qe{async _call(e,{pooling:t="none",normalize:r=!1,quantize:n=!1,precision:s="binary"}={}){const a=this.tokenizer(e,{padding:!0,truncation:!0}),o=await this.model(a);let i=o.last_hidden_state??o.logits??o.token_embeddings;switch(t){case"none":break;case"mean":i=ek(i,a.attention_mask);break;case"first_token":case"cls":i=i.slice(null,0);break;case"last_token":case"eos":i=i.slice(null,-1);break;default:throw Error(`Pooling method '${t}' not supported.`)}return r&&(i=i.normalize(2,-1)),n&&(i=nk(i,s)),i}},HN=class extends qe{async _call(e,{pool:t=null}={}){const r=await Xt(e),{pixel_values:n}=await this.processor(r),s=await this.model({pixel_values:n});let a;if(t){if(!("pooler_output"in s))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");a=s.pooler_output}else a=s.last_hidden_state??s.logits??s.image_embeds;return a}},no=Object.freeze({"text-classification":{pipeline:xN,model:lw,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{pipeline:kN,model:oN,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{pipeline:AN,model:hN,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{pipeline:CN,model:dN,default:{model:"onnx-community/ettin-encoder-32m-ONNX",dtype:"fp32"},type:"text"},summarization:{pipeline:SN,model:Du,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{pipeline:PN,model:Du,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{pipeline:Bu,model:Du,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{pipeline:FN,model:uN,default:{model:"onnx-community/Qwen3-0.6B-ONNX",dtype:"q4"},type:"text"},"zero-shot-classification":{pipeline:IN,model:lw,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:LN,model:wN,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{pipeline:ON,model:Es,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{pipeline:NN,model:[iN,gN],default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{pipeline:DN,model:[cN,lN],default:{model:"onnx-community/Supertonic-TTS-ONNX",dtype:"fp32"},type:"text"},"image-to-text":{pipeline:zN,model:fN,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:BN,model:_N,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:_w,model:[cw,uw,dw],default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:RN,model:[cw,uw,dw],default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{pipeline:$N,model:Es,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:GN,model:pN,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{pipeline:VN,model:mN,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{pipeline:UN,model:vN,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:jN,model:yN,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:WN,model:bN,default:{model:"onnx-community/depth-anything-v2-small"},type:"image"},"feature-extraction":{pipeline:qN,model:Es,default:{model:"onnx-community/all-MiniLM-L6-v2-ONNX",dtype:"fp32"},type:"text"},"image-feature-extraction":{pipeline:HN,model:[MN,Es],default:{model:"onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX",dtype:"fp32"},type:"image"}}),pw=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function QN(e){if(!e)throw new Error("modelId is required");return(await cs(e,_s,{})).exists?[_s]:[]}async function XN(e,{config:t=null,dtype:r=null,device:n=null,model_file_name:s=null,include_tokenizer:a=!0,include_processor:o=!0}={}){const i=await em(e,{config:t,dtype:r,device:n,model_file_name:s});if(a){const l=await q_(e);i.push(...l)}if(o){const l=await QN(e);i.push(...l)}return i}async function YN(e,t,r={}){e=pw[e]??e;const n=no[e];if(!n)throw new Error(`Unsupported pipeline task: ${e}. Must be one of [${Object.keys(no).join(", ")}]`);const{type:s}=n,i=await XN(t,{...r,include_tokenizer:s!=="audio"&&s!=="image",include_processor:s!=="text"});if(e==="text-generation"){const l=await Zp(t,r),c=Kp(l),d=Q2(c);if(d){const h=Object.values(d).map(_=>`onnx/${_}`);return i.filter(_=>!_.startsWith("onnx/")||h.some(p=>_.startsWith(p)))}}return i}async function JN(e,t=null,{progress_callback:r=null,config:n=null,cache_dir:s=null,local_files_only:a=!1,revision:o="main",device:i=null,dtype:l=null,subfolder:c="onnx",use_external_data_format:d=null,model_file_name:h=null,session_options:_={}}={}){e=pw[e]??e;const p=no[e.split("_",1)[0]];if(!p)throw Error(`Unsupported pipeline: ${e}. Must be one of [${Object.keys(no)}]`);t||(t=p.default.model,he.info(`No model specified. Using default model: "${t}".`),!l&&p.default.dtype&&(l=p.default.dtype));const w=await YN(e,t,{device:i,dtype:l});let v={};if(r)try{(await Promise.all(w.map(async J=>cs(t,J)))).forEach((J,Q)=>{J.exists&&(v[w[Q]]={loaded:0,total:J.size??0})})}catch(U){he.warn(`Unable to fetch model file metadata for total progress tracking: ${U}`)}const y={progress_callback:r?new la(r,v):void 0,config:n,cache_dir:s,local_files_only:a,revision:o,device:i,dtype:l,subfolder:c,use_external_data_format:d,model_file_name:h,session_options:_},x=w.includes("tokenizer.json"),k=w.includes("preprocessor_config.json"),A=p.model;let S;if(Array.isArray(A)){const U=n??await ps.from_pretrained(t,y),{model_type:J}=U,Q=A.find(B=>B.supports(J));if(!Q)throw Error(`Unsupported model type "${J}" for task "${e}". None of the candidate model classes support this type.`);S=Q.from_pretrained(t,{...y,config:U})}else S=A.from_pretrained(t,y);const[C,O,M]=await Promise.all([x?Te.from_pretrained(t,y):null,k?v2.from_pretrained(t,y):null,S]),V={task:e,model:M};C&&(V.tokenizer=C),O&&(V.processor=O),Pr(r,{status:"ready",task:e,model:t});const G=p.pipeline;return new G(V)}pe.IS_PROCESS_AVAILABLE;let so;self.addEventListener("message",async({data:e})=>{if(!["load","transcribe"].includes(e==null?void 0:e.type))return;const{id:t,audio:r}=e;try{so||(so=JN("automatic-speech-recognition","onnx-community/whisper-medium-ONNX",{dtype:"q8",device:"wasm",progress_callback:a=>self.postMessage({type:"progress",id:t,progress:{status:a.status,file:a.file,progress:a.progress}})}));const n=await so;if(e.type==="load"){self.postMessage({type:"ready",id:t});return}const s=await n(new Float32Array(r),{chunk_length_s:30,stride_length_s:5,num_beams:1,condition_on_prev_tokens:!1});self.postMessage({type:"result",id:t,text:String((s==null?void 0:s.text)||"").trim()})}catch(n){so=null,self.postMessage({type:"error",id:t,message:(n==null?void 0:n.message)||"Local Whisper could not transcribe this audio."})}})})();
|