@huggingface/transformers 3.0.0-alpha.20 → 3.0.0-alpha.21
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/README.md +3 -2
- package/dist/ort-wasm-simd-threaded.jsep.wasm +0 -0
- package/dist/transformers.cjs +129 -467
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.js +526 -861
- package/dist/transformers.js.map +1 -1
- package/dist/transformers.min.cjs +11 -11
- package/dist/transformers.min.cjs.map +1 -1
- package/dist/transformers.min.js +10 -10
- package/dist/transformers.min.js.map +1 -1
- package/dist/transformers.min.mjs +5 -5
- package/dist/transformers.min.mjs.map +1 -1
- package/dist/transformers.mjs +133 -468
- package/dist/transformers.mjs.map +1 -1
- package/package.json +2 -2
- package/src/configs.js +1 -0
- package/src/env.js +1 -1
- package/src/models.js +84 -453
- package/src/utils/tensor.js +37 -13
- package/types/configs.d.ts.map +1 -1
- package/types/models.d.ts +15 -294
- package/types/models.d.ts.map +1 -1
- package/types/pipelines.d.ts +1 -2
- package/types/pipelines.d.ts.map +1 -1
- package/types/utils/tensor.d.ts +14 -0
- package/types/utils/tensor.d.ts.map +1 -1
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
\*************************************/()=>{},"./node_modules/@huggingface/jinja/dist/index.js":
|
|
20
20
|
/*!*******************************************************!*\
|
|
21
21
|
!*** ./node_modules/@huggingface/jinja/dist/index.js ***!
|
|
22
|
-
\*******************************************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{Environment:()=>Y,Interpreter:()=>J,Template:()=>ee,parse:()=>B,tokenize:()=>d});var s=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",BooleanLiteral:"BooleanLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",OpenCurlyBracket:"OpenCurlyBracket",CloseCurlyBracket:"CloseCurlyBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Set:"Set",If:"If",For:"For",In:"In",Is:"Is",NotIn:"NotIn",Else:"Else",EndIf:"EndIf",ElseIf:"ElseIf",EndFor:"EndFor",And:"And",Or:"Or",Not:"UnaryOperator",Macro:"Macro",EndMacro:"EndMacro"}),r=Object.freeze({set:s.Set,for:s.For,in:s.In,is:s.Is,if:s.If,else:s.Else,endif:s.EndIf,elif:s.ElseIf,endfor:s.EndFor,and:s.And,or:s.Or,not:s.Not,"not in":s.NotIn,macro:s.Macro,endmacro:s.EndMacro,true:s.BooleanLiteral,false:s.BooleanLiteral,True:s.BooleanLiteral,False:s.BooleanLiteral}),o=class{constructor(e,t){this.value=e,this.type=t}};function i(e){return/\w/.test(e)}function a(e){return/[0-9]/.test(e)}var l=[["{%",s.OpenStatement],["%}",s.CloseStatement],["{{",s.OpenExpression],["}}",s.CloseExpression],["(",s.OpenParen],[")",s.CloseParen],["{",s.OpenCurlyBracket],["}",s.CloseCurlyBracket],["[",s.OpenSquareBracket],["]",s.CloseSquareBracket],[",",s.Comma],[".",s.Dot],[":",s.Colon],["|",s.Pipe],["<=",s.ComparisonBinaryOperator],[">=",s.ComparisonBinaryOperator],["==",s.ComparisonBinaryOperator],["!=",s.ComparisonBinaryOperator],["<",s.ComparisonBinaryOperator],[">",s.ComparisonBinaryOperator],["+",s.AdditiveBinaryOperator],["-",s.AdditiveBinaryOperator],["*",s.MultiplicativeBinaryOperator],["/",s.MultiplicativeBinaryOperator],["%",s.MultiplicativeBinaryOperator],["=",s.Equals]],c=new Map([["n","\n"],["t","\t"],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function d(e,t={}){const n=[],d=function(e,t={}){return e.endsWith("\n")&&(e=e.slice(0,-1)),e=e.replace(/{#.*?#}/gs,"{##}"),t.lstrip_blocks&&(e=e.replace(/^[ \t]*({[#%])/gm,"$1")),t.trim_blocks&&(e=e.replace(/([#%]})\n/g,"$1")),e.replace(/{##}/g,"").replace(/-%}\s*/g,"%}").replace(/\s*{%-/g,"{%").replace(/-}}\s*/g,"}}").replace(/\s*{{-/g,"{{")}(e,t);let u=0;const p=e=>{let t="";for(;e(d[u]);)if("\\"!==d[u]){if(t+=d[u++],u>=d.length)throw new SyntaxError("Unexpected end of input")}else{if(++u,u>=d.length)throw new SyntaxError("Unexpected end of input");const e=d[u++],n=c.get(e);if(void 0===n)throw new SyntaxError(`Unexpected escaped character: ${e}`);t+=n}return t};e:for(;u<d.length;){const e=n.at(-1)?.type;if(void 0===e||e===s.CloseStatement||e===s.CloseExpression){let e="";for(;u<d.length&&("{"!==d[u]||"%"!==d[u+1]&&"{"!==d[u+1]);)e+=d[u++];if(e.length>0){n.push(new o(e,s.Text));continue}}p((e=>/\s/.test(e)));const t=d[u];if("-"===t||"+"===t){const e=n.at(-1)?.type;if(e===s.Text||void 0===e)throw new SyntaxError(`Unexpected character: ${t}`);switch(e){case s.Identifier:case s.NumericLiteral:case s.BooleanLiteral:case s.StringLiteral:case s.CloseParen:case s.CloseSquareBracket:break;default:{++u;const e=p(a);n.push(new o(`${t}${e}`,e.length>0?s.NumericLiteral:s.UnaryOperator));continue}}}for(const[e,t]of l){if(d.slice(u,u+e.length)===e){n.push(new o(e,t)),u+=e.length;continue e}}if("'"!==t&&'"'!==t)if(a(t)){const e=p(a);n.push(new o(e,s.NumericLiteral))}else{if(!i(t))throw new SyntaxError(`Unexpected character: ${t}`);{const e=p(i),t=Object.hasOwn(r,e)?r[e]:s.Identifier;t===s.In&&n.at(-1)?.type===s.Not?(n.pop(),n.push(new o("not in",s.NotIn))):n.push(new o(e,t))}}else{++u;const e=p((e=>e!==t));n.push(new o(e,s.StringLiteral)),++u}}return n}var u=class{type="Statement"},p=class extends u{constructor(e){super(),this.body=e}type="Program"},h=class extends u{constructor(e,t,n){super(),this.test=e,this.body=t,this.alternate=n}type="If"},_=class extends u{constructor(e,t,n,s){super(),this.loopvar=e,this.iterable=t,this.body=n,this.defaultBlock=s}type="For"},m=class extends u{constructor(e,t){super(),this.assignee=e,this.value=t}type="Set"},f=class extends u{constructor(e,t,n){super(),this.name=e,this.args=t,this.body=n}type="Macro"},g=class extends u{type="Expression"},w=class extends g{constructor(e,t,n){super(),this.object=e,this.property=t,this.computed=n}type="MemberExpression"},M=class extends g{constructor(e,t){super(),this.callee=e,this.args=t}type="CallExpression"},b=class extends g{constructor(e){super(),this.value=e}type="Identifier"},y=class extends g{constructor(e){super(),this.value=e}type="Literal"},x=class extends y{type="NumericLiteral"},k=class extends y{type="StringLiteral"},T=class extends y{type="BooleanLiteral"},v=class extends y{type="ArrayLiteral"},F=class extends y{type="TupleLiteral"},C=class extends y{type="ObjectLiteral"},P=class extends g{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n}type="BinaryExpression"},S=class extends g{constructor(e,t){super(),this.operand=e,this.filter=t}type="FilterExpression"},A=class extends g{constructor(e,t){super(),this.iterable=e,this.test=t}type="SelectExpression"},E=class extends g{constructor(e,t,n){super(),this.operand=e,this.negate=t,this.test=n}type="TestExpression"},z=class extends g{constructor(e,t){super(),this.operator=e,this.argument=t}type="UnaryExpression"},L=class extends g{constructor(e=void 0,t=void 0,n=void 0){super(),this.start=e,this.stop=t,this.step=n}type="SliceExpression"},I=class extends g{constructor(e,t){super(),this.key=e,this.value=t}type="KeywordArgumentExpression"};function B(e){const t=new p([]);let n=0;function r(t,s){const r=e[n++];if(!r||r.type!==t)throw new Error(`Parser Error: ${s}. ${r.type} !== ${t}.`);return r}function o(){switch(e[n].type){case s.Text:return new k(r(s.Text,"Expected text token").value);case s.OpenStatement:return function(){let t;switch(r(s.OpenStatement,"Expected opening statement token"),e[n].type){case s.Set:++n,t=l(),r(s.CloseStatement,"Expected closing statement token");break;case s.If:++n,t=c(),r(s.OpenStatement,"Expected {% token"),r(s.EndIf,"Expected endif token"),r(s.CloseStatement,"Expected %} token");break;case s.Macro:++n,t=function(){const e=$();if("Identifier"!==e.type)throw new SyntaxError("Expected identifier following macro statement");const t=D();r(s.CloseStatement,"Expected closing statement token");const n=[];for(;i(s.OpenStatement,s.EndMacro);)n.push(o());return new f(e,t,n)}(),r(s.OpenStatement,"Expected {% token"),r(s.EndMacro,"Expected endmacro token"),r(s.CloseStatement,"Expected %} token");break;case s.For:++n,t=function(){const e=d(!0);if(!(e instanceof b||e instanceof F))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${e.type} instead`);r(s.In,"Expected `in` keyword following loop variable");const t=u();r(s.CloseStatement,"Expected closing statement token");const l=[];for(;i(s.OpenStatement,s.EndFor)&&i(s.OpenStatement,s.Else);)l.push(o());const c=[];if(a(s.OpenStatement,s.Else))for(++n,++n,r(s.CloseStatement,"Expected closing statement token");i(s.OpenStatement,s.EndFor);)c.push(o());return new _(e,t,l,c)}(),r(s.OpenStatement,"Expected {% token"),r(s.EndFor,"Expected endfor token"),r(s.CloseStatement,"Expected %} token");break;default:throw new SyntaxError(`Unknown statement type: ${e[n].type}`)}return t}();case s.OpenExpression:return function(){r(s.OpenExpression,"Expected opening expression token");const e=u();return r(s.CloseExpression,"Expected closing expression token"),e}();default:throw new SyntaxError(`Unexpected token type: ${e[n].type}`)}}function i(...t){return n+t.length<=e.length&&t.some(((t,s)=>t!==e[n+s].type))}function a(...t){return n+t.length<=e.length&&t.every(((t,s)=>t===e[n+s].type))}function l(){const e=u();if(a(s.Equals)){++n;const t=l();return new m(e,t)}return e}function c(){const t=u();r(s.CloseStatement,"Expected closing statement token");const i=[],l=[];for(;e[n]?.type!==s.OpenStatement||e[n+1]?.type!==s.ElseIf&&e[n+1]?.type!==s.Else&&e[n+1]?.type!==s.EndIf;)i.push(o());if(e[n]?.type===s.OpenStatement&&e[n+1]?.type!==s.EndIf)if(++n,a(s.ElseIf))r(s.ElseIf,"Expected elseif token"),l.push(c());else for(r(s.Else,"Expected else token"),r(s.CloseStatement,"Expected closing statement token");e[n]?.type!==s.OpenStatement||e[n+1]?.type!==s.EndIf;)l.push(o());return new h(t,i,l)}function d(e=!1){const t=e?$:u,r=[t()],o=a(s.Comma);for(;o&&(++n,r.push(t()),a(s.Comma)););return o?new F(r):r[0]}function u(){return function(){const e=g();if(a(s.If)){++n;const t=g();if(a(s.Else)){++n;const s=g();return new h(t,[e],[s])}return new A(e,t)}return e}()}function g(){let t=y();for(;a(s.Or);){const s=e[n];++n;const r=y();t=new P(s,t,r)}return t}function y(){let t=B();for(;a(s.And);){const s=e[n];++n;const r=B();t=new P(s,t,r)}return t}function B(){let t;for(;a(s.Not);){const s=e[n];++n;const r=B();t=new z(s,r)}return t??function(){let t=N();for(;a(s.ComparisonBinaryOperator)||a(s.In)||a(s.NotIn);){const s=e[n];++n;const r=N();t=new P(s,t,r)}return t}()}function N(){let t=R();for(;a(s.AdditiveBinaryOperator);){const s=e[n];++n;const r=R();t=new P(s,t,r)}return t}function O(){const t=function(){let t=$();for(;a(s.Dot)||a(s.OpenSquareBracket);){const o=e[n];let i;++n;const a=o.type!==s.Dot;if(a)i=V(),r(s.CloseSquareBracket,"Expected closing square bracket");else if(i=$(),"Identifier"!==i.type)throw new SyntaxError("Expected identifier following dot operator");t=new w(t,i,a)}return t}();return a(s.OpenParen)?j(t):t}function j(e){let t=new M(e,D());return a(s.OpenParen)&&(t=j(t)),t}function D(){r(s.OpenParen,"Expected opening parenthesis for arguments list");const e=function(){const e=[];for(;!a(s.CloseParen);){let t=u();if(a(s.Equals)){if(++n,!(t instanceof b))throw new SyntaxError("Expected identifier for keyword argument");const e=u();t=new I(t,e)}e.push(t),a(s.Comma)&&++n}return e}();return r(s.CloseParen,"Expected closing parenthesis for arguments list"),e}function V(){const e=[];let t=!1;for(;!a(s.CloseSquareBracket);)a(s.Colon)?(e.push(void 0),++n,t=!0):(e.push(u()),a(s.Colon)&&(++n,t=!0));if(0===e.length)throw new SyntaxError("Expected at least one argument for member/slice expression");if(t){if(e.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new L(...e)}return e[0]}function R(){let t=G();for(;a(s.MultiplicativeBinaryOperator);){const s=e[n];++n;const r=G();t=new P(s,t,r)}return t}function G(){let e=function(){let e=O();for(;a(s.Pipe);){++n;let t=$();if(!(t instanceof b))throw new SyntaxError("Expected identifier for the filter");a(s.OpenParen)&&(t=j(t)),e=new S(e,t)}return e}();for(;a(s.Is);){++n;const t=a(s.Not);t&&++n;let r=$();if(r instanceof T&&(r=new b(r.value.toString())),!(r instanceof b))throw new SyntaxError("Expected identifier for the test");e=new E(e,t,r)}return e}function $(){const t=e[n];switch(t.type){case s.NumericLiteral:return++n,new x(Number(t.value));case s.StringLiteral:return++n,new k(t.value);case s.BooleanLiteral:return++n,new T("true"===t.value.toLowerCase());case s.Identifier:return++n,new b(t.value);case s.OpenParen:{++n;const t=d();if(e[n].type!==s.CloseParen)throw new SyntaxError(`Expected closing parenthesis, got ${e[n].type} instead`);return++n,t}case s.OpenSquareBracket:{++n;const e=[];for(;!a(s.CloseSquareBracket);)e.push(u()),a(s.Comma)&&++n;return++n,new v(e)}case s.OpenCurlyBracket:{++n;const e=new Map;for(;!a(s.CloseCurlyBracket);){const t=u();r(s.Colon,"Expected colon between key and value in object literal");const o=u();e.set(t,o),a(s.Comma)&&++n}return++n,new C(e)}default:throw new SyntaxError(`Unexpected token: ${t.type}`)}}for(;n<e.length;)t.body.push(o());return t}function N(e,t,n=1){void 0===t&&(t=e,e=0);const s=[];for(let r=e;r<t;r+=n)s.push(r);return s}function O(e,t,n,s=1){const r=Math.sign(s);r>=0?(t=(t??=0)<0?Math.max(e.length+t,0):Math.min(t,e.length),n=(n??=e.length)<0?Math.max(e.length+n,0):Math.min(n,e.length)):(t=(t??=e.length-1)<0?Math.max(e.length+t,-1):Math.min(t,e.length-1),n=(n??=-1)<-1?Math.max(e.length+n,-1):Math.min(n,e.length-1));const o=[];for(let i=t;r*i<r*n;i+=s)o.push(e[i]);return o}function j(e){return e.replace(/\b\w/g,(e=>e.toUpperCase()))}var D=class{type="RuntimeValue";value;builtins=new Map;constructor(e=void 0){this.value=e}__bool__(){return new G(!!this.value)}},V=class extends D{type="NumericValue"},R=class extends D{type="StringValue";builtins=new Map([["upper",new X((()=>new R(this.value.toUpperCase())))],["lower",new X((()=>new R(this.value.toLowerCase())))],["strip",new X((()=>new R(this.value.trim())))],["title",new X((()=>new R(j(this.value))))],["length",new V(this.value.length)]])},G=class extends D{type="BooleanValue"},$=class extends D{type="ObjectValue";__bool__(){return new G(this.value.size>0)}builtins=new Map([["get",new X((([e,t])=>{if(!(e instanceof R))throw new Error(`Object key must be a string: got ${e.type}`);return this.value.get(e.value)??t??new Q}))],["items",new X((()=>new U(Array.from(this.value.entries()).map((([e,t])=>new U([new R(e),t]))))))]])},q=class extends ${type="KeywordArgumentsValue"},U=class extends D{type="ArrayValue";builtins=new Map([["length",new V(this.value.length)]]);__bool__(){return new G(this.value.length>0)}},W=class extends U{type="TupleValue"},X=class extends D{type="FunctionValue"},Q=class extends D{type="NullValue"},H=class extends D{type="UndefinedValue"},Y=class{constructor(e){this.parent=e}variables=new Map([["namespace",new X((e=>{if(0===e.length)return new $(new Map);if(1!==e.length||!(e[0]instanceof $))throw new Error("`namespace` expects either zero arguments or a single object argument");return e[0]}))]]);tests=new Map([["boolean",e=>"BooleanValue"===e.type],["callable",e=>e instanceof X],["odd",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "odd" to type: ${e.type}`);return e.value%2!=0}],["even",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "even" to type: ${e.type}`);return e.value%2==0}],["false",e=>"BooleanValue"===e.type&&!e.value],["true",e=>"BooleanValue"===e.type&&e.value],["string",e=>"StringValue"===e.type],["number",e=>"NumericValue"===e.type],["integer",e=>"NumericValue"===e.type&&Number.isInteger(e.value)],["iterable",e=>e instanceof U||e instanceof R],["lower",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toLowerCase()}],["upper",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toUpperCase()}],["none",e=>"NullValue"===e.type],["defined",e=>"UndefinedValue"!==e.type],["undefined",e=>"UndefinedValue"===e.type],["equalto",(e,t)=>e.value===t.value],["eq",(e,t)=>e.value===t.value]]);set(e,t){return this.declareVariable(e,K(t))}declareVariable(e,t){if(this.variables.has(e))throw new SyntaxError(`Variable already declared: ${e}`);return this.variables.set(e,t),t}setVariable(e,t){return this.variables.set(e,t),t}resolve(e){if(this.variables.has(e))return this;if(this.parent)return this.parent.resolve(e);throw new Error(`Unknown variable: ${e}`)}lookupVariable(e){try{return this.resolve(e).variables.get(e)??new H}catch{return new H}}},J=class{global;constructor(e){this.global=e??new Y}run(e){return this.evaluate(e,this.global)}evaluateBinaryExpression(e,t){const n=this.evaluate(e.left,t);switch(e.operator.value){case"and":return n.__bool__().value?this.evaluate(e.right,t):n;case"or":return n.__bool__().value?n:this.evaluate(e.right,t)}const s=this.evaluate(e.right,t);switch(e.operator.value){case"==":return new G(n.value==s.value);case"!=":return new G(n.value!=s.value)}if(n instanceof H||s instanceof H)throw new Error("Cannot perform operation on undefined values");if(n instanceof Q||s instanceof Q)throw new Error("Cannot perform operation on null values");if(n instanceof V&&s instanceof V)switch(e.operator.value){case"+":return new V(n.value+s.value);case"-":return new V(n.value-s.value);case"*":return new V(n.value*s.value);case"/":return new V(n.value/s.value);case"%":return new V(n.value%s.value);case"<":return new G(n.value<s.value);case">":return new G(n.value>s.value);case">=":return new G(n.value>=s.value);case"<=":return new G(n.value<=s.value)}else if(n instanceof U&&s instanceof U){if("+"===e.operator.value)return new U(n.value.concat(s.value))}else if(s instanceof U){const t=void 0!==s.value.find((e=>e.value===n.value));switch(e.operator.value){case"in":return new G(t);case"not in":return new G(!t)}}if((n instanceof R||s instanceof R)&&"+"===e.operator.value)return new R(n.value.toString()+s.value.toString());if(n instanceof R&&s instanceof R)switch(e.operator.value){case"in":return new G(s.value.includes(n.value));case"not in":return new G(!s.value.includes(n.value))}if(n instanceof R&&s instanceof $)switch(e.operator.value){case"in":return new G(s.value.has(n.value));case"not in":return new G(!s.value.has(n.value))}throw new SyntaxError(`Unknown operator "${e.operator.value}" between ${n.type} and ${s.type}`)}evaluateArguments(e,t){const n=[],s=new Map;for(const r of e)if("KeywordArgumentExpression"===r.type){const e=r;s.set(e.key.value,this.evaluate(e.value,t))}else{if(s.size>0)throw new Error("Positional arguments must come before keyword arguments");n.push(this.evaluate(r,t))}return[n,s]}evaluateFilterExpression(e,t){const n=this.evaluate(e.operand,t);if("Identifier"===e.filter.type){const t=e.filter;if("tojson"===t.value)return new R(Z(n));if(n instanceof U)switch(t.value){case"list":return n;case"first":return n.value[0];case"last":return n.value[n.value.length-1];case"length":return new V(n.value.length);case"reverse":return new U(n.value.reverse());case"sort":return new U(n.value.sort(((e,t)=>{if(e.type!==t.type)throw new Error(`Cannot compare different types: ${e.type} and ${t.type}`);switch(e.type){case"NumericValue":return e.value-t.value;case"StringValue":return e.value.localeCompare(t.value);default:throw new Error(`Cannot compare type: ${e.type}`)}})));default:throw new Error(`Unknown ArrayValue filter: ${t.value}`)}else if(n instanceof R)switch(t.value){case"length":return new V(n.value.length);case"upper":return new R(n.value.toUpperCase());case"lower":return new R(n.value.toLowerCase());case"title":return new R(j(n.value));case"capitalize":return new R(n.value.charAt(0).toUpperCase()+n.value.slice(1));case"trim":return new R(n.value.trim());case"indent":return new R(n.value.split("\n").map(((e,t)=>0===t||0===e.length?e:" "+e)).join("\n"));case"string":return n;default:throw new Error(`Unknown StringValue filter: ${t.value}`)}else{if(n instanceof V){if("abs"===t.value)return new V(Math.abs(n.value));throw new Error(`Unknown NumericValue filter: ${t.value}`)}if(n instanceof $)switch(t.value){case"items":return new U(Array.from(n.value.entries()).map((([e,t])=>new U([new R(e),t]))));case"length":return new V(n.value.size);default:throw new Error(`Unknown ObjectValue filter: ${t.value}`)}}throw new Error(`Cannot apply filter "${t.value}" to type: ${n.type}`)}if("CallExpression"===e.filter.type){const s=e.filter;if("Identifier"!==s.callee.type)throw new Error(`Unknown filter: ${s.callee.type}`);const r=s.callee.value;if("tojson"===r){const[,e]=this.evaluateArguments(s.args,t),r=e.get("indent")??new Q;if(!(r instanceof V||r instanceof Q))throw new Error("If set, indent must be a number");return new R(Z(n,r.value))}if(n instanceof U){switch(r){case"selectattr":{if(n.value.some((e=>!(e instanceof $))))throw new Error("`selectattr` can only be applied to array of objects");if(s.args.some((e=>"StringLiteral"!==e.type)))throw new Error("arguments of `selectattr` must be strings");const[e,r,o]=s.args.map((e=>this.evaluate(e,t)));let i;if(r){const e=t.tests.get(r.value);if(!e)throw new Error(`Unknown test: ${r.value}`);i=e}else i=(...e)=>e[0].__bool__().value;const a=n.value.filter((t=>{const n=t.value.get(e.value);return!!n&&i(n,o)}));return new U(a)}case"map":{const[,e]=this.evaluateArguments(s.args,t);if(e.has("attribute")){const t=e.get("attribute");if(!(t instanceof R))throw new Error("attribute must be a string");const s=e.get("default"),r=n.value.map((e=>{if(!(e instanceof $))throw new Error("items in map must be an object");return e.value.get(t.value)??s??new H}));return new U(r)}throw new Error("`map` expressions without `attribute` set are not currently supported.")}}throw new Error(`Unknown ArrayValue filter: ${r}`)}if(n instanceof R){if("indent"===r){const[e,r]=this.evaluateArguments(s.args,t),o=e.at(0)??r.get("width")??new V(4);if(!(o instanceof V))throw new Error("width must be a number");const i=e.at(1)??r.get("first")??new G(!1),a=e.at(2)??r.get("blank")??new G(!1),l=n.value.split("\n"),c=" ".repeat(o.value),d=l.map(((e,t)=>!i.value&&0===t||!a.value&&0===e.length?e:c+e));return new R(d.join("\n"))}throw new Error(`Unknown StringValue filter: ${r}`)}throw new Error(`Cannot apply filter "${r}" to type: ${n.type}`)}throw new Error(`Unknown filter: ${e.filter.type}`)}evaluateTestExpression(e,t){const n=this.evaluate(e.operand,t),s=t.tests.get(e.test.value);if(!s)throw new Error(`Unknown test: ${e.test.value}`);const r=s(n);return new G(e.negate?!r:r)}evaluateUnaryExpression(e,t){const n=this.evaluate(e.argument,t);if("not"===e.operator.value)return new G(!n.value);throw new SyntaxError(`Unknown operator: ${e.operator.value}`)}evalProgram(e,t){return this.evaluateBlock(e.body,t)}evaluateBlock(e,t){let n="";for(const s of e){const e=this.evaluate(s,t);"NullValue"!==e.type&&"UndefinedValue"!==e.type&&(n+=e.value)}return new R(n)}evaluateIdentifier(e,t){return t.lookupVariable(e.value)}evaluateCallExpression(e,t){const[n,s]=this.evaluateArguments(e.args,t);s.size>0&&n.push(new q(s));const r=this.evaluate(e.callee,t);if("FunctionValue"!==r.type)throw new Error(`Cannot call something that is not a function: got ${r.type}`);return r.value(n,t)}evaluateSliceExpression(e,t,n){if(!(e instanceof U||e instanceof R))throw new Error("Slice object must be an array or string");const s=this.evaluate(t.start,n),r=this.evaluate(t.stop,n),o=this.evaluate(t.step,n);if(!(s instanceof V||s instanceof H))throw new Error("Slice start must be numeric or undefined");if(!(r instanceof V||r instanceof H))throw new Error("Slice stop must be numeric or undefined");if(!(o instanceof V||o instanceof H))throw new Error("Slice step must be numeric or undefined");return e instanceof U?new U(O(e.value,s.value,r.value,o.value)):new R(O(Array.from(e.value),s.value,r.value,o.value).join(""))}evaluateMemberExpression(e,t){const n=this.evaluate(e.object,t);let s,r;if(e.computed){if("SliceExpression"===e.property.type)return this.evaluateSliceExpression(n,e.property,t);s=this.evaluate(e.property,t)}else s=new R(e.property.value);if(n instanceof $){if(!(s instanceof R))throw new Error(`Cannot access property with non-string: got ${s.type}`);r=n.value.get(s.value)??n.builtins.get(s.value)}else if(n instanceof U||n instanceof R)if(s instanceof V)r=n.value.at(s.value),n instanceof R&&(r=new R(n.value.at(s.value)));else{if(!(s instanceof R))throw new Error(`Cannot access property with non-string/non-number: got ${s.type}`);r=n.builtins.get(s.value)}else{if(!(s instanceof R))throw new Error(`Cannot access property with non-string: got ${s.type}`);r=n.builtins.get(s.value)}return r instanceof D?r:new H}evaluateSet(e,t){const n=this.evaluate(e.value,t);if("Identifier"===e.assignee.type){const s=e.assignee.value;t.setVariable(s,n)}else{if("MemberExpression"!==e.assignee.type)throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(e.assignee)}`);{const s=e.assignee,r=this.evaluate(s.object,t);if(!(r instanceof $))throw new Error("Cannot assign to member of non-object");if("Identifier"!==s.property.type)throw new Error("Cannot assign to member with non-identifier property");r.value.set(s.property.value,n)}}return new Q}evaluateIf(e,t){const n=this.evaluate(e.test,t);return this.evaluateBlock(n.__bool__().value?e.body:e.alternate,t)}evaluateFor(e,t){const n=new Y(t);let s,r;if("SelectExpression"===e.iterable.type){const t=e.iterable;r=this.evaluate(t.iterable,n),s=t.test}else r=this.evaluate(e.iterable,n);if(!(r instanceof U))throw new Error(`Expected iterable type in for loop: got ${r.type}`);const o=[],i=[];for(let t=0;t<r.value.length;++t){const a=new Y(n),l=r.value[t];let c;if("Identifier"===e.loopvar.type)c=t=>t.setVariable(e.loopvar.value,l);else{if("TupleLiteral"!==e.loopvar.type)throw new Error(`Invalid loop variable(s): ${e.loopvar.type}`);{const t=e.loopvar;if("ArrayValue"!==l.type)throw new Error(`Cannot unpack non-iterable type: ${l.type}`);const n=l;if(t.value.length!==n.value.length)throw new Error(`Too ${t.value.length>n.value.length?"few":"many"} items to unpack`);c=e=>{for(let s=0;s<t.value.length;++s){if("Identifier"!==t.value[s].type)throw new Error(`Cannot unpack non-identifier type: ${t.value[s].type}`);e.setVariable(t.value[s].value,n.value[s])}}}}if(s){c(a);if(!this.evaluate(s,a).__bool__().value)continue}o.push(l),i.push(c)}let a="",l=!0;for(let t=0;t<o.length;++t){const s=new Map([["index",new V(t+1)],["index0",new V(t)],["revindex",new V(o.length-t)],["revindex0",new V(o.length-t-1)],["first",new G(0===t)],["last",new G(t===o.length-1)],["length",new V(o.length)],["previtem",t>0?o[t-1]:new H],["nextitem",t<o.length-1?o[t+1]:new H]]);n.setVariable("loop",new $(s)),i[t](n);a+=this.evaluateBlock(e.body,n).value,l=!1}if(l){a+=this.evaluateBlock(e.defaultBlock,n).value}return new R(a)}evaluateMacro(e,t){return t.setVariable(e.name.value,new X(((t,n)=>{const s=new Y(n);let r;t=t.slice(),"KeywordArgumentsValue"===t.at(-1)?.type&&(r=t.pop());for(let n=0;n<e.args.length;++n){const o=e.args[n],i=t[n];if("Identifier"===o.type){const e=o;if(!i)throw new Error(`Missing positional argument: ${e.value}`);s.setVariable(e.value,i)}else{if("KeywordArgumentExpression"!==o.type)throw new Error(`Unknown argument type: ${o.type}`);{const e=o,t=i??r?.value.get(e.key.value)??this.evaluate(e.value,s);s.setVariable(e.key.value,t)}}}return this.evaluateBlock(e.body,s)}))),new Q}evaluate(e,t){if(void 0===e)return new H;switch(e.type){case"Program":return this.evalProgram(e,t);case"Set":return this.evaluateSet(e,t);case"If":return this.evaluateIf(e,t);case"For":return this.evaluateFor(e,t);case"Macro":return this.evaluateMacro(e,t);case"NumericLiteral":return new V(Number(e.value));case"StringLiteral":return new R(e.value);case"BooleanLiteral":return new G(e.value);case"ArrayLiteral":return new U(e.value.map((e=>this.evaluate(e,t))));case"TupleLiteral":return new W(e.value.map((e=>this.evaluate(e,t))));case"ObjectLiteral":{const n=new Map;for(const[s,r]of e.value){const e=this.evaluate(s,t);if(!(e instanceof R))throw new Error(`Object keys must be strings: got ${e.type}`);n.set(e.value,this.evaluate(r,t))}return new $(n)}case"Identifier":return this.evaluateIdentifier(e,t);case"CallExpression":return this.evaluateCallExpression(e,t);case"MemberExpression":return this.evaluateMemberExpression(e,t);case"UnaryExpression":return this.evaluateUnaryExpression(e,t);case"BinaryExpression":return this.evaluateBinaryExpression(e,t);case"FilterExpression":return this.evaluateFilterExpression(e,t);case"TestExpression":return this.evaluateTestExpression(e,t);default:throw new SyntaxError(`Unknown node type: ${e.type}`)}}};function K(e){switch(typeof e){case"number":return new V(e);case"string":return new R(e);case"boolean":return new G(e);case"undefined":return new H;case"object":return null===e?new Q:Array.isArray(e)?new U(e.map(K)):new $(new Map(Object.entries(e).map((([e,t])=>[e,K(t)]))));case"function":return new X(((t,n)=>K(e(...t.map((e=>e.value)))??null)));default:throw new Error(`Cannot convert to runtime value: ${e}`)}}function Z(e,t,n){const s=n??0;switch(e.type){case"NullValue":case"UndefinedValue":return"null";case"NumericValue":case"StringValue":case"BooleanValue":return JSON.stringify(e.value);case"ArrayValue":case"ObjectValue":{const n=t?" ".repeat(t):"",r="\n"+n.repeat(s),o=r+n;if("ArrayValue"===e.type){const n=e.value.map((e=>Z(e,t,s+1)));return t?`[${o}${n.join(`,${o}`)}${r}]`:`[${n.join(", ")}]`}{const n=Array.from(e.value.entries()).map((([e,n])=>{const r=`"${e}": ${Z(n,t,s+1)}`;return t?`${o}${r}`:r}));return t?`{${n.join(",")}${r}}`:`{${n.join(", ")}}`}}default:throw new Error(`Cannot convert to JSON: ${e.type}`)}}var ee=class{parsed;constructor(e){const t=d(e,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=B(t)}render(e){const t=new Y;t.set("false",!1),t.set("true",!0),t.set("raise_exception",(e=>{throw new Error(e)})),t.set("range",N);for(const[n,s]of Object.entries(e))t.set(n,s);return new J(t).run(this.parsed).value}}},"./node_modules/onnxruntime-common/dist/esm/backend-impl.js":
|
|
22
|
+
\*******************************************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{Environment:()=>Y,Interpreter:()=>J,Template:()=>ee,parse:()=>B,tokenize:()=>d});var s=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",BooleanLiteral:"BooleanLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",OpenCurlyBracket:"OpenCurlyBracket",CloseCurlyBracket:"CloseCurlyBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Set:"Set",If:"If",For:"For",In:"In",Is:"Is",NotIn:"NotIn",Else:"Else",EndIf:"EndIf",ElseIf:"ElseIf",EndFor:"EndFor",And:"And",Or:"Or",Not:"UnaryOperator",Macro:"Macro",EndMacro:"EndMacro"}),r=Object.freeze({set:s.Set,for:s.For,in:s.In,is:s.Is,if:s.If,else:s.Else,endif:s.EndIf,elif:s.ElseIf,endfor:s.EndFor,and:s.And,or:s.Or,not:s.Not,"not in":s.NotIn,macro:s.Macro,endmacro:s.EndMacro,true:s.BooleanLiteral,false:s.BooleanLiteral,True:s.BooleanLiteral,False:s.BooleanLiteral}),o=class{constructor(e,t){this.value=e,this.type=t}};function i(e){return/\w/.test(e)}function a(e){return/[0-9]/.test(e)}var l=[["{%",s.OpenStatement],["%}",s.CloseStatement],["{{",s.OpenExpression],["}}",s.CloseExpression],["(",s.OpenParen],[")",s.CloseParen],["{",s.OpenCurlyBracket],["}",s.CloseCurlyBracket],["[",s.OpenSquareBracket],["]",s.CloseSquareBracket],[",",s.Comma],[".",s.Dot],[":",s.Colon],["|",s.Pipe],["<=",s.ComparisonBinaryOperator],[">=",s.ComparisonBinaryOperator],["==",s.ComparisonBinaryOperator],["!=",s.ComparisonBinaryOperator],["<",s.ComparisonBinaryOperator],[">",s.ComparisonBinaryOperator],["+",s.AdditiveBinaryOperator],["-",s.AdditiveBinaryOperator],["*",s.MultiplicativeBinaryOperator],["/",s.MultiplicativeBinaryOperator],["%",s.MultiplicativeBinaryOperator],["=",s.Equals]],c=new Map([["n","\n"],["t","\t"],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function d(e,t={}){const n=[],d=function(e,t={}){return e.endsWith("\n")&&(e=e.slice(0,-1)),e=e.replace(/{#.*?#}/gs,"{##}"),t.lstrip_blocks&&(e=e.replace(/^[ \t]*({[#%])/gm,"$1")),t.trim_blocks&&(e=e.replace(/([#%]})\n/g,"$1")),e.replace(/{##}/g,"").replace(/-%}\s*/g,"%}").replace(/\s*{%-/g,"{%").replace(/-}}\s*/g,"}}").replace(/\s*{{-/g,"{{")}(e,t);let u=0;const p=e=>{let t="";for(;e(d[u]);)if("\\"!==d[u]){if(t+=d[u++],u>=d.length)throw new SyntaxError("Unexpected end of input")}else{if(++u,u>=d.length)throw new SyntaxError("Unexpected end of input");const e=d[u++],n=c.get(e);if(void 0===n)throw new SyntaxError(`Unexpected escaped character: ${e}`);t+=n}return t};e:for(;u<d.length;){const e=n.at(-1)?.type;if(void 0===e||e===s.CloseStatement||e===s.CloseExpression){let e="";for(;u<d.length&&("{"!==d[u]||"%"!==d[u+1]&&"{"!==d[u+1]);)e+=d[u++];if(e.length>0){n.push(new o(e,s.Text));continue}}p((e=>/\s/.test(e)));const t=d[u];if("-"===t||"+"===t){const e=n.at(-1)?.type;if(e===s.Text||void 0===e)throw new SyntaxError(`Unexpected character: ${t}`);switch(e){case s.Identifier:case s.NumericLiteral:case s.BooleanLiteral:case s.StringLiteral:case s.CloseParen:case s.CloseSquareBracket:break;default:{++u;const e=p(a);n.push(new o(`${t}${e}`,e.length>0?s.NumericLiteral:s.UnaryOperator));continue}}}for(const[e,t]of l){if(d.slice(u,u+e.length)===e){n.push(new o(e,t)),u+=e.length;continue e}}if("'"!==t&&'"'!==t)if(a(t)){const e=p(a);n.push(new o(e,s.NumericLiteral))}else{if(!i(t))throw new SyntaxError(`Unexpected character: ${t}`);{const e=p(i),t=Object.hasOwn(r,e)?r[e]:s.Identifier;t===s.In&&n.at(-1)?.type===s.Not?(n.pop(),n.push(new o("not in",s.NotIn))):n.push(new o(e,t))}}else{++u;const e=p((e=>e!==t));n.push(new o(e,s.StringLiteral)),++u}}return n}var u=class{type="Statement"},p=class extends u{constructor(e){super(),this.body=e}type="Program"},h=class extends u{constructor(e,t,n){super(),this.test=e,this.body=t,this.alternate=n}type="If"},_=class extends u{constructor(e,t,n,s){super(),this.loopvar=e,this.iterable=t,this.body=n,this.defaultBlock=s}type="For"},m=class extends u{constructor(e,t){super(),this.assignee=e,this.value=t}type="Set"},f=class extends u{constructor(e,t,n){super(),this.name=e,this.args=t,this.body=n}type="Macro"},g=class extends u{type="Expression"},w=class extends g{constructor(e,t,n){super(),this.object=e,this.property=t,this.computed=n}type="MemberExpression"},M=class extends g{constructor(e,t){super(),this.callee=e,this.args=t}type="CallExpression"},b=class extends g{constructor(e){super(),this.value=e}type="Identifier"},y=class extends g{constructor(e){super(),this.value=e}type="Literal"},x=class extends y{type="NumericLiteral"},k=class extends y{type="StringLiteral"},T=class extends y{type="BooleanLiteral"},v=class extends y{type="ArrayLiteral"},F=class extends y{type="TupleLiteral"},C=class extends y{type="ObjectLiteral"},P=class extends g{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n}type="BinaryExpression"},S=class extends g{constructor(e,t){super(),this.operand=e,this.filter=t}type="FilterExpression"},A=class extends g{constructor(e,t){super(),this.iterable=e,this.test=t}type="SelectExpression"},E=class extends g{constructor(e,t,n){super(),this.operand=e,this.negate=t,this.test=n}type="TestExpression"},L=class extends g{constructor(e,t){super(),this.operator=e,this.argument=t}type="UnaryExpression"},z=class extends g{constructor(e=void 0,t=void 0,n=void 0){super(),this.start=e,this.stop=t,this.step=n}type="SliceExpression"},I=class extends g{constructor(e,t){super(),this.key=e,this.value=t}type="KeywordArgumentExpression"};function B(e){const t=new p([]);let n=0;function r(t,s){const r=e[n++];if(!r||r.type!==t)throw new Error(`Parser Error: ${s}. ${r.type} !== ${t}.`);return r}function o(){switch(e[n].type){case s.Text:return new k(r(s.Text,"Expected text token").value);case s.OpenStatement:return function(){let t;switch(r(s.OpenStatement,"Expected opening statement token"),e[n].type){case s.Set:++n,t=l(),r(s.CloseStatement,"Expected closing statement token");break;case s.If:++n,t=c(),r(s.OpenStatement,"Expected {% token"),r(s.EndIf,"Expected endif token"),r(s.CloseStatement,"Expected %} token");break;case s.Macro:++n,t=function(){const e=$();if("Identifier"!==e.type)throw new SyntaxError("Expected identifier following macro statement");const t=D();r(s.CloseStatement,"Expected closing statement token");const n=[];for(;i(s.OpenStatement,s.EndMacro);)n.push(o());return new f(e,t,n)}(),r(s.OpenStatement,"Expected {% token"),r(s.EndMacro,"Expected endmacro token"),r(s.CloseStatement,"Expected %} token");break;case s.For:++n,t=function(){const e=d(!0);if(!(e instanceof b||e instanceof F))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${e.type} instead`);r(s.In,"Expected `in` keyword following loop variable");const t=u();r(s.CloseStatement,"Expected closing statement token");const l=[];for(;i(s.OpenStatement,s.EndFor)&&i(s.OpenStatement,s.Else);)l.push(o());const c=[];if(a(s.OpenStatement,s.Else))for(++n,++n,r(s.CloseStatement,"Expected closing statement token");i(s.OpenStatement,s.EndFor);)c.push(o());return new _(e,t,l,c)}(),r(s.OpenStatement,"Expected {% token"),r(s.EndFor,"Expected endfor token"),r(s.CloseStatement,"Expected %} token");break;default:throw new SyntaxError(`Unknown statement type: ${e[n].type}`)}return t}();case s.OpenExpression:return function(){r(s.OpenExpression,"Expected opening expression token");const e=u();return r(s.CloseExpression,"Expected closing expression token"),e}();default:throw new SyntaxError(`Unexpected token type: ${e[n].type}`)}}function i(...t){return n+t.length<=e.length&&t.some(((t,s)=>t!==e[n+s].type))}function a(...t){return n+t.length<=e.length&&t.every(((t,s)=>t===e[n+s].type))}function l(){const e=u();if(a(s.Equals)){++n;const t=l();return new m(e,t)}return e}function c(){const t=u();r(s.CloseStatement,"Expected closing statement token");const i=[],l=[];for(;e[n]?.type!==s.OpenStatement||e[n+1]?.type!==s.ElseIf&&e[n+1]?.type!==s.Else&&e[n+1]?.type!==s.EndIf;)i.push(o());if(e[n]?.type===s.OpenStatement&&e[n+1]?.type!==s.EndIf)if(++n,a(s.ElseIf))r(s.ElseIf,"Expected elseif token"),l.push(c());else for(r(s.Else,"Expected else token"),r(s.CloseStatement,"Expected closing statement token");e[n]?.type!==s.OpenStatement||e[n+1]?.type!==s.EndIf;)l.push(o());return new h(t,i,l)}function d(e=!1){const t=e?$:u,r=[t()],o=a(s.Comma);for(;o&&(++n,r.push(t()),a(s.Comma)););return o?new F(r):r[0]}function u(){return function(){const e=g();if(a(s.If)){++n;const t=g();if(a(s.Else)){++n;const s=g();return new h(t,[e],[s])}return new A(e,t)}return e}()}function g(){let t=y();for(;a(s.Or);){const s=e[n];++n;const r=y();t=new P(s,t,r)}return t}function y(){let t=B();for(;a(s.And);){const s=e[n];++n;const r=B();t=new P(s,t,r)}return t}function B(){let t;for(;a(s.Not);){const s=e[n];++n;const r=B();t=new L(s,r)}return t??function(){let t=N();for(;a(s.ComparisonBinaryOperator)||a(s.In)||a(s.NotIn);){const s=e[n];++n;const r=N();t=new P(s,t,r)}return t}()}function N(){let t=R();for(;a(s.AdditiveBinaryOperator);){const s=e[n];++n;const r=R();t=new P(s,t,r)}return t}function O(){const t=function(){let t=$();for(;a(s.Dot)||a(s.OpenSquareBracket);){const o=e[n];let i;++n;const a=o.type!==s.Dot;if(a)i=V(),r(s.CloseSquareBracket,"Expected closing square bracket");else if(i=$(),"Identifier"!==i.type)throw new SyntaxError("Expected identifier following dot operator");t=new w(t,i,a)}return t}();return a(s.OpenParen)?j(t):t}function j(e){let t=new M(e,D());return a(s.OpenParen)&&(t=j(t)),t}function D(){r(s.OpenParen,"Expected opening parenthesis for arguments list");const e=function(){const e=[];for(;!a(s.CloseParen);){let t=u();if(a(s.Equals)){if(++n,!(t instanceof b))throw new SyntaxError("Expected identifier for keyword argument");const e=u();t=new I(t,e)}e.push(t),a(s.Comma)&&++n}return e}();return r(s.CloseParen,"Expected closing parenthesis for arguments list"),e}function V(){const e=[];let t=!1;for(;!a(s.CloseSquareBracket);)a(s.Colon)?(e.push(void 0),++n,t=!0):(e.push(u()),a(s.Colon)&&(++n,t=!0));if(0===e.length)throw new SyntaxError("Expected at least one argument for member/slice expression");if(t){if(e.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new z(...e)}return e[0]}function R(){let t=G();for(;a(s.MultiplicativeBinaryOperator);){const s=e[n];++n;const r=G();t=new P(s,t,r)}return t}function G(){let e=function(){let e=O();for(;a(s.Pipe);){++n;let t=$();if(!(t instanceof b))throw new SyntaxError("Expected identifier for the filter");a(s.OpenParen)&&(t=j(t)),e=new S(e,t)}return e}();for(;a(s.Is);){++n;const t=a(s.Not);t&&++n;let r=$();if(r instanceof T&&(r=new b(r.value.toString())),!(r instanceof b))throw new SyntaxError("Expected identifier for the test");e=new E(e,t,r)}return e}function $(){const t=e[n];switch(t.type){case s.NumericLiteral:return++n,new x(Number(t.value));case s.StringLiteral:return++n,new k(t.value);case s.BooleanLiteral:return++n,new T("true"===t.value.toLowerCase());case s.Identifier:return++n,new b(t.value);case s.OpenParen:{++n;const t=d();if(e[n].type!==s.CloseParen)throw new SyntaxError(`Expected closing parenthesis, got ${e[n].type} instead`);return++n,t}case s.OpenSquareBracket:{++n;const e=[];for(;!a(s.CloseSquareBracket);)e.push(u()),a(s.Comma)&&++n;return++n,new v(e)}case s.OpenCurlyBracket:{++n;const e=new Map;for(;!a(s.CloseCurlyBracket);){const t=u();r(s.Colon,"Expected colon between key and value in object literal");const o=u();e.set(t,o),a(s.Comma)&&++n}return++n,new C(e)}default:throw new SyntaxError(`Unexpected token: ${t.type}`)}}for(;n<e.length;)t.body.push(o());return t}function N(e,t,n=1){void 0===t&&(t=e,e=0);const s=[];for(let r=e;r<t;r+=n)s.push(r);return s}function O(e,t,n,s=1){const r=Math.sign(s);r>=0?(t=(t??=0)<0?Math.max(e.length+t,0):Math.min(t,e.length),n=(n??=e.length)<0?Math.max(e.length+n,0):Math.min(n,e.length)):(t=(t??=e.length-1)<0?Math.max(e.length+t,-1):Math.min(t,e.length-1),n=(n??=-1)<-1?Math.max(e.length+n,-1):Math.min(n,e.length-1));const o=[];for(let i=t;r*i<r*n;i+=s)o.push(e[i]);return o}function j(e){return e.replace(/\b\w/g,(e=>e.toUpperCase()))}var D=class{type="RuntimeValue";value;builtins=new Map;constructor(e=void 0){this.value=e}__bool__(){return new G(!!this.value)}},V=class extends D{type="NumericValue"},R=class extends D{type="StringValue";builtins=new Map([["upper",new X((()=>new R(this.value.toUpperCase())))],["lower",new X((()=>new R(this.value.toLowerCase())))],["strip",new X((()=>new R(this.value.trim())))],["title",new X((()=>new R(j(this.value))))],["length",new V(this.value.length)]])},G=class extends D{type="BooleanValue"},$=class extends D{type="ObjectValue";__bool__(){return new G(this.value.size>0)}builtins=new Map([["get",new X((([e,t])=>{if(!(e instanceof R))throw new Error(`Object key must be a string: got ${e.type}`);return this.value.get(e.value)??t??new Q}))],["items",new X((()=>new U(Array.from(this.value.entries()).map((([e,t])=>new U([new R(e),t]))))))]])},q=class extends ${type="KeywordArgumentsValue"},U=class extends D{type="ArrayValue";builtins=new Map([["length",new V(this.value.length)]]);__bool__(){return new G(this.value.length>0)}},W=class extends U{type="TupleValue"},X=class extends D{type="FunctionValue"},Q=class extends D{type="NullValue"},H=class extends D{type="UndefinedValue"},Y=class{constructor(e){this.parent=e}variables=new Map([["namespace",new X((e=>{if(0===e.length)return new $(new Map);if(1!==e.length||!(e[0]instanceof $))throw new Error("`namespace` expects either zero arguments or a single object argument");return e[0]}))]]);tests=new Map([["boolean",e=>"BooleanValue"===e.type],["callable",e=>e instanceof X],["odd",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "odd" to type: ${e.type}`);return e.value%2!=0}],["even",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "even" to type: ${e.type}`);return e.value%2==0}],["false",e=>"BooleanValue"===e.type&&!e.value],["true",e=>"BooleanValue"===e.type&&e.value],["string",e=>"StringValue"===e.type],["number",e=>"NumericValue"===e.type],["integer",e=>"NumericValue"===e.type&&Number.isInteger(e.value)],["iterable",e=>e instanceof U||e instanceof R],["lower",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toLowerCase()}],["upper",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toUpperCase()}],["none",e=>"NullValue"===e.type],["defined",e=>"UndefinedValue"!==e.type],["undefined",e=>"UndefinedValue"===e.type],["equalto",(e,t)=>e.value===t.value],["eq",(e,t)=>e.value===t.value]]);set(e,t){return this.declareVariable(e,K(t))}declareVariable(e,t){if(this.variables.has(e))throw new SyntaxError(`Variable already declared: ${e}`);return this.variables.set(e,t),t}setVariable(e,t){return this.variables.set(e,t),t}resolve(e){if(this.variables.has(e))return this;if(this.parent)return this.parent.resolve(e);throw new Error(`Unknown variable: ${e}`)}lookupVariable(e){try{return this.resolve(e).variables.get(e)??new H}catch{return new H}}},J=class{global;constructor(e){this.global=e??new Y}run(e){return this.evaluate(e,this.global)}evaluateBinaryExpression(e,t){const n=this.evaluate(e.left,t);switch(e.operator.value){case"and":return n.__bool__().value?this.evaluate(e.right,t):n;case"or":return n.__bool__().value?n:this.evaluate(e.right,t)}const s=this.evaluate(e.right,t);switch(e.operator.value){case"==":return new G(n.value==s.value);case"!=":return new G(n.value!=s.value)}if(n instanceof H||s instanceof H)throw new Error("Cannot perform operation on undefined values");if(n instanceof Q||s instanceof Q)throw new Error("Cannot perform operation on null values");if(n instanceof V&&s instanceof V)switch(e.operator.value){case"+":return new V(n.value+s.value);case"-":return new V(n.value-s.value);case"*":return new V(n.value*s.value);case"/":return new V(n.value/s.value);case"%":return new V(n.value%s.value);case"<":return new G(n.value<s.value);case">":return new G(n.value>s.value);case">=":return new G(n.value>=s.value);case"<=":return new G(n.value<=s.value)}else if(n instanceof U&&s instanceof U){if("+"===e.operator.value)return new U(n.value.concat(s.value))}else if(s instanceof U){const t=void 0!==s.value.find((e=>e.value===n.value));switch(e.operator.value){case"in":return new G(t);case"not in":return new G(!t)}}if((n instanceof R||s instanceof R)&&"+"===e.operator.value)return new R(n.value.toString()+s.value.toString());if(n instanceof R&&s instanceof R)switch(e.operator.value){case"in":return new G(s.value.includes(n.value));case"not in":return new G(!s.value.includes(n.value))}if(n instanceof R&&s instanceof $)switch(e.operator.value){case"in":return new G(s.value.has(n.value));case"not in":return new G(!s.value.has(n.value))}throw new SyntaxError(`Unknown operator "${e.operator.value}" between ${n.type} and ${s.type}`)}evaluateArguments(e,t){const n=[],s=new Map;for(const r of e)if("KeywordArgumentExpression"===r.type){const e=r;s.set(e.key.value,this.evaluate(e.value,t))}else{if(s.size>0)throw new Error("Positional arguments must come before keyword arguments");n.push(this.evaluate(r,t))}return[n,s]}evaluateFilterExpression(e,t){const n=this.evaluate(e.operand,t);if("Identifier"===e.filter.type){const t=e.filter;if("tojson"===t.value)return new R(Z(n));if(n instanceof U)switch(t.value){case"list":return n;case"first":return n.value[0];case"last":return n.value[n.value.length-1];case"length":return new V(n.value.length);case"reverse":return new U(n.value.reverse());case"sort":return new U(n.value.sort(((e,t)=>{if(e.type!==t.type)throw new Error(`Cannot compare different types: ${e.type} and ${t.type}`);switch(e.type){case"NumericValue":return e.value-t.value;case"StringValue":return e.value.localeCompare(t.value);default:throw new Error(`Cannot compare type: ${e.type}`)}})));default:throw new Error(`Unknown ArrayValue filter: ${t.value}`)}else if(n instanceof R)switch(t.value){case"length":return new V(n.value.length);case"upper":return new R(n.value.toUpperCase());case"lower":return new R(n.value.toLowerCase());case"title":return new R(j(n.value));case"capitalize":return new R(n.value.charAt(0).toUpperCase()+n.value.slice(1));case"trim":return new R(n.value.trim());case"indent":return new R(n.value.split("\n").map(((e,t)=>0===t||0===e.length?e:" "+e)).join("\n"));case"string":return n;default:throw new Error(`Unknown StringValue filter: ${t.value}`)}else{if(n instanceof V){if("abs"===t.value)return new V(Math.abs(n.value));throw new Error(`Unknown NumericValue filter: ${t.value}`)}if(n instanceof $)switch(t.value){case"items":return new U(Array.from(n.value.entries()).map((([e,t])=>new U([new R(e),t]))));case"length":return new V(n.value.size);default:throw new Error(`Unknown ObjectValue filter: ${t.value}`)}}throw new Error(`Cannot apply filter "${t.value}" to type: ${n.type}`)}if("CallExpression"===e.filter.type){const s=e.filter;if("Identifier"!==s.callee.type)throw new Error(`Unknown filter: ${s.callee.type}`);const r=s.callee.value;if("tojson"===r){const[,e]=this.evaluateArguments(s.args,t),r=e.get("indent")??new Q;if(!(r instanceof V||r instanceof Q))throw new Error("If set, indent must be a number");return new R(Z(n,r.value))}if(n instanceof U){switch(r){case"selectattr":{if(n.value.some((e=>!(e instanceof $))))throw new Error("`selectattr` can only be applied to array of objects");if(s.args.some((e=>"StringLiteral"!==e.type)))throw new Error("arguments of `selectattr` must be strings");const[e,r,o]=s.args.map((e=>this.evaluate(e,t)));let i;if(r){const e=t.tests.get(r.value);if(!e)throw new Error(`Unknown test: ${r.value}`);i=e}else i=(...e)=>e[0].__bool__().value;const a=n.value.filter((t=>{const n=t.value.get(e.value);return!!n&&i(n,o)}));return new U(a)}case"map":{const[,e]=this.evaluateArguments(s.args,t);if(e.has("attribute")){const t=e.get("attribute");if(!(t instanceof R))throw new Error("attribute must be a string");const s=e.get("default"),r=n.value.map((e=>{if(!(e instanceof $))throw new Error("items in map must be an object");return e.value.get(t.value)??s??new H}));return new U(r)}throw new Error("`map` expressions without `attribute` set are not currently supported.")}}throw new Error(`Unknown ArrayValue filter: ${r}`)}if(n instanceof R){if("indent"===r){const[e,r]=this.evaluateArguments(s.args,t),o=e.at(0)??r.get("width")??new V(4);if(!(o instanceof V))throw new Error("width must be a number");const i=e.at(1)??r.get("first")??new G(!1),a=e.at(2)??r.get("blank")??new G(!1),l=n.value.split("\n"),c=" ".repeat(o.value),d=l.map(((e,t)=>!i.value&&0===t||!a.value&&0===e.length?e:c+e));return new R(d.join("\n"))}throw new Error(`Unknown StringValue filter: ${r}`)}throw new Error(`Cannot apply filter "${r}" to type: ${n.type}`)}throw new Error(`Unknown filter: ${e.filter.type}`)}evaluateTestExpression(e,t){const n=this.evaluate(e.operand,t),s=t.tests.get(e.test.value);if(!s)throw new Error(`Unknown test: ${e.test.value}`);const r=s(n);return new G(e.negate?!r:r)}evaluateUnaryExpression(e,t){const n=this.evaluate(e.argument,t);if("not"===e.operator.value)return new G(!n.value);throw new SyntaxError(`Unknown operator: ${e.operator.value}`)}evalProgram(e,t){return this.evaluateBlock(e.body,t)}evaluateBlock(e,t){let n="";for(const s of e){const e=this.evaluate(s,t);"NullValue"!==e.type&&"UndefinedValue"!==e.type&&(n+=e.value)}return new R(n)}evaluateIdentifier(e,t){return t.lookupVariable(e.value)}evaluateCallExpression(e,t){const[n,s]=this.evaluateArguments(e.args,t);s.size>0&&n.push(new q(s));const r=this.evaluate(e.callee,t);if("FunctionValue"!==r.type)throw new Error(`Cannot call something that is not a function: got ${r.type}`);return r.value(n,t)}evaluateSliceExpression(e,t,n){if(!(e instanceof U||e instanceof R))throw new Error("Slice object must be an array or string");const s=this.evaluate(t.start,n),r=this.evaluate(t.stop,n),o=this.evaluate(t.step,n);if(!(s instanceof V||s instanceof H))throw new Error("Slice start must be numeric or undefined");if(!(r instanceof V||r instanceof H))throw new Error("Slice stop must be numeric or undefined");if(!(o instanceof V||o instanceof H))throw new Error("Slice step must be numeric or undefined");return e instanceof U?new U(O(e.value,s.value,r.value,o.value)):new R(O(Array.from(e.value),s.value,r.value,o.value).join(""))}evaluateMemberExpression(e,t){const n=this.evaluate(e.object,t);let s,r;if(e.computed){if("SliceExpression"===e.property.type)return this.evaluateSliceExpression(n,e.property,t);s=this.evaluate(e.property,t)}else s=new R(e.property.value);if(n instanceof $){if(!(s instanceof R))throw new Error(`Cannot access property with non-string: got ${s.type}`);r=n.value.get(s.value)??n.builtins.get(s.value)}else if(n instanceof U||n instanceof R)if(s instanceof V)r=n.value.at(s.value),n instanceof R&&(r=new R(n.value.at(s.value)));else{if(!(s instanceof R))throw new Error(`Cannot access property with non-string/non-number: got ${s.type}`);r=n.builtins.get(s.value)}else{if(!(s instanceof R))throw new Error(`Cannot access property with non-string: got ${s.type}`);r=n.builtins.get(s.value)}return r instanceof D?r:new H}evaluateSet(e,t){const n=this.evaluate(e.value,t);if("Identifier"===e.assignee.type){const s=e.assignee.value;t.setVariable(s,n)}else{if("MemberExpression"!==e.assignee.type)throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(e.assignee)}`);{const s=e.assignee,r=this.evaluate(s.object,t);if(!(r instanceof $))throw new Error("Cannot assign to member of non-object");if("Identifier"!==s.property.type)throw new Error("Cannot assign to member with non-identifier property");r.value.set(s.property.value,n)}}return new Q}evaluateIf(e,t){const n=this.evaluate(e.test,t);return this.evaluateBlock(n.__bool__().value?e.body:e.alternate,t)}evaluateFor(e,t){const n=new Y(t);let s,r;if("SelectExpression"===e.iterable.type){const t=e.iterable;r=this.evaluate(t.iterable,n),s=t.test}else r=this.evaluate(e.iterable,n);if(!(r instanceof U))throw new Error(`Expected iterable type in for loop: got ${r.type}`);const o=[],i=[];for(let t=0;t<r.value.length;++t){const a=new Y(n),l=r.value[t];let c;if("Identifier"===e.loopvar.type)c=t=>t.setVariable(e.loopvar.value,l);else{if("TupleLiteral"!==e.loopvar.type)throw new Error(`Invalid loop variable(s): ${e.loopvar.type}`);{const t=e.loopvar;if("ArrayValue"!==l.type)throw new Error(`Cannot unpack non-iterable type: ${l.type}`);const n=l;if(t.value.length!==n.value.length)throw new Error(`Too ${t.value.length>n.value.length?"few":"many"} items to unpack`);c=e=>{for(let s=0;s<t.value.length;++s){if("Identifier"!==t.value[s].type)throw new Error(`Cannot unpack non-identifier type: ${t.value[s].type}`);e.setVariable(t.value[s].value,n.value[s])}}}}if(s){c(a);if(!this.evaluate(s,a).__bool__().value)continue}o.push(l),i.push(c)}let a="",l=!0;for(let t=0;t<o.length;++t){const s=new Map([["index",new V(t+1)],["index0",new V(t)],["revindex",new V(o.length-t)],["revindex0",new V(o.length-t-1)],["first",new G(0===t)],["last",new G(t===o.length-1)],["length",new V(o.length)],["previtem",t>0?o[t-1]:new H],["nextitem",t<o.length-1?o[t+1]:new H]]);n.setVariable("loop",new $(s)),i[t](n);a+=this.evaluateBlock(e.body,n).value,l=!1}if(l){a+=this.evaluateBlock(e.defaultBlock,n).value}return new R(a)}evaluateMacro(e,t){return t.setVariable(e.name.value,new X(((t,n)=>{const s=new Y(n);let r;t=t.slice(),"KeywordArgumentsValue"===t.at(-1)?.type&&(r=t.pop());for(let n=0;n<e.args.length;++n){const o=e.args[n],i=t[n];if("Identifier"===o.type){const e=o;if(!i)throw new Error(`Missing positional argument: ${e.value}`);s.setVariable(e.value,i)}else{if("KeywordArgumentExpression"!==o.type)throw new Error(`Unknown argument type: ${o.type}`);{const e=o,t=i??r?.value.get(e.key.value)??this.evaluate(e.value,s);s.setVariable(e.key.value,t)}}}return this.evaluateBlock(e.body,s)}))),new Q}evaluate(e,t){if(void 0===e)return new H;switch(e.type){case"Program":return this.evalProgram(e,t);case"Set":return this.evaluateSet(e,t);case"If":return this.evaluateIf(e,t);case"For":return this.evaluateFor(e,t);case"Macro":return this.evaluateMacro(e,t);case"NumericLiteral":return new V(Number(e.value));case"StringLiteral":return new R(e.value);case"BooleanLiteral":return new G(e.value);case"ArrayLiteral":return new U(e.value.map((e=>this.evaluate(e,t))));case"TupleLiteral":return new W(e.value.map((e=>this.evaluate(e,t))));case"ObjectLiteral":{const n=new Map;for(const[s,r]of e.value){const e=this.evaluate(s,t);if(!(e instanceof R))throw new Error(`Object keys must be strings: got ${e.type}`);n.set(e.value,this.evaluate(r,t))}return new $(n)}case"Identifier":return this.evaluateIdentifier(e,t);case"CallExpression":return this.evaluateCallExpression(e,t);case"MemberExpression":return this.evaluateMemberExpression(e,t);case"UnaryExpression":return this.evaluateUnaryExpression(e,t);case"BinaryExpression":return this.evaluateBinaryExpression(e,t);case"FilterExpression":return this.evaluateFilterExpression(e,t);case"TestExpression":return this.evaluateTestExpression(e,t);default:throw new SyntaxError(`Unknown node type: ${e.type}`)}}};function K(e){switch(typeof e){case"number":return new V(e);case"string":return new R(e);case"boolean":return new G(e);case"undefined":return new H;case"object":return null===e?new Q:Array.isArray(e)?new U(e.map(K)):new $(new Map(Object.entries(e).map((([e,t])=>[e,K(t)]))));case"function":return new X(((t,n)=>K(e(...t.map((e=>e.value)))??null)));default:throw new Error(`Cannot convert to runtime value: ${e}`)}}function Z(e,t,n){const s=n??0;switch(e.type){case"NullValue":case"UndefinedValue":return"null";case"NumericValue":case"StringValue":case"BooleanValue":return JSON.stringify(e.value);case"ArrayValue":case"ObjectValue":{const n=t?" ".repeat(t):"",r="\n"+n.repeat(s),o=r+n;if("ArrayValue"===e.type){const n=e.value.map((e=>Z(e,t,s+1)));return t?`[${o}${n.join(`,${o}`)}${r}]`:`[${n.join(", ")}]`}{const n=Array.from(e.value.entries()).map((([e,n])=>{const r=`"${e}": ${Z(n,t,s+1)}`;return t?`${o}${r}`:r}));return t?`{${n.join(",")}${r}}`:`{${n.join(", ")}}`}}default:throw new Error(`Cannot convert to JSON: ${e.type}`)}}var ee=class{parsed;constructor(e){const t=d(e,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=B(t)}render(e){const t=new Y;t.set("false",!1),t.set("true",!0),t.set("raise_exception",(e=>{throw new Error(e)})),t.set("range",N);for(const[n,s]of Object.entries(e))t.set(n,s);return new J(t).run(this.parsed).value}}},"./node_modules/onnxruntime-common/dist/esm/backend-impl.js":
|
|
23
23
|
/*!******************************************************************!*\
|
|
24
24
|
!*** ./node_modules/onnxruntime-common/dist/esm/backend-impl.js ***!
|
|
25
25
|
\******************************************************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{registerBackend:()=>o,resolveBackendAndExecutionProviders:()=>a});const s=new Map,r=[],o=(e,t,n)=>{if(!t||"function"!=typeof t.init||"function"!=typeof t.createInferenceSessionHandler)throw new TypeError("not a valid backend");{const o=s.get(e);if(void 0===o)s.set(e,{backend:t,priority:n});else{if(o.priority>n)return;if(o.priority===n&&o.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${n}`)}if(n>=0){const t=r.indexOf(e);-1!==t&&r.splice(t,1);for(let t=0;t<r.length;t++)if(s.get(r[t]).priority<=n)return void r.splice(t,0,e);r.push(e)}}},i=async e=>{const t=s.get(e);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{const n=!!t.initPromise;try{return n||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(e){return n||(t.error=`${e}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},a=async e=>{const t=e.executionProviders||[],n=t.map((e=>"string"==typeof e?e:e.name)),s=0===n.length?r:n;let o;const a=[],l=new Set;for(const e of s){const t=await i(e);"string"==typeof t?a.push({name:e,err:t}):(o||(o=t),o===t&&l.add(e))}if(!o)throw new Error(`no available backend found. ERR: ${a.map((e=>`[${e.name}] ${e.err}`)).join(", ")}`);for(const{name:e,err:t}of a)n.includes(e)&&console.warn(`removing requested execution provider "${e}" from session options because it is not available: ${t}`);const c=t.filter((e=>l.has("string"==typeof e?e:e.name)));return[o,new Proxy(e,{get:(e,t)=>"executionProviders"===t?c:Reflect.get(e,t)})]}},"./node_modules/onnxruntime-common/dist/esm/backend.js":
|
|
@@ -88,10 +88,10 @@
|
|
|
88
88
|
\******************************/(e,t,n)=>{"use strict";var s,r;n.r(t),n.d(t,{Tensor:()=>l.Tensor,createInferenceSession:()=>g,deviceToExecutionProviders:()=>m,isONNXProxy:()=>b,isONNXTensor:()=>w});var o=n(/*! ../env.js */"./src/env.js"),i=n(/*! onnxruntime-node */"onnxruntime-node"),a=n(/*! #onnxruntime-webgpu */"?cb4d"),l=n(/*! onnxruntime-common */"./node_modules/onnxruntime-common/dist/esm/index.js");const c=Object.freeze({auto:null,gpu:null,cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",webnn:{name:"webnn",deviceType:"cpu"},"webnn-npu":{name:"webnn",deviceType:"npu"},"webnn-gpu":{name:"webnn",deviceType:"gpu"},"webnn-cpu":{name:"webnn",deviceType:"cpu"}}),d=[];let u,p;const h=Symbol.for("onnxruntime");if(h in globalThis)p=globalThis[h];else if(o.apis.IS_NODE_ENV){switch(p=i??(s||(s=n.t(i,2))),process.platform){case"win32":d.push("dml");break;case"linux":"x64"===process.arch&&d.push("cuda")}d.push("cpu"),u=["cpu"]}else p=r||(r=n.t(a,2)),o.apis.IS_WEBNN_AVAILABLE&&d.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),o.apis.IS_WEBGPU_AVAILABLE&&d.push("webgpu"),d.push("wasm"),u=["wasm"];const _=p.InferenceSession;function m(e=null){if(!e)return u;switch(e){case"auto":return d;case"gpu":return d.filter((e=>["webgpu","cuda","dml","webnn-gpu"].includes(e)))}if(d.includes(e))return[c[e]??e];throw new Error(`Unsupported device: "${e}". Should be one of: ${d.join(", ")}.`)}let f=null;async function g(e,t){f&&await f;const n=_.create(e,t);return f??=n,await n}function w(e){return e instanceof p.Tensor}const M=p?.env;function b(){return M?.wasm?.proxy}M?.wasm&&(M.wasm.wasmPaths=`https://cdn.jsdelivr.net/npm/@huggingface/transformers@${o.env.version}/dist/`,M.wasm.proxy=!1,"undefined"!=typeof crossOriginIsolated&&crossOriginIsolated||(M.wasm.numThreads=1)),M?.webgpu&&(M.webgpu.powerPreference="high-performance"),o.env.backends.onnx=M},"./src/configs.js":
|
|
89
89
|
/*!************************!*\
|
|
90
90
|
!*** ./src/configs.js ***!
|
|
91
|
-
\************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{AutoConfig:()=>l,PretrainedConfig:()=>a,getKeyValueShapes:()=>i});var s=n(/*! ./utils/core.js */"./src/utils/core.js"),r=n(/*! ./utils/hub.js */"./src/utils/hub.js");function o(e){const t={};let n={};switch(e.model_type){case"llava":case"paligemma":case"florence2":n=o(e.text_config);break;case"moondream1":n=o(e.phi_config);break;case"musicgen":n=o(e.decoder);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"phi":case"phi3":case"falcon":t.num_heads="num_attention_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size";break;case"llama":case"cohere":case"mistral":case"starcoder2":case"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";break;case"gemma":case"gemma2":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"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"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"vision-encoder-decoder":const r=o(e.decoder),i="num_decoder_layers"in r,a=(0,s.pick)(e,["model_type","is_encoder_decoder"]);return i?(a.num_decoder_layers=r.num_decoder_layers,a.num_decoder_heads=r.num_decoder_heads,a.decoder_hidden_size=r.decoder_hidden_size,a.num_encoder_layers=r.num_encoder_layers,a.num_encoder_heads=r.num_encoder_heads,a.encoder_hidden_size=r.encoder_hidden_size):(a.num_layers=r.num_layers,a.num_heads=r.num_heads,a.hidden_size=r.hidden_size),a}const r={...n,...(0,s.pick)(e,["model_type","multi_query","is_encoder_decoder"])};for(const n in t)r[n]=e[t[n]];return r}function i(e,{prefix:t="past_key_values"}={}){const n={},s=e.normalized_config;if(s.is_encoder_decoder&&"num_encoder_heads"in s&&"num_decoder_heads"in s){const e=s.encoder_dim_kv??s.encoder_hidden_size/s.num_encoder_heads,r=s.decoder_dim_kv??s.decoder_hidden_size/s.num_decoder_heads,o=[1,s.num_encoder_heads,0,e],i=[1,s.num_decoder_heads,0,r];for(let e=0;e<s.num_decoder_layers;++e)n[`${t}.${e}.encoder.key`]=o,n[`${t}.${e}.encoder.value`]=o,n[`${t}.${e}.decoder.key`]=i,n[`${t}.${e}.decoder.value`]=i}else{const e=s.num_heads,r=s.num_layers,o=s.dim_kv??s.hidden_size/(s.num_attention_heads??e);if("falcon"===s.model_type){const s=[1*e,0,o];for(let e=0;e<r;++e)n[`${t}.${e}.key`]=s,n[`${t}.${e}.value`]=s}else if(s.multi_query){const s=[1*e,0,2*o];for(let e=0;e<r;++e)n[`${t}.${e}.key_value`]=s}else if("bloom"===s.model_type){const s=[1*e,o,0],i=[1*e,0,o];for(let e=0;e<r;++e)n[`${t}.${e}.key`]=s,n[`${t}.${e}.value`]=i}else if("openelm"===s.model_type)for(let s=0;s<r;++s){const r=[1,e[s],0,o];n[`${t}.${s}.key`]=r,n[`${t}.${s}.value`]=r}else{const s=[1,e,0,o];for(let e=0;e<r;++e)n[`${t}.${e}.key`]=s,n[`${t}.${e}.value`]=s}}return n}class a{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=o(this)}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:s=null,local_files_only:o=!1,revision:i="main"}={}){!n||n instanceof a||(n=new a(n));const l=n??await async function(e,t){return await(0,r.getModelJSON)(e,"config.json",!0,t)}(e,{progress_callback:t,config:n,cache_dir:s,local_files_only:o,revision:i});return new this(l)}}class l{static async from_pretrained(...e){return a.from_pretrained(...e)}}},"./src/env.js":
|
|
91
|
+
\************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{AutoConfig:()=>l,PretrainedConfig:()=>a,getKeyValueShapes:()=>i});var s=n(/*! ./utils/core.js */"./src/utils/core.js"),r=n(/*! ./utils/hub.js */"./src/utils/hub.js");function o(e){const t={};let n={};switch(e.model_type){case"llava":case"paligemma":case"florence2":n=o(e.text_config);break;case"moondream1":n=o(e.phi_config);break;case"musicgen":n=o(e.decoder);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"phi":case"phi3":case"falcon":t.num_heads="num_attention_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size";break;case"llama":case"granite":case"cohere":case"mistral":case"starcoder2":case"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";break;case"gemma":case"gemma2":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"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"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"vision-encoder-decoder":const r=o(e.decoder),i="num_decoder_layers"in r,a=(0,s.pick)(e,["model_type","is_encoder_decoder"]);return i?(a.num_decoder_layers=r.num_decoder_layers,a.num_decoder_heads=r.num_decoder_heads,a.decoder_hidden_size=r.decoder_hidden_size,a.num_encoder_layers=r.num_encoder_layers,a.num_encoder_heads=r.num_encoder_heads,a.encoder_hidden_size=r.encoder_hidden_size):(a.num_layers=r.num_layers,a.num_heads=r.num_heads,a.hidden_size=r.hidden_size),a}const r={...n,...(0,s.pick)(e,["model_type","multi_query","is_encoder_decoder"])};for(const n in t)r[n]=e[t[n]];return r}function i(e,{prefix:t="past_key_values"}={}){const n={},s=e.normalized_config;if(s.is_encoder_decoder&&"num_encoder_heads"in s&&"num_decoder_heads"in s){const e=s.encoder_dim_kv??s.encoder_hidden_size/s.num_encoder_heads,r=s.decoder_dim_kv??s.decoder_hidden_size/s.num_decoder_heads,o=[1,s.num_encoder_heads,0,e],i=[1,s.num_decoder_heads,0,r];for(let e=0;e<s.num_decoder_layers;++e)n[`${t}.${e}.encoder.key`]=o,n[`${t}.${e}.encoder.value`]=o,n[`${t}.${e}.decoder.key`]=i,n[`${t}.${e}.decoder.value`]=i}else{const e=s.num_heads,r=s.num_layers,o=s.dim_kv??s.hidden_size/(s.num_attention_heads??e);if("falcon"===s.model_type){const s=[1*e,0,o];for(let e=0;e<r;++e)n[`${t}.${e}.key`]=s,n[`${t}.${e}.value`]=s}else if(s.multi_query){const s=[1*e,0,2*o];for(let e=0;e<r;++e)n[`${t}.${e}.key_value`]=s}else if("bloom"===s.model_type){const s=[1*e,o,0],i=[1*e,0,o];for(let e=0;e<r;++e)n[`${t}.${e}.key`]=s,n[`${t}.${e}.value`]=i}else if("openelm"===s.model_type)for(let s=0;s<r;++s){const r=[1,e[s],0,o];n[`${t}.${s}.key`]=r,n[`${t}.${s}.value`]=r}else{const s=[1,e,0,o];for(let e=0;e<r;++e)n[`${t}.${e}.key`]=s,n[`${t}.${e}.value`]=s}}return n}class a{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=o(this)}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:s=null,local_files_only:o=!1,revision:i="main"}={}){!n||n instanceof a||(n=new a(n));const l=n??await async function(e,t){return await(0,r.getModelJSON)(e,"config.json",!0,t)}(e,{progress_callback:t,config:n,cache_dir:s,local_files_only:o,revision:i});return new this(l)}}class l{static async from_pretrained(...e){return a.from_pretrained(...e)}}},"./src/env.js":
|
|
92
92
|
/*!********************!*\
|
|
93
93
|
!*** ./src/env.js ***!
|
|
94
|
-
\********************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{apis:()=>m,env:()=>b});var s=n(/*! fs */"fs"),r=n(/*! path */"path"),o=n(/*! url */"url");const i="undefined"!=typeof self,a=i&&"DedicatedWorkerGlobalScope"===self.constructor.name,l=i&&"caches"in self,c="undefined"!=typeof navigator&&"gpu"in navigator,d="undefined"!=typeof navigator&&"ml"in navigator,u="undefined"!=typeof process,p=u&&"node"===process?.release?.name,h=!y(s),_=!y(r),m=Object.freeze({IS_BROWSER_ENV:i,IS_WEBWORKER_ENV:a,IS_WEB_CACHE_AVAILABLE:l,IS_WEBGPU_AVAILABLE:c,IS_WEBNN_AVAILABLE:d,IS_PROCESS_AVAILABLE:u,IS_NODE_ENV:p,IS_FS_AVAILABLE:h,IS_PATH_AVAILABLE:_}),f=h&&_,g=f?r.dirname(r.dirname(o.fileURLToPath("file:///workspaces/transformers.js/src/env.js"))):"./",w=f?r.join(g,"/.cache/"):null,M="/models/",b={version:"3.0.0-alpha.
|
|
94
|
+
\********************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{apis:()=>m,env:()=>b});var s=n(/*! fs */"fs"),r=n(/*! path */"path"),o=n(/*! url */"url");const i="undefined"!=typeof self,a=i&&"DedicatedWorkerGlobalScope"===self.constructor.name,l=i&&"caches"in self,c="undefined"!=typeof navigator&&"gpu"in navigator,d="undefined"!=typeof navigator&&"ml"in navigator,u="undefined"!=typeof process,p=u&&"node"===process?.release?.name,h=!y(s),_=!y(r),m=Object.freeze({IS_BROWSER_ENV:i,IS_WEBWORKER_ENV:a,IS_WEB_CACHE_AVAILABLE:l,IS_WEBGPU_AVAILABLE:c,IS_WEBNN_AVAILABLE:d,IS_PROCESS_AVAILABLE:u,IS_NODE_ENV:p,IS_FS_AVAILABLE:h,IS_PATH_AVAILABLE:_}),f=h&&_,g=f?r.dirname(r.dirname(o.fileURLToPath("file:///workspaces/transformers.js/src/env.js"))):"./",w=f?r.join(g,"/.cache/"):null,M="/models/",b={version:"3.0.0-alpha.21",backends:{onnx:{}},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!i,localModelPath:f?r.join(g,M):M,useFS:h,useBrowserCache:l,useFSCache:h,cacheDir:w,useCustomCache:!1,customCache:null};function y(e){return 0===Object.keys(e).length}},"./src/generation/configuration_utils.js":
|
|
95
95
|
/*!***********************************************!*\
|
|
96
96
|
!*** ./src/generation/configuration_utils.js ***!
|
|
97
97
|
\***********************************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{GenerationConfig:()=>r});var s=n(/*! ../utils/core.js */"./src/utils/core.js");class r{max_length=20;max_new_tokens=null;min_length=0;min_new_tokens=null;early_stopping=!1;max_time=null;do_sample=!1;num_beams=1;num_beam_groups=1;penalty_alpha=null;use_cache=!0;temperature=1;top_k=50;top_p=1;typical_p=1;epsilon_cutoff=0;eta_cutoff=0;diversity_penalty=0;repetition_penalty=1;encoder_repetition_penalty=1;length_penalty=1;no_repeat_ngram_size=0;bad_words_ids=null;force_words_ids=null;renormalize_logits=!1;constraints=null;forced_bos_token_id=null;forced_eos_token_id=null;remove_invalid_values=!1;exponential_decay_length_penalty=null;suppress_tokens=null;begin_suppress_tokens=null;forced_decoder_ids=null;guidance_scale=null;num_return_sequences=1;output_attentions=!1;output_hidden_states=!1;output_scores=!1;return_dict_in_generate=!1;pad_token_id=null;bos_token_id=null;eos_token_id=null;encoder_no_repeat_ngram_size=0;decoder_start_token_id=null;generation_kwargs={};constructor(e){Object.assign(this,(0,s.pick)(e,Object.getOwnPropertyNames(this)))}}},"./src/generation/logits_process.js":
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
\*************************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{BaseStreamer:()=>i,TextStreamer:()=>l,WhisperTextStreamer:()=>c});var s=n(/*! ../utils/core.js */"./src/utils/core.js"),r=n(/*! ../tokenizers.js */"./src/tokenizers.js"),o=n(/*! ../env.js */"./src/env.js");class i{put(e){throw Error("Not implemented")}end(){throw Error("Not implemented")}}const a=o.apis.IS_PROCESS_AVAILABLE?e=>process.stdout.write(e):e=>console.log(e);class l extends i{constructor(e,{skip_prompt:t=!1,callback_function:n=null,token_callback_function:s=null,decode_kwargs:r={},...o}={}){super(),this.tokenizer=e,this.skip_prompt=t,this.callback_function=n??a,this.token_callback_function=s,this.decode_kwargs={...r,...o},this.token_cache=[],this.print_len=0,this.next_tokens_are_prompt=!0}put(e){if(e.length>1)throw Error("TextStreamer only supports batch size of 1");if(this.skip_prompt&&this.next_tokens_are_prompt)return void(this.next_tokens_are_prompt=!1);const t=e[0];this.token_callback_function?.(t),this.token_cache=(0,s.mergeArrays)(this.token_cache,t);const n=this.tokenizer.decode(this.token_cache,this.decode_kwargs);let o;n.endsWith("\n")?(o=n.slice(this.print_len),this.token_cache=[],this.print_len=0):n.length>0&&(0,r.is_chinese_char)(n.charCodeAt(n.length-1))?(o=n.slice(this.print_len),this.print_len+=o.length):(o=n.slice(this.print_len,n.lastIndexOf(" ")+1),this.print_len+=o.length),this.on_finalized_text(o,!1)}end(){let e;if(this.token_cache.length>0){e=this.tokenizer.decode(this.token_cache,this.decode_kwargs).slice(this.print_len),this.token_cache=[],this.print_len=0}else e="";this.next_tokens_are_prompt=!0,this.on_finalized_text(e,!0)}on_finalized_text(e,t){e.length>0&&this.callback_function?.(e),t&&this.callback_function===a&&o.apis.IS_PROCESS_AVAILABLE&&this.callback_function?.("\n")}}class c extends l{constructor(e,{skip_prompt:t=!1,callback_function:n=null,token_callback_function:s=null,on_chunk_start:r=null,on_chunk_end:o=null,on_finalize:i=null,time_precision:a=.02,skip_special_tokens:l=!0,decode_kwargs:c={}}={}){super(e,{skip_prompt:t,callback_function:n,token_callback_function:s,decode_kwargs:{skip_special_tokens:l,...c}}),this.timestamp_begin=e.timestamp_begin,this.on_chunk_start=r,this.on_chunk_end=o,this.on_finalize=i,this.time_precision=a,this.waiting_for_timestamp=!1}put(e){if(e.length>1)throw Error("WhisperTextStreamer only supports batch size of 1");const t=e[0];if(1===t.length){const n=Number(t[0])-this.timestamp_begin;if(n>=0){const t=n*this.time_precision;this.waiting_for_timestamp?this.on_chunk_end?.(t):this.on_chunk_start?.(t),this.waiting_for_timestamp=!this.waiting_for_timestamp,e=[[]]}}return super.put(e)}end(){super.end(),this.on_finalize?.()}}},"./src/models.js":
|
|
110
110
|
/*!***********************!*\
|
|
111
111
|
!*** ./src/models.js ***!
|
|
112
|
-
\***********************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{ASTForAudioClassification:()=>nn,ASTModel:()=>tn,ASTPreTrainedModel:()=>en,AlbertForMaskedLM:()=>ut,AlbertForQuestionAnswering:()=>dt,AlbertForSequenceClassification:()=>ct,AlbertModel:()=>lt,AlbertPreTrainedModel:()=>at,AutoModel:()=>La,AutoModelForAudioClassification:()=>Ka,AutoModelForAudioFrameClassification:()=>el,AutoModelForCTC:()=>Ja,AutoModelForCausalLM:()=>Va,AutoModelForDepthEstimation:()=>rl,AutoModelForDocumentQuestionAnswering:()=>tl,AutoModelForImageClassification:()=>qa,AutoModelForImageFeatureExtraction:()=>il,AutoModelForImageMatting:()=>nl,AutoModelForImageSegmentation:()=>Ua,AutoModelForImageToImage:()=>sl,AutoModelForMaskGeneration:()=>Ya,AutoModelForMaskedLM:()=>Ra,AutoModelForNormalEstimation:()=>ol,AutoModelForObjectDetection:()=>Qa,AutoModelForQuestionAnswering:()=>Ga,AutoModelForSemanticSegmentation:()=>Wa,AutoModelForSeq2SeqLM:()=>Na,AutoModelForSequenceClassification:()=>Ia,AutoModelForSpeechSeq2Seq:()=>Oa,AutoModelForTextToSpectrogram:()=>ja,AutoModelForTextToWaveform:()=>Da,AutoModelForTokenClassification:()=>Ba,AutoModelForUniversalSegmentation:()=>Xa,AutoModelForVision2Seq:()=>$a,AutoModelForXVector:()=>Za,AutoModelForZeroShotObjectDetection:()=>Ha,BartForConditionalGeneration:()=>kt,BartForSequenceClassification:()=>Tt,BartModel:()=>xt,BartPretrainedModel:()=>yt,BaseModelOutput:()=>$,BeitForImageClassification:()=>ir,BeitModel:()=>or,BeitPreTrainedModel:()=>rr,BertForMaskedLM:()=>W,BertForQuestionAnswering:()=>H,BertForSequenceClassification:()=>X,BertForTokenClassification:()=>Q,BertModel:()=>U,BertPreTrainedModel:()=>q,BlenderbotForConditionalGeneration:()=>zt,BlenderbotModel:()=>Et,BlenderbotPreTrainedModel:()=>At,BlenderbotSmallForConditionalGeneration:()=>Bt,BlenderbotSmallModel:()=>It,BlenderbotSmallPreTrainedModel:()=>Lt,BloomForCausalLM:()=>ys,BloomModel:()=>bs,BloomPreTrainedModel:()=>Ms,CLIPModel:()=>_n,CLIPPreTrainedModel:()=>hn,CLIPSegForImageSegmentation:()=>Cn,CLIPSegModel:()=>Fn,CLIPSegPreTrainedModel:()=>vn,CLIPTextModel:()=>mn,CLIPTextModelWithProjection:()=>fn,CLIPVisionModel:()=>gn,CLIPVisionModelWithProjection:()=>wn,CamembertForMaskedLM:()=>we,CamembertForQuestionAnswering:()=>ye,CamembertForSequenceClassification:()=>Me,CamembertForTokenClassification:()=>be,CamembertModel:()=>ge,CamembertPreTrainedModel:()=>fe,CausalLMOutput:()=>hl,CausalLMOutputWithPast:()=>_l,ChineseCLIPModel:()=>Tn,ChineseCLIPPreTrainedModel:()=>kn,ClapAudioModelWithProjection:()=>xi,ClapModel:()=>bi,ClapPreTrainedModel:()=>Mi,ClapTextModelWithProjection:()=>yi,CodeGenForCausalLM:()=>Qn,CodeGenModel:()=>Xn,CodeGenPreTrainedModel:()=>Wn,CohereForCausalLM:()=>es,CohereModel:()=>Zn,CoherePreTrainedModel:()=>Kn,ConvBertForMaskedLM:()=>ie,ConvBertForQuestionAnswering:()=>ce,ConvBertForSequenceClassification:()=>ae,ConvBertForTokenClassification:()=>le,ConvBertModel:()=>oe,ConvBertPreTrainedModel:()=>re,ConvNextForImageClassification:()=>so,ConvNextModel:()=>no,ConvNextPreTrainedModel:()=>to,ConvNextV2ForImageClassification:()=>io,ConvNextV2Model:()=>oo,ConvNextV2PreTrainedModel:()=>ro,DPTForDepthEstimation:()=>jr,DPTModel:()=>Or,DPTPreTrainedModel:()=>Nr,DebertaForMaskedLM:()=>Te,DebertaForQuestionAnswering:()=>Ce,DebertaForSequenceClassification:()=>ve,DebertaForTokenClassification:()=>Fe,DebertaModel:()=>ke,DebertaPreTrainedModel:()=>xe,DebertaV2ForMaskedLM:()=>Ae,DebertaV2ForQuestionAnswering:()=>Le,DebertaV2ForSequenceClassification:()=>Ee,DebertaV2ForTokenClassification:()=>ze,DebertaV2Model:()=>Se,DebertaV2PreTrainedModel:()=>Pe,DecisionTransformerModel:()=>Ki,DecisionTransformerPreTrainedModel:()=>Ji,DeiTForImageClassification:()=>kr,DeiTModel:()=>xr,DeiTPreTrainedModel:()=>yr,DepthAnythingForDepthEstimation:()=>Vr,DepthAnythingPreTrainedModel:()=>Dr,DepthProForDepthEstimation:()=>Wr,DepthProPreTrainedModel:()=>Ur,DetrForObjectDetection:()=>cr,DetrForSegmentation:()=>dr,DetrModel:()=>lr,DetrObjectDetectionOutput:()=>ur,DetrPreTrainedModel:()=>ar,DetrSegmentationOutput:()=>pr,Dinov2ForImageClassification:()=>co,Dinov2Model:()=>lo,Dinov2PreTrainedModel:()=>ao,DistilBertForMaskedLM:()=>De,DistilBertForQuestionAnswering:()=>je,DistilBertForSequenceClassification:()=>Ne,DistilBertForTokenClassification:()=>Oe,DistilBertModel:()=>Be,DistilBertPreTrainedModel:()=>Ie,DonutSwinModel:()=>eo,DonutSwinPreTrainedModel:()=>Zr,EfficientNetForImageClassification:()=>Ii,EfficientNetModel:()=>Li,EfficientNetPreTrainedModel:()=>zi,ElectraForMaskedLM:()=>pe,ElectraForQuestionAnswering:()=>me,ElectraForSequenceClassification:()=>he,ElectraForTokenClassification:()=>_e,ElectraModel:()=>ue,ElectraPreTrainedModel:()=>de,EsmForMaskedLM:()=>Ge,EsmForSequenceClassification:()=>$e,EsmForTokenClassification:()=>qe,EsmModel:()=>Re,EsmPreTrainedModel:()=>Ve,FalconForCausalLM:()=>wi,FalconModel:()=>gi,FalconPreTrainedModel:()=>fi,FastViTForImageClassification:()=>$s,FastViTModel:()=>Gs,FastViTPreTrainedModel:()=>Rs,Florence2ForConditionalGeneration:()=>pn,Florence2PreTrainedModel:()=>un,GLPNForDepthEstimation:()=>Kr,GLPNModel:()=>Jr,GLPNPreTrainedModel:()=>Yr,GPT2LMHeadModel:()=>An,GPT2Model:()=>Sn,GPT2PreTrainedModel:()=>Pn,GPTBigCodeForCausalLM:()=>Un,GPTBigCodeModel:()=>qn,GPTBigCodePreTrainedModel:()=>$n,GPTJForCausalLM:()=>Gn,GPTJModel:()=>Rn,GPTJPreTrainedModel:()=>Vn,GPTNeoForCausalLM:()=>Nn,GPTNeoModel:()=>Bn,GPTNeoPreTrainedModel:()=>In,GPTNeoXForCausalLM:()=>Dn,GPTNeoXModel:()=>jn,GPTNeoXPreTrainedModel:()=>On,Gemma2ForCausalLM:()=>is,Gemma2Model:()=>os,Gemma2PreTrainedModel:()=>rs,GemmaForCausalLM:()=>ss,GemmaModel:()=>ns,GemmaPreTrainedModel:()=>ts,GroupViTModel:()=>Vs,GroupViTPreTrainedModel:()=>Ds,HieraForImageClassification:()=>Fr,HieraModel:()=>vr,HieraPreTrainedModel:()=>Tr,HubertForCTC:()=>Ho,HubertForSequenceClassification:()=>Yo,HubertModel:()=>Qo,HubertPreTrainedModel:()=>Xo,ImageMattingOutput:()=>ml,JAISLMHeadModel:()=>Ln,JAISModel:()=>zn,JAISPreTrainedModel:()=>En,LlamaForCausalLM:()=>Jn,LlamaModel:()=>Yn,LlamaPreTrainedModel:()=>Hn,LlavaForConditionalGeneration:()=>cn,LlavaPreTrainedModel:()=>ln,LongT5ForConditionalGeneration:()=>gt,LongT5Model:()=>ft,LongT5PreTrainedModel:()=>mt,M2M100ForConditionalGeneration:()=>ko,M2M100Model:()=>xo,M2M100PreTrainedModel:()=>yo,MBartForCausalLM:()=>St,MBartForConditionalGeneration:()=>Ct,MBartForSequenceClassification:()=>Pt,MBartModel:()=>Ft,MBartPreTrainedModel:()=>vt,MPNetForMaskedLM:()=>Ke,MPNetForQuestionAnswering:()=>tt,MPNetForSequenceClassification:()=>Ze,MPNetForTokenClassification:()=>et,MPNetModel:()=>Je,MPNetPreTrainedModel:()=>Ye,MT5ForConditionalGeneration:()=>bt,MT5Model:()=>Mt,MT5PreTrainedModel:()=>wt,MarianMTModel:()=>bo,MarianModel:()=>Mo,MarianPreTrainedModel:()=>wo,MaskFormerForInstanceSegmentation:()=>Hr,MaskFormerModel:()=>Qr,MaskFormerPreTrainedModel:()=>Xr,MaskedLMOutput:()=>ul,MistralForCausalLM:()=>pi,MistralModel:()=>ui,MistralPreTrainedModel:()=>di,MobileBertForMaskedLM:()=>Xe,MobileBertForQuestionAnswering:()=>He,MobileBertForSequenceClassification:()=>Qe,MobileBertModel:()=>We,MobileBertPreTrainedModel:()=>Ue,MobileNetV1ForImageClassification:()=>Ri,MobileNetV1Model:()=>Vi,MobileNetV1PreTrainedModel:()=>Di,MobileNetV2ForImageClassification:()=>qi,MobileNetV2Model:()=>$i,MobileNetV2PreTrainedModel:()=>Gi,MobileNetV3ForImageClassification:()=>Xi,MobileNetV3Model:()=>Wi,MobileNetV3PreTrainedModel:()=>Ui,MobileNetV4ForImageClassification:()=>Yi,MobileNetV4Model:()=>Hi,MobileNetV4PreTrainedModel:()=>Qi,MobileViTForImageClassification:()=>Qs,MobileViTModel:()=>Xs,MobileViTPreTrainedModel:()=>Ws,MobileViTV2ForImageClassification:()=>Js,MobileViTV2Model:()=>Ys,MobileViTV2PreTrainedModel:()=>Hs,ModelOutput:()=>G,Moondream1ForConditionalGeneration:()=>dn,MptForCausalLM:()=>Ts,MptModel:()=>ks,MptPreTrainedModel:()=>xs,MusicgenForCausalLM:()=>Oi,MusicgenForConditionalGeneration:()=>ji,MusicgenModel:()=>Ni,MusicgenPreTrainedModel:()=>Bi,NomicBertModel:()=>J,NomicBertPreTrainedModel:()=>Y,OPTForCausalLM:()=>Cs,OPTModel:()=>Fs,OPTPreTrainedModel:()=>vs,OpenELMForCausalLM:()=>cs,OpenELMModel:()=>ls,OpenELMPreTrainedModel:()=>as,OwlViTForObjectDetection:()=>er,OwlViTModel:()=>Zs,OwlViTPreTrainedModel:()=>Ks,Owlv2ForObjectDetection:()=>sr,Owlv2Model:()=>nr,Owlv2PreTrainedModel:()=>tr,Phi3ForCausalLM:()=>ws,Phi3Model:()=>gs,Phi3PreTrainedModel:()=>fs,PhiForCausalLM:()=>ms,PhiModel:()=>_s,PhiPreTrainedModel:()=>hs,PreTrainedModel:()=>R,PretrainedMixin:()=>Zi,PvtForImageClassification:()=>Ls,PvtModel:()=>zs,PvtPreTrainedModel:()=>Es,PyAnnoteForAudioFrameClassification:()=>Eo,PyAnnoteModel:()=>Ao,PyAnnotePreTrainedModel:()=>So,QuestionAnsweringModelOutput:()=>pl,Qwen2ForCausalLM:()=>ps,Qwen2Model:()=>us,Qwen2PreTrainedModel:()=>ds,RTDetrForObjectDetection:()=>mr,RTDetrModel:()=>_r,RTDetrObjectDetectionOutput:()=>fr,RTDetrPreTrainedModel:()=>hr,ResNetForImageClassification:()=>Sr,ResNetModel:()=>Pr,ResNetPreTrainedModel:()=>Cr,RoFormerForMaskedLM:()=>ee,RoFormerForQuestionAnswering:()=>se,RoFormerForSequenceClassification:()=>te,RoFormerForTokenClassification:()=>ne,RoFormerModel:()=>Z,RoFormerPreTrainedModel:()=>K,RobertaForMaskedLM:()=>jt,RobertaForQuestionAnswering:()=>Rt,RobertaForSequenceClassification:()=>Dt,RobertaForTokenClassification:()=>Vt,RobertaModel:()=>Ot,RobertaPreTrainedModel:()=>Nt,SamImageSegmentationOutput:()=>go,SamModel:()=>fo,SamPreTrainedModel:()=>mo,SapiensForDepthEstimation:()=>$r,SapiensForNormalEstimation:()=>qr,SapiensForSemanticSegmentation:()=>Gr,SapiensPreTrainedModel:()=>Rr,SegformerForImageClassification:()=>Ci,SegformerForSemanticSegmentation:()=>Pi,SegformerModel:()=>Fi,SegformerPreTrainedModel:()=>vi,Seq2SeqLMOutput:()=>al,SequenceClassifierOutput:()=>ll,SiglipModel:()=>bn,SiglipPreTrainedModel:()=>Mn,SiglipTextModel:()=>yn,SiglipVisionModel:()=>xn,SpeechT5ForSpeechToText:()=>oi,SpeechT5ForTextToSpeech:()=>ii,SpeechT5HifiGan:()=>ai,SpeechT5Model:()=>ri,SpeechT5PreTrainedModel:()=>si,SqueezeBertForMaskedLM:()=>rt,SqueezeBertForQuestionAnswering:()=>it,SqueezeBertForSequenceClassification:()=>ot,SqueezeBertModel:()=>st,SqueezeBertPreTrainedModel:()=>nt,StableLmForCausalLM:()=>Ei,StableLmModel:()=>Ai,StableLmPreTrainedModel:()=>Si,Starcoder2ForCausalLM:()=>mi,Starcoder2Model:()=>_i,Starcoder2PreTrainedModel:()=>hi,Swin2SRForImageSuperResolution:()=>Br,Swin2SRModel:()=>Ir,Swin2SRPreTrainedModel:()=>Lr,SwinForImageClassification:()=>zr,SwinModel:()=>Er,SwinPreTrainedModel:()=>Ar,T5ForConditionalGeneration:()=>_t,T5Model:()=>ht,T5PreTrainedModel:()=>pt,TableTransformerForObjectDetection:()=>Mr,TableTransformerModel:()=>wr,TableTransformerObjectDetectionOutput:()=>br,TableTransformerPreTrainedModel:()=>gr,TokenClassifierOutput:()=>dl,TrOCRForCausalLM:()=>ci,TrOCRPreTrainedModel:()=>li,UniSpeechForCTC:()=>No,UniSpeechForSequenceClassification:()=>Oo,UniSpeechModel:()=>Bo,UniSpeechPreTrainedModel:()=>Io,UniSpeechSatForAudioFrameClassification:()=>Go,UniSpeechSatForCTC:()=>Vo,UniSpeechSatForSequenceClassification:()=>Ro,UniSpeechSatModel:()=>Do,UniSpeechSatPreTrainedModel:()=>jo,ViTForImageClassification:()=>As,ViTMAEModel:()=>Bs,ViTMAEPreTrainedModel:()=>Is,ViTMSNForImageClassification:()=>js,ViTMSNModel:()=>Os,ViTMSNPreTrainedModel:()=>Ns,ViTModel:()=>Ss,ViTPreTrainedModel:()=>Ps,VisionEncoderDecoderModel:()=>an,VitMatteForImageMatting:()=>Us,VitMattePreTrainedModel:()=>qs,VitsModel:()=>Ti,VitsModelOutput:()=>fl,VitsPreTrainedModel:()=>ki,Wav2Vec2BertForCTC:()=>Uo,Wav2Vec2BertForSequenceClassification:()=>Wo,Wav2Vec2BertModel:()=>qo,Wav2Vec2BertPreTrainedModel:()=>$o,Wav2Vec2ForAudioFrameClassification:()=>Po,Wav2Vec2ForCTC:()=>Fo,Wav2Vec2ForSequenceClassification:()=>Co,Wav2Vec2Model:()=>vo,Wav2Vec2PreTrainedModel:()=>To,WavLMForAudioFrameClassification:()=>ni,WavLMForCTC:()=>Zo,WavLMForSequenceClassification:()=>ei,WavLMForXVector:()=>ti,WavLMModel:()=>Ko,WavLMPreTrainedModel:()=>Jo,WeSpeakerResNetModel:()=>Lo,WeSpeakerResNetPreTrainedModel:()=>zo,WhisperForConditionalGeneration:()=>on,WhisperModel:()=>rn,WhisperPreTrainedModel:()=>sn,XLMForQuestionAnswering:()=>Xt,XLMForSequenceClassification:()=>Ut,XLMForTokenClassification:()=>Wt,XLMModel:()=>$t,XLMPreTrainedModel:()=>Gt,XLMRobertaForMaskedLM:()=>Yt,XLMRobertaForQuestionAnswering:()=>Zt,XLMRobertaForSequenceClassification:()=>Jt,XLMRobertaForTokenClassification:()=>Kt,XLMRobertaModel:()=>Ht,XLMRobertaPreTrainedModel:()=>Qt,XLMWithLMHeadModel:()=>qt,XVectorOutput:()=>cl,YolosForObjectDetection:()=>ho,YolosModel:()=>po,YolosObjectDetectionOutput:()=>_o,YolosPreTrainedModel:()=>uo});var s=n(/*! ./configs.js */"./src/configs.js"),r=n(/*! ./backends/onnx.js */"./src/backends/onnx.js"),o=n(/*! ./utils/dtypes.js */"./src/utils/dtypes.js"),i=n(/*! ./utils/generic.js */"./src/utils/generic.js"),a=n(/*! ./utils/core.js */"./src/utils/core.js"),l=n(/*! ./utils/hub.js */"./src/utils/hub.js"),c=n(/*! ./generation/logits_process.js */"./src/generation/logits_process.js"),d=n(/*! ./generation/configuration_utils.js */"./src/generation/configuration_utils.js"),u=n(/*! ./utils/tensor.js */"./src/utils/tensor.js"),p=n(/*! ./utils/maths.js */"./src/utils/maths.js"),h=n(/*! ./generation/stopping_criteria.js */"./src/generation/stopping_criteria.js"),_=n(/*! ./generation/logits_sampler.js */"./src/generation/logits_sampler.js"),m=n(/*! ./env.js */"./src/env.js"),f=n(/*! ./models/whisper/generation_whisper.js */"./src/models/whisper/generation_whisper.js"),g=n(/*! ./models/whisper/common_whisper.js */"./src/models/whisper/common_whisper.js");const w=0,M=1,b=2,y=3,x=4,k=5,T=6,v=7,F=new Map,C=new Map,P=new Map;async function S(e,t,n){return Object.fromEntries(await Promise.all(Object.keys(t).map((async i=>{const{buffer:a,session_options:c}=await async function(e,t,n){const i=n.config?.["transformers.js_config"]??{};let a=n.device??i.device;a&&"string"!=typeof a&&(a.hasOwnProperty(t)?a=a[t]:(console.warn(`device not specified for "${t}". Using the default device.`),a=null));const c=a??(m.apis.IS_NODE_ENV?"cpu":"wasm"),d=(0,r.deviceToExecutionProviders)(c);let u=n.dtype??i.dtype;"string"!=typeof u&&(u&&u.hasOwnProperty(t)?u=u[t]:(u=o.DEFAULT_DEVICE_DTYPE_MAPPING[c]??o.DATA_TYPES.fp32,console.warn(`dtype not specified for "${t}". Using the default dtype (${u}) for this device (${c}).`)));const p=u;if(!o.DEFAULT_DTYPE_SUFFIX_MAPPING.hasOwnProperty(p))throw new Error(`Invalid dtype: ${p}. Should be one of: ${Object.keys(o.DATA_TYPES).join(", ")}`);if(p===o.DATA_TYPES.fp16&&"webgpu"===c&&!await(0,o.isWebGpuFp16Supported)())throw new Error(`The device (${c}) does not support fp16.`);const h=o.DEFAULT_DTYPE_SUFFIX_MAPPING[p],_=`${n.subfolder??""}/${t}${h}.onnx`,f={...n.session_options};f.executionProviders??=d;const g=i.free_dimension_overrides;g?f.freeDimensionOverrides??=g:c.startsWith("webnn")&&!f.freeDimensionOverrides&&console.warn('WebNN does not currently support dynamic shapes and requires `free_dimension_overrides` to be set in config.json as a field within "transformers.js_config". When `free_dimension_overrides` is not set, you may experience significant performance degradation.');const w=(0,l.getModelFile)(e,_,!0,n),M=n.use_external_data_format??i.use_external_data_format;let b=[];if(M&&(!0===M||"object"==typeof M&&M.hasOwnProperty(t)&&!0===M[t])){if(m.apis.IS_NODE_ENV)throw new Error("External data format is not yet supported in Node.js");const s=`${t}${h}.onnx_data`,r=`${n.subfolder??""}/${s}`;b.push(new Promise((async(t,o)=>{const i=await(0,l.getModelFile)(e,r,!0,n);t({path:s,data:i})})))}else void 0!==f.externalData&&(b=f.externalData.map((async t=>{if("string"==typeof t.data){const s=await(0,l.getModelFile)(e,t.data,!0,n);return{...t,data:s}}return t})));if(b.length>0&&(f.externalData=await Promise.all(b)),"webgpu"===c){const e=(0,s.getKeyValueShapes)(n.config,{prefix:"present"});if(Object.keys(e).length>0&&!(0,r.isONNXProxy)()){const t={};for(const n in e)t[n]="gpu-buffer";f.preferredOutputLocation=t}}return{buffer:await w,session_options:f}}(e,t[i],n);return[i,await(0,r.createInferenceSession)(a,c)]}))))}async function A(e,t){const n=function(e,t){const n=Object.create(null),s=[];for(const o of e.inputNames){const e=t[o];e instanceof u.Tensor?n[o]=(0,r.isONNXProxy)()?e.clone():e:s.push(o)}if(s.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${s.join(", ")}.`);const o=Object.keys(t).length,i=e.inputNames.length;if(o>i){let n=Object.keys(t).filter((t=>!e.inputNames.includes(t)));console.warn(`WARNING: Too many inputs were provided (${o} > ${i}). The following inputs will be ignored: "${n.join(", ")}".`)}return n}(e,t);try{const t=Object.fromEntries(Object.entries(n).map((([e,t])=>[e,t.ort_tensor])));let s=await e.run(t);return s=E(s),s}catch(e){throw console.error(`An error occurred during model execution: "${e}".`),console.error("Inputs given to model:",n),e}}function E(e){for(let t in e)(0,r.isONNXTensor)(e[t])?e[t]=new u.Tensor(e[t]):"object"==typeof e[t]&&E(e[t]);return e}function z(e){if(e instanceof u.Tensor)return e;if(0===e.length)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 u.Tensor("int64",BigInt64Array.from(e.flat().map((e=>BigInt(e)))),[e.length,e[0].length])}return new u.Tensor("int64",BigInt64Array.from(e.map((e=>BigInt(e)))),[1,e.length])}function L(e){return new u.Tensor("bool",[e],[1])}async function I(e,t){let{encoder_outputs:n,input_ids:s,decoder_input_ids:r,...o}=t;if(!n){const s=(0,a.pick)(t,e.sessions.model.inputNames);n=(await B(e,s)).last_hidden_state}o.input_ids=r,o.encoder_hidden_states=n,e.sessions.decoder_model_merged.inputNames.includes("encoder_attention_mask")&&(o.encoder_attention_mask=t.attention_mask);return await N(e,o,!0)}async function B(e,t){const n=e.sessions.model,s=(0,a.pick)(t,n.inputNames);if(n.inputNames.includes("inputs_embeds")&&!s.inputs_embeds){if(!t.input_ids)throw new Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");s.inputs_embeds=await e.encode_text({input_ids:t.input_ids})}return n.inputNames.includes("token_type_ids")&&!s.token_type_ids&&(s.token_type_ids=new u.Tensor("int64",new BigInt64Array(s.input_ids.data.length),s.input_ids.dims)),await A(n,s)}async function N(e,t,n=!1){const s=e.sessions[n?"decoder_model_merged":"model"],{past_key_values:r,...o}=t;s.inputNames.includes("use_cache_branch")&&(o.use_cache_branch=L(!!r)),s.inputNames.includes("position_ids")&&o.attention_mask&&!o.position_ids&&(o.position_ids=function(e,t=null){const{input_ids:n,inputs_embeds:s,attention_mask:r}=e,[o,i]=r.dims,a=new BigInt64Array(r.data.length);for(let e=0;e<o;++e){const t=e*i;let n=BigInt(0);for(let e=0;e<i;++e){const s=t+e;0n===r.data[s]?a[s]=BigInt(1):(a[s]=n,n+=r.data[s])}}let l=new u.Tensor("int64",a,r.dims);if(t){const e=-(n??s).dims.at(1);l=l.slice(null,[e,null])}return l}(o,r)),e.addPastKeyValues(o,r);const i=(0,a.pick)(o,s.inputNames);return await A(s,i)}async function O(e,{input_ids:t=null,attention_mask:n=null,pixel_values:s=null,position_ids:r=null,inputs_embeds:o=null,past_key_values:i=null,generation_config:a=null,logits_processor:l=null,...c}){if(!o)if(o=await e.encode_text({input_ids:t}),s&&1!==t.dims[1]){const r=await e.encode_image({pixel_values:s});({inputs_embeds:o,attention_mask:n}=e._merge_input_ids_with_image_features({image_features:r,inputs_embeds:o,input_ids:t,attention_mask:n}))}else if(i&&s&&1===t.dims[1]){const e=t.dims[1],s=Object.values(i)[0].dims.at(-2);n=(0,u.cat)([(0,u.ones)([t.dims[0],s]),n.slice(null,[n.dims[1]-e,n.dims[1]])],1)}return await N(e,{inputs_embeds:o,past_key_values:i,attention_mask:n,position_ids:r,generation_config:a,logits_processor:l},!0)}function j(e,t,n,s){if(n.past_key_values){const t=Object.values(n.past_key_values)[0].dims.at(-2),{input_ids:s,attention_mask:r}=n;if(r&&r.dims[1]>s.dims[1]);else if(t<s.dims[1])n.input_ids=s.slice(null,[t,null]);else if(null!=e.config.image_token_index&&s.data.some((t=>t==e.config.image_token_index))){const r=e.config.num_image_tokens;if(!r)throw new Error("`num_image_tokens` is missing in the model configuration.");const o=s.dims[1]-(t-r);n.input_ids=s.slice(null,[-o,null]),n.attention_mask=(0,u.ones)([1,t+o])}}return n}function D(e,t,n,s){return n.past_key_values&&(t=t.map((e=>[e.at(-1)]))),{...n,decoder_input_ids:z(t)}}function V(e,...t){return e.config.is_encoder_decoder?D(e,...t):j(e,...t)}class R extends i.Callable{main_input_name="input_ids";forward_params=["input_ids","attention_mask"];constructor(e,t){super(),this.config=e,this.sessions=t;const n=P.get(this.constructor),s=F.get(n);switch(this.can_generate=!1,this._forward=null,this._prepare_inputs_for_generation=null,s){case x:this.can_generate=!0,this._forward=N,this._prepare_inputs_for_generation=j;break;case b:case y:case v:this.can_generate=!0,this._forward=I,this._prepare_inputs_for_generation=D;break;case M:this._forward=I;break;case T:this.can_generate=!0,this._forward=O,this._prepare_inputs_for_generation=V;break;default:this._forward=B}this.can_generate&&this.forward_params.push("past_key_values"),this.custom_config=this.config["transformers.js_config"]??{}}async dispose(){const e=[];for(const t of Object.values(this.sessions))t?.handler?.dispose&&e.push(t.handler.dispose());return await Promise.all(e)}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:r=null,local_files_only:o=!1,revision:i="main",model_file_name:a=null,subfolder:c="onnx",device:d=null,dtype:u=null,use_external_data_format:p=null,session_options:h={}}={}){let _={progress_callback:t,config:n,cache_dir:r,local_files_only:o,revision:i,model_file_name:a,subfolder:c,device:d,dtype:u,use_external_data_format:p,session_options:h};const m=P.get(this),f=F.get(m);let g;if(n=_.config=await s.AutoConfig.from_pretrained(e,_),f===x)g=await Promise.all([S(e,{model:_.model_file_name??"model"},_),(0,l.getModelJSON)(e,"generation_config.json",!1,_)]);else if(f===b||f===y)g=await Promise.all([S(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_),(0,l.getModelJSON)(e,"generation_config.json",!1,_)]);else if(f===k)g=await Promise.all([S(e,{model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"},_)]);else if(f===M)g=await Promise.all([S(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_)]);else if(f===T){const t={embed_tokens:"embed_tokens",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};n.is_encoder_decoder&&(t.model="encoder_model"),g=await Promise.all([S(e,t,_),(0,l.getModelJSON)(e,"generation_config.json",!1,_)])}else f===v?g=await Promise.all([S(e,{model:"text_encoder",decoder_model_merged:"decoder_model_merged",encodec_decode:"encodec_decode"},_),(0,l.getModelJSON)(e,"generation_config.json",!1,_)]):(f!==w&&console.warn(`Model type for '${m??n?.model_type}' not found, assuming encoder-only architecture. Please report this at https://github.com/xenova/transformers.js/issues/new/choose.`),g=await Promise.all([S(e,{model:_.model_file_name??"model"},_)]));return new this(n,...g)}async _call(e){return await this.forward(e)}async forward(e){return await this._forward(this,e)}_get_logits_warper(e){const t=new c.LogitsProcessorList;return null!==e.temperature&&1!==e.temperature&&t.push(new c.TemperatureLogitsWarper(e.temperature)),null!==e.top_k&&0!==e.top_k&&t.push(new c.TopKLogitsWarper(e.top_k)),null!==e.top_p&&e.top_p<1&&t.push(new c.TopPLogitsWarper(e.top_p)),t}_get_logits_processor(e,t,n=null){const s=new c.LogitsProcessorList;if(null!==e.repetition_penalty&&1!==e.repetition_penalty&&s.push(new c.RepetitionPenaltyLogitsProcessor(e.repetition_penalty)),null!==e.no_repeat_ngram_size&&e.no_repeat_ngram_size>0&&s.push(new c.NoRepeatNGramLogitsProcessor(e.no_repeat_ngram_size)),null!==e.bad_words_ids&&s.push(new c.NoBadWordsLogitsProcessor(e.bad_words_ids,e.eos_token_id)),null!==e.min_length&&null!==e.eos_token_id&&e.min_length>0&&s.push(new c.MinLengthLogitsProcessor(e.min_length,e.eos_token_id)),null!==e.min_new_tokens&&null!==e.eos_token_id&&e.min_new_tokens>0&&s.push(new c.MinNewTokensLengthLogitsProcessor(t,e.min_new_tokens,e.eos_token_id)),null!==e.forced_bos_token_id&&s.push(new c.ForcedBOSTokenLogitsProcessor(e.forced_bos_token_id)),null!==e.forced_eos_token_id&&s.push(new c.ForcedEOSTokenLogitsProcessor(e.max_length,e.forced_eos_token_id)),null!==e.begin_suppress_tokens){const n=t>1||null===e.forced_bos_token_id?t:t+1;s.push(new c.SuppressTokensAtBeginLogitsProcessor(e.begin_suppress_tokens,n))}return null!==e.guidance_scale&&e.guidance_scale>1&&s.push(new c.ClassifierFreeGuidanceLogitsProcessor(e.guidance_scale)),null!==n&&s.extend(n),s}_prepare_generation_config(e,t,n=d.GenerationConfig){const s={...this.config};for(const e of["decoder","generator","text_config"])e in s&&Object.assign(s,s[e]);const r=new n(s);return"generation_config"in this&&Object.assign(r,this.generation_config),e&&Object.assign(r,e),t&&Object.assign(r,(0,a.pick)(t,Object.getOwnPropertyNames(r))),r}_get_stopping_criteria(e,t=null){const n=new h.StoppingCriteriaList;return null!==e.max_length&&n.push(new h.MaxLengthCriteria(e.max_length,this.config.max_position_embeddings??null)),null!==e.eos_token_id&&n.push(new h.EosTokenCriteria(e.eos_token_id)),t&&n.extend(t),n}_validate_model_class(){if(!this.can_generate){const e=[ca,pa,la,sa],t=P.get(this.constructor),n=new Set,s=this.config.model_type;for(const t of e){const e=t.get(s);e&&n.add(e[0])}let r=`The current model class (${t}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw n.size>0&&(r+=` Please use the following class instead: ${[...n].join(", ")}`),Error(r)}}prepare_inputs_for_generation(...e){return this._prepare_inputs_for_generation(this,...e)}_update_model_kwargs_for_generation({generated_input_ids:e,outputs:t,model_inputs:n,is_encoder_decoder:s}){return n.past_key_values=this.getPastKeyValues(t,n.past_key_values),n.input_ids=new u.Tensor("int64",e.flat(),[e.length,1]),s||(n.attention_mask=(0,u.cat)([n.attention_mask,(0,u.ones)([n.attention_mask.dims[0],1])],1)),n.position_ids=null,n}_prepare_model_inputs({inputs:e,bos_token_id:t,model_kwargs:n}){const s=(0,a.pick)(n,this.forward_params),r=this.main_input_name;if(r in s){if(e)throw new Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else s[r]=e;return{inputs_tensor:s[r],model_inputs:s,model_input_name:r}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:e,model_inputs:t,model_input_name:n,generation_config:s}){if(this.sessions.model.inputNames.includes("inputs_embeds")&&!t.inputs_embeds&&"_prepare_inputs_embeds"in this){const{input_ids:e,pixel_values:n,attention_mask:s,...r}=t,o=await this._prepare_inputs_embeds(t);t={...r,...(0,a.pick)(o,["inputs_embeds","attention_mask"])}}let{last_hidden_state:r}=await B(this,t);if(null!==s.guidance_scale&&s.guidance_scale>1)r=(0,u.cat)([r,(0,u.full_like)(r,0)],0),"attention_mask"in t&&(t.attention_mask=(0,u.cat)([t.attention_mask,(0,u.zeros_like)(t.attention_mask)],0));else if(t.decoder_input_ids){const e=z(t.decoder_input_ids).dims[0];if(e!==r.dims[0]){if(1!==r.dims[0])throw new Error(`The encoder outputs have a different batch size (${r.dims[0]}) than the decoder inputs (${e}).`);r=(0,u.cat)(Array.from({length:e},(()=>r)),0)}}return t.encoder_outputs=r,t}_prepare_decoder_input_ids_for_generation({batch_size:e,model_input_name:t,model_kwargs:n,decoder_start_token_id:s,bos_token_id:r,generation_config:o}){let{decoder_input_ids:i,...a}=n;if(i)Array.isArray(i[0])||(i=Array.from({length:e},(()=>i)));else if(s??=r,"musicgen"===this.config.model_type)i=Array.from({length:e*this.config.decoder.num_codebooks},(()=>[s]));else if(Array.isArray(s)){if(s.length!==e)throw new Error(`\`decoder_start_token_id\` expcted to have length ${e} but got ${s.length}`);i=s}else i=Array.from({length:e},(()=>[s]));return i=z(i),n.decoder_attention_mask=(0,u.ones_like)(i),{input_ids:i,model_inputs:a}}async generate({inputs:e=null,generation_config:t=null,logits_processor:n=null,stopping_criteria:s=null,streamer:r=null,...o}){this._validate_model_class(),t=this._prepare_generation_config(t,o);let{inputs_tensor:i,model_inputs:a,model_input_name:l}=this._prepare_model_inputs({inputs:e,model_kwargs:o});const c=this.config.is_encoder_decoder;let d;c&&("encoder_outputs"in a||(a=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:i,model_inputs:a,model_input_name:l,generation_config:t}))),c?({input_ids:d,model_inputs:a}=this._prepare_decoder_input_ids_for_generation({batch_size:a[l].dims.at(0),model_input_name:l,model_kwargs:a,decoder_start_token_id:t.decoder_start_token_id,bos_token_id:t.bos_token_id,generation_config:t})):d=a[l];let p=d.dims.at(-1);null!==t.max_new_tokens&&(t.max_length=p+t.max_new_tokens);const h=this._get_logits_processor(t,p,n),m=this._get_stopping_criteria(t,s),f=a[l].dims.at(0),g=_.LogitsSampler.getSampler(t),w=new Array(f).fill(0),M=d.tolist();let b;r&&r.put(M);let y={};for(;;){if(a=this.prepare_inputs_for_generation(M,a,t),b=await this.forward(a),t.output_attentions&&t.return_dict_in_generate){const e=this.getAttentions(b);for(const t in e)t in y||(y[t]=[]),y[t].push(e[t])}const e=h(M,b.logits.slice(null,-1,null)),n=[];for(let t=0;t<e.dims.at(0);++t){const s=e[t],r=await g(s);for(const[e,s]of r){const r=BigInt(e);w[t]+=s,M[t].push(r),n.push([r]);break}}r&&r.put(n);if(m(M).every((e=>e)))break;a=this._update_model_kwargs_for_generation({generated_input_ids:n,outputs:b,model_inputs:a,is_encoder_decoder:c})}r&&r.end();const x=this.getPastKeyValues(b,a.past_key_values,!0),k=new u.Tensor("int64",M.flat(),[M.length,M[0].length]);if(t.return_dict_in_generate)return{sequences:k,past_key_values:x,...y};for(const e of Object.values(b))"gpu-buffer"===e.location&&e.dispose();return k}getPastKeyValues(e,t,n=!1){const s=Object.create(null);for(const r in e)if(r.startsWith("present")){const o=r.replace("present","past_key_values"),i=r.includes("encoder");if(s[o]=i&&t?t[o]:e[r],t&&(!i||n)){const e=t[o];"gpu-buffer"===e.location&&e.dispose()}}return s}getAttentions(e){const t={};for(const n of["cross_attentions","encoder_attentions","decoder_attentions"])for(const s in e)s.startsWith(n)&&(n in t||(t[n]=[]),t[n].push(e[s]));return t}addPastKeyValues(e,t){if(t)Object.assign(e,t);else{const t=this.custom_config.kv_cache_dtype??"float32",n="float16"===t?new Uint16Array:[],r=(0,s.getKeyValueShapes)(this.config);for(const s in r)e[s]=new u.Tensor(t,n,r[s])}}async encode_image({pixel_values:e}){const t=(await A(this.sessions.vision_encoder,{pixel_values:e})).image_features;return this.config.num_image_tokens||(console.warn(`The number of image tokens was not set in the model configuration. Setting it to the number of features detected by the vision encoder (${t.dims[1]}).`),this.config.num_image_tokens=t.dims[1]),t}async encode_text({input_ids:e}){return(await A(this.sessions.embed_tokens,{input_ids:e})).inputs_embeds}}class G{}class $ extends G{constructor({last_hidden_state:e,hidden_states:t=null,attentions:n=null}){super(),this.last_hidden_state=e,this.hidden_states=t,this.attentions=n}}class q extends R{}class U extends q{}class W extends q{async _call(e){return new ul(await super._call(e))}}class X extends q{async _call(e){return new ll(await super._call(e))}}class Q extends q{async _call(e){return new dl(await super._call(e))}}class H extends q{async _call(e){return new pl(await super._call(e))}}class Y extends R{}class J extends Y{}class K extends R{}class Z extends K{}class ee extends K{async _call(e){return new ul(await super._call(e))}}class te extends K{async _call(e){return new ll(await super._call(e))}}class ne extends K{async _call(e){return new dl(await super._call(e))}}class se extends K{async _call(e){return new pl(await super._call(e))}}class re extends R{}class oe extends re{}class ie extends re{async _call(e){return new ul(await super._call(e))}}class ae extends re{async _call(e){return new ll(await super._call(e))}}class le extends re{async _call(e){return new dl(await super._call(e))}}class ce extends re{async _call(e){return new pl(await super._call(e))}}class de extends R{}class ue extends de{}class pe extends de{async _call(e){return new ul(await super._call(e))}}class he extends de{async _call(e){return new ll(await super._call(e))}}class _e extends de{async _call(e){return new dl(await super._call(e))}}class me extends de{async _call(e){return new pl(await super._call(e))}}class fe extends R{}class ge extends fe{}class we extends fe{async _call(e){return new ul(await super._call(e))}}class Me extends fe{async _call(e){return new ll(await super._call(e))}}class be extends fe{async _call(e){return new dl(await super._call(e))}}class ye extends fe{async _call(e){return new pl(await super._call(e))}}class xe extends R{}class ke extends xe{}class Te extends xe{async _call(e){return new ul(await super._call(e))}}class ve extends xe{async _call(e){return new ll(await super._call(e))}}class Fe extends xe{async _call(e){return new dl(await super._call(e))}}class Ce extends xe{async _call(e){return new pl(await super._call(e))}}class Pe extends R{}class Se extends Pe{}class Ae extends Pe{async _call(e){return new ul(await super._call(e))}}class Ee extends Pe{async _call(e){return new ll(await super._call(e))}}class ze extends Pe{async _call(e){return new dl(await super._call(e))}}class Le extends Pe{async _call(e){return new pl(await super._call(e))}}class Ie extends R{}class Be extends Ie{}class Ne extends Ie{async _call(e){return new ll(await super._call(e))}}class Oe extends Ie{async _call(e){return new dl(await super._call(e))}}class je extends Ie{async _call(e){return new pl(await super._call(e))}}class De extends Ie{async _call(e){return new ul(await super._call(e))}}class Ve extends R{}class Re extends Ve{}class Ge extends Ve{async _call(e){return new ul(await super._call(e))}}class $e extends Ve{async _call(e){return new ll(await super._call(e))}}class qe extends Ve{async _call(e){return new dl(await super._call(e))}}class Ue extends R{}class We extends Ue{}class Xe extends Ue{async _call(e){return new ul(await super._call(e))}}class Qe extends Ue{async _call(e){return new ll(await super._call(e))}}class He extends Ue{async _call(e){return new pl(await super._call(e))}}class Ye extends R{}class Je extends Ye{}class Ke extends Ye{async _call(e){return new ul(await super._call(e))}}class Ze extends Ye{async _call(e){return new ll(await super._call(e))}}class et extends Ye{async _call(e){return new dl(await super._call(e))}}class tt extends Ye{async _call(e){return new pl(await super._call(e))}}class nt extends R{}class st extends nt{}class rt extends nt{async _call(e){return new ul(await super._call(e))}}class ot extends nt{async _call(e){return new ll(await super._call(e))}}class it extends nt{async _call(e){return new pl(await super._call(e))}}class at extends R{}class lt extends at{}class ct extends at{async _call(e){return new ll(await super._call(e))}}class dt extends at{async _call(e){return new pl(await super._call(e))}}class ut extends at{async _call(e){return new ul(await super._call(e))}}class pt extends R{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"];constructor(e,t,n){super(e,t),this.generation_config=n}}class ht extends pt{}class _t extends pt{}class mt extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class ft extends mt{}class gt extends mt{}class wt extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Mt extends wt{}class bt extends wt{}class yt extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class xt extends yt{}class kt extends yt{}class Tt extends yt{async _call(e){return new ll(await super._call(e))}}class vt extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Ft extends vt{}class Ct extends vt{}class Pt extends vt{async _call(e){return new ll(await super._call(e))}}class St extends vt{}class At extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Et extends At{}class zt extends At{}class Lt extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class It extends Lt{}class Bt extends Lt{}class Nt extends R{}class Ot extends Nt{}class jt extends Nt{async _call(e){return new ul(await super._call(e))}}class Dt extends Nt{async _call(e){return new ll(await super._call(e))}}class Vt extends Nt{async _call(e){return new dl(await super._call(e))}}class Rt extends Nt{async _call(e){return new pl(await super._call(e))}}class Gt extends R{}class $t extends Gt{}class qt extends Gt{async _call(e){return new ul(await super._call(e))}}class Ut extends Gt{async _call(e){return new ll(await super._call(e))}}class Wt extends Gt{async _call(e){return new dl(await super._call(e))}}class Xt extends Gt{async _call(e){return new pl(await super._call(e))}}class Qt extends R{}class Ht extends Qt{}class Yt extends Qt{async _call(e){return new ul(await super._call(e))}}class Jt extends Qt{async _call(e){return new ll(await super._call(e))}}class Kt extends Qt{async _call(e){return new dl(await super._call(e))}}class Zt extends Qt{async _call(e){return new pl(await super._call(e))}}class en extends R{}class tn extends en{}class nn extends en{}class sn extends R{requires_attention_mask=!1;main_input_name="input_features";forward_params=["input_features","attention_mask","decoder_input_ids","decoder_attention_mask","past_key_values"];constructor(e,t,n){super(e,t),this.generation_config=n}}class rn extends sn{}class on extends sn{_prepare_generation_config(e,t){return super._prepare_generation_config(e,t,f.WhisperGenerationConfig)}_retrieve_init_tokens(e){const t=[e.decoder_start_token_id];let n=e.language;const s=e.task;if(e.is_multilingual){n||(console.warn("No language specified - defaulting to English (en)."),n="en");const r=`<|${(0,g.whisper_language_to_code)(n)}|>`;t.push(e.lang_to_id[r]),t.push(e.task_to_id[s??"transcribe"])}else if(n||s)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&&(console.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),t.pop()),t.filter((e=>null!=e))}async generate({inputs:e=null,generation_config:t=null,logits_processor:n=null,stopping_criteria:s=null,...r}){t=this._prepare_generation_config(t,r);const o=r.decoder_input_ids??this._retrieve_init_tokens(t);if(t.return_timestamps&&(n??=new c.LogitsProcessorList,n.push(new c.WhisperTimeStampLogitsProcessor(t,o))),t.begin_suppress_tokens&&(n??=new c.LogitsProcessorList,n.push(new c.SuppressTokensAtBeginLogitsProcessor(t.begin_suppress_tokens,o.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.");"translate"===t.task&&console.warn("Token-level timestamps may not be reliable for task 'translate'."),t.output_attentions=!0,t.return_dict_in_generate=!0}const i=await super.generate({inputs:e,generation_config:t,logits_processor:n,decoder_input_ids:o,...r});return t.return_token_timestamps&&(i.token_timestamps=this._extract_token_timestamps(i,t.alignment_heads,t.num_frames)),i}_extract_token_timestamps(e,t,n=null,s=.02){if(!e.cross_attentions)throw new Error("Model outputs must contain cross attentions to extract timestamps. This is most likely because the model was not exported with `output_attentions=True`.");null==n&&console.warn("`num_frames` has not been set, meaning the entire audio will be analyzed. This may lead to inaccurate token-level timestamps for short audios (< 30 seconds).");let r=this.config.median_filter_width;void 0===r&&(console.warn("Model config has no `median_filter_width`, using default value of 7."),r=7);const o=e.cross_attentions,i=Array.from({length:this.config.decoder_layers},((e,t)=>(0,u.cat)(o.map((e=>e[t])),2))),l=(0,u.stack)(t.map((([e,t])=>{if(e>=i.length)throw new Error(`Layer index ${e} is out of bounds for cross attentions (length ${i.length}).`);return n?i[e].slice(null,t,null,[0,n]):i[e].slice(null,t)}))).transpose(1,0,2,3),[c,d]=(0,u.std_mean)(l,-2,0,!0),h=l.clone();for(let e=0;e<h.dims[0];++e){const t=h[e];for(let n=0;n<t.dims[0];++n){const s=t[n],o=c[e][n][0].data,i=d[e][n][0].data;for(let e=0;e<s.dims[0];++e){let t=s[e].data;for(let e=0;e<t.length;++e)t[e]=(t[e]-i[e])/o[e];t.set((0,p.medianFilter)(t,r))}}}const _=[(0,u.mean)(h,1)],m=e.sequences.dims,f=new u.Tensor("float32",new Float32Array(m[0]*m[1]),m);for(let e=0;e<m[0];++e){const t=_[e].neg().squeeze_(0),[n,r]=(0,p.dynamic_time_warping)(t.tolist()),o=Array.from({length:n.length-1},((e,t)=>n[t+1]-n[t])),i=(0,a.mergeArrays)([1],o).map((e=>!!e)),l=[];for(let e=0;e<i.length;++e)i[e]&&l.push(r[e]*s);f[e].data.set(l,1)}return f}}class an extends R{main_input_name="pixel_values";forward_params=["pixel_values","input_ids","encoder_hidden_states","past_key_values"];constructor(e,t,n){super(e,t),this.generation_config=n}}class ln extends R{forward_params=["input_ids","pixel_values","attention_mask","position_ids","past_key_values"];constructor(e,t,n){super(e,t),this.generation_config=n}}class cn extends ln{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:t,input_ids:n,attention_mask:s}){const r=this.config.image_token_index,o=n.tolist().map((e=>e.findIndex((e=>e==r)))),i=o.every((e=>-1===e)),a=o.every((e=>-1!==e));if(!i&&!a)throw new Error("Every input should contain either 0 or 1 image token.");if(i)return{inputs_embeds:e,attention_mask:s};const l=[],c=[];for(let n=0;n<o.length;++n){const r=o[n],i=e[n],a=t[n],d=s[n];l.push((0,u.cat)([i.slice([0,r]),a,i.slice([r+1,i.dims[0]])],0)),c.push((0,u.cat)([d.slice([0,r]),(0,u.ones)([a.dims[0]]),d.slice([r+1,d.dims[0]])],0))}return{inputs_embeds:(0,u.stack)(l,0),attention_mask:(0,u.stack)(c,0)}}}class dn extends cn{}class un extends R{forward_params=["input_ids","inputs_embeds","attention_mask","pixel_values","encoder_outputs","decoder_input_ids","decoder_inputs_embeds","decoder_attention_mask","past_key_values"];main_input_name="inputs_embeds";constructor(e,t,n){super(e,t),this.generation_config=n}}class pn extends un{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:t,input_ids:n,attention_mask:s}){return{inputs_embeds:(0,u.cat)([t,e],1),attention_mask:(0,u.cat)([(0,u.ones)(t.dims.slice(0,2)),s],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:n,attention_mask:s}){if(!e&&!t)throw new Error("Either `input_ids` or `pixel_values` should be provided.");let r,o;return e&&(r=await this.encode_text({input_ids:e})),t&&(o=await this.encode_image({pixel_values:t})),r&&o?({inputs_embeds:n,attention_mask:s}=this._merge_input_ids_with_image_features({inputs_embeds:r,image_features:o,input_ids:e,attention_mask:s})):n=r||o,{inputs_embeds:n,attention_mask:s}}async forward({input_ids:e,pixel_values:t,attention_mask:n,decoder_input_ids:s,decoder_attention_mask:r,encoder_outputs:o,past_key_values:i,inputs_embeds:a,decoder_inputs_embeds:l}){if(a||({inputs_embeds:a,attention_mask:n}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:a,attention_mask:n})),!o){let{last_hidden_state:e}=await B(this,{inputs_embeds:a,attention_mask:n});o=e}if(!l){if(!s)throw new Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");l=await this.encode_text({input_ids:s})}const c={inputs_embeds:l,attention_mask:r,encoder_attention_mask:n,encoder_hidden_states:o,past_key_values:i};return await N(this,c,!0)}}class hn extends R{}class _n extends hn{}class mn extends hn{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class fn extends hn{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class gn extends hn{static async from_pretrained(e,t={}){return t.model_file_name??="vision_model",super.from_pretrained(e,t)}}class wn extends hn{static async from_pretrained(e,t={}){return t.model_file_name??="vision_model",super.from_pretrained(e,t)}}class Mn extends R{}class bn extends Mn{}class yn extends Mn{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class xn extends hn{static async from_pretrained(e,t={}){return t.model_file_name??="vision_model",super.from_pretrained(e,t)}}class kn extends R{}class Tn extends kn{}class vn extends R{}class Fn extends vn{}class Cn extends vn{}class Pn extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Sn extends Pn{}class An extends Pn{}class En extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class zn extends En{}class Ln extends En{}class In extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Bn extends In{}class Nn extends In{}class On extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class jn extends On{}class Dn extends On{}class Vn extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Rn extends Vn{}class Gn extends Vn{}class $n extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class qn extends $n{}class Un extends $n{}class Wn extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Xn extends Wn{}class Qn extends Wn{}class Hn extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Yn extends Hn{}class Jn extends Hn{}class Kn extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Zn extends Kn{}class es extends Kn{}class ts extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class ns extends ts{}class ss extends ts{}class rs extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class os extends rs{}class is extends rs{}class as extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class ls extends as{}class cs extends as{}class ds extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class us extends ds{}class ps extends ds{}class hs extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class _s extends hs{}class ms extends hs{}class fs extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class gs extends fs{}class ws extends fs{}class Ms extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class bs extends Ms{}class ys extends Ms{}class xs extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class ks extends xs{}class Ts extends xs{}class vs extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Fs extends vs{}class Cs extends vs{}class Ps extends R{}class Ss extends Ps{}class As extends Ps{async _call(e){return new ll(await super._call(e))}}class Es extends R{}class zs extends Es{}class Ls extends Es{async _call(e){return new ll(await super._call(e))}}class Is extends R{}class Bs extends Is{}class Ns extends R{}class Os extends Ns{}class js extends Ns{async _call(e){return new ll(await super._call(e))}}class Ds extends R{}class Vs extends Ds{}class Rs extends R{}class Gs extends Rs{}class $s extends Rs{async _call(e){return new ll(await super._call(e))}}class qs extends R{}class Us extends qs{async _call(e){return new ml(await super._call(e))}}class Ws extends R{}class Xs extends Ws{}class Qs extends Ws{async _call(e){return new ll(await super._call(e))}}class Hs extends R{}class Ys extends Hs{}class Js extends Hs{async _call(e){return new ll(await super._call(e))}}class Ks extends R{}class Zs extends Ks{}class er extends Ks{}class tr extends R{}class nr extends tr{}class sr extends tr{}class rr extends R{}class or extends rr{}class ir extends rr{async _call(e){return new ll(await super._call(e))}}class ar extends R{}class lr extends ar{}class cr extends ar{async _call(e){return new ur(await super._call(e))}}class dr extends ar{async _call(e){return new pr(await super._call(e))}}class ur extends G{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class pr extends G{constructor({logits:e,pred_boxes:t,pred_masks:n}){super(),this.logits=e,this.pred_boxes=t,this.pred_masks=n}}class hr extends R{}class _r extends hr{}class mr extends hr{async _call(e){return new fr(await super._call(e))}}class fr extends G{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class gr extends R{}class wr extends gr{}class Mr extends gr{async _call(e){return new br(await super._call(e))}}class br extends ur{}class yr extends R{}class xr extends yr{}class kr extends yr{async _call(e){return new ll(await super._call(e))}}class Tr extends R{}class vr extends Tr{}class Fr extends Tr{async _call(e){return new ll(await super._call(e))}}class Cr extends R{}class Pr extends Cr{}class Sr extends Cr{async _call(e){return new ll(await super._call(e))}}class Ar extends R{}class Er extends Ar{}class zr extends Ar{async _call(e){return new ll(await super._call(e))}}class Lr extends R{}class Ir extends Lr{}class Br extends Lr{}class Nr extends R{}class Or extends Nr{}class jr extends Nr{}class Dr extends R{}class Vr extends Dr{}class Rr extends R{}class Gr extends Rr{}class $r extends Rr{}class qr extends Rr{}class Ur extends R{}class Wr extends Ur{}class Xr extends R{}class Qr extends Xr{}class Hr extends Xr{}class Yr extends R{}class Jr extends Yr{}class Kr extends Yr{}class Zr extends R{}class eo extends Zr{}class to extends R{}class no extends to{}class so extends to{async _call(e){return new ll(await super._call(e))}}class ro extends R{}class oo extends ro{}class io extends ro{async _call(e){return new ll(await super._call(e))}}class ao extends R{}class lo extends ao{}class co extends ao{async _call(e){return new ll(await super._call(e))}}class uo extends R{}class po extends uo{}class ho extends uo{async _call(e){return new _o(await super._call(e))}}class _o extends G{constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class mo extends R{}class fo extends mo{async get_image_embeddings({pixel_values:e}){return await B(this,{pixel_values:e})}async forward(e){if(e.image_embeddings&&e.image_positional_embeddings||(e={...e,...await this.get_image_embeddings(e)}),!e.input_labels&&e.input_points){const t=e.input_points.dims.slice(0,-1),n=t.reduce(((e,t)=>e*t),1);e.input_labels=new u.Tensor("int64",new BigInt64Array(n).fill(1n),t)}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 A(this.sessions.prompt_encoder_mask_decoder,t)}async _call(e){return new go(await super._call(e))}}class go extends G{constructor({iou_scores:e,pred_masks:t}){super(),this.iou_scores=e,this.pred_masks=t}}class wo extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Mo extends wo{}class bo extends wo{}class yo extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class xo extends yo{}class ko extends yo{}class To extends R{}class vo extends To{}class Fo extends To{async _call(e){return new hl(await super._call(e))}}class Co extends To{async _call(e){return new ll(await super._call(e))}}class Po extends To{async _call(e){return new dl(await super._call(e))}}class So extends R{}class Ao extends So{}class Eo extends So{async _call(e){return new dl(await super._call(e))}}class zo extends R{}class Lo extends zo{}class Io extends R{}class Bo extends Io{}class No extends Io{async _call(e){return new hl(await super._call(e))}}class Oo extends Io{async _call(e){return new ll(await super._call(e))}}class jo extends R{}class Do extends jo{}class Vo extends jo{async _call(e){return new hl(await super._call(e))}}class Ro extends jo{async _call(e){return new ll(await super._call(e))}}class Go extends jo{async _call(e){return new dl(await super._call(e))}}class $o extends R{}class qo extends $o{}class Uo extends $o{async _call(e){return new hl(await super._call(e))}}class Wo extends $o{async _call(e){return new ll(await super._call(e))}}class Xo extends R{}class Qo extends To{}class Ho extends To{async _call(e){return new hl(await super._call(e))}}class Yo extends To{async _call(e){return new ll(await super._call(e))}}class Jo extends R{}class Ko extends Jo{}class Zo extends Jo{async _call(e){return new hl(await super._call(e))}}class ei extends Jo{async _call(e){return new ll(await super._call(e))}}class ti extends Jo{async _call(e){return new cl(await super._call(e))}}class ni extends Jo{async _call(e){return new dl(await super._call(e))}}class si extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class ri extends si{}class oi extends si{}class ii extends si{async generate_speech(e,t,{threshold:n=.5,minlenratio:s=0,maxlenratio:r=20,vocoder:o=null}={}){const i={input_ids:e},{encoder_outputs:a,encoder_attention_mask:l}=await B(this,i),c=a.dims[1]/this.config.reduction_factor,d=Math.floor(c*r),p=Math.floor(c*s),h=this.config.num_mel_bins;let _=[],m=null,f=null,g=0;for(;;){++g;const e=L(!!f);let s;s=f?f.output_sequence_out:new u.Tensor("float32",new Float32Array(h),[1,1,h]);let r={use_cache_branch:e,output_sequence:s,encoder_attention_mask:l,speaker_embeddings:t,encoder_hidden_states:a};this.addPastKeyValues(r,m),f=await A(this.sessions.decoder_model_merged,r),m=this.getPastKeyValues(f,m);const{prob:o,spectrum:i}=f;if(_.push(i),g>=p&&(Array.from(o.data).filter((e=>e>=n)).length>0||g>=d))break}const w=(0,u.cat)(_),{waveform:M}=await A(o.sessions.model,{spectrogram:w});return{spectrogram:w,waveform:M}}}class ai extends R{main_input_name="spectrogram"}class li extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class ci extends li{}class di extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class ui extends di{}class pi extends di{}class hi extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class _i extends hi{}class mi extends hi{}class fi extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class gi extends fi{}class wi extends fi{}class Mi extends R{}class bi extends Mi{}class yi extends Mi{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class xi extends Mi{static async from_pretrained(e,t={}){return t.model_file_name??="audio_model",super.from_pretrained(e,t)}}class ki extends R{}class Ti extends ki{async _call(e){return new fl(await super._call(e))}}class vi extends R{}class Fi extends vi{}class Ci extends vi{}class Pi extends vi{}class Si extends R{constructor(e,t,n){super(e,t),this.generation_config=n}}class Ai extends Si{}class Ei extends Si{}class zi extends R{}class Li extends zi{}class Ii extends zi{async _call(e){return new ll(await super._call(e))}}class Bi extends R{}class Ni extends Bi{}class Oi extends Bi{}class ji extends R{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"];constructor(e,t,n){super(e,t),this.generation_config=n}_apply_and_filter_by_delay_pattern_mask(e){const[t,n]=e.dims,s=this.config.decoder.num_codebooks,r=n-s;let o=0;for(let t=0;t<e.size;++t){if(e.data[t]===this.config.decoder.pad_token_id)continue;const i=t%n-Math.floor(t/n)%s;i>0&&i<=r&&(e.data[o++]=e.data[t])}const i=Math.floor(t/s),a=o/(i*s);return new u.Tensor(e.type,e.data.slice(0,o),[i,s,a])}prepare_inputs_for_generation(e,t,n){let s=structuredClone(e);for(let e=0;e<s.length;++e)for(let t=0;t<s[e].length;++t)e%this.config.decoder.num_codebooks>=t&&(s[e][t]=BigInt(this.config.decoder.pad_token_id));null!==n.guidance_scale&&n.guidance_scale>1&&(s=s.concat(s));return super.prepare_inputs_for_generation(s,t,n)}async generate(e){const t=await super.generate(e),n=this._apply_and_filter_by_delay_pattern_mask(t).unsqueeze_(0),{audio_values:s}=await A(this.sessions.encodec_decode,{audio_codes:n});return s}}class Di extends R{}class Vi extends Di{}class Ri extends Di{async _call(e){return new ll(await super._call(e))}}class Gi extends R{}class $i extends Gi{}class qi extends Gi{async _call(e){return new ll(await super._call(e))}}class Ui extends R{}class Wi extends Ui{}class Xi extends Ui{async _call(e){return new ll(await super._call(e))}}class Qi extends R{}class Hi extends Qi{}class Yi extends Qi{async _call(e){return new ll(await super._call(e))}}class Ji extends R{}class Ki extends Ji{}class Zi{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:r=null,local_files_only:o=!1,revision:i="main",model_file_name:a=null,subfolder:l="onnx",device:c=null,dtype:d=null,use_external_data_format:u=null,session_options:p={}}={}){const h={progress_callback:t,config:n,cache_dir:r,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:d,use_external_data_format:u,session_options:p};if(h.config=await s.AutoConfig.from_pretrained(e,h),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);for(const t of this.MODEL_CLASS_MAPPINGS){const n=t.get(h.config.model_type);if(n)return await n[1].from_pretrained(e,h)}if(this.BASE_IF_FAIL)return console.warn(`Unknown model class "${h.config.model_type}", attempting to construct from base class.`),await R.from_pretrained(e,h);throw Error(`Unsupported model type: ${h.config.model_type}`)}}const ea=new Map([["bert",["BertModel",U]],["nomic_bert",["NomicBertModel",J]],["roformer",["RoFormerModel",Z]],["electra",["ElectraModel",ue]],["esm",["EsmModel",Re]],["convbert",["ConvBertModel",oe]],["camembert",["CamembertModel",ge]],["deberta",["DebertaModel",ke]],["deberta-v2",["DebertaV2Model",Se]],["mpnet",["MPNetModel",Je]],["albert",["AlbertModel",lt]],["distilbert",["DistilBertModel",Be]],["roberta",["RobertaModel",Ot]],["xlm",["XLMModel",$t]],["xlm-roberta",["XLMRobertaModel",Ht]],["clap",["ClapModel",bi]],["clip",["CLIPModel",_n]],["clipseg",["CLIPSegModel",Fn]],["chinese_clip",["ChineseCLIPModel",Tn]],["siglip",["SiglipModel",bn]],["mobilebert",["MobileBertModel",We]],["squeezebert",["SqueezeBertModel",st]],["wav2vec2",["Wav2Vec2Model",vo]],["wav2vec2-bert",["Wav2Vec2BertModel",qo]],["unispeech",["UniSpeechModel",Bo]],["unispeech-sat",["UniSpeechSatModel",Do]],["hubert",["HubertModel",Qo]],["wavlm",["WavLMModel",Ko]],["audio-spectrogram-transformer",["ASTModel",tn]],["vits",["VitsModel",Ti]],["pyannote",["PyAnnoteModel",Ao]],["wespeaker-resnet",["WeSpeakerResNetModel",Lo]],["detr",["DetrModel",lr]],["rt_detr",["RTDetrModel",_r]],["table-transformer",["TableTransformerModel",wr]],["vit",["ViTModel",Ss]],["pvt",["PvtModel",zs]],["vit_msn",["ViTMSNModel",Os]],["vit_mae",["ViTMAEModel",Bs]],["groupvit",["GroupViTModel",Vs]],["fastvit",["FastViTModel",Gs]],["mobilevit",["MobileViTModel",Xs]],["mobilevitv2",["MobileViTV2Model",Ys]],["owlvit",["OwlViTModel",Zs]],["owlv2",["Owlv2Model",nr]],["beit",["BeitModel",or]],["deit",["DeiTModel",xr]],["hiera",["HieraModel",vr]],["convnext",["ConvNextModel",no]],["convnextv2",["ConvNextV2Model",oo]],["dinov2",["Dinov2Model",lo]],["resnet",["ResNetModel",Pr]],["swin",["SwinModel",Er]],["swin2sr",["Swin2SRModel",Ir]],["donut-swin",["DonutSwinModel",eo]],["yolos",["YolosModel",po]],["dpt",["DPTModel",Or]],["glpn",["GLPNModel",Jr]],["hifigan",["SpeechT5HifiGan",ai]],["efficientnet",["EfficientNetModel",Li]],["decision_transformer",["DecisionTransformerModel",Ki]],["mobilenet_v1",["MobileNetV1Model",Vi]],["mobilenet_v2",["MobileNetV2Model",$i]],["mobilenet_v3",["MobileNetV3Model",Wi]],["mobilenet_v4",["MobileNetV4Model",Hi]],["maskformer",["MaskFormerModel",Qr]]]),ta=new Map([["t5",["T5Model",ht]],["longt5",["LongT5Model",ft]],["mt5",["MT5Model",Mt]],["bart",["BartModel",xt]],["mbart",["MBartModel",Ft]],["marian",["MarianModel",Mo]],["whisper",["WhisperModel",rn]],["m2m_100",["M2M100Model",xo]],["blenderbot",["BlenderbotModel",Et]],["blenderbot-small",["BlenderbotSmallModel",It]]]),na=new Map([["bloom",["BloomModel",bs]],["jais",["JAISModel",zn]],["gpt2",["GPT2Model",Sn]],["gptj",["GPTJModel",Rn]],["gpt_bigcode",["GPTBigCodeModel",qn]],["gpt_neo",["GPTNeoModel",Bn]],["gpt_neox",["GPTNeoXModel",jn]],["codegen",["CodeGenModel",Xn]],["llama",["LlamaModel",Yn]],["cohere",["CohereModel",Zn]],["gemma",["GemmaModel",ns]],["gemma2",["Gemma2Model",os]],["openelm",["OpenELMModel",ls]],["qwen2",["Qwen2Model",us]],["phi",["PhiModel",_s]],["phi3",["Phi3Model",gs]],["mpt",["MptModel",ks]],["opt",["OPTModel",Fs]],["mistral",["MistralModel",ui]],["starcoder2",["Starcoder2Model",_i]],["falcon",["FalconModel",gi]],["stablelm",["StableLmModel",Ai]]]),sa=new Map([["speecht5",["SpeechT5ForSpeechToText",oi]],["whisper",["WhisperForConditionalGeneration",on]]]),ra=new Map([["speecht5",["SpeechT5ForTextToSpeech",ii]]]),oa=new Map([["vits",["VitsModel",Ti]],["musicgen",["MusicgenForConditionalGeneration",ji]]]),ia=new Map([["bert",["BertForSequenceClassification",X]],["roformer",["RoFormerForSequenceClassification",te]],["electra",["ElectraForSequenceClassification",he]],["esm",["EsmForSequenceClassification",$e]],["convbert",["ConvBertForSequenceClassification",ae]],["camembert",["CamembertForSequenceClassification",Me]],["deberta",["DebertaForSequenceClassification",ve]],["deberta-v2",["DebertaV2ForSequenceClassification",Ee]],["mpnet",["MPNetForSequenceClassification",Ze]],["albert",["AlbertForSequenceClassification",ct]],["distilbert",["DistilBertForSequenceClassification",Ne]],["roberta",["RobertaForSequenceClassification",Dt]],["xlm",["XLMForSequenceClassification",Ut]],["xlm-roberta",["XLMRobertaForSequenceClassification",Jt]],["bart",["BartForSequenceClassification",Tt]],["mbart",["MBartForSequenceClassification",Pt]],["mobilebert",["MobileBertForSequenceClassification",Qe]],["squeezebert",["SqueezeBertForSequenceClassification",ot]]]),aa=new Map([["bert",["BertForTokenClassification",Q]],["roformer",["RoFormerForTokenClassification",ne]],["electra",["ElectraForTokenClassification",_e]],["esm",["EsmForTokenClassification",qe]],["convbert",["ConvBertForTokenClassification",le]],["camembert",["CamembertForTokenClassification",be]],["deberta",["DebertaForTokenClassification",Fe]],["deberta-v2",["DebertaV2ForTokenClassification",ze]],["mpnet",["MPNetForTokenClassification",et]],["distilbert",["DistilBertForTokenClassification",Oe]],["roberta",["RobertaForTokenClassification",Vt]],["xlm",["XLMForTokenClassification",Wt]],["xlm-roberta",["XLMRobertaForTokenClassification",Kt]]]),la=new Map([["t5",["T5ForConditionalGeneration",_t]],["longt5",["LongT5ForConditionalGeneration",gt]],["mt5",["MT5ForConditionalGeneration",bt]],["bart",["BartForConditionalGeneration",kt]],["mbart",["MBartForConditionalGeneration",Ct]],["marian",["MarianMTModel",bo]],["m2m_100",["M2M100ForConditionalGeneration",ko]],["blenderbot",["BlenderbotForConditionalGeneration",zt]],["blenderbot-small",["BlenderbotSmallForConditionalGeneration",Bt]]]),ca=new Map([["bloom",["BloomForCausalLM",ys]],["gpt2",["GPT2LMHeadModel",An]],["jais",["JAISLMHeadModel",Ln]],["gptj",["GPTJForCausalLM",Gn]],["gpt_bigcode",["GPTBigCodeForCausalLM",Un]],["gpt_neo",["GPTNeoForCausalLM",Nn]],["gpt_neox",["GPTNeoXForCausalLM",Dn]],["codegen",["CodeGenForCausalLM",Qn]],["llama",["LlamaForCausalLM",Jn]],["cohere",["CohereForCausalLM",es]],["gemma",["GemmaForCausalLM",ss]],["gemma2",["Gemma2ForCausalLM",is]],["openelm",["OpenELMForCausalLM",cs]],["qwen2",["Qwen2ForCausalLM",ps]],["phi",["PhiForCausalLM",ms]],["phi3",["Phi3ForCausalLM",ws]],["mpt",["MptForCausalLM",Ts]],["opt",["OPTForCausalLM",Cs]],["mbart",["MBartForCausalLM",St]],["mistral",["MistralForCausalLM",pi]],["starcoder2",["Starcoder2ForCausalLM",mi]],["falcon",["FalconForCausalLM",wi]],["trocr",["TrOCRForCausalLM",ci]],["stablelm",["StableLmForCausalLM",Ei]]]),da=new Map([["bert",["BertForMaskedLM",W]],["roformer",["RoFormerForMaskedLM",ee]],["electra",["ElectraForMaskedLM",pe]],["esm",["EsmForMaskedLM",Ge]],["convbert",["ConvBertForMaskedLM",ie]],["camembert",["CamembertForMaskedLM",we]],["deberta",["DebertaForMaskedLM",Te]],["deberta-v2",["DebertaV2ForMaskedLM",Ae]],["mpnet",["MPNetForMaskedLM",Ke]],["albert",["AlbertForMaskedLM",ut]],["distilbert",["DistilBertForMaskedLM",De]],["roberta",["RobertaForMaskedLM",jt]],["xlm",["XLMWithLMHeadModel",qt]],["xlm-roberta",["XLMRobertaForMaskedLM",Yt]],["mobilebert",["MobileBertForMaskedLM",Xe]],["squeezebert",["SqueezeBertForMaskedLM",rt]]]),ua=new Map([["bert",["BertForQuestionAnswering",H]],["roformer",["RoFormerForQuestionAnswering",se]],["electra",["ElectraForQuestionAnswering",me]],["convbert",["ConvBertForQuestionAnswering",ce]],["camembert",["CamembertForQuestionAnswering",ye]],["deberta",["DebertaForQuestionAnswering",Ce]],["deberta-v2",["DebertaV2ForQuestionAnswering",Le]],["mpnet",["MPNetForQuestionAnswering",tt]],["albert",["AlbertForQuestionAnswering",dt]],["distilbert",["DistilBertForQuestionAnswering",je]],["roberta",["RobertaForQuestionAnswering",Rt]],["xlm",["XLMForQuestionAnswering",Xt]],["xlm-roberta",["XLMRobertaForQuestionAnswering",Zt]],["mobilebert",["MobileBertForQuestionAnswering",He]],["squeezebert",["SqueezeBertForQuestionAnswering",it]]]),pa=new Map([["vision-encoder-decoder",["VisionEncoderDecoderModel",an]]]),ha=new Map([["llava",["LlavaForConditionalGeneration",cn]],["moondream1",["Moondream1ForConditionalGeneration",dn]],["florence2",["Florence2ForConditionalGeneration",pn]]]),_a=new Map([["vision-encoder-decoder",["VisionEncoderDecoderModel",an]]]),ma=new Map([["vit",["ViTForImageClassification",As]],["pvt",["PvtForImageClassification",Ls]],["vit_msn",["ViTMSNForImageClassification",js]],["fastvit",["FastViTForImageClassification",$s]],["mobilevit",["MobileViTForImageClassification",Qs]],["mobilevitv2",["MobileViTV2ForImageClassification",Js]],["beit",["BeitForImageClassification",ir]],["deit",["DeiTForImageClassification",kr]],["hiera",["HieraForImageClassification",Fr]],["convnext",["ConvNextForImageClassification",so]],["convnextv2",["ConvNextV2ForImageClassification",io]],["dinov2",["Dinov2ForImageClassification",co]],["resnet",["ResNetForImageClassification",Sr]],["swin",["SwinForImageClassification",zr]],["segformer",["SegformerForImageClassification",Ci]],["efficientnet",["EfficientNetForImageClassification",Ii]],["mobilenet_v1",["MobileNetV1ForImageClassification",Ri]],["mobilenet_v2",["MobileNetV2ForImageClassification",qi]],["mobilenet_v3",["MobileNetV3ForImageClassification",Xi]],["mobilenet_v4",["MobileNetV4ForImageClassification",Yi]]]),fa=new Map([["detr",["DetrForObjectDetection",cr]],["rt_detr",["RTDetrForObjectDetection",mr]],["table-transformer",["TableTransformerForObjectDetection",Mr]],["yolos",["YolosForObjectDetection",ho]]]),ga=new Map([["owlvit",["OwlViTForObjectDetection",er]],["owlv2",["Owlv2ForObjectDetection",sr]]]),wa=new Map([["detr",["DetrForSegmentation",dr]],["clipseg",["CLIPSegForImageSegmentation",Cn]]]),Ma=new Map([["segformer",["SegformerForSemanticSegmentation",Pi]],["sapiens",["SapiensForSemanticSegmentation",Gr]]]),ba=new Map([["detr",["DetrForSegmentation",dr]],["maskformer",["MaskFormerForInstanceSegmentation",Hr]]]),ya=new Map([["sam",["SamModel",fo]]]),xa=new Map([["wav2vec2",["Wav2Vec2ForCTC",Fo]],["wav2vec2-bert",["Wav2Vec2BertForCTC",Uo]],["unispeech",["UniSpeechForCTC",No]],["unispeech-sat",["UniSpeechSatForCTC",Vo]],["wavlm",["WavLMForCTC",Zo]],["hubert",["HubertForCTC",Ho]]]),ka=new Map([["wav2vec2",["Wav2Vec2ForSequenceClassification",Co]],["wav2vec2-bert",["Wav2Vec2BertForSequenceClassification",Wo]],["unispeech",["UniSpeechForSequenceClassification",Oo]],["unispeech-sat",["UniSpeechSatForSequenceClassification",Ro]],["wavlm",["WavLMForSequenceClassification",ei]],["hubert",["HubertForSequenceClassification",Yo]],["audio-spectrogram-transformer",["ASTForAudioClassification",nn]]]),Ta=new Map([["wavlm",["WavLMForXVector",ti]]]),va=new Map([["unispeech-sat",["UniSpeechSatForAudioFrameClassification",Go]],["wavlm",["WavLMForAudioFrameClassification",ni]],["wav2vec2",["Wav2Vec2ForAudioFrameClassification",Po]],["pyannote",["PyAnnoteForAudioFrameClassification",Eo]]]),Fa=new Map([["vitmatte",["VitMatteForImageMatting",Us]]]),Ca=new Map([["swin2sr",["Swin2SRForImageSuperResolution",Br]]]),Pa=new Map([["dpt",["DPTForDepthEstimation",jr]],["depth_anything",["DepthAnythingForDepthEstimation",Vr]],["glpn",["GLPNForDepthEstimation",Kr]],["sapiens",["SapiensForDepthEstimation",$r]],["depth_pro",["DepthProForDepthEstimation",Wr]]]),Sa=new Map([["sapiens",["SapiensForNormalEstimation",qr]]]),Aa=new Map([["clip",["CLIPVisionModelWithProjection",wn]],["siglip",["SiglipVisionModel",xn]]]),Ea=[[ea,w],[ta,M],[na,x],[ia,w],[aa,w],[la,b],[sa,b],[ca,x],[da,w],[ua,w],[pa,y],[ha,T],[ma,w],[wa,w],[ba,w],[Ma,w],[Fa,w],[Ca,w],[Pa,w],[Sa,w],[fa,w],[ga,w],[ya,k],[xa,w],[ka,w],[ra,b],[oa,w],[Ta,w],[va,w],[Aa,w]];for(const[e,t]of Ea)for(const[n,s]of e.values())F.set(n,t),P.set(s,n),C.set(n,s);const za=[["MusicgenForConditionalGeneration",ji,v],["CLIPTextModelWithProjection",fn,w],["SiglipTextModel",yn,w],["ClapTextModelWithProjection",yi,w],["ClapAudioModelWithProjection",xi,w]];for(const[e,t,n]of za)F.set(e,n),P.set(t,e),C.set(e,t);class La extends Zi{static MODEL_CLASS_MAPPINGS=Ea.map((e=>e[0]));static BASE_IF_FAIL=!0}class Ia extends Zi{static MODEL_CLASS_MAPPINGS=[ia]}class Ba extends Zi{static MODEL_CLASS_MAPPINGS=[aa]}class Na extends Zi{static MODEL_CLASS_MAPPINGS=[la]}class Oa extends Zi{static MODEL_CLASS_MAPPINGS=[sa]}class ja extends Zi{static MODEL_CLASS_MAPPINGS=[ra]}class Da extends Zi{static MODEL_CLASS_MAPPINGS=[oa]}class Va extends Zi{static MODEL_CLASS_MAPPINGS=[ca]}class Ra extends Zi{static MODEL_CLASS_MAPPINGS=[da]}class Ga extends Zi{static MODEL_CLASS_MAPPINGS=[ua]}class $a extends Zi{static MODEL_CLASS_MAPPINGS=[pa]}class qa extends Zi{static MODEL_CLASS_MAPPINGS=[ma]}class Ua extends Zi{static MODEL_CLASS_MAPPINGS=[wa]}class Wa extends Zi{static MODEL_CLASS_MAPPINGS=[Ma]}class Xa extends Zi{static MODEL_CLASS_MAPPINGS=[ba]}class Qa extends Zi{static MODEL_CLASS_MAPPINGS=[fa]}class Ha extends Zi{static MODEL_CLASS_MAPPINGS=[ga]}class Ya extends Zi{static MODEL_CLASS_MAPPINGS=[ya]}class Ja extends Zi{static MODEL_CLASS_MAPPINGS=[xa]}class Ka extends Zi{static MODEL_CLASS_MAPPINGS=[ka]}class Za extends Zi{static MODEL_CLASS_MAPPINGS=[Ta]}class el extends Zi{static MODEL_CLASS_MAPPINGS=[va]}class tl extends Zi{static MODEL_CLASS_MAPPINGS=[_a]}class nl extends Zi{static MODEL_CLASS_MAPPINGS=[Fa]}class sl extends Zi{static MODEL_CLASS_MAPPINGS=[Ca]}class rl extends Zi{static MODEL_CLASS_MAPPINGS=[Pa]}class ol extends Zi{static MODEL_CLASS_MAPPINGS=[Sa]}class il extends Zi{static MODEL_CLASS_MAPPINGS=[Aa]}class al extends G{constructor({logits:e,past_key_values:t,encoder_outputs:n,decoder_attentions:s=null,cross_attentions:r=null}){super(),this.logits=e,this.past_key_values=t,this.encoder_outputs=n,this.decoder_attentions=s,this.cross_attentions=r}}class ll extends G{constructor({logits:e}){super(),this.logits=e}}class cl extends G{constructor({logits:e,embeddings:t}){super(),this.logits=e,this.embeddings=t}}class dl extends G{constructor({logits:e}){super(),this.logits=e}}class ul extends G{constructor({logits:e}){super(),this.logits=e}}class pl extends G{constructor({start_logits:e,end_logits:t}){super(),this.start_logits=e,this.end_logits=t}}class hl extends G{constructor({logits:e}){super(),this.logits=e}}class _l extends G{constructor({logits:e,past_key_values:t}){super(),this.logits=e,this.past_key_values=t}}class ml extends G{constructor({alphas:e}){super(),this.alphas=e}}class fl extends G{constructor({waveform:e,spectrogram:t}){super(),this.waveform=e,this.spectrogram=t}}},"./src/models/whisper/common_whisper.js":
|
|
112
|
+
\***********************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{ASTForAudioClassification:()=>sn,ASTModel:()=>nn,ASTPreTrainedModel:()=>tn,AlbertForMaskedLM:()=>pt,AlbertForQuestionAnswering:()=>ut,AlbertForSequenceClassification:()=>dt,AlbertModel:()=>ct,AlbertPreTrainedModel:()=>lt,AutoModel:()=>Oa,AutoModelForAudioClassification:()=>nl,AutoModelForAudioFrameClassification:()=>rl,AutoModelForCTC:()=>tl,AutoModelForCausalLM:()=>qa,AutoModelForDepthEstimation:()=>ll,AutoModelForDocumentQuestionAnswering:()=>ol,AutoModelForImageClassification:()=>Qa,AutoModelForImageFeatureExtraction:()=>dl,AutoModelForImageMatting:()=>il,AutoModelForImageSegmentation:()=>Ha,AutoModelForImageToImage:()=>al,AutoModelForMaskGeneration:()=>el,AutoModelForMaskedLM:()=>Ua,AutoModelForNormalEstimation:()=>cl,AutoModelForObjectDetection:()=>Ka,AutoModelForQuestionAnswering:()=>Wa,AutoModelForSemanticSegmentation:()=>Ya,AutoModelForSeq2SeqLM:()=>Va,AutoModelForSequenceClassification:()=>ja,AutoModelForSpeechSeq2Seq:()=>Ra,AutoModelForTextToSpectrogram:()=>Ga,AutoModelForTextToWaveform:()=>$a,AutoModelForTokenClassification:()=>Da,AutoModelForUniversalSegmentation:()=>Ja,AutoModelForVision2Seq:()=>Xa,AutoModelForXVector:()=>sl,AutoModelForZeroShotObjectDetection:()=>Za,BartForConditionalGeneration:()=>Tt,BartForSequenceClassification:()=>vt,BartModel:()=>kt,BartPretrainedModel:()=>xt,BaseModelOutput:()=>q,BeitForImageClassification:()=>dr,BeitModel:()=>cr,BeitPreTrainedModel:()=>lr,BertForMaskedLM:()=>X,BertForQuestionAnswering:()=>Y,BertForSequenceClassification:()=>Q,BertForTokenClassification:()=>H,BertModel:()=>W,BertPreTrainedModel:()=>U,BlenderbotForConditionalGeneration:()=>zt,BlenderbotModel:()=>Lt,BlenderbotPreTrainedModel:()=>Et,BlenderbotSmallForConditionalGeneration:()=>Nt,BlenderbotSmallModel:()=>Bt,BlenderbotSmallPreTrainedModel:()=>It,BloomForCausalLM:()=>vs,BloomModel:()=>Ts,BloomPreTrainedModel:()=>ks,CLIPModel:()=>mn,CLIPPreTrainedModel:()=>_n,CLIPSegForImageSegmentation:()=>Pn,CLIPSegModel:()=>Cn,CLIPSegPreTrainedModel:()=>Fn,CLIPTextModel:()=>fn,CLIPTextModelWithProjection:()=>gn,CLIPVisionModel:()=>wn,CLIPVisionModelWithProjection:()=>Mn,CamembertForMaskedLM:()=>Me,CamembertForQuestionAnswering:()=>xe,CamembertForSequenceClassification:()=>be,CamembertForTokenClassification:()=>ye,CamembertModel:()=>we,CamembertPreTrainedModel:()=>ge,CausalLMOutput:()=>gl,CausalLMOutputWithPast:()=>wl,ChineseCLIPModel:()=>vn,ChineseCLIPPreTrainedModel:()=>Tn,ClapAudioModelWithProjection:()=>Fi,ClapModel:()=>Ti,ClapPreTrainedModel:()=>ki,ClapTextModelWithProjection:()=>vi,CodeGenForCausalLM:()=>Hn,CodeGenModel:()=>Qn,CodeGenPreTrainedModel:()=>Xn,CohereForCausalLM:()=>rs,CohereModel:()=>ss,CoherePreTrainedModel:()=>ns,ConvBertForMaskedLM:()=>ae,ConvBertForQuestionAnswering:()=>de,ConvBertForSequenceClassification:()=>le,ConvBertForTokenClassification:()=>ce,ConvBertModel:()=>ie,ConvBertPreTrainedModel:()=>oe,ConvNextForImageClassification:()=>ao,ConvNextModel:()=>io,ConvNextPreTrainedModel:()=>oo,ConvNextV2ForImageClassification:()=>uo,ConvNextV2Model:()=>co,ConvNextV2PreTrainedModel:()=>lo,DPTForDepthEstimation:()=>Gr,DPTModel:()=>Rr,DPTPreTrainedModel:()=>Vr,DebertaForMaskedLM:()=>ve,DebertaForQuestionAnswering:()=>Pe,DebertaForSequenceClassification:()=>Fe,DebertaForTokenClassification:()=>Ce,DebertaModel:()=>Te,DebertaPreTrainedModel:()=>ke,DebertaV2ForMaskedLM:()=>Ee,DebertaV2ForQuestionAnswering:()=>Ie,DebertaV2ForSequenceClassification:()=>Le,DebertaV2ForTokenClassification:()=>ze,DebertaV2Model:()=>Ae,DebertaV2PreTrainedModel:()=>Se,DecisionTransformerModel:()=>na,DecisionTransformerPreTrainedModel:()=>ta,DeiTForImageClassification:()=>Cr,DeiTModel:()=>Fr,DeiTPreTrainedModel:()=>vr,DepthAnythingForDepthEstimation:()=>qr,DepthAnythingPreTrainedModel:()=>$r,DepthProForDepthEstimation:()=>Yr,DepthProPreTrainedModel:()=>Hr,DetrForObjectDetection:()=>hr,DetrForSegmentation:()=>_r,DetrModel:()=>pr,DetrObjectDetectionOutput:()=>mr,DetrPreTrainedModel:()=>ur,DetrSegmentationOutput:()=>fr,Dinov2ForImageClassification:()=>_o,Dinov2Model:()=>ho,Dinov2PreTrainedModel:()=>po,DistilBertForMaskedLM:()=>Ve,DistilBertForQuestionAnswering:()=>De,DistilBertForSequenceClassification:()=>Oe,DistilBertForTokenClassification:()=>je,DistilBertModel:()=>Ne,DistilBertPreTrainedModel:()=>Be,DonutSwinModel:()=>ro,DonutSwinPreTrainedModel:()=>so,EfficientNetForImageClassification:()=>ji,EfficientNetModel:()=>Oi,EfficientNetPreTrainedModel:()=>Ni,ElectraForMaskedLM:()=>he,ElectraForQuestionAnswering:()=>fe,ElectraForSequenceClassification:()=>_e,ElectraForTokenClassification:()=>me,ElectraModel:()=>pe,ElectraPreTrainedModel:()=>ue,EsmForMaskedLM:()=>$e,EsmForSequenceClassification:()=>qe,EsmForTokenClassification:()=>Ue,EsmModel:()=>Ge,EsmPreTrainedModel:()=>Re,FalconForCausalLM:()=>xi,FalconModel:()=>yi,FalconPreTrainedModel:()=>bi,FastViTForImageClassification:()=>Xs,FastViTModel:()=>Ws,FastViTPreTrainedModel:()=>Us,Florence2ForConditionalGeneration:()=>hn,Florence2PreTrainedModel:()=>pn,GLPNForDepthEstimation:()=>no,GLPNModel:()=>to,GLPNPreTrainedModel:()=>eo,GPT2LMHeadModel:()=>En,GPT2Model:()=>An,GPT2PreTrainedModel:()=>Sn,GPTBigCodeForCausalLM:()=>Wn,GPTBigCodeModel:()=>Un,GPTBigCodePreTrainedModel:()=>qn,GPTJForCausalLM:()=>$n,GPTJModel:()=>Gn,GPTJPreTrainedModel:()=>Rn,GPTNeoForCausalLM:()=>On,GPTNeoModel:()=>Nn,GPTNeoPreTrainedModel:()=>Bn,GPTNeoXForCausalLM:()=>Vn,GPTNeoXModel:()=>Dn,GPTNeoXPreTrainedModel:()=>jn,Gemma2ForCausalLM:()=>ds,Gemma2Model:()=>cs,Gemma2PreTrainedModel:()=>ls,GemmaForCausalLM:()=>as,GemmaModel:()=>is,GemmaPreTrainedModel:()=>os,GraniteForCausalLM:()=>ts,GraniteModel:()=>es,GranitePreTrainedModel:()=>Zn,GroupViTModel:()=>qs,GroupViTPreTrainedModel:()=>$s,HieraForImageClassification:()=>Ar,HieraModel:()=>Sr,HieraPreTrainedModel:()=>Pr,HubertForCTC:()=>Zo,HubertForSequenceClassification:()=>ei,HubertModel:()=>Ko,HubertPreTrainedModel:()=>Jo,ImageMattingOutput:()=>Ml,JAISLMHeadModel:()=>In,JAISModel:()=>zn,JAISPreTrainedModel:()=>Ln,LlamaForCausalLM:()=>Kn,LlamaModel:()=>Jn,LlamaPreTrainedModel:()=>Yn,LlavaForConditionalGeneration:()=>dn,LlavaPreTrainedModel:()=>cn,LongT5ForConditionalGeneration:()=>wt,LongT5Model:()=>gt,LongT5PreTrainedModel:()=>ft,M2M100ForConditionalGeneration:()=>Co,M2M100Model:()=>Fo,M2M100PreTrainedModel:()=>vo,MBartForCausalLM:()=>At,MBartForConditionalGeneration:()=>Pt,MBartForSequenceClassification:()=>St,MBartModel:()=>Ct,MBartPreTrainedModel:()=>Ft,MPNetForMaskedLM:()=>Ze,MPNetForQuestionAnswering:()=>nt,MPNetForSequenceClassification:()=>et,MPNetForTokenClassification:()=>tt,MPNetModel:()=>Ke,MPNetPreTrainedModel:()=>Je,MT5ForConditionalGeneration:()=>yt,MT5Model:()=>bt,MT5PreTrainedModel:()=>Mt,MarianMTModel:()=>To,MarianModel:()=>ko,MarianPreTrainedModel:()=>xo,MaskFormerForInstanceSegmentation:()=>Zr,MaskFormerModel:()=>Kr,MaskFormerPreTrainedModel:()=>Jr,MaskedLMOutput:()=>ml,MistralForCausalLM:()=>fi,MistralModel:()=>mi,MistralPreTrainedModel:()=>_i,MobileBertForMaskedLM:()=>Qe,MobileBertForQuestionAnswering:()=>Ye,MobileBertForSequenceClassification:()=>He,MobileBertModel:()=>Xe,MobileBertPreTrainedModel:()=>We,MobileNetV1ForImageClassification:()=>Ui,MobileNetV1Model:()=>qi,MobileNetV1PreTrainedModel:()=>$i,MobileNetV2ForImageClassification:()=>Qi,MobileNetV2Model:()=>Xi,MobileNetV2PreTrainedModel:()=>Wi,MobileNetV3ForImageClassification:()=>Ji,MobileNetV3Model:()=>Yi,MobileNetV3PreTrainedModel:()=>Hi,MobileNetV4ForImageClassification:()=>ea,MobileNetV4Model:()=>Zi,MobileNetV4PreTrainedModel:()=>Ki,MobileViTForImageClassification:()=>Ks,MobileViTModel:()=>Js,MobileViTPreTrainedModel:()=>Ys,MobileViTV2ForImageClassification:()=>tr,MobileViTV2Model:()=>er,MobileViTV2PreTrainedModel:()=>Zs,ModelOutput:()=>$,Moondream1ForConditionalGeneration:()=>un,MptForCausalLM:()=>Ps,MptModel:()=>Cs,MptPreTrainedModel:()=>Fs,MusicgenForCausalLM:()=>Ri,MusicgenForConditionalGeneration:()=>Gi,MusicgenModel:()=>Vi,MusicgenPreTrainedModel:()=>Di,NomicBertModel:()=>K,NomicBertPreTrainedModel:()=>J,OPTForCausalLM:()=>Es,OPTModel:()=>As,OPTPreTrainedModel:()=>Ss,OpenELMForCausalLM:()=>hs,OpenELMModel:()=>ps,OpenELMPreTrainedModel:()=>us,OwlViTForObjectDetection:()=>rr,OwlViTModel:()=>sr,OwlViTPreTrainedModel:()=>nr,Owlv2ForObjectDetection:()=>ar,Owlv2Model:()=>ir,Owlv2PreTrainedModel:()=>or,Phi3ForCausalLM:()=>xs,Phi3Model:()=>ys,Phi3PreTrainedModel:()=>bs,PhiForCausalLM:()=>Ms,PhiModel:()=>ws,PhiPreTrainedModel:()=>gs,PreTrainedModel:()=>G,PretrainedMixin:()=>sa,PvtForImageClassification:()=>Os,PvtModel:()=>Ns,PvtPreTrainedModel:()=>Bs,PyAnnoteForAudioFrameClassification:()=>Bo,PyAnnoteModel:()=>Io,PyAnnotePreTrainedModel:()=>zo,QuestionAnsweringModelOutput:()=>fl,Qwen2ForCausalLM:()=>fs,Qwen2Model:()=>ms,Qwen2PreTrainedModel:()=>_s,RTDetrForObjectDetection:()=>Mr,RTDetrModel:()=>wr,RTDetrObjectDetectionOutput:()=>br,RTDetrPreTrainedModel:()=>gr,ResNetForImageClassification:()=>zr,ResNetModel:()=>Lr,ResNetPreTrainedModel:()=>Er,RoFormerForMaskedLM:()=>te,RoFormerForQuestionAnswering:()=>re,RoFormerForSequenceClassification:()=>ne,RoFormerForTokenClassification:()=>se,RoFormerModel:()=>ee,RoFormerPreTrainedModel:()=>Z,RobertaForMaskedLM:()=>Dt,RobertaForQuestionAnswering:()=>Gt,RobertaForSequenceClassification:()=>Vt,RobertaForTokenClassification:()=>Rt,RobertaModel:()=>jt,RobertaPreTrainedModel:()=>Ot,SamImageSegmentationOutput:()=>yo,SamModel:()=>bo,SamPreTrainedModel:()=>Mo,SapiensForDepthEstimation:()=>Xr,SapiensForNormalEstimation:()=>Qr,SapiensForSemanticSegmentation:()=>Wr,SapiensPreTrainedModel:()=>Ur,SegformerForImageClassification:()=>Ei,SegformerForSemanticSegmentation:()=>Li,SegformerModel:()=>Ai,SegformerPreTrainedModel:()=>Si,Seq2SeqLMOutput:()=>ul,SequenceClassifierOutput:()=>pl,SiglipModel:()=>yn,SiglipPreTrainedModel:()=>bn,SiglipTextModel:()=>xn,SiglipVisionModel:()=>kn,SpeechT5ForSpeechToText:()=>ci,SpeechT5ForTextToSpeech:()=>di,SpeechT5HifiGan:()=>ui,SpeechT5Model:()=>li,SpeechT5PreTrainedModel:()=>ai,SqueezeBertForMaskedLM:()=>ot,SqueezeBertForQuestionAnswering:()=>at,SqueezeBertForSequenceClassification:()=>it,SqueezeBertModel:()=>rt,SqueezeBertPreTrainedModel:()=>st,StableLmForCausalLM:()=>Bi,StableLmModel:()=>Ii,StableLmPreTrainedModel:()=>zi,Starcoder2ForCausalLM:()=>Mi,Starcoder2Model:()=>wi,Starcoder2PreTrainedModel:()=>gi,Swin2SRForImageSuperResolution:()=>Dr,Swin2SRModel:()=>jr,Swin2SRPreTrainedModel:()=>Or,SwinForImageClassification:()=>Nr,SwinModel:()=>Br,SwinPreTrainedModel:()=>Ir,T5ForConditionalGeneration:()=>mt,T5Model:()=>_t,T5PreTrainedModel:()=>ht,TableTransformerForObjectDetection:()=>kr,TableTransformerModel:()=>xr,TableTransformerObjectDetectionOutput:()=>Tr,TableTransformerPreTrainedModel:()=>yr,TokenClassifierOutput:()=>_l,TrOCRForCausalLM:()=>hi,TrOCRPreTrainedModel:()=>pi,UniSpeechForCTC:()=>Vo,UniSpeechForSequenceClassification:()=>Ro,UniSpeechModel:()=>Do,UniSpeechPreTrainedModel:()=>jo,UniSpeechSatForAudioFrameClassification:()=>Wo,UniSpeechSatForCTC:()=>qo,UniSpeechSatForSequenceClassification:()=>Uo,UniSpeechSatModel:()=>$o,UniSpeechSatPreTrainedModel:()=>Go,ViTForImageClassification:()=>Is,ViTMAEModel:()=>Ds,ViTMAEPreTrainedModel:()=>js,ViTMSNForImageClassification:()=>Gs,ViTMSNModel:()=>Rs,ViTMSNPreTrainedModel:()=>Vs,ViTModel:()=>zs,ViTPreTrainedModel:()=>Ls,VisionEncoderDecoderModel:()=>ln,VitMatteForImageMatting:()=>Hs,VitMattePreTrainedModel:()=>Qs,VitsModel:()=>Pi,VitsModelOutput:()=>bl,VitsPreTrainedModel:()=>Ci,Wav2Vec2BertForCTC:()=>Ho,Wav2Vec2BertForSequenceClassification:()=>Yo,Wav2Vec2BertModel:()=>Qo,Wav2Vec2BertPreTrainedModel:()=>Xo,Wav2Vec2ForAudioFrameClassification:()=>Lo,Wav2Vec2ForCTC:()=>Ao,Wav2Vec2ForSequenceClassification:()=>Eo,Wav2Vec2Model:()=>So,Wav2Vec2PreTrainedModel:()=>Po,WavLMForAudioFrameClassification:()=>ii,WavLMForCTC:()=>si,WavLMForSequenceClassification:()=>ri,WavLMForXVector:()=>oi,WavLMModel:()=>ni,WavLMPreTrainedModel:()=>ti,WeSpeakerResNetModel:()=>Oo,WeSpeakerResNetPreTrainedModel:()=>No,WhisperForConditionalGeneration:()=>an,WhisperModel:()=>on,WhisperPreTrainedModel:()=>rn,XLMForQuestionAnswering:()=>Qt,XLMForSequenceClassification:()=>Wt,XLMForTokenClassification:()=>Xt,XLMModel:()=>qt,XLMPreTrainedModel:()=>$t,XLMRobertaForMaskedLM:()=>Jt,XLMRobertaForQuestionAnswering:()=>en,XLMRobertaForSequenceClassification:()=>Kt,XLMRobertaForTokenClassification:()=>Zt,XLMRobertaModel:()=>Yt,XLMRobertaPreTrainedModel:()=>Ht,XLMWithLMHeadModel:()=>Ut,XVectorOutput:()=>hl,YolosForObjectDetection:()=>go,YolosModel:()=>fo,YolosObjectDetectionOutput:()=>wo,YolosPreTrainedModel:()=>mo});var s=n(/*! ./configs.js */"./src/configs.js"),r=n(/*! ./backends/onnx.js */"./src/backends/onnx.js"),o=n(/*! ./utils/dtypes.js */"./src/utils/dtypes.js"),i=n(/*! ./utils/generic.js */"./src/utils/generic.js"),a=n(/*! ./utils/core.js */"./src/utils/core.js"),l=n(/*! ./utils/hub.js */"./src/utils/hub.js"),c=n(/*! ./generation/logits_process.js */"./src/generation/logits_process.js"),d=n(/*! ./generation/configuration_utils.js */"./src/generation/configuration_utils.js"),u=n(/*! ./utils/tensor.js */"./src/utils/tensor.js"),p=n(/*! ./utils/maths.js */"./src/utils/maths.js"),h=n(/*! ./generation/stopping_criteria.js */"./src/generation/stopping_criteria.js"),_=n(/*! ./generation/logits_sampler.js */"./src/generation/logits_sampler.js"),m=n(/*! ./env.js */"./src/env.js"),f=n(/*! ./models/whisper/generation_whisper.js */"./src/models/whisper/generation_whisper.js"),g=n(/*! ./models/whisper/common_whisper.js */"./src/models/whisper/common_whisper.js");const w=0,M=1,b=2,y=3,x=4,k=5,T=6,v=7,F=new Map,C=new Map,P=new Map;async function S(e,t,n){return Object.fromEntries(await Promise.all(Object.keys(t).map((async i=>{const{buffer:a,session_options:c}=await async function(e,t,n){const i=n.config?.["transformers.js_config"]??{};let a=n.device??i.device;a&&"string"!=typeof a&&(a.hasOwnProperty(t)?a=a[t]:(console.warn(`device not specified for "${t}". Using the default device.`),a=null));const c=a??(m.apis.IS_NODE_ENV?"cpu":"wasm"),d=(0,r.deviceToExecutionProviders)(c);let u=n.dtype??i.dtype;"string"!=typeof u&&(u&&u.hasOwnProperty(t)?u=u[t]:(u=o.DEFAULT_DEVICE_DTYPE_MAPPING[c]??o.DATA_TYPES.fp32,console.warn(`dtype not specified for "${t}". Using the default dtype (${u}) for this device (${c}).`)));const p=u;if(!o.DEFAULT_DTYPE_SUFFIX_MAPPING.hasOwnProperty(p))throw new Error(`Invalid dtype: ${p}. Should be one of: ${Object.keys(o.DATA_TYPES).join(", ")}`);if(p===o.DATA_TYPES.fp16&&"webgpu"===c&&!await(0,o.isWebGpuFp16Supported)())throw new Error(`The device (${c}) does not support fp16.`);const h=o.DEFAULT_DTYPE_SUFFIX_MAPPING[p],_=`${n.subfolder??""}/${t}${h}.onnx`,f={...n.session_options};f.executionProviders??=d;const g=i.free_dimension_overrides;g?f.freeDimensionOverrides??=g:c.startsWith("webnn")&&!f.freeDimensionOverrides&&console.warn('WebNN does not currently support dynamic shapes and requires `free_dimension_overrides` to be set in config.json as a field within "transformers.js_config". When `free_dimension_overrides` is not set, you may experience significant performance degradation.');const w=(0,l.getModelFile)(e,_,!0,n),M=n.use_external_data_format??i.use_external_data_format;let b=[];if(M&&(!0===M||"object"==typeof M&&M.hasOwnProperty(t)&&!0===M[t])){if(m.apis.IS_NODE_ENV)throw new Error("External data format is not yet supported in Node.js");const s=`${t}${h}.onnx_data`,r=`${n.subfolder??""}/${s}`;b.push(new Promise((async(t,o)=>{const i=await(0,l.getModelFile)(e,r,!0,n);t({path:s,data:i})})))}else void 0!==f.externalData&&(b=f.externalData.map((async t=>{if("string"==typeof t.data){const s=await(0,l.getModelFile)(e,t.data,!0,n);return{...t,data:s}}return t})));if(b.length>0&&(f.externalData=await Promise.all(b)),"webgpu"===c){const e=(0,s.getKeyValueShapes)(n.config,{prefix:"present"});if(Object.keys(e).length>0&&!(0,r.isONNXProxy)()){const t={};for(const n in e)t[n]="gpu-buffer";f.preferredOutputLocation=t}}return{buffer:await w,session_options:f}}(e,t[i],n);return[i,await(0,r.createInferenceSession)(a,c)]}))))}async function A(e,t,n){return Object.fromEntries(await Promise.all(Object.keys(t).map((async s=>[s,await(0,l.getModelJSON)(e,t[s],!1,n)]))))}async function E(e,t){const n=function(e,t){const n=Object.create(null),s=[];for(const o of e.inputNames){const e=t[o];e instanceof u.Tensor?n[o]=(0,r.isONNXProxy)()?e.clone():e:s.push(o)}if(s.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${s.join(", ")}.`);const o=Object.keys(t).length,i=e.inputNames.length;if(o>i){let n=Object.keys(t).filter((t=>!e.inputNames.includes(t)));console.warn(`WARNING: Too many inputs were provided (${o} > ${i}). The following inputs will be ignored: "${n.join(", ")}".`)}return n}(e,t);try{const t=Object.fromEntries(Object.entries(n).map((([e,t])=>[e,t.ort_tensor])));let s=await e.run(t);return s=L(s),s}catch(e){throw console.error(`An error occurred during model execution: "${e}".`),console.error("Inputs given to model:",n),e}}function L(e){for(let t in e)(0,r.isONNXTensor)(e[t])?e[t]=new u.Tensor(e[t]):"object"==typeof e[t]&&L(e[t]);return e}function z(e){if(e instanceof u.Tensor)return e;if(0===e.length)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 u.Tensor("int64",BigInt64Array.from(e.flat().map((e=>BigInt(e)))),[e.length,e[0].length])}return new u.Tensor("int64",BigInt64Array.from(e.map((e=>BigInt(e)))),[1,e.length])}function I(e){return new u.Tensor("bool",[e],[1])}async function B(e,t){let{encoder_outputs:n,input_ids:s,decoder_input_ids:r,...o}=t;if(!n){const s=(0,a.pick)(t,e.sessions.model.inputNames);n=(await N(e,s)).last_hidden_state}o.input_ids=r,o.encoder_hidden_states=n,e.sessions.decoder_model_merged.inputNames.includes("encoder_attention_mask")&&(o.encoder_attention_mask=t.attention_mask);return await O(e,o,!0)}async function N(e,t){const n=e.sessions.model,s=(0,a.pick)(t,n.inputNames);if(n.inputNames.includes("inputs_embeds")&&!s.inputs_embeds){if(!t.input_ids)throw new Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");s.inputs_embeds=await e.encode_text({input_ids:t.input_ids})}return n.inputNames.includes("token_type_ids")&&!s.token_type_ids&&(s.token_type_ids=new u.Tensor("int64",new BigInt64Array(s.input_ids.data.length),s.input_ids.dims)),await E(n,s)}async function O(e,t,n=!1){const s=e.sessions[n?"decoder_model_merged":"model"],{past_key_values:r,...o}=t;s.inputNames.includes("use_cache_branch")&&(o.use_cache_branch=I(!!r)),s.inputNames.includes("position_ids")&&o.attention_mask&&!o.position_ids&&(o.position_ids=function(e,t=null){const{input_ids:n,inputs_embeds:s,attention_mask:r}=e,[o,i]=r.dims,a=new BigInt64Array(r.data.length);for(let e=0;e<o;++e){const t=e*i;let n=BigInt(0);for(let e=0;e<i;++e){const s=t+e;0n===r.data[s]?a[s]=BigInt(1):(a[s]=n,n+=r.data[s])}}let l=new u.Tensor("int64",a,r.dims);if(t){const e=-(n??s).dims.at(1);l=l.slice(null,[e,null])}return l}(o,r)),e.addPastKeyValues(o,r);const i=(0,a.pick)(o,s.inputNames);return await E(s,i)}async function j(e,{input_ids:t=null,attention_mask:n=null,pixel_values:s=null,position_ids:r=null,inputs_embeds:o=null,past_key_values:i=null,generation_config:a=null,logits_processor:l=null,...c}){if(!o)if(o=await e.encode_text({input_ids:t}),s&&1!==t.dims[1]){const r=await e.encode_image({pixel_values:s});({inputs_embeds:o,attention_mask:n}=e._merge_input_ids_with_image_features({image_features:r,inputs_embeds:o,input_ids:t,attention_mask:n}))}else if(i&&s&&1===t.dims[1]){const e=t.dims[1],s=Object.values(i)[0].dims.at(-2);n=(0,u.cat)([(0,u.ones)([t.dims[0],s]),n.slice(null,[n.dims[1]-e,n.dims[1]])],1)}return await O(e,{inputs_embeds:o,past_key_values:i,attention_mask:n,position_ids:r,generation_config:a,logits_processor:l},!0)}function D(e,t,n,s){if(n.past_key_values){const t=Object.values(n.past_key_values)[0].dims.at(-2),{input_ids:s,attention_mask:r}=n;if(r&&r.dims[1]>s.dims[1]);else if(t<s.dims[1])n.input_ids=s.slice(null,[t,null]);else if(null!=e.config.image_token_index&&s.data.some((t=>t==e.config.image_token_index))){const r=e.config.num_image_tokens;if(!r)throw new Error("`num_image_tokens` is missing in the model configuration.");const o=s.dims[1]-(t-r);n.input_ids=s.slice(null,[-o,null]),n.attention_mask=(0,u.ones)([1,t+o])}}return n}function V(e,t,n,s){return n.past_key_values&&(t=t.map((e=>[e.at(-1)]))),{...n,decoder_input_ids:z(t)}}function R(e,...t){return e.config.is_encoder_decoder?V(e,...t):D(e,...t)}class G extends i.Callable{main_input_name="input_ids";forward_params=["input_ids","attention_mask"];constructor(e,t,n){super(),this.config=e,this.sessions=t,this.configs=n;const s=P.get(this.constructor),r=F.get(s);switch(this.can_generate=!1,this._forward=null,this._prepare_inputs_for_generation=null,r){case x:this.can_generate=!0,this._forward=O,this._prepare_inputs_for_generation=D;break;case b:case y:case v:this.can_generate=!0,this._forward=B,this._prepare_inputs_for_generation=V;break;case M:this._forward=B;break;case T:this.can_generate=!0,this._forward=j,this._prepare_inputs_for_generation=R;break;default:this._forward=N}this.can_generate&&this.forward_params.push("past_key_values"),this.custom_config=this.config["transformers.js_config"]??{}}async dispose(){const e=[];for(const t of Object.values(this.sessions))t?.handler?.dispose&&e.push(t.handler.dispose());return await Promise.all(e)}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:r=null,local_files_only:o=!1,revision:i="main",model_file_name:a=null,subfolder:l="onnx",device:c=null,dtype:d=null,use_external_data_format:u=null,session_options:p={}}={}){let h={progress_callback:t,config:n,cache_dir:r,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:d,use_external_data_format:u,session_options:p};const _=P.get(this),m=F.get(_);let f;if(n=h.config=await s.AutoConfig.from_pretrained(e,h),m===x)f=await Promise.all([S(e,{model:h.model_file_name??"model"},h),A(e,{generation_config:"generation_config.json"},h)]);else if(m===b||m===y)f=await Promise.all([S(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},h),A(e,{generation_config:"generation_config.json"},h)]);else if(m===k)f=await Promise.all([S(e,{model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"},h)]);else if(m===M)f=await Promise.all([S(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},h)]);else if(m===T){const t={embed_tokens:"embed_tokens",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};n.is_encoder_decoder&&(t.model="encoder_model"),f=await Promise.all([S(e,t,h),A(e,{generation_config:"generation_config.json"},h)])}else m===v?f=await Promise.all([S(e,{model:"text_encoder",decoder_model_merged:"decoder_model_merged",encodec_decode:"encodec_decode"},h),A(e,{generation_config:"generation_config.json"},h)]):(m!==w&&console.warn(`Model type for '${_??n?.model_type}' not found, assuming encoder-only architecture. Please report this at https://github.com/xenova/transformers.js/issues/new/choose.`),f=await Promise.all([S(e,{model:h.model_file_name??"model"},h)]));return new this(n,...f)}async _call(e){return await this.forward(e)}async forward(e){return await this._forward(this,e)}get generation_config(){return this.configs?.generation_config??null}_get_logits_warper(e){const t=new c.LogitsProcessorList;return null!==e.temperature&&1!==e.temperature&&t.push(new c.TemperatureLogitsWarper(e.temperature)),null!==e.top_k&&0!==e.top_k&&t.push(new c.TopKLogitsWarper(e.top_k)),null!==e.top_p&&e.top_p<1&&t.push(new c.TopPLogitsWarper(e.top_p)),t}_get_logits_processor(e,t,n=null){const s=new c.LogitsProcessorList;if(null!==e.repetition_penalty&&1!==e.repetition_penalty&&s.push(new c.RepetitionPenaltyLogitsProcessor(e.repetition_penalty)),null!==e.no_repeat_ngram_size&&e.no_repeat_ngram_size>0&&s.push(new c.NoRepeatNGramLogitsProcessor(e.no_repeat_ngram_size)),null!==e.bad_words_ids&&s.push(new c.NoBadWordsLogitsProcessor(e.bad_words_ids,e.eos_token_id)),null!==e.min_length&&null!==e.eos_token_id&&e.min_length>0&&s.push(new c.MinLengthLogitsProcessor(e.min_length,e.eos_token_id)),null!==e.min_new_tokens&&null!==e.eos_token_id&&e.min_new_tokens>0&&s.push(new c.MinNewTokensLengthLogitsProcessor(t,e.min_new_tokens,e.eos_token_id)),null!==e.forced_bos_token_id&&s.push(new c.ForcedBOSTokenLogitsProcessor(e.forced_bos_token_id)),null!==e.forced_eos_token_id&&s.push(new c.ForcedEOSTokenLogitsProcessor(e.max_length,e.forced_eos_token_id)),null!==e.begin_suppress_tokens){const n=t>1||null===e.forced_bos_token_id?t:t+1;s.push(new c.SuppressTokensAtBeginLogitsProcessor(e.begin_suppress_tokens,n))}return null!==e.guidance_scale&&e.guidance_scale>1&&s.push(new c.ClassifierFreeGuidanceLogitsProcessor(e.guidance_scale)),null!==n&&s.extend(n),s}_prepare_generation_config(e,t,n=d.GenerationConfig){const s={...this.config};for(const e of["decoder","generator","text_config"])e in s&&Object.assign(s,s[e]);const r=new n(s);return Object.assign(r,this.generation_config??{}),e&&Object.assign(r,e),t&&Object.assign(r,(0,a.pick)(t,Object.getOwnPropertyNames(r))),r}_get_stopping_criteria(e,t=null){const n=new h.StoppingCriteriaList;return null!==e.max_length&&n.push(new h.MaxLengthCriteria(e.max_length,this.config.max_position_embeddings??null)),null!==e.eos_token_id&&n.push(new h.EosTokenCriteria(e.eos_token_id)),t&&n.extend(t),n}_validate_model_class(){if(!this.can_generate){const e=[ha,fa,pa,aa],t=P.get(this.constructor),n=new Set,s=this.config.model_type;for(const t of e){const e=t.get(s);e&&n.add(e[0])}let r=`The current model class (${t}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw n.size>0&&(r+=` Please use the following class instead: ${[...n].join(", ")}`),Error(r)}}prepare_inputs_for_generation(...e){return this._prepare_inputs_for_generation(this,...e)}_update_model_kwargs_for_generation({generated_input_ids:e,outputs:t,model_inputs:n,is_encoder_decoder:s}){return n.past_key_values=this.getPastKeyValues(t,n.past_key_values),n.input_ids=new u.Tensor("int64",e.flat(),[e.length,1]),s||(n.attention_mask=(0,u.cat)([n.attention_mask,(0,u.ones)([n.attention_mask.dims[0],1])],1)),n.position_ids=null,n}_prepare_model_inputs({inputs:e,bos_token_id:t,model_kwargs:n}){const s=(0,a.pick)(n,this.forward_params),r=this.main_input_name;if(r in s){if(e)throw new Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else s[r]=e;return{inputs_tensor:s[r],model_inputs:s,model_input_name:r}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:e,model_inputs:t,model_input_name:n,generation_config:s}){if(this.sessions.model.inputNames.includes("inputs_embeds")&&!t.inputs_embeds&&"_prepare_inputs_embeds"in this){const{input_ids:e,pixel_values:n,attention_mask:s,...r}=t,o=await this._prepare_inputs_embeds(t);t={...r,...(0,a.pick)(o,["inputs_embeds","attention_mask"])}}let{last_hidden_state:r}=await N(this,t);if(null!==s.guidance_scale&&s.guidance_scale>1)r=(0,u.cat)([r,(0,u.full_like)(r,0)],0),"attention_mask"in t&&(t.attention_mask=(0,u.cat)([t.attention_mask,(0,u.zeros_like)(t.attention_mask)],0));else if(t.decoder_input_ids){const e=z(t.decoder_input_ids).dims[0];if(e!==r.dims[0]){if(1!==r.dims[0])throw new Error(`The encoder outputs have a different batch size (${r.dims[0]}) than the decoder inputs (${e}).`);r=(0,u.cat)(Array.from({length:e},(()=>r)),0)}}return t.encoder_outputs=r,t}_prepare_decoder_input_ids_for_generation({batch_size:e,model_input_name:t,model_kwargs:n,decoder_start_token_id:s,bos_token_id:r,generation_config:o}){let{decoder_input_ids:i,...a}=n;if(i)Array.isArray(i[0])||(i=Array.from({length:e},(()=>i)));else if(s??=r,"musicgen"===this.config.model_type)i=Array.from({length:e*this.config.decoder.num_codebooks},(()=>[s]));else if(Array.isArray(s)){if(s.length!==e)throw new Error(`\`decoder_start_token_id\` expcted to have length ${e} but got ${s.length}`);i=s}else i=Array.from({length:e},(()=>[s]));return i=z(i),n.decoder_attention_mask=(0,u.ones_like)(i),{input_ids:i,model_inputs:a}}async generate({inputs:e=null,generation_config:t=null,logits_processor:n=null,stopping_criteria:s=null,streamer:r=null,...o}){this._validate_model_class(),t=this._prepare_generation_config(t,o);let{inputs_tensor:i,model_inputs:a,model_input_name:l}=this._prepare_model_inputs({inputs:e,model_kwargs:o});const c=this.config.is_encoder_decoder;let d;c&&("encoder_outputs"in a||(a=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:i,model_inputs:a,model_input_name:l,generation_config:t}))),c?({input_ids:d,model_inputs:a}=this._prepare_decoder_input_ids_for_generation({batch_size:a[l].dims.at(0),model_input_name:l,model_kwargs:a,decoder_start_token_id:t.decoder_start_token_id,bos_token_id:t.bos_token_id,generation_config:t})):d=a[l];let p=d.dims.at(-1);null!==t.max_new_tokens&&(t.max_length=p+t.max_new_tokens);const h=this._get_logits_processor(t,p,n),m=this._get_stopping_criteria(t,s),f=a[l].dims.at(0),g=_.LogitsSampler.getSampler(t),w=new Array(f).fill(0),M=d.tolist();let b;r&&r.put(M);let y={};for(;;){if(a=this.prepare_inputs_for_generation(M,a,t),b=await this.forward(a),t.output_attentions&&t.return_dict_in_generate){const e=this.getAttentions(b);for(const t in e)t in y||(y[t]=[]),y[t].push(e[t])}const e=h(M,b.logits.slice(null,-1,null)),n=[];for(let t=0;t<e.dims.at(0);++t){const s=e[t],r=await g(s);for(const[e,s]of r){const r=BigInt(e);w[t]+=s,M[t].push(r),n.push([r]);break}}r&&r.put(n);if(m(M).every((e=>e)))break;a=this._update_model_kwargs_for_generation({generated_input_ids:n,outputs:b,model_inputs:a,is_encoder_decoder:c})}r&&r.end();const x=this.getPastKeyValues(b,a.past_key_values,!0),k=new u.Tensor("int64",M.flat(),[M.length,M[0].length]);if(t.return_dict_in_generate)return{sequences:k,past_key_values:x,...y};for(const e of Object.values(b))"gpu-buffer"===e.location&&e.dispose();return k}getPastKeyValues(e,t,n=!1){const s=Object.create(null);for(const r in e)if(r.startsWith("present")){const o=r.replace("present","past_key_values"),i=r.includes("encoder");if(s[o]=i&&t?t[o]:e[r],t&&(!i||n)){const e=t[o];"gpu-buffer"===e.location&&e.dispose()}}return s}getAttentions(e){const t={};for(const n of["cross_attentions","encoder_attentions","decoder_attentions"])for(const s in e)s.startsWith(n)&&(n in t||(t[n]=[]),t[n].push(e[s]));return t}addPastKeyValues(e,t){if(t)Object.assign(e,t);else{const t=this.custom_config.kv_cache_dtype??"float32",n="float16"===t?new Uint16Array:[],r=(0,s.getKeyValueShapes)(this.config);for(const s in r)e[s]=new u.Tensor(t,n,r[s])}}async encode_image({pixel_values:e}){const t=(await E(this.sessions.vision_encoder,{pixel_values:e})).image_features;return this.config.num_image_tokens||(console.warn(`The number of image tokens was not set in the model configuration. Setting it to the number of features detected by the vision encoder (${t.dims[1]}).`),this.config.num_image_tokens=t.dims[1]),t}async encode_text({input_ids:e}){return(await E(this.sessions.embed_tokens,{input_ids:e})).inputs_embeds}}class ${}class q extends ${constructor({last_hidden_state:e,hidden_states:t=null,attentions:n=null}){super(),this.last_hidden_state=e,this.hidden_states=t,this.attentions=n}}class U extends G{}class W extends U{}class X extends U{async _call(e){return new ml(await super._call(e))}}class Q extends U{async _call(e){return new pl(await super._call(e))}}class H extends U{async _call(e){return new _l(await super._call(e))}}class Y extends U{async _call(e){return new fl(await super._call(e))}}class J extends G{}class K extends J{}class Z extends G{}class ee extends Z{}class te extends Z{async _call(e){return new ml(await super._call(e))}}class ne extends Z{async _call(e){return new pl(await super._call(e))}}class se extends Z{async _call(e){return new _l(await super._call(e))}}class re extends Z{async _call(e){return new fl(await super._call(e))}}class oe extends G{}class ie extends oe{}class ae extends oe{async _call(e){return new ml(await super._call(e))}}class le extends oe{async _call(e){return new pl(await super._call(e))}}class ce extends oe{async _call(e){return new _l(await super._call(e))}}class de extends oe{async _call(e){return new fl(await super._call(e))}}class ue extends G{}class pe extends ue{}class he extends ue{async _call(e){return new ml(await super._call(e))}}class _e extends ue{async _call(e){return new pl(await super._call(e))}}class me extends ue{async _call(e){return new _l(await super._call(e))}}class fe extends ue{async _call(e){return new fl(await super._call(e))}}class ge extends G{}class we extends ge{}class Me extends ge{async _call(e){return new ml(await super._call(e))}}class be extends ge{async _call(e){return new pl(await super._call(e))}}class ye extends ge{async _call(e){return new _l(await super._call(e))}}class xe extends ge{async _call(e){return new fl(await super._call(e))}}class ke extends G{}class Te extends ke{}class ve extends ke{async _call(e){return new ml(await super._call(e))}}class Fe extends ke{async _call(e){return new pl(await super._call(e))}}class Ce extends ke{async _call(e){return new _l(await super._call(e))}}class Pe extends ke{async _call(e){return new fl(await super._call(e))}}class Se extends G{}class Ae extends Se{}class Ee extends Se{async _call(e){return new ml(await super._call(e))}}class Le extends Se{async _call(e){return new pl(await super._call(e))}}class ze extends Se{async _call(e){return new _l(await super._call(e))}}class Ie extends Se{async _call(e){return new fl(await super._call(e))}}class Be extends G{}class Ne extends Be{}class Oe extends Be{async _call(e){return new pl(await super._call(e))}}class je extends Be{async _call(e){return new _l(await super._call(e))}}class De extends Be{async _call(e){return new fl(await super._call(e))}}class Ve extends Be{async _call(e){return new ml(await super._call(e))}}class Re extends G{}class Ge extends Re{}class $e extends Re{async _call(e){return new ml(await super._call(e))}}class qe extends Re{async _call(e){return new pl(await super._call(e))}}class Ue extends Re{async _call(e){return new _l(await super._call(e))}}class We extends G{}class Xe extends We{}class Qe extends We{async _call(e){return new ml(await super._call(e))}}class He extends We{async _call(e){return new pl(await super._call(e))}}class Ye extends We{async _call(e){return new fl(await super._call(e))}}class Je extends G{}class Ke extends Je{}class Ze extends Je{async _call(e){return new ml(await super._call(e))}}class et extends Je{async _call(e){return new pl(await super._call(e))}}class tt extends Je{async _call(e){return new _l(await super._call(e))}}class nt extends Je{async _call(e){return new fl(await super._call(e))}}class st extends G{}class rt extends st{}class ot extends st{async _call(e){return new ml(await super._call(e))}}class it extends st{async _call(e){return new pl(await super._call(e))}}class at extends st{async _call(e){return new fl(await super._call(e))}}class lt extends G{}class ct extends lt{}class dt extends lt{async _call(e){return new pl(await super._call(e))}}class ut extends lt{async _call(e){return new fl(await super._call(e))}}class pt extends lt{async _call(e){return new ml(await super._call(e))}}class ht extends G{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"]}class _t extends ht{}class mt extends ht{}class ft extends G{}class gt extends ft{}class wt extends ft{}class Mt extends G{}class bt extends Mt{}class yt extends Mt{}class xt extends G{}class kt extends xt{}class Tt extends xt{}class vt extends xt{async _call(e){return new pl(await super._call(e))}}class Ft extends G{}class Ct extends Ft{}class Pt extends Ft{}class St extends Ft{async _call(e){return new pl(await super._call(e))}}class At extends Ft{}class Et extends G{}class Lt extends Et{}class zt extends Et{}class It extends G{}class Bt extends It{}class Nt extends It{}class Ot extends G{}class jt extends Ot{}class Dt extends Ot{async _call(e){return new ml(await super._call(e))}}class Vt extends Ot{async _call(e){return new pl(await super._call(e))}}class Rt extends Ot{async _call(e){return new _l(await super._call(e))}}class Gt extends Ot{async _call(e){return new fl(await super._call(e))}}class $t extends G{}class qt extends $t{}class Ut extends $t{async _call(e){return new ml(await super._call(e))}}class Wt extends $t{async _call(e){return new pl(await super._call(e))}}class Xt extends $t{async _call(e){return new _l(await super._call(e))}}class Qt extends $t{async _call(e){return new fl(await super._call(e))}}class Ht extends G{}class Yt extends Ht{}class Jt extends Ht{async _call(e){return new ml(await super._call(e))}}class Kt extends Ht{async _call(e){return new pl(await super._call(e))}}class Zt extends Ht{async _call(e){return new _l(await super._call(e))}}class en extends Ht{async _call(e){return new fl(await super._call(e))}}class tn extends G{}class nn extends tn{}class sn extends tn{}class rn extends G{requires_attention_mask=!1;main_input_name="input_features";forward_params=["input_features","attention_mask","decoder_input_ids","decoder_attention_mask","past_key_values"]}class on extends rn{}class an extends rn{_prepare_generation_config(e,t){return super._prepare_generation_config(e,t,f.WhisperGenerationConfig)}_retrieve_init_tokens(e){const t=[e.decoder_start_token_id];let n=e.language;const s=e.task;if(e.is_multilingual){n||(console.warn("No language specified - defaulting to English (en)."),n="en");const r=`<|${(0,g.whisper_language_to_code)(n)}|>`;t.push(e.lang_to_id[r]),t.push(e.task_to_id[s??"transcribe"])}else if(n||s)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&&(console.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),t.pop()),t.filter((e=>null!=e))}async generate({inputs:e=null,generation_config:t=null,logits_processor:n=null,stopping_criteria:s=null,...r}){t=this._prepare_generation_config(t,r);const o=r.decoder_input_ids??this._retrieve_init_tokens(t);if(t.return_timestamps&&(n??=new c.LogitsProcessorList,n.push(new c.WhisperTimeStampLogitsProcessor(t,o))),t.begin_suppress_tokens&&(n??=new c.LogitsProcessorList,n.push(new c.SuppressTokensAtBeginLogitsProcessor(t.begin_suppress_tokens,o.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.");"translate"===t.task&&console.warn("Token-level timestamps may not be reliable for task 'translate'."),t.output_attentions=!0,t.return_dict_in_generate=!0}const i=await super.generate({inputs:e,generation_config:t,logits_processor:n,decoder_input_ids:o,...r});return t.return_token_timestamps&&(i.token_timestamps=this._extract_token_timestamps(i,t.alignment_heads,t.num_frames)),i}_extract_token_timestamps(e,t,n=null,s=.02){if(!e.cross_attentions)throw new Error("Model outputs must contain cross attentions to extract timestamps. This is most likely because the model was not exported with `output_attentions=True`.");null==n&&console.warn("`num_frames` has not been set, meaning the entire audio will be analyzed. This may lead to inaccurate token-level timestamps for short audios (< 30 seconds).");let r=this.config.median_filter_width;void 0===r&&(console.warn("Model config has no `median_filter_width`, using default value of 7."),r=7);const o=e.cross_attentions,i=Array.from({length:this.config.decoder_layers},((e,t)=>(0,u.cat)(o.map((e=>e[t])),2))),l=(0,u.stack)(t.map((([e,t])=>{if(e>=i.length)throw new Error(`Layer index ${e} is out of bounds for cross attentions (length ${i.length}).`);return n?i[e].slice(null,t,null,[0,n]):i[e].slice(null,t)}))).transpose(1,0,2,3),[c,d]=(0,u.std_mean)(l,-2,0,!0),h=l.clone();for(let e=0;e<h.dims[0];++e){const t=h[e];for(let n=0;n<t.dims[0];++n){const s=t[n],o=c[e][n][0].data,i=d[e][n][0].data;for(let e=0;e<s.dims[0];++e){let t=s[e].data;for(let e=0;e<t.length;++e)t[e]=(t[e]-i[e])/o[e];t.set((0,p.medianFilter)(t,r))}}}const _=[(0,u.mean)(h,1)],m=e.sequences.dims,f=new u.Tensor("float32",new Float32Array(m[0]*m[1]),m);for(let e=0;e<m[0];++e){const t=_[e].neg().squeeze_(0),[n,r]=(0,p.dynamic_time_warping)(t.tolist()),o=Array.from({length:n.length-1},((e,t)=>n[t+1]-n[t])),i=(0,a.mergeArrays)([1],o).map((e=>!!e)),l=[];for(let e=0;e<i.length;++e)i[e]&&l.push(r[e]*s);f[e].data.set(l,1)}return f}}class ln extends G{main_input_name="pixel_values";forward_params=["pixel_values","input_ids","encoder_hidden_states","past_key_values"]}class cn extends G{forward_params=["input_ids","pixel_values","attention_mask","position_ids","past_key_values"]}class dn extends cn{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:t,input_ids:n,attention_mask:s}){const r=this.config.image_token_index,o=n.tolist().map((e=>e.findIndex((e=>e==r)))),i=o.every((e=>-1===e)),a=o.every((e=>-1!==e));if(!i&&!a)throw new Error("Every input should contain either 0 or 1 image token.");if(i)return{inputs_embeds:e,attention_mask:s};const l=[],c=[];for(let n=0;n<o.length;++n){const r=o[n],i=e[n],a=t[n],d=s[n];l.push((0,u.cat)([i.slice([0,r]),a,i.slice([r+1,i.dims[0]])],0)),c.push((0,u.cat)([d.slice([0,r]),(0,u.ones)([a.dims[0]]),d.slice([r+1,d.dims[0]])],0))}return{inputs_embeds:(0,u.stack)(l,0),attention_mask:(0,u.stack)(c,0)}}}class un extends dn{}class pn extends G{forward_params=["input_ids","inputs_embeds","attention_mask","pixel_values","encoder_outputs","decoder_input_ids","decoder_inputs_embeds","decoder_attention_mask","past_key_values"];main_input_name="inputs_embeds"}class hn extends pn{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:t,input_ids:n,attention_mask:s}){return{inputs_embeds:(0,u.cat)([t,e],1),attention_mask:(0,u.cat)([(0,u.ones)(t.dims.slice(0,2)),s],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:n,attention_mask:s}){if(!e&&!t)throw new Error("Either `input_ids` or `pixel_values` should be provided.");let r,o;return e&&(r=await this.encode_text({input_ids:e})),t&&(o=await this.encode_image({pixel_values:t})),r&&o?({inputs_embeds:n,attention_mask:s}=this._merge_input_ids_with_image_features({inputs_embeds:r,image_features:o,input_ids:e,attention_mask:s})):n=r||o,{inputs_embeds:n,attention_mask:s}}async forward({input_ids:e,pixel_values:t,attention_mask:n,decoder_input_ids:s,decoder_attention_mask:r,encoder_outputs:o,past_key_values:i,inputs_embeds:a,decoder_inputs_embeds:l}){if(a||({inputs_embeds:a,attention_mask:n}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:t,inputs_embeds:a,attention_mask:n})),!o){let{last_hidden_state:e}=await N(this,{inputs_embeds:a,attention_mask:n});o=e}if(!l){if(!s)throw new Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");l=await this.encode_text({input_ids:s})}const c={inputs_embeds:l,attention_mask:r,encoder_attention_mask:n,encoder_hidden_states:o,past_key_values:i};return await O(this,c,!0)}}class _n extends G{}class mn extends _n{}class fn extends _n{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class gn extends _n{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class wn extends _n{static async from_pretrained(e,t={}){return t.model_file_name??="vision_model",super.from_pretrained(e,t)}}class Mn extends _n{static async from_pretrained(e,t={}){return t.model_file_name??="vision_model",super.from_pretrained(e,t)}}class bn extends G{}class yn extends bn{}class xn extends bn{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class kn extends _n{static async from_pretrained(e,t={}){return t.model_file_name??="vision_model",super.from_pretrained(e,t)}}class Tn extends G{}class vn extends Tn{}class Fn extends G{}class Cn extends Fn{}class Pn extends Fn{}class Sn extends G{}class An extends Sn{}class En extends Sn{}class Ln extends G{}class zn extends Ln{}class In extends Ln{}class Bn extends G{}class Nn extends Bn{}class On extends Bn{}class jn extends G{}class Dn extends jn{}class Vn extends jn{}class Rn extends G{}class Gn extends Rn{}class $n extends Rn{}class qn extends G{}class Un extends qn{}class Wn extends qn{}class Xn extends G{}class Qn extends Xn{}class Hn extends Xn{}class Yn extends G{}class Jn extends Yn{}class Kn extends Yn{}class Zn extends G{}class es extends Zn{}class ts extends Zn{}class ns extends G{}class ss extends ns{}class rs extends ns{}class os extends G{}class is extends os{}class as extends os{}class ls extends G{}class cs extends ls{}class ds extends ls{}class us extends G{}class ps extends us{}class hs extends us{}class _s extends G{}class ms extends _s{}class fs extends _s{}class gs extends G{}class ws extends gs{}class Ms extends gs{}class bs extends G{}class ys extends bs{}class xs extends bs{}class ks extends G{}class Ts extends ks{}class vs extends ks{}class Fs extends G{}class Cs extends Fs{}class Ps extends Fs{}class Ss extends G{}class As extends Ss{}class Es extends Ss{}class Ls extends G{}class zs extends Ls{}class Is extends Ls{async _call(e){return new pl(await super._call(e))}}class Bs extends G{}class Ns extends Bs{}class Os extends Bs{async _call(e){return new pl(await super._call(e))}}class js extends G{}class Ds extends js{}class Vs extends G{}class Rs extends Vs{}class Gs extends Vs{async _call(e){return new pl(await super._call(e))}}class $s extends G{}class qs extends $s{}class Us extends G{}class Ws extends Us{}class Xs extends Us{async _call(e){return new pl(await super._call(e))}}class Qs extends G{}class Hs extends Qs{async _call(e){return new Ml(await super._call(e))}}class Ys extends G{}class Js extends Ys{}class Ks extends Ys{async _call(e){return new pl(await super._call(e))}}class Zs extends G{}class er extends Zs{}class tr extends Zs{async _call(e){return new pl(await super._call(e))}}class nr extends G{}class sr extends nr{}class rr extends nr{}class or extends G{}class ir extends or{}class ar extends or{}class lr extends G{}class cr extends lr{}class dr extends lr{async _call(e){return new pl(await super._call(e))}}class ur extends G{}class pr extends ur{}class hr extends ur{async _call(e){return new mr(await super._call(e))}}class _r extends ur{async _call(e){return new fr(await super._call(e))}}class mr extends ${constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class fr extends ${constructor({logits:e,pred_boxes:t,pred_masks:n}){super(),this.logits=e,this.pred_boxes=t,this.pred_masks=n}}class gr extends G{}class wr extends gr{}class Mr extends gr{async _call(e){return new br(await super._call(e))}}class br extends ${constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class yr extends G{}class xr extends yr{}class kr extends yr{async _call(e){return new Tr(await super._call(e))}}class Tr extends mr{}class vr extends G{}class Fr extends vr{}class Cr extends vr{async _call(e){return new pl(await super._call(e))}}class Pr extends G{}class Sr extends Pr{}class Ar extends Pr{async _call(e){return new pl(await super._call(e))}}class Er extends G{}class Lr extends Er{}class zr extends Er{async _call(e){return new pl(await super._call(e))}}class Ir extends G{}class Br extends Ir{}class Nr extends Ir{async _call(e){return new pl(await super._call(e))}}class Or extends G{}class jr extends Or{}class Dr extends Or{}class Vr extends G{}class Rr extends Vr{}class Gr extends Vr{}class $r extends G{}class qr extends $r{}class Ur extends G{}class Wr extends Ur{}class Xr extends Ur{}class Qr extends Ur{}class Hr extends G{}class Yr extends Hr{}class Jr extends G{}class Kr extends Jr{}class Zr extends Jr{}class eo extends G{}class to extends eo{}class no extends eo{}class so extends G{}class ro extends so{}class oo extends G{}class io extends oo{}class ao extends oo{async _call(e){return new pl(await super._call(e))}}class lo extends G{}class co extends lo{}class uo extends lo{async _call(e){return new pl(await super._call(e))}}class po extends G{}class ho extends po{}class _o extends po{async _call(e){return new pl(await super._call(e))}}class mo extends G{}class fo extends mo{}class go extends mo{async _call(e){return new wo(await super._call(e))}}class wo extends ${constructor({logits:e,pred_boxes:t}){super(),this.logits=e,this.pred_boxes=t}}class Mo extends G{}class bo extends Mo{async get_image_embeddings({pixel_values:e}){return await N(this,{pixel_values:e})}async forward(e){if(e.image_embeddings&&e.image_positional_embeddings||(e={...e,...await this.get_image_embeddings(e)}),!e.input_labels&&e.input_points){const t=e.input_points.dims.slice(0,-1),n=t.reduce(((e,t)=>e*t),1);e.input_labels=new u.Tensor("int64",new BigInt64Array(n).fill(1n),t)}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 E(this.sessions.prompt_encoder_mask_decoder,t)}async _call(e){return new yo(await super._call(e))}}class yo extends ${constructor({iou_scores:e,pred_masks:t}){super(),this.iou_scores=e,this.pred_masks=t}}class xo extends G{}class ko extends xo{}class To extends xo{}class vo extends G{}class Fo extends vo{}class Co extends vo{}class Po extends G{}class So extends Po{}class Ao extends Po{async _call(e){return new gl(await super._call(e))}}class Eo extends Po{async _call(e){return new pl(await super._call(e))}}class Lo extends Po{async _call(e){return new _l(await super._call(e))}}class zo extends G{}class Io extends zo{}class Bo extends zo{async _call(e){return new _l(await super._call(e))}}class No extends G{}class Oo extends No{}class jo extends G{}class Do extends jo{}class Vo extends jo{async _call(e){return new gl(await super._call(e))}}class Ro extends jo{async _call(e){return new pl(await super._call(e))}}class Go extends G{}class $o extends Go{}class qo extends Go{async _call(e){return new gl(await super._call(e))}}class Uo extends Go{async _call(e){return new pl(await super._call(e))}}class Wo extends Go{async _call(e){return new _l(await super._call(e))}}class Xo extends G{}class Qo extends Xo{}class Ho extends Xo{async _call(e){return new gl(await super._call(e))}}class Yo extends Xo{async _call(e){return new pl(await super._call(e))}}class Jo extends G{}class Ko extends Po{}class Zo extends Po{async _call(e){return new gl(await super._call(e))}}class ei extends Po{async _call(e){return new pl(await super._call(e))}}class ti extends G{}class ni extends ti{}class si extends ti{async _call(e){return new gl(await super._call(e))}}class ri extends ti{async _call(e){return new pl(await super._call(e))}}class oi extends ti{async _call(e){return new hl(await super._call(e))}}class ii extends ti{async _call(e){return new _l(await super._call(e))}}class ai extends G{}class li extends ai{}class ci extends ai{}class di extends ai{async generate_speech(e,t,{threshold:n=.5,minlenratio:s=0,maxlenratio:r=20,vocoder:o=null}={}){const i={input_ids:e},{encoder_outputs:a,encoder_attention_mask:l}=await N(this,i),c=a.dims[1]/this.config.reduction_factor,d=Math.floor(c*r),p=Math.floor(c*s),h=this.config.num_mel_bins;let _=[],m=null,f=null,g=0;for(;;){++g;const e=I(!!f);let s;s=f?f.output_sequence_out:new u.Tensor("float32",new Float32Array(h),[1,1,h]);let r={use_cache_branch:e,output_sequence:s,encoder_attention_mask:l,speaker_embeddings:t,encoder_hidden_states:a};this.addPastKeyValues(r,m),f=await E(this.sessions.decoder_model_merged,r),m=this.getPastKeyValues(f,m);const{prob:o,spectrum:i}=f;if(_.push(i),g>=p&&(Array.from(o.data).filter((e=>e>=n)).length>0||g>=d))break}const w=(0,u.cat)(_),{waveform:M}=await E(o.sessions.model,{spectrogram:w});return{spectrogram:w,waveform:M}}}class ui extends G{main_input_name="spectrogram"}class pi extends G{}class hi extends pi{}class _i extends G{}class mi extends _i{}class fi extends _i{}class gi extends G{}class wi extends gi{}class Mi extends gi{}class bi extends G{}class yi extends bi{}class xi extends bi{}class ki extends G{}class Ti extends ki{}class vi extends ki{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class Fi extends ki{static async from_pretrained(e,t={}){return t.model_file_name??="audio_model",super.from_pretrained(e,t)}}class Ci extends G{}class Pi extends Ci{async _call(e){return new bl(await super._call(e))}}class Si extends G{}class Ai extends Si{}class Ei extends Si{}class Li extends Si{}class zi extends G{}class Ii extends zi{}class Bi extends zi{}class Ni extends G{}class Oi extends Ni{}class ji extends Ni{async _call(e){return new pl(await super._call(e))}}class Di extends G{}class Vi extends Di{}class Ri extends Di{}class Gi extends G{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"];_apply_and_filter_by_delay_pattern_mask(e){const[t,n]=e.dims,s=this.config.decoder.num_codebooks,r=n-s;let o=0;for(let t=0;t<e.size;++t){if(e.data[t]===this.config.decoder.pad_token_id)continue;const i=t%n-Math.floor(t/n)%s;i>0&&i<=r&&(e.data[o++]=e.data[t])}const i=Math.floor(t/s),a=o/(i*s);return new u.Tensor(e.type,e.data.slice(0,o),[i,s,a])}prepare_inputs_for_generation(e,t,n){let s=structuredClone(e);for(let e=0;e<s.length;++e)for(let t=0;t<s[e].length;++t)e%this.config.decoder.num_codebooks>=t&&(s[e][t]=BigInt(this.config.decoder.pad_token_id));null!==n.guidance_scale&&n.guidance_scale>1&&(s=s.concat(s));return super.prepare_inputs_for_generation(s,t,n)}async generate(e){const t=await super.generate(e),n=this._apply_and_filter_by_delay_pattern_mask(t).unsqueeze_(0),{audio_values:s}=await E(this.sessions.encodec_decode,{audio_codes:n});return s}}class $i extends G{}class qi extends $i{}class Ui extends $i{async _call(e){return new pl(await super._call(e))}}class Wi extends G{}class Xi extends Wi{}class Qi extends Wi{async _call(e){return new pl(await super._call(e))}}class Hi extends G{}class Yi extends Hi{}class Ji extends Hi{async _call(e){return new pl(await super._call(e))}}class Ki extends G{}class Zi extends Ki{}class ea extends Ki{async _call(e){return new pl(await super._call(e))}}class ta extends G{}class na extends ta{}class sa{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:r=null,local_files_only:o=!1,revision:i="main",model_file_name:a=null,subfolder:l="onnx",device:c=null,dtype:d=null,use_external_data_format:u=null,session_options:p={}}={}){const h={progress_callback:t,config:n,cache_dir:r,local_files_only:o,revision:i,model_file_name:a,subfolder:l,device:c,dtype:d,use_external_data_format:u,session_options:p};if(h.config=await s.AutoConfig.from_pretrained(e,h),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);for(const t of this.MODEL_CLASS_MAPPINGS){const n=t.get(h.config.model_type);if(n)return await n[1].from_pretrained(e,h)}if(this.BASE_IF_FAIL)return console.warn(`Unknown model class "${h.config.model_type}", attempting to construct from base class.`),await G.from_pretrained(e,h);throw Error(`Unsupported model type: ${h.config.model_type}`)}}const ra=new Map([["bert",["BertModel",W]],["nomic_bert",["NomicBertModel",K]],["roformer",["RoFormerModel",ee]],["electra",["ElectraModel",pe]],["esm",["EsmModel",Ge]],["convbert",["ConvBertModel",ie]],["camembert",["CamembertModel",we]],["deberta",["DebertaModel",Te]],["deberta-v2",["DebertaV2Model",Ae]],["mpnet",["MPNetModel",Ke]],["albert",["AlbertModel",ct]],["distilbert",["DistilBertModel",Ne]],["roberta",["RobertaModel",jt]],["xlm",["XLMModel",qt]],["xlm-roberta",["XLMRobertaModel",Yt]],["clap",["ClapModel",Ti]],["clip",["CLIPModel",mn]],["clipseg",["CLIPSegModel",Cn]],["chinese_clip",["ChineseCLIPModel",vn]],["siglip",["SiglipModel",yn]],["mobilebert",["MobileBertModel",Xe]],["squeezebert",["SqueezeBertModel",rt]],["wav2vec2",["Wav2Vec2Model",So]],["wav2vec2-bert",["Wav2Vec2BertModel",Qo]],["unispeech",["UniSpeechModel",Do]],["unispeech-sat",["UniSpeechSatModel",$o]],["hubert",["HubertModel",Ko]],["wavlm",["WavLMModel",ni]],["audio-spectrogram-transformer",["ASTModel",nn]],["vits",["VitsModel",Pi]],["pyannote",["PyAnnoteModel",Io]],["wespeaker-resnet",["WeSpeakerResNetModel",Oo]],["detr",["DetrModel",pr]],["rt_detr",["RTDetrModel",wr]],["table-transformer",["TableTransformerModel",xr]],["vit",["ViTModel",zs]],["pvt",["PvtModel",Ns]],["vit_msn",["ViTMSNModel",Rs]],["vit_mae",["ViTMAEModel",Ds]],["groupvit",["GroupViTModel",qs]],["fastvit",["FastViTModel",Ws]],["mobilevit",["MobileViTModel",Js]],["mobilevitv2",["MobileViTV2Model",er]],["owlvit",["OwlViTModel",sr]],["owlv2",["Owlv2Model",ir]],["beit",["BeitModel",cr]],["deit",["DeiTModel",Fr]],["hiera",["HieraModel",Sr]],["convnext",["ConvNextModel",io]],["convnextv2",["ConvNextV2Model",co]],["dinov2",["Dinov2Model",ho]],["resnet",["ResNetModel",Lr]],["swin",["SwinModel",Br]],["swin2sr",["Swin2SRModel",jr]],["donut-swin",["DonutSwinModel",ro]],["yolos",["YolosModel",fo]],["dpt",["DPTModel",Rr]],["glpn",["GLPNModel",to]],["hifigan",["SpeechT5HifiGan",ui]],["efficientnet",["EfficientNetModel",Oi]],["decision_transformer",["DecisionTransformerModel",na]],["mobilenet_v1",["MobileNetV1Model",qi]],["mobilenet_v2",["MobileNetV2Model",Xi]],["mobilenet_v3",["MobileNetV3Model",Yi]],["mobilenet_v4",["MobileNetV4Model",Zi]],["maskformer",["MaskFormerModel",Kr]]]),oa=new Map([["t5",["T5Model",_t]],["longt5",["LongT5Model",gt]],["mt5",["MT5Model",bt]],["bart",["BartModel",kt]],["mbart",["MBartModel",Ct]],["marian",["MarianModel",ko]],["whisper",["WhisperModel",on]],["m2m_100",["M2M100Model",Fo]],["blenderbot",["BlenderbotModel",Lt]],["blenderbot-small",["BlenderbotSmallModel",Bt]]]),ia=new Map([["bloom",["BloomModel",Ts]],["jais",["JAISModel",zn]],["gpt2",["GPT2Model",An]],["gptj",["GPTJModel",Gn]],["gpt_bigcode",["GPTBigCodeModel",Un]],["gpt_neo",["GPTNeoModel",Nn]],["gpt_neox",["GPTNeoXModel",Dn]],["codegen",["CodeGenModel",Qn]],["llama",["LlamaModel",Jn]],["granite",["GraniteModel",es]],["cohere",["CohereModel",ss]],["gemma",["GemmaModel",is]],["gemma2",["Gemma2Model",cs]],["openelm",["OpenELMModel",ps]],["qwen2",["Qwen2Model",ms]],["phi",["PhiModel",ws]],["phi3",["Phi3Model",ys]],["mpt",["MptModel",Cs]],["opt",["OPTModel",As]],["mistral",["MistralModel",mi]],["starcoder2",["Starcoder2Model",wi]],["falcon",["FalconModel",yi]],["stablelm",["StableLmModel",Ii]]]),aa=new Map([["speecht5",["SpeechT5ForSpeechToText",ci]],["whisper",["WhisperForConditionalGeneration",an]]]),la=new Map([["speecht5",["SpeechT5ForTextToSpeech",di]]]),ca=new Map([["vits",["VitsModel",Pi]],["musicgen",["MusicgenForConditionalGeneration",Gi]]]),da=new Map([["bert",["BertForSequenceClassification",Q]],["roformer",["RoFormerForSequenceClassification",ne]],["electra",["ElectraForSequenceClassification",_e]],["esm",["EsmForSequenceClassification",qe]],["convbert",["ConvBertForSequenceClassification",le]],["camembert",["CamembertForSequenceClassification",be]],["deberta",["DebertaForSequenceClassification",Fe]],["deberta-v2",["DebertaV2ForSequenceClassification",Le]],["mpnet",["MPNetForSequenceClassification",et]],["albert",["AlbertForSequenceClassification",dt]],["distilbert",["DistilBertForSequenceClassification",Oe]],["roberta",["RobertaForSequenceClassification",Vt]],["xlm",["XLMForSequenceClassification",Wt]],["xlm-roberta",["XLMRobertaForSequenceClassification",Kt]],["bart",["BartForSequenceClassification",vt]],["mbart",["MBartForSequenceClassification",St]],["mobilebert",["MobileBertForSequenceClassification",He]],["squeezebert",["SqueezeBertForSequenceClassification",it]]]),ua=new Map([["bert",["BertForTokenClassification",H]],["roformer",["RoFormerForTokenClassification",se]],["electra",["ElectraForTokenClassification",me]],["esm",["EsmForTokenClassification",Ue]],["convbert",["ConvBertForTokenClassification",ce]],["camembert",["CamembertForTokenClassification",ye]],["deberta",["DebertaForTokenClassification",Ce]],["deberta-v2",["DebertaV2ForTokenClassification",ze]],["mpnet",["MPNetForTokenClassification",tt]],["distilbert",["DistilBertForTokenClassification",je]],["roberta",["RobertaForTokenClassification",Rt]],["xlm",["XLMForTokenClassification",Xt]],["xlm-roberta",["XLMRobertaForTokenClassification",Zt]]]),pa=new Map([["t5",["T5ForConditionalGeneration",mt]],["longt5",["LongT5ForConditionalGeneration",wt]],["mt5",["MT5ForConditionalGeneration",yt]],["bart",["BartForConditionalGeneration",Tt]],["mbart",["MBartForConditionalGeneration",Pt]],["marian",["MarianMTModel",To]],["m2m_100",["M2M100ForConditionalGeneration",Co]],["blenderbot",["BlenderbotForConditionalGeneration",zt]],["blenderbot-small",["BlenderbotSmallForConditionalGeneration",Nt]]]),ha=new Map([["bloom",["BloomForCausalLM",vs]],["gpt2",["GPT2LMHeadModel",En]],["jais",["JAISLMHeadModel",In]],["gptj",["GPTJForCausalLM",$n]],["gpt_bigcode",["GPTBigCodeForCausalLM",Wn]],["gpt_neo",["GPTNeoForCausalLM",On]],["gpt_neox",["GPTNeoXForCausalLM",Vn]],["codegen",["CodeGenForCausalLM",Hn]],["llama",["LlamaForCausalLM",Kn]],["granite",["GraniteForCausalLM",ts]],["cohere",["CohereForCausalLM",rs]],["gemma",["GemmaForCausalLM",as]],["gemma2",["Gemma2ForCausalLM",ds]],["openelm",["OpenELMForCausalLM",hs]],["qwen2",["Qwen2ForCausalLM",fs]],["phi",["PhiForCausalLM",Ms]],["phi3",["Phi3ForCausalLM",xs]],["mpt",["MptForCausalLM",Ps]],["opt",["OPTForCausalLM",Es]],["mbart",["MBartForCausalLM",At]],["mistral",["MistralForCausalLM",fi]],["starcoder2",["Starcoder2ForCausalLM",Mi]],["falcon",["FalconForCausalLM",xi]],["trocr",["TrOCRForCausalLM",hi]],["stablelm",["StableLmForCausalLM",Bi]]]),_a=new Map([["bert",["BertForMaskedLM",X]],["roformer",["RoFormerForMaskedLM",te]],["electra",["ElectraForMaskedLM",he]],["esm",["EsmForMaskedLM",$e]],["convbert",["ConvBertForMaskedLM",ae]],["camembert",["CamembertForMaskedLM",Me]],["deberta",["DebertaForMaskedLM",ve]],["deberta-v2",["DebertaV2ForMaskedLM",Ee]],["mpnet",["MPNetForMaskedLM",Ze]],["albert",["AlbertForMaskedLM",pt]],["distilbert",["DistilBertForMaskedLM",Ve]],["roberta",["RobertaForMaskedLM",Dt]],["xlm",["XLMWithLMHeadModel",Ut]],["xlm-roberta",["XLMRobertaForMaskedLM",Jt]],["mobilebert",["MobileBertForMaskedLM",Qe]],["squeezebert",["SqueezeBertForMaskedLM",ot]]]),ma=new Map([["bert",["BertForQuestionAnswering",Y]],["roformer",["RoFormerForQuestionAnswering",re]],["electra",["ElectraForQuestionAnswering",fe]],["convbert",["ConvBertForQuestionAnswering",de]],["camembert",["CamembertForQuestionAnswering",xe]],["deberta",["DebertaForQuestionAnswering",Pe]],["deberta-v2",["DebertaV2ForQuestionAnswering",Ie]],["mpnet",["MPNetForQuestionAnswering",nt]],["albert",["AlbertForQuestionAnswering",ut]],["distilbert",["DistilBertForQuestionAnswering",De]],["roberta",["RobertaForQuestionAnswering",Gt]],["xlm",["XLMForQuestionAnswering",Qt]],["xlm-roberta",["XLMRobertaForQuestionAnswering",en]],["mobilebert",["MobileBertForQuestionAnswering",Ye]],["squeezebert",["SqueezeBertForQuestionAnswering",at]]]),fa=new Map([["vision-encoder-decoder",["VisionEncoderDecoderModel",ln]]]),ga=new Map([["llava",["LlavaForConditionalGeneration",dn]],["moondream1",["Moondream1ForConditionalGeneration",un]],["florence2",["Florence2ForConditionalGeneration",hn]]]),wa=new Map([["vision-encoder-decoder",["VisionEncoderDecoderModel",ln]]]),Ma=new Map([["vit",["ViTForImageClassification",Is]],["pvt",["PvtForImageClassification",Os]],["vit_msn",["ViTMSNForImageClassification",Gs]],["fastvit",["FastViTForImageClassification",Xs]],["mobilevit",["MobileViTForImageClassification",Ks]],["mobilevitv2",["MobileViTV2ForImageClassification",tr]],["beit",["BeitForImageClassification",dr]],["deit",["DeiTForImageClassification",Cr]],["hiera",["HieraForImageClassification",Ar]],["convnext",["ConvNextForImageClassification",ao]],["convnextv2",["ConvNextV2ForImageClassification",uo]],["dinov2",["Dinov2ForImageClassification",_o]],["resnet",["ResNetForImageClassification",zr]],["swin",["SwinForImageClassification",Nr]],["segformer",["SegformerForImageClassification",Ei]],["efficientnet",["EfficientNetForImageClassification",ji]],["mobilenet_v1",["MobileNetV1ForImageClassification",Ui]],["mobilenet_v2",["MobileNetV2ForImageClassification",Qi]],["mobilenet_v3",["MobileNetV3ForImageClassification",Ji]],["mobilenet_v4",["MobileNetV4ForImageClassification",ea]]]),ba=new Map([["detr",["DetrForObjectDetection",hr]],["rt_detr",["RTDetrForObjectDetection",Mr]],["table-transformer",["TableTransformerForObjectDetection",kr]],["yolos",["YolosForObjectDetection",go]]]),ya=new Map([["owlvit",["OwlViTForObjectDetection",rr]],["owlv2",["Owlv2ForObjectDetection",ar]]]),xa=new Map([["detr",["DetrForSegmentation",_r]],["clipseg",["CLIPSegForImageSegmentation",Pn]]]),ka=new Map([["segformer",["SegformerForSemanticSegmentation",Li]],["sapiens",["SapiensForSemanticSegmentation",Wr]]]),Ta=new Map([["detr",["DetrForSegmentation",_r]],["maskformer",["MaskFormerForInstanceSegmentation",Zr]]]),va=new Map([["sam",["SamModel",bo]]]),Fa=new Map([["wav2vec2",["Wav2Vec2ForCTC",Ao]],["wav2vec2-bert",["Wav2Vec2BertForCTC",Ho]],["unispeech",["UniSpeechForCTC",Vo]],["unispeech-sat",["UniSpeechSatForCTC",qo]],["wavlm",["WavLMForCTC",si]],["hubert",["HubertForCTC",Zo]]]),Ca=new Map([["wav2vec2",["Wav2Vec2ForSequenceClassification",Eo]],["wav2vec2-bert",["Wav2Vec2BertForSequenceClassification",Yo]],["unispeech",["UniSpeechForSequenceClassification",Ro]],["unispeech-sat",["UniSpeechSatForSequenceClassification",Uo]],["wavlm",["WavLMForSequenceClassification",ri]],["hubert",["HubertForSequenceClassification",ei]],["audio-spectrogram-transformer",["ASTForAudioClassification",sn]]]),Pa=new Map([["wavlm",["WavLMForXVector",oi]]]),Sa=new Map([["unispeech-sat",["UniSpeechSatForAudioFrameClassification",Wo]],["wavlm",["WavLMForAudioFrameClassification",ii]],["wav2vec2",["Wav2Vec2ForAudioFrameClassification",Lo]],["pyannote",["PyAnnoteForAudioFrameClassification",Bo]]]),Aa=new Map([["vitmatte",["VitMatteForImageMatting",Hs]]]),Ea=new Map([["swin2sr",["Swin2SRForImageSuperResolution",Dr]]]),La=new Map([["dpt",["DPTForDepthEstimation",Gr]],["depth_anything",["DepthAnythingForDepthEstimation",qr]],["glpn",["GLPNForDepthEstimation",no]],["sapiens",["SapiensForDepthEstimation",Xr]],["depth_pro",["DepthProForDepthEstimation",Yr]]]),za=new Map([["sapiens",["SapiensForNormalEstimation",Qr]]]),Ia=new Map([["clip",["CLIPVisionModelWithProjection",Mn]],["siglip",["SiglipVisionModel",kn]]]),Ba=[[ra,w],[oa,M],[ia,x],[da,w],[ua,w],[pa,b],[aa,b],[ha,x],[_a,w],[ma,w],[fa,y],[ga,T],[Ma,w],[xa,w],[Ta,w],[ka,w],[Aa,w],[Ea,w],[La,w],[za,w],[ba,w],[ya,w],[va,k],[Fa,w],[Ca,w],[la,b],[ca,w],[Pa,w],[Sa,w],[Ia,w]];for(const[e,t]of Ba)for(const[n,s]of e.values())F.set(n,t),P.set(s,n),C.set(n,s);const Na=[["MusicgenForConditionalGeneration",Gi,v],["CLIPTextModelWithProjection",gn,w],["SiglipTextModel",xn,w],["ClapTextModelWithProjection",vi,w],["ClapAudioModelWithProjection",Fi,w]];for(const[e,t,n]of Na)F.set(e,n),P.set(t,e),C.set(e,t);class Oa extends sa{static MODEL_CLASS_MAPPINGS=Ba.map((e=>e[0]));static BASE_IF_FAIL=!0}class ja extends sa{static MODEL_CLASS_MAPPINGS=[da]}class Da extends sa{static MODEL_CLASS_MAPPINGS=[ua]}class Va extends sa{static MODEL_CLASS_MAPPINGS=[pa]}class Ra extends sa{static MODEL_CLASS_MAPPINGS=[aa]}class Ga extends sa{static MODEL_CLASS_MAPPINGS=[la]}class $a extends sa{static MODEL_CLASS_MAPPINGS=[ca]}class qa extends sa{static MODEL_CLASS_MAPPINGS=[ha]}class Ua extends sa{static MODEL_CLASS_MAPPINGS=[_a]}class Wa extends sa{static MODEL_CLASS_MAPPINGS=[ma]}class Xa extends sa{static MODEL_CLASS_MAPPINGS=[fa]}class Qa extends sa{static MODEL_CLASS_MAPPINGS=[Ma]}class Ha extends sa{static MODEL_CLASS_MAPPINGS=[xa]}class Ya extends sa{static MODEL_CLASS_MAPPINGS=[ka]}class Ja extends sa{static MODEL_CLASS_MAPPINGS=[Ta]}class Ka extends sa{static MODEL_CLASS_MAPPINGS=[ba]}class Za extends sa{static MODEL_CLASS_MAPPINGS=[ya]}class el extends sa{static MODEL_CLASS_MAPPINGS=[va]}class tl extends sa{static MODEL_CLASS_MAPPINGS=[Fa]}class nl extends sa{static MODEL_CLASS_MAPPINGS=[Ca]}class sl extends sa{static MODEL_CLASS_MAPPINGS=[Pa]}class rl extends sa{static MODEL_CLASS_MAPPINGS=[Sa]}class ol extends sa{static MODEL_CLASS_MAPPINGS=[wa]}class il extends sa{static MODEL_CLASS_MAPPINGS=[Aa]}class al extends sa{static MODEL_CLASS_MAPPINGS=[Ea]}class ll extends sa{static MODEL_CLASS_MAPPINGS=[La]}class cl extends sa{static MODEL_CLASS_MAPPINGS=[za]}class dl extends sa{static MODEL_CLASS_MAPPINGS=[Ia]}class ul extends ${constructor({logits:e,past_key_values:t,encoder_outputs:n,decoder_attentions:s=null,cross_attentions:r=null}){super(),this.logits=e,this.past_key_values=t,this.encoder_outputs=n,this.decoder_attentions=s,this.cross_attentions=r}}class pl extends ${constructor({logits:e}){super(),this.logits=e}}class hl extends ${constructor({logits:e,embeddings:t}){super(),this.logits=e,this.embeddings=t}}class _l extends ${constructor({logits:e}){super(),this.logits=e}}class ml extends ${constructor({logits:e}){super(),this.logits=e}}class fl extends ${constructor({start_logits:e,end_logits:t}){super(),this.start_logits=e,this.end_logits=t}}class gl extends ${constructor({logits:e}){super(),this.logits=e}}class wl extends ${constructor({logits:e,past_key_values:t}){super(),this.logits=e,this.past_key_values=t}}class Ml extends ${constructor({alphas:e}){super(),this.alphas=e}}class bl extends ${constructor({waveform:e,spectrogram:t}){super(),this.waveform=e,this.spectrogram=t}}},"./src/models/whisper/common_whisper.js":
|
|
113
113
|
/*!**********************************************!*\
|
|
114
114
|
!*** ./src/models/whisper/common_whisper.js ***!
|
|
115
115
|
\**********************************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{WHISPER_LANGUAGE_MAPPING:()=>r,WHISPER_TO_LANGUAGE_CODE_MAPPING:()=>o,whisper_language_to_code:()=>i});const s=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],r=new Map(s),o=new Map([...s.map((([e,t])=>[t,e])),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);function i(e){e=e.toLowerCase();let t=o.get(e);if(void 0===t){if(!r.has(e)){const t=2===e.length?r.keys():r.values();throw new Error(`Language "${e}" is not supported. Must be one of: ${JSON.stringify(t)}`)}t=e}return t}},"./src/models/whisper/generation_whisper.js":
|
|
@@ -121,16 +121,16 @@
|
|
|
121
121
|
\*****************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{TensorOpRegistry:()=>i});var s=n(/*! ../backends/onnx.js */"./src/backends/onnx.js"),r=n(/*! ../utils/tensor.js */"./src/utils/tensor.js");const o=async(e,t,n)=>{const o=await(0,s.createInferenceSession)(new Uint8Array(e),t);return async e=>{const t=Object.fromEntries(Object.entries(e).map((([e,t])=>[e,t.ort_tensor]))),s=await o.run(t);return Array.isArray(n)?n.map((e=>new r.Tensor(s[e]))):new r.Tensor(s[n])}};class i{static session_options={};static get bilinear_interpolate_4d(){return this._bilinear_interpolate_4d||(this._bilinear_interpolate_4d=o([8,9,18,0,58,128,1,10,40,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,17,10,4,109,111,100,101,34,6,108,105,110,101,97,114,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bilinear_interpolate_4d}static get bicubic_interpolate_4d(){return this._bicubic_interpolate_4d||(this._bicubic_interpolate_4d=o([8,9,18,0,58,127,10,39,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,16,10,4,109,111,100,101,34,5,99,117,98,105,99,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bicubic_interpolate_4d}static get matmul(){return this._matmul||(this._matmul=o([8,9,18,0,58,55,10,17,10,1,97,10,1,98,18,1,99,34,6,77,97,116,77,117,108,18,1,114,90,9,10,1,97,18,4,10,2,8,1,90,9,10,1,98,18,4,10,2,8,1,98,9,10,1,99,18,4,10,2,8,1,66,2,16,20],this.session_options,"c")),this._matmul}static get stft(){return this._stft||(this._stft=o([8,7,18,0,58,148,1,10,38,10,1,115,10,1,106,10,1,119,10,1,108,18,1,111,34,4,83,84,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,115,90,26,10,1,115,18,21,10,19,8,1,18,15,10,3,18,1,98,10,3,18,1,115,10,3,18,1,99,90,11,10,1,106,18,6,10,4,8,7,18,0,90,16,10,1,119,18,11,10,9,8,1,18,5,10,3,18,1,119,90,11,10,1,108,18,6,10,4,8,7,18,0,98,31,10,1,111,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,102,10,3,18,1,100,10,3,18,1,99,66,2,16,17],this.session_options,"o")),this._stft}static get rfft(){return this._rfft||(this._rfft=o([8,9,18,0,58,97,10,33,10,1,120,10,0,10,1,97,18,1,121,34,3,68,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,100,90,21,10,1,120,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,90,11,10,1,97,18,6,10,4,8,7,18,0,98,21,10,1,121,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,66,2,16,20],this.session_options,"y")),this._rfft}static get top_k(){return this._top_k||(this._top_k=o([8,10,18,0,58,73,10,18,10,1,120,10,1,107,18,1,118,18,1,105,34,4,84,111,112,75,18,1,116,90,9,10,1,120,18,4,10,2,8,1,90,15,10,1,107,18,10,10,8,8,7,18,4,10,2,8,1,98,9,10,1,118,18,4,10,2,8,1,98,9,10,1,105,18,4,10,2,8,7,66,2,16,21],this.session_options,["v","i"])),this._top_k}}},"./src/pipelines.js":
|
|
122
122
|
/*!**************************!*\
|
|
123
123
|
!*** ./src/pipelines.js ***!
|
|
124
|
-
\**************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{AudioClassificationPipeline:()=>P,AutomaticSpeechRecognitionPipeline:()=>A,DepthEstimationPipeline:()=>V,DocumentQuestionAnsweringPipeline:()=>O,FeatureExtractionPipeline:()=>F,FillMaskPipeline:()=>M,ImageClassificationPipeline:()=>z,ImageFeatureExtractionPipeline:()=>C,ImageSegmentationPipeline:()=>L,ImageToImagePipeline:()=>D,ImageToTextPipeline:()=>E,ObjectDetectionPipeline:()=>B,Pipeline:()=>m,QuestionAnsweringPipeline:()=>w,SummarizationPipeline:()=>y,Text2TextGenerationPipeline:()=>b,TextClassificationPipeline:()=>f,TextGenerationPipeline:()=>T,TextToAudioPipeline:()=>j,TokenClassificationPipeline:()=>g,TranslationPipeline:()=>x,ZeroShotAudioClassificationPipeline:()=>S,ZeroShotClassificationPipeline:()=>v,ZeroShotImageClassificationPipeline:()=>I,ZeroShotObjectDetectionPipeline:()=>N,pipeline:()=>$});var s=n(/*! ./tokenizers.js */"./src/tokenizers.js"),r=n(/*! ./models.js */"./src/models.js"),o=n(/*! ./processors.js */"./src/processors.js"),i=n(/*! ./utils/generic.js */"./src/utils/generic.js"),a=n(/*! ./utils/core.js */"./src/utils/core.js"),l=n(/*! ./utils/maths.js */"./src/utils/maths.js"),c=n(/*! ./utils/audio.js */"./src/utils/audio.js"),d=n(/*! ./utils/tensor.js */"./src/utils/tensor.js"),u=n(/*! ./utils/image.js */"./src/utils/image.js");async function p(e){return Array.isArray(e)||(e=[e]),await Promise.all(e.map((e=>u.RawImage.read(e))))}async function h(e,t){return Array.isArray(e)||(e=[e]),await Promise.all(e.map((e=>"string"==typeof e||e instanceof URL?(0,c.read_audio)(e,t):e instanceof Float64Array?new Float32Array(e):e)))}function _(e,t){t&&(e=e.map((e=>0|e)));const[n,s,r,o]=e;return{xmin:n,ymin:s,xmax:r,ymax:o}}class m extends i.Callable{constructor({task:e,model:t,tokenizer:n=null,processor:s=null}){super(),this.task=e,this.model=t,this.tokenizer=n,this.processor=s}async dispose(){await this.model.dispose()}}class f extends m{constructor(e){super(e)}async _call(e,{top_k:t=1}={}){const n=this.tokenizer(e,{padding:!0,truncation:!0}),s=await this.model(n),r="multi_label_classification"===this.model.config.problem_type?e=>e.sigmoid():e=>new d.Tensor("float32",(0,l.softmax)(e.data),e.dims),o=this.model.config.id2label,i=[];for(const e of s.logits){const n=r(e),s=await(0,d.topk)(n,t),a=s[0].tolist(),l=s[1].tolist().map(((e,t)=>({label:o?o[e]:`LABEL_${e}`,score:a[t]})));1===t?i.push(...l):i.push(l)}return Array.isArray(e)||1===t?i:i[0]}}class g extends m{constructor(e){super(e)}async _call(e,{ignore_labels:t=["O"]}={}){const n=Array.isArray(e),s=this.tokenizer(n?e:[e],{padding:!0,truncation:!0}),r=(await this.model(s)).logits,o=this.model.config.id2label,i=[];for(let e=0;e<r.dims[0];++e){const n=s.input_ids[e],a=r[e],c=[];for(let e=0;e<a.dims[0];++e){const s=a[e],r=(0,l.max)(s.data)[1],i=o?o[r]:`LABEL_${r}`;if(t.includes(i))continue;const d=this.tokenizer.decode([n[e].item()],{skip_special_tokens:!0});if(""===d)continue;const u=(0,l.softmax)(s.data);c.push({entity:i,score:u[r],index:e,word:d})}i.push(c)}return n?i:i[0]}}class w extends m{constructor(e){super(e)}async _call(e,t,{top_k:n=1}={}){const s=this.tokenizer(e,{text_pair:t,padding:!0,truncation:!0}),{start_logits:r,end_logits:o}=await this.model(s),i=s.input_ids.tolist(),c=s.attention_mask.tolist(),d=this.tokenizer.all_special_ids,u=[];for(let e=0;e<r.dims[0];++e){const t=i[e],s=t.findIndex((e=>e==this.tokenizer.sep_token_id)),p=(c[e].map(((e,n)=>1==e&&(0===n||n>s&&-1===d.findIndex((e=>e==t[n]))))),r[e].tolist()),h=o[e].tolist();for(let n=1;n<p.length;++n)(0==c[e]||n<=s||-1!==d.findIndex((e=>e==t[n])))&&(p[n]=-1/0,h[n]=-1/0);const _=(0,l.softmax)(p).map(((e,t)=>[e,t])),m=(0,l.softmax)(h).map(((e,t)=>[e,t]));_[0][0]=0,m[0][0]=0;const f=(0,a.product)(_,m).filter((e=>e[0][1]<=e[1][1])).map((e=>[e[0][1],e[1][1],e[0][0]*e[1][0]])).sort(((e,t)=>t[2]-e[2]));for(let e=0;e<Math.min(f.length,n);++e){const[n,s,r]=f[e],o=t.slice(n,s+1),i=this.tokenizer.decode(o,{skip_special_tokens:!0});u.push({answer:i,score:r})}}return 1===n?u[0]:u}}class M extends m{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){const n=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:s}=await this.model(n),r=[],o=n.input_ids.tolist();for(let e=0;e<o.length;++e){const n=o[e],i=n.findIndex((e=>e==this.tokenizer.mask_token_id));if(-1===i)throw Error(`Mask token (${this.tokenizer.mask_token}) not found in text.`);const a=s[e][i],c=await(0,d.topk)(new d.Tensor("float32",(0,l.softmax)(a.data),a.dims),t),u=c[0].tolist(),p=c[1].tolist();r.push(p.map(((e,t)=>{const s=n.slice();return s[i]=e,{score:u[t],token:Number(e),token_str:this.tokenizer.model.vocab[e],sequence:this.tokenizer.decode(s,{skip_special_tokens:!0})}})))}return Array.isArray(e)?r:r[0]}}class b extends m{_key="generated_text";constructor(e){super(e)}async _call(e,t={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map((e=>this.model.config.prefix+e)));const n=this.model.config.task_specific_params;n&&n[this.task]&&n[this.task].prefix&&(e=e.map((e=>n[this.task].prefix+e)));const s=this.tokenizer,r={padding:!0,truncation:!0};let o;o=this instanceof x&&"_build_translation_inputs"in s?s._build_translation_inputs(e,r,t):s(e,r);const i=await this.model.generate({...o,...t});return s.batch_decode(i,{skip_special_tokens:!0}).map((e=>({[this._key]:e})))}}class y extends b{_key="summary_text";constructor(e){super(e)}}class x extends b{_key="translation_text";constructor(e){super(e)}}function k(e){return Array.isArray(e)&&e.every((e=>"role"in e&&"content"in e))}class T extends m{constructor(e){super(e)}async _call(e,t={}){let n,s=!1,r=!1;if("string"==typeof e)n=e=[e];else if(Array.isArray(e)&&e.every((e=>"string"==typeof e)))s=!0,n=e;else{if(k(e))e=[e];else{if(!Array.isArray(e)||!e.every(k))throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");s=!0}r=!0,n=e.map((e=>this.tokenizer.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0})))}const o=t.add_special_tokens??!1,i=!r&&(t.return_full_text??!0);this.tokenizer.padding_side="left";const a=this.tokenizer(n,{add_special_tokens:o,padding:!0,truncation:!0}),l=await this.model.generate({...a,...t}),c=this.tokenizer.batch_decode(l,{skip_special_tokens:!0});let d;!i&&a.input_ids.dims.at(-1)>0&&(d=this.tokenizer.batch_decode(a.input_ids,{skip_special_tokens:!0}).map((e=>e.length)));const u=Array.from({length:e.length},(e=>[]));for(let t=0;t<c.length;++t){const n=Math.floor(t/l.dims[0]*e.length);d&&(c[t]=c[t].slice(d[n])),u[n].push({generated_text:r?[...e[n],{role:"assistant",content:c[t]}]:c[t]})}return s||1!==u.length?u:u[0]}}class v extends m{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map((([e,t])=>[e.toLowerCase(),t]))),this.entailment_id=this.label2id.entailment,void 0===this.entailment_id&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,void 0===this.contradiction_id&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,t,{hypothesis_template:n="This example is {}.",multi_label:s=!1}={}){const r=Array.isArray(e);r||(e=[e]),Array.isArray(t)||(t=[t]);const o=t.map((e=>n.replace("{}",e))),i=s||1===t.length,a=[];for(const n of e){const e=[];for(const t of o){const s=this.tokenizer(n,{text_pair:t,padding:!0,truncation:!0}),r=await this.model(s);i?e.push([r.logits.data[this.contradiction_id],r.logits.data[this.entailment_id]]):e.push(r.logits.data[this.entailment_id])}const s=(i?e.map((e=>(0,l.softmax)(e)[1])):(0,l.softmax)(e)).map(((e,t)=>[e,t])).sort(((e,t)=>t[0]-e[0]));a.push({sequence:n,labels:s.map((e=>t[e[1]])),scores:s.map((e=>e[0]))})}return r?a:a[0]}}class F extends m{constructor(e){super(e)}async _call(e,{pooling:t="none",normalize:n=!1,quantize:s=!1,precision:r="binary"}={}){const o=this.tokenizer(e,{padding:!0,truncation:!0}),i=await this.model(o);let a=i.last_hidden_state??i.logits??i.token_embeddings;if("none"===t);else if("mean"===t)a=(0,d.mean_pooling)(a,o.attention_mask);else{if("cls"!==t)throw Error(`Pooling method '${t}' not supported.`);a=a.slice(null,0)}return n&&(a=a.normalize(2,-1)),s&&(a=(0,d.quantize_embeddings)(a,r)),a}}class C extends m{constructor(e){super(e)}async _call(e,{pool:t=null}={}){const n=await p(e),{pixel_values:s}=await this.processor(n),r=await this.model({pixel_values:s});let o;if(t){if(!("pooler_output"in r))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");o=r.pooler_output}else o=r.last_hidden_state??r.logits??r.image_embeds;return o}}class P extends m{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){const n=this.processor.feature_extractor.config.sampling_rate,s=await h(e,n),r=this.model.config.id2label,o=[];for(const e of s){const n=await this.processor(e),s=(await this.model(n)).logits[0],i=await(0,d.topk)(new d.Tensor("float32",(0,l.softmax)(s.data),s.dims),t),a=i[0].tolist(),c=i[1].tolist().map(((e,t)=>({label:r?r[e]:`LABEL_${e}`,score:a[t]})));o.push(c)}return Array.isArray(e)?o:o[0]}}class S extends m{constructor(e){super(e)}async _call(e,t,{hypothesis_template:n="This is a sound of {}."}={}){const s=!Array.isArray(e);s&&(e=[e]);const r=t.map((e=>n.replace("{}",e))),o=this.tokenizer(r,{padding:!0,truncation:!0}),i=this.processor.feature_extractor.config.sampling_rate,a=await h(e,i),c=[];for(const e of a){const n=await this.processor(e),s=await this.model({...o,...n}),r=(0,l.softmax)(s.logits_per_audio.data);c.push([...r].map(((e,n)=>({score:e,label:t[n]}))))}return s?c[0]:c}}class A extends m{constructor(e){super(e)}async _call(e,t={}){switch(this.model.config.model_type){case"whisper":return this._call_whisper(e,t);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":return this._call_wav2vec2(e,t);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,t){t.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),t.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');const n=!Array.isArray(e);n&&(e=[e]);const s=this.processor.feature_extractor.config.sampling_rate,r=await h(e,s),o=[];for(const e of r){const t=await this.processor(e),n=(await this.model(t)).logits[0],s=[];for(const e of n)s.push((0,l.max)(e.data)[1]);const r=this.tokenizer.decode(s);o.push({text:r})}return n?o[0]:o}async _call_whisper(e,t){const n=t.return_timestamps??!1,s=t.chunk_length_s??0,r=t.force_full_sequences??!1;let o=t.stride_length_s??null;const i={...t};"word"===n&&(i.return_token_timestamps=!0,i.return_timestamps=!1);const a=!Array.isArray(e);a&&(e=[e]);const c=this.processor.feature_extractor.config.chunk_length/this.model.config.max_source_positions,d=this.processor.feature_extractor.config.hop_length,u=this.processor.feature_extractor.config.sampling_rate,p=await h(e,u),_=[];for(const e of p){let t=[];if(s>0){if(null===o)o=s/6;else if(s<=o)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");const n=u*s,r=u*o,i=n-2*r;let a=0;for(;;){const s=a+n,o=e.subarray(a,s),l=await this.processor(o),c=0===a,d=s>=e.length;if(t.push({stride:[o.length,c?0:r,d?0:r],input_features:l.input_features,is_last:d}),d)break;a+=i}}else t=[{stride:[e.length,0,0],input_features:(await this.processor(e)).input_features,is_last:!0}];for(const e of t){i.num_frames=Math.floor(e.stride[0]/d);const t=await this.model.generate({inputs:e.input_features,...i});"word"===n?(e.tokens=t.sequences.tolist()[0],e.token_timestamps=t.token_timestamps.tolist()[0].map((e=>(0,l.round)(e,2)))):e.tokens=t[0].tolist(),e.stride=e.stride.map((e=>e/u))}const[a,p]=this.tokenizer._decode_asr(t,{time_precision:c,return_timestamps:n,force_full_sequences:r});_.push({text:a,...p})}return a?_[0]:_}}class E extends m{constructor(e){super(e)}async _call(e,t={}){const n=Array.isArray(e),s=await p(e),{pixel_values:r}=await this.processor(s),o=[];for(const e of r){e.dims=[1,...e.dims];const n=await this.model.generate({inputs:e,...t}),s=this.tokenizer.batch_decode(n,{skip_special_tokens:!0}).map((e=>({generated_text:e.trim()})));o.push(s)}return n?o:o[0]}}class z extends m{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){const n=await p(e),{pixel_values:s}=await this.processor(n),r=await this.model({pixel_values:s}),o=this.model.config.id2label,i=[];for(const e of r.logits){const n=await(0,d.topk)(new d.Tensor("float32",(0,l.softmax)(e.data),e.dims),t),s=n[0].tolist(),r=n[1].tolist().map(((e,t)=>({label:o?o[e]:`LABEL_${e}`,score:s[t]})));i.push(r)}return Array.isArray(e)?i:i[0]}}class L extends m{constructor(e){super(e),this.subtasks_mapping={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"}}async _call(e,{threshold:t=.5,mask_threshold:n=.5,overlap_mask_area_threshold:s=.8,label_ids_to_fuse:r=null,target_sizes:o=null,subtask:i=null}={}){if(Array.isArray(e)&&1!==e.length)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");const a=await p(e),l=a.map((e=>[e.height,e.width])),{pixel_values:c,pixel_mask:d}=await this.processor(a),h=await this.model({pixel_values:c,pixel_mask:d});let _=null;if(null!==i)_=this.subtasks_mapping[i];else for(let[e,t]of Object.entries(this.subtasks_mapping))if(t in this.processor.feature_extractor){_=this.processor.feature_extractor[t].bind(this.processor.feature_extractor),i=e;break}const m=this.model.config.id2label,f=[];if("panoptic"===i||"instance"===i){const e=_(h,t,n,s,r,o??l)[0],i=e.segmentation;for(const t of e.segments_info){const e=new Uint8ClampedArray(i.data.length);for(let n=0;n<i.data.length;++n)i.data[n]===t.id&&(e[n]=255);const n=new u.RawImage(e,i.dims[1],i.dims[0],1);f.push({score:t.score,label:m[t.label_id],mask:n})}}else{if("semantic"!==i)throw Error(`Subtask ${i} not supported.`);{const{segmentation:e,labels:t}=_(h,o??l)[0];for(const n of t){const t=new Uint8ClampedArray(e.data.length);for(let s=0;s<e.data.length;++s)e.data[s]===n&&(t[s]=255);const s=new u.RawImage(t,e.dims[1],e.dims[0],1);f.push({score:null,label:m[n],mask:s})}}}return f}}class I extends m{constructor(e){super(e)}async _call(e,t,{hypothesis_template:n="This is a photo of {}"}={}){const s=Array.isArray(e),r=await p(e),o=t.map((e=>n.replace("{}",e))),i=this.tokenizer(o,{padding:"siglip"!==this.model.config.model_type||"max_length",truncation:!0}),{pixel_values:a}=await this.processor(r),c=await this.model({...i,pixel_values:a}),d="siglip"===this.model.config.model_type?e=>e.sigmoid().data:e=>(0,l.softmax)(e.data),u=[];for(const e of c.logits_per_image){const n=[...d(e)].map(((e,n)=>({score:e,label:t[n]})));n.sort(((e,t)=>t.score-e.score)),u.push(n)}return s?u:u[0]}}class B extends m{constructor(e){super(e)}async _call(e,{threshold:t=.9,percentage:n=!1}={}){const s=Array.isArray(e);if(s&&1!==e.length)throw Error("Object detection pipeline currently only supports a batch size of 1.");const r=await p(e),o=n?null:r.map((e=>[e.height,e.width])),{pixel_values:i,pixel_mask:a}=await this.processor(r),l=await this.model({pixel_values:i,pixel_mask:a}),c=this.processor.feature_extractor.post_process_object_detection(l,t,o),d=this.model.config.id2label,u=c.map((e=>e.boxes.map(((t,s)=>({score:e.scores[s],label:d[e.classes[s]],box:_(t,!n)})))));return s?u:u[0]}}class N extends m{constructor(e){super(e)}async _call(e,t,{threshold:n=.1,top_k:s=null,percentage:r=!1}={}){const o=Array.isArray(e),i=await p(e),a=this.tokenizer(t,{padding:!0,truncation:!0}),l=await this.processor(i),c=[];for(let e=0;e<i.length;++e){const o=i[e],d=r?null:[[o.height,o.width]],u=l.pixel_values[e].unsqueeze_(0),p=await this.model({...a,pixel_values:u}),h=this.processor.feature_extractor.post_process_object_detection(p,n,d,!0)[0];let m=h.boxes.map(((e,n)=>({score:h.scores[n],label:t[h.classes[n]],box:_(e,!r)}))).sort(((e,t)=>t.score-e.score));null!==s&&(m=m.slice(0,s)),c.push(m)}return o?c:c[0]}}class O extends m{constructor(e){super(e)}async _call(e,t,n={}){throw new Error("This pipeline is not yet supported in Transformers.js v3.")}}class j extends m{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(e){super(e),this.vocoder=e.vocoder??null}async _call(e,{speaker_embeddings:t=null}={}){return this.processor?this._call_text_to_spectrogram(e,{speaker_embeddings:t}):this._call_text_to_waveform(e)}async _call_text_to_waveform(e){const t=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:n}=await this.model(t),s=this.model.config.sampling_rate;return{audio:n.data,sampling_rate:s}}async _call_text_to_spectrogram(e,{speaker_embeddings:t}){if(this.vocoder||(console.log("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await r.AutoModel.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"})),("string"==typeof t||t instanceof URL)&&(t=new Float32Array(await(await fetch(t)).arrayBuffer())),t instanceof Float32Array)t=new d.Tensor("float32",t,[1,t.length]);else if(!(t instanceof d.Tensor))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");const{input_ids:n}=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:s}=await this.model.generate_speech(n,t,{vocoder:this.vocoder}),o=this.processor.feature_extractor.config.sampling_rate;return{audio:s.data,sampling_rate:o}}}class D extends m{constructor(e){super(e)}async _call(e){const t=await p(e),n=await this.processor(t),s=await this.model(n),r=[];for(const e of s.reconstruction){const t=e.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");r.push(u.RawImage.fromTensor(t))}return r.length>1?r:r[0]}}class V extends m{constructor(e){super(e)}async _call(e){const t=await p(e),n=await this.processor(t),{predicted_depth:s}=await this.model(n),r=[];for(let e=0;e<t.length;++e){const n=(0,d.interpolate)(s[e],t[e].size.reverse(),"bilinear",!1),o=n.mul_(255/(0,l.max)(n.data)[0]).to("uint8");r.push({predicted_depth:s[e],depth:u.RawImage.fromTensor(o)})}return r.length>1?r:r[0]}}const R=Object.freeze({"text-classification":{tokenizer:s.AutoTokenizer,pipeline:f,model:r.AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:s.AutoTokenizer,pipeline:g,model:r.AutoModelForTokenClassification,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:s.AutoTokenizer,pipeline:w,model:r.AutoModelForQuestionAnswering,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:s.AutoTokenizer,pipeline:M,model:r.AutoModelForMaskedLM,default:{model:"Xenova/bert-base-uncased"},type:"text"},summarization:{tokenizer:s.AutoTokenizer,pipeline:y,model:r.AutoModelForSeq2SeqLM,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:s.AutoTokenizer,pipeline:x,model:r.AutoModelForSeq2SeqLM,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:s.AutoTokenizer,pipeline:b,model:r.AutoModelForSeq2SeqLM,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:s.AutoTokenizer,pipeline:T,model:r.AutoModelForCausalLM,default:{model:"Xenova/gpt2"},type:"text"},"zero-shot-classification":{tokenizer:s.AutoTokenizer,pipeline:v,model:r.AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:P,model:r.AutoModelForAudioClassification,processor:o.AutoProcessor,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:s.AutoTokenizer,pipeline:S,model:r.AutoModel,processor:o.AutoProcessor,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:s.AutoTokenizer,pipeline:A,model:[r.AutoModelForSpeechSeq2Seq,r.AutoModelForCTC],processor:o.AutoProcessor,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:s.AutoTokenizer,pipeline:j,model:[r.AutoModelForTextToWaveform,r.AutoModelForTextToSpectrogram],processor:[o.AutoProcessor,null],default:{model:"Xenova/speecht5_tts"},type:"text"},"image-to-text":{tokenizer:s.AutoTokenizer,pipeline:E,model:r.AutoModelForVision2Seq,processor:o.AutoProcessor,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:z,model:r.AutoModelForImageClassification,processor:o.AutoProcessor,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:L,model:[r.AutoModelForImageSegmentation,r.AutoModelForSemanticSegmentation,r.AutoModelForUniversalSegmentation],processor:o.AutoProcessor,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"zero-shot-image-classification":{tokenizer:s.AutoTokenizer,pipeline:I,model:r.AutoModel,processor:o.AutoProcessor,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:B,model:r.AutoModelForObjectDetection,processor:o.AutoProcessor,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:s.AutoTokenizer,pipeline:N,model:r.AutoModelForZeroShotObjectDetection,processor:o.AutoProcessor,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:s.AutoTokenizer,pipeline:O,model:r.AutoModelForDocumentQuestionAnswering,processor:o.AutoProcessor,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:D,model:r.AutoModelForImageToImage,processor:o.AutoProcessor,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:V,model:r.AutoModelForDepthEstimation,processor:o.AutoProcessor,default:{model:"Xenova/dpt-large"},type:"image"},"feature-extraction":{tokenizer:s.AutoTokenizer,pipeline:F,model:r.AutoModel,default:{model:"Xenova/all-MiniLM-L6-v2"},type:"text"},"image-feature-extraction":{processor:o.AutoProcessor,pipeline:C,model:[r.AutoModelForImageFeatureExtraction,r.AutoModel],default:{model:"Xenova/vit-base-patch16-224-in21k"},type:"image"}}),G=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function $(e,t=null,{progress_callback:n=null,config:s=null,cache_dir:r=null,local_files_only:o=!1,revision:i="main",device:l=null,dtype:c=null,model_file_name:d=null,session_options:u={}}={}){e=G[e]??e;const p=R[e.split("_",1)[0]];if(!p)throw Error(`Unsupported pipeline: ${e}. Must be one of [${Object.keys(R)}]`);t||(t=p.default.model,console.log(`No model specified. Using default model: "${t}".`));const h={progress_callback:n,config:s,cache_dir:r,local_files_only:o,revision:i,device:l,dtype:c,model_file_name:d,session_options:u},_=new Map([["tokenizer",p.tokenizer],["model",p.model],["processor",p.processor]]),m=await async function(e,t,n){const s=Object.create(null),r=[];for(const[o,i]of e.entries()){if(!i)continue;let e;e=Array.isArray(i)?new Promise((async(e,s)=>{let r;for(const o of i){if(null===o)return void e(null);try{return void e(await o.from_pretrained(t,n))}catch(e){if(e.message?.includes("Unsupported model type"))r=e;else{if(!e.message?.includes("Could not locate file"))return void s(e);r=e}}}s(r)})):i.from_pretrained(t,n),s[o]=e,r.push(e)}await Promise.all(r);for(const[e,t]of Object.entries(s))s[e]=await t;return s}(_,t,h);m.task=e,(0,a.dispatchCallback)(n,{status:"ready",task:e,model:t});return new(0,p.pipeline)(m)}},"./src/processors.js":
|
|
124
|
+
\**************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{AudioClassificationPipeline:()=>P,AutomaticSpeechRecognitionPipeline:()=>A,DepthEstimationPipeline:()=>V,DocumentQuestionAnsweringPipeline:()=>O,FeatureExtractionPipeline:()=>F,FillMaskPipeline:()=>M,ImageClassificationPipeline:()=>L,ImageFeatureExtractionPipeline:()=>C,ImageSegmentationPipeline:()=>z,ImageToImagePipeline:()=>D,ImageToTextPipeline:()=>E,ObjectDetectionPipeline:()=>B,Pipeline:()=>m,QuestionAnsweringPipeline:()=>w,SummarizationPipeline:()=>y,Text2TextGenerationPipeline:()=>b,TextClassificationPipeline:()=>f,TextGenerationPipeline:()=>T,TextToAudioPipeline:()=>j,TokenClassificationPipeline:()=>g,TranslationPipeline:()=>x,ZeroShotAudioClassificationPipeline:()=>S,ZeroShotClassificationPipeline:()=>v,ZeroShotImageClassificationPipeline:()=>I,ZeroShotObjectDetectionPipeline:()=>N,pipeline:()=>$});var s=n(/*! ./tokenizers.js */"./src/tokenizers.js"),r=n(/*! ./models.js */"./src/models.js"),o=n(/*! ./processors.js */"./src/processors.js"),i=n(/*! ./utils/generic.js */"./src/utils/generic.js"),a=n(/*! ./utils/core.js */"./src/utils/core.js"),l=n(/*! ./utils/maths.js */"./src/utils/maths.js"),c=n(/*! ./utils/audio.js */"./src/utils/audio.js"),d=n(/*! ./utils/tensor.js */"./src/utils/tensor.js"),u=n(/*! ./utils/image.js */"./src/utils/image.js");async function p(e){return Array.isArray(e)||(e=[e]),await Promise.all(e.map((e=>u.RawImage.read(e))))}async function h(e,t){return Array.isArray(e)||(e=[e]),await Promise.all(e.map((e=>"string"==typeof e||e instanceof URL?(0,c.read_audio)(e,t):e instanceof Float64Array?new Float32Array(e):e)))}function _(e,t){t&&(e=e.map((e=>0|e)));const[n,s,r,o]=e;return{xmin:n,ymin:s,xmax:r,ymax:o}}class m extends i.Callable{constructor({task:e,model:t,tokenizer:n=null,processor:s=null}){super(),this.task=e,this.model=t,this.tokenizer=n,this.processor=s}async dispose(){await this.model.dispose()}}class f extends m{constructor(e){super(e)}async _call(e,{top_k:t=1}={}){const n=this.tokenizer(e,{padding:!0,truncation:!0}),s=await this.model(n),r="multi_label_classification"===this.model.config.problem_type?e=>e.sigmoid():e=>new d.Tensor("float32",(0,l.softmax)(e.data),e.dims),o=this.model.config.id2label,i=[];for(const e of s.logits){const n=r(e),s=await(0,d.topk)(n,t),a=s[0].tolist(),l=s[1].tolist().map(((e,t)=>({label:o?o[e]:`LABEL_${e}`,score:a[t]})));1===t?i.push(...l):i.push(l)}return Array.isArray(e)||1===t?i:i[0]}}class g extends m{constructor(e){super(e)}async _call(e,{ignore_labels:t=["O"]}={}){const n=Array.isArray(e),s=this.tokenizer(n?e:[e],{padding:!0,truncation:!0}),r=(await this.model(s)).logits,o=this.model.config.id2label,i=[];for(let e=0;e<r.dims[0];++e){const n=s.input_ids[e],a=r[e],c=[];for(let e=0;e<a.dims[0];++e){const s=a[e],r=(0,l.max)(s.data)[1],i=o?o[r]:`LABEL_${r}`;if(t.includes(i))continue;const d=this.tokenizer.decode([n[e].item()],{skip_special_tokens:!0});if(""===d)continue;const u=(0,l.softmax)(s.data);c.push({entity:i,score:u[r],index:e,word:d})}i.push(c)}return n?i:i[0]}}class w extends m{constructor(e){super(e)}async _call(e,t,{top_k:n=1}={}){const s=this.tokenizer(e,{text_pair:t,padding:!0,truncation:!0}),{start_logits:r,end_logits:o}=await this.model(s),i=s.input_ids.tolist(),c=s.attention_mask.tolist(),d=this.tokenizer.all_special_ids,u=[];for(let e=0;e<r.dims[0];++e){const t=i[e],s=t.findIndex((e=>e==this.tokenizer.sep_token_id)),p=(c[e].map(((e,n)=>1==e&&(0===n||n>s&&-1===d.findIndex((e=>e==t[n]))))),r[e].tolist()),h=o[e].tolist();for(let n=1;n<p.length;++n)(0==c[e]||n<=s||-1!==d.findIndex((e=>e==t[n])))&&(p[n]=-1/0,h[n]=-1/0);const _=(0,l.softmax)(p).map(((e,t)=>[e,t])),m=(0,l.softmax)(h).map(((e,t)=>[e,t]));_[0][0]=0,m[0][0]=0;const f=(0,a.product)(_,m).filter((e=>e[0][1]<=e[1][1])).map((e=>[e[0][1],e[1][1],e[0][0]*e[1][0]])).sort(((e,t)=>t[2]-e[2]));for(let e=0;e<Math.min(f.length,n);++e){const[n,s,r]=f[e],o=t.slice(n,s+1),i=this.tokenizer.decode(o,{skip_special_tokens:!0});u.push({answer:i,score:r})}}return 1===n?u[0]:u}}class M extends m{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){const n=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:s}=await this.model(n),r=[],o=n.input_ids.tolist();for(let e=0;e<o.length;++e){const n=o[e],i=n.findIndex((e=>e==this.tokenizer.mask_token_id));if(-1===i)throw Error(`Mask token (${this.tokenizer.mask_token}) not found in text.`);const a=s[e][i],c=await(0,d.topk)(new d.Tensor("float32",(0,l.softmax)(a.data),a.dims),t),u=c[0].tolist(),p=c[1].tolist();r.push(p.map(((e,t)=>{const s=n.slice();return s[i]=e,{score:u[t],token:Number(e),token_str:this.tokenizer.model.vocab[e],sequence:this.tokenizer.decode(s,{skip_special_tokens:!0})}})))}return Array.isArray(e)?r:r[0]}}class b extends m{_key="generated_text";constructor(e){super(e)}async _call(e,t={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map((e=>this.model.config.prefix+e)));const n=this.model.config.task_specific_params;n&&n[this.task]&&n[this.task].prefix&&(e=e.map((e=>n[this.task].prefix+e)));const s=this.tokenizer,r={padding:!0,truncation:!0};let o;o=this instanceof x&&"_build_translation_inputs"in s?s._build_translation_inputs(e,r,t):s(e,r);const i=await this.model.generate({...o,...t});return s.batch_decode(i,{skip_special_tokens:!0}).map((e=>({[this._key]:e})))}}class y extends b{_key="summary_text";constructor(e){super(e)}}class x extends b{_key="translation_text";constructor(e){super(e)}}function k(e){return Array.isArray(e)&&e.every((e=>"role"in e&&"content"in e))}class T extends m{constructor(e){super(e)}async _call(e,t={}){let n,s=!1,r=!1;if("string"==typeof e)n=e=[e];else if(Array.isArray(e)&&e.every((e=>"string"==typeof e)))s=!0,n=e;else{if(k(e))e=[e];else{if(!Array.isArray(e)||!e.every(k))throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");s=!0}r=!0,n=e.map((e=>this.tokenizer.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0})))}const o=t.add_special_tokens??!1,i=!r&&(t.return_full_text??!0);this.tokenizer.padding_side="left";const a=this.tokenizer(n,{add_special_tokens:o,padding:!0,truncation:!0}),l=await this.model.generate({...a,...t}),c=this.tokenizer.batch_decode(l,{skip_special_tokens:!0});let d;!i&&a.input_ids.dims.at(-1)>0&&(d=this.tokenizer.batch_decode(a.input_ids,{skip_special_tokens:!0}).map((e=>e.length)));const u=Array.from({length:e.length},(e=>[]));for(let t=0;t<c.length;++t){const n=Math.floor(t/l.dims[0]*e.length);d&&(c[t]=c[t].slice(d[n])),u[n].push({generated_text:r?[...e[n],{role:"assistant",content:c[t]}]:c[t]})}return s||1!==u.length?u:u[0]}}class v extends m{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map((([e,t])=>[e.toLowerCase(),t]))),this.entailment_id=this.label2id.entailment,void 0===this.entailment_id&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,void 0===this.contradiction_id&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,t,{hypothesis_template:n="This example is {}.",multi_label:s=!1}={}){const r=Array.isArray(e);r||(e=[e]),Array.isArray(t)||(t=[t]);const o=t.map((e=>n.replace("{}",e))),i=s||1===t.length,a=[];for(const n of e){const e=[];for(const t of o){const s=this.tokenizer(n,{text_pair:t,padding:!0,truncation:!0}),r=await this.model(s);i?e.push([r.logits.data[this.contradiction_id],r.logits.data[this.entailment_id]]):e.push(r.logits.data[this.entailment_id])}const s=(i?e.map((e=>(0,l.softmax)(e)[1])):(0,l.softmax)(e)).map(((e,t)=>[e,t])).sort(((e,t)=>t[0]-e[0]));a.push({sequence:n,labels:s.map((e=>t[e[1]])),scores:s.map((e=>e[0]))})}return r?a:a[0]}}class F extends m{constructor(e){super(e)}async _call(e,{pooling:t="none",normalize:n=!1,quantize:s=!1,precision:r="binary"}={}){const o=this.tokenizer(e,{padding:!0,truncation:!0}),i=await this.model(o);let a=i.last_hidden_state??i.logits??i.token_embeddings;if("none"===t);else if("mean"===t)a=(0,d.mean_pooling)(a,o.attention_mask);else{if("cls"!==t)throw Error(`Pooling method '${t}' not supported.`);a=a.slice(null,0)}return n&&(a=a.normalize(2,-1)),s&&(a=(0,d.quantize_embeddings)(a,r)),a}}class C extends m{constructor(e){super(e)}async _call(e,{pool:t=null}={}){const n=await p(e),{pixel_values:s}=await this.processor(n),r=await this.model({pixel_values:s});let o;if(t){if(!("pooler_output"in r))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");o=r.pooler_output}else o=r.last_hidden_state??r.logits??r.image_embeds;return o}}class P extends m{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){const n=this.processor.feature_extractor.config.sampling_rate,s=await h(e,n),r=this.model.config.id2label,o=[];for(const e of s){const n=await this.processor(e),s=(await this.model(n)).logits[0],i=await(0,d.topk)(new d.Tensor("float32",(0,l.softmax)(s.data),s.dims),t),a=i[0].tolist(),c=i[1].tolist().map(((e,t)=>({label:r?r[e]:`LABEL_${e}`,score:a[t]})));o.push(c)}return Array.isArray(e)?o:o[0]}}class S extends m{constructor(e){super(e)}async _call(e,t,{hypothesis_template:n="This is a sound of {}."}={}){const s=!Array.isArray(e);s&&(e=[e]);const r=t.map((e=>n.replace("{}",e))),o=this.tokenizer(r,{padding:!0,truncation:!0}),i=this.processor.feature_extractor.config.sampling_rate,a=await h(e,i),c=[];for(const e of a){const n=await this.processor(e),s=await this.model({...o,...n}),r=(0,l.softmax)(s.logits_per_audio.data);c.push([...r].map(((e,n)=>({score:e,label:t[n]}))))}return s?c[0]:c}}class A extends m{constructor(e){super(e)}async _call(e,t={}){switch(this.model.config.model_type){case"whisper":return this._call_whisper(e,t);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":return this._call_wav2vec2(e,t);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,t){t.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),t.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');const n=!Array.isArray(e);n&&(e=[e]);const s=this.processor.feature_extractor.config.sampling_rate,r=await h(e,s),o=[];for(const e of r){const t=await this.processor(e),n=(await this.model(t)).logits[0],s=[];for(const e of n)s.push((0,l.max)(e.data)[1]);const r=this.tokenizer.decode(s);o.push({text:r})}return n?o[0]:o}async _call_whisper(e,t){const n=t.return_timestamps??!1,s=t.chunk_length_s??0,r=t.force_full_sequences??!1;let o=t.stride_length_s??null;const i={...t};"word"===n&&(i.return_token_timestamps=!0,i.return_timestamps=!1);const a=!Array.isArray(e);a&&(e=[e]);const c=this.processor.feature_extractor.config.chunk_length/this.model.config.max_source_positions,d=this.processor.feature_extractor.config.hop_length,u=this.processor.feature_extractor.config.sampling_rate,p=await h(e,u),_=[];for(const e of p){let t=[];if(s>0){if(null===o)o=s/6;else if(s<=o)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");const n=u*s,r=u*o,i=n-2*r;let a=0;for(;;){const s=a+n,o=e.subarray(a,s),l=await this.processor(o),c=0===a,d=s>=e.length;if(t.push({stride:[o.length,c?0:r,d?0:r],input_features:l.input_features,is_last:d}),d)break;a+=i}}else t=[{stride:[e.length,0,0],input_features:(await this.processor(e)).input_features,is_last:!0}];for(const e of t){i.num_frames=Math.floor(e.stride[0]/d);const t=await this.model.generate({inputs:e.input_features,...i});"word"===n?(e.tokens=t.sequences.tolist()[0],e.token_timestamps=t.token_timestamps.tolist()[0].map((e=>(0,l.round)(e,2)))):e.tokens=t[0].tolist(),e.stride=e.stride.map((e=>e/u))}const[a,p]=this.tokenizer._decode_asr(t,{time_precision:c,return_timestamps:n,force_full_sequences:r});_.push({text:a,...p})}return a?_[0]:_}}class E extends m{constructor(e){super(e)}async _call(e,t={}){const n=Array.isArray(e),s=await p(e),{pixel_values:r}=await this.processor(s),o=[];for(const e of r){e.dims=[1,...e.dims];const n=await this.model.generate({inputs:e,...t}),s=this.tokenizer.batch_decode(n,{skip_special_tokens:!0}).map((e=>({generated_text:e.trim()})));o.push(s)}return n?o:o[0]}}class L extends m{constructor(e){super(e)}async _call(e,{top_k:t=5}={}){const n=await p(e),{pixel_values:s}=await this.processor(n),r=await this.model({pixel_values:s}),o=this.model.config.id2label,i=[];for(const e of r.logits){const n=await(0,d.topk)(new d.Tensor("float32",(0,l.softmax)(e.data),e.dims),t),s=n[0].tolist(),r=n[1].tolist().map(((e,t)=>({label:o?o[e]:`LABEL_${e}`,score:s[t]})));i.push(r)}return Array.isArray(e)?i:i[0]}}class z extends m{constructor(e){super(e),this.subtasks_mapping={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"}}async _call(e,{threshold:t=.5,mask_threshold:n=.5,overlap_mask_area_threshold:s=.8,label_ids_to_fuse:r=null,target_sizes:o=null,subtask:i=null}={}){if(Array.isArray(e)&&1!==e.length)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");const a=await p(e),l=a.map((e=>[e.height,e.width])),{pixel_values:c,pixel_mask:d}=await this.processor(a),h=await this.model({pixel_values:c,pixel_mask:d});let _=null;if(null!==i)_=this.subtasks_mapping[i];else for(let[e,t]of Object.entries(this.subtasks_mapping))if(t in this.processor.feature_extractor){_=this.processor.feature_extractor[t].bind(this.processor.feature_extractor),i=e;break}const m=this.model.config.id2label,f=[];if("panoptic"===i||"instance"===i){const e=_(h,t,n,s,r,o??l)[0],i=e.segmentation;for(const t of e.segments_info){const e=new Uint8ClampedArray(i.data.length);for(let n=0;n<i.data.length;++n)i.data[n]===t.id&&(e[n]=255);const n=new u.RawImage(e,i.dims[1],i.dims[0],1);f.push({score:t.score,label:m[t.label_id],mask:n})}}else{if("semantic"!==i)throw Error(`Subtask ${i} not supported.`);{const{segmentation:e,labels:t}=_(h,o??l)[0];for(const n of t){const t=new Uint8ClampedArray(e.data.length);for(let s=0;s<e.data.length;++s)e.data[s]===n&&(t[s]=255);const s=new u.RawImage(t,e.dims[1],e.dims[0],1);f.push({score:null,label:m[n],mask:s})}}}return f}}class I extends m{constructor(e){super(e)}async _call(e,t,{hypothesis_template:n="This is a photo of {}"}={}){const s=Array.isArray(e),r=await p(e),o=t.map((e=>n.replace("{}",e))),i=this.tokenizer(o,{padding:"siglip"!==this.model.config.model_type||"max_length",truncation:!0}),{pixel_values:a}=await this.processor(r),c=await this.model({...i,pixel_values:a}),d="siglip"===this.model.config.model_type?e=>e.sigmoid().data:e=>(0,l.softmax)(e.data),u=[];for(const e of c.logits_per_image){const n=[...d(e)].map(((e,n)=>({score:e,label:t[n]})));n.sort(((e,t)=>t.score-e.score)),u.push(n)}return s?u:u[0]}}class B extends m{constructor(e){super(e)}async _call(e,{threshold:t=.9,percentage:n=!1}={}){const s=Array.isArray(e);if(s&&1!==e.length)throw Error("Object detection pipeline currently only supports a batch size of 1.");const r=await p(e),o=n?null:r.map((e=>[e.height,e.width])),{pixel_values:i,pixel_mask:a}=await this.processor(r),l=await this.model({pixel_values:i,pixel_mask:a}),c=this.processor.feature_extractor.post_process_object_detection(l,t,o),d=this.model.config.id2label,u=c.map((e=>e.boxes.map(((t,s)=>({score:e.scores[s],label:d[e.classes[s]],box:_(t,!n)})))));return s?u:u[0]}}class N extends m{constructor(e){super(e)}async _call(e,t,{threshold:n=.1,top_k:s=null,percentage:r=!1}={}){const o=Array.isArray(e),i=await p(e),a=this.tokenizer(t,{padding:!0,truncation:!0}),l=await this.processor(i),c=[];for(let e=0;e<i.length;++e){const o=i[e],d=r?null:[[o.height,o.width]],u=l.pixel_values[e].unsqueeze_(0),p=await this.model({...a,pixel_values:u}),h=this.processor.feature_extractor.post_process_object_detection(p,n,d,!0)[0];let m=h.boxes.map(((e,n)=>({score:h.scores[n],label:t[h.classes[n]],box:_(e,!r)}))).sort(((e,t)=>t.score-e.score));null!==s&&(m=m.slice(0,s)),c.push(m)}return o?c:c[0]}}class O extends m{constructor(e){super(e)}async _call(e,t,n={}){throw new Error("This pipeline is not yet supported in Transformers.js v3.")}}class j extends m{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(e){super(e),this.vocoder=e.vocoder??null}async _call(e,{speaker_embeddings:t=null}={}){return this.processor?this._call_text_to_spectrogram(e,{speaker_embeddings:t}):this._call_text_to_waveform(e)}async _call_text_to_waveform(e){const t=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:n}=await this.model(t),s=this.model.config.sampling_rate;return{audio:n.data,sampling_rate:s}}async _call_text_to_spectrogram(e,{speaker_embeddings:t}){if(this.vocoder||(console.log("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await r.AutoModel.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"})),("string"==typeof t||t instanceof URL)&&(t=new Float32Array(await(await fetch(t)).arrayBuffer())),t instanceof Float32Array)t=new d.Tensor("float32",t,[1,t.length]);else if(!(t instanceof d.Tensor))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");const{input_ids:n}=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:s}=await this.model.generate_speech(n,t,{vocoder:this.vocoder}),o=this.processor.feature_extractor.config.sampling_rate;return{audio:s.data,sampling_rate:o}}}class D extends m{constructor(e){super(e)}async _call(e){const t=await p(e),n=await this.processor(t),s=await this.model(n),r=[];for(const e of s.reconstruction){const t=e.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");r.push(u.RawImage.fromTensor(t))}return r.length>1?r:r[0]}}class V extends m{constructor(e){super(e)}async _call(e){const t=await p(e),n=await this.processor(t),{predicted_depth:s}=await this.model(n),r=[];for(let e=0;e<t.length;++e){const n=(0,d.interpolate)(s[e],t[e].size.reverse(),"bilinear",!1),o=n.mul_(255/(0,l.max)(n.data)[0]).to("uint8");r.push({predicted_depth:s[e],depth:u.RawImage.fromTensor(o)})}return r.length>1?r:r[0]}}const R=Object.freeze({"text-classification":{tokenizer:s.AutoTokenizer,pipeline:f,model:r.AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:s.AutoTokenizer,pipeline:g,model:r.AutoModelForTokenClassification,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:s.AutoTokenizer,pipeline:w,model:r.AutoModelForQuestionAnswering,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:s.AutoTokenizer,pipeline:M,model:r.AutoModelForMaskedLM,default:{model:"Xenova/bert-base-uncased"},type:"text"},summarization:{tokenizer:s.AutoTokenizer,pipeline:y,model:r.AutoModelForSeq2SeqLM,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:s.AutoTokenizer,pipeline:x,model:r.AutoModelForSeq2SeqLM,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:s.AutoTokenizer,pipeline:b,model:r.AutoModelForSeq2SeqLM,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:s.AutoTokenizer,pipeline:T,model:r.AutoModelForCausalLM,default:{model:"Xenova/gpt2"},type:"text"},"zero-shot-classification":{tokenizer:s.AutoTokenizer,pipeline:v,model:r.AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:P,model:r.AutoModelForAudioClassification,processor:o.AutoProcessor,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:s.AutoTokenizer,pipeline:S,model:r.AutoModel,processor:o.AutoProcessor,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:s.AutoTokenizer,pipeline:A,model:[r.AutoModelForSpeechSeq2Seq,r.AutoModelForCTC],processor:o.AutoProcessor,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:s.AutoTokenizer,pipeline:j,model:[r.AutoModelForTextToWaveform,r.AutoModelForTextToSpectrogram],processor:[o.AutoProcessor,null],default:{model:"Xenova/speecht5_tts"},type:"text"},"image-to-text":{tokenizer:s.AutoTokenizer,pipeline:E,model:r.AutoModelForVision2Seq,processor:o.AutoProcessor,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:L,model:r.AutoModelForImageClassification,processor:o.AutoProcessor,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:z,model:[r.AutoModelForImageSegmentation,r.AutoModelForSemanticSegmentation,r.AutoModelForUniversalSegmentation],processor:o.AutoProcessor,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"zero-shot-image-classification":{tokenizer:s.AutoTokenizer,pipeline:I,model:r.AutoModel,processor:o.AutoProcessor,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:B,model:r.AutoModelForObjectDetection,processor:o.AutoProcessor,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:s.AutoTokenizer,pipeline:N,model:r.AutoModelForZeroShotObjectDetection,processor:o.AutoProcessor,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:s.AutoTokenizer,pipeline:O,model:r.AutoModelForDocumentQuestionAnswering,processor:o.AutoProcessor,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:D,model:r.AutoModelForImageToImage,processor:o.AutoProcessor,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:V,model:r.AutoModelForDepthEstimation,processor:o.AutoProcessor,default:{model:"Xenova/dpt-large"},type:"image"},"feature-extraction":{tokenizer:s.AutoTokenizer,pipeline:F,model:r.AutoModel,default:{model:"Xenova/all-MiniLM-L6-v2"},type:"text"},"image-feature-extraction":{processor:o.AutoProcessor,pipeline:C,model:[r.AutoModelForImageFeatureExtraction,r.AutoModel],default:{model:"Xenova/vit-base-patch16-224-in21k"},type:"image"}}),G=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function $(e,t=null,{progress_callback:n=null,config:s=null,cache_dir:r=null,local_files_only:o=!1,revision:i="main",device:l=null,dtype:c=null,model_file_name:d=null,session_options:u={}}={}){e=G[e]??e;const p=R[e.split("_",1)[0]];if(!p)throw Error(`Unsupported pipeline: ${e}. Must be one of [${Object.keys(R)}]`);t||(t=p.default.model,console.log(`No model specified. Using default model: "${t}".`));const h={progress_callback:n,config:s,cache_dir:r,local_files_only:o,revision:i,device:l,dtype:c,model_file_name:d,session_options:u},_=new Map([["tokenizer",p.tokenizer],["model",p.model],["processor",p.processor]]),m=await async function(e,t,n){const s=Object.create(null),r=[];for(const[o,i]of e.entries()){if(!i)continue;let e;e=Array.isArray(i)?new Promise((async(e,s)=>{let r;for(const o of i){if(null===o)return void e(null);try{return void e(await o.from_pretrained(t,n))}catch(e){if(e.message?.includes("Unsupported model type"))r=e;else{if(!e.message?.includes("Could not locate file"))return void s(e);r=e}}}s(r)})):i.from_pretrained(t,n),s[o]=e,r.push(e)}await Promise.all(r);for(const[e,t]of Object.entries(s))s[e]=await t;return s}(_,t,h);m.task=e,(0,a.dispatchCallback)(n,{status:"ready",task:e,model:t});return new(0,p.pipeline)(m)}},"./src/processors.js":
|
|
125
125
|
/*!***************************!*\
|
|
126
126
|
!*** ./src/processors.js ***!
|
|
127
|
-
\***************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{ASTFeatureExtractor:()=>oe,AutoProcessor:()=>we,BeitFeatureExtractor:()=>X,BitImageProcessor:()=>F,CLIPFeatureExtractor:()=>P,CLIPImageProcessor:()=>S,ChineseCLIPFeatureExtractor:()=>A,ClapFeatureExtractor:()=>ie,ConvNextFeatureExtractor:()=>z,ConvNextImageProcessor:()=>L,DPTFeatureExtractor:()=>T,DPTImageProcessor:()=>v,DeiTFeatureExtractor:()=>W,DetrFeatureExtractor:()=>Y,DonutFeatureExtractor:()=>Q,EfficientNetImageProcessor:()=>N,FeatureExtractor:()=>M,Florence2Processor:()=>ge,GLPNFeatureExtractor:()=>C,ImageFeatureExtractor:()=>b,MaskFormerFeatureExtractor:()=>J,MobileNetV1FeatureExtractor:()=>O,MobileNetV2FeatureExtractor:()=>j,MobileNetV3FeatureExtractor:()=>D,MobileNetV4FeatureExtractor:()=>V,MobileViTFeatureExtractor:()=>R,MobileViTImageProcessor:()=>G,NougatImageProcessor:()=>H,OwlViTFeatureExtractor:()=>$,OwlViTProcessor:()=>fe,Owlv2ImageProcessor:()=>q,Processor:()=>de,PvtImageProcessor:()=>k,PyAnnoteFeatureExtractor:()=>ae,PyAnnoteProcessor:()=>_e,RTDetrImageProcessor:()=>U,SamImageProcessor:()=>Z,SamProcessor:()=>ue,SapiensFeatureExtractor:()=>y,SeamlessM4TFeatureExtractor:()=>re,SegformerFeatureExtractor:()=>x,SiglipImageProcessor:()=>E,SpeechT5FeatureExtractor:()=>ce,SpeechT5Processor:()=>me,Swin2SRImageProcessor:()=>ee,ViTFeatureExtractor:()=>I,ViTImageProcessor:()=>B,VitMatteImageProcessor:()=>te,Wav2Vec2FeatureExtractor:()=>se,Wav2Vec2ProcessorWithLM:()=>he,WeSpeakerFeatureExtractor:()=>le,WhisperFeatureExtractor:()=>ne,WhisperProcessor:()=>pe,YolosFeatureExtractor:()=>K});var s=n(/*! ./utils/generic.js */"./src/utils/generic.js"),r=n(/*! ./utils/core.js */"./src/utils/core.js"),o=n(/*! ./utils/hub.js */"./src/utils/hub.js"),i=n(/*! ./utils/maths.js */"./src/utils/maths.js"),a=n(/*! ./utils/tensor.js */"./src/utils/tensor.js"),l=(n(/*! ./utils/image.js */"./src/utils/image.js"),n(/*! ./utils/audio.js */"./src/utils/audio.js"));function c([e,t,n,s]){return[e-n/2,t-s/2,e+n/2,t+s/2]}function d(e,t=.5,n=null,s=!1){const r=e.logits,o=e.pred_boxes,[a,l,d]=r.dims;if(null!==n&&n.length!==a)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let u=[];for(let e=0;e<a;++e){let a=null!==n?n[e]:null,p={boxes:[],classes:[],scores:[]},h=r[e],_=o[e];for(let e=0;e<l;++e){let n,r=h[e],o=[];if(s){n=r.sigmoid().data;for(let e=0;e<n.length;++e)n[e]>t&&o.push(e)}else{let e=(0,i.max)(r.data)[1];if(e===d-1)continue;if(n=(0,i.softmax)(r.data),n[e]<t)continue;o.push(e)}for(const t of o){let s=_[e].data;s=c(s),null!==a&&(s=s.map(((e,t)=>e*a[(t+1)%2]))),p.boxes.push(s),p.classes.push(t),p.scores.push(n[t])}}u.push(p)}return u}function u(e,t=null){const n=e.logits,s=n.dims[0];if(null!==t&&t.length!==s)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");const r=[];for(let e=0;e<s;++e){const s=null!==t?t[e]:null;let o=n[e];null!==s&&(o=(0,a.interpolate)(o,s,"bilinear",!1));const[i,l]=s??o.dims.slice(-2),c=new a.Tensor("int32",new Int32Array(i*l),[i,l]),d=o[0].data,u=c.data;for(let e=1;e<o.dims[0];++e){const t=o[e].data;for(let n=0;n<t.length;++n)t[n]>d[n]&&(d[n]=t[n],u[n]=e)}const p=new Array(o.dims[0]);for(let e=0;e<u.length;++e){const t=u[e];p[t]=t}const h=p.filter((e=>void 0!==e));r.push({segmentation:c,labels:h})}return r}function p(e,t,n,s){const r=[],o=[],a=[];for(let l=0;l<e.dims[0];++l){const c=e[l],d=t[l],u=(0,i.max)(c.data)[1];if(u===s)continue;const p=(0,i.softmax)(c.data)[u];p>n&&(r.push(d),o.push(p),a.push(u))}return[r,o,a]}function h(e,t,n,s=.5,r=.8){const o=[];let i=0,a=0;const l=t[n].data;for(let t=0;t<e.length;++t)e[t]===n&&(o.push(t),++i),l[t]>=s&&++a;let c=i>0&&a>0;if(c){c=i/a>r}return[c,o]}function _(e,t,n,s,r,o=null,i=null){const[l,c]=i??e[0].dims,d=new a.Tensor("int32",new Int32Array(l*c),[l,c]),u=[];if(null!==i)for(let t=0;t<e.length;++t)e[t]=(0,a.interpolate)(e[t],i,"bilinear",!1);const p=new Int32Array(e[0].data.length),_=new Float32Array(e[0].data.length);for(let n=0;n<e.length;++n){let s=t[n];const r=e[n].data;for(let e=0;e<r.length;++e)r[e]*=s,r[e]>_[e]&&(p[e]=n,_[e]=r[e])}let m=0;const f=d.data;for(let o=0;o<n.length;++o){const i=n[o],[a,l]=h(p,e,o,s,r);if(a){++m;for(const e of l)f[e]=m;u.push({id:m,label_id:i,score:t[o]})}}return[d,u]}function m(e,t=.5,n=.5,s=.8,r=null,o=null){null===r&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),r=new Set);const i=e.class_queries_logits??e.logits,l=(e.masks_queries_logits??e.pred_masks).sigmoid();let[c,d,u]=i.dims;if(u-=1,null!==o&&o.length!==c)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let h=[];for(let e=0;e<c;++e){let c=null!==o?o[e]:null,d=i[e],m=l[e],[f,g,w]=p(d,m,t,u);if(0===w.length){let[e,t]=c??m.dims.slice(-2),n=new a.Tensor("int32",new Int32Array(e*t).fill(-1),[e,t]);h.push({segmentation:n,segments_info:[]});continue}let[M,b]=_(f,g,w,n,s,r,c);h.push({segmentation:M,segments_info:b})}return h}function f(e,t){if(!(e instanceof Float32Array||e instanceof Float64Array))throw new Error(`${t} expects input to be a Float32Array or a Float64Array, but got ${e?.constructor?.name??typeof e} instead. If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}function g(e,t,n=0,s=null){const r=e/t;let o=(0,i.bankers_round)(r)*t;return null!==s&&o>s&&(o=Math.floor(r)*t),o<n&&(o=Math.ceil(r)*t),o}function w([e,t],n){return[Math.max(Math.floor(e/n),1)*n,Math.max(Math.floor(t/n),1)*n]}class M extends s.Callable{constructor(e){super(),this.config=e}}class b extends M{constructor(e){super(e),this.image_mean=this.config.image_mean??this.config.mean,this.image_std=this.config.image_std??this.config.std,this.resample=this.config.resample??2,this.do_rescale=this.config.do_rescale??!0,this.rescale_factor=this.config.rescale_factor??1/255,this.do_normalize=this.config.do_normalize,this.do_resize=this.config.do_resize,this.do_thumbnail=this.config.do_thumbnail,this.size=this.config.size,this.size_divisibility=this.config.size_divisibility??this.config.size_divisor,this.do_center_crop=this.config.do_center_crop,this.crop_size=this.config.crop_size,this.do_convert_rgb=this.config.do_convert_rgb??!0,this.do_crop_margin=this.config.do_crop_margin,this.pad_size=this.config.pad_size,this.do_pad=this.config.do_pad,this.do_pad&&!this.pad_size&&this.size&&void 0!==this.size.width&&void 0!==this.size.height&&(this.pad_size=this.size),this.do_flip_channel_order=this.config.do_flip_channel_order??!1}async thumbnail(e,t,n=2){const s=e.height,r=e.width,o=t.height,i=t.width;let a=Math.min(s,o),l=Math.min(r,i);return a===s&&l===r?e:(s>r?l=Math.floor(r*a/s):r>s&&(a=Math.floor(s*l/r)),await e.resize(l,a,{resample:n}))}async crop_margin(e,t=200){const n=e.clone().grayscale(),s=(0,i.min)(n.data)[0],r=(0,i.max)(n.data)[0]-s;if(0===r)return e;const o=t/255;let a=n.width,l=n.height,c=0,d=0;const u=n.data;for(let e=0;e<n.height;++e){const t=e*n.width;for(let i=0;i<n.width;++i)(u[t+i]-s)/r<o&&(a=Math.min(a,i),l=Math.min(l,e),c=Math.max(c,i),d=Math.max(d,e))}return e=await e.crop([a,l,c,d])}pad_image(e,t,n,{mode:s="constant",center:o=!1,constant_values:i=0}={}){const[a,l,c]=t;let d,u;if("number"==typeof n?(d=n,u=n):(d=n.width,u=n.height),d!==l||u!==a){const n=new Float32Array(d*u*c);if(Array.isArray(i))for(let e=0;e<n.length;++e)n[e]=i[e%c];else 0!==i&&n.fill(i);const[p,h]=o?[Math.floor((d-l)/2),Math.floor((u-a)/2)]:[0,0];for(let t=0;t<a;++t){const s=(t+h)*d,r=t*l;for(let t=0;t<l;++t){const o=(s+t+p)*c,i=(r+t)*c;for(let t=0;t<c;++t)n[o+t]=e[i+t]}}if("symmetric"===s){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");const t=a-1,s=l-1;for(let o=0;o<u;++o){const i=o*d,u=(0,r.calculateReflectOffset)(o,t)*l;for(let t=0;t<d;++t){if(o<a&&t<l)continue;const d=(i+t)*c,p=(u+(0,r.calculateReflectOffset)(t,s))*c;for(let t=0;t<c;++t)n[d+t]=e[p+t]}}}e=n,t=[u,d,c]}return[e,t]}rescale(e){for(let t=0;t<e.length;++t)e[t]=this.rescale_factor*e[t]}get_resize_output_image_size(e,t){const[n,s]=e.size;let r,o;if(this.do_thumbnail){const{height:e,width:n}=t;r=Math.min(e,n)}else Number.isInteger(t)?(r=t,o=this.config.max_size??r):void 0!==t&&(r=t.shortest_edge,o=t.longest_edge);if(void 0!==r||void 0!==o){const e=void 0===r?1:Math.max(r/n,r/s),t=n*e,i=s*e,a=void 0===o?1:Math.min(o/t,o/i);let l=Math.floor(Number((t*a).toFixed(2))),c=Math.floor(Number((i*a).toFixed(2)));return void 0!==this.size_divisibility&&([l,c]=w([l,c],this.size_divisibility)),[l,c]}if(void 0!==t&&void 0!==t.width&&void 0!==t.height){let e=t.width,r=t.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let t=r/s,o=e/n;Math.abs(1-o)<Math.abs(1-t)?t=o:o=t,r=g(t*s,this.config.ensure_multiple_of),e=g(o*n,this.config.ensure_multiple_of)}return[e,r]}if(void 0!==this.size_divisibility)return w([n,s],this.size_divisibility);throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(t)}`)}async resize(e){const[t,n]=this.get_resize_output_image_size(e,this.size);return await e.resize(t,n,{resample:this.resample})}async preprocess(e,{do_normalize:t=null,do_pad:n=null,do_convert_rgb:s=null,do_convert_grayscale:r=null,do_flip_channel_order:o=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));const[i,l]=e.size;if(s??this.do_convert_rgb?e=e.rgb():r&&(e=e.grayscale()),this.do_resize&&(e=await this.resize(e)),this.do_thumbnail&&(e=await this.thumbnail(e,this.size,this.resample)),this.do_center_crop){let t,n;Number.isInteger(this.crop_size)?(t=this.crop_size,n=this.crop_size):(t=this.crop_size.width,n=this.crop_size.height),e=await e.center_crop(t,n)}const c=[e.height,e.width];let d=Float32Array.from(e.data),u=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(d),t??this.do_normalize){let t=this.image_mean;Array.isArray(this.image_mean)||(t=new Array(e.channels).fill(t));let n=this.image_std;if(Array.isArray(this.image_std)||(n=new Array(e.channels).fill(t)),t.length!==e.channels||n.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${t.length}) and \`image_std\` (${n.length}) must match the number of channels in the image (${e.channels}).`);for(let s=0;s<d.length;s+=e.channels)for(let r=0;r<e.channels;++r)d[s+r]=(d[s+r]-t[r])/n[r]}if(n??this.do_pad)if(this.pad_size){const t=this.pad_image(d,[e.height,e.width,e.channels],this.pad_size);[d,u]=t}else if(this.size_divisibility){const[e,t]=w([u[1],u[0]],this.size_divisibility);[d,u]=this.pad_image(d,u,{width:e,height:t})}if(o??this.do_flip_channel_order){if(3!==u[2])throw new Error("Flipping channel order is only supported for RGB images.");for(let e=0;e<d.length;e+=3){const t=d[e];d[e]=d[e+2],d[e+2]=t}}return{original_size:[l,i],reshaped_input_size:c,pixel_values:new a.Tensor("float32",d,u).permute(2,0,1)}}async _call(e,...t){Array.isArray(e)||(e=[e]);const n=await Promise.all(e.map((e=>this.preprocess(e))));return{pixel_values:(0,a.stack)(n.map((e=>e.pixel_values)),0),original_sizes:n.map((e=>e.original_size)),reshaped_input_sizes:n.map((e=>e.reshaped_input_size))}}}class y extends b{post_process_semantic_segmentation(...e){return u(...e)}}class x extends b{post_process_semantic_segmentation(...e){return u(...e)}}class k extends b{}class T extends b{}class v extends T{}class F extends b{}class C extends b{}class P extends b{}class S extends P{}class A extends b{}class E extends b{}class z extends b{constructor(e){super(e),this.crop_pct=this.config.crop_pct??.875}async resize(e){const t=this.size?.shortest_edge;if(void 0===t)throw new Error("Size dictionary must contain 'shortest_edge' key.");if(t<384){const n=Math.floor(t/this.crop_pct),[s,r]=this.get_resize_output_image_size(e,{shortest_edge:n});e=await e.resize(s,r,{resample:this.resample}),e=await e.center_crop(t,t)}else e=await e.resize(t,t,{resample:this.resample});return e}}class L extends z{}class I extends b{}class B extends b{}class N extends b{constructor(e){super(e),this.include_top=this.config.include_top??!0,this.include_top&&(this.image_std=this.image_std.map((e=>e*e)))}}class O extends b{}class j extends b{}class D extends b{}class V extends b{}class R extends b{}class G extends R{}class $ extends b{post_process_object_detection(...e){return d(...e)}}class q extends ${}class U extends b{post_process_object_detection(...e){return d(...e)}}class W extends b{}class X extends b{}class Q extends b{pad_image(e,t,n,s={}){const[r,o,i]=t;let a=this.image_mean;Array.isArray(this.image_mean)||(a=new Array(i).fill(a));let l=this.image_std;Array.isArray(l)||(l=new Array(i).fill(a));const c=a.map(((e,t)=>-e/l[t]));return super.pad_image(e,t,n,{center:!0,constant_values:c,...s})}}class H extends Q{}class Y extends b{async _call(e){const t=await super._call(e),n=[t.pixel_values.dims[0],64,64],s=(0,a.full)(n,1n);return{...t,pixel_mask:s}}post_process_object_detection(...e){return d(...e)}post_process_panoptic_segmentation(...e){return m(...e)}post_process_instance_segmentation(){throw Error("Not implemented yet")}}class J extends b{post_process_panoptic_segmentation(...e){return m(...e)}post_process_instance_segmentation(){throw Error("Not implemented yet")}}class K extends b{post_process_object_detection(...e){return d(...e)}}class Z extends b{reshape_input_points(e,t,n,s=!1){e=structuredClone(e);let o=(0,r.calculateDimensions)(e);if(3===o.length)s||(o=[1,...o]),e=[e];else if(4!==o.length)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let s=0;s<e.length;++s){let r=t[s],o=n[s],i=[o[0]/r[0],o[1]/r[1]];for(let t=0;t<e[s].length;++t)for(let n=0;n<e[s][t].length;++n)for(let r=0;r<e[s][t][n].length;++r)e[s][t][n][r]*=i[r%2]}return new a.Tensor("float32",Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,t){let n=(0,r.calculateDimensions)(e);if(2===n.length)n=[1,...n],e=[e];else if(3!==n.length)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");if(n.some(((e,n)=>e!==t.dims[n])))throw Error(`The first ${n.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new a.Tensor("int64",e.flat(1/0).map(BigInt),n)}async _call(e,{input_points:t=null,input_labels:n=null,input_boxes:s=null}={}){const r=await super._call(e);if(t&&(r.input_points=this.reshape_input_points(t,r.original_sizes,r.reshaped_input_sizes)),n){if(!r.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");r.input_labels=this.add_input_labels(n,r.input_points)}return s&&(r.input_boxes=this.reshape_input_points(s,r.original_sizes,r.reshaped_input_sizes,!0)),r}async post_process_masks(e,t,n,{mask_threshold:s=0,binarize:r=!0,pad_size:o=null}={}){const i=[],l=[(o=o??this.pad_size).height,o.width];for(let o=0;o<t.length;++o){const c=t[o],d=n[o];let u=await(0,a.interpolate_4d)(e[o],{mode:"bilinear",size:l});if(u=u.slice(null,null,[0,d[0]],[0,d[1]]),u=await(0,a.interpolate_4d)(u,{mode:"bilinear",size:c}),r){const e=u.data,t=new Uint8Array(e.length);for(let n=0;n<e.length;++n)e[n]>s&&(t[n]=1);u=new a.Tensor("bool",t,u.dims)}i.push(u)}return i}generate_crop_boxes(e,t,{crop_n_layers:n=0,overlap_ratio:s=512/1500,points_per_crop:r=32,crop_n_points_downscale_factor:o=1}={}){}}class ee extends b{pad_image(e,t,n,s={}){const[r,o,i]=t;return super.pad_image(e,t,{width:o+(n-o%n)%n,height:r+(n-r%n)%n},{mode:"symmetric",center:!1,constant_values:-1,...s})}}class te extends b{async _call(e,t){Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]);const n=await Promise.all(e.map((e=>this.preprocess(e)))),s=await Promise.all(t.map((e=>this.preprocess(e,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})))),r=(0,a.stack)(n.map(((e,t)=>(0,a.cat)([e.pixel_values,s[t].pixel_values],0))),0);return{pixel_values:r,original_sizes:n.map((e=>e.original_size)),reshaped_input_sizes:n.map((e=>e.reshaped_input_size))}}}class ne extends M{constructor(e){super(e),this.config.mel_filters??=(0,l.mel_filter_bank)(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=(0,l.window_function)(this.config.n_fft,"hann")}async _extract_fbank_features(e){const t=await(0,l.spectrogram)(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:this.config.nb_max_frames}),n=t.data,s=(0,i.max)(n)[0];for(let e=0;e<n.length;++e)n[e]=(Math.max(n[e],s-8)+4)/4;return t}async _call(e){let t;f(e,"WhisperFeatureExtractor"),e.length>this.config.n_samples?(console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."),t=e.slice(0,this.config.n_samples)):(t=new Float32Array(this.config.n_samples),t.set(e));return{input_features:(await this._extract_fbank_features(t)).unsqueeze_(0)}}}class se extends M{_zero_mean_unit_var_norm(e){const t=e.reduce(((e,t)=>e+t),0)/e.length,n=e.reduce(((e,n)=>e+(n-t)**2),0)/e.length;return e.map((e=>(e-t)/Math.sqrt(n+1e-7)))}async _call(e){f(e,"Wav2Vec2FeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let t=e;this.config.do_normalize&&(t=this._zero_mean_unit_var_norm(t));const n=[1,t.length];return{input_values:new a.Tensor("float32",t,n),attention_mask:new a.Tensor("int64",new BigInt64Array(t.length).fill(1n),n)}}}class re extends M{constructor(e){super(e);const t=this.config.sampling_rate,n=(0,l.mel_filter_bank)(256,this.config.num_mel_bins,20,Math.floor(t/2),t,null,"kaldi",!0);for(let e=0;e<n.length;++e)n[e].push(0);this.mel_filters=n,this.window=(0,l.window_function)(400,"povey",{periodic:!1})}async _extract_fbank_features(e,t){return e=e.map((e=>32768*e)),(0,l.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1.192092955078125e-7,remove_dc_offset:!0,max_num_frames:t,transpose:!0})}async _call(e,{padding:t=!0,pad_to_multiple_of:n=2,do_normalize_per_mel_bins:s=!0,return_attention_mask:r=!0}={}){f(e,"SeamlessM4TFeatureExtractor");let o,i=await this._extract_fbank_features(e,this.config.max_length);if(s){const[e,t]=i.dims,n=i.data;for(let s=0;s<t;++s){let r=0;for(let o=0;o<e;++o)r+=n[o*t+s];const o=r/e;let i=0;for(let r=0;r<e;++r)i+=(n[r*t+s]-o)**2;i/=e-1;const a=Math.sqrt(i+1e-7);for(let r=0;r<e;++r){const e=r*t+s;n[e]=(n[e]-o)/a}}}if(t){const[e,t]=i.dims,s=i.data,l=e%n;if(l>0){const n=new Float32Array(t*(e+l));n.set(s),n.fill(this.config.padding_value,s.length);const c=e+l;i=new a.Tensor(i.type,n,[c,t]),r&&(o=new a.Tensor("int64",new BigInt64Array(c),[1,c]),o.data.fill(1n,0,e))}}const[l,c]=i.dims,d=this.config.stride;if(0!==l%d)throw new Error(`The number of frames (${l}) must be a multiple of the stride (${d}).`);const u=i.view(1,Math.floor(l/d),c*d),p={input_features:u};if(r){const e=u.dims[1],t=new BigInt64Array(e);if(o){const e=o.data;for(let n=1,s=0;n<l;n+=d,++s)t[s]=e[n]}else t.fill(1n);p.attention_mask=new a.Tensor("int64",t,[1,e])}return p}}class oe extends M{constructor(e){super(e);const t=this.config.sampling_rate,n=(0,l.mel_filter_bank)(256,this.config.num_mel_bins,20,Math.floor(t/2),t,null,"kaldi",!0);for(let e=0;e<n.length;++e)n[e].push(0);this.mel_filters=n,this.window=(0,l.window_function)(400,"hann",{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,t){return(0,l.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1.192092955078125e-7,remove_dc_offset:!0,max_num_frames:t,transpose:!0})}async _call(e){f(e,"ASTFeatureExtractor");const t=await this._extract_fbank_features(e,this.config.max_length);if(this.config.do_normalize){const e=2*this.std,n=t.data;for(let t=0;t<n.length;++t)n[t]=(n[t]-this.mean)/e}return{input_values:t.unsqueeze_(0)}}}class ie extends M{constructor(e){super(e),this.mel_filters=(0,l.mel_filter_bank)(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,null,"htk"),this.mel_filters_slaney=(0,l.mel_filter_bank)(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,"slaney","slaney"),this.window=(0,l.window_function)(this.config.fft_window_size,"hann")}async _get_input_mel(e,t,n,s){let r,o=!1;const i=e.length-t;if(i>0){if("rand_trunc"!==n)throw new Error(`Truncation strategy "${n}" not implemented`);{o=!0;const n=Math.floor(Math.random()*(i+1));e=e.subarray(n,n+t),r=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}}else{if(i<0){let n=new Float64Array(t);if(n.set(e),"repeat"===s)for(let s=e.length;s<t;s+=e.length)n.set(e.subarray(0,Math.min(e.length,t-s)),s);else if("repeatpad"===s)for(let t=e.length;t<-i;t+=e.length)n.set(e,t);e=n}if("fusion"===n)throw new Error(`Truncation strategy "${n}" not implemented`);r=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}return r.unsqueeze_(0)}async _extract_fbank_features(e,t,n=null){return(0,l.spectrogram)(e,this.window,this.config.fft_window_size,this.config.hop_length,{power:2,mel_filters:t,log_mel:"dB",max_num_frames:n,do_pad:!1,transpose:!0})}async _call(e,{max_length:t=null}={}){f(e,"ClapFeatureExtractor");return{input_features:(await this._get_input_mel(e,t??this.config.nb_max_samples,this.config.truncation,this.config.padding)).unsqueeze_(0)}}}class ae extends M{async _call(e){f(e,"PyAnnoteFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));const t=[1,1,e.length];return{input_values:new a.Tensor("float32",e,t)}}samples_to_frames(e){return(e-this.config.offset)/this.config.step}post_process_speaker_diarization(e,t){const n=t/this.samples_to_frames(t)/this.config.sampling_rate,s=[];for(const t of e.tolist()){const e=[];let r=-1;for(let n=0;n<t.length;++n){const s=(0,i.softmax)(t[n]),[o,a]=(0,i.max)(s),[l,c]=[n,n+1];a!==r?(r=a,e.push({id:a,start:l,end:c,score:o})):(e.at(-1).end=c,e.at(-1).score+=o)}s.push(e.map((({id:e,start:t,end:s,score:r})=>({id:e,start:t*n,end:s*n,confidence:r/(s-t)}))))}return s}}class le extends M{constructor(e){super(e);const t=this.config.sampling_rate,n=(0,l.mel_filter_bank)(256,this.config.num_mel_bins,20,Math.floor(t/2),t,null,"kaldi",!0);for(let e=0;e<n.length;++e)n[e].push(0);this.mel_filters=n,this.window=(0,l.window_function)(400,"hamming",{periodic:!1}),this.min_num_frames=this.config.min_num_frames}async _extract_fbank_features(e){return e=e.map((e=>32768*e)),(0,l.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1.192092955078125e-7,remove_dc_offset:!0,transpose:!0,min_num_frames:this.min_num_frames})}async _call(e){f(e,"WeSpeakerFeatureExtractor");const t=(await this._extract_fbank_features(e)).unsqueeze_(0);if(null===this.config.fbank_centering_span){const e=t.mean(1).data,n=t.data,[s,r,o]=t.dims;for(let t=0;t<s;++t){const s=t*r*o,i=t*o;for(let t=0;t<r;++t){const r=s+t*o;for(let t=0;t<o;++t)n[r+t]-=e[i+t]}}}return{input_features:t}}}class ce extends M{}class de extends s.Callable{constructor(e){super(),this.feature_extractor=e}async _call(e,...t){return await this.feature_extractor(e,...t)}}class ue extends de{async _call(...e){return await this.feature_extractor(...e)}post_process_masks(...e){return this.feature_extractor.post_process_masks(...e)}reshape_input_points(...e){return this.feature_extractor.reshape_input_points(...e)}}class pe extends de{async _call(e){return await this.feature_extractor(e)}}class he extends de{async _call(e){return await this.feature_extractor(e)}}class _e extends de{async _call(e){return await this.feature_extractor(e)}post_process_speaker_diarization(...e){return this.feature_extractor.post_process_speaker_diarization(...e)}}class me extends de{async _call(e){return await this.feature_extractor(e)}}class fe extends de{}class ge extends de{constructor(e){super(e);const{tasks_answer_post_processing_type:t,task_prompts_without_inputs:n,task_prompts_with_input:s}=e.config;this.tasks_answer_post_processing_type=new Map(Object.entries(t??{})),this.task_prompts_without_inputs=new Map(Object.entries(n??{})),this.task_prompts_with_input=new Map(Object.entries(s??{})),this.regexes={quad_boxes:/(.+?)<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm,bboxes:/([^<]+)?<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm},this.size_per_bin=1e3}construct_prompts(e){"string"==typeof e&&(e=[e]);const t=[];for(const n of e)if(this.task_prompts_without_inputs.has(n))t.push(this.task_prompts_without_inputs.get(n));else{for(const[e,s]of this.task_prompts_with_input)if(n.includes(e)){t.push(s.replaceAll("{input}",n).replaceAll(e,""));break}t.length!==e.length&&t.push(n)}return t}post_process_generation(e,t,n){const s=this.tasks_answer_post_processing_type.get(t)??"pure_text";let r;switch(e=e.replaceAll("<s>","").replaceAll("</s>",""),s){case"pure_text":r=e;break;case"description_with_bboxes":case"bboxes":case"phrase_grounding":case"ocr":const o="ocr"===s?"quad_boxes":"bboxes",i=e.matchAll(this.regexes[o]),a=[],l=[];for(const[e,t,...s]of i)a.push(t?t.trim():a.at(-1)??""),l.push(s.map(((e,t)=>(Number(e)+.5)/this.size_per_bin*n[t%2])));r={labels:a,[o]:l};break;default:throw new Error(`Task "${t}" (of type "${s}") not yet implemented.`)}return{[t]:r}}}class we{static FEATURE_EXTRACTOR_CLASS_MAPPING={ImageFeatureExtractor:b,WhisperFeatureExtractor:ne,ViTFeatureExtractor:I,MobileViTFeatureExtractor:R,MobileViTImageProcessor:G,MobileNetV1FeatureExtractor:O,MobileNetV2FeatureExtractor:j,MobileNetV3FeatureExtractor:D,MobileNetV4FeatureExtractor:V,OwlViTFeatureExtractor:$,Owlv2ImageProcessor:q,CLIPFeatureExtractor:P,CLIPImageProcessor:S,Florence2Processor:ge,ChineseCLIPFeatureExtractor:A,SiglipImageProcessor:E,ConvNextFeatureExtractor:z,ConvNextImageProcessor:L,SegformerFeatureExtractor:x,SapiensFeatureExtractor:y,BitImageProcessor:F,DPTImageProcessor:v,DPTFeatureExtractor:T,PvtImageProcessor:k,GLPNFeatureExtractor:C,BeitFeatureExtractor:X,DeiTFeatureExtractor:W,DetrFeatureExtractor:Y,RTDetrImageProcessor:U,MaskFormerFeatureExtractor:J,YolosFeatureExtractor:K,DonutFeatureExtractor:Q,NougatImageProcessor:H,EfficientNetImageProcessor:N,ViTImageProcessor:B,VitMatteImageProcessor:te,SamImageProcessor:Z,Swin2SRImageProcessor:ee,Wav2Vec2FeatureExtractor:se,SeamlessM4TFeatureExtractor:re,SpeechT5FeatureExtractor:ce,ASTFeatureExtractor:oe,ClapFeatureExtractor:ie,PyAnnoteFeatureExtractor:ae,WeSpeakerFeatureExtractor:le};static PROCESSOR_CLASS_MAPPING={WhisperProcessor:pe,Wav2Vec2ProcessorWithLM:he,PyAnnoteProcessor:_e,SamProcessor:ue,SpeechT5Processor:me,OwlViTProcessor:fe,Florence2Processor:ge};static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:s=null,local_files_only:r=!1,revision:i="main"}={}){let a=n??await(0,o.getModelJSON)(e,"preprocessor_config.json",!0,{progress_callback:t,config:n,cache_dir:s,local_files_only:r,revision:i}),l=a.feature_extractor_type??a.image_processor_type,c=this.FEATURE_EXTRACTOR_CLASS_MAPPING[l];if(!c){if(void 0===a.size)throw new Error(`Unknown Feature Extractor type: ${l}`);console.warn(`Feature extractor type "${l}" not found, assuming ImageFeatureExtractor due to size parameter in config.`),c=b}return new(this.PROCESSOR_CLASS_MAPPING[a.processor_class]??de)(new c(a))}}},"./src/tokenizers.js":
|
|
127
|
+
\***************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{ASTFeatureExtractor:()=>oe,AutoProcessor:()=>we,BeitFeatureExtractor:()=>X,BitImageProcessor:()=>F,CLIPFeatureExtractor:()=>P,CLIPImageProcessor:()=>S,ChineseCLIPFeatureExtractor:()=>A,ClapFeatureExtractor:()=>ie,ConvNextFeatureExtractor:()=>L,ConvNextImageProcessor:()=>z,DPTFeatureExtractor:()=>T,DPTImageProcessor:()=>v,DeiTFeatureExtractor:()=>W,DetrFeatureExtractor:()=>Y,DonutFeatureExtractor:()=>Q,EfficientNetImageProcessor:()=>N,FeatureExtractor:()=>M,Florence2Processor:()=>ge,GLPNFeatureExtractor:()=>C,ImageFeatureExtractor:()=>b,MaskFormerFeatureExtractor:()=>J,MobileNetV1FeatureExtractor:()=>O,MobileNetV2FeatureExtractor:()=>j,MobileNetV3FeatureExtractor:()=>D,MobileNetV4FeatureExtractor:()=>V,MobileViTFeatureExtractor:()=>R,MobileViTImageProcessor:()=>G,NougatImageProcessor:()=>H,OwlViTFeatureExtractor:()=>$,OwlViTProcessor:()=>fe,Owlv2ImageProcessor:()=>q,Processor:()=>de,PvtImageProcessor:()=>k,PyAnnoteFeatureExtractor:()=>ae,PyAnnoteProcessor:()=>_e,RTDetrImageProcessor:()=>U,SamImageProcessor:()=>Z,SamProcessor:()=>ue,SapiensFeatureExtractor:()=>y,SeamlessM4TFeatureExtractor:()=>re,SegformerFeatureExtractor:()=>x,SiglipImageProcessor:()=>E,SpeechT5FeatureExtractor:()=>ce,SpeechT5Processor:()=>me,Swin2SRImageProcessor:()=>ee,ViTFeatureExtractor:()=>I,ViTImageProcessor:()=>B,VitMatteImageProcessor:()=>te,Wav2Vec2FeatureExtractor:()=>se,Wav2Vec2ProcessorWithLM:()=>he,WeSpeakerFeatureExtractor:()=>le,WhisperFeatureExtractor:()=>ne,WhisperProcessor:()=>pe,YolosFeatureExtractor:()=>K});var s=n(/*! ./utils/generic.js */"./src/utils/generic.js"),r=n(/*! ./utils/core.js */"./src/utils/core.js"),o=n(/*! ./utils/hub.js */"./src/utils/hub.js"),i=n(/*! ./utils/maths.js */"./src/utils/maths.js"),a=n(/*! ./utils/tensor.js */"./src/utils/tensor.js"),l=(n(/*! ./utils/image.js */"./src/utils/image.js"),n(/*! ./utils/audio.js */"./src/utils/audio.js"));function c([e,t,n,s]){return[e-n/2,t-s/2,e+n/2,t+s/2]}function d(e,t=.5,n=null,s=!1){const r=e.logits,o=e.pred_boxes,[a,l,d]=r.dims;if(null!==n&&n.length!==a)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let u=[];for(let e=0;e<a;++e){let a=null!==n?n[e]:null,p={boxes:[],classes:[],scores:[]},h=r[e],_=o[e];for(let e=0;e<l;++e){let n,r=h[e],o=[];if(s){n=r.sigmoid().data;for(let e=0;e<n.length;++e)n[e]>t&&o.push(e)}else{let e=(0,i.max)(r.data)[1];if(e===d-1)continue;if(n=(0,i.softmax)(r.data),n[e]<t)continue;o.push(e)}for(const t of o){let s=_[e].data;s=c(s),null!==a&&(s=s.map(((e,t)=>e*a[(t+1)%2]))),p.boxes.push(s),p.classes.push(t),p.scores.push(n[t])}}u.push(p)}return u}function u(e,t=null){const n=e.logits,s=n.dims[0];if(null!==t&&t.length!==s)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");const r=[];for(let e=0;e<s;++e){const s=null!==t?t[e]:null;let o=n[e];null!==s&&(o=(0,a.interpolate)(o,s,"bilinear",!1));const[i,l]=s??o.dims.slice(-2),c=new a.Tensor("int32",new Int32Array(i*l),[i,l]),d=o[0].data,u=c.data;for(let e=1;e<o.dims[0];++e){const t=o[e].data;for(let n=0;n<t.length;++n)t[n]>d[n]&&(d[n]=t[n],u[n]=e)}const p=new Array(o.dims[0]);for(let e=0;e<u.length;++e){const t=u[e];p[t]=t}const h=p.filter((e=>void 0!==e));r.push({segmentation:c,labels:h})}return r}function p(e,t,n,s){const r=[],o=[],a=[];for(let l=0;l<e.dims[0];++l){const c=e[l],d=t[l],u=(0,i.max)(c.data)[1];if(u===s)continue;const p=(0,i.softmax)(c.data)[u];p>n&&(r.push(d),o.push(p),a.push(u))}return[r,o,a]}function h(e,t,n,s=.5,r=.8){const o=[];let i=0,a=0;const l=t[n].data;for(let t=0;t<e.length;++t)e[t]===n&&(o.push(t),++i),l[t]>=s&&++a;let c=i>0&&a>0;if(c){c=i/a>r}return[c,o]}function _(e,t,n,s,r,o=null,i=null){const[l,c]=i??e[0].dims,d=new a.Tensor("int32",new Int32Array(l*c),[l,c]),u=[];if(null!==i)for(let t=0;t<e.length;++t)e[t]=(0,a.interpolate)(e[t],i,"bilinear",!1);const p=new Int32Array(e[0].data.length),_=new Float32Array(e[0].data.length);for(let n=0;n<e.length;++n){let s=t[n];const r=e[n].data;for(let e=0;e<r.length;++e)r[e]*=s,r[e]>_[e]&&(p[e]=n,_[e]=r[e])}let m=0;const f=d.data;for(let o=0;o<n.length;++o){const i=n[o],[a,l]=h(p,e,o,s,r);if(a){++m;for(const e of l)f[e]=m;u.push({id:m,label_id:i,score:t[o]})}}return[d,u]}function m(e,t=.5,n=.5,s=.8,r=null,o=null){null===r&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),r=new Set);const i=e.class_queries_logits??e.logits,l=(e.masks_queries_logits??e.pred_masks).sigmoid();let[c,d,u]=i.dims;if(u-=1,null!==o&&o.length!==c)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let h=[];for(let e=0;e<c;++e){let c=null!==o?o[e]:null,d=i[e],m=l[e],[f,g,w]=p(d,m,t,u);if(0===w.length){let[e,t]=c??m.dims.slice(-2),n=new a.Tensor("int32",new Int32Array(e*t).fill(-1),[e,t]);h.push({segmentation:n,segments_info:[]});continue}let[M,b]=_(f,g,w,n,s,r,c);h.push({segmentation:M,segments_info:b})}return h}function f(e,t){if(!(e instanceof Float32Array||e instanceof Float64Array))throw new Error(`${t} expects input to be a Float32Array or a Float64Array, but got ${e?.constructor?.name??typeof e} instead. If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}function g(e,t,n=0,s=null){const r=e/t;let o=(0,i.bankers_round)(r)*t;return null!==s&&o>s&&(o=Math.floor(r)*t),o<n&&(o=Math.ceil(r)*t),o}function w([e,t],n){return[Math.max(Math.floor(e/n),1)*n,Math.max(Math.floor(t/n),1)*n]}class M extends s.Callable{constructor(e){super(),this.config=e}}class b extends M{constructor(e){super(e),this.image_mean=this.config.image_mean??this.config.mean,this.image_std=this.config.image_std??this.config.std,this.resample=this.config.resample??2,this.do_rescale=this.config.do_rescale??!0,this.rescale_factor=this.config.rescale_factor??1/255,this.do_normalize=this.config.do_normalize,this.do_resize=this.config.do_resize,this.do_thumbnail=this.config.do_thumbnail,this.size=this.config.size,this.size_divisibility=this.config.size_divisibility??this.config.size_divisor,this.do_center_crop=this.config.do_center_crop,this.crop_size=this.config.crop_size,this.do_convert_rgb=this.config.do_convert_rgb??!0,this.do_crop_margin=this.config.do_crop_margin,this.pad_size=this.config.pad_size,this.do_pad=this.config.do_pad,this.do_pad&&!this.pad_size&&this.size&&void 0!==this.size.width&&void 0!==this.size.height&&(this.pad_size=this.size),this.do_flip_channel_order=this.config.do_flip_channel_order??!1}async thumbnail(e,t,n=2){const s=e.height,r=e.width,o=t.height,i=t.width;let a=Math.min(s,o),l=Math.min(r,i);return a===s&&l===r?e:(s>r?l=Math.floor(r*a/s):r>s&&(a=Math.floor(s*l/r)),await e.resize(l,a,{resample:n}))}async crop_margin(e,t=200){const n=e.clone().grayscale(),s=(0,i.min)(n.data)[0],r=(0,i.max)(n.data)[0]-s;if(0===r)return e;const o=t/255;let a=n.width,l=n.height,c=0,d=0;const u=n.data;for(let e=0;e<n.height;++e){const t=e*n.width;for(let i=0;i<n.width;++i)(u[t+i]-s)/r<o&&(a=Math.min(a,i),l=Math.min(l,e),c=Math.max(c,i),d=Math.max(d,e))}return e=await e.crop([a,l,c,d])}pad_image(e,t,n,{mode:s="constant",center:o=!1,constant_values:i=0}={}){const[a,l,c]=t;let d,u;if("number"==typeof n?(d=n,u=n):(d=n.width,u=n.height),d!==l||u!==a){const n=new Float32Array(d*u*c);if(Array.isArray(i))for(let e=0;e<n.length;++e)n[e]=i[e%c];else 0!==i&&n.fill(i);const[p,h]=o?[Math.floor((d-l)/2),Math.floor((u-a)/2)]:[0,0];for(let t=0;t<a;++t){const s=(t+h)*d,r=t*l;for(let t=0;t<l;++t){const o=(s+t+p)*c,i=(r+t)*c;for(let t=0;t<c;++t)n[o+t]=e[i+t]}}if("symmetric"===s){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");const t=a-1,s=l-1;for(let o=0;o<u;++o){const i=o*d,u=(0,r.calculateReflectOffset)(o,t)*l;for(let t=0;t<d;++t){if(o<a&&t<l)continue;const d=(i+t)*c,p=(u+(0,r.calculateReflectOffset)(t,s))*c;for(let t=0;t<c;++t)n[d+t]=e[p+t]}}}e=n,t=[u,d,c]}return[e,t]}rescale(e){for(let t=0;t<e.length;++t)e[t]=this.rescale_factor*e[t]}get_resize_output_image_size(e,t){const[n,s]=e.size;let r,o;if(this.do_thumbnail){const{height:e,width:n}=t;r=Math.min(e,n)}else Number.isInteger(t)?(r=t,o=this.config.max_size??r):void 0!==t&&(r=t.shortest_edge,o=t.longest_edge);if(void 0!==r||void 0!==o){const e=void 0===r?1:Math.max(r/n,r/s),t=n*e,i=s*e,a=void 0===o?1:Math.min(o/t,o/i);let l=Math.floor(Number((t*a).toFixed(2))),c=Math.floor(Number((i*a).toFixed(2)));return void 0!==this.size_divisibility&&([l,c]=w([l,c],this.size_divisibility)),[l,c]}if(void 0!==t&&void 0!==t.width&&void 0!==t.height){let e=t.width,r=t.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let t=r/s,o=e/n;Math.abs(1-o)<Math.abs(1-t)?t=o:o=t,r=g(t*s,this.config.ensure_multiple_of),e=g(o*n,this.config.ensure_multiple_of)}return[e,r]}if(void 0!==this.size_divisibility)return w([n,s],this.size_divisibility);throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(t)}`)}async resize(e){const[t,n]=this.get_resize_output_image_size(e,this.size);return await e.resize(t,n,{resample:this.resample})}async preprocess(e,{do_normalize:t=null,do_pad:n=null,do_convert_rgb:s=null,do_convert_grayscale:r=null,do_flip_channel_order:o=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));const[i,l]=e.size;if(s??this.do_convert_rgb?e=e.rgb():r&&(e=e.grayscale()),this.do_resize&&(e=await this.resize(e)),this.do_thumbnail&&(e=await this.thumbnail(e,this.size,this.resample)),this.do_center_crop){let t,n;Number.isInteger(this.crop_size)?(t=this.crop_size,n=this.crop_size):(t=this.crop_size.width,n=this.crop_size.height),e=await e.center_crop(t,n)}const c=[e.height,e.width];let d=Float32Array.from(e.data),u=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(d),t??this.do_normalize){let t=this.image_mean;Array.isArray(this.image_mean)||(t=new Array(e.channels).fill(t));let n=this.image_std;if(Array.isArray(this.image_std)||(n=new Array(e.channels).fill(t)),t.length!==e.channels||n.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${t.length}) and \`image_std\` (${n.length}) must match the number of channels in the image (${e.channels}).`);for(let s=0;s<d.length;s+=e.channels)for(let r=0;r<e.channels;++r)d[s+r]=(d[s+r]-t[r])/n[r]}if(n??this.do_pad)if(this.pad_size){const t=this.pad_image(d,[e.height,e.width,e.channels],this.pad_size);[d,u]=t}else if(this.size_divisibility){const[e,t]=w([u[1],u[0]],this.size_divisibility);[d,u]=this.pad_image(d,u,{width:e,height:t})}if(o??this.do_flip_channel_order){if(3!==u[2])throw new Error("Flipping channel order is only supported for RGB images.");for(let e=0;e<d.length;e+=3){const t=d[e];d[e]=d[e+2],d[e+2]=t}}return{original_size:[l,i],reshaped_input_size:c,pixel_values:new a.Tensor("float32",d,u).permute(2,0,1)}}async _call(e,...t){Array.isArray(e)||(e=[e]);const n=await Promise.all(e.map((e=>this.preprocess(e))));return{pixel_values:(0,a.stack)(n.map((e=>e.pixel_values)),0),original_sizes:n.map((e=>e.original_size)),reshaped_input_sizes:n.map((e=>e.reshaped_input_size))}}}class y extends b{post_process_semantic_segmentation(...e){return u(...e)}}class x extends b{post_process_semantic_segmentation(...e){return u(...e)}}class k extends b{}class T extends b{}class v extends T{}class F extends b{}class C extends b{}class P extends b{}class S extends P{}class A extends b{}class E extends b{}class L extends b{constructor(e){super(e),this.crop_pct=this.config.crop_pct??.875}async resize(e){const t=this.size?.shortest_edge;if(void 0===t)throw new Error("Size dictionary must contain 'shortest_edge' key.");if(t<384){const n=Math.floor(t/this.crop_pct),[s,r]=this.get_resize_output_image_size(e,{shortest_edge:n});e=await e.resize(s,r,{resample:this.resample}),e=await e.center_crop(t,t)}else e=await e.resize(t,t,{resample:this.resample});return e}}class z extends L{}class I extends b{}class B extends b{}class N extends b{constructor(e){super(e),this.include_top=this.config.include_top??!0,this.include_top&&(this.image_std=this.image_std.map((e=>e*e)))}}class O extends b{}class j extends b{}class D extends b{}class V extends b{}class R extends b{}class G extends R{}class $ extends b{post_process_object_detection(...e){return d(...e)}}class q extends ${}class U extends b{post_process_object_detection(...e){return d(...e)}}class W extends b{}class X extends b{}class Q extends b{pad_image(e,t,n,s={}){const[r,o,i]=t;let a=this.image_mean;Array.isArray(this.image_mean)||(a=new Array(i).fill(a));let l=this.image_std;Array.isArray(l)||(l=new Array(i).fill(a));const c=a.map(((e,t)=>-e/l[t]));return super.pad_image(e,t,n,{center:!0,constant_values:c,...s})}}class H extends Q{}class Y extends b{async _call(e){const t=await super._call(e),n=[t.pixel_values.dims[0],64,64],s=(0,a.full)(n,1n);return{...t,pixel_mask:s}}post_process_object_detection(...e){return d(...e)}post_process_panoptic_segmentation(...e){return m(...e)}post_process_instance_segmentation(){throw Error("Not implemented yet")}}class J extends b{post_process_panoptic_segmentation(...e){return m(...e)}post_process_instance_segmentation(){throw Error("Not implemented yet")}}class K extends b{post_process_object_detection(...e){return d(...e)}}class Z extends b{reshape_input_points(e,t,n,s=!1){e=structuredClone(e);let o=(0,r.calculateDimensions)(e);if(3===o.length)s||(o=[1,...o]),e=[e];else if(4!==o.length)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let s=0;s<e.length;++s){let r=t[s],o=n[s],i=[o[0]/r[0],o[1]/r[1]];for(let t=0;t<e[s].length;++t)for(let n=0;n<e[s][t].length;++n)for(let r=0;r<e[s][t][n].length;++r)e[s][t][n][r]*=i[r%2]}return new a.Tensor("float32",Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,t){let n=(0,r.calculateDimensions)(e);if(2===n.length)n=[1,...n],e=[e];else if(3!==n.length)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");if(n.some(((e,n)=>e!==t.dims[n])))throw Error(`The first ${n.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new a.Tensor("int64",e.flat(1/0).map(BigInt),n)}async _call(e,{input_points:t=null,input_labels:n=null,input_boxes:s=null}={}){const r=await super._call(e);if(t&&(r.input_points=this.reshape_input_points(t,r.original_sizes,r.reshaped_input_sizes)),n){if(!r.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");r.input_labels=this.add_input_labels(n,r.input_points)}return s&&(r.input_boxes=this.reshape_input_points(s,r.original_sizes,r.reshaped_input_sizes,!0)),r}async post_process_masks(e,t,n,{mask_threshold:s=0,binarize:r=!0,pad_size:o=null}={}){const i=[],l=[(o=o??this.pad_size).height,o.width];for(let o=0;o<t.length;++o){const c=t[o],d=n[o];let u=await(0,a.interpolate_4d)(e[o],{mode:"bilinear",size:l});if(u=u.slice(null,null,[0,d[0]],[0,d[1]]),u=await(0,a.interpolate_4d)(u,{mode:"bilinear",size:c}),r){const e=u.data,t=new Uint8Array(e.length);for(let n=0;n<e.length;++n)e[n]>s&&(t[n]=1);u=new a.Tensor("bool",t,u.dims)}i.push(u)}return i}generate_crop_boxes(e,t,{crop_n_layers:n=0,overlap_ratio:s=512/1500,points_per_crop:r=32,crop_n_points_downscale_factor:o=1}={}){}}class ee extends b{pad_image(e,t,n,s={}){const[r,o,i]=t;return super.pad_image(e,t,{width:o+(n-o%n)%n,height:r+(n-r%n)%n},{mode:"symmetric",center:!1,constant_values:-1,...s})}}class te extends b{async _call(e,t){Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]);const n=await Promise.all(e.map((e=>this.preprocess(e)))),s=await Promise.all(t.map((e=>this.preprocess(e,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})))),r=(0,a.stack)(n.map(((e,t)=>(0,a.cat)([e.pixel_values,s[t].pixel_values],0))),0);return{pixel_values:r,original_sizes:n.map((e=>e.original_size)),reshaped_input_sizes:n.map((e=>e.reshaped_input_size))}}}class ne extends M{constructor(e){super(e),this.config.mel_filters??=(0,l.mel_filter_bank)(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=(0,l.window_function)(this.config.n_fft,"hann")}async _extract_fbank_features(e){const t=await(0,l.spectrogram)(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:this.config.nb_max_frames}),n=t.data,s=(0,i.max)(n)[0];for(let e=0;e<n.length;++e)n[e]=(Math.max(n[e],s-8)+4)/4;return t}async _call(e){let t;f(e,"WhisperFeatureExtractor"),e.length>this.config.n_samples?(console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."),t=e.slice(0,this.config.n_samples)):(t=new Float32Array(this.config.n_samples),t.set(e));return{input_features:(await this._extract_fbank_features(t)).unsqueeze_(0)}}}class se extends M{_zero_mean_unit_var_norm(e){const t=e.reduce(((e,t)=>e+t),0)/e.length,n=e.reduce(((e,n)=>e+(n-t)**2),0)/e.length;return e.map((e=>(e-t)/Math.sqrt(n+1e-7)))}async _call(e){f(e,"Wav2Vec2FeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let t=e;this.config.do_normalize&&(t=this._zero_mean_unit_var_norm(t));const n=[1,t.length];return{input_values:new a.Tensor("float32",t,n),attention_mask:new a.Tensor("int64",new BigInt64Array(t.length).fill(1n),n)}}}class re extends M{constructor(e){super(e);const t=this.config.sampling_rate,n=(0,l.mel_filter_bank)(256,this.config.num_mel_bins,20,Math.floor(t/2),t,null,"kaldi",!0);for(let e=0;e<n.length;++e)n[e].push(0);this.mel_filters=n,this.window=(0,l.window_function)(400,"povey",{periodic:!1})}async _extract_fbank_features(e,t){return e=e.map((e=>32768*e)),(0,l.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1.192092955078125e-7,remove_dc_offset:!0,max_num_frames:t,transpose:!0})}async _call(e,{padding:t=!0,pad_to_multiple_of:n=2,do_normalize_per_mel_bins:s=!0,return_attention_mask:r=!0}={}){f(e,"SeamlessM4TFeatureExtractor");let o,i=await this._extract_fbank_features(e,this.config.max_length);if(s){const[e,t]=i.dims,n=i.data;for(let s=0;s<t;++s){let r=0;for(let o=0;o<e;++o)r+=n[o*t+s];const o=r/e;let i=0;for(let r=0;r<e;++r)i+=(n[r*t+s]-o)**2;i/=e-1;const a=Math.sqrt(i+1e-7);for(let r=0;r<e;++r){const e=r*t+s;n[e]=(n[e]-o)/a}}}if(t){const[e,t]=i.dims,s=i.data,l=e%n;if(l>0){const n=new Float32Array(t*(e+l));n.set(s),n.fill(this.config.padding_value,s.length);const c=e+l;i=new a.Tensor(i.type,n,[c,t]),r&&(o=new a.Tensor("int64",new BigInt64Array(c),[1,c]),o.data.fill(1n,0,e))}}const[l,c]=i.dims,d=this.config.stride;if(0!==l%d)throw new Error(`The number of frames (${l}) must be a multiple of the stride (${d}).`);const u=i.view(1,Math.floor(l/d),c*d),p={input_features:u};if(r){const e=u.dims[1],t=new BigInt64Array(e);if(o){const e=o.data;for(let n=1,s=0;n<l;n+=d,++s)t[s]=e[n]}else t.fill(1n);p.attention_mask=new a.Tensor("int64",t,[1,e])}return p}}class oe extends M{constructor(e){super(e);const t=this.config.sampling_rate,n=(0,l.mel_filter_bank)(256,this.config.num_mel_bins,20,Math.floor(t/2),t,null,"kaldi",!0);for(let e=0;e<n.length;++e)n[e].push(0);this.mel_filters=n,this.window=(0,l.window_function)(400,"hann",{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,t){return(0,l.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1.192092955078125e-7,remove_dc_offset:!0,max_num_frames:t,transpose:!0})}async _call(e){f(e,"ASTFeatureExtractor");const t=await this._extract_fbank_features(e,this.config.max_length);if(this.config.do_normalize){const e=2*this.std,n=t.data;for(let t=0;t<n.length;++t)n[t]=(n[t]-this.mean)/e}return{input_values:t.unsqueeze_(0)}}}class ie extends M{constructor(e){super(e),this.mel_filters=(0,l.mel_filter_bank)(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,null,"htk"),this.mel_filters_slaney=(0,l.mel_filter_bank)(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,"slaney","slaney"),this.window=(0,l.window_function)(this.config.fft_window_size,"hann")}async _get_input_mel(e,t,n,s){let r,o=!1;const i=e.length-t;if(i>0){if("rand_trunc"!==n)throw new Error(`Truncation strategy "${n}" not implemented`);{o=!0;const n=Math.floor(Math.random()*(i+1));e=e.subarray(n,n+t),r=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}}else{if(i<0){let n=new Float64Array(t);if(n.set(e),"repeat"===s)for(let s=e.length;s<t;s+=e.length)n.set(e.subarray(0,Math.min(e.length,t-s)),s);else if("repeatpad"===s)for(let t=e.length;t<-i;t+=e.length)n.set(e,t);e=n}if("fusion"===n)throw new Error(`Truncation strategy "${n}" not implemented`);r=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}return r.unsqueeze_(0)}async _extract_fbank_features(e,t,n=null){return(0,l.spectrogram)(e,this.window,this.config.fft_window_size,this.config.hop_length,{power:2,mel_filters:t,log_mel:"dB",max_num_frames:n,do_pad:!1,transpose:!0})}async _call(e,{max_length:t=null}={}){f(e,"ClapFeatureExtractor");return{input_features:(await this._get_input_mel(e,t??this.config.nb_max_samples,this.config.truncation,this.config.padding)).unsqueeze_(0)}}}class ae extends M{async _call(e){f(e,"PyAnnoteFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));const t=[1,1,e.length];return{input_values:new a.Tensor("float32",e,t)}}samples_to_frames(e){return(e-this.config.offset)/this.config.step}post_process_speaker_diarization(e,t){const n=t/this.samples_to_frames(t)/this.config.sampling_rate,s=[];for(const t of e.tolist()){const e=[];let r=-1;for(let n=0;n<t.length;++n){const s=(0,i.softmax)(t[n]),[o,a]=(0,i.max)(s),[l,c]=[n,n+1];a!==r?(r=a,e.push({id:a,start:l,end:c,score:o})):(e.at(-1).end=c,e.at(-1).score+=o)}s.push(e.map((({id:e,start:t,end:s,score:r})=>({id:e,start:t*n,end:s*n,confidence:r/(s-t)}))))}return s}}class le extends M{constructor(e){super(e);const t=this.config.sampling_rate,n=(0,l.mel_filter_bank)(256,this.config.num_mel_bins,20,Math.floor(t/2),t,null,"kaldi",!0);for(let e=0;e<n.length;++e)n[e].push(0);this.mel_filters=n,this.window=(0,l.window_function)(400,"hamming",{periodic:!1}),this.min_num_frames=this.config.min_num_frames}async _extract_fbank_features(e){return e=e.map((e=>32768*e)),(0,l.spectrogram)(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1.192092955078125e-7,remove_dc_offset:!0,transpose:!0,min_num_frames:this.min_num_frames})}async _call(e){f(e,"WeSpeakerFeatureExtractor");const t=(await this._extract_fbank_features(e)).unsqueeze_(0);if(null===this.config.fbank_centering_span){const e=t.mean(1).data,n=t.data,[s,r,o]=t.dims;for(let t=0;t<s;++t){const s=t*r*o,i=t*o;for(let t=0;t<r;++t){const r=s+t*o;for(let t=0;t<o;++t)n[r+t]-=e[i+t]}}}return{input_features:t}}}class ce extends M{}class de extends s.Callable{constructor(e){super(),this.feature_extractor=e}async _call(e,...t){return await this.feature_extractor(e,...t)}}class ue extends de{async _call(...e){return await this.feature_extractor(...e)}post_process_masks(...e){return this.feature_extractor.post_process_masks(...e)}reshape_input_points(...e){return this.feature_extractor.reshape_input_points(...e)}}class pe extends de{async _call(e){return await this.feature_extractor(e)}}class he extends de{async _call(e){return await this.feature_extractor(e)}}class _e extends de{async _call(e){return await this.feature_extractor(e)}post_process_speaker_diarization(...e){return this.feature_extractor.post_process_speaker_diarization(...e)}}class me extends de{async _call(e){return await this.feature_extractor(e)}}class fe extends de{}class ge extends de{constructor(e){super(e);const{tasks_answer_post_processing_type:t,task_prompts_without_inputs:n,task_prompts_with_input:s}=e.config;this.tasks_answer_post_processing_type=new Map(Object.entries(t??{})),this.task_prompts_without_inputs=new Map(Object.entries(n??{})),this.task_prompts_with_input=new Map(Object.entries(s??{})),this.regexes={quad_boxes:/(.+?)<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm,bboxes:/([^<]+)?<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm},this.size_per_bin=1e3}construct_prompts(e){"string"==typeof e&&(e=[e]);const t=[];for(const n of e)if(this.task_prompts_without_inputs.has(n))t.push(this.task_prompts_without_inputs.get(n));else{for(const[e,s]of this.task_prompts_with_input)if(n.includes(e)){t.push(s.replaceAll("{input}",n).replaceAll(e,""));break}t.length!==e.length&&t.push(n)}return t}post_process_generation(e,t,n){const s=this.tasks_answer_post_processing_type.get(t)??"pure_text";let r;switch(e=e.replaceAll("<s>","").replaceAll("</s>",""),s){case"pure_text":r=e;break;case"description_with_bboxes":case"bboxes":case"phrase_grounding":case"ocr":const o="ocr"===s?"quad_boxes":"bboxes",i=e.matchAll(this.regexes[o]),a=[],l=[];for(const[e,t,...s]of i)a.push(t?t.trim():a.at(-1)??""),l.push(s.map(((e,t)=>(Number(e)+.5)/this.size_per_bin*n[t%2])));r={labels:a,[o]:l};break;default:throw new Error(`Task "${t}" (of type "${s}") not yet implemented.`)}return{[t]:r}}}class we{static FEATURE_EXTRACTOR_CLASS_MAPPING={ImageFeatureExtractor:b,WhisperFeatureExtractor:ne,ViTFeatureExtractor:I,MobileViTFeatureExtractor:R,MobileViTImageProcessor:G,MobileNetV1FeatureExtractor:O,MobileNetV2FeatureExtractor:j,MobileNetV3FeatureExtractor:D,MobileNetV4FeatureExtractor:V,OwlViTFeatureExtractor:$,Owlv2ImageProcessor:q,CLIPFeatureExtractor:P,CLIPImageProcessor:S,Florence2Processor:ge,ChineseCLIPFeatureExtractor:A,SiglipImageProcessor:E,ConvNextFeatureExtractor:L,ConvNextImageProcessor:z,SegformerFeatureExtractor:x,SapiensFeatureExtractor:y,BitImageProcessor:F,DPTImageProcessor:v,DPTFeatureExtractor:T,PvtImageProcessor:k,GLPNFeatureExtractor:C,BeitFeatureExtractor:X,DeiTFeatureExtractor:W,DetrFeatureExtractor:Y,RTDetrImageProcessor:U,MaskFormerFeatureExtractor:J,YolosFeatureExtractor:K,DonutFeatureExtractor:Q,NougatImageProcessor:H,EfficientNetImageProcessor:N,ViTImageProcessor:B,VitMatteImageProcessor:te,SamImageProcessor:Z,Swin2SRImageProcessor:ee,Wav2Vec2FeatureExtractor:se,SeamlessM4TFeatureExtractor:re,SpeechT5FeatureExtractor:ce,ASTFeatureExtractor:oe,ClapFeatureExtractor:ie,PyAnnoteFeatureExtractor:ae,WeSpeakerFeatureExtractor:le};static PROCESSOR_CLASS_MAPPING={WhisperProcessor:pe,Wav2Vec2ProcessorWithLM:he,PyAnnoteProcessor:_e,SamProcessor:ue,SpeechT5Processor:me,OwlViTProcessor:fe,Florence2Processor:ge};static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:s=null,local_files_only:r=!1,revision:i="main"}={}){let a=n??await(0,o.getModelJSON)(e,"preprocessor_config.json",!0,{progress_callback:t,config:n,cache_dir:s,local_files_only:r,revision:i}),l=a.feature_extractor_type??a.image_processor_type,c=this.FEATURE_EXTRACTOR_CLASS_MAPPING[l];if(!c){if(void 0===a.size)throw new Error(`Unknown Feature Extractor type: ${l}`);console.warn(`Feature extractor type "${l}" not found, assuming ImageFeatureExtractor due to size parameter in config.`),c=b}return new(this.PROCESSOR_CLASS_MAPPING[a.processor_class]??de)(new c(a))}}},"./src/tokenizers.js":
|
|
128
128
|
/*!***************************!*\
|
|
129
129
|
!*** ./src/tokenizers.js ***!
|
|
130
|
-
\***************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{AlbertTokenizer:()=>xe,AutoTokenizer:()=>ht,BartTokenizer:()=>Ne,BertTokenizer:()=>ye,BlenderbotSmallTokenizer:()=>lt,BlenderbotTokenizer:()=>at,BloomTokenizer:()=>Ve,CLIPTokenizer:()=>st,CamembertTokenizer:()=>Ee,CodeGenTokenizer:()=>nt,CodeLlamaTokenizer:()=>$e,CohereTokenizer:()=>pt,ConvBertTokenizer:()=>Pe,DebertaTokenizer:()=>ve,DebertaV2Tokenizer:()=>Fe,DistilBertTokenizer:()=>Ae,ElectraTokenizer:()=>Le,EsmTokenizer:()=>Qe,FalconTokenizer:()=>We,GPT2Tokenizer:()=>Be,GPTNeoXTokenizer:()=>Xe,GemmaTokenizer:()=>Ye,Grok1Tokenizer:()=>Je,HerbertTokenizer:()=>Ce,LlamaTokenizer:()=>Ge,M2M100Tokenizer:()=>et,MBart50Tokenizer:()=>je,MBartTokenizer:()=>Oe,MPNetTokenizer:()=>Ue,MarianTokenizer:()=>ot,MobileBertTokenizer:()=>ke,NllbTokenizer:()=>Ze,NougatTokenizer:()=>dt,PreTrainedTokenizer:()=>be,Qwen2Tokenizer:()=>He,RoFormerTokenizer:()=>Se,RobertaTokenizer:()=>De,SiglipTokenizer:()=>rt,SpeechT5Tokenizer:()=>ct,SqueezeBertTokenizer:()=>Te,T5Tokenizer:()=>Ie,TokenizerModel:()=>k,VitsTokenizer:()=>ut,Wav2Vec2CTCTokenizer:()=>it,WhisperTokenizer:()=>tt,XLMRobertaTokenizer:()=>qe,XLMTokenizer:()=>ze,is_chinese_char:()=>g});var s=n(/*! ./utils/generic.js */"./src/utils/generic.js"),r=n(/*! ./utils/core.js */"./src/utils/core.js"),o=n(/*! ./utils/hub.js */"./src/utils/hub.js"),i=n(/*! ./utils/maths.js */"./src/utils/maths.js"),a=n(/*! ./utils/tensor.js */"./src/utils/tensor.js"),l=n(/*! ./utils/data-structures.js */"./src/utils/data-structures.js"),c=n(/*! @huggingface/jinja */"./node_modules/@huggingface/jinja/dist/index.js"),d=n(/*! ./models/whisper/common_whisper.js */"./src/models/whisper/common_whisper.js");n(/*! ./utils/constants.js */"./src/utils/constants.js");async function u(e,t){const n=await Promise.all([(0,o.getModelJSON)(e,"tokenizer.json",!0,t),(0,o.getModelJSON)(e,"tokenizer_config.json",!0,t)]);return null!==t.legacy&&(n[1].legacy=t.legacy),n}function p(e,t=!0){if(void 0!==e.Regex){let t=e.Regex.replace(/\\([#&~])/g,"$1");for(const[e,n]of y)t=t.replaceAll(e,n);return new RegExp(t,"gu")}if(void 0!==e.String){const n=(0,r.escapeRegExp)(e.String);return new RegExp(t?n:`(${n})`,"gu")}return console.warn("Unknown pattern type:",e),null}function h(e){return new Map(Object.entries(e))}function _(e){const t=e.dims;switch(t.length){case 1:return e.tolist();case 2:if(1!==t[0])throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return e.tolist()[0];default:throw new Error(`Expected tensor to have 1-2 dimensions, got ${t.length}.`)}}function m(e){return e.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n\'t/g,"n't").replace(/ \'m/g,"'m").replace(/ \'s/g,"'s").replace(/ \'ve/g,"'ve").replace(/ \'re/g,"'re")}function f(e){return e.replace(/\p{M}/gu,"")}function g(e){return e>=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=173824&&e<=177983||e>=177984&&e<=178207||e>=178208&&e<=183983||e>=63744&&e<=64255||e>=194560&&e<=195103}const w="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",M=new RegExp(`^[${w}]+$`,"gu"),b=".,!?…。,、।۔،",y=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"],[` ?[^(\\s|[${b}])]+`,` ?[^\\s${b}]+`]]);class x{constructor(e){this.content=e.content,this.id=e.id,this.single_word=e.single_word??!1,this.lstrip=e.lstrip??!1,this.rstrip=e.rstrip??!1,this.special=e.special??!1,this.normalized=e.normalized??null}}class k extends s.Callable{constructor(e){super(),this.config=e,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}static fromConfig(e,...t){switch(e.type){case"WordPiece":return new T(e);case"Unigram":return new v(e,...t);case"BPE":return new P(e);default:if(e.vocab)return Array.isArray(e.vocab)?new v(e,...t):new S(e,...t);throw new Error(`Unknown TokenizerModel type: ${e.type}`)}}_call(e){return e=this.encode(e),this.fuse_unk&&(e=function(e,t,n){const s=[];let r=0;for(;r<e.length;)if(s.push(e[r]),(t.get(e[r])??n)===n)for(;++r<e.length&&(t.get(e[r])??n)===n;)t.get(s.at(-1))!==n&&(s[s.length-1]+=e[r]);else++r;return s}(e,this.tokens_to_ids,this.unk_token_id)),e}encode(e){throw Error("encode should be implemented in subclass.")}convert_tokens_to_ids(e){return e.map((e=>this.tokens_to_ids.get(e)??this.unk_token_id))}convert_ids_to_tokens(e){return e.map((e=>this.vocab[e]??this.unk_token))}}class T extends k{constructor(e){super(e),this.tokens_to_ids=h(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.max_input_chars_per_word=e.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e}encode(e){const t=[];for(const n of e){const e=[...n];if(e.length>this.max_input_chars_per_word){t.push(this.unk_token);continue}let s=!1,r=0;const o=[];for(;r<e.length;){let t=e.length,n=null;for(;r<t;){let s=e.slice(r,t).join("");if(r>0&&(s=this.config.continuing_subword_prefix+s),this.tokens_to_ids.has(s)){n=s;break}--t}if(null===n){s=!0;break}o.push(n),r=t}s?t.push(this.unk_token):t.push(...o)}return t}}class v extends k{constructor(e,t){super(e);const n=e.vocab.length;this.vocab=new Array(n),this.scores=new Array(n);for(let t=0;t<n;++t){const n=e.vocab[t];this.vocab[t]=n[0],this.scores[t]=n[1]}this.unk_token_id=e.unk_id,this.unk_token=this.vocab[e.unk_id],this.tokens_to_ids=new Map(this.vocab.map(((e,t)=>[e,t]))),this.bos_token=" ",this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=t.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.unk_token=this.vocab[this.unk_token_id],this.minScore=(0,i.min)(this.scores)[0],this.unk_score=this.minScore-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new l.CharTrie,this.trie.extend(this.vocab),this.fuse_unk=!0}populateNodes(e){const t=e.chars;let n=0;for(;n<t.length;){let s=!1;const o=[],i=t.slice(n).join(""),a=this.trie.commonPrefixSearch(i);for(const t of a){o.push(t);const i=this.tokens_to_ids.get(t),a=this.scores[i],l=(0,r.len)(t);e.insert(n,l,a,i),s||1!==l||(s=!0)}s||e.insert(n,1,this.unk_score,this.unk_token_id),n+=1}}tokenize(e){const t=new l.TokenLattice(e,this.bos_token_id,this.eos_token_id);return this.populateNodes(t),t.tokens()}encode(e){const t=[];for(const n of e){const e=this.tokenize(n);t.push(...e)}return t}}const F=(()=>{const e=[...Array.from({length:"~".charCodeAt(0)-"!".charCodeAt(0)+1},((e,t)=>t+"!".charCodeAt(0))),...Array.from({length:"¬".charCodeAt(0)-"¡".charCodeAt(0)+1},((e,t)=>t+"¡".charCodeAt(0))),...Array.from({length:"ÿ".charCodeAt(0)-"®".charCodeAt(0)+1},((e,t)=>t+"®".charCodeAt(0)))],t=e.slice();let n=0;for(let s=0;s<256;++s)e.includes(s)||(e.push(s),t.push(256+n),n+=1);const s=t.map((e=>String.fromCharCode(e)));return Object.fromEntries(e.map(((e,t)=>[e,s[t]])))})(),C=(0,r.reverseDictionary)(F);class P extends k{constructor(e){super(e),this.tokens_to_ids=h(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e;const t=Array.isArray(e.merges[0]);this.merges=t?e.merges:e.merges.map((e=>e.split(" ",2))),this.bpe_ranks=new Map(this.merges.map(((e,t)=>[JSON.stringify(e),t]))),this.end_of_word_suffix=e.end_of_word_suffix,this.continuing_subword_suffix=e.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.ignore_merges=this.config.ignore_merges??!1,this.cache=new Map}bpe(e){if(0===e.length)return[];const t=this.cache.get(e);if(void 0!==t)return t;const n=Array.from(e);this.end_of_word_suffix&&(n[n.length-1]+=this.end_of_word_suffix);let s=[];if(n.length>1){const e=new l.PriorityQueue(((e,t)=>e.score<t.score));let t={token:n[0],bias:0,prev:null,next:null},r=t;for(let t=1;t<n.length;++t){const s={bias:t/n.length,token:n[t],prev:r,next:null};r.next=s,this._add_node(e,r),r=s}for(;!e.isEmpty();){const n=e.pop();if(n.deleted||!n.next||n.next.deleted)continue;if(n.deleted=!0,n.next.deleted=!0,n.prev){const e={...n.prev};n.prev.deleted=!0,n.prev=e,e.prev?e.prev.next=e:t=e}const s={token:n.token+n.next.token,bias:n.bias,prev:n.prev,next:n.next.next};s.prev?(s.prev.next=s,this._add_node(e,s.prev)):t=s,s.next&&(s.next.prev=s,this._add_node(e,s))}for(let e=t;null!==e;e=e.next)s.push(e.token)}else s=n;if(this.continuing_subword_suffix)for(let e=0;e<s.length-1;++e)s[e]+=this.continuing_subword_suffix;return this.cache.set(e,s),s}_add_node(e,t){const n=this.bpe_ranks.get(JSON.stringify([t.token,t.next.token]));void 0!==n&&(t.score=n+t.bias,e.push(t))}encode(e){const t=[];for(const n of e){if(this.ignore_merges&&this.tokens_to_ids.has(n)){t.push(n);continue}const e=this.bpe(n);for(const n of e)if(this.tokens_to_ids.has(n))t.push(n);else if(this.byte_fallback){const e=Array.from(this.text_encoder.encode(n)).map((e=>`<0x${e.toString(16).toUpperCase().padStart(2,"0")}>`));e.every((e=>this.tokens_to_ids.has(e)))?t.push(...e):t.push(this.unk_token)}else t.push(this.unk_token)}return t}}class S extends k{constructor(e,t){super(e),this.tokens_to_ids=h(t.target_lang?e.vocab[t.target_lang]:e.vocab),this.bos_token=t.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=t.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=t.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=t.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e}encode(e){return e}}class A extends s.Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(null===e)return null;switch(e.type){case"BertNormalizer":return new V(e);case"Precompiled":return new pe(e);case"Sequence":return new D(e);case"Replace":return new E(e);case"NFC":return new z(e);case"NFKC":return new L(e);case"NFKD":return new I(e);case"Strip":return new B(e);case"StripAccents":return new N(e);case"Lowercase":return new O(e);case"Prepend":return new j(e);default:throw new Error(`Unknown Normalizer type: ${e.type}`)}}normalize(e){throw Error("normalize should be implemented in subclass.")}_call(e){return this.normalize(e)}}class E extends A{normalize(e){const t=p(this.config.pattern);return null===t?e:e.replaceAll(t,this.config.content)}}class z extends A{normalize(e){return e=e.normalize("NFC")}}class L extends A{normalize(e){return e=e.normalize("NFKC")}}class I extends A{normalize(e){return e=e.normalize("NFKD")}}class B extends A{normalize(e){return this.config.strip_left&&this.config.strip_right?e=e.trim():(this.config.strip_left&&(e=e.trimStart()),this.config.strip_right&&(e=e.trimEnd())),e}}class N extends A{normalize(e){return e=f(e)}}class O extends A{normalize(e){return e=e.toLowerCase()}}class j extends A{normalize(e){return e=this.config.prepend+e}}class D extends A{constructor(e){super(e),this.normalizers=e.normalizers.map((e=>A.fromConfig(e)))}normalize(e){return this.normalizers.reduce(((e,t)=>t.normalize(e)),e)}}class V extends A{_tokenize_chinese_chars(e){const t=[];for(let n=0;n<e.length;++n){const s=e[n];g(s.charCodeAt(0))?(t.push(" "),t.push(s),t.push(" ")):t.push(s)}return t.join("")}stripAccents(e){return e.normalize("NFD").replace(/\p{Mn}/gu,"")}_is_control(e){switch(e){case"\t":case"\n":case"\r":return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(e)}}_clean_text(e){const t=[];for(const n of e){const e=n.charCodeAt(0);0===e||65533===e||this._is_control(n)||(/^\s$/.test(n)?t.push(" "):t.push(n))}return t.join("")}normalize(e){return this.config.clean_text&&(e=this._clean_text(e)),this.config.handle_chinese_chars&&(e=this._tokenize_chinese_chars(e)),this.config.lowercase?(e=e.toLowerCase(),!1!==this.config.strip_accents&&(e=this.stripAccents(e))):this.config.strip_accents&&(e=this.stripAccents(e)),e}}class R extends s.Callable{static fromConfig(e){if(null===e)return null;switch(e.type){case"BertPreTokenizer":return new G(e);case"Sequence":return new he(e);case"Whitespace":return new _e(e);case"WhitespaceSplit":return new me(e);case"Metaspace":return new de(e);case"ByteLevel":return new $(e);case"Split":return new q(e);case"Punctuation":return new U(e);case"Digits":return new W(e);case"Replace":return new fe(e);default:throw new Error(`Unknown PreTokenizer type: ${e.type}`)}}pre_tokenize_text(e,t){throw Error("pre_tokenize_text should be implemented in subclass.")}pre_tokenize(e,t){return(Array.isArray(e)?e.map((e=>this.pre_tokenize_text(e,t))):this.pre_tokenize_text(e,t)).flat()}_call(e,t){return this.pre_tokenize(e,t)}}class G extends R{constructor(e){super(),this.pattern=new RegExp(`[^\\s${w}]+|[${w}]`,"gu")}pre_tokenize_text(e,t){return e.trim().match(this.pattern)||[]}}class $ extends R{constructor(e){super(),this.config=e,this.add_prefix_space=this.config.add_prefix_space,this.trim_offsets=this.config.trim_offsets,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=F,this.text_encoder=new TextEncoder}pre_tokenize_text(e,t){this.add_prefix_space&&!e.startsWith(" ")&&(e=" "+e);return(this.use_regex?e.match(this.pattern)||[]:[e]).map((e=>Array.from(this.text_encoder.encode(e),(e=>this.byte_encoder[e])).join("")))}}class q extends R{constructor(e){super(),this.config=e,this.pattern=p(this.config.pattern,this.config.invert)}pre_tokenize_text(e,t){return null===this.pattern?[]:this.config.invert?e.match(this.pattern)||[]:function(e,t){const n=[];let s=0;for(const r of e.matchAll(t)){const t=r[0];s<r.index&&n.push(e.slice(s,r.index)),t.length>0&&n.push(t),s=r.index+t.length}return s<e.length&&n.push(e.slice(s)),n}(e,this.pattern)}}class U extends R{constructor(e){super(),this.config=e,this.pattern=new RegExp(`[^${w}]+|[${w}]+`,"gu")}pre_tokenize_text(e,t){return e.match(this.pattern)||[]}}class W extends R{constructor(e){super(),this.config=e;const t="[^\\d]+|\\d"+(this.config.individual_digits?"":"+");this.pattern=new RegExp(t,"gu")}pre_tokenize_text(e,t){return e.match(this.pattern)||[]}}class X extends s.Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(null===e)return null;switch(e.type){case"TemplateProcessing":return new Y(e);case"ByteLevel":return new J(e);case"RobertaProcessing":return new H(e);case"BertProcessing":return new Q(e);case"Sequence":return new K(e);default:throw new Error(`Unknown PostProcessor type: ${e.type}`)}}post_process(e,...t){throw Error("post_process should be implemented in subclass.")}_call(e,...t){return this.post_process(e,...t)}}class Q extends X{constructor(e){super(e),this.cls=e.cls[0],this.sep=e.sep[0]}post_process(e,t=null,{add_special_tokens:n=!0}={}){n&&(e=(0,r.mergeArrays)([this.cls],e,[this.sep]));let s=new Array(e.length).fill(0);if(null!==t){const o=n&&this instanceof H?[this.sep]:[],i=n?[this.sep]:[];e=(0,r.mergeArrays)(e,o,t,i),s=(0,r.mergeArrays)(s,new Array(t.length+o.length+i.length).fill(1))}return{tokens:e,token_type_ids:s}}}class H extends Q{}class Y extends X{constructor(e){super(e),this.single=e.single,this.pair=e.pair}post_process(e,t=null,{add_special_tokens:n=!0}={}){const s=null===t?this.single:this.pair;let o=[],i=[];for(const a of s)"SpecialToken"in a?n&&(o.push(a.SpecialToken.id),i.push(a.SpecialToken.type_id)):"Sequence"in a&&("A"===a.Sequence.id?(o=(0,r.mergeArrays)(o,e),i=(0,r.mergeArrays)(i,new Array(e.length).fill(a.Sequence.type_id))):"B"===a.Sequence.id&&(o=(0,r.mergeArrays)(o,t),i=(0,r.mergeArrays)(i,new Array(t.length).fill(a.Sequence.type_id))));return{tokens:o,token_type_ids:i}}}class J extends X{post_process(e,t=null){return t&&(e=(0,r.mergeArrays)(e,t)),{tokens:e}}}class K extends X{constructor(e){super(e),this.processors=e.processors.map((e=>X.fromConfig(e)))}post_process(e,t=null,n={}){let s;for(const r of this.processors)if(r instanceof J){if(e=r.post_process(e).tokens,t){t=r.post_process(t).tokens}}else{const o=r.post_process(e,t,n);e=o.tokens,s=o.token_type_ids}return{tokens:e,token_type_ids:s}}}class Z extends s.Callable{constructor(e){super(),this.config=e,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets=e.trim_offsets}static fromConfig(e){if(null===e)return null;switch(e.type){case"WordPiece":return new re(e);case"Metaspace":return new ue(e);case"ByteLevel":return new oe(e);case"Replace":return new ee(e);case"ByteFallback":return new te(e);case"Fuse":return new ne(e);case"Strip":return new se(e);case"Sequence":return new ae(e);case"CTC":return new ie(e);case"BPEDecoder":return new le(e);default:throw new Error(`Unknown Decoder type: ${e.type}`)}}_call(e){return this.decode(e)}decode(e){return this.decode_chain(e).join("")}decode_chain(e){throw Error("`decode_chain` should be implemented in subclass.")}}class ee extends Z{decode_chain(e){const t=p(this.config.pattern);return null===t?e:e.map((e=>e.replaceAll(t,this.config.content)))}}class te extends Z{constructor(e){super(e),this.text_decoder=new TextDecoder}decode_chain(e){const t=[];let n=[];for(const s of e){let e=null;if(6===s.length&&s.startsWith("<0x")&&s.endsWith(">")){const t=parseInt(s.slice(3,5),16);isNaN(t)||(e=t)}if(null!==e)n.push(e);else{if(n.length>0){const e=this.text_decoder.decode(Uint8Array.from(n));t.push(e),n=[]}t.push(s)}}if(n.length>0){const e=this.text_decoder.decode(Uint8Array.from(n));t.push(e),n=[]}return t}}class ne extends Z{decode_chain(e){return[e.join("")]}}class se extends Z{constructor(e){super(e),this.content=this.config.content,this.start=this.config.start,this.stop=this.config.stop}decode_chain(e){return e.map((e=>{let t=0;for(let n=0;n<this.start&&e[n]===this.content;++n)t=n+1;let n=e.length;for(let t=0;t<this.stop;++t){const s=e.length-t-1;if(e[s]!==this.content)break;n=s}return e.slice(t,n)}))}}class re extends Z{constructor(e){super(e),this.cleanup=e.cleanup}decode_chain(e){return e.map(((e,t)=>(0!==t&&(e=e.startsWith(this.config.prefix)?e.replace(this.config.prefix,""):" "+e),this.cleanup&&(e=m(e)),e)))}}class oe extends Z{constructor(e){super(e),this.byte_decoder=C,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(e){const t=e.join(""),n=new Uint8Array([...t].map((e=>this.byte_decoder[e])));return this.text_decoder.decode(n)}decode_chain(e){const t=[];let n=[];for(const s of e)void 0!==this.added_tokens.find((e=>e.content===s))?(n.length>0&&(t.push(this.convert_tokens_to_string(n)),n=[]),t.push(s)):n.push(s);return n.length>0&&t.push(this.convert_tokens_to_string(n)),t}}class ie extends Z{constructor(e){super(e),this.pad_token=this.config.pad_token,this.word_delimiter_token=this.config.word_delimiter_token,this.cleanup=this.config.cleanup}convert_tokens_to_string(e){if(0===e.length)return"";const t=[e[0]];for(let n=1;n<e.length;++n)e[n]!==t.at(-1)&&t.push(e[n]);let n=t.filter((e=>e!==this.pad_token)).join("");return this.cleanup&&(n=m(n).replaceAll(this.word_delimiter_token," ").trim()),n}decode_chain(e){return[this.convert_tokens_to_string(e)]}}class ae extends Z{constructor(e){super(e),this.decoders=e.decoders.map((e=>Z.fromConfig(e)))}decode_chain(e){return this.decoders.reduce(((e,t)=>t.decode_chain(e)),e)}}class le extends Z{constructor(e){super(e),this.suffix=this.config.suffix}decode_chain(e){return e.map(((t,n)=>t.replaceAll(this.suffix,n===e.length-1?"":" ")))}}class ce extends Z{decode_chain(e){let t="";for(let n=1;n<e.length;n+=2)t+=e[n];return[t]}}class de extends R{constructor(e){super(),this.addPrefixSpace=e.add_prefix_space,this.replacement=e.replacement,this.strRep=e.str_rep||this.replacement,this.prepend_scheme=e.prepend_scheme??"always"}pre_tokenize_text(e,{section_index:t}={}){let n=e.replaceAll(" ",this.strRep);return this.addPrefixSpace&&!n.startsWith(this.replacement)&&("always"===this.prepend_scheme||"first"===this.prepend_scheme&&0===t)&&(n=this.strRep+n),[n]}}class ue extends Z{constructor(e){super(e),this.addPrefixSpace=e.add_prefix_space,this.replacement=e.replacement}decode_chain(e){const t=[];for(let n=0;n<e.length;++n){let s=e[n].replaceAll(this.replacement," ");this.addPrefixSpace&&0==n&&s.startsWith(" ")&&(s=s.substring(1)),t.push(s)}return t}}class pe extends A{constructor(e){super(e),this.charsmap=e.precompiled_charsmap}normalize(e){if((e=(e=e.replace(/[\u0001-\u0008\u000B\u000E-\u001F\u007F\u008F\u009F]/gm,"")).replace(/[\u0009\u000A\u000C\u000D\u00A0\u1680\u2000-\u200F\u2028\u2029\u202F\u205F\u2581\u3000\uFEFF\uFFFD]/gm," ")).includes("~")){const t=e.split("~");e=t.map((e=>e.normalize("NFKC"))).join("~")}else e=e.normalize("NFKC");return e}}class he extends R{constructor(e){super(),this.tokenizers=e.pretokenizers.map((e=>R.fromConfig(e)))}pre_tokenize_text(e,t){return this.tokenizers.reduce(((e,n)=>n.pre_tokenize(e,t)),[e])}}class _e extends R{constructor(e){super()}pre_tokenize_text(e,t){return e.match(/\w+|[^\w\s]+/g)||[]}}class me extends R{constructor(e){super()}pre_tokenize_text(e,t){return function(e){return e.match(/\S+/g)||[]}(e)}}class fe extends R{constructor(e){super(),this.config=e,this.pattern=p(this.config.pattern),this.content=this.config.content}pre_tokenize_text(e,t){return null===this.pattern?[e]:[e.replaceAll(this.pattern,this.config.content)]}}const ge=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function we(e,t,n,s){for(const o of Object.keys(e)){const i=t-e[o].length,a=n(o),l=new Array(i).fill(a);e[o]="right"===s?(0,r.mergeArrays)(e[o],l):(0,r.mergeArrays)(l,e[o])}}function Me(e,t){for(const n of Object.keys(e))e[n].length=t}class be extends s.Callable{return_token_type_ids=!1;padding_side="right";constructor(e,t){super(),this._tokenizer_config=t,this.normalizer=A.fromConfig(e.normalizer),this.pre_tokenizer=R.fromConfig(e.pre_tokenizer),this.model=k.fromConfig(e.model,t),this.post_processor=X.fromConfig(e.post_processor),this.decoder=Z.fromConfig(e.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];for(const t of e.added_tokens){const e=new x(t);this.added_tokens.push(e),this.model.tokens_to_ids.set(e.content,e.id),this.model.vocab[e.id]=e.content,e.special&&(this.special_tokens.push(e.content),this.all_special_ids.push(e.id))}if(this.additional_special_tokens=t.additional_special_tokens??[],this.special_tokens.push(...this.additional_special_tokens),this.special_tokens=[...new Set(this.special_tokens)],this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.added_tokens_regex=this.added_tokens.length>0?new RegExp(this.added_tokens.slice().sort(((e,t)=>t.content.length-e.content.length)).map((e=>`${e.lstrip?"\\s*":""}(${(0,r.escapeRegExp)(e.content)})${e.rstrip?"\\s*":""}`)).join("|")):null,this.mask_token=this.getToken("mask_token"),this.mask_token_id=this.model.tokens_to_ids.get(this.mask_token),this.pad_token=this.getToken("pad_token","eos_token"),this.pad_token_id=this.model.tokens_to_ids.get(this.pad_token),this.sep_token=this.getToken("sep_token"),this.sep_token_id=this.model.tokens_to_ids.get(this.sep_token),this.unk_token=this.getToken("unk_token"),this.unk_token_id=this.model.tokens_to_ids.get(this.unk_token),this.model_max_length=t.model_max_length,this.remove_space=t.remove_space,this.clean_up_tokenization_spaces=t.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=t.do_lowercase_and_remove_accent??!1,t.padding_side&&(this.padding_side=t.padding_side),this.legacy=!1,this.chat_template=t.chat_template??null,Array.isArray(this.chat_template)){const e=Object.create(null);for(const{name:t,template:n}of this.chat_template){if("string"!=typeof t||"string"!=typeof n)throw new Error('Chat template must be a list of objects with "name" and "template" properties');e[t]=n}this.chat_template=e}this._compiled_template_cache=new Map}getToken(...e){for(const t of e){const e=this._tokenizer_config[t];if(e){if("object"==typeof e){if("AddedToken"===e.__type)return e.content;throw Error(`Unknown token: ${e}`)}return e}}return null}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:s=null,local_files_only:r=!1,revision:o="main",legacy:i=null}={}){return new this(...await u(e,{progress_callback:t,config:n,cache_dir:s,local_files_only:r,revision:o,legacy:i}))}_call(e,{text_pair:t=null,add_special_tokens:n=!0,padding:s=!1,truncation:r=null,max_length:o=null,return_tensor:l=!0,return_token_type_ids:c=null}={}){const d=Array.isArray(e);let u;if(d){if(0===e.length)throw Error("text array must be non-empty");if(null!==t){if(!Array.isArray(t))throw Error("text_pair must also be an array");if(e.length!==t.length)throw Error("text and text_pair must have the same length");u=e.map(((e,s)=>this._encode_plus(e,{text_pair:t[s],add_special_tokens:n,return_token_type_ids:c})))}else u=e.map((e=>this._encode_plus(e,{add_special_tokens:n,return_token_type_ids:c})))}else{if(null==e)throw Error("text may not be null or undefined");if(Array.isArray(t))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");u=[this._encode_plus(e,{text_pair:t,add_special_tokens:n,return_token_type_ids:c})]}if(null===o?o="max_length"===s?this.model_max_length:(0,i.max)(u.map((e=>e.input_ids.length)))[0]:r||console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation=true` to explicitly truncate examples to max length."),o=Math.min(o,this.model_max_length??1/0),s||r)for(let e=0;e<u.length;++e)u[e].input_ids.length!==o&&(u[e].input_ids.length>o?r&&Me(u[e],o):s&&we(u[e],o,(e=>"input_ids"===e?this.pad_token_id:0),this.padding_side));const p={};if(l){if((!s||!r)&&u.some((e=>{for(const t of Object.keys(e))if(e[t].length!==u[0][t]?.length)return!0;return!1})))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");const e=[u.length,u[0].input_ids.length];for(const t of Object.keys(u[0]))p[t]=new a.Tensor("int64",BigInt64Array.from(u.flatMap((e=>e[t])).map(BigInt)),e)}else{for(const e of Object.keys(u[0]))p[e]=u.map((t=>t[e]));if(!d)for(const e of Object.keys(p))p[e]=p[e][0]}return p}_encode_text(e){if(null===e)return null;const t=(this.added_tokens_regex?e.split(this.added_tokens_regex).filter((e=>e)):[e]).map(((e,t)=>{if(void 0!==this.added_tokens.find((t=>t.content===e)))return e;{if(!0===this.remove_space&&(e=e.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(e=function(e){return f(e.toLowerCase())}(e)),null!==this.normalizer&&(e=this.normalizer(e)),0===e.length)return[];const n=null!==this.pre_tokenizer?this.pre_tokenizer(e,{section_index:t}):[e];return this.model(n)}})).flat();return t}_encode_plus(e,{text_pair:t=null,add_special_tokens:n=!0,return_token_type_ids:s=null}={}){const{tokens:r,token_type_ids:o}=this._tokenize_helper(e,{pair:t,add_special_tokens:n}),i=this.model.convert_tokens_to_ids(r),a={input_ids:i,attention_mask:new Array(i.length).fill(1)};return(s??this.return_token_type_ids)&&o&&(a.token_type_ids=o),a}_tokenize_helper(e,{pair:t=null,add_special_tokens:n=!1}={}){const s=this._encode_text(e),o=this._encode_text(t);return this.post_processor?this.post_processor(s,o,{add_special_tokens:n}):{tokens:(0,r.mergeArrays)(s??[],o??[])}}tokenize(e,{pair:t=null,add_special_tokens:n=!1}={}){return this._tokenize_helper(e,{pair:t,add_special_tokens:n}).tokens}encode(e,{text_pair:t=null,add_special_tokens:n=!0,return_token_type_ids:s=null}={}){return this._encode_plus(e,{text_pair:t,add_special_tokens:n,return_token_type_ids:s}).input_ids}batch_decode(e,t={}){return e instanceof a.Tensor&&(e=e.tolist()),e.map((e=>this.decode(e,t)))}decode(e,t={}){if(e instanceof a.Tensor&&(e=_(e)),!Array.isArray(e)||0===e.length||!(0,r.isIntegralNumber)(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,t)}decode_single(e,{skip_special_tokens:t=!1,clean_up_tokenization_spaces:n=null}){let s=this.model.convert_ids_to_tokens(e);t&&(s=s.filter((e=>!this.special_tokens.includes(e))));let r=this.decoder?this.decoder(s):s.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(r=r.replaceAll(this.decoder.end_of_word_suffix," "),t&&(r=r.trim())),(n??this.clean_up_tokenization_spaces)&&(r=m(r)),r}get_chat_template({chat_template:e=null,tools:t=null}={}){if(this.chat_template&&"object"==typeof this.chat_template){const n=this.chat_template;if(null!==e&&Object.hasOwn(n,e))e=n[e];else if(null===e)if(null!==t&&"tool_use"in n)e=n.tool_use;else{if(!("default"in n))throw Error(`This model has multiple chat templates with no default specified! Please either pass a chat template or the name of the template you wish to use to the 'chat_template' argument. Available template names are ${Object.keys(n).sort()}.`);e=n.default}}else if(null===e){if(!this.chat_template)throw Error("Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating");e=this.chat_template}return e}apply_chat_template(e,{tools:t=null,documents:n=null,chat_template:s=null,add_generation_prompt:r=!1,tokenize:o=!0,padding:i=!1,truncation:a=!1,max_length:l=null,return_tensor:d=!0,return_dict:u=!1,tokenizer_kwargs:p={},...h}={}){if("string"!=typeof(s=this.get_chat_template({chat_template:s,tools:t})))throw Error("chat_template must be a string, but got "+typeof s);let _=this._compiled_template_cache.get(s);void 0===_&&(_=new c.Template(s),this._compiled_template_cache.set(s,_));const m=Object.create(null);for(const e of ge){const t=this.getToken(e);t&&(m[e]=t)}const f=_.render({messages:e,add_generation_prompt:r,tools:t,documents:n,...m,...h});if(o){const e=this._call(f,{add_special_tokens:!1,padding:i,truncation:a,max_length:l,return_tensor:d,...p});return u?e:e.input_ids}return f}}class ye extends be{return_token_type_ids=!0}class xe extends be{return_token_type_ids=!0}class ke extends be{return_token_type_ids=!0}class Te extends be{return_token_type_ids=!0}class ve extends be{return_token_type_ids=!0}class Fe extends be{return_token_type_ids=!0}class Ce extends be{return_token_type_ids=!0}class Pe extends be{return_token_type_ids=!0}class Se extends be{return_token_type_ids=!0}class Ae extends be{}class Ee extends be{}class ze extends be{return_token_type_ids=!0;constructor(e,t){super(e,t),console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}}class Le extends be{return_token_type_ids=!0}class Ie extends be{}class Be extends be{}class Ne extends be{}class Oe extends be{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))),this.lang_to_token=e=>e}_build_translation_inputs(e,t,n){return Ke(this,e,t,n)}}class je extends Oe{}class De extends be{}class Ve extends be{}const Re="▁";class Ge extends be{padding_side="left";constructor(e,t){super(e,t),this.legacy=t.legacy??!0,this.legacy||(this.normalizer=null,this.pre_tokenizer=new de({replacement:Re,add_prefix_space:!0,prepend_scheme:"first"}))}_encode_text(e){if(null===e)return null;if(this.legacy||0===e.length)return super._encode_text(e);let t=super._encode_text(Re+e.replaceAll(Re," "));return t.length>1&&t[0]===Re&&this.special_tokens.includes(t[1])&&(t=t.slice(1)),t}}class $e extends be{}class qe extends be{}class Ue extends be{}class We extends be{}class Xe extends be{}class Qe extends be{}class He extends be{}class Ye extends be{}class Je extends be{}function Ke(e,t,n,s){if(!("language_codes"in e)||!Array.isArray(e.language_codes))throw new Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!("languageRegex"in e&&e.languageRegex instanceof RegExp))throw new Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!("lang_to_token"in e)||"function"!=typeof e.lang_to_token)throw new Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");const r=s.src_lang,o=s.tgt_lang;if(!e.language_codes.includes(o))throw new Error(`Target language code "${o}" is not valid. Must be one of: {${e.language_codes.join(", ")}}`);if(void 0!==r){if(!e.language_codes.includes(r))throw new Error(`Source language code "${r}" is not valid. Must be one of: {${e.language_codes.join(", ")}}`);for(const t of e.post_processor.config.single)if("SpecialToken"in t&&e.languageRegex.test(t.SpecialToken.id)){t.SpecialToken.id=e.lang_to_token(r);break}}return s.forced_bos_token_id=e.model.convert_tokens_to_ids([e.lang_to_token(o)])[0],e._call(t,n)}class Ze extends be{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))),this.lang_to_token=e=>e}_build_translation_inputs(e,t,n){return Ke(this,e,t,n)}}class et extends be{constructor(e,t){super(e,t),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))).map((e=>e.slice(2,-2))),this.lang_to_token=e=>`__${e}__`}_build_translation_inputs(e,t,n){return Ke(this,e,t,n)}}class tt extends be{get timestamp_begin(){return this.model.convert_tokens_to_ids(["<|notimestamps|>"])[0]+1}_decode_asr(e,{return_timestamps:t=!1,return_language:n=!1,time_precision:s=null,force_full_sequences:r=!0}={}){if(null===s)throw Error("Must specify time_precision");let o=null;const a="word"===t;function l(){return{language:o,timestamp:[null,null],text:""}}const c=[];let u=l(),p=0;const h=this.timestamp_begin;let _=[],m=[],f=!1,g=null;const w=new Set(this.all_special_ids);for(const n of e){const e=n.tokens,r=a?n.token_timestamps:null;let b=null,y=h;if("stride"in n){const[t,r,o]=n.stride;if(p-=r,g=t-o,r&&(y=r/s+h),o)for(let t=e.length-1;t>=0;--t){const n=Number(e[t]);if(n>=h){if(null!==b&&(n-h)*s<g)break;b=n}}}let x=[],k=[];for(let n=0;n<e.length;++n){const g=Number(e[n]);if(w.has(g)){const e=this.decode([g]),n=d.WHISPER_LANGUAGE_MAPPING.get(e.slice(2,-2));if(void 0!==n){if(null!==o&&n!==o&&!t){_.push(x);const e=this.findLongestCommonSequence(_)[0],t=this.decode(e);u.text=t,c.push(u),_=[],x=[],u=l()}o=u.language=n}}else if(g>=h){const e=(g-h)*s+p,t=(0,i.round)(e,2);if(null!==b&&g>=b)f=!0;else if(f||_.length>0&&g<y)f=!1;else if(null===u.timestamp[0])u.timestamp[0]=t;else if(t===u.timestamp[0]);else{u.timestamp[1]=t,_.push(x),a&&m.push(k);const[e,n]=this.findLongestCommonSequence(_,m),s=this.decode(e);u.text=s,a&&(u.words=this.collateWordTimestamps(e,n,o)),c.push(u),_=[],x=[],m=[],k=[],u=l()}}else if(x.push(g),a){let e,t=(0,i.round)(r[n]+p,2);if(n+1<r.length){e=(0,i.round)(r[n+1]+p,2);const o=this.decode([g]);M.test(o)&&(e=(0,i.round)(Math.min(t+s,e),2))}else e=null;k.push([t,e])}}if("stride"in n){const[e,t,s]=n.stride;p+=e-s}x.length>0?(_.push(x),a&&m.push(k)):_.every((e=>0===e.length))&&(u=l(),_=[],x=[],m=[],k=[])}if(_.length>0){if(r&&t)throw new Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");const[e,n]=this.findLongestCommonSequence(_,m),s=this.decode(e);u.text=s,a&&(u.words=this.collateWordTimestamps(e,n,o)),c.push(u)}let b=Object.create(null);const y=c.map((e=>e.text)).join("");if(t||n){for(let e=0;e<c.length;++e){const s=c[e];t||delete s.timestamp,n||delete s.language}if(a){const e=[];for(const t of c)for(const n of t.words)e.push(n);b={chunks:e}}else b={chunks:c}}return[y,b]}findLongestCommonSequence(e,t=null){let n=e[0],s=n.length,r=[];const o=Array.isArray(t)&&t.length>0;let i=o?[]:null,a=o?t[0]:null;for(let l=1;l<e.length;++l){const c=e[l];let d=0,u=[s,s,0,0];const p=c.length;for(let e=1;e<s+p;++e){const r=Math.max(0,s-e),i=Math.min(s,s+p-e),h=n.slice(r,i),_=Math.max(0,e-s),m=Math.min(p,e),f=c.slice(_,m);if(h.length!==f.length)throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let g;g=o?h.filter(((e,n)=>e===f[n]&&a[r+n]<=t[l][_+n])).length:h.filter(((e,t)=>e===f[t])).length;const w=g/e+e/1e4;g>1&&w>d&&(d=w,u=[r,i,_,m])}const[h,_,m,f]=u,g=Math.floor((_+h)/2),w=Math.floor((f+m)/2);r.push(...n.slice(0,g)),n=c.slice(w),s=n.length,o&&(i.push(...a.slice(0,g)),a=t[l].slice(w))}return r.push(...n),o?(i.push(...a),[r,i]):[r,[]]}collateWordTimestamps(e,t,n){const[s,r,o]=this.combineTokensIntoWords(e,n),i=[];for(let e=0;e<s.length;++e){const n=o[e];i.push({text:s[e],timestamp:[t[n.at(0)][0],t[n.at(-1)][1]]})}return i}combineTokensIntoWords(e,t,n="\"'“¡¿([{-",s="\"'.。,,!!??::”)]}、"){let r,o,i;return["chinese","japanese","thai","lao","myanmar"].includes(t=t??"english")?[r,o,i]=this.splitTokensOnUnicode(e):[r,o,i]=this.splitTokensOnSpaces(e),this.mergePunctuations(r,o,i,n,s)}decode(e,t){let n;return t?.decode_with_timestamps?(e instanceof a.Tensor&&(e=_(e)),n=this.decodeWithTimestamps(e,t)):n=super.decode(e,t),n}decodeWithTimestamps(e,t){const n=t?.time_precision??.02,s=Array.from(this.all_special_ids).at(-1)+1;let r=[[]];for(let t of e)if(t=Number(t),t>=s){const e=((t-s)*n).toFixed(2);r.push(`<|${e}|>`),r.push([])}else r[r.length-1].push(t);return r=r.map((e=>"string"==typeof e?e:super.decode(e,t))),r.join("")}splitTokensOnUnicode(e){const t=this.decode(e,{decode_with_timestamps:!0}),n=[],s=[],r=[];let o=[],i=[],a=0;for(let l=0;l<e.length;++l){const c=e[l];o.push(c),i.push(l);const d=this.decode(o,{decode_with_timestamps:!0});d.includes("�")&&"�"!==t[a+d.indexOf("�")]||(n.push(d),s.push(o),r.push(i),o=[],i=[],a+=d.length)}return[n,s,r]}splitTokensOnSpaces(e){const[t,n,s]=this.splitTokensOnUnicode(e),r=[],o=[],i=[],a=new RegExp(`^[${w}]$`,"gu");for(let e=0;e<t.length;++e){const l=t[e],c=n[e],d=s[e],u=c[0]>=this.model.tokens_to_ids.get("<|endoftext|>"),p=l.startsWith(" "),h=l.trim(),_=a.test(h);if(u||p||_||0===r.length)r.push(l),o.push(c),i.push(d);else{const e=r.length-1;r[e]+=l,o[e].push(...c),i[e].push(...d)}}return[r,o,i]}mergePunctuations(e,t,n,s,o){const i=structuredClone(e),a=structuredClone(t),l=structuredClone(n);let c=i.length-2,d=i.length-1;for(;c>=0;)i[c].startsWith(" ")&&s.includes(i[c].trim())?(i[d]=i[c]+i[d],a[d]=(0,r.mergeArrays)(a[c],a[d]),l[d]=(0,r.mergeArrays)(l[c],l[d]),i[c]="",a[c]=[],l[c]=[]):d=c,--c;for(c=0,d=1;d<i.length;)!i[c].endsWith(" ")&&o.includes(i[d])?(i[c]+=i[d],a[c]=(0,r.mergeArrays)(a[c],a[d]),l[c]=(0,r.mergeArrays)(l[c],l[d]),i[d]="",a[d]=[],l[d]=[]):c=d,++d;return[i.filter((e=>e)),a.filter((e=>e.length>0)),l.filter((e=>e.length>0))]}}class nt extends be{}class st extends be{}class rt extends be{}class ot extends be{constructor(e,t){super(e,t),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=this.model.vocab.filter((e=>this.languageRegex.test(e))),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(null===e)return null;const[t,...n]=e.trim().split(this.languageRegex);if(0===n.length)return super._encode_text(t);if(2===n.length){const[e,t]=n;return this.supported_language_codes.includes(e)||console.warn(`Unsupported language code "${e}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),(0,r.mergeArrays)([e],super._encode_text(t))}}}class it extends be{}class at extends be{}class lt extends be{}class ct extends be{}class dt extends be{}class ut extends be{constructor(e,t){super(e,t),this.decoder=new ce({})}}class pt extends be{}class ht{static TOKENIZER_CLASS_MAPPING={T5Tokenizer:Ie,DistilBertTokenizer:Ae,CamembertTokenizer:Ee,DebertaTokenizer:ve,DebertaV2Tokenizer:Fe,BertTokenizer:ye,HerbertTokenizer:Ce,ConvBertTokenizer:Pe,RoFormerTokenizer:Se,XLMTokenizer:ze,ElectraTokenizer:Le,MobileBertTokenizer:ke,SqueezeBertTokenizer:Te,AlbertTokenizer:xe,GPT2Tokenizer:Be,BartTokenizer:Ne,MBartTokenizer:Oe,MBart50Tokenizer:je,RobertaTokenizer:De,WhisperTokenizer:tt,CodeGenTokenizer:nt,CLIPTokenizer:st,SiglipTokenizer:rt,MarianTokenizer:ot,BloomTokenizer:Ve,NllbTokenizer:Ze,M2M100Tokenizer:et,LlamaTokenizer:Ge,CodeLlamaTokenizer:$e,XLMRobertaTokenizer:qe,MPNetTokenizer:Ue,FalconTokenizer:We,GPTNeoXTokenizer:Xe,EsmTokenizer:Qe,Wav2Vec2CTCTokenizer:it,BlenderbotTokenizer:at,BlenderbotSmallTokenizer:lt,SpeechT5Tokenizer:ct,NougatTokenizer:dt,VitsTokenizer:ut,Qwen2Tokenizer:He,GemmaTokenizer:Ye,Grok1Tokenizer:Je,CohereTokenizer:pt,PreTrainedTokenizer:be};static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:s=null,local_files_only:r=!1,revision:o="main",legacy:i=null}={}){const[a,l]=await u(e,{progress_callback:t,config:n,cache_dir:s,local_files_only:r,revision:o,legacy:i}),c=l.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer";let d=this.TOKENIZER_CLASS_MAPPING[c];return d||(console.warn(`Unknown tokenizer class "${c}", attempting to construct from base class.`),d=be),new d(a,l)}}},"./src/utils/audio.js":
|
|
130
|
+
\***************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{AlbertTokenizer:()=>xe,AutoTokenizer:()=>ht,BartTokenizer:()=>Ne,BertTokenizer:()=>ye,BlenderbotSmallTokenizer:()=>lt,BlenderbotTokenizer:()=>at,BloomTokenizer:()=>Ve,CLIPTokenizer:()=>st,CamembertTokenizer:()=>Ee,CodeGenTokenizer:()=>nt,CodeLlamaTokenizer:()=>$e,CohereTokenizer:()=>pt,ConvBertTokenizer:()=>Pe,DebertaTokenizer:()=>ve,DebertaV2Tokenizer:()=>Fe,DistilBertTokenizer:()=>Ae,ElectraTokenizer:()=>ze,EsmTokenizer:()=>Qe,FalconTokenizer:()=>We,GPT2Tokenizer:()=>Be,GPTNeoXTokenizer:()=>Xe,GemmaTokenizer:()=>Ye,Grok1Tokenizer:()=>Je,HerbertTokenizer:()=>Ce,LlamaTokenizer:()=>Ge,M2M100Tokenizer:()=>et,MBart50Tokenizer:()=>je,MBartTokenizer:()=>Oe,MPNetTokenizer:()=>Ue,MarianTokenizer:()=>ot,MobileBertTokenizer:()=>ke,NllbTokenizer:()=>Ze,NougatTokenizer:()=>dt,PreTrainedTokenizer:()=>be,Qwen2Tokenizer:()=>He,RoFormerTokenizer:()=>Se,RobertaTokenizer:()=>De,SiglipTokenizer:()=>rt,SpeechT5Tokenizer:()=>ct,SqueezeBertTokenizer:()=>Te,T5Tokenizer:()=>Ie,TokenizerModel:()=>k,VitsTokenizer:()=>ut,Wav2Vec2CTCTokenizer:()=>it,WhisperTokenizer:()=>tt,XLMRobertaTokenizer:()=>qe,XLMTokenizer:()=>Le,is_chinese_char:()=>g});var s=n(/*! ./utils/generic.js */"./src/utils/generic.js"),r=n(/*! ./utils/core.js */"./src/utils/core.js"),o=n(/*! ./utils/hub.js */"./src/utils/hub.js"),i=n(/*! ./utils/maths.js */"./src/utils/maths.js"),a=n(/*! ./utils/tensor.js */"./src/utils/tensor.js"),l=n(/*! ./utils/data-structures.js */"./src/utils/data-structures.js"),c=n(/*! @huggingface/jinja */"./node_modules/@huggingface/jinja/dist/index.js"),d=n(/*! ./models/whisper/common_whisper.js */"./src/models/whisper/common_whisper.js");n(/*! ./utils/constants.js */"./src/utils/constants.js");async function u(e,t){const n=await Promise.all([(0,o.getModelJSON)(e,"tokenizer.json",!0,t),(0,o.getModelJSON)(e,"tokenizer_config.json",!0,t)]);return null!==t.legacy&&(n[1].legacy=t.legacy),n}function p(e,t=!0){if(void 0!==e.Regex){let t=e.Regex.replace(/\\([#&~])/g,"$1");for(const[e,n]of y)t=t.replaceAll(e,n);return new RegExp(t,"gu")}if(void 0!==e.String){const n=(0,r.escapeRegExp)(e.String);return new RegExp(t?n:`(${n})`,"gu")}return console.warn("Unknown pattern type:",e),null}function h(e){return new Map(Object.entries(e))}function _(e){const t=e.dims;switch(t.length){case 1:return e.tolist();case 2:if(1!==t[0])throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return e.tolist()[0];default:throw new Error(`Expected tensor to have 1-2 dimensions, got ${t.length}.`)}}function m(e){return e.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n\'t/g,"n't").replace(/ \'m/g,"'m").replace(/ \'s/g,"'s").replace(/ \'ve/g,"'ve").replace(/ \'re/g,"'re")}function f(e){return e.replace(/\p{M}/gu,"")}function g(e){return e>=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=173824&&e<=177983||e>=177984&&e<=178207||e>=178208&&e<=183983||e>=63744&&e<=64255||e>=194560&&e<=195103}const w="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",M=new RegExp(`^[${w}]+$`,"gu"),b=".,!?…。,、।۔،",y=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"],[` ?[^(\\s|[${b}])]+`,` ?[^\\s${b}]+`]]);class x{constructor(e){this.content=e.content,this.id=e.id,this.single_word=e.single_word??!1,this.lstrip=e.lstrip??!1,this.rstrip=e.rstrip??!1,this.special=e.special??!1,this.normalized=e.normalized??null}}class k extends s.Callable{constructor(e){super(),this.config=e,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}static fromConfig(e,...t){switch(e.type){case"WordPiece":return new T(e);case"Unigram":return new v(e,...t);case"BPE":return new P(e);default:if(e.vocab)return Array.isArray(e.vocab)?new v(e,...t):new S(e,...t);throw new Error(`Unknown TokenizerModel type: ${e.type}`)}}_call(e){return e=this.encode(e),this.fuse_unk&&(e=function(e,t,n){const s=[];let r=0;for(;r<e.length;)if(s.push(e[r]),(t.get(e[r])??n)===n)for(;++r<e.length&&(t.get(e[r])??n)===n;)t.get(s.at(-1))!==n&&(s[s.length-1]+=e[r]);else++r;return s}(e,this.tokens_to_ids,this.unk_token_id)),e}encode(e){throw Error("encode should be implemented in subclass.")}convert_tokens_to_ids(e){return e.map((e=>this.tokens_to_ids.get(e)??this.unk_token_id))}convert_ids_to_tokens(e){return e.map((e=>this.vocab[e]??this.unk_token))}}class T extends k{constructor(e){super(e),this.tokens_to_ids=h(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.max_input_chars_per_word=e.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e}encode(e){const t=[];for(const n of e){const e=[...n];if(e.length>this.max_input_chars_per_word){t.push(this.unk_token);continue}let s=!1,r=0;const o=[];for(;r<e.length;){let t=e.length,n=null;for(;r<t;){let s=e.slice(r,t).join("");if(r>0&&(s=this.config.continuing_subword_prefix+s),this.tokens_to_ids.has(s)){n=s;break}--t}if(null===n){s=!0;break}o.push(n),r=t}s?t.push(this.unk_token):t.push(...o)}return t}}class v extends k{constructor(e,t){super(e);const n=e.vocab.length;this.vocab=new Array(n),this.scores=new Array(n);for(let t=0;t<n;++t){const n=e.vocab[t];this.vocab[t]=n[0],this.scores[t]=n[1]}this.unk_token_id=e.unk_id,this.unk_token=this.vocab[e.unk_id],this.tokens_to_ids=new Map(this.vocab.map(((e,t)=>[e,t]))),this.bos_token=" ",this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=t.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.unk_token=this.vocab[this.unk_token_id],this.minScore=(0,i.min)(this.scores)[0],this.unk_score=this.minScore-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new l.CharTrie,this.trie.extend(this.vocab),this.fuse_unk=!0}populateNodes(e){const t=e.chars;let n=0;for(;n<t.length;){let s=!1;const o=[],i=t.slice(n).join(""),a=this.trie.commonPrefixSearch(i);for(const t of a){o.push(t);const i=this.tokens_to_ids.get(t),a=this.scores[i],l=(0,r.len)(t);e.insert(n,l,a,i),s||1!==l||(s=!0)}s||e.insert(n,1,this.unk_score,this.unk_token_id),n+=1}}tokenize(e){const t=new l.TokenLattice(e,this.bos_token_id,this.eos_token_id);return this.populateNodes(t),t.tokens()}encode(e){const t=[];for(const n of e){const e=this.tokenize(n);t.push(...e)}return t}}const F=(()=>{const e=[...Array.from({length:"~".charCodeAt(0)-"!".charCodeAt(0)+1},((e,t)=>t+"!".charCodeAt(0))),...Array.from({length:"¬".charCodeAt(0)-"¡".charCodeAt(0)+1},((e,t)=>t+"¡".charCodeAt(0))),...Array.from({length:"ÿ".charCodeAt(0)-"®".charCodeAt(0)+1},((e,t)=>t+"®".charCodeAt(0)))],t=e.slice();let n=0;for(let s=0;s<256;++s)e.includes(s)||(e.push(s),t.push(256+n),n+=1);const s=t.map((e=>String.fromCharCode(e)));return Object.fromEntries(e.map(((e,t)=>[e,s[t]])))})(),C=(0,r.reverseDictionary)(F);class P extends k{constructor(e){super(e),this.tokens_to_ids=h(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e;const t=Array.isArray(e.merges[0]);this.merges=t?e.merges:e.merges.map((e=>e.split(" ",2))),this.bpe_ranks=new Map(this.merges.map(((e,t)=>[JSON.stringify(e),t]))),this.end_of_word_suffix=e.end_of_word_suffix,this.continuing_subword_suffix=e.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.ignore_merges=this.config.ignore_merges??!1,this.cache=new Map}bpe(e){if(0===e.length)return[];const t=this.cache.get(e);if(void 0!==t)return t;const n=Array.from(e);this.end_of_word_suffix&&(n[n.length-1]+=this.end_of_word_suffix);let s=[];if(n.length>1){const e=new l.PriorityQueue(((e,t)=>e.score<t.score));let t={token:n[0],bias:0,prev:null,next:null},r=t;for(let t=1;t<n.length;++t){const s={bias:t/n.length,token:n[t],prev:r,next:null};r.next=s,this._add_node(e,r),r=s}for(;!e.isEmpty();){const n=e.pop();if(n.deleted||!n.next||n.next.deleted)continue;if(n.deleted=!0,n.next.deleted=!0,n.prev){const e={...n.prev};n.prev.deleted=!0,n.prev=e,e.prev?e.prev.next=e:t=e}const s={token:n.token+n.next.token,bias:n.bias,prev:n.prev,next:n.next.next};s.prev?(s.prev.next=s,this._add_node(e,s.prev)):t=s,s.next&&(s.next.prev=s,this._add_node(e,s))}for(let e=t;null!==e;e=e.next)s.push(e.token)}else s=n;if(this.continuing_subword_suffix)for(let e=0;e<s.length-1;++e)s[e]+=this.continuing_subword_suffix;return this.cache.set(e,s),s}_add_node(e,t){const n=this.bpe_ranks.get(JSON.stringify([t.token,t.next.token]));void 0!==n&&(t.score=n+t.bias,e.push(t))}encode(e){const t=[];for(const n of e){if(this.ignore_merges&&this.tokens_to_ids.has(n)){t.push(n);continue}const e=this.bpe(n);for(const n of e)if(this.tokens_to_ids.has(n))t.push(n);else if(this.byte_fallback){const e=Array.from(this.text_encoder.encode(n)).map((e=>`<0x${e.toString(16).toUpperCase().padStart(2,"0")}>`));e.every((e=>this.tokens_to_ids.has(e)))?t.push(...e):t.push(this.unk_token)}else t.push(this.unk_token)}return t}}class S extends k{constructor(e,t){super(e),this.tokens_to_ids=h(t.target_lang?e.vocab[t.target_lang]:e.vocab),this.bos_token=t.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=t.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=t.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=t.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(const[e,t]of this.tokens_to_ids)this.vocab[t]=e}encode(e){return e}}class A extends s.Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(null===e)return null;switch(e.type){case"BertNormalizer":return new V(e);case"Precompiled":return new pe(e);case"Sequence":return new D(e);case"Replace":return new E(e);case"NFC":return new L(e);case"NFKC":return new z(e);case"NFKD":return new I(e);case"Strip":return new B(e);case"StripAccents":return new N(e);case"Lowercase":return new O(e);case"Prepend":return new j(e);default:throw new Error(`Unknown Normalizer type: ${e.type}`)}}normalize(e){throw Error("normalize should be implemented in subclass.")}_call(e){return this.normalize(e)}}class E extends A{normalize(e){const t=p(this.config.pattern);return null===t?e:e.replaceAll(t,this.config.content)}}class L extends A{normalize(e){return e=e.normalize("NFC")}}class z extends A{normalize(e){return e=e.normalize("NFKC")}}class I extends A{normalize(e){return e=e.normalize("NFKD")}}class B extends A{normalize(e){return this.config.strip_left&&this.config.strip_right?e=e.trim():(this.config.strip_left&&(e=e.trimStart()),this.config.strip_right&&(e=e.trimEnd())),e}}class N extends A{normalize(e){return e=f(e)}}class O extends A{normalize(e){return e=e.toLowerCase()}}class j extends A{normalize(e){return e=this.config.prepend+e}}class D extends A{constructor(e){super(e),this.normalizers=e.normalizers.map((e=>A.fromConfig(e)))}normalize(e){return this.normalizers.reduce(((e,t)=>t.normalize(e)),e)}}class V extends A{_tokenize_chinese_chars(e){const t=[];for(let n=0;n<e.length;++n){const s=e[n];g(s.charCodeAt(0))?(t.push(" "),t.push(s),t.push(" ")):t.push(s)}return t.join("")}stripAccents(e){return e.normalize("NFD").replace(/\p{Mn}/gu,"")}_is_control(e){switch(e){case"\t":case"\n":case"\r":return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(e)}}_clean_text(e){const t=[];for(const n of e){const e=n.charCodeAt(0);0===e||65533===e||this._is_control(n)||(/^\s$/.test(n)?t.push(" "):t.push(n))}return t.join("")}normalize(e){return this.config.clean_text&&(e=this._clean_text(e)),this.config.handle_chinese_chars&&(e=this._tokenize_chinese_chars(e)),this.config.lowercase?(e=e.toLowerCase(),!1!==this.config.strip_accents&&(e=this.stripAccents(e))):this.config.strip_accents&&(e=this.stripAccents(e)),e}}class R extends s.Callable{static fromConfig(e){if(null===e)return null;switch(e.type){case"BertPreTokenizer":return new G(e);case"Sequence":return new he(e);case"Whitespace":return new _e(e);case"WhitespaceSplit":return new me(e);case"Metaspace":return new de(e);case"ByteLevel":return new $(e);case"Split":return new q(e);case"Punctuation":return new U(e);case"Digits":return new W(e);case"Replace":return new fe(e);default:throw new Error(`Unknown PreTokenizer type: ${e.type}`)}}pre_tokenize_text(e,t){throw Error("pre_tokenize_text should be implemented in subclass.")}pre_tokenize(e,t){return(Array.isArray(e)?e.map((e=>this.pre_tokenize_text(e,t))):this.pre_tokenize_text(e,t)).flat()}_call(e,t){return this.pre_tokenize(e,t)}}class G extends R{constructor(e){super(),this.pattern=new RegExp(`[^\\s${w}]+|[${w}]`,"gu")}pre_tokenize_text(e,t){return e.trim().match(this.pattern)||[]}}class $ extends R{constructor(e){super(),this.config=e,this.add_prefix_space=this.config.add_prefix_space,this.trim_offsets=this.config.trim_offsets,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=F,this.text_encoder=new TextEncoder}pre_tokenize_text(e,t){this.add_prefix_space&&!e.startsWith(" ")&&(e=" "+e);return(this.use_regex?e.match(this.pattern)||[]:[e]).map((e=>Array.from(this.text_encoder.encode(e),(e=>this.byte_encoder[e])).join("")))}}class q extends R{constructor(e){super(),this.config=e,this.pattern=p(this.config.pattern,this.config.invert)}pre_tokenize_text(e,t){return null===this.pattern?[]:this.config.invert?e.match(this.pattern)||[]:function(e,t){const n=[];let s=0;for(const r of e.matchAll(t)){const t=r[0];s<r.index&&n.push(e.slice(s,r.index)),t.length>0&&n.push(t),s=r.index+t.length}return s<e.length&&n.push(e.slice(s)),n}(e,this.pattern)}}class U extends R{constructor(e){super(),this.config=e,this.pattern=new RegExp(`[^${w}]+|[${w}]+`,"gu")}pre_tokenize_text(e,t){return e.match(this.pattern)||[]}}class W extends R{constructor(e){super(),this.config=e;const t="[^\\d]+|\\d"+(this.config.individual_digits?"":"+");this.pattern=new RegExp(t,"gu")}pre_tokenize_text(e,t){return e.match(this.pattern)||[]}}class X extends s.Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(null===e)return null;switch(e.type){case"TemplateProcessing":return new Y(e);case"ByteLevel":return new J(e);case"RobertaProcessing":return new H(e);case"BertProcessing":return new Q(e);case"Sequence":return new K(e);default:throw new Error(`Unknown PostProcessor type: ${e.type}`)}}post_process(e,...t){throw Error("post_process should be implemented in subclass.")}_call(e,...t){return this.post_process(e,...t)}}class Q extends X{constructor(e){super(e),this.cls=e.cls[0],this.sep=e.sep[0]}post_process(e,t=null,{add_special_tokens:n=!0}={}){n&&(e=(0,r.mergeArrays)([this.cls],e,[this.sep]));let s=new Array(e.length).fill(0);if(null!==t){const o=n&&this instanceof H?[this.sep]:[],i=n?[this.sep]:[];e=(0,r.mergeArrays)(e,o,t,i),s=(0,r.mergeArrays)(s,new Array(t.length+o.length+i.length).fill(1))}return{tokens:e,token_type_ids:s}}}class H extends Q{}class Y extends X{constructor(e){super(e),this.single=e.single,this.pair=e.pair}post_process(e,t=null,{add_special_tokens:n=!0}={}){const s=null===t?this.single:this.pair;let o=[],i=[];for(const a of s)"SpecialToken"in a?n&&(o.push(a.SpecialToken.id),i.push(a.SpecialToken.type_id)):"Sequence"in a&&("A"===a.Sequence.id?(o=(0,r.mergeArrays)(o,e),i=(0,r.mergeArrays)(i,new Array(e.length).fill(a.Sequence.type_id))):"B"===a.Sequence.id&&(o=(0,r.mergeArrays)(o,t),i=(0,r.mergeArrays)(i,new Array(t.length).fill(a.Sequence.type_id))));return{tokens:o,token_type_ids:i}}}class J extends X{post_process(e,t=null){return t&&(e=(0,r.mergeArrays)(e,t)),{tokens:e}}}class K extends X{constructor(e){super(e),this.processors=e.processors.map((e=>X.fromConfig(e)))}post_process(e,t=null,n={}){let s;for(const r of this.processors)if(r instanceof J){if(e=r.post_process(e).tokens,t){t=r.post_process(t).tokens}}else{const o=r.post_process(e,t,n);e=o.tokens,s=o.token_type_ids}return{tokens:e,token_type_ids:s}}}class Z extends s.Callable{constructor(e){super(),this.config=e,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets=e.trim_offsets}static fromConfig(e){if(null===e)return null;switch(e.type){case"WordPiece":return new re(e);case"Metaspace":return new ue(e);case"ByteLevel":return new oe(e);case"Replace":return new ee(e);case"ByteFallback":return new te(e);case"Fuse":return new ne(e);case"Strip":return new se(e);case"Sequence":return new ae(e);case"CTC":return new ie(e);case"BPEDecoder":return new le(e);default:throw new Error(`Unknown Decoder type: ${e.type}`)}}_call(e){return this.decode(e)}decode(e){return this.decode_chain(e).join("")}decode_chain(e){throw Error("`decode_chain` should be implemented in subclass.")}}class ee extends Z{decode_chain(e){const t=p(this.config.pattern);return null===t?e:e.map((e=>e.replaceAll(t,this.config.content)))}}class te extends Z{constructor(e){super(e),this.text_decoder=new TextDecoder}decode_chain(e){const t=[];let n=[];for(const s of e){let e=null;if(6===s.length&&s.startsWith("<0x")&&s.endsWith(">")){const t=parseInt(s.slice(3,5),16);isNaN(t)||(e=t)}if(null!==e)n.push(e);else{if(n.length>0){const e=this.text_decoder.decode(Uint8Array.from(n));t.push(e),n=[]}t.push(s)}}if(n.length>0){const e=this.text_decoder.decode(Uint8Array.from(n));t.push(e),n=[]}return t}}class ne extends Z{decode_chain(e){return[e.join("")]}}class se extends Z{constructor(e){super(e),this.content=this.config.content,this.start=this.config.start,this.stop=this.config.stop}decode_chain(e){return e.map((e=>{let t=0;for(let n=0;n<this.start&&e[n]===this.content;++n)t=n+1;let n=e.length;for(let t=0;t<this.stop;++t){const s=e.length-t-1;if(e[s]!==this.content)break;n=s}return e.slice(t,n)}))}}class re extends Z{constructor(e){super(e),this.cleanup=e.cleanup}decode_chain(e){return e.map(((e,t)=>(0!==t&&(e=e.startsWith(this.config.prefix)?e.replace(this.config.prefix,""):" "+e),this.cleanup&&(e=m(e)),e)))}}class oe extends Z{constructor(e){super(e),this.byte_decoder=C,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(e){const t=e.join(""),n=new Uint8Array([...t].map((e=>this.byte_decoder[e])));return this.text_decoder.decode(n)}decode_chain(e){const t=[];let n=[];for(const s of e)void 0!==this.added_tokens.find((e=>e.content===s))?(n.length>0&&(t.push(this.convert_tokens_to_string(n)),n=[]),t.push(s)):n.push(s);return n.length>0&&t.push(this.convert_tokens_to_string(n)),t}}class ie extends Z{constructor(e){super(e),this.pad_token=this.config.pad_token,this.word_delimiter_token=this.config.word_delimiter_token,this.cleanup=this.config.cleanup}convert_tokens_to_string(e){if(0===e.length)return"";const t=[e[0]];for(let n=1;n<e.length;++n)e[n]!==t.at(-1)&&t.push(e[n]);let n=t.filter((e=>e!==this.pad_token)).join("");return this.cleanup&&(n=m(n).replaceAll(this.word_delimiter_token," ").trim()),n}decode_chain(e){return[this.convert_tokens_to_string(e)]}}class ae extends Z{constructor(e){super(e),this.decoders=e.decoders.map((e=>Z.fromConfig(e)))}decode_chain(e){return this.decoders.reduce(((e,t)=>t.decode_chain(e)),e)}}class le extends Z{constructor(e){super(e),this.suffix=this.config.suffix}decode_chain(e){return e.map(((t,n)=>t.replaceAll(this.suffix,n===e.length-1?"":" ")))}}class ce extends Z{decode_chain(e){let t="";for(let n=1;n<e.length;n+=2)t+=e[n];return[t]}}class de extends R{constructor(e){super(),this.addPrefixSpace=e.add_prefix_space,this.replacement=e.replacement,this.strRep=e.str_rep||this.replacement,this.prepend_scheme=e.prepend_scheme??"always"}pre_tokenize_text(e,{section_index:t}={}){let n=e.replaceAll(" ",this.strRep);return this.addPrefixSpace&&!n.startsWith(this.replacement)&&("always"===this.prepend_scheme||"first"===this.prepend_scheme&&0===t)&&(n=this.strRep+n),[n]}}class ue extends Z{constructor(e){super(e),this.addPrefixSpace=e.add_prefix_space,this.replacement=e.replacement}decode_chain(e){const t=[];for(let n=0;n<e.length;++n){let s=e[n].replaceAll(this.replacement," ");this.addPrefixSpace&&0==n&&s.startsWith(" ")&&(s=s.substring(1)),t.push(s)}return t}}class pe extends A{constructor(e){super(e),this.charsmap=e.precompiled_charsmap}normalize(e){if((e=(e=e.replace(/[\u0001-\u0008\u000B\u000E-\u001F\u007F\u008F\u009F]/gm,"")).replace(/[\u0009\u000A\u000C\u000D\u00A0\u1680\u2000-\u200F\u2028\u2029\u202F\u205F\u2581\u3000\uFEFF\uFFFD]/gm," ")).includes("~")){const t=e.split("~");e=t.map((e=>e.normalize("NFKC"))).join("~")}else e=e.normalize("NFKC");return e}}class he extends R{constructor(e){super(),this.tokenizers=e.pretokenizers.map((e=>R.fromConfig(e)))}pre_tokenize_text(e,t){return this.tokenizers.reduce(((e,n)=>n.pre_tokenize(e,t)),[e])}}class _e extends R{constructor(e){super()}pre_tokenize_text(e,t){return e.match(/\w+|[^\w\s]+/g)||[]}}class me extends R{constructor(e){super()}pre_tokenize_text(e,t){return function(e){return e.match(/\S+/g)||[]}(e)}}class fe extends R{constructor(e){super(),this.config=e,this.pattern=p(this.config.pattern),this.content=this.config.content}pre_tokenize_text(e,t){return null===this.pattern?[e]:[e.replaceAll(this.pattern,this.config.content)]}}const ge=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function we(e,t,n,s){for(const o of Object.keys(e)){const i=t-e[o].length,a=n(o),l=new Array(i).fill(a);e[o]="right"===s?(0,r.mergeArrays)(e[o],l):(0,r.mergeArrays)(l,e[o])}}function Me(e,t){for(const n of Object.keys(e))e[n].length=t}class be extends s.Callable{return_token_type_ids=!1;padding_side="right";constructor(e,t){super(),this._tokenizer_config=t,this.normalizer=A.fromConfig(e.normalizer),this.pre_tokenizer=R.fromConfig(e.pre_tokenizer),this.model=k.fromConfig(e.model,t),this.post_processor=X.fromConfig(e.post_processor),this.decoder=Z.fromConfig(e.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];for(const t of e.added_tokens){const e=new x(t);this.added_tokens.push(e),this.model.tokens_to_ids.set(e.content,e.id),this.model.vocab[e.id]=e.content,e.special&&(this.special_tokens.push(e.content),this.all_special_ids.push(e.id))}if(this.additional_special_tokens=t.additional_special_tokens??[],this.special_tokens.push(...this.additional_special_tokens),this.special_tokens=[...new Set(this.special_tokens)],this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.added_tokens_regex=this.added_tokens.length>0?new RegExp(this.added_tokens.slice().sort(((e,t)=>t.content.length-e.content.length)).map((e=>`${e.lstrip?"\\s*":""}(${(0,r.escapeRegExp)(e.content)})${e.rstrip?"\\s*":""}`)).join("|")):null,this.mask_token=this.getToken("mask_token"),this.mask_token_id=this.model.tokens_to_ids.get(this.mask_token),this.pad_token=this.getToken("pad_token","eos_token"),this.pad_token_id=this.model.tokens_to_ids.get(this.pad_token),this.sep_token=this.getToken("sep_token"),this.sep_token_id=this.model.tokens_to_ids.get(this.sep_token),this.unk_token=this.getToken("unk_token"),this.unk_token_id=this.model.tokens_to_ids.get(this.unk_token),this.model_max_length=t.model_max_length,this.remove_space=t.remove_space,this.clean_up_tokenization_spaces=t.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=t.do_lowercase_and_remove_accent??!1,t.padding_side&&(this.padding_side=t.padding_side),this.legacy=!1,this.chat_template=t.chat_template??null,Array.isArray(this.chat_template)){const e=Object.create(null);for(const{name:t,template:n}of this.chat_template){if("string"!=typeof t||"string"!=typeof n)throw new Error('Chat template must be a list of objects with "name" and "template" properties');e[t]=n}this.chat_template=e}this._compiled_template_cache=new Map}getToken(...e){for(const t of e){const e=this._tokenizer_config[t];if(e){if("object"==typeof e){if("AddedToken"===e.__type)return e.content;throw Error(`Unknown token: ${e}`)}return e}}return null}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:s=null,local_files_only:r=!1,revision:o="main",legacy:i=null}={}){return new this(...await u(e,{progress_callback:t,config:n,cache_dir:s,local_files_only:r,revision:o,legacy:i}))}_call(e,{text_pair:t=null,add_special_tokens:n=!0,padding:s=!1,truncation:r=null,max_length:o=null,return_tensor:l=!0,return_token_type_ids:c=null}={}){const d=Array.isArray(e);let u;if(d){if(0===e.length)throw Error("text array must be non-empty");if(null!==t){if(!Array.isArray(t))throw Error("text_pair must also be an array");if(e.length!==t.length)throw Error("text and text_pair must have the same length");u=e.map(((e,s)=>this._encode_plus(e,{text_pair:t[s],add_special_tokens:n,return_token_type_ids:c})))}else u=e.map((e=>this._encode_plus(e,{add_special_tokens:n,return_token_type_ids:c})))}else{if(null==e)throw Error("text may not be null or undefined");if(Array.isArray(t))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");u=[this._encode_plus(e,{text_pair:t,add_special_tokens:n,return_token_type_ids:c})]}if(null===o?o="max_length"===s?this.model_max_length:(0,i.max)(u.map((e=>e.input_ids.length)))[0]:r||console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation=true` to explicitly truncate examples to max length."),o=Math.min(o,this.model_max_length??1/0),s||r)for(let e=0;e<u.length;++e)u[e].input_ids.length!==o&&(u[e].input_ids.length>o?r&&Me(u[e],o):s&&we(u[e],o,(e=>"input_ids"===e?this.pad_token_id:0),this.padding_side));const p={};if(l){if((!s||!r)&&u.some((e=>{for(const t of Object.keys(e))if(e[t].length!==u[0][t]?.length)return!0;return!1})))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");const e=[u.length,u[0].input_ids.length];for(const t of Object.keys(u[0]))p[t]=new a.Tensor("int64",BigInt64Array.from(u.flatMap((e=>e[t])).map(BigInt)),e)}else{for(const e of Object.keys(u[0]))p[e]=u.map((t=>t[e]));if(!d)for(const e of Object.keys(p))p[e]=p[e][0]}return p}_encode_text(e){if(null===e)return null;const t=(this.added_tokens_regex?e.split(this.added_tokens_regex).filter((e=>e)):[e]).map(((e,t)=>{if(void 0!==this.added_tokens.find((t=>t.content===e)))return e;{if(!0===this.remove_space&&(e=e.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(e=function(e){return f(e.toLowerCase())}(e)),null!==this.normalizer&&(e=this.normalizer(e)),0===e.length)return[];const n=null!==this.pre_tokenizer?this.pre_tokenizer(e,{section_index:t}):[e];return this.model(n)}})).flat();return t}_encode_plus(e,{text_pair:t=null,add_special_tokens:n=!0,return_token_type_ids:s=null}={}){const{tokens:r,token_type_ids:o}=this._tokenize_helper(e,{pair:t,add_special_tokens:n}),i=this.model.convert_tokens_to_ids(r),a={input_ids:i,attention_mask:new Array(i.length).fill(1)};return(s??this.return_token_type_ids)&&o&&(a.token_type_ids=o),a}_tokenize_helper(e,{pair:t=null,add_special_tokens:n=!1}={}){const s=this._encode_text(e),o=this._encode_text(t);return this.post_processor?this.post_processor(s,o,{add_special_tokens:n}):{tokens:(0,r.mergeArrays)(s??[],o??[])}}tokenize(e,{pair:t=null,add_special_tokens:n=!1}={}){return this._tokenize_helper(e,{pair:t,add_special_tokens:n}).tokens}encode(e,{text_pair:t=null,add_special_tokens:n=!0,return_token_type_ids:s=null}={}){return this._encode_plus(e,{text_pair:t,add_special_tokens:n,return_token_type_ids:s}).input_ids}batch_decode(e,t={}){return e instanceof a.Tensor&&(e=e.tolist()),e.map((e=>this.decode(e,t)))}decode(e,t={}){if(e instanceof a.Tensor&&(e=_(e)),!Array.isArray(e)||0===e.length||!(0,r.isIntegralNumber)(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,t)}decode_single(e,{skip_special_tokens:t=!1,clean_up_tokenization_spaces:n=null}){let s=this.model.convert_ids_to_tokens(e);t&&(s=s.filter((e=>!this.special_tokens.includes(e))));let r=this.decoder?this.decoder(s):s.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(r=r.replaceAll(this.decoder.end_of_word_suffix," "),t&&(r=r.trim())),(n??this.clean_up_tokenization_spaces)&&(r=m(r)),r}get_chat_template({chat_template:e=null,tools:t=null}={}){if(this.chat_template&&"object"==typeof this.chat_template){const n=this.chat_template;if(null!==e&&Object.hasOwn(n,e))e=n[e];else if(null===e)if(null!==t&&"tool_use"in n)e=n.tool_use;else{if(!("default"in n))throw Error(`This model has multiple chat templates with no default specified! Please either pass a chat template or the name of the template you wish to use to the 'chat_template' argument. Available template names are ${Object.keys(n).sort()}.`);e=n.default}}else if(null===e){if(!this.chat_template)throw Error("Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating");e=this.chat_template}return e}apply_chat_template(e,{tools:t=null,documents:n=null,chat_template:s=null,add_generation_prompt:r=!1,tokenize:o=!0,padding:i=!1,truncation:a=!1,max_length:l=null,return_tensor:d=!0,return_dict:u=!1,tokenizer_kwargs:p={},...h}={}){if("string"!=typeof(s=this.get_chat_template({chat_template:s,tools:t})))throw Error("chat_template must be a string, but got "+typeof s);let _=this._compiled_template_cache.get(s);void 0===_&&(_=new c.Template(s),this._compiled_template_cache.set(s,_));const m=Object.create(null);for(const e of ge){const t=this.getToken(e);t&&(m[e]=t)}const f=_.render({messages:e,add_generation_prompt:r,tools:t,documents:n,...m,...h});if(o){const e=this._call(f,{add_special_tokens:!1,padding:i,truncation:a,max_length:l,return_tensor:d,...p});return u?e:e.input_ids}return f}}class ye extends be{return_token_type_ids=!0}class xe extends be{return_token_type_ids=!0}class ke extends be{return_token_type_ids=!0}class Te extends be{return_token_type_ids=!0}class ve extends be{return_token_type_ids=!0}class Fe extends be{return_token_type_ids=!0}class Ce extends be{return_token_type_ids=!0}class Pe extends be{return_token_type_ids=!0}class Se extends be{return_token_type_ids=!0}class Ae extends be{}class Ee extends be{}class Le extends be{return_token_type_ids=!0;constructor(e,t){super(e,t),console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}}class ze extends be{return_token_type_ids=!0}class Ie extends be{}class Be extends be{}class Ne extends be{}class Oe extends be{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))),this.lang_to_token=e=>e}_build_translation_inputs(e,t,n){return Ke(this,e,t,n)}}class je extends Oe{}class De extends be{}class Ve extends be{}const Re="▁";class Ge extends be{padding_side="left";constructor(e,t){super(e,t),this.legacy=t.legacy??!0,this.legacy||(this.normalizer=null,this.pre_tokenizer=new de({replacement:Re,add_prefix_space:!0,prepend_scheme:"first"}))}_encode_text(e){if(null===e)return null;if(this.legacy||0===e.length)return super._encode_text(e);let t=super._encode_text(Re+e.replaceAll(Re," "));return t.length>1&&t[0]===Re&&this.special_tokens.includes(t[1])&&(t=t.slice(1)),t}}class $e extends be{}class qe extends be{}class Ue extends be{}class We extends be{}class Xe extends be{}class Qe extends be{}class He extends be{}class Ye extends be{}class Je extends be{}function Ke(e,t,n,s){if(!("language_codes"in e)||!Array.isArray(e.language_codes))throw new Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!("languageRegex"in e&&e.languageRegex instanceof RegExp))throw new Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!("lang_to_token"in e)||"function"!=typeof e.lang_to_token)throw new Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");const r=s.src_lang,o=s.tgt_lang;if(!e.language_codes.includes(o))throw new Error(`Target language code "${o}" is not valid. Must be one of: {${e.language_codes.join(", ")}}`);if(void 0!==r){if(!e.language_codes.includes(r))throw new Error(`Source language code "${r}" is not valid. Must be one of: {${e.language_codes.join(", ")}}`);for(const t of e.post_processor.config.single)if("SpecialToken"in t&&e.languageRegex.test(t.SpecialToken.id)){t.SpecialToken.id=e.lang_to_token(r);break}}return s.forced_bos_token_id=e.model.convert_tokens_to_ids([e.lang_to_token(o)])[0],e._call(t,n)}class Ze extends be{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))),this.lang_to_token=e=>e}_build_translation_inputs(e,t,n){return Ke(this,e,t,n)}}class et extends be{constructor(e,t){super(e,t),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.special_tokens.filter((e=>this.languageRegex.test(e))).map((e=>e.slice(2,-2))),this.lang_to_token=e=>`__${e}__`}_build_translation_inputs(e,t,n){return Ke(this,e,t,n)}}class tt extends be{get timestamp_begin(){return this.model.convert_tokens_to_ids(["<|notimestamps|>"])[0]+1}_decode_asr(e,{return_timestamps:t=!1,return_language:n=!1,time_precision:s=null,force_full_sequences:r=!0}={}){if(null===s)throw Error("Must specify time_precision");let o=null;const a="word"===t;function l(){return{language:o,timestamp:[null,null],text:""}}const c=[];let u=l(),p=0;const h=this.timestamp_begin;let _=[],m=[],f=!1,g=null;const w=new Set(this.all_special_ids);for(const n of e){const e=n.tokens,r=a?n.token_timestamps:null;let b=null,y=h;if("stride"in n){const[t,r,o]=n.stride;if(p-=r,g=t-o,r&&(y=r/s+h),o)for(let t=e.length-1;t>=0;--t){const n=Number(e[t]);if(n>=h){if(null!==b&&(n-h)*s<g)break;b=n}}}let x=[],k=[];for(let n=0;n<e.length;++n){const g=Number(e[n]);if(w.has(g)){const e=this.decode([g]),n=d.WHISPER_LANGUAGE_MAPPING.get(e.slice(2,-2));if(void 0!==n){if(null!==o&&n!==o&&!t){_.push(x);const e=this.findLongestCommonSequence(_)[0],t=this.decode(e);u.text=t,c.push(u),_=[],x=[],u=l()}o=u.language=n}}else if(g>=h){const e=(g-h)*s+p,t=(0,i.round)(e,2);if(null!==b&&g>=b)f=!0;else if(f||_.length>0&&g<y)f=!1;else if(null===u.timestamp[0])u.timestamp[0]=t;else if(t===u.timestamp[0]);else{u.timestamp[1]=t,_.push(x),a&&m.push(k);const[e,n]=this.findLongestCommonSequence(_,m),s=this.decode(e);u.text=s,a&&(u.words=this.collateWordTimestamps(e,n,o)),c.push(u),_=[],x=[],m=[],k=[],u=l()}}else if(x.push(g),a){let e,t=(0,i.round)(r[n]+p,2);if(n+1<r.length){e=(0,i.round)(r[n+1]+p,2);const o=this.decode([g]);M.test(o)&&(e=(0,i.round)(Math.min(t+s,e),2))}else e=null;k.push([t,e])}}if("stride"in n){const[e,t,s]=n.stride;p+=e-s}x.length>0?(_.push(x),a&&m.push(k)):_.every((e=>0===e.length))&&(u=l(),_=[],x=[],m=[],k=[])}if(_.length>0){if(r&&t)throw new Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");const[e,n]=this.findLongestCommonSequence(_,m),s=this.decode(e);u.text=s,a&&(u.words=this.collateWordTimestamps(e,n,o)),c.push(u)}let b=Object.create(null);const y=c.map((e=>e.text)).join("");if(t||n){for(let e=0;e<c.length;++e){const s=c[e];t||delete s.timestamp,n||delete s.language}if(a){const e=[];for(const t of c)for(const n of t.words)e.push(n);b={chunks:e}}else b={chunks:c}}return[y,b]}findLongestCommonSequence(e,t=null){let n=e[0],s=n.length,r=[];const o=Array.isArray(t)&&t.length>0;let i=o?[]:null,a=o?t[0]:null;for(let l=1;l<e.length;++l){const c=e[l];let d=0,u=[s,s,0,0];const p=c.length;for(let e=1;e<s+p;++e){const r=Math.max(0,s-e),i=Math.min(s,s+p-e),h=n.slice(r,i),_=Math.max(0,e-s),m=Math.min(p,e),f=c.slice(_,m);if(h.length!==f.length)throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let g;g=o?h.filter(((e,n)=>e===f[n]&&a[r+n]<=t[l][_+n])).length:h.filter(((e,t)=>e===f[t])).length;const w=g/e+e/1e4;g>1&&w>d&&(d=w,u=[r,i,_,m])}const[h,_,m,f]=u,g=Math.floor((_+h)/2),w=Math.floor((f+m)/2);r.push(...n.slice(0,g)),n=c.slice(w),s=n.length,o&&(i.push(...a.slice(0,g)),a=t[l].slice(w))}return r.push(...n),o?(i.push(...a),[r,i]):[r,[]]}collateWordTimestamps(e,t,n){const[s,r,o]=this.combineTokensIntoWords(e,n),i=[];for(let e=0;e<s.length;++e){const n=o[e];i.push({text:s[e],timestamp:[t[n.at(0)][0],t[n.at(-1)][1]]})}return i}combineTokensIntoWords(e,t,n="\"'“¡¿([{-",s="\"'.。,,!!??::”)]}、"){let r,o,i;return["chinese","japanese","thai","lao","myanmar"].includes(t=t??"english")?[r,o,i]=this.splitTokensOnUnicode(e):[r,o,i]=this.splitTokensOnSpaces(e),this.mergePunctuations(r,o,i,n,s)}decode(e,t){let n;return t?.decode_with_timestamps?(e instanceof a.Tensor&&(e=_(e)),n=this.decodeWithTimestamps(e,t)):n=super.decode(e,t),n}decodeWithTimestamps(e,t){const n=t?.time_precision??.02,s=Array.from(this.all_special_ids).at(-1)+1;let r=[[]];for(let t of e)if(t=Number(t),t>=s){const e=((t-s)*n).toFixed(2);r.push(`<|${e}|>`),r.push([])}else r[r.length-1].push(t);return r=r.map((e=>"string"==typeof e?e:super.decode(e,t))),r.join("")}splitTokensOnUnicode(e){const t=this.decode(e,{decode_with_timestamps:!0}),n=[],s=[],r=[];let o=[],i=[],a=0;for(let l=0;l<e.length;++l){const c=e[l];o.push(c),i.push(l);const d=this.decode(o,{decode_with_timestamps:!0});d.includes("�")&&"�"!==t[a+d.indexOf("�")]||(n.push(d),s.push(o),r.push(i),o=[],i=[],a+=d.length)}return[n,s,r]}splitTokensOnSpaces(e){const[t,n,s]=this.splitTokensOnUnicode(e),r=[],o=[],i=[],a=new RegExp(`^[${w}]$`,"gu");for(let e=0;e<t.length;++e){const l=t[e],c=n[e],d=s[e],u=c[0]>=this.model.tokens_to_ids.get("<|endoftext|>"),p=l.startsWith(" "),h=l.trim(),_=a.test(h);if(u||p||_||0===r.length)r.push(l),o.push(c),i.push(d);else{const e=r.length-1;r[e]+=l,o[e].push(...c),i[e].push(...d)}}return[r,o,i]}mergePunctuations(e,t,n,s,o){const i=structuredClone(e),a=structuredClone(t),l=structuredClone(n);let c=i.length-2,d=i.length-1;for(;c>=0;)i[c].startsWith(" ")&&s.includes(i[c].trim())?(i[d]=i[c]+i[d],a[d]=(0,r.mergeArrays)(a[c],a[d]),l[d]=(0,r.mergeArrays)(l[c],l[d]),i[c]="",a[c]=[],l[c]=[]):d=c,--c;for(c=0,d=1;d<i.length;)!i[c].endsWith(" ")&&o.includes(i[d])?(i[c]+=i[d],a[c]=(0,r.mergeArrays)(a[c],a[d]),l[c]=(0,r.mergeArrays)(l[c],l[d]),i[d]="",a[d]=[],l[d]=[]):c=d,++d;return[i.filter((e=>e)),a.filter((e=>e.length>0)),l.filter((e=>e.length>0))]}}class nt extends be{}class st extends be{}class rt extends be{}class ot extends be{constructor(e,t){super(e,t),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=this.model.vocab.filter((e=>this.languageRegex.test(e))),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(null===e)return null;const[t,...n]=e.trim().split(this.languageRegex);if(0===n.length)return super._encode_text(t);if(2===n.length){const[e,t]=n;return this.supported_language_codes.includes(e)||console.warn(`Unsupported language code "${e}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),(0,r.mergeArrays)([e],super._encode_text(t))}}}class it extends be{}class at extends be{}class lt extends be{}class ct extends be{}class dt extends be{}class ut extends be{constructor(e,t){super(e,t),this.decoder=new ce({})}}class pt extends be{}class ht{static TOKENIZER_CLASS_MAPPING={T5Tokenizer:Ie,DistilBertTokenizer:Ae,CamembertTokenizer:Ee,DebertaTokenizer:ve,DebertaV2Tokenizer:Fe,BertTokenizer:ye,HerbertTokenizer:Ce,ConvBertTokenizer:Pe,RoFormerTokenizer:Se,XLMTokenizer:Le,ElectraTokenizer:ze,MobileBertTokenizer:ke,SqueezeBertTokenizer:Te,AlbertTokenizer:xe,GPT2Tokenizer:Be,BartTokenizer:Ne,MBartTokenizer:Oe,MBart50Tokenizer:je,RobertaTokenizer:De,WhisperTokenizer:tt,CodeGenTokenizer:nt,CLIPTokenizer:st,SiglipTokenizer:rt,MarianTokenizer:ot,BloomTokenizer:Ve,NllbTokenizer:Ze,M2M100Tokenizer:et,LlamaTokenizer:Ge,CodeLlamaTokenizer:$e,XLMRobertaTokenizer:qe,MPNetTokenizer:Ue,FalconTokenizer:We,GPTNeoXTokenizer:Xe,EsmTokenizer:Qe,Wav2Vec2CTCTokenizer:it,BlenderbotTokenizer:at,BlenderbotSmallTokenizer:lt,SpeechT5Tokenizer:ct,NougatTokenizer:dt,VitsTokenizer:ut,Qwen2Tokenizer:He,GemmaTokenizer:Ye,Grok1Tokenizer:Je,CohereTokenizer:pt,PreTrainedTokenizer:be};static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:s=null,local_files_only:r=!1,revision:o="main",legacy:i=null}={}){const[a,l]=await u(e,{progress_callback:t,config:n,cache_dir:s,local_files_only:r,revision:o,legacy:i}),c=l.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer";let d=this.TOKENIZER_CLASS_MAPPING[c];return d||(console.warn(`Unknown tokenizer class "${c}", attempting to construct from base class.`),d=be),new d(a,l)}}},"./src/utils/audio.js":
|
|
131
131
|
/*!****************************!*\
|
|
132
132
|
!*** ./src/utils/audio.js ***!
|
|
133
|
-
\****************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{hamming:()=>d,hanning:()=>c,mel_filter_bank:()=>m,read_audio:()=>a,spectrogram:()=>g,window_function:()=>w});var s=n(/*! ./hub.js */"./src/utils/hub.js"),r=n(/*! ./maths.js */"./src/utils/maths.js"),o=n(/*! ./core.js */"./src/utils/core.js"),i=n(/*! ./tensor.js */"./src/utils/tensor.js");async function a(e,t){if("undefined"==typeof AudioContext)throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");const n=await(await(0,s.getFile)(e)).arrayBuffer(),r=new AudioContext({sampleRate:t});void 0===t&&console.warn(`No sampling rate provided, using default of ${r.sampleRate}Hz.`);const o=await r.decodeAudioData(n);let i;if(2===o.numberOfChannels){const e=Math.sqrt(2),t=o.getChannelData(0),n=o.getChannelData(1);i=new Float32Array(t.length);for(let s=0;s<o.length;++s)i[s]=e*(t[s]+n[s])/2}else i=o.getChannelData(0);return i}function l(e,t){if(e<1)return new Float64Array;if(1===e)return new Float64Array([1]);const n=1-t,s=2*Math.PI/(e-1),r=new Float64Array(e);for(let o=0;o<e;++o)r[o]=t-n*Math.cos(o*s);return r}function c(e){return l(e,.5)}function d(e){return l(e,.54)}const u={htk:e=>2595*Math.log10(1+e/700),kaldi:e=>1127*Math.log(1+e/700),slaney:(e,t=1e3,n=15,s=27/Math.log(6.4))=>e>=t?n+Math.log(e/t)*s:3*e/200};function p(e,t="htk"){const n=u[t];if(!n)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return"number"==typeof e?n(e):e.map((e=>n(e)))}const h={htk:e=>700*(10**(e/2595)-1),kaldi:e=>700*(Math.exp(e/1127)-1),slaney:(e,t=1e3,n=15,s=Math.log(6.4)/27)=>e>=n?t*Math.exp(s*(e-n)):200*e/3};function _(e,t,n){const s=(t-e)/(n-1);return Float64Array.from({length:n},((t,n)=>e+s*n))}function m(e,t,n,s,r,o=null,i="htk",a=!1){if(null!==o&&"slaney"!==o)throw new Error('norm must be one of null or "slaney"');const l=_(p(n,i),p(s,i),t+2);let c,d=function(e,t="htk"){const n=h[t];if(!n)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return"number"==typeof e?n(e):e.map((e=>n(e)))}(l,i);if(a){const t=r/(2*e);c=p(Float64Array.from({length:e},((e,n)=>n*t)),i),d=l}else c=_(0,Math.floor(r/2),e);const u=function(e,t){const n=Float64Array.from({length:t.length-1},((e,n)=>t[n+1]-t[n])),s=Array.from({length:e.length},(()=>new Array(t.length)));for(let n=0;n<e.length;++n){const r=s[n];for(let s=0;s<t.length;++s)r[s]=t[s]-e[n]}const r=t.length-2,o=Array.from({length:r},(()=>new Array(e.length)));for(let t=0;t<e.length;++t){const e=s[t];for(let s=0;s<r;++s){const r=-e[s]/n[s],i=e[s+2]/n[s+1];o[s][t]=Math.max(0,Math.min(r,i))}}return o}(c,d);if(null!==o&&"slaney"===o)for(let n=0;n<t;++n){const t=u[n],s=2/(d[n+2]-d[n]);for(let n=0;n<e;++n)t[n]*=s}return u}function f(e,t,n,s,o){if(n<=0)throw new Error("reference must be greater than zero");if(s<=0)throw new Error("min_value must be greater than zero");n=Math.max(s,n);const i=Math.log10(n);for(let n=0;n<e.length;++n)e[n]=t*Math.log10(Math.max(s,e[n])-i);if(null!==o){if(o<=0)throw new Error("db_range must be greater than zero");const t=(0,r.max)(e)[0]-o;for(let n=0;n<e.length;++n)e[n]=Math.max(e[n],t)}return e}async function g(e,t,n,s,{fft_length:a=null,power:l=1,center:c=!0,pad_mode:d="reflect",onesided:u=!0,preemphasis:p=null,mel_filters:h=null,mel_floor:_=1e-10,log_mel:m=null,reference:g=1,min_value:w=1e-10,db_range:M=null,remove_dc_offset:b=null,min_num_frames:y=null,max_num_frames:x=null,do_pad:k=!0,transpose:T=!1}={}){const v=t.length;if(null===a&&(a=n),n>a)throw Error(`frame_length (${n}) may not be larger than fft_length (${a})`);if(v!==n)throw new Error(`Length of the window (${v}) must equal frame_length (${n})`);if(s<=0)throw new Error("hop_length must be greater than zero");if(null===l&&null!==h)throw new Error("You have provided `mel_filters` but `power` is `None`. Mel spectrogram computation is not yet supported for complex-valued spectrogram. Specify `power` to fix this issue.");if(c){if("reflect"!==d)throw new Error(`pad_mode="${d}" not implemented yet.`);const t=Math.floor((a-1)/2)+1;e=function(e,t,n){const s=new e.constructor(e.length+t+n),r=e.length-1;for(let n=0;n<e.length;++n)s[t+n]=e[n];for(let n=1;n<=t;++n)s[t-n]=e[(0,o.calculateReflectOffset)(n,r)];for(let i=1;i<=n;++i)s[r+t+i]=e[(0,o.calculateReflectOffset)(r-i,r)];return s}(e,t,t)}let F=Math.floor(1+Math.floor((e.length-n)/s));null!==y&&F<y&&(F=y);const C=u?Math.floor(a/2)+1:a;let P=F,S=F;null!==x&&(x>F?k&&(S=x):S=P=x);const A=new r.FFT(a),E=new Float64Array(a),
|
|
133
|
+
\****************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{hamming:()=>d,hanning:()=>c,mel_filter_bank:()=>m,read_audio:()=>a,spectrogram:()=>g,window_function:()=>w});var s=n(/*! ./hub.js */"./src/utils/hub.js"),r=n(/*! ./maths.js */"./src/utils/maths.js"),o=n(/*! ./core.js */"./src/utils/core.js"),i=n(/*! ./tensor.js */"./src/utils/tensor.js");async function a(e,t){if("undefined"==typeof AudioContext)throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");const n=await(await(0,s.getFile)(e)).arrayBuffer(),r=new AudioContext({sampleRate:t});void 0===t&&console.warn(`No sampling rate provided, using default of ${r.sampleRate}Hz.`);const o=await r.decodeAudioData(n);let i;if(2===o.numberOfChannels){const e=Math.sqrt(2),t=o.getChannelData(0),n=o.getChannelData(1);i=new Float32Array(t.length);for(let s=0;s<o.length;++s)i[s]=e*(t[s]+n[s])/2}else i=o.getChannelData(0);return i}function l(e,t){if(e<1)return new Float64Array;if(1===e)return new Float64Array([1]);const n=1-t,s=2*Math.PI/(e-1),r=new Float64Array(e);for(let o=0;o<e;++o)r[o]=t-n*Math.cos(o*s);return r}function c(e){return l(e,.5)}function d(e){return l(e,.54)}const u={htk:e=>2595*Math.log10(1+e/700),kaldi:e=>1127*Math.log(1+e/700),slaney:(e,t=1e3,n=15,s=27/Math.log(6.4))=>e>=t?n+Math.log(e/t)*s:3*e/200};function p(e,t="htk"){const n=u[t];if(!n)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return"number"==typeof e?n(e):e.map((e=>n(e)))}const h={htk:e=>700*(10**(e/2595)-1),kaldi:e=>700*(Math.exp(e/1127)-1),slaney:(e,t=1e3,n=15,s=Math.log(6.4)/27)=>e>=n?t*Math.exp(s*(e-n)):200*e/3};function _(e,t,n){const s=(t-e)/(n-1);return Float64Array.from({length:n},((t,n)=>e+s*n))}function m(e,t,n,s,r,o=null,i="htk",a=!1){if(null!==o&&"slaney"!==o)throw new Error('norm must be one of null or "slaney"');const l=_(p(n,i),p(s,i),t+2);let c,d=function(e,t="htk"){const n=h[t];if(!n)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return"number"==typeof e?n(e):e.map((e=>n(e)))}(l,i);if(a){const t=r/(2*e);c=p(Float64Array.from({length:e},((e,n)=>n*t)),i),d=l}else c=_(0,Math.floor(r/2),e);const u=function(e,t){const n=Float64Array.from({length:t.length-1},((e,n)=>t[n+1]-t[n])),s=Array.from({length:e.length},(()=>new Array(t.length)));for(let n=0;n<e.length;++n){const r=s[n];for(let s=0;s<t.length;++s)r[s]=t[s]-e[n]}const r=t.length-2,o=Array.from({length:r},(()=>new Array(e.length)));for(let t=0;t<e.length;++t){const e=s[t];for(let s=0;s<r;++s){const r=-e[s]/n[s],i=e[s+2]/n[s+1];o[s][t]=Math.max(0,Math.min(r,i))}}return o}(c,d);if(null!==o&&"slaney"===o)for(let n=0;n<t;++n){const t=u[n],s=2/(d[n+2]-d[n]);for(let n=0;n<e;++n)t[n]*=s}return u}function f(e,t,n,s,o){if(n<=0)throw new Error("reference must be greater than zero");if(s<=0)throw new Error("min_value must be greater than zero");n=Math.max(s,n);const i=Math.log10(n);for(let n=0;n<e.length;++n)e[n]=t*Math.log10(Math.max(s,e[n])-i);if(null!==o){if(o<=0)throw new Error("db_range must be greater than zero");const t=(0,r.max)(e)[0]-o;for(let n=0;n<e.length;++n)e[n]=Math.max(e[n],t)}return e}async function g(e,t,n,s,{fft_length:a=null,power:l=1,center:c=!0,pad_mode:d="reflect",onesided:u=!0,preemphasis:p=null,mel_filters:h=null,mel_floor:_=1e-10,log_mel:m=null,reference:g=1,min_value:w=1e-10,db_range:M=null,remove_dc_offset:b=null,min_num_frames:y=null,max_num_frames:x=null,do_pad:k=!0,transpose:T=!1}={}){const v=t.length;if(null===a&&(a=n),n>a)throw Error(`frame_length (${n}) may not be larger than fft_length (${a})`);if(v!==n)throw new Error(`Length of the window (${v}) must equal frame_length (${n})`);if(s<=0)throw new Error("hop_length must be greater than zero");if(null===l&&null!==h)throw new Error("You have provided `mel_filters` but `power` is `None`. Mel spectrogram computation is not yet supported for complex-valued spectrogram. Specify `power` to fix this issue.");if(c){if("reflect"!==d)throw new Error(`pad_mode="${d}" not implemented yet.`);const t=Math.floor((a-1)/2)+1;e=function(e,t,n){const s=new e.constructor(e.length+t+n),r=e.length-1;for(let n=0;n<e.length;++n)s[t+n]=e[n];for(let n=1;n<=t;++n)s[t-n]=e[(0,o.calculateReflectOffset)(n,r)];for(let i=1;i<=n;++i)s[r+t+i]=e[(0,o.calculateReflectOffset)(r-i,r)];return s}(e,t,t)}let F=Math.floor(1+Math.floor((e.length-n)/s));null!==y&&F<y&&(F=y);const C=u?Math.floor(a/2)+1:a;let P=F,S=F;null!==x&&(x>F?k&&(S=x):S=P=x);const A=new r.FFT(a),E=new Float64Array(a),L=new Float64Array(A.outputBufferSize),z=new Float32Array(C*S);for(let r=0;r<P;++r){const o=r*s,i=Math.min(e.length-o,n);i!==n&&E.fill(0,0,n);for(let t=0;t<i;++t)E[t]=e[o+t];if(b){let e=0;for(let t=0;t<i;++t)e+=E[t];const t=e/i;for(let e=0;e<i;++e)E[e]-=t}if(null!==p){for(let e=i-1;e>=1;--e)E[e]-=p*E[e-1];E[0]*=1-p}for(let e=0;e<t.length;++e)E[e]*=t[e];A.realTransform(L,E);for(let e=0;e<C;++e){const t=e<<1;z[e*S+r]=L[t]**2+L[t+1]**2}}if(null!==l&&2!==l){const e=2/l;for(let t=0;t<z.length;++t)z[t]**=e}const I=h.length;let B=await(0,i.matmul)(new i.Tensor("float32",h.flat(),[I,C]),new i.Tensor("float32",z,[C,S]));T&&(B=B.transpose(1,0));const N=B.data;for(let e=0;e<N.length;++e)N[e]=Math.max(_,N[e]);if(null!==l&&null!==m){const e=Math.min(N.length,P*I);switch(m){case"log":for(let t=0;t<e;++t)N[t]=Math.log(N[t]);break;case"log10":for(let t=0;t<e;++t)N[t]=Math.log10(N[t]);break;case"dB":if(1===l)!function(e,t=1,n=1e-5,s=null){f(e,20,t,n,s)}(N,g,w,M);else{if(2!==l)throw new Error(`Cannot use log_mel option '${m}' with power ${l}`);!function(e,t=1,n=1e-10,s=null){f(e,10,t,n,s)}(N,g,w,M)}break;default:throw new Error(`log_mel must be one of null, 'log', 'log10' or 'dB'. Got '${m}'`)}}return B}function w(e,t,{periodic:n=!0,frame_length:s=null,center:r=!0}={}){const o=n?e+1:e;let i;switch(t){case"boxcar":i=new Float64Array(o).fill(1);break;case"hann":case"hann_window":i=c(o);break;case"hamming":i=d(o);break;case"povey":i=c(o).map((e=>Math.pow(e,.85)));break;default:throw new Error(`Unknown window type ${t}.`)}if(n&&(i=i.subarray(0,e)),null===s)return i;if(e>s)throw new Error(`Length of the window (${e}) may not be larger than frame_length (${s})`);return i}},"./src/utils/constants.js":
|
|
134
134
|
/*!********************************!*\
|
|
135
135
|
!*** ./src/utils/constants.js ***!
|
|
136
136
|
\********************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{GITHUB_ISSUE_URL:()=>s});const s="https://github.com/xenova/transformers.js/issues/new/choose"},"./src/utils/core.js":
|
|
@@ -157,11 +157,11 @@
|
|
|
157
157
|
\****************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{RawImage:()=>_});var s=n(/*! ./hub.js */"./src/utils/hub.js"),r=n(/*! ../env.js */"./src/env.js"),o=n(/*! ./tensor.js */"./src/utils/tensor.js"),i=n(/*! sharp */"sharp");const a="undefined"!=typeof self,l=a&&"DedicatedWorkerGlobalScope"===self.constructor.name;let c,d,u;if(a)c=(e,t)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(e,t)},u=self.createImageBitmap,d=self.ImageData;else{if(!i)throw new Error("Unable to load image processing library.");u=async e=>{const t=(await e.metadata()).channels,{data:n,info:s}=await e.rotate().raw().toBuffer({resolveWithObject:!0}),r=new _(new Uint8ClampedArray(n),s.width,s.height,s.channels);return void 0!==t&&t!==s.channels&&r.convert(t),r}}const p={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},h=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]);class _{constructor(e,t,n,s){this.data=e,this.width=t,this.height=n,this.channels=s}get size(){return[this.width,this.height]}static async read(e){if(e instanceof _)return e;if("string"==typeof e||e instanceof URL)return await this.fromURL(e);throw new Error("Unsupported input type: "+typeof e)}static fromCanvas(e){if(!a)throw new Error("fromCanvas() is only supported in browser environments.");const t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;return new _(t,e.width,e.height,4)}static async fromURL(e){const t=await(0,s.getFile)(e);if(200!==t.status)throw new Error(`Unable to read image from "${e}" (${t.status} ${t.statusText})`);const n=await t.blob();return this.fromBlob(n)}static async fromBlob(e){if(a){const t=await u(e),n=c(t.width,t.height).getContext("2d");return n.drawImage(t,0,0),new this(n.getImageData(0,0,t.width,t.height).data,t.width,t.height,4)}{const t=i(await e.arrayBuffer());return await u(t)}}static fromTensor(e,t="CHW"){if(3!==e.dims.length)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if("CHW"===t)e=e.transpose(1,2,0);else if("HWC"!==t)throw new Error(`Unsupported channel format: ${t}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new _(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(1===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let t=0,n=0;t<this.data.length;t+=this.channels){const s=this.data[t],r=this.data[t+1],o=this.data[t+2];e[n++]=Math.round(.2989*s+.587*r+.114*o)}break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(3===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let t=0,n=0;t<this.data.length;++t)e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=this.data[t];break;case 4:for(let t=0,n=0;t<this.data.length;t+=4)e[n++]=this.data[t],e[n++]=this.data[t+1],e[n++]=this.data[t+2];break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(4===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let t=0,n=0;t<this.data.length;++t)e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=255;break;case 3:for(let t=0,n=0;t<this.data.length;t+=3)e[n++]=this.data[t],e[n++]=this.data[t+1],e[n++]=this.data[t+2],e[n++]=255;break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}async resize(e,t,{resample:n=2}={}){let s=p[n]??n;if(a){const n=this.channels,s=this.toCanvas(),r=c(e,t).getContext("2d");r.drawImage(s,0,0,e,t);return new _(r.getImageData(0,0,e,t).data,e,t,4).convert(n)}{let n=this.toSharp();switch(s){case"box":case"hamming":"box"!==s&&"hamming"!==s||(console.warn(`Resampling method ${s} is not yet supported. Using bilinear instead.`),s="bilinear");case"nearest":case"bilinear":case"bicubic":n=n.affine([e/this.width,0,0,t/this.height],{interpolator:s});break;case"lanczos":n=n.resize({width:e,height:t,fit:"fill",kernel:"lanczos3"});break;default:throw new Error(`Resampling method ${s} is not supported.`)}return await u(n)}}async pad([e,t,n,s]){if(e=Math.max(e,0),t=Math.max(t,0),n=Math.max(n,0),s=Math.max(s,0),0===e&&0===t&&0===n&&0===s)return this;if(a){const r=this.channels,o=this.toCanvas(),i=this.width+e+t,a=this.height+n+s,l=c(i,a).getContext("2d");l.drawImage(o,0,0,this.width,this.height,e,n,i,a);return new _(l.getImageData(0,0,i,a).data,i,a,4).convert(r)}{const r=this.toSharp().extend({left:e,right:t,top:n,bottom:s});return await u(r)}}async crop([e,t,n,s]){if(e=Math.max(e,0),t=Math.max(t,0),n=Math.min(n,this.width-1),s=Math.min(s,this.height-1),0===e&&0===t&&n===this.width-1&&s===this.height-1)return this;const r=n-e+1,o=s-t+1;if(a){const n=this.channels,s=this.toCanvas(),i=c(r,o).getContext("2d");i.drawImage(s,e,t,r,o,0,0,r,o);return new _(i.getImageData(0,0,r,o).data,r,o,4).convert(n)}{const n=this.toSharp().extract({left:e,top:t,width:r,height:o});return await u(n)}}async center_crop(e,t){if(this.width===e&&this.height===t)return this;const n=(this.width-e)/2,s=(this.height-t)/2;if(a){const r=this.channels,o=this.toCanvas(),i=c(e,t).getContext("2d");let a=0,l=0,d=0,u=0;n>=0?a=n:d=-n,s>=0?l=s:u=-s,i.drawImage(o,a,l,e,t,d,u,e,t);return new _(i.getImageData(0,0,e,t).data,e,t,4).convert(r)}{let r=this.toSharp();if(n>=0&&s>=0)r=r.extract({left:Math.floor(n),top:Math.floor(s),width:e,height:t});else if(n<=0&&s<=0){const o=Math.floor(-s),i=Math.floor(-n);r=r.extend({top:o,left:i,right:e-this.width-i,bottom:t-this.height-o})}else{let o=[0,0],i=0;s<0?(o[0]=Math.floor(-s),o[1]=t-this.height-o[0]):i=Math.floor(s);let a=[0,0],l=0;n<0?(a[0]=Math.floor(-n),a[1]=e-this.width-a[0]):l=Math.floor(n),r=r.extend({top:o[0],bottom:o[1],left:a[0],right:a[1]}).extract({left:l,top:i,width:e,height:t})}return await u(r)}}async toBlob(e="image/png",t=1){if(!a)throw new Error("toBlob() is only supported in browser environments.");const n=this.toCanvas();return await n.convertToBlob({type:e,quality:t})}toTensor(e="CHW"){let t=new o.Tensor("uint8",new Uint8Array(this.data),[this.height,this.width,this.channels]);if("HWC"===e);else{if("CHW"!==e)throw new Error(`Unsupported channel format: ${e}`);t=t.permute(2,0,1)}return t}toCanvas(){if(!a)throw new Error("toCanvas() is only supported in browser environments.");const e=this.clone().rgba(),t=c(e.width,e.height),n=new d(e.data,e.width,e.height);return t.getContext("2d").putImageData(n,0,0),t}_update(e,t,n,s=null){return this.data=e,this.width=t,this.height=n,null!==s&&(this.channels=s),this}clone(){return new _(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(!a){if(r.env.useFS){const t=this.toSharp();return await t.toFile(e)}throw new Error("Unable to save the image because filesystem is disabled in this environment.")}{if(l)throw new Error("Unable to save an image from a Web Worker.");const t=e.split(".").pop().toLowerCase(),n=h.get(t)??"image/png",s=await this.toBlob(n),r=URL.createObjectURL(s),o=document.createElement("a");o.href=r,o.download=e,o.click(),o.remove()}}toSharp(){if(a)throw new Error("toSharp() is only supported in server-side environments.");return i(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}}},"./src/utils/maths.js":
|
|
158
158
|
/*!****************************!*\
|
|
159
159
|
!*** ./src/utils/maths.js ***!
|
|
160
|
-
\****************************/(e,t,n)=>{"use strict";function s(e,[t,n,s],[r,o],i="bilinear",a=!1){const l=o/s,c=r/n,d=new e.constructor(r*o*t),u=n*s,p=r*o;for(let i=0;i<r;++i)for(let r=0;r<o;++r){const a=i*o+r,h=(r+.5)/l-.5,_=(i+.5)/c-.5;let m=Math.floor(h),f=Math.floor(_);const g=Math.min(m+1,s-1),w=Math.min(f+1,n-1);m=Math.max(m,0),f=Math.max(f,0);const M=h-m,b=_-f,y=(1-M)*(1-b),x=M*(1-b),k=(1-M)*b,T=M*b,v=f*s,F=w*s,C=v+m,P=v+g,S=F+m,A=F+g;for(let n=0;n<t;++n){const t=n*u;d[n*p+a]=y*e[t+C]+x*e[t+P]+k*e[t+S]+T*e[t+A]}}return d}function r(e,t,n){const s=new Array(n.length),r=new Array(n.length);for(let e=n.length-1,o=1;e>=0;--e)r[e]=o,s[e]=t[n[e]],o*=s[e];const o=n.map(((e,t)=>r[n.indexOf(t)])),i=new e.constructor(e.length);for(let n=0;n<e.length;++n){let s=0;for(let e=t.length-1,r=n;e>=0;--e)s+=r%t[e]*o[e],r=Math.floor(r/t[e]);i[s]=e[n]}return[i,s]}function o(e){const t=u(e)[0],n=e.map((e=>Math.exp(e-t))),s=n.reduce(((e,t)=>e+t),0);return n.map((e=>e/s))}function i(e){const t=u(e)[0];let n=0;for(let s=0;s<e.length;++s)n+=Math.exp(e[s]-t);const s=Math.log(n);return e.map((e=>e-t-s))}function a(e,t){let n=0;for(let s=0;s<e.length;++s)n+=e[s]*t[s];return n}function l(e,t){return a(e,t)/(c(e)*c(t))}function c(e){return Math.sqrt(e.reduce(((e,t)=>e+t*t),0))}function d(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],n=0;for(let s=1;s<e.length;++s)e[s]<t&&(t=e[s],n=s);return[t,n]}function u(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],n=0;for(let s=1;s<e.length;++s)e[s]>t&&(t=e[s],n=s);return[Number(t),n]}function p(e){return e>0&&!(e&e-1)}n.r(t),n.d(t,{FFT:()=>m,bankers_round:()=>w,cos_sim:()=>l,dot:()=>a,dynamic_time_warping:()=>M,interpolate_data:()=>s,log_softmax:()=>i,magnitude:()=>c,max:()=>u,medianFilter:()=>f,min:()=>d,permute_data:()=>r,round:()=>g,softmax:()=>o});class h{constructor(e){if(this.size=0|e,this.size<=1||!p(this.size))throw new Error("FFT size must be a power of two larger than 1");this._csize=e<<1,this.table=new Float64Array(2*this.size);for(let e=0;e<this.table.length;e+=2){const t=Math.PI*e/this.size;this.table[e]=Math.cos(t),this.table[e+1]=-Math.sin(t)}let t=0;for(let e=1;this.size>e;e<<=1)++t;this._width=t%2==0?t-1:t,this._bitrev=new Int32Array(1<<this._width);for(let e=0;e<this._bitrev.length;++e){this._bitrev[e]=0;for(let t=0;t<this._width;t+=2){const n=this._width-t-2;this._bitrev[e]|=(e>>>t&3)<<n}}}createComplexArray(){return new Float64Array(this._csize)}fromComplexArray(e,t){const n=t||new Array(e.length>>>1);for(let t=0;t<e.length;t+=2)n[t>>>1]=e[t];return n}toComplexArray(e,t){const n=t||this.createComplexArray();for(let t=0;t<n.length;t+=2)n[t]=e[t>>>1],n[t+1]=0;return n}transform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._transform4(e,t,1)}realTransform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._realTransform4(e,t,1)}inverseTransform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._transform4(e,t,-1);for(let t=0;t<e.length;++t)e[t]/=this.size}_transform4(e,t,n){const s=this._csize;let r,o,i=1<<this._width,a=s/i<<1;const l=this._bitrev;if(4===a)for(r=0,o=0;r<s;r+=a,++o){const n=l[o];this._singleTransform2(t,e,r,n,i)}else for(r=0,o=0;r<s;r+=a,++o){const s=l[o];this._singleTransform4(t,e,r,s,i,n)}const c=this.table;for(i>>=2;i>=2;i>>=2){a=s/i<<1;const t=a>>>2;for(r=0;r<s;r+=a){const s=r+t-1;for(let o=r,a=0;o<s;o+=2,a+=i){const s=o,r=s+t,i=r+t,l=i+t,d=e[s],u=e[s+1],p=e[r],h=e[r+1],_=e[i],m=e[i+1],f=e[l],g=e[l+1],w=c[a],M=n*c[a+1],b=p*w-h*M,y=p*M+h*w,x=c[2*a],k=n*c[2*a+1],T=_*x-m*k,v=_*k+m*x,F=c[3*a],C=n*c[3*a+1],P=f*F-g*C,S=f*C+g*F,A=d+T,E=u+v,
|
|
160
|
+
\****************************/(e,t,n)=>{"use strict";function s(e,[t,n,s],[r,o],i="bilinear",a=!1){const l=o/s,c=r/n,d=new e.constructor(r*o*t),u=n*s,p=r*o;for(let i=0;i<r;++i)for(let r=0;r<o;++r){const a=i*o+r,h=(r+.5)/l-.5,_=(i+.5)/c-.5;let m=Math.floor(h),f=Math.floor(_);const g=Math.min(m+1,s-1),w=Math.min(f+1,n-1);m=Math.max(m,0),f=Math.max(f,0);const M=h-m,b=_-f,y=(1-M)*(1-b),x=M*(1-b),k=(1-M)*b,T=M*b,v=f*s,F=w*s,C=v+m,P=v+g,S=F+m,A=F+g;for(let n=0;n<t;++n){const t=n*u;d[n*p+a]=y*e[t+C]+x*e[t+P]+k*e[t+S]+T*e[t+A]}}return d}function r(e,t,n){const s=new Array(n.length),r=new Array(n.length);for(let e=n.length-1,o=1;e>=0;--e)r[e]=o,s[e]=t[n[e]],o*=s[e];const o=n.map(((e,t)=>r[n.indexOf(t)])),i=new e.constructor(e.length);for(let n=0;n<e.length;++n){let s=0;for(let e=t.length-1,r=n;e>=0;--e)s+=r%t[e]*o[e],r=Math.floor(r/t[e]);i[s]=e[n]}return[i,s]}function o(e){const t=u(e)[0],n=e.map((e=>Math.exp(e-t))),s=n.reduce(((e,t)=>e+t),0);return n.map((e=>e/s))}function i(e){const t=u(e)[0];let n=0;for(let s=0;s<e.length;++s)n+=Math.exp(e[s]-t);const s=Math.log(n);return e.map((e=>e-t-s))}function a(e,t){let n=0;for(let s=0;s<e.length;++s)n+=e[s]*t[s];return n}function l(e,t){return a(e,t)/(c(e)*c(t))}function c(e){return Math.sqrt(e.reduce(((e,t)=>e+t*t),0))}function d(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],n=0;for(let s=1;s<e.length;++s)e[s]<t&&(t=e[s],n=s);return[t,n]}function u(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],n=0;for(let s=1;s<e.length;++s)e[s]>t&&(t=e[s],n=s);return[Number(t),n]}function p(e){return e>0&&!(e&e-1)}n.r(t),n.d(t,{FFT:()=>m,bankers_round:()=>w,cos_sim:()=>l,dot:()=>a,dynamic_time_warping:()=>M,interpolate_data:()=>s,log_softmax:()=>i,magnitude:()=>c,max:()=>u,medianFilter:()=>f,min:()=>d,permute_data:()=>r,round:()=>g,softmax:()=>o});class h{constructor(e){if(this.size=0|e,this.size<=1||!p(this.size))throw new Error("FFT size must be a power of two larger than 1");this._csize=e<<1,this.table=new Float64Array(2*this.size);for(let e=0;e<this.table.length;e+=2){const t=Math.PI*e/this.size;this.table[e]=Math.cos(t),this.table[e+1]=-Math.sin(t)}let t=0;for(let e=1;this.size>e;e<<=1)++t;this._width=t%2==0?t-1:t,this._bitrev=new Int32Array(1<<this._width);for(let e=0;e<this._bitrev.length;++e){this._bitrev[e]=0;for(let t=0;t<this._width;t+=2){const n=this._width-t-2;this._bitrev[e]|=(e>>>t&3)<<n}}}createComplexArray(){return new Float64Array(this._csize)}fromComplexArray(e,t){const n=t||new Array(e.length>>>1);for(let t=0;t<e.length;t+=2)n[t>>>1]=e[t];return n}toComplexArray(e,t){const n=t||this.createComplexArray();for(let t=0;t<n.length;t+=2)n[t]=e[t>>>1],n[t+1]=0;return n}transform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._transform4(e,t,1)}realTransform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._realTransform4(e,t,1)}inverseTransform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._transform4(e,t,-1);for(let t=0;t<e.length;++t)e[t]/=this.size}_transform4(e,t,n){const s=this._csize;let r,o,i=1<<this._width,a=s/i<<1;const l=this._bitrev;if(4===a)for(r=0,o=0;r<s;r+=a,++o){const n=l[o];this._singleTransform2(t,e,r,n,i)}else for(r=0,o=0;r<s;r+=a,++o){const s=l[o];this._singleTransform4(t,e,r,s,i,n)}const c=this.table;for(i>>=2;i>=2;i>>=2){a=s/i<<1;const t=a>>>2;for(r=0;r<s;r+=a){const s=r+t-1;for(let o=r,a=0;o<s;o+=2,a+=i){const s=o,r=s+t,i=r+t,l=i+t,d=e[s],u=e[s+1],p=e[r],h=e[r+1],_=e[i],m=e[i+1],f=e[l],g=e[l+1],w=c[a],M=n*c[a+1],b=p*w-h*M,y=p*M+h*w,x=c[2*a],k=n*c[2*a+1],T=_*x-m*k,v=_*k+m*x,F=c[3*a],C=n*c[3*a+1],P=f*F-g*C,S=f*C+g*F,A=d+T,E=u+v,L=d-T,z=u-v,I=b+P,B=y+S,N=n*(b-P),O=n*(y-S);e[s]=A+I,e[s+1]=E+B,e[r]=L+O,e[r+1]=z-N,e[i]=A-I,e[i+1]=E-B,e[l]=L-O,e[l+1]=z+N}}}}_singleTransform2(e,t,n,s,r){const o=e[s],i=e[s+1],a=e[s+r],l=e[s+r+1];t[n]=o+a,t[n+1]=i+l,t[n+2]=o-a,t[n+3]=i-l}_singleTransform4(e,t,n,s,r,o){const i=2*r,a=3*r,l=e[s],c=e[s+1],d=e[s+r],u=e[s+r+1],p=e[s+i],h=e[s+i+1],_=e[s+a],m=e[s+a+1],f=l+p,g=c+h,w=l-p,M=c-h,b=d+_,y=u+m,x=o*(d-_),k=o*(u-m);t[n]=f+b,t[n+1]=g+y,t[n+2]=w+k,t[n+3]=M-x,t[n+4]=f-b,t[n+5]=g-y,t[n+6]=w-k,t[n+7]=M+x}_realTransform4(e,t,n){const s=this._csize;let r,o,i=1<<this._width,a=s/i<<1;const l=this._bitrev;if(4===a)for(r=0,o=0;r<s;r+=a,++o){const n=l[o];this._singleRealTransform2(t,e,r,n>>>1,i>>>1)}else for(r=0,o=0;r<s;r+=a,++o){const s=l[o];this._singleRealTransform4(t,e,r,s>>>1,i>>>1,n)}const c=this.table;for(i>>=2;i>=2;i>>=2){a=s/i<<1;const t=a>>>1,o=t>>>1,l=o>>>1;for(r=0;r<s;r+=a)for(let s=0,a=0;s<=l;s+=2,a+=i){const i=r+s,d=i+o,u=d+o,p=u+o,h=e[i],_=e[i+1],m=e[d],f=e[d+1],g=e[u],w=e[u+1],M=e[p],b=e[p+1],y=h,x=_,k=c[a],T=n*c[a+1],v=m*k-f*T,F=m*T+f*k,C=c[2*a],P=n*c[2*a+1],S=g*C-w*P,A=g*P+w*C,E=c[3*a],L=n*c[3*a+1],z=M*E-b*L,I=M*L+b*E,B=y+S,N=x+A,O=y-S,j=x-A,D=v+z,V=F+I,R=n*(v-z),G=n*(F-I);if(e[i]=B+D,e[i+1]=N+V,e[d]=O+G,e[d+1]=j-R,0===s){e[u]=B-D,e[u+1]=N-V;continue}if(s===l)continue;const $=r+o-s,q=r+t-s;e[$]=O-n*G,e[$+1]=-j-n*R,e[q]=B-n*D,e[q+1]=n*V-N}}const d=s>>>1;for(let t=2;t<d;t+=2)e[s-t]=e[t],e[s-t+1]=-e[t+1]}_singleRealTransform2(e,t,n,s,r){const o=e[s],i=e[s+r];t[n]=o+i,t[n+1]=0,t[n+2]=o-i,t[n+3]=0}_singleRealTransform4(e,t,n,s,r,o){const i=2*r,a=3*r,l=e[s],c=e[s+r],d=e[s+i],u=e[s+a],p=l+d,h=l-d,_=c+u,m=o*(c-u);t[n]=p+_,t[n+1]=0,t[n+2]=h,t[n+3]=-m,t[n+4]=p-_,t[n+5]=0,t[n+6]=h,t[n+7]=m}}class _{constructor(e){const t=2*(e-1),n=2*(2*e-1),s=2**Math.ceil(Math.log2(n));this.bufferSize=s,this._a=t;const r=new Float64Array(n),o=new Float64Array(s);this._chirpBuffer=new Float64Array(s),this._buffer1=new Float64Array(s),this._buffer2=new Float64Array(s),this._outBuffer1=new Float64Array(s),this._outBuffer2=new Float64Array(s);const i=-2*Math.PI/e,a=Math.cos(i),l=Math.sin(i);for(let t=0;t<n>>1;++t){const n=(t+1-e)**2/2,s=Math.sqrt(a**2+l**2)**n,i=n*Math.atan2(l,a),c=2*t;r[c]=s*Math.cos(i),r[c+1]=s*Math.sin(i),o[c]=r[c],o[c+1]=-r[c+1]}this._slicedChirpBuffer=r.subarray(t,n),this._f=new h(s>>1),this._f.transform(this._chirpBuffer,o)}_transform(e,t,n){const s=this._buffer1,r=this._buffer2,o=this._outBuffer1,i=this._outBuffer2,a=this._chirpBuffer,l=this._slicedChirpBuffer,c=this._a;if(n)for(let e=0;e<l.length;e+=2){const n=e+1,r=t[e>>1];s[e]=r*l[e],s[n]=r*l[n]}else for(let e=0;e<l.length;e+=2){const n=e+1;s[e]=t[e]*l[e]-t[n]*l[n],s[n]=t[e]*l[n]+t[n]*l[e]}this._f.transform(o,s);for(let e=0;e<a.length;e+=2){const t=e+1;r[e]=o[e]*a[e]-o[t]*a[t],r[t]=o[e]*a[t]+o[t]*a[e]}this._f.inverseTransform(i,r);for(let t=0;t<i.length;t+=2){const n=i[t+c],s=i[t+c+1],r=l[t],o=l[t+1];e[t]=n*r-s*o,e[t+1]=n*o+s*r}}transform(e,t){this._transform(e,t,!1)}realTransform(e,t){this._transform(e,t,!0)}}class m{constructor(e){this.fft_length=e,this.isPowerOfTwo=p(e),this.isPowerOfTwo?(this.fft=new h(e),this.outputBufferSize=2*e):(this.fft=new _(e),this.outputBufferSize=this.fft.bufferSize)}realTransform(e,t){this.fft.realTransform(e,t)}transform(e,t){this.fft.transform(e,t)}}function f(e,t){if(t%2==0||t<=0)throw new Error("Window size must be a positive odd number");const n=new e.constructor(e.length),s=new e.constructor(t),r=Math.floor(t/2);for(let t=0;t<e.length;++t){let o=0;for(let n=-r;n<=r;++n){let r=t+n;r<0?r=Math.abs(r):r>=e.length&&(r=2*(e.length-1)-r),s[o++]=e[r]}s.sort(),n[t]=s[r]}return n}function g(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}function w(e){const t=Math.round(e);return Math.abs(e)%1==.5?t%2==0?t:t-1:t}function M(e){const t=e.length,n=e[0].length,s=[t+1,n+1],r=Array.from({length:s[0]},(()=>Array(s[1]).fill(1/0)));r[0][0]=0;const o=Array.from({length:s[0]},(()=>Array(s[1]).fill(-1)));for(let t=1;t<s[1];++t)for(let n=1;n<s[0];++n){const s=r[n-1][t-1],i=r[n-1][t],a=r[n][t-1];let l,c;s<i&&s<a?(l=s,c=0):i<s&&i<a?(l=i,c=1):(l=a,c=2),r[n][t]=e[n-1][t-1]+l,o[n][t]=c}for(let e=0;e<s[1];++e)o[0][e]=2;for(let e=0;e<s[0];++e)o[e][0]=1;let i=t,a=n,l=[],c=[];for(;i>0||a>0;)switch(l.push(i-1),c.push(a-1),o[i][a]){case 0:--i,--a;break;case 1:--i;break;case 2:--a;break;default:throw new Error(`Internal error in dynamic time warping. Unexpected trace[${i}, ${a}]. Please file a bug report.`)}return l.reverse(),c.reverse(),[l,c]}},"./src/utils/tensor.js":
|
|
161
161
|
/*!*****************************!*\
|
|
162
162
|
!*** ./src/utils/tensor.js ***!
|
|
163
|
-
\*****************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{Tensor:()=>a,cat:()=>M,full:()=>T,full_like:()=>v,interpolate:()=>c,interpolate_4d:()=>d,layer_norm:()=>m,matmul:()=>u,mean:()=>x,mean_pooling:()=>_,ones:()=>F,ones_like:()=>C,permute:()=>l,quantize_embeddings:()=>A,rfft:()=>p,stack:()=>b,std_mean:()=>y,topk:()=>h,zeros:()=>P,zeros_like:()=>S});var s=n(/*! ./maths.js */"./src/utils/maths.js"),r=n(/*! ../backends/onnx.js */"./src/backends/onnx.js"),o=n(/*! ../ops/registry.js */"./src/ops/registry.js");const i=Object.freeze({float32:Float32Array,float16:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array});class a{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return(0,r.isONNXTensor)(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new r.Tensor(e[0],e[1],e[2]),new Proxy(this,{get:(e,t)=>{if("string"==typeof t){let n=Number(t);if(Number.isInteger(n))return e._getitem(n)}return e[t]},set:(e,t,n)=>e[t]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){const[e,...t]=this.dims;if(t.length>0){const n=t.reduce(((e,t)=>e*t));for(let s=0;s<e;++s)yield this._subarray(s,n,t)}else yield*this.data}_getitem(e){const[t,...n]=this.dims;if(e=w(e,t),n.length>0){const t=n.reduce(((e,t)=>e*t));return this._subarray(e,t,n)}return new a(this.type,[this.data[e]],n)}indexOf(e){const t=this.data;for(let n=0;n<t.length;++n)if(t[n]==e)return n;return-1}_subarray(e,t,n){const s=e*t,r=(e+1)*t,o="subarray"in this.data?this.data.subarray(s,r):this.data.slice(s,r);return new a(this.type,o,n)}item(){const e=this.data;if(1!==e.length)throw new Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return function(e,t){const n=e.length,s=t.reduce(((e,t)=>e*t));if(n!==s)throw Error(`cannot reshape array of size ${n} into shape (${t})`);let r=e;for(let e=t.length-1;e>=0;e--)r=r.reduce(((n,s)=>{let r=n[n.length-1];return r.length<t[e]?r.push(s):n.push([s]),n}),[[]]);return r[0]}(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=1/(1+Math.exp(-e[t]));return this}mul(e){return this.clone().mul_(e)}mul_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]*=e;return this}div(e){return this.clone().div_(e)}div_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]/=e;return this}add(e){return this.clone().add_(e)}add_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]+=e;return this}sub(e){return this.clone().sub_(e)}sub_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]-=e;return this}clone(){return new a(this.type,this.data.slice(),this.dims.slice())}slice(...e){const t=[],n=[];for(let s=0;s<this.dims.length;++s){let r=e[s];if(null==r)n.push([0,this.dims[s]]),t.push(this.dims[s]);else if("number"==typeof r)r=w(r,this.dims[s],s),n.push([r,r+1]);else{if(!Array.isArray(r)||2!==r.length)throw new Error(`Invalid slice: ${r}`);{let[e,o]=r;if(e=null===e?0:w(e,this.dims[s],s,!1),o=null===o?this.dims[s]:w(o,this.dims[s],s,!1),e>o)throw new Error(`Invalid slice: ${r}`);const i=[Math.max(e,0),Math.min(o,this.dims[s])];n.push(i),t.push(i[1]-i[0])}}}const s=n.map((([e,t])=>t-e)),r=s.reduce(((e,t)=>e*t)),o=this.data,i=new o.constructor(r),l=this.stride();for(let e=0;e<r;++e){let t=0;for(let r=s.length-1,o=e;r>=0;--r){const e=s[r];t+=(o%e+n[r][0])*l[r],o=Math.floor(o/e)}i[e]=o[t]}return new a(this.type,i,t)}permute(...e){return l(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,t=!1){return this.norm(1,e,t)}norm(e="fro",t=null,n=!1){if("fro"===e)e=2;else if("string"==typeof e)throw Error(`Unsupported norm: ${e}`);const s=this.data;if(null===t){let t=s.reduce(((t,n)=>t+n**e),0)**(1/e);return new a(this.type,[t],[])}t=w(t,this.dims.length);const r=this.dims.slice();r[t]=1;const o=new s.constructor(s.length/this.dims[t]);for(let n=0;n<s.length;++n){let i=0;for(let e=this.dims.length-1,s=n,o=1;e>=0;--e){const n=this.dims[e];if(e!==t){i+=s%n*o,o*=r[e]}s=Math.floor(s/n)}o[i]+=s[n]**e}if(1!==e)for(let t=0;t<o.length;++t)o[t]=o[t]**(1/e);return n||r.splice(t,1),new a(this.type,o,r)}normalize_(e=2,t=1){t=w(t,this.dims.length);const n=this.norm(e,t,!0),s=this.data,r=n.data;for(let e=0;e<s.length;++e){let n=0;for(let s=this.dims.length-1,r=e,o=1;s>=0;--s){const e=this.dims[s];if(s!==t){n+=r%e*o,o*=this.dims[s]}r=Math.floor(r/e)}s[e]/=r[n]}return this}normalize(e=2,t=1){return this.clone().normalize_(e,t)}stride(){return function(e){const t=new Array(e.length);for(let n=e.length-1,s=1;n>=0;--n)t[n]=s,s*=e[n];return t}(this.dims)}squeeze(e=null){return new a(this.type,this.data,f(this.dims,e))}squeeze_(e=null){return this.dims=f(this.dims,e),this}unsqueeze(e=null){return new a(this.type,this.data,g(this.dims,e))}unsqueeze_(e=null){return this.dims=g(this.dims,e),this}flatten_(e=0,t=-1){t=(t+this.dims.length)%this.dims.length;let n=this.dims.slice(0,e),s=this.dims.slice(e,t+1),r=this.dims.slice(t+1);return this.dims=[...n,s.reduce(((e,t)=>e*t),1),...r],this}flatten(e=0,t=-1){return this.clone().flatten_(e,t)}view(...e){let t=-1;for(let n=0;n<e.length;++n)if(-1===e[n]){if(-1!==t)throw new Error("Only one dimension can be inferred");t=n}const n=this.data;if(-1!==t){const s=e.reduce(((e,n,s)=>s!==t?e*n:e),1);e[t]=n.length/s}return new a(this.type,n,e)}neg_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=-e[t];return this}neg(){return this.clone().neg_()}clamp_(e,t){const n=this.data;for(let s=0;s<n.length;++s)n[s]=Math.min(Math.max(n[s],e),t);return this}clamp(e,t){return this.clone().clamp_(e,t)}round_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=Math.round(e[t]);return this}round(){return this.clone().round_()}mean(e=null,t=!1){return x(this,e,t)}to(e){if(this.type===e)return this;if(!i.hasOwnProperty(e))throw new Error(`Unsupported type: ${e}`);return new a(e,i[e].from(this.data),this.dims)}}function l(e,t){const[n,r]=(0,s.permute_data)(e.data,e.dims,t);return new a(e.type,n,r)}function c(e,[t,n],r="bilinear",o=!1){const i=e.dims.at(-3)??1,l=e.dims.at(-2),c=e.dims.at(-1);let d=(0,s.interpolate_data)(e.data,[i,l,c],[t,n],r,o);return new a(e.type,d,[i,t,n])}async function d(e,{size:t=null,mode:n="bilinear"}={}){if(4!==e.dims.length)throw new Error("`interpolate_4d` currently only supports 4D input.");if(!t)throw new Error("`interpolate_4d` requires a `size` argument.");let s,r;if(2===t.length)s=[...e.dims.slice(0,2),...t];else if(3===t.length)s=[e.dims[0],...t];else{if(4!==t.length)throw new Error("`size` must be of length 2, 3, or 4.");s=t}if("bilinear"===n)r=await o.TensorOpRegistry.bilinear_interpolate_4d;else{if("bicubic"!==n)throw new Error(`Unsupported mode: ${n}`);r=await o.TensorOpRegistry.bicubic_interpolate_4d}const i=new a("int64",new BigInt64Array(s.map(BigInt)),[s.length]);return await r({x:e,s:i})}async function u(e,t){const n=await o.TensorOpRegistry.matmul;return await n({a:e,b:t})}async function p(e,t){const n=await o.TensorOpRegistry.rfft;return await n({x:e,a:t})}async function h(e,t){const n=await o.TensorOpRegistry.top_k;return t=null===t?e.dims.at(-1):Math.min(t,e.dims.at(-1)),await n({x:e,k:new a("int64",[BigInt(t)],[1])})}function _(e,t){const n=e.data,s=t.data,r=[e.dims[0],e.dims[2]],o=new n.constructor(r[0]*r[1]),[i,l,c]=e.dims;let d=0;for(let e=0;e<i;++e){const t=e*c*l;for(let r=0;r<c;++r){let i=0,a=0;const u=e*l,p=t+r;for(let e=0;e<l;++e){const t=Number(s[u+e]);a+=t,i+=n[p+e*c]*t}const h=i/a;o[d++]=h}}return new a(e.type,o,r)}function m(e,t,{eps:n=1e-5}={}){if(2!==e.dims.length)throw new Error("`layer_norm` currently only supports 2D input.");const[s,r]=e.dims;if(1!==t.length&&t[0]!==r)throw new Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");const[o,i]=y(e,1,0,!0),l=o.data,c=i.data,d=e.data,u=new d.constructor(d.length);for(let e=0;e<s;++e){const t=e*r;for(let s=0;s<r;++s){const r=t+s;u[r]=(d[r]-c[e])/(l[e]+n)}}return new a(e.type,u,e.dims)}function f(e,t){return e=e.slice(),null===t?e=e.filter((e=>1!==e)):"number"==typeof t?1===e[t]&&e.splice(t,1):Array.isArray(t)&&(e=e.filter(((e,n)=>1!==e||!t.includes(n)))),e}function g(e,t){return t=w(t,e.length+1),(e=e.slice()).splice(t,0,1),e}function w(e,t,n=null,s=!0){if(s&&(e<-t||e>=t))throw new Error(`IndexError: index ${e} is out of bounds for dimension${null===n?"":" "+n} with size ${t}`);return e<0&&(e=(e%t+t)%t),e}function M(e,t=0){t=w(t,e[0].dims.length);const n=e[0].dims.slice();n[t]=e.reduce(((e,n)=>e+n.dims[t]),0);const s=n.reduce(((e,t)=>e*t),1),r=new e[0].data.constructor(s),o=e[0].type;if(0===t){let t=0;for(const n of e){const e=n.data;r.set(e,t),t+=e.length}}else{let s=0;for(let o=0;o<e.length;++o){const{data:i,dims:a}=e[o];for(let e=0;e<i.length;++e){let o=0;for(let r=a.length-1,i=e,l=1;r>=0;--r){const e=a[r];let c=i%e;r===t&&(c+=s),o+=c*l,l*=n[r],i=Math.floor(i/e)}r[o]=i[e]}s+=a[t]}}return new a(o,r,n)}function b(e,t=0){return M(e.map((e=>e.unsqueeze(t))),t)}function y(e,t=null,n=1,s=!1){const r=e.data,o=e.dims;if(null===t){const t=r.reduce(((e,t)=>e+t),0)/r.length,s=Math.sqrt(r.reduce(((e,n)=>e+(n-t)**2),0)/(r.length-n)),o=new a(e.type,[t],[]);return[new a(e.type,[s],[]),o]}const i=x(e,t=w(t,o.length),s),l=i.data,c=o.slice();c[t]=1;const d=new r.constructor(r.length/o[t]);for(let e=0;e<r.length;++e){let n=0;for(let s=o.length-1,r=e,i=1;s>=0;--s){const e=o[s];if(s!==t){n+=r%e*i,i*=c[s]}r=Math.floor(r/e)}d[n]+=(r[e]-l[n])**2}for(let e=0;e<d.length;++e)d[e]=Math.sqrt(d[e]/(o[t]-n));s||c.splice(t,1);return[new a(e.type,d,c),i]}function x(e,t=null,n=!1){const s=e.data;if(null===t){const t=s.reduce(((e,t)=>e+t),0);return new a(e.type,[t/s.length],[])}const r=e.dims;t=w(t,r.length);const o=r.slice();o[t]=1;const i=new s.constructor(s.length/r[t]);for(let e=0;e<s.length;++e){let n=0;for(let s=r.length-1,i=e,a=1;s>=0;--s){const e=r[s];if(s!==t){n+=i%e*a,a*=o[s]}i=Math.floor(i/e)}i[n]+=s[e]}if(1!==r[t])for(let e=0;e<i.length;++e)i[e]=i[e]/r[t];return n||o.splice(t,1),new a(e.type,i,o)}function k(e,t,n,s){const r=e.reduce(((e,t)=>e*t),1);return new a(n,new s(r).fill(t),e)}function T(e,t){let n,s;if("number"==typeof t)n="float32",s=Float32Array;else{if("bigint"!=typeof t)throw new Error("Unsupported data type: "+typeof t);n="int64",s=BigInt64Array}return k(e,t,n,s)}function v(e,t){return T(e.dims,t)}function F(e){return k(e,1n,"int64",BigInt64Array)}function C(e){return F(e.dims)}function P(e){return k(e,0n,"int64",BigInt64Array)}function S(e){return P(e.dims)}function A(e,t){if(2!==e.dims.length)throw new Error("The tensor must have 2 dimensions");if(e.dims.at(-1)%8!=0)throw new Error("The last dimension of the tensor must be a multiple of 8");if(!["binary","ubinary"].includes(t))throw new Error("The precision must be either 'binary' or 'ubinary'");const n="binary"===t,s=n?"int8":"uint8",r=n?Int8Array:Uint8Array,o=e.data,i=new r(o.length/8);for(let e=0;e<o.length;++e){const t=o[e]>0?1:0,s=Math.floor(e/8),r=e%8;i[s]|=t<<7-r,n&&0===r&&(i[s]-=128)}return new a(s,i,[e.dims[0],e.dims[1]/8])}}},s={};function r(e){var t=s[e];if(void 0!==t)return t.exports;var o=s[e]={exports:{}};return n[e](o,o.exports,r),o.exports}t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,r.t=function(n,s){if(1&s&&(n=this(n)),8&s)return n;if("object"==typeof n&&n){if(4&s&&n.__esModule)return n;if(16&s&&"function"==typeof n.then)return n}var o=Object.create(null);r.r(o);var i={};e=e||[null,t({}),t([]),t(t)];for(var a=2&s&&n;"object"==typeof a&&!~e.indexOf(a);a=t(a))Object.getOwnPropertyNames(a).forEach((e=>i[e]=()=>n[e]));return i.default=()=>n,r.d(o,i),o},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";
|
|
163
|
+
\*****************************/(e,t,n)=>{"use strict";n.r(t),n.d(t,{Tensor:()=>a,cat:()=>M,full:()=>T,full_like:()=>v,interpolate:()=>c,interpolate_4d:()=>d,layer_norm:()=>m,matmul:()=>u,mean:()=>x,mean_pooling:()=>_,ones:()=>F,ones_like:()=>C,permute:()=>l,quantize_embeddings:()=>A,rfft:()=>p,stack:()=>b,std_mean:()=>y,topk:()=>h,zeros:()=>P,zeros_like:()=>S});var s=n(/*! ./maths.js */"./src/utils/maths.js"),r=n(/*! ../backends/onnx.js */"./src/backends/onnx.js"),o=n(/*! ../ops/registry.js */"./src/ops/registry.js");const i=Object.freeze({float32:Float32Array,float16:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array});class a{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return(0,r.isONNXTensor)(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new r.Tensor(e[0],e[1],e[2]),new Proxy(this,{get:(e,t)=>{if("string"==typeof t){let n=Number(t);if(Number.isInteger(n))return e._getitem(n)}return e[t]},set:(e,t,n)=>e[t]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){const[e,...t]=this.dims;if(t.length>0){const n=t.reduce(((e,t)=>e*t));for(let s=0;s<e;++s)yield this._subarray(s,n,t)}else yield*this.data}_getitem(e){const[t,...n]=this.dims;if(e=w(e,t),n.length>0){const t=n.reduce(((e,t)=>e*t));return this._subarray(e,t,n)}return new a(this.type,[this.data[e]],n)}indexOf(e){const t=this.data;for(let n=0;n<t.length;++n)if(t[n]==e)return n;return-1}_subarray(e,t,n){const s=e*t,r=(e+1)*t,o="subarray"in this.data?this.data.subarray(s,r):this.data.slice(s,r);return new a(this.type,o,n)}item(){const e=this.data;if(1!==e.length)throw new Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return function(e,t){const n=e.length,s=t.reduce(((e,t)=>e*t));if(n!==s)throw Error(`cannot reshape array of size ${n} into shape (${t})`);let r=e;for(let e=t.length-1;e>=0;e--)r=r.reduce(((n,s)=>{let r=n[n.length-1];return r.length<t[e]?r.push(s):n.push([s]),n}),[[]]);return r[0]}(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=1/(1+Math.exp(-e[t]));return this}map(e){return this.clone().map_(e)}map_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]=e(t[n],n,t);return this}mul(e){return this.clone().mul_(e)}mul_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]*=e;return this}div(e){return this.clone().div_(e)}div_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]/=e;return this}add(e){return this.clone().add_(e)}add_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]+=e;return this}sub(e){return this.clone().sub_(e)}sub_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]-=e;return this}clone(){return new a(this.type,this.data.slice(),this.dims.slice())}slice(...e){const t=[],n=[];for(let s=0;s<this.dims.length;++s){let r=e[s];if(null==r)n.push([0,this.dims[s]]),t.push(this.dims[s]);else if("number"==typeof r)r=w(r,this.dims[s],s),n.push([r,r+1]);else{if(!Array.isArray(r)||2!==r.length)throw new Error(`Invalid slice: ${r}`);{let[e,o]=r;if(e=null===e?0:w(e,this.dims[s],s,!1),o=null===o?this.dims[s]:w(o,this.dims[s],s,!1),e>o)throw new Error(`Invalid slice: ${r}`);const i=[Math.max(e,0),Math.min(o,this.dims[s])];n.push(i),t.push(i[1]-i[0])}}}const s=n.map((([e,t])=>t-e)),r=s.reduce(((e,t)=>e*t)),o=this.data,i=new o.constructor(r),l=this.stride();for(let e=0;e<r;++e){let t=0;for(let r=s.length-1,o=e;r>=0;--r){const e=s[r];t+=(o%e+n[r][0])*l[r],o=Math.floor(o/e)}i[e]=o[t]}return new a(this.type,i,t)}permute(...e){return l(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,t=!1){return this.norm(1,e,t)}norm(e="fro",t=null,n=!1){if("fro"===e)e=2;else if("string"==typeof e)throw Error(`Unsupported norm: ${e}`);const s=this.data;if(null===t){let t=s.reduce(((t,n)=>t+n**e),0)**(1/e);return new a(this.type,[t],[])}t=w(t,this.dims.length);const r=this.dims.slice();r[t]=1;const o=new s.constructor(s.length/this.dims[t]);for(let n=0;n<s.length;++n){let i=0;for(let e=this.dims.length-1,s=n,o=1;e>=0;--e){const n=this.dims[e];if(e!==t){i+=s%n*o,o*=r[e]}s=Math.floor(s/n)}o[i]+=s[n]**e}if(1!==e)for(let t=0;t<o.length;++t)o[t]=o[t]**(1/e);return n||r.splice(t,1),new a(this.type,o,r)}normalize_(e=2,t=1){t=w(t,this.dims.length);const n=this.norm(e,t,!0),s=this.data,r=n.data;for(let e=0;e<s.length;++e){let n=0;for(let s=this.dims.length-1,r=e,o=1;s>=0;--s){const e=this.dims[s];if(s!==t){n+=r%e*o,o*=this.dims[s]}r=Math.floor(r/e)}s[e]/=r[n]}return this}normalize(e=2,t=1){return this.clone().normalize_(e,t)}stride(){return function(e){const t=new Array(e.length);for(let n=e.length-1,s=1;n>=0;--n)t[n]=s,s*=e[n];return t}(this.dims)}squeeze(e=null){return new a(this.type,this.data,f(this.dims,e))}squeeze_(e=null){return this.dims=f(this.dims,e),this}unsqueeze(e=null){return new a(this.type,this.data,g(this.dims,e))}unsqueeze_(e=null){return this.dims=g(this.dims,e),this}flatten_(e=0,t=-1){t=(t+this.dims.length)%this.dims.length;let n=this.dims.slice(0,e),s=this.dims.slice(e,t+1),r=this.dims.slice(t+1);return this.dims=[...n,s.reduce(((e,t)=>e*t),1),...r],this}flatten(e=0,t=-1){return this.clone().flatten_(e,t)}view(...e){let t=-1;for(let n=0;n<e.length;++n)if(-1===e[n]){if(-1!==t)throw new Error("Only one dimension can be inferred");t=n}const n=this.data;if(-1!==t){const s=e.reduce(((e,n,s)=>s!==t?e*n:e),1);e[t]=n.length/s}return new a(this.type,n,e)}neg_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=-e[t];return this}neg(){return this.clone().neg_()}clamp_(e,t){const n=this.data;for(let s=0;s<n.length;++s)n[s]=Math.min(Math.max(n[s],e),t);return this}clamp(e,t){return this.clone().clamp_(e,t)}round_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=Math.round(e[t]);return this}round(){return this.clone().round_()}mean(e=null,t=!1){return x(this,e,t)}to(e){if(this.type===e)return this;if(!i.hasOwnProperty(e))throw new Error(`Unsupported type: ${e}`);return new a(e,i[e].from(this.data),this.dims)}}function l(e,t){const[n,r]=(0,s.permute_data)(e.data,e.dims,t);return new a(e.type,n,r)}function c(e,[t,n],r="bilinear",o=!1){const i=e.dims.at(-3)??1,l=e.dims.at(-2),c=e.dims.at(-1);let d=(0,s.interpolate_data)(e.data,[i,l,c],[t,n],r,o);return new a(e.type,d,[i,t,n])}async function d(e,{size:t=null,mode:n="bilinear"}={}){if(4!==e.dims.length)throw new Error("`interpolate_4d` currently only supports 4D input.");if(!t)throw new Error("`interpolate_4d` requires a `size` argument.");let s,r;if(2===t.length)s=[...e.dims.slice(0,2),...t];else if(3===t.length)s=[e.dims[0],...t];else{if(4!==t.length)throw new Error("`size` must be of length 2, 3, or 4.");s=t}if("bilinear"===n)r=await o.TensorOpRegistry.bilinear_interpolate_4d;else{if("bicubic"!==n)throw new Error(`Unsupported mode: ${n}`);r=await o.TensorOpRegistry.bicubic_interpolate_4d}const i=new a("int64",new BigInt64Array(s.map(BigInt)),[s.length]);return await r({x:e,s:i})}async function u(e,t){const n=await o.TensorOpRegistry.matmul;return await n({a:e,b:t})}async function p(e,t){const n=await o.TensorOpRegistry.rfft;return await n({x:e,a:t})}async function h(e,t){const n=await o.TensorOpRegistry.top_k;return t=null===t?e.dims.at(-1):Math.min(t,e.dims.at(-1)),await n({x:e,k:new a("int64",[BigInt(t)],[1])})}function _(e,t){const n=e.data,s=t.data,r=[e.dims[0],e.dims[2]],o=new n.constructor(r[0]*r[1]),[i,l,c]=e.dims;let d=0;for(let e=0;e<i;++e){const t=e*c*l;for(let r=0;r<c;++r){let i=0,a=0;const u=e*l,p=t+r;for(let e=0;e<l;++e){const t=Number(s[u+e]);a+=t,i+=n[p+e*c]*t}const h=i/a;o[d++]=h}}return new a(e.type,o,r)}function m(e,t,{eps:n=1e-5}={}){if(2!==e.dims.length)throw new Error("`layer_norm` currently only supports 2D input.");const[s,r]=e.dims;if(1!==t.length&&t[0]!==r)throw new Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");const[o,i]=y(e,1,0,!0),l=o.data,c=i.data,d=e.data,u=new d.constructor(d.length);for(let e=0;e<s;++e){const t=e*r;for(let s=0;s<r;++s){const r=t+s;u[r]=(d[r]-c[e])/(l[e]+n)}}return new a(e.type,u,e.dims)}function f(e,t){return e=e.slice(),null===t?e=e.filter((e=>1!==e)):"number"==typeof t?1===e[t]&&e.splice(t,1):Array.isArray(t)&&(e=e.filter(((e,n)=>1!==e||!t.includes(n)))),e}function g(e,t){return t=w(t,e.length+1),(e=e.slice()).splice(t,0,1),e}function w(e,t,n=null,s=!0){if(s&&(e<-t||e>=t))throw new Error(`IndexError: index ${e} is out of bounds for dimension${null===n?"":" "+n} with size ${t}`);return e<0&&(e=(e%t+t)%t),e}function M(e,t=0){t=w(t,e[0].dims.length);const n=e[0].dims.slice();n[t]=e.reduce(((e,n)=>e+n.dims[t]),0);const s=n.reduce(((e,t)=>e*t),1),r=new e[0].data.constructor(s),o=e[0].type;if(0===t){let t=0;for(const n of e){const e=n.data;r.set(e,t),t+=e.length}}else{let s=0;for(let o=0;o<e.length;++o){const{data:i,dims:a}=e[o];for(let e=0;e<i.length;++e){let o=0;for(let r=a.length-1,i=e,l=1;r>=0;--r){const e=a[r];let c=i%e;r===t&&(c+=s),o+=c*l,l*=n[r],i=Math.floor(i/e)}r[o]=i[e]}s+=a[t]}}return new a(o,r,n)}function b(e,t=0){return M(e.map((e=>e.unsqueeze(t))),t)}function y(e,t=null,n=1,s=!1){const r=e.data,o=e.dims;if(null===t){const t=r.reduce(((e,t)=>e+t),0)/r.length,s=Math.sqrt(r.reduce(((e,n)=>e+(n-t)**2),0)/(r.length-n)),o=new a(e.type,[t],[]);return[new a(e.type,[s],[]),o]}const i=x(e,t=w(t,o.length),s),l=i.data,c=o.slice();c[t]=1;const d=new r.constructor(r.length/o[t]);for(let e=0;e<r.length;++e){let n=0;for(let s=o.length-1,r=e,i=1;s>=0;--s){const e=o[s];if(s!==t){n+=r%e*i,i*=c[s]}r=Math.floor(r/e)}d[n]+=(r[e]-l[n])**2}for(let e=0;e<d.length;++e)d[e]=Math.sqrt(d[e]/(o[t]-n));s||c.splice(t,1);return[new a(e.type,d,c),i]}function x(e,t=null,n=!1){const s=e.data;if(null===t){const t=s.reduce(((e,t)=>e+t),0);return new a(e.type,[t/s.length],[])}const r=e.dims;t=w(t,r.length);const o=r.slice();o[t]=1;const i=new s.constructor(s.length/r[t]);for(let e=0;e<s.length;++e){let n=0;for(let s=r.length-1,i=e,a=1;s>=0;--s){const e=r[s];if(s!==t){n+=i%e*a,a*=o[s]}i=Math.floor(i/e)}i[n]+=s[e]}if(1!==r[t])for(let e=0;e<i.length;++e)i[e]=i[e]/r[t];return n||o.splice(t,1),new a(e.type,i,o)}function k(e,t,n,s){const r=e.reduce(((e,t)=>e*t),1);return new a(n,new s(r).fill(t),e)}function T(e,t){let n,s;if("number"==typeof t)n="float32",s=Float32Array;else{if("bigint"!=typeof t)throw new Error("Unsupported data type: "+typeof t);n="int64",s=BigInt64Array}return k(e,t,n,s)}function v(e,t){return T(e.dims,t)}function F(e){return k(e,1n,"int64",BigInt64Array)}function C(e){return F(e.dims)}function P(e){return k(e,0n,"int64",BigInt64Array)}function S(e){return P(e.dims)}function A(e,t){if(2!==e.dims.length)throw new Error("The tensor must have 2 dimensions");if(e.dims.at(-1)%8!=0)throw new Error("The last dimension of the tensor must be a multiple of 8");if(!["binary","ubinary"].includes(t))throw new Error("The precision must be either 'binary' or 'ubinary'");const n="binary"===t,s=n?"int8":"uint8",r=n?Int8Array:Uint8Array,o=e.data,i=new r(o.length/8);for(let e=0;e<o.length;++e){const t=o[e]>0?1:0,s=Math.floor(e/8),r=e%8;i[s]|=t<<7-r,n&&0===r&&(i[s]-=128)}return new a(s,i,[e.dims[0],e.dims[1]/8])}}},s={};function r(e){var t=s[e];if(void 0!==t)return t.exports;var o=s[e]={exports:{}};return n[e](o,o.exports,r),o.exports}t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,r.t=function(n,s){if(1&s&&(n=this(n)),8&s)return n;if("object"==typeof n&&n){if(4&s&&n.__esModule)return n;if(16&s&&"function"==typeof n.then)return n}var o=Object.create(null);r.r(o);var i={};e=e||[null,t({}),t([]),t(t)];for(var a=2&s&&n;"object"==typeof a&&!~e.indexOf(a);a=t(a))Object.getOwnPropertyNames(a).forEach((e=>i[e]=()=>n[e]));return i.default=()=>n,r.d(o,i),o},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";
|
|
164
164
|
/*!*****************************!*\
|
|
165
165
|
!*** ./src/transformers.js ***!
|
|
166
|
-
\*****************************/r.r(o),r.d(o,{ASTFeatureExtractor:()=>i.ASTFeatureExtractor,ASTForAudioClassification:()=>n.ASTForAudioClassification,ASTModel:()=>n.ASTModel,ASTPreTrainedModel:()=>n.ASTPreTrainedModel,AlbertForMaskedLM:()=>n.AlbertForMaskedLM,AlbertForQuestionAnswering:()=>n.AlbertForQuestionAnswering,AlbertForSequenceClassification:()=>n.AlbertForSequenceClassification,AlbertModel:()=>n.AlbertModel,AlbertPreTrainedModel:()=>n.AlbertPreTrainedModel,AlbertTokenizer:()=>s.AlbertTokenizer,AudioClassificationPipeline:()=>t.AudioClassificationPipeline,AutoConfig:()=>a.AutoConfig,AutoModel:()=>n.AutoModel,AutoModelForAudioClassification:()=>n.AutoModelForAudioClassification,AutoModelForAudioFrameClassification:()=>n.AutoModelForAudioFrameClassification,AutoModelForCTC:()=>n.AutoModelForCTC,AutoModelForCausalLM:()=>n.AutoModelForCausalLM,AutoModelForDepthEstimation:()=>n.AutoModelForDepthEstimation,AutoModelForDocumentQuestionAnswering:()=>n.AutoModelForDocumentQuestionAnswering,AutoModelForImageClassification:()=>n.AutoModelForImageClassification,AutoModelForImageFeatureExtraction:()=>n.AutoModelForImageFeatureExtraction,AutoModelForImageMatting:()=>n.AutoModelForImageMatting,AutoModelForImageSegmentation:()=>n.AutoModelForImageSegmentation,AutoModelForImageToImage:()=>n.AutoModelForImageToImage,AutoModelForMaskGeneration:()=>n.AutoModelForMaskGeneration,AutoModelForMaskedLM:()=>n.AutoModelForMaskedLM,AutoModelForNormalEstimation:()=>n.AutoModelForNormalEstimation,AutoModelForObjectDetection:()=>n.AutoModelForObjectDetection,AutoModelForQuestionAnswering:()=>n.AutoModelForQuestionAnswering,AutoModelForSemanticSegmentation:()=>n.AutoModelForSemanticSegmentation,AutoModelForSeq2SeqLM:()=>n.AutoModelForSeq2SeqLM,AutoModelForSequenceClassification:()=>n.AutoModelForSequenceClassification,AutoModelForSpeechSeq2Seq:()=>n.AutoModelForSpeechSeq2Seq,AutoModelForTextToSpectrogram:()=>n.AutoModelForTextToSpectrogram,AutoModelForTextToWaveform:()=>n.AutoModelForTextToWaveform,AutoModelForTokenClassification:()=>n.AutoModelForTokenClassification,AutoModelForUniversalSegmentation:()=>n.AutoModelForUniversalSegmentation,AutoModelForVision2Seq:()=>n.AutoModelForVision2Seq,AutoModelForXVector:()=>n.AutoModelForXVector,AutoModelForZeroShotObjectDetection:()=>n.AutoModelForZeroShotObjectDetection,AutoProcessor:()=>i.AutoProcessor,AutoTokenizer:()=>s.AutoTokenizer,AutomaticSpeechRecognitionPipeline:()=>t.AutomaticSpeechRecognitionPipeline,BartForConditionalGeneration:()=>n.BartForConditionalGeneration,BartForSequenceClassification:()=>n.BartForSequenceClassification,BartModel:()=>n.BartModel,BartPretrainedModel:()=>n.BartPretrainedModel,BartTokenizer:()=>s.BartTokenizer,BaseModelOutput:()=>n.BaseModelOutput,BaseStreamer:()=>p.BaseStreamer,BeitFeatureExtractor:()=>i.BeitFeatureExtractor,BeitForImageClassification:()=>n.BeitForImageClassification,BeitModel:()=>n.BeitModel,BeitPreTrainedModel:()=>n.BeitPreTrainedModel,BertForMaskedLM:()=>n.BertForMaskedLM,BertForQuestionAnswering:()=>n.BertForQuestionAnswering,BertForSequenceClassification:()=>n.BertForSequenceClassification,BertForTokenClassification:()=>n.BertForTokenClassification,BertModel:()=>n.BertModel,BertPreTrainedModel:()=>n.BertPreTrainedModel,BertTokenizer:()=>s.BertTokenizer,BitImageProcessor:()=>i.BitImageProcessor,BlenderbotForConditionalGeneration:()=>n.BlenderbotForConditionalGeneration,BlenderbotModel:()=>n.BlenderbotModel,BlenderbotPreTrainedModel:()=>n.BlenderbotPreTrainedModel,BlenderbotSmallForConditionalGeneration:()=>n.BlenderbotSmallForConditionalGeneration,BlenderbotSmallModel:()=>n.BlenderbotSmallModel,BlenderbotSmallPreTrainedModel:()=>n.BlenderbotSmallPreTrainedModel,BlenderbotSmallTokenizer:()=>s.BlenderbotSmallTokenizer,BlenderbotTokenizer:()=>s.BlenderbotTokenizer,BloomForCausalLM:()=>n.BloomForCausalLM,BloomModel:()=>n.BloomModel,BloomPreTrainedModel:()=>n.BloomPreTrainedModel,BloomTokenizer:()=>s.BloomTokenizer,CLIPFeatureExtractor:()=>i.CLIPFeatureExtractor,CLIPImageProcessor:()=>i.CLIPImageProcessor,CLIPModel:()=>n.CLIPModel,CLIPPreTrainedModel:()=>n.CLIPPreTrainedModel,CLIPSegForImageSegmentation:()=>n.CLIPSegForImageSegmentation,CLIPSegModel:()=>n.CLIPSegModel,CLIPSegPreTrainedModel:()=>n.CLIPSegPreTrainedModel,CLIPTextModel:()=>n.CLIPTextModel,CLIPTextModelWithProjection:()=>n.CLIPTextModelWithProjection,CLIPTokenizer:()=>s.CLIPTokenizer,CLIPVisionModel:()=>n.CLIPVisionModel,CLIPVisionModelWithProjection:()=>n.CLIPVisionModelWithProjection,CamembertForMaskedLM:()=>n.CamembertForMaskedLM,CamembertForQuestionAnswering:()=>n.CamembertForQuestionAnswering,CamembertForSequenceClassification:()=>n.CamembertForSequenceClassification,CamembertForTokenClassification:()=>n.CamembertForTokenClassification,CamembertModel:()=>n.CamembertModel,CamembertPreTrainedModel:()=>n.CamembertPreTrainedModel,CamembertTokenizer:()=>s.CamembertTokenizer,CausalLMOutput:()=>n.CausalLMOutput,CausalLMOutputWithPast:()=>n.CausalLMOutputWithPast,ChineseCLIPFeatureExtractor:()=>i.ChineseCLIPFeatureExtractor,ChineseCLIPModel:()=>n.ChineseCLIPModel,ChineseCLIPPreTrainedModel:()=>n.ChineseCLIPPreTrainedModel,ClapAudioModelWithProjection:()=>n.ClapAudioModelWithProjection,ClapFeatureExtractor:()=>i.ClapFeatureExtractor,ClapModel:()=>n.ClapModel,ClapPreTrainedModel:()=>n.ClapPreTrainedModel,ClapTextModelWithProjection:()=>n.ClapTextModelWithProjection,CodeGenForCausalLM:()=>n.CodeGenForCausalLM,CodeGenModel:()=>n.CodeGenModel,CodeGenPreTrainedModel:()=>n.CodeGenPreTrainedModel,CodeGenTokenizer:()=>s.CodeGenTokenizer,CodeLlamaTokenizer:()=>s.CodeLlamaTokenizer,CohereForCausalLM:()=>n.CohereForCausalLM,CohereModel:()=>n.CohereModel,CoherePreTrainedModel:()=>n.CoherePreTrainedModel,CohereTokenizer:()=>s.CohereTokenizer,ConvBertForMaskedLM:()=>n.ConvBertForMaskedLM,ConvBertForQuestionAnswering:()=>n.ConvBertForQuestionAnswering,ConvBertForSequenceClassification:()=>n.ConvBertForSequenceClassification,ConvBertForTokenClassification:()=>n.ConvBertForTokenClassification,ConvBertModel:()=>n.ConvBertModel,ConvBertPreTrainedModel:()=>n.ConvBertPreTrainedModel,ConvBertTokenizer:()=>s.ConvBertTokenizer,ConvNextFeatureExtractor:()=>i.ConvNextFeatureExtractor,ConvNextForImageClassification:()=>n.ConvNextForImageClassification,ConvNextImageProcessor:()=>i.ConvNextImageProcessor,ConvNextModel:()=>n.ConvNextModel,ConvNextPreTrainedModel:()=>n.ConvNextPreTrainedModel,ConvNextV2ForImageClassification:()=>n.ConvNextV2ForImageClassification,ConvNextV2Model:()=>n.ConvNextV2Model,ConvNextV2PreTrainedModel:()=>n.ConvNextV2PreTrainedModel,DPTFeatureExtractor:()=>i.DPTFeatureExtractor,DPTForDepthEstimation:()=>n.DPTForDepthEstimation,DPTImageProcessor:()=>i.DPTImageProcessor,DPTModel:()=>n.DPTModel,DPTPreTrainedModel:()=>n.DPTPreTrainedModel,DebertaForMaskedLM:()=>n.DebertaForMaskedLM,DebertaForQuestionAnswering:()=>n.DebertaForQuestionAnswering,DebertaForSequenceClassification:()=>n.DebertaForSequenceClassification,DebertaForTokenClassification:()=>n.DebertaForTokenClassification,DebertaModel:()=>n.DebertaModel,DebertaPreTrainedModel:()=>n.DebertaPreTrainedModel,DebertaTokenizer:()=>s.DebertaTokenizer,DebertaV2ForMaskedLM:()=>n.DebertaV2ForMaskedLM,DebertaV2ForQuestionAnswering:()=>n.DebertaV2ForQuestionAnswering,DebertaV2ForSequenceClassification:()=>n.DebertaV2ForSequenceClassification,DebertaV2ForTokenClassification:()=>n.DebertaV2ForTokenClassification,DebertaV2Model:()=>n.DebertaV2Model,DebertaV2PreTrainedModel:()=>n.DebertaV2PreTrainedModel,DebertaV2Tokenizer:()=>s.DebertaV2Tokenizer,DecisionTransformerModel:()=>n.DecisionTransformerModel,DecisionTransformerPreTrainedModel:()=>n.DecisionTransformerPreTrainedModel,DeiTFeatureExtractor:()=>i.DeiTFeatureExtractor,DeiTForImageClassification:()=>n.DeiTForImageClassification,DeiTModel:()=>n.DeiTModel,DeiTPreTrainedModel:()=>n.DeiTPreTrainedModel,DepthAnythingForDepthEstimation:()=>n.DepthAnythingForDepthEstimation,DepthAnythingPreTrainedModel:()=>n.DepthAnythingPreTrainedModel,DepthEstimationPipeline:()=>t.DepthEstimationPipeline,DepthProForDepthEstimation:()=>n.DepthProForDepthEstimation,DepthProPreTrainedModel:()=>n.DepthProPreTrainedModel,DetrFeatureExtractor:()=>i.DetrFeatureExtractor,DetrForObjectDetection:()=>n.DetrForObjectDetection,DetrForSegmentation:()=>n.DetrForSegmentation,DetrModel:()=>n.DetrModel,DetrObjectDetectionOutput:()=>n.DetrObjectDetectionOutput,DetrPreTrainedModel:()=>n.DetrPreTrainedModel,DetrSegmentationOutput:()=>n.DetrSegmentationOutput,Dinov2ForImageClassification:()=>n.Dinov2ForImageClassification,Dinov2Model:()=>n.Dinov2Model,Dinov2PreTrainedModel:()=>n.Dinov2PreTrainedModel,DistilBertForMaskedLM:()=>n.DistilBertForMaskedLM,DistilBertForQuestionAnswering:()=>n.DistilBertForQuestionAnswering,DistilBertForSequenceClassification:()=>n.DistilBertForSequenceClassification,DistilBertForTokenClassification:()=>n.DistilBertForTokenClassification,DistilBertModel:()=>n.DistilBertModel,DistilBertPreTrainedModel:()=>n.DistilBertPreTrainedModel,DistilBertTokenizer:()=>s.DistilBertTokenizer,DocumentQuestionAnsweringPipeline:()=>t.DocumentQuestionAnsweringPipeline,DonutFeatureExtractor:()=>i.DonutFeatureExtractor,DonutSwinModel:()=>n.DonutSwinModel,DonutSwinPreTrainedModel:()=>n.DonutSwinPreTrainedModel,EfficientNetForImageClassification:()=>n.EfficientNetForImageClassification,EfficientNetImageProcessor:()=>i.EfficientNetImageProcessor,EfficientNetModel:()=>n.EfficientNetModel,EfficientNetPreTrainedModel:()=>n.EfficientNetPreTrainedModel,ElectraForMaskedLM:()=>n.ElectraForMaskedLM,ElectraForQuestionAnswering:()=>n.ElectraForQuestionAnswering,ElectraForSequenceClassification:()=>n.ElectraForSequenceClassification,ElectraForTokenClassification:()=>n.ElectraForTokenClassification,ElectraModel:()=>n.ElectraModel,ElectraPreTrainedModel:()=>n.ElectraPreTrainedModel,ElectraTokenizer:()=>s.ElectraTokenizer,EosTokenCriteria:()=>h.EosTokenCriteria,EsmForMaskedLM:()=>n.EsmForMaskedLM,EsmForSequenceClassification:()=>n.EsmForSequenceClassification,EsmForTokenClassification:()=>n.EsmForTokenClassification,EsmModel:()=>n.EsmModel,EsmPreTrainedModel:()=>n.EsmPreTrainedModel,EsmTokenizer:()=>s.EsmTokenizer,FFT:()=>u.FFT,FalconForCausalLM:()=>n.FalconForCausalLM,FalconModel:()=>n.FalconModel,FalconPreTrainedModel:()=>n.FalconPreTrainedModel,FalconTokenizer:()=>s.FalconTokenizer,FastViTForImageClassification:()=>n.FastViTForImageClassification,FastViTModel:()=>n.FastViTModel,FastViTPreTrainedModel:()=>n.FastViTPreTrainedModel,FeatureExtractionPipeline:()=>t.FeatureExtractionPipeline,FeatureExtractor:()=>i.FeatureExtractor,FillMaskPipeline:()=>t.FillMaskPipeline,Florence2ForConditionalGeneration:()=>n.Florence2ForConditionalGeneration,Florence2PreTrainedModel:()=>n.Florence2PreTrainedModel,Florence2Processor:()=>i.Florence2Processor,GLPNFeatureExtractor:()=>i.GLPNFeatureExtractor,GLPNForDepthEstimation:()=>n.GLPNForDepthEstimation,GLPNModel:()=>n.GLPNModel,GLPNPreTrainedModel:()=>n.GLPNPreTrainedModel,GPT2LMHeadModel:()=>n.GPT2LMHeadModel,GPT2Model:()=>n.GPT2Model,GPT2PreTrainedModel:()=>n.GPT2PreTrainedModel,GPT2Tokenizer:()=>s.GPT2Tokenizer,GPTBigCodeForCausalLM:()=>n.GPTBigCodeForCausalLM,GPTBigCodeModel:()=>n.GPTBigCodeModel,GPTBigCodePreTrainedModel:()=>n.GPTBigCodePreTrainedModel,GPTJForCausalLM:()=>n.GPTJForCausalLM,GPTJModel:()=>n.GPTJModel,GPTJPreTrainedModel:()=>n.GPTJPreTrainedModel,GPTNeoForCausalLM:()=>n.GPTNeoForCausalLM,GPTNeoModel:()=>n.GPTNeoModel,GPTNeoPreTrainedModel:()=>n.GPTNeoPreTrainedModel,GPTNeoXForCausalLM:()=>n.GPTNeoXForCausalLM,GPTNeoXModel:()=>n.GPTNeoXModel,GPTNeoXPreTrainedModel:()=>n.GPTNeoXPreTrainedModel,GPTNeoXTokenizer:()=>s.GPTNeoXTokenizer,Gemma2ForCausalLM:()=>n.Gemma2ForCausalLM,Gemma2Model:()=>n.Gemma2Model,Gemma2PreTrainedModel:()=>n.Gemma2PreTrainedModel,GemmaForCausalLM:()=>n.GemmaForCausalLM,GemmaModel:()=>n.GemmaModel,GemmaPreTrainedModel:()=>n.GemmaPreTrainedModel,GemmaTokenizer:()=>s.GemmaTokenizer,Grok1Tokenizer:()=>s.Grok1Tokenizer,GroupViTModel:()=>n.GroupViTModel,GroupViTPreTrainedModel:()=>n.GroupViTPreTrainedModel,HerbertTokenizer:()=>s.HerbertTokenizer,HieraForImageClassification:()=>n.HieraForImageClassification,HieraModel:()=>n.HieraModel,HieraPreTrainedModel:()=>n.HieraPreTrainedModel,HubertForCTC:()=>n.HubertForCTC,HubertForSequenceClassification:()=>n.HubertForSequenceClassification,HubertModel:()=>n.HubertModel,HubertPreTrainedModel:()=>n.HubertPreTrainedModel,ImageClassificationPipeline:()=>t.ImageClassificationPipeline,ImageFeatureExtractionPipeline:()=>t.ImageFeatureExtractionPipeline,ImageFeatureExtractor:()=>i.ImageFeatureExtractor,ImageMattingOutput:()=>n.ImageMattingOutput,ImageSegmentationPipeline:()=>t.ImageSegmentationPipeline,ImageToImagePipeline:()=>t.ImageToImagePipeline,ImageToTextPipeline:()=>t.ImageToTextPipeline,InterruptableStoppingCriteria:()=>h.InterruptableStoppingCriteria,JAISLMHeadModel:()=>n.JAISLMHeadModel,JAISModel:()=>n.JAISModel,JAISPreTrainedModel:()=>n.JAISPreTrainedModel,LlamaForCausalLM:()=>n.LlamaForCausalLM,LlamaModel:()=>n.LlamaModel,LlamaPreTrainedModel:()=>n.LlamaPreTrainedModel,LlamaTokenizer:()=>s.LlamaTokenizer,LlavaForConditionalGeneration:()=>n.LlavaForConditionalGeneration,LlavaPreTrainedModel:()=>n.LlavaPreTrainedModel,LongT5ForConditionalGeneration:()=>n.LongT5ForConditionalGeneration,LongT5Model:()=>n.LongT5Model,LongT5PreTrainedModel:()=>n.LongT5PreTrainedModel,M2M100ForConditionalGeneration:()=>n.M2M100ForConditionalGeneration,M2M100Model:()=>n.M2M100Model,M2M100PreTrainedModel:()=>n.M2M100PreTrainedModel,M2M100Tokenizer:()=>s.M2M100Tokenizer,MBart50Tokenizer:()=>s.MBart50Tokenizer,MBartForCausalLM:()=>n.MBartForCausalLM,MBartForConditionalGeneration:()=>n.MBartForConditionalGeneration,MBartForSequenceClassification:()=>n.MBartForSequenceClassification,MBartModel:()=>n.MBartModel,MBartPreTrainedModel:()=>n.MBartPreTrainedModel,MBartTokenizer:()=>s.MBartTokenizer,MPNetForMaskedLM:()=>n.MPNetForMaskedLM,MPNetForQuestionAnswering:()=>n.MPNetForQuestionAnswering,MPNetForSequenceClassification:()=>n.MPNetForSequenceClassification,MPNetForTokenClassification:()=>n.MPNetForTokenClassification,MPNetModel:()=>n.MPNetModel,MPNetPreTrainedModel:()=>n.MPNetPreTrainedModel,MPNetTokenizer:()=>s.MPNetTokenizer,MT5ForConditionalGeneration:()=>n.MT5ForConditionalGeneration,MT5Model:()=>n.MT5Model,MT5PreTrainedModel:()=>n.MT5PreTrainedModel,MarianMTModel:()=>n.MarianMTModel,MarianModel:()=>n.MarianModel,MarianPreTrainedModel:()=>n.MarianPreTrainedModel,MarianTokenizer:()=>s.MarianTokenizer,MaskFormerFeatureExtractor:()=>i.MaskFormerFeatureExtractor,MaskFormerForInstanceSegmentation:()=>n.MaskFormerForInstanceSegmentation,MaskFormerModel:()=>n.MaskFormerModel,MaskFormerPreTrainedModel:()=>n.MaskFormerPreTrainedModel,MaskedLMOutput:()=>n.MaskedLMOutput,MaxLengthCriteria:()=>h.MaxLengthCriteria,MistralForCausalLM:()=>n.MistralForCausalLM,MistralModel:()=>n.MistralModel,MistralPreTrainedModel:()=>n.MistralPreTrainedModel,MobileBertForMaskedLM:()=>n.MobileBertForMaskedLM,MobileBertForQuestionAnswering:()=>n.MobileBertForQuestionAnswering,MobileBertForSequenceClassification:()=>n.MobileBertForSequenceClassification,MobileBertModel:()=>n.MobileBertModel,MobileBertPreTrainedModel:()=>n.MobileBertPreTrainedModel,MobileBertTokenizer:()=>s.MobileBertTokenizer,MobileNetV1FeatureExtractor:()=>i.MobileNetV1FeatureExtractor,MobileNetV1ForImageClassification:()=>n.MobileNetV1ForImageClassification,MobileNetV1Model:()=>n.MobileNetV1Model,MobileNetV1PreTrainedModel:()=>n.MobileNetV1PreTrainedModel,MobileNetV2FeatureExtractor:()=>i.MobileNetV2FeatureExtractor,MobileNetV2ForImageClassification:()=>n.MobileNetV2ForImageClassification,MobileNetV2Model:()=>n.MobileNetV2Model,MobileNetV2PreTrainedModel:()=>n.MobileNetV2PreTrainedModel,MobileNetV3FeatureExtractor:()=>i.MobileNetV3FeatureExtractor,MobileNetV3ForImageClassification:()=>n.MobileNetV3ForImageClassification,MobileNetV3Model:()=>n.MobileNetV3Model,MobileNetV3PreTrainedModel:()=>n.MobileNetV3PreTrainedModel,MobileNetV4FeatureExtractor:()=>i.MobileNetV4FeatureExtractor,MobileNetV4ForImageClassification:()=>n.MobileNetV4ForImageClassification,MobileNetV4Model:()=>n.MobileNetV4Model,MobileNetV4PreTrainedModel:()=>n.MobileNetV4PreTrainedModel,MobileViTFeatureExtractor:()=>i.MobileViTFeatureExtractor,MobileViTForImageClassification:()=>n.MobileViTForImageClassification,MobileViTImageProcessor:()=>i.MobileViTImageProcessor,MobileViTModel:()=>n.MobileViTModel,MobileViTPreTrainedModel:()=>n.MobileViTPreTrainedModel,MobileViTV2ForImageClassification:()=>n.MobileViTV2ForImageClassification,MobileViTV2Model:()=>n.MobileViTV2Model,MobileViTV2PreTrainedModel:()=>n.MobileViTV2PreTrainedModel,ModelOutput:()=>n.ModelOutput,Moondream1ForConditionalGeneration:()=>n.Moondream1ForConditionalGeneration,MptForCausalLM:()=>n.MptForCausalLM,MptModel:()=>n.MptModel,MptPreTrainedModel:()=>n.MptPreTrainedModel,MusicgenForCausalLM:()=>n.MusicgenForCausalLM,MusicgenForConditionalGeneration:()=>n.MusicgenForConditionalGeneration,MusicgenModel:()=>n.MusicgenModel,MusicgenPreTrainedModel:()=>n.MusicgenPreTrainedModel,NllbTokenizer:()=>s.NllbTokenizer,NomicBertModel:()=>n.NomicBertModel,NomicBertPreTrainedModel:()=>n.NomicBertPreTrainedModel,NougatImageProcessor:()=>i.NougatImageProcessor,NougatTokenizer:()=>s.NougatTokenizer,OPTForCausalLM:()=>n.OPTForCausalLM,OPTModel:()=>n.OPTModel,OPTPreTrainedModel:()=>n.OPTPreTrainedModel,ObjectDetectionPipeline:()=>t.ObjectDetectionPipeline,OpenELMForCausalLM:()=>n.OpenELMForCausalLM,OpenELMModel:()=>n.OpenELMModel,OpenELMPreTrainedModel:()=>n.OpenELMPreTrainedModel,OwlViTFeatureExtractor:()=>i.OwlViTFeatureExtractor,OwlViTForObjectDetection:()=>n.OwlViTForObjectDetection,OwlViTModel:()=>n.OwlViTModel,OwlViTPreTrainedModel:()=>n.OwlViTPreTrainedModel,OwlViTProcessor:()=>i.OwlViTProcessor,Owlv2ForObjectDetection:()=>n.Owlv2ForObjectDetection,Owlv2ImageProcessor:()=>i.Owlv2ImageProcessor,Owlv2Model:()=>n.Owlv2Model,Owlv2PreTrainedModel:()=>n.Owlv2PreTrainedModel,Phi3ForCausalLM:()=>n.Phi3ForCausalLM,Phi3Model:()=>n.Phi3Model,Phi3PreTrainedModel:()=>n.Phi3PreTrainedModel,PhiForCausalLM:()=>n.PhiForCausalLM,PhiModel:()=>n.PhiModel,PhiPreTrainedModel:()=>n.PhiPreTrainedModel,Pipeline:()=>t.Pipeline,PreTrainedModel:()=>n.PreTrainedModel,PreTrainedTokenizer:()=>s.PreTrainedTokenizer,PretrainedConfig:()=>a.PretrainedConfig,PretrainedMixin:()=>n.PretrainedMixin,Processor:()=>i.Processor,PvtForImageClassification:()=>n.PvtForImageClassification,PvtImageProcessor:()=>i.PvtImageProcessor,PvtModel:()=>n.PvtModel,PvtPreTrainedModel:()=>n.PvtPreTrainedModel,PyAnnoteFeatureExtractor:()=>i.PyAnnoteFeatureExtractor,PyAnnoteForAudioFrameClassification:()=>n.PyAnnoteForAudioFrameClassification,PyAnnoteModel:()=>n.PyAnnoteModel,PyAnnotePreTrainedModel:()=>n.PyAnnotePreTrainedModel,PyAnnoteProcessor:()=>i.PyAnnoteProcessor,QuestionAnsweringModelOutput:()=>n.QuestionAnsweringModelOutput,QuestionAnsweringPipeline:()=>t.QuestionAnsweringPipeline,Qwen2ForCausalLM:()=>n.Qwen2ForCausalLM,Qwen2Model:()=>n.Qwen2Model,Qwen2PreTrainedModel:()=>n.Qwen2PreTrainedModel,Qwen2Tokenizer:()=>s.Qwen2Tokenizer,RTDetrForObjectDetection:()=>n.RTDetrForObjectDetection,RTDetrImageProcessor:()=>i.RTDetrImageProcessor,RTDetrModel:()=>n.RTDetrModel,RTDetrObjectDetectionOutput:()=>n.RTDetrObjectDetectionOutput,RTDetrPreTrainedModel:()=>n.RTDetrPreTrainedModel,RawImage:()=>c.RawImage,ResNetForImageClassification:()=>n.ResNetForImageClassification,ResNetModel:()=>n.ResNetModel,ResNetPreTrainedModel:()=>n.ResNetPreTrainedModel,RoFormerForMaskedLM:()=>n.RoFormerForMaskedLM,RoFormerForQuestionAnswering:()=>n.RoFormerForQuestionAnswering,RoFormerForSequenceClassification:()=>n.RoFormerForSequenceClassification,RoFormerForTokenClassification:()=>n.RoFormerForTokenClassification,RoFormerModel:()=>n.RoFormerModel,RoFormerPreTrainedModel:()=>n.RoFormerPreTrainedModel,RoFormerTokenizer:()=>s.RoFormerTokenizer,RobertaForMaskedLM:()=>n.RobertaForMaskedLM,RobertaForQuestionAnswering:()=>n.RobertaForQuestionAnswering,RobertaForSequenceClassification:()=>n.RobertaForSequenceClassification,RobertaForTokenClassification:()=>n.RobertaForTokenClassification,RobertaModel:()=>n.RobertaModel,RobertaPreTrainedModel:()=>n.RobertaPreTrainedModel,RobertaTokenizer:()=>s.RobertaTokenizer,SamImageProcessor:()=>i.SamImageProcessor,SamImageSegmentationOutput:()=>n.SamImageSegmentationOutput,SamModel:()=>n.SamModel,SamPreTrainedModel:()=>n.SamPreTrainedModel,SamProcessor:()=>i.SamProcessor,SapiensFeatureExtractor:()=>i.SapiensFeatureExtractor,SapiensForDepthEstimation:()=>n.SapiensForDepthEstimation,SapiensForNormalEstimation:()=>n.SapiensForNormalEstimation,SapiensForSemanticSegmentation:()=>n.SapiensForSemanticSegmentation,SapiensPreTrainedModel:()=>n.SapiensPreTrainedModel,SeamlessM4TFeatureExtractor:()=>i.SeamlessM4TFeatureExtractor,SegformerFeatureExtractor:()=>i.SegformerFeatureExtractor,SegformerForImageClassification:()=>n.SegformerForImageClassification,SegformerForSemanticSegmentation:()=>n.SegformerForSemanticSegmentation,SegformerModel:()=>n.SegformerModel,SegformerPreTrainedModel:()=>n.SegformerPreTrainedModel,Seq2SeqLMOutput:()=>n.Seq2SeqLMOutput,SequenceClassifierOutput:()=>n.SequenceClassifierOutput,SiglipImageProcessor:()=>i.SiglipImageProcessor,SiglipModel:()=>n.SiglipModel,SiglipPreTrainedModel:()=>n.SiglipPreTrainedModel,SiglipTextModel:()=>n.SiglipTextModel,SiglipTokenizer:()=>s.SiglipTokenizer,SiglipVisionModel:()=>n.SiglipVisionModel,SpeechT5FeatureExtractor:()=>i.SpeechT5FeatureExtractor,SpeechT5ForSpeechToText:()=>n.SpeechT5ForSpeechToText,SpeechT5ForTextToSpeech:()=>n.SpeechT5ForTextToSpeech,SpeechT5HifiGan:()=>n.SpeechT5HifiGan,SpeechT5Model:()=>n.SpeechT5Model,SpeechT5PreTrainedModel:()=>n.SpeechT5PreTrainedModel,SpeechT5Processor:()=>i.SpeechT5Processor,SpeechT5Tokenizer:()=>s.SpeechT5Tokenizer,SqueezeBertForMaskedLM:()=>n.SqueezeBertForMaskedLM,SqueezeBertForQuestionAnswering:()=>n.SqueezeBertForQuestionAnswering,SqueezeBertForSequenceClassification:()=>n.SqueezeBertForSequenceClassification,SqueezeBertModel:()=>n.SqueezeBertModel,SqueezeBertPreTrainedModel:()=>n.SqueezeBertPreTrainedModel,SqueezeBertTokenizer:()=>s.SqueezeBertTokenizer,StableLmForCausalLM:()=>n.StableLmForCausalLM,StableLmModel:()=>n.StableLmModel,StableLmPreTrainedModel:()=>n.StableLmPreTrainedModel,Starcoder2ForCausalLM:()=>n.Starcoder2ForCausalLM,Starcoder2Model:()=>n.Starcoder2Model,Starcoder2PreTrainedModel:()=>n.Starcoder2PreTrainedModel,StoppingCriteria:()=>h.StoppingCriteria,StoppingCriteriaList:()=>h.StoppingCriteriaList,SummarizationPipeline:()=>t.SummarizationPipeline,Swin2SRForImageSuperResolution:()=>n.Swin2SRForImageSuperResolution,Swin2SRImageProcessor:()=>i.Swin2SRImageProcessor,Swin2SRModel:()=>n.Swin2SRModel,Swin2SRPreTrainedModel:()=>n.Swin2SRPreTrainedModel,SwinForImageClassification:()=>n.SwinForImageClassification,SwinModel:()=>n.SwinModel,SwinPreTrainedModel:()=>n.SwinPreTrainedModel,T5ForConditionalGeneration:()=>n.T5ForConditionalGeneration,T5Model:()=>n.T5Model,T5PreTrainedModel:()=>n.T5PreTrainedModel,T5Tokenizer:()=>s.T5Tokenizer,TableTransformerForObjectDetection:()=>n.TableTransformerForObjectDetection,TableTransformerModel:()=>n.TableTransformerModel,TableTransformerObjectDetectionOutput:()=>n.TableTransformerObjectDetectionOutput,TableTransformerPreTrainedModel:()=>n.TableTransformerPreTrainedModel,Tensor:()=>d.Tensor,Text2TextGenerationPipeline:()=>t.Text2TextGenerationPipeline,TextClassificationPipeline:()=>t.TextClassificationPipeline,TextGenerationPipeline:()=>t.TextGenerationPipeline,TextStreamer:()=>p.TextStreamer,TextToAudioPipeline:()=>t.TextToAudioPipeline,TokenClassificationPipeline:()=>t.TokenClassificationPipeline,TokenClassifierOutput:()=>n.TokenClassifierOutput,TokenizerModel:()=>s.TokenizerModel,TrOCRForCausalLM:()=>n.TrOCRForCausalLM,TrOCRPreTrainedModel:()=>n.TrOCRPreTrainedModel,TranslationPipeline:()=>t.TranslationPipeline,UniSpeechForCTC:()=>n.UniSpeechForCTC,UniSpeechForSequenceClassification:()=>n.UniSpeechForSequenceClassification,UniSpeechModel:()=>n.UniSpeechModel,UniSpeechPreTrainedModel:()=>n.UniSpeechPreTrainedModel,UniSpeechSatForAudioFrameClassification:()=>n.UniSpeechSatForAudioFrameClassification,UniSpeechSatForCTC:()=>n.UniSpeechSatForCTC,UniSpeechSatForSequenceClassification:()=>n.UniSpeechSatForSequenceClassification,UniSpeechSatModel:()=>n.UniSpeechSatModel,UniSpeechSatPreTrainedModel:()=>n.UniSpeechSatPreTrainedModel,ViTFeatureExtractor:()=>i.ViTFeatureExtractor,ViTForImageClassification:()=>n.ViTForImageClassification,ViTImageProcessor:()=>i.ViTImageProcessor,ViTMAEModel:()=>n.ViTMAEModel,ViTMAEPreTrainedModel:()=>n.ViTMAEPreTrainedModel,ViTMSNForImageClassification:()=>n.ViTMSNForImageClassification,ViTMSNModel:()=>n.ViTMSNModel,ViTMSNPreTrainedModel:()=>n.ViTMSNPreTrainedModel,ViTModel:()=>n.ViTModel,ViTPreTrainedModel:()=>n.ViTPreTrainedModel,VisionEncoderDecoderModel:()=>n.VisionEncoderDecoderModel,VitMatteForImageMatting:()=>n.VitMatteForImageMatting,VitMatteImageProcessor:()=>i.VitMatteImageProcessor,VitMattePreTrainedModel:()=>n.VitMattePreTrainedModel,VitsModel:()=>n.VitsModel,VitsModelOutput:()=>n.VitsModelOutput,VitsPreTrainedModel:()=>n.VitsPreTrainedModel,VitsTokenizer:()=>s.VitsTokenizer,Wav2Vec2BertForCTC:()=>n.Wav2Vec2BertForCTC,Wav2Vec2BertForSequenceClassification:()=>n.Wav2Vec2BertForSequenceClassification,Wav2Vec2BertModel:()=>n.Wav2Vec2BertModel,Wav2Vec2BertPreTrainedModel:()=>n.Wav2Vec2BertPreTrainedModel,Wav2Vec2CTCTokenizer:()=>s.Wav2Vec2CTCTokenizer,Wav2Vec2FeatureExtractor:()=>i.Wav2Vec2FeatureExtractor,Wav2Vec2ForAudioFrameClassification:()=>n.Wav2Vec2ForAudioFrameClassification,Wav2Vec2ForCTC:()=>n.Wav2Vec2ForCTC,Wav2Vec2ForSequenceClassification:()=>n.Wav2Vec2ForSequenceClassification,Wav2Vec2Model:()=>n.Wav2Vec2Model,Wav2Vec2PreTrainedModel:()=>n.Wav2Vec2PreTrainedModel,Wav2Vec2ProcessorWithLM:()=>i.Wav2Vec2ProcessorWithLM,WavLMForAudioFrameClassification:()=>n.WavLMForAudioFrameClassification,WavLMForCTC:()=>n.WavLMForCTC,WavLMForSequenceClassification:()=>n.WavLMForSequenceClassification,WavLMForXVector:()=>n.WavLMForXVector,WavLMModel:()=>n.WavLMModel,WavLMPreTrainedModel:()=>n.WavLMPreTrainedModel,WeSpeakerFeatureExtractor:()=>i.WeSpeakerFeatureExtractor,WeSpeakerResNetModel:()=>n.WeSpeakerResNetModel,WeSpeakerResNetPreTrainedModel:()=>n.WeSpeakerResNetPreTrainedModel,WhisperFeatureExtractor:()=>i.WhisperFeatureExtractor,WhisperForConditionalGeneration:()=>n.WhisperForConditionalGeneration,WhisperModel:()=>n.WhisperModel,WhisperPreTrainedModel:()=>n.WhisperPreTrainedModel,WhisperProcessor:()=>i.WhisperProcessor,WhisperTextStreamer:()=>p.WhisperTextStreamer,WhisperTokenizer:()=>s.WhisperTokenizer,XLMForQuestionAnswering:()=>n.XLMForQuestionAnswering,XLMForSequenceClassification:()=>n.XLMForSequenceClassification,XLMForTokenClassification:()=>n.XLMForTokenClassification,XLMModel:()=>n.XLMModel,XLMPreTrainedModel:()=>n.XLMPreTrainedModel,XLMRobertaForMaskedLM:()=>n.XLMRobertaForMaskedLM,XLMRobertaForQuestionAnswering:()=>n.XLMRobertaForQuestionAnswering,XLMRobertaForSequenceClassification:()=>n.XLMRobertaForSequenceClassification,XLMRobertaForTokenClassification:()=>n.XLMRobertaForTokenClassification,XLMRobertaModel:()=>n.XLMRobertaModel,XLMRobertaPreTrainedModel:()=>n.XLMRobertaPreTrainedModel,XLMRobertaTokenizer:()=>s.XLMRobertaTokenizer,XLMTokenizer:()=>s.XLMTokenizer,XLMWithLMHeadModel:()=>n.XLMWithLMHeadModel,XVectorOutput:()=>n.XVectorOutput,YolosFeatureExtractor:()=>i.YolosFeatureExtractor,YolosForObjectDetection:()=>n.YolosForObjectDetection,YolosModel:()=>n.YolosModel,YolosObjectDetectionOutput:()=>n.YolosObjectDetectionOutput,YolosPreTrainedModel:()=>n.YolosPreTrainedModel,ZeroShotAudioClassificationPipeline:()=>t.ZeroShotAudioClassificationPipeline,ZeroShotClassificationPipeline:()=>t.ZeroShotClassificationPipeline,ZeroShotImageClassificationPipeline:()=>t.ZeroShotImageClassificationPipeline,ZeroShotObjectDetectionPipeline:()=>t.ZeroShotObjectDetectionPipeline,bankers_round:()=>u.bankers_round,cat:()=>d.cat,cos_sim:()=>u.cos_sim,dot:()=>u.dot,dynamic_time_warping:()=>u.dynamic_time_warping,env:()=>e.env,full:()=>d.full,full_like:()=>d.full_like,getKeyValueShapes:()=>a.getKeyValueShapes,hamming:()=>l.hamming,hanning:()=>l.hanning,interpolate:()=>d.interpolate,interpolate_4d:()=>d.interpolate_4d,interpolate_data:()=>u.interpolate_data,is_chinese_char:()=>s.is_chinese_char,layer_norm:()=>d.layer_norm,log_softmax:()=>u.log_softmax,magnitude:()=>u.magnitude,matmul:()=>d.matmul,max:()=>u.max,mean:()=>d.mean,mean_pooling:()=>d.mean_pooling,medianFilter:()=>u.medianFilter,mel_filter_bank:()=>l.mel_filter_bank,min:()=>u.min,ones:()=>d.ones,ones_like:()=>d.ones_like,permute:()=>d.permute,permute_data:()=>u.permute_data,pipeline:()=>t.pipeline,quantize_embeddings:()=>d.quantize_embeddings,read_audio:()=>l.read_audio,rfft:()=>d.rfft,round:()=>u.round,softmax:()=>u.softmax,spectrogram:()=>l.spectrogram,stack:()=>d.stack,std_mean:()=>d.std_mean,topk:()=>d.topk,window_function:()=>l.window_function,zeros:()=>d.zeros,zeros_like:()=>d.zeros_like});var e=r(/*! ./env.js */"./src/env.js"),t=r(/*! ./pipelines.js */"./src/pipelines.js"),n=r(/*! ./models.js */"./src/models.js"),s=r(/*! ./tokenizers.js */"./src/tokenizers.js"),i=r(/*! ./processors.js */"./src/processors.js"),a=r(/*! ./configs.js */"./src/configs.js"),l=r(/*! ./utils/audio.js */"./src/utils/audio.js"),c=r(/*! ./utils/image.js */"./src/utils/image.js"),d=r(/*! ./utils/tensor.js */"./src/utils/tensor.js"),u=r(/*! ./utils/maths.js */"./src/utils/maths.js"),p=r(/*! ./generation/streamers.js */"./src/generation/streamers.js"),h=r(/*! ./generation/stopping_criteria.js */"./src/generation/stopping_criteria.js")})();var i=exports;for(var a in o)i[a]=o[a];o.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})})();
|
|
166
|
+
\*****************************/r.r(o),r.d(o,{ASTFeatureExtractor:()=>i.ASTFeatureExtractor,ASTForAudioClassification:()=>n.ASTForAudioClassification,ASTModel:()=>n.ASTModel,ASTPreTrainedModel:()=>n.ASTPreTrainedModel,AlbertForMaskedLM:()=>n.AlbertForMaskedLM,AlbertForQuestionAnswering:()=>n.AlbertForQuestionAnswering,AlbertForSequenceClassification:()=>n.AlbertForSequenceClassification,AlbertModel:()=>n.AlbertModel,AlbertPreTrainedModel:()=>n.AlbertPreTrainedModel,AlbertTokenizer:()=>s.AlbertTokenizer,AudioClassificationPipeline:()=>t.AudioClassificationPipeline,AutoConfig:()=>a.AutoConfig,AutoModel:()=>n.AutoModel,AutoModelForAudioClassification:()=>n.AutoModelForAudioClassification,AutoModelForAudioFrameClassification:()=>n.AutoModelForAudioFrameClassification,AutoModelForCTC:()=>n.AutoModelForCTC,AutoModelForCausalLM:()=>n.AutoModelForCausalLM,AutoModelForDepthEstimation:()=>n.AutoModelForDepthEstimation,AutoModelForDocumentQuestionAnswering:()=>n.AutoModelForDocumentQuestionAnswering,AutoModelForImageClassification:()=>n.AutoModelForImageClassification,AutoModelForImageFeatureExtraction:()=>n.AutoModelForImageFeatureExtraction,AutoModelForImageMatting:()=>n.AutoModelForImageMatting,AutoModelForImageSegmentation:()=>n.AutoModelForImageSegmentation,AutoModelForImageToImage:()=>n.AutoModelForImageToImage,AutoModelForMaskGeneration:()=>n.AutoModelForMaskGeneration,AutoModelForMaskedLM:()=>n.AutoModelForMaskedLM,AutoModelForNormalEstimation:()=>n.AutoModelForNormalEstimation,AutoModelForObjectDetection:()=>n.AutoModelForObjectDetection,AutoModelForQuestionAnswering:()=>n.AutoModelForQuestionAnswering,AutoModelForSemanticSegmentation:()=>n.AutoModelForSemanticSegmentation,AutoModelForSeq2SeqLM:()=>n.AutoModelForSeq2SeqLM,AutoModelForSequenceClassification:()=>n.AutoModelForSequenceClassification,AutoModelForSpeechSeq2Seq:()=>n.AutoModelForSpeechSeq2Seq,AutoModelForTextToSpectrogram:()=>n.AutoModelForTextToSpectrogram,AutoModelForTextToWaveform:()=>n.AutoModelForTextToWaveform,AutoModelForTokenClassification:()=>n.AutoModelForTokenClassification,AutoModelForUniversalSegmentation:()=>n.AutoModelForUniversalSegmentation,AutoModelForVision2Seq:()=>n.AutoModelForVision2Seq,AutoModelForXVector:()=>n.AutoModelForXVector,AutoModelForZeroShotObjectDetection:()=>n.AutoModelForZeroShotObjectDetection,AutoProcessor:()=>i.AutoProcessor,AutoTokenizer:()=>s.AutoTokenizer,AutomaticSpeechRecognitionPipeline:()=>t.AutomaticSpeechRecognitionPipeline,BartForConditionalGeneration:()=>n.BartForConditionalGeneration,BartForSequenceClassification:()=>n.BartForSequenceClassification,BartModel:()=>n.BartModel,BartPretrainedModel:()=>n.BartPretrainedModel,BartTokenizer:()=>s.BartTokenizer,BaseModelOutput:()=>n.BaseModelOutput,BaseStreamer:()=>p.BaseStreamer,BeitFeatureExtractor:()=>i.BeitFeatureExtractor,BeitForImageClassification:()=>n.BeitForImageClassification,BeitModel:()=>n.BeitModel,BeitPreTrainedModel:()=>n.BeitPreTrainedModel,BertForMaskedLM:()=>n.BertForMaskedLM,BertForQuestionAnswering:()=>n.BertForQuestionAnswering,BertForSequenceClassification:()=>n.BertForSequenceClassification,BertForTokenClassification:()=>n.BertForTokenClassification,BertModel:()=>n.BertModel,BertPreTrainedModel:()=>n.BertPreTrainedModel,BertTokenizer:()=>s.BertTokenizer,BitImageProcessor:()=>i.BitImageProcessor,BlenderbotForConditionalGeneration:()=>n.BlenderbotForConditionalGeneration,BlenderbotModel:()=>n.BlenderbotModel,BlenderbotPreTrainedModel:()=>n.BlenderbotPreTrainedModel,BlenderbotSmallForConditionalGeneration:()=>n.BlenderbotSmallForConditionalGeneration,BlenderbotSmallModel:()=>n.BlenderbotSmallModel,BlenderbotSmallPreTrainedModel:()=>n.BlenderbotSmallPreTrainedModel,BlenderbotSmallTokenizer:()=>s.BlenderbotSmallTokenizer,BlenderbotTokenizer:()=>s.BlenderbotTokenizer,BloomForCausalLM:()=>n.BloomForCausalLM,BloomModel:()=>n.BloomModel,BloomPreTrainedModel:()=>n.BloomPreTrainedModel,BloomTokenizer:()=>s.BloomTokenizer,CLIPFeatureExtractor:()=>i.CLIPFeatureExtractor,CLIPImageProcessor:()=>i.CLIPImageProcessor,CLIPModel:()=>n.CLIPModel,CLIPPreTrainedModel:()=>n.CLIPPreTrainedModel,CLIPSegForImageSegmentation:()=>n.CLIPSegForImageSegmentation,CLIPSegModel:()=>n.CLIPSegModel,CLIPSegPreTrainedModel:()=>n.CLIPSegPreTrainedModel,CLIPTextModel:()=>n.CLIPTextModel,CLIPTextModelWithProjection:()=>n.CLIPTextModelWithProjection,CLIPTokenizer:()=>s.CLIPTokenizer,CLIPVisionModel:()=>n.CLIPVisionModel,CLIPVisionModelWithProjection:()=>n.CLIPVisionModelWithProjection,CamembertForMaskedLM:()=>n.CamembertForMaskedLM,CamembertForQuestionAnswering:()=>n.CamembertForQuestionAnswering,CamembertForSequenceClassification:()=>n.CamembertForSequenceClassification,CamembertForTokenClassification:()=>n.CamembertForTokenClassification,CamembertModel:()=>n.CamembertModel,CamembertPreTrainedModel:()=>n.CamembertPreTrainedModel,CamembertTokenizer:()=>s.CamembertTokenizer,CausalLMOutput:()=>n.CausalLMOutput,CausalLMOutputWithPast:()=>n.CausalLMOutputWithPast,ChineseCLIPFeatureExtractor:()=>i.ChineseCLIPFeatureExtractor,ChineseCLIPModel:()=>n.ChineseCLIPModel,ChineseCLIPPreTrainedModel:()=>n.ChineseCLIPPreTrainedModel,ClapAudioModelWithProjection:()=>n.ClapAudioModelWithProjection,ClapFeatureExtractor:()=>i.ClapFeatureExtractor,ClapModel:()=>n.ClapModel,ClapPreTrainedModel:()=>n.ClapPreTrainedModel,ClapTextModelWithProjection:()=>n.ClapTextModelWithProjection,CodeGenForCausalLM:()=>n.CodeGenForCausalLM,CodeGenModel:()=>n.CodeGenModel,CodeGenPreTrainedModel:()=>n.CodeGenPreTrainedModel,CodeGenTokenizer:()=>s.CodeGenTokenizer,CodeLlamaTokenizer:()=>s.CodeLlamaTokenizer,CohereForCausalLM:()=>n.CohereForCausalLM,CohereModel:()=>n.CohereModel,CoherePreTrainedModel:()=>n.CoherePreTrainedModel,CohereTokenizer:()=>s.CohereTokenizer,ConvBertForMaskedLM:()=>n.ConvBertForMaskedLM,ConvBertForQuestionAnswering:()=>n.ConvBertForQuestionAnswering,ConvBertForSequenceClassification:()=>n.ConvBertForSequenceClassification,ConvBertForTokenClassification:()=>n.ConvBertForTokenClassification,ConvBertModel:()=>n.ConvBertModel,ConvBertPreTrainedModel:()=>n.ConvBertPreTrainedModel,ConvBertTokenizer:()=>s.ConvBertTokenizer,ConvNextFeatureExtractor:()=>i.ConvNextFeatureExtractor,ConvNextForImageClassification:()=>n.ConvNextForImageClassification,ConvNextImageProcessor:()=>i.ConvNextImageProcessor,ConvNextModel:()=>n.ConvNextModel,ConvNextPreTrainedModel:()=>n.ConvNextPreTrainedModel,ConvNextV2ForImageClassification:()=>n.ConvNextV2ForImageClassification,ConvNextV2Model:()=>n.ConvNextV2Model,ConvNextV2PreTrainedModel:()=>n.ConvNextV2PreTrainedModel,DPTFeatureExtractor:()=>i.DPTFeatureExtractor,DPTForDepthEstimation:()=>n.DPTForDepthEstimation,DPTImageProcessor:()=>i.DPTImageProcessor,DPTModel:()=>n.DPTModel,DPTPreTrainedModel:()=>n.DPTPreTrainedModel,DebertaForMaskedLM:()=>n.DebertaForMaskedLM,DebertaForQuestionAnswering:()=>n.DebertaForQuestionAnswering,DebertaForSequenceClassification:()=>n.DebertaForSequenceClassification,DebertaForTokenClassification:()=>n.DebertaForTokenClassification,DebertaModel:()=>n.DebertaModel,DebertaPreTrainedModel:()=>n.DebertaPreTrainedModel,DebertaTokenizer:()=>s.DebertaTokenizer,DebertaV2ForMaskedLM:()=>n.DebertaV2ForMaskedLM,DebertaV2ForQuestionAnswering:()=>n.DebertaV2ForQuestionAnswering,DebertaV2ForSequenceClassification:()=>n.DebertaV2ForSequenceClassification,DebertaV2ForTokenClassification:()=>n.DebertaV2ForTokenClassification,DebertaV2Model:()=>n.DebertaV2Model,DebertaV2PreTrainedModel:()=>n.DebertaV2PreTrainedModel,DebertaV2Tokenizer:()=>s.DebertaV2Tokenizer,DecisionTransformerModel:()=>n.DecisionTransformerModel,DecisionTransformerPreTrainedModel:()=>n.DecisionTransformerPreTrainedModel,DeiTFeatureExtractor:()=>i.DeiTFeatureExtractor,DeiTForImageClassification:()=>n.DeiTForImageClassification,DeiTModel:()=>n.DeiTModel,DeiTPreTrainedModel:()=>n.DeiTPreTrainedModel,DepthAnythingForDepthEstimation:()=>n.DepthAnythingForDepthEstimation,DepthAnythingPreTrainedModel:()=>n.DepthAnythingPreTrainedModel,DepthEstimationPipeline:()=>t.DepthEstimationPipeline,DepthProForDepthEstimation:()=>n.DepthProForDepthEstimation,DepthProPreTrainedModel:()=>n.DepthProPreTrainedModel,DetrFeatureExtractor:()=>i.DetrFeatureExtractor,DetrForObjectDetection:()=>n.DetrForObjectDetection,DetrForSegmentation:()=>n.DetrForSegmentation,DetrModel:()=>n.DetrModel,DetrObjectDetectionOutput:()=>n.DetrObjectDetectionOutput,DetrPreTrainedModel:()=>n.DetrPreTrainedModel,DetrSegmentationOutput:()=>n.DetrSegmentationOutput,Dinov2ForImageClassification:()=>n.Dinov2ForImageClassification,Dinov2Model:()=>n.Dinov2Model,Dinov2PreTrainedModel:()=>n.Dinov2PreTrainedModel,DistilBertForMaskedLM:()=>n.DistilBertForMaskedLM,DistilBertForQuestionAnswering:()=>n.DistilBertForQuestionAnswering,DistilBertForSequenceClassification:()=>n.DistilBertForSequenceClassification,DistilBertForTokenClassification:()=>n.DistilBertForTokenClassification,DistilBertModel:()=>n.DistilBertModel,DistilBertPreTrainedModel:()=>n.DistilBertPreTrainedModel,DistilBertTokenizer:()=>s.DistilBertTokenizer,DocumentQuestionAnsweringPipeline:()=>t.DocumentQuestionAnsweringPipeline,DonutFeatureExtractor:()=>i.DonutFeatureExtractor,DonutSwinModel:()=>n.DonutSwinModel,DonutSwinPreTrainedModel:()=>n.DonutSwinPreTrainedModel,EfficientNetForImageClassification:()=>n.EfficientNetForImageClassification,EfficientNetImageProcessor:()=>i.EfficientNetImageProcessor,EfficientNetModel:()=>n.EfficientNetModel,EfficientNetPreTrainedModel:()=>n.EfficientNetPreTrainedModel,ElectraForMaskedLM:()=>n.ElectraForMaskedLM,ElectraForQuestionAnswering:()=>n.ElectraForQuestionAnswering,ElectraForSequenceClassification:()=>n.ElectraForSequenceClassification,ElectraForTokenClassification:()=>n.ElectraForTokenClassification,ElectraModel:()=>n.ElectraModel,ElectraPreTrainedModel:()=>n.ElectraPreTrainedModel,ElectraTokenizer:()=>s.ElectraTokenizer,EosTokenCriteria:()=>h.EosTokenCriteria,EsmForMaskedLM:()=>n.EsmForMaskedLM,EsmForSequenceClassification:()=>n.EsmForSequenceClassification,EsmForTokenClassification:()=>n.EsmForTokenClassification,EsmModel:()=>n.EsmModel,EsmPreTrainedModel:()=>n.EsmPreTrainedModel,EsmTokenizer:()=>s.EsmTokenizer,FFT:()=>u.FFT,FalconForCausalLM:()=>n.FalconForCausalLM,FalconModel:()=>n.FalconModel,FalconPreTrainedModel:()=>n.FalconPreTrainedModel,FalconTokenizer:()=>s.FalconTokenizer,FastViTForImageClassification:()=>n.FastViTForImageClassification,FastViTModel:()=>n.FastViTModel,FastViTPreTrainedModel:()=>n.FastViTPreTrainedModel,FeatureExtractionPipeline:()=>t.FeatureExtractionPipeline,FeatureExtractor:()=>i.FeatureExtractor,FillMaskPipeline:()=>t.FillMaskPipeline,Florence2ForConditionalGeneration:()=>n.Florence2ForConditionalGeneration,Florence2PreTrainedModel:()=>n.Florence2PreTrainedModel,Florence2Processor:()=>i.Florence2Processor,GLPNFeatureExtractor:()=>i.GLPNFeatureExtractor,GLPNForDepthEstimation:()=>n.GLPNForDepthEstimation,GLPNModel:()=>n.GLPNModel,GLPNPreTrainedModel:()=>n.GLPNPreTrainedModel,GPT2LMHeadModel:()=>n.GPT2LMHeadModel,GPT2Model:()=>n.GPT2Model,GPT2PreTrainedModel:()=>n.GPT2PreTrainedModel,GPT2Tokenizer:()=>s.GPT2Tokenizer,GPTBigCodeForCausalLM:()=>n.GPTBigCodeForCausalLM,GPTBigCodeModel:()=>n.GPTBigCodeModel,GPTBigCodePreTrainedModel:()=>n.GPTBigCodePreTrainedModel,GPTJForCausalLM:()=>n.GPTJForCausalLM,GPTJModel:()=>n.GPTJModel,GPTJPreTrainedModel:()=>n.GPTJPreTrainedModel,GPTNeoForCausalLM:()=>n.GPTNeoForCausalLM,GPTNeoModel:()=>n.GPTNeoModel,GPTNeoPreTrainedModel:()=>n.GPTNeoPreTrainedModel,GPTNeoXForCausalLM:()=>n.GPTNeoXForCausalLM,GPTNeoXModel:()=>n.GPTNeoXModel,GPTNeoXPreTrainedModel:()=>n.GPTNeoXPreTrainedModel,GPTNeoXTokenizer:()=>s.GPTNeoXTokenizer,Gemma2ForCausalLM:()=>n.Gemma2ForCausalLM,Gemma2Model:()=>n.Gemma2Model,Gemma2PreTrainedModel:()=>n.Gemma2PreTrainedModel,GemmaForCausalLM:()=>n.GemmaForCausalLM,GemmaModel:()=>n.GemmaModel,GemmaPreTrainedModel:()=>n.GemmaPreTrainedModel,GemmaTokenizer:()=>s.GemmaTokenizer,GraniteForCausalLM:()=>n.GraniteForCausalLM,GraniteModel:()=>n.GraniteModel,GranitePreTrainedModel:()=>n.GranitePreTrainedModel,Grok1Tokenizer:()=>s.Grok1Tokenizer,GroupViTModel:()=>n.GroupViTModel,GroupViTPreTrainedModel:()=>n.GroupViTPreTrainedModel,HerbertTokenizer:()=>s.HerbertTokenizer,HieraForImageClassification:()=>n.HieraForImageClassification,HieraModel:()=>n.HieraModel,HieraPreTrainedModel:()=>n.HieraPreTrainedModel,HubertForCTC:()=>n.HubertForCTC,HubertForSequenceClassification:()=>n.HubertForSequenceClassification,HubertModel:()=>n.HubertModel,HubertPreTrainedModel:()=>n.HubertPreTrainedModel,ImageClassificationPipeline:()=>t.ImageClassificationPipeline,ImageFeatureExtractionPipeline:()=>t.ImageFeatureExtractionPipeline,ImageFeatureExtractor:()=>i.ImageFeatureExtractor,ImageMattingOutput:()=>n.ImageMattingOutput,ImageSegmentationPipeline:()=>t.ImageSegmentationPipeline,ImageToImagePipeline:()=>t.ImageToImagePipeline,ImageToTextPipeline:()=>t.ImageToTextPipeline,InterruptableStoppingCriteria:()=>h.InterruptableStoppingCriteria,JAISLMHeadModel:()=>n.JAISLMHeadModel,JAISModel:()=>n.JAISModel,JAISPreTrainedModel:()=>n.JAISPreTrainedModel,LlamaForCausalLM:()=>n.LlamaForCausalLM,LlamaModel:()=>n.LlamaModel,LlamaPreTrainedModel:()=>n.LlamaPreTrainedModel,LlamaTokenizer:()=>s.LlamaTokenizer,LlavaForConditionalGeneration:()=>n.LlavaForConditionalGeneration,LlavaPreTrainedModel:()=>n.LlavaPreTrainedModel,LongT5ForConditionalGeneration:()=>n.LongT5ForConditionalGeneration,LongT5Model:()=>n.LongT5Model,LongT5PreTrainedModel:()=>n.LongT5PreTrainedModel,M2M100ForConditionalGeneration:()=>n.M2M100ForConditionalGeneration,M2M100Model:()=>n.M2M100Model,M2M100PreTrainedModel:()=>n.M2M100PreTrainedModel,M2M100Tokenizer:()=>s.M2M100Tokenizer,MBart50Tokenizer:()=>s.MBart50Tokenizer,MBartForCausalLM:()=>n.MBartForCausalLM,MBartForConditionalGeneration:()=>n.MBartForConditionalGeneration,MBartForSequenceClassification:()=>n.MBartForSequenceClassification,MBartModel:()=>n.MBartModel,MBartPreTrainedModel:()=>n.MBartPreTrainedModel,MBartTokenizer:()=>s.MBartTokenizer,MPNetForMaskedLM:()=>n.MPNetForMaskedLM,MPNetForQuestionAnswering:()=>n.MPNetForQuestionAnswering,MPNetForSequenceClassification:()=>n.MPNetForSequenceClassification,MPNetForTokenClassification:()=>n.MPNetForTokenClassification,MPNetModel:()=>n.MPNetModel,MPNetPreTrainedModel:()=>n.MPNetPreTrainedModel,MPNetTokenizer:()=>s.MPNetTokenizer,MT5ForConditionalGeneration:()=>n.MT5ForConditionalGeneration,MT5Model:()=>n.MT5Model,MT5PreTrainedModel:()=>n.MT5PreTrainedModel,MarianMTModel:()=>n.MarianMTModel,MarianModel:()=>n.MarianModel,MarianPreTrainedModel:()=>n.MarianPreTrainedModel,MarianTokenizer:()=>s.MarianTokenizer,MaskFormerFeatureExtractor:()=>i.MaskFormerFeatureExtractor,MaskFormerForInstanceSegmentation:()=>n.MaskFormerForInstanceSegmentation,MaskFormerModel:()=>n.MaskFormerModel,MaskFormerPreTrainedModel:()=>n.MaskFormerPreTrainedModel,MaskedLMOutput:()=>n.MaskedLMOutput,MaxLengthCriteria:()=>h.MaxLengthCriteria,MistralForCausalLM:()=>n.MistralForCausalLM,MistralModel:()=>n.MistralModel,MistralPreTrainedModel:()=>n.MistralPreTrainedModel,MobileBertForMaskedLM:()=>n.MobileBertForMaskedLM,MobileBertForQuestionAnswering:()=>n.MobileBertForQuestionAnswering,MobileBertForSequenceClassification:()=>n.MobileBertForSequenceClassification,MobileBertModel:()=>n.MobileBertModel,MobileBertPreTrainedModel:()=>n.MobileBertPreTrainedModel,MobileBertTokenizer:()=>s.MobileBertTokenizer,MobileNetV1FeatureExtractor:()=>i.MobileNetV1FeatureExtractor,MobileNetV1ForImageClassification:()=>n.MobileNetV1ForImageClassification,MobileNetV1Model:()=>n.MobileNetV1Model,MobileNetV1PreTrainedModel:()=>n.MobileNetV1PreTrainedModel,MobileNetV2FeatureExtractor:()=>i.MobileNetV2FeatureExtractor,MobileNetV2ForImageClassification:()=>n.MobileNetV2ForImageClassification,MobileNetV2Model:()=>n.MobileNetV2Model,MobileNetV2PreTrainedModel:()=>n.MobileNetV2PreTrainedModel,MobileNetV3FeatureExtractor:()=>i.MobileNetV3FeatureExtractor,MobileNetV3ForImageClassification:()=>n.MobileNetV3ForImageClassification,MobileNetV3Model:()=>n.MobileNetV3Model,MobileNetV3PreTrainedModel:()=>n.MobileNetV3PreTrainedModel,MobileNetV4FeatureExtractor:()=>i.MobileNetV4FeatureExtractor,MobileNetV4ForImageClassification:()=>n.MobileNetV4ForImageClassification,MobileNetV4Model:()=>n.MobileNetV4Model,MobileNetV4PreTrainedModel:()=>n.MobileNetV4PreTrainedModel,MobileViTFeatureExtractor:()=>i.MobileViTFeatureExtractor,MobileViTForImageClassification:()=>n.MobileViTForImageClassification,MobileViTImageProcessor:()=>i.MobileViTImageProcessor,MobileViTModel:()=>n.MobileViTModel,MobileViTPreTrainedModel:()=>n.MobileViTPreTrainedModel,MobileViTV2ForImageClassification:()=>n.MobileViTV2ForImageClassification,MobileViTV2Model:()=>n.MobileViTV2Model,MobileViTV2PreTrainedModel:()=>n.MobileViTV2PreTrainedModel,ModelOutput:()=>n.ModelOutput,Moondream1ForConditionalGeneration:()=>n.Moondream1ForConditionalGeneration,MptForCausalLM:()=>n.MptForCausalLM,MptModel:()=>n.MptModel,MptPreTrainedModel:()=>n.MptPreTrainedModel,MusicgenForCausalLM:()=>n.MusicgenForCausalLM,MusicgenForConditionalGeneration:()=>n.MusicgenForConditionalGeneration,MusicgenModel:()=>n.MusicgenModel,MusicgenPreTrainedModel:()=>n.MusicgenPreTrainedModel,NllbTokenizer:()=>s.NllbTokenizer,NomicBertModel:()=>n.NomicBertModel,NomicBertPreTrainedModel:()=>n.NomicBertPreTrainedModel,NougatImageProcessor:()=>i.NougatImageProcessor,NougatTokenizer:()=>s.NougatTokenizer,OPTForCausalLM:()=>n.OPTForCausalLM,OPTModel:()=>n.OPTModel,OPTPreTrainedModel:()=>n.OPTPreTrainedModel,ObjectDetectionPipeline:()=>t.ObjectDetectionPipeline,OpenELMForCausalLM:()=>n.OpenELMForCausalLM,OpenELMModel:()=>n.OpenELMModel,OpenELMPreTrainedModel:()=>n.OpenELMPreTrainedModel,OwlViTFeatureExtractor:()=>i.OwlViTFeatureExtractor,OwlViTForObjectDetection:()=>n.OwlViTForObjectDetection,OwlViTModel:()=>n.OwlViTModel,OwlViTPreTrainedModel:()=>n.OwlViTPreTrainedModel,OwlViTProcessor:()=>i.OwlViTProcessor,Owlv2ForObjectDetection:()=>n.Owlv2ForObjectDetection,Owlv2ImageProcessor:()=>i.Owlv2ImageProcessor,Owlv2Model:()=>n.Owlv2Model,Owlv2PreTrainedModel:()=>n.Owlv2PreTrainedModel,Phi3ForCausalLM:()=>n.Phi3ForCausalLM,Phi3Model:()=>n.Phi3Model,Phi3PreTrainedModel:()=>n.Phi3PreTrainedModel,PhiForCausalLM:()=>n.PhiForCausalLM,PhiModel:()=>n.PhiModel,PhiPreTrainedModel:()=>n.PhiPreTrainedModel,Pipeline:()=>t.Pipeline,PreTrainedModel:()=>n.PreTrainedModel,PreTrainedTokenizer:()=>s.PreTrainedTokenizer,PretrainedConfig:()=>a.PretrainedConfig,PretrainedMixin:()=>n.PretrainedMixin,Processor:()=>i.Processor,PvtForImageClassification:()=>n.PvtForImageClassification,PvtImageProcessor:()=>i.PvtImageProcessor,PvtModel:()=>n.PvtModel,PvtPreTrainedModel:()=>n.PvtPreTrainedModel,PyAnnoteFeatureExtractor:()=>i.PyAnnoteFeatureExtractor,PyAnnoteForAudioFrameClassification:()=>n.PyAnnoteForAudioFrameClassification,PyAnnoteModel:()=>n.PyAnnoteModel,PyAnnotePreTrainedModel:()=>n.PyAnnotePreTrainedModel,PyAnnoteProcessor:()=>i.PyAnnoteProcessor,QuestionAnsweringModelOutput:()=>n.QuestionAnsweringModelOutput,QuestionAnsweringPipeline:()=>t.QuestionAnsweringPipeline,Qwen2ForCausalLM:()=>n.Qwen2ForCausalLM,Qwen2Model:()=>n.Qwen2Model,Qwen2PreTrainedModel:()=>n.Qwen2PreTrainedModel,Qwen2Tokenizer:()=>s.Qwen2Tokenizer,RTDetrForObjectDetection:()=>n.RTDetrForObjectDetection,RTDetrImageProcessor:()=>i.RTDetrImageProcessor,RTDetrModel:()=>n.RTDetrModel,RTDetrObjectDetectionOutput:()=>n.RTDetrObjectDetectionOutput,RTDetrPreTrainedModel:()=>n.RTDetrPreTrainedModel,RawImage:()=>c.RawImage,ResNetForImageClassification:()=>n.ResNetForImageClassification,ResNetModel:()=>n.ResNetModel,ResNetPreTrainedModel:()=>n.ResNetPreTrainedModel,RoFormerForMaskedLM:()=>n.RoFormerForMaskedLM,RoFormerForQuestionAnswering:()=>n.RoFormerForQuestionAnswering,RoFormerForSequenceClassification:()=>n.RoFormerForSequenceClassification,RoFormerForTokenClassification:()=>n.RoFormerForTokenClassification,RoFormerModel:()=>n.RoFormerModel,RoFormerPreTrainedModel:()=>n.RoFormerPreTrainedModel,RoFormerTokenizer:()=>s.RoFormerTokenizer,RobertaForMaskedLM:()=>n.RobertaForMaskedLM,RobertaForQuestionAnswering:()=>n.RobertaForQuestionAnswering,RobertaForSequenceClassification:()=>n.RobertaForSequenceClassification,RobertaForTokenClassification:()=>n.RobertaForTokenClassification,RobertaModel:()=>n.RobertaModel,RobertaPreTrainedModel:()=>n.RobertaPreTrainedModel,RobertaTokenizer:()=>s.RobertaTokenizer,SamImageProcessor:()=>i.SamImageProcessor,SamImageSegmentationOutput:()=>n.SamImageSegmentationOutput,SamModel:()=>n.SamModel,SamPreTrainedModel:()=>n.SamPreTrainedModel,SamProcessor:()=>i.SamProcessor,SapiensFeatureExtractor:()=>i.SapiensFeatureExtractor,SapiensForDepthEstimation:()=>n.SapiensForDepthEstimation,SapiensForNormalEstimation:()=>n.SapiensForNormalEstimation,SapiensForSemanticSegmentation:()=>n.SapiensForSemanticSegmentation,SapiensPreTrainedModel:()=>n.SapiensPreTrainedModel,SeamlessM4TFeatureExtractor:()=>i.SeamlessM4TFeatureExtractor,SegformerFeatureExtractor:()=>i.SegformerFeatureExtractor,SegformerForImageClassification:()=>n.SegformerForImageClassification,SegformerForSemanticSegmentation:()=>n.SegformerForSemanticSegmentation,SegformerModel:()=>n.SegformerModel,SegformerPreTrainedModel:()=>n.SegformerPreTrainedModel,Seq2SeqLMOutput:()=>n.Seq2SeqLMOutput,SequenceClassifierOutput:()=>n.SequenceClassifierOutput,SiglipImageProcessor:()=>i.SiglipImageProcessor,SiglipModel:()=>n.SiglipModel,SiglipPreTrainedModel:()=>n.SiglipPreTrainedModel,SiglipTextModel:()=>n.SiglipTextModel,SiglipTokenizer:()=>s.SiglipTokenizer,SiglipVisionModel:()=>n.SiglipVisionModel,SpeechT5FeatureExtractor:()=>i.SpeechT5FeatureExtractor,SpeechT5ForSpeechToText:()=>n.SpeechT5ForSpeechToText,SpeechT5ForTextToSpeech:()=>n.SpeechT5ForTextToSpeech,SpeechT5HifiGan:()=>n.SpeechT5HifiGan,SpeechT5Model:()=>n.SpeechT5Model,SpeechT5PreTrainedModel:()=>n.SpeechT5PreTrainedModel,SpeechT5Processor:()=>i.SpeechT5Processor,SpeechT5Tokenizer:()=>s.SpeechT5Tokenizer,SqueezeBertForMaskedLM:()=>n.SqueezeBertForMaskedLM,SqueezeBertForQuestionAnswering:()=>n.SqueezeBertForQuestionAnswering,SqueezeBertForSequenceClassification:()=>n.SqueezeBertForSequenceClassification,SqueezeBertModel:()=>n.SqueezeBertModel,SqueezeBertPreTrainedModel:()=>n.SqueezeBertPreTrainedModel,SqueezeBertTokenizer:()=>s.SqueezeBertTokenizer,StableLmForCausalLM:()=>n.StableLmForCausalLM,StableLmModel:()=>n.StableLmModel,StableLmPreTrainedModel:()=>n.StableLmPreTrainedModel,Starcoder2ForCausalLM:()=>n.Starcoder2ForCausalLM,Starcoder2Model:()=>n.Starcoder2Model,Starcoder2PreTrainedModel:()=>n.Starcoder2PreTrainedModel,StoppingCriteria:()=>h.StoppingCriteria,StoppingCriteriaList:()=>h.StoppingCriteriaList,SummarizationPipeline:()=>t.SummarizationPipeline,Swin2SRForImageSuperResolution:()=>n.Swin2SRForImageSuperResolution,Swin2SRImageProcessor:()=>i.Swin2SRImageProcessor,Swin2SRModel:()=>n.Swin2SRModel,Swin2SRPreTrainedModel:()=>n.Swin2SRPreTrainedModel,SwinForImageClassification:()=>n.SwinForImageClassification,SwinModel:()=>n.SwinModel,SwinPreTrainedModel:()=>n.SwinPreTrainedModel,T5ForConditionalGeneration:()=>n.T5ForConditionalGeneration,T5Model:()=>n.T5Model,T5PreTrainedModel:()=>n.T5PreTrainedModel,T5Tokenizer:()=>s.T5Tokenizer,TableTransformerForObjectDetection:()=>n.TableTransformerForObjectDetection,TableTransformerModel:()=>n.TableTransformerModel,TableTransformerObjectDetectionOutput:()=>n.TableTransformerObjectDetectionOutput,TableTransformerPreTrainedModel:()=>n.TableTransformerPreTrainedModel,Tensor:()=>d.Tensor,Text2TextGenerationPipeline:()=>t.Text2TextGenerationPipeline,TextClassificationPipeline:()=>t.TextClassificationPipeline,TextGenerationPipeline:()=>t.TextGenerationPipeline,TextStreamer:()=>p.TextStreamer,TextToAudioPipeline:()=>t.TextToAudioPipeline,TokenClassificationPipeline:()=>t.TokenClassificationPipeline,TokenClassifierOutput:()=>n.TokenClassifierOutput,TokenizerModel:()=>s.TokenizerModel,TrOCRForCausalLM:()=>n.TrOCRForCausalLM,TrOCRPreTrainedModel:()=>n.TrOCRPreTrainedModel,TranslationPipeline:()=>t.TranslationPipeline,UniSpeechForCTC:()=>n.UniSpeechForCTC,UniSpeechForSequenceClassification:()=>n.UniSpeechForSequenceClassification,UniSpeechModel:()=>n.UniSpeechModel,UniSpeechPreTrainedModel:()=>n.UniSpeechPreTrainedModel,UniSpeechSatForAudioFrameClassification:()=>n.UniSpeechSatForAudioFrameClassification,UniSpeechSatForCTC:()=>n.UniSpeechSatForCTC,UniSpeechSatForSequenceClassification:()=>n.UniSpeechSatForSequenceClassification,UniSpeechSatModel:()=>n.UniSpeechSatModel,UniSpeechSatPreTrainedModel:()=>n.UniSpeechSatPreTrainedModel,ViTFeatureExtractor:()=>i.ViTFeatureExtractor,ViTForImageClassification:()=>n.ViTForImageClassification,ViTImageProcessor:()=>i.ViTImageProcessor,ViTMAEModel:()=>n.ViTMAEModel,ViTMAEPreTrainedModel:()=>n.ViTMAEPreTrainedModel,ViTMSNForImageClassification:()=>n.ViTMSNForImageClassification,ViTMSNModel:()=>n.ViTMSNModel,ViTMSNPreTrainedModel:()=>n.ViTMSNPreTrainedModel,ViTModel:()=>n.ViTModel,ViTPreTrainedModel:()=>n.ViTPreTrainedModel,VisionEncoderDecoderModel:()=>n.VisionEncoderDecoderModel,VitMatteForImageMatting:()=>n.VitMatteForImageMatting,VitMatteImageProcessor:()=>i.VitMatteImageProcessor,VitMattePreTrainedModel:()=>n.VitMattePreTrainedModel,VitsModel:()=>n.VitsModel,VitsModelOutput:()=>n.VitsModelOutput,VitsPreTrainedModel:()=>n.VitsPreTrainedModel,VitsTokenizer:()=>s.VitsTokenizer,Wav2Vec2BertForCTC:()=>n.Wav2Vec2BertForCTC,Wav2Vec2BertForSequenceClassification:()=>n.Wav2Vec2BertForSequenceClassification,Wav2Vec2BertModel:()=>n.Wav2Vec2BertModel,Wav2Vec2BertPreTrainedModel:()=>n.Wav2Vec2BertPreTrainedModel,Wav2Vec2CTCTokenizer:()=>s.Wav2Vec2CTCTokenizer,Wav2Vec2FeatureExtractor:()=>i.Wav2Vec2FeatureExtractor,Wav2Vec2ForAudioFrameClassification:()=>n.Wav2Vec2ForAudioFrameClassification,Wav2Vec2ForCTC:()=>n.Wav2Vec2ForCTC,Wav2Vec2ForSequenceClassification:()=>n.Wav2Vec2ForSequenceClassification,Wav2Vec2Model:()=>n.Wav2Vec2Model,Wav2Vec2PreTrainedModel:()=>n.Wav2Vec2PreTrainedModel,Wav2Vec2ProcessorWithLM:()=>i.Wav2Vec2ProcessorWithLM,WavLMForAudioFrameClassification:()=>n.WavLMForAudioFrameClassification,WavLMForCTC:()=>n.WavLMForCTC,WavLMForSequenceClassification:()=>n.WavLMForSequenceClassification,WavLMForXVector:()=>n.WavLMForXVector,WavLMModel:()=>n.WavLMModel,WavLMPreTrainedModel:()=>n.WavLMPreTrainedModel,WeSpeakerFeatureExtractor:()=>i.WeSpeakerFeatureExtractor,WeSpeakerResNetModel:()=>n.WeSpeakerResNetModel,WeSpeakerResNetPreTrainedModel:()=>n.WeSpeakerResNetPreTrainedModel,WhisperFeatureExtractor:()=>i.WhisperFeatureExtractor,WhisperForConditionalGeneration:()=>n.WhisperForConditionalGeneration,WhisperModel:()=>n.WhisperModel,WhisperPreTrainedModel:()=>n.WhisperPreTrainedModel,WhisperProcessor:()=>i.WhisperProcessor,WhisperTextStreamer:()=>p.WhisperTextStreamer,WhisperTokenizer:()=>s.WhisperTokenizer,XLMForQuestionAnswering:()=>n.XLMForQuestionAnswering,XLMForSequenceClassification:()=>n.XLMForSequenceClassification,XLMForTokenClassification:()=>n.XLMForTokenClassification,XLMModel:()=>n.XLMModel,XLMPreTrainedModel:()=>n.XLMPreTrainedModel,XLMRobertaForMaskedLM:()=>n.XLMRobertaForMaskedLM,XLMRobertaForQuestionAnswering:()=>n.XLMRobertaForQuestionAnswering,XLMRobertaForSequenceClassification:()=>n.XLMRobertaForSequenceClassification,XLMRobertaForTokenClassification:()=>n.XLMRobertaForTokenClassification,XLMRobertaModel:()=>n.XLMRobertaModel,XLMRobertaPreTrainedModel:()=>n.XLMRobertaPreTrainedModel,XLMRobertaTokenizer:()=>s.XLMRobertaTokenizer,XLMTokenizer:()=>s.XLMTokenizer,XLMWithLMHeadModel:()=>n.XLMWithLMHeadModel,XVectorOutput:()=>n.XVectorOutput,YolosFeatureExtractor:()=>i.YolosFeatureExtractor,YolosForObjectDetection:()=>n.YolosForObjectDetection,YolosModel:()=>n.YolosModel,YolosObjectDetectionOutput:()=>n.YolosObjectDetectionOutput,YolosPreTrainedModel:()=>n.YolosPreTrainedModel,ZeroShotAudioClassificationPipeline:()=>t.ZeroShotAudioClassificationPipeline,ZeroShotClassificationPipeline:()=>t.ZeroShotClassificationPipeline,ZeroShotImageClassificationPipeline:()=>t.ZeroShotImageClassificationPipeline,ZeroShotObjectDetectionPipeline:()=>t.ZeroShotObjectDetectionPipeline,bankers_round:()=>u.bankers_round,cat:()=>d.cat,cos_sim:()=>u.cos_sim,dot:()=>u.dot,dynamic_time_warping:()=>u.dynamic_time_warping,env:()=>e.env,full:()=>d.full,full_like:()=>d.full_like,getKeyValueShapes:()=>a.getKeyValueShapes,hamming:()=>l.hamming,hanning:()=>l.hanning,interpolate:()=>d.interpolate,interpolate_4d:()=>d.interpolate_4d,interpolate_data:()=>u.interpolate_data,is_chinese_char:()=>s.is_chinese_char,layer_norm:()=>d.layer_norm,log_softmax:()=>u.log_softmax,magnitude:()=>u.magnitude,matmul:()=>d.matmul,max:()=>u.max,mean:()=>d.mean,mean_pooling:()=>d.mean_pooling,medianFilter:()=>u.medianFilter,mel_filter_bank:()=>l.mel_filter_bank,min:()=>u.min,ones:()=>d.ones,ones_like:()=>d.ones_like,permute:()=>d.permute,permute_data:()=>u.permute_data,pipeline:()=>t.pipeline,quantize_embeddings:()=>d.quantize_embeddings,read_audio:()=>l.read_audio,rfft:()=>d.rfft,round:()=>u.round,softmax:()=>u.softmax,spectrogram:()=>l.spectrogram,stack:()=>d.stack,std_mean:()=>d.std_mean,topk:()=>d.topk,window_function:()=>l.window_function,zeros:()=>d.zeros,zeros_like:()=>d.zeros_like});var e=r(/*! ./env.js */"./src/env.js"),t=r(/*! ./pipelines.js */"./src/pipelines.js"),n=r(/*! ./models.js */"./src/models.js"),s=r(/*! ./tokenizers.js */"./src/tokenizers.js"),i=r(/*! ./processors.js */"./src/processors.js"),a=r(/*! ./configs.js */"./src/configs.js"),l=r(/*! ./utils/audio.js */"./src/utils/audio.js"),c=r(/*! ./utils/image.js */"./src/utils/image.js"),d=r(/*! ./utils/tensor.js */"./src/utils/tensor.js"),u=r(/*! ./utils/maths.js */"./src/utils/maths.js"),p=r(/*! ./generation/streamers.js */"./src/generation/streamers.js"),h=r(/*! ./generation/stopping_criteria.js */"./src/generation/stopping_criteria.js")})();var i=exports;for(var a in o)i[a]=o[a];o.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})})();
|
|
167
167
|
//# sourceMappingURL=transformers.min.cjs.map
|