Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
datasets:
|
| 3 |
+
- HuggingFaceH4/CodeAlpaca_20K
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
library_name: transformers
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
tags:
|
| 9 |
+
- code
|
| 10 |
+
- LLaMa2
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# LLaMaCoder
|
| 14 |
+
|
| 15 |
+
## Model Description
|
| 16 |
+
|
| 17 |
+
`LLaMaCoder` is based on LLaMa2 7B language model, finetuned using LoRA adaptors.
|
| 18 |
+
|
| 19 |
+
## Usage
|
| 20 |
+
|
| 21 |
+
Generate code with LLaMaCoder in 4bit model according to the following python snippet:
|
| 22 |
+
|
| 23 |
+
```python
|
| 24 |
+
from transformers import AutoModelForCausalLM, BitsAndBytesConfig, AutoTokenizer
|
| 25 |
+
import torch
|
| 26 |
+
|
| 27 |
+
MODEL_NAME = "Sakuna/LLaMaCoderAll"
|
| 28 |
+
device = "cuda:0"
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
bnb_config = BitsAndBytesConfig(
|
| 32 |
+
load_in_4bit=True,
|
| 33 |
+
bnb_4bit_quant_type="nf4",
|
| 34 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
+
MODEL_NAME,
|
| 39 |
+
quantization_config=bnb_config,
|
| 40 |
+
trust_remote_code=True
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
|
| 44 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 45 |
+
|
| 46 |
+
model = model.to(device)
|
| 47 |
+
model.eval()
|
| 48 |
+
|
| 49 |
+
prompt = "Write a Java program to calculate the factorial of a given number k"
|
| 50 |
+
input = f"{prompt}\n### Solution:\n"
|
| 51 |
+
device = "cuda:0"
|
| 52 |
+
|
| 53 |
+
inputs = tokenizer(input, return_tensors="pt").to(device)
|
| 54 |
+
outputs = model.generate(**inputs, max_length=256, temperature=0.7)
|
| 55 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 56 |
+
```
|