File size: 1,034 Bytes
c5778e1
 
72c814f
925d43b
 
 
c1e0503
 
 
60870dc
c5778e1
60870dc
 
 
 
 
 
55b5608
60870dc
55b5608
60870dc
 
 
 
 
 
 
55b5608
60870dc
 
55b5608
60870dc
 
 
 
 
55b5608
c1e0503
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
import torch
from datasets import load_dataset

torch.cuda.is_available()
print("executed successfully")

dataset_name = "timdettmers/openassistant-guanaco"
dataset = load_dataset(dataset_name, split="train")

from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

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

# download model

model_name = "TinyPixel/Llama-2-7B-bf16-sharded"
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    quantization_config=bnb_config,
    trust_remote_code=True
)
model.config.use_cache = False

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

text = "What is a large language model?"
device = "cuda:0"
inputs = tokenizer(text, return_tensors="pt").to(device)
outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))