import{s as kl,o as Zl,n as Gl}from"../chunks/scheduler.aec39e6a.js";import{S as Wl,i as Fl,e as p,s as a,c,h as Al,a as i,d as l,b as e,f as Ql,g as o,j as M,k as $l,l as ql,m as n,n as T,t as m,o as J,p as r}from"../chunks/index.4ee0a2d0.js";import{T as Vl}from"../chunks/Tip.e2132029.js";import{C as Hl,H as U,E as vl}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.c1459923.js";import{C as g}from"../chunks/CodeBlock.55c9cf00.js";function zl(ks){let u,y='📍 Find the complete example on GitHub <a href="https://github.com/huggingface/hub-docs/tree/main/notebooks/sagemaker-sdk/fine-tune-trl-cli/sagemaker-notebook.ipynb" rel="nofollow">here</a>!';return{c(){u=p("p"),u.innerHTML=y},l(j){u=i(j,"P",{"data-svelte-h":!0}),M(u)!=="svelte-12riiza"&&(u.innerHTML=y)},m(j,Qs){n(j,u,Qs)},p:Gl,d(j){j&&l(u)}}}function xl(ks){let u,y,j,Qs,b,Zs,w,Gs,f,Dt='This notebook shows how to fine-tune language models on AWS SageMaker using the <strong><code>trl sft</code> CLI</strong> - the same command used by <a href="https://github.com/huggingface/trl-jobs" rel="nofollow">trl-jobs</a> on HuggingFace.',Ws,d,Kt="<strong>Hardware:</strong> <code>ml.g6e.12xlarge</code> (4x L40S) or <code>ml.p4de.24xlarge</code> (8x A100)",Fs,I,sl="<strong>Why TRL CLI?</strong>",As,N,tl='<li>Zero Python code - just config and run</li> <li>Multi-GPU training via <code>accelerate</code></li> <li>Compatible with <a href="https://github.com/huggingface/trl-jobs/tree/main/trl_jobs/configs" rel="nofollow">trl-jobs configs</a></li>',qs,C,Vs,E,ll="<li>AWS credentials configured</li> <li>SageMaker execution role with S3 access</li> <li>HuggingFace token</li>",Hs,_,vs,B,zs,R,nl=`\x1B[33mWARNING: Ignoring invalid distribution ~ackaging (/opt/pytorch/lib/python3.12/site-packages)\x1B[0m\x1B[33m
\x1B[0m\x1B[33mWARNING: Ignoring invalid distribution ~ackaging (/opt/pytorch/lib/python3.12/site-packages)\x1B[0m\x1B[33m
\x1B[0m\x1B[33mWARNING: Ignoring invalid distribution ~ackaging (/opt/pytorch/lib/python3.12/site-packages)\x1B[0m\x1B[33m
\x1B[0m\x1B[33mWARNING: Ignoring invalid distribution ~ackaging (/opt/pytorch/lib/python3.12/site-packages)\x1B[0m\x1B[33m
\x1B[0m\x1B[33mWARNING: Ignoring invalid distribution ~ackaging (/opt/pytorch/lib/python3.12/site-packages)\x1B[0m\x1B[33m
\x1B[0m\x1B[33mWARNING: Ignoring invalid distribution ~ackaging (/opt/pytorch/lib/python3.12/site-packages)\x1B[0m\x1B[33m
\x1B[0m
\x1B[1m[\x1B[0m\x1B[34;49mnotice\x1B[0m\x1B[1;39;49m]\x1B[0m\x1B[39;49m A new release of pip is available: \x1B[0m\x1B[31;49m25.1.1\x1B[0m\x1B[39;49m -> \x1B[0m\x1B[32;49m25.3\x1B[0m
\x1B[1m[\x1B[0m\x1B[34;49mnotice\x1B[0m\x1B[1;39;49m]\x1B[0m\x1B[39;49m To update, run: \x1B[0m\x1B[32;49mpip install --upgrade pip\x1B[0m
Note: you may need to restart the kernel to use updated packages.
`,xs,S,Ys,Q,Xs,$,al=`HF_TOKEN set: hf_MICph...
`,Ls,k,Ps,Z,el=`sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml
sagemaker.config INFO - Not applying SDK defaults from location: /home/ec2-user/.config/sagemaker/config.yaml
`,Os,G,Ds,W,pl=`Region: us-east-1
Account: 754289655784
Role: arn:aws:iam::754289655784:role/sagemaker-dlcs
`,Ks,F,st,A,il='We use <strong>YAML config files</strong> exactly like <a href="https://github.com/huggingface/trl-jobs/blob/main/trl_jobs/configs/Qwen3-4B-a100-large.yaml" rel="nofollow">trl-jobs</a>.',tt,q,Ml="<strong>Hardware:</strong> 4x L40S GPUs on <code>ml.g6e.12xlarge</code> (192GB total VRAM)",lt,V,nt,H,cl=`Model: Qwen/Qwen3-4B-Instruct-2507
Dataset: OpenMed/Medical-Reasoning-SFT-GPT-OSS-120B
Instance: ml.p4de.24xlarge (8x L40S GPUs)
`,at,v,et,z,ol=`Output model name: Qwen3-4B-Base-SFT-20260120162518
(Copy this to hub_model_id and run_name in the YAML config cell)
`,pt,x,it,Y,Tl="TRL CLI has <strong>native accelerate support</strong> - just put <code>num_processes</code> in the YAML config:",Mt,X,ct,L,ml='No need for <code>accelerate launch</code> wrapper! See <a href="https://huggingface.co/docs/trl/en/clis#scaling-up-with-accelerate" rel="nofollow">TRL CLI docs</a>.',ot,P,Tt,O,Jl=`Command:
  trl sft --config sft_config.yaml

Config: scripts/sft_config.yaml
Model: Qwen/Qwen3-4B-Base
Dataset: trl-lib/Capybara
GPUs: 4 (via num_processes in YAML)
`,mt,D,Jt,K,rl="We create:",rt,ss,gl="<li><strong><code>sft_config.yaml</code></strong> - TRL SFT config (same format as trl-jobs)</li> <li><strong><code>run_sft.py</code></strong> - Entry script that calls <code>trl sft --config</code></li> <li><strong><code>requirements.txt</code></strong> - Python dependencies</li>",gt,ts,ut,ls,ul='This notebook uses <a href="https://huggingface.co/docs/trl/en/trackio_integration" rel="nofollow">Trackio</a> for real-time training metrics visualization. Trackio is TRL’s native integration for logging training runs to a Hugging Face Space.',jt,ns,jl="<strong>To use Trackio:</strong>",Ut,as,Ul="<li>Set <code>report_to: trackio</code> in your config</li> <li>Configure <code>TRACKIO_SPACE_ID</code> (your HF Space) and <code>TRACKIO_PROJECT</code> (project name) as environment variables</li>",ht,es,hl="<strong>To disable:</strong> Change <code>report_to: trackio</code> to <code>report_to: none</code> in the config and remove the <code>TRACKIO_*</code> environment variables.",yt,ps,bt,is,yl=`✓ Created scripts/
`,wt,Ms,ft,cs,bl=`Overwriting scripts/run_sft.py
`,dt,os,It,Ts,wl=`Overwriting scripts/requirements.txt
`,Nt,ms,Ct,Js,fl=`Overwriting scripts/sft_config.yaml
`,Et,rs,_t,gs,dl=`Contents of scripts/:
  ✓ requirements.txt
  ✓ run_sft.py
  ✓ sft_config.yaml
`,Bt,us,Rt,js,Il="We use the SageMaker <code>ModelTrainer</code> with <code>SourceCode</code> to launch the training job.",St,Us,Nl="The TRL CLI arguments are embedded directly in the entry script to avoid SageMaker/accelerate argument parsing conflicts.",Qt,hs,$t,ys,Cl=`Job name: trl-sft-yaml-97d3b6c5
Instance: ml.p4de.24xlarge (8x L40S GPUs)
Output: s3://sagemaker-us-east-1-754289655784/trl-sft-yaml
Image: huggingface-pytorch-training:2.8.0-transformers4.56.2-gpu-py312-cu129-ubuntu22.04-v1.2

Ready to launch!
`,kt,bs,Zt,ws,El=`Launching training job: trl-sft-yaml-97d3b6c5
Model: Qwen/Qwen3-4B-Instruct-2507
Dataset: OpenMed/Medical-Reasoning-SFT-GPT-OSS-120B
Instance: ml.p4de.24xlarge (8x L40S)

Using: trl sft --config sft_config.yaml
`,Gt,fs,Wt,ds,_l="If you launched with <code>wait=False</code>, you can monitor the job here.",Ft,Is,At,Ns,Bl=`Job name: trl-sft-yaml-dfe9c258
Console: https://us-east-1.console.aws.amazon.com/sagemaker/home?region=us-east-1#/jobs/trl-sft-yaml-dfe9c258
`,qt,Cs,Vt,Es,Rl="After training completes, the model is pushed to the Hugging Face Hub.",Ht,_s,vt,Bs,zt,Rs,xt,Yt,Xt,h,Lt,Ss,Pt,$s,Ot;return b=new Hl({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),w=new U({props:{title:"Fine-Tuning LLMs with TRL CLI on SageMaker",local:"fine-tuning-llms-with-trl-cli-on-sagemaker",headingTag:"h1"}}),C=new U({props:{title:"Prerequisites",local:"prerequisites",headingTag:"h2"}}),_=new U({props:{title:"⚙️ Setup",local:"-setup",headingTag:"h2"}}),B=new g({props:{code:"JTNFJTNFJTIwJTI1cGlwJTIwaW5zdGFsbCUyMHNhZ2VtYWtlciUyMC0tdXBncmFkZSUyMC0tcXVpZXQ=",highlighted:"&gt;&gt; %pip install sagemaker --upgrade --quiet",wrap:!1}}),S=new g({props:{code:"aW1wb3J0JTIwc2FnZW1ha2Vy",highlighted:'<span class="hljs-keyword">import</span> sagemaker',wrap:!1}}),Q=new g({props:{code:"JTNFJTNFJTIwJTIzJTIwQXV0aGVudGljYXRlJTIwd2l0aCUyMEh1Z2dpbmclMjBGYWNlJTBBJTNFJTNFJTIwaW1wb3J0JTIwb3MlMEElM0UlM0UlMjBmcm9tJTIwaHVnZ2luZ2ZhY2VfaHViJTIwaW1wb3J0JTIwbG9naW4lMkMlMjBnZXRfdG9rZW4lMEElMEElM0UlM0UlMjBsb2dpbigpJTBBJTBBJTNFJTNFJTIwSEZfVE9LRU4lMjAlM0QlMjBnZXRfdG9rZW4oKSUwQSUzRSUzRSUyMG9zLmVudmlyb24lNUIlMjJIRl9UT0tFTiUyMiU1RCUyMCUzRCUyMEhGX1RPS0VOJTBBJTNFJTNFJTIwcHJpbnQoZiUyMkhGX1RPS0VOJTIwc2V0JTNBJTIwJTdCSEZfVE9LRU4lNUIlM0E4JTVEJTdELi4uJTIyKQ==",highlighted:`&gt;&gt; <span class="hljs-comment"># Authenticate with Hugging Face</span>
&gt;&gt; <span class="hljs-keyword">import</span> os
&gt;&gt; <span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> login, get_token

&gt;&gt; login()

&gt;&gt; HF_TOKEN = get_token()
&gt;&gt; os.environ[<span class="hljs-string">&quot;HF_TOKEN&quot;</span>] = HF_TOKEN
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;HF_TOKEN set: <span class="hljs-subst">{HF_TOKEN[:<span class="hljs-number">8</span>]}</span>...&quot;</span>)`,wrap:!1}}),k=new g({props:{code:"JTNFJTNFJTIwaW1wb3J0JTIwanNvbiUwQSUzRSUzRSUyMGltcG9ydCUyMHRpbWUlMEElM0UlM0UlMjBpbXBvcnQlMjB1dWlkJTBBJTNFJTNFJTIwaW1wb3J0JTIwdGVtcGZpbGUlMEElM0UlM0UlMjBpbXBvcnQlMjBzaHV0aWwlMEElM0UlM0UlMjBmcm9tJTIwcGF0aGxpYiUyMGltcG9ydCUyMFBhdGglMEElMEElM0UlM0UlMjBpbXBvcnQlMjBib3RvMyUwQSUzRSUzRSUyMGltcG9ydCUyMHNhZ2VtYWtlciUwQSUzRSUzRSUyMGZyb20lMjBzYWdlbWFrZXIudHJhaW4ubW9kZWxfdHJhaW5lciUyMGltcG9ydCUyME1vZGVsVHJhaW5lciUwQSUzRSUzRSUyMGZyb20lMjBzYWdlbWFrZXIudHJhaW4uY29uZmlncyUyMGltcG9ydCUyMFNvdXJjZUNvZGUlMkMlMjBDb21wdXRlJTJDJTIwU3RvcHBpbmdDb25kaXRpb24lMkMlMjBPdXRwdXREYXRhQ29uZmlnJTBBJTNFJTNFJTIwZnJvbSUyMHNhZ2VtYWtlci5jb3JlLmhlbHBlci5zZXNzaW9uX2hlbHBlciUyMGltcG9ydCUyMFNlc3Npb24=",highlighted:`&gt;&gt; <span class="hljs-keyword">import</span> json
&gt;&gt; <span class="hljs-keyword">import</span> time
&gt;&gt; <span class="hljs-keyword">import</span> uuid
&gt;&gt; <span class="hljs-keyword">import</span> tempfile
&gt;&gt; <span class="hljs-keyword">import</span> shutil
&gt;&gt; <span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path

&gt;&gt; <span class="hljs-keyword">import</span> boto3
&gt;&gt; <span class="hljs-keyword">import</span> sagemaker
&gt;&gt; <span class="hljs-keyword">from</span> sagemaker.train.model_trainer <span class="hljs-keyword">import</span> ModelTrainer
&gt;&gt; <span class="hljs-keyword">from</span> sagemaker.train.configs <span class="hljs-keyword">import</span> SourceCode, Compute, StoppingCondition, OutputDataConfig
&gt;&gt; <span class="hljs-keyword">from</span> sagemaker.core.helper.session_helper <span class="hljs-keyword">import</span> Session`,wrap:!1}}),G=new g({props:{code:"JTNFJTNFJTIwJTIzJTIwSW5pdGlhbGl6ZSUyMFNhZ2VNYWtlciUyMHNlc3Npb24lMEElM0UlM0UlMjBzYWdlbWFrZXJfc2Vzc2lvbiUyMCUzRCUyMFNlc3Npb24oKSUwQSUzRSUzRSUyMGlhbSUyMCUzRCUyMGJvdG8zLmNsaWVudCgnaWFtJyklMEElM0UlM0UlMjByb2xlJTIwJTNEJTIwaWFtLmdldF9yb2xlKFJvbGVOYW1lJTNEJ3NhZ2VtYWtlci1kbGNzJyklNUInUm9sZSclNUQlNUInQXJuJyU1RCUwQSUzRSUzRSUyMHJlZ2lvbiUyMCUzRCUyMHNhZ2VtYWtlcl9zZXNzaW9uLmJvdG9fcmVnaW9uX25hbWUlMEElM0UlM0UlMjBhY2NvdW50X2lkJTIwJTNEJTIwYm90bzMuY2xpZW50KCUyMnN0cyUyMikuZ2V0X2NhbGxlcl9pZGVudGl0eSgpJTVCJTIyQWNjb3VudCUyMiU1RCUwQSUwQSUzRSUzRSUyMHByaW50KGYlMjJSZWdpb24lM0ElMjAlN0JyZWdpb24lN0QlMjIpJTBBJTNFJTNFJTIwcHJpbnQoZiUyMkFjY291bnQlM0ElMjAlN0JhY2NvdW50X2lkJTdEJTIyKSUwQSUzRSUzRSUyMHByaW50KGYlMjJSb2xlJTNBJTIwJTdCcm9sZSU3RCUyMik=",highlighted:`&gt;&gt; <span class="hljs-comment"># Initialize SageMaker session</span>
&gt;&gt; sagemaker_session = Session()
&gt;&gt; iam = boto3.client(<span class="hljs-string">&#x27;iam&#x27;</span>)
&gt;&gt; role = iam.get_role(RoleName=<span class="hljs-string">&#x27;sagemaker-dlcs&#x27;</span>)[<span class="hljs-string">&#x27;Role&#x27;</span>][<span class="hljs-string">&#x27;Arn&#x27;</span>]
&gt;&gt; region = sagemaker_session.boto_region_name
&gt;&gt; account_id = boto3.client(<span class="hljs-string">&quot;sts&quot;</span>).get_caller_identity()[<span class="hljs-string">&quot;Account&quot;</span>]

&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Region: <span class="hljs-subst">{region}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Account: <span class="hljs-subst">{account_id}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Role: <span class="hljs-subst">{role}</span>&quot;</span>)`,wrap:!1}}),F=new U({props:{title:"⚙️ Configuration",local:"-configuration",headingTag:"h2"}}),V=new g({props:{code:"JTNFJTNFJTIwJTIzJTIwJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTNEJTBBJTNFJTNFJTIwJTIzJTIwTU9ERUwlMjAlMjYlMjBJTlNUQU5DRSUyMENPTkZJR1VSQVRJT04lMEElM0UlM0UlMjAlMjMlMjAlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlM0QlMEElM0UlM0UlMjAlMjMlMjBCYXNlZCUyMG9uJTIwdHJsLWpvYnMlMjBvcHRpbWFsJTIwY29uZmlncyUzQSUwQSUzRSUzRSUyMCUyMyUyMGh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvb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gt; <span class="hljs-comment"># =============================================================================</span>
&gt;&gt; <span class="hljs-comment"># MODEL &amp; INSTANCE CONFIGURATION</span>
&gt;&gt; <span class="hljs-comment"># =============================================================================</span>
&gt;&gt; <span class="hljs-comment"># Based on trl-jobs optimal configs:</span>
&gt;&gt; <span class="hljs-comment"># https://github.com/huggingface/trl-jobs/blob/main/trl_jobs/configs/</span>

&gt;&gt; MODEL_NAME = <span class="hljs-string">&quot;Qwen/Qwen3-4B-Instruct-2507&quot;</span>  <span class="hljs-comment"># trl-jobs optimal config</span>
&gt;&gt; DATASET_NAME = <span class="hljs-string">&quot;OpenMed/Medical-Reasoning-SFT-GPT-OSS-120B&quot;</span>

&gt;&gt; <span class="hljs-comment"># Instance: ml.g6e.12xlarge = 4x L40S GPUs (48GB each = 192GB total)</span>
&gt;&gt; <span class="hljs-comment"># Note: g6e.16xlarge only has 1 GPU, g6e.12xlarge/g6e.24xlarge have 4 GPUs</span>
&gt;&gt; INSTANCE_TYPE = <span class="hljs-string">&quot;ml.p4de.24xlarge&quot;</span>
&gt;&gt; NUM_GPUS = <span class="hljs-number">8</span>

&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Model: <span class="hljs-subst">{MODEL_NAME}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Dataset: <span class="hljs-subst">{DATASET_NAME}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Instance: <span class="hljs-subst">{INSTANCE_TYPE}</span> (<span class="hljs-subst">{NUM_GPUS}</span>x L40S GPUs)&quot;</span>)`,wrap:!1}}),v=new g({props:{code:"JTNFJTNFJTIwJTIzJTIwR2VuZXJhdGUlMjB1bmlxdWUlMjBvdXRwdXQlMjBtb2RlbCUyMG5hbWUlMjBmb3IlMjBodWJfbW9kZWxfaWQlMjBhbmQlMjBydW5fbmFtZSUwQSUzRSUzRSUyMHRpbWVzdGFtcCUyMCUzRCUyMHRpbWUuc3RyZnRpbWUoJTIyJTI1WSUyNW0lMjVkJTI1SCUyNU0lMjVTJTIyJTJDJTIwdGltZS5nbXRpbWUoKSklMEElM0UlM0UlMjBPVVRQVVRfTU9ERUxfTkFNRSUyMCUzRCUyMGYlMjJRd2VuMy00Qi1CYXNlLVNGVC0lN0J0aW1lc3RhbXAlN0QlMjIlMEElMEElM0UlM0UlMjBwcmludChmJTIyT3V0cHV0JTIwbW9kZWwlMjBuYW1lJTNBJTIwJTdCT1VUUFVUX01PREVMX05BTUUlN0QlMjIpJTBBJTNFJTNFJTIwcHJpbnQoJTIyKENvcHklMjB0aGlzJTIwdG8lMjBodWJfbW9kZWxfaWQlMjBhbmQlMjBydW5fbmFtZSUyMGluJTIwdGhlJTIwWUFNTCUyMGNvbmZpZyUyMGNlbGwpJTIyKQ==",highlighted:`&gt;&gt; <span class="hljs-comment"># Generate unique output model name for hub_model_id and run_name</span>
&gt;&gt; timestamp = time.strftime(<span class="hljs-string">&quot;%Y%m%d%H%M%S&quot;</span>, time.gmtime())
&gt;&gt; OUTPUT_MODEL_NAME = <span class="hljs-string">f&quot;Qwen3-4B-Base-SFT-<span class="hljs-subst">{timestamp}</span>&quot;</span>

&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Output model name: <span class="hljs-subst">{OUTPUT_MODEL_NAME}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;(Copy this to hub_model_id and run_name in the YAML config cell)&quot;</span>)`,wrap:!1}}),x=new U({props:{title:"🔧 TRL CLI with YAML Config",local:"-trl-cli-with-yaml-config",headingTag:"h2"}}),X=new g({props:{code:"dHJsJTIwc2Z0JTIwLS1jb25maWclMjBzZnRfY29uZmlnLnlhbWw=",highlighted:"trl sft --config sft_config.yaml",wrap:!1}}),P=new g({props:{code:"JTNFJTNFJTIwJTIzJTIwUHJldmlldyUyMHRoZSUyMGNvbW1hbmQlMjB0aGF0JTIwd2lsbCUyMGJlJTIwZXhlY3V0ZWQlMEElM0UlM0UlMjBwcmludCglMjJDb21tYW5kJTNBJTIyKSUwQSUzRSUzRSUyMHByaW50KCUyMiUyMCUyMHRybCUyMHNmdCUyMC0tY29uZmlnJTIwc2Z0X2NvbmZpZy55YW1sJTIyKSUwQSUzRSUzRSUyMHByaW50KCklMEElM0UlM0UlMjBwcmludCglMjJDb25maWclM0ElMjBzY3JpcHRzJTJGc2Z0X2NvbmZpZy55YW1sJTIyKSUwQSUzRSUzRSUyMHByaW50KCUyMk1vZGVsJTNBJTIwUXdlbiUyRlF3ZW4zLTRCLUJhc2UlMjIpJTBBJTNFJTNFJTIwcHJpbnQoJTIyRGF0YXNldCUzQSUyMHRybC1saWIlMkZDYXB5YmFyYSUyMiklMEElM0UlM0UlMjBwcmludCglMjJHUFVzJTNBJTIwNCUyMCh2aWElMjBudW1fcHJvY2Vzc2VzJTIwaW4lMjBZQU1MKSUyMik=",highlighted:`&gt;&gt; <span class="hljs-comment"># Preview the command that will be executed</span>
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Command:&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;  trl sft --config sft_config.yaml&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>()
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Config: scripts/sft_config.yaml&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Model: Qwen/Qwen3-4B-Base&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Dataset: trl-lib/Capybara&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;GPUs: 4 (via num_processes in YAML)&quot;</span>)`,wrap:!1}}),D=new U({props:{title:"📝 Create Training Files",local:"-create-training-files",headingTag:"h2"}}),ts=new U({props:{title:"📊 Training Logging with Trackio",local:"-training-logging-with-trackio",headingTag:"h3"}}),ps=new g({props:{code:"JTBBJTIwJTIwJTIwJTIwc2h1dGlsLnJtdHJlZShzb3VyY2VfZGlyKSUwQQ==",highlighted:`&gt;&gt; <span class="hljs-comment"># Create scripts directory</span>
&gt;&gt; <span class="hljs-keyword">import</span> shutil

&gt;&gt; source_dir = Path(<span class="hljs-string">&quot;scripts&quot;</span>)
&gt;&gt; <span class="hljs-keyword">if</span> source_dir.exists():
<span class="hljs-meta">... </span>    shutil.rmtree(source_dir)
&gt;&gt; source_dir.mkdir(exist_ok=<span class="hljs-literal">True</span>)

&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;✓ Created <span class="hljs-subst">{source_dir}</span>/&quot;</span>)`,wrap:!1}}),Ms=new g({props:{code:"JTBBUnVucyUzQSUyMHRybCUyMHNmdCUyMC0tY29uZmlnJTIwc2Z0X2NvbmZpZy55YW1sJTBBJTBBVFJMJTIwQ0xJJTIwbmF0aXZlbHklMjBzdXBwb3J0cyUyMGFjY2VsZXJhdGUlMjAtJTIwbnVtX3Byb2Nlc3NlcyUyMGlzJTIwaW4lMjB0aGUlMjBZQU1MJTIwY29uZmlnLiUwQVNlZSUzQSUyMGh0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZkb2NzJTJGdHJsJTJGZW4lMkZjbGlzJTIzc2NhbGluZy11cC13aXRoLWFjY2VsZXJhdGUlMEElMjIlMjIlMjIlMEElMEElMEElMjAlMjAlMjAlMjBwcmludCglMjIlM0QlMjIlMjAqJTIwNjApJTBBJTIwJTIwJTIwJTIwcHJpbnQoJTIyVFJMJTIwU0ZUJTIwVHJhaW5pbmclMjBvbiUyMFNhZ2VNYWtlciUyMiklMEElMjAlMjAlMjAlMjBwcmludCglMjIlM0QlMjIlMjAqJTIwNjApJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwRW52aXJvbm1lbnQlMjBpbmZvJTBBJTIwJTIwJTIwJTIwaGZfdG9rZW4lMjAlM0QlMjBvcy5lbnZpcm9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lMjAlMjBwcmludCgpJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwVFJMJTIwQ0xJJTIwaGFzJTIwbmF0aXZlJTIwYWNjZWxlcmF0ZSUyMHN1cHBvcnQlMjAtJTIwanVzdCUyMHBhc3MlMjB0aGUlMjBjb25maWclMEElMjAlMjAlMjAlMjAlMjMlMjBudW1fcHJvY2Vzc2VzJTJDJTIwbWl4ZWRfcHJlY2lzaW9uJTJDJTIwZXRjLiUyMGFyZSUyMHJlYWQlMjBmcm9tJTIwdGhlJTIwWUFNTCUwQSUyMCUyMCUyMCUyMGNtZCUyMCUzRCUyMCU1QiUyMnRybCUyMiUyQyUyMCUyMnNmdCUyMiUyQyUyMCUyMi0tY29uZmlnJTIyJTJDJTIwc3RyKGNvbmZpZ19wYXRoKSU1RCUwQSUwQSUyMCUyMCUyMCUyMHByaW50KGYlMjJSdW5uaW5nJTNBJTIwJTdCJyUyMCcuam9pbihjbWQpJTdEJTIyKSUwQSUyMCUyMCUyMCUyMHByaW50KCUyMiUzRCUyMiUyMColMjA2MCklMEElMEElMjAlMjAlMjAlMjAlMjMlMjBFeGVjdXRlJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwc3VicHJvY2Vzcy5ydW4oY21kJTJDJTIwY2hlY2slM0RGYWxzZSklMEElMjAlMjAlMjAlMjBzeXMuZXhpdChyZXN1bHQucmV0dXJuY29kZSklMEElMEElMEElMjAlMjAlMjAlMjBtYWluKCk=",highlighted:`&gt;&gt; %%writefile scripts/run_sft.py
&gt;&gt; <span class="hljs-comment">#!/usr/bin/env python3</span>
&gt;&gt; <span class="hljs-string">&quot;&quot;&quot;Entry script for TRL SFT training on SageMaker.

<span class="hljs-meta">... </span>Runs: trl sft --config sft_config.yaml

<span class="hljs-meta">... </span>TRL CLI natively supports accelerate - num_processes is in the YAML config.
<span class="hljs-meta">... </span>See: https://huggingface.co/docs/trl/en/clis#scaling-up-with-accelerate
<span class="hljs-meta">... </span>&quot;&quot;&quot;</span>
&gt;&gt; <span class="hljs-keyword">import</span> os
&gt;&gt; <span class="hljs-keyword">import</span> sys
&gt;&gt; <span class="hljs-keyword">import</span> subprocess
&gt;&gt; <span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path


&gt;&gt; <span class="hljs-keyword">def</span> <span class="hljs-title function_">main</span>():
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=&quot;</span> * <span class="hljs-number">60</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;TRL SFT Training on SageMaker&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=&quot;</span> * <span class="hljs-number">60</span>)

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Environment info</span>
<span class="hljs-meta">... </span>    hf_token = os.environ.get(<span class="hljs-string">&quot;HF_TOKEN&quot;</span>, <span class="hljs-string">&quot;&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;HF_TOKEN: <span class="hljs-subst">{hf_token[:<span class="hljs-number">8</span>]}</span>...&quot;</span> <span class="hljs-keyword">if</span> hf_token <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;HF_TOKEN: NOT SET&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Working directory: <span class="hljs-subst">{os.getcwd()}</span>&quot;</span>)

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Find config file</span>
<span class="hljs-meta">... </span>    config_path = Path(<span class="hljs-string">&quot;/opt/ml/input/data/code/sft_config.yaml&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> config_path.exists():
<span class="hljs-meta">... </span>        config_path = Path(<span class="hljs-string">&quot;sft_config.yaml&quot;</span>)

<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Config file: <span class="hljs-subst">{config_path}</span>&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>()

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Print config contents</span>
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Configuration:&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-&quot;</span> * <span class="hljs-number">40</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(config_path.read_text())
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-&quot;</span> * <span class="hljs-number">40</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>()

<span class="hljs-meta">... </span>    <span class="hljs-comment"># TRL CLI has native accelerate support - just pass the config</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># num_processes, mixed_precision, etc. are read from the YAML</span>
<span class="hljs-meta">... </span>    cmd = [<span class="hljs-string">&quot;trl&quot;</span>, <span class="hljs-string">&quot;sft&quot;</span>, <span class="hljs-string">&quot;--config&quot;</span>, <span class="hljs-built_in">str</span>(config_path)]

<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Running: <span class="hljs-subst">{<span class="hljs-string">&#x27; &#x27;</span>.join(cmd)}</span>&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=&quot;</span> * <span class="hljs-number">60</span>)

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Execute</span>
<span class="hljs-meta">... </span>    result = subprocess.run(cmd, check=<span class="hljs-literal">False</span>)
<span class="hljs-meta">... </span>    sys.exit(result.returncode)


&gt;&gt; <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&quot;__main__&quot;</span>:
<span class="hljs-meta">... </span>    main()`,wrap:!1}}),os=new g({props:{code:"JTNFJTNFJTIwJTI1JTI1d3JpdGVmaWxlJTIwc2NyaXB0cyUyRnJlcXVpcmVtZW50cy50eHQlMEElM0UlM0UlMjB0cmwlM0UlM0QwLjEyLjAlMEElM0UlM0UlMjB0cmFuc2Zvcm1lcnMlM0UlM0Q0LjQ1LjAlMEElM0UlM0UlMjBkYXRhc2V0cyUzRSUzRDMuMC4wJTBBJTNFJTNFJTIwcGVmdCUzRSUzRDAuMTMuMCUwQSUzRSUzRSUyMGFjY2VsZXJhdGUlM0UlM0QxLjAuMCUwQSUzRSUzRSUyMGh1Z2dpbmdmYWNlX2h1YiUzRSUzRDAuMjYuMCUwQSUzRSUzRSUyMGxpZ2VyLWtlcm5lbCUzRSUzRDAuNC4wJTBBJTNFJTNFJTIwZmxhc2gtYXR0biUzRSUzRDIuMC4wJTBBJTNFJTNFJTIwdHJhY2tpbyUwQSUzRSUzRSUyMGhmX3RyYW5zZmVy",highlighted:`&gt;&gt; %%writefile scripts/requirements.txt
&gt;&gt; trl&gt;=<span class="hljs-number">0.12</span><span class="hljs-number">.0</span>
&gt;&gt; transformers&gt;=<span class="hljs-number">4.45</span><span class="hljs-number">.0</span>
&gt;&gt; datasets&gt;=<span class="hljs-number">3.0</span><span class="hljs-number">.0</span>
&gt;&gt; peft&gt;=<span class="hljs-number">0.13</span><span class="hljs-number">.0</span>
&gt;&gt; accelerate&gt;=<span class="hljs-number">1.0</span><span class="hljs-number">.0</span>
&gt;&gt; huggingface_hub&gt;=<span class="hljs-number">0.26</span><span class="hljs-number">.0</span>
&gt;&gt; liger-kernel&gt;=<span class="hljs-number">0.4</span><span class="hljs-number">.0</span>
&gt;&gt; flash-attn&gt;=<span class="hljs-number">2.0</span><span class="hljs-number">.0</span>
&gt;&gt; trackio
&gt;&gt; hf_transfer`,wrap:!1}}),ms=new g({props:{code:"JTBBJTBBJTBBJTBBJTIwJTIwdXNlX3JlZW50cmFudCUzQSUyMGZhbHNlJTBBJTIwJTIwbWluX2xyX3JhdGUlM0ElMjAwLjElMEElMEE=",highlighted:`&gt;&gt; %%writefile scripts/sft_config.yaml
&gt;&gt; <span class="hljs-comment"># TRL SFT Config - Based on trl-jobs</span>
&gt;&gt; <span class="hljs-comment"># https://github.com/huggingface/trl-jobs/blob/main/trl_jobs/configs/Qwen3-4B-a100-large.yaml</span>
&gt;&gt; <span class="hljs-comment"># Adapted for 4x L40S GPUs (ml.g6e.12xlarge)</span>

&gt;&gt; <span class="hljs-comment"># Accelerate arguments</span>
&gt;&gt; num_processes: <span class="hljs-number">8</span>
&gt;&gt; num_machines: <span class="hljs-number">1</span>
&gt;&gt; mixed_precision: <span class="hljs-string">&quot;no&quot;</span>
&gt;&gt; dynamo_backend: <span class="hljs-string">&quot;no&quot;</span>

&gt;&gt; <span class="hljs-comment"># Model arguments</span>
&gt;&gt; model_name_or_path: Qwen/Qwen3-4B-Instruct-<span class="hljs-number">2507</span>
&gt;&gt; model_revision: main
&gt;&gt; torch_dtype: bfloat16
&gt;&gt; attn_implementation: kernels-community/flash-attn2
&gt;&gt; use_peft: true

&gt;&gt; <span class="hljs-comment"># Data arguments</span>
&gt;&gt; dataset_name: OpenMed/Medical-Reasoning-SFT-GPT-OSS-120B
&gt;&gt; dataset_num_proc: <span class="hljs-number">96</span>

&gt;&gt; <span class="hljs-comment"># Training arguments</span>
&gt;&gt; bf16: true
&gt;&gt; do_eval: false
&gt;&gt; eval_strategy: <span class="hljs-string">&quot;no&quot;</span>
&gt;&gt; gradient_accumulation_steps: <span class="hljs-number">8</span>
&gt;&gt; gradient_checkpointing: true
&gt;&gt; gradient_checkpointing_kwargs:
<span class="hljs-meta">... </span>  use_reentrant: false
&gt;&gt; learning_rate: <span class="hljs-number">2.0e-04</span>
&gt;&gt; log_level: info
&gt;&gt; logging_strategy: steps
&gt;&gt; logging_steps: <span class="hljs-number">10</span>
&gt;&gt; lr_scheduler_type: cosine_with_min_lr
&gt;&gt; lr_scheduler_kwargs:
<span class="hljs-meta">... </span>  min_lr_rate: <span class="hljs-number">0.1</span>
&gt;&gt; max_grad_norm: <span class="hljs-number">0.2</span>
&gt;&gt; max_length: <span class="hljs-number">24576</span>
&gt;&gt; num_train_epochs: <span class="hljs-number">1</span>
&gt;&gt; output_dir: /opt/ml/model
&gt;&gt; overwrite_output_dir: true
&gt;&gt; packing: true
&gt;&gt; pad_to_multiple_of: <span class="hljs-number">4096</span>
&gt;&gt; per_device_eval_batch_size: <span class="hljs-number">1</span>
&gt;&gt; per_device_train_batch_size: <span class="hljs-number">1</span>
&gt;&gt; seed: <span class="hljs-number">42</span>
&gt;&gt; use_liger_kernel: true
&gt;&gt; warmup_ratio: <span class="hljs-number">0.03</span>

&gt;&gt; <span class="hljs-comment"># Checkpointing</span>
&gt;&gt; save_steps: <span class="hljs-number">100</span>
&gt;&gt; save_strategy: steps
&gt;&gt; save_total_limit: <span class="hljs-number">2</span>

&gt;&gt; <span class="hljs-comment"># Hub &amp; Logging</span>
&gt;&gt; push_to_hub: true
&gt;&gt; hub_strategy: every_save
&gt;&gt; hub_model_id: Qwen3-4B-Instruct-OpenMed  <span class="hljs-comment"># &lt;-- UPDATE with OUTPUT_MODEL_NAME from Cell 10</span>
&gt;&gt; run_name: Qwen3-4B-Instruct-OpenMed-SFT      <span class="hljs-comment"># &lt;-- UPDATE with OUTPUT_MODEL_NAME from Cell 10</span>
&gt;&gt; report_to: trackio`,wrap:!1}}),rs=new g({props:{code:"JTIwJTIwJTIwJTIwcHJpbnQoZiUyMiUyMCUyMCVFMiU5QyU5MyUyMCU3QmYubmFtZSU3RCUyMik=",highlighted:`&gt;&gt; <span class="hljs-comment"># Verify all files created</span>
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Contents of scripts/:&quot;</span>)
&gt;&gt; <span class="hljs-keyword">for</span> f <span class="hljs-keyword">in</span> <span class="hljs-built_in">sorted</span>(source_dir.iterdir()):
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;  ✓ <span class="hljs-subst">{f.name}</span>&quot;</span>)`,wrap:!1}}),us=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jAlMjAlMjAlMjAlMjAlMjAlMjAlMjJUUkFDS0lPX1BST0pFQ1QlMjIlM0ElMjAlMjJ0cmwtc2Z0JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIySEZfSFVCX0VOQUJMRV9IRl9UUkFOU0ZFUiUyMiUzQSUyMCUyMjElMjIlMkMlMEElMjAlMjAlMjAlMjAlN0QlMkMlMEElMjAlMjAlMjAlMjB0cmFpbmluZ19pbWFnZSUzRFRSQUlOSU5HX0lNQUdFJTJDJTBBKSUwQQ==",highlighted:`&gt;&gt; <span class="hljs-comment"># Job configuration</span>
&gt;&gt; PROJECT_NAME = <span class="hljs-string">&quot;trl-sft-yaml&quot;</span>
&gt;&gt; BUCKET_NAME = sagemaker_session.default_bucket()
&gt;&gt; S3_OUTPUT_URI = <span class="hljs-string">f&quot;s3://<span class="hljs-subst">{BUCKET_NAME}</span>/<span class="hljs-subst">{PROJECT_NAME}</span>&quot;</span>

&gt;&gt; unique_id = uuid.uuid4().<span class="hljs-built_in">hex</span>[:<span class="hljs-number">8</span>]
&gt;&gt; base_job_name = <span class="hljs-string">f&quot;<span class="hljs-subst">{PROJECT_NAME}</span>-<span class="hljs-subst">{unique_id}</span>&quot;</span>

&gt;&gt; <span class="hljs-comment"># Training image - PyTorch DLC with GPU support</span>
&gt;&gt; TRAINING_IMAGE = <span class="hljs-string">f&quot;763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-pytorch-training:2.8.0-transformers4.56.2-gpu-py312-cu129-ubuntu22.04-v1.2&quot;</span>

&gt;&gt; <span class="hljs-comment"># Create ModelTrainer with SourceCode</span>
&gt;&gt; trainer = ModelTrainer(
<span class="hljs-meta">... </span>    sagemaker_session=sagemaker_session,
<span class="hljs-meta">... </span>    role=role,
<span class="hljs-meta">... </span>    training_mode=<span class="hljs-string">&quot;SAGEMAKER_TRAINING_JOB&quot;</span>,
<span class="hljs-meta">... </span>    source_code=SourceCode(
<span class="hljs-meta">... </span>        source_dir=<span class="hljs-built_in">str</span>(source_dir),
<span class="hljs-meta">... </span>        entry_script=<span class="hljs-string">&quot;run_sft.py&quot;</span>,
<span class="hljs-meta">... </span>        requirements=<span class="hljs-string">&quot;requirements.txt&quot;</span>,
<span class="hljs-meta">... </span>    ),
<span class="hljs-meta">... </span>    compute=Compute(
<span class="hljs-meta">... </span>        instance_type=INSTANCE_TYPE,
<span class="hljs-meta">... </span>        instance_count=<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>        volume_size_in_gb=<span class="hljs-number">200</span>,  <span class="hljs-comment"># Larger for 4B model + checkpoints</span>
<span class="hljs-meta">... </span>    ),
<span class="hljs-meta">... </span>    stopping_condition=StoppingCondition(
<span class="hljs-meta">... </span>        max_runtime_in_seconds=<span class="hljs-number">6</span> * <span class="hljs-number">60</span> * <span class="hljs-number">60</span>,  <span class="hljs-comment"># 6 hours</span>
<span class="hljs-meta">... </span>    ),
<span class="hljs-meta">... </span>    output_data_config=OutputDataConfig(
<span class="hljs-meta">... </span>        s3_output_path=<span class="hljs-string">f&quot;<span class="hljs-subst">{S3_OUTPUT_URI}</span>/output/&quot;</span>,
<span class="hljs-meta">... </span>    ),
<span class="hljs-meta">... </span>    base_job_name=base_job_name,
<span class="hljs-meta">... </span>    environment={
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;HF_TOKEN&quot;</span>: HF_TOKEN,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;TRANSFORMERS_VERBOSITY&quot;</span>: <span class="hljs-string">&quot;info&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;NCCL_DEBUG&quot;</span>: <span class="hljs-string">&quot;WARN&quot;</span>,  <span class="hljs-comment"># For multi-GPU debugging</span>
<span class="hljs-meta">... </span>        <span class="hljs-comment"># Trackio logging - https://huggingface.co/docs/trl/en/trackio_integration</span>
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;TRACKIO_SPACE_ID&quot;</span>: <span class="hljs-string">&quot;florentgbelidji/trackio&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;TRACKIO_PROJECT&quot;</span>: <span class="hljs-string">&quot;trl-sft&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;HF_HUB_ENABLE_HF_TRANSFER&quot;</span>: <span class="hljs-string">&quot;1&quot;</span>,
<span class="hljs-meta">... </span>    },
<span class="hljs-meta">... </span>    training_image=TRAINING_IMAGE,
<span class="hljs-meta">... </span>)

&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Job name: <span class="hljs-subst">{base_job_name}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Instance: <span class="hljs-subst">{INSTANCE_TYPE}</span> (<span class="hljs-subst">{NUM_GPUS}</span>x L40S GPUs)&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Output: <span class="hljs-subst">{S3_OUTPUT_URI}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Image: <span class="hljs-subst">{TRAINING_IMAGE.split(<span class="hljs-string">&#x27;/&#x27;</span>)[-<span class="hljs-number">1</span>]}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\\nReady to launch!&quot;</span>)`,wrap:!1}}),bs=new g({props:{code:"JTNFJTNFJTIwJTIzJTIwTGF1bmNoJTIwdGhlJTIwdHJhaW5pbmclMjBqb2IlMEElM0UlM0UlMjBwcmludChmJTIyTGF1bmNoaW5nJTIwdHJhaW5pbmclMjBqb2IlM0ElMjAlN0JiYXNlX2pvYl9uYW1lJTdEJTIyKSUwQSUzRSUzRSUyMHByaW50KGYlMjJNb2RlbCUzQSUyMCU3Qk1PREVMX05BTUUlN0QlMjIpJTBBJTNFJTNFJTIwcHJpbnQoZiUyMkRhdGFzZXQlM0ElMjAlN0JEQVRBU0VUX05BTUUlN0QlMjIpJTBBJTNFJTNFJTIwcHJpbnQoZiUyMkluc3RhbmNlJTNBJTIwJTdCSU5TVEFOQ0VfVFlQRSU3RCUyMCglN0JOVU1fR1BVUyU3RHglMjBMNDBTKSUyMiklMEElM0UlM0UlMjBwcmludChmJTIyJTVDblVzaW5nJTNBJTIwdHJsJTIwc2Z0JTIwLS1jb25maWclMjBzZnRfY29uZmlnLnlhbWwlMjIpJTBBJTNFJTNFJTIwcHJpbnQoKSUwQSUwQSUzRSUzRSUyMCUyMyUyMFNldCUyMHdhaXQlM0RUcnVlJTIwdG8lMjBzdHJlYW0lMjBsb2dzJTJDJTIwd2FpdCUzREZhbHNlJTIwdG8lMjBydW4lMjBpbiUyMGJhY2tncm91bmQlMEElM0UlM0UlMjB0cmFpbmVyLnRyYWluKHdhaXQlM0RUcnVlKQ==",highlighted:`&gt;&gt; <span class="hljs-comment"># Launch the training job</span>
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Launching training job: <span class="hljs-subst">{base_job_name}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Model: <span class="hljs-subst">{MODEL_NAME}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Dataset: <span class="hljs-subst">{DATASET_NAME}</span>&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Instance: <span class="hljs-subst">{INSTANCE_TYPE}</span> (<span class="hljs-subst">{NUM_GPUS}</span>x L40S)&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\\nUsing: trl sft --config sft_config.yaml&quot;</span>)
&gt;&gt; <span class="hljs-built_in">print</span>()

&gt;&gt; <span class="hljs-comment"># Set wait=True to stream logs, wait=False to run in background</span>
&gt;&gt; trainer.train(wait=<span class="hljs-literal">True</span>)`,wrap:!1}}),fs=new U({props:{title:"📊 Monitor Training",local:"-monitor-training",headingTag:"h2"}}),Is=new g({props:{code:"JTNFJTNFJTIwJTIzJTIwR2V0JTIwdGhlJTIwam9iJTIwbmFtZSUwQSUzRSUzRSUyMHRyYWluaW5nX2pvYl9uYW1lJTIwJTNEJTIwdHJhaW5lci5sYXRlc3RfdHJhaW5pbmdfam9iLm5hbWUlMjBpZiUyMGhhc2F0dHIodHJhaW5lciUyQyUyMCdsYXRlc3RfdHJhaW5pbmdfam9iJyklMjBlbHNlJTIwYmFzZV9qb2JfbmFtZSUwQSUzRSUzRSUyMHByaW50KGYlMjJKb2IlMjBuYW1lJTNBJTIwJTdCdHJhaW5pbmdfam9iX25hbWUlN0QlMjIpJTBBJTBBJTNFJTNFJTIwJTIzJTIwVmlldyUyMGluJTIwY29uc29sZSUwQSUzRSUzRSUyMGNvbnNvbGVfdXJsJTIwJTNEJTIwZiUyMmh0dHBzJTNBJTJGJTJGJTdCcmVnaW9uJTdELmNvbnNvbGUuYXdzLmFtYXpvbi5jb20lMkZzYWdlbWFrZXIlMkZob21lJTNGcmVnaW9uJTNEJTdCcmVnaW9uJTdEJTIzJTJGam9icyUyRiU3QnRyYWluaW5nX2pvYl9uYW1lJTdEJTIyJTBBJTNFJTNFJTIwcHJpbnQoZiUyMkNvbnNvbGUlM0ElMjAlN0Jjb25zb2xlX3VybCU3RCUyMik=",highlighted:`&gt;&gt; <span class="hljs-comment"># Get the job name</span>
&gt;&gt; training_job_name = trainer.latest_training_job.name <span class="hljs-keyword">if</span> <span class="hljs-built_in">hasattr</span>(trainer, <span class="hljs-string">&#x27;latest_training_job&#x27;</span>) <span class="hljs-keyword">else</span> base_job_name
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Job name: <span class="hljs-subst">{training_job_name}</span>&quot;</span>)

&gt;&gt; <span class="hljs-comment"># View in console</span>
&gt;&gt; console_url = <span class="hljs-string">f&quot;https://<span class="hljs-subst">{region}</span>.console.aws.amazon.com/sagemaker/home?region=<span class="hljs-subst">{region}</span>#/jobs/<span class="hljs-subst">{training_job_name}</span>&quot;</span>
&gt;&gt; <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Console: <span class="hljs-subst">{console_url}</span>&quot;</span>)`,wrap:!1}}),Cs=new U({props:{title:"🧪 Load and Test the Model",local:"-load-and-test-the-model",headingTag:"h2"}}),_s=new g({props:{code:"JTIzJTIwTG9hZCUyMHRoZSUyMGZpbmUtdHVuZWQlMjBtb2RlbCUyMGZyb20lMjBIdWIlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwcGlwZWxpbmUlMEElMEElMjMlMjBZb3VyJTIwSEYlMjB1c2VybmFtZSUwQUhGX1VTRVJOQU1FJTIwJTNEJTIwJTIyZmxvcmVudGdiZWxpZGppJTIyJTIwJTIwJTIzJTIwQ2hhbmdlJTIwdGhpcyElMEElMEFmaW5ldHVuZWRfbW9kZWxfaWQlMjAlM0QlMjBmJTIyJTdCSEZfVVNFUk5BTUUlN0QlMkYlN0JPVVRQVVRfTU9ERUxfTkFNRSU3RCUyMiUwQXByaW50KGYlMjJNb2RlbCUyMHdpbGwlMjBiZSUyMGF2YWlsYWJsZSUyMGF0JTNBJTIwJTdCZmluZXR1bmVkX21vZGVsX2lkJTdEJTIyKSUwQSUwQSUyMyUyMFVuY29tbWVudCUyMGFmdGVyJTIwdHJhaW5pbmclMjBjb21wbGV0ZXMlMEElMjMlMjBwaXBlJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIzJTIwJTIwJTIwJTIwJTIwJTIydGV4dC1nZW5lcmF0aW9uJTIyJTJDJTBBJTIzJTIwJTIwJTIwJTIwJTIwbW9kZWwlM0RmaW5ldHVuZWRfbW9kZWxfaWQlMkMlMEElMjMlMjAlMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRCUyMmF1dG8lMjIlMkMlMEElMjMlMjAlMjAlMjAlMjAlMjBkZXZpY2VfbWFwJTNEJTIyYXV0byUyMiUyQyUwQSUyMyUyMCklMEElMEElMjMlMjBtZXNzYWdlcyUyMCUzRCUyMCU1QiU3QiUyMnJvbGUlMjIlM0ElMjAlMjJ1c2VyJTIyJTJDJTIwJTIyY29udGVudCUyMiUzQSUyMCUyMldoYXQlMjBpcyUyMHRoZSUyMGNhcGl0YWwlMjBvZiUyMEZyYW5jZSUzRiUyMiU3RCU1RCUwQSUyMyUyMG91dHB1dCUyMCUzRCUyMHBpcGUobWVzc2FnZXMlMkMlMjBtYXhfbmV3X3Rva2VucyUzRDEwMCklMEElMjMlMjBwcmludChvdXRwdXQlNUIwJTVEJTVCJTIyZ2VuZXJhdGVkX3RleHQlMjIlNUQlNUItMSU1RCU1QiUyMmNvbnRlbnQlMjIlNUQp",highlighted:`<span class="hljs-comment"># Load the fine-tuned model from Hub</span>
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-comment"># Your HF username</span>
HF_USERNAME = <span class="hljs-string">&quot;florentgbelidji&quot;</span>  <span class="hljs-comment"># Change this!</span>

finetuned_model_id = <span class="hljs-string">f&quot;<span class="hljs-subst">{HF_USERNAME}</span>/<span class="hljs-subst">{OUTPUT_MODEL_NAME}</span>&quot;</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Model will be available at: <span class="hljs-subst">{finetuned_model_id}</span>&quot;</span>)

<span class="hljs-comment"># Uncomment after training completes</span>
<span class="hljs-comment"># pipe = pipeline(</span>
<span class="hljs-comment">#     &quot;text-generation&quot;,</span>
<span class="hljs-comment">#     model=finetuned_model_id,</span>
<span class="hljs-comment">#     torch_dtype=&quot;auto&quot;,</span>
<span class="hljs-comment">#     device_map=&quot;auto&quot;,</span>
<span class="hljs-comment"># )</span>

<span class="hljs-comment"># messages = [{&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;What is the capital of France?&quot;}]</span>
<span class="hljs-comment"># output = pipe(messages, max_new_tokens=100)</span>
<span class="hljs-comment"># print(output[0][&quot;generated_text&quot;][-1][&quot;content&quot;])</span>`,wrap:!1}}),Bs=new U({props:{title:"🧹 Cleanup",local:"-cleanup",headingTag:"h2"}}),Rs=new g({props:{code:"c2h1dGlsLnJtdHJlZShzb3VyY2VfZGlyJTJDJTIwaWdub3JlX2Vycm9ycyUzRFRydWUpJTBBcHJpbnQoJTIyQ2xlYW5lZCUyMHVwJTIwdGVtcG9yYXJ5JTIwZmlsZXMuJTIyKQ==",highlighted:`shutil.rmtree(source_dir, ignore_errors=<span class="hljs-literal">True</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Cleaned up temporary files.&quot;</span>)`,wrap:!1}}),h=new Vl({props:{$$slots:{default:[zl]},$$scope:{ctx:ks}}}),Ss=new vl({props:{source:"https://github.com/huggingface/hub-docs/blob/main/docs/sagemaker/source/examples/sagemaker-sdk-fine-tune-trl-cli.mdx"}}),{c(){u=p("meta"),y=a(),j=p("p"),Qs=a(),c(b.$$.fragment),Zs=a(),c(w.$$.fragment),Gs=a(),f=p("p"),f.innerHTML=Dt,Ws=a(),d=p("p"),d.innerHTML=Kt,Fs=a(),I=p("p"),I.innerHTML=sl,As=a(),N=p("ul"),N.innerHTML=tl,qs=a(),c(C.$$.fragment),Vs=a(),E=p("ul"),E.innerHTML=ll,Hs=a(),c(_.$$.fragment),vs=a(),c(B.$$.fragment),zs=a(),R=p("pre"),R.textContent=nl,xs=a(),c(S.$$.fragment),Ys=a(),c(Q.$$.fragment),Xs=a(),$=p("pre"),$.textContent=al,Ls=a(),c(k.$$.fragment),Ps=a(),Z=p("pre"),Z.textContent=el,Os=a(),c(G.$$.fragment),Ds=a(),W=p("pre"),W.textContent=pl,Ks=a(),c(F.$$.fragment),st=a(),A=p("p"),A.innerHTML=il,tt=a(),q=p("p"),q.innerHTML=Ml,lt=a(),c(V.$$.fragment),nt=a(),H=p("pre"),H.textContent=cl,at=a(),c(v.$$.fragment),et=a(),z=p("pre"),z.textContent=ol,pt=a(),c(x.$$.fragment),it=a(),Y=p("p"),Y.innerHTML=Tl,Mt=a(),c(X.$$.fragment),ct=a(),L=p("p"),L.innerHTML=ml,ot=a(),c(P.$$.fragment),Tt=a(),O=p("pre"),O.textContent=Jl,mt=a(),c(D.$$.fragment),Jt=a(),K=p("p"),K.textContent=rl,rt=a(),ss=p("ol"),ss.innerHTML=gl,gt=a(),c(ts.$$.fragment),ut=a(),ls=p("p"),ls.innerHTML=ul,jt=a(),ns=p("p"),ns.innerHTML=jl,Ut=a(),as=p("ol"),as.innerHTML=Ul,ht=a(),es=p("p"),es.innerHTML=hl,yt=a(),c(ps.$$.fragment),bt=a(),is=p("pre"),is.textContent=yl,wt=a(),c(Ms.$$.fragment),ft=a(),cs=p("pre"),cs.textContent=bl,dt=a(),c(os.$$.fragment),It=a(),Ts=p("pre"),Ts.textContent=wl,Nt=a(),c(ms.$$.fragment),Ct=a(),Js=p("pre"),Js.textContent=fl,Et=a(),c(rs.$$.fragment),_t=a(),gs=p("pre"),gs.textContent=dl,Bt=a(),c(us.$$.fragment),Rt=a(),js=p("p"),js.innerHTML=Il,St=a(),Us=p("p"),Us.textContent=Nl,Qt=a(),c(hs.$$.fragment),$t=a(),ys=p("pre"),ys.textContent=Cl,kt=a(),c(bs.$$.fragment),Zt=a(),ws=p("pre"),ws.textContent=El,Gt=a(),c(fs.$$.fragment),Wt=a(),ds=p("p"),ds.innerHTML=_l,Ft=a(),c(Is.$$.fragment),At=a(),Ns=p("pre"),Ns.textContent=Bl,qt=a(),c(Cs.$$.fragment),Vt=a(),Es=p("p"),Es.textContent=Rl,Ht=a(),c(_s.$$.fragment),vt=a(),c(Bs.$$.fragment),zt=a(),c(Rs.$$.fragment),xt=a(),Yt=p("hr"),Xt=a(),c(h.$$.fragment),Lt=a(),c(Ss.$$.fragment),Pt=a(),$s=p("p"),this.h()},l(s){const t=Al("svelte-u9bgzb",document.head);u=i(t,"META",{name:!0,content:!0}),t.forEach(l),y=e(s),j=i(s,"P",{}),Ql(j).forEach(l),Qs=e(s),o(b.$$.fragment,s),Zs=e(s),o(w.$$.fragment,s),Gs=e(s),f=i(s,"P",{"data-svelte-h":!0}),M(f)!=="svelte-10rirhv"&&(f.innerHTML=Dt),Ws=e(s),d=i(s,"P",{"data-svelte-h":!0}),M(d)!=="svelte-asbjt7"&&(d.innerHTML=Kt),Fs=e(s),I=i(s,"P",{"data-svelte-h":!0}),M(I)!=="svelte-1gdx2t4"&&(I.innerHTML=sl),As=e(s),N=i(s,"UL",{"data-svelte-h":!0}),M(N)!=="svelte-1xzrglb"&&(N.innerHTML=tl),qs=e(s),o(C.$$.fragment,s),Vs=e(s),E=i(s,"UL",{"data-svelte-h":!0}),M(E)!=="svelte-shr2a1"&&(E.innerHTML=ll),Hs=e(s),o(_.$$.fragment,s),vs=e(s),o(B.$$.fragment,s),zs=e(s),R=i(s,"PRE",{"data-svelte-h":!0}),M(R)!=="svelte-17iqp4r"&&(R.textContent=nl),xs=e(s),o(S.$$.fragment,s),Ys=e(s),o(Q.$$.fragment,s),Xs=e(s),$=i(s,"PRE",{"data-svelte-h":!0}),M($)!=="svelte-12puo0c"&&($.textContent=al),Ls=e(s),o(k.$$.fragment,s),Ps=e(s),Z=i(s,"PRE",{"data-svelte-h":!0}),M(Z)!=="svelte-1k0tiap"&&(Z.textContent=el),Os=e(s),o(G.$$.fragment,s),Ds=e(s),W=i(s,"PRE",{"data-svelte-h":!0}),M(W)!=="svelte-blti5a"&&(W.textContent=pl),Ks=e(s),o(F.$$.fragment,s),st=e(s),A=i(s,"P",{"data-svelte-h":!0}),M(A)!=="svelte-uk8vqv"&&(A.innerHTML=il),tt=e(s),q=i(s,"P",{"data-svelte-h":!0}),M(q)!=="svelte-r7hp5o"&&(q.innerHTML=Ml),lt=e(s),o(V.$$.fragment,s),nt=e(s),H=i(s,"PRE",{"data-svelte-h":!0}),M(H)!=="svelte-8uq4u2"&&(H.textContent=cl),at=e(s),o(v.$$.fragment,s),et=e(s),z=i(s,"PRE",{"data-svelte-h":!0}),M(z)!=="svelte-v6xiiq"&&(z.textContent=ol),pt=e(s),o(x.$$.fragment,s),it=e(s),Y=i(s,"P",{"data-svelte-h":!0}),M(Y)!=="svelte-vgee4u"&&(Y.innerHTML=Tl),Mt=e(s),o(X.$$.fragment,s),ct=e(s),L=i(s,"P",{"data-svelte-h":!0}),M(L)!=="svelte-1bu7p6r"&&(L.innerHTML=ml),ot=e(s),o(P.$$.fragment,s),Tt=e(s),O=i(s,"PRE",{"data-svelte-h":!0}),M(O)!=="svelte-1f2b3x9"&&(O.textContent=Jl),mt=e(s),o(D.$$.fragment,s),Jt=e(s),K=i(s,"P",{"data-svelte-h":!0}),M(K)!=="svelte-u05ibi"&&(K.textContent=rl),rt=e(s),ss=i(s,"OL",{"data-svelte-h":!0}),M(ss)!=="svelte-1x0qyyz"&&(ss.innerHTML=gl),gt=e(s),o(ts.$$.fragment,s),ut=e(s),ls=i(s,"P",{"data-svelte-h":!0}),M(ls)!=="svelte-heatfk"&&(ls.innerHTML=ul),jt=e(s),ns=i(s,"P",{"data-svelte-h":!0}),M(ns)!=="svelte-fx8nq4"&&(ns.innerHTML=jl),Ut=e(s),as=i(s,"OL",{"data-svelte-h":!0}),M(as)!=="svelte-1d3wvnx"&&(as.innerHTML=Ul),ht=e(s),es=i(s,"P",{"data-svelte-h":!0}),M(es)!=="svelte-gec9i3"&&(es.innerHTML=hl),yt=e(s),o(ps.$$.fragment,s),bt=e(s),is=i(s,"PRE",{"data-svelte-h":!0}),M(is)!=="svelte-15dm47y"&&(is.textContent=yl),wt=e(s),o(Ms.$$.fragment,s),ft=e(s),cs=i(s,"PRE",{"data-svelte-h":!0}),M(cs)!=="svelte-hfy09j"&&(cs.textContent=bl),dt=e(s),o(os.$$.fragment,s),It=e(s),Ts=i(s,"PRE",{"data-svelte-h":!0}),M(Ts)!=="svelte-1jtnupv"&&(Ts.textContent=wl),Nt=e(s),o(ms.$$.fragment,s),Ct=e(s),Js=i(s,"PRE",{"data-svelte-h":!0}),M(Js)!=="svelte-1yslspo"&&(Js.textContent=fl),Et=e(s),o(rs.$$.fragment,s),_t=e(s),gs=i(s,"PRE",{"data-svelte-h":!0}),M(gs)!=="svelte-18v1uj6"&&(gs.textContent=dl),Bt=e(s),o(us.$$.fragment,s),Rt=e(s),js=i(s,"P",{"data-svelte-h":!0}),M(js)!=="svelte-4ynnjy"&&(js.innerHTML=Il),St=e(s),Us=i(s,"P",{"data-svelte-h":!0}),M(Us)!=="svelte-1rg2oxc"&&(Us.textContent=Nl),Qt=e(s),o(hs.$$.fragment,s),$t=e(s),ys=i(s,"PRE",{"data-svelte-h":!0}),M(ys)!=="svelte-1dmol27"&&(ys.textContent=Cl),kt=e(s),o(bs.$$.fragment,s),Zt=e(s),ws=i(s,"PRE",{"data-svelte-h":!0}),M(ws)!=="svelte-1ow53zd"&&(ws.textContent=El),Gt=e(s),o(fs.$$.fragment,s),Wt=e(s),ds=i(s,"P",{"data-svelte-h":!0}),M(ds)!=="svelte-12wqj5"&&(ds.innerHTML=_l),Ft=e(s),o(Is.$$.fragment,s),At=e(s),Ns=i(s,"PRE",{"data-svelte-h":!0}),M(Ns)!=="svelte-lmlvhp"&&(Ns.textContent=Bl),qt=e(s),o(Cs.$$.fragment,s),Vt=e(s),Es=i(s,"P",{"data-svelte-h":!0}),M(Es)!=="svelte-69dbxo"&&(Es.textContent=Rl),Ht=e(s),o(_s.$$.fragment,s),vt=e(s),o(Bs.$$.fragment,s),zt=e(s),o(Rs.$$.fragment,s),xt=e(s),Yt=i(s,"HR",{}),Xt=e(s),o(h.$$.fragment,s),Lt=e(s),o(Ss.$$.fragment,s),Pt=e(s),$s=i(s,"P",{}),Ql($s).forEach(l),this.h()},h(){$l(u,"name","hf:doc:metadata"),$l(u,"content",Yl)},m(s,t){ql(document.head,u),n(s,y,t),n(s,j,t),n(s,Qs,t),T(b,s,t),n(s,Zs,t),T(w,s,t),n(s,Gs,t),n(s,f,t),n(s,Ws,t),n(s,d,t),n(s,Fs,t),n(s,I,t),n(s,As,t),n(s,N,t),n(s,qs,t),T(C,s,t),n(s,Vs,t),n(s,E,t),n(s,Hs,t),T(_,s,t),n(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t,t),T(h,s,t),n(s,Lt,t),T(Ss,s,t),n(s,Pt,t),n(s,$s,t),Ot=!0},p(s,[t]){const Sl={};t&2&&(Sl.$$scope={dirty:t,ctx:s}),h.$set(Sl)},i(s){Ot||(m(b.$$.fragment,s),m(w.$$.fragment,s),m(C.$$.fragment,s),m(_.$$.fragment,s),m(B.$$.fragment,s),m(S.$$.fragment,s),m(Q.$$.fragment,s),m(k.$$.fragment,s),m(G.$$.fragment,s),m(F.$$.fragment,s),m(V.$$.fragment,s),m(v.$$.fragment,s),m(x.$$.fragment,s),m(X.$$.fragment,s),m(P.$$.fragment,s),m(D.$$.fragment,s),m(ts.$$.fragment,s),m(ps.$$.fragment,s),m(Ms.$$.fragment,s),m(os.$$.fragment,s),m(ms.$$.fragment,s),m(rs.$$.fragment,s),m(us.$$.fragment,s),m(hs.$$.fragment,s),m(bs.$$.fragment,s),m(fs.$$.fragment,s),m(Is.$$.fragment,s),m(Cs.$$.fragment,s),m(_s.$$.fragment,s),m(Bs.$$.fragment,s),m(Rs.$$.fragment,s),m(h.$$.fragment,s),m(Ss.$$.fragment,s),Ot=!0)},o(s){J(b.$$.fragment,s),J(w.$$.fragment,s),J(C.$$.fragment,s),J(_.$$.fragment,s),J(B.$$.fragment,s),J(S.$$.fragment,s),J(Q.$$.fragment,s),J(k.$$.fragment,s),J(G.$$.fragment,s),J(F.$$.fragment,s),J(V.$$.fragment,s),J(v.$$.fragment,s),J(x.$$.fragment,s),J(X.$$.fragment,s),J(P.$$.fragment,s),J(D.$$.fragment,s),J(ts.$$.fragment,s),J(ps.$$.fragment,s),J(Ms.$$.fragment,s),J(os.$$.fragment,s),J(ms.$$.fragment,s),J(rs.$$.fragment,s),J(us.$$.fragment,s),J(hs.$$.fragment,s),J(bs.$$.fragment,s),J(fs.$$.fragment,s),J(Is.$$.fragment,s),J(Cs.$$.fragment,s),J(_s.$$.fragment,s),J(Bs.$$.fragment,s),J(Rs.$$.fragment,s),J(h.$$.fragment,s),J(Ss.$$.fragment,s),Ot=!1},d(s){s&&(l(y),l(j),l(Qs),l(Zs),l(Gs),l(f),l(Ws),l(d),l(Fs),l(I),l(As),l(N),l(qs),l(Vs),l(E),l(Hs),l(vs),l(zs),l(R),l(xs),l(Ys),l(Xs),l($),l(Ls),l(Ps),l(Z),l(Os),l(Ds),l(W),l(Ks),l(st),l(A),l(tt),l(q),l(lt),l(nt),l(H),l(at),l(et),l(z),l(pt),l(it),l(Y),l(Mt),l(ct),l(L),l(ot),l(Tt),l(O),l(mt),l(Jt),l(K),l(rt),l(ss),l(gt),l(ut),l(ls),l(jt),l(ns),l(Ut),l(as),l(ht),l(es),l(yt),l(bt),l(is),l(wt),l(ft),l(cs),l(dt),l(It),l(Ts),l(Nt),l(Ct),l(Js),l(Et),l(_t),l(gs),l(Bt),l(Rt),l(js),l(St),l(Us),l(Qt),l($t),l(ys),l(kt),l(Zt),l(ws),l(Gt),l(Wt),l(ds),l(Ft),l(At),l(Ns),l(qt),l(Vt),l(Es),l(Ht),l(vt),l(zt),l(xt),l(Yt),l(Xt),l(Lt),l(Pt),l($s)),l(u),r(b,s),r(w,s),r(C,s),r(_,s),r(B,s),r(S,s),r(Q,s),r(k,s),r(G,s),r(F,s),r(V,s),r(v,s),r(x,s),r(X,s),r(P,s),r(D,s),r(ts,s),r(ps,s),r(Ms,s),r(os,s),r(ms,s),r(rs,s),r(us,s),r(hs,s),r(bs,s),r(fs,s),r(Is,s),r(Cs,s),r(_s,s),r(Bs,s),r(Rs,s),r(h,s),r(Ss,s)}}}const Yl='{"title":"Fine-Tuning LLMs with TRL CLI on SageMaker","local":"fine-tuning-llms-with-trl-cli-on-sagemaker","sections":[{"title":"Prerequisites","local":"prerequisites","sections":[],"depth":2},{"title":"⚙️ Setup","local":"-setup","sections":[],"depth":2},{"title":"⚙️ Configuration","local":"-configuration","sections":[],"depth":2},{"title":"🔧 TRL CLI with YAML Config","local":"-trl-cli-with-yaml-config","sections":[],"depth":2},{"title":"📝 Create Training Files","local":"-create-training-files","sections":[{"title":"📊 Training Logging with Trackio","local":"-training-logging-with-trackio","sections":[],"depth":3}],"depth":2},{"title":"🚀 Launch Training Job","local":"-launch-training-job","sections":[],"depth":2},{"title":"📊 Monitor Training","local":"-monitor-training","sections":[],"depth":2},{"title":"🧪 Load and Test the Model","local":"-load-and-test-the-model","sections":[],"depth":2},{"title":"🧹 Cleanup","local":"-cleanup","sections":[],"depth":2}],"depth":1}';function Xl(ks){return Zl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class sn extends Wl{constructor(u){super(),Fl(this,u,Xl,xl,kl,{})}}export{sn as component};
