File size: 1,609 Bytes
e8124f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# LLaMA 3.2 3B — Python Code Generation (QLoRA Fine-tune)

## Model Description
Fine-tuned LLaMA 3.2 3B on Python code generation using QLoRA (4-bit NF4 quantization).
Trained on `iamtarun/python_code_instructions_18k_alpaca` — 18k Python instruction-output pairs.

## Training Details
- **Base model:** meta-llama/Llama-3.2-3B
- **Method:** QLoRA (LoRA rank=16, alpha=32, 4-bit NF4 quantization)
- **Target modules:** q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
- **Dataset:** 16,738 training samples, 1,862 test samples
- **Epochs:** 3
- **Batch size:** 2 × 8 gradient accumulation = 16 effective
- **Learning rate:** 2e-4 with linear scheduler
- **Optimizer:** AdamW 8-bit
- **Hardware:** Single NVIDIA T4 (16GB)
- **Training time:** ~3.6 hours
- **Final training loss:** 0.573

## Loss Curve
| Epoch | Loss |
|---|---|
| 1 | ~0.65 |
| 2 | ~0.47 |
| 3 | 0.57 |

## Usage
```python
from unsloth import FastLanguageModel

model, tokenizer = FastLanguageModel.from_pretrained(
    "reddyrohith49471/llama3.2-3b-python-qlora",
    max_seq_length=2048,
    load_in_4bit=True,
)
FastLanguageModel.for_inference(model)

inputs = tokenizer(
    "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n"
    "Write a Python function to check if a number is prime."
    "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
    return_tensors="pt"
).to("cuda")

outputs = model.generate(**inputs, max_new_tokens=256)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```

## Framework
- Unsloth 2x faster fine-tuning
- HuggingFace PEFT + TRL
- PyTorch + bitsandbytes