import{s as Ua,o as ba,n as C}from"../chunks/scheduler.25b97de1.js";import{S as _a,i as Za,g as p,s as r,r as M,A as $a,h as c,f as t,c as i,j as Ja,u as d,x as m,k as ga,y as Ca,a as l,v as h,d as u,t as y,w as f,m as Ba,n as Xa}from"../chunks/index.d9030fc9.js";import{T as Js}from"../chunks/Tip.baa67368.js";import{C as U}from"../chunks/CodeBlock.e6cd0d95.js";import{H as $,E as Wa}from"../chunks/EditOnGithub.91d95064.js";import{H as ja,a as gs}from"../chunks/HfOption.1e589c90.js";function Ia(j){let a,o='In addition to the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class, Transformers also provides a <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Seq2SeqTrainer">Seq2SeqTrainer</a> class for sequence-to-sequence tasks like translation or summarization. There is also the <a href="https://huggingface.co/docs/trl/main/en/sft_trainer#trl.SFTTrainer" rel="nofollow">SFTTrainer</a> class from the <a href="https://hf.co/docs/trl" rel="nofollow">TRL</a> library which wraps the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class and is optimized for training language models like Llama-2 and Mistral with autoregressive techniques. <a href="https://huggingface.co/docs/trl/main/en/sft_trainer#trl.SFTTrainer" rel="nofollow">SFTTrainer</a> also supports features like sequence packing, LoRA, quantization, and DeepSpeed for efficiently scaling to any model size.',n,T,w,g,b='Feel free to check out the <a href="./main_classes/trainer">API reference</a> for these other <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>-type classes to learn more about when to use which one. In general, <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> is the most versatile option and is appropriate for a broad spectrum of tasks. <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Seq2SeqTrainer">Seq2SeqTrainer</a> is designed for sequence-to-sequence tasks and <a href="https://huggingface.co/docs/trl/main/en/sft_trainer#trl.SFTTrainer" rel="nofollow">SFTTrainer</a> is designed for training language models.';return{c(){a=p("p"),a.innerHTML=o,n=r(),T=p("br"),w=r(),g=p("p"),g.innerHTML=b},l(Z){a=c(Z,"P",{"data-svelte-h":!0}),m(a)!=="svelte-15ihuvx"&&(a.innerHTML=o),n=i(Z),T=c(Z,"BR",{}),w=i(Z),g=c(Z,"P",{"data-svelte-h":!0}),m(g)!=="svelte-j40fee"&&(g.innerHTML=b)},m(Z,J){l(Z,a,J),l(Z,n,J),l(Z,T,J),l(Z,w,J),l(Z,g,J)},p:C,d(Z){Z&&(t(a),t(n),t(T),t(w),t(g))}}}function ka(j){let a,o='Check out the <a href="./main_classes/logging">logging</a> API reference for more information about the different logging levels.';return{c(){a=p("p"),a.innerHTML=o},l(n){a=c(n,"P",{"data-svelte-h":!0}),m(a)!=="svelte-6jeeaq"&&(a.innerHTML=o)},m(n,T){l(n,a,T)},p:C,d(n){n&&t(a)}}}function Ea(j){let a,o='<a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> sets the log level separately for each node in the <code>Trainer.__init__()</code> method, so you may want to consider setting this sooner if you’re using other Transformers functionalities before creating the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> object.';return{c(){a=p("p"),a.innerHTML=o},l(n){a=c(n,"P",{"data-svelte-h":!0}),m(a)!=="svelte-cqiynt"&&(a.innerHTML=o)},m(n,T){l(n,a,T)},p:C,d(n){n&&t(a)}}}function va(j){let a,o;return a=new U({props:{code:"bXlfYXBwLnB5JTIwLi4uJTIwLS1sb2dfbGV2ZWwlMjB3YXJuaW5nJTIwLS1sb2dfbGV2ZWxfcmVwbGljYSUyMGVycm9y",highlighted:"my_app.py ... --log_level warning --log_level_replica error",wrap:!1}}),{c(){M(a.$$.fragment)},l(n){d(a.$$.fragment,n)},m(n,T){h(a,n,T),o=!0},p:C,i(n){o||(u(a.$$.fragment,n),o=!0)},o(n){y(a.$$.fragment,n),o=!1},d(n){f(a,n)}}}function Fa(j){let a,o="Add the <code>log_on_each_node 0</code> parameter for multi-node environments.",n,T,w;return T=new U({props:{code:"bXlfYXBwLnB5JTIwLi4uJTIwLS1sb2dfbGV2ZWwlMjB3YXJuaW5nJTIwLS1sb2dfbGV2ZWxfcmVwbGljYSUyMGVycm9yJTIwLS1sb2dfb25fZWFjaF9ub2RlJTIwMCUwQSUwQSUyMyUyMHNldCUyMHRvJTIwb25seSUyMHJlcG9ydCUyMGVycm9ycyUwQW15X2FwcC5weSUyMC4uLiUyMC0tbG9nX2xldmVsJTIwZXJyb3IlMjAtLWxvZ19sZXZlbF9yZXBsaWNhJTIwZXJyb3IlMjAtLWxvZ19vbl9lYWNoX25vZGUlMjAw",highlighted:`my_app.py ... --log_level warning --log_level_replica error --log_on_each_node 0

<span class="hljs-comment"># set to only report errors</span>
my_app.py ... --log_level error --log_level_replica error --log_on_each_node 0`,wrap:!1}}),{c(){a=p("p"),a.innerHTML=o,n=r(),M(T.$$.fragment)},l(g){a=c(g,"P",{"data-svelte-h":!0}),m(a)!=="svelte-86ubk0"&&(a.innerHTML=o),n=i(g),d(T.$$.fragment,g)},m(g,b){l(g,a,b),l(g,n,b),h(T,g,b),w=!0},p:C,i(g){w||(u(T.$$.fragment,g),w=!0)},o(g){y(T.$$.fragment,g),w=!1},d(g){g&&(t(a),t(n)),f(T,g)}}}function Ra(j){let a,o,n,T;return a=new gs({props:{id:"logging",option:"single node",$$slots:{default:[va]},$$scope:{ctx:j}}}),n=new gs({props:{id:"logging",option:"multi-node",$$slots:{default:[Fa]},$$scope:{ctx:j}}}),{c(){M(a.$$.fragment),o=r(),M(n.$$.fragment)},l(w){d(a.$$.fragment,w),o=i(w),d(n.$$.fragment,w)},m(w,g){h(a,w,g),l(w,o,g),h(n,w,g),T=!0},p(w,g){const b={};g&2&&(b.$$scope={dirty:g,ctx:w}),a.$set(b);const Z={};g&2&&(Z.$$scope={dirty:g,ctx:w}),n.$set(Z)},i(w){T||(u(a.$$.fragment,w),u(n.$$.fragment,w),T=!0)},o(w){y(a.$$.fragment,w),y(n.$$.fragment,w),T=!1},d(w){w&&t(o),f(a,w),f(n,w)}}}function Ga(j){let a;return{c(){a=Ba("Gain +20% throughput and reduce memory usage by 60% on LLaMA 3-8B model training. Achieve longer context lengths and larger batch sizes. It’s also useful if you want to scale up your model to multi-head training or large vocabulary sizes. Unleash multi-head training (medusa) and more. See details and examples in [Liger](https://github.com/linkedin/Liger-Kernel/tree/main/examples)")},l(o){a=Xa(o,"Gain +20% throughput and reduce memory usage by 60% on LLaMA 3-8B model training. Achieve longer context lengths and larger batch sizes. It’s also useful if you want to scale up your model to multi-head training or large vocabulary sizes. Unleash multi-head training (medusa) and more. See details and examples in [Liger](https://github.com/linkedin/Liger-Kernel/tree/main/examples)")},m(o,n){l(o,a,n)},d(o){o&&t(a)}}}function Va(j){let a,o="According to the authors, it is recommended to use <code>AdaLomo</code> without <code>grad_norm</code> to get better performance and higher throughput.";return{c(){a=p("p"),a.innerHTML=o},l(n){a=c(n,"P",{"data-svelte-h":!0}),m(a)!=="svelte-q6vma3"&&(a.innerHTML=o)},m(n,T){l(n,a,T)},p:C,d(n){n&&t(a)}}}function Aa(j){let a,o="GrokAdamW is particularly useful for models that require advanced optimization techniques to achieve better performance and stability.";return{c(){a=p("p"),a.textContent=o},l(n){a=c(n,"P",{"data-svelte-h":!0}),m(a)!=="svelte-kys0va"&&(a.textContent=o)},m(n,T){l(n,a,T)},p:C,d(n){n&&t(a)}}}function Qa(j){let a,o='Learn more about FSDP sharding strategies, CPU offloading, and more with the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> in the <a href="fsdp">Fully Sharded Data Parallel</a> guide.';return{c(){a=p("p"),a.innerHTML=o},l(n){a=c(n,"P",{"data-svelte-h":!0}),m(a)!=="svelte-1bk7spl"&&(a.innerHTML=o)},m(n,T){l(n,a,T)},p:C,d(n){n&&t(a)}}}function Na(j){let a,o;return a=new U({props:{code:"Y29tcHV0ZV9lbnZpcm9ubWVudCUzQSUyMExPQ0FMX01BQ0hJTkUlMEFkaXN0cmlidXRlZF90eXBlJTNBJTIwTVVMVElfR1BVJTBBZG93bmNhc3RfYmYxNiUzQSUyMCdubyclMEFncHVfaWRzJTNBJTIwYWxsJTBBbWFjaGluZV9yYW5rJTNBJTIwMCUyMCUyM2NoYW5nZSUyMHJhbmslMjBhcyUyMHBlciUyMHRoZSUyMG5vZGUlMEFtYWluX3Byb2Nlc3NfaXAlM0ElMjAxOTIuMTY4LjIwLjElMEFtYWluX3Byb2Nlc3NfcG9ydCUzQSUyMDk4OTglMEFtYWluX3RyYWluaW5nX2Z1bmN0aW9uJTNBJTIwbWFpbiUwQW1peGVkX3ByZWNpc2lvbiUzQSUyMGZwMTYlMEFudW1fbWFjaGluZXMlM0ElMjAyJTBBbnVtX3Byb2Nlc3NlcyUzQSUyMDglMEFyZHp2X2JhY2tlbmQlM0ElMjBzdGF0aWMlMEFzYW1lX25ldHdvcmslM0ElMjB0cnVlJTBBdHB1X2VudiUzQSUyMCU1QiU1RCUwQXRwdV91c2VfY2x1c3RlciUzQSUyMGZhbHNlJTBBdHB1X3VzZV9zdWRvJTNBJTIwZmFsc2UlMEF1c2VfY3B1JTNBJTIwZmFsc2U=",highlighted:`<span class="hljs-attr">compute_environment:</span> <span class="hljs-string">LOCAL_MACHINE</span>
<span class="hljs-attr">distributed_type:</span> <span class="hljs-string">MULTI_GPU</span>
<span class="hljs-attr">downcast_bf16:</span> <span class="hljs-string">&#x27;no&#x27;</span>
<span class="hljs-attr">gpu_ids:</span> <span class="hljs-string">all</span>
<span class="hljs-attr">machine_rank:</span> <span class="hljs-number">0</span> <span class="hljs-comment">#change rank as per the node</span>
<span class="hljs-attr">main_process_ip:</span> <span class="hljs-number">192.168</span><span class="hljs-number">.20</span><span class="hljs-number">.1</span>
<span class="hljs-attr">main_process_port:</span> <span class="hljs-number">9898</span>
<span class="hljs-attr">main_training_function:</span> <span class="hljs-string">main</span>
<span class="hljs-attr">mixed_precision:</span> <span class="hljs-string">fp16</span>
<span class="hljs-attr">num_machines:</span> <span class="hljs-number">2</span>
<span class="hljs-attr">num_processes:</span> <span class="hljs-number">8</span>
<span class="hljs-attr">rdzv_backend:</span> <span class="hljs-string">static</span>
<span class="hljs-attr">same_network:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">tpu_env:</span> []
<span class="hljs-attr">tpu_use_cluster:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">tpu_use_sudo:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">use_cpu:</span> <span class="hljs-literal">false</span>`,wrap:!1}}),{c(){M(a.$$.fragment)},l(n){d(a.$$.fragment,n)},m(n,T){h(a,n,T),o=!0},p:C,i(n){o||(u(a.$$.fragment,n),o=!0)},o(n){y(a.$$.fragment,n),o=!1},d(n){f(a,n)}}}function za(j){let a,o;return a=new U({props:{code:"Y29tcHV0ZV9lbnZpcm9ubWVudCUzQSUyMExPQ0FMX01BQ0hJTkUlMEFkaXN0cmlidXRlZF90eXBlJTNBJTIwRlNEUCUwQWRvd25jYXN0X2JmMTYlM0ElMjAnbm8nJTBBZnNkcF9jb25maWclM0ElMEElMjAlMjBmc2RwX2F1dG9fd3JhcF9wb2xpY3klM0ElMjBUUkFOU0ZPUk1FUl9CQVNFRF9XUkFQJTBBJTIwJTIwZnNkcF9iYWNrd2FyZF9wcmVmZXRjaF9wb2xpY3klM0ElMjBCQUNLV0FSRF9QUkUlMEElMjAlMjBmc2RwX2ZvcndhcmRfcHJlZmV0Y2glM0ElMjB0cnVlJTBBJTIwJTIwZnNkcF9vZmZsb2FkX3BhcmFtcyUzQSUyMGZhbHNlJTBBJTIwJTIwZnNkcF9zaGFyZGluZ19zdHJhdGVneSUzQSUyMDElMEElMjAlMjBmc2RwX3N0YXRlX2RpY3RfdHlwZSUzQSUyMEZVTExfU1RBVEVfRElDVCUwQSUyMCUyMGZzZHBfc3luY19tb2R1bGVfc3RhdGVzJTNBJTIwdHJ1ZSUwQSUyMCUyMGZzZHBfdHJhbnNmb3JtZXJfbGF5ZXJfY2xzX3RvX3dyYXAlM0ElMjBCZXJ0TGF5ZXIlMEElMjAlMjBmc2RwX3VzZV9vcmlnX3BhcmFtcyUzQSUyMHRydWUlMEFtYWNoaW5lX3JhbmslM0ElMjAwJTBBbWFpbl90cmFpbmluZ19mdW5jdGlvbiUzQSUyMG1haW4lMEFtaXhlZF9wcmVjaXNpb24lM0ElMjBiZjE2JTBBbnVtX21hY2hpbmVzJTNBJTIwMSUwQW51bV9wcm9jZXNzZXMlM0ElMjAyJTBBcmR6dl9iYWNrZW5kJTNBJTIwc3RhdGljJTBBc2FtZV9uZXR3b3JrJTNBJTIwdHJ1ZSUwQXRwdV9lbnYlM0ElMjAlNUIlNUQlMEF0cHVfdXNlX2NsdXN0ZXIlM0ElMjBmYWxzZSUwQXRwdV91c2Vfc3VkbyUzQSUyMGZhbHNlJTBBdXNlX2NwdSUzQSUyMGZhbHNl",highlighted:`<span class="hljs-attr">compute_environment:</span> <span class="hljs-string">LOCAL_MACHINE</span>
<span class="hljs-attr">distributed_type:</span> <span class="hljs-string">FSDP</span>
<span class="hljs-attr">downcast_bf16:</span> <span class="hljs-string">&#x27;no&#x27;</span>
<span class="hljs-attr">fsdp_config:</span>
  <span class="hljs-attr">fsdp_auto_wrap_policy:</span> <span class="hljs-string">TRANSFORMER_BASED_WRAP</span>
  <span class="hljs-attr">fsdp_backward_prefetch_policy:</span> <span class="hljs-string">BACKWARD_PRE</span>
  <span class="hljs-attr">fsdp_forward_prefetch:</span> <span class="hljs-literal">true</span>
  <span class="hljs-attr">fsdp_offload_params:</span> <span class="hljs-literal">false</span>
  <span class="hljs-attr">fsdp_sharding_strategy:</span> <span class="hljs-number">1</span>
  <span class="hljs-attr">fsdp_state_dict_type:</span> <span class="hljs-string">FULL_STATE_DICT</span>
  <span class="hljs-attr">fsdp_sync_module_states:</span> <span class="hljs-literal">true</span>
  <span class="hljs-attr">fsdp_transformer_layer_cls_to_wrap:</span> <span class="hljs-string">BertLayer</span>
  <span class="hljs-attr">fsdp_use_orig_params:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">machine_rank:</span> <span class="hljs-number">0</span>
<span class="hljs-attr">main_training_function:</span> <span class="hljs-string">main</span>
<span class="hljs-attr">mixed_precision:</span> <span class="hljs-string">bf16</span>
<span class="hljs-attr">num_machines:</span> <span class="hljs-number">1</span>
<span class="hljs-attr">num_processes:</span> <span class="hljs-number">2</span>
<span class="hljs-attr">rdzv_backend:</span> <span class="hljs-string">static</span>
<span class="hljs-attr">same_network:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">tpu_env:</span> []
<span class="hljs-attr">tpu_use_cluster:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">tpu_use_sudo:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">use_cpu:</span> <span class="hljs-literal">false</span>`,wrap:!1}}),{c(){M(a.$$.fragment)},l(n){d(a.$$.fragment,n)},m(n,T){h(a,n,T),o=!0},p:C,i(n){o||(u(a.$$.fragment,n),o=!0)},o(n){y(a.$$.fragment,n),o=!1},d(n){f(a,n)}}}function Ya(j){let a,o;return a=new U({props:{code:"Y29tcHV0ZV9lbnZpcm9ubWVudCUzQSUyMExPQ0FMX01BQ0hJTkUlMEFkZWVwc3BlZWRfY29uZmlnJTNBJTBBJTIwJTIwZGVlcHNwZWVkX2NvbmZpZ19maWxlJTNBJTIwJTJGaG9tZSUyRnVzZXIlMkZjb25maWdzJTJGZHNfemVybzNfY29uZmlnLmpzb24lMEElMjAlMjB6ZXJvM19pbml0X2ZsYWclM0ElMjB0cnVlJTBBZGlzdHJpYnV0ZWRfdHlwZSUzQSUyMERFRVBTUEVFRCUwQWRvd25jYXN0X2JmMTYlM0ElMjAnbm8nJTBBbWFjaGluZV9yYW5rJTNBJTIwMCUwQW1haW5fdHJhaW5pbmdfZnVuY3Rpb24lM0ElMjBtYWluJTBBbnVtX21hY2hpbmVzJTNBJTIwMSUwQW51bV9wcm9jZXNzZXMlM0ElMjA0JTBBcmR6dl9iYWNrZW5kJTNBJTIwc3RhdGljJTBBc2FtZV9uZXR3b3JrJTNBJTIwdHJ1ZSUwQXRwdV9lbnYlM0ElMjAlNUIlNUQlMEF0cHVfdXNlX2NsdXN0ZXIlM0ElMjBmYWxzZSUwQXRwdV91c2Vfc3VkbyUzQSUyMGZhbHNlJTBBdXNlX2NwdSUzQSUyMGZhbHNl",highlighted:`<span class="hljs-attr">compute_environment:</span> <span class="hljs-string">LOCAL_MACHINE</span>
<span class="hljs-attr">deepspeed_config:</span>
  <span class="hljs-attr">deepspeed_config_file:</span> <span class="hljs-string">/home/user/configs/ds_zero3_config.json</span>
  <span class="hljs-attr">zero3_init_flag:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">distributed_type:</span> <span class="hljs-string">DEEPSPEED</span>
<span class="hljs-attr">downcast_bf16:</span> <span class="hljs-string">&#x27;no&#x27;</span>
<span class="hljs-attr">machine_rank:</span> <span class="hljs-number">0</span>
<span class="hljs-attr">main_training_function:</span> <span class="hljs-string">main</span>
<span class="hljs-attr">num_machines:</span> <span class="hljs-number">1</span>
<span class="hljs-attr">num_processes:</span> <span class="hljs-number">4</span>
<span class="hljs-attr">rdzv_backend:</span> <span class="hljs-string">static</span>
<span class="hljs-attr">same_network:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">tpu_env:</span> []
<span class="hljs-attr">tpu_use_cluster:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">tpu_use_sudo:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">use_cpu:</span> <span class="hljs-literal">false</span>`,wrap:!1}}),{c(){M(a.$$.fragment)},l(n){d(a.$$.fragment,n)},m(n,T){h(a,n,T),o=!0},p:C,i(n){o||(u(a.$$.fragment,n),o=!0)},o(n){y(a.$$.fragment,n),o=!1},d(n){f(a,n)}}}function Sa(j){let a,o;return a=new U({props:{code:"Y29tcHV0ZV9lbnZpcm9ubWVudCUzQSUyMExPQ0FMX01BQ0hJTkUlMEFkZWVwc3BlZWRfY29uZmlnJTNBJTBBJTIwJTIwZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNBJTIwMSUwQSUyMCUyMGdyYWRpZW50X2NsaXBwaW5nJTNBJTIwMC43JTBBJTIwJTIwb2ZmbG9hZF9vcHRpbWl6ZXJfZGV2aWNlJTNBJTIwY3B1JTBBJTIwJTIwb2ZmbG9hZF9wYXJhbV9kZXZpY2UlM0ElMjBjcHUlMEElMjAlMjB6ZXJvM19pbml0X2ZsYWclM0ElMjB0cnVlJTBBJTIwJTIwemVyb19zdGFnZSUzQSUyMDIlMEFkaXN0cmlidXRlZF90eXBlJTNBJTIwREVFUFNQRUVEJTBBZG93bmNhc3RfYmYxNiUzQSUyMCdubyclMEFtYWNoaW5lX3JhbmslM0ElMjAwJTBBbWFpbl90cmFpbmluZ19mdW5jdGlvbiUzQSUyMG1haW4lMEFtaXhlZF9wcmVjaXNpb24lM0ElMjBiZjE2JTBBbnVtX21hY2hpbmVzJTNBJTIwMSUwQW51bV9wcm9jZXNzZXMlM0ElMjA0JTBBcmR6dl9iYWNrZW5kJTNBJTIwc3RhdGljJTBBc2FtZV9uZXR3b3JrJTNBJTIwdHJ1ZSUwQXRwdV9lbnYlM0ElMjAlNUIlNUQlMEF0cHVfdXNlX2NsdXN0ZXIlM0ElMjBmYWxzZSUwQXRwdV91c2Vfc3VkbyUzQSUyMGZhbHNlJTBBdXNlX2NwdSUzQSUyMGZhbHNl",highlighted:`<span class="hljs-attr">compute_environment:</span> <span class="hljs-string">LOCAL_MACHINE</span>
<span class="hljs-attr">deepspeed_config:</span>
  <span class="hljs-attr">gradient_accumulation_steps:</span> <span class="hljs-number">1</span>
  <span class="hljs-attr">gradient_clipping:</span> <span class="hljs-number">0.7</span>
  <span class="hljs-attr">offload_optimizer_device:</span> <span class="hljs-string">cpu</span>
  <span class="hljs-attr">offload_param_device:</span> <span class="hljs-string">cpu</span>
  <span class="hljs-attr">zero3_init_flag:</span> <span class="hljs-literal">true</span>
  <span class="hljs-attr">zero_stage:</span> <span class="hljs-number">2</span>
<span class="hljs-attr">distributed_type:</span> <span class="hljs-string">DEEPSPEED</span>
<span class="hljs-attr">downcast_bf16:</span> <span class="hljs-string">&#x27;no&#x27;</span>
<span class="hljs-attr">machine_rank:</span> <span class="hljs-number">0</span>
<span class="hljs-attr">main_training_function:</span> <span class="hljs-string">main</span>
<span class="hljs-attr">mixed_precision:</span> <span class="hljs-string">bf16</span>
<span class="hljs-attr">num_machines:</span> <span class="hljs-number">1</span>
<span class="hljs-attr">num_processes:</span> <span class="hljs-number">4</span>
<span class="hljs-attr">rdzv_backend:</span> <span class="hljs-string">static</span>
<span class="hljs-attr">same_network:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">tpu_env:</span> []
<span class="hljs-attr">tpu_use_cluster:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">tpu_use_sudo:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">use_cpu:</span> <span class="hljs-literal">false</span>`,wrap:!1}}),{c(){M(a.$$.fragment)},l(n){d(a.$$.fragment,n)},m(n,T){h(a,n,T),o=!0},p:C,i(n){o||(u(a.$$.fragment,n),o=!0)},o(n){y(a.$$.fragment,n),o=!1},d(n){f(a,n)}}}function Ha(j){let a,o,n,T,w,g,b,Z;return a=new gs({props:{id:"config",option:"DistributedDataParallel",$$slots:{default:[Na]},$$scope:{ctx:j}}}),n=new gs({props:{id:"config",option:"FSDP",$$slots:{default:[za]},$$scope:{ctx:j}}}),w=new gs({props:{id:"config",option:"DeepSpeed",$$slots:{default:[Ya]},$$scope:{ctx:j}}}),b=new gs({props:{id:"config",option:"DeepSpeed with Accelerate plugin",$$slots:{default:[Sa]},$$scope:{ctx:j}}}),{c(){M(a.$$.fragment),o=r(),M(n.$$.fragment),T=r(),M(w.$$.fragment),g=r(),M(b.$$.fragment)},l(J){d(a.$$.fragment,J),o=i(J),d(n.$$.fragment,J),T=i(J),d(w.$$.fragment,J),g=i(J),d(b.$$.fragment,J)},m(J,_){h(a,J,_),l(J,o,_),h(n,J,_),l(J,T,_),h(w,J,_),l(J,g,_),h(b,J,_),Z=!0},p(J,_){const G={};_&2&&(G.$$scope={dirty:_,ctx:J}),a.$set(G);const B={};_&2&&(B.$$scope={dirty:_,ctx:J}),n.$set(B);const js={};_&2&&(js.$$scope={dirty:_,ctx:J}),w.$set(js);const V={};_&2&&(V.$$scope={dirty:_,ctx:J}),b.$set(V)},i(J){Z||(u(a.$$.fragment,J),u(n.$$.fragment,J),u(w.$$.fragment,J),u(b.$$.fragment,J),Z=!0)},o(J){y(a.$$.fragment,J),y(n.$$.fragment,J),y(w.$$.fragment,J),y(b.$$.fragment,J),Z=!1},d(J){J&&(t(o),t(T),t(g)),f(a,J),f(n,J),f(w,J),f(b,J)}}}function xa(j){let a,o,n,T,w,g,b,Z='The <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> is a complete training and evaluation loop for PyTorch models implemented in the Transformers library. You only need to pass it the necessary pieces for training (model, tokenizer, dataset, evaluation function, training hyperparameters, etc.), and the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class takes care of the rest. This makes it easier to start training faster without manually writing your own training loop. But at the same time, <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> is very customizable and offers a ton of training options so you can tailor it to your exact training needs.',J,_,G,B,js='Before you start, make sure <a href="https://hf.co/docs/accelerate" rel="nofollow">Accelerate</a> - a library for enabling and running PyTorch training across distributed environments - is installed.',V,A,bs,Q,dl='This guide provides an overview of the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class.',_s,N,Zs,z,hl='<a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> includes all the code you’ll find in a basic training loop:',$s,Y,ul='<li>perform a training step to calculate the loss</li> <li>calculate the gradients with the <a href="https://huggingface.co/docs/accelerate/main/en/package_reference/accelerator#accelerate.Accelerator.backward" rel="nofollow">backward</a> method</li> <li>update the weights based on the gradients</li> <li>repeat this process until you’ve reached a predetermined number of epochs</li>',Cs,S,yl='The <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class abstracts all of this code away so you don’t have to worry about manually writing a training loop every time or if you’re just getting started with PyTorch and training. You only need to provide the essential components required for training, such as a model and a dataset, and the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class handles everything else.',Bs,H,fl='If you want to specify any training options or hyperparameters, you can find them in the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> class. For example, let’s define where to save the model in <code>output_dir</code> and push the model to the Hub after training with <code>push_to_hub=True</code>.',Xs,x,Ws,L,Tl='Pass <code>training_args</code> to the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> along with a model, dataset, something to preprocess the dataset with (depending on your data type it could be a tokenizer, feature extractor or image processor), a data collator, and a function to compute the metrics you want to track during training.',Is,q,wl='Finally, call <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.train">train()</a> to start training!',ks,D,Es,P,vs,K,Jl='The <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class saves your model checkpoints to the directory specified in the <code>output_dir</code> parameter of <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>. You’ll find the checkpoints saved in a <code>checkpoint-000</code> subfolder where the numbers at the end correspond to the training step. Saving checkpoints are useful for resuming training later.',Fs,O,Rs,ee,gl='You can save your checkpoints (the optimizer state is not saved by default) to the Hub by setting <code>push_to_hub=True</code> in <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> to commit and push them. Other options for deciding how your checkpoints are saved are set up in the <a href="https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments.hub_strategy" rel="nofollow"><code>hub_strategy</code></a> parameter:',Gs,se,jl="<li><code>hub_strategy=&quot;checkpoint&quot;</code> pushes the latest checkpoint to a subfolder named “last-checkpoint” from which you can resume training</li> <li><code>hub_strategy=&quot;all_checkpoints&quot;</code> pushes all checkpoints to the directory defined in <code>output_dir</code> (you’ll see one checkpoint per folder in your model repository)</li>",Vs,te,Ul='When you resume training from a checkpoint, the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> tries to keep the Python, NumPy, and PyTorch RNG states the same as they were when the checkpoint was saved. But because PyTorch has various non-deterministic default settings, the RNG states aren’t guaranteed to be the same. If you want to enable full determinism, take a look at the <a href="https://pytorch.org/docs/stable/notes/randomness#controlling-sources-of-randomness" rel="nofollow">Controlling sources of randomness</a> guide to learn what you can enable to make your training fully deterministic. Keep in mind though that by making certain settings deterministic, training may be slower.',As,le,Qs,ae,bl='While the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class is designed to be accessible and easy-to-use, it also offers a lot of customizability for more adventurous users. Many of the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>’s method can be subclassed and overridden to support the functionality you want, without having to rewrite the entire training loop from scratch to accommodate it. These methods include:',Ns,ne,_l='<li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.get_train_dataloader">get_train_dataloader()</a> creates a training DataLoader</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.get_eval_dataloader">get_eval_dataloader()</a> creates an evaluation DataLoader</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.get_test_dataloader">get_test_dataloader()</a> creates a test DataLoader</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.log">log()</a> logs information on the various objects that watch training</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.create_optimizer_and_scheduler">create_optimizer_and_scheduler()</a> creates an optimizer and learning rate scheduler if they weren’t passed in the <code>__init__</code>; these can also be separately customized with <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.create_optimizer">create_optimizer()</a> and <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.create_scheduler">create_scheduler()</a> respectively</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.compute_loss">compute_loss()</a> computes the loss on a batch of training inputs</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.training_step">training_step()</a> performs the training step</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.prediction_step">prediction_step()</a> performs the prediction and test step</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.evaluate">evaluate()</a> evaluates the model and returns the evaluation metrics</li> <li><a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.predict">predict()</a> makes predictions (with metrics if labels are available) on the test set</li>',zs,re,Zl='For example, if you want to customize the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.compute_loss">compute_loss()</a> method to use a weighted loss instead.',Ys,ie,Ss,oe,Hs,pe,$l='Another option for customizing the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> is to use <a href="callbacks">callbacks</a>. Callbacks <em>don’t change</em> anything in the training loop. They inspect the training loop state and then execute some action (early stopping, logging results, etc.) depending on the state. In other words, a callback can’t be used to implement something like a custom loss function and you’ll need to subclass and override the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer.compute_loss">compute_loss()</a> method for that.',xs,ce,Cl="For example, if you want to add an early stopping callback to the training loop after 10 steps.",Ls,me,qs,Me,Bl='Then pass it to the <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>’s <code>callback</code> parameter.',Ds,de,Ps,he,Ks,X,Os,ue,Xl='The <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> is set to <code>logging.INFO</code> by default which reports errors, warnings, and other basic information. A <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> replica - in distributed environments - is set to <code>logging.WARNING</code> which only reports errors and warnings. You can change the logging level with the <a href="https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments.log_level" rel="nofollow"><code>log_level</code></a> and <a href="https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments.log_level_replica" rel="nofollow"><code>log_level_replica</code></a> parameters in <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>.',et,ye,Wl='To configure the log level setting for each node, use the <a href="https://huggingface.co/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments.log_on_each_node" rel="nofollow"><code>log_on_each_node</code></a> parameter to determine whether to use the log level on each node or only on the main node.',st,W,tt,fe,Il="For example, to set your main code and modules to use the same log level according to each node:",lt,Te,at,we,kl="Use different combinations of <code>log_level</code> and <code>log_level_replica</code> to configure what gets logged on each of the nodes.",nt,I,rt,Je,it,ge,El='<a href="https://hf.co/papers/2310.05914" rel="nofollow">NEFTune</a> is a technique that can improve performance by adding noise to the embedding vectors during training. To enable it in <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>, set the <code>neftune_noise_alpha</code> parameter in <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> to control how much noise is added.',ot,je,pt,Ue,vl="NEFTune is disabled after training to restore the original embedding layer to avoid any unexpected behavior.",ct,be,mt,_e,Fl='<a href="https://github.com/linkedin/Liger-Kernel" rel="nofollow">Liger-Kernel</a> Kernel is a collection of Triton kernels developed by Linkedin designed specifically for LLM training. We have implemented Hugging Face Compatible RMSNorm, RoPE, SwiGLU, CrossEntropy, FusedLinearCrossEntropy, and more to come. It can effectively increase multi-GPU training throughput by 20% and reduces memory usage by 60%. The kernel works out of the box with flash attention, PyTorch FSDP, and Microsoft DeepSpeed.',Mt,k,dt,Ze,Rl="First make sure to install Liger official repository:",ht,$e,ut,Ce,Gl="You should pass <code>use_liger_kernel=True</code> to apply liger kernel on your model, for example:",yt,Be,ft,Xe,Vl='The kernel supports the Llama, Gemma, Mistral, and Mixtral model architectures. The most up-to-date list of supported models can be found <a href="https://github.com/linkedin/Liger-Kernel" rel="nofollow">here</a>. When <code>use_liger_kernel</code> is set to <code>True</code>, the corresponding layers in the original model will be patched with Liger’s efficient implementation, so you don’t need to do anything extra other than setting the argument value.',Tt,We,wt,Ie,Al="You can choose a built-in optimizer for training using:",Jt,ke,gt,Ee,Ql='See <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/training_args.py" rel="nofollow"><code>OptimizerNames</code></a> for a full list of choices. We include advanced examples in the sections below.',jt,ve,Nl="You can also use an arbitrary PyTorch optimizer via:",Ut,Fe,bt,Re,_t,Ge,zl="Gradient Low-Rank Projection (GaLore) is a memory-efficient low-rank training strategy that allows full-parameter learning but is more memory-efficient than common low-rank adaptation methods, such as LoRA.",Zt,Ve,Yl="First make sure to install GaLore official repository:",$t,Ae,Ct,Qe,Sl="Then simply add one of <code>[&quot;galore_adamw&quot;, &quot;galore_adafactor&quot;, &quot;galore_adamw_8bit&quot;]</code> in <code>optim</code> together with <code>optim_target_modules</code>, which can be a list of strings, regex or full path corresponding to the target module names you want to adapt. Below is an end-to-end example script (make sure to <code>pip install trl datasets</code>):",Bt,Ne,Xt,ze,Hl="To pass extra arguments supported by GaLore, you should pass correctly <code>optim_args</code>, for example:",Wt,Ye,It,Se,xl='You can read more about the method in the <a href="https://github.com/jiaweizzhao/GaLore" rel="nofollow">original repository</a> or the <a href="https://arxiv.org/abs/2403.03507" rel="nofollow">paper</a>.',kt,He,Ll="Currently you can only train Linear layers that are considered as GaLore layers and will use low-rank decomposition to be trained while remaining layers will be optimized in the conventional manner.",Et,xe,ql="Note it will take a bit of time before starting the training (~3 minutes for a 2B model on a NVIDIA A100), but training should go smoothly afterwards.",vt,Le,Dl="You can also perform layer-wise optimization by post-pending the optimizer name with <code>layerwise</code> like below:",Ft,qe,Rt,De,Pl='Note layerwise optimization is a bit experimental and does not support DDP (Distributed Data Parallel), thus you can run the training script only on a single GPU. Please see <a href="https://github.com/jiaweizzhao/GaLore?tab=readme-ov-file#train-7b-model-with-a-single-gpu-with-24gb-memory" rel="nofollow">this appropriate section</a> for more details. Other features such as gradient clipping, DeepSpeed, etc might not be supported out of the box. Please <a href="https://github.com/huggingface/transformers/issues" rel="nofollow">raise an issue on GitHub</a> if you encounter such issue.',Gt,Pe,Vt,Ke,Kl=`The LOMO optimizers have been introduced in <a href="https://hf.co/papers/2306.09782" rel="nofollow">Full Parameter Fine-Tuning for Large Language Models with Limited Resources</a> and <a href="https://hf.co/papers/2310.10195" rel="nofollow">AdaLomo: Low-memory Optimization with Adaptive Learning Rate</a>.
They both consist of an efficient full-parameter fine-tuning method. These optimizers fuse the gradient computation and the parameter update in one step to reduce memory usage. Supported optimizers for LOMO are <code>&quot;lomo&quot;</code> and <code>&quot;adalomo&quot;</code>. First either install LOMO from pypi <code>pip install lomo-optim</code> or install it from source with <code>pip install git+https://github.com/OpenLMLab/LOMO.git</code>.`,At,E,Qt,Oe,Ol='Below is a simple script to demonstrate how to fine-tune <a href="https://huggingface.co/google/gemma-2b" rel="nofollow">google/gemma-2b</a> on IMDB dataset in full precision:',Nt,es,zt,ss,Yt,ts,ea="The GrokAdamW optimizer is designed to enhance training performance and stability, particularly for models that benefit from grokking signal functions. To use GrokAdamW, first install the optimizer package with <code>pip install grokadamw</code>.",St,v,Ht,ls,sa='Below is a simple script to demonstrate how to fine-tune <a href="https://huggingface.co/google/gemma-2b" rel="nofollow">google/gemma-2b</a> on the IMDB dataset using the GrokAdamW optimizer:',xt,as,Lt,ns,ta="This script demonstrates how to fine-tune the <code>google/gemma-2b</code> model on the IMDB dataset using the GrokAdamW optimizer. The <code>TrainingArguments</code> are configured to use GrokAdamW, and the dataset is passed to the <code>Trainer</code> for training.",qt,rs,Dt,is,la=`The Schedule Free optimizers have been introduced in <a href="https://hf.co/papers/2405.15682" rel="nofollow">The Road Less Scheduled</a>.
Schedule-Free learning replaces the momentum of the base optimizer with a combination of averaging and interpolation, to completely remove the need to anneal the learning rate with a traditional schedule.
Supported optimizers for SFO are <code>&quot;schedule_free_adamw&quot;</code> and <code>&quot;schedule_free_sgd&quot;</code>. First install schedulefree from pypi <code>pip install schedulefree</code>.`,Pt,os,aa='Below is a simple script to demonstrate how to fine-tune <a href="https://huggingface.co/google/gemma-2b" rel="nofollow">google/gemma-2b</a> on IMDB dataset in full precision:',Kt,ps,Ot,cs,el,ms,na='The <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> class is powered by <a href="https://hf.co/docs/accelerate" rel="nofollow">Accelerate</a>, a library for easily training PyTorch models in distributed environments with support for integrations such as <a href="https://pytorch.org/blog/introducing-pytorch-fully-sharded-data-parallel-api/" rel="nofollow">FullyShardedDataParallel (FSDP)</a> and <a href="https://www.deepspeed.ai/" rel="nofollow">DeepSpeed</a>.',sl,F,tl,Ms,ra='To use Accelerate with <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a>, run the <a href="https://huggingface.co/docs/accelerate/package_reference/cli#accelerate-config" rel="nofollow"><code>accelerate.config</code></a> command to set up training for your training environment. This command creates a <code>config_file.yaml</code> that’ll be used when you launch your training script. For example, some example configurations you can setup are:',ll,R,al,ds,ia='The <a href="https://huggingface.co/docs/accelerate/package_reference/cli#accelerate-launch" rel="nofollow"><code>accelerate_launch</code></a> command is the recommended way to launch your training script on a distributed system with Accelerate and <a href="/docs/transformers/pr_30530/en/main_classes/trainer#transformers.Trainer">Trainer</a> with the parameters specified in <code>config_file.yaml</code>. This file is saved to the Accelerate cache folder and automatically loaded when you run <code>accelerate_launch</code>.',nl,hs,oa='For example, to run the <a href="https://github.com/huggingface/transformers/blob/f4db565b695582891e43a5e042e5d318e28f20b8/examples/pytorch/text-classification/run_glue.py#L4" rel="nofollow">run_glue.py</a> training script with the FSDP configuration:',rl,us,il,ys,pa="You could also specify the parameters from the <code>config_file.yaml</code> file directly in the command line:",ol,fs,pl,Ts,ca='Check out the <a href="https://huggingface.co/docs/accelerate/basic_tutorials/launch" rel="nofollow">Launching your Accelerate scripts</a> tutorial to learn more about <code>accelerate_launch</code> and custom configurations.',cl,ws,ml,Us,Ml;return w=new $({props:{title:"Trainer",local:"trainer",headingTag:"h1"}}),_=new Js({props:{$$slots:{default:[Ia]},$$scope:{ctx:j}}}),A=new U({props:{code:"cGlwJTIwaW5zdGFsbCUyMGFjY2VsZXJhdGUlMEElMEElMjMlMjB1cGdyYWRlJTBBcGlwJTIwaW5zdGFsbCUyMGFjY2VsZXJhdGUlMjAtLXVwZ3JhZGU=",highlighted:`pip install accelerate

<span class="hljs-comment"># upgrade</span>
pip install accelerate --upgrade`,wrap:!1}}),N=new $({props:{title:"Basic usage",local:"basic-usage",headingTag:"h2"}}),x=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjJ5b3VyLW1vZGVsJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfZXZhbF9iYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNEMiUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheSUzRDAuMDElMkMlMEElMjAlMjAlMjAlMjBldmFsX3N0cmF0ZWd5JTNEJTIyZXBvY2glMjIlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0cmF0ZWd5JTNEJTIyZXBvY2glMjIlMkMlMEElMjAlMjAlMjAlMjBsb2FkX2Jlc3RfbW9kZWxfYXRfZW5kJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

training_args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;your-model&quot;</span>,
    learning_rate=<span class="hljs-number">2e-5</span>,
    per_device_train_batch_size=<span class="hljs-number">16</span>,
    per_device_eval_batch_size=<span class="hljs-number">16</span>,
    num_train_epochs=<span class="hljs-number">2</span>,
    weight_decay=<span class="hljs-number">0.01</span>,
    eval_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    load_best_model_at_end=<span class="hljs-literal">True</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),D=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRHRyYWluaW5nX2FyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEZGF0YXNldCU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBwcm9jZXNzaW5nX2NsYXNzJTNEdG9rZW5pemVyJTJDJTBBJTIwJTIwJTIwJTIwZGF0YV9jb2xsYXRvciUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX21ldHJpY3MlM0Rjb21wdXRlX21ldHJpY3MlMkMlMEEpJTBBJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=dataset[<span class="hljs-string">&quot;test&quot;</span>],
    processing_class=tokenizer,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
)

