Buckets:

rtrm's picture
download
raw
129 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;ပြည့်စုံသော Training Loop တစ်ခု&quot;,&quot;local&quot;:&quot;a-full-training&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Training အတွက် ပြင်ဆင်ခြင်း&quot;,&quot;local&quot;:&quot;prepare-for-training&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Training Loop&quot;,&quot;local&quot;:&quot;the-training-loop&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Evaluation Loop&quot;,&quot;local&quot;:&quot;the-evaluation-loop&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;🤗 Accelerate ဖြင့် သင်၏ Training Loop ကို အစွမ်းထက်စေခြင်း&quot;,&quot;local&quot;:&quot;supercharge-your-training-loop-with-accelerate&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;နောက်တစ်ဆင့်များနှင့် အကောင်းဆုံးအလေ့အကျင့်များ&quot;,&quot;local&quot;:&quot;next-steps-and-best-practices&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;အခန်း၏ ဗဟုသုတစစ်ဆေးခြင်း&quot;,&quot;local&quot;:&quot;section-quiz&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;1. Adam နှင့် AdamW optimizers များကြား အဓိကကွာခြားချက်က ဘာလဲ။&quot;,&quot;local&quot;:&quot;1-adam-နင-adamw-optimizers-မက-အဓကကခခကက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;2. training loop တစ်ခုတွင် လုပ်ဆောင်မှုများ၏ မှန်ကန်သော အစီအစဉ်က ဘာလဲ။&quot;,&quot;local&quot;:&quot;2-training-loop-တစခတင-လပဆငမမ-မနကနသ-အစအစဉက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;3. 🤗 Accelerate library သည် အဓိကအားဖြင့် ဘာကို ကူညီသလဲ။&quot;,&quot;local&quot;:&quot;3--accelerate-library-သည-အဓကအဖင-ဘက-ကညသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;4. training loop တစ်ခုတွင် batches များကို device သို့ ဘာကြောင့် ရွှေ့ရသလဲ။&quot;,&quot;local&quot;:&quot;4-training-loop-တစခတင-batches-မက-device-သ-ဘကင-ရရသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;5. evaluation မတိုင်မီ model.eval() က ဘာလုပ်သလဲ။&quot;,&quot;local&quot;:&quot;5-evaluation-မတငမ-modeleval-က-ဘလပသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;6. evaluation လုပ်နေစဉ် torch.no_grad() ရဲ့ ရည်ရွယ်ချက်က ဘာလဲ။&quot;,&quot;local&quot;:&quot;6-evaluation-လပနစဉ-torchnograd-ရ-ရညရယခကက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;7. သင်၏ training loop တွင် 🤗 Accelerate ကို အသုံးပြုသောအခါ ဘာတွေ ပြောင်းလဲသွားသလဲ။&quot;,&quot;local&quot;:&quot;7-သင-training-loop-တင--accelerate-က-အသပသအခ-ဘတ-ပငလသသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;ဝေါဟာရ ရှင်းလင်းချက် (Glossary)&quot;,&quot;local&quot;:&quot;ဝဟရ-ရငလငခက-glossary&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/course/pr_1107/my/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/entry/start.5c6233a8.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/scheduler.0835143d.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/singletons.c8b11329.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/index.1bab75e2.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/paths.e4a366ea.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/entry/app.55586789.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/preload-helper.5f7c8393.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/index.3d7efe79.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/nodes/0.0cec3d6c.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/nodes/26.ad467866.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/Youtube.96e00463.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/CodeBlock.116ed840.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/CourseFloatingBanner.860ea6e4.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/Question.a2f852b0.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/stores.6af6d5ae.js">
<link rel="modulepreload" href="/docs/course/pr_1107/my/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.0b02b772.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;ပြည့်စုံသော Training Loop တစ်ခု&quot;,&quot;local&quot;:&quot;a-full-training&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Training အတွက် ပြင်ဆင်ခြင်း&quot;,&quot;local&quot;:&quot;prepare-for-training&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Training Loop&quot;,&quot;local&quot;:&quot;the-training-loop&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Evaluation Loop&quot;,&quot;local&quot;:&quot;the-evaluation-loop&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;🤗 Accelerate ဖြင့် သင်၏ Training Loop ကို အစွမ်းထက်စေခြင်း&quot;,&quot;local&quot;:&quot;supercharge-your-training-loop-with-accelerate&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;နောက်တစ်ဆင့်များနှင့် အကောင်းဆုံးအလေ့အကျင့်များ&quot;,&quot;local&quot;:&quot;next-steps-and-best-practices&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;အခန်း၏ ဗဟုသုတစစ်ဆေးခြင်း&quot;,&quot;local&quot;:&quot;section-quiz&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;1. Adam နှင့် AdamW optimizers များကြား အဓိကကွာခြားချက်က ဘာလဲ။&quot;,&quot;local&quot;:&quot;1-adam-နင-adamw-optimizers-မက-အဓကကခခကက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;2. training loop တစ်ခုတွင် လုပ်ဆောင်မှုများ၏ မှန်ကန်သော အစီအစဉ်က ဘာလဲ။&quot;,&quot;local&quot;:&quot;2-training-loop-တစခတင-လပဆငမမ-မနကနသ-အစအစဉက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;3. 🤗 Accelerate library သည် အဓိကအားဖြင့် ဘာကို ကူညီသလဲ။&quot;,&quot;local&quot;:&quot;3--accelerate-library-သည-အဓကအဖင-ဘက-ကညသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;4. training loop တစ်ခုတွင် batches များကို device သို့ ဘာကြောင့် ရွှေ့ရသလဲ။&quot;,&quot;local&quot;:&quot;4-training-loop-တစခတင-batches-မက-device-သ-ဘကင-ရရသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;5. evaluation မတိုင်မီ model.eval() က ဘာလုပ်သလဲ။&quot;,&quot;local&quot;:&quot;5-evaluation-မတငမ-modeleval-က-ဘလပသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;6. evaluation လုပ်နေစဉ် torch.no_grad() ရဲ့ ရည်ရွယ်ချက်က ဘာလဲ။&quot;,&quot;local&quot;:&quot;6-evaluation-လပနစဉ-torchnograd-ရ-ရညရယခကက-ဘလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;7. သင်၏ training loop တွင် 🤗 Accelerate ကို အသုံးပြုသောအခါ ဘာတွေ ပြောင်းလဲသွားသလဲ။&quot;,&quot;local&quot;:&quot;7-သင-training-loop-တင--accelerate-က-အသပသအခ-ဘတ-ပငလသသလ&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;ဝေါဟာရ ရှင်းလင်းချက် (Glossary)&quot;,&quot;local&quot;:&quot;ဝဟရ-ရငလငခက-glossary&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="a-full-training" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#a-full-training"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ပြည့်စုံသော Training Loop တစ်ခု</span></h1> <div class="flex space-x-1 absolute z-10 right-0 top-0"><a href="https://discuss.huggingface.co/t/chapter-3-questions" target="_blank"><img alt="Ask a Question" class="!m-0" src="https://img.shields.io/badge/Ask%20a%20question-ffcb4c.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgLTEgMTA0IDEwNiI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiMyMzFmMjA7fS5jbHMtMntmaWxsOiNmZmY5YWU7fS5jbHMtM3tmaWxsOiMwMGFlZWY7fS5jbHMtNHtmaWxsOiMwMGE5NGY7fS5jbHMtNXtmaWxsOiNmMTVkMjI7fS5jbHMtNntmaWxsOiNlMzFiMjM7fTwvc3R5bGU+PC9kZWZzPjx0aXRsZT5EaXNjb3Vyc2VfbG9nbzwvdGl0bGU+PGcgaWQ9IkxheWVyXzIiPjxnIGlkPSJMYXllcl8zIj48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik01MS44NywwQzIzLjcxLDAsMCwyMi44MywwLDUxYzAsLjkxLDAsNTIuODEsMCw1Mi44MWw1MS44Ni0uMDVjMjguMTYsMCw1MS0yMy43MSw1MS01MS44N1M4MCwwLDUxLjg3LDBaIi8+PHBhdGggY2xhc3M9ImNscy0yIiBkPSJNNTIuMzcsMTkuNzRBMzEuNjIsMzEuNjIsMCwwLDAsMjQuNTgsNjYuNDFsLTUuNzIsMTguNEwzOS40LDgwLjE3YTMxLjYxLDMxLjYxLDAsMSwwLDEzLTYwLjQzWiIvPjxwYXRoIGNsYXNzPSJjbHMtMyIgZD0iTTc3LjQ1LDMyLjEyYTMxLjYsMzEuNiwwLDAsMS0zOC4wNSw0OEwxOC44Niw4NC44MmwyMC45MS0yLjQ3QTMxLjYsMzEuNiwwLDAsMCw3Ny40NSwzMi4xMloiLz48cGF0aCBjbGFzcz0iY2xzLTQiIGQ9Ik03MS42MywyNi4yOUEzMS42LDMxLjYsMCwwLDEsMzguOCw3OEwxOC44Niw4NC44MiwzOS40LDgwLjE3QTMxLjYsMzEuNiwwLDAsMCw3MS42MywyNi4yOVoiLz48cGF0aCBjbGFzcz0iY2xzLTUiIGQ9Ik0yNi40Nyw2Ny4xMWEzMS42MSwzMS42MSwwLDAsMSw1MS0zNUEzMS42MSwzMS42MSwwLDAsMCwyNC41OCw2Ni40MWwtNS43MiwxOC40WiIvPjxwYXRoIGNsYXNzPSJjbHMtNiIgZD0iTTI0LjU4LDY2LjQxQTMxLjYxLDMxLjYxLDAsMCwxLDcxLjYzLDI2LjI5YTMxLjYxLDMxLjYxLDAsMCwwLTQ5LDM5LjYzbC0zLjc2LDE4LjlaIi8+PC9nPjwvZz48L3N2Zz4="></a> <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter3/section4.ipynb" target="_blank"><img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"></a> <a href="https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter3/section4.ipynb" target="_blank"><img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"></a></div> <iframe class="w-full xl:w-4/6 h-80" src="https://www.youtube-nocookie.com/embed/Dh9CL8fyG80" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <p data-svelte-h="svelte-1o2uogw">ယခု ကျွန်တော်တို့သည် <code>Trainer</code> class ကို အသုံးမပြုဘဲ၊ ခေတ်မီ PyTorch ၏ အကောင်းဆုံး အလေ့အကျင့်များနှင့်အတူ training loop တစ်ခုကို စတင်တည်ဆောက်ခြင်းဖြင့် ယခင်အပိုင်းတွင် ရရှိခဲ့သော ရလဒ်များအတိုင်း မည်သို့ရရှိနိုင်ကြောင်း လေ့လာပါမည်။ ထပ်မံ၍ သင်သည် အပိုင်း ၂ တွင် ဒေတာ စီမံဆောင်ရွက်မှု (data processing) ကို လုပ်ဆောင်ပြီးဖြစ်သည်ဟု ကျွန်တော်တို့ ယူဆပါသည်။ သင်လိုအပ်မည့် အရာအားလုံး၏ အကျဉ်းချုပ်ကို ဤတွင် ဖော်ပြထားသည်။</p> <blockquote class="tip" data-svelte-h="svelte-izqlv2"><p>🏗️ <strong>Scratch မှ Training လုပ်ခြင်း</strong>: ဤအပိုင်းသည် ယခင်အကြောင်းအရာများပေါ်တွင် အခြေခံထားသည်။ PyTorch training loops နှင့် အကောင်းဆုံးအလေ့အကျင့်များဆိုင်ရာ ပြည့်စုံသော လမ်းညွှန်ချက်များအတွက် <a href="https://huggingface.co/docs/transformers/main/en/training#train-in-native-pytorch" rel="nofollow">🤗 Transformers training documentation</a> နှင့် <a href="https://huggingface.co/learn/cookbook/en/fine_tuning_code_llm_on_single_gpu#model" rel="nofollow">custom training cookbook</a> ကို ကြည့်ရှုပါ။</p></blockquote> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, DataCollatorWithPadding
raw_datasets = load_dataset(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
checkpoint = <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">example</span>):
<span class="hljs-keyword">return</span> tokenizer(example[<span class="hljs-string">&quot;sentence1&quot;</span>], example[<span class="hljs-string">&quot;sentence2&quot;</span>], truncation=<span class="hljs-literal">True</span>)
tokenized_datasets = raw_datasets.<span class="hljs-built_in">map</span>(tokenize_function, batched=<span class="hljs-literal">True</span>)
data_collator = DataCollatorWithPadding(tokenizer=tokenizer)<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="prepare-for-training" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#prepare-for-training"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Training အတွက် ပြင်ဆင်ခြင်း</span></h3> <p data-svelte-h="svelte-1hderjf">ကျွန်တော်တို့၏ training loop ကို တကယ်တမ်း မရေးမီတွင် objects အချို့ကို သတ်မှတ်ရန် လိုအပ်ပါလိမ့်မည်။ ပထမဆုံးအရာများမှာ batches များကို ထပ်ခါတလဲလဲ လုပ်ဆောင်ရန် အသုံးပြုမည့် dataloaders များဖြစ်သည်။ သို့သော် ထို dataloaders များကို မသတ်မှတ်မီ၊ <code>Trainer</code> က ကျွန်တော်တို့အတွက် အလိုအလျောက် လုပ်ဆောင်ပေးခဲ့သော အရာအချို့ကို ဂရုစိုက်ရန်အတွက် ကျွန်တော်တို့၏ <code>tokenized_datasets</code> ကို postprocessing အနည်းငယ် လုပ်ရန်လိုအပ်သည်။ အထူးသဖြင့်၊ ကျွန်တော်တို့ လုပ်ရန်လိုအပ်သည်များမှာ</p> <ul data-svelte-h="svelte-1p3q9ex"><li>model က မမျှော်လင့်ထားသော (ဥပမာ <code>sentence1</code> နှင့် <code>sentence2</code> columns ကဲ့သို့) values များနှင့် ကိုက်ညီသော columns များကို ဖယ်ရှားပါ။</li> <li><code>label</code> column ကို <code>labels</code> ဟု ပြန်လည်အမည်ပြောင်းပါ (ဘာလို့လဲဆိုတော့ model က argument ကို <code>labels</code> ဟု အမည်ပေးထားတာကို မျှော်လင့်ထားလို့ပါ)။</li> <li>datasets ၏ format ကို PyTorch tensors များကို ပြန်ပို့မည့်အစား lists များကို ပြန်ပို့ရန် သတ်မှတ်ပါ။</li></ul> <p data-svelte-h="svelte-1hvrm35">ကျွန်တော်တို့၏ <code>tokenized_datasets</code> တွင် ထိုအဆင့်တစ်ခုစီအတွက် method တစ်ခုစီ ရှိသည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->tokenized_datasets = tokenized_datasets.remove_columns([<span class="hljs-string">&quot;sentence1&quot;</span>, <span class="hljs-string">&quot;sentence2&quot;</span>, <span class="hljs-string">&quot;idx&quot;</span>])
tokenized_datasets = tokenized_datasets.rename_column(<span class="hljs-string">&quot;label&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>)
tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)
tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].column_names<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1gselsu">ထို့နောက် ရလဒ်တွင် ကျွန်တော်တို့၏ model က လက်ခံမည့် columns များသာ ပါဝင်ခြင်း ရှိမရှိ စစ်ဆေးနိုင်သည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>]<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-e4e29n">ယခု ဒါတွေအားလုံး ပြီးသွားပြီဆိုတော့ ကျွန်တော်တို့၏ dataloaders များကို အလွယ်တကူ သတ်မှတ်နိုင်သည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader
train_dataloader = DataLoader(
tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>], shuffle=<span class="hljs-literal">True</span>, batch_size=<span class="hljs-number">8</span>, collate_fn=data_collator
)
eval_dataloader = DataLoader(
tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>], batch_size=<span class="hljs-number">8</span>, collate_fn=data_collator
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1dbloqh">ဒေတာ စီမံဆောင်ရွက်မှု (data processing) တွင် အမှားအယွင်းမရှိစေရန် လျင်မြန်စွာ စစ်ဆေးရန်အတွက် batch တစ်ခုကို ဤသို့ စစ်ဆေးနိုင်သည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
<span class="hljs-keyword">break</span>
{k: v.shape <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->{<span class="hljs-string">&#x27;attention_mask&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">65</span>]),
<span class="hljs-string">&#x27;input_ids&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">65</span>]),
<span class="hljs-string">&#x27;labels&#x27;</span>: torch.Size([<span class="hljs-number">8</span>]),
<span class="hljs-string">&#x27;token_type_ids&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">65</span>])}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-st6ail">training dataloader အတွက် <code>shuffle=True</code> ကို သတ်မှတ်ထားပြီး batch အတွင်းရှိ အများဆုံးအရှည်အထိ padding လုပ်ထားသောကြောင့် အမှန်တကယ် shape များသည် သင်အတွက် အနည်းငယ် ကွဲပြားနိုင်သည်ကို သတိပြုပါ။</p> <p data-svelte-h="svelte-q97d4a">ယခု ဒေတာ preprocessing ကို ကျွန်တော်တို့ အပြည့်အဝ ပြီးဆုံးသွားပြီဖြစ်ရာ (မည်သည့် ML (Machine Learning) practitioner အတွက်မဆို ကျေနပ်ဖွယ်ကောင်းသော်လည်း ရရှိရန်ခက်ခဲသော ပန်းတိုင်တစ်ခု) model ဆီသို့ ပြောင်းရအောင်။ ၎င်းကို ယခင်အပိုင်းတွင် ကျွန်တော်တို့ လုပ်ဆောင်ခဲ့သည့်အတိုင်း အတိအကျ instantiate လုပ်သည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-16ya5nu">training လုပ်နေစဉ် အားလုံးချောမွေ့စွာ ဖြစ်ပျက်စေရန်အတွက် ကျွန်တော်တို့၏ batch ကို model ထံ ပေးပို့သည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->outputs = model(**batch)
<span class="hljs-built_in">print</span>(outputs.loss, outputs.logits.shape)<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->tensor(<span class="hljs-number">0.5441</span>, grad_fn=&lt;NllLossBackward&gt;) torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">2</span>])<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1h5j7kg">🤗 Transformers model များအားလုံးသည် <code>labels</code> များကို ပေးဆောင်သောအခါ loss ကို ပြန်ပေးလိမ့်မည်ဖြစ်ပြီး ကျွန်တော်တို့သည် logits (ကျွန်တော်တို့၏ batch ရှိ input တစ်ခုစီအတွက် နှစ်ခုစီ၊ ထို့ကြောင့် size 8 x 2 tensor တစ်ခု) ကိုလည်း ရရှိသည်။</p> <p data-svelte-h="svelte-f8508e">ကျွန်တော်တို့၏ training loop ကို ရေးရန် အသင့်ဖြစ်ခါနီးပြီ။ ကျွန်တော်တို့ နှစ်ခုသာ လိုအပ်တော့သည်- optimizer နှင့် learning rate scheduler။ <code>Trainer</code> က လုပ်ဆောင်ခဲ့သည့်အရာများကို ကိုယ်တိုင် ပြန်လုပ်ရန် ကြိုးစားနေသောကြောင့် တူညီသော defaults များကို အသုံးပြုမည်။ <code>Trainer</code> မှ အသုံးပြုသော optimizer မှာ <code>AdamW</code> ဖြစ်သည်။ ၎င်းသည် Adam နှင့် တူသော်လည်း weight decay regularization အတွက် အနည်းငယ် ကွဲပြားမှုရှိသည် (Ilya Loshchilov နှင့် Frank Hutter ရေးသားသော <a href="https://arxiv.org/abs/1711.05101" rel="nofollow">“Decoupled Weight Decay Regularization”</a> ကို ကြည့်ပါ)။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW
optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">5e-5</span>)<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-1b7mdp2"><p>💡 <strong>ခေတ်မီ Optimization အကြံပြုချက်များ</strong>: ပိုမိုကောင်းမွန်သော စွမ်းဆောင်ရည်အတွက်၊ အောက်ပါတို့ကို စမ်းသပ်နိုင်သည်။</p> <ul><li><strong>Weight decay ပါသော AdamW</strong>: <code>AdamW(model.parameters(), lr=5e-5, weight_decay=0.01)</code></li> <li><strong>8-bit Adam</strong>: memory-efficient optimization အတွက် <code>bitsandbytes</code> ကို အသုံးပြုပါ။</li> <li><strong>မတူညီသော learning rates</strong>: large models များအတွက် learning rates နည်းပါးခြင်း (1e-5 မှ 3e-5) က ပိုမိုကောင်းမွန်စွာ အလုပ်လုပ်လေ့ရှိသည်။</li></ul> <p>🚀 <strong>Optimization အရင်းအမြစ်များ</strong>: optimizers များနှင့် training strategies များအကြောင်း <a href="https://huggingface.co/docs/transformers/main/en/performance#optimizer" rel="nofollow">🤗 Transformers optimization guide</a> တွင် ပိုမိုလေ့လာပါ။</p></blockquote> <p data-svelte-h="svelte-ehbs2n">နောက်ဆုံးအနေဖြင့်၊ default အားဖြင့် အသုံးပြုသော learning rate scheduler သည် အများဆုံးတန်ဖိုး (5e-5) မှ 0 အထိ linear decay သက်သက်ဖြစ်သည်။ ၎င်းကို မှန်ကန်စွာ သတ်မှတ်ရန်အတွက် ကျွန်တော်တို့ လုပ်ဆောင်မည့် training steps အရေအတွက်ကို သိရှိရန် လိုအပ်သည်၊ ၎င်းသည် ကျွန်တော်တို့ run လိုသော epochs အရေအတွက်ကို training batches အရေအတွက် (ကျွန်တော်တို့၏ training dataloader ၏ length) ဖြင့် မြှောက်ခြင်းဖြစ်သည်။ <code>Trainer</code> သည် default အားဖြင့် သုံး epochs ကို အသုံးပြုသောကြောင့် ကျွန်တော်တို့ ထိုအတိုင်း လိုက်နာမည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler
num_epochs = <span class="hljs-number">3</span>
num_training_steps = num_epochs * <span class="hljs-built_in">len</span>(train_dataloader)
lr_scheduler = get_scheduler(
<span class="hljs-string">&quot;linear&quot;</span>,
optimizer=optimizer,
num_warmup_steps=<span class="hljs-number">0</span>,
num_training_steps=num_training_steps,
)
<span class="hljs-built_in">print</span>(num_training_steps)<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-number">1377</span><!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="the-training-loop" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-training-loop"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Training Loop</span></h3> <p data-svelte-h="svelte-4ok8s0">နောက်ဆုံးတစ်ချက်- ကျွန်တော်တို့ GPU တစ်ခုကို အသုံးပြုနိုင်သည်ဆိုလျှင် ၎င်းကို အသုံးပြုလိုသည် (CPU ပေါ်တွင် training သည် မိနစ်အနည်းငယ်အစား နာရီများစွာ ကြာနိုင်သည်)။ ၎င်းကို လုပ်ဆောင်ရန်အတွက် ကျွန်တော်တို့၏ model နှင့် batches များကို တင်မည့် <code>device</code> တစ်ခုကို သတ်မှတ်သည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> torch
device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)
model.to(device)
device<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->device(<span class="hljs-built_in">type</span>=<span class="hljs-string">&#x27;cuda&#x27;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1jpqiod">ကျွန်တော်တို့ training လုပ်ရန် အသင့်ဖြစ်ပြီ။ training ပြီးဆုံးမည့်အချိန်ကို ခန့်မှန်းနိုင်ရန် <code>tqdm</code> library ကို အသုံးပြု၍ ကျွန်တော်တို့၏ training steps အရေအတွက်ပေါ်တွင် progress bar တစ်ခု ထည့်သွင်းသည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))
model.train()
<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_epochs):
<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
outputs = model(**batch)
loss = outputs.loss
loss.backward()
optimizer.step()
lr_scheduler.step()
optimizer.zero_grad()
progress_bar.update(<span class="hljs-number">1</span>)<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-1eklxvg"><p>💡 <strong>ခေတ်မီ Training Optimization များ</strong>: သင်၏ training loop ကို ပိုမိုထိရောက်စေရန်အတွက် အောက်ပါတို့ကို ထည့်သွင်းစဉ်းစားပါ။</p> <ul><li><strong>Gradient Clipping</strong>: <code>optimizer.step()</code> မတိုင်မီ <code>torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)</code> ကို ထည့်သွင်းပါ။</li> <li><strong>Mixed Precision</strong>: ပိုမိုမြန်ဆန်သော training အတွက် <code>torch.cuda.amp.autocast()</code> နှင့် <code>GradScaler</code> ကို အသုံးပြုပါ။</li> <li><strong>Gradient Accumulation</strong>: ပိုကြီးမားသော batch sizes များကို အတုယူရန် batches အများအပြားပေါ်တွင် gradients များကို စုဆောင်းပါ။</li> <li><strong>Checkpointing</strong>: training လုပ်ငန်းစဉ် ပြတ်တောက်သွားပါက ပြန်လည်စတင်နိုင်ရန် model checkpoints များကို အခါအားလျော်စွာ သိမ်းဆည်းပါ။</li></ul> <p>🔧 <strong>Implementation လမ်းညွှန်</strong>: ဤ optimization များ၏ အသေးစိတ်ဥပမာများအတွက် <a href="https://huggingface.co/docs/transformers/main/en/perf_train_gpu_one" rel="nofollow">🤗 Transformers efficient training guide</a> နှင့် <a href="https://huggingface.co/docs/transformers/main/en/optimizers" rel="nofollow">optimizers များ</a> ကို ကြည့်ရှုပါ။</p></blockquote> <p data-svelte-h="svelte-g09toq">training loop ၏ အဓိက အစိတ်အပိုင်းသည် နိဒါန်းတွင် ပါရှိသည့်ပုံစံနှင့် အလွန်တူညီကြောင်း သင်တွေ့ရပါလိမ့်မည်။ ကျွန်တော်တို့သည် မည်သည့်အစီရင်ခံမှုကိုမျှ တောင်းဆိုခြင်း မရှိသောကြောင့် ဤ training loop က model ၏ စွမ်းဆောင်ရည်နှင့် ပတ်သက်၍ ဘာမျှ ပြောပြမည်မဟုတ်ပါ။ ထိုအတွက် evaluation loop တစ်ခု ထည့်သွင်းရန် လိုအပ်သည်။</p> <h3 class="relative group"><a id="the-evaluation-loop" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-evaluation-loop"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Evaluation Loop</span></h3> <p data-svelte-h="svelte-1k1j4kf">ကျွန်တော်တို့ ယခင်က လုပ်ဆောင်ခဲ့သည့်အတိုင်း 🤗 Evaluate library မှ ပံ့ပိုးပေးထားသော metric တစ်ခုကို အသုံးပြုမည်။ ကျွန်တော်တို့သည် <code>metric.compute()</code> method ကို မြင်တွေ့ခဲ့ပြီးဖြစ်သော်လည်း metrics များသည် <code>add_batch()</code> method ဖြင့် prediction loop ကို လုပ်ဆောင်နေစဉ် batches များကို တကယ်တမ်း စုဆောင်းနိုင်ပါသည်။ batches အားလုံးကို စုဆောင်းပြီးသည်နှင့် <code>metric.compute()</code> ဖြင့် နောက်ဆုံးရလဒ်ကို ရရှိနိုင်ပါသည်။ evaluation loop တွင် ဤအရာအားလုံးကို မည်သို့ အကောင်အထည်ဖော်ရမည်ကို ဤတွင် ဖော်ပြထားသည်။</p> <blockquote class="tip" data-svelte-h="svelte-1yp9tui"><p>📊 <strong>Evaluation အကောင်းဆုံးအလေ့အကျင့်များ</strong>: ပိုမိုရှုပ်ထွေးသော evaluation strategies နှင့် metrics များအတွက် <a href="https://huggingface.co/docs/evaluate/" rel="nofollow">🤗 Evaluate documentation</a> နှင့် <a href="https://github.com/huggingface/evaluation-guidebook" rel="nofollow">comprehensive evaluation cookbook</a> ကို လေ့လာပါ။</p></blockquote> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> evaluate
metric = evaluate.load(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
model.<span class="hljs-built_in">eval</span>()
<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> eval_dataloader:
batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
<span class="hljs-keyword">with</span> torch.no_grad():
outputs = model(**batch)
logits = outputs.logits
predictions = torch.argmax(logits, dim=-<span class="hljs-number">1</span>)
metric.add_batch(predictions=predictions, references=batch[<span class="hljs-string">&quot;labels&quot;</span>])
metric.compute()<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->{<span class="hljs-string">&#x27;accuracy&#x27;</span>: <span class="hljs-number">0.8431372549019608</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.8907849829351535</span>}<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-swfkim">ထပ်မံ၍ သင်၏ရလဒ်များသည် model head initialization နှင့် data shuffling ရှိ ကျပန်း (randomness) ကြောင့် အနည်းငယ် ကွဲပြားနိုင်သော်လည်း ၎င်းတို့သည် အနီးစပ်ဆုံး တူညီသင့်သည်။</p> <blockquote class="tip" data-svelte-h="svelte-rqoyj9"><p>✏️ <strong>စမ်းသပ်ကြည့်ပါ။</strong> သင်၏ model ကို SST-2 dataset ပေါ်တွင် fine-tune လုပ်ရန် ယခင် training loop ကို ပြင်ဆင်ပါ။</p></blockquote> <h3 class="relative group"><a id="supercharge-your-training-loop-with-accelerate" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#supercharge-your-training-loop-with-accelerate"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>🤗 Accelerate ဖြင့် သင်၏ Training Loop ကို အစွမ်းထက်စေခြင်း</span></h3> <iframe class="w-full xl:w-4/6 h-80" src="https://www.youtube-nocookie.com/embed/s7dy8QRgjJ0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <p data-svelte-h="svelte-1g8av81">ကျွန်တော်တို့ ယခင်က သတ်မှတ်ခဲ့သော training loop သည် single CPU (Central Processing Unit) သို့မဟုတ် GPU (Graphics Processing Unit) ပေါ်တွင် ကောင်းစွာ အလုပ်လုပ်ပါသည်။ သို့သော် <a href="https://github.com/huggingface/accelerate" rel="nofollow">🤗 Accelerate</a> library ကို အသုံးပြု၍ အပြောင်းအလဲ အနည်းငယ်ဖြင့် GPUs များစွာ သို့မဟုတ် TPUs (Tensor Processing Units) များပေါ်တွင် distributed training (ဖြန့်ကျက်လေ့ကျင့်မှု) ကို ဖွင့်နိုင်ပါသည်။ 🤗 Accelerate သည် distributed training၊ mixed precision နှင့် device placement တို့၏ ရှုပ်ထွေးမှုများကို အလိုအလျောက် ကိုင်တွယ်ပေးပါသည်။ training နှင့် validation dataloaders များ ဖန်တီးခြင်းမှ စတင်၍ ကျွန်တော်တို့၏ manual training loop သည် ဤသို့ ဖြစ်ပါသည်။</p> <blockquote class="tip" data-svelte-h="svelte-nsv3uf"><p><strong>Accelerate Deep Dive</strong>: distributed training၊ mixed precision နှင့် hardware optimization အကြောင်း <a href="https://huggingface.co/docs/accelerate/" rel="nofollow">🤗 Accelerate documentation</a> တွင် အားလုံးကို လေ့လာပြီး <a href="https://huggingface.co/docs/transformers/main/en/accelerate" rel="nofollow">transformers documentation</a> တွင် လက်တွေ့ဥပမာများကို ရှာဖွေပါ။</p></blockquote> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator
<span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification, get_scheduler
accelerator = Accelerator()
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)
optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">3e-5</span>)
train_dl, eval_dl, model, optimizer = accelerator.prepare(
train_dataloader, eval_dataloader, model, optimizer
)
num_epochs = <span class="hljs-number">3</span>
num_training_steps = num_epochs * <span class="hljs-built_in">len</span>(train_dl)
lr_scheduler = get_scheduler(
<span class="hljs-string">&quot;linear&quot;</span>,
optimizer=optimizer,
num_warmup_steps=<span class="hljs-number">0</span>,
num_training_steps=num_training_steps,
)
progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))
model.train()
<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_epochs):
<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dl:
outputs = model(**batch)
loss = outputs.loss
accelerator.backward(loss)
optimizer.step()
lr_scheduler.step()
optimizer.zero_grad()
progress_bar.update(<span class="hljs-number">1</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-95wxu2">ပထမဆုံး ထည့်သွင်းရမည့် လိုင်းမှာ import လိုင်းဖြစ်သည်။ ဒုတိယလိုင်းတွင် <code>Accelerator</code> object တစ်ခုကို instantiate လုပ်ထားသည်၊ ၎င်းသည် ပတ်ဝန်းကျင်ကို ကြည့်ရှုပြီး မှန်ကန်သော distributed setup ကို initialize လုပ်ပေးမည်။ 🤗 Accelerate သည် သင့်အတွက် device placement ကို ကိုင်တွယ်ပေးသောကြောင့် model ကို device ပေါ်တွင် တင်မည့်လိုင်းများကို ဖယ်ရှားနိုင်သည် (သို့မဟုတ် သင်ပိုနှစ်သက်ပါက ၎င်းတို့ကို <code>device</code> အစား <code>accelerator.device</code> ကို အသုံးပြုရန် ပြောင်းလဲနိုင်သည်)။</p> <p data-svelte-h="svelte-6h1m9i">ထို့နောက် အလုပ်၏ အဓိကအစိတ်အပိုင်းကို dataloaders, model နှင့် optimizer တို့ကို <code>accelerator.prepare()</code> ထံ ပေးပို့သည့် လိုင်းတွင် လုပ်ဆောင်သည်။ ၎င်းသည် ထို objects များကို သင်၏ distributed training က ရည်ရွယ်ထားသည့်အတိုင်း အလုပ်လုပ်ကြောင်း သေချာစေရန် မှန်ကန်သော container ထဲတွင် ထည့်သွင်းပေးမည်။ ပြုလုပ်ရမည့် ကျန်ရှိသော အပြောင်းအလဲများမှာ batch ကို <code>device</code> ပေါ်တွင် တင်သည့်လိုင်းကို ဖယ်ရှားခြင်း (ထပ်မံ၍ သင် ၎င်းကို ထားလိုပါက <code>accelerator.device</code> ကို အသုံးပြုရန် ပြောင်းလဲနိုင်သည်) နှင့် <code>loss.backward()</code> ကို <code>accelerator.backward(loss)</code> ဖြင့် အစားထိုးခြင်းတို့ဖြစ်သည်။</p> <blockquote class="tip" data-svelte-h="svelte-130re8s"><p>⚠️ Cloud TPUs မှ ပေးဆောင်သော အရှိန်အဟုန်ကို အကျိုးခံစားရန်အတွက် သင်၏ samples များကို tokenizer ၏ <code>padding=&quot;max_length&quot;</code> နှင့် <code>max_length</code> arguments များဖြင့် fixed length တစ်ခုသို့ padding လုပ်ရန် ကျွန်ုပ်တို့ အကြံပြုပါသည်။</p></blockquote> <p data-svelte-h="svelte-udsbt6">သင် ကူးယူပြီး ကစားကြည့်လိုပါက 🤗 Accelerate ဖြင့် ပြည့်စုံသော training loop သည် ဤသို့ ဖြစ်ပါသည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator
<span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification, get_scheduler
accelerator = Accelerator()
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)
optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">3e-5</span>)
train_dl, eval_dl, model, optimizer = accelerator.prepare(
train_dataloader, eval_dataloader, model, optimizer
)
num_epochs = <span class="hljs-number">3</span>
num_training_steps = num_epochs * <span class="hljs-built_in">len</span>(train_dl)
lr_scheduler = get_scheduler(
<span class="hljs-string">&quot;linear&quot;</span>,
optimizer=optimizer,
num_warmup_steps=<span class="hljs-number">0</span>,
num_training_steps=num_training_steps,
)
progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))
model.train()
<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_epochs):
<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dl:
outputs = model(**batch)
loss = outputs.loss
accelerator.backward(loss)
optimizer.step()
lr_scheduler.step()
optimizer.zero_grad()
progress_bar.update(<span class="hljs-number">1</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1q8llwv">ဤ code ကို <code>train.py</code> script တစ်ခုထဲတွင် ထည့်သွင်းခြင်းဖြင့် မည်သည့် distributed setup အမျိုးအစားပေါ်တွင်မဆို ထို script ကို run နိုင်မည်ဖြစ်သည်။ သင်၏ distributed setup တွင် ၎င်းကို စမ်းသပ်ရန်အတွက် အောက်ပါ command ကို run ပါ။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->accelerate config<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1bv6x7b">၎င်းသည် သင့်အား မေးခွန်းအနည်းငယ် မေးပြီး သင်၏ အဖြေများကို configuration file တစ်ခုထဲတွင် dump လုပ်လိမ့်မည်၊ ၎င်းကို ဤ command မှ အသုံးပြုသည်။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->accelerate <span class="hljs-built_in">launch</span> train.py<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-15p5okf">၎င်းသည် distributed training ကို စတင်လိမ့်မည်။</p> <p data-svelte-h="svelte-1nzfqok">သင် ၎င်းကို Notebook (ဥပမာ Colab တွင် TPUs ဖြင့် စမ်းသပ်ရန်) တွင် စမ်းသပ်လိုပါက code ကို <code>training_function()</code> တစ်ခုထဲတွင် ကူးထည့်ပြီး နောက်ဆုံး cell တစ်ခုကို ဤသို့ run ပါ။</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> notebook_launcher
notebook_launcher(training_function)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-tgdmxn"><a href="https://github.com/huggingface/accelerate/tree/main/examples" rel="nofollow">🤗 Accelerate repo</a> တွင် ဥပမာများ ထပ်မံ ရှာဖွေနိုင်ပါသည်။</p> <blockquote class="tip" data-svelte-h="svelte-1folp5e"><p>🌐 <strong>Distributed Training</strong>: multi-GPU နှင့် multi-node training များအကြောင်း ပြည့်စုံသော အကြောင်းအရာများအတွက် <a href="https://huggingface.co/docs/transformers/main/en/perf_train_gpu_many" rel="nofollow">🤗 Transformers distributed training guide</a> နှင့် <a href="https://huggingface.co/docs/transformers/main/en/accelerate" rel="nofollow">scaling training cookbook</a> ကို ကြည့်ရှုပါ။</p></blockquote> <h3 class="relative group"><a id="next-steps-and-best-practices" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#next-steps-and-best-practices"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>နောက်တစ်ဆင့်များနှင့် အကောင်းဆုံးအလေ့အကျင့်များ</span></h3> <p data-svelte-h="svelte-x3or08">ယခု သင်သည် training ကို အစမှ အကောင်အထည်ဖော်နည်းကို သင်ယူပြီးပြီဖြစ်ရာ၊ ထုတ်လုပ်မှု (production) အတွက် ထပ်မံ ထည့်သွင်းစဉ်းစားရမည့် အချက်အချို့ ဤတွင် ဖော်ပြထားသည်။</p> <p data-svelte-h="svelte-jf66qy"><strong>Model Evaluation</strong>: သင်၏ model ကို accuracy သက်သက်မဟုတ်ဘဲ metrics များစွာဖြင့် အမြဲတမ်း အကဲဖြတ်ပါ။ ပြည့်စုံသော evaluation အတွက် 🤗 Evaluate library ကို အသုံးပြုပါ။</p> <p data-svelte-h="svelte-10hgvco"><strong>Hyperparameter Tuning</strong>: စနစ်တကျ hyperparameter optimization အတွက် Optuna သို့မဟုတ် Ray Tune ကဲ့သို့သော library များကို အသုံးပြုရန် စဉ်းစားပါ။</p> <p data-svelte-h="svelte-9gy3l7"><strong>Model Monitoring</strong>: training လုပ်နေစဉ် တစ်လျှောက်လုံး training metrics၊ learning curves နှင့် validation performance များကို မှတ်တမ်းတင်ပါ။</p> <p data-svelte-h="svelte-cxq0i6"><strong>Model Sharing</strong>: လေ့ကျင့်ပြီးသည်နှင့် သင်၏ model ကို Hugging Face Hub ပေါ်တွင် မျှဝေခြင်းဖြင့် လူအဖွဲ့အစည်း (community) အတွက် ရရှိနိုင်စေပါ။</p> <p data-svelte-h="svelte-qj123p"><strong>Efficiency</strong>: large models များအတွက် gradient checkpointing၊ parameter-efficient fine-tuning (LoRA, AdaLoRA) သို့မဟုတ် quantization methods ကဲ့သို့သော နည်းလမ်းများကို ထည့်သွင်းစဉ်းစားပါ။</p> <p data-svelte-h="svelte-sib0cr">ဒါက custom training loops တွေနဲ့ fine-tuning လုပ်ခြင်းအကြောင်း ကျွန်တော်တို့ရဲ့ နက်နက်နဲနဲ လေ့လာမှုကို နိဂုံးချုပ်လိုက်ပါပြီ။ ဒီနေရာမှာ သင်သင်ယူခဲ့တဲ့ ကျွမ်းကျင်မှုတွေက training process ပေါ်မှာ အပြည့်အဝ ထိန်းချုပ်ဖို့ လိုအပ်တဲ့အခါ ဒါမှမဟုတ် <code>Trainer</code> API က ပေးစွမ်းနိုင်တာထက် ကျော်လွန်တဲ့ custom training logic ကို အကောင်အထည်ဖော်ချင်တဲ့အခါ သင့်ကို အထောက်အကူပြုပါလိမ့်မယ်။</p> <h2 class="relative group"><a id="section-quiz" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#section-quiz"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>အခန်း၏ ဗဟုသုတစစ်ဆေးခြင်း</span></h2> <p data-svelte-h="svelte-1cnnhfl">custom training loops များနှင့် advanced training နည်းလမ်းများအကြောင်း သင့်နားလည်မှုကို စမ်းသပ်ပါ။</p> <h3 class="relative group"><a id="1-adam-နင-adamw-optimizers-မက-အဓကကခခကက-ဘလ" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#1-adam-နင-adamw-optimizers-မက-အဓကကခခကက-ဘလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>1. Adam နှင့် AdamW optimizers များကြား အဓိကကွာခြားချက်က ဘာလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->AdamW သည် မတူညီသော learning rate schedule ကို အသုံးပြုသည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->AdamW တွင် decoupled weight decay regularization ပါဝင်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->AdamW သည် transformer models များနှင့်သာ အလုပ်လုပ်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->AdamW သည် Adam ထက် memory ပိုမိုနည်းပါးစွာ လိုအပ်သည်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="2-training-loop-တစခတင-လပဆငမမ-မနကနသ-အစအစဉက-ဘလ" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#2-training-loop-တစခတင-လပဆငမမ-မနကနသ-အစအစဉက-ဘလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2. training loop တစ်ခုတွင် လုပ်ဆောင်မှုများ၏ မှန်ကန်သော အစီအစဉ်က ဘာလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->Forward pass → Backward pass → Optimizer step → Zero gradients<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->Forward pass → Backward pass → Optimizer step → Scheduler step → Zero gradients<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->Zero gradients → Forward pass → Optimizer step → Backward pass<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->Forward pass → Zero gradients → Backward pass → Optimizer step<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="3--accelerate-library-သည-အဓကအဖင-ဘက-ကညသလ" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#3--accelerate-library-သည-အဓကအဖင-ဘက-ကညသလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>3. 🤗 Accelerate library သည် အဓိကအားဖြင့် ဘာကို ကူညီသလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->forward pass ကို optimized လုပ်ခြင်းဖြင့် သင်၏ models များကို ပိုမိုမြန်ဆန်စွာ train လုပ်ခြင်း။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->အကောင်းဆုံး hyperparameters များကို အလိုအလျောက် ရွေးချယ်ခြင်း။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->code အပြောင်းအလဲ အနည်းငယ်ဖြင့် GPUs/TPUs များစွာတွင် distributed training ကို ဖွင့်နိုင်စေခြင်း။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->models များကို TensorFlow ကဲ့သို့သော မတူညီသော frameworks များသို့ ပြောင်းလဲခြင်း။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="4-training-loop-တစခတင-batches-မက-device-သ-ဘကင-ရရသလ" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#4-training-loop-တစခတင-batches-မက-device-သ-ဘကင-ရရသလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>4. training loop တစ်ခုတွင် batches များကို device သို့ ဘာကြောင့် ရွှေ့ရသလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->training ကို ပိုမိုမြန်ဆန်စေရန်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->computation လုပ်ဆောင်ရန်အတွက် model နှင့် data ကို တူညီသော device (CPU/GPU) ပေါ်တွင် ရှိရမည်ဖြစ်သောကြောင့်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->memory ချွေတာရန်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->DataLoader က လိုအပ်သောကြောင့်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="5-evaluation-မတငမ-modeleval-က-ဘလပသလ" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#5-evaluation-မတငမ-modeleval-က-ဘလပသလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>5. evaluation မတိုင်မီ model.eval() က ဘာလုပ်သလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->model parameters များကို freeze လုပ်ခြင်းဖြင့် ၎င်းတို့ကို update လုပ်လို့ မရအောင် တားဆီးသည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->dropout နှင့် batch normalization ကဲ့သို့သော layers များ၏ အပြုအမူကို inference အတွက် ပြောင်းလဲသည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->evaluation metrics အတွက် gradient computation ကို ဖွင့်ပေးသည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->evaluation metrics များကို အလိုအလျောက် တွက်ချက်သည်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="6-evaluation-လပနစဉ-torchnograd-ရ-ရညရယခကက-ဘလ" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#6-evaluation-လပနစဉ-torchnograd-ရ-ရညရယခကက-ဘလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>6. evaluation လုပ်နေစဉ် torch.no_grad() ရဲ့ ရည်ရွယ်ချက်က ဘာလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->model က predictions တွေ မလုပ်နိုင်အောင် တားဆီးရန်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->gradient tracking ကို ပိတ်ခြင်းဖြင့် memory ချွေတာရန်နှင့် computation ကို အရှိန်မြှင့်ရန်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->model အတွက် evaluation mode ကို ဖွင့်ရန်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->run များတစ်လျှောက် တူညီသောရလဒ်များ ရရှိစေရန်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <h3 class="relative group"><a id="7-သင-training-loop-တင--accelerate-က-အသပသအခ-ဘတ-ပငလသသလ" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#7-သင-training-loop-တင--accelerate-က-အသပသအခ-ဘတ-ပငလသသလ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>7. သင်၏ training loop တွင် 🤗 Accelerate ကို အသုံးပြုသောအခါ ဘာတွေ ပြောင်းလဲသွားသလဲ။</span></h3> <div><form><label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="0"> <!-- HTML_TAG_START -->သင်၏ training loop တစ်ခုလုံးကို အစမှ ပြန်ရေးရမည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="1"> <!-- HTML_TAG_START -->အဓိက objects များကို accelerator.prepare() ဖြင့် ထုပ်ပိုးပြီး loss.backward() အစား accelerator.backward() ကို အသုံးပြုရမည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="2"> <!-- HTML_TAG_START -->သင်၏ code တွင် GPUs အရေအတွက်ကို သတ်မှတ်ရန် လိုအပ်သည်။<!-- HTML_TAG_END --></label> <label class="block"><input autocomplete="off" class="form-input -mt-1.5 mr-2" name="choice" type="checkbox" value="3"> <!-- HTML_TAG_START -->သင်သည် မတူညီသော optimizer နှင့် scheduler ကို အသုံးပြုရမည်။<!-- HTML_TAG_END --></label> <div class="flex flex-row items-center mt-3"><button class="btn px-4 mr-4" type="submit" disabled>Submit</button> </div></form></div> <blockquote class="tip" data-svelte-h="svelte-13flwci"><p>💡 <strong>အဓိက အချက်များ:</strong></p> <ul><li>Manual training loops များသည် သင့်အား အပြည့်အဝ ထိန်းချုပ်ခွင့်ပေးသော်လည်း မှန်ကန်သော အစီအစဉ်ကို နားလည်ရန် လိုအပ်သည်- forward → backward → optimizer step → scheduler step → zero gradients။</li> <li>Weight decay ပါသော AdamW သည် transformer models များအတွက် အကြံပြုထားသော optimizer ဖြစ်သည်။</li> <li>မှန်ကန်သော အပြုအမူနှင့် ထိရောက်မှုအတွက် evaluation လုပ်နေစဉ် <code>model.eval()</code> နှင့် <code>torch.no_grad()</code> ကို အမြဲတမ်း အသုံးပြုပါ။</li> <li>🤗 Accelerate သည် code အပြောင်းအလဲ အနည်းငယ်ဖြင့် distributed training ကို လက်လှမ်းမီစေသည်။</li> <li>Device management (tensors များကို GPU/CPU သို့ ရွှေ့ခြင်း) သည် PyTorch operation များအတွက် အရေးကြီးသည်။</li> <li>Mixed precision၊ gradient accumulation နှင့် gradient clipping ကဲ့သို့သော ခေတ်မီနည်းလမ်းများသည် training ထိရောက်မှုကို သိသိသာသာ တိုးတက်စေနိုင်သည်။</li></ul></blockquote> <h2 class="relative group"><a id="ဝဟရ-ရငလငခက-glossary" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#ဝဟရ-ရငလငခက-glossary"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ဝေါဟာရ ရှင်းလင်းချက် (Glossary)</span></h2> <ul data-svelte-h="svelte-1otecbq"><li><strong>Training Loop</strong>: AI (Artificial Intelligence) မော်ဒယ်တစ်ခုကို ဒေတာများဖြင့် အကြိမ်ကြိမ် လေ့ကျင့်ပေးသည့် လုပ်ငန်းစဉ်။</li> <li><strong><code>Trainer</code> Class</strong>: 🤗 Transformers library မှ model များကို လေ့ကျင့်ရန်နှင့် အကဲဖြတ်ရန်အတွက် အသုံးပြုသော class။</li> <li><strong>PyTorch</strong>: Facebook (ယခု Meta) က ဖန်တီးထားတဲ့ open-source machine learning library တစ်ခုဖြစ်ပြီး deep learning မော်ဒယ်တွေ တည်ဆောက်ဖို့အတွက် အသုံးပြုပါတယ်။</li> <li><strong>Data Processing</strong>: ဒေတာများကို model က နားလည်ပြီး လုပ်ဆောင်နိုင်တဲ့ ပုံစံအဖြစ် ပြောင်းလဲပြင်ဆင်ခြင်း လုပ်ငန်းစဉ်။</li> <li><strong>Dataloaders</strong>: Datasets များမှ ဒေတာများကို batches အလိုက် ထုတ်ယူပေးသည့် PyTorch utility class။</li> <li><strong>Batch</strong>: မတူညီသော input များစွာကို တစ်ပြိုင်နက်တည်း လုပ်ဆောင်နိုင်ရန် အုပ်စုဖွဲ့ခြင်း။</li> <li><strong>Postprocessing</strong>: Preprocessing လုပ်ပြီးနောက် ဒေတာများကို ထပ်မံပြင်ဆင်ခြင်း လုပ်ငန်းစဉ်။</li> <li><strong><code>tokenized_datasets</code></strong>: Tokenization ပြုလုပ်ပြီးသော dataset များ ပါဝင်သော object။</li> <li><strong><code>remove_columns()</code> Method</strong>: Dataset မှ မလိုအပ်သော columns များကို ဖယ်ရှားရန် အသုံးပြုသော method။</li> <li><strong><code>rename_column()</code> Method</strong>: Dataset ၏ column အမည်ကို ပြောင်းလဲရန် အသုံးပြုသော method။</li> <li><strong><code>set_format(&quot;torch&quot;)</code> Method</strong>: Dataset ၏ output format ကို PyTorch tensors အဖြစ် ပြောင်းလဲရန် သတ်မှတ်သော method။</li> <li><strong>PyTorch Tensors</strong>: PyTorch framework မှာ data တွေကို ကိုယ်စားပြုသော multi-dimensional array များ။</li> <li><strong><code>torch.utils.data.DataLoader</code></strong>: PyTorch မှာ dataloaders များကို ဖန်တီးရန် အသုံးပြုသော class။</li> <li><strong><code>shuffle=True</code></strong>: <code>DataLoader</code> တွင် samples များကို training လုပ်နေစဉ် ကျပန်း (randomly) ရောနှောရန် သတ်မှတ်သော parameter။</li> <li><strong><code>batch_size</code></strong>: batch တစ်ခုစီတွင် ပါဝင်မည့် samples အရေအတွက်။</li> <li><strong><code>collate_fn</code></strong>: batch တစ်ခုအတွင်း samples များကို စုစည်းပေးသော function (ဥပမာ- <code>DataCollatorWithPadding</code>)။</li> <li><strong><code>DataCollatorWithPadding</code></strong>: Hugging Face Transformers library မှ ပံ့ပိုးပေးသော class တစ်ခုဖြစ်ပြီး dynamic padding ကို အသုံးပြု၍ batch တစ်ခုအတွင်း samples များကို စုစည်းပေးသည်။</li> <li><strong>Model</strong>: Artificial Intelligence (AI) နယ်ပယ်တွင် အချက်အလက်များကို လေ့လာပြီး ခန့်မှန်းချက်များ ပြုလုပ်ရန် ဒီဇိုင်းထုတ်ထားသော သင်္ချာဆိုင်ရာဖွဲ့စည်းပုံ။</li> <li><strong><code>AutoModelForSequenceClassification</code></strong>: Hugging Face Transformers library မှာ ပါဝင်တဲ့ class တစ်ခုဖြစ်ပြီး sequence classification အတွက် pre-trained model ကို အလိုအလျောက် load လုပ်ပေးသည်။</li> <li><strong><code>num_labels</code></strong>: Classification လုပ်ငန်းအတွက် label (အမျိုးအစား) အရေအတွက်။</li> <li><strong>`outputs = model(</strong>batch)`**: Model ကို input batch ပေးပို့ပြီး output ရယူခြင်း။</li> <li><strong><code>outputs.loss</code></strong>: Model ၏ output မှ ပြန်ပေးသော loss တန်ဖိုး။</li> <li><strong><code>outputs.logits</code></strong>: Model ၏ output မှ ပြန်ပေးသော raw, unnormalized scores များ။</li> <li><strong>Optimizer</strong>: Model ၏ parameters များကို လေ့ကျင့်နေစဉ် update လုပ်ရန် အသုံးပြုသော algorithm။</li> <li><strong>Learning Rate Scheduler</strong>: Training လုပ်နေစဉ် learning rate ကို အချိန်ကြာလာသည်နှင့်အမျှ ပြောင်းလဲသွားစေရန် နည်းလမ်း။</li> <li><strong><code>AdamW</code></strong>: <code>Adam</code> optimizer ၏ မူကွဲတစ်ခုဖြစ်ပြီး weight decay regularization ကို ပိုမိုထိရောက်စွာ လုပ်ဆောင်သည်။<ul><li><strong>Adam (Adaptive Moment Estimation)</strong>: Deep learning တွင် အသုံးများသော optimizer တစ်ခုဖြစ်ပြီး learning rate ကို အလိုအလျောက် ချိန်ညှိပေးသည်။</li> <li><strong>Weight Decay Regularization</strong>: model ၏ weights များကို သေးငယ်အောင် ထိန်းညှိခြင်းဖြင့် overfitting ကို လျှော့ချရန် အသုံးပြုသော နည်းလမ်း။</li> <li><strong>Decoupled Weight Decay</strong>: Weight decay ကို gradient update များနှင့် သီးခြားစီ လုပ်ဆောင်ခြင်း။</li></ul></li> <li><strong><code>model.parameters()</code></strong>: model ၏ လေ့ကျင့်နိုင်သော parameters (weights နှင့် biases) များကို ပြန်ပေးသော method။</li> <li><strong><code>lr</code> (Learning Rate)</strong>: Training လုပ်နေစဉ် model ၏ weights များကို update လုပ်ရာတွင် အသုံးပြုသော step size။</li> <li><strong><code>get_scheduler()</code> Function</strong>: Hugging Face Transformers library မှ learning rate scheduler တစ်ခုကို ဖန်တီးရန် အသုံးပြုသော function။</li> <li><strong>Linear Decay</strong>: Learning rate ကို အချိန်ကြာလာသည်နှင့်အမျှ လိုင်းဖြောင့်အတိုင်း (linearly) လျှော့ချသွားသော scheduling နည်းလမ်း။</li> <li><strong><code>num_warmup_steps</code></strong>: learning rate ကို တိုးမြှင့်မည့် training steps အရေအတွက်။</li> <li><strong><code>num_training_steps</code></strong>: training လုပ်ငန်းစဉ်၏ စုစုပေါင်း steps အရေအတွက်။</li> <li><strong><code>device</code></strong>: Model နှင့် data များကို ထားရှိမည့် computing device (CPU သို့မဟုတ် GPU)။</li> <li><strong><code>torch.device(&quot;cuda&quot;)</code></strong>: GPU (CUDA enabled) ကို အသုံးပြုရန် သတ်မှတ်ခြင်း။</li> <li><strong><code>torch.device(&quot;cpu&quot;)</code></strong>: CPU ကို အသုံးပြုရန် သတ်မှတ်ခြင်း။</li> <li><strong><code>model.to(device)</code></strong>: Model ကို သတ်မှတ်ထားသော device သို့ ရွှေ့ပြောင်းခြင်း။</li> <li><strong><code>tqdm</code> (Library)</strong>: Python loop များအတွက် progress bars များကို ဖန်တီးရန် အသုံးပြုသော library။</li> <li><strong><code>tqdm.auto.tqdm</code></strong>: <code>tqdm</code> library မှ progress bar class။</li> <li><strong><code>progress_bar.update(1)</code></strong>: progress bar ကို တစ် step တိုးမြှင့်ခြင်း။</li> <li><strong><code>model.train()</code> Method</strong>: Model ကို training mode သို့ ပြောင်းလဲခြင်း။ ၎င်းသည် dropout နှင့် batch normalization ကဲ့သို့သော layers များကို training အတွက် သင့်လျော်သောအပြုအမူသို့ ပြောင်းလဲပေးသည်။</li> <li><strong><code>batch = {k: v.to(device) for k, v in batch.items()}</code></strong>: batch ထဲရှိ tensors များကို သတ်မှတ်ထားသော device သို့ ရွှေ့ပြောင်းခြင်း။</li> <li><strong><code>loss.backward()</code> Method</strong>: PyTorch မှာ backpropagation ကို လုပ်ဆောင်ပြီး model ၏ parameters တွေအတွက် gradients များကို တွက်ချက်သော method။</li> <li><strong><code>optimizer.step()</code> Method</strong>: တွက်ချက်ထားသော gradients များကို အသုံးပြုပြီး model ၏ parameters များကို update လုပ်သော optimizer method။</li> <li><strong><code>lr_scheduler.step()</code> Method</strong>: Learning rate scheduler ကို update လုပ်သော method။</li> <li><strong><code>optimizer.zero_grad()</code> Method</strong>: Optimizer အတွင်းရှိ gradient များကို zero ပြန်လုပ်ခြင်း (နောက်ထပ် batch အတွက် gradient များကို စုပုံခြင်းမှ ကာကွယ်ရန်)။</li> <li><strong>Gradient Clipping</strong>: Gradients များ၏ တန်ဖိုးကို ကန့်သတ်ခြင်းဖြင့် gradient exploding ပြဿနာကို ကာကွယ်သော နည်းလမ်း။</li> <li><strong><code>torch.nn.utils.clip_grad_norm_</code></strong>: PyTorch function တစ်ခုဖြစ်ပြီး gradients များကို clip လုပ်ရန် အသုံးပြုသည်။</li> <li><strong><code>max_norm</code></strong>: Gradient clipping လုပ်ရာတွင် သတ်မှတ်သော အများဆုံး norm တန်ဖိုး။</li> <li><strong><code>torch.cuda.amp.autocast()</code></strong>: PyTorch တွင် mixed precision training ကို အသုံးပြုရန်အတွက် context manager။</li> <li><strong><code>GradScaler</code></strong>: PyTorch တွင် mixed precision training အတွက် gradients များကို scale လုပ်ရန် အသုံးပြုသော class။</li> <li><strong>Gradient Accumulation</strong>: GPU memory ကန့်သတ်ချက်ရှိသောအခါ ပိုကြီးမားသော batch sizes များကို အတုယူရန် batches အများအပြားပေါ်တွင် gradients များကို စုဆောင်းပြီးမှ update လုပ်ခြင်း။</li> <li><strong>Checkpointing</strong>: Model parameters များကို အခါအားလျော်စွာ သိမ်းဆည်းထားခြင်း။</li> <li><strong><code>model.eval()</code> Method</strong>: Model ကို evaluation mode သို့ ပြောင်းလဲခြင်း။ ၎င်းသည် dropout နှင့် batch normalization ကဲ့သို့သော layers များကို inference အတွက် သင့်လျော်သောအပြုအမူသို့ ပြောင်းလဲပေးသည်။</li> <li><strong><code>torch.no_grad()</code></strong>: PyTorch တွင် gradient တွက်ချက်မှုကို ပိတ်ရန်အတွက် context manager။ Evaluation လုပ်နေစဉ် memory ချွေတာရန်နှင့် အရှိန်မြှင့်ရန် အသုံးပြုသည်။</li> <li><strong><code>torch.argmax(logits, dim=-1)</code></strong>: Logits များမှ အများဆုံးတန်ဖိုးရှိသော index ကို ယူခြင်းဖြင့် prediction ကို ရရှိစေသည်။ <code>dim=-1</code> ဆိုသည်မှာ နောက်ဆုံး dimension ကို ဆိုလိုသည်။</li> <li><strong><code>metric.add_batch()</code> Method</strong>: 🤗 Evaluate library ၏ metric object ၏ method ဖြစ်ပြီး predictions နှင့် references များကို batch အလိုက် စုဆောင်းပေးသည်။</li> <li><strong><code>metric.compute()</code> Method</strong>: စုဆောင်းထားသော predictions နှင့် references များမှ နောက်ဆုံး metric value ကို တွက်ချက်ရန် metric object ၏ method။</li> <li><strong><code>tqdm</code> (Library)</strong>: Python loop များအတွက် progress bars များကို ဖန်တီးရန် အသုံးပြုသော library။</li> <li><strong><code>randomness</code></strong>: ကျပန်းသဘောတရား၊ ကြိုတင်ခန့်မှန်း၍မရသော အဖြစ်အပျက်များ။</li> <li><strong>SST-2 Dataset</strong>: GLUE benchmark ထဲက sentiment analysis task တစ်ခုဖြစ်ပြီး single sentences တွေ ပါဝင်ပါတယ်။</li> <li><strong>🤗 Accelerate Library</strong>: Hugging Face က ထုတ်လုပ်ထားတဲ့ library တစ်ခုဖြစ်ပြီး PyTorch training loops တွေကို code အပြောင်းအလဲ အနည်းငယ်နဲ့ distributed training (multiple GPUs, TPUs) မှာ run နိုင်အောင် ကူညီပေးပါတယ်။</li> <li><strong><code>Accelerator</code> Object</strong>: 🤗 Accelerate library မှ main object ဖြစ်ပြီး distributed setup ကို initialize လုပ်ပေးသည်။</li> <li><strong><code>accelerator.prepare()</code> Method</strong>: <code>Accelerator</code> object ၏ method ဖြစ်ပြီး dataloaders, model နှင့် optimizer များကို distributed training အတွက် သင့်လျော်သော container များအဖြစ် ထုပ်ပိုးပေးသည်။</li> <li><strong><code>accelerator.device</code></strong>: <code>Accelerator</code> object မှ ဖော်ပြသော လက်ရှိအသုံးပြုနေသော device (CPU သို့မဟုတ် GPU)။</li> <li><strong><code>accelerator.backward(loss)</code> Method</strong>: <code>Accelerator</code> object မှ gradient များကို တွက်ချက်ရန် အသုံးပြုသော method ဖြစ်ပြီး distributed training အတွက် မှန်ကန်စွာ လုပ်ဆောင်ပေးသည်။</li> <li><strong><code>accelerate config</code> Command</strong>: 🤗 Accelerate ကို စတင်အသုံးပြုရန်အတွက် configuration file တစ်ခုကို ဖန်တီးရန် အသုံးပြုသော command line tool။</li> <li><strong><code>accelerate launch train.py</code> Command</strong>: <code>train.py</code> script ကို distributed setup တွင် run ရန် အသုံးပြုသော command line tool။</li> <li><strong><code>notebook_launcher()</code> Function</strong>: 🤗 Accelerate library မှ function တစ်ခုဖြစ်ပြီး Notebook environment တွင် distributed training function များကို run နိုင်စေသည်။</li> <li><strong>Production Use</strong>: ဆော့ဖ်ဝဲလ် သို့မဟုတ် AI model တစ်ခုကို လက်တွေ့အသုံးချရန် အဆင့်။</li> <li><strong>Optuna / Ray Tune (Libraries)</strong>: Hyperparameter optimization အတွက် အသုံးပြုသော library များ။</li> <li><strong>Hyperparameter Tuning</strong>: Model ၏ စွမ်းဆောင်ရည်ကို အကောင်းဆုံးဖြစ်စေရန် hyperparameters များကို ရှာဖွေခြင်း လုပ်ငန်းစဉ်။</li> <li><strong>Model Monitoring</strong>: Training metrics, learning curves နှင့် validation performance များကို အချိန်နှင့်တစ်ပြေးညီ စောင့်ကြည့်ခြင်း။</li> <li><strong>Learning Curves</strong>: Training လုပ်နေစဉ် training loss နှင့် validation loss/metrics များကို ဂရပ်ဖြင့် ပြသထားခြင်း။</li> <li><strong>Parameter-efficient Fine-tuning (PEFT)</strong>: Model ၏ အချို့သော parameters များကိုသာ fine-tune လုပ်ခြင်းဖြင့် memory နှင့် computation ကို ချွေတာသော နည်းလမ်းများ (ဥပမာ- LoRA, AdaLoRA)။<ul><li><strong>LoRA (Low-Rank Adaptation)</strong>: Pretrained model ၏ weights များကို freeze လုပ်ထားပြီး small, low-rank matrices များကိုသာ fine-tune လုပ်သော PEFT နည်းလမ်း။</li> <li><strong>AdaLoRA</strong>: LoRA ၏ မူကွဲတစ်ခုဖြစ်ပြီး adaptive rank selection ကို အသုံးပြုသည်။</li></ul></li> <li><strong>Quantization</strong>: Model ၏ parameters များကို floating-point မှ integer ကဲ့သို့သော ပိုမိုသေးငယ်သော data types များသို့ ပြောင်းလဲခြင်းဖြင့် memory အသုံးပြုမှုနှင့် computation ကို လျှော့ချသော နည်းလမ်း။</li> <li><strong>Gradient Checkpointing</strong>: Computation graph ၏ အချို့သော အလယ်အလတ် activations များကိုသာ သိမ်းဆည်းခြင်းဖြင့် memory အသုံးပြုမှုကို လျှော့ချသော နည်းလမ်း (backward pass အတွက် လိုအပ်သောအခါ ၎င်းတို့ကို ပြန်လည်တွက်ချက်သည်)။</li></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/course/blob/main/chapters/my/chapter3/4.mdx" target="_blank"><span data-svelte-h="svelte-1kd6by1">&lt;</span> <span data-svelte-h="svelte-x0xyl0">&gt;</span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_dep9rk = {
assets: "/docs/course/pr_1107/my",
base: "/docs/course/pr_1107/my",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/course/pr_1107/my/_app/immutable/entry/start.5c6233a8.js"),
import("/docs/course/pr_1107/my/_app/immutable/entry/app.55586789.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 26],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
129 kB
·
Xet hash:
cb71abf4ab422cd6d388db5c8dc8a77600a1a36a5fc05fba3fdb04e5b09b4207

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.