Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
tags:
|
| 5 |
+
- llama2
|
| 6 |
+
- lora
|
| 7 |
+
- code
|
| 8 |
+
- adapter
|
| 9 |
+
datasets:
|
| 10 |
+
- iamtarun/python_code_instructions_18k_alpaca
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# LLaMA-2-7B CODE LoRA Adapter
|
| 14 |
+
|
| 15 |
+
This is a LoRA adapter for LLaMA-2-7B fine-tuned on code domain data.
|
| 16 |
+
|
| 17 |
+
## Model Details
|
| 18 |
+
|
| 19 |
+
- **Base Model**: meta-llama/Llama-2-7b-hf
|
| 20 |
+
- **Adapter Type**: LoRA (Low-Rank Adaptation)
|
| 21 |
+
- **Domain**: Code
|
| 22 |
+
- **Training Data**: Python code instructions
|
| 23 |
+
- **Training Examples**: 2000 (1600 train, 200 val, 200 test)
|
| 24 |
+
- **Epochs**: 2
|
| 25 |
+
|
| 26 |
+
## LoRA Configuration
|
| 27 |
+
|
| 28 |
+
- Rank (r): 16
|
| 29 |
+
- Alpha: 32
|
| 30 |
+
- Dropout: 0.05
|
| 31 |
+
- Target Modules: q_proj, v_proj, k_proj, o_proj
|
| 32 |
+
|
| 33 |
+
## Performance Metrics (100 test examples)
|
| 34 |
+
|
| 35 |
+
- Loss: 0.573
|
| 36 |
+
- Perplexity: 1.773
|
| 37 |
+
- BLEU: 32.76
|
| 38 |
+
|
| 39 |
+
## Usage
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 43 |
+
from peft import PeftModel
|
| 44 |
+
|
| 45 |
+
# Load base model
|
| 46 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 47 |
+
"meta-llama/Llama-2-7b-hf",
|
| 48 |
+
load_in_8bit=True,
|
| 49 |
+
device_map="auto"
|
| 50 |
+
)
|
| 51 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
|
| 52 |
+
|
| 53 |
+
# Load adapter
|
| 54 |
+
model = PeftModel.from_pretrained(model, "Thamirawaran/llama2-7b-code-lora")
|
| 55 |
+
|
| 56 |
+
# Generate
|
| 57 |
+
prompt = 'Write a Python function to sort a list'
|
| 58 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 59 |
+
outputs = model.generate(**inputs, max_length=256, temperature=0.7)
|
| 60 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
## Training Details
|
| 64 |
+
|
| 65 |
+
- Trained with FYP_MDLE library
|
| 66 |
+
- 8-bit quantization during training
|
| 67 |
+
- Gradient accumulation: 16 steps
|
| 68 |
+
- Learning rate: 2e-4
|
| 69 |
+
- Warmup steps: 20
|
| 70 |
+
|
| 71 |
+
## Citation
|
| 72 |
+
|
| 73 |
+
```bibtex
|
| 74 |
+
@misc{llama2-code-lora,
|
| 75 |
+
author = {Team RAISE},
|
| 76 |
+
title = {LLaMA-2-7B Code LoRA Adapter},
|
| 77 |
+
year = {2026},
|
| 78 |
+
publisher = {HuggingFace},
|
| 79 |
+
howpublished = {\url{https://huggingface.co/Thamirawaran/llama2-7b-code-lora}}
|
| 80 |
+
}
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## License
|
| 84 |
+
|
| 85 |
+
Apache 2.0
|