trainer.train()`,wrap:!1}}),P=new $({props:{title:"Checkpoints",local:"checkpoints",headingTag:"h3"}}),O=new U({props:{code:"JTIzJTIwcmVzdW1lJTIwZnJvbSUyMGxhdGVzdCUyMGNoZWNrcG9pbnQlMEF0cmFpbmVyLnRyYWluKHJlc3VtZV9mcm9tX2NoZWNrcG9pbnQlM0RUcnVlKSUwQSUwQSUyMyUyMHJlc3VtZSUyMGZyb20lMjBzcGVjaWZpYyUyMGNoZWNrcG9pbnQlMjBzYXZlZCUyMGluJTIwb3V0cHV0JTIwZGlyZWN0b3J5JTBBdHJhaW5lci50cmFpbihyZXN1bWVfZnJvbV9jaGVja3BvaW50JTNEJTIyeW91ci1tb2RlbCUyRmNoZWNrcG9pbnQtMTAwMCUyMik=",highlighted:`<span class="hljs-comment"># resume from latest checkpoint</span>
trainer.train(resume_from_checkpoint=<span class="hljs-literal">True</span>)

<span class="hljs-comment"># resume from specific checkpoint saved in output directory</span>
trainer.train(resume_from_checkpoint=<span class="hljs-string">&quot;your-model/checkpoint-1000&quot;</span>)`,wrap:!1}}),le=new $({props:{title:"Customize the Trainer",local:"customize-the-trainer",headingTag:"h2"}}),ie=new U({props:{code:"ZnJvbSUyMHRvcmNoJTIwaW1wb3J0JTIwbm4lMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwVHJhaW5lciUwQSUwQWNsYXNzJTIwQ3VzdG9tVHJhaW5lcihUcmFpbmVyKSUzQSUwQSUyMCUyMCUyMCUyMGRlZiUyMGNvbXB1dGVfbG9zcyhzZWxmJTJDJTIwbW9kZWwlMkMlMjBpbnB1dHMlMkMlMjByZXR1cm5fb3V0cHV0cyUzREZhbHNlKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMGlucHV0cy5wb3AoJTIybGFiZWxzJTIyKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMGZvcndhcmQlMjBwYXNzJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvZ2l0cyUyMCUzRCUyMG91dHB1dHMuZ2V0KCUyMmxvZ2l0cyUyMiklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBjb21wdXRlJTIwY3VzdG9tJTIwbG9zcyUyMGZvciUyMDMlMjBsYWJlbHMlMjB3aXRoJTIwZGlmZmVyZW50JTIwd2VpZ2h0cyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvc3NfZmN0JTIwJTNEJTIwbm4uQ3Jvc3NFbnRyb3B5TG9zcyh3ZWlnaHQlM0R0b3JjaC50ZW5zb3IoJTVCMS4wJTJDJTIwMi4wJTJDJTIwMy4wJTVEJTJDJTIwZGV2aWNlJTNEbW9kZWwuZGV2aWNlKSklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb3NzJTIwJTNEJTIwbG9zc19mY3QobG9naXRzLnZpZXcoLTElMkMlMjBzZWxmLm1vZGVsLmNvbmZpZy5udW1fbGFiZWxzKSUyQyUyMGxhYmVscy52aWV3KC0xKSklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXR1cm4lMjAobG9zcyUyQyUyMG91dHB1dHMpJTIwaWYlMjByZXR1cm5fb3V0cHV0cyUyMGVsc2UlMjBsb3Nz",highlighted:`<span class="hljs-keyword">from</span> torch <span class="hljs-keyword">import</span> nn
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer

