This repo contains a LoRA adapter finetuned on Meta Llama 3.2 (3B), trained using QLoRA and SFTTrainer on an instruction dataset derived from the Databricks Dolly instruction corpus.
1{
2 "r": 8,
3 "lora_alpha": 32,
4 "target_modules": ["q_proj", "k_proj", "v_proj", "out_proj", "fc_in", "fc_out", "wte"],
5 "lora_dropout": 0.05,
6 "bias": "none",
7 "task_type": "CAUSAL_LM"
8}
1{
2 "num_train_epochs": 3,
3 "per_device_train_batch_size": 1,
4 "gradient_accumulation_steps": 1,
5 "learning_rate": 2e-4,
6 "weight_decay": 0.001,
7 "warmup_ratio": 0.03,
8 "lr_scheduler_type": "constant",
9 "max_seq_length": 256,
10 "optim": "paged_adamw_32bit",
11 "gradient_checkpointing": true,
12 "eval_strategy": "steps",
13 "eval_steps": 100,
14 "save_steps": 100,
15 "logging_steps": 100,
16 "packing": true
17}
1{
2 "load_in_4bit": true,
3 "bnb_4bit_quant_type": "nf4",
4 "bnb_4bit_compute_dtype": "float16",
5 "bnb_4bit_use_double_quant": false
6}
1{
2 "framework": "PyTorch with Hugging Face Transformers",
3 "fine_tuning_method": "LoRA (Low-Rank Adaptation)",
4 "quantization": "4-bit NF4 with QLoRA",
5 "compute": "Google Colab T4",
6 "gpu_memory": "~16GB VRAM",
7}
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# Load base model
6model_name = "meta-llama/Llama-3.2-3B"
7base_model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype=torch.float16,
10 low_cpu_mem_usage=True,
11 return_dict=True,
12 device_map="auto",
13)
14
15# Load Tokenizer
16tokenizer = AutoTokenizer.from_pretrained(
17 "MagicaNeko/llama-3b-lora-dolly",
18 subfolder="model-ft-tokenizer"
19)
20
21# Load LoRA Adapter
22model = PeftModel.from_pretrained(
23 base_model,
24 "MagicaNeko/llama-3b-lora-dolly",
25 subfolder="model-ft-lora-adapter"
26)
27
28# Merge adapters
29model = model.merge_and_unload()
30
31# Inference
32prompt = "What is machine learning?"
33inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
34outputs = model.generate(**inputs, max_new_tokens=128)
35print(tokenizer.decode(outputs[0], skip_special_tokens=True))```
The training notebook is available at:
Colab link
This LoRA adapter is released as open-source under the Apache 2.0 License.
It contains only the adapter weights and does not include any Meta LLaMA 3B base model weights.
You must still comply with the
Meta Llama 3 license if using the base model together with this adapter.