import{s as ce,o as le,n as ee}from"../chunks/scheduler.defa9a21.js";import{S as ie,i as ue,g as f,s as l,r as b,A as de,h as g,f as a,c as i,j as N,u as $,x as E,k as H,y as z,a as c,v,d as x,t as w,w as k}from"../chunks/index.fe795e71.js";import{T as re}from"../chunks/Tip.179eb360.js";import{D as se}from"../chunks/Docstring.07f3d703.js";import{C as me}from"../chunks/CodeBlock.42404125.js";import{E as pe}from"../chunks/ExampleCodeBlock.54a2eac1.js";import{H as O,E as fe}from"../chunks/EditOnGithub.0f575778.js";function ge(T){let t,m=`To use this function absolutely zero calls to a CUDA device must be made in the notebook session before calling. If
any have been made, you will need to restart the notebook and make sure no cells use any CUDA capability.`,s,r,u=`Setting <code>ACCELERATE_DEBUG_MODE=&quot;1&quot;</code> in your environment will run a test before truly launching to ensure that none
of those calls have been made.`;return{c(){t=f("p"),t.textContent=m,s=l(),r=f("p"),r.innerHTML=u},l(n){t=g(n,"P",{"data-svelte-h":!0}),E(t)!=="svelte-izav3m"&&(t.textContent=m),s=i(n),r=g(n,"P",{"data-svelte-h":!0}),E(r)!=="svelte-18vojj9"&&(r.innerHTML=u)},m(n,d){c(n,t,d),c(n,s,d),c(n,r,d)},p:ee,d(n){n&&(a(t),a(s),a(r))}}}function he(T){let t,m="Example:",s,r,u;return r=new me({props:{code:"JTIzJTIwQXNzdW1lJTIwdGhpcyUyMGlzJTIwZGVmaW5lZCUyMGluJTIwYSUyMEp1cHl0ZXIlMjBOb3RlYm9vayUyMG9uJTIwYW4lMjBpbnN0YW5jZSUyMHdpdGglMjB0d28lMjBHUFVzJTBBZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBub3RlYm9va19sYXVuY2hlciUwQSUwQSUwQWRlZiUyMHRyYWluKCphcmdzKSUzQSUwQSUyMCUyMCUyMCUyMCUyMyUyMFlvdXIlMjB0cmFpbmluZyUyMGZ1bmN0aW9uJTIwaGVyZSUwQSUyMCUyMCUyMCUyMC4uLiUwQSUwQSUwQW5vdGVib29rX2xhdW5jaGVyKHRyYWluJTJDJTIwYXJncyUzRChhcmcxJTJDJTIwYXJnMiklMkMlMjBudW1fcHJvY2Vzc2VzJTNEMiUyQyUyMG1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjIp",highlighted:`<span class="hljs-comment"># Assume this is defined in a Jupyter Notebook on an instance with two GPUs</span>
<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> notebook_launcher


<span class="hljs-keyword">def</span> <span class="hljs-title function_">train</span>(<span class="hljs-params">*args</span>):
    <span class="hljs-comment"># Your training function here</span>
    ...


notebook_launcher(train, args=(arg1, arg2), num_processes=<span class="hljs-number">2</span>, mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>)`,wrap:!1}}),{c(){t=f("p"),t.textContent=m,s=l(),b(r.$$.fragment)},l(n){t=g(n,"P",{"data-svelte-h":!0}),E(t)!=="svelte-11lpom8"&&(t.textContent=m),s=i(n),$(r.$$.fragment,n)},m(n,d){c(n,t,d),c(n,s,d),v(r,n,d),u=!0},p:ee,i(n){u||(x(r.$$.fragment,n),u=!0)},o(n){w(r.$$.fragment,n),u=!1},d(n){n&&(a(t),a(s)),k(r,n)}}}function _e(T){let t,m=`This function is provided for internal testing and debugging, but it’s not intended for real trainings. It will
only use the CPU.`;return{c(){t=f("p"),t.textContent=m},l(s){t=g(s,"P",{"data-svelte-h":!0}),E(t)!=="svelte-3x34in"&&(t.textContent=m)},m(s,r){c(s,t,r)},p:ee,d(s){s&&a(t)}}}function be(T){let t,m,s,r,u,n,d,te="Functions for launching training on distributed processes.",Y,j,D,p,P,X,I,ne=`Launches a training function, using several processes or multiple nodes if it’s possible in the current environment
(TPU with multiple cores for instance).`,A,U,R,C,W,J,Q,h,G,F,S,oe="Launches a training function using several processes on CPU for debugging purposes.",K,M,V,q,Z,B,L;return u=new O({props:{title:"Launchers",local:"launchers",headingTag:"h1"}}),j=new O({props:{title:"notebook_launcher",local:"accelerate.notebook_launcher",headingTag:"h2"}}),P=new se({props:{name:"accelerate.notebook_launcher",anchor:"accelerate.notebook_launcher",parameters:[{name:"function",val:""},{name:"args",val:" = ()"},{name:"num_processes",val:" = None"},{name:"mixed_precision",val:" = 'no'"},{name:"use_port",val:" = '29500'"},{name:"master_addr",val:" = '127.0.0.1'"},{name:"node_rank",val:" = 0"},{name:"num_nodes",val:" = 1"},{name:"rdzv_backend",val:" = 'static'"},{name:"rdzv_endpoint",val:" = ''"},{name:"rdzv_conf",val:" = None"},{name:"rdzv_id",val:" = 'none'"},{name:"max_restarts",val:" = 0"},{name:"monitor_interval",val:" = 0.1"},{name:"log_line_prefix_template",val:" = None"}],parametersDescription:[{anchor:"accelerate.notebook_launcher.function",description:`<strong>function</strong> (<code>Callable</code>) &#x2014;
The training function to execute. If it accepts arguments, the first argument should be the index of the
process run.`,name:"function"},{anchor:"accelerate.notebook_launcher.args",description:`<strong>args</strong> (<code>Tuple</code>) &#x2014;
Tuple of arguments to pass to the function (it will receive <code>*args</code>).`,name:"args"},{anchor:"accelerate.notebook_launcher.num_processes",description:`<strong>num_processes</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The number of processes to use for training. Will default to 8 in Colab/Kaggle if a TPU is available, to
the number of GPUs available otherwise.`,name:"num_processes"},{anchor:"accelerate.notebook_launcher.mixed_precision",description:`<strong>mixed_precision</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;no&quot;</code>) &#x2014;
If <code>fp16</code> or <code>bf16</code>, will use mixed precision training on multi-GPU.`,name:"mixed_precision"},{anchor:"accelerate.notebook_launcher.use_port",description:`<strong>use_port</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;29500&quot;</code>) &#x2014;
The port to use to communicate between processes when launching a multi-GPU training.`,name:"use_port"},{anchor:"accelerate.notebook_launcher.master_addr",description:`<strong>master_addr</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;127.0.0.1&quot;</code>) &#x2014;
The address to use for communication between processes.`,name:"master_addr"},{anchor:"accelerate.notebook_launcher.node_rank",description:`<strong>node_rank</strong> (<code>int</code>, <em>optional</em>, defaults to 0) &#x2014;
The rank of the current node.`,name:"node_rank"},{anchor:"accelerate.notebook_launcher.num_nodes",description:`<strong>num_nodes</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of nodes to use for training.`,name:"num_nodes"},{anchor:"accelerate.notebook_launcher.rdzv_backend",description:`<strong>rdzv_backend</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;static&quot;</code>) &#x2014;
The rendezvous method to use, such as &#x2018;static&#x2019; (the default) or &#x2018;c10d&#x2019;`,name:"rdzv_backend"},{anchor:"accelerate.notebook_launcher.rdzv_endpoint",description:`<strong>rdzv_endpoint</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&quot;</code>) &#x2014;
The endpoint of the rdzv sync. storage.`,name:"rdzv_endpoint"},{anchor:"accelerate.notebook_launcher.rdzv_conf",description:`<strong>rdzv_conf</strong> (<code>Dict</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
Additional rendezvous configuration.`,name:"rdzv_conf"},{anchor:"accelerate.notebook_launcher.rdzv_id",description:`<strong>rdzv_id</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;none&quot;</code>) &#x2014;
The unique run id of the job.`,name:"rdzv_id"},{anchor:"accelerate.notebook_launcher.max_restarts",description:`<strong>max_restarts</strong> (<code>int</code>, <em>optional</em>, defaults to 0) &#x2014;
The maximum amount of restarts that elastic agent will conduct on workers before failure.`,name:"max_restarts"},{anchor:"accelerate.notebook_launcher.monitor_interval",description:`<strong>monitor_interval</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The interval in seconds that is used by the elastic_agent as a period of monitoring workers.`,name:"monitor_interval"},{anchor:"accelerate.notebook_launcher.log_line_prefix_template",description:`<strong>log_line_prefix_template</strong> (<code>str</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
The prefix template for elastic launch logging. Available from PyTorch 2.2.0.`,name:"log_line_prefix_template"}],source:"https://github.com/huggingface/accelerate/blob/v1.2.1/src/accelerate/launchers.py#L40"}}),U=new re({props:{warning:!0,$$slots:{default:[ge]},$$scope:{ctx:T}}}),C=new pe({props:{anchor:"accelerate.notebook_launcher.example",$$slots:{default:[he]},$$scope:{ctx:T}}}),J=new O({props:{title:"debug_launcher",local:"accelerate.debug_launcher",headingTag:"h2"}}),G=new se({props:{name:"accelerate.debug_launcher",anchor:"accelerate.debug_launcher",parameters:[{name:"function",val:""},{name:"args",val:" = ()"},{name:"num_processes",val:" = 2"}],parametersDescription:[{anchor:"accelerate.debug_launcher.function",description:`<strong>function</strong> (<code>Callable</code>) &#x2014;
The training function to execute.`,name:"function"},{anchor:"accelerate.debug_launcher.args",description:`<strong>args</strong> (<code>Tuple</code>) &#x2014;
Tuple of arguments to pass to the function (it will receive <code>*args</code>).`,name:"args"},{anchor:"accelerate.debug_launcher.num_processes",description:`<strong>num_processes</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The number of processes to use for training.`,name:"num_processes"}],source:"https://github.com/huggingface/accelerate/blob/v1.2.1/src/accelerate/launchers.py#L269"}}),M=new re({props:{warning:!0,$$slots:{default:[_e]},$$scope:{ctx:T}}}),q=new fe({props:{source:"https://github.com/huggingface/accelerate/blob/main/docs/source/package_reference/launchers.md"}}),{c(){t=f("meta"),m=l(),s=f("p"),r=l(),b(u.$$.fragment),n=l(),d=f("p"),d.textContent=te,Y=l(),b(j.$$.fragment),D=l(),p=f("div"),b(P.$$.fragment),X=l(),I=f("p"),I.textContent=ne,A=l(),b(U.$$.fragment),R=l(),b(C.$$.fragment),W=l(),b(J.$$.fragment),Q=l(),h=f("div"),b(G.$$.fragment),F=l(),S=f("p"),S.textContent=oe,K=l(),b(M.$$.fragment),V=l(),b(q.$$.fragment),Z=l(),B=f("p"),this.h()},l(e){const o=de("svelte-u9bgzb",document.head);t=g(o,"META",{name:!0,content:!0}),o.forEach(a),m=i(e),s=g(e,"P",{}),N(s).forEach(a),r=i(e),$(u.$$.fragment,e),n=i(e),d=g(e,"P",{"data-svelte-h":!0}),E(d)!=="svelte-7doq2e"&&(d.textContent=te),Y=i(e),$(j.$$.fragment,e),D=i(e),p=g(e,"DIV",{class:!0});var _=N(p);$(P.$$.fragment,_),X=i(_),I=g(_,"P",{"data-svelte-h":!0}),E(I)!=="svelte-9bm6uy"&&(I.textContent=ne),A=i(_),$(U.$$.fragment,_),R=i(_),$(C.$$.fragment,_),_.forEach(a),W=i(e),$(J.$$.fragment,e),Q=i(e),h=g(e,"DIV",{class:!0});var y=N(h);$(G.$$.fragment,y),F=i(y),S=g(y,"P",{"data-svelte-h":!0}),E(S)!=="svelte-1urs4mm"&&(S.textContent=oe),K=i(y),$(M.$$.fragment,y),y.forEach(a),V=i(e),$(q.$$.fragment,e),Z=i(e),B=g(e,"P",{}),N(B).forEach(a),this.h()},h(){H(t,"name","hf:doc:metadata"),H(t,"content",$e),H(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(h,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,o){z(document.head,t),c(e,m,o),c(e,s,o),c(e,r,o),v(u,e,o),c(e,n,o),c(e,d,o),c(e,Y,o),v(j,e,o),c(e,D,o),c(e,p,o),v(P,p,null),z(p,X),z(p,I),z(p,A),v(U,p,null),z(p,R),v(C,p,null),c(e,W,o),v(J,e,o),c(e,Q,o),c(e,h,o),v(G,h,null),z(h,F),z(h,S),z(h,K),v(M,h,null),c(e,V,o),v(q,e,o),c(e,Z,o),c(e,B,o),L=!0},p(e,[o]){const _={};o&2&&(_.$$scope={dirty:o,ctx:e}),U.$set(_);const y={};o&2&&(y.$$scope={dirty:o,ctx:e}),C.$set(y);const ae={};o&2&&(ae.$$scope={dirty:o,ctx:e}),M.$set(ae)},i(e){L||(x(u.$$.fragment,e),x(j.$$.fragment,e),x(P.$$.fragment,e),x(U.$$.fragment,e),x(C.$$.fragment,e),x(J.$$.fragment,e),x(G.$$.fragment,e),x(M.$$.fragment,e),x(q.$$.fragment,e),L=!0)},o(e){w(u.$$.fragment,e),w(j.$$.fragment,e),w(P.$$.fragment,e),w(U.$$.fragment,e),w(C.$$.fragment,e),w(J.$$.fragment,e),w(G.$$.fragment,e),w(M.$$.fragment,e),w(q.$$.fragment,e),L=!1},d(e){e&&(a(m),a(s),a(r),a(n),a(d),a(Y),a(D),a(p),a(W),a(Q),a(h),a(V),a(Z),a(B)),a(t),k(u,e),k(j,e),k(P),k(U),k(C),k(J,e),k(G),k(M),k(q,e)}}}const $e='{"title":"Launchers","local":"launchers","sections":[{"title":"notebook_launcher","local":"accelerate.notebook_launcher","sections":[],"depth":2},{"title":"debug_launcher","local":"accelerate.debug_launcher","sections":[],"depth":2}],"depth":1}';function ve(T){return le(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Me extends ie{constructor(t){super(),ue(this,t,ve,be,ce,{})}}export{Me as component};
