File size: 1,269 Bytes
ff30036
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
datasets:
- HuggingFaceH4/CodeAlpaca_20K
language:
- en
library_name: transformers
pipeline_tag: text-generation
tags:
- code
- LLaMa2
---

# LLaMaCoder

## Model Description

`LLaMaCoder` is based on LLaMa2 7B language model, finetuned using LoRA adaptors. 

## Usage

Generate code with LLaMaCoder in 4bit model according to the following python snippet:

```python
from transformers import AutoModelForCausalLM, BitsAndBytesConfig, AutoTokenizer
import torch

MODEL_NAME = "Sakuna/LLaMaCoderAll"
device = "cuda:0"


bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.float16,
)

model = AutoModelForCausalLM.from_pretrained(
    MODEL_NAME,
    quantization_config=bnb_config,
    trust_remote_code=True
)

tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token

model = model.to(device)
model.eval()

prompt = "Write a Java program to calculate the factorial of a given number k"
input = f"{prompt}\n### Solution:\n"
device = "cuda:0"

inputs = tokenizer(input, return_tensors="pt").to(device)
outputs = model.generate(**inputs, max_length=256, temperature=0.7)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```