import{s as ho,o as Io,n as S}from"../chunks/scheduler.25b97de1.js";import{S as Co,i as bo,g as m,s as r,r as d,A as go,h as u,f as t,c as M,j as Uo,u as w,x as T,k as jo,y as $o,a as l,v as f,d as U,t as j,w as h,m as Ao,n as Bo}from"../chunks/index.d9030fc9.js";import{T as re}from"../chunks/Tip.baa67368.js";import{C as v}from"../chunks/CodeBlock.e6cd0d95.js";import{H as q,E as _o}from"../chunks/EditOnGithub.91d95064.js";import{H as ie,a as Y}from"../chunks/HfOption.1e589c90.js";function Zo(g){let s,c='If you’re having difficulties installing DeepSpeed, check the <a href="../debugging#deepspeed-cuda-installation">DeepSpeed CUDA installation</a> guide. While DeepSpeed has a pip installable PyPI package, it is highly recommended to <a href="https://www.deepspeed.ai/tutorials/advanced-install/#install-deepspeed-from-source" rel="nofollow">install it from source</a> to best match your hardware and to support certain features, like 1-bit Adam, which aren’t available in the PyPI distribution.';return{c(){s=m("p"),s.innerHTML=c},l(n){s=u(n,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1cityiq"&&(s.innerHTML=c)},m(n,p){l(n,s,p)},p:S,d(n){n&&t(s)}}}function vo(g){let s,c;return s=new v({props:{code:"cGlwJTIwaW5zdGFsbCUyMGRlZXBzcGVlZA==",highlighted:"pip install deepspeed",wrap:!1}}),{c(){d(s.$$.fragment)},l(n){w(s.$$.fragment,n)},m(n,p){f(s,n,p),c=!0},p:S,i(n){c||(U(s.$$.fragment,n),c=!0)},o(n){j(s.$$.fragment,n),c=!1},d(n){h(s,n)}}}function Go(g){let s,c;return s=new v({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyU1QmRlZXBzcGVlZCU1RA==",highlighted:"pip install transformers[deepspeed]",wrap:!1}}),{c(){d(s.$$.fragment)},l(n){w(s.$$.fragment,n)},m(n,p){f(s,n,p),c=!0},p:S,i(n){c||(U(s.$$.fragment,n),c=!0)},o(n){j(s.$$.fragment,n),c=!1},d(n){h(s,n)}}}function Wo(g){let s,c,n,p;return s=new Y({props:{id:"install",option:"PyPI",$$slots:{default:[vo]},$$scope:{ctx:g}}}),n=new Y({props:{id:"install",option:"Transformers",$$slots:{default:[Go]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment)},l(o){w(s.$$.fragment,o),c=M(o),w(n.$$.fragment,o)},m(o,i){f(s,o,i),l(o,c,i),f(n,o,i),p=!0},p(o,i){const y={};i&2&&(y.$$scope={dirty:i,ctx:o}),s.$set(y);const b={};i&2&&(b.$$scope={dirty:i,ctx:o}),n.$set(b)},i(o){p||(U(s.$$.fragment,o),U(n.$$.fragment,o),p=!0)},o(o){j(s.$$.fragment,o),j(n.$$.fragment,o),p=!1},d(o){o&&t(c),h(s,o),h(n,o)}}}function Ro(g){let s,c='Find a complete list of DeepSpeed configuration options on the <a href="https://www.deepspeed.ai/docs/config-json/" rel="nofollow">DeepSpeed Configuration JSON</a> reference. You can also find more practical examples of various DeepSpeed configuration examples on the <a href="https://github.com/microsoft/DeepSpeedExamples" rel="nofollow">DeepSpeedExamples</a> repository or the main <a href="https://github.com/microsoft/DeepSpeed" rel="nofollow">DeepSpeed</a> repository. To quickly find specific examples, you can:',n,p,o;return p=new v({props:{code:"Z2l0JTIwY2xvbmUlMjBodHRwcyUzQSUyRiUyRmdpdGh1Yi5jb20lMkZtaWNyb3NvZnQlMkZEZWVwU3BlZWRFeGFtcGxlcyUwQWNkJTIwRGVlcFNwZWVkRXhhbXBsZXMlMEFmaW5kJTIwLiUyMC1uYW1lJTIwJypqc29uJyUwQSUyMyUyMGZpbmQlMjBleGFtcGxlcyUyMHdpdGglMjB0aGUlMjBMYW1iJTIwb3B0aW1pemVyJTBBZ3JlcCUyMC1pJTIwTGFtYiUyMCUyNChmaW5kJTIwLiUyMC1uYW1lJTIwJypqc29uJyk=",highlighted:`git <span class="hljs-built_in">clone</span> https://github.com/microsoft/DeepSpeedExamples
<span class="hljs-built_in">cd</span> DeepSpeedExamples
find . -name <span class="hljs-string">&#x27;*json&#x27;</span>
<span class="hljs-comment"># find examples with the Lamb optimizer</span>
grep -i Lamb $(find . -name <span class="hljs-string">&#x27;*json&#x27;</span>)`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),d(p.$$.fragment)},l(i){s=u(i,"P",{"data-svelte-h":!0}),T(s)!=="svelte-a4z01l"&&(s.innerHTML=c),n=M(i),w(p.$$.fragment,i)},m(i,y){l(i,s,y),l(i,n,y),f(p,i,y),o=!0},p:S,i(i){o||(U(p.$$.fragment,i),o=!0)},o(i){j(p.$$.fragment,i),o=!1},d(i){i&&(t(s),t(n)),h(p,i)}}}function zo(g){let s,c;return s=new v({props:{code:"VHJhaW5pbmdBcmd1bWVudHMoLi4uJTJDJTIwZGVlcHNwZWVkJTNEJTIycGF0aCUyRnRvJTJGZGVlcHNwZWVkX2NvbmZpZy5qc29uJTIyKQ==",highlighted:'TrainingArguments(..., deepspeed=<span class="hljs-string">&quot;path/to/deepspeed_config.json&quot;</span>)',wrap:!1}}),{c(){d(s.$$.fragment)},l(n){w(s.$$.fragment,n)},m(n,p){f(s,n,p),c=!0},p:S,i(n){c||(U(s.$$.fragment,n),c=!0)},o(n){j(s.$$.fragment,n),c=!1},d(n){h(s,n)}}}function Xo(g){let s,c;return s=new v({props:{code:"ZHNfY29uZmlnX2RpY3QlMjAlM0QlMjBkaWN0KHNjaGVkdWxlciUzRHNjaGVkdWxlcl9wYXJhbXMlMkMlMjBvcHRpbWl6ZXIlM0RvcHRpbWl6ZXJfcGFyYW1zKSUwQWFyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyguLi4lMkMlMjBkZWVwc3BlZWQlM0Rkc19jb25maWdfZGljdCklMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lcihtb2RlbCUyQyUyMGFyZ3MlMkMlMjAuLi4p",highlighted:`ds_config_dict = <span class="hljs-built_in">dict</span>(scheduler=scheduler_params, optimizer=optimizer_params)
args = TrainingArguments(..., deepspeed=ds_config_dict)
trainer = Trainer(model, args, ...)`,wrap:!1}}),{c(){d(s.$$.fragment)},l(n){w(s.$$.fragment,n)},m(n,p){f(s,n,p),c=!0},p:S,i(n){c||(U(s.$$.fragment,n),c=!0)},o(n){j(s.$$.fragment,n),c=!1},d(n){h(s,n)}}}function ko(g){let s,c,n,p;return s=new Y({props:{id:"pass-config",option:"path to file",$$slots:{default:[zo]},$$scope:{ctx:g}}}),n=new Y({props:{id:"pass-config",option:"nested dict",$$slots:{default:[Xo]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment)},l(o){w(s.$$.fragment,o),c=M(o),w(n.$$.fragment,o)},m(o,i){f(s,o,i),l(o,c,i),f(n,o,i),p=!0},p(o,i){const y={};i&2&&(y.$$scope={dirty:i,ctx:o}),s.$set(y);const b={};i&2&&(b.$$scope={dirty:i,ctx:o}),n.$set(b)},i(o){p||(U(s.$$.fragment,o),U(n.$$.fragment,o),p=!0)},o(o){j(s.$$.fragment,o),j(n.$$.fragment,o),p=!1},d(o){o&&t(c),h(s,o),h(n,o)}}}function qo(g){let s;return{c(){s=Ao("DeepSpeed doesn’t validate parameter names and any typos fallback on the parameter's default setting. You can watch the DeepSpeed engine startup log messages to see what values it is going to use.")},l(c){s=Bo(c,"DeepSpeed doesn’t validate parameter names and any typos fallback on the parameter's default setting. You can watch the DeepSpeed engine startup log messages to see what values it is going to use.")},m(c,n){l(c,s,n)},d(c){c&&t(s)}}}function No(g){let s,c="ZeRO-1 shards the optimizer states across GPUs, and you can expect a tiny speed up. The ZeRO-1 config can be setup like this:",n,p,o;return p=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyemVyb19vcHRpbWl6YXRpb24lMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJzdGFnZSUyMiUzQSUyMDElMEElMjAlMjAlMjAlMjAlN0QlMEElN0Q=",highlighted:`{
    <span class="hljs-attr">&quot;zero_optimization&quot;:</span> {
        <span class="hljs-attr">&quot;stage&quot;:</span> <span class="hljs-number">1</span>
    }
}`,wrap:!1}}),{c(){s=m("p"),s.textContent=c,n=r(),d(p.$$.fragment)},l(i){s=u(i,"P",{"data-svelte-h":!0}),T(s)!=="svelte-hkpv8b"&&(s.textContent=c),n=M(i),w(p.$$.fragment,i)},m(i,y){l(i,s,y),l(i,n,y),f(p,i,y),o=!0},p:S,i(i){o||(U(p.$$.fragment,i),o=!0)},o(i){j(p.$$.fragment,i),o=!1},d(i){i&&(t(s),t(n)),h(p,i)}}}function Vo(g){let s,c="ZeRO-2 shards the optimizer and gradients across GPUs. This stage is primarily used for training since its features are not relevant to inference. Some important parameters to configure for better performance include:",n,p,o="<li><code>offload_optimizer</code> should be enabled to reduce GPU memory usage.</li> <li><code>overlap_comm</code> when set to <code>true</code> trades off increased GPU memory usage to lower allreduce latency. This feature uses 4.5x the <code>allgather_bucket_size</code> and <code>reduce_bucket_size</code> values. In this example, they’re set to <code>5e8</code> which means it requires 9GB of GPU memory. If your GPU memory is 8GB or less, you should reduce <code>overlap_comm</code> to lower the memory requirements and prevent an out-of-memory (OOM) error.</li> <li><code>allgather_bucket_size</code> and <code>reduce_bucket_size</code> trade off available GPU memory for communication speed. The smaller their values, the slower communication is and the more GPU memory is available. You can balance, for example, whether a bigger batch size is more important than a slightly slower training time.</li> <li><code>round_robin_gradients</code> is available in DeepSpeed 0.4.4 for CPU offloading. It parallelizes gradient copying to CPU memory among ranks by fine-grained gradient partitioning. Performance benefit grows with gradient accumulation steps (more copying between optimizer steps) or GPU count (increased parallelism).</li>",i,y,b;return y=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyemVyb19vcHRpbWl6YXRpb24lMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJzdGFnZSUyMiUzQSUyMDIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJvZmZsb2FkX29wdGltaXplciUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmRldmljZSUyMiUzQSUyMCUyMmNwdSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnBpbl9tZW1vcnklMjIlM0ElMjB0cnVlJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYWxsZ2F0aGVyX3BhcnRpdGlvbnMlMjIlM0ElMjB0cnVlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYWxsZ2F0aGVyX2J1Y2tldF9zaXplJTIyJTNBJTIwNWU4JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyb3ZlcmxhcF9jb21tJTIyJTNBJTIwdHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnJlZHVjZV9zY2F0dGVyJTIyJTNBJTIwdHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnJlZHVjZV9idWNrZXRfc2l6ZSUyMiUzQSUyMDVlOCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmNvbnRpZ3VvdXNfZ3JhZGllbnRzJTIyJTNBJTIwdHJ1ZSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnJvdW5kX3JvYmluX2dyYWRpZW50cyUyMiUzQSUyMHRydWUlMEElMjAlMjAlMjAlMjAlN0QlMEElN0Q=",highlighted:`{
    <span class="hljs-attr">&quot;zero_optimization&quot;:</span> {
        <span class="hljs-attr">&quot;stage&quot;:</span> <span class="hljs-number">2</span>,
        <span class="hljs-attr">&quot;offload_optimizer&quot;:</span> {
            <span class="hljs-attr">&quot;device&quot;:</span> <span class="hljs-string">&quot;cpu&quot;</span>,
            <span class="hljs-attr">&quot;pin_memory&quot;:</span> <span class="hljs-literal">true</span>
        },
        <span class="hljs-attr">&quot;allgather_partitions&quot;:</span> <span class="hljs-literal">true</span>,
        <span class="hljs-attr">&quot;allgather_bucket_size&quot;:</span> <span class="hljs-number">5e8</span>,
        <span class="hljs-attr">&quot;overlap_comm&quot;:</span> <span class="hljs-literal">true</span>,
        <span class="hljs-attr">&quot;reduce_scatter&quot;:</span> <span class="hljs-literal">true</span>,
        <span class="hljs-attr">&quot;reduce_bucket_size&quot;:</span> <span class="hljs-number">5e8</span>,
        <span class="hljs-attr">&quot;contiguous_gradients&quot;:</span> <span class="hljs-literal">true</span>
        <span class="hljs-attr">&quot;round_robin_gradients&quot;:</span> <span class="hljs-literal">true</span>
    }
}`,wrap:!1}}),{c(){s=m("p"),s.textContent=c,n=r(),p=m("ul"),p.innerHTML=o,i=r(),d(y.$$.fragment)},l(I){s=u(I,"P",{"data-svelte-h":!0}),T(s)!=="svelte-19reu34"&&(s.textContent=c),n=M(I),p=u(I,"UL",{"data-svelte-h":!0}),T(p)!=="svelte-1ji2a0e"&&(p.innerHTML=o),i=M(I),w(y.$$.fragment,I)},m(I,B){l(I,s,B),l(I,n,B),l(I,p,B),l(I,i,B),f(y,I,B),b=!0},p:S,i(I){b||(U(y.$$.fragment,I),b=!0)},o(I){j(y.$$.fragment,I),b=!1},d(I){I&&(t(s),t(n),t(p),t(i)),h(y,I)}}}function So(g){let s,c='For more information about initializing large models with ZeRO-3 and accessing the parameters, take a look at the <a href="https://deepspeed.readthedocs.io/en/latest/zero3.html#constructing-massive-models" rel="nofollow">Constructing Massive Models</a> and <a href="https://deepspeed.readthedocs.io/en/latest/zero3.html#gathering-parameters" rel="nofollow">Gathering Parameters</a> guides.';return{c(){s=m("p"),s.innerHTML=c},l(n){s=u(n,"P",{"data-svelte-h":!0}),T(s)!=="svelte-14c3i1p"&&(s.innerHTML=c)},m(n,p){l(n,s,p)},p:S,d(n){n&&t(s)}}}function Eo(g){let s,c="ZeRO-3 shards the optimizer, gradient, and parameters across GPUs. Unlike ZeRO-2, ZeRO-3 can also be used for inference, in addition to training, because it allows large models to be loaded on multiple GPUs. Some important parameters to configure include:",n,p,o='<li><p><code>device: &quot;cpu&quot;</code> can help if you’re running out of GPU memory and if you have free CPU memory available. This allows offloading model parameters to the CPU.</p></li> <li><p><code>pin_memory: true</code> can improve throughput, but less memory becomes available for other processes because the pinned memory is reserved for the specific process that requested it and it’s typically accessed much faster than normal CPU memory.</p></li> <li><p><code>stage3_max_live_parameters</code> is the upper limit on how many full parameters you want to keep on the GPU at any given time. Reduce this value if you encounter an OOM error.</p></li> <li><p><code>stage3_max_reuse_distance</code> is a value for determining when a parameter is used again in the future, and it helps decide whether to throw the parameter away or to keep it. If the parameter is going to be reused (if the value is less than <code>stage3_max_reuse_distance</code>), then it is kept to reduce communication overhead. This is super helpful when activation checkpointing is enabled and you want to keep the parameter in the forward recompute until the backward pass. But reduce this value if you encounter an OOM error.</p></li> <li><p><code>stage3_gather_16bit_weights_on_model_save</code> consolidates fp16 weights when a model is saved. For large models and multiple GPUs, this is expensive in terms of memory and speed. You should enable it if you’re planning on resuming training.</p></li> <li><p><code>sub_group_size</code> controls which parameters are updated during the optimizer step. Parameters are grouped into buckets of <code>sub_group_size</code> and each bucket is updated one at a time. When used with NVMe offload, <code>sub_group_size</code> determines when model states are moved in and out of CPU memory from during the optimization step. This prevents running out of CPU memory for extremely large models. <code>sub_group_size</code> can be left to its default value if you aren’t using NVMe offload, but you may want to change it if you:</p> <ol><li>Run into an OOM error during the optimizer step. In this case, reduce <code>sub_group_size</code> to reduce memory usage of the temporary buffers.</li> <li>The optimizer step is taking a really long time. In this case, increase <code>sub_group_size</code> to improve bandwidth utilization as a result of increased data buffers.</li></ol></li> <li><p><code>reduce_bucket_size</code>, <code>stage3_prefetch_bucket_size</code>, and <code>stage3_param_persistence_threshold</code> are dependent on a model’s hidden size. It is recommended to set these values to <code>auto</code> and allow the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> to automatically assign the values.</p></li>',i,y,b,I,B='You can use the <a href="https://deepspeed.readthedocs.io/en/latest/zero3.html#deepspeed.zero.Init" rel="nofollow"><code>deepspeed.zero.Init</code></a> context manager to initialize a model faster:',W,G,R,J,_='For pretrained models, the DeepSped config file needs to have <code>is_deepspeed_zero3_enabled: true</code> setup in <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> and it needs a ZeRO configuration enabled. The <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> object must be created <strong>before</strong> calling the model <a href="/docs/transformers/pr_30530/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a>.',k,N,Z,A,V='You’ll need ZeRO-3 if the fp16 weights don’t fit on a single GPU. If you’re able to load fp16 weights, then make sure you specify <code>torch_dtype=torch.float16</code> in <a href="/docs/transformers/pr_30530/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a>.',H,D,P='Another consideration for ZeRO-3 is if you have multiple GPUs, no single GPU has all the parameters unless it’s the parameters for the currently executing layer. To access all parameters from all the layers at once, such as loading pretrained model weights in <a href="/docs/transformers/pr_30530/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a>, one layer is loaded at a time and immediately partitioned to all GPUs. This is because for very large models, it isn’t possible to load the weights on one GPU and then distribute them across the other GPUs due to memory limitations.',F,x,K="If you encounter a model parameter weight that looks like the following, where <code>tensor([1.])</code> or the parameter size is 1 instead of a larger multi-dimensional shape, this means the parameter is partitioned and this is a ZeRO-3 placeholder.",ee,E,te,Q,O;return y=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyemVyb19vcHRpbWl6YXRpb24lMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJzdGFnZSUyMiUzQSUyMDMlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJvZmZsb2FkX29wdGltaXplciUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmRldmljZSUyMiUzQSUyMCUyMmNwdSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnBpbl9tZW1vcnklMjIlM0ElMjB0cnVlJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyb2ZmbG9hZF9wYXJhbSUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmRldmljZSUyMiUzQSUyMCUyMmNwdSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnBpbl9tZW1vcnklMjIlM0ElMjB0cnVlJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyb3ZlcmxhcF9jb21tJTIyJTNBJTIwdHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmNvbnRpZ3VvdXNfZ3JhZGllbnRzJTIyJTNBJTIwdHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnN1Yl9ncm91cF9zaXplJTIyJTNBJTIwMWU5JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycmVkdWNlX2J1Y2tldF9zaXplJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnN0YWdlM19wcmVmZXRjaF9idWNrZXRfc2l6ZSUyMiUzQSUyMCUyMmF1dG8lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJzdGFnZTNfcGFyYW1fcGVyc2lzdGVuY2VfdGhyZXNob2xkJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnN0YWdlM19tYXhfbGl2ZV9wYXJhbWV0ZXJzJTIyJTNBJTIwMWU5JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc3RhZ2UzX21heF9yZXVzZV9kaXN0YW5jZSUyMiUzQSUyMDFlOSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnN0YWdlM19nYXRoZXJfMTZiaXRfd2VpZ2h0c19vbl9tb2RlbF9zYXZlJTIyJTNBJTIwdHJ1ZSUwQSUyMCUyMCUyMCUyMCU3RCUwQSU3RA==",highlighted:`{
    <span class="hljs-attr">&quot;zero_optimization&quot;:</span> {
        <span class="hljs-attr">&quot;stage&quot;:</span> <span class="hljs-number">3</span>,
        <span class="hljs-attr">&quot;offload_optimizer&quot;:</span> {
            <span class="hljs-attr">&quot;device&quot;:</span> <span class="hljs-string">&quot;cpu&quot;</span>,
            <span class="hljs-attr">&quot;pin_memory&quot;:</span> <span class="hljs-literal">true</span>
        },
        <span class="hljs-attr">&quot;offload_param&quot;:</span> {
            <span class="hljs-attr">&quot;device&quot;:</span> <span class="hljs-string">&quot;cpu&quot;</span>,
            <span class="hljs-attr">&quot;pin_memory&quot;:</span> <span class="hljs-literal">true</span>
        },
        <span class="hljs-attr">&quot;overlap_comm&quot;:</span> <span class="hljs-literal">true</span>,
        <span class="hljs-attr">&quot;contiguous_gradients&quot;:</span> <span class="hljs-literal">true</span>,
        <span class="hljs-attr">&quot;sub_group_size&quot;:</span> <span class="hljs-number">1e9</span>,
        <span class="hljs-attr">&quot;reduce_bucket_size&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;stage3_prefetch_bucket_size&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;stage3_param_persistence_threshold&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;stage3_max_live_parameters&quot;:</span> <span class="hljs-number">1e9</span>,
        <span class="hljs-attr">&quot;stage3_max_reuse_distance&quot;:</span> <span class="hljs-number">1e9</span>,
        <span class="hljs-attr">&quot;stage3_gather_16bit_weights_on_model_save&quot;:</span> <span class="hljs-literal">true</span>
    }
}`,wrap:!1}}),G=new v({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFQ1Rm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uJTJDJTIwVDVDb25maWclMEFpbXBvcnQlMjBkZWVwc3BlZWQlMEElMEF3aXRoJTIwZGVlcHNwZWVkLnplcm8uSW5pdCgpJTNBJTBBJTIwJTIwJTIwJTIwY29uZmlnJTIwJTNEJTIwVDVDb25maWcuZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZS10NSUyRnQ1LXNtYWxsJTIyKSUwQSUyMCUyMCUyMCUyMG1vZGVsJTIwJTNEJTIwVDVGb3JDb25kaXRpb25hbEdlbmVyYXRpb24oY29uZmlnKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> T5ForConditionalGeneration, T5Config
<span class="hljs-keyword">import</span> deepspeed

<span class="hljs-keyword">with</span> deepspeed.zero.Init():
    config = T5Config.from_pretrained(<span class="hljs-string">&quot;google-t5/t5-small&quot;</span>)
    model = T5ForConditionalGeneration(config)`,wrap:!1}}),N=new v({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbCUyQyUyMFRyYWluZXIlMkMlMjBUcmFpbmluZ0FyZ3VtZW50cyUwQSUwQXRyYWluaW5nX2FyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyguLi4lMkMlMjBkZWVwc3BlZWQlM0Rkc19jb25maWcpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZS10NSUyRnQ1LXNtYWxsJTIyKSUwQXRyYWluZXIlMjAlM0QlMjBUcmFpbmVyKG1vZGVsJTNEbW9kZWwlMkMlMjBhcmdzJTNEdHJhaW5pbmdfYXJncyUyQyUyMC4uLik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModel, Trainer, TrainingArguments

training_args = TrainingArguments(..., deepspeed=ds_config)
model = AutoModel.from_pretrained(<span class="hljs-string">&quot;google-t5/t5-small&quot;</span>)
trainer = Trainer(model=model, args=training_args, ...)`,wrap:!1}}),E=new v({props:{code:"dGVuc29yKCU1QjEuMCU1RCUyQyUyMGRldmljZSUzRCUyMmN1ZGElM0EwJTIyJTJDJTIwZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTIwcmVxdWlyZXNfZ3JhZCUzRFRydWUp",highlighted:'tensor([<span class="hljs-number">1.0</span>], device=<span class="hljs-string">&quot;cuda:0&quot;</span>, dtype=torch.float16, requires_grad=<span class="hljs-literal">True</span>)',wrap:!1}}),Q=new re({props:{$$slots:{default:[So]},$$scope:{ctx:g}}}),{c(){s=m("p"),s.textContent=c,n=r(),p=m("ul"),p.innerHTML=o,i=r(),d(y.$$.fragment),b=r(),I=m("p"),I.innerHTML=B,W=r(),d(G.$$.fragment),R=r(),J=m("p"),J.innerHTML=_,k=r(),d(N.$$.fragment),Z=r(),A=m("p"),A.innerHTML=V,H=r(),D=m("p"),D.innerHTML=P,F=r(),x=m("p"),x.innerHTML=K,ee=r(),d(E.$$.fragment),te=r(),d(Q.$$.fragment)},l($){s=u($,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1xly99k"&&(s.textContent=c),n=M($),p=u($,"UL",{"data-svelte-h":!0}),T(p)!=="svelte-1rsxujf"&&(p.innerHTML=o),i=M($),w(y.$$.fragment,$),b=M($),I=u($,"P",{"data-svelte-h":!0}),T(I)!=="svelte-19jrhyn"&&(I.innerHTML=B),W=M($),w(G.$$.fragment,$),R=M($),J=u($,"P",{"data-svelte-h":!0}),T(J)!=="svelte-1s2yryh"&&(J.innerHTML=_),k=M($),w(N.$$.fragment,$),Z=M($),A=u($,"P",{"data-svelte-h":!0}),T(A)!=="svelte-iule0u"&&(A.innerHTML=V),H=M($),D=u($,"P",{"data-svelte-h":!0}),T(D)!=="svelte-1q7tfs6"&&(D.innerHTML=P),F=M($),x=u($,"P",{"data-svelte-h":!0}),T(x)!=="svelte-1t077r5"&&(x.innerHTML=K),ee=M($),w(E.$$.fragment,$),te=M($),w(Q.$$.fragment,$)},m($,X){l($,s,X),l($,n,X),l($,p,X),l($,i,X),f(y,$,X),l($,b,X),l($,I,X),l($,W,X),f(G,$,X),l($,R,X),l($,J,X),l($,k,X),f(N,$,X),l($,Z,X),l($,A,X),l($,H,X),l($,D,X),l($,F,X),l($,x,X),l($,ee,X),f(E,$,X),l($,te,X),f(Q,$,X),O=!0},p($,X){const se={};X&2&&(se.$$scope={dirty:X,ctx:$}),Q.$set(se)},i($){O||(U(y.$$.fragment,$),U(G.$$.fragment,$),U(N.$$.fragment,$),U(E.$$.fragment,$),U(Q.$$.fragment,$),O=!0)},o($){j(y.$$.fragment,$),j(G.$$.fragment,$),j(N.$$.fragment,$),j(E.$$.fragment,$),j(Q.$$.fragment,$),O=!1},d($){$&&(t(s),t(n),t(p),t(i),t(b),t(I),t(W),t(R),t(J),t(k),t(Z),t(A),t(H),t(D),t(F),t(x),t(ee),t(te)),h(y,$),h(G,$),h(N,$),h(E,$),h(Q,$)}}}function Qo(g){let s,c,n,p,o,i;return s=new Y({props:{id:"zero-config",option:"ZeRO-1",$$slots:{default:[No]},$$scope:{ctx:g}}}),n=new Y({props:{id:"zero-config",option:"ZeRO-2",$$slots:{default:[Vo]},$$scope:{ctx:g}}}),o=new Y({props:{id:"zero-config",option:"ZeRO-3",$$slots:{default:[Eo]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment),p=r(),d(o.$$.fragment)},l(y){w(s.$$.fragment,y),c=M(y),w(n.$$.fragment,y),p=M(y),w(o.$$.fragment,y)},m(y,b){f(s,y,b),l(y,c,b),f(n,y,b),l(y,p,b),f(o,y,b),i=!0},p(y,b){const I={};b&2&&(I.$$scope={dirty:b,ctx:y}),s.$set(I);const B={};b&2&&(B.$$scope={dirty:b,ctx:y}),n.$set(B);const W={};b&2&&(W.$$scope={dirty:b,ctx:y}),o.$set(W)},i(y){i||(U(s.$$.fragment,y),U(n.$$.fragment,y),U(o.$$.fragment,y),i=!0)},o(y){j(s.$$.fragment,y),j(n.$$.fragment,y),j(o.$$.fragment,y),i=!1},d(y){y&&(t(c),t(p)),h(s,y),h(n,y),h(o,y)}}}function Ho(g){let s,c='The optimizer and scheduler parameters for the config file can be set from the command line to avoid hard to find errors. For example, if the learning rate is set to a different value in another place you can override it from the command line. Aside from the optimizer and scheduler parameters, you’ll need to ensure your <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> command line arguments match the DeepSpeed configuration.';return{c(){s=m("p"),s.innerHTML=c},l(n){s=u(n,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1o1hjl6"&&(s.innerHTML=c)},m(n,p){l(n,s,p)},p:S,d(n){n&&t(s)}}}function xo(g){let s,c='DeepSpeed offers several <a href="https://www.deepspeed.ai/docs/config-json/#optimizer-parameters" rel="nofollow">optimizers</a> (Adam, AdamW, OneBitAdam, and LAMB) but you can also import other optimizers from PyTorch. If you don’t configure the optimizer in the config, the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> automatically selects AdamW and either uses the supplied values or the default values for the following parameters from the command line: <code>lr</code>, <code>adam_beta1</code>, <code>adam_beta2</code>, <code>adam_epsilon</code>, <code>weight_decay</code>.',n,p,o="You can set the parameters to <code>&quot;auto&quot;</code> or manually input your own desired values.",i,y,b,I,B="You can also use an unsupported optimizer by adding the following to the top level configuration.",W,G,R,J,_="From DeepSpeed==0.8.3 on, if you want to use offload, you’ll also need to the following to the top level configuration because offload works best with DeepSpeed’s CPU Adam optimizer.",k,N,Z;return y=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIyb3B0aW1pemVyJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydHlwZSUyMiUzQSUyMCUyMkFkYW1XJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycGFyYW1zJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybHIlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYmV0YXMlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZXBzJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMndlaWdodF9kZWNheSUyMiUzQSUyMCUyMmF1dG8lMjIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMEElMjAlMjAlMjAlN0QlMEElN0Q=",highlighted:`{
   <span class="hljs-attr">&quot;optimizer&quot;:</span> {
       <span class="hljs-attr">&quot;type&quot;:</span> <span class="hljs-string">&quot;AdamW&quot;</span>,
       <span class="hljs-attr">&quot;params&quot;:</span> {
         <span class="hljs-attr">&quot;lr&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
         <span class="hljs-attr">&quot;betas&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
         <span class="hljs-attr">&quot;eps&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
         <span class="hljs-attr">&quot;weight_decay&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
       }
   }
}`,wrap:!1}}),G=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIyemVyb19hbGxvd191bnRlc3RlZF9vcHRpbWl6ZXIlMjIlM0ElMjB0cnVlJTBBJTdE",highlighted:`{
   <span class="hljs-attr">&quot;zero_allow_untested_optimizer&quot;:</span> <span class="hljs-literal">true</span>
}`,wrap:!1}}),N=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIyemVyb19mb3JjZV9kc19jcHVfb3B0aW1pemVyJTIyJTNBJTIwZmFsc2UlMEElN0Q=",highlighted:`{
   <span class="hljs-attr">&quot;zero_force_ds_cpu_optimizer&quot;:</span> <span class="hljs-literal">false</span>
}`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),p=m("p"),p.innerHTML=o,i=r(),d(y.$$.fragment),b=r(),I=m("p"),I.textContent=B,W=r(),d(G.$$.fragment),R=r(),J=m("p"),J.textContent=_,k=r(),d(N.$$.fragment)},l(A){s=u(A,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1lcuygi"&&(s.innerHTML=c),n=M(A),p=u(A,"P",{"data-svelte-h":!0}),T(p)!=="svelte-1c8r8fs"&&(p.innerHTML=o),i=M(A),w(y.$$.fragment,A),b=M(A),I=u(A,"P",{"data-svelte-h":!0}),T(I)!=="svelte-1ecbnix"&&(I.textContent=B),W=M(A),w(G.$$.fragment,A),R=M(A),J=u(A,"P",{"data-svelte-h":!0}),T(J)!=="svelte-ybmwnz"&&(J.textContent=_),k=M(A),w(N.$$.fragment,A)},m(A,V){l(A,s,V),l(A,n,V),l(A,p,V),l(A,i,V),f(y,A,V),l(A,b,V),l(A,I,V),l(A,W,V),f(G,A,V),l(A,R,V),l(A,J,V),l(A,k,V),f(N,A,V),Z=!0},p:S,i(A){Z||(U(y.$$.fragment,A),U(G.$$.fragment,A),U(N.$$.fragment,A),Z=!0)},o(A){j(y.$$.fragment,A),j(G.$$.fragment,A),j(N.$$.fragment,A),Z=!1},d(A){A&&(t(s),t(n),t(p),t(i),t(b),t(I),t(W),t(R),t(J),t(k)),h(y,A),h(G,A),h(N,A)}}}function Yo(g){let s,c='DeepSpeed supports the LRRangeTest, OneCycle, WarmupLR and WarmupDecayLR learning rate <a href="https://www.deepspeed.ai/docs/config-json/#scheduler-parameters" rel="nofollow">schedulers</a>.',n,p,o="Transformers and DeepSpeed provide two of the same schedulers:",i,y,b="<li>WarmupLR is the same as <code>--lr_scheduler_type constant_with_warmup</code> in Transformers</li> <li>WarmupDecayLR is the same as  <code>--lr_scheduler_type linear</code> in Transformers (this is the default scheduler used in Transformers)</li>",I,B,W='If you don’t configure the scheduler in the config, the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> automatically selects WarmupDecayLR and either uses the supplied values or the default values for the following parameters from the command line: <code>warmup_min_lr</code>, <code>warmup_max_lr</code>, <code>warmup_num_steps</code>, <code>total_num_steps</code> (automatically calculated during run time if <code>max_steps</code> is not provided).',G,R,J="You can set the parameters to <code>&quot;auto&quot;</code> or manually input your own desired values.",_,k,N;return k=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIyc2NoZWR1bGVyJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydHlwZSUyMiUzQSUyMCUyMldhcm11cERlY2F5TFIlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJwYXJhbXMlMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ0b3RhbF9udW1fc3RlcHMlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyd2FybXVwX21pbl9sciUyMiUzQSUyMCUyMmF1dG8lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ3YXJtdXBfbWF4X2xyJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMndhcm11cF9udW1fc3RlcHMlMjIlM0ElMjAlMjJhdXRvJTIyJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTdEJTBBJTdE",highlighted:`{
   <span class="hljs-attr">&quot;scheduler&quot;:</span> {
         <span class="hljs-attr">&quot;type&quot;:</span> <span class="hljs-string">&quot;WarmupDecayLR&quot;</span>,
         <span class="hljs-attr">&quot;params&quot;:</span> {
             <span class="hljs-attr">&quot;total_num_steps&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
             <span class="hljs-attr">&quot;warmup_min_lr&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
             <span class="hljs-attr">&quot;warmup_max_lr&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
             <span class="hljs-attr">&quot;warmup_num_steps&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
         }
     }
}`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),p=m("p"),p.textContent=o,i=r(),y=m("ul"),y.innerHTML=b,I=r(),B=m("p"),B.innerHTML=W,G=r(),R=m("p"),R.innerHTML=J,_=r(),d(k.$$.fragment)},l(Z){s=u(Z,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1te33vu"&&(s.innerHTML=c),n=M(Z),p=u(Z,"P",{"data-svelte-h":!0}),T(p)!=="svelte-6jv6ql"&&(p.textContent=o),i=M(Z),y=u(Z,"UL",{"data-svelte-h":!0}),T(y)!=="svelte-1g6khrb"&&(y.innerHTML=b),I=M(Z),B=u(Z,"P",{"data-svelte-h":!0}),T(B)!=="svelte-1camay8"&&(B.innerHTML=W),G=M(Z),R=u(Z,"P",{"data-svelte-h":!0}),T(R)!=="svelte-1c8r8fs"&&(R.innerHTML=J),_=M(Z),w(k.$$.fragment,Z)},m(Z,A){l(Z,s,A),l(Z,n,A),l(Z,p,A),l(Z,i,A),l(Z,y,A),l(Z,I,A),l(Z,B,A),l(Z,G,A),l(Z,R,A),l(Z,_,A),f(k,Z,A),N=!0},p:S,i(Z){N||(U(k.$$.fragment,Z),N=!0)},o(Z){j(k.$$.fragment,Z),N=!1},d(Z){Z&&(t(s),t(n),t(p),t(i),t(y),t(I),t(B),t(G),t(R),t(_)),h(k,Z)}}}function Fo(g){let s,c,n,p;return s=new Y({props:{id:"opt-sched",option:"optimizer",$$slots:{default:[xo]},$$scope:{ctx:g}}}),n=new Y({props:{id:"opt-sched",option:"scheduler",$$slots:{default:[Yo]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment)},l(o){w(s.$$.fragment,o),c=M(o),w(n.$$.fragment,o)},m(o,i){f(s,o,i),l(o,c,i),f(n,o,i),p=!0},p(o,i){const y={};i&2&&(y.$$scope={dirty:i,ctx:o}),s.$set(y);const b={};i&2&&(b.$$scope={dirty:i,ctx:o}),n.$set(b)},i(o){p||(U(s.$$.fragment,o),U(n.$$.fragment,o),p=!0)},o(o){j(s.$$.fragment,o),j(n.$$.fragment,o),p=!1},d(o){o&&t(c),h(s,o),h(n,o)}}}function Lo(g){let s,c="If your model doesn’t work well with mixed precision, for example if it wasn’t pretrained in mixed precision, you may encounter overflow or underflow issues which can cause NaN loss. For these cases, you should use full fp32 precision by explicitly disabling the default fp16 mode.",n,p,o,i,y='For Ampere GPUs and PyTorch &gt; 1.7, it automatically switches to the more efficient <a href="https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices" rel="nofollow">tf32</a> format for some operations but the results are still in fp32. You can control it from the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> by setting <code>--tf32</code> to enable it, and <code>--tf32 0</code> or <code>--no_tf32</code> to disable it.',b;return p=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyZnAxNiUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmVuYWJsZWQlMjIlM0ElMjBmYWxzZSUwQSUyMCUyMCUyMCUyMCU3RCUwQSU3RA==",highlighted:`{
    <span class="hljs-attr">&quot;fp16&quot;:</span> {
        <span class="hljs-attr">&quot;enabled&quot;:</span> <span class="hljs-literal">false</span>
    }
}`,wrap:!1}}),{c(){s=m("p"),s.textContent=c,n=r(),d(p.$$.fragment),o=r(),i=m("p"),i.innerHTML=y},l(I){s=u(I,"P",{"data-svelte-h":!0}),T(s)!=="svelte-14q857h"&&(s.textContent=c),n=M(I),w(p.$$.fragment,I),o=M(I),i=u(I,"P",{"data-svelte-h":!0}),T(i)!=="svelte-1ecoemb"&&(i.innerHTML=y)},m(I,B){l(I,s,B),l(I,n,B),f(p,I,B),l(I,o,B),l(I,i,B),b=!0},p:S,i(I){b||(U(p.$$.fragment,I),b=!0)},o(I){j(p.$$.fragment,I),b=!1},d(I){I&&(t(s),t(n),t(o),t(i)),h(p,I)}}}function Do(g){let s,c='To configure PyTorch AMP-like fp16 mixed precision reduces memory usage and accelerates training speed. <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> automatically enables or disables fp16 based on the value of <code>args.fp16_backend</code>, and the rest of the config can be set by you. fp16 is enabled from the command line when the following arguments are passed: <code>--fp16</code>, <code>--fp16_backend amp</code> or <code>--fp16_full_eval</code>.',n,p,o,i,y='For additional DeepSpeed fp16 training options, take a look at the <a href="https://www.deepspeed.ai/docs/config-json/#fp16-training-options" rel="nofollow">FP16 Training Options</a> reference.',b,I,B='To configure Apex-like fp16 mixed precision, setup the config as shown below with <code>&quot;auto&quot;</code> or your own values. <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> automatically configure <code>amp</code> based on the values of <code>args.fp16_backend</code> and <code>args.fp16_opt_level</code>. It can also be enabled from the command line when the following arguments are passed: <code>--fp16</code>, <code>--fp16_backend apex</code> or <code>--fp16_opt_level 01</code>.',W,G,R;return p=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyZnAxNiUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmVuYWJsZWQlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybG9zc19zY2FsZSUyMiUzQSUyMDAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJsb3NzX3NjYWxlX3dpbmRvdyUyMiUzQSUyMDEwMDAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJpbml0aWFsX3NjYWxlX3Bvd2VyJTIyJTNBJTIwMTYlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJoeXN0ZXJlc2lzJTIyJTNBJTIwMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMm1pbl9sb3NzX3NjYWxlJTIyJTNBJTIwMSUwQSUyMCUyMCUyMCUyMCU3RCUwQSU3RA==",highlighted:`{
    <span class="hljs-attr">&quot;fp16&quot;:</span> {
        <span class="hljs-attr">&quot;enabled&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;loss_scale&quot;:</span> <span class="hljs-number">0</span>,
        <span class="hljs-attr">&quot;loss_scale_window&quot;:</span> <span class="hljs-number">1000</span>,
        <span class="hljs-attr">&quot;initial_scale_power&quot;:</span> <span class="hljs-number">16</span>,
        <span class="hljs-attr">&quot;hysteresis&quot;:</span> <span class="hljs-number">2</span>,
        <span class="hljs-attr">&quot;min_loss_scale&quot;:</span> <span class="hljs-number">1</span>
    }
}`,wrap:!1}}),G=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyYW1wJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZW5hYmxlZCUyMiUzQSUyMCUyMmF1dG8lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJvcHRfbGV2ZWwlMjIlM0ElMjAlMjJhdXRvJTIyJTBBJTIwJTIwJTIwJTIwJTdEJTBBJTdE",highlighted:`{
    <span class="hljs-attr">&quot;amp&quot;:</span> {
        <span class="hljs-attr">&quot;enabled&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;opt_level&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
    }
}`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),d(p.$$.fragment),o=r(),i=m("p"),i.innerHTML=y,b=r(),I=m("p"),I.innerHTML=B,W=r(),d(G.$$.fragment)},l(J){s=u(J,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1ctj7i5"&&(s.innerHTML=c),n=M(J),w(p.$$.fragment,J),o=M(J),i=u(J,"P",{"data-svelte-h":!0}),T(i)!=="svelte-rsxg0g"&&(i.innerHTML=y),b=M(J),I=u(J,"P",{"data-svelte-h":!0}),T(I)!=="svelte-16gbm4p"&&(I.innerHTML=B),W=M(J),w(G.$$.fragment,J)},m(J,_){l(J,s,_),l(J,n,_),f(p,J,_),l(J,o,_),l(J,i,_),l(J,b,_),l(J,I,_),l(J,W,_),f(G,J,_),R=!0},p:S,i(J){R||(U(p.$$.fragment,J),U(G.$$.fragment,J),R=!0)},o(J){j(p.$$.fragment,J),j(G.$$.fragment,J),R=!1},d(J){J&&(t(s),t(n),t(o),t(i),t(b),t(I),t(W)),h(p,J),h(G,J)}}}function Po(g){let s,c='To use bf16, you’ll need at least DeepSpeed==0.6.0. bf16 has the same dynamic range as fp32 and doesn’t require loss scaling. However, if you use <a href="#gradient-accumulation">gradient accumulation</a> with bf16, gradients are accumulated in bf16 which may not be desired because this format’s low precision can lead to lossy accumulation.',n,p,o="bf16 can be setup in the config file or enabled from the command line when the following arguments are passed: <code>--bf16</code> or <code>--bf16_full_eval</code>.",i,y,b;return y=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyYmYxNiUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmVuYWJsZWQlMjIlM0ElMjAlMjJhdXRvJTIyJTBBJTIwJTIwJTIwJTIwJTdEJTBBJTdE",highlighted:`{
    <span class="hljs-attr">&quot;bf16&quot;:</span> {
        <span class="hljs-attr">&quot;enabled&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
    }
}`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),p=m("p"),p.innerHTML=o,i=r(),d(y.$$.fragment)},l(I){s=u(I,"P",{"data-svelte-h":!0}),T(s)!=="svelte-9fep10"&&(s.innerHTML=c),n=M(I),p=u(I,"P",{"data-svelte-h":!0}),T(p)!=="svelte-f1ubot"&&(p.innerHTML=o),i=M(I),w(y.$$.fragment,I)},m(I,B){l(I,s,B),l(I,n,B),l(I,p,B),l(I,i,B),f(y,I,B),b=!0},p:S,i(I){b||(U(y.$$.fragment,I),b=!0)},o(I){j(y.$$.fragment,I),b=!1},d(I){I&&(t(s),t(n),t(p),t(i)),h(y,I)}}}function Oo(g){let s,c,n,p,o,i;return s=new Y({props:{id:"precision",option:"fp32",$$slots:{default:[Lo]},$$scope:{ctx:g}}}),n=new Y({props:{id:"precision",option:"fp16",$$slots:{default:[Do]},$$scope:{ctx:g}}}),o=new Y({props:{id:"precision",option:"bf16",$$slots:{default:[Po]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment),p=r(),d(o.$$.fragment)},l(y){w(s.$$.fragment,y),c=M(y),w(n.$$.fragment,y),p=M(y),w(o.$$.fragment,y)},m(y,b){f(s,y,b),l(y,c,b),f(n,y,b),l(y,p,b),f(o,y,b),i=!0},p(y,b){const I={};b&2&&(I.$$scope={dirty:b,ctx:y}),s.$set(I);const B={};b&2&&(B.$$scope={dirty:b,ctx:y}),n.$set(B);const W={};b&2&&(W.$$scope={dirty:b,ctx:y}),o.$set(W)},i(y){i||(U(s.$$.fragment,y),U(n.$$.fragment,y),U(o.$$.fragment,y),i=!0)},o(y){j(s.$$.fragment,y),j(n.$$.fragment,y),j(o.$$.fragment,y),i=!1},d(y){y&&(t(c),t(p)),h(s,y),h(n,y),h(o,y)}}}function Ko(g){let s,c="To deploy DeepSpeed on multiple GPUs, add the <code>--num_gpus</code> parameter. If you want to use all available GPUs, you don’t need to add <code>--num_gpus</code>. The example below uses 2 GPUs.",n,p,o;return p=new v({props:{code:"ZGVlcHNwZWVkJTIwLS1udW1fZ3B1cyUzRDIlMjBleGFtcGxlcyUyRnB5dG9yY2glMkZ0cmFuc2xhdGlvbiUyRnJ1bl90cmFuc2xhdGlvbi5weSUyMCU1QyUwQS0tZGVlcHNwZWVkJTIwdGVzdHMlMkZkZWVwc3BlZWQlMkZkc19jb25maWdfemVybzMuanNvbiUyMCU1QyUwQS0tbW9kZWxfbmFtZV9vcl9wYXRoJTIwZ29vZ2xlLXQ1JTJGdDUtc21hbGwlMjAtLXBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUyMDElMjAlNUMlMEEtLW91dHB1dF9kaXIlMjBvdXRwdXRfZGlyJTIwLS1vdmVyd3JpdGVfb3V0cHV0X2RpciUyMC0tZnAxNiUyMCU1QyUwQS0tZG9fdHJhaW4lMjAtLW1heF90cmFpbl9zYW1wbGVzJTIwNTAwJTIwLS1udW1fdHJhaW5fZXBvY2hzJTIwMSUyMCU1QyUwQS0tZGF0YXNldF9uYW1lJTIwd210MTYlMjAtLWRhdGFzZXRfY29uZmlnJTIwJTIycm8tZW4lMjIlMjAlNUMlMEEtLXNvdXJjZV9sYW5nJTIwZW4lMjAtLXRhcmdldF9sYW5nJTIwcm8=",highlighted:`deepspeed --num_gpus=2 examples/pytorch/translation/run_translation.py \\
--deepspeed tests/deepspeed/ds_config_zero3.json \\
--model_name_or_path google-t5/t5-small --per_device_train_batch_size 1 \\
--output_dir output_dir --overwrite_output_dir --fp16 \\
--do_train --max_train_samples 500 --num_train_epochs 1 \\
--dataset_name wmt16 --dataset_config <span class="hljs-string">&quot;ro-en&quot;</span> \\
--source_lang en --target_lang ro`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),d(p.$$.fragment)},l(i){s=u(i,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1crs7lp"&&(s.innerHTML=c),n=M(i),w(p.$$.fragment,i)},m(i,y){l(i,s,y),l(i,n,y),f(p,i,y),o=!0},p:S,i(i){o||(U(p.$$.fragment,i),o=!0)},o(i){j(p.$$.fragment,i),o=!1},d(i){i&&(t(s),t(n)),h(p,i)}}}function ei(g){let s,c='Set the <code>allgather_bucket_size</code> and <code>reduce_bucket_size</code> values to 2e8 in the <a href="#zero-configuration">ZeRO-2</a> configuration file to get better performance on a single GPU.';return{c(){s=m("p"),s.innerHTML=c},l(n){s=u(n,"P",{"data-svelte-h":!0}),T(s)!=="svelte-7bkscr"&&(s.innerHTML=c)},m(n,p){l(n,s,p)},p:S,d(n){n&&t(s)}}}function ti(g){let s,c="To deploy DeepSpeed on a single GPU, add the <code>--num_gpus</code> parameter. It isn’t necessary to explicitly set this value if you only have 1 GPU because DeepSpeed deploys all GPUs it can see on a given node.",n,p,o,i,y="DeepSpeed is still useful with just 1 GPU because you can:",b,I,B="<li>Offload some computations and memory to the CPU to make more GPU resources available to your model to use a larger batch size or fit a very large model that normally won’t fit.</li> <li>Minimize memory fragmentation with it’s smart GPU memory management system which also allows you to fit bigger models and data batches.</li>",W,G,R;return p=new v({props:{code:"ZGVlcHNwZWVkJTIwLS1udW1fZ3B1cyUzRDElMjBleGFtcGxlcyUyRnB5dG9yY2glMkZ0cmFuc2xhdGlvbiUyRnJ1bl90cmFuc2xhdGlvbi5weSUyMCU1QyUwQS0tZGVlcHNwZWVkJTIwdGVzdHMlMkZkZWVwc3BlZWQlMkZkc19jb25maWdfemVybzIuanNvbiUyMCU1QyUwQS0tbW9kZWxfbmFtZV9vcl9wYXRoJTIwZ29vZ2xlLXQ1JTJGdDUtc21hbGwlMjAtLXBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUyMDElMjAlNUMlMEEtLW91dHB1dF9kaXIlMjBvdXRwdXRfZGlyJTIwLS1vdmVyd3JpdGVfb3V0cHV0X2RpciUyMC0tZnAxNiUyMCU1QyUwQS0tZG9fdHJhaW4lMjAtLW1heF90cmFpbl9zYW1wbGVzJTIwNTAwJTIwLS1udW1fdHJhaW5fZXBvY2hzJTIwMSUyMCU1QyUwQS0tZGF0YXNldF9uYW1lJTIwd210MTYlMjAtLWRhdGFzZXRfY29uZmlnJTIwJTIycm8tZW4lMjIlMjAlNUMlMEEtLXNvdXJjZV9sYW5nJTIwZW4lMjAtLXRhcmdldF9sYW5nJTIwcm8=",highlighted:`deepspeed --num_gpus=1 examples/pytorch/translation/run_translation.py \\
--deepspeed tests/deepspeed/ds_config_zero2.json \\
--model_name_or_path google-t5/t5-small --per_device_train_batch_size 1 \\
--output_dir output_dir --overwrite_output_dir --fp16 \\
--do_train --max_train_samples 500 --num_train_epochs 1 \\
--dataset_name wmt16 --dataset_config <span class="hljs-string">&quot;ro-en&quot;</span> \\
--source_lang en --target_lang ro`,wrap:!1}}),G=new re({props:{$$slots:{default:[ei]},$$scope:{ctx:g}}}),{c(){s=m("p"),s.innerHTML=c,n=r(),d(p.$$.fragment),o=r(),i=m("p"),i.textContent=y,b=r(),I=m("ol"),I.innerHTML=B,W=r(),d(G.$$.fragment)},l(J){s=u(J,"P",{"data-svelte-h":!0}),T(s)!=="svelte-qfcnk"&&(s.innerHTML=c),n=M(J),w(p.$$.fragment,J),o=M(J),i=u(J,"P",{"data-svelte-h":!0}),T(i)!=="svelte-1nox3dx"&&(i.textContent=y),b=M(J),I=u(J,"OL",{"data-svelte-h":!0}),T(I)!=="svelte-1g5xefo"&&(I.innerHTML=B),W=M(J),w(G.$$.fragment,J)},m(J,_){l(J,s,_),l(J,n,_),f(p,J,_),l(J,o,_),l(J,i,_),l(J,b,_),l(J,I,_),l(J,W,_),f(G,J,_),R=!0},p(J,_){const k={};_&2&&(k.$$scope={dirty:_,ctx:J}),G.$set(k)},i(J){R||(U(p.$$.fragment,J),U(G.$$.fragment,J),R=!0)},o(J){j(p.$$.fragment,J),j(G.$$.fragment,J),R=!1},d(J){J&&(t(s),t(n),t(o),t(i),t(b),t(I),t(W)),h(p,J),h(G,J)}}}function li(g){let s,c,n,p;return s=new Y({props:{id:"deploy",option:"multi-GPU",$$slots:{default:[Ko]},$$scope:{ctx:g}}}),n=new Y({props:{id:"deploy",option:"single-GPU",$$slots:{default:[ti]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment)},l(o){w(s.$$.fragment,o),c=M(o),w(n.$$.fragment,o)},m(o,i){f(s,o,i),l(o,c,i),f(n,o,i),p=!0},p(o,i){const y={};i&2&&(y.$$scope={dirty:i,ctx:o}),s.$set(y);const b={};i&2&&(b.$$scope={dirty:i,ctx:o}),n.$set(b)},i(o){p||(U(s.$$.fragment,o),U(n.$$.fragment,o),p=!0)},o(o){j(s.$$.fragment,o),j(n.$$.fragment,o),p=!1},d(o){o&&t(c),h(s,o),h(n,o)}}}function si(g){let s,c='For <a href="https://pytorch.org/docs/stable/elastic/run.html" rel="nofollow">torchrun</a>, you have to ssh to each node and run the following command on both of them. The launcher waits until both nodes are synchronized before launching the training.',n,p,o;return p=new v({props:{code:"dG9yY2hydW4lMjAtLW5wcm9jX3Blcl9ub2RlJTNEOCUyMC0tbm5vZGUlM0QyJTIwLS1ub2RlX3JhbmslM0QwJTIwLS1tYXN0ZXJfYWRkciUzRGhvc3RuYW1lMSUyMCU1QyUwQS0tbWFzdGVyX3BvcnQlM0Q5OTAxJTIweW91cl9wcm9ncmFtLnB5JTIwJTNDbm9ybWFsJTIwY2wlMjBhcmdzJTNFJTIwLS1kZWVwc3BlZWQlMjBkc19jb25maWcuanNvbg==",highlighted:`torchrun --nproc_per_node=8 --nnode=2 --node_rank=0 --master_addr=hostname1 \\
--master_port=9901 your_program.py &lt;normal cl args&gt; --deepspeed ds_config.json`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),d(p.$$.fragment)},l(i){s=u(i,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1bt3z60"&&(s.innerHTML=c),n=M(i),w(p.$$.fragment,i)},m(i,y){l(i,s,y),l(i,n,y),f(p,i,y),o=!0},p:S,i(i){o||(U(p.$$.fragment,i),o=!0)},o(i){j(p.$$.fragment,i),o=!1},d(i){i&&(t(s),t(n)),h(p,i)}}}function ai(g){let s,c="For the <code>deepspeed</code> launcher, start by creating a <code>hostfile</code>.",n,p,o,i,y="Then you can launch the training with the following command. The <code>deepspeed</code> launcher automatically launches the command on both nodes at once.",b,I,B,W,G='Check out the <a href="https://www.deepspeed.ai/getting-started/#resource-configuration-multi-node" rel="nofollow">Resource Configuration (multi-node)</a> guide for more details about configuring multi-node compute resources.',R;return p=new v({props:{code:"aG9zdG5hbWUxJTIwc2xvdHMlM0Q4JTBBaG9zdG5hbWUyJTIwc2xvdHMlM0Q4",highlighted:`hostname1 slots=8
hostname2 slots=8`,wrap:!1}}),I=new v({props:{code:"ZGVlcHNwZWVkJTIwLS1udW1fZ3B1cyUyMDglMjAtLW51bV9ub2RlcyUyMDIlMjAtLWhvc3RmaWxlJTIwaG9zdGZpbGUlMjAtLW1hc3Rlcl9hZGRyJTIwaG9zdG5hbWUxJTIwLS1tYXN0ZXJfcG9ydCUzRDk5MDElMjAlNUMlMEF5b3VyX3Byb2dyYW0ucHklMjAlM0Nub3JtYWwlMjBjbCUyMGFyZ3MlM0UlMjAtLWRlZXBzcGVlZCUyMGRzX2NvbmZpZy5qc29u",highlighted:`deepspeed --num_gpus 8 --num_nodes 2 --hostfile hostfile --master_addr hostname1 --master_port=9901 \\
your_program.py &lt;normal cl args&gt; --deepspeed ds_config.json`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),d(p.$$.fragment),o=r(),i=m("p"),i.innerHTML=y,b=r(),d(I.$$.fragment),B=r(),W=m("p"),W.innerHTML=G},l(J){s=u(J,"P",{"data-svelte-h":!0}),T(s)!=="svelte-ijhrw"&&(s.innerHTML=c),n=M(J),w(p.$$.fragment,J),o=M(J),i=u(J,"P",{"data-svelte-h":!0}),T(i)!=="svelte-1vzgmv9"&&(i.innerHTML=y),b=M(J),w(I.$$.fragment,J),B=M(J),W=u(J,"P",{"data-svelte-h":!0}),T(W)!=="svelte-1ahoskn"&&(W.innerHTML=G)},m(J,_){l(J,s,_),l(J,n,_),f(p,J,_),l(J,o,_),l(J,i,_),l(J,b,_),f(I,J,_),l(J,B,_),l(J,W,_),R=!0},p:S,i(J){R||(U(p.$$.fragment,J),U(I.$$.fragment,J),R=!0)},o(J){j(p.$$.fragment,J),j(I.$$.fragment,J),R=!1},d(J){J&&(t(s),t(n),t(o),t(i),t(b),t(B),t(W)),h(p,J),h(I,J)}}}function ni(g){let s,c,n,p;return s=new Y({props:{id:"multinode",option:"torchrun",$$slots:{default:[si]},$$scope:{ctx:g}}}),n=new Y({props:{id:"multinode",option:"deepspeed",$$slots:{default:[ai]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment)},l(o){w(s.$$.fragment,o),c=M(o),w(n.$$.fragment,o)},m(o,i){f(s,o,i),l(o,c,i),f(n,o,i),p=!0},p(o,i){const y={};i&2&&(y.$$scope={dirty:i,ctx:o}),s.$set(y);const b={};i&2&&(b.$$scope={dirty:i,ctx:o}),n.$set(b)},i(o){p||(U(s.$$.fragment,o),U(n.$$.fragment,o),p=!0)},o(o){j(s.$$.fragment,o),j(n.$$.fragment,o),p=!1},d(o){o&&t(c),h(s,o),h(n,o)}}}function oi(g){let s,c='A model trained with ZeRO-2 saves the pytorch_model.bin weights in fp16. To save the model weights in fp16 for a model trained with ZeRO-3, you need to set <code>&quot;stage3_gather_16bit_weights_on_model_save&quot;: true</code> because the model weights are partitioned across multiple GPUs. Otherwise, the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> won’t save the weights in fp16 and it won’t create a pytorch_model.bin file. This is because DeepSpeed’s state_dict contains a placeholder instead of the real weights and you won’t be able to load them.',n,p,o;return p=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyemVyb19vcHRpbWl6YXRpb24lMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJzdGFnZTNfZ2F0aGVyXzE2Yml0X3dlaWdodHNfb25fbW9kZWxfc2F2ZSUyMiUzQSUyMHRydWUlMEElMjAlMjAlMjAlMjAlN0QlMEElN0Q=",highlighted:`{
    <span class="hljs-attr">&quot;zero_optimization&quot;:</span> {
        <span class="hljs-attr">&quot;stage3_gather_16bit_weights_on_model_save&quot;:</span> <span class="hljs-literal">true</span>
    }
}`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),d(p.$$.fragment)},l(i){s=u(i,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1kj3ivu"&&(s.innerHTML=c),n=M(i),w(p.$$.fragment,i)},m(i,y){l(i,s,y),l(i,n,y),f(p,i,y),o=!0},p:S,i(i){o||(U(p.$$.fragment,i),o=!0)},o(i){j(p.$$.fragment,i),o=!1},d(i){i&&(t(s),t(n)),h(p,i)}}}function ii(g){let s,c="Once <code>load_state_dict_from_zero_checkpoint</code> is run, the model is no longer usable in DeepSpeed in the context of the same application. You’ll need to initialize the DeepSpeed engine again since <code>model.load_state_dict(state_dict)</code> removes all the DeepSpeed magic from it. Only use this at the very end of training.";return{c(){s=m("p"),s.innerHTML=c},l(n){s=u(n,"P",{"data-svelte-h":!0}),T(s)!=="svelte-s2e8vm"&&(s.innerHTML=c)},m(n,p){l(n,s,p)},p:S,d(n){n&&t(s)}}}function ri(g){let s,c="Run <code>python zero_to_fp32.py -h</code> for more usage details. The script requires 2x the general RAM of the final fp32 weights.";return{c(){s=m("p"),s.innerHTML=c},l(n){s=u(n,"P",{"data-svelte-h":!0}),T(s)!=="svelte-m8616q"&&(s.innerHTML=c)},m(n,p){l(n,s,p)},p:S,d(n){n&&t(s)}}}function Mi(g){let s,c="The full precision weights shouldn’t be saved during training because it can require a lot of memory. It is usually best to save the fp32 weights offline after training is complete. But if you have a lot of free CPU memory, it is possible to save the fp32 weights during training. This section covers both online and offline approaches.",n,p,o,i,y="You must have saved at least one checkpoint to load the latest checkpoint as shown in the following:",b,I,B,W,G='If you’ve enabled the <code>--load_best_model_at_end</code> parameter to track the best checkpoint in <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>, you can finish training first and save the final model explicitly. Then you can reload it as shown below:',R,J,_,k,N,Z,A="You can also extract and load the state_dict of the fp32 weights:",V,H,D,P,F,x,K='DeepSpeed provides a zero_to_fp32.py script at the top-level of the checkpoint folder for extracting weights at any point. This is a standalone script and you don’t need a configuration file or <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>.',ee,E,te="For example, if your checkpoint folder looked like this:",Q,O,$,X,se="To reconstruct the fp32 weights from the DeepSpeed checkpoint (ZeRO-2 or ZeRO-3) subfolder <code>global_step1</code>, run the following command to create and consolidate the full fp32 weights from multiple GPUs into a single pytorch_model.bin file. The script automatically discovers the subfolder containing the checkpoint.",le,ae,oe,L,je;return p=new q({props:{title:"Online",local:"online",headingTag:"h3"}}),I=new v({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy50cmFpbmVyX3V0aWxzJTIwaW1wb3J0JTIwZ2V0X2xhc3RfY2hlY2twb2ludCUwQWZyb20lMjBkZWVwc3BlZWQudXRpbHMuemVyb190b19mcDMyJTIwaW1wb3J0JTIwbG9hZF9zdGF0ZV9kaWN0X2Zyb21femVyb19jaGVja3BvaW50JTBBJTBBY2hlY2twb2ludF9kaXIlMjAlM0QlMjBnZXRfbGFzdF9jaGVja3BvaW50KHRyYWluZXIuYXJncy5vdXRwdXRfZGlyKSUwQWZwMzJfbW9kZWwlMjAlM0QlMjBsb2FkX3N0YXRlX2RpY3RfZnJvbV96ZXJvX2NoZWNrcG9pbnQodHJhaW5lci5tb2RlbCUyQyUyMGNoZWNrcG9pbnRfZGlyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers.trainer_utils <span class="hljs-keyword">import</span> get_last_checkpoint
<span class="hljs-keyword">from</span> deepspeed.utils.zero_to_fp32 <span class="hljs-keyword">import</span> load_state_dict_from_zero_checkpoint

checkpoint_dir = get_last_checkpoint(trainer.args.output_dir)
fp32_model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)`,wrap:!1}}),J=new v({props:{code:"ZnJvbSUyMGRlZXBzcGVlZC51dGlscy56ZXJvX3RvX2ZwMzIlMjBpbXBvcnQlMjBsb2FkX3N0YXRlX2RpY3RfZnJvbV96ZXJvX2NoZWNrcG9pbnQlMEElMEFjaGVja3BvaW50X2RpciUyMCUzRCUyMG9zLnBhdGguam9pbih0cmFpbmVyLmFyZ3Mub3V0cHV0X2RpciUyQyUyMCUyMmNoZWNrcG9pbnQtZmluYWwlMjIpJTBBdHJhaW5lci5kZWVwc3BlZWQuc2F2ZV9jaGVja3BvaW50KGNoZWNrcG9pbnRfZGlyKSUwQWZwMzJfbW9kZWwlMjAlM0QlMjBsb2FkX3N0YXRlX2RpY3RfZnJvbV96ZXJvX2NoZWNrcG9pbnQodHJhaW5lci5tb2RlbCUyQyUyMGNoZWNrcG9pbnRfZGlyKQ==",highlighted:`<span class="hljs-keyword">from</span> deepspeed.utils.zero_to_fp32 <span class="hljs-keyword">import</span> load_state_dict_from_zero_checkpoint

checkpoint_dir = os.path.join(trainer.args.output_dir, <span class="hljs-string">&quot;checkpoint-final&quot;</span>)
trainer.deepspeed.save_checkpoint(checkpoint_dir)
fp32_model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)`,wrap:!1}}),k=new re({props:{$$slots:{default:[ii]},$$scope:{ctx:g}}}),H=new v({props:{code:"ZnJvbSUyMGRlZXBzcGVlZC51dGlscy56ZXJvX3RvX2ZwMzIlMjBpbXBvcnQlMjBnZXRfZnAzMl9zdGF0ZV9kaWN0X2Zyb21femVyb19jaGVja3BvaW50JTBBJTBBc3RhdGVfZGljdCUyMCUzRCUyMGdldF9mcDMyX3N0YXRlX2RpY3RfZnJvbV96ZXJvX2NoZWNrcG9pbnQoY2hlY2twb2ludF9kaXIpJTIwJTIwJTIzJTIwYWxyZWFkeSUyMG9uJTIwY3B1JTBBbW9kZWwlMjAlM0QlMjBtb2RlbC5jcHUoKSUwQW1vZGVsLmxvYWRfc3RhdGVfZGljdChzdGF0ZV9kaWN0KQ==",highlighted:`<span class="hljs-keyword">from</span> deepspeed.utils.zero_to_fp32 <span class="hljs-keyword">import</span> get_fp32_state_dict_from_zero_checkpoint

state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir)  <span class="hljs-comment"># already on cpu</span>
model = model.cpu()
model.load_state_dict(state_dict)`,wrap:!1}}),P=new q({props:{title:"Offline",local:"offline",headingTag:"h3"}}),O=new v({props:{code:"JTI0JTIwbHMlMjAtbCUyMG91dHB1dF9kaXIlMkZjaGVja3BvaW50LTElMkYlMEEtcnctcnctci0tJTIwMSUyMHN0YXMlMjBzdGFzJTIwMS40SyUyME1hciUyMDI3JTIwMjAlM0E0MiUyMGNvbmZpZy5qc29uJTBBZHJ3eHJ3eHIteCUyMDIlMjBzdGFzJTIwc3RhcyUyMDQuMEslMjBNYXIlMjAyNSUyMDE5JTNBNTIlMjBnbG9iYWxfc3RlcDElMkYlMEEtcnctcnctci0tJTIwMSUyMHN0YXMlMjBzdGFzJTIwJTIwJTIwMTIlMjBNYXIlMjAyNyUyMDEzJTNBMTYlMjBsYXRlc3QlMEEtcnctcnctci0tJTIwMSUyMHN0YXMlMjBzdGFzJTIwODI3SyUyME1hciUyMDI3JTIwMjAlM0E0MiUyMG9wdGltaXplci5wdCUwQS1ydy1ydy1yLS0lMjAxJTIwc3RhcyUyMHN0YXMlMjAyMzFNJTIwTWFyJTIwMjclMjAyMCUzQTQyJTIwcHl0b3JjaF9tb2RlbC5iaW4lMEEtcnctcnctci0tJTIwMSUyMHN0YXMlMjBzdGFzJTIwJTIwNjIzJTIwTWFyJTIwMjclMjAyMCUzQTQyJTIwc2NoZWR1bGVyLnB0JTBBLXJ3LXJ3LXItLSUyMDElMjBzdGFzJTIwc3RhcyUyMDEuOEslMjBNYXIlMjAyNyUyMDIwJTNBNDIlMjBzcGVjaWFsX3Rva2Vuc19tYXAuanNvbiUwQS1ydy1ydy1yLS0lMjAxJTIwc3RhcyUyMHN0YXMlMjA3NzRLJTIwTWFyJTIwMjclMjAyMCUzQTQyJTIwc3BpZWNlLm1vZGVsJTBBLXJ3LXJ3LXItLSUyMDElMjBzdGFzJTIwc3RhcyUyMDEuOUslMjBNYXIlMjAyNyUyMDIwJTNBNDIlMjB0b2tlbml6ZXJfY29uZmlnLmpzb24lMEEtcnctcnctci0tJTIwMSUyMHN0YXMlMjBzdGFzJTIwJTIwMzM5JTIwTWFyJTIwMjclMjAyMCUzQTQyJTIwdHJhaW5lcl9zdGF0ZS5qc29uJTBBLXJ3LXJ3LXItLSUyMDElMjBzdGFzJTIwc3RhcyUyMDIuM0slMjBNYXIlMjAyNyUyMDIwJTNBNDIlMjB0cmFpbmluZ19hcmdzLmJpbiUwQS1yd3hydy1yLS0lMjAxJTIwc3RhcyUyMHN0YXMlMjA1LjVLJTIwTWFyJTIwMjclMjAxMyUzQTE2JTIwemVyb190b19mcDMyLnB5Kg==",highlighted:`$ <span class="hljs-built_in">ls</span> -l output_dir/checkpoint-1/
-rw-rw-r-- 1 stas stas 1.4K Mar 27 20:42 config.json
drwxrwxr-x 2 stas stas 4.0K Mar 25 19:52 global_step1/
-rw-rw-r-- 1 stas stas   12 Mar 27 13:16 latest
-rw-rw-r-- 1 stas stas 827K Mar 27 20:42 optimizer.pt
-rw-rw-r-- 1 stas stas 231M Mar 27 20:42 pytorch_model.bin
-rw-rw-r-- 1 stas stas  623 Mar 27 20:42 scheduler.pt
-rw-rw-r-- 1 stas stas 1.8K Mar 27 20:42 special_tokens_map.json
-rw-rw-r-- 1 stas stas 774K Mar 27 20:42 spiece.model
-rw-rw-r-- 1 stas stas 1.9K Mar 27 20:42 tokenizer_config.json
-rw-rw-r-- 1 stas stas  339 Mar 27 20:42 trainer_state.json
-rw-rw-r-- 1 stas stas 2.3K Mar 27 20:42 training_args.bin
-rwxrw-r-- 1 stas stas 5.5K Mar 27 13:16 zero_to_fp32.py*`,wrap:!1}}),ae=new v({props:{code:"cHl0aG9uJTIwemVyb190b19mcDMyLnB5JTIwLiUyMHB5dG9yY2hfbW9kZWwuYmlu",highlighted:'python zero_to_fp32.py . pytorch_model.<span class="hljs-built_in">bin</span>',wrap:!1}}),L=new re({props:{$$slots:{default:[ri]},$$scope:{ctx:g}}}),{c(){s=m("p"),s.textContent=c,n=r(),d(p.$$.fragment),o=r(),i=m("p"),i.textContent=y,b=r(),d(I.$$.fragment),B=r(),W=m("p"),W.innerHTML=G,R=r(),d(J.$$.fragment),_=r(),d(k.$$.fragment),N=r(),Z=m("p"),Z.textContent=A,V=r(),d(H.$$.fragment),D=r(),d(P.$$.fragment),F=r(),x=m("p"),x.innerHTML=K,ee=r(),E=m("p"),E.textContent=te,Q=r(),d(O.$$.fragment),$=r(),X=m("p"),X.innerHTML=se,le=r(),d(ae.$$.fragment),oe=r(),d(L.$$.fragment)},l(C){s=u(C,"P",{"data-svelte-h":!0}),T(s)!=="svelte-idar67"&&(s.textContent=c),n=M(C),w(p.$$.fragment,C),o=M(C),i=u(C,"P",{"data-svelte-h":!0}),T(i)!=="svelte-130bwnm"&&(i.textContent=y),b=M(C),w(I.$$.fragment,C),B=M(C),W=u(C,"P",{"data-svelte-h":!0}),T(W)!=="svelte-fvrss9"&&(W.innerHTML=G),R=M(C),w(J.$$.fragment,C),_=M(C),w(k.$$.fragment,C),N=M(C),Z=u(C,"P",{"data-svelte-h":!0}),T(Z)!=="svelte-axrctj"&&(Z.textContent=A),V=M(C),w(H.$$.fragment,C),D=M(C),w(P.$$.fragment,C),F=M(C),x=u(C,"P",{"data-svelte-h":!0}),T(x)!=="svelte-1hs4224"&&(x.innerHTML=K),ee=M(C),E=u(C,"P",{"data-svelte-h":!0}),T(E)!=="svelte-1gq5knk"&&(E.textContent=te),Q=M(C),w(O.$$.fragment,C),$=M(C),X=u(C,"P",{"data-svelte-h":!0}),T(X)!=="svelte-10tjpq7"&&(X.innerHTML=se),le=M(C),w(ae.$$.fragment,C),oe=M(C),w(L.$$.fragment,C)},m(C,z){l(C,s,z),l(C,n,z),f(p,C,z),l(C,o,z),l(C,i,z),l(C,b,z),f(I,C,z),l(C,B,z),l(C,W,z),l(C,R,z),f(J,C,z),l(C,_,z),f(k,C,z),l(C,N,z),l(C,Z,z),l(C,V,z),f(H,C,z),l(C,D,z),f(P,C,z),l(C,F,z),l(C,x,z),l(C,ee,z),l(C,E,z),l(C,Q,z),f(O,C,z),l(C,$,z),l(C,X,z),l(C,le,z),f(ae,C,z),l(C,oe,z),f(L,C,z),je=!0},p(C,z){const he={};z&2&&(he.$$scope={dirty:z,ctx:C}),k.$set(he);const ne={};z&2&&(ne.$$scope={dirty:z,ctx:C}),L.$set(ne)},i(C){je||(U(p.$$.fragment,C),U(I.$$.fragment,C),U(J.$$.fragment,C),U(k.$$.fragment,C),U(H.$$.fragment,C),U(P.$$.fragment,C),U(O.$$.fragment,C),U(ae.$$.fragment,C),U(L.$$.fragment,C),je=!0)},o(C){j(p.$$.fragment,C),j(I.$$.fragment,C),j(J.$$.fragment,C),j(k.$$.fragment,C),j(H.$$.fragment,C),j(P.$$.fragment,C),j(O.$$.fragment,C),j(ae.$$.fragment,C),j(L.$$.fragment,C),je=!1},d(C){C&&(t(s),t(n),t(o),t(i),t(b),t(B),t(W),t(R),t(_),t(N),t(Z),t(V),t(D),t(F),t(x),t(ee),t(E),t(Q),t($),t(X),t(le),t(oe)),h(p,C),h(I,C),h(J,C),h(k,C),h(H,C),h(P,C),h(O,C),h(ae,C),h(L,C)}}}function pi(g){let s,c,n,p;return s=new Y({props:{id:"save",option:"fp16",$$slots:{default:[oi]},$$scope:{ctx:g}}}),n=new Y({props:{id:"save",option:"fp32",$$slots:{default:[Mi]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment)},l(o){w(s.$$.fragment,o),c=M(o),w(n.$$.fragment,o)},m(o,i){f(s,o,i),l(o,c,i),f(n,o,i),p=!0},p(o,i){const y={};i&2&&(y.$$scope={dirty:i,ctx:o}),s.$set(y);const b={};i&2&&(b.$$scope={dirty:i,ctx:o}),n.$set(b)},i(o){p||(U(s.$$.fragment,o),U(n.$$.fragment,o),p=!0)},o(o){j(s.$$.fragment,o),j(n.$$.fragment,o),p=!1},d(o){o&&t(c),h(s,o),h(n,o)}}}function yi(g){let s,c='If you want everything automatically taken care of for you, try using DeepSpeed with the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>! You’ll need to follow the <a href="https://www.deepspeed.ai/" rel="nofollow">DeepSpeed documentation</a>, and manually configure the parameter values in the config file (you can’t use the <code>&quot;auto&quot;</code> value).';return{c(){s=m("p"),s.innerHTML=c},l(n){s=u(n,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1ern0wt"&&(s.innerHTML=c)},m(n,p){l(n,s,p)},p:S,d(n){n&&t(s)}}}function ci(g){let s,c;return s=new v({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5pbnRlZ3JhdGlvbnMlMjBpbXBvcnQlMjBIZkRlZXBTcGVlZENvbmZpZyUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvTW9kZWwlMEFpbXBvcnQlMjBkZWVwc3BlZWQlMEElMEFkc19jb25maWclMjAlM0QlMjAlN0IuLi4lN0QlMjAlMjAlMjMlMjBkZWVwc3BlZWQlMjBjb25maWclMjBvYmplY3QlMjBvciUyMHBhdGglMjB0byUyMHRoZSUyMGZpbGUlMEElMjMlMjBtdXN0JTIwcnVuJTIwYmVmb3JlJTIwaW5zdGFudGlhdGluZyUyMHRoZSUyMG1vZGVsJTIwdG8lMjBkZXRlY3QlMjB6ZXJvJTIwMyUwQWRzY2hmJTIwJTNEJTIwSGZEZWVwU3BlZWRDb25maWcoZHNfY29uZmlnKSUyMCUyMCUyMyUyMGtlZXAlMjB0aGlzJTIwb2JqZWN0JTIwYWxpdmUlMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyb3BlbmFpLWNvbW11bml0eSUyRmdwdDIlMjIpJTBBZW5naW5lJTIwJTNEJTIwZGVlcHNwZWVkLmluaXRpYWxpemUobW9kZWwlM0Rtb2RlbCUyQyUyMGNvbmZpZ19wYXJhbXMlM0Rkc19jb25maWclMkMlMjAuLi4p",highlighted:`<span class="hljs-keyword">from</span> transformers.integrations <span class="hljs-keyword">import</span> HfDeepSpeedConfig
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModel
<span class="hljs-keyword">import</span> deepspeed

ds_config = {...}  <span class="hljs-comment"># deepspeed config object or path to the file</span>
<span class="hljs-comment"># must run before instantiating the model to detect zero 3</span>
dschf = HfDeepSpeedConfig(ds_config)  <span class="hljs-comment"># keep this object alive</span>
model = AutoModel.from_pretrained(<span class="hljs-string">&quot;openai-community/gpt2&quot;</span>)
engine = deepspeed.initialize(model=model, config_params=ds_config, ...)`,wrap:!1}}),{c(){d(s.$$.fragment)},l(n){w(s.$$.fragment,n)},m(n,p){f(s,n,p),c=!0},p:S,i(n){c||(U(s.$$.fragment,n),c=!0)},o(n){j(s.$$.fragment,n),c=!1},d(n){h(s,n)}}}function mi(g){let s,c="<code>HfDeepSpeedConfig</code> is not required for ZeRO-1 or ZeRO-2.",n,p,o;return p=new v({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5pbnRlZ3JhdGlvbnMlMjBpbXBvcnQlMjBIZkRlZXBTcGVlZENvbmZpZyUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvTW9kZWwlMkMlMjBBdXRvQ29uZmlnJTBBaW1wb3J0JTIwZGVlcHNwZWVkJTBBJTBBZHNfY29uZmlnJTIwJTNEJTIwJTdCLi4uJTdEJTIwJTIwJTIzJTIwZGVlcHNwZWVkJTIwY29uZmlnJTIwb2JqZWN0JTIwb3IlMjBwYXRoJTIwdG8lMjB0aGUlMjBmaWxlJTBBJTIzJTIwbXVzdCUyMHJ1biUyMGJlZm9yZSUyMGluc3RhbnRpYXRpbmclMjB0aGUlMjBtb2RlbCUyMHRvJTIwZGV0ZWN0JTIwemVybyUyMDMlMEFkc2NoZiUyMCUzRCUyMEhmRGVlcFNwZWVkQ29uZmlnKGRzX2NvbmZpZyklMjAlMjAlMjMlMjBrZWVwJTIwdGhpcyUyMG9iamVjdCUyMGFsaXZlJTBBY29uZmlnJTIwJTNEJTIwQXV0b0NvbmZpZy5mcm9tX3ByZXRyYWluZWQoJTIyb3BlbmFpLWNvbW11bml0eSUyRmdwdDIlMjIpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9jb25maWcoY29uZmlnKSUwQWVuZ2luZSUyMCUzRCUyMGRlZXBzcGVlZC5pbml0aWFsaXplKG1vZGVsJTNEbW9kZWwlMkMlMjBjb25maWdfcGFyYW1zJTNEZHNfY29uZmlnJTJDJTIwLi4uKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers.integrations <span class="hljs-keyword">import</span> HfDeepSpeedConfig
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModel, AutoConfig
<span class="hljs-keyword">import</span> deepspeed

ds_config = {...}  <span class="hljs-comment"># deepspeed config object or path to the file</span>
<span class="hljs-comment"># must run before instantiating the model to detect zero 3</span>
dschf = HfDeepSpeedConfig(ds_config)  <span class="hljs-comment"># keep this object alive</span>
config = AutoConfig.from_pretrained(<span class="hljs-string">&quot;openai-community/gpt2&quot;</span>)
model = AutoModel.from_config(config)
engine = deepspeed.initialize(model=model, config_params=ds_config, ...)`,wrap:!1}}),{c(){s=m("p"),s.innerHTML=c,n=r(),d(p.$$.fragment)},l(i){s=u(i,"P",{"data-svelte-h":!0}),T(s)!=="svelte-1i7ih4n"&&(s.innerHTML=c),n=M(i),w(p.$$.fragment,i)},m(i,y){l(i,s,y),l(i,n,y),f(p,i,y),o=!0},p:S,i(i){o||(U(p.$$.fragment,i),o=!0)},o(i){j(p.$$.fragment,i),o=!1},d(i){i&&(t(s),t(n)),h(p,i)}}}function ui(g){let s,c,n,p;return s=new Y({props:{id:"models",option:"pretrained model",$$slots:{default:[ci]},$$scope:{ctx:g}}}),n=new Y({props:{id:"models",option:"non-pretrained model",$$slots:{default:[mi]},$$scope:{ctx:g}}}),{c(){d(s.$$.fragment),c=r(),d(n.$$.fragment)},l(o){w(s.$$.fragment,o),c=M(o),w(n.$$.fragment,o)},m(o,i){f(s,o,i),l(o,c,i),f(n,o,i),p=!0},p(o,i){const y={};i&2&&(y.$$scope={dirty:i,ctx:o}),s.$set(y);const b={};i&2&&(b.$$scope={dirty:i,ctx:o}),n.$set(b)},i(o){p||(U(s.$$.fragment,o),U(n.$$.fragment,o),p=!0)},o(o){j(s.$$.fragment,o),j(n.$$.fragment,o),p=!1},d(o){o&&t(c),h(s,o),h(n,o)}}}function Ti(g){let s,c,n,p,o,i,y,b='<a href="https://www.deepspeed.ai/" rel="nofollow">DeepSpeed</a> is a PyTorch optimization library that makes distributed training memory-efficient and fast. At its core is the <a href="https://hf.co/papers/1910.02054" rel="nofollow">Zero Redundancy Optimizer (ZeRO)</a> which enables training large models at scale. ZeRO works in several stages:',I,B,W="<li>ZeRO-1, optimizer state partitioning across GPUs</li> <li>ZeRO-2, gradient partitioning across GPUs</li> <li>ZeRO-3, parameter partitioning across GPUs</li>",G,R,J='In GPU-limited environments, ZeRO also enables offloading optimizer memory and computation from the GPU to the CPU to fit and train really large models on a single GPU. DeepSpeed is integrated with the Transformers <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class for all ZeRO stages and offloading. All you need to do is provide a config file or you can use a provided template. For inference, Transformers support ZeRO-3 and offloading since it allows loading huge models.',_,k,N='This guide will walk you through how to deploy DeepSpeed training, the features you can enable, how to setup the config files for different ZeRO stages, offloading, inference, and using DeepSpeed without the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>.',Z,A,V,H,D='DeepSpeed is available to install from PyPI or Transformers (for more detailed installation options, take a look at the DeepSpeed <a href="https://www.deepspeed.ai/tutorials/advanced-install/" rel="nofollow">installation details</a> or the GitHub <a href="https://github.com/microsoft/deepspeed#installation" rel="nofollow">README</a>).',P,F,x,K,ee,E,te,Q,O='Before you begin, it is a good idea to check whether you have enough GPU and CPU memory to fit your model. DeepSpeed provides a tool for estimating the required CPU/GPU memory. For example, to estimate the memory requirements for the <a href="bigscience/T0_3B">bigscience/T0_3B</a> model on a single GPU:',$,X,se,le,ae="This means you either need a single 80GB GPU without CPU offload or a 8GB GPU and a ~60GB CPU to offload to (these are just the memory requirements for the parameters, optimizer states and gradients, and you’ll need a bit more for the CUDA kernels and activations). You should also consider the tradeoff between cost and speed because it’ll be cheaper to rent or buy a smaller GPU but it’ll take longer to train your model.",oe,L,je="If you have enough GPU memory make sure you disable CPU/NVMe offload to make everything faster.",C,z,he,ne,Qa="After you’ve installed DeepSpeed and have a better idea of your memory requirements, the next step is selecting a ZeRO stage to use. In order of fastest and most memory-efficient:",$l,Ie,Ha="<thead><tr><th>Fastest</th> <th>Memory efficient</th></tr></thead> <tbody><tr><td>ZeRO-1</td> <td>ZeRO-3 + offload</td></tr> <tr><td>ZeRO-2</td> <td>ZeRO-3</td></tr> <tr><td>ZeRO-2 + offload</td> <td>ZeRO-2 + offload</td></tr> <tr><td>ZeRO-3</td> <td>ZeRO-2</td></tr> <tr><td>ZeRO-3 + offload</td> <td>ZeRO-1</td></tr></tbody>",Al,Ce,xa="To find what works best for you, start with the fastest approach and if you run out of memory, try the next stage which is slower but more memory efficient. Feel free to work in whichever direction you prefer (starting with the most memory efficient or fastest) to discover the appropriate balance between speed and memory usage.",Bl,be,Ya="A general process you can use is (start with batch size of 1):",_l,ge,Fa='<li>enable gradient checkpointing</li> <li>try ZeRO-2</li> <li>try ZeRO-2 and offload the optimizer</li> <li>try ZeRO-3</li> <li>try ZeRO-3 and offload parameters to the CPU</li> <li>try ZeRO-3 and offload parameters and the optimizer to the CPU</li> <li>try lowering various default values like a narrower search beam if you’re using the <a href="/docs/transformers/pr_30530/en/main_classes/text_generation#transformers.GenerationMixin.generate">generate()</a> method</li> <li>try mixed half-precision (fp16 on older GPU architectures and bf16 on Ampere) over full-precision weights</li> <li>add more hardware if possible or enable Infinity to offload parameters and the optimizer to a NVMe</li> <li>once you’re not running out of memory, measure effective throughput and then try to increase the batch size as large as you can to maximize GPU efficiency</li> <li>lastly, try to optimize your training setup by disabling some offload features or use a faster ZeRO stage and increasing/decreasing the batch size to find the best tradeoff between speed and memory usage</li>',Zl,$e,vl,Ae,La='DeepSpeed works with the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class by way of a config file containing all the parameters for configuring how you want setup your training run. When you execute your training script, DeepSpeed logs the configuration it received from <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> to the console so you can see exactly what configuration was used.',Gl,Me,Wl,Be,Da='The DeepSpeed configuration file is passed as a path to a JSON file if you’re training from the command line interface or as a nested <code>dict</code> object if you’re using the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> in a notebook setting.',Rl,pe,zl,_e,Xl,Ze,Pa="There are three types of configuration parameters:",kl,ve,Oa='<li><p>Some of the configuration parameters are shared by <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> and DeepSpeed, and it can be difficult to identify errors when there are conflicting definitions. To make it easier, these shared configuration parameters are configured from the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> command line arguments.</p></li> <li><p>Some configuration parameters that are automatically derived from the model configuration so you don’t need to manually adjust these values. The <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> uses a configuration value <code>auto</code> to determine set the most correct or efficient value. You could set your own configuration parameters explicitly, but you must take care to ensure the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> arguments and DeepSpeed configuration parameters agree. Mismatches may cause the training to fail in very difficult to detect ways!</p></li> <li><p>Some configuration parameters specific to DeepSpeed only which need to be manually set based on your training needs.</p></li>',ql,Ge,Ka='You could also modify the DeepSpeed configuration and edit <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> from it:',Nl,We,en='<li>Create or load a DeepSpeed configuration to use as the main configuration</li> <li>Create a <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> object based on these DeepSpeed configuration values</li>',Vl,Re,tn='Some values, such as <code>scheduler.params.total_num_steps</code> are calculated by the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> during training.',Sl,ze,El,Xe,ln='There are three configurations, each corresponding to a different ZeRO stage. Stage 1 is not as interesting for scalability, and this guide focuses on stages 2 and 3. The <code>zero_optimization</code> configuration contains all the options for what to enable and how to configure them. For a more detailed explanation of each parameter, take a look at the <a href="https://www.deepspeed.ai/docs/config-json/" rel="nofollow">DeepSpeed Configuration JSON</a> reference.',Ql,ye,Hl,ke,sn='The following configurations must be setup with DeepSpeed because the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> doesn’t provide equivalent command line arguments.',xl,ce,Yl,qe,Fl,Ne,an='<a href="https://hf.co/papers/2104.07857" rel="nofollow">ZeRO-Infinity</a> allows offloading model states to the CPU and/or NVMe to save even more memory. Smart partitioning and tiling algorithms allow each GPU to send and receive very small amounts of data during offloading such that a modern NVMe can fit an even larger total memory pool than is available to your training process. ZeRO-Infinity requires ZeRO-3.',Ll,Ve,nn='Depending on the CPU and/or NVMe memory available, you can offload both the <a href="https://www.deepspeed.ai/docs/config-json/#optimizer-offloading" rel="nofollow">optimizer states</a> and <a href="https://www.deepspeed.ai/docs/config-json/#parameter-offloading" rel="nofollow">parameters</a>, just one of them, or none. You should also make sure the <code>nvme_path</code> is pointing to an NVMe device, because while it still works with a normal hard drive or solid state drive, it’ll be significantly slower. With a modern NVMe, you can expect peak transfer speeds of ~3.5GB/s for read and ~3GB/s for write operations. Lastly, <a href="https://github.com/microsoft/DeepSpeed/issues/998" rel="nofollow">run a benchmark</a> on your training setup to determine the optimal <code>aio</code> configuration.',Dl,Se,on="The example ZeRO-3/Infinity configuration file below sets most of the parameter values to <code>auto</code>, but you could also manually add these values.",Pl,Ee,Ol,Qe,Kl,He,rn="There are a number of important parameters to specify in the DeepSpeed configuration file which are briefly described in this section.",es,xe,ts,Ye,Mn="Activation and gradient checkpointing trades speed for more GPU memory which allows you to overcome scenarios where your GPU is out of memory or to increase your batch size for better performance. To enable this feature:",ls,Fe,pn='<li>For a Hugging Face model, set <code>model.gradient_checkpointing_enable()</code> or <code>--gradient_checkpointing</code> in the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>.</li> <li>For a non-Hugging Face model, use the DeepSpeed <a href="https://deepspeed.readthedocs.io/en/latest/activation-checkpointing.html" rel="nofollow">Activation Checkpointing API</a>. You could also replace the Transformers modeling code and replace <code>torch.utils.checkpoint</code> with the DeepSpeed API. This approach is more flexible because you can offload the forward activations to the CPU memory instead of recalculating them.</li>',ss,Le,as,De,yn="DeepSpeed and Transformers optimizer and scheduler can be mixed and matched as long as you don’t enable <code>offload_optimizer</code>. When <code>offload_optimizer</code> is enabled, you could use a non-DeepSpeed optimizer (except for LAMB) as long as it has both a CPU and GPU implementation.",ns,me,os,ue,is,Pe,rs,Oe,cn="Deepspeed supports fp32, fp16, and bf16 mixed precision.",Ms,Te,ps,Ke,ys,et,mn='The batch size can be auto-configured or explicitly set. If you choose to use the <code>&quot;auto&quot;</code> option, <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> sets <code>train_micro_batch_size_per_gpu</code> to the value of args.<code>per_device_train_batch_size</code> and <code>train_batch_size</code> to <code>args.world_size * args.per_device_train_batch_size * args.gradient_accumulation_steps</code>.',cs,tt,ms,lt,us,st,un='Gradient accumulation can be auto-configured or explicitly set. If you choose to use the <code>&quot;auto&quot;</code> option, <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> sets it to the value of <code>args.gradient_accumulation_steps</code>.',Ts,at,Js,nt,ds,ot,Tn='Gradient clipping can be auto-configured or explicitly set. If you choose to use the <code>&quot;auto&quot;</code> option, <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> sets it to the value of <code>args.max_grad_norm</code>.',ws,it,fs,rt,Us,Mt,Jn="For communication collectives like reduction, gathering and scattering operations, a separate data type is used.",js,pt,dn="All gather and scatter operations are performed in the same data type the data is in. For example, if you’re training with bf16, the data is also gathered in bf16 because gathering is a non-lossy operation.",hs,yt,wn="Reduce operations are lossy, for example when gradients are averaged across multiple GPUs. When the communication is done in fp16 or bf16, it is more likely to be lossy because adding multiple numbers in low precision isn’t exact. This is especially the case with bf16 which has a lower precision than fp16. For this reason, fp16 is the default for reduction operations because the loss is minimal when averaging gradients.",Is,ct,fn="You can choose the communication data type by setting the <code>communication_data_type</code> parameter in the config file. For example, choosing fp32 adds a small amount of overhead but ensures the reduction operation is accumulated in fp32 and when it is ready, it is downcasted to whichever half-precision dtype you’re training in.",Cs,mt,bs,ut,gs,Tt,Un='DeepSpeed can be deployed by different launchers such as <a href="https://pytorch.org/docs/stable/elastic/run.html" rel="nofollow">torchrun</a>, the <code>deepspeed</code> launcher, or <a href="https://huggingface.co/docs/accelerate/basic_tutorials/launch#using-accelerate-launch" rel="nofollow">Accelerate</a>. To deploy, add <code>--deepspeed ds_config.json</code> to the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> command line. It’s recommended to use DeepSpeed’s <a href="https://deepspeed.readthedocs.io/en/latest/initialize.html#argument-parsing" rel="nofollow"><code>add_config_arguments</code></a> utility to add any necessary command line arguments to your code.',$s,Jt,jn='This guide will show you how to deploy DeepSpeed with the <code>deepspeed</code> launcher for different training setups. You can check out this <a href="https://github.com/huggingface/transformers/issues/8771#issuecomment-759248400" rel="nofollow">post</a> for more practical usage examples.',As,Je,Bs,dt,_s,wt,hn="A node is one or more GPUs for running a workload. A more powerful setup is a multi-node setup which can be launched with the <code>deepspeed</code> launcher. For this guide, let’s assume there are two nodes with 8 GPUs each. The first node can be accessed <code>ssh hostname1</code> and the second node with <code>ssh hostname2</code>. Both nodes must be able to communicate with each other locally over ssh without a password.",Zs,ft,In='By default, DeepSpeed expects your multi-node environment to use a shared storage. If this is not the case and each node can only see the local filesystem, you need to adjust the config file to include a <a href="https://www.deepspeed.ai/docs/config-json/#checkpoint-options" rel="nofollow"><code>checkpoint</code></a> to allow loading without access to a shared filesystem:',vs,Ut,Gs,jt,Cn='You could also use the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>’s <code>--save_on_each_node</code> argument to automatically add the above <code>checkpoint</code> to your config.',Ws,de,Rs,ht,zs,It,bn="In a SLURM environment, you’ll need to adapt your SLURM script to your specific SLURM environment. An example SLURM script may look like:",Xs,Ct,ks,bt,gn="Then you can schedule your multi-node deployment with the following command which launches training simultaneously on all nodes.",qs,gt,Ns,$t,Vs,At,$n="The <code>deepspeed</code> launcher doesn’t support deployment from a notebook so you’ll need to emulate the distributed environment. However, this only works for 1 GPU. If you want to use more than 1 GPU, you must use a multi-process environment for DeepSpeed to work. This means you have to use the <code>deepspeed</code> launcher which can’t be emulated as shown here.",Ss,Bt,Es,_t,An="If you want to create the config file on the fly in the notebook in the current directory, you could have a dedicated cell.",Qs,Zt,Hs,vt,Bn="If the training script is in a file and not in a notebook cell, you can launch <code>deepspeed</code> normally from the shell in a notebook cell. For example, to launch <code>run_translation.py</code>:",xs,Gt,Ys,Wt,_n="You could also use <code>%%bash</code> magic and write multi-line code to run the shell program, but you won’t be able to view the logs until training is complete. With <code>%%bash</code> magic, you don’t need to emulate a distributed environment.",Fs,Rt,Ls,zt,Ds,Xt,Zn="DeepSpeed stores the main full precision fp32 weights in custom checkpoint optimizer files (the glob pattern looks like <code>global_step*/*optim_states.pt</code>) and are saved under the normal checkpoint.",Ps,we,Os,kt,Ks,qt,vn='<a href="https://www.deepspeed.ai/2022/09/09/zero-inference.html" rel="nofollow">ZeRO Inference</a> places the model weights in CPU or NVMe memory to avoid burdening the GPU which makes it possible to run inference with huge models on a GPU. Inference doesn’t require any large additional amounts of memory for the optimizer states and gradients so you can fit much larger batches and/or sequence lengths on the same hardware.',ea,Nt,Gn='ZeRO Inference shares the same configuration file as <a href="#zero-configuration">ZeRO-3</a>, and ZeRO-2 and ZeRO-1 configs won’t work because they don’t provide any benefits for inference.',ta,Vt,Wn='To run ZeRO Inference, pass your usual training arguments to the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> class and add the <code>--do_eval</code> argument.',la,St,sa,Et,aa,Qt,Rn='DeepSpeed also works with Transformers without the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class. This is handled by the <code>HfDeepSpeedConfig</code> which only takes care of gathering ZeRO-3 parameters and splitting a model across multiple GPUs when you call <a href="/docs/transformers/pr_30530/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a>.',na,fe,oa,Ht,zn="To efficiently deploy ZeRO-3, you must instantiate the <code>HfDeepSpeedConfig</code> object before the model and keep that object alive:",ia,Ue,ra,xt,Ma,Yt,Xn='To run ZeRO Inference without the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> in cases where you can’t fit a model onto a single GPU, try using additional GPUs or/and offloading to CPU memory. The important nuance to understand here is that the way ZeRO is designed, you can process different inputs on different GPUs in parallel.',pa,Ft,kn="Make sure to:",ya,Lt,qn="<li>disable CPU offload if you have enough GPU memory (since it slows things down).</li> <li>enable bf16 if you have an Ampere or newer GPU to make things faster. If you don’t have one of these GPUs, you may enable fp16 as long as you don’t use a model pretrained in bf16 (T5 models) because it may lead to an overflow error.</li>",ca,Dt,Nn='Take a look at the following script to get a better idea of how to run ZeRO Inference without the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> on a model that won’t fit on a single GPU.',ma,Pt,ua,Ot,Vn="Save the script as t0.py and launch it:",Ta,Kt,Ja,el,Sn="This is a very basic example and you’ll want to adapt it to your use case.",da,tl,wa,ll,En='Using multiple GPUs with ZeRO-3 for generation requires synchronizing the GPUs by setting <code>synced_gpus=True</code> in the <a href="/docs/transformers/pr_30530/en/main_classes/text_generation#transformers.GenerationMixin.generate">generate()</a> method. Otherwise, if one GPU is finished generating before another one, the whole system hangs because the remaining GPUs haven’t received the weight shard from the GPU that finished first.',fa,sl,Qn="For Transformers&gt;=4.28, if <code>synced_gpus</code> is automatically set to <code>True</code> if multiple GPUs are detected during generation.",Ua,al,ja,nl,Hn='When you encounter an issue, you should consider whether DeepSpeed is the cause of the problem because often it isn’t (unless it’s super obviously and you can see DeepSpeed modules in the exception)! The first step should be to retry your setup without DeepSpeed, and if the problem persists, then you can report the issue. If the issue is a core DeepSpeed problem and unrelated to the Transformers integration, open an Issue on the <a href="https://github.com/microsoft/DeepSpeed" rel="nofollow">DeepSpeed repository</a>.',ha,ol,xn="For issues related to the Transformers integration, please provide the following information:",Ia,il,Yn='<li><p>the full DeepSpeed config file</p></li> <li><p>the command line arguments of the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>, or <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> arguments if you’re scripting the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> setup yourself (don’t dump the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> which has dozens of irrelevant entries)</p></li> <li><p>the outputs of:</p></li>',Ca,rl,ba,Ml,Fn="<li><p>a link to a Google Colab notebook to reproduce the issue</p></li> <li><p>if impossible, a standard and non-custom dataset we can use and also try to use an existing example to reproduce the issue with</p></li>",ga,pl,Ln="The following sections provide a guide for resolving two of the most common issues.",$a,yl,Aa,cl,Dn="When the DeepSpeed process is killed during launch without a traceback, that usually means the program tried to allocate more CPU memory than your system has or your process tried to allocate more CPU memory than allowed leading the OS kernel to terminate the process. In this case, check whether your configuration file has either <code>offload_optimizer</code>, <code>offload_param</code> or both configured to offload to the CPU.",Ba,ml,Pn='If you have NVMe and ZeRO-3 setup, experiment with offloading to the NVMe (<a href="https://deepspeed.readthedocs.io/en/latest/memory.html" rel="nofollow">estimate</a> the memory requirements for your model).',_a,ul,Za,Tl,On="NaN loss often occurs when a model is pretrained in bf16 and then you try to use it with fp16 (especially relevant for TPU trained models). To resolve this, use fp32 or bf16 if your hardware supports it (TPU, Ampere GPUs or newer).",va,Jl,Kn="The other issue may be related to using fp16. For example, if this is your fp16 configuration:",Ga,dl,Wa,wl,eo="You might see the following <code>OVERFLOW!</code> messages in the logs:",Ra,fl,za,Ul,to="This means the DeepSpeed loss scaler is unable to find a scaling coefficient to overcome loss overflow. To fix it, try a higher <code>initial_scale_power</code> value (32 usually works).",Xa,jl,ka,hl,lo='DeepSpeed ZeRO is a powerful technology for training and loading very large models for inference with limited GPU resources, making it more accessible to everyone. To learn more about DeepSpeed, feel free to read the <a href="https://www.microsoft.com/en-us/research/search/?q=deepspeed" rel="nofollow">blog posts</a>, <a href="https://www.deepspeed.ai/getting-started/" rel="nofollow">documentation</a>, and <a href="https://github.com/microsoft/deepspeed" rel="nofollow">GitHub repository</a>.',qa,Il,so="The following papers are also a great resource for learning more about ZeRO:",Na,Cl,ao='<li><a href="https://hf.co/papers/1910.02054" rel="nofollow">ZeRO: Memory Optimizations Toward Training Trillion Parameter Models</a></li> <li><a href="https://hf.co/papers/2101.06840" rel="nofollow">ZeRO-Offload: Democratizing Billion-Scale Model Training</a></li> <li><a href="https://hf.co/papers/2104.07857" rel="nofollow">ZeRO-Infinity: Breaking the GPU Memory Wall for Extreme Scale Deep Learning</a></li>',Va,bl,Sa,gl,Ea;return o=new q({props:{title:"DeepSpeed",local:"deepspeed",headingTag:"h1"}}),A=new q({props:{title:"Installation",local:"installation",headingTag:"h2"}}),F=new re({props:{$$slots:{default:[Zo]},$$scope:{ctx:g}}}),K=new ie({props:{id:"install",options:["PyPI","Transformers"],$$slots:{default:[Wo]},$$scope:{ctx:g}}}),E=new q({props:{title:"Memory requirements",local:"memory-requirements",headingTag:"h2"}}),X=new v({props:{code:"JTI0JTIwcHl0aG9uJTIwLWMlMjAnZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbCUzQiUyMCU1QyUwQWZyb20lMjBkZWVwc3BlZWQucnVudGltZS56ZXJvLnN0YWdlMyUyMGltcG9ydCUyMGVzdGltYXRlX3plcm8zX21vZGVsX3N0YXRlc19tZW1fbmVlZHNfYWxsX2xpdmUlM0IlMjAlNUMlMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyYmlnc2NpZW5jZSUyRlQwXzNCJTIyKSUzQiUyMCU1QyUwQWVzdGltYXRlX3plcm8zX21vZGVsX3N0YXRlc19tZW1fbmVlZHNfYWxsX2xpdmUobW9kZWwlMkMlMjBudW1fZ3B1c19wZXJfbm9kZSUzRDElMkMlMjBudW1fbm9kZXMlM0QxKSclMEElNUIuLi4lNUQlMEFFc3RpbWF0ZWQlMjBtZW1vcnklMjBuZWVkZWQlMjBmb3IlMjBwYXJhbXMlMkMlMjBvcHRpbSUyMHN0YXRlcyUyMGFuZCUyMGdyYWRpZW50cyUyMGZvciUyMGElM0ElMEFIVyUzQSUyMFNldHVwJTIwd2l0aCUyMDElMjBub2RlJTJDJTIwMSUyMEdQVSUyMHBlciUyMG5vZGUuJTBBU1clM0ElMjBNb2RlbCUyMHdpdGglMjAyNzgzTSUyMHRvdGFsJTIwcGFyYW1zJTJDJTIwNjVNJTIwbGFyZ2VzdCUyMGxheWVyJTIwcGFyYW1zLiUwQSUyMCUyMHBlciUyMENQVSUyMCUyMCU3QyUyMCUyMHBlciUyMEdQVSUyMCU3QyUyMCUyMCUyME9wdGlvbnMlMEElMjAlMjAlMjA3MC4wMEdCJTIwJTdDJTIwJTIwJTIwMC4yNUdCJTIwJTdDJTIwb2ZmbG9hZF9wYXJhbSUzRGNwdSUyMCUyQyUyMG9mZmxvYWRfb3B0aW1pemVyJTNEY3B1JTIwJTJDJTIwemVyb19pbml0JTNEMSUwQSUyMCUyMCUyMDcwLjAwR0IlMjAlN0MlMjAlMjAlMjAwLjI1R0IlMjAlN0MlMjBvZmZsb2FkX3BhcmFtJTNEY3B1JTIwJTJDJTIwb2ZmbG9hZF9vcHRpbWl6ZXIlM0RjcHUlMjAlMkMlMjB6ZXJvX2luaXQlM0QwJTBBJTIwJTIwJTIwNjIuMjNHQiUyMCU3QyUyMCUyMCUyMDUuNDNHQiUyMCU3QyUyMG9mZmxvYWRfcGFyYW0lM0Rub25lJTJDJTIwb2ZmbG9hZF9vcHRpbWl6ZXIlM0RjcHUlMjAlMkMlMjB6ZXJvX2luaXQlM0QxJTBBJTIwJTIwJTIwNjIuMjNHQiUyMCU3QyUyMCUyMCUyMDUuNDNHQiUyMCU3QyUyMG9mZmxvYWRfcGFyYW0lM0Rub25lJTJDJTIwb2ZmbG9hZF9vcHRpbWl6ZXIlM0RjcHUlMjAlMkMlMjB6ZXJvX2luaXQlM0QwJTBBJTIwJTIwJTIwJTIwMC4zN0dCJTIwJTdDJTIwJTIwNDYuOTFHQiUyMCU3QyUyMG9mZmxvYWRfcGFyYW0lM0Rub25lJTJDJTIwb2ZmbG9hZF9vcHRpbWl6ZXIlM0Rub25lJTJDJTIwemVyb19pbml0JTNEMSUwQSUyMCUyMCUyMDE1LjU2R0IlMjAlN0MlMjAlMjA0Ni45MUdCJTIwJTdDJTIwb2ZmbG9hZF9wYXJhbSUzRG5vbmUlMkMlMjBvZmZsb2FkX29wdGltaXplciUzRG5vbmUlMkMlMjB6ZXJvX2luaXQlM0Qw",highlighted:`$ python -c <span class="hljs-string">&#x27;from transformers import AutoModel; \\
from deepspeed.runtime.zero.stage3 import estimate_zero3_model_states_mem_needs_all_live; \\
model = AutoModel.from_pretrained(&quot;bigscience/T0_3B&quot;); \\
estimate_zero3_model_states_mem_needs_all_live(model, num_gpus_per_node=1, num_nodes=1)&#x27;</span>
[...]
Estimated memory needed <span class="hljs-keyword">for</span> params, optim states and gradients <span class="hljs-keyword">for</span> a:
HW: Setup with 1 node, 1 GPU per node.
SW: Model with 2783M total params, 65M largest layer params.
  per CPU  |  per GPU |   Options
   70.00GB |   0.25GB | offload_param=cpu , offload_optimizer=cpu , zero_init=1
   70.00GB |   0.25GB | offload_param=cpu , offload_optimizer=cpu , zero_init=0
   62.23GB |   5.43GB | offload_param=none, offload_optimizer=cpu , zero_init=1
   62.23GB |   5.43GB | offload_param=none, offload_optimizer=cpu , zero_init=0
    0.37GB |  46.91GB | offload_param=none, offload_optimizer=none, zero_init=1
   15.56GB |  46.91GB | offload_param=none, offload_optimizer=none, zero_init=0`,wrap:!1}}),z=new q({props:{title:"Select a ZeRO stage",local:"select-a-zero-stage",headingTag:"h2"}}),$e=new q({props:{title:"DeepSpeed configuration file",local:"deepspeed-configuration-file",headingTag:"h2"}}),Me=new re({props:{$$slots:{default:[Ro]},$$scope:{ctx:g}}}),pe=new ie({props:{id:"pass-config",options:["path to file","nested dict"],$$slots:{default:[ko]},$$scope:{ctx:g}}}),_e=new q({props:{title:"DeepSpeed and Trainer parameters",local:"deepspeed-and-trainer-parameters",headingTag:"h3"}}),ze=new q({props:{title:"ZeRO configuration",local:"zero-configuration",headingTag:"h3"}}),ye=new re({props:{warning:!0,$$slots:{default:[qo]},$$scope:{ctx:g}}}),ce=new ie({props:{id:"zero-config",options:["ZeRO-1","ZeRO-2","ZeRO-3"],$$slots:{default:[Qo]},$$scope:{ctx:g}}}),qe=new q({props:{title:"NVMe configuration",local:"nvme-configuration",headingTag:"h3"}}),Ee=new v({props:{code:" ",highlighted:`{
    <span class="hljs-attr">&quot;fp16&quot;:</span> {
        <span class="hljs-attr">&quot;enabled&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;loss_scale&quot;:</span> <span class="hljs-number">0</span>,
        <span class="hljs-attr">&quot;loss_scale_window&quot;:</span> <span class="hljs-number">1000</span>,
        <span class="hljs-attr">&quot;initial_scale_power&quot;:</span> <span class="hljs-number">16</span>,
        <span class="hljs-attr">&quot;hysteresis&quot;:</span> <span class="hljs-number">2</span>,
        <span class="hljs-attr">&quot;min_loss_scale&quot;:</span> <span class="hljs-number">1</span>
    },

    <span class="hljs-attr">&quot;optimizer&quot;:</span> {
        <span class="hljs-attr">&quot;type&quot;:</span> <span class="hljs-string">&quot;AdamW&quot;</span>,
        <span class="hljs-attr">&quot;params&quot;:</span> {
            <span class="hljs-attr">&quot;lr&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-attr">&quot;betas&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-attr">&quot;eps&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-attr">&quot;weight_decay&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
        }
    },

    <span class="hljs-attr">&quot;scheduler&quot;:</span> {
        <span class="hljs-attr">&quot;type&quot;:</span> <span class="hljs-string">&quot;WarmupLR&quot;</span>,
        <span class="hljs-attr">&quot;params&quot;:</span> {
            <span class="hljs-attr">&quot;warmup_min_lr&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-attr">&quot;warmup_max_lr&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-attr">&quot;warmup_num_steps&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
        }
    },

    <span class="hljs-attr">&quot;zero_optimization&quot;:</span> {
        <span class="hljs-attr">&quot;stage&quot;:</span> <span class="hljs-number">3</span>,
        <span class="hljs-attr">&quot;offload_optimizer&quot;:</span> {
            <span class="hljs-attr">&quot;device&quot;:</span> <span class="hljs-string">&quot;nvme&quot;</span>,
            <span class="hljs-attr">&quot;nvme_path&quot;:</span> <span class="hljs-string">&quot;/local_nvme&quot;</span>,
            <span class="hljs-attr">&quot;pin_memory&quot;:</span> <span class="hljs-literal">true</span>,
            <span class="hljs-attr">&quot;buffer_count&quot;:</span> <span class="hljs-number">4</span>,
            <span class="hljs-attr">&quot;fast_init&quot;:</span> <span class="hljs-literal">false</span>
        },
        <span class="hljs-attr">&quot;offload_param&quot;:</span> {
            <span class="hljs-attr">&quot;device&quot;:</span> <span class="hljs-string">&quot;nvme&quot;</span>,
            <span class="hljs-attr">&quot;nvme_path&quot;:</span> <span class="hljs-string">&quot;/local_nvme&quot;</span>,
            <span class="hljs-attr">&quot;pin_memory&quot;:</span> <span class="hljs-literal">true</span>,
            <span class="hljs-attr">&quot;buffer_count&quot;:</span> <span class="hljs-number">5</span>,
            <span class="hljs-attr">&quot;buffer_size&quot;:</span> <span class="hljs-number">1e8</span>,
            <span class="hljs-attr">&quot;max_in_cpu&quot;:</span> <span class="hljs-number">1e9</span>
        },
        <span class="hljs-attr">&quot;aio&quot;:</span> {
            <span class="hljs-attr">&quot;block_size&quot;:</span> <span class="hljs-number">262144</span>,
            <span class="hljs-attr">&quot;queue_depth&quot;:</span> <span class="hljs-number">32</span>,
            <span class="hljs-attr">&quot;thread_count&quot;:</span> <span class="hljs-number">1</span>,
            <span class="hljs-attr">&quot;single_submit&quot;:</span> <span class="hljs-literal">false</span>,
            <span class="hljs-attr">&quot;overlap_events&quot;:</span> <span class="hljs-literal">true</span>
        },
        <span class="hljs-attr">&quot;overlap_comm&quot;:</span> <span class="hljs-literal">true</span>,
        <span class="hljs-attr">&quot;contiguous_gradients&quot;:</span> <span class="hljs-literal">true</span>,
        <span class="hljs-attr">&quot;sub_group_size&quot;:</span> <span class="hljs-number">1e9</span>,
        <span class="hljs-attr">&quot;reduce_bucket_size&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;stage3_prefetch_bucket_size&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;stage3_param_persistence_threshold&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;stage3_max_live_parameters&quot;:</span> <span class="hljs-number">1e9</span>,
        <span class="hljs-attr">&quot;stage3_max_reuse_distance&quot;:</span> <span class="hljs-number">1e9</span>,
        <span class="hljs-attr">&quot;stage3_gather_16bit_weights_on_model_save&quot;:</span> <span class="hljs-literal">true</span>
    },

    <span class="hljs-attr">&quot;gradient_accumulation_steps&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-attr">&quot;gradient_clipping&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-attr">&quot;steps_per_print&quot;:</span> <span class="hljs-number">2000</span>,
    <span class="hljs-attr">&quot;train_batch_size&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-attr">&quot;train_micro_batch_size_per_gpu&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-attr">&quot;wall_clock_breakdown&quot;:</span> <span class="hljs-literal">false</span>
}`,wrap:!1}}),Qe=new q({props:{title:"DeepSpeed features",local:"deepspeed-features",headingTag:"h2"}}),xe=new q({props:{title:"Activation/gradient checkpointing",local:"activationgradient-checkpointing",headingTag:"h3"}}),Le=new q({props:{title:"Optimizer and scheduler",local:"optimizer-and-scheduler",headingTag:"h3"}}),me=new re({props:{warning:!0,$$slots:{default:[Ho]},$$scope:{ctx:g}}}),ue=new ie({props:{id:"opt-sched",options:["optimizer","scheduler"],$$slots:{default:[Fo]},$$scope:{ctx:g}}}),Pe=new q({props:{title:"Precision",local:"precision",headingTag:"h3"}}),Te=new ie({props:{id:"precision",options:["fp32","fp16","bf16"],$$slots:{default:[Oo]},$$scope:{ctx:g}}}),Ke=new q({props:{title:"Batch size",local:"batch-size",headingTag:"h3"}}),tt=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIydHJhaW5fbWljcm9fYmF0Y2hfc2l6ZV9wZXJfZ3B1JTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMnRyYWluX2JhdGNoX3NpemUlMjIlM0ElMjAlMjJhdXRvJTIyJTBBJTdE",highlighted:`{
    <span class="hljs-attr">&quot;train_micro_batch_size_per_gpu&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-attr">&quot;train_batch_size&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
}`,wrap:!1}}),lt=new q({props:{title:"Gradient accumulation",local:"gradient-accumulation",headingTag:"h3"}}),at=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTIyJTNBJTIwJTIyYXV0byUyMiUwQSU3RCUwQQ==",highlighted:`{
    <span class="hljs-attr">&quot;gradient_accumulation_steps&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
}
`,wrap:!1}}),nt=new q({props:{title:"Gradient clipping",local:"gradient-clipping",headingTag:"h3"}}),it=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyZ3JhZGllbnRfY2xpcHBpbmclMjIlM0ElMjAlMjJhdXRvJTIyJTBBJTdE",highlighted:`{
    <span class="hljs-attr">&quot;gradient_clipping&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>
}`,wrap:!1}}),rt=new q({props:{title:"Communication data type",local:"communication-data-type",headingTag:"h3"}}),mt=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyY29tbXVuaWNhdGlvbl9kYXRhX3R5cGUlMjIlM0ElMjAlMjJmcDMyJTIyJTBBJTdE",highlighted:`{
    <span class="hljs-attr">&quot;communication_data_type&quot;:</span> <span class="hljs-string">&quot;fp32&quot;</span>
}`,wrap:!1}}),ut=new q({props:{title:"Deployment",local:"deployment",headingTag:"h2"}}),Je=new ie({props:{id:"deploy",options:["multi-GPU","single-GPU"],$$slots:{default:[li]},$$scope:{ctx:g}}}),dt=new q({props:{title:"Multi-node deployment",local:"multi-node-deployment",headingTag:"h3"}}),Ut=new v({props:{code:"JTdCJTBBJTIwJTIwJTIyY2hlY2twb2ludCUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMnVzZV9ub2RlX2xvY2FsX3N0b3JhZ2UlMjIlM0ElMjB0cnVlJTBBJTIwJTIwJTdEJTBBJTdE",highlighted:`{
  <span class="hljs-attr">&quot;checkpoint&quot;:</span> {
    <span class="hljs-attr">&quot;use_node_local_storage&quot;:</span> <span class="hljs-literal">true</span>
  }
}`,wrap:!1}}),de=new ie({props:{id:"multinode",options:["torchrun","deepspeed"],$$slots:{default:[ni]},$$scope:{ctx:g}}}),ht=new q({props:{title:"SLURM",local:"slurm",headingTag:"h3"}}),Ct=new v({props:{code:"JTIzU0JBVENIJTIwLS1qb2ItbmFtZSUzRHRlc3Qtbm9kZXMlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBuYW1lJTBBJTIzU0JBVENIJTIwLS1ub2RlcyUzRDIlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBub2RlcyUwQSUyM1NCQVRDSCUyMC0tbnRhc2tzLXBlci1ub2RlJTNEMSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMGNydWNpYWwlMjAtJTIwb25seSUyMDElMjB0YXNrJTIwcGVyJTIwZGlzdCUyMHBlciUyMG5vZGUhJTBBJTIzU0JBVENIJTIwLS1jcHVzLXBlci10YXNrJTNEMTAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBudW1iZXIlMjBvZiUyMGNvcmVzJTIwcGVyJTIwdGFza3MlMEElMjNTQkFUQ0glMjAtLWdyZXMlM0RncHUlM0E4JTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwbnVtYmVyJTIwb2YlMjBncHVzJTBBJTIzU0JBVENIJTIwLS10aW1lJTIwMjAlM0EwMCUzQTAwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwbWF4aW11bSUyMGV4ZWN1dGlvbiUyMHRpbWUlMjAoSEglM0FNTSUzQVNTKSUwQSUyM1NCQVRDSCUyMC0tb3V0cHV0JTNEJTI1eC0lMjVqLm91dCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMG91dHB1dCUyMGZpbGUlMjBuYW1lJTBBJTBBZXhwb3J0JTIwR1BVU19QRVJfTk9ERSUzRDglMEFleHBvcnQlMjBNQVNURVJfQUREUiUzRCUyNChzY29udHJvbCUyMHNob3clMjBob3N0bmFtZXMlMjAlMjRTTFVSTV9KT0JfTk9ERUxJU1QlMjAlN0MlMjBoZWFkJTIwLW4lMjAxKSUwQWV4cG9ydCUyME1BU1RFUl9QT1JUJTNEOTkwMSUwQSUwQXNydW4lMjAtLWpvYmlkJTIwJTI0U0xVUk1fSk9CSUQlMjBiYXNoJTIwLWMlMjAncHl0aG9uJTIwLW0lMjB0b3JjaC5kaXN0cmlidXRlZC5ydW4lMjAlNUMlMEElMjAtLW5wcm9jX3Blcl9ub2RlJTIwJTI0R1BVU19QRVJfTk9ERSUyMC0tbm5vZGVzJTIwJTI0U0xVUk1fTk5PREVTJTIwLS1ub2RlX3JhbmslMjAlMjRTTFVSTV9QUk9DSUQlMjAlNUMlMEElMjAtLW1hc3Rlcl9hZGRyJTIwJTI0TUFTVEVSX0FERFIlMjAtLW1hc3Rlcl9wb3J0JTIwJTI0TUFTVEVSX1BPUlQlMjAlNUMlMEF5b3VyX3Byb2dyYW0ucHklMjAlM0Nub3JtYWwlMjBjbCUyMGFyZ3MlM0UlMjAtLWRlZXBzcGVlZCUyMGRzX2NvbmZpZy5qc29uJw==",highlighted:`<span class="hljs-comment">#SBATCH --job-name=test-nodes        # name</span>
<span class="hljs-comment">#SBATCH --nodes=2                    # nodes</span>
<span class="hljs-comment">#SBATCH --ntasks-per-node=1          # crucial - only 1 task per dist per node!</span>
<span class="hljs-comment">#SBATCH --cpus-per-task=10           # number of cores per tasks</span>
<span class="hljs-comment">#SBATCH --gres=gpu:8                 # number of gpus</span>
<span class="hljs-comment">#SBATCH --time 20:00:00              # maximum execution time (HH:MM:SS)</span>
<span class="hljs-comment">#SBATCH --output=%x-%j.out           # output file name</span>

<span class="hljs-built_in">export</span> GPUS_PER_NODE=8
<span class="hljs-built_in">export</span> MASTER_ADDR=$(scontrol show hostnames <span class="hljs-variable">$SLURM_JOB_NODELIST</span> | <span class="hljs-built_in">head</span> -n 1)
<span class="hljs-built_in">export</span> MASTER_PORT=9901

srun --jobid <span class="hljs-variable">$SLURM_JOBID</span> bash -c <span class="hljs-string">&#x27;python -m torch.distributed.run \\
 --nproc_per_node $GPUS_PER_NODE --nnodes $SLURM_NNODES --node_rank $SLURM_PROCID \\
 --master_addr $MASTER_ADDR --master_port $MASTER_PORT \\
your_program.py &lt;normal cl args&gt; --deepspeed ds_config.json&#x27;</span>`,wrap:!1}}),gt=new v({props:{code:"c2JhdGNoJTIwbGF1bmNoLnNsdXJt",highlighted:"sbatch launch.slurm",wrap:!1}}),$t=new q({props:{title:"Notebook",local:"notebook",headingTag:"h3"}}),Bt=new v({props:{code:"JTIzJTIwRGVlcFNwZWVkJTIwcmVxdWlyZXMlMjBhJTIwZGlzdHJpYnV0ZWQlMjBlbnZpcm9ubWVudCUyMGV2ZW4lMjB3aGVuJTIwb25seSUyMG9uZSUyMHByb2Nlc3MlMjBpcyUyMHVzZWQuJTBBJTIzJTIwVGhpcyUyMGVtdWxhdGVzJTIwYSUyMGxhdW5jaGVyJTIwaW4lMjB0aGUlMjBub3RlYm9vayUwQWltcG9ydCUyMG9zJTBBJTBBb3MuZW52aXJvbiU1QiUyMk1BU1RFUl9BRERSJTIyJTVEJTIwJTNEJTIwJTIybG9jYWxob3N0JTIyJTBBb3MuZW52aXJvbiU1QiUyMk1BU1RFUl9QT1JUJTIyJTVEJTIwJTNEJTIwJTIyOTk5NCUyMiUyMCUyMCUyMyUyMG1vZGlmeSUyMGlmJTIwUnVudGltZUVycm9yJTNBJTIwQWRkcmVzcyUyMGFscmVhZHklMjBpbiUyMHVzZSUwQW9zLmVudmlyb24lNUIlMjJSQU5LJTIyJTVEJTIwJTNEJTIwJTIyMCUyMiUwQW9zLmVudmlyb24lNUIlMjJMT0NBTF9SQU5LJTIyJTVEJTIwJTNEJTIwJTIyMCUyMiUwQW9zLmVudmlyb24lNUIlMjJXT1JMRF9TSVpFJTIyJTVEJTIwJTNEJTIwJTIyMSUyMiUwQSUwQSUyMyUyME5vdyUyMHByb2NlZWQlMjBhcyUyMG5vcm1hbCUyQyUyMHBsdXMlMjBwYXNzJTIwdGhlJTIwRGVlcFNwZWVkJTIwY29uZmlnJTIwZmlsZSUwQXRyYWluaW5nX2FyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyguLi4lMkMlMjBkZWVwc3BlZWQlM0QlMjJkc19jb25maWdfemVybzMuanNvbiUyMiklMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciguLi4pJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-comment"># DeepSpeed requires a distributed environment even when only one process is used.</span>
<span class="hljs-comment"># This emulates a launcher in the notebook</span>
<span class="hljs-keyword">import</span> os

os.environ[<span class="hljs-string">&quot;MASTER_ADDR&quot;</span>] = <span class="hljs-string">&quot;localhost&quot;</span>
os.environ[<span class="hljs-string">&quot;MASTER_PORT&quot;</span>] = <span class="hljs-string">&quot;9994&quot;</span>  <span class="hljs-comment"># modify if RuntimeError: Address already in use</span>
os.environ[<span class="hljs-string">&quot;RANK&quot;</span>] = <span class="hljs-string">&quot;0&quot;</span>
os.environ[<span class="hljs-string">&quot;LOCAL_RANK&quot;</span>] = <span class="hljs-string">&quot;0&quot;</span>
os.environ[<span class="hljs-string">&quot;WORLD_SIZE&quot;</span>] = <span class="hljs-string">&quot;1&quot;</span>

<span class="hljs-comment"># Now proceed as normal, plus pass the DeepSpeed config file</span>
training_args = TrainingArguments(..., deepspeed=<span class="hljs-string">&quot;ds_config_zero3.json&quot;</span>)
trainer = Trainer(...)
trainer.train()`,wrap:!1}}),Zt=new v({props:{code:"JTI1JTI1YmFzaCUwQWNhdCUyMCUzQyUzQydFT1QnJTIwJTNFJTIwZHNfY29uZmlnX3plcm8zLmpzb24lMEElN0IlMEElMjAlMjAlMjAlMjAlMjJmcDE2JTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZW5hYmxlZCUyMiUzQSUyMCUyMmF1dG8lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJsb3NzX3NjYWxlJTIyJTNBJTIwMCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmxvc3Nfc2NhbGVfd2luZG93JTIyJTNBJTIwMTAwMCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmluaXRpYWxfc2NhbGVfcG93ZXIlMjIlM0ElMjAxNiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmh5c3RlcmVzaXMlMjIlM0ElMjAyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybWluX2xvc3Nfc2NhbGUlMjIlM0ElMjAxJTBBJTIwJTIwJTIwJTIwJTdEJTJDJTBBJTBBJTIwJTIwJTIwJTIwJTIyb3B0aW1pemVyJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydHlwZSUyMiUzQSUyMCUyMkFkYW1XJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycGFyYW1zJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybHIlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYmV0YXMlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZXBzJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMndlaWdodF9kZWNheSUyMiUzQSUyMCUyMmF1dG8lMjIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMEElMjAlMjAlMjAlMjAlN0QlMkMlMEElMEElMjAlMjAlMjAlMjAlMjJzY2hlZHVsZXIlMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ0eXBlJTIyJTNBJTIwJTIyV2FybXVwTFIlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJwYXJhbXMlMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ3YXJtdXBfbWluX2xyJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMndhcm11cF9tYXhfbHIlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyd2FybXVwX251bV9zdGVwcyUyMiUzQSUyMCUyMmF1dG8lMjIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMEElMjAlMjAlMjAlMjAlN0QlMkMlMEElMEElMjAlMjAlMjAlMjAlMjJ6ZXJvX29wdGltaXphdGlvbiUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnN0YWdlJTIyJTNBJTIwMyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMm9mZmxvYWRfb3B0aW1pemVyJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZGV2aWNlJTIyJTNBJTIwJTIyY3B1JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycGluX21lbW9yeSUyMiUzQSUyMHRydWUlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJvZmZsb2FkX3BhcmFtJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZGV2aWNlJTIyJTNBJTIwJTIyY3B1JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycGluX21lbW9yeSUyMiUzQSUyMHRydWUlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJvdmVybGFwX2NvbW0lMjIlM0ElMjB0cnVlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyY29udGlndW91c19ncmFkaWVudHMlMjIlM0ElMjB0cnVlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc3ViX2dyb3VwX3NpemUlMjIlM0ElMjAxZTklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJyZWR1Y2VfYnVja2V0X3NpemUlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc3RhZ2UzX3ByZWZldGNoX2J1Y2tldF9zaXplJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnN0YWdlM19wYXJhbV9wZXJzaXN0ZW5jZV90aHJlc2hvbGQlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc3RhZ2UzX21heF9saXZlX3BhcmFtZXRlcnMlMjIlM0ElMjAxZTklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJzdGFnZTNfbWF4X3JldXNlX2Rpc3RhbmNlJTIyJTNBJTIwMWU5JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyc3RhZ2UzX2dhdGhlcl8xNmJpdF93ZWlnaHRzX29uX21vZGVsX3NhdmUlMjIlM0ElMjB0cnVlJTBBJTIwJTIwJTIwJTIwJTdEJTJDJTBBJTBBJTIwJTIwJTIwJTIwJTIyZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMmdyYWRpZW50X2NsaXBwaW5nJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMnN0ZXBzX3Blcl9wcmludCUyMiUzQSUyMDIwMDAlMkMlMEElMjAlMjAlMjAlMjAlMjJ0cmFpbl9iYXRjaF9zaXplJTIyJTNBJTIwJTIyYXV0byUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMnRyYWluX21pY3JvX2JhdGNoX3NpemVfcGVyX2dwdSUyMiUzQSUyMCUyMmF1dG8lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJ3YWxsX2Nsb2NrX2JyZWFrZG93biUyMiUzQSUyMGZhbHNlJTBBJTdEJTBBRU9U",highlighted:`%%bash
cat &lt;&lt;<span class="hljs-string">&#x27;EOT&#x27;</span> &gt; ds_config_zero3.json
{
    <span class="hljs-string">&quot;fp16&quot;</span>: {
        <span class="hljs-string">&quot;enabled&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-string">&quot;loss_scale&quot;</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">&quot;loss_scale_window&quot;</span>: <span class="hljs-number">1000</span>,
        <span class="hljs-string">&quot;initial_scale_power&quot;</span>: <span class="hljs-number">16</span>,
        <span class="hljs-string">&quot;hysteresis&quot;</span>: <span class="hljs-number">2</span>,
        <span class="hljs-string">&quot;min_loss_scale&quot;</span>: <span class="hljs-number">1</span>
    },

    <span class="hljs-string">&quot;optimizer&quot;</span>: {
        <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;AdamW&quot;</span>,
        <span class="hljs-string">&quot;params&quot;</span>: {
            <span class="hljs-string">&quot;lr&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-string">&quot;betas&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-string">&quot;eps&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-string">&quot;weight_decay&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>
        }
    },

    <span class="hljs-string">&quot;scheduler&quot;</span>: {
        <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;WarmupLR&quot;</span>,
        <span class="hljs-string">&quot;params&quot;</span>: {
            <span class="hljs-string">&quot;warmup_min_lr&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-string">&quot;warmup_max_lr&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
            <span class="hljs-string">&quot;warmup_num_steps&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>
        }
    },

    <span class="hljs-string">&quot;zero_optimization&quot;</span>: {
        <span class="hljs-string">&quot;stage&quot;</span>: <span class="hljs-number">3</span>,
        <span class="hljs-string">&quot;offload_optimizer&quot;</span>: {
            <span class="hljs-string">&quot;device&quot;</span>: <span class="hljs-string">&quot;cpu&quot;</span>,
            <span class="hljs-string">&quot;pin_memory&quot;</span>: true
        },
        <span class="hljs-string">&quot;offload_param&quot;</span>: {
            <span class="hljs-string">&quot;device&quot;</span>: <span class="hljs-string">&quot;cpu&quot;</span>,
            <span class="hljs-string">&quot;pin_memory&quot;</span>: true
        },
        <span class="hljs-string">&quot;overlap_comm&quot;</span>: true,
        <span class="hljs-string">&quot;contiguous_gradients&quot;</span>: true,
        <span class="hljs-string">&quot;sub_group_size&quot;</span>: <span class="hljs-number">1e9</span>,
        <span class="hljs-string">&quot;reduce_bucket_size&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-string">&quot;stage3_prefetch_bucket_size&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-string">&quot;stage3_param_persistence_threshold&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-string">&quot;stage3_max_live_parameters&quot;</span>: <span class="hljs-number">1e9</span>,
        <span class="hljs-string">&quot;stage3_max_reuse_distance&quot;</span>: <span class="hljs-number">1e9</span>,
        <span class="hljs-string">&quot;stage3_gather_16bit_weights_on_model_save&quot;</span>: true
    },

    <span class="hljs-string">&quot;gradient_accumulation_steps&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-string">&quot;gradient_clipping&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-string">&quot;steps_per_print&quot;</span>: <span class="hljs-number">2000</span>,
    <span class="hljs-string">&quot;train_batch_size&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-string">&quot;train_micro_batch_size_per_gpu&quot;</span>: <span class="hljs-string">&quot;auto&quot;</span>,
    <span class="hljs-string">&quot;wall_clock_breakdown&quot;</span>: false
}
EOT`,wrap:!1}}),Gt=new v({props:{code:"IWdpdCUyMGNsb25lJTIwaHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGaHVnZ2luZ2ZhY2UlMkZ0cmFuc2Zvcm1lcnMlMEEhY2QlMjB0cmFuc2Zvcm1lcnMlM0IlMjBkZWVwc3BlZWQlMjBleGFtcGxlcyUyRnB5dG9yY2glMkZ0cmFuc2xhdGlvbiUyRnJ1bl90cmFuc2xhdGlvbi5weSUyMC4uLg==",highlighted:`!git clone https://github.com/huggingface/transformers
!cd transformers; deepspeed examples/pytorch/translation/run_translation.py ...`,wrap:!1}}),Rt=new v({props:{code:"JTI1JTI1YmFzaCUwQSUwQWdpdCUyMGNsb25lJTIwaHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGaHVnZ2luZ2ZhY2UlMkZ0cmFuc2Zvcm1lcnMlMEFjZCUyMHRyYW5zZm9ybWVycyUwQWRlZXBzcGVlZCUyMGV4YW1wbGVzJTJGcHl0b3JjaCUyRnRyYW5zbGF0aW9uJTJGcnVuX3RyYW5zbGF0aW9uLnB5JTIwLi4u",highlighted:`%%bash

git clone https://github.com/huggingface/transformers
cd transformers
deepspeed examples/pytorch/translation/run_translation.py ...`,wrap:!1}}),zt=new q({props:{title:"Save model weights",local:"save-model-weights",headingTag:"h2"}}),we=new ie({props:{id:"save",options:["fp16","fp32"],$$slots:{default:[pi]},$$scope:{ctx:g}}}),kt=new q({props:{title:"ZeRO Inference",local:"zero-inference",headingTag:"h2"}}),St=new v({props:{code:"ZGVlcHNwZWVkJTIwLS1udW1fZ3B1cyUzRDIlMjB5b3VyX3Byb2dyYW0ucHklMjAlM0Nub3JtYWwlMjBjbCUyMGFyZ3MlM0UlMjAtLWRvX2V2YWwlMjAtLWRlZXBzcGVlZCUyMGRzX2NvbmZpZy5qc29u",highlighted:"deepspeed --num_gpus=2 your_program.py &lt;normal cl args&gt; --do_eval --deepspeed ds_config.json",wrap:!1}}),Et=new q({props:{title:"Non-Trainer DeepSpeed integration",local:"non-trainer-deepspeed-integration",headingTag:"h2"}}),fe=new re({props:{$$slots:{default:[yi]},$$scope:{ctx:g}}}),Ue=new ie({props:{id:"models",options:["pretrained model","non-pretrained model"],$$slots:{default:[ui]},$$scope:{ctx:g}}}),xt=new q({props:{title:"Non-Trainer ZeRO Inference",local:"non-trainer-zero-inference",headingTag:"h3"}}),Pt=new v({props:{code:" ",highlighted:`<span class="hljs-comment">#!/usr/bin/env python</span>

<span class="hljs-comment"># This script demonstrates how to use Deepspeed ZeRO in an inference mode when one can&#x27;t fit a model</span>
<span class="hljs-comment"># into a single GPU</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># 1. Use 1 GPU with CPU offload</span>
<span class="hljs-comment"># 2. Or use multiple GPUs instead</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># First you need to install deepspeed: pip install deepspeed</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># Here we use a 3B &quot;bigscience/T0_3B&quot; model which needs about 15GB GPU RAM - so 1 largish or 2</span>
<span class="hljs-comment"># small GPUs can handle it. or 1 small GPU and a lot of CPU memory.</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># To use a larger model like &quot;bigscience/T0&quot; which needs about 50GB, unless you have an 80GB GPU -</span>
<span class="hljs-comment"># you will need 2-4 gpus. And then you can adapt the script to handle more gpus if you want to</span>
<span class="hljs-comment"># process multiple inputs at once.</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># The provided deepspeed config also activates CPU memory offloading, so chances are that if you</span>
<span class="hljs-comment"># have a lot of available CPU memory and you don&#x27;t mind a slowdown you should be able to load a</span>
<span class="hljs-comment"># model that doesn&#x27;t normally fit into a single GPU. If you have enough GPU memory the program will</span>
<span class="hljs-comment"># run faster if you don&#x27;t want offload to CPU - so disable that section then.</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># To deploy on 1 gpu:</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># deepspeed --num_gpus 1 t0.py</span>
<span class="hljs-comment"># or:</span>
<span class="hljs-comment"># python -m torch.distributed.run --nproc_per_node=1 t0.py</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># To deploy on 2 gpus:</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># deepspeed --num_gpus 2 t0.py</span>
<span class="hljs-comment"># or:</span>
<span class="hljs-comment"># python -m torch.distributed.run --nproc_per_node=2 t0.py</span>

<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoConfig, AutoModelForSeq2SeqLM
<span class="hljs-keyword">from</span> transformers.integrations <span class="hljs-keyword">import</span> HfDeepSpeedConfig
<span class="hljs-keyword">import</span> deepspeed
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> torch

os.environ[<span class="hljs-string">&quot;TOKENIZERS_PARALLELISM&quot;</span>] = <span class="hljs-string">&quot;false&quot;</span>  <span class="hljs-comment"># To avoid warnings about parallelism in tokenizers</span>

<span class="hljs-comment"># distributed setup</span>
local_rank = <span class="hljs-built_in">int</span>(os.getenv(<span class="hljs-string">&quot;LOCAL_RANK&quot;</span>, <span class="hljs-string">&quot;0&quot;</span>))
world_size = <span class="hljs-built_in">int</span>(os.getenv(<span class="hljs-string">&quot;WORLD_SIZE&quot;</span>, <span class="hljs-string">&quot;1&quot;</span>))
torch.cuda.set_device(local_rank)
deepspeed.init_distributed()

model_name = <span class="hljs-string">&quot;bigscience/T0_3B&quot;</span>

config = AutoConfig.from_pretrained(model_name)
model_hidden_size = config.d_model

<span class="hljs-comment"># batch size has to be divisible by world_size, but can be bigger than world_size</span>
train_batch_size = <span class="hljs-number">1</span> * world_size

<span class="hljs-comment"># ds_config notes</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># - enable bf16 if you use Ampere or higher GPU - this will run in mixed precision and will be</span>
<span class="hljs-comment"># faster.</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># - for older GPUs you can enable fp16, but it&#x27;ll only work for non-bf16 pretrained models - e.g.</span>
<span class="hljs-comment"># all official t5 models are bf16-pretrained</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># - set offload_param.device to &quot;none&quot; or completely remove the \`offload_param\` section if you don&#x27;t</span>
<span class="hljs-comment"># - want CPU offload</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># - if using \`offload_param\` you can manually finetune stage3_param_persistence_threshold to control</span>
<span class="hljs-comment"># - which params should remain on gpus - the larger the value the smaller the offload size</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># For in-depth info on Deepspeed config see</span>
<span class="hljs-comment"># https://huggingface.co/docs/transformers/main/main_classes/deepspeed</span>

<span class="hljs-comment"># keeping the same format as json for consistency, except it uses lower case for true/false</span>
<span class="hljs-comment"># fmt: off</span>
ds_config = {
    <span class="hljs-string">&quot;fp16&quot;</span>: {
        <span class="hljs-string">&quot;enabled&quot;</span>: <span class="hljs-literal">False</span>
    },
    <span class="hljs-string">&quot;bf16&quot;</span>: {
        <span class="hljs-string">&quot;enabled&quot;</span>: <span class="hljs-literal">False</span>
    },
    <span class="hljs-string">&quot;zero_optimization&quot;</span>: {
        <span class="hljs-string">&quot;stage&quot;</span>: <span class="hljs-number">3</span>,
        <span class="hljs-string">&quot;offload_param&quot;</span>: {
            <span class="hljs-string">&quot;device&quot;</span>: <span class="hljs-string">&quot;cpu&quot;</span>,
            <span class="hljs-string">&quot;pin_memory&quot;</span>: <span class="hljs-literal">True</span>
        },
        <span class="hljs-string">&quot;overlap_comm&quot;</span>: <span class="hljs-literal">True</span>,
        <span class="hljs-string">&quot;contiguous_gradients&quot;</span>: <span class="hljs-literal">True</span>,
        <span class="hljs-string">&quot;reduce_bucket_size&quot;</span>: model_hidden_size * model_hidden_size,
        <span class="hljs-string">&quot;stage3_prefetch_bucket_size&quot;</span>: <span class="hljs-number">0.9</span> * model_hidden_size * model_hidden_size,
        <span class="hljs-string">&quot;stage3_param_persistence_threshold&quot;</span>: <span class="hljs-number">10</span> * model_hidden_size
    },
    <span class="hljs-string">&quot;steps_per_print&quot;</span>: <span class="hljs-number">2000</span>,
    <span class="hljs-string">&quot;train_batch_size&quot;</span>: train_batch_size,
    <span class="hljs-string">&quot;train_micro_batch_size_per_gpu&quot;</span>: <span class="hljs-number">1</span>,
    <span class="hljs-string">&quot;wall_clock_breakdown&quot;</span>: <span class="hljs-literal">False</span>
}
<span class="hljs-comment"># fmt: on</span>

<span class="hljs-comment"># next line instructs transformers to partition the model directly over multiple gpus using</span>
<span class="hljs-comment"># deepspeed.zero.Init when model&#x27;s \`from_pretrained\` method is called.</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># **it has to be run before loading the model AutoModelForSeq2SeqLM.from_pretrained(model_name)**</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># otherwise the model will first be loaded normally and only partitioned at forward time which is</span>
<span class="hljs-comment"># less efficient and when there is little CPU RAM may fail</span>
dschf = HfDeepSpeedConfig(ds_config)  <span class="hljs-comment"># keep this object alive</span>

<span class="hljs-comment"># now a model can be loaded.</span>
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

<span class="hljs-comment"># initialise Deepspeed ZeRO and store only the engine object</span>
ds_engine = deepspeed.initialize(model=model, config_params=ds_config)[<span class="hljs-number">0</span>]
ds_engine.module.<span class="hljs-built_in">eval</span>()  <span class="hljs-comment"># inference</span>

<span class="hljs-comment"># Deepspeed ZeRO can process unrelated inputs on each GPU. So for 2 gpus you process 2 inputs at once.</span>
<span class="hljs-comment"># If you use more GPUs adjust for more.</span>
<span class="hljs-comment"># And of course if you have just one input to process you then need to pass the same string to both gpus</span>
<span class="hljs-comment"># If you use only one GPU, then you will have only rank 0.</span>
rank = torch.distributed.get_rank()
<span class="hljs-keyword">if</span> rank == <span class="hljs-number">0</span>:
    text_in = <span class="hljs-string">&quot;Is this review positive or negative? Review: this is the best cast iron skillet you will ever buy&quot;</span>
<span class="hljs-keyword">elif</span> rank == <span class="hljs-number">1</span>:
    text_in = <span class="hljs-string">&quot;Is this review positive or negative? Review: this is the worst restaurant ever&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(model_name)
inputs = tokenizer.encode(text_in, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device=local_rank)
<span class="hljs-keyword">with</span> torch.no_grad():
    outputs = ds_engine.module.generate(inputs, synced_gpus=<span class="hljs-literal">True</span>)
text_out = tokenizer.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;rank<span class="hljs-subst">{rank}</span>:\\n   in=<span class="hljs-subst">{text_in}</span>\\n  out=<span class="hljs-subst">{text_out}</span>&quot;</span>)`,wrap:!1}}),Kt=new v({props:{code:"JTI0JTIwZGVlcHNwZWVkJTIwLS1udW1fZ3B1cyUyMDIlMjB0MC5weSUwQXJhbmswJTNBJTBBJTIwJTIwJTIwaW4lM0RJcyUyMHRoaXMlMjByZXZpZXclMjBwb3NpdGl2ZSUyMG9yJTIwbmVnYXRpdmUlM0YlMjBSZXZpZXclM0ElMjB0aGlzJTIwaXMlMjB0aGUlMjBiZXN0JTIwY2FzdCUyMGlyb24lMjBza2lsbGV0JTIweW91JTIwd2lsbCUyMGV2ZXIlMjBidXklMEElMjAlMjBvdXQlM0RQb3NpdGl2ZSUwQXJhbmsxJTNBJTBBJTIwJTIwJTIwaW4lM0RJcyUyMHRoaXMlMjByZXZpZXclMjBwb3NpdGl2ZSUyMG9yJTIwbmVnYXRpdmUlM0YlMjBSZXZpZXclM0ElMjB0aGlzJTIwaXMlMjB0aGUlMjB3b3JzdCUyMHJlc3RhdXJhbnQlMjBldmVyJTBBJTIwJTIwb3V0JTNEbmVnYXRpdmU=",highlighted:`$ deepspeed --num_gpus 2 t0.py
rank0:
   <span class="hljs-keyword">in</span>=Is this review positive or negative? Review: this is the best cast iron skillet you will ever buy
  out=Positive
rank1:
   <span class="hljs-keyword">in</span>=Is this review positive or negative? Review: this is the worst restaurant ever
  out=negative`,wrap:!1}}),tl=new q({props:{title:"Generate",local:"generate",headingTag:"h3"}}),al=new q({props:{title:"Troubleshoot",local:"troubleshoot",headingTag:"h2"}}),rl=new v({props:{code:"cHl0aG9uJTIwLWMlMjAnaW1wb3J0JTIwdG9yY2glM0IlMjBwcmludChmJTIydG9yY2glM0ElMjAlN0J0b3JjaC5fX3ZlcnNpb25fXyU3RCUyMiknJTBBcHl0aG9uJTIwLWMlMjAnaW1wb3J0JTIwdHJhbnNmb3JtZXJzJTNCJTIwcHJpbnQoZiUyMnRyYW5zZm9ybWVycyUzQSUyMCU3QnRyYW5zZm9ybWVycy5fX3ZlcnNpb25fXyU3RCUyMiknJTBBcHl0aG9uJTIwLWMlMjAnaW1wb3J0JTIwZGVlcHNwZWVkJTNCJTIwcHJpbnQoZiUyMmRlZXBzcGVlZCUzQSUyMCU3QmRlZXBzcGVlZC5fX3ZlcnNpb25fXyU3RCUyMikn",highlighted:`python -c <span class="hljs-string">&#x27;import torch; print(f&quot;torch: {torch.__version__}&quot;)&#x27;</span>
python -c <span class="hljs-string">&#x27;import transformers; print(f&quot;transformers: {transformers.__version__}&quot;)&#x27;</span>
python -c <span class="hljs-string">&#x27;import deepspeed; print(f&quot;deepspeed: {deepspeed.__version__}&quot;)&#x27;</span>`,wrap:!1}}),yl=new q({props:{title:"DeepSpeed process killed at startup",local:"deepspeed-process-killed-at-startup",headingTag:"h3"}}),ul=new q({props:{title:"NaN loss",local:"nan-loss",headingTag:"h3"}}),dl=new v({props:{code:"JTdCJTBBJTIwJTIwJTIwJTIwJTIyZnAxNiUyMiUzQSUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmVuYWJsZWQlMjIlM0ElMjAlMjJhdXRvJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybG9zc19zY2FsZSUyMiUzQSUyMDAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJsb3NzX3NjYWxlX3dpbmRvdyUyMiUzQSUyMDEwMDAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJpbml0aWFsX3NjYWxlX3Bvd2VyJTIyJTNBJTIwMTYlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJoeXN0ZXJlc2lzJTIyJTNBJTIwMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMm1pbl9sb3NzX3NjYWxlJTIyJTNBJTIwMSUwQSUyMCUyMCUyMCUyMCU3RCUwQSU3RA==",highlighted:`{
    <span class="hljs-attr">&quot;fp16&quot;:</span> {
        <span class="hljs-attr">&quot;enabled&quot;:</span> <span class="hljs-string">&quot;auto&quot;</span>,
        <span class="hljs-attr">&quot;loss_scale&quot;:</span> <span class="hljs-number">0</span>,
        <span class="hljs-attr">&quot;loss_scale_window&quot;:</span> <span class="hljs-number">1000</span>,
        <span class="hljs-attr">&quot;initial_scale_power&quot;:</span> <span class="hljs-number">16</span>,
        <span class="hljs-attr">&quot;hysteresis&quot;:</span> <span class="hljs-number">2</span>,
        <span class="hljs-attr">&quot;min_loss_scale&quot;:</span> <span class="hljs-number">1</span>
    }
}`,wrap:!1}}),fl=new v({props:{code:" ",highlighted:`0%|                                                                                                                             | 0/189 [00:00&lt;?, ?it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 262144, reducing to 262144
  1%|▌                                                                                                                    | 1/189 [00:00&lt;01:26,  2.17it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 262144, reducing to 131072.0
  1%|█▏
 [...]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 14%|████████████████▌                                                                                                   | 27/189 [00:14&lt;01:13,  2.21it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 15%|█████████████████▏                                                                                                  | 28/189 [00:14&lt;01:13,  2.18it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
 15%|█████████████████▊                                                                                                  | 29/189 [00:15&lt;01:13,  2.18it/s]
 [deepscale] OVERFLOW! Rank 0 Skipping step. Attempted loss scale: 1, reducing to 1
[...]`,wrap:!1}}),jl=new q({props:{title:"Resources",local:"resources",headingTag:"h2"}}),bl=new _o({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/deepspeed.md"}}),{c(){s=m("meta"),c=r(),n=m("p"),p=r(),d(o.$$.fragment),i=r(),y=m("p"),y.innerHTML=b,I=r(),B=m("ul"),B.innerHTML=W,G=r(),R=m("p"),R.innerHTML=J,_=r(),k=m("p"),k.innerHTML=N,Z=r(),d(A.$$.fragment),V=r(),H=m("p"),H.innerHTML=D,P=r(),d(F.$$.fragment),x=r(),d(K.$$.fragment),ee=r(),d(E.$$.fragment),te=r(),Q=m("p"),Q.innerHTML=O,$=r(),d(X.$$.fragment),se=r(),le=m("p"),le.textContent=ae,oe=r(),L=m("p"),L.textContent=je,C=r(),d(z.$$.fragment),he=r(),ne=m("p"),ne.textContent=Qa,$l=r(),Ie=m("table"),Ie.innerHTML=Ha,Al=r(),Ce=m("p"),Ce.textContent=xa,Bl=r(),be=m("p"),be.textContent=Ya,_l=r(),ge=m("ol"),ge.innerHTML=Fa,Zl=r(),d($e.$$.fragment),vl=r(),Ae=m("p"),Ae.innerHTML=La,Gl=r(),d(Me.$$.fragment),Wl=r(),Be=m("p"),Be.innerHTML=Da,Rl=r(),d(pe.$$.fragment),zl=r(),d(_e.$$.fragment),Xl=r(),Ze=m("p"),Ze.textContent=Pa,kl=r(),ve=m("ol"),ve.innerHTML=Oa,ql=r(),Ge=m("p"),Ge.innerHTML=Ka,Nl=r(),We=m("ol"),We.innerHTML=en,Vl=r(),Re=m("p"),Re.innerHTML=tn,Sl=r(),d(ze.$$.fragment),El=r(),Xe=m("p"),Xe.innerHTML=ln,Ql=r(),d(ye.$$.fragment),Hl=r(),ke=m("p"),ke.innerHTML=sn,xl=r(),d(ce.$$.fragment),Yl=r(),d(qe.$$.fragment),Fl=r(),Ne=m("p"),Ne.innerHTML=an,Ll=r(),Ve=m("p"),Ve.innerHTML=nn,Dl=r(),Se=m("p"),Se.innerHTML=on,Pl=r(),d(Ee.$$.fragment),Ol=r(),d(Qe.$$.fragment),Kl=r(),He=m("p"),He.textContent=rn,es=r(),d(xe.$$.fragment),ts=r(),Ye=m("p"),Ye.textContent=Mn,ls=r(),Fe=m("ol"),Fe.innerHTML=pn,ss=r(),d(Le.$$.fragment),as=r(),De=m("p"),De.innerHTML=yn,ns=r(),d(me.$$.fragment),os=r(),d(ue.$$.fragment),is=r(),d(Pe.$$.fragment),rs=r(),Oe=m("p"),Oe.textContent=cn,Ms=r(),d(Te.$$.fragment),ps=r(),d(Ke.$$.fragment),ys=r(),et=m("p"),et.innerHTML=mn,cs=r(),d(tt.$$.fragment),ms=r(),d(lt.$$.fragment),us=r(),st=m("p"),st.innerHTML=un,Ts=r(),d(at.$$.fragment),Js=r(),d(nt.$$.fragment),ds=r(),ot=m("p"),ot.innerHTML=Tn,ws=r(),d(it.$$.fragment),fs=r(),d(rt.$$.fragment),Us=r(),Mt=m("p"),Mt.textContent=Jn,js=r(),pt=m("p"),pt.textContent=dn,hs=r(),yt=m("p"),yt.textContent=wn,Is=r(),ct=m("p"),ct.innerHTML=fn,Cs=r(),d(mt.$$.fragment),bs=r(),d(ut.$$.fragment),gs=r(),Tt=m("p"),Tt.innerHTML=Un,$s=r(),Jt=m("p"),Jt.innerHTML=jn,As=r(),d(Je.$$.fragment),Bs=r(),d(dt.$$.fragment),_s=r(),wt=m("p"),wt.innerHTML=hn,Zs=r(),ft=m("p"),ft.innerHTML=In,vs=r(),d(Ut.$$.fragment),Gs=r(),jt=m("p"),jt.innerHTML=Cn,Ws=r(),d(de.$$.fragment),Rs=r(),d(ht.$$.fragment),zs=r(),It=m("p"),It.textContent=bn,Xs=r(),d(Ct.$$.fragment),ks=r(),bt=m("p"),bt.textContent=gn,qs=r(),d(gt.$$.fragment),Ns=r(),d($t.$$.fragment),Vs=r(),At=m("p"),At.innerHTML=$n,Ss=r(),d(Bt.$$.fragment),Es=r(),_t=m("p"),_t.textContent=An,Qs=r(),d(Zt.$$.fragment),Hs=r(),vt=m("p"),vt.innerHTML=Bn,xs=r(),d(Gt.$$.fragment),Ys=r(),Wt=m("p"),Wt.innerHTML=_n,Fs=r(),d(Rt.$$.fragment),Ls=r(),d(zt.$$.fragment),Ds=r(),Xt=m("p"),Xt.innerHTML=Zn,Ps=r(),d(we.$$.fragment),Os=r(),d(kt.$$.fragment),Ks=r(),qt=m("p"),qt.innerHTML=vn,ea=r(),Nt=m("p"),Nt.innerHTML=Gn,ta=r(),Vt=m("p"),Vt.innerHTML=Wn,la=r(),d(St.$$.fragment),sa=r(),d(Et.$$.fragment),aa=r(),Qt=m("p"),Qt.innerHTML=Rn,na=r(),d(fe.$$.fragment),oa=r(),Ht=m("p"),Ht.innerHTML=zn,ia=r(),d(Ue.$$.fragment),ra=r(),d(xt.$$.fragment),Ma=r(),Yt=m("p"),Yt.innerHTML=Xn,pa=r(),Ft=m("p"),Ft.textContent=kn,ya=r(),Lt=m("ul"),Lt.innerHTML=qn,ca=r(),Dt=m("p"),Dt.innerHTML=Nn,ma=r(),d(Pt.$$.fragment),ua=r(),Ot=m("p"),Ot.textContent=Vn,Ta=r(),d(Kt.$$.fragment),Ja=r(),el=m("p"),el.textContent=Sn,da=r(),d(tl.$$.fragment),wa=r(),ll=m("p"),ll.innerHTML=En,fa=r(),sl=m("p"),sl.innerHTML=Qn,Ua=r(),d(al.$$.fragment),ja=r(),nl=m("p"),nl.innerHTML=Hn,ha=r(),ol=m("p"),ol.textContent=xn,Ia=r(),il=m("ul"),il.innerHTML=Yn,Ca=r(),d(rl.$$.fragment),ba=r(),Ml=m("ul"),Ml.innerHTML=Fn,ga=r(),pl=m("p"),pl.textContent=Ln,$a=r(),d(yl.$$.fragment),Aa=r(),cl=m("p"),cl.innerHTML=Dn,Ba=r(),ml=m("p"),ml.innerHTML=Pn,_a=r(),d(ul.$$.fragment),Za=r(),Tl=m("p"),Tl.textContent=On,va=r(),Jl=m("p"),Jl.textContent=Kn,Ga=r(),d(dl.$$.fragment),Wa=r(),wl=m("p"),wl.innerHTML=eo,Ra=r(),d(fl.$$.fragment),za=r(),Ul=m("p"),Ul.innerHTML=to,Xa=r(),d(jl.$$.fragment),ka=r(),hl=m("p"),hl.innerHTML=lo,qa=r(),Il=m("p"),Il.textContent=so,Na=r(),Cl=m("ul"),Cl.innerHTML=ao,Va=r(),d(bl.$$.fragment),Sa=r(),gl=m("p"),this.h()},l(e){const a=go("svelte-u9bgzb",document.head);s=u(a,"META",{name:!0,content:!0}),a.forEach(t),c=M(e),n=u(e,"P",{}),Uo(n).forEach(t),p=M(e),w(o.$$.fragment,e),i=M(e),y=u(e,"P",{"data-svelte-h":!0}),T(y)!=="svelte-na7xsx"&&(y.innerHTML=b),I=M(e),B=u(e,"UL",{"data-svelte-h":!0}),T(B)!=="svelte-q7iq3b"&&(B.innerHTML=W),G=M(e),R=u(e,"P",{"data-svelte-h":!0}),T(R)!=="svelte-1v6adv7"&&(R.innerHTML=J),_=M(e),k=u(e,"P",{"data-svelte-h":!0}),T(k)!=="svelte-1sfk3ud"&&(k.innerHTML=N),Z=M(e),w(A.$$.fragment,e),V=M(e),H=u(e,"P",{"data-svelte-h":!0}),T(H)!=="svelte-fuidv5"&&(H.innerHTML=D),P=M(e),w(F.$$.fragment,e),x=M(e),w(K.$$.fragment,e),ee=M(e),w(E.$$.fragment,e),te=M(e),Q=u(e,"P",{"data-svelte-h":!0}),T(Q)!=="svelte-1fd8xlc"&&(Q.innerHTML=O),$=M(e),w(X.$$.fragment,e),se=M(e),le=u(e,"P",{"data-svelte-h":!0}),T(le)!=="svelte-1xpnss2"&&(le.textContent=ae),oe=M(e),L=u(e,"P",{"data-svelte-h":!0}),T(L)!=="svelte-js61aw"&&(L.textContent=je),C=M(e),w(z.$$.fragment,e),he=M(e),ne=u(e,"P",{"data-svelte-h":!0}),T(ne)!=="svelte-rkauna"&&(ne.textContent=Qa),$l=M(e),Ie=u(e,"TABLE",{"data-svelte-h":!0}),T(Ie)!=="svelte-msolv0"&&(Ie.innerHTML=Ha),Al=M(e),Ce=u(e,"P",{"data-svelte-h":!0}),T(Ce)!=="svelte-4tusjn"&&(Ce.textContent=xa),Bl=M(e),be=u(e,"P",{"data-svelte-h":!0}),T(be)!=="svelte-po9y52"&&(be.textContent=Ya),_l=M(e),ge=u(e,"OL",{"data-svelte-h":!0}),T(ge)!=="svelte-1h4y3ly"&&(ge.innerHTML=Fa),Zl=M(e),w($e.$$.fragment,e),vl=M(e),Ae=u(e,"P",{"data-svelte-h":!0}),T(Ae)!=="svelte-vuobrs"&&(Ae.innerHTML=La),Gl=M(e),w(Me.$$.fragment,e),Wl=M(e),Be=u(e,"P",{"data-svelte-h":!0}),T(Be)!=="svelte-5i3ic7"&&(Be.innerHTML=Da),Rl=M(e),w(pe.$$.fragment,e),zl=M(e),w(_e.$$.fragment,e),Xl=M(e),Ze=u(e,"P",{"data-svelte-h":!0}),T(Ze)!=="svelte-1nzz5la"&&(Ze.textContent=Pa),kl=M(e),ve=u(e,"OL",{"data-svelte-h":!0}),T(ve)!=="svelte-1y8oxop"&&(ve.innerHTML=Oa),ql=M(e),Ge=u(e,"P",{"data-svelte-h":!0}),T(Ge)!=="svelte-17z8p9g"&&(Ge.innerHTML=Ka),Nl=M(e),We=u(e,"OL",{"data-svelte-h":!0}),T(We)!=="svelte-texlss"&&(We.innerHTML=en),Vl=M(e),Re=u(e,"P",{"data-svelte-h":!0}),T(Re)!=="svelte-y1gm8a"&&(Re.innerHTML=tn),Sl=M(e),w(ze.$$.fragment,e),El=M(e),Xe=u(e,"P",{"data-svelte-h":!0}),T(Xe)!=="svelte-nuf72i"&&(Xe.innerHTML=ln),Ql=M(e),w(ye.$$.fragment,e),Hl=M(e),ke=u(e,"P",{"data-svelte-h":!0}),T(ke)!=="svelte-7kafjj"&&(ke.innerHTML=sn),xl=M(e),w(ce.$$.fragment,e),Yl=M(e),w(qe.$$.fragment,e),Fl=M(e),Ne=u(e,"P",{"data-svelte-h":!0}),T(Ne)!=="svelte-1yvixx2"&&(Ne.innerHTML=an),Ll=M(e),Ve=u(e,"P",{"data-svelte-h":!0}),T(Ve)!=="svelte-14zbxsz"&&(Ve.innerHTML=nn),Dl=M(e),Se=u(e,"P",{"data-svelte-h":!0}),T(Se)!=="svelte-1bftyio"&&(Se.innerHTML=on),Pl=M(e),w(Ee.$$.fragment,e),Ol=M(e),w(Qe.$$.fragment,e),Kl=M(e),He=u(e,"P",{"data-svelte-h":!0}),T(He)!=="svelte-t13qkh"&&(He.textContent=rn),es=M(e),w(xe.$$.fragment,e),ts=M(e),Ye=u(e,"P",{"data-svelte-h":!0}),T(Ye)!=="svelte-1pyala7"&&(Ye.textContent=Mn),ls=M(e),Fe=u(e,"OL",{"data-svelte-h":!0}),T(Fe)!=="svelte-4mw7zb"&&(Fe.innerHTML=pn),ss=M(e),w(Le.$$.fragment,e),as=M(e),De=u(e,"P",{"data-svelte-h":!0}),T(De)!=="svelte-8lb90i"&&(De.innerHTML=yn),ns=M(e),w(me.$$.fragment,e),os=M(e),w(ue.$$.fragment,e),is=M(e),w(Pe.$$.fragment,e),rs=M(e),Oe=u(e,"P",{"data-svelte-h":!0}),T(Oe)!=="svelte-j5yqaq"&&(Oe.textContent=cn),Ms=M(e),w(Te.$$.fragment,e),ps=M(e),w(Ke.$$.fragment,e),ys=M(e),et=u(e,"P",{"data-svelte-h":!0}),T(et)!=="svelte-12ncds6"&&(et.innerHTML=mn),cs=M(e),w(tt.$$.fragment,e),ms=M(e),w(lt.$$.fragment,e),us=M(e),st=u(e,"P",{"data-svelte-h":!0}),T(st)!=="svelte-1ql9xpc"&&(st.innerHTML=un),Ts=M(e),w(at.$$.fragment,e),Js=M(e),w(nt.$$.fragment,e),ds=M(e),ot=u(e,"P",{"data-svelte-h":!0}),T(ot)!=="svelte-li9etl"&&(ot.innerHTML=Tn),ws=M(e),w(it.$$.fragment,e),fs=M(e),w(rt.$$.fragment,e),Us=M(e),Mt=u(e,"P",{"data-svelte-h":!0}),T(Mt)!=="svelte-gpfm4j"&&(Mt.textContent=Jn),js=M(e),pt=u(e,"P",{"data-svelte-h":!0}),T(pt)!=="svelte-mvoza6"&&(pt.textContent=dn),hs=M(e),yt=u(e,"P",{"data-svelte-h":!0}),T(yt)!=="svelte-1ulbaso"&&(yt.textContent=wn),Is=M(e),ct=u(e,"P",{"data-svelte-h":!0}),T(ct)!=="svelte-b2p3xv"&&(ct.innerHTML=fn),Cs=M(e),w(mt.$$.fragment,e),bs=M(e),w(ut.$$.fragment,e),gs=M(e),Tt=u(e,"P",{"data-svelte-h":!0}),T(Tt)!=="svelte-4v19kt"&&(Tt.innerHTML=Un),$s=M(e),Jt=u(e,"P",{"data-svelte-h":!0}),T(Jt)!=="svelte-1270bwq"&&(Jt.innerHTML=jn),As=M(e),w(Je.$$.fragment,e),Bs=M(e),w(dt.$$.fragment,e),_s=M(e),wt=u(e,"P",{"data-svelte-h":!0}),T(wt)!=="svelte-1vvv5pa"&&(wt.innerHTML=hn),Zs=M(e),ft=u(e,"P",{"data-svelte-h":!0}),T(ft)!=="svelte-mp54lp"&&(ft.innerHTML=In),vs=M(e),w(Ut.$$.fragment,e),Gs=M(e),jt=u(e,"P",{"data-svelte-h":!0}),T(jt)!=="svelte-19muhuq"&&(jt.innerHTML=Cn),Ws=M(e),w(de.$$.fragment,e),Rs=M(e),w(ht.$$.fragment,e),zs=M(e),It=u(e,"P",{"data-svelte-h":!0}),T(It)!=="svelte-ow6xqy"&&(It.textContent=bn),Xs=M(e),w(Ct.$$.fragment,e),ks=M(e),bt=u(e,"P",{"data-svelte-h":!0}),T(bt)!=="svelte-xfixmf"&&(bt.textContent=gn),qs=M(e),w(gt.$$.fragment,e),Ns=M(e),w($t.$$.fragment,e),Vs=M(e),At=u(e,"P",{"data-svelte-h":!0}),T(At)!=="svelte-4dix30"&&(At.innerHTML=$n),Ss=M(e),w(Bt.$$.fragment,e),Es=M(e),_t=u(e,"P",{"data-svelte-h":!0}),T(_t)!=="svelte-1fw1nb2"&&(_t.textContent=An),Qs=M(e),w(Zt.$$.fragment,e),Hs=M(e),vt=u(e,"P",{"data-svelte-h":!0}),T(vt)!=="svelte-xvblu4"&&(vt.innerHTML=Bn),xs=M(e),w(Gt.$$.fragment,e),Ys=M(e),Wt=u(e,"P",{"data-svelte-h":!0}),T(Wt)!=="svelte-1dkflot"&&(Wt.innerHTML=_n),Fs=M(e),w(Rt.$$.fragment,e),Ls=M(e),w(zt.$$.fragment,e),Ds=M(e),Xt=u(e,"P",{"data-svelte-h":!0}),T(Xt)!=="svelte-v8wycf"&&(Xt.innerHTML=Zn),Ps=M(e),w(we.$$.fragment,e),Os=M(e),w(kt.$$.fragment,e),Ks=M(e),qt=u(e,"P",{"data-svelte-h":!0}),T(qt)!=="svelte-1cd47xa"&&(qt.innerHTML=vn),ea=M(e),Nt=u(e,"P",{"data-svelte-h":!0}),T(Nt)!=="svelte-1tp1ibg"&&(Nt.innerHTML=Gn),ta=M(e),Vt=u(e,"P",{"data-svelte-h":!0}),T(Vt)!=="svelte-1h6w6yj"&&(Vt.innerHTML=Wn),la=M(e),w(St.$$.fragment,e),sa=M(e),w(Et.$$.fragment,e),aa=M(e),Qt=u(e,"P",{"data-svelte-h":!0}),T(Qt)!=="svelte-139nt83"&&(Qt.innerHTML=Rn),na=M(e),w(fe.$$.fragment,e),oa=M(e),Ht=u(e,"P",{"data-svelte-h":!0}),T(Ht)!=="svelte-1u0t2ts"&&(Ht.innerHTML=zn),ia=M(e),w(Ue.$$.fragment,e),ra=M(e),w(xt.$$.fragment,e),Ma=M(e),Yt=u(e,"P",{"data-svelte-h":!0}),T(Yt)!=="svelte-hjlyem"&&(Yt.innerHTML=Xn),pa=M(e),Ft=u(e,"P",{"data-svelte-h":!0}),T(Ft)!=="svelte-o4r1i6"&&(Ft.textContent=kn),ya=M(e),Lt=u(e,"UL",{"data-svelte-h":!0}),T(Lt)!=="svelte-1bodp8e"&&(Lt.innerHTML=qn),ca=M(e),Dt=u(e,"P",{"data-svelte-h":!0}),T(Dt)!=="svelte-a62ak4"&&(Dt.innerHTML=Nn),ma=M(e),w(Pt.$$.fragment,e),ua=M(e),Ot=u(e,"P",{"data-svelte-h":!0}),T(Ot)!=="svelte-15z7rtv"&&(Ot.textContent=Vn),Ta=M(e),w(Kt.$$.fragment,e),Ja=M(e),el=u(e,"P",{"data-svelte-h":!0}),T(el)!=="svelte-sp9gkx"&&(el.textContent=Sn),da=M(e),w(tl.$$.fragment,e),wa=M(e),ll=u(e,"P",{"data-svelte-h":!0}),T(ll)!=="svelte-1hfmlz"&&(ll.innerHTML=En),fa=M(e),sl=u(e,"P",{"data-svelte-h":!0}),T(sl)!=="svelte-1fhttxy"&&(sl.innerHTML=Qn),Ua=M(e),w(al.$$.fragment,e),ja=M(e),nl=u(e,"P",{"data-svelte-h":!0}),T(nl)!=="svelte-12ltrno"&&(nl.innerHTML=Hn),ha=M(e),ol=u(e,"P",{"data-svelte-h":!0}),T(ol)!=="svelte-13gytjz"&&(ol.textContent=xn),Ia=M(e),il=u(e,"UL",{"data-svelte-h":!0}),T(il)!=="svelte-sugpct"&&(il.innerHTML=Yn),Ca=M(e),w(rl.$$.fragment,e),ba=M(e),Ml=u(e,"UL",{"data-svelte-h":!0}),T(Ml)!=="svelte-1mmu83y"&&(Ml.innerHTML=Fn),ga=M(e),pl=u(e,"P",{"data-svelte-h":!0}),T(pl)!=="svelte-oia8x0"&&(pl.textContent=Ln),$a=M(e),w(yl.$$.fragment,e),Aa=M(e),cl=u(e,"P",{"data-svelte-h":!0}),T(cl)!=="svelte-1yhr0cr"&&(cl.innerHTML=Dn),Ba=M(e),ml=u(e,"P",{"data-svelte-h":!0}),T(ml)!=="svelte-1s2gzku"&&(ml.innerHTML=Pn),_a=M(e),w(ul.$$.fragment,e),Za=M(e),Tl=u(e,"P",{"data-svelte-h":!0}),T(Tl)!=="svelte-4mvvb2"&&(Tl.textContent=On),va=M(e),Jl=u(e,"P",{"data-svelte-h":!0}),T(Jl)!=="svelte-7me63n"&&(Jl.textContent=Kn),Ga=M(e),w(dl.$$.fragment,e),Wa=M(e),wl=u(e,"P",{"data-svelte-h":!0}),T(wl)!=="svelte-1livx4i"&&(wl.innerHTML=eo),Ra=M(e),w(fl.$$.fragment,e),za=M(e),Ul=u(e,"P",{"data-svelte-h":!0}),T(Ul)!=="svelte-1fiingf"&&(Ul.innerHTML=to),Xa=M(e),w(jl.$$.fragment,e),ka=M(e),hl=u(e,"P",{"data-svelte-h":!0}),T(hl)!=="svelte-1ufcnmq"&&(hl.innerHTML=lo),qa=M(e),Il=u(e,"P",{"data-svelte-h":!0}),T(Il)!=="svelte-khzrsx"&&(Il.textContent=so),Na=M(e),Cl=u(e,"UL",{"data-svelte-h":!0}),T(Cl)!=="svelte-o0yfva"&&(Cl.innerHTML=ao),Va=M(e),w(bl.$$.fragment,e),Sa=M(e),gl=u(e,"P",{}),Uo(gl).forEach(t),this.h()},h(){jo(s,"name","hf:doc:metadata"),jo(s,"content",Ji)},m(e,a){$o(document.head,s),l(e,c,a),l(e,n,a),l(e,p,a),f(o,e,a),l(e,i,a),l(e,y,a),l(e,I,a),l(e,B,a),l(e,G,a),l(e,R,a),l(e,_,a),l(e,k,a),l(e,Z,a),f(A,e,a),l(e,V,a),l(e,H,a),l(e,P,a),f(F,e,a),l(e,x,a),f(K,e,a),l(e,ee,a),f(E,e,a),l(e,te,a),l(e,Q,a),l(e,$,a),f(X,e,a),l(e,se,a),l(e,le,a),l(e,oe,a),l(e,L,a),l(e,C,a),f(z,e,a),l(e,he,a),l(e,ne,a),l(e,$l,a),l(e,Ie,a),l(e,Al,a),l(e,Ce,a),l(e,Bl,a),l(e,be,a),l(e,_l,a),l(e,ge,a),l(e,Zl,a),f($e,e,a),l(e,vl,a),l(e,Ae,a),l(e,Gl,a),f(Me,e,a),l(e,Wl,a),l(e,Be,a),l(e,Rl,a),f(pe,e,a),l(e,zl,a),f(_e,e,a),l(e,Xl,a),l(e,Ze,a),l(e,kl,a),l(e,ve,a),l(e,ql,a),l(e,Ge,a),l(e,Nl,a),l(e,We,a),l(e,Vl,a),l(e,Re,a),l(e,Sl,a),f(ze,e,a),l(e,El,a),l(e,Xe,a),l(e,Ql,a),f(ye,e,a),l(e,Hl,a),l(e,ke,a),l(e,xl,a),f(ce,e,a),l(e,Yl,a),f(qe,e,a),l(e,Fl,a),l(e,Ne,a),l(e,Ll,a),l(e,Ve,a),l(e,Dl,a),l(e,Se,a),l(e,Pl,a),f(Ee,e,a),l(e,Ol,a),f(Qe,e,a),l(e,Kl,a),l(e,He,a),l(e,es,a),f(xe,e,a),l(e,ts,a),l(e,Ye,a),l(e,ls,a),l(e,Fe,a),l(e,ss,a),f(Le,e,a),l(e,as,a),l(e,De,a),l(e,ns,a),f(me,e,a),l(e,os,a),f(ue,e,a),l(e,is,a),f(Pe,e,a),l(e,rs,a),l(e,Oe,a),l(e,Ms,a),f(Te,e,a),l(e,ps,a),f(Ke,e,a),l(e,ys,a),l(e,et,a),l(e,cs,a),f(tt,e,a),l(e,ms,a),f(lt,e,a),l(e,us,a),l(e,st,a),l(e,Ts,a),f(at,e,a),l(e,Js,a),f(nt,e,a),l(e,ds,a),l(e,ot,a),l(e,ws,a),f(it,e,a),l(e,fs,a),f(rt,e,a),l(e,Us,a),l(e,Mt,a),l(e,js,a),l(e,pt,a),l(e,hs,a),l(e,yt,a),l(e,Is,a),l(e,ct,a),l(e,Cs,a),f(mt,e,a),l(e,bs,a),f(ut,e,a),l(e,gs,a),l(e,Tt,a),l(e,$s,a),l(e,Jt,a),l(e,As,a),f(Je,e,a),l(e,Bs,a),f(dt,e,a),l(e,_s,a),l(e,wt,a),l(e,Zs,a),l(e,ft,a),l(e,vs,a),f(Ut,e,a),l(e,Gs,a),l(e,jt,a),l(e,Ws,a),f(de,e,a),l(e,Rs,a),f(ht,e,a),l(e,zs,a),l(e,It,a),l(e,Xs,a),f(Ct,e,a),l(e,ks,a),l(e,bt,a),l(e,qs,a),f(gt,e,a),l(e,Ns,a),f($t,e,a),l(e,Vs,a),l(e,At,a),l(e,Ss,a),f(Bt,e,a),l(e,Es,a),l(e,_t,a),l(e,Qs,a),f(Zt,e,a),l(e,Hs,a),l(e,vt,a),l(e,xs,a),f(Gt,e,a),l(e,Ys,a),l(e,Wt,a),l(e,Fs,a),f(Rt,e,a),l(e,Ls,a),f(zt,e,a),l(e,Ds,a),l(e,Xt,a),l(e,Ps,a),f(we,e,a),l(e,Os,a),f(kt,e,a),l(e,Ks,a),l(e,qt,a),l(e,ea,a),l(e,Nt,a),l(e,ta,a),l(e,Vt,a),l(e,la,a),f(St,e,a),l(e,sa,a),f(Et,e,a),l(e,aa,a),l(e,Qt,a),l(e,na,a),f(fe,e,a),l(e,oa,a),l(e,Ht,a),l(e,ia,a),f(Ue,e,a),l(e,ra,a),f(xt,e,a),l(e,Ma,a),l(e,Yt,a),l(e,pa,a),l(e,Ft,a),l(e,ya,a),l(e,Lt,a),l(e,ca,a),l(e,Dt,a),l(e,ma,a),f(Pt,e,a),l(e,ua,a),l(e,Ot,a),l(e,Ta,a),f(Kt,e,a),l(e,Ja,a),l(e,el,a),l(e,da,a),f(tl,e,a),l(e,wa,a),l(e,ll,a),l(e,fa,a),l(e,sl,a),l(e,Ua,a),f(al,e,a),l(e,ja,a),l(e,nl,a),l(e,ha,a),l(e,ol,a),l(e,Ia,a),l(e,il,a),l(e,Ca,a),f(rl,e,a),l(e,ba,a),l(e,Ml,a),l(e,ga,a),l(e,pl,a),l(e,$a,a),f(yl,e,a),l(e,Aa,a),l(e,cl,a),l(e,Ba,a),l(e,ml,a),l(e,_a,a),f(ul,e,a),l(e,Za,a),l(e,Tl,a),l(e,va,a),l(e,Jl,a),l(e,Ga,a),f(dl,e,a),l(e,Wa,a),l(e,wl,a),l(e,Ra,a),f(fl,e,a),l(e,za,a),l(e,Ul,a),l(e,Xa,a),f(jl,e,a),l(e,ka,a),l(e,hl,a),l(e,qa,a),l(e,Il,a),l(e,Na,a),l(e,Cl,a),l(e,Va,a),f(bl,e,a),l(e,Sa,a),l(e,gl,a),Ea=!0},p(e,[a]){const no={};a&2&&(no.$$scope={dirty:a,ctx:e}),F.$set(no);const oo={};a&2&&(oo.$$scope={dirty:a,ctx:e}),K.$set(oo);const io={};a&2&&(io.$$scope={dirty:a,ctx:e}),Me.$set(io);const ro={};a&2&&(ro.$$scope={dirty:a,ctx:e}),pe.$set(ro);const Mo={};a&2&&(Mo.$$scope={dirty:a,ctx:e}),ye.$set(Mo);const po={};a&2&&(po.$$scope={dirty:a,ctx:e}),ce.$set(po);const yo={};a&2&&(yo.$$scope={dirty:a,ctx:e}),me.$set(yo);const co={};a&2&&(co.$$scope={dirty:a,ctx:e}),ue.$set(co);const mo={};a&2&&(mo.$$scope={dirty:a,ctx:e}),Te.$set(mo);const uo={};a&2&&(uo.$$scope={dirty:a,ctx:e}),Je.$set(uo);const To={};a&2&&(To.$$scope={dirty:a,ctx:e}),de.$set(To);const Jo={};a&2&&(Jo.$$scope={dirty:a,ctx:e}),we.$set(Jo);const wo={};a&2&&(wo.$$scope={dirty:a,ctx:e}),fe.$set(wo);const fo={};a&2&&(fo.$$scope={dirty:a,ctx:e}),Ue.$set(fo)},i(e){Ea||(U(o.$$.fragment,e),U(A.$$.fragment,e),U(F.$$.fragment,e),U(K.$$.fragment,e),U(E.$$.fragment,e),U(X.$$.fragment,e),U(z.$$.fragment,e),U($e.$$.fragment,e),U(Me.$$.fragment,e),U(pe.$$.fragment,e),U(_e.$$.fragment,e),U(ze.$$.fragment,e),U(ye.$$.fragment,e),U(ce.$$.fragment,e),U(qe.$$.fragment,e),U(Ee.$$.fragment,e),U(Qe.$$.fragment,e),U(xe.$$.fragment,e),U(Le.$$.fragment,e),U(me.$$.fragment,e),U(ue.$$.fragment,e),U(Pe.$$.fragment,e),U(Te.$$.fragment,e),U(Ke.$$.fragment,e),U(tt.$$.fragment,e),U(lt.$$.fragment,e),U(at.$$.fragment,e),U(nt.$$.fragment,e),U(it.$$.fragment,e),U(rt.$$.fragment,e),U(mt.$$.fragment,e),U(ut.$$.fragment,e),U(Je.$$.fragment,e),U(dt.$$.fragment,e),U(Ut.$$.fragment,e),U(de.$$.fragment,e),U(ht.$$.fragment,e),U(Ct.$$.fragment,e),U(gt.$$.fragment,e),U($t.$$.fragment,e),U(Bt.$$.fragment,e),U(Zt.$$.fragment,e),U(Gt.$$.fragment,e),U(Rt.$$.fragment,e),U(zt.$$.fragment,e),U(we.$$.fragment,e),U(kt.$$.fragment,e),U(St.$$.fragment,e),U(Et.$$.fragment,e),U(fe.$$.fragment,e),U(Ue.$$.fragment,e),U(xt.$$.fragment,e),U(Pt.$$.fragment,e),U(Kt.$$.fragment,e),U(tl.$$.fragment,e),U(al.$$.fragment,e),U(rl.$$.fragment,e),U(yl.$$.fragment,e),U(ul.$$.fragment,e),U(dl.$$.fragment,e),U(fl.$$.fragment,e),U(jl.$$.fragment,e),U(bl.$$.fragment,e),Ea=!0)},o(e){j(o.$$.fragment,e),j(A.$$.fragment,e),j(F.$$.fragment,e),j(K.$$.fragment,e),j(E.$$.fragment,e),j(X.$$.fragment,e),j(z.$$.fragment,e),j($e.$$.fragment,e),j(Me.$$.fragment,e),j(pe.$$.fragment,e),j(_e.$$.fragment,e),j(ze.$$.fragment,e),j(ye.$$.fragment,e),j(ce.$$.fragment,e),j(qe.$$.fragment,e),j(Ee.$$.fragment,e),j(Qe.$$.fragment,e),j(xe.$$.fragment,e),j(Le.$$.fragment,e),j(me.$$.fragment,e),j(ue.$$.fragment,e),j(Pe.$$.fragment,e),j(Te.$$.fragment,e),j(Ke.$$.fragment,e),j(tt.$$.fragment,e),j(lt.$$.fragment,e),j(at.$$.fragment,e),j(nt.$$.fragment,e),j(it.$$.fragment,e),j(rt.$$.fragment,e),j(mt.$$.fragment,e),j(ut.$$.fragment,e),j(Je.$$.fragment,e),j(dt.$$.fragment,e),j(Ut.$$.fragment,e),j(de.$$.fragment,e),j(ht.$$.fragment,e),j(Ct.$$.fragment,e),j(gt.$$.fragment,e),j($t.$$.fragment,e),j(Bt.$$.fragment,e),j(Zt.$$.fragment,e),j(Gt.$$.fragment,e),j(Rt.$$.fragment,e),j(zt.$$.fragment,e),j(we.$$.fragment,e),j(kt.$$.fragment,e),j(St.$$.fragment,e),j(Et.$$.fragment,e),j(fe.$$.fragment,e),j(Ue.$$.fragment,e),j(xt.$$.fragment,e),j(Pt.$$.fragment,e),j(Kt.$$.fragment,e),j(tl.$$.fragment,e),j(al.$$.fragment,e),j(rl.$$.fragment,e),j(yl.$$.fragment,e),j(ul.$$.fragment,e),j(dl.$$.fragment,e),j(fl.$$.fragment,e),j(jl.$$.fragment,e),j(bl.$$.fragment,e),Ea=!1},d(e){e&&(t(c),t(n),t(p),t(i),t(y),t(I),t(B),t(G),t(R),t(_),t(k),t(Z),t(V),t(H),t(P),t(x),t(ee),t(te),t(Q),t($),t(se),t(le),t(oe),t(L),t(C),t(he),t(ne),t($l),t(Ie),t(Al),t(Ce),t(Bl),t(be),t(_l),t(ge),t(Zl),t(vl),t(Ae),t(Gl),t(Wl),t(Be),t(Rl),t(zl),t(Xl),t(Ze),t(kl),t(ve),t(ql),t(Ge),t(Nl),t(We),t(Vl),t(Re),t(Sl),t(El),t(Xe),t(Ql),t(Hl),t(ke),t(xl),t(Yl),t(Fl),t(Ne),t(Ll),t(Ve),t(Dl),t(Se),t(Pl),t(Ol),t(Kl),t(He),t(es),t(ts),t(Ye),t(ls),t(Fe),t(ss),t(as),t(De),t(ns),t(os),t(is),t(rs),t(Oe),t(Ms),t(ps),t(ys),t(et),t(cs),t(ms),t(us),t(st),t(Ts),t(Js),t(ds),t(ot),t(ws),t(fs),t(Us),t(Mt),t(js),t(pt),t(hs),t(yt),t(Is),t(ct),t(Cs),t(bs),t(gs),t(Tt),t($s),t(Jt),t(As),t(Bs),t(_s),t(wt),t(Zs),t(ft),t(vs),t(Gs),t(jt),t(Ws),t(Rs),t(zs),t(It),t(Xs),t(ks),t(bt),t(qs),t(Ns),t(Vs),t(At),t(Ss),t(Es),t(_t),t(Qs),t(Hs),t(vt),t(xs),t(Ys),t(Wt),t(Fs),t(Ls),t(Ds),t(Xt),t(Ps),t(Os),t(Ks),t(qt),t(ea),t(Nt),t(ta),t(Vt),t(la),t(sa),t(aa),t(Qt),t(na),t(oa),t(Ht),t(ia),t(ra),t(Ma),t(Yt),t(pa),t(Ft),t(ya),t(Lt),t(ca),t(Dt),t(ma),t(ua),t(Ot),t(Ta),t(Ja),t(el),t(da),t(wa),t(ll),t(fa),t(sl),t(Ua),t(ja),t(nl),t(ha),t(ol),t(Ia),t(il),t(Ca),t(ba),t(Ml),t(ga),t(pl),t($a),t(Aa),t(cl),t(Ba),t(ml),t(_a),t(Za),t(Tl),t(va),t(Jl),t(Ga),t(Wa),t(wl),t(Ra),t(za),t(Ul),t(Xa),t(ka),t(hl),t(qa),t(Il),t(Na),t(Cl),t(Va),t(Sa),t(gl)),t(s),h(o,e),h(A,e),h(F,e),h(K,e),h(E,e),h(X,e),h(z,e),h($e,e),h(Me,e),h(pe,e),h(_e,e),h(ze,e),h(ye,e),h(ce,e),h(qe,e),h(Ee,e),h(Qe,e),h(xe,e),h(Le,e),h(me,e),h(ue,e),h(Pe,e),h(Te,e),h(Ke,e),h(tt,e),h(lt,e),h(at,e),h(nt,e),h(it,e),h(rt,e),h(mt,e),h(ut,e),h(Je,e),h(dt,e),h(Ut,e),h(de,e),h(ht,e),h(Ct,e),h(gt,e),h($t,e),h(Bt,e),h(Zt,e),h(Gt,e),h(Rt,e),h(zt,e),h(we,e),h(kt,e),h(St,e),h(Et,e),h(fe,e),h(Ue,e),h(xt,e),h(Pt,e),h(Kt,e),h(tl,e),h(al,e),h(rl,e),h(yl,e),h(ul,e),h(dl,e),h(fl,e),h(jl,e),h(bl,e)}}}const Ji='{"title":"DeepSpeed","local":"deepspeed","sections":[{"title":"Installation","local":"installation","sections":[],"depth":2},{"title":"Memory requirements","local":"memory-requirements","sections":[],"depth":2},{"title":"Select a ZeRO stage","local":"select-a-zero-stage","sections":[],"depth":2},{"title":"DeepSpeed configuration file","local":"deepspeed-configuration-file","sections":[{"title":"DeepSpeed and Trainer parameters","local":"deepspeed-and-trainer-parameters","sections":[],"depth":3},{"title":"ZeRO configuration","local":"zero-configuration","sections":[],"depth":3},{"title":"NVMe configuration","local":"nvme-configuration","sections":[],"depth":3}],"depth":2},{"title":"DeepSpeed features","local":"deepspeed-features","sections":[{"title":"Activation/gradient checkpointing","local":"activationgradient-checkpointing","sections":[],"depth":3},{"title":"Optimizer and scheduler","local":"optimizer-and-scheduler","sections":[],"depth":3},{"title":"Precision","local":"precision","sections":[],"depth":3},{"title":"Batch size","local":"batch-size","sections":[],"depth":3},{"title":"Gradient accumulation","local":"gradient-accumulation","sections":[],"depth":3},{"title":"Gradient clipping","local":"gradient-clipping","sections":[],"depth":3},{"title":"Communication data type","local":"communication-data-type","sections":[],"depth":3}],"depth":2},{"title":"Deployment","local":"deployment","sections":[{"title":"Multi-node deployment","local":"multi-node-deployment","sections":[],"depth":3},{"title":"SLURM","local":"slurm","sections":[],"depth":3},{"title":"Notebook","local":"notebook","sections":[],"depth":3}],"depth":2},{"title":"Save model weights","local":"save-model-weights","sections":[{"title":"Online","local":"online","sections":[],"depth":3},{"title":"Offline","local":"offline","sections":[],"depth":3}],"depth":2},{"title":"ZeRO Inference","local":"zero-inference","sections":[],"depth":2},{"title":"Non-Trainer DeepSpeed integration","local":"non-trainer-deepspeed-integration","sections":[{"title":"Non-Trainer ZeRO Inference","local":"non-trainer-zero-inference","sections":[],"depth":3},{"title":"Generate","local":"generate","sections":[],"depth":3}],"depth":2},{"title":"Troubleshoot","local":"troubleshoot","sections":[{"title":"DeepSpeed process killed at startup","local":"deepspeed-process-killed-at-startup","sections":[],"depth":3},{"title":"NaN loss","local":"nan-loss","sections":[],"depth":3}],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2}],"depth":1}';function di(g){return Io(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ci extends Co{constructor(s){super(),bo(this,s,di,Ti,ho,{})}}export{Ci as component};
