Flo-Tuning Llama 3.2 3B commands the Python code: The perfect guide to enter

In this lesson, we will go to setup and edit well and plan well in the Llama teaching model 3.2 3B using Pataset for special Python code. At the end of this guide, you will be better aware that you can customize large languages with the active code of code and understanding activities needed to find the best plan.
To include the required leaning
!pip install "unsloth[colab-new] @ git+
!pip install "git+
!pip install -U trl
!pip install --no-deps trl peft accelerate bitsandbytes
!pip install torch torchvision torchaudio triton
!pip install xformers
!python -m xformers.info
!python -m bitsandbytes
These instructions include all the required libraries – such as unpleasant, variables, and XformMers – needed to organize the lllam 3.2 3b. Finally, we run by diagnosis instructions to ensure effective installation of xformers and bisandbytes.
Important Ingregation
from unsloth import FastLanguageModel
from trl import SFTTrainer
from transformers import TrainingArguments
import torch
from datasets import load_dataset
We import classes and functions from Ensloth, TRL, as well as models of model and good order. Also, we upload the Python code data with Hugging Face's `Load_Dataset` to prepare training samples.
Loading the Python code data
max_seq_length = 2048
dataset = load_dataset("user/Llama-3.2-Python-Alpaca-143k", split="train") #Save the dataset on your user profile on HF, then load the dataset on your user id
We put the tall length to 2048 tokens in a well-prepared model and upload the custom Python code from the face of face. Make sure you have data stored under your username to access appropriate access.
Starting Model Yelllama 3.2 3b
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "unsloth/Llama-3.2-3B-Instruct-bnb-4bit",
max_seq_length = max_seq_length,
dtype = None,
load_in_4bit = True
)
We upload the Llama teaching model 3.2 3B in 4-bit format using the invisible library, which reduces memory use. Managing text input for a long time, we also set the following lengths of the muttering in 2048.
Lora preparation with Unsloth
model = FastLanguageModel.get_peft_model(
model,
r = 16,
target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj",],
lora_alpha = 16,
lora_dropout = 0, # Supports any, but = 0 is optimized
bias = "none", # Supports any, but = "none" is optimized
# [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
random_state = 3407,
use_rslora = False, # We support rank stabilized LoRA
loftq_config = None, # And LoftQ
max_seq_length = max_seq_length
)
We Apply Lora (Low-Rank Adaptation) To Our 4-bit Loaded Model, Specify the Rank (R), Alpha (Lora_alpha), and Dropout settings. Wese_gradient_Checkpoint = “Unsloth” enables us to be used for well-efficient memory and allows the training of Moilded. Additional Lora Options such as use_slora and Louftq_config are available with developed scheduled strategies and is disabled here for easy. Finally, we put the best length of sequence to match our previous configuration.
Google Google Drive
from google.colab import drive
drive.mount("/content/drive")
We import Google Colab Drive module to access access to Google Drive from Colob Environment.
Setting and Using Loop Training Loop
trainer = SFTTrainer(
model = model,
train_dataset = dataset,
dataset_text_field = "text",
max_seq_length = max_seq_length,
tokenizer = tokenizer,
args = TrainingArguments(
per_device_train_batch_size = 2,
gradient_accumulation_steps = 4,
warmup_steps = 10,
# num_train_epochs = 1, # Set this for 1 full training run.
max_steps = 60,
learning_rate = 2e-4,
fp16 = not torch.cuda.is_bf16_supported(),
bf16 = torch.cuda.is_bf16_supported(),
logging_steps = 1,
optim = "adamw_8bit",
weight_decay = 0.01,
lr_scheduler_type = "linear",
seed = 3407,
output_dir = "/content/drive/My Drive/Llama-3.2-3B-Instruct-bnb-4bit"
),
)
trainer.train()
We create an example of a sfftraer with our model, Tokenzer, and Python Code Dataset, which describes the training field. Traininggargs describes key hyperpameters as a batch size, learning rating, high training steps, hardware such as FP16 or BF16. In this example, we put the output directory from Google Drive to save Checkpoints and logs. Finally, we urge the method of training.Train () to start a good order process.
Keeps a well-prepared model
model.save_pretrained("lora_model") # Local saving
tokenizer.save_pretrained("lora_model")
We keep the Lora trained model and its Tokenzer in a local area folder is Lora_model. This allows you to upload and use a well-prepared model over time without repeating the training process.
In the conclusion, indicate the entire lesson, showing how well we can fix Llama 3.2 3b I teach me a model in the Pythoset Dataset using Lora, and 4-bit Suaty library. By entering the texts provided, you can train a small model, working with well-functioning memory than producing and in understanding the Python code. In this process, we showed an evlothi integration of well-made memory usage, Lora adaptation of model, as well as close to the face management tools and training. This setup allows you to build and customize language models that are associated with specific operations related to the code, improve the accuracy and functioning of resources.
Download Colab Notebook HERE. All credit for this study goes to research for this project. Also, don't forget to follow Sane and join ours Telegraph station including LinkedIn Grtopic. Don't forget to join ours 75k + ml subreddit.
🚨 MarktechPost is shouting for companies / initializing / groups to cooperate with the coming magazines of AI the following 'Source Ai in production' and 'and' Agentic Ai '.
Asphazzaq is a Markteach Media Inc. According to a View Business and Developer, Asifi is committed to integrating a good social intelligence. His latest attempt is launched by the launch of the chemistrylife plan for an intelligence, MarktechPost, a devastating intimate practice of a machine learning and deep learning issues that are clearly and easily understood. The platform is adhering to more than two million moon visits, indicating its popularity between the audience.
✅ [Recommended] Join Our Telegraph Channel