import{s as _e,n as Te,o as be}from"../chunks/scheduler.25b97de1.js";import{S as ve,i as $e,g as i,s as r,r as k,A as we,h as s,f as t,c as n,j as N,u as S,x as m,k as V,y as c,a,v as D,d as I,t as W,w as z}from"../chunks/index.d9030fc9.js";import{D as ie}from"../chunks/Docstring.ffac8efa.js";import{H as ge,E as ye}from"../chunks/EditOnGithub.91d95064.js";function Ee(se){let l,q,A,O,x,F,g,ce='<a href="https://github.com/pytorch/executorch" rel="nofollow"><code>ExecuTorch</code></a> is an end-to-end solution for enabling on-device inference capabilities across mobile and edge devices including wearables, embedded devices and microcontrollers. It is part of the PyTorch ecosystem and supports the deployment of PyTorch models with a focus on portability, productivity, and performance.',G,_,de='ExecuTorch introduces well defined entry points to perform model, device, and/or use-case specific optimizations such as backend delegation, user-defined compiler transformations, memory planning, and more. The first step in preparing a PyTorch model for execution on an edge device using ExecuTorch is to export the model. This is achieved through the use of a PyTorch API called <a href="https://pytorch.org/docs/stable/export.html" rel="nofollow"><code>torch.export</code></a>.',R,T,U,b,pe="An integration point is being developed to ensure that 🤗 Transformers can be exported using <code>torch.export</code>. The goal of this integration is not only to enable export but also to ensure that the exported artifact can be further lowered and optimized to run efficiently in <code>ExecuTorch</code>, particularly for mobile and edge use cases.",B,d,v,Z,E,le=`A wrapper module designed to make a <code>PreTrainedModel</code> exportable with <code>torch.export</code>,
specifically for use with static caching. This module ensures that the exported model
is compatible with further lowering and execution in <code>ExecuTorch</code>.`,ee,M,he=`Note:
This class is specifically designed to support export process using <code>torch.export</code>
in a way that ensures the model can be further lowered and run efficiently in <code>ExecuTorch</code>.`,te,p,$,oe,C,me="Forward pass of the module, which is compatible with the ExecuTorch runtime.",re,P,ue="This forward adapter serves two primary purposes:",ne,L,fe=`<li><p><strong>Making the Model <code>torch.export</code>-Compatible</strong>:
The adapter hides unsupported objects, such as the <code>Cache</code>, from the graph inputs and outputs,
enabling the model to be exportable using <code>torch.export</code> without encountering issues.</p></li> <li><p><strong>Ensuring Compatibility with <code>ExecuTorch</code> runtime</strong>:
The adapter matches the model’s forward signature with that in <code>executorch/extension/llm/runner</code>,
ensuring that the exported model can be executed in <code>ExecuTorch</code> out-of-the-box.</p></li>`,J,h,w,ae,H,xe=`Convert a <code>PreTrainedModel</code> into an exportable module and export it using <code>torch.export</code>,
ensuring the exported model is compatible with <code>ExecuTorch</code>.`,K,y,Q,j,X;return x=new ge({props:{title:"ExecuTorch",local:"executorch",headingTag:"h1"}}),T=new ge({props:{title:"ExecuTorch Integration",local:"transformers.TorchExportableModuleWithStaticCache",headingTag:"h2"}}),v=new ie({props:{name:"class transformers.TorchExportableModuleWithStaticCache",anchor:"transformers.TorchExportableModuleWithStaticCache",parameters:[{name:"model",val:": PreTrainedModel"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/integrations/executorch.py#L23"}}),$=new ie({props:{name:"forward",anchor:"transformers.TorchExportableModuleWithStaticCache.forward",parameters:[{name:"input_ids",val:": Tensor"},{name:"cache_position",val:": Tensor"}],parametersDescription:[{anchor:"transformers.TorchExportableModuleWithStaticCache.forward.input_ids",description:"<strong>input_ids</strong> (<code>torch.Tensor</code>) &#x2014; Tensor representing current input token id to the module.",name:"input_ids"},{anchor:"transformers.TorchExportableModuleWithStaticCache.forward.cache_position",description:"<strong>cache_position</strong> (<code>torch.Tensor</code>) &#x2014; Tensor representing current input position in the cache.",name:"cache_position"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/integrations/executorch.py#L90",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>Logits output from the model.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p>torch.Tensor</p>
`}}),w=new ie({props:{name:"transformers.convert_and_export_with_cache",anchor:"transformers.convert_and_export_with_cache",parameters:[{name:"model",val:": PreTrainedModel"},{name:"example_input_ids",val:": Tensor = None"},{name:"example_cache_position",val:": Tensor = None"}],parametersDescription:[{anchor:"transformers.convert_and_export_with_cache.model",description:"<strong>model</strong> (<code>PreTrainedModel</code>) &#x2014; The pretrained model to be exported.",name:"model"},{anchor:"transformers.convert_and_export_with_cache.example_input_ids",description:"<strong>example_input_ids</strong> (<code>torch.Tensor</code>) &#x2014; Example input token id used by <code>torch.export</code>.",name:"example_input_ids"},{anchor:"transformers.convert_and_export_with_cache.example_cache_position",description:"<strong>example_cache_position</strong> (<code>torch.Tensor</code>) &#x2014; Example current cache position used by <code>torch.export</code>.",name:"example_cache_position"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/integrations/executorch.py#L177",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The exported program generated via <code>torch.export</code>.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p>Exported program (<code>torch.export.ExportedProgram</code>)</p>
`}}),y=new ye({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/main_classes/executorch.md"}}),{c(){l=i("meta"),q=r(),A=i("p"),O=r(),k(x.$$.fragment),F=r(),g=i("p"),g.innerHTML=ce,G=r(),_=i("p"),_.innerHTML=de,R=r(),k(T.$$.fragment),U=r(),b=i("p"),b.innerHTML=pe,B=r(),d=i("div"),k(v.$$.fragment),Z=r(),E=i("p"),E.innerHTML=le,ee=r(),M=i("p"),M.innerHTML=he,te=r(),p=i("div"),k($.$$.fragment),oe=r(),C=i("p"),C.textContent=me,re=r(),P=i("p"),P.textContent=ue,ne=r(),L=i("ol"),L.innerHTML=fe,J=r(),h=i("div"),k(w.$$.fragment),ae=r(),H=i("p"),H.innerHTML=xe,K=r(),k(y.$$.fragment),Q=r(),j=i("p"),this.h()},l(e){const o=we("svelte-u9bgzb",document.head);l=s(o,"META",{name:!0,content:!0}),o.forEach(t),q=n(e),A=s(e,"P",{}),N(A).forEach(t),O=n(e),S(x.$$.fragment,e),F=n(e),g=s(e,"P",{"data-svelte-h":!0}),m(g)!=="svelte-s52zyj"&&(g.innerHTML=ce),G=n(e),_=s(e,"P",{"data-svelte-h":!0}),m(_)!=="svelte-krphnt"&&(_.innerHTML=de),R=n(e),S(T.$$.fragment,e),U=n(e),b=s(e,"P",{"data-svelte-h":!0}),m(b)!=="svelte-rak2iw"&&(b.innerHTML=pe),B=n(e),d=s(e,"DIV",{class:!0});var u=N(d);S(v.$$.fragment,u),Z=n(u),E=s(u,"P",{"data-svelte-h":!0}),m(E)!=="svelte-2k5iuq"&&(E.innerHTML=le),ee=n(u),M=s(u,"P",{"data-svelte-h":!0}),m(M)!=="svelte-sxfggh"&&(M.innerHTML=he),te=n(u),p=s(u,"DIV",{class:!0});var f=N(p);S($.$$.fragment,f),oe=n(f),C=s(f,"P",{"data-svelte-h":!0}),m(C)!=="svelte-1b4e8fi"&&(C.textContent=me),re=n(f),P=s(f,"P",{"data-svelte-h":!0}),m(P)!=="svelte-15fkaet"&&(P.textContent=ue),ne=n(f),L=s(f,"OL",{"data-svelte-h":!0}),m(L)!=="svelte-ezgyom"&&(L.innerHTML=fe),f.forEach(t),u.forEach(t),J=n(e),h=s(e,"DIV",{class:!0});var Y=N(h);S(w.$$.fragment,Y),ae=n(Y),H=s(Y,"P",{"data-svelte-h":!0}),m(H)!=="svelte-2axmlh"&&(H.innerHTML=xe),Y.forEach(t),K=n(e),S(y.$$.fragment,e),Q=n(e),j=s(e,"P",{}),N(j).forEach(t),this.h()},h(){V(l,"name","hf:doc:metadata"),V(l,"content",Me),V(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),V(d,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),V(h,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,o){c(document.head,l),a(e,q,o),a(e,A,o),a(e,O,o),D(x,e,o),a(e,F,o),a(e,g,o),a(e,G,o),a(e,_,o),a(e,R,o),D(T,e,o),a(e,U,o),a(e,b,o),a(e,B,o),a(e,d,o),D(v,d,null),c(d,Z),c(d,E),c(d,ee),c(d,M),c(d,te),c(d,p),D($,p,null),c(p,oe),c(p,C),c(p,re),c(p,P),c(p,ne),c(p,L),a(e,J,o),a(e,h,o),D(w,h,null),c(h,ae),c(h,H),a(e,K,o),D(y,e,o),a(e,Q,o),a(e,j,o),X=!0},p:Te,i(e){X||(I(x.$$.fragment,e),I(T.$$.fragment,e),I(v.$$.fragment,e),I($.$$.fragment,e),I(w.$$.fragment,e),I(y.$$.fragment,e),X=!0)},o(e){W(x.$$.fragment,e),W(T.$$.fragment,e),W(v.$$.fragment,e),W($.$$.fragment,e),W(w.$$.fragment,e),W(y.$$.fragment,e),X=!1},d(e){e&&(t(q),t(A),t(O),t(F),t(g),t(G),t(_),t(R),t(U),t(b),t(B),t(d),t(J),t(h),t(K),t(Q),t(j)),t(l),z(x,e),z(T,e),z(v),z($),z(w),z(y,e)}}}const Me='{"title":"ExecuTorch","local":"executorch","sections":[{"title":"ExecuTorch Integration","local":"transformers.TorchExportableModuleWithStaticCache","sections":[],"depth":2}],"depth":1}';function Ce(se){return be(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends ve{constructor(l){super(),$e(this,l,Ce,Ee,_e,{})}}export{Se as component};
