import{s as $l,o as Tl,n as _t}from"../chunks/scheduler.defa9a21.js";import{S as jl,i as vl,g as p,s as a,r as u,A as Jl,h as o,f as l,c as n,j as Ml,u as d,x as r,k as bl,y as gl,a as s,v as f,d as h,t as y,w,m as Ul,n as Cl}from"../chunks/index.fe795e71.js";import{T as Ue}from"../chunks/Tip.179eb360.js";import{C as $}from"../chunks/CodeBlock.204b6c34.js";import{H as Zt,E as kl}from"../chunks/getInferenceSnippets.2234a8dd.js";function xl(T){let i,m=`This is only needed when trying to perform an action such as gathering the results, where the data on each device
needs to be the same length. Basic inference does not require this.`;return{c(){i=p("p"),i.textContent=m},l(c){i=o(c,"P",{"data-svelte-h":!0}),r(i)!=="svelte-rtowy2"&&(i.textContent=m)},m(c,M){s(c,i,M)},p:_t,d(c){c&&l(i)}}}function _l(T){let i;return{c(){i=Ul(`However you make this example will determine the relative batch size that will be used/passed
    through the model at a given time, so make sure to remember how many items there are!`)},l(m){i=Cl(m,`However you make this example will determine the relative batch size that will be used/passed
    through the model at a given time, so make sure to remember how many items there are!`)},m(m,c){s(m,i,c)},d(m){m&&l(i)}}}function Zl(T){let i,m="There are a variety of parameters you can pass through to <code>prepare_pippy</code>:",c,M,v="<li><p><code>split_points</code> lets you determine what layers to split the model at. By default we use wherever <code>device_map=&quot;auto&quot; declares, such as </code>fc<code>or</code>conv1`.</p></li> <li><p><code>num_chunks</code> determines how the batch will be split and sent to the model itself (so <code>num_chunks=1</code> with four split points/four GPUs will have a naive MP where a single input gets passed between the four layer split points)</p></li>";return{c(){i=p("p"),i.innerHTML=m,c=a(),M=p("ul"),M.innerHTML=v},l(b){i=o(b,"P",{"data-svelte-h":!0}),r(i)!=="svelte-123k9fd"&&(i.innerHTML=m),c=n(b),M=o(b,"UL",{"data-svelte-h":!0}),r(M)!=="svelte-1bax0io"&&(M.innerHTML=v)},m(b,j){s(b,i,j),s(b,c,j),s(b,M,j)},p:_t,d(b){b&&(l(i),l(c),l(M))}}}function Bl(T){let i,m="When passing inputs, we highly recommend to pass them in as a tuple of arguments. Using <code>kwargs</code> is supported, however, this approach is experimental.";return{c(){i=p("p"),i.innerHTML=m},l(c){i=o(c,"P",{"data-svelte-h":!0}),r(i)!=="svelte-1cjitly"&&(i.innerHTML=m)},m(c,M){s(c,i,M)},p:_t,d(c){c&&l(i)}}}function Gl(T){let i,m=`If you pass in <code>gather_output=True</code> to <a href="/docs/accelerate/main/en/package_reference/inference#accelerate.prepare_pippy">inference.prepare_pippy()</a>, the output will be sent
across to all the GPUs afterwards without needing the <code>is_last_process</code> check. This is
<code>False</code> by default as it incurs a communication call.`;return{c(){i=p("p"),i.innerHTML=m},l(c){i=o(c,"P",{"data-svelte-h":!0}),r(i)!=="svelte-18wou7y"&&(i.innerHTML=m)},m(c,M){s(c,i,M)},p:_t,d(c){c&&l(i)}}}function Wl(T){let i,m,c,M,v,b,j,Bt="Distributed inference can fall into three brackets:",Ce,x,Gt="<li>Loading an entire model onto each GPU and sending chunks of a batch through each GPU’s model copy at a time</li> <li>Loading parts of a model onto each GPU and processing a single input at one time</li> <li>Loading parts of a model onto each GPU and using what is called scheduled Pipeline Parallelism to combine the two prior techniques.</li>",ke,_,Wt="We’re going to go through the first and the last bracket, showcasing how to do each as they are more realistic scenarios.",xe,Z,_e,B,Ht="This is the most memory-intensive solution, as it requires each GPU to keep a full copy of the model in memory at a given time.",Ze,G,Xt="Normally when doing this, users send the model to a specific device to load it from the CPU, and then move each prompt to a different device.",Be,W,It="A basic pipeline using the <code>diffusers</code> library might look something like so:",Ge,H,We,X,Nt="Followed then by performing inference based on the specific prompt:",He,I,Xe,N,Pt="One will notice how we have to check the rank to know what prompt to send, which can be a bit tedious.",Ie,P,Rt=`A user might then also think that with Accelerate, using the <code>Accelerator</code> to prepare a dataloader for such a task might also be
a simple way to manage this. (To learn more, check out the relevant section in the <a href="../quicktour#distributed-evaluation">Quick Tour</a>)`,Ne,R,St="Can it manage it? Yes. Does it add unneeded extra code however: also yes.",Pe,S,Yt=`With Accelerate, we can simplify this process by using the <a href="/docs/accelerate/main/en/package_reference/accelerator#accelerate.Accelerator.split_between_processes">Accelerator.split_between_processes()</a> context manager (which also exists in <code>PartialState</code> and <code>AcceleratorState</code>).
This function will automatically split whatever data you pass to it (be it a prompt, a set of tensors, a dictionary of the prior data, etc.) across all the processes (with a potential
to be padded) for you to use right away.`,Re,Y,zt="Let’s rewrite the above example using this context manager:",Se,z,Ye,E,Et="And then to launch the code, we can use the Accelerate:",ze,F,Ft="If you have generated a config file to be used using <code>accelerate config</code>:",Ee,Q,Fe,A,Qt="If you have a specific config file you want to use:",Qe,L,Ae,V,At="Or if don’t want to make any config files and launch on two GPUs:",Le,q,Lt="<p>Note: You will get some warnings about values being guessed based on your system. To remove these you can do <code>accelerate config default</code> or go through <code>accelerate config</code> to create a config file.</p>",Ve,D,qe,K,Vt="We’ve now reduced the boilerplate code needed to split this data to a few lines of code quite easily.",De,O,qt="But what if we have an odd distribution of prompts to GPUs? For example, what if we have 3 prompts, but only 2 GPUs?",Ke,ee,Dt=`Under the context manager, the first GPU would receive the first two prompts and the second GPU the third, ensuring that
all prompts are split and no overhead is needed.`,Oe,te,Kt=`<em>However</em>, what if we then wanted to do something with the results of <em>all the GPUs</em>? (Say gather them all and perform some kind of post processing)
You can pass in <code>apply_padding=True</code> to ensure that the lists of prompts are padded to the same length, with extra data being taken
from the last sample. This way all GPUs will have the same number of prompts, and you can then gather the results.`,et,J,tt,le,Ot="For instance:",lt,se,st,ae,el=`On the first GPU, the prompts will be <code>[&quot;a dog&quot;, &quot;a cat&quot;]</code>, and on the second GPU it will be <code>[&quot;a chicken&quot;, &quot;a chicken&quot;]</code>.
Make sure to drop the final sample, as it will be a duplicate of the previous one.`,at,ne,tl='You can find more complex examples <a href="https://github.com/huggingface/accelerate/tree/main/examples/inference/distributed" rel="nofollow">here</a> such as how to use it with LLMs.',nt,ie,it,pe,ll='This next part will discuss using <em>pipeline parallelism</em>. This is an <strong>experimental</strong> API that utilizes <a href="https://pytorch.org/docs/stable/distributed.pipelining.html#" rel="nofollow">torch.distributed.pipelining</a> as a native solution.',pt,oe,sl="The general idea with pipeline parallelism is: say you have 4 GPUs and a model big enough it can be <em>split</em> on four GPUs using <code>device_map=&quot;auto&quot;</code>. With this method you can send in 4 inputs at a time (for example here, any amount works) and each model chunk will work on an input, then receive the next input once the prior chunk finished, making it <em>much</em> more efficient <strong>and faster</strong> than the method described earlier. Here’s a visual taken from the PyTorch repository:",ot,re,al='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/accelerate/pipeline_parallel.png" alt="Pipeline parallelism example"/>',rt,ce,nl='To illustrate how you can use this with Accelerate, we have created an <a href="https://github.com/huggingface/accelerate/tree/main/examples/inference" rel="nofollow">example zoo</a> showcasing a number of different models and situations. In this tutorial, we’ll show this method for GPT2 across two GPUs.',ct,me,il="Before you proceed, please make sure you have the latest PyTorch version installed by running the following:",mt,ue,ut,de,pl="Start by creating the model on the CPU:",dt,fe,ft,he,ol="Next you’ll need to create some example inputs to use. These help <code>torch.distributed.pipelining</code> trace the model.",ht,g,yt,ye,wt,we,rl='Next we need to actually perform the tracing and get the model ready. To do so, use the <a href="/docs/accelerate/main/en/package_reference/inference#accelerate.prepare_pippy">inference.prepare_pippy()</a> function and it will fully wrap the model for pipeline parallelism automatically:',Mt,Me,bt,U,$t,be,cl="From here, all that’s left is to actually perform the distributed inference!",Tt,C,jt,$e,vt,Te,ml="When finished all the data will be on the last process only:",Jt,je,gt,k,Ut,ve,ul='And that’s it! To explore more, please check out the inference examples in the <a href="https://github.com/huggingface/accelerate/tree/main/examples/inference/pippy" rel="nofollow">Accelerate repo</a> and our <a href="../package_reference/inference">documentation</a> as we work to improving this integration.',Ct,Je,kt,ge,xt;return v=new Zt({props:{title:"Distributed inference",local:"distributed-inference",headingTag:"h1"}}),Z=new Zt({props:{title:"Sending chunks of a batch automatically to each loaded model",local:"sending-chunks-of-a-batch-automatically-to-each-loaded-model",headingTag:"h2"}}),H=new $({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjB0b3JjaC5kaXN0cmlidXRlZCUyMGFzJTIwZGlzdCUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBEaWZmdXNpb25QaXBlbGluZSUwQSUwQXBpcGUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> torch.distributed <span class="hljs-keyword">as</span> dist
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>, torch_dtype=torch.float16)`,wrap:!1}}),I=new $({props:{code:"ZGVmJTIwcnVuX2luZmVyZW5jZShyYW5rJTJDJTIwd29ybGRfc2l6ZSklM0ElMEElMjAlMjAlMjAlMjBkaXN0LmluaXRfcHJvY2Vzc19ncm91cCglMjJuY2NsJTIyJTJDJTIwcmFuayUzRHJhbmslMkMlMjB3b3JsZF9zaXplJTNEd29ybGRfc2l6ZSklMEElMjAlMjAlMjAlMjBwaXBlLnRvKHJhbmspJTBBJTBBJTIwJTIwJTIwJTIwaWYlMjB0b3JjaC5kaXN0cmlidXRlZC5nZXRfcmFuaygpJTIwJTNEJTNEJTIwMCUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHByb21wdCUyMCUzRCUyMCUyMmElMjBkb2clMjIlMEElMjAlMjAlMjAlMjBlbGlmJTIwdG9yY2guZGlzdHJpYnV0ZWQuZ2V0X3JhbmsoKSUyMCUzRCUzRCUyMDElM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcm9tcHQlMjAlM0QlMjAlMjJhJTIwY2F0JTIyJTBBJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwcGlwZShwcm9tcHQpLmltYWdlcyU1QjAlNUQlMEElMjAlMjAlMjAlMjByZXN1bHQuc2F2ZShmJTIycmVzdWx0XyU3QnJhbmslN0QucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">run_inference</span>(<span class="hljs-params">rank, world_size</span>):
    dist.init_process_group(<span class="hljs-string">&quot;nccl&quot;</span>, rank=rank, world_size=world_size)
    pipe.to(rank)

    <span class="hljs-keyword">if</span> torch.distributed.get_rank() == <span class="hljs-number">0</span>:
        prompt = <span class="hljs-string">&quot;a dog&quot;</span>
    <span class="hljs-keyword">elif</span> torch.distributed.get_rank() == <span class="hljs-number">1</span>:
        prompt = <span class="hljs-string">&quot;a cat&quot;</span>

    result = pipe(prompt).images[<span class="hljs-number">0</span>]
    result.save(<span class="hljs-string">f&quot;result_<span class="hljs-subst">{rank}</span>.png&quot;</span>)`,wrap:!1}}),z=new $({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwYWNjZWxlcmF0ZSUyMGltcG9ydCUyMFBhcnRpYWxTdGF0ZSUyMCUyMCUyMyUyMENhbiUyMGFsc28lMjBiZSUyMEFjY2VsZXJhdG9yJTIwb3IlMjBBY2NlbGVyYXRvclN0YXRlJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFkaXN0cmlidXRlZF9zdGF0ZSUyMCUzRCUyMFBhcnRpYWxTdGF0ZSgpJTBBcGlwZS50byhkaXN0cmlidXRlZF9zdGF0ZS5kZXZpY2UpJTBBJTBBJTIzJTIwQXNzdW1lJTIwdHdvJTIwcHJvY2Vzc2VzJTBBd2l0aCUyMGRpc3RyaWJ1dGVkX3N0YXRlLnNwbGl0X2JldHdlZW5fcHJvY2Vzc2VzKCU1QiUyMmElMjBkb2clMjIlMkMlMjAlMjJhJTIwY2F0JTIyJTVEKSUyMGFzJTIwcHJvbXB0JTNBJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwcGlwZShwcm9tcHQpLmltYWdlcyU1QjAlNUQlMEElMjAlMjAlMjAlMjByZXN1bHQuc2F2ZShmJTIycmVzdWx0XyU3QmRpc3RyaWJ1dGVkX3N0YXRlLnByb2Nlc3NfaW5kZXglN0QucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> PartialState  <span class="hljs-comment"># Can also be Accelerator or AcceleratorState</span>
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>, torch_dtype=torch.float16)
distributed_state = PartialState()
pipe.to(distributed_state.device)

<span class="hljs-comment"># Assume two processes</span>
<span class="hljs-keyword">with</span> distributed_state.split_between_processes([<span class="hljs-string">&quot;a dog&quot;</span>, <span class="hljs-string">&quot;a cat&quot;</span>]) <span class="hljs-keyword">as</span> prompt:
    result = pipe(prompt).images[<span class="hljs-number">0</span>]
    result.save(<span class="hljs-string">f&quot;result_<span class="hljs-subst">{distributed_state.process_index}</span>.png&quot;</span>)`,wrap:!1}}),Q=new $({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMGRpc3RyaWJ1dGVkX2luZmVyZW5jZS5weQ==",highlighted:"accelerate launch distributed_inference.py",wrap:!1}}),L=new $({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tY29uZmlnX2ZpbGUlMjBteV9jb25maWcuanNvbiUyMGRpc3RyaWJ1dGVkX2luZmVyZW5jZS5weQ==",highlighted:"accelerate launch --config_file my_config.json distributed_inference.py",wrap:!1}}),D=new $({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbnVtX3Byb2Nlc3NlcyUyMDIlMjBkaXN0cmlidXRlZF9pbmZlcmVuY2UucHk=",highlighted:"accelerate launch --num_processes 2 distributed_inference.py",wrap:!1}}),J=new Ue({props:{$$slots:{default:[xl]},$$scope:{ctx:T}}}),se=new $({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwYWNjZWxlcmF0ZSUyMGltcG9ydCUyMFBhcnRpYWxTdGF0ZSUyMCUyMCUyMyUyMENhbiUyMGFsc28lMjBiZSUyMEFjY2VsZXJhdG9yJTIwb3IlMjBBY2NlbGVyYXRvclN0YXRlJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFkaXN0cmlidXRlZF9zdGF0ZSUyMCUzRCUyMFBhcnRpYWxTdGF0ZSgpJTBBcGlwZS50byhkaXN0cmlidXRlZF9zdGF0ZS5kZXZpY2UpJTBBJTBBJTIzJTIwQXNzdW1lJTIwdHdvJTIwcHJvY2Vzc2VzJTBBd2l0aCUyMGRpc3RyaWJ1dGVkX3N0YXRlLnNwbGl0X2JldHdlZW5fcHJvY2Vzc2VzKCU1QiUyMmElMjBkb2clMjIlMkMlMjAlMjJhJTIwY2F0JTIyJTJDJTIwJTIyYSUyMGNoaWNrZW4lMjIlNUQlMkMlMjBhcHBseV9wYWRkaW5nJTNEVHJ1ZSklMjBhcyUyMHByb21wdCUzQSUwQSUyMCUyMCUyMCUyMHJlc3VsdCUyMCUzRCUyMHBpcGUocHJvbXB0KS5pbWFnZXM=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> PartialState  <span class="hljs-comment"># Can also be Accelerator or AcceleratorState</span>
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>, torch_dtype=torch.float16)
distributed_state = PartialState()
pipe.to(distributed_state.device)

<span class="hljs-comment"># Assume two processes</span>
<span class="hljs-keyword">with</span> distributed_state.split_between_processes([<span class="hljs-string">&quot;a dog&quot;</span>, <span class="hljs-string">&quot;a cat&quot;</span>, <span class="hljs-string">&quot;a chicken&quot;</span>], apply_padding=<span class="hljs-literal">True</span>) <span class="hljs-keyword">as</span> prompt:
    result = pipe(prompt).images`,wrap:!1}}),ie=new Zt({props:{title:"Memory-efficient pipeline parallelism (experimental)",local:"memory-efficient-pipeline-parallelism-experimental",headingTag:"h2"}}),ue=new $({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRvcmNo",highlighted:"pip install torch",wrap:!1}}),fe=new $({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEdQVDJGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uJTJDJTIwR1BUMkNvbmZpZyUwQSUwQWNvbmZpZyUyMCUzRCUyMEdQVDJDb25maWcoKSUwQW1vZGVsJTIwJTNEJTIwR1BUMkZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24oY29uZmlnKSUwQW1vZGVsLmV2YWwoKQ==",highlighted:`from transformers <span class="hljs-keyword">import</span> GPT2ForSequenceClassification, GPT2Config

config = <span class="hljs-built_in">GPT2Config</span>()
model = <span class="hljs-built_in">GPT2ForSequenceClassification</span>(config)
model.<span class="hljs-built_in">eval</span>()`,wrap:!1}}),g=new Ue({props:{warning:!0,$$slots:{default:[_l]},$$scope:{ctx:T}}}),ye=new $({props:{code:"aW5wdXQlMjAlM0QlMjB0b3JjaC5yYW5kaW50KCUwQSUyMCUyMCUyMCUyMGxvdyUzRDAlMkMlMEElMjAlMjAlMjAlMjBoaWdoJTNEY29uZmlnLnZvY2FiX3NpemUlMkMlMEElMjAlMjAlMjAlMjBzaXplJTNEKDIlMkMlMjAxMDI0KSUyQyUyMCUyMCUyMyUyMGJzJTIweCUyMHNlcV9sZW4lMEElMjAlMjAlMjAlMjBkZXZpY2UlM0QlMjJjcHUlMjIlMkMlMEElMjAlMjAlMjAlMjBkdHlwZSUzRHRvcmNoLmludDY0JTJDJTBBJTIwJTIwJTIwJTIwcmVxdWlyZXNfZ3JhZCUzREZhbHNlJTJDJTBBKQ==",highlighted:`input = torch.randint(
    <span class="hljs-attribute">low</span>=0,
    <span class="hljs-attribute">high</span>=config.vocab_size,
    size=(2, 1024),  # bs x seq_len
    <span class="hljs-attribute">device</span>=<span class="hljs-string">&quot;cpu&quot;</span>,
    <span class="hljs-attribute">dtype</span>=torch.int64,
    <span class="hljs-attribute">requires_grad</span>=<span class="hljs-literal">False</span>,
)`,wrap:!1}}),Me=new $({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUuaW5mZXJlbmNlJTIwaW1wb3J0JTIwcHJlcGFyZV9waXBweSUwQWV4YW1wbGVfaW5wdXRzJTIwJTNEJTIwJTdCJTIyaW5wdXRfaWRzJTIyJTNBJTIwaW5wdXQlN0QlMEFtb2RlbCUyMCUzRCUyMHByZXBhcmVfcGlwcHkobW9kZWwlMkMlMjBleGFtcGxlX2FyZ3MlM0QoaW5wdXQlMkMpKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate.inference <span class="hljs-keyword">import</span> prepare_pippy
example_inputs = {&quot;input_ids&quot;: <span class="hljs-keyword">input</span>}
model = prepare_pippy(model, example_args=(<span class="hljs-keyword">input</span>,))`,wrap:!1}}),U=new Ue({props:{$$slots:{default:[Zl]},$$scope:{ctx:T}}}),C=new Ue({props:{warning:!0,$$slots:{default:[Bl]},$$scope:{ctx:T}}}),$e=new $({props:{code:"YXJncyUyMCUzRCUyMHNvbWVfbW9yZV9hcmd1bWVudHMlMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwb3V0cHV0JTIwJTNEJTIwbW9kZWwoKmFyZ3Mp",highlighted:`<span class="hljs-variable">args</span> = <span class="hljs-variable">some_more_arguments</span>
<span class="hljs-variable">with</span> <span class="hljs-variable">torch.no_grad</span>():
    <span class="hljs-variable">output</span> = <span class="hljs-function"><span class="hljs-title">model</span>(*<span class="hljs-variable">args</span>)</span>`,wrap:!1}}),je=new $({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBQYXJ0aWFsU3RhdGUlMEFpZiUyMFBhcnRpYWxTdGF0ZSgpLmlzX2xhc3RfcHJvY2VzcyUzQSUwQSUyMCUyMCUyMCUyMHByaW50KG91dHB1dCk=",highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> PartialState
<span class="hljs-keyword">if</span> PartialState().is_last_process:
    <span class="hljs-built_in">print</span>(output)`,wrap:!1}}),k=new Ue({props:{$$slots:{default:[Gl]},$$scope:{ctx:T}}}),Je=new kl({props:{source:"https://github.com/huggingface/accelerate/blob/main/docs/source/usage_guides/distributed_inference.md"}}),{c(){i=p("meta"),m=a(),c=p("p"),M=a(),u(v.$$.fragment),b=a(),j=p("p"),j.textContent=Bt,Ce=a(),x=p("ol"),x.innerHTML=Gt,ke=a(),_=p("p"),_.textContent=Wt,xe=a(),u(Z.$$.fragment),_e=a(),B=p("p"),B.textContent=Ht,Ze=a(),G=p("p"),G.textContent=Xt,Be=a(),W=p("p"),W.innerHTML=It,Ge=a(),u(H.$$.fragment),We=a(),X=p("p"),X.textContent=Nt,He=a(),u(I.$$.fragment),Xe=a(),N=p("p"),N.textContent=Pt,Ie=a(),P=p("p"),P.innerHTML=Rt,Ne=a(),R=p("p"),R.textContent=St,Pe=a(),S=p("p"),S.innerHTML=Yt,Re=a(),Y=p("p"),Y.textContent=zt,Se=a(),u(z.$$.fragment),Ye=a(),E=p("p"),E.textContent=Et,ze=a(),F=p("p"),F.innerHTML=Ft,Ee=a(),u(Q.$$.fragment),Fe=a(),A=p("p"),A.textContent=Qt,Qe=a(),u(L.$$.fragment),Ae=a(),V=p("p"),V.textContent=At,Le=a(),q=p("blockquote"),q.innerHTML=Lt,Ve=a(),u(D.$$.fragment),qe=a(),K=p("p"),K.textContent=Vt,De=a(),O=p("p"),O.textContent=qt,Ke=a(),ee=p("p"),ee.textContent=Dt,Oe=a(),te=p("p"),te.innerHTML=Kt,et=a(),u(J.$$.fragment),tt=a(),le=p("p"),le.textContent=Ot,lt=a(),u(se.$$.fragment),st=a(),ae=p("p"),ae.innerHTML=el,at=a(),ne=p("p"),ne.innerHTML=tl,nt=a(),u(ie.$$.fragment),it=a(),pe=p("p"),pe.innerHTML=ll,pt=a(),oe=p("p"),oe.innerHTML=sl,ot=a(),re=p("p"),re.innerHTML=al,rt=a(),ce=p("p"),ce.innerHTML=nl,ct=a(),me=p("p"),me.textContent=il,mt=a(),u(ue.$$.fragment),ut=a(),de=p("p"),de.textContent=pl,dt=a(),u(fe.$$.fragment),ft=a(),he=p("p"),he.innerHTML=ol,ht=a(),u(g.$$.fragment),yt=a(),u(ye.$$.fragment),wt=a(),we=p("p"),we.innerHTML=rl,Mt=a(),u(Me.$$.fragment),bt=a(),u(U.$$.fragment),$t=a(),be=p("p"),be.textContent=cl,Tt=a(),u(C.$$.fragment),jt=a(),u($e.$$.fragment),vt=a(),Te=p("p"),Te.textContent=ml,Jt=a(),u(je.$$.fragment),gt=a(),u(k.$$.fragment),Ut=a(),ve=p("p"),ve.innerHTML=ul,Ct=a(),u(Je.$$.fragment),kt=a(),ge=p("p"),this.h()},l(e){const t=Jl("svelte-u9bgzb",document.head);i=o(t,"META",{name:!0,content:!0}),t.forEach(l),m=n(e),c=o(e,"P",{}),Ml(c).forEach(l),M=n(e),d(v.$$.fragment,e),b=n(e),j=o(e,"P",{"data-svelte-h":!0}),r(j)!=="svelte-pzys4w"&&(j.textContent=Bt),Ce=n(e),x=o(e,"OL",{"data-svelte-h":!0}),r(x)!=="svelte-auhvyh"&&(x.innerHTML=Gt),ke=n(e),_=o(e,"P",{"data-svelte-h":!0}),r(_)!=="svelte-105ktyk"&&(_.textContent=Wt),xe=n(e),d(Z.$$.fragment,e),_e=n(e),B=o(e,"P",{"data-svelte-h":!0}),r(B)!=="svelte-1ojc10y"&&(B.textContent=Ht),Ze=n(e),G=o(e,"P",{"data-svelte-h":!0}),r(G)!=="svelte-1qi053h"&&(G.textContent=Xt),Be=n(e),W=o(e,"P",{"data-svelte-h":!0}),r(W)!=="svelte-rhvic4"&&(W.innerHTML=It),Ge=n(e),d(H.$$.fragment,e),We=n(e),X=o(e,"P",{"data-svelte-h":!0}),r(X)!=="svelte-1dzspg1"&&(X.textContent=Nt),He=n(e),d(I.$$.fragment,e),Xe=n(e),N=o(e,"P",{"data-svelte-h":!0}),r(N)!=="svelte-1ov43u6"&&(N.textContent=Pt),Ie=n(e),P=o(e,"P",{"data-svelte-h":!0}),r(P)!=="svelte-1n5a8vc"&&(P.innerHTML=Rt),Ne=n(e),R=o(e,"P",{"data-svelte-h":!0}),r(R)!=="svelte-12rt8sz"&&(R.textContent=St),Pe=n(e),S=o(e,"P",{"data-svelte-h":!0}),r(S)!=="svelte-1usr9nr"&&(S.innerHTML=Yt),Re=n(e),Y=o(e,"P",{"data-svelte-h":!0}),r(Y)!=="svelte-8uk323"&&(Y.textContent=zt),Se=n(e),d(z.$$.fragment,e),Ye=n(e),E=o(e,"P",{"data-svelte-h":!0}),r(E)!=="svelte-k1tgc3"&&(E.textContent=Et),ze=n(e),F=o(e,"P",{"data-svelte-h":!0}),r(F)!=="svelte-glszdf"&&(F.innerHTML=Ft),Ee=n(e),d(Q.$$.fragment,e),Fe=n(e),A=o(e,"P",{"data-svelte-h":!0}),r(A)!=="svelte-1beq8se"&&(A.textContent=Qt),Qe=n(e),d(L.$$.fragment,e),Ae=n(e),V=o(e,"P",{"data-svelte-h":!0}),r(V)!=="svelte-52p69u"&&(V.textContent=At),Le=n(e),q=o(e,"BLOCKQUOTE",{"data-svelte-h":!0}),r(q)!=="svelte-ix7ij8"&&(q.innerHTML=Lt),Ve=n(e),d(D.$$.fragment,e),qe=n(e),K=o(e,"P",{"data-svelte-h":!0}),r(K)!=="svelte-ui4crb"&&(K.textContent=Vt),De=n(e),O=o(e,"P",{"data-svelte-h":!0}),r(O)!=="svelte-dyqt5a"&&(O.textContent=qt),Ke=n(e),ee=o(e,"P",{"data-svelte-h":!0}),r(ee)!=="svelte-1o56krx"&&(ee.textContent=Dt),Oe=n(e),te=o(e,"P",{"data-svelte-h":!0}),r(te)!=="svelte-1y9mak3"&&(te.innerHTML=Kt),et=n(e),d(J.$$.fragment,e),tt=n(e),le=o(e,"P",{"data-svelte-h":!0}),r(le)!=="svelte-4vay6o"&&(le.textContent=Ot),lt=n(e),d(se.$$.fragment,e),st=n(e),ae=o(e,"P",{"data-svelte-h":!0}),r(ae)!=="svelte-42h08l"&&(ae.innerHTML=el),at=n(e),ne=o(e,"P",{"data-svelte-h":!0}),r(ne)!=="svelte-13go2fo"&&(ne.innerHTML=tl),nt=n(e),d(ie.$$.fragment,e),it=n(e),pe=o(e,"P",{"data-svelte-h":!0}),r(pe)!=="svelte-ynzvto"&&(pe.innerHTML=ll),pt=n(e),oe=o(e,"P",{"data-svelte-h":!0}),r(oe)!=="svelte-1l3sfxh"&&(oe.innerHTML=sl),ot=n(e),re=o(e,"P",{"data-svelte-h":!0}),r(re)!=="svelte-l2zgqj"&&(re.innerHTML=al),rt=n(e),ce=o(e,"P",{"data-svelte-h":!0}),r(ce)!=="svelte-heqe2k"&&(ce.innerHTML=nl),ct=n(e),me=o(e,"P",{"data-svelte-h":!0}),r(me)!=="svelte-1pr52sj"&&(me.textContent=il),mt=n(e),d(ue.$$.fragment,e),ut=n(e),de=o(e,"P",{"data-svelte-h":!0}),r(de)!=="svelte-1mviugk"&&(de.textContent=pl),dt=n(e),d(fe.$$.fragment,e),ft=n(e),he=o(e,"P",{"data-svelte-h":!0}),r(he)!=="svelte-15xaqzv"&&(he.innerHTML=ol),ht=n(e),d(g.$$.fragment,e),yt=n(e),d(ye.$$.fragment,e),wt=n(e),we=o(e,"P",{"data-svelte-h":!0}),r(we)!=="svelte-iarnyl"&&(we.innerHTML=rl),Mt=n(e),d(Me.$$.fragment,e),bt=n(e),d(U.$$.fragment,e),$t=n(e),be=o(e,"P",{"data-svelte-h":!0}),r(be)!=="svelte-t45mca"&&(be.textContent=cl),Tt=n(e),d(C.$$.fragment,e),jt=n(e),d($e.$$.fragment,e),vt=n(e),Te=o(e,"P",{"data-svelte-h":!0}),r(Te)!=="svelte-1f6tfb4"&&(Te.textContent=ml),Jt=n(e),d(je.$$.fragment,e),gt=n(e),d(k.$$.fragment,e),Ut=n(e),ve=o(e,"P",{"data-svelte-h":!0}),r(ve)!=="svelte-bz2a3m"&&(ve.innerHTML=ul),Ct=n(e),d(Je.$$.fragment,e),kt=n(e),ge=o(e,"P",{}),Ml(ge).forEach(l),this.h()},h(){bl(i,"name","hf:doc:metadata"),bl(i,"content",Hl)},m(e,t){gl(document.head,i),s(e,m,t),s(e,c,t),s(e,M,t),f(v,e,t),s(e,b,t),s(e,j,t),s(e,Ce,t),s(e,x,t),s(e,ke,t),s(e,_,t),s(e,xe,t),f(Z,e,t),s(e,_e,t),s(e,B,t),s(e,Ze,t),s(e,G,t),s(e,Be,t),s(e,W,t),s(e,Ge,t),f(H,e,t),s(e,We,t),s(e,X,t),s(e,He,t),f(I,e,t),s(e,Xe,t),s(e,N,t),s(e,Ie,t),s(e,P,t),s(e,Ne,t),s(e,R,t),s(e,Pe,t),s(e,S,t),s(e,Re,t),s(e,Y,t),s(e,Se,t),f(z,e,t),s(e,Ye,t),s(e,E,t),s(e,ze,t),s(e,F,t),s(e,Ee,t),f(Q,e,t),s(e,Fe,t),s(e,A,t),s(e,Qe,t),f(L,e,t),s(e,Ae,t),s(e,V,t),s(e,Le,t),s(e,q,t),s(e,Ve,t),f(D,e,t),s(e,qe,t),s(e,K,t),s(e,De,t),s(e,O,t),s(e,Ke,t),s(e,ee,t),s(e,Oe,t),s(e,te,t),s(e,et,t),f(J,e,t),s(e,tt,t),s(e,le,t),s(e,lt,t),f(se,e,t),s(e,st,t),s(e,ae,t),s(e,at,t),s(e,ne,t),s(e,nt,t),f(ie,e,t),s(e,it,t),s(e,pe,t),s(e,pt,t),s(e,oe,t),s(e,ot,t),s(e,re,t),s(e,rt,t),s(e,ce,t),s(e,ct,t),s(e,me,t),s(e,mt,t),f(ue,e,t),s(e,ut,t),s(e,de,t),s(e,dt,t),f(fe,e,t),s(e,ft,t),s(e,he,t),s(e,ht,t),f(g,e,t),s(e,yt,t),f(ye,e,t),s(e,wt,t),s(e,we,t),s(e,Mt,t),f(Me,e,t),s(e,bt,t),f(U,e,t),s(e,$t,t),s(e,be,t),s(e,Tt,t),f(C,e,t),s(e,jt,t),f($e,e,t),s(e,vt,t),s(e,Te,t),s(e,Jt,t),f(je,e,t),s(e,gt,t),f(k,e,t),s(e,Ut,t),s(e,ve,t),s(e,Ct,t),f(Je,e,t),s(e,kt,t),s(e,ge,t),xt=!0},p(e,[t]){const dl={};t&2&&(dl.$$scope={dirty:t,ctx:e}),J.$set(dl);const fl={};t&2&&(fl.$$scope={dirty:t,ctx:e}),g.$set(fl);const hl={};t&2&&(hl.$$scope={dirty:t,ctx:e}),U.$set(hl);const yl={};t&2&&(yl.$$scope={dirty:t,ctx:e}),C.$set(yl);const wl={};t&2&&(wl.$$scope={dirty:t,ctx:e}),k.$set(wl)},i(e){xt||(h(v.$$.fragment,e),h(Z.$$.fragment,e),h(H.$$.fragment,e),h(I.$$.fragment,e),h(z.$$.fragment,e),h(Q.$$.fragment,e),h(L.$$.fragment,e),h(D.$$.fragment,e),h(J.$$.fragment,e),h(se.$$.fragment,e),h(ie.$$.fragment,e),h(ue.$$.fragment,e),h(fe.$$.fragment,e),h(g.$$.fragment,e),h(ye.$$.fragment,e),h(Me.$$.fragment,e),h(U.$$.fragment,e),h(C.$$.fragment,e),h($e.$$.fragment,e),h(je.$$.fragment,e),h(k.$$.fragment,e),h(Je.$$.fragment,e),xt=!0)},o(e){y(v.$$.fragment,e),y(Z.$$.fragment,e),y(H.$$.fragment,e),y(I.$$.fragment,e),y(z.$$.fragment,e),y(Q.$$.fragment,e),y(L.$$.fragment,e),y(D.$$.fragment,e),y(J.$$.fragment,e),y(se.$$.fragment,e),y(ie.$$.fragment,e),y(ue.$$.fragment,e),y(fe.$$.fragment,e),y(g.$$.fragment,e),y(ye.$$.fragment,e),y(Me.$$.fragment,e),y(U.$$.fragment,e),y(C.$$.fragment,e),y($e.$$.fragment,e),y(je.$$.fragment,e),y(k.$$.fragment,e),y(Je.$$.fragment,e),xt=!1},d(e){e&&(l(m),l(c),l(M),l(b),l(j),l(Ce),l(x),l(ke),l(_),l(xe),l(_e),l(B),l(Ze),l(G),l(Be),l(W),l(Ge),l(We),l(X),l(He),l(Xe),l(N),l(Ie),l(P),l(Ne),l(R),l(Pe),l(S),l(Re),l(Y),l(Se),l(Ye),l(E),l(ze),l(F),l(Ee),l(Fe),l(A),l(Qe),l(Ae),l(V),l(Le),l(q),l(Ve),l(qe),l(K),l(De),l(O),l(Ke),l(ee),l(Oe),l(te),l(et),l(tt),l(le),l(lt),l(st),l(ae),l(at),l(ne),l(nt),l(it),l(pe),l(pt),l(oe),l(ot),l(re),l(rt),l(ce),l(ct),l(me),l(mt),l(ut),l(de),l(dt),l(ft),l(he),l(ht),l(yt),l(wt),l(we),l(Mt),l(bt),l($t),l(be),l(Tt),l(jt),l(vt),l(Te),l(Jt),l(gt),l(Ut),l(ve),l(Ct),l(kt),l(ge)),l(i),w(v,e),w(Z,e),w(H,e),w(I,e),w(z,e),w(Q,e),w(L,e),w(D,e),w(J,e),w(se,e),w(ie,e),w(ue,e),w(fe,e),w(g,e),w(ye,e),w(Me,e),w(U,e),w(C,e),w($e,e),w(je,e),w(k,e),w(Je,e)}}}const Hl='{"title":"Distributed inference","local":"distributed-inference","sections":[{"title":"Sending chunks of a batch automatically to each loaded model","local":"sending-chunks-of-a-batch-automatically-to-each-loaded-model","sections":[],"depth":2},{"title":"Memory-efficient pipeline parallelism (experimental)","local":"memory-efficient-pipeline-parallelism-experimental","sections":[],"depth":2}],"depth":1}';function Xl(T){return Tl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Yl extends jl{constructor(i){super(),vl(this,i,Xl,Wl,$l,{})}}export{Yl as component};