<span class="hljs-keyword">class</span> <span class="hljs-title class_">CustomTrainer</span>(<span class="hljs-title class_ inherited__">Trainer</span>):
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_loss</span>(<span class="hljs-params">self, model, inputs, return_outputs=<span class="hljs-literal">False</span></span>):
        labels = inputs.pop(<span class="hljs-string">&quot;labels&quot;</span>)
        <span class="hljs-comment"># forward pass</span>
        outputs = model(**inputs)
        logits = outputs.get(<span class="hljs-string">&quot;logits&quot;</span>)
        <span class="hljs-comment"># compute custom loss for 3 labels with different weights</span>
        loss_fct = nn.CrossEntropyLoss(weight=torch.tensor([<span class="hljs-number">1.0</span>, <span class="hljs-number">2.0</span>, <span class="hljs-number">3.0</span>], device=model.device))
        loss = loss_fct(logits.view(-<span class="hljs-number">1</span>, self.model.config.num_labels), labels.view(-<span class="hljs-number">1</span>))
        <span class="hljs-keyword">return</span> (loss, outputs) <span class="hljs-keyword">if</span> return_outputs <span class="hljs-keyword">else</span> loss`,wrap:!1}}),oe=new $({props:{title:"Callbacks",local:"callbacks",headingTag:"h3"}}),me=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXJDYWxsYmFjayUwQSUwQWNsYXNzJTIwRWFybHlTdG9wcGluZ0NhbGxiYWNrKFRyYWluZXJDYWxsYmFjayklM0ElMEElMjAlMjAlMjAlMjBkZWYlMjBfX2luaXRfXyhzZWxmJTJDJTIwbnVtX3N0ZXBzJTNEMTApJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2VsZi5udW1fc3RlcHMlMjAlM0QlMjBudW1fc3RlcHMlMEElMEElMjAlMjAlMjAlMjBkZWYlMjBvbl9zdGVwX2VuZChzZWxmJTJDJTIwYXJncyUyQyUyMHN0YXRlJTJDJTIwY29udHJvbCUyQyUyMCoqa3dhcmdzKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGlmJTIwc3RhdGUuZ2xvYmFsX3N0ZXAlMjAlM0UlM0QlMjBzZWxmLm51bV9zdGVwcyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybiUyMCU3QiUyMnNob3VsZF90cmFpbmluZ19zdG9wJTIyJTNBJTIwVHJ1ZSU3RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGVsc2UlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlN0Q=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainerCallback

<span class="hljs-keyword">class</span> <span class="hljs-title class_">EarlyStoppingCallback</span>(<span class="hljs-title class_ inherited__">TrainerCallback</span>):
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, num_steps=<span class="hljs-number">10</span></span>):
        self.num_steps = num_steps

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">on_step_end</span>(<span class="hljs-params">self, args, state, control, **kwargs</span>):
        <span class="hljs-keyword">if</span> state.global_step &gt;= self.num_steps:
            <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;should_training_stop&quot;</span>: <span class="hljs-literal">True</span>}
        <span class="hljs-keyword">else</span>:
            <span class="hljs-keyword">return</span> {}`,wrap:!1}}),de=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRHRyYWluaW5nX2FyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEZGF0YXNldCU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBwcm9jZXNzaW5nX2NsYXNzJTNEdG9rZW5pemVyJTJDJTBBJTIwJTIwJTIwJTIwZGF0YV9jb2xsYXRvciUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX21ldHJpY3MlM0Rjb21wdXRlX21ldHJpY3MlMkMlMEElMjAlMjAlMjAlMjBjYWxsYmFja3MlM0QlNUJFYXJseVN0b3BwaW5nQ2FsbGJhY2soKSU1RCUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=dataset[<span class="hljs-string">&quot;test&quot;</span>],
    processing_class=tokenizer,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
    callbacks=[EarlyStoppingCallback()],
)`,wrap:!1}}),he=new $({props:{title:"Logging",local:"logging",headingTag:"h2"}}),X=new Js({props:{$$slots:{default:[ka]},$$scope:{ctx:j}}}),W=new Js({props:{$$slots:{default:[Ea]},$$scope:{ctx:j}}}),Te=new U({props:{code:"bG9nZ2VyJTIwJTNEJTIwbG9nZ2luZy5nZXRMb2dnZXIoX19uYW1lX18pJTBBJTBBbG9nZ2luZy5iYXNpY0NvbmZpZyglMEElMjAlMjAlMjAlMjBmb3JtYXQlM0QlMjIlMjUoYXNjdGltZSlzJTIwLSUyMCUyNShsZXZlbG5hbWUpcyUyMC0lMjAlMjUobmFtZSlzJTIwLSUyMCUyNShtZXNzYWdlKXMlMjIlMkMlMEElMjAlMjAlMjAlMjBkYXRlZm10JTNEJTIyJTI1bSUyRiUyNWQlMkYlMjVZJTIwJTI1SCUzQSUyNU0lM0ElMjVTJTIyJTJDJTBBJTIwJTIwJTIwJTIwaGFuZGxlcnMlM0QlNUJsb2dnaW5nLlN0cmVhbUhhbmRsZXIoc3lzLnN0ZG91dCklNUQlMkMlMEEpJTBBJTBBbG9nX2xldmVsJTIwJTNEJTIwdHJhaW5pbmdfYXJncy5nZXRfcHJvY2Vzc19sb2dfbGV2ZWwoKSUwQWxvZ2dlci5zZXRMZXZlbChsb2dfbGV2ZWwpJTBBZGF0YXNldHMudXRpbHMubG9nZ2luZy5zZXRfdmVyYm9zaXR5KGxvZ19sZXZlbCklMEF0cmFuc2Zvcm1lcnMudXRpbHMubG9nZ2luZy5zZXRfdmVyYm9zaXR5KGxvZ19sZXZlbCklMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciguLi4p",highlighted:`logger = logging.getLogger(__name__)

