import{s as Mt,n as et,o as tt}from"../chunks/scheduler.1f027d5a.js";import{S as st,i as at,e as n,s,c as J,h as nt,a as y,d as e,b as a,f as Oe,g as T,j as U,k as lt,l as yt,m as t,n as j,t as p,o as w,p as i}from"../chunks/index.cedebf1a.js";import{C as Ut}from"../chunks/CopyLLMTxtMenu.9763f102.js";import{D as Jt,C as o}from"../chunks/DocNotebookDropdown.aa615a4d.js";import{H as gl,E as Tt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.71ce9e32.js";function jt(ye){let C,Wl,Ql,Sl,I,Nl,m,Yl,r,vl,d,Ue='<em>Authored by: <a href="https://github.com/MKhalusova" rel="nofollow">Maria Khalusova</a></em>',xl,c,Je="Publicly available code LLMs such as Codex, StarCoder, and Code Llama are great at generating code that adheres to general programming principles and syntax, but they may not align with an organization’s internal conventions, or be aware of proprietary libraries.",Hl,A,Te="In this notebook, we’ll see show how you can fine-tune a code LLM on private code bases to enhance its contextual awareness and improve a model’s usefulness to your organization’s needs. Since the code LLMs are quite large, fine-tuning them in a traditional manner can be resource-draining. Worry not! We will show how you can optimize fine-tuning to fit on a single GPU.",zl,h,$l,u,je='For this example, we picked the top 10 Hugging Face public repositories on GitHub. We have excluded non-code files from the data, such as images, audio files, presentations, and so on. For Jupyter notebooks, we’ve kept only cells containing code. The resulting code is stored as a dataset that you can find on the Hugging Face Hub under <a href="https://huggingface.co/datasets/smangrul/hf-stack-v1" rel="nofollow"><code>smangrul/hf-stack-v1</code></a>. It contains repo id, file path, and file content.',Ll,f,ql,b,pe='We’ll finetune <a href="https://huggingface.co/bigcode/starcoderbase-1b" rel="nofollow"><code>bigcode/starcoderbase-1b</code></a>, which is a 1B parameter model trained on 80+ programming languages. This is a gated model, so if you plan to run this notebook with this exact model, you’ll need to gain access to it on the model’s page. Log in to your Hugging Face account to do so:',Dl,Z,Pl,B,we="To get started, let’s install all the necessary libraries. As you can see, in addition to <code>transformers</code> and <code>datasets</code>, we’ll be using <code>peft</code>, <code>bitsandbytes</code>, and <code>flash-attn</code> to optimize the training.",Kl,_,ie="By employing parameter-efficient training techniques, we can run this notebook on a single A100 High-RAM GPU.",Ol,G,lM,R,oe="Let’s define some variables now. Feel free to play with these.",MM,E,eM,k,tM,X,sM,V,Ce="Begin by loading the data. As the dataset is likely to be quite large, make sure to enable the streaming mode. Streaming allows us to load the data progressively as we iterate over the dataset instead of downloading the whole dataset at once.",aM,g,Ie="We’ll reserve the first 4000 examples as the validation set, and everything else will be the training data.",nM,Q,yM,F,me="At this step, the dataset still contains raw data with code of arbitraty length. For training, we need inputs of fixed length. Let’s create an Iterable dataset that would return constant-length chunks of tokens from a stream of text files.",UM,W,re="First, let’s estimate the average number of characters per token in the dataset, which will help us later estimate the number of tokens in the text buffer later. By default, we’ll only take 400 examples (<code>nb_examples</code>) from the dataset. Using only a subset of the entire dataset will reduce computational cost while still providing a reasonable estimate of the overall character-to-token ratio.",JM,S,TM,N,de=`The character to token ratio of the dataset is: 2.43
`,jM,Y,ce="The character-to-token ratio can also be used as an indicator of the quality of text tokenization. For instance, a character-to-token ratio of 1.0 would mean that each character is represented with a token, which is not very meaningful. This would indicate poor tokenization. In standard English text, one token is typically equivalent to approximately four characters, meaning the character-to-token ratio is around 4.0. We can expect a lower ratio in the code dataset, but generally speaking, a number between 2.0 and 3.5 can be considered good enough.",pM,v,Ae="<strong>Optional FIM transformations</strong>",wM,x,he=`Autoregressive language models typically generate sequences from left to right. By applying the FIM transformations, the model can also learn to infill text.  Check out <a href="https://arxiv.org/pdf/2207.14255.pdf" rel="nofollow">“Efficient Training of Language Models to Fill in the Middle” paper</a> to learn more about the technique.
We’ll define the FIM transformations here and will use them when creating the Iterable Dataset. However, if you want to omit transformations, feel free to set <code>fim_rate</code> to 0.`,iM,H,oM,z,ue="Let’s define the <code>ConstantLengthDataset</code>, an Iterable dataset that will return constant-length chunks of tokens. To do so, we’ll read a buffer of text from the original dataset until we hit the size limits and then apply tokenizer to convert the raw text into tokenized inputs. Optionally, we’ll perform FIM transformations on some sequences (the proportion of sequences affected is controlled by <code>fim_rate</code>).",CM,$,fe="Once defined, we can create instances of the <code>ConstantLengthDataset</code> from both training and validation data.",IM,L,mM,q,rM,D,be="Now that the data is prepared, it’s time to load the model! We’re going to load the quantized version of the model.",dM,P,Ze="This will allow us to reduce memory usage, as quantization represents data with fewer bits. We’ll use the <code>bitsandbytes</code> library to quantize the model, as it has a nice integration with <code>transformers</code>. All we need to do is define a <code>bitsandbytes</code> config, and then use it when loading the model.",cM,K,Be="There are different variants of 4bit quantization, but generally, we recommend using NF4 quantization for better performance (<code>bnb_4bit_quant_type=&quot;nf4&quot;</code>).",AM,O,_e="The <code>bnb_4bit_use_double_quant</code> option adds a second quantization after the first one to save an additional 0.4 bits per parameter.",hM,ll,Ge='To learn more about quantization, check out the <a href="https://huggingface.co/blog/4bit-transformers-bitsandbytes" rel="nofollow">“Making LLMs even more accessible with bitsandbytes, 4-bit quantization and QLoRA” blog post</a>.',uM,Ml,Re="Once defined, pass the config to the <code>from_pretrained</code> method to load the quantized version of the model.",fM,el,bM,tl,Ee="When using a quantized model for training, you need to call the <code>prepare_model_for_kbit_training()</code> function to preprocess the quantized model for training.",ZM,sl,BM,al,ke="Now that the quantized model is ready, we can set up a LoRA configuration. LoRA makes fine-tuning more efficient by drastically reducing the number of trainable parameters.",_M,nl,Xe="To train a model using LoRA technique, we need to wrap the base model as a <code>PeftModel</code>. This involves definign LoRA configuration with <code>LoraConfig</code>, and wrapping the original model with <code>get_peft_model()</code> using the <code>LoraConfig</code>.",GM,yl,Ve='To learn more about LoRA and its parameters, refer to <a href="https://huggingface.co/docs/peft/main/en/conceptual_guides/lora" rel="nofollow">PEFT documentation</a>.',RM,Ul,EM,Jl,ge=`trainable params: 5,554,176 || all params: 1,142,761,472 || trainable%: 0.4860310866343243
`,kM,Tl,Qe="As you can see, by applying LoRA technique we will now need to train less than 1% of the parameters.",XM,jl,VM,pl,Fe="Now that we have prepared the data, and optimized the model, we are ready to bring everything together to start the training.",gM,wl,We="To instantiate a <code>Trainer</code>, you need to define the training configuration. The most important is the <code>TrainingArguments</code>, which is a class that contains all the attributes to configure the training.",QM,il,Se="These are similar to any other kind of model training you may run, so we won’t go into detail here.",FM,ol,WM,Cl,Ne="As a final step, instantiate the <code>Trainer</code> and call the <code>train</code> method.",SM,Il,NM,ml,Ye=`Training...
`,YM,rl,ve="Finally, you can push the fine-tuned model to your Hub repository to share with your team.",vM,dl,xM,cl,HM,Al,xe="Once the model is uploaded to Hub, we can use it for inference. To do so we first initialize the original base model and its tokenizer. Next, we need to merge the fine-duned weights with the base model.",zM,hl,$M,ul,He="Now we can use the merged model for inference. For convenience, we’ll define a <code>get_code_completion</code> - feel free to experiment with text generation parameters!",LM,fl,qM,bl,ze="Now all we need to do to get code completion is call the <code>get_code_complete</code> function and pass the first few lines that we want to be completed as a prefix, and an empty string as a suffix.",DM,Zl,PM,Bl,$e=`from peft import LoraConfig, TaskType, get_peft_model
from transformers import AutoModelForCausalLM
peft_config = LoraConfig(
    task_type=TaskType.CAUSAL_LM,
    r=8,
    lora_alpha=32,
    target_modules=["q_proj", "v_proj"],
    lora_dropout=0.1,
    bias="none",
    modules_to_save=["q_proj", "v_proj"],
    inference_mode=False,
)
model = AutoModelForCausalLM.from_pretrained("gpt2")
model = get_peft_model(model, peft_config)
model.print_trainable_parameters()
`,KM,_l,Le="As someone who has just used the PEFT library earlier in this notebook, you can see that the generated result for creating a <code>LoraConfig</code> is rather good!",OM,Gl,qe="If you go back to the cell where we instantiate the model for inference, and comment out the lines where we merge the fine-tuned weights, you can see what the original model would’ve generated for the exact same prefix:",le,Rl,Me,El,De=`from peft import LoraConfig, TaskType, get_peft_model
from transformers import AutoModelForCausalLM
peft_config = LoraConfig(
    model_name_or_path="facebook/wav2vec2-base-960h",
    num_labels=1,
    num_features=1,
    num_hidden_layers=1,
    num_attention_heads=1,
    num_hidden_layers_per_attention_head=1,
    num_attention_heads_per_hidden_layer=1,
    hidden_size=1024,
    hidden_dropout_prob=0.1,
    hidden_act="gelu",
    hidden_act_dropout_prob=0.1,
    hidden
`,ee,kl,Pe="While it is Python syntax, you can see that the original model has no understanding of what a <code>LoraConfig</code> should be doing.",te,Xl,Ke='To learn how this kind of fine-tuning compares to full fine-tuning, and how to use a model like this as your copilot in VS Code via Inference Endpoints, or locally, check out the <a href="https://huggingface.co/blog/personal-copilot" rel="nofollow">“Personal Copilot: Train Your Own Coding Assistant” blog post</a>. This notebook complements the original blog post.',se,Vl,ae,Fl,ne;return I=new Jt({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_tuning_code_llm_on_single_gpu.ipynb"}]}}),m=new Ut({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),r=new gl({props:{title:"Fine-tuning a Code LLM on Custom Code on a single GPU",local:"fine-tuning-a-code-llm-on-custom-code-on-a-single-gpu",headingTag:"h1"}}),h=new gl({props:{title:"Dataset",local:"dataset",headingTag:"h2"}}),f=new gl({props:{title:"Model",local:"model",headingTag:"h2"}}),Z=new o({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),G=new o({props:{code:"IXBpcCUyMGluc3RhbGwlMjAtcSUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwcGVmdCUyMGJpdHNhbmRieXRlcyUyMGZsYXNoLWF0dG4=",highlighted:"!pip install -q transformers datasets peft bitsandbytes flash-attn",wrap:!1}}),E=new o({props:{code:"TU9ERUwlM0QlMjJiaWdjb2RlJTJGc3RhcmNvZGVyYmFzZS0xYiUyMiUyMCUyMyUyME1vZGVsJTIwY2hlY2twb2ludCUyMG9uJTIwdGhlJTIwSHVnZ2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RUWVBFJTNEJTIyYmZsb2F0MTYlMjIlMjMlMjBibmJfNGJpdF9jb21wdXRlX2R0eXBlJTBBJTBBU0VFRCUzRDA=",highlighted:`MODEL=<span class="hljs-string">&quot;bigcode/starcoderbase-1b&quot;</span> <span class="hljs-comment"># Model checkpoint on the Hugging Face Hub</span>
DATASET=<span class="hljs-string">&quot;smangrul/hf-stack-v1&quot;</span>   <span class="hljs-comment"># Dataset on the Hugging Face Hub</span>
DATA_COLUMN=<span class="hljs-string">&quot;content&quot;</span>            <span class="hljs-comment"># Column name containing the code content</span>

SEQ_LENGTH=<span class="hljs-number">2048</span>                  <span class="hljs-comment"># Sequence length</span>

<span class="hljs-comment"># Training arguments</span>
MAX_STEPS=<span class="hljs-number">2000</span>                   <span class="hljs-comment"># max_steps</span>
BATCH_SIZE=<span class="hljs-number">16</span>                    <span class="hljs-comment"># batch_size</span>
GR_ACC_STEPS=<span class="hljs-number">1</span>                   <span class="hljs-comment"># gradient_accumulation_steps</span>
LR=<span class="hljs-number">5e-4</span>                          <span class="hljs-comment"># learning_rate</span>
LR_SCHEDULER_TYPE=<span class="hljs-string">&quot;cosine&quot;</span>       <span class="hljs-comment"># lr_scheduler_type</span>
WEIGHT_DECAY=<span class="hljs-number">0.01</span>                <span class="hljs-comment"># weight_decay</span>
NUM_WARMUP_STEPS=<span class="hljs-number">30</span>              <span class="hljs-comment"># num_warmup_steps</span>
EVAL_FREQ=<span class="hljs-number">100</span>                    <span class="hljs-comment"># eval_freq</span>
SAVE_FREQ=<span class="hljs-number">100</span>                    <span class="hljs-comment"># save_freq</span>
LOG_FREQ=<span class="hljs-number">25</span>                      <span class="hljs-comment"># log_freq</span>
OUTPUT_DIR=<span class="hljs-string">&quot;peft-starcoder-lora-a100&quot;</span> <span class="hljs-comment"># output_dir</span>
BF16=<span class="hljs-literal">True</span>                        <span class="hljs-comment"># bf16</span>
FP16=<span class="hljs-literal">False</span>                       <span class="hljs-comment"># no_fp16</span>

<span class="hljs-comment"># FIM trasformations arguments</span>
FIM_RATE=<span class="hljs-number">0.5</span>                     <span class="hljs-comment"># fim_rate</span>
FIM_SPM_RATE=<span class="hljs-number">0.5</span>                 <span class="hljs-comment"># fim_spm_rate</span>

<span class="hljs-comment"># LORA</span>
LORA_R=<span class="hljs-number">8</span>                         <span class="hljs-comment"># lora_r</span>
LORA_ALPHA=<span class="hljs-number">32</span>                    <span class="hljs-comment"># lora_alpha</span>
LORA_DROPOUT=<span class="hljs-number">0.0</span>                 <span class="hljs-comment"># lora_dropout</span>
LORA_TARGET_MODULES=<span class="hljs-string">&quot;c_proj,c_attn,q_attn,c_fc,c_proj&quot;</span>    <span class="hljs-comment"># lora_target_modules</span>

<span class="hljs-comment"># bitsandbytes config</span>
USE_NESTED_QUANT=<span class="hljs-literal">True</span>            <span class="hljs-comment"># use_nested_quant</span>
BNB_4BIT_COMPUTE_DTYPE=<span class="hljs-string">&quot;bfloat16&quot;</span><span class="hljs-comment"># bnb_4bit_compute_dtype</span>

SEED=<span class="hljs-number">0</span>`,wrap:!1}}),k=new o({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMCglMEElMjAlMjAlMjAlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUyQyUwQSUyMCUyMCUyMCUyMEF1dG9Ub2tlbml6ZXIlMkMlMEElMjAlMjAlMjAlMjBUcmFpbmVyJTJDJTBBJTIwJTIwJTIwJTIwVHJhaW5pbmdBcmd1bWVudHMlMkMlMEElMjAlMjAlMjAlMjBsb2dnaW5nJTJDJTBBJTIwJTIwJTIwJTIwc2V0X3NlZWQlMkMlMEElMjAlMjAlMjAlMjBCaXRzQW5kQnl0ZXNDb25maWclMkMlMEEpJTBBJTBBc2V0X3NlZWQoU0VFRCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> (
    AutoModelForCausalLM,
    AutoTokenizer,
    Trainer,
    TrainingArguments,
    logging,
    set_seed,
    BitsAndBytesConfig,
)

set_seed(SEED)`,wrap:!1}}),X=new gl({props:{title:"Prepare the data",local:"prepare-the-data",headingTag:"h2"}}),Q=new o({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBaW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHFkbSUyMGltcG9ydCUyMHRxZG0lMEElMEElMEFkYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMERBVEFTRVQlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2RpciUzRCUyMmRhdGElMjIlMkMlMEElMjAlMjAlMjAlMjBzcGxpdCUzRCUyMnRyYWluJTIyJTJDJTBBJTIwJTIwJTIwJTIwc3RyZWFtaW5nJTNEVHJ1ZSUyQyUwQSklMEElMEF2YWxpZF9kYXRhJTIwJTNEJTIwZGF0YXNldC50YWtlKDQwMDApJTBBdHJhaW5fZGF0YSUyMCUzRCUyMGRhdGFzZXQuc2tpcCg0MDAwKSUwQXRyYWluX2RhdGElMjAlM0QlMjB0cmFpbl9kYXRhLnNodWZmbGUoYnVmZmVyX3NpemUlM0Q1MDAwJTJDJTIwc2VlZCUzRFNFRUQp",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> tqdm <span class="hljs-keyword">import</span> tqdm


dataset = load_dataset(
    DATASET,
    data_dir=<span class="hljs-string">&quot;data&quot;</span>,
    split=<span class="hljs-string">&quot;train&quot;</span>,
    streaming=<span class="hljs-literal">True</span>,
)

valid_data = dataset.take(<span class="hljs-number">4000</span>)
train_data = dataset.skip(<span class="hljs-number">4000</span>)
train_data = train_data.shuffle(buffer_size=<span class="hljs-number">5000</span>, seed=SEED)`,wrap:!1}}),S=new o({props:{code:"dG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoTU9ERUwlMkMlMjB0cnVzd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RBX0NPTFVNTiklMEFwcmludChmJTIyVGhlJTIwY2hhcmFjdGVyJTIwdG8lMjB0b2tlbiUyMHJhdGlvJTIwb2YlMjB0aGUlMjBkYXRhc2V0JTIwaXMlM0ElMjAlN0JjaGFyc19wZXJfdG9rZW4lM0EuMmYlN0QlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">chars_token_ratio</span>(<span class="hljs-params">dataset, tokenizer, data_column, nb_examples=<span class="hljs-number">400</span></span>):
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;&quot;&quot;
<span class="hljs-meta">... </span>    Estimate the average number of characters per token in the dataset.
<span class="hljs-meta">... </span>    &quot;&quot;&quot;</span>

<span class="hljs-meta">... </span>    total_characters, total_tokens = <span class="hljs-number">0</span>, <span class="hljs-number">0</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> _, example <span class="hljs-keyword">in</span> tqdm(<span class="hljs-built_in">zip</span>(<span class="hljs-built_in">range</span>(nb_examples), <span class="hljs-built_in">iter</span>(dataset)), total=nb_examples):
<span class="hljs-meta">... </span>        total_characters += <span class="hljs-built_in">len</span>(example[data_column])
<span class="hljs-meta">... </span>        total_tokens += <span class="hljs-built_in">len</span>(tokenizer(example[data_column]).tokens())

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> total_characters / total_tokens


<span class="hljs-meta">&gt;&gt;&gt; </span>chars_per_token = chars_token_ratio(train_data, tokenizer, DATA_COLUMN)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;The character to token ratio of the dataset is: <span class="hljs-subst">{chars_per_token:<span class="hljs-number">.2</span>f}</span>&quot;</span>)`,wrap:!1}}),H=new o({props:{code:" ",highlighted:`<span class="hljs-keyword">import</span> functools
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-comment"># Helper function to get token ids of the special tokens for prefix, suffix and middle for FIM transformations.</span>
<span class="hljs-meta">@functools.lru_cache(<span class="hljs-params">maxsize=<span class="hljs-literal">None</span></span>)</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_fim_token_ids</span>(<span class="hljs-params">tokenizer</span>):
    <span class="hljs-keyword">try</span>:
        FIM_PREFIX, FIM_MIDDLE, FIM_SUFFIX, FIM_PAD = tokenizer.special_tokens_map[<span class="hljs-string">&quot;additional_special_tokens&quot;</span>][<span class="hljs-number">1</span>:<span class="hljs-number">5</span>]
        suffix_tok_id, prefix_tok_id, middle_tok_id, pad_tok_id = (
            tokenizer.vocab[tok] <span class="hljs-keyword">for</span> tok <span class="hljs-keyword">in</span> [FIM_SUFFIX, FIM_PREFIX, FIM_MIDDLE, FIM_PAD]
        )
    <span class="hljs-keyword">except</span> KeyError:
        suffix_tok_id, prefix_tok_id, middle_tok_id, pad_tok_id = <span class="hljs-literal">None</span>, <span class="hljs-literal">None</span>, <span class="hljs-literal">None</span>, <span class="hljs-literal">None</span>
    <span class="hljs-keyword">return</span> suffix_tok_id, prefix_tok_id, middle_tok_id, pad_tok_id


<span class="hljs-comment">## Adapted from https://github.com/bigcode-project/Megatron-LM/blob/6c4bf908df8fd86b4977f54bf5b8bd4b521003d1/megatron/data/gpt_dataset.py</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">permute</span>(<span class="hljs-params">
    sample,
    np_rng,
    suffix_tok_id,
    prefix_tok_id,
    middle_tok_id,
    pad_tok_id,
    fim_rate=<span class="hljs-number">0.5</span>,
    fim_spm_rate=<span class="hljs-number">0.5</span>,
    truncate_or_pad=<span class="hljs-literal">False</span>,
</span>):
    <span class="hljs-string">&quot;&quot;&quot;
    Take in a sample (list of tokens) and perform a FIM transformation on it with a probability of fim_rate, using two FIM modes:
    PSM and SPM (with a probability of fim_spm_rate).
    &quot;&quot;&quot;</span>

    <span class="hljs-comment"># The if condition will trigger with the probability of fim_rate</span>
    <span class="hljs-comment"># This means FIM transformations will apply to samples with a probability of fim_rate</span>
    <span class="hljs-keyword">if</span> np_rng.binomial(<span class="hljs-number">1</span>, fim_rate):

        <span class="hljs-comment"># Split the sample into prefix, middle, and suffix, based on randomly generated indices stored in the boundaries list.</span>
        boundaries = <span class="hljs-built_in">list</span>(np_rng.randint(low=<span class="hljs-number">0</span>, high=<span class="hljs-built_in">len</span>(sample) + <span class="hljs-number">1</span>, size=<span class="hljs-number">2</span>))
        boundaries.sort()

        prefix = np.array(sample[: boundaries[<span class="hljs-number">0</span>]], dtype=np.int64)
        middle = np.array(sample[boundaries[<span class="hljs-number">0</span>] : boundaries[<span class="hljs-number">1</span>]], dtype=np.int64)
        suffix = np.array(sample[boundaries[<span class="hljs-number">1</span>] :], dtype=np.int64)

        <span class="hljs-keyword">if</span> truncate_or_pad:
            <span class="hljs-comment"># calculate the new total length of the sample, taking into account tokens indicating prefix, middle, and suffix</span>
            new_length = suffix.shape[<span class="hljs-number">0</span>] + prefix.shape[<span class="hljs-number">0</span>] + middle.shape[<span class="hljs-number">0</span>] + <span class="hljs-number">3</span>
            diff = new_length - <span class="hljs-built_in">len</span>(sample)

            <span class="hljs-comment"># trancate or pad if there&#x27;s a difference in length between the new length and the original</span>
            <span class="hljs-keyword">if</span> diff &gt; <span class="hljs-number">0</span>:
                <span class="hljs-keyword">if</span> suffix.shape[<span class="hljs-number">0</span>] &lt;= diff:
                    <span class="hljs-keyword">return</span> sample, np_rng
                suffix = suffix[: suffix.shape[<span class="hljs-number">0</span>] - diff]
            <span class="hljs-keyword">elif</span> diff &lt; <span class="hljs-number">0</span>:
                suffix = np.concatenate([suffix, np.full((-<span class="hljs-number">1</span> * diff), pad_tok_id)])

        <span class="hljs-comment"># With the probability of fim_spm_rateapply SPM variant of FIM transformations</span>
        <span class="hljs-comment"># SPM: suffix, prefix, middle</span>
        <span class="hljs-keyword">if</span> np_rng.binomial(<span class="hljs-number">1</span>, fim_spm_rate):
            new_sample = np.concatenate(
                [
                    [prefix_tok_id, suffix_tok_id],
                    suffix,
                    [middle_tok_id],
                    prefix,
                    middle,
                ]
            )
        <span class="hljs-comment"># Otherwise, apply the PSM variant of FIM transformations</span>
        <span class="hljs-comment"># PSM: prefix, suffix, middle</span>
        <span class="hljs-keyword">else</span>:

            new_sample = np.concatenate(
                [
                    [prefix_tok_id],
                    prefix,
                    [suffix_tok_id],
                    suffix,
                    [middle_tok_id],
                    middle,
                ]
            )
    <span class="hljs-keyword">else</span>:
        <span class="hljs-comment"># don&#x27;t apply FIM transformations</span>
        new_sample = sample

    <span class="hljs-keyword">return</span> <span class="hljs-built_in">list</span>(new_sample), np_rng`,wrap:!1}}),L=new o({props:{code:" ",highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> IterableDataset
<span class="hljs-keyword">from</span> torch.utils.data.dataloader <span class="hljs-keyword">import</span> DataLoader
<span class="hljs-keyword">import</span> random

<span class="hljs-comment"># Create an Iterable dataset that returns constant-length chunks of tokens from a stream of text files.</span>

<span class="hljs-keyword">class</span> <span class="hljs-title class_">ConstantLengthDataset</span>(<span class="hljs-title class_ inherited__">IterableDataset</span>):
    <span class="hljs-string">&quot;&quot;&quot;
    Iterable dataset that returns constant length chunks of tokens from stream of text files.
        Args:
            tokenizer (Tokenizer): The processor used for proccessing the data.
            dataset (dataset.Dataset): Dataset with text files.
            infinite (bool): If True the iterator is reset after dataset reaches end else stops.
            seq_length (int): Length of token sequences to return.
            num_of_sequences (int): Number of token sequences to keep in buffer.
            chars_per_token (int): Number of characters per token used to estimate number of tokens in text buffer.
            fim_rate (float): Rate (0.0 to 1.0) that sample will be permuted with FIM.
            fim_spm_rate (float): Rate (0.0 to 1.0) of FIM permuations that will use SPM.
            seed (int): Seed for random number generator.
    &quot;&quot;&quot;</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">
        self,
        tokenizer,
        dataset,
        infinite=<span class="hljs-literal">False</span>,
        seq_length=<span class="hljs-number">1024</span>,
        num_of_sequences=<span class="hljs-number">1024</span>,
        chars_per_token=<span class="hljs-number">3.6</span>,
        content_field=<span class="hljs-string">&quot;content&quot;</span>,
        fim_rate=<span class="hljs-number">0.5</span>,
        fim_spm_rate=<span class="hljs-number">0.5</span>,
        seed=<span class="hljs-number">0</span>,
    </span>):
        self.tokenizer = tokenizer
        self.concat_token_id = tokenizer.eos_token_id
        self.dataset = dataset
        self.seq_length = seq_length
        self.infinite = infinite
        self.current_size = <span class="hljs-number">0</span>
        self.max_buffer_size = seq_length * chars_per_token * num_of_sequences
        self.content_field = content_field
        self.fim_rate = fim_rate
        self.fim_spm_rate = fim_spm_rate
        self.seed = seed

        (
            self.suffix_tok_id,
            self.prefix_tok_id,
            self.middle_tok_id,
            self.pad_tok_id,
        ) = get_fim_token_ids(self.tokenizer)
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> self.suffix_tok_id <span class="hljs-keyword">and</span> self.fim_rate &gt; <span class="hljs-number">0</span>:
            <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;FIM is not supported by tokenizer, disabling FIM&quot;</span>)
            self.fim_rate = <span class="hljs-number">0</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__iter__</span>(<span class="hljs-params">self</span>):
        iterator = <span class="hljs-built_in">iter</span>(self.dataset)
        more_examples = <span class="hljs-literal">True</span>
        np_rng = np.random.RandomState(seed=self.seed)
        <span class="hljs-keyword">while</span> more_examples:
            buffer, buffer_len = [], <span class="hljs-number">0</span>
            <span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>:
                <span class="hljs-keyword">if</span> buffer_len &gt;= self.max_buffer_size:
                    <span class="hljs-keyword">break</span>
                <span class="hljs-keyword">try</span>:
                    buffer.append(<span class="hljs-built_in">next</span>(iterator)[self.content_field])
                    buffer_len += <span class="hljs-built_in">len</span>(buffer[-<span class="hljs-number">1</span>])
                <span class="hljs-keyword">except</span> StopIteration:
                    <span class="hljs-keyword">if</span> self.infinite:
                        iterator = <span class="hljs-built_in">iter</span>(self.dataset)
                    <span class="hljs-keyword">else</span>:
                        more_examples = <span class="hljs-literal">False</span>
                        <span class="hljs-keyword">break</span>
            tokenized_inputs = self.tokenizer(buffer, truncation=<span class="hljs-literal">False</span>)[<span class="hljs-string">&quot;input_ids&quot;</span>]
            all_token_ids = []

            <span class="hljs-keyword">for</span> tokenized_input <span class="hljs-keyword">in</span> tokenized_inputs:
                <span class="hljs-comment"># optionally do FIM permutations</span>
                <span class="hljs-keyword">if</span> self.fim_rate &gt; <span class="hljs-number">0</span>:
                    tokenized_input, np_rng = permute(
                        tokenized_input,
                        np_rng,
                        self.suffix_tok_id,
                        self.prefix_tok_id,
                        self.middle_tok_id,
                        self.pad_tok_id,
                        fim_rate=self.fim_rate,
                        fim_spm_rate=self.fim_spm_rate,
                        truncate_or_pad=<span class="hljs-literal">False</span>,
                    )

                all_token_ids.extend(tokenized_input + [self.concat_token_id])
            examples = []
            <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-built_in">len</span>(all_token_ids), self.seq_length):
                input_ids = all_token_ids[i : i + self.seq_length]
                <span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(input_ids) == self.seq_length:
                    examples.append(input_ids)
            random.shuffle(examples)
            <span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> examples:
                self.current_size += <span class="hljs-number">1</span>
                <span class="hljs-keyword">yield</span> {
                    <span class="hljs-string">&quot;input_ids&quot;</span>: torch.LongTensor(example),
                    <span class="hljs-string">&quot;labels&quot;</span>: torch.LongTensor(example),
                }


train_dataset = ConstantLengthDataset(
        tokenizer,
        train_data,
        infinite=<span class="hljs-literal">True</span>,
        seq_length=SEQ_LENGTH,
        chars_per_token=chars_per_token,
        content_field=DATA_COLUMN,
        fim_rate=FIM_RATE,
        fim_spm_rate=FIM_SPM_RATE,
        seed=SEED,
)
eval_dataset = ConstantLengthDataset(
        tokenizer,
        valid_data,
        infinite=<span class="hljs-literal">False</span>,
        seq_length=SEQ_LENGTH,
        chars_per_token=chars_per_token,
        content_field=DATA_COLUMN,
        fim_rate=FIM_RATE,
        fim_spm_rate=FIM_SPM_RATE,
        seed=SEED,
)`,wrap:!1}}),q=new gl({props:{title:"Prepare the model",local:"prepare-the-model",headingTag:"h2"}}),el=new o({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBMb3JhQ29uZmlnJTJDJTIwZ2V0X3BlZnRfbW9kZWwlMkMlMjBwcmVwYXJlX21vZGVsX2Zvcl9rYml0X3RyYWluaW5nJTBBZnJvbSUyMHBlZnQudHVuZXJzLmxvcmElMjBpbXBvcnQlMjBMb3JhTGF5ZXIlMEElMEFsb2FkX2luXzhiaXQlMjAlM0QlMjBGYWxzZSUwQSUwQSUyMyUyMDQtYml0JTIwcXVhbnRpemF0aW9uJTBBY29tcHV0ZV9kdHlwZSUyMCUzRCUyMGdldGF0dHIodG9yY2glMkMlMjBCTkJfNEJJVF9DT01QVVRFX0RUWVBFKSUwQSUwQWJuYl9jb25maWclMjAlM0QlMjBCaXRzQW5kQnl0ZXNDb25maWcoJTBBJTIwJTIwJTIwJTIwbG9hZF9pbl80Yml0JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGJuYl80Yml0X3F1YW50X3R5cGUlM0QlMjJuZjQlMjIlMkMlMEElMjAlMjAlMjAlMjBibmJfNGJpdF9jb21wdXRlX2R0eXBlJTNEY29tcHV0ZV9kdHlwZSUyQyUwQSUyMCUyMCUyMCUyMGJuYl80Yml0X3VzZV9kb3VibGVfcXVhbnQlM0RVU0VfTkVTVEVEX1FVQU5UJTJDJTBBKSUwQSUwQWRldmljZV9tYXAlMjAlM0QlMjAlN0IlMjIlMjIlM0ElMjAwJTdEJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwTU9ERUwlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb2FkX2luXzhiaXQlM0Rsb2FkX2luXzhiaXQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBxdWFudGl6YXRpb25fY29uZmlnJTNEYm5iX2NvbmZpZyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGRldmljZV9tYXAlM0RkZXZpY2VfbWFwJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdXNlX2NhY2hlJTNERmFsc2UlMkMlMjAlMjAlMjMlMjBXZSUyMHdpbGwlMjBiZSUyMHVzaW5nJTIwZ3JhZGllbnQlMjBjaGVja3BvaW50aW5nJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdHJ1c3RfcmVtb3RlX2NvZGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdXNlX2ZsYXNoX2F0dGVudGlvbl8yJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> LoraConfig, get_peft_model, prepare_model_for_kbit_training
<span class="hljs-keyword">from</span> peft.tuners.lora <span class="hljs-keyword">import</span> LoraLayer

load_in_8bit = <span class="hljs-literal">False</span>

<span class="hljs-comment"># 4-bit quantization</span>
compute_dtype = <span class="hljs-built_in">getattr</span>(torch, BNB_4BIT_COMPUTE_DTYPE)

bnb_config = BitsAndBytesConfig(
    load_in_4bit=<span class="hljs-literal">True</span>,
    bnb_4bit_quant_type=<span class="hljs-string">&quot;nf4&quot;</span>,
    bnb_4bit_compute_dtype=compute_dtype,
    bnb_4bit_use_double_quant=USE_NESTED_QUANT,
)

device_map = {<span class="hljs-string">&quot;&quot;</span>: <span class="hljs-number">0</span>}

model = AutoModelForCausalLM.from_pretrained(
        MODEL,
        load_in_8bit=load_in_8bit,
        quantization_config=bnb_config,
        device_map=device_map,
        use_cache=<span class="hljs-literal">False</span>,  <span class="hljs-comment"># We will be using gradient checkpointing</span>
        trust_remote_code=<span class="hljs-literal">True</span>,
        use_flash_attention_2=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),sl=new o({props:{code:"bW9kZWwlMjAlM0QlMjBwcmVwYXJlX21vZGVsX2Zvcl9rYml0X3RyYWluaW5nKG1vZGVsKQ==",highlighted:"model = prepare_model_for_kbit_training(model)",wrap:!1}}),Ul=new o({props:{code:"JTIzJTIwU2V0JTIwdXAlMjBsb3JhJTBBcGVmdF9jb25maWclMjAlM0QlMjBMb3JhQ29uZmlnKCUwQSUyMCUyMCUyMCUyMGxvcmFfYWxwaGElM0RMT1JBX0FMUEhBJTJDJTBBJTIwJTIwJTIwJTIwbG9yYV9kcm9wb3V0JTNETE9SQV9EUk9QT1VUJTJDJTBBJTIwJTIwJTIwJTIwciUzRExPUkFfUiUyQyUwQSUyMCUyMCUyMCUyMGJpYXMlM0QlMjJub25lJTIyJTJDJTBBJTIwJTIwJTIwJTIwdGFza190eXBlJTNEJTIyQ0FVU0FMX0xNJTIyJTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X21vZHVsZXMlM0RMT1JBX1RBUkdFVF9NT0RVTEVTLnNwbGl0KCUyMiUyQyUyMiklMkMlMEEpJTBBJTBBbW9kZWwlMjAlM0QlMjBnZXRfcGVmdF9tb2RlbChtb2RlbCUyQyUyMHBlZnRfY29uZmlnKSUwQW1vZGVsLnByaW50X3RyYWluYWJsZV9wYXJhbWV0ZXJzKCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Set up lora</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>peft_config = LoraConfig(
<span class="hljs-meta">... </span>    lora_alpha=LORA_ALPHA,
<span class="hljs-meta">... </span>    lora_dropout=LORA_DROPOUT,
<span class="hljs-meta">... </span>    r=LORA_R,
<span class="hljs-meta">... </span>    bias=<span class="hljs-string">&quot;none&quot;</span>,
<span class="hljs-meta">... </span>    task_type=<span class="hljs-string">&quot;CAUSAL_LM&quot;</span>,
<span class="hljs-meta">... </span>    target_modules=LORA_TARGET_MODULES.split(<span class="hljs-string">&quot;,&quot;</span>),
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = get_peft_model(model, peft_config)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.print_trainable_parameters()`,wrap:!1}}),jl=new gl({props:{title:"Train the model",local:"train-the-model",headingTag:"h2"}}),ol=new o({props:{code:"dHJhaW5fZGF0YS5zdGFydF9pdGVyYXRpb24lMjAlM0QlMjAwJTBBJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RmJTIyWW91cl9IRl91c2VybmFtZSUyRiU3Qk9VVFBVVF9ESVIlN0QlMjIlMkMlMEElMjAlMjAlMjAlMjBkYXRhbG9hZGVyX2Ryb3BfbGFzdCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBldmFsdWF0aW9uX3N0cmF0ZWd5JTNEJTIyc3RlcHMlMjIlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0cmF0ZWd5JTNEJTIyc3RlcHMlMjIlMkMlMEElMjAlMjAlMjAlMjBtYXhfc3RlcHMlM0RNQVhfU1RFUFMlMkMlMEElMjAlMjAlMjAlMjBldmFsX3N0ZXBzJTNERVZBTF9GUkVRJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV9zdGVwcyUzRFNBVkVfRlJFUSUyQyUwQSUyMCUyMCUyMCUyMGxvZ2dpbmdfc3RlcHMlM0RMT0dfRlJFUSUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzREJBVENIX1NJWkUlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX2V2YWxfYmF0Y2hfc2l6ZSUzREJBVENIX1NJWkUlMkMlMEElMjAlMjAlMjAlMjBsZWFybmluZ19yYXRlJTNETFIlMkMlMEElMjAlMjAlMjAlMjBscl9zY2hlZHVsZXJfdHlwZSUzRExSX1NDSEVEVUxFUl9UWVBFJTJDJTBBJTIwJTIwJTIwJTIwd2FybXVwX3N0ZXBzJTNETlVNX1dBUk1VUF9TVEVQUyUyQyUwQSUyMCUyMCUyMCUyMGdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzREdSX0FDQ19TVEVQUyUyQyUwQSUyMCUyMCUyMCUyMGdyYWRpZW50X2NoZWNrcG9pbnRpbmclM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwZnAxNiUzREZQMTYlMkMlMEElMjAlMjAlMjAlMjBiZjE2JTNEQkYxNiUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheSUzRFdFSUdIVF9ERUNBWSUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGluY2x1ZGVfdG9rZW5zX3Blcl9zZWNvbmQlM0RUcnVlJTJDJTBBKQ==",highlighted:`train_data.start_iteration = <span class="hljs-number">0</span>


training_args = TrainingArguments(
    output_dir=<span class="hljs-string">f&quot;Your_HF_username/<span class="hljs-subst">{OUTPUT_DIR}</span>&quot;</span>,
    dataloader_drop_last=<span class="hljs-literal">True</span>,
    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    save_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
    max_steps=MAX_STEPS,
    eval_steps=EVAL_FREQ,
    save_steps=SAVE_FREQ,
    logging_steps=LOG_FREQ,
    per_device_train_batch_size=BATCH_SIZE,
    per_device_eval_batch_size=BATCH_SIZE,
    learning_rate=LR,
    lr_scheduler_type=LR_SCHEDULER_TYPE,
    warmup_steps=NUM_WARMUP_STEPS,
    gradient_accumulation_steps=GR_ACC_STEPS,
    gradient_checkpointing=<span class="hljs-literal">True</span>,
    fp16=FP16,
    bf16=BF16,
    weight_decay=WEIGHT_DECAY,
    push_to_hub=<span class="hljs-literal">True</span>,
    include_tokens_per_second=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),Il=new o({props:{code:"dHJhaW5lciUyMCUzRCUyMFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTIwdHJhaW5fZGF0YXNldCUzRHRyYWluX2RhdGFzZXQlMkMlMjBldmFsX2RhdGFzZXQlM0RldmFsX2RhdGFzZXQlMEEpJTBBJTBBcHJpbnQoJTIyVHJhaW5pbmcuLi4lMjIpJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Trainer(
<span class="hljs-meta">... </span>    model=model, args=training_args, train_dataset=train_dataset, eval_dataset=eval_dataset
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Training...&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`,wrap:!1}}),dl=new o({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:"trainer.push_to_hub()",wrap:!1}}),cl=new gl({props:{title:"Inference",local:"inference",headingTag:"h2"}}),hl=new o({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBQZWZ0TW9kZWwlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQSUyMyUyMGxvYWQlMjB0aGUlMjBvcmlnaW5hbCUyMG1vZGVsJTIwZmlyc3QlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChNT0RFTCUyQyUyMHRydXN0X3JlbW90ZV9jb2RlJTNEVHJ1ZSklMEFiYXNlX21vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyME1PREVMJTJDJTBBJTIwJTIwJTIwJTIwcXVhbnRpemF0aW9uX2NvbmZpZyUzRE5vbmUlMkMlMEElMjAlMjAlMjAlMjBkZXZpY2VfbWFwJTNETm9uZSUyQyUwQSUyMCUyMCUyMCUyMHRydXN0X3JlbW90ZV9jb2RlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHRvcmNoX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMEEpLmN1ZGEoKSUwQSUwQSUyMyUyMG1lcmdlJTIwZmluZS10dW5lZCUyMHdlaWdodHMlMjB3aXRoJTIwdGhlJTIwYmFzZSUyMG1vZGVsJTBBcGVmdF9tb2RlbF9pZCUyMCUzRCUyMGYlMjJZb3VyX0hGX3VzZXJuYW1lJTJGJTdCT1VUUFVUX0RJUiU3RCUyMiUwQW1vZGVsJTIwJTNEJTIwUGVmdE1vZGVsLmZyb21fcHJldHJhaW5lZChiYXNlX21vZGVsJTJDJTIwcGVmdF9tb2RlbF9pZCklMEFtb2RlbC5tZXJnZV9hbmRfdW5sb2FkKCk=",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PeftModel
<span class="hljs-keyword">import</span> torch

<span class="hljs-comment"># load the original model first</span>
tokenizer = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=<span class="hljs-literal">True</span>)
base_model = AutoModelForCausalLM.from_pretrained(
    MODEL,
    quantization_config=<span class="hljs-literal">None</span>,
    device_map=<span class="hljs-literal">None</span>,
    trust_remote_code=<span class="hljs-literal">True</span>,
    torch_dtype=torch.bfloat16,
).cuda()

<span class="hljs-comment"># merge fine-tuned weights with the base model</span>
peft_model_id = <span class="hljs-string">f&quot;Your_HF_username/<span class="hljs-subst">{OUTPUT_DIR}</span>&quot;</span>
model = PeftModel.from_pretrained(base_model, peft_model_id)
model.merge_and_unload()`,wrap:!1}}),fl=new o({props:{code:"ZGVmJTIwZ2V0X2NvZGVfY29tcGxldGlvbihwcmVmaXglMkMlMjBzdWZmaXgpJTNBJTBBJTIwJTIwJTIwJTIwdGV4dCUyMCUzRCUyMHByb21wdCUyMCUzRCUyMGYlMjIlMjIlMjIlM0NmaW1fcHJlZml4JTNFJTdCcHJlZml4JTdEJTNDZmltX3N1ZmZpeCUzRSU3QnN1ZmZpeCU3RCUzQ2ZpbV9taWRkbGUlM0UlMjIlMjIlMjIlMEElMjAlMjAlMjAlMjBtb2RlbC5ldmFsKCklMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRfaWRzJTNEdG9rZW5pemVyKHRleHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS5pbnB1dF9pZHMuY3VkYSgpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWF4X25ld190b2tlbnMlM0QxMjglMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0ZW1wZXJhdHVyZSUzRDAuMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHRvcF9rJTNENTAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0b3BfcCUzRDAuOTUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkb19zYW1wbGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmVwZXRpdGlvbl9wZW5hbHR5JTNEMS4wJTJDJTBBJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQ=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_code_completion</span>(<span class="hljs-params">prefix, suffix</span>):
    text = prompt = <span class="hljs-string">f&quot;&quot;&quot;&lt;fim_prefix&gt;<span class="hljs-subst">{prefix}</span>&lt;fim_suffix&gt;<span class="hljs-subst">{suffix}</span>&lt;fim_middle&gt;&quot;&quot;&quot;</span>
    model.<span class="hljs-built_in">eval</span>()
    outputs = model.generate(
        input_ids=tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids.cuda(),
        max_new_tokens=<span class="hljs-number">128</span>,
        temperature=<span class="hljs-number">0.2</span>,
        top_k=<span class="hljs-number">50</span>,
        top_p=<span class="hljs-number">0.95</span>,
        do_sample=<span class="hljs-literal">True</span>,
        repetition_penalty=<span class="hljs-number">1.0</span>,
    )
    <span class="hljs-keyword">return</span> tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]`,wrap:!1}}),Zl=new o({props:{code:"cHJlZml4JTIwJTNEJTIwJTIyJTIyJTIyZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBMb3JhQ29uZmlnJTJDJTIwVGFza1R5cGUlMkMlMjBnZXRfcGVmdF9tb2RlbCUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQXBlZnRfY29uZmlnJTIwJTNEJTIwTG9yYUNvbmZpZyglMEElMjIlMjIlMjIlMEFzdWZmaXglMjAlM0QlMjIlMjIlMjIlMjIlMjIlMjIlMEElMEFwcmludChnZXRfY29kZV9jb21wbGV0aW9uKHByZWZpeCUyQyUyMHN1ZmZpeCkp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>prefix = <span class="hljs-string">&quot;&quot;&quot;from peft import LoraConfig, TaskType, get_peft_model
<span class="hljs-meta">... </span>from transformers import AutoModelForCausalLM
<span class="hljs-meta">... </span>peft_config = LoraConfig(
<span class="hljs-meta">... </span>&quot;&quot;&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>suffix =<span class="hljs-string">&quot;&quot;&quot;&quot;&quot;&quot;</span>

<span class="hljs-meta">... </span><span class="hljs-built_in">print</span>(get_code_completion(prefix, suffix))`,wrap:!1}}),Rl=new o({props:{code:"cHJlZml4JTIwJTNEJTIwJTIyJTIyJTIyZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBMb3JhQ29uZmlnJTJDJTIwVGFza1R5cGUlMkMlMjBnZXRfcGVmdF9tb2RlbCUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQXBlZnRfY29uZmlnJTIwJTNEJTIwTG9yYUNvbmZpZyglMEElMjIlMjIlMjIlMEFzdWZmaXglMjAlM0QlMjIlMjIlMjIlMjIlMjIlMjIlMEElMEFwcmludChnZXRfY29kZV9jb21wbGV0aW9uKHByZWZpeCUyQyUyMHN1ZmZpeCkp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>prefix = <span class="hljs-string">&quot;&quot;&quot;from peft import LoraConfig, TaskType, get_peft_model
<span class="hljs-meta">... </span>from transformers import AutoModelForCausalLM
<span class="hljs-meta">... </span>peft_config = LoraConfig(
<span class="hljs-meta">... </span>&quot;&quot;&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>suffix =<span class="hljs-string">&quot;&quot;&quot;&quot;&quot;&quot;</span>

<span class="hljs-meta">... </span><span class="hljs-built_in">print</span>(get_code_completion(prefix, suffix))`,wrap:!1}}),Vl=new Tt({props:{source:"https://github.com/huggingface/cookbook/blob/main/notebooks/en/fine_tuning_code_llm_on_single_gpu.md"}}),{c(){C=n("meta"),Wl=s(),Ql=n("p"),Sl=s(),J(I.$$.fragment),Nl=s(),J(m.$$.fragment),Yl=s(),J(r.$$.fragment),vl=s(),d=n("p"),d.innerHTML=Ue,xl=s(),c=n("p"),c.textContent=Je,Hl=s(),A=n("p"),A.textContent=Te,zl=s(),J(h.$$.fragment),$l=s(),u=n("p"),u.innerHTML=je,Ll=s(),J(f.$$.fragment),ql=s(),b=n("p"),b.innerHTML=pe,Dl=s(),J(Z.$$.fragment),Pl=s(),B=n("p"),B.innerHTML=we,Kl=s(),_=n("p"),_.textContent=ie,Ol=s(),J(G.$$.fragment),lM=s(),R=n("p"),R.textContent=oe,MM=s(),J(E.$$.fragment),eM=s(),J(k.$$.fragment),tM=s(),J(X.$$.fragment),sM=s(),V=n("p"),V.textContent=Ce,aM=s(),g=n("p"),g.textContent=Ie,nM=s(),J(Q.$$.fragment),yM=s(),F=n("p"),F.textContent=me,UM=s(),W=n("p"),W.innerHTML=re,JM=s(),J(S.$$.fragment),TM=s(),N=n("pre"),N.textContent=de,jM=s(),Y=n("p"),Y.textContent=ce,pM=s(),v=n("p"),v.innerHTML=Ae,wM=s(),x=n("p"),x.innerHTML=he,iM=s(),J(H.$$.fragment),oM=s(),z=n("p"),z.innerHTML=ue,CM=s(),$=n("p"),$.innerHTML=fe,IM=s(),J(L.$$.fragment),mM=s(),J(q.$$.fragment),rM=s(),D=n("p"),D.textContent=be,dM=s(),P=n("p"),P.innerHTML=Ze,cM=s(),K=n("p"),K.innerHTML=Be,AM=s(),O=n("p"),O.innerHTML=_e,hM=s(),ll=n("p"),ll.innerHTML=Ge,uM=s(),Ml=n("p"),Ml.innerHTML=Re,fM=s(),J(el.$$.fragment),bM=s(),tl=n("p"),tl.innerHTML=Ee,ZM=s(),J(sl.$$.fragment),BM=s(),al=n("p"),al.textContent=ke,_M=s(),nl=n("p"),nl.innerHTML=Xe,GM=s(),yl=n("p"),yl.innerHTML=Ve,RM=s(),J(Ul.$$.fragment),EM=s(),Jl=n("pre"),Jl.textContent=ge,kM=s(),Tl=n("p"),Tl.textContent=Qe,XM=s(),J(jl.$$.fragment),VM=s(),pl=n("p"),pl.textContent=Fe,gM=s(),wl=n("p"),wl.innerHTML=We,QM=s(),il=n("p"),il.textContent=Se,FM=s(),J(ol.$$.fragment),WM=s(),Cl=n("p"),Cl.innerHTML=Ne,SM=s(),J(Il.$$.fragment),NM=s(),ml=n("pre"),ml.textContent=Ye,YM=s(),rl=n("p"),rl.textContent=ve,vM=s(),J(dl.$$.fragment),xM=s(),J(cl.$$.fragment),HM=s(),Al=n("p"),Al.textContent=xe,zM=s(),J(hl.$$.fragment),$M=s(),ul=n("p"),ul.innerHTML=He,LM=s(),J(fl.$$.fragment),qM=s(),bl=n("p"),bl.innerHTML=ze,DM=s(),J(Zl.$$.fragment),PM=s(),Bl=n("pre"),Bl.textContent=$e,KM=s(),_l=n("p"),_l.innerHTML=Le,OM=s(),Gl=n("p"),Gl.textContent=qe,le=s(),J(Rl.$$.fragment),Me=s(),El=n("pre"),El.textContent=De,ee=s(),kl=n("p"),kl.innerHTML=Pe,te=s(),Xl=n("p"),Xl.innerHTML=Ke,se=s(),J(Vl.$$.fragment),ae=s(),Fl=n("p"),this.h()},l(l){const M=nt("svelte-u9bgzb",document.head);C=y(M,"META",{name:!0,content:!0}),M.forEach(e),Wl=a(l),Ql=y(l,"P",{}),Oe(Ql).forEach(e),Sl=a(l),T(I.$$.fragment,l),Nl=a(l),T(m.$$.fragment,l),Yl=a(l),T(r.$$.fragment,l),vl=a(l),d=y(l,"P",{"data-svelte-h":!0}),U(d)!=="svelte-26mfp8"&&(d.innerHTML=Ue),xl=a(l),c=y(l,"P",{"data-svelte-h":!0}),U(c)!=="svelte-1jkdfbx"&&(c.textContent=Je),Hl=a(l),A=y(l,"P",{"data-svelte-h":!0}),U(A)!=="svelte-twmb21"&&(A.textContent=Te),zl=a(l),T(h.$$.fragment,l),$l=a(l),u=y(l,"P",{"data-svelte-h":!0}),U(u)!=="svelte-lcmz04"&&(u.innerHTML=je),Ll=a(l),T(f.$$.fragment,l),ql=a(l),b=y(l,"P",{"data-svelte-h":!0}),U(b)!=="svelte-1wkzu9g"&&(b.innerHTML=pe),Dl=a(l),T(Z.$$.fragment,l),Pl=a(l),B=y(l,"P",{"data-svelte-h":!0}),U(B)!=="svelte-pqckta"&&(B.innerHTML=we),Kl=a(l),_=y(l,"P",{"data-svelte-h":!0}),U(_)!=="svelte-1bfizik"&&(_.textContent=ie),Ol=a(l),T(G.$$.fragment,l),lM=a(l),R=y(l,"P",{"data-svelte-h":!0}),U(R)!=="svelte-1n5u6bj"&&(R.textContent=oe),MM=a(l),T(E.$$.fragment,l),eM=a(l),T(k.$$.fragment,l),tM=a(l),T(X.$$.fragment,l),sM=a(l),V=y(l,"P",{"data-svelte-h":!0}),U(V)!=="svelte-p22occ"&&(V.textContent=Ce),aM=a(l),g=y(l,"P",{"data-svelte-h":!0}),U(g)!=="svelte-nud4q8"&&(g.textContent=Ie),nM=a(l),T(Q.$$.fragment,l),yM=a(l),F=y(l,"P",{"data-svelte-h":!0}),U(F)!=="svelte-169rcmc"&&(F.textContent=me),UM=a(l),W=y(l,"P",{"data-svelte-h":!0}),U(W)!=="svelte-1n3y7wl"&&(W.innerHTML=re),JM=a(l),T(S.$$.fragment,l),TM=a(l),N=y(l,"PRE",{"data-svelte-h":!0}),U(N)!=="svelte-ko6dme"&&(N.textContent=de),jM=a(l),Y=y(l,"P",{"data-svelte-h":!0}),U(Y)!=="svelte-4527xa"&&(Y.textContent=ce),pM=a(l),v=y(l,"P",{"data-svelte-h":!0}),U(v)!=="svelte-1lk8r3"&&(v.innerHTML=Ae),wM=a(l),x=y(l,"P",{"data-svelte-h":!0}),U(x)!=="svelte-1l3szds"&&(x.innerHTML=he),iM=a(l),T(H.$$.fragment,l),oM=a(l),z=y(l,"P",{"data-svelte-h":!0}),U(z)!=="svelte-2233ic"&&(z.innerHTML=ue),CM=a(l),$=y(l,"P",{"data-svelte-h":!0}),U($)!=="svelte-155t8oo"&&($.innerHTML=fe),IM=a(l),T(L.$$.fragment,l),mM=a(l),T(q.$$.fragment,l),rM=a(l),D=y(l,"P",{"data-svelte-h":!0}),U(D)!=="svelte-9bd9cz"&&(D.textContent=be),dM=a(l),P=y(l,"P",{"data-svelte-h":!0}),U(P)!=="svelte-1uhrhyi"&&(P.innerHTML=Ze),cM=a(l),K=y(l,"P",{"data-svelte-h":!0}),U(K)!=="svelte-2m06yu"&&(K.innerHTML=Be),AM=a(l),O=y(l,"P",{"data-svelte-h":!0}),U(O)!=="svelte-lrsdq"&&(O.innerHTML=_e),hM=a(l),ll=y(l,"P",{"data-svelte-h":!0}),U(ll)!=="svelte-1s6fz64"&&(ll.innerHTML=Ge),uM=a(l),Ml=y(l,"P",{"data-svelte-h":!0}),U(Ml)!=="svelte-1uji32v"&&(Ml.innerHTML=Re),fM=a(l),T(el.$$.fragment,l),bM=a(l),tl=y(l,"P",{"data-svelte-h":!0}),U(tl)!=="svelte-1h52q0h"&&(tl.innerHTML=Ee),ZM=a(l),T(sl.$$.fragment,l),BM=a(l),al=y(l,"P",{"data-svelte-h":!0}),U(al)!=="svelte-1oeq64f"&&(al.textContent=ke),_M=a(l),nl=y(l,"P",{"data-svelte-h":!0}),U(nl)!=="svelte-6kkm2s"&&(nl.innerHTML=Xe),GM=a(l),yl=y(l,"P",{"data-svelte-h":!0}),U(yl)!=="svelte-1tuhj0w"&&(yl.innerHTML=Ve),RM=a(l),T(Ul.$$.fragment,l),EM=a(l),Jl=y(l,"PRE",{"data-svelte-h":!0}),U(Jl)!=="svelte-hpf32x"&&(Jl.textContent=ge),kM=a(l),Tl=y(l,"P",{"data-svelte-h":!0}),U(Tl)!=="svelte-g92wi0"&&(Tl.textContent=Qe),XM=a(l),T(jl.$$.fragment,l),VM=a(l),pl=y(l,"P",{"data-svelte-h":!0}),U(pl)!=="svelte-nh2kp6"&&(pl.textContent=Fe),gM=a(l),wl=y(l,"P",{"data-svelte-h":!0}),U(wl)!=="svelte-rhwpb7"&&(wl.innerHTML=We),QM=a(l),il=y(l,"P",{"data-svelte-h":!0}),U(il)!=="svelte-6zfky8"&&(il.textContent=Se),FM=a(l),T(ol.$$.fragment,l),WM=a(l),Cl=y(l,"P",{"data-svelte-h":!0}),U(Cl)!=="svelte-1yquuuu"&&(Cl.innerHTML=Ne),SM=a(l),T(Il.$$.fragment,l),NM=a(l),ml=y(l,"PRE",{"data-svelte-h":!0}),U(ml)!=="svelte-9xzew6"&&(ml.textContent=Ye),YM=a(l),rl=y(l,"P",{"data-svelte-h":!0}),U(rl)!=="svelte-p9ps3w"&&(rl.textContent=ve),vM=a(l),T(dl.$$.fragment,l),xM=a(l),T(cl.$$.fragment,l),HM=a(l),Al=y(l,"P",{"data-svelte-h":!0}),U(Al)!=="svelte-lw3peh"&&(Al.textContent=xe),zM=a(l),T(hl.$$.fragment,l),$M=a(l),ul=y(l,"P",{"data-svelte-h":!0}),U(ul)!=="svelte-1xk304l"&&(ul.innerHTML=He),LM=a(l),T(fl.$$.fragment,l),qM=a(l),bl=y(l,"P",{"data-svelte-h":!0}),U(bl)!=="svelte-1nsj0eg"&&(bl.innerHTML=ze),DM=a(l),T(Zl.$$.fragment,l),PM=a(l),Bl=y(l,"PRE",{"data-svelte-h":!0}),U(Bl)!=="svelte-11ixuz2"&&(Bl.textContent=$e),KM=a(l),_l=y(l,"P",{"data-svelte-h":!0}),U(_l)!=="svelte-tkz9oe"&&(_l.innerHTML=Le),OM=a(l),Gl=y(l,"P",{"data-svelte-h":!0}),U(Gl)!=="svelte-1wna85g"&&(Gl.textContent=qe),le=a(l),T(Rl.$$.fragment,l),Me=a(l),El=y(l,"PRE",{"data-svelte-h":!0}),U(El)!=="svelte-1ud779o"&&(El.textContent=De),ee=a(l),kl=y(l,"P",{"data-svelte-h":!0}),U(kl)!=="svelte-1dhv5aw"&&(kl.innerHTML=Pe),te=a(l),Xl=y(l,"P",{"data-svelte-h":!0}),U(Xl)!=="svelte-zjkw3y"&&(Xl.innerHTML=Ke),se=a(l),T(Vl.$$.fragment,l),ae=a(l),Fl=y(l,"P",{}),Oe(Fl).forEach(e),this.h()},h(){lt(C,"name","hf:doc:metadata"),lt(C,"content",pt)},m(l,M){yt(document.head,C),t(l,Wl,M),t(l,Ql,M),t(l,Sl,M),j(I,l,M),t(l,Nl,M),j(m,l,M),t(l,Yl,M),j(r,l,M),t(l,vl,M),t(l,d,M),t(l,xl,M),t(l,c,M),t(l,Hl,M),t(l,A,M),t(l,zl,M),j(h,l,M),t(l,$l,M),t(l,u,M),t(l,Ll,M),j(f,l,M),t(l,ql,M),t(l,b,M),t(l,Dl,M),j(Z,l,M),t(l,Pl,M),t(l,B,M),t(l,Kl,M),t(l,_,M),t(l,Ol,M),j(G,l,M),t(l,lM,M),t(l,R,M),t(l,MM,M),j(E,l,M),t(l,eM,M),j(k,l,M),t(l,tM,M),j(X,l,M),t(l,sM,M),t(l,V,M),t(l,aM,M),t(l,g,M),t(l,nM,M),j(Q,l,M),t(l,yM,M),t(l,F,M),t(l,UM,M),t(l,W,M),t(l,JM,M),j(S,l,M),t(l,TM,M),t(l,N,M),t(l,jM,M),t(l,Y,M),t(l,pM,M),t(l,v,M),t(l,wM,M),t(l,x,M),t(l,iM,M),j(H,l,M),t(l,oM,M),t(l,z,M),t(l,CM,M),t(l,$,M),t(l,IM,M),j(L,l,M),t(l,mM,M),j(q,l,M),t(l,rM,M),t(l,D,M),t(l,dM,M),t(l,P,M),t(l,cM,M),t(l,K,M),t(l,AM,M),t(l,O,M),t(l,hM,M),t(l,ll,M),t(l,uM,M),t(l,Ml,M),t(l,fM,M),j(el,l,M),t(l,bM,M),t(l,tl,M),t(l,ZM,M),j(sl,l,M),t(l,BM,M),t(l,al,M),t(l,_M,M),t(l,nl,M),t(l,GM,M),t(l,yl,M),t(l,RM,M),j(Ul,l,M),t(l,EM,M),t(l,Jl,M),t(l,kM,M),t(l,Tl,M),t(l,XM,M),j(jl,l,M),t(l,VM,M),t(l,pl,M),t(l,gM,M),t(l,wl,M),t(l,QM,M),t(l,il,M),t(l,FM,M),j(ol,l,M),t(l,WM,M),t(l,Cl,M),t(l,SM,M),j(Il,l,M),t(l,NM,M),t(l,ml,M),t(l,YM,M),t(l,rl,M),t(l,vM,M),j(dl,l,M),t(l,xM,M),j(cl,l,M),t(l,HM,M),t(l,Al,M),t(l,zM,M),j(hl,l,M),t(l,$M,M),t(l,ul,M),t(l,LM,M),j(fl,l,M),t(l,qM,M),t(l,bl,M),t(l,DM,M),j(Zl,l,M),t(l,PM,M),t(l,Bl,M),t(l,KM,M),t(l,_l,M),t(l,OM,M),t(l,Gl,M),t(l,le,M),j(Rl,l,M),t(l,Me,M),t(l,El,M),t(l,ee,M),t(l,kl,M),t(l,te,M),t(l,Xl,M),t(l,se,M),j(Vl,l,M),t(l,ae,M),t(l,Fl,M),ne=!0},p:et,i(l){ne||(p(I.$$.fragment,l),p(m.$$.fragment,l),p(r.$$.fragment,l),p(h.$$.fragment,l),p(f.$$.fragment,l),p(Z.$$.fragment,l),p(G.$$.fragment,l),p(E.$$.fragment,l),p(k.$$.fragment,l),p(X.$$.fragment,l),p(Q.$$.fragment,l),p(S.$$.fragment,l),p(H.$$.fragment,l),p(L.$$.fragment,l),p(q.$$.fragment,l),p(el.$$.fragment,l),p(sl.$$.fragment,l),p(Ul.$$.fragment,l),p(jl.$$.fragment,l),p(ol.$$.fragment,l),p(Il.$$.fragment,l),p(dl.$$.fragment,l),p(cl.$$.fragment,l),p(hl.$$.fragment,l),p(fl.$$.fragment,l),p(Zl.$$.fragment,l),p(Rl.$$.fragment,l),p(Vl.$$.fragment,l),ne=!0)},o(l){w(I.$$.fragment,l),w(m.$$.fragment,l),w(r.$$.fragment,l),w(h.$$.fragment,l),w(f.$$.fragment,l),w(Z.$$.fragment,l),w(G.$$.fragment,l),w(E.$$.fragment,l),w(k.$$.fragment,l),w(X.$$.fragment,l),w(Q.$$.fragment,l),w(S.$$.fragment,l),w(H.$$.fragment,l),w(L.$$.fragment,l),w(q.$$.fragment,l),w(el.$$.fragment,l),w(sl.$$.fragment,l),w(Ul.$$.fragment,l),w(jl.$$.fragment,l),w(ol.$$.fragment,l),w(Il.$$.fragment,l),w(dl.$$.fragment,l),w(cl.$$.fragment,l),w(hl.$$.fragment,l),w(fl.$$.fragment,l),w(Zl.$$.fragment,l),w(Rl.$$.fragment,l),w(Vl.$$.fragment,l),ne=!1},d(l){l&&(e(Wl),e(Ql),e(Sl),e(Nl),e(Yl),e(vl),e(d),e(xl),e(c),e(Hl),e(A),e(zl),e($l),e(u),e(Ll),e(ql),e(b),e(Dl),e(Pl),e(B),e(Kl),e(_),e(Ol),e(lM),e(R),e(MM),e(eM),e(tM),e(sM),e(V),e(aM),e(g),e(nM),e(yM),e(F),e(UM),e(W),e(JM),e(TM),e(N),e(jM),e(Y),e(pM),e(v),e(wM),e(x),e(iM),e(oM),e(z),e(CM),e($),e(IM),e(mM),e(rM),e(D),e(dM),e(P),e(cM),e(K),e(AM),e(O),e(hM),e(ll),e(uM),e(Ml),e(fM),e(bM),e(tl),e(ZM),e(BM),e(al),e(_M),e(nl),e(GM),e(yl),e(RM),e(EM),e(Jl),e(kM),e(Tl),e(XM),e(VM),e(pl),e(gM),e(wl),e(QM),e(il),e(FM),e(WM),e(Cl),e(SM),e(NM),e(ml),e(YM),e(rl),e(vM),e(xM),e(HM),e(Al),e(zM),e($M),e(ul),e(LM),e(qM),e(bl),e(DM),e(PM),e(Bl),e(KM),e(_l),e(OM),e(Gl),e(le),e(Me),e(El),e(ee),e(kl),e(te),e(Xl),e(se),e(ae),e(Fl)),e(C),i(I,l),i(m,l),i(r,l),i(h,l),i(f,l),i(Z,l),i(G,l),i(E,l),i(k,l),i(X,l),i(Q,l),i(S,l),i(H,l),i(L,l),i(q,l),i(el,l),i(sl,l),i(Ul,l),i(jl,l),i(ol,l),i(Il,l),i(dl,l),i(cl,l),i(hl,l),i(fl,l),i(Zl,l),i(Rl,l),i(Vl,l)}}}const pt='{"title":"Fine-tuning a Code LLM on Custom Code on a single GPU","local":"fine-tuning-a-code-llm-on-custom-code-on-a-single-gpu","sections":[{"title":"Dataset","local":"dataset","sections":[],"depth":2},{"title":"Model","local":"model","sections":[],"depth":2},{"title":"Prepare the data","local":"prepare-the-data","sections":[],"depth":2},{"title":"Prepare the model","local":"prepare-the-model","sections":[],"depth":2},{"title":"Train the model","local":"train-the-model","sections":[],"depth":2},{"title":"Inference","local":"inference","sections":[],"depth":2}],"depth":1}';function wt(ye){return tt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class rt extends st{constructor(C){super(),at(this,C,wt,jt,Mt,{})}}export{rt as component};
