import{s as _n,f as Oe,o as Cn,n as bn}from"../chunks/scheduler.37c15a92.js";import{S as kn,i as Un,g as r,s as a,r as m,A as Fn,h as o,f as i,c as s,j as ki,u,x as d,k as T,y as jn,a as n,v as g,d as f,t as c,w as h,m as Ne,n as De}from"../chunks/index.2bf4358c.js";import{T as Ze}from"../chunks/Tip.363c041f.js";import{C as Sn}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Ln}from"../chunks/CourseFloatingBanner.15ba07e6.js";import{Q as Ke}from"../chunks/Question.668688bc.js";import{H as $,E as zn}from"../chunks/EditOnGithub.8916dc7c.js";function Jn(w){let p;return{c(){p=Ne(`Consider SFT only if you:
- Need additional performance beyond what prompting can achieve
- Have a specific use case where the cost of using a large general-purpose model outweighs the cost of fine-tuning a smaller model
- Require specialized output formats or domain-specific knowledge that existing models struggle with`)},l(l){p=De(l,`Consider SFT only if you:
- Need additional performance beyond what prompting can achieve
- Have a specific use case where the cost of using a large general-purpose model outweighs the cost of fine-tuning a smaller model
- Require specialized output formats or domain-specific knowledge that existing models struggle with`)},m(l,v){n(l,p,v)},d(l){l&&i(p)}}}function Rn(w){let p,l,v="This evaluation will help determine if SFT is the right approach for your needs.";return{c(){p=Ne(`Before starting SFT, evaluate whether your use case requires:
- Precise output formatting
- Domain-specific knowledge
- Consistent response patterns
- Adherence to specific guidelines
`),l=r("p"),l.textContent=v},l(y){p=De(y,`Before starting SFT, evaluate whether your use case requires:
- Precise output formatting
- Domain-specific knowledge
- Consistent response patterns
- Adherence to specific guidelines
`),l=o(y,"P",{"data-svelte-h":!0}),d(l)!=="svelte-ktd560"&&(l.textContent=v)},m(y,M){n(y,p,M),n(y,l,M)},p:bn,d(y){y&&(i(p),i(l))}}}function Hn(w){let p;return{c(){p=Ne(`Start with conservative values and adjust based on monitoring:
- Begin with 1-3 epochs
- Use smaller batch sizes initially
- Monitor validation metrics closely
- Adjust learning rate if training is unstable`)},l(l){p=De(l,`Start with conservative values and adjust based on monitoring:
- Begin with 1-3 epochs
- Use smaller batch sizes initially
- Monitor validation metrics closely
- Adjust learning rate if training is unstable`)},m(l,v){n(l,p,v)},d(l){l&&i(p)}}}function qn(w){let p;return{c(){p=Ne(`When using a dataset with a "messages" field (like the example above), the SFTTrainer automatically applies the model's chat template, which it retrieves from the hub. This means you don't need any additional configuration to handle chat-style conversations - the trainer will format the messages according to the model's expected template format.`)},l(l){p=De(l,`When using a dataset with a "messages" field (like the example above), the SFTTrainer automatically applies the model's chat template, which it retrieves from the hub. This means you don't need any additional configuration to handle chat-style conversations - the trainer will format the messages according to the model's expected template format.`)},m(l,v){n(l,p,v)},d(l){l&&i(p)}}}function En(w){let p;return{c(){p=Ne(`Watch for these warning signs during training:
1. Validation loss increasing while training loss decreases (overfitting)
2. No significant improvement in loss values (underfitting)
3. Extremely low loss values (potential memorization)
4. Inconsistent output formatting (template learning issues)`)},l(l){p=De(l,`Watch for these warning signs during training:
1. Validation loss increasing while training loss decreases (overfitting)
2. No significant improvement in loss values (underfitting)
3. Extremely low loss values (potential memorization)
4. Inconsistent output formatting (template learning issues)`)},m(l,v){n(l,p,v)},d(l){l&&i(p)}}}function Pn(w){let p;return{c(){p=Ne("Monitor both the loss values and the model's actual outputs during training. Sometimes the loss can look good while the model develops unwanted behaviors. Regular qualitative evaluation of the model's responses helps catch issues that metrics alone might miss.")},l(l){p=De(l,"Monitor both the loss values and the model's actual outputs during training. Sometimes the loss can look good while the model develops unwanted behaviors. Regular qualitative evaluation of the model's responses helps catch issues that metrics alone might miss.")},m(l,v){n(l,p,v)},d(l){l&&i(p)}}}function In(w){let p;return{c(){p=Ne(`Document your training process, including:
- Dataset characteristics
- Training parameters
- Performance metrics
- Known limitations
This documentation will be valuable for future model iterations.`)},l(l){p=De(l,`Document your training process, including:
- Dataset characteristics
- Training parameters
- Performance metrics
- Known limitations
This documentation will be valuable for future model iterations.`)},m(l,v){n(l,p,v)},d(l){l&&i(p)}}}function Wn(w){let p,l,v,y,M,et,S,tt,L,Ui="Supervised Fine-Tuning (SFT) is a process primarily used to adapt pre-trained language models to follow instructions, engage in dialogue, and use specific output formats. While pre-trained models have impressive general capabilities, SFT helps transform them into assistant-like models that can better understand and respond to user prompts. This is typically done by training on datasets of human-written conversations and instructions.",it,z,Fi='This page provides a step-by-step guide to fine-tuning the <a href="https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B" rel="nofollow"><code>deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B</code></a> model using the <a href="https://huggingface.co/docs/trl/en/sft_trainer" rel="nofollow"><code>SFTTrainer</code></a>. By following these steps, you can adapt the model to perform specific tasks more effectively.',nt,J,at,R,ji="Before diving into implementation, it’s important to understand when SFT is the right choice for your project. As a first step, you should consider whether using an existing instruction-tuned model with well-crafted prompts would suffice for your use case. SFT involves significant computational resources and engineering effort, so it should only be pursued when prompting existing models proves insufficient.",st,_,lt,H,Si="If you determine that SFT is necessary, the decision to proceed depends on two primary factors:",rt,q,ot,E,Li="SFT allows precise control over the model’s output structure. This is particularly valuable when you need the model to:",pt,P,zi="<li>Generate responses in a specific chat template format</li> <li>Follow strict output schemas</li> <li>Maintain consistent styling across responses</li>",mt,I,ut,W,Ji="When working in specialized domains, SFT helps align the model with domain-specific requirements by:",gt,B,Ri="<li>Teaching domain terminology and concepts</li> <li>Enforcing professional standards</li> <li>Handling technical queries appropriately</li> <li>Following industry-specific guidelines</li>",ft,C,ct,G,ht,Q,Hi="The supervised fine-tuning process requires a task-specific dataset structured with input-output pairs. Each pair should consist of:",dt,A,qi="<li>An input prompt</li> <li>The expected model response</li> <li>Any additional context or metadata</li>",$t,X,Ei="The quality of your training data is crucial for successful fine-tuning. Let’s look at how to prepare and validate your dataset:",vt,x,Pi,wt,V,Tt,Z,Ii="The success of your fine-tuning depends heavily on choosing the right training parameters. Let’s explore each important parameter and how to configure them effectively:",yt,N,Wi="The SFTTrainer configuration requires consideration of several parameters that control the training process. Let’s explore each parameter and their purpose:",Mt,D,Bi="<li><p><strong>Training Duration Parameters</strong>:</p> <ul><li><code>num_train_epochs</code>: Controls total training duration</li> <li><code>max_steps</code>: Alternative to epochs, sets maximum number of training steps</li> <li>More epochs allow better learning but risk overfitting</li></ul></li> <li><p><strong>Batch Size Parameters</strong>:</p> <ul><li><code>per_device_train_batch_size</code>: Determines memory usage and training stability</li> <li><code>gradient_accumulation_steps</code>: Enables larger effective batch sizes</li> <li>Larger batches provide more stable gradients but require more memory</li></ul></li> <li><p><strong>Learning Rate Parameters</strong>:</p> <ul><li><code>learning_rate</code>: Controls size of weight updates</li> <li><code>warmup_ratio</code>: Portion of training used for learning rate warmup</li> <li>Too high can cause instability, too low results in slow learning</li></ul></li> <li><p><strong>Monitoring Parameters</strong>:</p> <ul><li><code>logging_steps</code>: Frequency of metric logging</li> <li><code>eval_steps</code>: How often to evaluate on validation data</li> <li><code>save_steps</code>: Frequency of model checkpoint saves</li></ul></li>",xt,b,_t,Y,Ct,O,Gi="Now that we understand the key components, let’s implement the training with proper validation and monitoring. We will use the <code>SFTTrainer</code> class from the Transformers Reinforcement Learning (TRL) library, which is built on top of the <code>transformers</code> library. Here’s a complete example using the TRL library:",bt,K,kt,k,Ut,ee,Ft,te,Qi="The SFTTrainer supports example packing to optimize training efficiency through the <code>ConstantLengthDataset</code> utility class. This feature allows multiple short examples to be packed into the same input sequence, maximizing GPU utilization during training. To enable packing, simply set <code>packing=True</code> in the SFTConfig constructor. When using packed datasets with <code>max_steps</code>, be aware that you may train for more epochs than expected depending on your packing configuration. You can customize how examples are combined using a formatting function - particularly useful when working with datasets that have multiple fields like question-answer pairs. For evaluation datasets, you can disable packing by setting <code>eval_packing=False</code> in the SFTConfig. Here’s a basic example:",jt,ie,St,ne,Ai="Effective monitoring is crucial for successful fine-tuning. Let’s explore what to watch for during training:",Lt,ae,zt,se,Xi="Training loss typically follows three distinct phases:",Jt,le,Vi="<li>Initial Sharp Drop: Rapid adaptation to new data distribution</li> <li>Gradual Stabilization: Learning rate slows as model fine-tunes</li> <li>Convergence: Loss values stabilize, indicating training completion</li>",Rt,re,Zi,Ht,oe,qt,pe,Ni="Effective monitoring involves tracking quantitative metrics, and evaluating qualitative metrics. Available metrics are:",Et,me,Di="<li>Training loss</li> <li>Validation loss</li> <li>Learning rate progression</li> <li>Gradient norms</li>",Pt,U,It,ue,Wt,ge,Yi=`As training progresses, the loss curve should gradually stabilize. The key indicator of healthy training is a small gap between training and validation loss, suggesting
the model is learning generalizable patterns rather than memorizing specific examples. The absolute loss values will vary depending on your task and dataset.`,Bt,fe,Gt,ce,Oi="The graph above shows a typical training progression. Notice how both training and validation loss decrease sharply at first, then gradually level off. This pattern indicates the model is learning effectively while maintaining generalization ability.",Qt,he,At,de,Ki="Several patterns in the loss curves can indicate potential issues. Below we illustrate common warning signs and solutions that we can consider.",Xt,$e,en,Vt,ve,tn="If the validation loss decreases at a significantly slower rate than training loss, your model is likely overfitting to the training data. Consider:",Zt,we,nn="<li>Reducing the training steps</li> <li>Increasing the dataset size</li> <li>Validating dataset quality and diversity</li>",Nt,Te,an,Dt,ye,sn="If the loss doesn’t show significant improvement, the model might be:",Yt,Me,ln="<li>Learning too slowly (try increasing the learning rate)</li> <li>Struggling with the task (check data quality and task complexity)</li> <li>Hitting architecture limitations (consider a different model)</li>",Ot,xe,rn,Kt,_e,on="Extremely low loss values could suggest memorization rather than learning. This is particularly concerning if:",ei,Ce,pn="<li>The model performs poorly on new, similar examples</li> <li>The outputs lack diversity</li> <li>The responses are too similar to training examples</li>",ti,F,ii,be,mn='We should note that the interpretation of the loss values we outline here is aimed on the most common case, and in fact, loss values can behave on various ways depending on the model, the dataset, the training parameters, etc. If you interested in exploring more about outlined patterns, you should check out this blog post by the people at <a href="https://www.fast.ai/posts/2023-09-04-learning-jumps/" rel="nofollow">Fast AI</a>.',ni,ke,ai,Ue,un='In section <a href="/en/chapter11/4">11.4</a> we will learn how to evaluate the model using benchmark datasets. For now, we will focus on the qualitative evaluation of the model.',si,Fe,gn="After completing SFT, consider these follow-up actions:",li,je,fn="<li>Evaluate the model thoroughly on held-out test data</li> <li>Validate template adherence across various inputs</li> <li>Test domain-specific knowledge retention</li> <li>Monitor real-world performance metrics</li>",ri,j,oi,Se,pi,Le,mi,ze,ui,Je,gi,Re,fi,He,ci,qe,hi,Ee,di,Pe,$i,Ie,vi,We,wi,Be,Ti,Ge,cn="You’ve learned how to fine-tune models using SFT! To continue your learning:",yi,Qe,hn="<li>Try the notebook with different parameters</li> <li>Experiment with other datasets</li> <li>Contribute improvements to the course material</li>",Mi,Ae,xi,Xe,dn='<li><a href="https://huggingface.co/docs/trl" rel="nofollow">TRL Documentation</a></li> <li><a href="https://github.com/huggingface/trl/tree/main/examples/sft" rel="nofollow">SFT Examples Repository</a></li> <li><a href="https://huggingface.co/docs/transformers/training" rel="nofollow">Fine-tuning Best Practices</a></li>',_i,Ve,Ci,Ye,bi;return M=new Ln({props:{chapter:2,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/course/en/chapter11/section3.ipynb"}]}}),S=new $({props:{title:"Supervised Fine-Tuning",local:"supervised-fine-tuning",headingTag:"h1"}}),J=new $({props:{title:"When to Use SFT",local:"when-to-use-sft",headingTag:"h2"}}),_=new Ze({props:{$$slots:{default:[Jn]},$$scope:{ctx:w}}}),q=new $({props:{title:"Template Control",local:"template-control",headingTag:"h3"}}),I=new $({props:{title:"Domain Adaptation",local:"domain-adaptation",headingTag:"h3"}}),C=new Ze({props:{$$slots:{default:[Rn]},$$scope:{ctx:w}}}),G=new $({props:{title:"Dataset Preparation",local:"dataset-preparation",headingTag:"h2"}}),V=new $({props:{title:"Training Configuration",local:"training-configuration",headingTag:"h2"}}),b=new Ze({props:{$$slots:{default:[Hn]},$$scope:{ctx:w}}}),Y=new $({props:{title:"Implementation with TRL",local:"implementation-with-trl",headingTag:"h2"}}),K=new Sn({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBZnJvbSUyMHRybCUyMGltcG9ydCUyMFNGVENvbmZpZyUyQyUyMFNGVFRyYWluZXIlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQSUyMyUyMFNldCUyMGRldmljZSUwQWRldmljZSUyMCUzRCUyMCUyMmN1ZGElMjIlMjBpZiUyMHRvcmNoLmN1ZGEuaXNfYXZhaWxhYmxlKCklMjBlbHNlJTIwJTIyY3B1JTIyJTBBJTBBJTIzJTIwTG9hZCUyMGRhdGFzZXQlMEFkYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMkh1Z2dpbmdGYWNlVEIlMkZzbW9sdGFsayUyMiklMEElMEElMjMlMjBDb25maWd1cmUlMjB0cmFpbmVyJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFNGVENvbmZpZyglMEElMjAlMjAlMjAlMjBvdXRwdXRfZGlyJTNEJTIyLiUyRnNmdF9vdXRwdXQlMjIlMkMlMEElMjAlMjAlMjAlMjBtYXhfc3RlcHMlM0QxMDAwJTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV90cmFpbl9iYXRjaF9zaXplJTNENCUyQyUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0Q1ZS01JTJDJTBBJTIwJTIwJTIwJTIwbG9nZ2luZ19zdGVwcyUzRDEwJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV9zdGVwcyUzRDEwMCUyQyUwQSUyMCUyMCUyMCUyMGV2YWx1YXRpb25fc3RyYXRlZ3klM0QlMjJzdGVwcyUyMiUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfc3RlcHMlM0Q1MCUyQyUwQSklMEElMEElMjMlMjBJbml0aWFsaXplJTIwdHJhaW5lciUwQXRyYWluZXIlMjAlM0QlMjBTRlRUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTNEbW9kZWwlMkMlMEElMjAlMjAlMjAlMjBhcmdzJTNEdHJhaW5pbmdfYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0RkYXRhc2V0JTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0RkYXRhc2V0JTVCJTIydGVzdCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSklMEElMEElMjMlMjBTdGFydCUyMHRyYWluaW5nJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> trl <span class="hljs-keyword">import</span> SFTConfig, SFTTrainer
<span class="hljs-keyword">import</span> torch

<span class="hljs-comment"># Set device</span>
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> <span class="hljs-string">&quot;cpu&quot;</span>

<span class="hljs-comment"># Load dataset</span>
dataset = load_dataset(<span class="hljs-string">&quot;HuggingFaceTB/smoltalk&quot;</span>)

<span class="hljs-comment"># Configure trainer</span>
training_args = SFTConfig(
    output_dir=<span class="hljs-string">&quot;./sft_output&quot;</span>,
    max_steps=<span class="hljs-number">1000</span>,
    per_device_train_batch_size=<span class="hljs-number">4</span>,
    learning_rate=<span class="hljs-number">5e-5</span>,
    logging_steps=<span class="hljs-number">10</span>,
    save_steps=<span class="hljs-number">100</span>,
    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    eval_steps=<span class="hljs-number">50</span>,
)

<span class="hljs-comment"># Initialize trainer</span>
trainer = SFTTrainer(
    model=model,
    args=training_args,
    train_dataset=dataset[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=dataset[<span class="hljs-string">&quot;test&quot;</span>],
    tokenizer=tokenizer,
)

<span class="hljs-comment"># Start training</span>
trainer.train()`,wrap:!1}}),k=new Ze({props:{$$slots:{default:[qn]},$$scope:{ctx:w}}}),ee=new $({props:{title:"Packing the Dataset",local:"packing-the-dataset",headingTag:"h2"}}),ie=new $({props:{title:"Monitoring Training Progress",local:"monitoring-training-progress",headingTag:"h2"}}),ae=new $({props:{title:"Understanding Loss Patterns",local:"understanding-loss-patterns",headingTag:"h3"}}),oe=new $({props:{title:"Metrics to Monitor",local:"metrics-to-monitor",headingTag:"h3"}}),U=new Ze({props:{warning:!0,$$slots:{default:[En]},$$scope:{ctx:w}}}),ue=new $({props:{title:"The Path to Convergence",local:"the-path-to-convergence",headingTag:"h3"}}),fe=new $({props:{title:"Monitoring Training Progress",local:"monitoring-training-progress",headingTag:"h3"}}),he=new $({props:{title:"Warning Signs to Watch For",local:"warning-signs-to-watch-for",headingTag:"h3"}}),F=new Ze({props:{warning:!0,$$slots:{default:[Pn]},$$scope:{ctx:w}}}),ke=new $({props:{title:"Evaluation after SFT",local:"evaluation-after-sft",headingTag:"h2"}}),j=new Ze({props:{$$slots:{default:[In]},$$scope:{ctx:w}}}),Se=new $({props:{title:"Quiz",local:"quiz",headingTag:"h2"}}),Le=new $({props:{title:"1. What parameters control the training duration in SFT?",local:"1-what-parameters-control-the-training-duration-in-sft",headingTag:"h3"}}),ze=new Ke({props:{choices:[{text:"num_train_epochs and max_steps",explain:"Correct! These parameters determine how long the model will train, either by number of epochs or total steps.",correct:!0},{text:"batch_size and learning_rate",explain:"While these affect training, they don't directly control the duration."},{text:"gradient_checkpointing and warmup_ratio",explain:"These parameters affect training efficiency and stability, not duration."}]}}),Je=new $({props:{title:"2. Which pattern in the loss curves indicates potential overfitting?",local:"2-which-pattern-in-the-loss-curves-indicates-potential-overfitting",headingTag:"h3"}}),Re=new Ke({props:{choices:[{text:"Validation loss increases while training loss continues to decrease",explain:"Correct! This divergence between training and validation loss is a classic sign of overfitting.",correct:!0},{text:"Both training and validation loss decrease steadily",explain:"This pattern actually indicates healthy training."},{text:"Training loss remains constant while validation loss decreases",explain:"This would be an unusual pattern and doesn't indicate overfitting."}]}}),He=new $({props:{title:"3. What is gradient_accumulation_steps used for?",local:"3-what-is-gradientaccumulationsteps-used-for",headingTag:"h3"}}),qe=new Ke({props:{choices:[{text:"To increase effective batch size without using more memory",explain:"Correct! It accumulates gradients across multiple forward passes before updating weights.",correct:!0},{text:"To save checkpoints during training",explain:"This is handled by save_steps and save_strategy parameters."},{text:"To control the learning rate schedule",explain:"Learning rate scheduling is controlled by learning_rate and warmup_ratio."}]}}),Ee=new $({props:{title:"4. What should you monitor during SFT training?",local:"4-what-should-you-monitor-during-sft-training",headingTag:"h3"}}),Pe=new Ke({props:{choices:[{text:"Both quantitative metrics and qualitative outputs",explain:"Correct! Monitoring both types of metrics helps catch all potential issues.",correct:!0},{text:"Only the training loss",explain:"Training loss alone isn't sufficient to ensure good model behavior."},{text:"Only the model's output quality",explain:"While important, qualitative evaluation alone misses important training dynamics."}]}}),Ie=new $({props:{title:"5. What indicates healthy convergence during training?",local:"5-what-indicates-healthy-convergence-during-training",headingTag:"h3"}}),We=new Ke({props:{choices:[{text:"A small gap between training and validation loss",explain:"Correct! This indicates the model is learning generalizable patterns.",correct:!0},{text:"Training loss reaching zero",explain:"Extremely low loss values might indicate memorization rather than learning."},{text:"Validation loss being lower than training loss",explain:"This would be unusual and might indicate problems with the validation set."}]}}),Be=new $({props:{title:"💐 Nice work!",local:"-nice-work",headingTag:"h2"}}),Ae=new $({props:{title:"Additional Resources",local:"additional-resources",headingTag:"h2"}}),Ve=new zn({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter11/3.mdx"}}),{c(){p=r("meta"),l=a(),v=r("p"),y=a(),m(M.$$.fragment),et=a(),m(S.$$.fragment),tt=a(),L=r("p"),L.textContent=Ui,it=a(),z=r("p"),z.innerHTML=Fi,nt=a(),m(J.$$.fragment),at=a(),R=r("p"),R.textContent=ji,st=a(),m(_.$$.fragment),lt=a(),H=r("p"),H.textContent=Si,rt=a(),m(q.$$.fragment),ot=a(),E=r("p"),E.textContent=Li,pt=a(),P=r("ol"),P.innerHTML=zi,mt=a(),m(I.$$.fragment),ut=a(),W=r("p"),W.textContent=Ji,gt=a(),B=r("ol"),B.innerHTML=Ri,ft=a(),m(C.$$.fragment),ct=a(),m(G.$$.fragment),ht=a(),Q=r("p"),Q.textContent=Hi,dt=a(),A=r("ol"),A.innerHTML=qi,$t=a(),X=r("p"),X.textContent=Ei,vt=a(),x=r("iframe"),wt=a(),m(V.$$.fragment),Tt=a(),Z=r("p"),Z.textContent=Ii,yt=a(),N=r("p"),N.textContent=Wi,Mt=a(),D=r("ol"),D.innerHTML=Bi,xt=a(),m(b.$$.fragment),_t=a(),m(Y.$$.fragment),Ct=a(),O=r("p"),O.innerHTML=Gi,bt=a(),m(K.$$.fragment),kt=a(),m(k.$$.fragment),Ut=a(),m(ee.$$.fragment),Ft=a(),te=r("p"),te.innerHTML=Qi,jt=a(),m(ie.$$.fragment),St=a(),ne=r("p"),ne.textContent=Ai,Lt=a(),m(ae.$$.fragment),zt=a(),se=r("p"),se.textContent=Xi,Jt=a(),le=r("ol"),le.innerHTML=Vi,Rt=a(),re=r("img"),Ht=a(),m(oe.$$.fragment),qt=a(),pe=r("p"),pe.textContent=Ni,Et=a(),me=r("ul"),me.innerHTML=Di,Pt=a(),m(U.$$.fragment),It=a(),m(ue.$$.fragment),Wt=a(),ge=r("p"),ge.textContent=Yi,Bt=a(),m(fe.$$.fragment),Gt=a(),ce=r("p"),ce.textContent=Oi,Qt=a(),m(he.$$.fragment),At=a(),de=r("p"),de.textContent=Ki,Xt=a(),$e=r("img"),Vt=a(),ve=r("p"),ve.textContent=tn,Zt=a(),we=r("ul"),we.innerHTML=nn,Nt=a(),Te=r("img"),Dt=a(),ye=r("p"),ye.textContent=sn,Yt=a(),Me=r("ul"),Me.innerHTML=ln,Ot=a(),xe=r("img"),Kt=a(),_e=r("p"),_e.textContent=on,ei=a(),Ce=r("ul"),Ce.innerHTML=pn,ti=a(),m(F.$$.fragment),ii=a(),be=r("p"),be.innerHTML=mn,ni=a(),m(ke.$$.fragment),ai=a(),Ue=r("p"),Ue.innerHTML=un,si=a(),Fe=r("p"),Fe.textContent=gn,li=a(),je=r("ol"),je.innerHTML=fn,ri=a(),m(j.$$.fragment),oi=a(),m(Se.$$.fragment),pi=a(),m(Le.$$.fragment),mi=a(),m(ze.$$.fragment),ui=a(),m(Je.$$.fragment),gi=a(),m(Re.$$.fragment),fi=a(),m(He.$$.fragment),ci=a(),m(qe.$$.fragment),hi=a(),m(Ee.$$.fragment),di=a(),m(Pe.$$.fragment),$i=a(),m(Ie.$$.fragment),vi=a(),m(We.$$.fragment),wi=a(),m(Be.$$.fragment),Ti=a(),Ge=r("p"),Ge.textContent=cn,yi=a(),Qe=r("ol"),Qe.innerHTML=hn,Mi=a(),m(Ae.$$.fragment),xi=a(),Xe=r("ul"),Xe.innerHTML=dn,_i=a(),m(Ve.$$.fragment),Ci=a(),Ye=r("p"),this.h()},l(e){const t=Fn("svelte-u9bgzb",document.head);p=o(t,"META",{name:!0,content:!0}),t.forEach(i),l=s(e),v=o(e,"P",{}),ki(v).forEach(i),y=s(e),u(M.$$.fragment,e),et=s(e),u(S.$$.fragment,e),tt=s(e),L=o(e,"P",{"data-svelte-h":!0}),d(L)!=="svelte-1r3e85q"&&(L.textContent=Ui),it=s(e),z=o(e,"P",{"data-svelte-h":!0}),d(z)!=="svelte-1lbymgt"&&(z.innerHTML=Fi),nt=s(e),u(J.$$.fragment,e),at=s(e),R=o(e,"P",{"data-svelte-h":!0}),d(R)!=="svelte-bzr0f8"&&(R.textContent=ji),st=s(e),u(_.$$.fragment,e),lt=s(e),H=o(e,"P",{"data-svelte-h":!0}),d(H)!=="svelte-1vu1858"&&(H.textContent=Si),rt=s(e),u(q.$$.fragment,e),ot=s(e),E=o(e,"P",{"data-svelte-h":!0}),d(E)!=="svelte-vqqipn"&&(E.textContent=Li),pt=s(e),P=o(e,"OL",{"data-svelte-h":!0}),d(P)!=="svelte-f2jeai"&&(P.innerHTML=zi),mt=s(e),u(I.$$.fragment,e),ut=s(e),W=o(e,"P",{"data-svelte-h":!0}),d(W)!=="svelte-63mafi"&&(W.textContent=Ji),gt=s(e),B=o(e,"OL",{"data-svelte-h":!0}),d(B)!=="svelte-14ez77z"&&(B.innerHTML=Ri),ft=s(e),u(C.$$.fragment,e),ct=s(e),u(G.$$.fragment,e),ht=s(e),Q=o(e,"P",{"data-svelte-h":!0}),d(Q)!=="svelte-1gnb02p"&&(Q.textContent=Hi),dt=s(e),A=o(e,"OL",{"data-svelte-h":!0}),d(A)!=="svelte-1vwaxbl"&&(A.innerHTML=qi),$t=s(e),X=o(e,"P",{"data-svelte-h":!0}),d(X)!=="svelte-irg7th"&&(X.textContent=Ei),vt=s(e),x=o(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),ki(x).forEach(i),wt=s(e),u(V.$$.fragment,e),Tt=s(e),Z=o(e,"P",{"data-svelte-h":!0}),d(Z)!=="svelte-ioywgh"&&(Z.textContent=Ii),yt=s(e),N=o(e,"P",{"data-svelte-h":!0}),d(N)!=="svelte-14sqfj"&&(N.textContent=Wi),Mt=s(e),D=o(e,"OL",{"data-svelte-h":!0}),d(D)!=="svelte-6ztbbs"&&(D.innerHTML=Bi),xt=s(e),u(b.$$.fragment,e),_t=s(e),u(Y.$$.fragment,e),Ct=s(e),O=o(e,"P",{"data-svelte-h":!0}),d(O)!=="svelte-grvvks"&&(O.innerHTML=Gi),bt=s(e),u(K.$$.fragment,e),kt=s(e),u(k.$$.fragment,e),Ut=s(e),u(ee.$$.fragment,e),Ft=s(e),te=o(e,"P",{"data-svelte-h":!0}),d(te)!=="svelte-i2qqsc"&&(te.innerHTML=Qi),jt=s(e),u(ie.$$.fragment,e),St=s(e),ne=o(e,"P",{"data-svelte-h":!0}),d(ne)!=="svelte-muo025"&&(ne.textContent=Ai),Lt=s(e),u(ae.$$.fragment,e),zt=s(e),se=o(e,"P",{"data-svelte-h":!0}),d(se)!=="svelte-1kxz6c2"&&(se.textContent=Xi),Jt=s(e),le=o(e,"OL",{"data-svelte-h":!0}),d(le)!=="svelte-12kgh6p"&&(le.innerHTML=Vi),Rt=s(e),re=o(e,"IMG",{src:!0,alt:!0}),Ht=s(e),u(oe.$$.fragment,e),qt=s(e),pe=o(e,"P",{"data-svelte-h":!0}),d(pe)!=="svelte-1y9ggj5"&&(pe.textContent=Ni),Et=s(e),me=o(e,"UL",{"data-svelte-h":!0}),d(me)!=="svelte-acv7jp"&&(me.innerHTML=Di),Pt=s(e),u(U.$$.fragment,e),It=s(e),u(ue.$$.fragment,e),Wt=s(e),ge=o(e,"P",{"data-svelte-h":!0}),d(ge)!=="svelte-ie5i5"&&(ge.textContent=Yi),Bt=s(e),u(fe.$$.fragment,e),Gt=s(e),ce=o(e,"P",{"data-svelte-h":!0}),d(ce)!=="svelte-1s6faap"&&(ce.textContent=Oi),Qt=s(e),u(he.$$.fragment,e),At=s(e),de=o(e,"P",{"data-svelte-h":!0}),d(de)!=="svelte-1yge1oh"&&(de.textContent=Ki),Xt=s(e),$e=o(e,"IMG",{src:!0,alt:!0}),Vt=s(e),ve=o(e,"P",{"data-svelte-h":!0}),d(ve)!=="svelte-13ggrtv"&&(ve.textContent=tn),Zt=s(e),we=o(e,"UL",{"data-svelte-h":!0}),d(we)!=="svelte-1a305az"&&(we.innerHTML=nn),Nt=s(e),Te=o(e,"IMG",{src:!0,alt:!0}),Dt=s(e),ye=o(e,"P",{"data-svelte-h":!0}),d(ye)!=="svelte-176u6kl"&&(ye.textContent=sn),Yt=s(e),Me=o(e,"UL",{"data-svelte-h":!0}),d(Me)!=="svelte-1dkaf9f"&&(Me.innerHTML=ln),Ot=s(e),xe=o(e,"IMG",{src:!0,alt:!0}),Kt=s(e),_e=o(e,"P",{"data-svelte-h":!0}),d(_e)!=="svelte-ilfaf"&&(_e.textContent=on),ei=s(e),Ce=o(e,"UL",{"data-svelte-h":!0}),d(Ce)!=="svelte-99mvik"&&(Ce.innerHTML=pn),ti=s(e),u(F.$$.fragment,e),ii=s(e),be=o(e,"P",{"data-svelte-h":!0}),d(be)!=="svelte-ttgvgc"&&(be.innerHTML=mn),ni=s(e),u(ke.$$.fragment,e),ai=s(e),Ue=o(e,"P",{"data-svelte-h":!0}),d(Ue)!=="svelte-1rfoj7z"&&(Ue.innerHTML=un),si=s(e),Fe=o(e,"P",{"data-svelte-h":!0}),d(Fe)!=="svelte-1028cbr"&&(Fe.textContent=gn),li=s(e),je=o(e,"OL",{"data-svelte-h":!0}),d(je)!=="svelte-1irg2q8"&&(je.innerHTML=fn),ri=s(e),u(j.$$.fragment,e),oi=s(e),u(Se.$$.fragment,e),pi=s(e),u(Le.$$.fragment,e),mi=s(e),u(ze.$$.fragment,e),ui=s(e),u(Je.$$.fragment,e),gi=s(e),u(Re.$$.fragment,e),fi=s(e),u(He.$$.fragment,e),ci=s(e),u(qe.$$.fragment,e),hi=s(e),u(Ee.$$.fragment,e),di=s(e),u(Pe.$$.fragment,e),$i=s(e),u(Ie.$$.fragment,e),vi=s(e),u(We.$$.fragment,e),wi=s(e),u(Be.$$.fragment,e),Ti=s(e),Ge=o(e,"P",{"data-svelte-h":!0}),d(Ge)!=="svelte-11s8azl"&&(Ge.textContent=cn),yi=s(e),Qe=o(e,"OL",{"data-svelte-h":!0}),d(Qe)!=="svelte-eabkx7"&&(Qe.innerHTML=hn),Mi=s(e),u(Ae.$$.fragment,e),xi=s(e),Xe=o(e,"UL",{"data-svelte-h":!0}),d(Xe)!=="svelte-19bqv1j"&&(Xe.innerHTML=dn),_i=s(e),u(Ve.$$.fragment,e),Ci=s(e),Ye=o(e,"P",{}),ki(Ye).forEach(i),this.h()},h(){T(p,"name","hf:doc:metadata"),T(p,"content",Bn),Oe(x.src,Pi="https://huggingface.co/datasets/HuggingFaceTB/smoltalk/embed/viewer/all/train?row=0")||T(x,"src",Pi),T(x,"frameborder","0"),T(x,"width","100%"),T(x,"height","360px"),Oe(re.src,Zi="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/nlp_course_sft_loss_graphic.png")||T(re,"src",Zi),T(re,"alt","SFTTrainer Training"),Oe($e.src,en="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/sft_loss_1.png")||T($e,"src",en),T($e,"alt","SFTTrainer Training"),Oe(Te.src,an="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/sft_loss_2.png")||T(Te,"src",an),T(Te,"alt","SFTTrainer Training"),Oe(xe.src,rn="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/sft_loss_3.png")||T(xe,"src",rn),T(xe,"alt","SFTTrainer Training")},m(e,t){jn(document.head,p),n(e,l,t),n(e,v,t),n(e,y,t),g(M,e,t),n(e,et,t),g(S,e,t),n(e,tt,t),n(e,L,t),n(e,it,t),n(e,z,t),n(e,nt,t),g(J,e,t),n(e,at,t),n(e,R,t),n(e,st,t),g(_,e,t),n(e,lt,t),n(e,H,t),n(e,rt,t),g(q,e,t),n(e,ot,t),n(e,E,t),n(e,pt,t),n(e,P,t),n(e,mt,t),g(I,e,t),n(e,ut,t),n(e,W,t),n(e,gt,t),n(e,B,t),n(e,ft,t),g(C,e,t),n(e,ct,t),g(G,e,t),n(e,ht,t),n(e,Q,t),n(e,dt,t),n(e,A,t),n(e,$t,t),n(e,X,t),n(e,vt,t),n(e,x,t),n(e,wt,t),g(V,e,t),n(e,Tt,t),n(e,Z,t),n(e,yt,t),n(e,N,t),n(e,Mt,t),n(e,D,t),n(e,xt,t),g(b,e,t),n(e,_t,t),g(Y,e,t),n(e,Ct,t),n(e,O,t),n(e,bt,t),g(K,e,t),n(e,kt,t),g(k,e,t),n(e,Ut,t),g(ee,e,t),n(e,Ft,t),n(e,te,t),n(e,jt,t),g(ie,e,t),n(e,St,t),n(e,ne,t),n(e,Lt,t),g(ae,e,t),n(e,zt,t),n(e,se,t),n(e,Jt,t),n(e,le,t),n(e,Rt,t),n(e,re,t),n(e,Ht,t),g(oe,e,t),n(e,qt,t),n(e,pe,t),n(e,Et,t),n(e,me,t),n(e,Pt,t),g(U,e,t),n(e,It,t),g(ue,e,t),n(e,Wt,t),n(e,ge,t),n(e,Bt,t),g(fe,e,t),n(e,Gt,t),n(e,ce,t),n(e,Qt,t),g(he,e,t),n(e,At,t),n(e,de,t),n(e,Xt,t),n(e,$e,t),n(e,Vt,t),n(e,ve,t),n(e,Zt,t),n(e,we,t),n(e,Nt,t),n(e,Te,t),n(e,Dt,t),n(e,ye,t),n(e,Yt,t),n(e,Me,t),n(e,Ot,t),n(e,xe,t),n(e,Kt,t),n(e,_e,t),n(e,ei,t),n(e,Ce,t),n(e,ti,t),g(F,e,t),n(e,ii,t),n(e,be,t),n(e,ni,t),g(ke,e,t),n(e,ai,t),n(e,Ue,t),n(e,si,t),n(e,Fe,t),n(e,li,t),n(e,je,t),n(e,ri,t),g(j,e,t),n(e,oi,t),g(Se,e,t),n(e,pi,t),g(Le,e,t),n(e,mi,t),g(ze,e,t),n(e,ui,t),g(Je,e,t),n(e,gi,t),g(Re,e,t),n(e,fi,t),g(He,e,t),n(e,ci,t),g(qe,e,t),n(e,hi,t),g(Ee,e,t),n(e,di,t),g(Pe,e,t),n(e,$i,t),g(Ie,e,t),n(e,vi,t),g(We,e,t),n(e,wi,t),g(Be,e,t),n(e,Ti,t),n(e,Ge,t),n(e,yi,t),n(e,Qe,t),n(e,Mi,t),g(Ae,e,t),n(e,xi,t),n(e,Xe,t),n(e,_i,t),g(Ve,e,t),n(e,Ci,t),n(e,Ye,t),bi=!0},p(e,[t]){const $n={};t&2&&($n.$$scope={dirty:t,ctx:e}),_.$set($n);const vn={};t&2&&(vn.$$scope={dirty:t,ctx:e}),C.$set(vn);const wn={};t&2&&(wn.$$scope={dirty:t,ctx:e}),b.$set(wn);const Tn={};t&2&&(Tn.$$scope={dirty:t,ctx:e}),k.$set(Tn);const yn={};t&2&&(yn.$$scope={dirty:t,ctx:e}),U.$set(yn);const Mn={};t&2&&(Mn.$$scope={dirty:t,ctx:e}),F.$set(Mn);const xn={};t&2&&(xn.$$scope={dirty:t,ctx:e}),j.$set(xn)},i(e){bi||(f(M.$$.fragment,e),f(S.$$.fragment,e),f(J.$$.fragment,e),f(_.$$.fragment,e),f(q.$$.fragment,e),f(I.$$.fragment,e),f(C.$$.fragment,e),f(G.$$.fragment,e),f(V.$$.fragment,e),f(b.$$.fragment,e),f(Y.$$.fragment,e),f(K.$$.fragment,e),f(k.$$.fragment,e),f(ee.$$.fragment,e),f(ie.$$.fragment,e),f(ae.$$.fragment,e),f(oe.$$.fragment,e),f(U.$$.fragment,e),f(ue.$$.fragment,e),f(fe.$$.fragment,e),f(he.$$.fragment,e),f(F.$$.fragment,e),f(ke.$$.fragment,e),f(j.$$.fragment,e),f(Se.$$.fragment,e),f(Le.$$.fragment,e),f(ze.$$.fragment,e),f(Je.$$.fragment,e),f(Re.$$.fragment,e),f(He.$$.fragment,e),f(qe.$$.fragment,e),f(Ee.$$.fragment,e),f(Pe.$$.fragment,e),f(Ie.$$.fragment,e),f(We.$$.fragment,e),f(Be.$$.fragment,e),f(Ae.$$.fragment,e),f(Ve.$$.fragment,e),bi=!0)},o(e){c(M.$$.fragment,e),c(S.$$.fragment,e),c(J.$$.fragment,e),c(_.$$.fragment,e),c(q.$$.fragment,e),c(I.$$.fragment,e),c(C.$$.fragment,e),c(G.$$.fragment,e),c(V.$$.fragment,e),c(b.$$.fragment,e),c(Y.$$.fragment,e),c(K.$$.fragment,e),c(k.$$.fragment,e),c(ee.$$.fragment,e),c(ie.$$.fragment,e),c(ae.$$.fragment,e),c(oe.$$.fragment,e),c(U.$$.fragment,e),c(ue.$$.fragment,e),c(fe.$$.fragment,e),c(he.$$.fragment,e),c(F.$$.fragment,e),c(ke.$$.fragment,e),c(j.$$.fragment,e),c(Se.$$.fragment,e),c(Le.$$.fragment,e),c(ze.$$.fragment,e),c(Je.$$.fragment,e),c(Re.$$.fragment,e),c(He.$$.fragment,e),c(qe.$$.fragment,e),c(Ee.$$.fragment,e),c(Pe.$$.fragment,e),c(Ie.$$.fragment,e),c(We.$$.fragment,e),c(Be.$$.fragment,e),c(Ae.$$.fragment,e),c(Ve.$$.fragment,e),bi=!1},d(e){e&&(i(l),i(v),i(y),i(et),i(tt),i(L),i(it),i(z),i(nt),i(at),i(R),i(st),i(lt),i(H),i(rt),i(ot),i(E),i(pt),i(P),i(mt),i(ut),i(W),i(gt),i(B),i(ft),i(ct),i(ht),i(Q),i(dt),i(A),i($t),i(X),i(vt),i(x),i(wt),i(Tt),i(Z),i(yt),i(N),i(Mt),i(D),i(xt),i(_t),i(Ct),i(O),i(bt),i(kt),i(Ut),i(Ft),i(te),i(jt),i(St),i(ne),i(Lt),i(zt),i(se),i(Jt),i(le),i(Rt),i(re),i(Ht),i(qt),i(pe),i(Et),i(me),i(Pt),i(It),i(Wt),i(ge),i(Bt),i(Gt),i(ce),i(Qt),i(At),i(de),i(Xt),i($e),i(Vt),i(ve),i(Zt),i(we),i(Nt),i(Te),i(Dt),i(ye),i(Yt),i(Me),i(Ot),i(xe),i(Kt),i(_e),i(ei),i(Ce),i(ti),i(ii),i(be),i(ni),i(ai),i(Ue),i(si),i(Fe),i(li),i(je),i(ri),i(oi),i(pi),i(mi),i(ui),i(gi),i(fi),i(ci),i(hi),i(di),i($i),i(vi),i(wi),i(Ti),i(Ge),i(yi),i(Qe),i(Mi),i(xi),i(Xe),i(_i),i(Ci),i(Ye)),i(p),h(M,e),h(S,e),h(J,e),h(_,e),h(q,e),h(I,e),h(C,e),h(G,e),h(V,e),h(b,e),h(Y,e),h(K,e),h(k,e),h(ee,e),h(ie,e),h(ae,e),h(oe,e),h(U,e),h(ue,e),h(fe,e),h(he,e),h(F,e),h(ke,e),h(j,e),h(Se,e),h(Le,e),h(ze,e),h(Je,e),h(Re,e),h(He,e),h(qe,e),h(Ee,e),h(Pe,e),h(Ie,e),h(We,e),h(Be,e),h(Ae,e),h(Ve,e)}}}const Bn='{"title":"Supervised Fine-Tuning","local":"supervised-fine-tuning","sections":[{"title":"When to Use SFT","local":"when-to-use-sft","sections":[{"title":"Template Control","local":"template-control","sections":[],"depth":3},{"title":"Domain Adaptation","local":"domain-adaptation","sections":[],"depth":3}],"depth":2},{"title":"Dataset Preparation","local":"dataset-preparation","sections":[],"depth":2},{"title":"Training Configuration","local":"training-configuration","sections":[],"depth":2},{"title":"Implementation with TRL","local":"implementation-with-trl","sections":[],"depth":2},{"title":"Packing the Dataset","local":"packing-the-dataset","sections":[],"depth":2},{"title":"Monitoring Training Progress","local":"monitoring-training-progress","sections":[{"title":"Understanding Loss Patterns","local":"understanding-loss-patterns","sections":[],"depth":3},{"title":"Metrics to Monitor","local":"metrics-to-monitor","sections":[],"depth":3},{"title":"The Path to Convergence","local":"the-path-to-convergence","sections":[],"depth":3},{"title":"Monitoring Training Progress","local":"monitoring-training-progress","sections":[],"depth":3},{"title":"Warning Signs to Watch For","local":"warning-signs-to-watch-for","sections":[],"depth":3}],"depth":2},{"title":"Evaluation after SFT","local":"evaluation-after-sft","sections":[],"depth":2},{"title":"Quiz","local":"quiz","sections":[{"title":"1. What parameters control the training duration in SFT?","local":"1-what-parameters-control-the-training-duration-in-sft","sections":[],"depth":3},{"title":"2. Which pattern in the loss curves indicates potential overfitting?","local":"2-which-pattern-in-the-loss-curves-indicates-potential-overfitting","sections":[],"depth":3},{"title":"3. What is gradient_accumulation_steps used for?","local":"3-what-is-gradientaccumulationsteps-used-for","sections":[],"depth":3},{"title":"4. What should you monitor during SFT training?","local":"4-what-should-you-monitor-during-sft-training","sections":[],"depth":3},{"title":"5. What indicates healthy convergence during training?","local":"5-what-indicates-healthy-convergence-during-training","sections":[],"depth":3}],"depth":2},{"title":"💐 Nice work!","local":"-nice-work","sections":[],"depth":2},{"title":"Additional Resources","local":"additional-resources","sections":[],"depth":2}],"depth":1}';function Gn(w){return Cn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Yn extends kn{constructor(p){super(),Un(this,p,Gn,Wn,_n,{})}}export{Yn as component};
