File size: 1,603 Bytes
b970d2b
 
 
48b8a7d
 
 
 
 
 
 
b970d2b
 
48b8a7d
b970d2b
48b8a7d
b970d2b
48b8a7d
b970d2b
48b8a7d
 
 
 
b970d2b
48b8a7d
 
 
 
 
 
 
b970d2b
48b8a7d
 
b970d2b
48b8a7d
 
 
b970d2b
48b8a7d
 
 
 
 
b970d2b
 
 
48b8a7d
 
 
 
 
b970d2b
48b8a7d
b970d2b
48b8a7d
 
 
 
 
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
53
54
55
56
57
58
59
60
---
base_model: codellama/CodeLlama-7b-Instruct-hf
library_name: peft
license: llama2
tags:
- code
- unit-testing
- c++
- lora
- peft
---

# CodeLlama Unit Test Generator

This is a LoRA adapter for CodeLlama-7b-Instruct-hf, fine-tuned to generate comprehensive unit tests for C/C++ code.

## Usage

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch

# Load base model and tokenizer
base_model = AutoModelForCausalLM.from_pretrained(
    "codellama/CodeLlama-7b-Instruct-hf",
    device_map="auto",
    torch_dtype=torch.float16
)
tokenizer = AutoTokenizer.from_pretrained("athrv/codellama_utests_adapter")

# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "athrv/codellama_utests_adapter")

# Generate unit tests
system_prompt = "Generate comprehensive unit tests for C/C++ code."
user_prompt = "Create unit tests for: [YOUR_CODE_HERE]"

prompt = f"<<SYS>>\n{system_prompt}\n<</SYS>>\n\n[INST] {user_prompt} [/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
```

## Training Details

- **Base Model**: CodeLlama-7b-Instruct-hf  
- **Dataset**: Embedded_Unittest2
- **Training Method**: LoRA fine-tuning
- **Target Modules**: Attention layers
- **Sequence Length**: 4096-6144 tokens

## Model Performance

This model generates comprehensive unit tests covering:
- Function testing and edge cases
- Boundary conditions
- Error scenarios
- Proper test naming conventions