logging.basicConfig(
    <span class="hljs-built_in">format</span>=<span class="hljs-string">&quot;%(asctime)s - %(levelname)s - %(name)s - %(message)s&quot;</span>,
    datefmt=<span class="hljs-string">&quot;%m/%d/%Y %H:%M:%S&quot;</span>,
    handlers=[logging.StreamHandler(sys.stdout)],
)

log_level = training_args.get_process_log_level()
logger.setLevel(log_level)
datasets.utils.logging.set_verbosity(log_level)
transformers.utils.logging.set_verbosity(log_level)

trainer = Trainer(...)`,wrap:!1}}),I=new ja({props:{id:"logging",options:["single node","multi-node"],$$slots:{default:[Ra]},$$scope:{ctx:j}}}),Je=new $({props:{title:"NEFTune",local:"neftune",headingTag:"h2"}}),je=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTJDJTIwVHJhaW5lciUwQSUwQXRyYWluaW5nX2FyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyguLi4lMkMlMjBuZWZ0dW5lX25vaXNlX2FscGhhJTNEMC4xKSUwQXRyYWluZXIlMjAlM0QlMjBUcmFpbmVyKC4uLiUyQyUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, Trainer

training_args = TrainingArguments(..., neftune_noise_alpha=<span class="hljs-number">0.1</span>)
trainer = Trainer(..., args=training_args)`,wrap:!1}}),be=new $({props:{title:"Liger Kernel",local:"liger-kernel",headingTag:"h2"}}),k=new Js({props:{$$slots:{default:[Ga]},$$scope:{ctx:j}}}),$e=new U({props:{code:"cGlwJTIwaW5zdGFsbCUyMGxpZ2VyLWtlcm5lbA==",highlighted:"pip install liger-kernel",wrap:!1}}),Be=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjJ5b3VyLW1vZGVsJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfZXZhbF9iYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNEMiUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheSUzRDAuMDElMkMlMEElMjAlMjAlMjAlMjBldmFsX3N0cmF0ZWd5JTNEJTIyZXBvY2glMjIlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0cmF0ZWd5JTNEJTIyZXBvY2glMjIlMkMlMEElMjAlMjAlMjAlMjBsb2FkX2Jlc3RfbW9kZWxfYXRfZW5kJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHVzZV9saWdlcl9rZXJuZWwlM0RUcnVlJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

training_args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;your-model&quot;</span>,
    learning_rate=<span class="hljs-number">2e-5</span>,
    per_device_train_batch_size=<span class="hljs-number">16</span>,
    per_device_eval_batch_size=<span class="hljs-number">16</span>,
    num_train_epochs=<span class="hljs-number">2</span>,
    weight_decay=<span class="hljs-number">0.01</span>,
    eval_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    load_best_model_at_end=<span class="hljs-literal">True</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
    use_liger_kernel=<span class="hljs-literal">True</span>
)`,wrap:!1}}),We=new $({props:{title:"Optimizers",local:"optimizers",headingTag:"h2"}}),ke=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKC4uLiUyQyUyMG9wdGltJTNEJTIyYWRhbXdfdG9yY2glMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments
training_args = TrainingArguments(..., optim=<span class="hljs-string">&quot;adamw_torch&quot;</span>)`,wrap:!1}}),Fe=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFvcHRpbWl6ZXJfY2xzJTIwJTNEJTIwdG9yY2gub3B0aW0uQWRhbVclMEFvcHRpbWl6ZXJfa3dhcmdzJTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIybHIlMjIlM0ElMjA0ZS0zJTJDJTBBJTIwJTIwJTIwJTIwJTIyYmV0YXMlMjIlM0ElMjAoMC45JTJDJTIwMC45OTkpJTJDJTBBJTIwJTIwJTIwJTIwJTIyd2VpZ2h0X2RlY2F5JTIyJTNBJTIwMC4wNSUyQyUwQSU3RCUwQSUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBUcmFpbmVyJTBBdHJhaW5lciUyMCUzRCUyMFRyYWluZXIoLi4uJTJDJTIwb3B0aW1pemVyX2Nsc19hbmRfa3dhcmdzJTNEKG9wdGltaXplcl9jbHMlMkMlMjBvcHRpbWl6ZXJfa3dhcmdzKSk=",highlighted:`<span class="hljs-keyword">import</span> torch

