import{s as cs,n as us,o as ys}from"../chunks/scheduler.1f027d5a.js";import{S as ds,i as Js,e as i,s as a,c as m,h as hs,a as p,d as l,b as n,f as Ms,g as o,j as y,k as rs,l as Ts,m as s,n as M,t as r,o as c,p as u}from"../chunks/index.5cb6ce42.js";import{C as ws}from"../chunks/CopyLLMTxtMenu.c64d5249.js";import{D as bs,C as d}from"../chunks/DocNotebookDropdown.adbd98a5.js";import{H as J,E as js}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.903c2670.js";function Us(fl){let h,Lt,St,Ht,T,qt,w,Dt,b,Pt,j,Il='<em>Authored by: <a href="https://huggingface.co/AlanPonnachan" rel="nofollow">Alan Ponnachan</a></em>',Kt,U,gl="This notebook demonstrates a practical approach to building a domain-specific Question & Answering chatbot. We’ll focus on creating a chatbot that can answer questions about a specific piece of documentation – in this case, LangChain’s documentation on Chat Models.",Ot,f,Cl="<strong>Goal:</strong> To fine-tune a small, efficient Language Model (LLM) to understand and answer questions about the LangChain Chat Models documentation.",te,I,Zl="<strong>Approach:</strong>",ee,g,Gl="<li><strong>Data Acquisition:</strong> Obtain the text content from the target LangChain documentation page.</li> <li><strong>Synthetic Data Generation:</strong> Use Meta’s <code>synthetic-data-kit</code> to automatically generate Question/Answer pairs from this documentation.</li> <li><strong>Efficient Fine-tuning:</strong> Employ Unsloth and <code>Hugging Face&#39;s TRL SFTTrainer</code> to efficiently fine-tune a Llama-3.2-3B model on the generated synthetic data.</li> <li><strong>Evaluation:</strong> Test the fine-tuned model with specific questions about the documentation.</li>",le,C,Bl="This method allows us to adapt an LLM to a niche domain without requiring a large, manually curated dataset.",se,Z,$l="<strong>Hardware Used:</strong>",ae,G,vl="This notebook was run on Google Colab (Free Tier) with an NVIDIA T4 GPU",ne,B,ie,$,Wl="First, we need to install the necessary libraries. We’ll use <code>unsloth</code> for efficient model handling and training, and <code>synthetic-data-kit</code> for generating our training data.",pe,v,me,W,oe,_,Me,k,_l="We’ll use <code>SyntheticDataKit</code> from Unsloth (which wraps Meta’s <code>synthetic-data-kit</code>) to create Question/Answer pairs from our chosen documentation.",re,R,ce,X,kl=`🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!
INFO 05-05 15:14:48 [__init__.py:239] Automatically detected platform cuda.
`,ue,A,ye,x,de,F,Rl=`\x1B[?25l\x1B[32m VLLM server is running at \x1B[0m\x1B[4;94mhttp://localhost:8000/v1\x1B[0m
\x1B[32m⠋\x1B[0m\x1B[32m Checking VLLM server at http://localhost:8000/v1...\x1B[0m
\x1B[2KAvailable models: \x1B[1m&#123;\x1B[0m\x1B[32m'object'\x1B[0m: \x1B[32m'list'\x1B[0m, \x1B[32m'data'\x1B[0m: \x1B[1m[\x1B[0m\x1B[1m&#123;\x1B[0m\x1B[32m'id'\x1B[0m: 
\x1B[32m'unsloth/Llama-3.2-3B-Instruct'\x1B[0m, \x1B[32m'object'\x1B[0m: \x1B[32m'model'\x1B[0m, \x1B[32m'created'\x1B[0m: \x1B[1;36m1746459182\x1B[0m, 
\x1B[32m'owned_by'\x1B[0m: \x1B[32m'vllm'\x1B[0m, \x1B[32m'root'\x1B[0m: \x1B[32m'unsloth/Llama-3.2-3B-Instruct'\x1B[0m, \x1B[32m'parent'\x1B[0m: \x1B[3;35mNone\x1B[0m, 
\x1B[32m'max_model_len'\x1B[0m: \x1B[1;36m2048\x1B[0m, \x1B[32m'permission'\x1B[0m: \x1B[1m[\x1B[0m\x1B[1m&#123;\x1B[0m\x1B[32m'id'\x1B[0m: 
\x1B[32m'modelperm-5296f16bbd3c425a82af4d2f84f0cbfe'\x1B[0m, \x1B[32m'object'\x1B[0m: \x1B[32m'model_permission'\x1B[0m, 
\x1B[32m'created'\x1B[0m: \x1B[1;36m1746459182\x1B[0m, \x1B[32m'allow_create_engine'\x1B[0m: \x1B[3;91mFalse\x1B[0m, \x1B[32m'allow_sampling'\x1B[0m: \x1B[3;92mTrue\x1B[0m, 
\x1B[32m'allow_logprobs'\x1B[0m: \x1B[3;92mTrue\x1B[0m, \x1B[32m'allow_search_indices'\x1B[0m: \x1B[3;91mFalse\x1B[0m, \x1B[32m'allow_view'\x1B[0m: \x1B[3;92mTrue\x1B[0m, 
\x1B[32m'allow_fine_tuning'\x1B[0m: \x1B[3;91mFalse\x1B[0m, \x1B[32m'organization'\x1B[0m: \x1B[32m'*'\x1B[0m, \x1B[32m'group'\x1B[0m: \x1B[3;35mNone\x1B[0m, \x1B[32m'is_blocking'\x1B[0m: 
\x1B[3;91mFalse\x1B[0m\x1B[1m}\x1B[0m\x1B[1m]\x1B[0m\x1B[1m}\x1B[0m\x1B[1m]\x1B[0m\x1B[1m}\x1B[0m
\x1B[32m⠋\x1B[0m Checking VLLM server at http://localhost:8000/v1...
\x1B[2K\x1B[32m⠋\x1B[0m Checking VLLM server at http://localhost:8000/v1...
\x1B[?25h
\x1B[1A\x1B[2K
`,Je,N,he,V,Xl='For this example, we’ll use the LangChain documentation page on <a href="https://github.com/langchain-ai/langchain/blob/master/docs/docs/concepts/chat_models.mdx" rel="nofollow">Chat Models</a>.',Te,z,Al="<strong>To get the text:</strong>",we,Q,xl="<li>Go to the raw version of the MDX file (e.g., by clicking “Raw” on GitHub).</li> <li>Copy the entire text content.</li> <li>Save it locally as a <code>.txt</code> file. For this notebook, we assume you’ve saved it as <code>/content/langchain-ai-langchain.txt</code>. You can use a tool like <code>gitingest</code> or manual copy-paste.</li>",be,E,Fl="<strong>Note:</strong> Ensure the text file is uploaded to your Colab environment at <code>/content/langchain-ai-langchain.txt</code> if you’re running this in Colab.",je,S,Ue,Y,Nl=`\x1B[?25l\x1B[32m⠋\x1B[0m Processing /content/langchain-ai-langchain.txt...
\x1B[?25h
\x1B[1A\x1B[2K\x1B[32m Text successfully extracted to \x1B[0m\x1B[1;32mdata/output/langchain-ai-langchain.txt\x1B[0m
`,fe,L,Ie,H,Vl="The ingested document will be split into smaller chunks, and then QA pairs will be generated for each chunk.",ge,q,Ce,D,zl=`Created 3 chunks.
`,Ze,P,Ge,K,Be,O,Ql="The generated QA pairs are then converted into a format suitable for fine-tuning.",$e,tt,ve,et,El=`\x1B[?25l\x1B[32m⠋\x1B[0m Converting data/generated/langchain-ai-langchain_0_qa_pairs.json to ft format 
with json storage...
\x1B[?25h
\x1B[1A\x1B[2K\x1B[1A\x1B[2K\x1B[32m Converted to ft format and saved to \x1B[0m
\x1B[1;32mdata/final/langchain-ai-langchain_0_qa_pairs_ft.json\x1B[0m
\x1B[?25l\x1B[32m⠋\x1B[0m Converting data/generated/langchain-ai-langchain_1_qa_pairs.json to ft format 
with json storage...
\x1B[1A\x1B[2K\x1B[1A\x1B[2K\x1B[32m Converted to ft format and saved to \x1B[0m
\x1B[1;32mdata/final/langchain-ai-langchain_1_qa_pairs_ft.json\x1B[0m
`,We,lt,_e,st,Sl=`Attempting to terminate the VLLM server gracefully...
Server did not terminate gracefully after 10 seconds. Forcing kill...
Server killed forcefully.
`,ke,at,Re,nt,Yl="Now, let’s load the generated and formatted data.",Xe,it,Ae,pt,xe,mt,Fe,ot,Ne,Mt,Ll="If you encounter CUDA Out-of-Memory (OOM) errors when trying to load the Llama model for fine-tuning in the next steps (even after <code>generator.cleanup()</code>), it means the GPU memory wasn’t fully released. This is common in environments like Google Colab’s free tier.",Ve,rt,Hl="<strong>Workaround Strategy:</strong>",ze,ct,ql="<li><strong>Archive the generated data:</strong> After the <code>generator.cleanup()</code> cell, zip the entire <code>/content/data</code> folder and download to local.</li> <li><strong>Restart the Colab Runtime:</strong> Go to “Runtime” -&gt; “Restart runtime…“. This completely clears GPU memory.</li> <li><strong>Re-run Installations &amp; Imports:</strong> Execute the initial installation cells and necessary import cells again.</li> <li><strong>Restore Data:</strong> Upload the zip data folder and Unzip your data.</li> <li><strong>Load Dataset from Restored Files:</strong> Use a script to load from the unzipped <code>/content/data/final/</code> directory.</li> <li><strong>Proceed to model loading and fine-tuning.</strong></li>",Qe,ut,Dl="The cells below include commands for zipping. If you restart, you’d manually run the unzip and data loading code from the “Optional: Restart and Reload Data” section.",Ee,yt,Se,dt,Ye,Jt,Pl="Now, we’ll load our base model using Unsloth for 4-bit quantization and then fine-tune it on our synthetically generated dataset.",Le,ht,He,Tt,Kl="We’ll use <code>Llama-3.2-3B-Instruct</code> in 4-bit precision. Unsloth makes this very memory-efficient.",qe,wt,De,bt,Ol=`🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!
INFO 05-05 15:54:31 [__init__.py:239] Automatically detected platform cuda.
==((====))==  Unsloth 2025.4.7: Fast Llama patching. Transformers: 4.51.3. vLLM: 0.8.2.
   \\\\   /|    Tesla T4. Num GPUs = 1. Max memory: 14.741 GB. Platform: Linux.
O^O/ \\_/ \\    Torch: 2.6.0+cu124. CUDA: 7.5. CUDA Toolkit: 12.4. Triton: 3.2.0
\\        /    Bfloat16 = FALSE. FA [Xformers = 0.0.29.post3. FA2 = False]
 "-____-"     Free license: http://github.com/unslothai/unsloth
Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!
`,Pe,jt,Ke,Ut,ts="We use LoRA (Low-Rank Adaptation) for parameter-efficient fine-tuning.",Oe,ft,tl,It,el,gt,es="We need to format our dataset into the chat template expected by the Llama-3.2 model.",ll,Ct,sl,Zt,al,Gt,nl,Bt,il,$t,ls="We’ll use Hugging Face TRL’s <code>SFTTrainer</code> to fine-tune the model with the SFTTrainer class—designed specifically for supervised fine-tuning (SFT). We configure the training parameters using SFTConfig, specifying the dataset, model, training steps, and optimization settings. This setup allows us to efficiently fine-tune models with gradient accumulation and mixed-precision optimizers like adamw_8bit, onlimited hardware environment.",pl,vt,ml,Wt,ol,_t,Ml,kt,ss="Let’s test our fine-tuned model with some questions related to the LangChain Chat Models documentation.",rl,Rt,cl,Xt,as=`Standard [tool calling API](/docs/concepts/tool_calling): standard interface for binding tools to models.<|eot_id|>
`,ul,At,yl,xt,ns="We have successfully:",dl,Ft,is='<li>Acquired documentation text for <a href="https://github.com/langchain-ai/langchain/blob/master/docs/docs/concepts/chat_models.mdx" rel="nofollow">LangChain Chat Models</a>..</li> <li>Generated synthetic Question/Answer pairs using <a href="https://github.com/meta-llama/synthetic-data-kit" rel="nofollow"><code>synthetic-data-kit</code></a>.</li> <li>Fine-tuned a Llama-3.2-3B model efficiently using Unsloth and <a href="https://huggingface.co/docs/trl/en/sft_trainer" rel="nofollow">Hugging Face’s TRL SFTTrainer</a>.</li> <li>Tested the model’s ability to answer questions specific to the documentation.</li>',Jl,Nt,ps="This notebook provides a template for creating specialized chatbots for various documentation or domain-specific texts. The use of synthetic data generation and efficient fine-tuning techniques makes this approach accessible even with limited resources.",hl,Vt,ms="<strong>Further improvements could include:</strong>",Tl,zt,os="<li>Using a larger portion of the documentation or multiple related pages.</li> <li>More sophisticated curation of synthetic QA pairs.</li> <li>Experimenting with different base models or hyperparameter tuning.</li> <li>Implementing a more robust evaluation framework (e.g., comparing against a held-out set of questions or using metrics like ROUGE, BLEU if applicable, or LLM-as-a-judge).</li>",wl,Qt,bl,Et,jl,Yt,Ul;return T=new bs({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/cookbook/blob/main/notebooks/en/fine_tune_chatbot_docs_synthetic.ipynb"}]}}),w=new ws({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),b=new J({props:{title:"Documentation Chatbot with Meta Synthetic Data Kit",local:"documentation-chatbot-with-meta-synthetic-data-kit",headingTag:"h1"}}),B=new J({props:{title:"1. Setup and Installation",local:"1-setup-and-installation",headingTag:"h2"}}),v=new d({props:{code:"JTI1JTI1Y2FwdHVyZSUwQSUyMyUyMEluJTIwQ29sYWIlMkMlMjB3ZSUyMHNraXAlMjBkZXBlbmRlbmN5JTIwaW5zdGFsbGF0aW9uJTIwdG8lMjBhdm9pZCUyMGNvbmZsaWN0cyUyMHdpdGglMjBwcmVpbnN0YWxsZWQlMjBwYWNrYWdlcy4lMEElMjMlMjBPbiUyMGxvY2FsJTIwbWFjaGluZXMlMkMlMjB3ZSUyMGluY2x1ZGUlMjBkZXBlbmRlbmNpZXMlMjBmb3IlMjBjb21wbGV0ZW5lc3MuJTBBJTBBaW1wb3J0JTIwb3MlMEFpZiUyMCUyMkNPTEFCXyUyMiUyMG5vdCUyMGluJTIwJTIyJTIyLmpvaW4ob3MuZW52aXJvbi5rZXlzKCkpJTNBJTBBJTIwJTIwJTIwJTIwIXBpcCUyMGluc3RhbGwlMjB1bnNsb3RoJTIwdmxsbSUzRCUzRDAuOC4yJTBBZWxzZSUzQSUwQSUwQSUyMCUyMCUyMCUyMCFwaXAlMjBpbnN0YWxsJTIwLS1uby1kZXBzJTIwdW5zbG90aCUyMHZsbG0lM0QlM0QwLjguMiUwQSUwQSUyMyUyMEdldCUyMGh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRm1ldGEtbGxhbWElMkZzeW50aGV0aWMtZGF0YS1raXQlMEEhcGlwJTIwaW5zdGFsbCUyMHN5bnRoZXRpYy1kYXRhLWtpdA==",highlighted:`%%capture
<span class="hljs-comment"># In Colab, we skip dependency installation to avoid conflicts with preinstalled packages.</span>
<span class="hljs-comment"># On local machines, we include dependencies for completeness.</span>

<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">if</span> <span class="hljs-string">&quot;COLAB_&quot;</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> <span class="hljs-string">&quot;&quot;</span>.join(os.environ.keys()):
    !pip install unsloth vllm==<span class="hljs-number">0.8</span><span class="hljs-number">.2</span>
<span class="hljs-keyword">else</span>:

    !pip install --no-deps unsloth vllm==<span class="hljs-number">0.8</span><span class="hljs-number">.2</span>

<span class="hljs-comment"># Get https://github.com/meta-llama/synthetic-data-kit</span>
!pip install synthetic-data-kit`,wrap:!1}}),W=new d({props:{code:"JTI1JTI1Y2FwdHVyZSUwQWltcG9ydCUyMG9zJTBBaWYlMjAlMjJDT0xBQl8lMjIlMjBpbiUyMCUyMiUyMi5qb2luKG9zLmVudmlyb24ua2V5cygpKSUzQSUwQSUwQSUyMCUyMCUyMCUyMGltcG9ydCUyMHN5cyUyQyUyMHJlJTJDJTIwcmVxdWVzdHMlM0IlMjBtb2R1bGVzJTIwJTNEJTIwbGlzdChzeXMubW9kdWxlcy5rZXlzKCkpJTBBJTIwJTIwJTIwJTIwZm9yJTIweCUyMGluJTIwbW9kdWxlcyUzQSUyMHN5cy5tb2R1bGVzLnBvcCh4KSUyMGlmJTIwJTIyUElMJTIyJTIwaW4lMjB4JTIwb3IlMjAlMjJnb29nbGUlMjIlMjBpbiUyMHglMjBlbHNlJTIwTm9uZSUwQSUyMCUyMCUyMCUyMCFwaXAlMjBpbnN0YWxsJTIwLS1uby1kZXBzJTIwYml0c2FuZGJ5dGVzJTIwYWNjZWxlcmF0ZSUyMHhmb3JtZXJzJTNEJTNEMC4wLjI5LnBvc3QzJTIwcGVmdCUyMCUyMnRybCUzRCUzRDAuMTUuMiUyMiUyMHRyaXRvbiUyMGN1dF9jcm9zc19lbnRyb3B5JTIwdW5zbG90aF96b28lMEElMjAlMjAlMjAlMjAhcGlwJTIwaW5zdGFsbCUyMHNlbnRlbmNlcGllY2UlMjBwcm90b2J1ZiUyMGRhdGFzZXRzJTIwaHVnZ2luZ2ZhY2VfaHViJTVCaGZfeGV0JTVEJTIwaGZfdHJhbnNmZXIlMEElMEElMjAlMjAlMjAlMjAlMjMlMjB2TExNJTIwcmVxdWlyZW1lbnRzJTIwLSUyMHZMTE0lMjBicmVha3MlMjBDb2xhYiUyMGR1ZSUyMHRvJTIwcmVpbnN0YWxsaW5nJTIwbnVtcHklMEElMjAlMjAlMjAlMjBmJTIwJTNEJTIwcmVxdWVzdHMuZ2V0KCUyMmh0dHBzJTNBJTJGJTJGcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSUyRnZsbG0tcHJvamVjdCUyRnZsbG0lMkZyZWZzJTJGaGVhZHMlMkZtYWluJTJGcmVxdWlyZW1lbnRzJTJGY29tbW9uLnR4dCUyMikuY29udGVudCUwQSUyMCUyMCUyMCUyMHdpdGglMjBvcGVuKCUyMnZsbG1fcmVxdWlyZW1lbnRzLnR4dCUyMiUyQyUyMCUyMndiJTIyKSUyMGFzJTIwZmlsZSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZpbGUud3JpdGUocmUuc3ViKHJiJTIyKHRyYW5zZm9ybWVycyU3Q251bXB5JTdDeGZvcm1lcnMlN0NpbXBvcnRsaWJfbWV0YWRhdGEpJTVCJTVFJTVDbiU1RCU3QjAlMkMlN0QlNUNuJTIyJTJDJTIwYiUyMiUyMiUyQyUyMGYpKSUwQSUyMCUyMCUyMCUyMCFwaXAlMjBpbnN0YWxsJTIwLXIlMjB2bGxtX3JlcXVpcmVtZW50cy50eHQ=",highlighted:`%%capture
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">if</span> <span class="hljs-string">&quot;COLAB_&quot;</span> <span class="hljs-keyword">in</span> <span class="hljs-string">&quot;&quot;</span>.join(os.environ.keys()):

    <span class="hljs-keyword">import</span> sys, re, requests; modules = <span class="hljs-built_in">list</span>(sys.modules.keys())
    <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> modules: sys.modules.pop(x) <span class="hljs-keyword">if</span> <span class="hljs-string">&quot;PIL&quot;</span> <span class="hljs-keyword">in</span> x <span class="hljs-keyword">or</span> <span class="hljs-string">&quot;google&quot;</span> <span class="hljs-keyword">in</span> x <span class="hljs-keyword">else</span> <span class="hljs-literal">None</span>
    !pip install --no-deps bitsandbytes accelerate xformers==<span class="hljs-number">0.0</span><span class="hljs-number">.29</span>.post3 peft <span class="hljs-string">&quot;trl==0.15.2&quot;</span> triton cut_cross_entropy unsloth_zoo
    !pip install sentencepiece protobuf datasets huggingface_hub[hf_xet] hf_transfer

    <span class="hljs-comment"># vLLM requirements - vLLM breaks Colab due to reinstalling numpy</span>
    f = requests.get(<span class="hljs-string">&quot;https://raw.githubusercontent.com/vllm-project/vllm/refs/heads/main/requirements/common.txt&quot;</span>).content
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">&quot;vllm_requirements.txt&quot;</span>, <span class="hljs-string">&quot;wb&quot;</span>) <span class="hljs-keyword">as</span> file:
        file.write(re.sub(<span class="hljs-string">rb&quot;(transformers|numpy|xformers|importlib_metadata)[^\\n]{0,}\\n&quot;</span>, <span class="hljs-string">b&quot;&quot;</span>, f))
    !pip install -r vllm_requirements.txt`,wrap:!1}}),_=new J({props:{title:"2. Synthetic Data Generation",local:"2-synthetic-data-generation",headingTag:"h2"}}),R=new d({props:{code:"ZnJvbSUyMHVuc2xvdGguZGF0YXByZXAlMjBpbXBvcnQlMjBTeW50aGV0aWNEYXRhS2l0JTBBJTBBZ2VuZXJhdG9yJTIwJTNEJTIwU3ludGhldGljRGF0YUtpdC5mcm9tX3ByZXRyYWluZWQoJTBBJTBBJTIwJTIwJTIwJTIwbW9kZWxfbmFtZSUyMCUzRCUyMCUyMnVuc2xvdGglMkZMbGFtYS0zLjItM0ItSW5zdHJ1Y3QlMjIlMkMlMEElMjAlMjAlMjAlMjBtYXhfc2VxX2xlbmd0aCUyMCUzRCUyMDIwNDglMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> unsloth.dataprep <span class="hljs-keyword">import</span> SyntheticDataKit

<span class="hljs-meta">&gt;&gt;&gt; </span>generator = SyntheticDataKit.from_pretrained(

<span class="hljs-meta">... </span>    model_name = <span class="hljs-string">&quot;unsloth/Llama-3.2-3B-Instruct&quot;</span>,
<span class="hljs-meta">... </span>    max_seq_length = <span class="hljs-number">2048</span>,
<span class="hljs-meta">... </span>)`,wrap:!1}}),A=new d({props:{code:"Z2VuZXJhdG9yLnByZXBhcmVfcWFfZ2VuZXJhdGlvbiglMEElMjAlMjAlMjAlMjBvdXRwdXRfZm9sZGVyJTIwJTNEJTIwJTIyZGF0YSUyMiUyQyUyMCUyMyUyME91dHB1dCUyMGxvY2F0aW9uJTIwb2YlMjBzeW50aGV0aWMlMjBkYXRhJTBBJTIwJTIwJTIwJTIwdGVtcGVyYXR1cmUlMjAlM0QlMjAwLjclMkMlMjAlMjMlMjBIaWdoZXIlMjB0ZW1wJTIwbWFrZXMlMjBtb3JlJTIwZGl2ZXJzZSUyMGRhdGElMEElMjAlMjAlMjAlMjB0b3BfcCUyMCUzRCUyMDAuOTUlMkMlMEElMjAlMjAlMjAlMjBvdmVybGFwJTIwJTNEJTIwNjQlMkMlMjAlMjMlMjBPdmVybGFwJTIwcG9ydGlvbiUyMGR1cmluZyUyMGNodW5raW5nJTBBJTIwJTIwJTIwJTIwbWF4X2dlbmVyYXRpb25fdG9rZW5zJTIwJTNEJTIwNTEyJTJDJTIwJTIzJTIwQ2FuJTIwaW5jcmVhc2UlMjBmb3IlMjBsb25nZXIlMjBRQSUyMHBhaXJzJTBBKQ==",highlighted:`generator.prepare_qa_generation(
    output_folder = <span class="hljs-string">&quot;data&quot;</span>, <span class="hljs-comment"># Output location of synthetic data</span>
    temperature = <span class="hljs-number">0.7</span>, <span class="hljs-comment"># Higher temp makes more diverse data</span>
    top_p = <span class="hljs-number">0.95</span>,
    overlap = <span class="hljs-number">64</span>, <span class="hljs-comment"># Overlap portion during chunking</span>
    max_generation_tokens = <span class="hljs-number">512</span>, <span class="hljs-comment"># Can increase for longer QA pairs</span>
)`,wrap:!1}}),x=new d({props:{code:"IXN5bnRoZXRpYy1kYXRhLWtpdCUyMHN5c3RlbS1jaGVjaw==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>!synthetic-data-kit system-check',wrap:!1}}),N=new J({props:{title:"2.1. Acquire and Ingest Documentation",local:"21-acquire-and-ingest-documentation",headingTag:"h3"}}),S=new d({props:{code:"JTIzJTIwTWFrZSUyMHN1cmUlMjBzeW50aGV0aWNfZGF0YV9raXRfY29uZmlnLnlhbWwlMjBwb2ludHMlMjB0byUyMHRoZSUyMCdkYXRhX2RvY3MnJTIwZm9sZGVyJTBBIXN5bnRoZXRpYy1kYXRhLWtpdCUyMC1jJTIwc3ludGhldGljX2RhdGFfa2l0X2NvbmZpZy55YW1sJTIwaW5nZXN0JTIwJTJGY29udGVudCUyRmxhbmdjaGFpbi1haS1sYW5nY2hhaW4udHh0",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Make sure synthetic_data_kit_config.yaml points to the &#x27;data_docs&#x27; folder</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>!synthetic-data-kit -c synthetic_data_kit_config.yaml ingest /content/langchain-ai-langchain.txt`,wrap:!1}}),L=new J({props:{title:"2.2. Chunk Data and Generate QA Pairs",local:"22-chunk-data-and-generate-qa-pairs",headingTag:"h3"}}),q=new d({props:{code:"ZmlsZW5hbWVzJTIwJTNEJTIwZ2VuZXJhdG9yLmNodW5rX2RhdGEoJTIyZGF0YSUyRm91dHB1dCUyRmxhbmdjaGFpbi1haS1sYW5nY2hhaW4udHh0JTIyKSUwQXByaW50KGYlMjJDcmVhdGVkJTIwJTdCbGVuKGZpbGVuYW1lcyklN0QlMjBjaHVua3MuJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>filenames = generator.chunk_data(<span class="hljs-string">&quot;data/output/langchain-ai-langchain.txt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Created <span class="hljs-subst">{<span class="hljs-built_in">len</span>(filenames)}</span> chunks.&quot;</span>)`,wrap:!1}}),P=new d({props:{code:"aW1wb3J0JTIwdGltZSUwQSUyMyUyMFByb2Nlc3MlMjAyJTIwY2h1bmtzJTIwZm9yJTIwbm93JTIwLSUzRSUyMGNhbiUyMGluY3JlYXNlJTIwYnV0JTIwc2xvd2VyISUwQWZvciUyMGZpbGVuYW1lJTIwaW4lMjBmaWxlbmFtZXMlNUIlM0EyJTVEJTNBJTBBJTIwJTIwJTIwJTIwIXN5bnRoZXRpYy1kYXRhLWtpdCUyMCU1QyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMC1jJTIwc3ludGhldGljX2RhdGFfa2l0X2NvbmZpZy55YW1sJTIwJTVDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY3JlYXRlJTIwJTdCZmlsZW5hbWUlN0QlMjAlNUMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAtLW51bS1wYWlycyUyMDI1JTIwJTVDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwLS10eXBlJTIwJTIycWElMjIlMEElMjAlMjAlMjAlMjB0aW1lLnNsZWVwKDIpJTIwJTIzJTIwU2xlZXAlMjBzb21lJTIwdGltZSUyMHRvJTIwbGVhdmUlMjBzb21lJTIwcm9vbSUyMGZvciUyMHByb2Nlc3Npbmc=",highlighted:`<span class="hljs-keyword">import</span> time
<span class="hljs-comment"># Process 2 chunks for now -&gt; can increase but slower!</span>
<span class="hljs-keyword">for</span> filename <span class="hljs-keyword">in</span> filenames[:<span class="hljs-number">2</span>]:
    !synthetic-data-kit \\
        -c synthetic_data_kit_config.yaml \\
        create {filename} \\
        --num-pairs <span class="hljs-number">25</span> \\
        --<span class="hljs-built_in">type</span> <span class="hljs-string">&quot;qa&quot;</span>
    time.sleep(<span class="hljs-number">2</span>) <span class="hljs-comment"># Sleep some time to leave some room for processing</span>`,wrap:!1}}),K=new J({props:{title:"2.3. Format and Save QA Pairs",local:"23-format-and-save-qa-pairs",headingTag:"h3"}}),tt=new d({props:{code:"cWFfcGFpcnNfZmlsZW5hbWVzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwZiUyMmRhdGElMkZnZW5lcmF0ZWQlMkZsYW5nY2hhaW4tYWktbGFuZ2NoYWluXyU3QmklN0RfcWFfcGFpcnMuanNvbiUyMiUwQSUyMCUyMCUyMCUyMGZvciUyMGklMjBpbiUyMHJhbmdlKGxlbihmaWxlbmFtZXMlNUIlM0EyJTVEKSklMEElNUQlMEFmb3IlMjBmaWxlbmFtZSUyMGluJTIwcWFfcGFpcnNfZmlsZW5hbWVzJTNBJTBBJTIwJTIwJTIwJTIwIXN5bnRoZXRpYy1kYXRhLWtpdCUyMCU1QyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMC1jJTIwc3ludGhldGljX2RhdGFfa2l0X2NvbmZpZy55YW1sJTIwJTVDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2F2ZS1hcyUyMCU3QmZpbGVuYW1lJTdEJTIwLWYlMjBmdA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>qa_pairs_filenames = [
<span class="hljs-meta">... </span>    <span class="hljs-string">f&quot;data/generated/langchain-ai-langchain_<span class="hljs-subst">{i}</span>_qa_pairs.json&quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(filenames[:<span class="hljs-number">2</span>]))
<span class="hljs-meta">... </span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> filename <span class="hljs-keyword">in</span> qa_pairs_filenames:
<span class="hljs-meta">... </span>    !synthetic-data-kit \\
<span class="hljs-meta">... </span>        -c synthetic_data_kit_config.yaml \\
<span class="hljs-meta">... </span>        save-<span class="hljs-keyword">as</span> {filename} -f ft`,wrap:!1}}),lt=new d({props:{code:"Z2VuZXJhdG9yLmNsZWFudXAoKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>generator.cleanup()',wrap:!1}}),at=new J({props:{title:"2.4. Load the Formatted Dataset",local:"24-load-the-formatted-dataset",headingTag:"h3"}}),it=new d({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwRGF0YXNldCUwQWltcG9ydCUyMHBhbmRhcyUyMGFzJTIwcGQlMEFmaW5hbF9maWxlbmFtZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjBmJTIyZGF0YSUyRmZpbmFsJTJGbGFuZ2NoYWluLWFpLWxhbmdjaGFpbl8lN0JpJTdEX3FhX3BhaXJzX2Z0Lmpzb24lMjIlMEElMjAlMjAlMjAlMjBmb3IlMjBpJTIwaW4lMjByYW5nZShsZW4oZmlsZW5hbWVzJTVCJTNBMiU1RCkpJTBBJTVEJTBBY29udmVyc2F0aW9ucyUyMCUzRCUyMHBkLmNvbmNhdCglNUIlMEElMjAlMjAlMjAlMjBwZC5yZWFkX2pzb24obmFtZSklMjBmb3IlMjBuYW1lJTIwaW4lMjBmaW5hbF9maWxlbmFtZXMlMEElNUQpLnJlc2V0X2luZGV4KGRyb3AlMjAlM0QlMjBUcnVlKSUwQSUwQWRhdGFzZXQlMjAlM0QlMjBEYXRhc2V0LmZyb21fcGFuZGFzKGNvbnZlcnNhdGlvbnMp",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Dataset
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
final_filenames = [
    <span class="hljs-string">f&quot;data/final/langchain-ai-langchain_<span class="hljs-subst">{i}</span>_qa_pairs_ft.json&quot;</span>
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(filenames[:<span class="hljs-number">2</span>]))
]
conversations = pd.concat([
    pd.read_json(name) <span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> final_filenames
]).reset_index(drop = <span class="hljs-literal">True</span>)

dataset = Dataset.from_pandas(conversations)`,wrap:!1}}),pt=new d({props:{code:"ZGF0YXNldCU1QjAlNUQ=",highlighted:'dataset[<span class="hljs-number">0</span>]',wrap:!1}}),mt=new d({props:{code:"ZGF0YXNldCU1Qi0xJTVE",highlighted:'dataset[-<span class="hljs-number">1</span>]',wrap:!1}}),ot=new J({props:{title:"Memory Management Note (Critical for Resource-Constrained Environments)",local:"memory-management-note-critical-for-resource-constrained-environments",headingTag:"h3"}}),yt=new d({props:{code:"JTIzJTIwIXppcCUyMC1yJTIwZGF0YS56aXAlMjAlMkZjb250ZW50JTJGJTBBJTIzJTIwIXVuemlwJTIwZGF0YS56aXAlMEElMEElMjMlMjBpbXBvcnQlMjBvcyUwQSUyMyUyMGltcG9ydCUyMHBhbmRhcyUyMGFzJTIwcGQlMEElMjMlMjBmcm9tJTIwZGF0YXNldHMlMjBpbXBvcnQlMjBEYXRhc2V0JTBBJTBBJTIzJTIwJTIzJTIwUGF0aCUyMHRvJTIweW91ciUyMGZvbGRlciUyMGNvbnRhaW5pbmclMjBKU09OJTIwZmlsZXMlMEElMjMlMjBmb2xkZXJfcGF0aCUyMCUzRCUyMCdjb250ZW50JTJGZGF0YSUyRmZpbmFsJTJGJyUwQSUwQSUyMyUyMCUyMyUyMExpc3QlMjBhbGwlMjAuanNvbiUyMGZpbGVzJTIwaW4lMjB0aGUlMjBmb2xkZXIlMEElMjMlMjBmaW5hbF9maWxlbmFtZXMlMjAlM0QlMjAlNUJvcy5wYXRoLmpvaW4oZm9sZGVyX3BhdGglMkMlMjBmKSUyMGZvciUyMGYlMjBpbiUyMG9zLmxpc3RkaXIoZm9sZGVyX3BhdGgpJTIwaWYlMjBmLmVuZHN3aXRoKCcuanNvbicpJTVEJTBBJTBBJTIzJTIwJTIzJTIwUmVhZCUyMGFuZCUyMGNvbWJpbmUlMjB0aGUlMjBKU09OJTIwZmlsZXMlMEElMjMlMjBjb252ZXJzYXRpb25zJTIwJTNEJTIwcGQuY29uY2F0KCU1QiUwQSUyMyUyMCUyMCUyMCUyMCUyMHBkLnJlYWRfanNvbihuYW1lKSUyMGZvciUyMG5hbWUlMjBpbiUyMGZpbmFsX2ZpbGVuYW1lcyUwQSUyMyUyMCU1RCkucmVzZXRfaW5kZXgoZHJvcCUzRFRydWUpJTBBJTBBJTIzJTIwJTIzJTIwQ29udmVydCUyMHRvJTIwSHVnZ2luZyUyMEZhY2UlMjBEYXRhc2V0JTBBJTIzJTIwZGF0YXNldCUyMCUzRCUyMERhdGFzZXQuZnJvbV9wYW5kYXMoY29udmVyc2F0aW9ucyk=",highlighted:`<span class="hljs-comment"># !zip -r data.zip /content/</span>
<span class="hljs-comment"># !unzip data.zip</span>

<span class="hljs-comment"># import os</span>
<span class="hljs-comment"># import pandas as pd</span>
<span class="hljs-comment"># from datasets import Dataset</span>

<span class="hljs-comment"># # Path to your folder containing JSON files</span>
<span class="hljs-comment"># folder_path = &#x27;content/data/final/&#x27;</span>

<span class="hljs-comment"># # List all .json files in the folder</span>
<span class="hljs-comment"># final_filenames = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.endswith(&#x27;.json&#x27;)]</span>

<span class="hljs-comment"># # Read and combine the JSON files</span>
<span class="hljs-comment"># conversations = pd.concat([</span>
<span class="hljs-comment">#     pd.read_json(name) for name in final_filenames</span>
<span class="hljs-comment"># ]).reset_index(drop=True)</span>

<span class="hljs-comment"># # Convert to Hugging Face Dataset</span>
<span class="hljs-comment"># dataset = Dataset.from_pandas(conversations)</span>`,wrap:!1}}),dt=new J({props:{title:"3. Fine-tuning the LLM with Unsloth",local:"3-fine-tuning-the-llm-with-unsloth",headingTag:"h2"}}),ht=new J({props:{title:"3.1. Load Base Model and Tokenizer",local:"31-load-base-model-and-tokenizer",headingTag:"h3"}}),wt=new d({props:{code:"ZnJvbSUyMHVuc2xvdGglMjBpbXBvcnQlMjBGYXN0TGFuZ3VhZ2VNb2RlbCUwQWltcG9ydCUyMHRvcmNoJTBBJTBBJTBBJTBBbW9kZWwlMkMlMjB0b2tlbml6ZXIlMjAlM0QlMjBGYXN0TGFuZ3VhZ2VNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwbW9kZWxfbmFtZSUyMCUzRCUyMCUyMnVuc2xvdGglMkZMbGFtYS0zLjItM0ItSW5zdHJ1Y3QlMjIlMkMlMEElMjAlMjAlMjAlMjBtYXhfc2VxX2xlbmd0aCUyMCUzRCUyMDEwMjQlMkMlMjAlMjMlMjBDaG9vc2UlMjBhbnklMjBmb3IlMjBsb25nJTIwY29udGV4dCElMEElMjAlMjAlMjAlMjBsb2FkX2luXzRiaXQlMjAlM0QlMjBUcnVlJTJDJTIwJTIwJTIzJTIwNCUyMGJpdCUyMHF1YW50aXphdGlvbiUyMHRvJTIwcmVkdWNlJTIwbWVtb3J5JTBBJTIwJTIwJTIwJTIwbG9hZF9pbl84Yml0JTIwJTNEJTIwRmFsc2UlMkMlMjAlMjMlMjAlNUJORVchJTVEJTIwQSUyMGJpdCUyMG1vcmUlMjBhY2N1cmF0ZSUyQyUyMHVzZXMlMjAyeCUyMG1lbW9yeSUwQSUyMCUyMCUyMCUyMGZ1bGxfZmluZXR1bmluZyUyMCUzRCUyMEZhbHNlJTJDJTIwJTIzJTIwJTVCTkVXISU1RCUyMFdlJTIwaGF2ZSUyMGZ1bGwlMjBmaW5ldHVuaW5nJTIwbm93ISUwQSUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> unsloth <span class="hljs-keyword">import</span> FastLanguageModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch



<span class="hljs-meta">&gt;&gt;&gt; </span>model, tokenizer = FastLanguageModel.from_pretrained(
<span class="hljs-meta">... </span>    model_name = <span class="hljs-string">&quot;unsloth/Llama-3.2-3B-Instruct&quot;</span>,
<span class="hljs-meta">... </span>    max_seq_length = <span class="hljs-number">1024</span>, <span class="hljs-comment"># Choose any for long context!</span>
<span class="hljs-meta">... </span>    load_in_4bit = <span class="hljs-literal">True</span>,  <span class="hljs-comment"># 4 bit quantization to reduce memory</span>
<span class="hljs-meta">... </span>    load_in_8bit = <span class="hljs-literal">False</span>, <span class="hljs-comment"># [NEW!] A bit more accurate, uses 2x memory</span>
<span class="hljs-meta">... </span>    full_finetuning = <span class="hljs-literal">False</span>, <span class="hljs-comment"># [NEW!] We have full finetuning now!</span>

<span class="hljs-meta">... </span>)`,wrap:!1}}),jt=new J({props:{title:"3.2. Add LoRA Adapters",local:"32-add-lora-adapters",headingTag:"h3"}}),ft=new d({props:{code:"bW9kZWwlMjAlM0QlMjBGYXN0TGFuZ3VhZ2VNb2RlbC5nZXRfcGVmdF9tb2RlbCglMEElMjAlMjAlMjAlMjBtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMHIlMjAlM0QlMjAxNiUyQyUyMCUyMyUyMENob29zZSUyMGFueSUyMG51bWJlciUyMCUzRSUyMDAlMjAhJTIwU3VnZ2VzdGVkJTIwOCUyQyUyMDE2JTJDJTIwMzIlMkMlMjA2NCUyQyUyMDEyOCUwQSUyMCUyMCUyMCUyMHRhcmdldF9tb2R1bGVzJTIwJTNEJTIwJTVCJTIycV9wcm9qJTIyJTJDJTIwJTIya19wcm9qJTIyJTJDJTIwJTIydl9wcm9qJTIyJTJDJTIwJTIyb19wcm9qJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyZ2F0ZV9wcm9qJTIyJTJDJTIwJTIydXBfcHJvaiUyMiUyQyUyMCUyMmRvd25fcHJvaiUyMiUyQyU1RCUyQyUwQSUyMCUyMCUyMCUyMGxvcmFfYWxwaGElMjAlM0QlMjAxNiUyQyUwQSUyMCUyMCUyMCUyMGxvcmFfZHJvcG91dCUyMCUzRCUyMDAlMkMlMjAlMjMlMjBTdXBwb3J0cyUyMGFueSUyQyUyMGJ1dCUyMCUzRCUyMDAlMjBpcyUyMG9wdGltaXplZCUwQSUyMCUyMCUyMCUyMGJpYXMlMjAlM0QlMjAlMjJub25lJTIyJTJDJTIwJTIwJTIwJTIwJTIzJTIwU3VwcG9ydHMlMjBhbnklMkMlMjBidXQlMjAlM0QlMjAlMjJub25lJTIyJTIwaXMlMjBvcHRpbWl6ZWQlMEElMjAlMjAlMjAlMjAlMjMlMjAlNUJORVclNUQlMjAlMjJ1bnNsb3RoJTIyJTIwdXNlcyUyMDMwJTI1JTIwbGVzcyUyMFZSQU0lMkMlMjBmaXRzJTIwMnglMjBsYXJnZXIlMjBiYXRjaCUyMHNpemVzISUwQSUyMCUyMCUyMCUyMHVzZV9ncmFkaWVudF9jaGVja3BvaW50aW5nJTIwJTNEJTIwJTIydW5zbG90aCUyMiUyQyUyMCUyMyUyMFRydWUlMjBvciUyMCUyMnVuc2xvdGglMjIlMjBmb3IlMjB2ZXJ5JTIwbG9uZyUyMGNvbnRleHQlMEElMjAlMjAlMjAlMjByYW5kb21fc3RhdGUlMjAlM0QlMjAzNDA3JTJDJTBBJTIwJTIwJTIwJTIwdXNlX3JzbG9yYSUyMCUzRCUyMEZhbHNlJTJDJTIwJTIwJTIzJTIwV2UlMjBzdXBwb3J0JTIwcmFuayUyMHN0YWJpbGl6ZWQlMjBMb1JBJTBBJTIwJTIwJTIwJTIwbG9mdHFfY29uZmlnJTIwJTNEJTIwTm9uZSUyQyUyMCUyMyUyMEFuZCUyMExvZnRRJTBBKQ==",highlighted:`model = FastLanguageModel.get_peft_model(
    model,
    r = <span class="hljs-number">16</span>, <span class="hljs-comment"># Choose any number &gt; 0 ! Suggested 8, 16, 32, 64, 128</span>
    target_modules = [<span class="hljs-string">&quot;q_proj&quot;</span>, <span class="hljs-string">&quot;k_proj&quot;</span>, <span class="hljs-string">&quot;v_proj&quot;</span>, <span class="hljs-string">&quot;o_proj&quot;</span>,
                      <span class="hljs-string">&quot;gate_proj&quot;</span>, <span class="hljs-string">&quot;up_proj&quot;</span>, <span class="hljs-string">&quot;down_proj&quot;</span>,],
    lora_alpha = <span class="hljs-number">16</span>,
    lora_dropout = <span class="hljs-number">0</span>, <span class="hljs-comment"># Supports any, but = 0 is optimized</span>
    bias = <span class="hljs-string">&quot;none&quot;</span>,    <span class="hljs-comment"># Supports any, but = &quot;none&quot; is optimized</span>
    <span class="hljs-comment"># [NEW] &quot;unsloth&quot; uses 30% less VRAM, fits 2x larger batch sizes!</span>
    use_gradient_checkpointing = <span class="hljs-string">&quot;unsloth&quot;</span>, <span class="hljs-comment"># True or &quot;unsloth&quot; for very long context</span>
    random_state = <span class="hljs-number">3407</span>,
    use_rslora = <span class="hljs-literal">False</span>,  <span class="hljs-comment"># We support rank stabilized LoRA</span>
    loftq_config = <span class="hljs-literal">None</span>, <span class="hljs-comment"># And LoftQ</span>
)`,wrap:!1}}),It=new J({props:{title:"3.3. Data Preparation for Chat Format",local:"33-data-preparation-for-chat-format",headingTag:"h3"}}),Ct=new d({props:{code:"JTNDJTdDYmVnaW5fb2ZfdGV4dCU3QyUzRSUzQyU3Q3N0YXJ0X2hlYWRlcl9pZCU3QyUzRXN5c3RlbSUzQyU3Q2VuZF9oZWFkZXJfaWQlN0MlM0UlMEElMEFDdXR0aW5nJTIwS25vd2xlZGdlJTIwRGF0ZSUzQSUyMERlY2VtYmVyJTIwMjAyMyUwQVRvZGF5JTIwRGF0ZSUzQSUyMDAxJTIwTWF5JTIwMjAyNSUwQSUwQVlvdSUyMGFyZSUyMGElMjBoZWxwZnVsJTIwYXNzaXN0YW50LiUzQyU3Q2VvdF9pZCU3QyUzRSUzQyU3Q3N0YXJ0X2hlYWRlcl9pZCU3QyUzRXVzZXIlM0MlN0NlbmRfaGVhZGVyX2lkJTdDJTNFJTBBJTBBV2hhdCUyMGlzJTIwMSUyQjElM0YlM0MlN0Nlb3RfaWQlN0MlM0UlM0MlN0NzdGFydF9oZWFkZXJfaWQlN0MlM0Vhc3Npc3RhbnQlM0MlN0NlbmRfaGVhZGVyX2lkJTdDJTNFJTBBJTBBMiUzQyU3Q2VvdF9pZCU3QyUzRQ==",highlighted:`&lt;|begin_of_text|&gt;&lt;|start_header_id|&gt;system&lt;|end_header_id|&gt;

<span class="hljs-type">Cutting</span> <span class="hljs-type">Knowledge</span> <span class="hljs-type">Date</span>: <span class="hljs-type">December</span> <span class="hljs-number">2023</span>
<span class="hljs-type">Today</span> <span class="hljs-type">Date</span>: <span class="hljs-number">01</span> <span class="hljs-type">May</span> <span class="hljs-number">2025</span>

<span class="hljs-type">You</span> are a helpful assistant.&lt;|eot_id|&gt;&lt;|start_header_id|&gt;user&lt;|end_header_id|&gt;

<span class="hljs-type">What</span> is <span class="hljs-number">1</span>+<span class="hljs-number">1</span>?&lt;|eot_id|&gt;&lt;|start_header_id|&gt;assistant&lt;|end_header_id|&gt;

<span class="hljs-number">2</span>&lt;|eot_id|&gt;`,wrap:!1}}),Zt=new d({props:{code:"ZGVmJTIwZm9ybWF0dGluZ19wcm9tcHRzX2Z1bmMoZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwY29udm9zJTIwJTNEJTIwZXhhbXBsZXMlNUIlMjJtZXNzYWdlcyUyMiU1RCUwQSUyMCUyMCUyMCUyMHRleHRzJTIwJTNEJTIwJTVCdG9rZW5pemVyLmFwcGx5X2NoYXRfdGVtcGxhdGUoY29udm8lMkMlMjB0b2tlbml6ZSUyMCUzRCUyMEZhbHNlJTJDJTIwYWRkX2dlbmVyYXRpb25fcHJvbXB0JTIwJTNEJTIwRmFsc2UpJTIwZm9yJTIwY29udm8lMjBpbiUyMGNvbnZvcyU1RCUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCU3QiUyMCUyMnRleHQlMjIlMjAlM0ElMjB0ZXh0cyUyQyUyMCU3RCUwQXBhc3MlMEElMEElMjMlMjBHZXQlMjBvdXIlMjBwcmV2aW91cyUyMGRhdGFzZXQlMjBhbmQlMjBmb3JtYXQlMjBpdCUzQSUwQWRhdGFzZXQlMjAlM0QlMjBkYXRhc2V0Lm1hcChmb3JtYXR0aW5nX3Byb21wdHNfZnVuYyUyQyUyMGJhdGNoZWQlMjAlM0QlMjBUcnVlJTJDKQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">formatting_prompts_func</span>(<span class="hljs-params">examples</span>):
    convos = examples[<span class="hljs-string">&quot;messages&quot;</span>]
    texts = [tokenizer.apply_chat_template(convo, tokenize = <span class="hljs-literal">False</span>, add_generation_prompt = <span class="hljs-literal">False</span>) <span class="hljs-keyword">for</span> convo <span class="hljs-keyword">in</span> convos]
    <span class="hljs-keyword">return</span> { <span class="hljs-string">&quot;text&quot;</span> : texts, }
<span class="hljs-keyword">pass</span>

<span class="hljs-comment"># Get our previous dataset and format it:</span>
dataset = dataset.<span class="hljs-built_in">map</span>(formatting_prompts_func, batched = <span class="hljs-literal">True</span>,)`,wrap:!1}}),Gt=new d({props:{code:"ZGF0YXNldCU1QjAlNUQ=",highlighted:'dataset[<span class="hljs-number">0</span>]',wrap:!1}}),Bt=new J({props:{title:"3.4. Train the Model",local:"34-train-the-model",headingTag:"h3"}}),vt=new d({props:{code:"ZnJvbSUyMHRybCUyMGltcG9ydCUyMFNGVFRyYWluZXIlMkMlMjBTRlRDb25maWclMEElMEF0cmFpbmVyJTIwJTNEJTIwU0ZUVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUyMCUzRCUyMG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwcHJvY2Vzc2luZ19jbGFzcyUyMCUzRCUyMHRva2VuaXplciUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlMjAlM0QlMjBkYXRhc2V0JTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTIwJTNEJTIwTm9uZSUyQyUyMCUyMyUyMENhbiUyMHNldCUyMHVwJTIwZXZhbHVhdGlvbiElMEElMjAlMjAlMjAlMjBhcmdzJTIwJTNEJTIwU0ZUQ29uZmlnKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGRhdGFzZXRfdGV4dF9maWVsZCUyMCUzRCUyMCUyMnRleHQlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlMjAlM0QlMjAyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTIwJTNEJTIwNCUyQyUyMCUyMyUyMFVzZSUyMEdBJTIwdG8lMjBtaW1pYyUyMGJhdGNoJTIwc2l6ZSElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB3YXJtdXBfc3RlcHMlMjAlM0QlMjA1JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWF4X3N0ZXBzJTIwJTNEJTIwNjAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsZWFybmluZ19yYXRlJTIwJTNEJTIwMmUtNCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RlcHMlMjAlM0QlMjAxJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3B0aW0lMjAlM0QlMjAlMjJhZGFtd184Yml0JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2VpZ2h0X2RlY2F5JTIwJTNEJTIwMC4wMSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxyX3NjaGVkdWxlcl90eXBlJTIwJTNEJTIwJTIybGluZWFyJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2VlZCUyMCUzRCUyMDM0MDclMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXBvcnRfdG8lMjAlM0QlMjAlMjJub25lJTIyJTJDJTIwJTIzJTIwVXNlJTIwdGhpcyUyMGZvciUyMFdhbmRCJTIwZXRjJTBBJTIwJTIwJTIwJTIwKSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> trl <span class="hljs-keyword">import</span> SFTTrainer, SFTConfig

trainer = SFTTrainer(
    model = model,
    processing_class = tokenizer,
    train_dataset = dataset,
    eval_dataset = <span class="hljs-literal">None</span>, <span class="hljs-comment"># Can set up evaluation!</span>
    args = SFTConfig(
        dataset_text_field = <span class="hljs-string">&quot;text&quot;</span>,
        per_device_train_batch_size = <span class="hljs-number">2</span>,
        gradient_accumulation_steps = <span class="hljs-number">4</span>, <span class="hljs-comment"># Use GA to mimic batch size!</span>
        warmup_steps = <span class="hljs-number">5</span>,
        max_steps = <span class="hljs-number">60</span>,
        learning_rate = <span class="hljs-number">2e-4</span>,
        logging_steps = <span class="hljs-number">1</span>,
        optim = <span class="hljs-string">&quot;adamw_8bit&quot;</span>,
        weight_decay = <span class="hljs-number">0.01</span>,
        lr_scheduler_type = <span class="hljs-string">&quot;linear&quot;</span>,
        seed = <span class="hljs-number">3407</span>,
        report_to = <span class="hljs-string">&quot;none&quot;</span>, <span class="hljs-comment"># Use this for WandB etc</span>
    ),
)`,wrap:!1}}),Wt=new d({props:{code:"dHJhaW5lcl9zdGF0cyUyMCUzRCUyMHRyYWluZXIudHJhaW4oKQ==",highlighted:"trainer_stats = trainer.train()",wrap:!1}}),_t=new J({props:{title:"4. Inference and Testing",local:"4-inference-and-testing",headingTag:"h2"}}),Rt=new d({props:{code:"bWVzc2FnZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlN0IlMjJyb2xlJTIyJTNBJTIwJTIydXNlciUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjAlMjJXaGF0JTIwaXMlMjB0aGUlMjBzdGFuZGFyZCUyMGludGVyZmFjZSUyMGZvciUyMGJpbmRpbmclMjB0b29scyUyMHRvJTIwbW9kZWxzJTNGJTIyJTdEJTJDJTBBJTVEJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyLmFwcGx5X2NoYXRfdGVtcGxhdGUoJTBBJTIwJTIwJTIwJTIwbWVzc2FnZXMlMkMlMEElMjAlMjAlMjAlMjB0b2tlbml6ZSUyMCUzRCUyMFRydWUlMkMlMEElMjAlMjAlMjAlMjBhZGRfZ2VuZXJhdGlvbl9wcm9tcHQlMjAlM0QlMjBUcnVlJTJDJTIwJTIzJTIwTXVzdCUyMGFkZCUyMGZvciUyMGdlbmVyYXRpb24lMEElMjAlMjAlMjAlMjByZXR1cm5fdGVuc29ycyUyMCUzRCUyMCUyMnB0JTIyJTJDJTBBKS50byglMjJjdWRhJTIyKSUwQSUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBUZXh0U3RyZWFtZXIlMEF0ZXh0X3N0cmVhbWVyJTIwJTNEJTIwVGV4dFN0cmVhbWVyKHRva2VuaXplciUyQyUyMHNraXBfcHJvbXB0JTIwJTNEJTIwVHJ1ZSklMEFfJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoaW5wdXRfaWRzJTIwJTNEJTIwaW5wdXRzJTJDJTIwc3RyZWFtZXIlMjAlM0QlMjB0ZXh0X3N0cmVhbWVyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWF4X25ld190b2tlbnMlMjAlM0QlMjAyNTYlMkMlMjB0ZW1wZXJhdHVyZSUyMCUzRCUyMDAuMSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>messages = [
<span class="hljs-meta">... </span>    {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;What is the standard interface for binding tools to models?&quot;</span>},
<span class="hljs-meta">... </span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer.apply_chat_template(
<span class="hljs-meta">... </span>    messages,
<span class="hljs-meta">... </span>    tokenize = <span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    add_generation_prompt = <span class="hljs-literal">True</span>, <span class="hljs-comment"># Must add for generation</span>
<span class="hljs-meta">... </span>    return_tensors = <span class="hljs-string">&quot;pt&quot;</span>,
<span class="hljs-meta">... </span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TextStreamer
<span class="hljs-meta">&gt;&gt;&gt; </span>text_streamer = TextStreamer(tokenizer, skip_prompt = <span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>_ = model.generate(input_ids = inputs, streamer = text_streamer,
<span class="hljs-meta">... </span>                   max_new_tokens = <span class="hljs-number">256</span>, temperature = <span class="hljs-number">0.1</span>)`,wrap:!1}}),At=new J({props:{title:"5. Conclusion",local:"5-conclusion",headingTag:"h2"}}),Qt=new d({props:{code:"",highlighted:"",wrap:!1}}),Et=new js({props:{source:"https://github.com/huggingface/cookbook/blob/main/notebooks/en/fine_tune_chatbot_docs_synthetic.md"}}),{c(){h=i("meta"),Lt=a(),St=i("p"),Ht=a(),m(T.$$.fragment),qt=a(),m(w.$$.fragment),Dt=a(),m(b.$$.fragment),Pt=a(),j=i("p"),j.innerHTML=Il,Kt=a(),U=i("p"),U.textContent=gl,Ot=a(),f=i("p"),f.innerHTML=Cl,te=a(),I=i("p"),I.innerHTML=Zl,ee=a(),g=i("ol"),g.innerHTML=Gl,le=a(),C=i("p"),C.textContent=Bl,se=a(),Z=i("p"),Z.innerHTML=$l,ae=a(),G=i("p"),G.textContent=vl,ne=a(),m(B.$$.fragment),ie=a(),$=i("p"),$.innerHTML=Wl,pe=a(),m(v.$$.fragment),me=a(),m(W.$$.fragment),oe=a(),m(_.$$.fragment),Me=a(),k=i("p"),k.innerHTML=_l,re=a(),m(R.$$.fragment),ce=a(),X=i("pre"),X.textContent=kl,ue=a(),m(A.$$.fragment),ye=a(),m(x.$$.fragment),de=a(),F=i("pre"),F.textContent=Rl,Je=a(),m(N.$$.fragment),he=a(),V=i("p"),V.innerHTML=Xl,Te=a(),z=i("p"),z.innerHTML=Al,we=a(),Q=i("ol"),Q.innerHTML=xl,be=a(),E=i("p"),E.innerHTML=Fl,je=a(),m(S.$$.fragment),Ue=a(),Y=i("pre"),Y.textContent=Nl,fe=a(),m(L.$$.fragment),Ie=a(),H=i("p"),H.textContent=Vl,ge=a(),m(q.$$.fragment),Ce=a(),D=i("pre"),D.textContent=zl,Ze=a(),m(P.$$.fragment),Ge=a(),m(K.$$.fragment),Be=a(),O=i("p"),O.textContent=Ql,$e=a(),m(tt.$$.fragment),ve=a(),et=i("pre"),et.textContent=El,We=a(),m(lt.$$.fragment),_e=a(),st=i("pre"),st.textContent=Sl,ke=a(),m(at.$$.fragment),Re=a(),nt=i("p"),nt.textContent=Yl,Xe=a(),m(it.$$.fragment),Ae=a(),m(pt.$$.fragment),xe=a(),m(mt.$$.fragment),Fe=a(),m(ot.$$.fragment),Ne=a(),Mt=i("p"),Mt.innerHTML=Ll,Ve=a(),rt=i("p"),rt.innerHTML=Hl,ze=a(),ct=i("ol"),ct.innerHTML=ql,Qe=a(),ut=i("p"),ut.textContent=Dl,Ee=a(),m(yt.$$.fragment),Se=a(),m(dt.$$.fragment),Ye=a(),Jt=i("p"),Jt.textContent=Pl,Le=a(),m(ht.$$.fragment),He=a(),Tt=i("p"),Tt.innerHTML=Kl,qe=a(),m(wt.$$.fragment),De=a(),bt=i("pre"),bt.textContent=Ol,Pe=a(),m(jt.$$.fragment),Ke=a(),Ut=i("p"),Ut.textContent=ts,Oe=a(),m(ft.$$.fragment),tl=a(),m(It.$$.fragment),el=a(),gt=i("p"),gt.textContent=es,ll=a(),m(Ct.$$.fragment),sl=a(),m(Zt.$$.fragment),al=a(),m(Gt.$$.fragment),nl=a(),m(Bt.$$.fragment),il=a(),$t=i("p"),$t.innerHTML=ls,pl=a(),m(vt.$$.fragment),ml=a(),m(Wt.$$.fragment),ol=a(),m(_t.$$.fragment),Ml=a(),kt=i("p"),kt.textContent=ss,rl=a(),m(Rt.$$.fragment),cl=a(),Xt=i("pre"),Xt.textContent=as,ul=a(),m(At.$$.fragment),yl=a(),xt=i("p"),xt.textContent=ns,dl=a(),Ft=i("ol"),Ft.innerHTML=is,Jl=a(),Nt=i("p"),Nt.textContent=ps,hl=a(),Vt=i("p"),Vt.innerHTML=ms,Tl=a(),zt=i("ul"),zt.innerHTML=os,wl=a(),m(Qt.$$.fragment),bl=a(),m(Et.$$.fragment),jl=a(),Yt=i("p"),this.h()},l(t){const e=hs("svelte-u9bgzb",document.head);h=p(e,"META",{name:!0,content:!0}),e.forEach(l),Lt=n(t),St=p(t,"P",{}),Ms(St).forEach(l),Ht=n(t),o(T.$$.fragment,t),qt=n(t),o(w.$$.fragment,t),Dt=n(t),o(b.$$.fragment,t),Pt=n(t),j=p(t,"P",{"data-svelte-h":!0}),y(j)!=="svelte-c06g5p"&&(j.innerHTML=Il),Kt=n(t),U=p(t,"P",{"data-svelte-h":!0}),y(U)!=="svelte-1cnaxkg"&&(U.textContent=gl),Ot=n(t),f=p(t,"P",{"data-svelte-h":!0}),y(f)!=="svelte-73dzvq"&&(f.innerHTML=Cl),te=n(t),I=p(t,"P",{"data-svelte-h":!0}),y(I)!=="svelte-i4nscf"&&(I.innerHTML=Zl),ee=n(t),g=p(t,"OL",{"data-svelte-h":!0}),y(g)!=="svelte-1le0kfw"&&(g.innerHTML=Gl),le=n(t),C=p(t,"P",{"data-svelte-h":!0}),y(C)!=="svelte-1rs47kw"&&(C.textContent=Bl),se=n(t),Z=p(t,"P",{"data-svelte-h":!0}),y(Z)!=="svelte-1orajwa"&&(Z.innerHTML=$l),ae=n(t),G=p(t,"P",{"data-svelte-h":!0}),y(G)!=="svelte-y9jr31"&&(G.textContent=vl),ne=n(t),o(B.$$.fragment,t),ie=n(t),$=p(t,"P",{"data-svelte-h":!0}),y($)!=="svelte-17owk8i"&&($.innerHTML=Wl),pe=n(t),o(v.$$.fragment,t),me=n(t),o(W.$$.fragment,t),oe=n(t),o(_.$$.fragment,t),Me=n(t),k=p(t,"P",{"data-svelte-h":!0}),y(k)!=="svelte-9jqzic"&&(k.innerHTML=_l),re=n(t),o(R.$$.fragment,t),ce=n(t),X=p(t,"PRE",{"data-svelte-h":!0}),y(X)!=="svelte-1hlm4ai"&&(X.textContent=kl),ue=n(t),o(A.$$.fragment,t),ye=n(t),o(x.$$.fragment,t),de=n(t),F=p(t,"PRE",{"data-svelte-h":!0}),y(F)!=="svelte-1vvuct2"&&(F.textContent=Rl),Je=n(t),o(N.$$.fragment,t),he=n(t),V=p(t,"P",{"data-svelte-h":!0}),y(V)!=="svelte-fvf5ac"&&(V.innerHTML=Xl),Te=n(t),z=p(t,"P",{"data-svelte-h":!0}),y(z)!=="svelte-18woua2"&&(z.innerHTML=Al),we=n(t),Q=p(t,"OL",{"data-svelte-h":!0}),y(Q)!=="svelte-1hhu8ba"&&(Q.innerHTML=xl),be=n(t),E=p(t,"P",{"data-svelte-h":!0}),y(E)!=="svelte-12vz8vx"&&(E.innerHTML=Fl),je=n(t),o(S.$$.fragment,t),Ue=n(t),Y=p(t,"PRE",{"data-svelte-h":!0}),y(Y)!=="svelte-1c1fim5"&&(Y.textContent=Nl),fe=n(t),o(L.$$.fragment,t),Ie=n(t),H=p(t,"P",{"data-svelte-h":!0}),y(H)!=="svelte-174504e"&&(H.textContent=Vl),ge=n(t),o(q.$$.fragment,t),Ce=n(t),D=p(t,"PRE",{"data-svelte-h":!0}),y(D)!=="svelte-1jnwt9n"&&(D.textContent=zl),Ze=n(t),o(P.$$.fragment,t),Ge=n(t),o(K.$$.fragment,t),Be=n(t),O=p(t,"P",{"data-svelte-h":!0}),y(O)!=="svelte-1qd6zzu"&&(O.textContent=Ql),$e=n(t),o(tt.$$.fragment,t),ve=n(t),et=p(t,"PRE",{"data-svelte-h":!0}),y(et)!=="svelte-xkwqfq"&&(et.textContent=El),We=n(t),o(lt.$$.fragment,t),_e=n(t),st=p(t,"PRE",{"data-svelte-h":!0}),y(st)!=="svelte-7imcon"&&(st.textContent=Sl),ke=n(t),o(at.$$.fragment,t),Re=n(t),nt=p(t,"P",{"data-svelte-h":!0}),y(nt)!=="svelte-2zxtoy"&&(nt.textContent=Yl),Xe=n(t),o(it.$$.fragment,t),Ae=n(t),o(pt.$$.fragment,t),xe=n(t),o(mt.$$.fragment,t),Fe=n(t),o(ot.$$.fragment,t),Ne=n(t),Mt=p(t,"P",{"data-svelte-h":!0}),y(Mt)!=="svelte-ra054m"&&(Mt.innerHTML=Ll),Ve=n(t),rt=p(t,"P",{"data-svelte-h":!0}),y(rt)!=="svelte-w67mbi"&&(rt.innerHTML=Hl),ze=n(t),ct=p(t,"OL",{"data-svelte-h":!0}),y(ct)!=="svelte-zckd8z"&&(ct.innerHTML=ql),Qe=n(t),ut=p(t,"P",{"data-svelte-h":!0}),y(ut)!=="svelte-idkzl3"&&(ut.textContent=Dl),Ee=n(t),o(yt.$$.fragment,t),Se=n(t),o(dt.$$.fragment,t),Ye=n(t),Jt=p(t,"P",{"data-svelte-h":!0}),y(Jt)!=="svelte-142vbq7"&&(Jt.textContent=Pl),Le=n(t),o(ht.$$.fragment,t),He=n(t),Tt=p(t,"P",{"data-svelte-h":!0}),y(Tt)!=="svelte-48hl85"&&(Tt.innerHTML=Kl),qe=n(t),o(wt.$$.fragment,t),De=n(t),bt=p(t,"PRE",{"data-svelte-h":!0}),y(bt)!=="svelte-15aiiyo"&&(bt.textContent=Ol),Pe=n(t),o(jt.$$.fragment,t),Ke=n(t),Ut=p(t,"P",{"data-svelte-h":!0}),y(Ut)!=="svelte-1c2y3vw"&&(Ut.textContent=ts),Oe=n(t),o(ft.$$.fragment,t),tl=n(t),o(It.$$.fragment,t),el=n(t),gt=p(t,"P",{"data-svelte-h":!0}),y(gt)!=="svelte-4dekm1"&&(gt.textContent=es),ll=n(t),o(Ct.$$.fragment,t),sl=n(t),o(Zt.$$.fragment,t),al=n(t),o(Gt.$$.fragment,t),nl=n(t),o(Bt.$$.fragment,t),il=n(t),$t=p(t,"P",{"data-svelte-h":!0}),y($t)!=="svelte-1lapb9t"&&($t.innerHTML=ls),pl=n(t),o(vt.$$.fragment,t),ml=n(t),o(Wt.$$.fragment,t),ol=n(t),o(_t.$$.fragment,t),Ml=n(t),kt=p(t,"P",{"data-svelte-h":!0}),y(kt)!=="svelte-1x9d7gm"&&(kt.textContent=ss),rl=n(t),o(Rt.$$.fragment,t),cl=n(t),Xt=p(t,"PRE",{"data-svelte-h":!0}),y(Xt)!=="svelte-obtvzv"&&(Xt.textContent=as),ul=n(t),o(At.$$.fragment,t),yl=n(t),xt=p(t,"P",{"data-svelte-h":!0}),y(xt)!=="svelte-x5xn5v"&&(xt.textContent=ns),dl=n(t),Ft=p(t,"OL",{"data-svelte-h":!0}),y(Ft)!=="svelte-1o9abay"&&(Ft.innerHTML=is),Jl=n(t),Nt=p(t,"P",{"data-svelte-h":!0}),y(Nt)!=="svelte-1i9u9tk"&&(Nt.textContent=ps),hl=n(t),Vt=p(t,"P",{"data-svelte-h":!0}),y(Vt)!=="svelte-1tazzm1"&&(Vt.innerHTML=ms),Tl=n(t),zt=p(t,"UL",{"data-svelte-h":!0}),y(zt)!=="svelte-157e32j"&&(zt.innerHTML=os),wl=n(t),o(Qt.$$.fragment,t),bl=n(t),o(Et.$$.fragment,t),jl=n(t),Yt=p(t,"P",{}),Ms(Yt).forEach(l),this.h()},h(){rs(h,"name","hf:doc:metadata"),rs(h,"content",fs)},m(t,e){Ts(document.head,h),s(t,Lt,e),s(t,St,e),s(t,Ht,e),M(T,t,e),s(t,qt,e),M(w,t,e),s(t,Dt,e),M(b,t,e),s(t,Pt,e),s(t,j,e),s(t,Kt,e),s(t,U,e),s(t,Ot,e),s(t,f,e),s(t,te,e),s(t,I,e),s(t,ee,e),s(t,g,e),s(t,le,e),s(t,C,e),s(t,se,e),s(t,Z,e),s(t,ae,e),s(t,G,e),s(t,ne,e),M(B,t,e),s(t,ie,e),s(t,$,e),s(t,pe,e),M(v,t,e),s(t,me,e),M(W,t,e),s(t,oe,e),M(_,t,e),s(t,Me,e),s(t,k,e),s(t,re,e),M(R,t,e),s(t,ce,e),s(t,X,e),s(t,ue,e),M(A,t,e),s(t,ye,e),M(x,t,e),s(t,de,e),s(t,F,e),s(t,Je,e),M(N,t,e),s(t,he,e),s(t,V,e),s(t,Te,e),s(t,z,e),s(t,we,e),s(t,Q,e),s(t,be,e),s(t,E,e),s(t,je,e),M(S,t,e),s(t,Ue,e),s(t,Y,e),s(t,fe,e),M(L,t,e),s(t,Ie,e),s(t,H,e),s(t,ge,e),M(q,t,e),s(t,Ce,e),s(t,D,e),s(t,Ze,e),M(P,t,e),s(t,Ge,e),M(K,t,e),s(t,Be,e),s(t,O,e),s(t,$e,e),M(tt,t,e),s(t,ve,e),s(t,et,e),s(t,We,e),M(lt,t,e),s(t,_e,e),s(t,st,e),s(t,ke,e),M(at,t,e),s(t,Re,e),s(t,nt,e),s(t,Xe,e),M(it,t,e),s(t,Ae,e),M(pt,t,e),s(t,xe,e),M(mt,t,e),s(t,Fe,e),M(ot,t,e),s(t,Ne,e),s(t,Mt,e),s(t,Ve,e),s(t,rt,e),s(t,ze,e),s(t,ct,e),s(t,Qe,e),s(t,ut,e),s(t,Ee,e),M(yt,t,e),s(t,Se,e),M(dt,t,e),s(t,Ye,e),s(t,Jt,e),s(t,Le,e),M(ht,t,e),s(t,He,e),s(t,Tt,e),s(t,qe,e),M(wt,t,e),s(t,De,e),s(t,bt,e),s(t,Pe,e),M(jt,t,e),s(t,Ke,e),s(t,Ut,e),s(t,Oe,e),M(ft,t,e),s(t,tl,e),M(It,t,e),s(t,el,e),s(t,gt,e),s(t,ll,e),M(Ct,t,e),s(t,sl,e),M(Zt,t,e),s(t,al,e),M(Gt,t,e),s(t,nl,e),M(Bt,t,e),s(t,il,e),s(t,$t,e),s(t,pl,e),M(vt,t,e),s(t,ml,e),M(Wt,t,e),s(t,ol,e),M(_t,t,e),s(t,Ml,e),s(t,kt,e),s(t,rl,e),M(Rt,t,e),s(t,cl,e),s(t,Xt,e),s(t,ul,e),M(At,t,e),s(t,yl,e),s(t,xt,e),s(t,dl,e),s(t,Ft,e),s(t,Jl,e),s(t,Nt,e),s(t,hl,e),s(t,Vt,e),s(t,Tl,e),s(t,zt,e),s(t,wl,e),M(Qt,t,e),s(t,bl,e),M(Et,t,e),s(t,jl,e),s(t,Yt,e),Ul=!0},p:us,i(t){Ul||(r(T.$$.fragment,t),r(w.$$.fragment,t),r(b.$$.fragment,t),r(B.$$.fragment,t),r(v.$$.fragment,t),r(W.$$.fragment,t),r(_.$$.fragment,t),r(R.$$.fragment,t),r(A.$$.fragment,t),r(x.$$.fragment,t),r(N.$$.fragment,t),r(S.$$.fragment,t),r(L.$$.fragment,t),r(q.$$.fragment,t),r(P.$$.fragment,t),r(K.$$.fragment,t),r(tt.$$.fragment,t),r(lt.$$.fragment,t),r(at.$$.fragment,t),r(it.$$.fragment,t),r(pt.$$.fragment,t),r(mt.$$.fragment,t),r(ot.$$.fragment,t),r(yt.$$.fragment,t),r(dt.$$.fragment,t),r(ht.$$.fragment,t),r(wt.$$.fragment,t),r(jt.$$.fragment,t),r(ft.$$.fragment,t),r(It.$$.fragment,t),r(Ct.$$.fragment,t),r(Zt.$$.fragment,t),r(Gt.$$.fragment,t),r(Bt.$$.fragment,t),r(vt.$$.fragment,t),r(Wt.$$.fragment,t),r(_t.$$.fragment,t),r(Rt.$$.fragment,t),r(At.$$.fragment,t),r(Qt.$$.fragment,t),r(Et.$$.fragment,t),Ul=!0)},o(t){c(T.$$.fragment,t),c(w.$$.fragment,t),c(b.$$.fragment,t),c(B.$$.fragment,t),c(v.$$.fragment,t),c(W.$$.fragment,t),c(_.$$.fragment,t),c(R.$$.fragment,t),c(A.$$.fragment,t),c(x.$$.fragment,t),c(N.$$.fragment,t),c(S.$$.fragment,t),c(L.$$.fragment,t),c(q.$$.fragment,t),c(P.$$.fragment,t),c(K.$$.fragment,t),c(tt.$$.fragment,t),c(lt.$$.fragment,t),c(at.$$.fragment,t),c(it.$$.fragment,t),c(pt.$$.fragment,t),c(mt.$$.fragment,t),c(ot.$$.fragment,t),c(yt.$$.fragment,t),c(dt.$$.fragment,t),c(ht.$$.fragment,t),c(wt.$$.fragment,t),c(jt.$$.fragment,t),c(ft.$$.fragment,t),c(It.$$.fragment,t),c(Ct.$$.fragment,t),c(Zt.$$.fragment,t),c(Gt.$$.fragment,t),c(Bt.$$.fragment,t),c(vt.$$.fragment,t),c(Wt.$$.fragment,t),c(_t.$$.fragment,t),c(Rt.$$.fragment,t),c(At.$$.fragment,t),c(Qt.$$.fragment,t),c(Et.$$.fragment,t),Ul=!1},d(t){t&&(l(Lt),l(St),l(Ht),l(qt),l(Dt),l(Pt),l(j),l(Kt),l(U),l(Ot),l(f),l(te),l(I),l(ee),l(g),l(le),l(C),l(se),l(Z),l(ae),l(G),l(ne),l(ie),l($),l(pe),l(me),l(oe),l(Me),l(k),l(re),l(ce),l(X),l(ue),l(ye),l(de),l(F),l(Je),l(he),l(V),l(Te),l(z),l(we),l(Q),l(be),l(E),l(je),l(Ue),l(Y),l(fe),l(Ie),l(H),l(ge),l(Ce),l(D),l(Ze),l(Ge),l(Be),l(O),l($e),l(ve),l(et),l(We),l(_e),l(st),l(ke),l(Re),l(nt),l(Xe),l(Ae),l(xe),l(Fe),l(Ne),l(Mt),l(Ve),l(rt),l(ze),l(ct),l(Qe),l(ut),l(Ee),l(Se),l(Ye),l(Jt),l(Le),l(He),l(Tt),l(qe),l(De),l(bt),l(Pe),l(Ke),l(Ut),l(Oe),l(tl),l(el),l(gt),l(ll),l(sl),l(al),l(nl),l(il),l($t),l(pl),l(ml),l(ol),l(Ml),l(kt),l(rl),l(cl),l(Xt),l(ul),l(yl),l(xt),l(dl),l(Ft),l(Jl),l(Nt),l(hl),l(Vt),l(Tl),l(zt),l(wl),l(bl),l(jl),l(Yt)),l(h),u(T,t),u(w,t),u(b,t),u(B,t),u(v,t),u(W,t),u(_,t),u(R,t),u(A,t),u(x,t),u(N,t),u(S,t),u(L,t),u(q,t),u(P,t),u(K,t),u(tt,t),u(lt,t),u(at,t),u(it,t),u(pt,t),u(mt,t),u(ot,t),u(yt,t),u(dt,t),u(ht,t),u(wt,t),u(jt,t),u(ft,t),u(It,t),u(Ct,t),u(Zt,t),u(Gt,t),u(Bt,t),u(vt,t),u(Wt,t),u(_t,t),u(Rt,t),u(At,t),u(Qt,t),u(Et,t)}}}const fs='{"title":"Documentation Chatbot with Meta Synthetic Data Kit","local":"documentation-chatbot-with-meta-synthetic-data-kit","sections":[{"title":"1. Setup and Installation","local":"1-setup-and-installation","sections":[],"depth":2},{"title":"2. Synthetic Data Generation","local":"2-synthetic-data-generation","sections":[{"title":"2.1. Acquire and Ingest Documentation","local":"21-acquire-and-ingest-documentation","sections":[],"depth":3},{"title":"2.2. Chunk Data and Generate QA Pairs","local":"22-chunk-data-and-generate-qa-pairs","sections":[],"depth":3},{"title":"2.3. Format and Save QA Pairs","local":"23-format-and-save-qa-pairs","sections":[],"depth":3},{"title":"2.4. Load the Formatted Dataset","local":"24-load-the-formatted-dataset","sections":[],"depth":3},{"title":"Memory Management Note (Critical for Resource-Constrained Environments)","local":"memory-management-note-critical-for-resource-constrained-environments","sections":[],"depth":3}],"depth":2},{"title":"3. Fine-tuning the LLM with Unsloth","local":"3-fine-tuning-the-llm-with-unsloth","sections":[{"title":"3.1. Load Base Model and Tokenizer","local":"31-load-base-model-and-tokenizer","sections":[],"depth":3},{"title":"3.2. Add LoRA Adapters","local":"32-add-lora-adapters","sections":[],"depth":3},{"title":"3.3. Data Preparation for Chat Format","local":"33-data-preparation-for-chat-format","sections":[],"depth":3},{"title":"3.4. Train the Model","local":"34-train-the-model","sections":[],"depth":3}],"depth":2},{"title":"4. Inference and Testing","local":"4-inference-and-testing","sections":[],"depth":2},{"title":"5. Conclusion","local":"5-conclusion","sections":[],"depth":2}],"depth":1}';function Is(fl){return ys(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class $s extends ds{constructor(h){super(),Js(this,h,Is,Us,cs,{})}}export{$s as component};
