import{S as is,i as cs,s as ps,e as o,k as m,w as R,t as i,M as ms,c as a,d as s,m as f,a as n,x as S,h as c,b as r,G as t,g as p,y as I,L as fs,q as F,o as W,B as z,v as hs}from"../chunks/vendor-hf-doc-builder.js";import{I as Xe}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as Je}from"../chunks/CodeBlock-hf-doc-builder.js";function us(Ye){let d,K,v,M,Q,j,Me,O,we,ee,h,Te,g,Ue,be,_,$e,je,se,y,w,P,C,ge,H,_e,te,G,le,T,Ce,V,Ge,Ze,oe,J,U,L,Z,Ne,q,ke,ae,u,Be,N,Ee,xe,k,Ae,Re,re,B,ne,b,Se,E,Ie,Fe,ie,x,ce,$,We,D,ze,Ve,pe,A,me;return j=new Xe({}),C=new Xe({}),G=new Je({props:{code:"aW1wb3J0JTIwJTdCJTIwZW52JTIwJTdEJTIwZnJvbSUyMCclNDB4ZW5vdmElMkZ0cmFuc2Zvcm1lcnMnJTNCJTBBJTBBJTJGJTJGJTIwU3BlY2lmeSUyMGElMjBjdXN0b20lMjBsb2NhdGlvbiUyMGZvciUyMG1vZGVscyUyMChkZWZhdWx0cyUyMHRvJTIwJyUyRm1vZGVscyUyRicpLiUwQWVudi5sb2NhbE1vZGVsUGF0aCUyMCUzRCUyMCclMkZwYXRoJTJGdG8lMkZtb2RlbHMlMkYnJTNCJTBBJTBBJTJGJTJGJTIwRGlzYWJsZSUyMHRoZSUyMGxvYWRpbmclMjBvZiUyMHJlbW90ZSUyMG1vZGVscyUyMGZyb20lMjB0aGUlMjBIdWdnaW5nJTIwRmFjZSUyMEh1YiUzQSUwQWVudi5hbGxvd1JlbW90ZU1vZGVscyUyMCUzRCUyMGZhbHNlJTNCJTBBJTBBJTJGJTJGJTIwU2V0JTIwbG9jYXRpb24lMjBvZiUyMC53YXNtJTIwZmlsZXMuJTIwRGVmYXVsdHMlMjB0byUyMHVzZSUyMGElMjBDRE4uJTBBZW52LmJhY2tlbmRzLm9ubngud2FzbS53YXNtUGF0aHMlMjAlM0QlMjAnJTJGcGF0aCUyRnRvJTJGZmlsZXMlMkYnJTNC",highlighted:`<span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@xenova/transformers&#x27;</span>;

<span class="hljs-comment">// Specify a custom location for models (defaults to &#x27;/models/&#x27;).</span>
env.<span class="hljs-property">localModelPath</span> = <span class="hljs-string">&#x27;/path/to/models/&#x27;</span>;

<span class="hljs-comment">// Disable the loading of remote models from the Hugging Face Hub:</span>
env.<span class="hljs-property">allowRemoteModels</span> = <span class="hljs-literal">false</span>;

<span class="hljs-comment">// Set location of .wasm files. Defaults to use a CDN.</span>
env.<span class="hljs-property">backends</span>.<span class="hljs-property">onnx</span>.<span class="hljs-property">wasm</span>.<span class="hljs-property">wasmPaths</span> = <span class="hljs-string">&#x27;/path/to/files/&#x27;</span>;`}}),Z=new Xe({}),B=new Je({props:{code:"cHl0aG9uJTIwLW0lMjBzY3JpcHRzLmNvbnZlcnQlMjAtLXF1YW50aXplJTIwLS1tb2RlbF9pZCUyMCUzQ21vZGVsX25hbWVfb3JfcGF0aCUzRQ==",highlighted:"python -m scripts.convert --quantize --model_id &lt;model_name_or_path&gt;"}}),x=new Je({props:{code:"cHl0aG9uJTIwLW0lMjBzY3JpcHRzLmNvbnZlcnQlMjAtLXF1YW50aXplJTIwLS1tb2RlbF9pZCUyMGJlcnQtYmFzZS11bmNhc2Vk",highlighted:"python -m scripts.convert --quantize --model_id bert-base-uncased"}}),A=new Je({props:{code:"YmVydC1iYXNlLXVuY2FzZWQlMkYlMEElRTIlOTQlOUMlRTIlOTQlODAlRTIlOTQlODAlMjBjb25maWcuanNvbiUwQSVFMiU5NCU5QyVFMiU5NCU4MCVFMiU5NCU4MCUyMHRva2VuaXplci5qc29uJTBBJUUyJTk0JTlDJUUyJTk0JTgwJUUyJTk0JTgwJTIwdG9rZW5pemVyX2NvbmZpZy5qc29uJTBBJUUyJTk0JTk0JUUyJTk0JTgwJUUyJTk0JTgwJTIwb25ueCUyRiUwQSUyMCUyMCUyMCUyMCVFMiU5NCU5QyVFMiU5NCU4MCVFMiU5NCU4MCUyMG1vZGVsLm9ubnglMEElMjAlMjAlMjAlMjAlRTIlOTQlOTQlRTIlOTQlODAlRTIlOTQlODAlMjBtb2RlbF9xdWFudGl6ZWQub25ueA==",highlighted:`bert-base-uncased/
\u251C\u2500\u2500 config<span class="hljs-selector-class">.json</span>
\u251C\u2500\u2500 tokenizer<span class="hljs-selector-class">.json</span>
\u251C\u2500\u2500 tokenizer_config<span class="hljs-selector-class">.json</span>
\u2514\u2500\u2500 onnx/
    \u251C\u2500\u2500 model<span class="hljs-selector-class">.onnx</span>
    \u2514\u2500\u2500 model_quantized.onnx`}}),{c(){d=o("meta"),K=m(),v=o("h1"),M=o("a"),Q=o("span"),R(j.$$.fragment),Me=m(),O=o("span"),we=i("Use custom models"),ee=m(),h=o("p"),Te=i("By default, Transformers.js uses "),g=o("a"),Ue=i("hosted pretrained models"),be=i(" and "),_=o("a"),$e=i("precompiled WASM binaries"),je=i(", which should work out-of-the-box. You can customize this as follows:"),se=m(),y=o("h3"),w=o("a"),P=o("span"),R(C.$$.fragment),ge=m(),H=o("span"),_e=i("Settings"),te=m(),R(G.$$.fragment),le=m(),T=o("p"),Ce=i("For a full list of available settings, check out the "),V=o("a"),Ge=i("API Reference"),Ze=i("."),oe=m(),J=o("h3"),U=o("a"),L=o("span"),R(Z.$$.fragment),Ne=m(),q=o("span"),ke=i("Convert your models to ONNX"),ae=m(),u=o("p"),Be=i("We recommend using our "),N=o("a"),Ee=i("conversion script"),xe=i(" to convert your PyTorch, TensorFlow, or JAX models to ONNX in a single command. Behind the scenes, it uses "),k=o("a"),Ae=i("\u{1F917} Optimum"),Re=i(" to perform conversion and quantization of your model."),re=m(),R(B.$$.fragment),ne=m(),b=o("p"),Se=i("For example, convert and quantize "),E=o("a"),Ie=i("bert-base-uncased"),Fe=i(" using:"),ie=m(),R(x.$$.fragment),ce=m(),$=o("p"),We=i("This will save the following files to "),D=o("code"),ze=i("./models/"),Ve=i(":"),pe=m(),R(A.$$.fragment),this.h()},l(e){const l=ms('[data-svelte="svelte-1phssyn"]',document.head);d=a(l,"META",{name:!0,content:!0}),l.forEach(s),K=f(e),v=a(e,"H1",{class:!0});var fe=n(v);M=a(fe,"A",{id:!0,class:!0,href:!0});var Qe=n(M);Q=a(Qe,"SPAN",{});var Oe=n(Q);S(j.$$.fragment,Oe),Oe.forEach(s),Qe.forEach(s),Me=f(fe),O=a(fe,"SPAN",{});var Pe=n(O);we=c(Pe,"Use custom models"),Pe.forEach(s),fe.forEach(s),ee=f(e),h=a(e,"P",{});var X=n(h);Te=c(X,"By default, Transformers.js uses "),g=a(X,"A",{href:!0,rel:!0});var He=n(g);Ue=c(He,"hosted pretrained models"),He.forEach(s),be=c(X," and "),_=a(X,"A",{href:!0,rel:!0});var Le=n(_);$e=c(Le,"precompiled WASM binaries"),Le.forEach(s),je=c(X,", which should work out-of-the-box. You can customize this as follows:"),X.forEach(s),se=f(e),y=a(e,"H3",{class:!0});var he=n(y);w=a(he,"A",{id:!0,class:!0,href:!0});var qe=n(w);P=a(qe,"SPAN",{});var De=n(P);S(C.$$.fragment,De),De.forEach(s),qe.forEach(s),ge=f(he),H=a(he,"SPAN",{});var Ke=n(H);_e=c(Ke,"Settings"),Ke.forEach(s),he.forEach(s),te=f(e),S(G.$$.fragment,e),le=f(e),T=a(e,"P",{});var ue=n(T);Ce=c(ue,"For a full list of available settings, check out the "),V=a(ue,"A",{href:!0});var es=n(V);Ge=c(es,"API Reference"),es.forEach(s),Ze=c(ue,"."),ue.forEach(s),oe=f(e),J=a(e,"H3",{class:!0});var de=n(J);U=a(de,"A",{id:!0,class:!0,href:!0});var ss=n(U);L=a(ss,"SPAN",{});var ts=n(L);S(Z.$$.fragment,ts),ts.forEach(s),ss.forEach(s),Ne=f(de),q=a(de,"SPAN",{});var ls=n(q);ke=c(ls,"Convert your models to ONNX"),ls.forEach(s),de.forEach(s),ae=f(e),u=a(e,"P",{});var Y=n(u);Be=c(Y,"We recommend using our "),N=a(Y,"A",{href:!0,rel:!0});var os=n(N);Ee=c(os,"conversion script"),os.forEach(s),xe=c(Y," to convert your PyTorch, TensorFlow, or JAX models to ONNX in a single command. Behind the scenes, it uses "),k=a(Y,"A",{href:!0,rel:!0});var as=n(k);Ae=c(as,"\u{1F917} Optimum"),as.forEach(s),Re=c(Y," to perform conversion and quantization of your model."),Y.forEach(s),re=f(e),S(B.$$.fragment,e),ne=f(e),b=a(e,"P",{});var ve=n(b);Se=c(ve,"For example, convert and quantize "),E=a(ve,"A",{href:!0,rel:!0});var rs=n(E);Ie=c(rs,"bert-base-uncased"),rs.forEach(s),Fe=c(ve," using:"),ve.forEach(s),ie=f(e),S(x.$$.fragment,e),ce=f(e),$=a(e,"P",{});var ye=n($);We=c(ye,"This will save the following files to "),D=a(ye,"CODE",{});var ns=n(D);ze=c(ns,"./models/"),ns.forEach(s),Ve=c(ye,":"),ye.forEach(s),pe=f(e),S(A.$$.fragment,e),this.h()},h(){r(d,"name","hf:doc:metadata"),r(d,"content",JSON.stringify(ds)),r(M,"id","use-custom-models"),r(M,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),r(M,"href","#use-custom-models"),r(v,"class","relative group"),r(g,"href","https://huggingface.co/models"),r(g,"rel","nofollow"),r(_,"href","https://cdn.jsdelivr.net/npm/@xenova/transformers@2.4.4/dist/"),r(_,"rel","nofollow"),r(w,"id","settings"),r(w,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),r(w,"href","#settings"),r(y,"class","relative group"),r(V,"href","/api/env"),r(U,"id","convert-your-models-to-onnx"),r(U,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),r(U,"href","#convert-your-models-to-onnx"),r(J,"class","relative group"),r(N,"href","https://github.com/xenova/transformers.js/blob/main/scripts/convert.py"),r(N,"rel","nofollow"),r(k,"href","https://huggingface.co/docs/optimum"),r(k,"rel","nofollow"),r(E,"href","https://huggingface.co/bert-base-uncased"),r(E,"rel","nofollow")},m(e,l){t(document.head,d),p(e,K,l),p(e,v,l),t(v,M),t(M,Q),I(j,Q,null),t(v,Me),t(v,O),t(O,we),p(e,ee,l),p(e,h,l),t(h,Te),t(h,g),t(g,Ue),t(h,be),t(h,_),t(_,$e),t(h,je),p(e,se,l),p(e,y,l),t(y,w),t(w,P),I(C,P,null),t(y,ge),t(y,H),t(H,_e),p(e,te,l),I(G,e,l),p(e,le,l),p(e,T,l),t(T,Ce),t(T,V),t(V,Ge),t(T,Ze),p(e,oe,l),p(e,J,l),t(J,U),t(U,L),I(Z,L,null),t(J,Ne),t(J,q),t(q,ke),p(e,ae,l),p(e,u,l),t(u,Be),t(u,N),t(N,Ee),t(u,xe),t(u,k),t(k,Ae),t(u,Re),p(e,re,l),I(B,e,l),p(e,ne,l),p(e,b,l),t(b,Se),t(b,E),t(E,Ie),t(b,Fe),p(e,ie,l),I(x,e,l),p(e,ce,l),p(e,$,l),t($,We),t($,D),t(D,ze),t($,Ve),p(e,pe,l),I(A,e,l),me=!0},p:fs,i(e){me||(F(j.$$.fragment,e),F(C.$$.fragment,e),F(G.$$.fragment,e),F(Z.$$.fragment,e),F(B.$$.fragment,e),F(x.$$.fragment,e),F(A.$$.fragment,e),me=!0)},o(e){W(j.$$.fragment,e),W(C.$$.fragment,e),W(G.$$.fragment,e),W(Z.$$.fragment,e),W(B.$$.fragment,e),W(x.$$.fragment,e),W(A.$$.fragment,e),me=!1},d(e){s(d),e&&s(K),e&&s(v),z(j),e&&s(ee),e&&s(h),e&&s(se),e&&s(y),z(C),e&&s(te),z(G,e),e&&s(le),e&&s(T),e&&s(oe),e&&s(J),z(Z),e&&s(ae),e&&s(u),e&&s(re),z(B,e),e&&s(ne),e&&s(b),e&&s(ie),z(x,e),e&&s(ce),e&&s($),e&&s(pe),z(A,e)}}}const ds={local:"use-custom-models",sections:[{local:"settings",title:"Settings"},{local:"convert-your-models-to-onnx",title:"Convert your models to ONNX"}],title:"Use custom models"};function vs(Ye){return hs(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ws extends is{constructor(d){super();cs(this,d,vs,us,ps,{})}}export{ws as default,ds as metadata};