optimizer_cls = torch.optim.AdamW
optimizer_kwargs = {
    <span class="hljs-string">&quot;lr&quot;</span>: <span class="hljs-number">4e-3</span>,
    <span class="hljs-string">&quot;betas&quot;</span>: (<span class="hljs-number">0.9</span>, <span class="hljs-number">0.999</span>),
    <span class="hljs-string">&quot;weight_decay&quot;</span>: <span class="hljs-number">0.05</span>,
}

<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer
trainer = Trainer(..., optimizer_cls_and_kwargs=(optimizer_cls, optimizer_kwargs))`,wrap:!1}}),Re=new $({props:{title:"GaLore",local:"galore",headingTag:"h3"}}),Ae=new U({props:{code:"cGlwJTIwaW5zdGFsbCUyMGdhbG9yZS10b3JjaA==",highlighted:"pip install galore-torch",wrap:!1}}),Ne=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBkYXRhc2V0cyUwQWltcG9ydCUyMHRybCUwQSUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMEF1dG9Db25maWclMkMlMjBBdXRvVG9rZW5pemVyJTJDJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMEElMEF0cmFpbl9kYXRhc2V0JTIwJTNEJTIwZGF0YXNldHMubG9hZF9kYXRhc2V0KCdpbWRiJyUyQyUyMHNwbGl0JTNEJ3RyYWluJyklMEElMEFhcmdzJTIwJTNEJTIwVHJhaW5pbmdBcmd1bWVudHMoJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMi4lMkZ0ZXN0LWdhbG9yZSUyMiUyQyUwQSUyMCUyMCUyMCUyMG1heF9zdGVwcyUzRDEwMCUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDIlMkMlMEElMjAlMjAlMjAlMjBvcHRpbSUzRCUyMmdhbG9yZV9hZGFtdyUyMiUyQyUwQSUyMCUyMCUyMCUyMG9wdGltX3RhcmdldF9tb2R1bGVzJTNEJTVCciUyMi4qLmF0dG4uKiUyMiUyQyUyMHIlMjIuKi5tbHAuKiUyMiU1RCUwQSklMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMmdvb2dsZSUyRmdlbW1hLTJiJTIyJTBBJTBBY29uZmlnJTIwJTNEJTIwQXV0b0NvbmZpZy5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQpJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX2NvbmZpZyhjb25maWcpLnRvKDApJTBBJTBBdHJhaW5lciUyMCUzRCUyMHRybC5TRlRUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTNEbW9kZWwlMkMlMEElMjAlMjAlMjAlMjBhcmdzJTNEYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0R0cmFpbl9kYXRhc2V0JTJDJTBBJTIwJTIwJTIwJTIwZGF0YXNldF90ZXh0X2ZpZWxkJTNEJ3RleHQnJTJDJTBBJTIwJTIwJTIwJTIwbWF4X3NlcV9sZW5ndGglM0Q1MTIlMkMlMEEpJTBBJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> datasets
<span class="hljs-keyword">import</span> trl

<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, AutoConfig, AutoTokenizer, AutoModelForCausalLM

train_dataset = datasets.load_dataset(<span class="hljs-string">&#x27;imdb&#x27;</span>, split=<span class="hljs-string">&#x27;train&#x27;</span>)

args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;./test-galore&quot;</span>,
    max_steps=<span class="hljs-number">100</span>,
    per_device_train_batch_size=<span class="hljs-number">2</span>,
    optim=<span class="hljs-string">&quot;galore_adamw&quot;</span>,
    optim_target_modules=[<span class="hljs-string">r&quot;.*.attn.*&quot;</span>, <span class="hljs-string">r&quot;.*.mlp.*&quot;</span>]
)

model_id = <span class="hljs-string">&quot;google/gemma-2b&quot;</span>

config = AutoConfig.from_pretrained(model_id)

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_config(config).to(<span class="hljs-number">0</span>)

trainer = trl.SFTTrainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
    dataset_text_field=<span class="hljs-string">&#x27;text&#x27;</span>,
    max_seq_length=<span class="hljs-number">512</span>,
)

trainer.train()`,wrap:!1}}),Ye=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBkYXRhc2V0cyUwQWltcG9ydCUyMHRybCUwQSUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMEF1dG9Db25maWclMkMlMjBBdXRvVG9rZW5pemVyJTJDJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMEElMEF0cmFpbl9kYXRhc2V0JTIwJTNEJTIwZGF0YXNldHMubG9hZF9kYXRhc2V0KCdpbWRiJyUyQyUyMHNwbGl0JTNEJ3RyYWluJyklMEElMEFhcmdzJTIwJTNEJTIwVHJhaW5pbmdBcmd1bWVudHMoJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMi4lMkZ0ZXN0LWdhbG9yZSUyMiUyQyUwQSUyMCUyMCUyMCUyMG1heF9zdGVwcyUzRDEwMCUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDIlMkMlMEElMjAlMjAlMjAlMjBvcHRpbSUzRCUyMmdhbG9yZV9hZGFtdyUyMiUyQyUwQSUyMCUyMCUyMCUyMG9wdGltX3RhcmdldF9tb2R1bGVzJTNEJTVCciUyMi4qLmF0dG4uKiUyMiUyQyUyMHIlMjIuKi5tbHAuKiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMG9wdGltX2FyZ3MlM0QlMjJyYW5rJTNENjQlMkMlMjB1cGRhdGVfcHJval9nYXAlM0QxMDAlMkMlMjBzY2FsZSUzRDAuMTAlMjIlMkMlMEEpJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZnZW1tYS0yYiUyMiUwQSUwQWNvbmZpZyUyMCUzRCUyMEF1dG9Db25maWcuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9jb25maWcoY29uZmlnKS50bygwKSUwQSUwQXRyYWluZXIlMjAlM0QlMjB0cmwuU0ZUVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRGFyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMGRhdGFzZXRfdGV4dF9maWVsZCUzRCd0ZXh0JyUyQyUwQSUyMCUyMCUyMCUyMG1heF9zZXFfbGVuZ3RoJTNENTEyJTJDJTBBKSUwQSUwQXRyYWluZXIudHJhaW4oKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> datasets
<span class="hljs-keyword">import</span> trl

<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, AutoConfig, AutoTokenizer, AutoModelForCausalLM

train_dataset = datasets.load_dataset(<span class="hljs-string">&#x27;imdb&#x27;</span>, split=<span class="hljs-string">&#x27;train&#x27;</span>)

args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;./test-galore&quot;</span>,
    max_steps=<span class="hljs-number">100</span>,
    per_device_train_batch_size=<span class="hljs-number">2</span>,
    optim=<span class="hljs-string">&quot;galore_adamw&quot;</span>,
    optim_target_modules=[<span class="hljs-string">r&quot;.*.attn.*&quot;</span>, <span class="hljs-string">r&quot;.*.mlp.*&quot;</span>],
    optim_args=<span class="hljs-string">&quot;rank=64, update_proj_gap=100, scale=0.10&quot;</span>,
)

model_id = <span class="hljs-string">&quot;google/gemma-2b&quot;</span>

config = AutoConfig.from_pretrained(model_id)

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_config(config).to(<span class="hljs-number">0</span>)

trainer = trl.SFTTrainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
    dataset_text_field=<span class="hljs-string">&#x27;text&#x27;</span>,
    max_seq_length=<span class="hljs-number">512</span>,
)

trainer.train()`,wrap:!1}}),qe=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBkYXRhc2V0cyUwQWltcG9ydCUyMHRybCUwQSUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMEF1dG9Db25maWclMkMlMjBBdXRvVG9rZW5pemVyJTJDJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMEElMEF0cmFpbl9kYXRhc2V0JTIwJTNEJTIwZGF0YXNldHMubG9hZF9kYXRhc2V0KCdpbWRiJyUyQyUyMHNwbGl0JTNEJ3RyYWluJyklMEElMEFhcmdzJTIwJTNEJTIwVHJhaW5pbmdBcmd1bWVudHMoJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMi4lMkZ0ZXN0LWdhbG9yZSUyMiUyQyUwQSUyMCUyMCUyMCUyMG1heF9zdGVwcyUzRDEwMCUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDIlMkMlMEElMjAlMjAlMjAlMjBvcHRpbSUzRCUyMmdhbG9yZV9hZGFtd19sYXllcndpc2UlMjIlMkMlMEElMjAlMjAlMjAlMjBvcHRpbV90YXJnZXRfbW9kdWxlcyUzRCU1QnIlMjIuKi5hdHRuLiolMjIlMkMlMjByJTIyLioubWxwLiolMjIlNUQlMEEpJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZnZW1tYS0yYiUyMiUwQSUwQWNvbmZpZyUyMCUzRCUyMEF1dG9Db25maWcuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9jb25maWcoY29uZmlnKS50bygwKSUwQSUwQXRyYWluZXIlMjAlM0QlMjB0cmwuU0ZUVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRGFyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMGRhdGFzZXRfdGV4dF9maWVsZCUzRCd0ZXh0JyUyQyUwQSUyMCUyMCUyMCUyMG1heF9zZXFfbGVuZ3RoJTNENTEyJTJDJTBBKSUwQSUwQXRyYWluZXIudHJhaW4oKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> datasets
<span class="hljs-keyword">import</span> trl

<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, AutoConfig, AutoTokenizer, AutoModelForCausalLM

train_dataset = datasets.load_dataset(<span class="hljs-string">&#x27;imdb&#x27;</span>, split=<span class="hljs-string">&#x27;train&#x27;</span>)

args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;./test-galore&quot;</span>,
    max_steps=<span class="hljs-number">100</span>,
    per_device_train_batch_size=<span class="hljs-number">2</span>,
    optim=<span class="hljs-string">&quot;galore_adamw_layerwise&quot;</span>,
    optim_target_modules=[<span class="hljs-string">r&quot;.*.attn.*&quot;</span>, <span class="hljs-string">r&quot;.*.mlp.*&quot;</span>]
)

model_id = <span class="hljs-string">&quot;google/gemma-2b&quot;</span>

config = AutoConfig.from_pretrained(model_id)

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_config(config).to(<span class="hljs-number">0</span>)

trainer = trl.SFTTrainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
    dataset_text_field=<span class="hljs-string">&#x27;text&#x27;</span>,
    max_seq_length=<span class="hljs-number">512</span>,
)

trainer.train()`,wrap:!1}}),Pe=new $({props:{title:"LOMO optimizer",local:"lomo-optimizer",headingTag:"h3"}}),E=new Js({props:{$$slots:{default:[Va]},$$scope:{ctx:j}}}),es=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBkYXRhc2V0cyUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQWltcG9ydCUyMHRybCUwQSUwQXRyYWluX2RhdGFzZXQlMjAlM0QlMjBkYXRhc2V0cy5sb2FkX2RhdGFzZXQoJ2ltZGInJTJDJTIwc3BsaXQlM0QndHJhaW4nKSUwQSUwQWFyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyglMEElMjAlMjAlMjAlMjBvdXRwdXRfZGlyJTNEJTIyLiUyRnRlc3QtbG9tbyUyMiUyQyUwQSUyMCUyMCUyMCUyMG1heF9zdGVwcyUzRDEwMDAlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0Q0JTJDJTBBJTIwJTIwJTIwJTIwb3B0aW0lM0QlMjJhZGFsb21vJTIyJTJDJTBBJTIwJTIwJTIwJTIwZ3JhZGllbnRfY2hlY2twb2ludGluZyUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBsb2dnaW5nX3N0cmF0ZWd5JTNEJTIyc3RlcHMlMjIlMkMlMEElMjAlMjAlMjAlMjBsb2dnaW5nX3N0ZXBzJTNEMSUyQyUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0QyZS02JTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV9zdHJhdGVneSUzRCUyMm5vJTIyJTJDJTBBJTIwJTIwJTIwJTIwcnVuX25hbWUlM0QlMjJsb21vLWltZGIlMjIlMkMlMEEpJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZnZW1tYS0yYiUyMiUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwbG93X2NwdV9tZW1fdXNhZ2UlM0RUcnVlKS50bygwKSUwQSUwQXRyYWluZXIlMjAlM0QlMjB0cmwuU0ZUVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRGFyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMGRhdGFzZXRfdGV4dF9maWVsZCUzRCd0ZXh0JyUyQyUwQSUyMCUyMCUyMCUyMG1heF9zZXFfbGVuZ3RoJTNEMTAyNCUyQyUwQSklMEElMEF0cmFpbmVyLnRyYWluKCk=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> datasets
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, AutoTokenizer, AutoModelForCausalLM
<span class="hljs-keyword">import</span> trl

train_dataset = datasets.load_dataset(<span class="hljs-string">&#x27;imdb&#x27;</span>, split=<span class="hljs-string">&#x27;train&#x27;</span>)

args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;./test-lomo&quot;</span>,
    max_steps=<span class="hljs-number">1000</span>,
    per_device_train_batch_size=<span class="hljs-number">4</span>,
    optim=<span class="hljs-string">&quot;adalomo&quot;</span>,
    gradient_checkpointing=<span class="hljs-literal">True</span>,
    logging_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    logging_steps=<span class="hljs-number">1</span>,
    learning_rate=<span class="hljs-number">2e-6</span>,
    save_strategy=<span class="hljs-string">&quot;no&quot;</span>,
    run_name=<span class="hljs-string">&quot;lomo-imdb&quot;</span>,
)

model_id = <span class="hljs-string">&quot;google/gemma-2b&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, low_cpu_mem_usage=<span class="hljs-literal">True</span>).to(<span class="hljs-number">0</span>)

trainer = trl.SFTTrainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
    dataset_text_field=<span class="hljs-string">&#x27;text&#x27;</span>,
    max_seq_length=<span class="hljs-number">1024</span>,
)

trainer.train()`,wrap:!1}}),ss=new $({props:{title:"GrokAdamW optimizer",local:"grokadamw-optimizer",headingTag:"h3"}}),v=new Js({props:{$$slots:{default:[Aa]},$$scope:{ctx:j}}}),as=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBkYXRhc2V0cyUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUyQyUyMFRyYWluZXIlMEElMEElMjMlMjBMb2FkJTIwdGhlJTIwSU1EQiUyMGRhdGFzZXQlMEF0cmFpbl9kYXRhc2V0JTIwJTNEJTIwZGF0YXNldHMubG9hZF9kYXRhc2V0KCdpbWRiJyUyQyUyMHNwbGl0JTNEJ3RyYWluJyklMEElMEElMjMlMjBEZWZpbmUlMjB0aGUlMjB0cmFpbmluZyUyMGFyZ3VtZW50cyUwQWFyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyglMEElMjAlMjAlMjAlMjBvdXRwdXRfZGlyJTNEJTIyLiUyRnRlc3QtZ3Jva2FkYW13JTIyJTJDJTBBJTIwJTIwJTIwJTIwbWF4X3N0ZXBzJTNEMTAwMCUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDQlMkMlMEElMjAlMjAlMjAlMjBvcHRpbSUzRCUyMmdyb2thZGFtdyUyMiUyQyUwQSUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RlcHMlM0QxJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0cmF0ZWd5JTNEJTIybm8lMjIlMkMlMEElMjAlMjAlMjAlMjBydW5fbmFtZSUzRCUyMmdyb2thZGFtdy1pbWRiJTIyJTJDJTBBKSUwQSUwQSUyMyUyMExvYWQlMjB0aGUlMjBtb2RlbCUyMGFuZCUyMHRva2VuaXplciUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyZ29vZ2xlJTJGZ2VtbWEtMmIlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMGxvd19jcHVfbWVtX3VzYWdlJTNEVHJ1ZSkudG8oMCklMEElMEElMjMlMjBJbml0aWFsaXplJTIwdGhlJTIwVHJhaW5lciUwQXRyYWluZXIlMjAlM0QlMjBUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTNEbW9kZWwlMkMlMEElMjAlMjAlMjAlMjBhcmdzJTNEYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0R0cmFpbl9kYXRhc2V0JTJDJTBBKSUwQSUwQSUyMyUyMFRyYWluJTIwdGhlJTIwbW9kZWwlMEF0cmFpbmVyLnRyYWluKCk=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> datasets
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, AutoTokenizer, AutoModelForCausalLM, Trainer

<span class="hljs-comment"># Load the IMDB dataset</span>
train_dataset = datasets.load_dataset(<span class="hljs-string">&#x27;imdb&#x27;</span>, split=<span class="hljs-string">&#x27;train&#x27;</span>)

<span class="hljs-comment"># Define the training arguments</span>
args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;./test-grokadamw&quot;</span>,
    max_steps=<span class="hljs-number">1000</span>,
    per_device_train_batch_size=<span class="hljs-number">4</span>,
    optim=<span class="hljs-string">&quot;grokadamw&quot;</span>,
    logging_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    logging_steps=<span class="hljs-number">1</span>,
    learning_rate=<span class="hljs-number">2e-5</span>,
    save_strategy=<span class="hljs-string">&quot;no&quot;</span>,
    run_name=<span class="hljs-string">&quot;grokadamw-imdb&quot;</span>,
)

<span class="hljs-comment"># Load the model and tokenizer</span>
model_id = <span class="hljs-string">&quot;google/gemma-2b&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, low_cpu_mem_usage=<span class="hljs-literal">True</span>).to(<span class="hljs-number">0</span>)

<span class="hljs-comment"># Initialize the Trainer</span>
trainer = Trainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
)

<span class="hljs-comment"># Train the model</span>
trainer.train()`,wrap:!1}}),rs=new $({props:{title:"Schedule Free Optimizer",local:"schedule-free-optimizer",headingTag:"h3"}}),ps=new U({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBkYXRhc2V0cyUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQWltcG9ydCUyMHRybCUwQSUwQXRyYWluX2RhdGFzZXQlMjAlM0QlMjBkYXRhc2V0cy5sb2FkX2RhdGFzZXQoJ2ltZGInJTJDJTIwc3BsaXQlM0QndHJhaW4nKSUwQSUwQWFyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyglMEElMjAlMjAlMjAlMjBvdXRwdXRfZGlyJTNEJTIyLiUyRnRlc3Qtc2NoZWR1bGVmcmVlJTIyJTJDJTBBJTIwJTIwJTIwJTIwbWF4X3N0ZXBzJTNEMTAwMCUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDQlMkMlMEElMjAlMjAlMjAlMjBvcHRpbSUzRCUyMnNjaGVkdWxlX2ZyZWVfYWRhbXclMjIlMkMlMEElMjAlMjAlMjAlMjBncmFkaWVudF9jaGVja3BvaW50aW5nJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RlcHMlM0QxJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTYlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0cmF0ZWd5JTNEJTIybm8lMjIlMkMlMEElMjAlMjAlMjAlMjBydW5fbmFtZSUzRCUyMnNmby1pbWRiJTIyJTJDJTBBKSUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyZ29vZ2xlJTJGZ2VtbWEtMmIlMjIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMGxvd19jcHVfbWVtX3VzYWdlJTNEVHJ1ZSkudG8oMCklMEElMEF0cmFpbmVyJTIwJTNEJTIwdHJsLlNGVFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUyMCUwQSUyMCUyMCUyMCUyMGFyZ3MlM0RhcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHRyYWluX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjBkYXRhc2V0X3RleHRfZmllbGQlM0QndGV4dCclMkMlMEElMjAlMjAlMjAlMjBtYXhfc2VxX2xlbmd0aCUzRDEwMjQlMkMlMEEpJTBBJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> datasets
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, AutoTokenizer, AutoModelForCausalLM
<span class="hljs-keyword">import</span> trl

train_dataset = datasets.load_dataset(<span class="hljs-string">&#x27;imdb&#x27;</span>, split=<span class="hljs-string">&#x27;train&#x27;</span>)

args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;./test-schedulefree&quot;</span>,
    max_steps=<span class="hljs-number">1000</span>,
    per_device_train_batch_size=<span class="hljs-number">4</span>,
    optim=<span class="hljs-string">&quot;schedule_free_adamw&quot;</span>,
    gradient_checkpointing=<span class="hljs-literal">True</span>,
    logging_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    logging_steps=<span class="hljs-number">1</span>,
    learning_rate=<span class="hljs-number">2e-6</span>,
    save_strategy=<span class="hljs-string">&quot;no&quot;</span>,
    run_name=<span class="hljs-string">&quot;sfo-imdb&quot;</span>,
)

model_id = <span class="hljs-string">&quot;google/gemma-2b&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, low_cpu_mem_usage=<span class="hljs-literal">True</span>).to(<span class="hljs-number">0</span>)

trainer = trl.SFTTrainer(
    model=model, 
    args=args,
    train_dataset=train_dataset,
    dataset_text_field=<span class="hljs-string">&#x27;text&#x27;</span>,
    max_seq_length=<span class="hljs-number">1024</span>,
)

trainer.train()`,wrap:!1}}),cs=new $({props:{title:"Accelerate and Trainer",local:"accelerate-and-trainer",headingTag:"h2"}}),F=new Js({props:{$$slots:{default:[Qa]},$$scope:{ctx:j}}}),R=new ja({props:{id:"config",options:["DistributedDataParallel","FSDP","DeepSpeed","DeepSpeed with Accelerate plugin"],$$slots:{default:[Ha]},$$scope:{ctx:j}}}),us=new U({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMCU1QyUwQSUyMCUyMCUyMCUyMC4lMkZleGFtcGxlcyUyRnB5dG9yY2glMkZ0ZXh0LWNsYXNzaWZpY2F0aW9uJTJGcnVuX2dsdWUucHklMjAlNUMlMEElMjAlMjAlMjAlMjAtLW1vZGVsX25hbWVfb3JfcGF0aCUyMGdvb2dsZS1iZXJ0JTJGYmVydC1iYXNlLWNhc2VkJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS10YXNrX25hbWUlMjAlMjRUQVNLX05BTUUlMjAlNUMlMEElMjAlMjAlMjAlMjAtLWRvX3RyYWluJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1kb19ldmFsJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1tYXhfc2VxX2xlbmd0aCUyMDEyOCUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tcGVyX2RldmljZV90cmFpbl9iYXRjaF9zaXplJTIwMTYlMjAlNUMlMEElMjAlMjAlMjAlMjAtLWxlYXJuaW5nX3JhdGUlMjA1ZS01JTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1udW1fdHJhaW5fZXBvY2hzJTIwMyUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tb3V0cHV0X2RpciUyMCUyRnRtcCUyRiUyNFRBU0tfTkFNRSUyRiUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tb3ZlcndyaXRlX291dHB1dF9kaXI=",highlighted:`accelerate launch \\
    ./examples/pytorch/text-classification/run_glue.py \\
    --model_name_or_path google-bert/bert-base-cased \\
    --task_name <span class="hljs-variable">$TASK_NAME</span> \\
    --do_train \\
    --do_eval \\
    --max_seq_length 128 \\
    --per_device_train_batch_size 16 \\
    --learning_rate 5e-5 \\
    --num_train_epochs 3 \\
    --output_dir /tmp/<span class="hljs-variable">$TASK_NAME</span>/ \\
    --overwrite_output_dir`,wrap:!1}}),fs=new U({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbnVtX3Byb2Nlc3NlcyUzRDIlMjAlNUMlMEElMjAlMjAlMjAlMjAtLXVzZV9mc2RwJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1taXhlZF9wcmVjaXNpb24lM0RiZjE2JTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1mc2RwX2F1dG9fd3JhcF9wb2xpY3klM0RUUkFOU0ZPUk1FUl9CQVNFRF9XUkFQJTIwJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1mc2RwX3RyYW5zZm9ybWVyX2xheWVyX2Nsc190b193cmFwJTNEJTIyQmVydExheWVyJTIyJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1mc2RwX3NoYXJkaW5nX3N0cmF0ZWd5JTNEMSUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tZnNkcF9zdGF0ZV9kaWN0X3R5cGUlM0RGVUxMX1NUQVRFX0RJQ1QlMjAlNUMlMEElMjAlMjAlMjAlMjAuJTJGZXhhbXBsZXMlMkZweXRvcmNoJTJGdGV4dC1jbGFzc2lmaWNhdGlvbiUyRnJ1bl9nbHVlLnB5JTBBJTIwJTIwJTIwJTIwLS1tb2RlbF9uYW1lX29yX3BhdGglMjBnb29nbGUtYmVydCUyRmJlcnQtYmFzZS1jYXNlZCUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tdGFza19uYW1lJTIwJTI0VEFTS19OQU1FJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1kb190cmFpbiUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tZG9fZXZhbCUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tbWF4X3NlcV9sZW5ndGglMjAxMjglMjAlNUMlMEElMjAlMjAlMjAlMjAtLXBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUyMDE2JTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1sZWFybmluZ19yYXRlJTIwNWUtNSUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tbnVtX3RyYWluX2Vwb2NocyUyMDMlMjAlNUMlMEElMjAlMjAlMjAlMjAtLW91dHB1dF9kaXIlMjAlMkZ0bXAlMkYlMjRUQVNLX05BTUUlMkYlMjAlNUMlMEElMjAlMjAlMjAlMjAtLW92ZXJ3cml0ZV9vdXRwdXRfZGly",highlighted:`accelerate launch --num_processes=2 \\
    --use_fsdp \\
    --mixed_precision=bf16 \\
    --fsdp_auto_wrap_policy=TRANSFORMER_BASED_WRAP  \\
    --fsdp_transformer_layer_cls_to_wrap=<span class="hljs-string">&quot;BertLayer&quot;</span> \\
    --fsdp_sharding_strategy=1 \\
    --fsdp_state_dict_type=FULL_STATE_DICT \\
    ./examples/pytorch/text-classification/run_glue.py
    --model_name_or_path google-bert/bert-base-cased \\
    --task_name <span class="hljs-variable">$TASK_NAME</span> \\
    --do_train \\
    --do_eval \\
    --max_seq_length 128 \\
    --per_device_train_batch_size 16 \\
    --learning_rate 5e-5 \\
    --num_train_epochs 3 \\
    --output_dir /tmp/<span class="hljs-variable">$TASK_NAME</span>/ \\
    --overwrite_output_dir`,wrap:!1}}),ws=new Wa({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/trainer.md"}}),{c(){a=p("meta"),o=r(),n=p("p"),T=r(),M(w.$$.fragment),g=r(),b=p("p"),b.innerHTML=Z,J=r(),M(_.$$.fragment),G=r(),B=p("p"),B.innerHTML=js,V=r(),M(A.$$.fragment),bs=r(),Q=p("p"),Q.innerHTML=dl,_s=r(),M(N.$$.fragment),Zs=r(),z=p("p"),z.innerHTML=hl,$s=r(),Y=p("ol"),Y.innerHTML=ul,Cs=r(),S=p("p"),S.innerHTML=yl,Bs=r(),H=p("p"),H.innerHTML=fl,Xs=r(),M(x.$$.fragment),Ws=r(),L=p("p"),L.innerHTML=Tl,Is=r(),q=p("p"),q.innerHTML=wl,ks=r(),M(D.$$.fragment),Es=r(),M(P.$$.fragment),vs=r(),K=p("p"),K.innerHTML=Jl,Fs=r(),M(O.$$.fragment),Rs=r(),ee=p("p"),ee.innerHTML=gl,Gs=r(),se=p("ul"),se.innerHTML=jl,Vs=r(),te=p("p"),te.innerHTML=Ul,As=r(),M(le.$$.fragment),Qs=r(),ae=p("p"),ae.innerHTML=bl,Ns=r(),ne=p("ul"),ne.innerHTML=_l,zs=r(),re=p("p"),re.innerHTML=Zl,Ys=r(),M(ie.$$.fragment),Ss=r(),M(oe.$$.fragment),Hs=r(),pe=p("p"),pe.innerHTML=$l,xs=r(),ce=p("p"),ce.textContent=Cl,Ls=r(),M(me.$$.fragment),qs=r(),Me=p("p"),Me.innerHTML=Bl,Ds=r(),M(de.$$.fragment),Ps=r(),M(he.$$.fragment),Ks=r(),M(X.$$.fragment),Os=r(),ue=p("p"),ue.innerHTML=Xl,et=r(),ye=p("p"),ye.innerHTML=Wl,st=r(),M(W.$$.fragment),tt=r(),fe=p("p"),fe.textContent=Il,lt=r(),M(Te.$$.fragment),at=r(),we=p("p"),we.innerHTML=kl,nt=r(),M(I.$$.fragment),rt=r(),M(Je.$$.fragment),it=r(),ge=p("p"),ge.innerHTML=El,ot=r(),M(je.$$.fragment),pt=r(),Ue=p("p"),Ue.textContent=vl,ct=r(),M(be.$$.fragment),mt=r(),_e=p("p"),_e.innerHTML=Fl,Mt=r(),M(k.$$.fragment),dt=r(),Ze=p("p"),Ze.textContent=Rl,ht=r(),M($e.$$.fragment),ut=r(),Ce=p("p"),Ce.innerHTML=Gl,yt=r(),M(Be.$$.fragment),ft=r(),Xe=p("p"),Xe.innerHTML=Vl,Tt=r(),M(We.$$.fragment),wt=r(),Ie=p("p"),Ie.textContent=Al,Jt=r(),M(ke.$$.fragment),gt=r(),Ee=p("p"),Ee.innerHTML=Ql,jt=r(),ve=p("p"),ve.textContent=Nl,Ut=r(),M(Fe.$$.fragment),bt=r(),M(Re.$$.fragment),_t=r(),Ge=p("p"),Ge.textContent=zl,Zt=r(),Ve=p("p"),Ve.textContent=Yl,$t=r(),M(Ae.$$.fragment),Ct=r(),Qe=p("p"),Qe.innerHTML=Sl,Bt=r(),M(Ne.$$.fragment),Xt=r(),ze=p("p"),ze.innerHTML=Hl,Wt=r(),M(Ye.$$.fragment),It=r(),Se=p("p"),Se.innerHTML=xl,kt=r(),He=p("p"),He.textContent=Ll,Et=r(),xe=p("p"),xe.textContent=ql,vt=r(),Le=p("p"),Le.innerHTML=Dl,Ft=r(),M(qe.$$.fragment),Rt=r(),De=p("p"),De.innerHTML=Pl,Gt=r(),M(Pe.$$.fragment),Vt=r(),Ke=p("p"),Ke.innerHTML=Kl,At=r(),M(E.$$.fragment),Qt=r(),Oe=p("p"),Oe.innerHTML=Ol,Nt=r(),M(es.$$.fragment),zt=r(),M(ss.$$.fragment),Yt=r(),ts=p("p"),ts.innerHTML=ea,St=r(),M(v.$$.fragment),Ht=r(),ls=p("p"),ls.innerHTML=sa,xt=r(),M(as.$$.fragment),Lt=r(),ns=p("p"),ns.innerHTML=ta,qt=r(),M(rs.$$.fragment),Dt=r(),is=p("p"),is.innerHTML=la,Pt=r(),os=p("p"),os.innerHTML=aa,Kt=r(),M(ps.$$.fragment),Ot=r(),M(cs.$$.fragment),el=r(),ms=p("p"),ms.innerHTML=na,sl=r(),M(F.$$.fragment),tl=r(),Ms=p("p"),Ms.innerHTML=ra,ll=r(),M(R.$$.fragment),al=r(),ds=p("p"),ds.innerHTML=ia,nl=r(),hs=p("p"),hs.innerHTML=oa,rl=r(),M(us.$$.fragment),il=r(),ys=p("p"),ys.innerHTML=pa,ol=r(),M(fs.$$.fragment),pl=r(),Ts=p("p"),Ts.innerHTML=ca,cl=r(),M(ws.$$.fragment),ml=r(),Us=p("p"),this.h()},l(e){const s=$a("svelte-u9bgzb",document.head);a=c(s,"META",{name:!0,content:!0}),s.forEach(t),o=i(e),n=c(e,"P",{}),Ja(n).forEach(t),T=i(e),d(w.$$.fragment,e),g=i(e),b=c(e,"P",{"data-svelte-h":!0}),m(b)!=="svelte-jcr00h"&&(b.innerHTML=Z),J=i(e),d(_.$$.fragment,e),G=i(e),B=c(e,"P",{"data-svelte-h":!0}),m(B)!=="svelte-17cwfvo"&&(B.innerHTML=js),V=i(e),d(A.$$.fragment,e),bs=i(e),Q=c(e,"P",{"data-svelte-h":!0}),m(Q)!=="svelte-1vtu769"&&(Q.innerHTML=dl),_s=i(e),d(N.$$.fragment,e),Zs=i(e),z=c(e,"P",{"data-svelte-h":!0}),m(z)!=="svelte-1tnfzs8"&&(z.innerHTML=hl),$s=i(e),Y=c(e,"OL",{"data-svelte-h":!0}),m(Y)!=="svelte-300ub0"&&(Y.innerHTML=ul),Cs=i(e),S=c(e,"P",{"data-svelte-h":!0}),m(S)!=="svelte-1aq3mqr"&&(S.innerHTML=yl),Bs=i(e),H=c(e,"P",{"data-svelte-h":!0}),m(H)!=="svelte-1da15g7"&&(H.innerHTML=fl),Xs=i(e),d(x.$$.fragment,e),Ws=i(e),L=c(e,"P",{"data-svelte-h":!0}),m(L)!=="svelte-nqmldp"&&(L.innerHTML=Tl),Is=i(e),q=c(e,"P",{"data-svelte-h":!0}),m(q)!=="svelte-ylgc0g"&&(q.innerHTML=wl),ks=i(e),d(D.$$.fragment,e),Es=i(e),d(P.$$.fragment,e),vs=i(e),K=c(e,"P",{"data-svelte-h":!0}),m(K)!=="svelte-1qbrdit"&&(K.innerHTML=Jl),Fs=i(e),d(O.$$.fragment,e),Rs=i(e),ee=c(e,"P",{"data-svelte-h":!0}),m(ee)!=="svelte-1shgppu"&&(ee.innerHTML=gl),Gs=i(e),se=c(e,"UL",{"data-svelte-h":!0}),m(se)!=="svelte-1f7sie2"&&(se.innerHTML=jl),Vs=i(e),te=c(e,"P",{"data-svelte-h":!0}),m(te)!=="svelte-1lhivzo"&&(te.innerHTML=Ul),As=i(e),d(le.$$.fragment,e),Qs=i(e),ae=c(e,"P",{"data-svelte-h":!0}),m(ae)!=="svelte-1ua4hq8"&&(ae.innerHTML=bl),Ns=i(e),ne=c(e,"UL",{"data-svelte-h":!0}),m(ne)!=="svelte-n0xbmd"&&(ne.innerHTML=_l),zs=i(e),re=c(e,"P",{"data-svelte-h":!0}),m(re)!=="svelte-14rt2hd"&&(re.innerHTML=Zl),Ys=i(e),d(ie.$$.fragment,e),Ss=i(e),d(oe.$$.fragment,e),Hs=i(e),pe=c(e,"P",{"data-svelte-h":!0}),m(pe)!=="svelte-f1pptb"&&(pe.innerHTML=$l),xs=i(e),ce=c(e,"P",{"data-svelte-h":!0}),m(ce)!=="svelte-ckk1ok"&&(ce.textContent=Cl),Ls=i(e),d(me.$$.fragment,e),qs=i(e),Me=c(e,"P",{"data-svelte-h":!0}),m(Me)!=="svelte-73zmcn"&&(Me.innerHTML=Bl),Ds=i(e),d(de.$$.fragment,e),Ps=i(e),d(he.$$.fragment,e),Ks=i(e),d(X.$$.fragment,e),Os=i(e),ue=c(e,"P",{"data-svelte-h":!0}),m(ue)!=="svelte-nlqir1"&&(ue.innerHTML=Xl),et=i(e),ye=c(e,"P",{"data-svelte-h":!0}),m(ye)!=="svelte-3l1nfv"&&(ye.innerHTML=Wl),st=i(e),d(W.$$.fragment,e),tt=i(e),fe=c(e,"P",{"data-svelte-h":!0}),m(fe)!=="svelte-14qffqk"&&(fe.textContent=Il),lt=i(e),d(Te.$$.fragment,e),at=i(e),we=c(e,"P",{"data-svelte-h":!0}),m(we)!=="svelte-fy4z00"&&(we.innerHTML=kl),nt=i(e),d(I.$$.fragment,e),rt=i(e),d(Je.$$.fragment,e),it=i(e),ge=c(e,"P",{"data-svelte-h":!0}),m(ge)!=="svelte-1cjhj2p"&&(ge.innerHTML=El),ot=i(e),d(je.$$.fragment,e),pt=i(e),Ue=c(e,"P",{"data-svelte-h":!0}),m(Ue)!=="svelte-1tyg2gl"&&(Ue.textContent=vl),ct=i(e),d(be.$$.fragment,e),mt=i(e),_e=c(e,"P",{"data-svelte-h":!0}),m(_e)!=="svelte-1s4q0bp"&&(_e.innerHTML=Fl),Mt=i(e),d(k.$$.fragment,e),dt=i(e),Ze=c(e,"P",{"data-svelte-h":!0}),m(Ze)!=="svelte-y2r2m1"&&(Ze.textContent=Rl),ht=i(e),d($e.$$.fragment,e),ut=i(e),Ce=c(e,"P",{"data-svelte-h":!0}),m(Ce)!=="svelte-1jlq39z"&&(Ce.innerHTML=Gl),yt=i(e),d(Be.$$.fragment,e),ft=i(e),Xe=c(e,"P",{"data-svelte-h":!0}),m(Xe)!=="svelte-1t0qhj8"&&(Xe.innerHTML=Vl),Tt=i(e),d(We.$$.fragment,e),wt=i(e),Ie=c(e,"P",{"data-svelte-h":!0}),m(Ie)!=="svelte-5eb3w7"&&(Ie.textContent=Al),Jt=i(e),d(ke.$$.fragment,e),gt=i(e),Ee=c(e,"P",{"data-svelte-h":!0}),m(Ee)!=="svelte-keyyt"&&(Ee.innerHTML=Ql),jt=i(e),ve=c(e,"P",{"data-svelte-h":!0}),m(ve)!=="svelte-1va5gwm"&&(ve.textContent=Nl),Ut=i(e),d(Fe.$$.fragment,e),bt=i(e),d(Re.$$.fragment,e),_t=i(e),Ge=c(e,"P",{"data-svelte-h":!0}),m(Ge)!=="svelte-qi406x"&&(Ge.textContent=zl),Zt=i(e),Ve=c(e,"P",{"data-svelte-h":!0}),m(Ve)!=="svelte-6gjlmq"&&(Ve.textContent=Yl),$t=i(e),d(Ae.$$.fragment,e),Ct=i(e),Qe=c(e,"P",{"data-svelte-h":!0}),m(Qe)!=="svelte-1g9eiy6"&&(Qe.innerHTML=Sl),Bt=i(e),d(Ne.$$.fragment,e),Xt=i(e),ze=c(e,"P",{"data-svelte-h":!0}),m(ze)!=="svelte-i13fla"&&(ze.innerHTML=Hl),Wt=i(e),d(Ye.$$.fragment,e),It=i(e),Se=c(e,"P",{"data-svelte-h":!0}),m(Se)!=="svelte-1ag0i93"&&(Se.innerHTML=xl),kt=i(e),He=c(e,"P",{"data-svelte-h":!0}),m(He)!=="svelte-14lab64"&&(He.textContent=Ll),Et=i(e),xe=c(e,"P",{"data-svelte-h":!0}),m(xe)!=="svelte-k79irj"&&(xe.textContent=ql),vt=i(e),Le=c(e,"P",{"data-svelte-h":!0}),m(Le)!=="svelte-uvc2be"&&(Le.innerHTML=Dl),Ft=i(e),d(qe.$$.fragment,e),Rt=i(e),De=c(e,"P",{"data-svelte-h":!0}),m(De)!=="svelte-c2nuo5"&&(De.innerHTML=Pl),Gt=i(e),d(Pe.$$.fragment,e),Vt=i(e),Ke=c(e,"P",{"data-svelte-h":!0}),m(Ke)!=="svelte-1nv1q2g"&&(Ke.innerHTML=Kl),At=i(e),d(E.$$.fragment,e),Qt=i(e),Oe=c(e,"P",{"data-svelte-h":!0}),m(Oe)!=="svelte-1ed4he8"&&(Oe.innerHTML=Ol),Nt=i(e),d(es.$$.fragment,e),zt=i(e),d(ss.$$.fragment,e),Yt=i(e),ts=c(e,"P",{"data-svelte-h":!0}),m(ts)!=="svelte-19cxj8v"&&(ts.innerHTML=ea),St=i(e),d(v.$$.fragment,e),Ht=i(e),ls=c(e,"P",{"data-svelte-h":!0}),m(ls)!=="svelte-sjszbo"&&(ls.innerHTML=sa),xt=i(e),d(as.$$.fragment,e),Lt=i(e),ns=c(e,"P",{"data-svelte-h":!0}),m(ns)!=="svelte-pxxonu"&&(ns.innerHTML=ta),qt=i(e),d(rs.$$.fragment,e),Dt=i(e),is=c(e,"P",{"data-svelte-h":!0}),m(is)!=="svelte-w5uo13"&&(is.innerHTML=la),Pt=i(e),os=c(e,"P",{"data-svelte-h":!0}),m(os)!=="svelte-1ed4he8"&&(os.innerHTML=aa),Kt=i(e),d(ps.$$.fragment,e),Ot=i(e),d(cs.$$.fragment,e),el=i(e),ms=c(e,"P",{"data-svelte-h":!0}),m(ms)!=="svelte-thv413"&&(ms.innerHTML=na),sl=i(e),d(F.$$.fragment,e),tl=i(e),Ms=c(e,"P",{"data-svelte-h":!0}),m(Ms)!=="svelte-1sguly9"&&(Ms.innerHTML=ra),ll=i(e),d(R.$$.fragment,e),al=i(e),ds=c(e,"P",{"data-svelte-h":!0}),m(ds)!=="svelte-1s5mlic"&&(ds.innerHTML=ia),nl=i(e),hs=c(e,"P",{"data-svelte-h":!0}),m(hs)!=="svelte-cneufk"&&(hs.innerHTML=oa),rl=i(e),d(us.$$.fragment,e),il=i(e),ys=c(e,"P",{"data-svelte-h":!0}),m(ys)!=="svelte-13yow9q"&&(ys.innerHTML=pa),ol=i(e),d(fs.$$.fragment,e),pl=i(e),Ts=c(e,"P",{"data-svelte-h":!0}),m(Ts)!=="svelte-zjyylh"&&(Ts.innerHTML=ca),cl=i(e),d(ws.$$.fragment,e),ml=i(e),Us=c(e,"P",{}),Ja(Us).forEach(t),this.h()},h(){ga(a,"name","hf:doc:metadata"),ga(a,"content",La)},m(e,s){Ca(document.head,a),l(e,o,s),l(e,n,s),l(e,T,s),h(w,e,s),l(e,g,s),l(e,b,s),l(e,J,s),h(_,e,s),l(e,G,s),l(e,B,s),l(e,V,s),h(A,e,s),l(e,bs,s),l(e,Q,s),l(e,_s,s),h(N,e,s),l(e,Zs,s),l(e,z,s),l(e,$s,s),l(e,Y,s),l(e,Cs,s),l(e,S,s),l(e,Bs,s),l(e,H,s),l(e,Xs,s),h(x,e,s),l(e,Ws,s),l(e,L,s),l(e,Is,s),l(e,q,s),l(e,ks,s),h(D,e,s),l(e,Es,s),h(P,e,s),l(e,vs,s),l(e,K,s),l(e,Fs,s),h(O,e,s),l(e,Rs,s),l(e,ee,s),l(e,Gs,s),l(e,se,s),l(e,Vs,s),l(e,te,s),l(e,As,s),h(le,e,s),l(e,Qs,s),l(e,ae,s),l(e,Ns,s),l(e,ne,s),l(e,zs,s),l(e,re,s),l(e,Ys,s),h(ie,e,s),l(e,Ss,s),h(oe,e,s),l(e,Hs,s),l(e,pe,s),l(e,xs,s),l(e,ce,s),l(e,Ls,s),h(me,e,s),l(e,qs,s),l(e,Me,s),l(e,Ds,s),h(de,e,s),l(e,Ps,s),h(he,e,s),l(e,Ks,s),h(X,e,s),l(e,Os,s),l(e,ue,s),l(e,et,s),l(e,ye,s),l(e,st,s),h(W,e,s),l(e,tt,s),l(e,fe,s),l(e,lt,s),h(Te,e,s),l(e,at,s),l(e,we,s),l(e,nt,s),h(I,e,s),l(e,rt,s),h(Je,e,s),l(e,it,s),l(e,ge,s),l(e,ot,s),h(je,e,s),l(e,pt,s),l(e,Ue,s),l(e,ct,s),h(be,e,s),l(e,mt,s),l(e,_e,s),l(e,Mt,s),h(k,e,s),l(e,dt,s),l(e,Ze,s),l(e,ht,s),h($e,e,s),l(e,ut,s),l(e,Ce,s),l(e,yt,s),h(Be,e,s),l(e,ft,s),l(e,Xe,s),l(e,Tt,s),h(We,e,s),l(e,wt,s),l(e,Ie,s),l(e,Jt,s),h(ke,e,s),l(e,gt,s),l(e,Ee,s),l(e,jt,s),l(e,ve,s),l(e,Ut,s),h(Fe,e,s),l(e,bt,s),h(Re,e,s),l(e,_t,s),l(e,Ge,s),l(e,Zt,s),l(e,Ve,s),l(e,$t,s),h(Ae,e,s),l(e,Ct,s),l(e,Qe,s),l(e,Bt,s),h(Ne,e,s),l(e,Xt,s),l(e,ze,s),l(e,Wt,s),h(Ye,e,s),l(e,It,s),l(e,Se,s),l(e,kt,s),l(e,He,s),l(e,Et,s),l(e,xe,s),l(e,vt,s),l(e,Le,s),l(e,Ft,s),h(qe,e,s),l(e,Rt,s),l(e,De,s),l(e,Gt,s),h(Pe,e,s),l(e,Vt,s),l(e,Ke,s),l(e,At,s),h(E,e,s),l(e,Qt,s),l(e,Oe,s),l(e,Nt,s),h(es,e,s),l(e,zt,s),h(ss,e,s),l(e,Yt,s),l(e,ts,s),l(e,St,s),h(v,e,s),l(e,Ht,s),l(e,ls,s),l(e,xt,s),h(as,e,s),l(e,Lt,s),l(e,ns,s),l(e,qt,s),h(rs,e,s),l(e,Dt,s),l(e,is,s),l(e,Pt,s),l(e,os,s),l(e,Kt,s),h(ps,e,s),l(e,Ot,s),h(cs,e,s),l(e,el,s),l(e,ms,s),l(e,sl,s),h(F,e,s),l(e,tl,s),l(e,Ms,s),l(e,ll,s),h(R,e,s),l(e,al,s),l(e,ds,s),l(e,nl,s),l(e,hs,s),l(e,rl,s),h(us,e,s),l(e,il,s),l(e,ys,s),l(e,ol,s),h(fs,e,s),l(e,pl,s),l(e,Ts,s),l(e,cl,s),h(ws,e,s),l(e,ml,s),l(e,Us,s),Ml=!0},p(e,[s]){const ma={};s&2&&(ma.$$scope={dirty:s,ctx:e}),_.$set(ma);const Ma={};s&2&&(Ma.$$scope={dirty:s,ctx:e}),X.$set(Ma);const da={};s&2&&(da.$$scope={dirty:s,ctx:e}),W.$set(da);const ha={};s&2&&(ha.$$scope={dirty:s,ctx:e}),I.$set(ha);const ua={};s&2&&(ua.$$scope={dirty:s,ctx:e}),k.$set(ua);const ya={};s&2&&(ya.$$scope={dirty:s,ctx:e}),E.$set(ya);const fa={};s&2&&(fa.$$scope={dirty:s,ctx:e}),v.$set(fa);const Ta={};s&2&&(Ta.$$scope={dirty:s,ctx:e}),F.$set(Ta);const wa={};s&2&&(wa.$$scope={dirty:s,ctx:e}),R.$set(wa)},i(e){Ml||(u(w.$$.fragment,e),u(_.$$.fragment,e),u(A.$$.fragment,e),u(N.$$.fragment,e),u(x.$$.fragment,e),u(D.$$.fragment,e),u(P.$$.fragment,e),u(O.$$.fragment,e),u(le.$$.fragment,e),u(ie.$$.fragment,e),u(oe.$$.fragment,e),u(me.$$.fragment,e),u(de.$$.fragment,e),u(he.$$.fragment,e),u(X.$$.fragment,e),u(W.$$.fragment,e),u(Te.$$.fragment,e),u(I.$$.fragment,e),u(Je.$$.fragment,e),u(je.$$.fragment,e),u(be.$$.fragment,e),u(k.$$.fragment,e),u($e.$$.fragment,e),u(Be.$$.fragment,e),u(We.$$.fragment,e),u(ke.$$.fragment,e),u(Fe.$$.fragment,e),u(Re.$$.fragment,e),u(Ae.$$.fragment,e),u(Ne.$$.fragment,e),u(Ye.$$.fragment,e),u(qe.$$.fragment,e),u(Pe.$$.fragment,e),u(E.$$.fragment,e),u(es.$$.fragment,e),u(ss.$$.fragment,e),u(v.$$.fragment,e),u(as.$$.fragment,e),u(rs.$$.fragment,e),u(ps.$$.fragment,e),u(cs.$$.fragment,e),u(F.$$.fragment,e),u(R.$$.fragment,e),u(us.$$.fragment,e),u(fs.$$.fragment,e),u(ws.$$.fragment,e),Ml=!0)},o(e){y(w.$$.fragment,e),y(_.$$.fragment,e),y(A.$$.fragment,e),y(N.$$.fragment,e),y(x.$$.fragment,e),y(D.$$.fragment,e),y(P.$$.fragment,e),y(O.$$.fragment,e),y(le.$$.fragment,e),y(ie.$$.fragment,e),y(oe.$$.fragment,e),y(me.$$.fragment,e),y(de.$$.fragment,e),y(he.$$.fragment,e),y(X.$$.fragment,e),y(W.$$.fragment,e),y(Te.$$.fragment,e),y(I.$$.fragment,e),y(Je.$$.fragment,e),y(je.$$.fragment,e),y(be.$$.fragment,e),y(k.$$.fragment,e),y($e.$$.fragment,e),y(Be.$$.fragment,e),y(We.$$.fragment,e),y(ke.$$.fragment,e),y(Fe.$$.fragment,e),y(Re.$$.fragment,e),y(Ae.$$.fragment,e),y(Ne.$$.fragment,e),y(Ye.$$.fragment,e),y(qe.$$.fragment,e),y(Pe.$$.fragment,e),y(E.$$.fragment,e),y(es.$$.fragment,e),y(ss.$$.fragment,e),y(v.$$.fragment,e),y(as.$$.fragment,e),y(rs.$$.fragment,e),y(ps.$$.fragment,e),y(cs.$$.fragment,e),y(F.$$.fragment,e),y(R.$$.fragment,e),y(us.$$.fragment,e),y(fs.$$.fragment,e),y(ws.$$.fragment,e),Ml=!1},d(e){e&&(t(o),t(n),t(T),t(g),t(b),t(J),t(G),t(B),t(V),t(bs),t(Q),t(_s),t(Zs),t(z),t($s),t(Y),t(Cs),t(S),t(Bs),t(H),t(Xs),t(Ws),t(L),t(Is),t(q),t(ks),t(Es),t(vs),t(K),t(Fs),t(Rs),t(ee),t(Gs),t(se),t(Vs),t(te),t(As),t(Qs),t(ae),t(Ns),t(ne),t(zs),t(re),t(Ys),t(Ss),t(Hs),t(pe),t(xs),t(ce),t(Ls),t(qs),t(Me),t(Ds),t(Ps),t(Ks),t(Os),t(ue),t(et),t(ye),t(st),t(tt),t(fe),t(lt),t(at),t(we),t(nt),t(rt),t(it),t(ge),t(ot),t(pt),t(Ue),t(ct),t(mt),t(_e),t(Mt),t(dt),t(Ze),t(ht),t(ut),t(Ce),t(yt),t(ft),t(Xe),t(Tt),t(wt),t(Ie),t(Jt),t(gt),t(Ee),t(jt),t(ve),t(Ut),t(bt),t(_t),t(Ge),t(Zt),t(Ve),t($t),t(Ct),t(Qe),t(Bt),t(Xt),t(ze),t(Wt),t(It),t(Se),t(kt),t(He),t(Et),t(xe),t(vt),t(Le),t(Ft),t(Rt),t(De),t(Gt),t(Vt),t(Ke),t(At),t(Qt),t(Oe),t(Nt),t(zt),t(Yt),t(ts),t(St),t(Ht),t(ls),t(xt),t(Lt),t(ns),t(qt),t(Dt),t(is),t(Pt),t(os),t(Kt),t(Ot),t(el),t(ms),t(sl),t(tl),t(Ms),t(ll),t(al),t(ds),t(nl),t(hs),t(rl),t(il),t(ys),t(ol),t(pl),t(Ts),t(cl),t(ml),t(Us)),t(a),f(w,e),f(_,e),f(A,e),f(N,e),f(x,e),f(D,e),f(P,e),f(O,e),f(le,e),f(ie,e),f(oe,e),f(me,e),f(de,e),f(he,e),f(X,e),f(W,e),f(Te,e),f(I,e),f(Je,e),f(je,e),f(be,e),f(k,e),f($e,e),f(Be,e),f(We,e),f(ke,e),f(Fe,e),f(Re,e),f(Ae,e),f(Ne,e),f(Ye,e),f(qe,e),f(Pe,e),f(E,e),f(es,e),f(ss,e),f(v,e),f(as,e),f(rs,e),f(ps,e),f(cs,e),f(F,e),f(R,e),f(us,e),f(fs,e),f(ws,e)}}}const La='{"title":"Trainer","local":"trainer","sections":[{"title":"Basic usage","local":"basic-usage","sections":[{"title":"Checkpoints","local":"checkpoints","sections":[],"depth":3}],"depth":2},{"title":"Customize the Trainer","local":"customize-the-trainer","sections":[{"title":"Callbacks","local":"callbacks","sections":[],"depth":3}],"depth":2},{"title":"Logging","local":"logging","sections":[],"depth":2},{"title":"NEFTune","local":"neftune","sections":[],"depth":2},{"title":"Liger Kernel","local":"liger-kernel","sections":[],"depth":2},{"title":"Optimizers","local":"optimizers","sections":[{"title":"GaLore","local":"galore","sections":[],"depth":3},{"title":"LOMO optimizer","local":"lomo-optimizer","sections":[],"depth":3},{"title":"GrokAdamW optimizer","local":"grokadamw-optimizer","sections":[],"depth":3},{"title":"Schedule Free Optimizer","local":"schedule-free-optimizer","sections":[],"depth":3}],"depth":2},{"title":"Accelerate and Trainer","local":"accelerate-and-trainer","sections":[],"depth":2}],"depth":1}';function qa(j){return ba(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class tn extends _a{constructor(a){super(),Za(this,a,qa,xa,Ua,{})}}export{tn as component};
