Views
No views yet
pip install -q transformers accelerate sentencepiece scipy torch1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Check for the bfloat16 support. T4 does not support bfloat16
5dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] == 8 else torch.float16
6
7model_id = "duliadotio/dulia-13b-8k-alpha"
8
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11model = AutoModelForCausalLM.from_pretrained(
12 model_id
13 torch_dtype=dtype,
14 low_cpu_mem_usage=True,
15 device_map="cuda"
16)
17
18system_message = "Dulia AI is a helpful and honest assistant designed by Dulia Inc. Take a step by step approach to answer user's query. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."
19system_prompt = f"<|system|>{system_message}</s>"
20
21def infer(user_prompt, history = "", skip_special_tokens=False):
22 prompt = ""
23 if history == "":
24 prompt += system_prompt
25 prompt += history + f"<|prompter|>{user_prompt}</s><|assistant|>"
26 inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
27 output = model.generate(**inputs, do_sample=True, top_p=0.95, top_k=0, max_new_tokens=512)
28
29 return tokenizer.decode(output[0], skip_special_tokens)
30
31user_prompt = "What is your name?"
32
33# This is the first message so, we don't have to pass the history.
34response = infer(user_prompt)
35
36user_prompt = "Can you write me an email?"
37response = infer(user_prompt, response)<|system|>system message</s><|prompter|>user prompt</s><|assistant|><|system|>system message</s><|prompter|>User Question 1</s><|assistant|>Answer 1</s><|prompter|>User Question 2</s><|assistant|>| Metric | Value |
|---|---|
| Avg. | 49.67 |
| ARC (25-shot) | 60.67 |
| HellaSwag (10-shot) | 82.0 |
| MMLU (5-shot) | 56.87 |
| TruthfulQA (0-shot) | 42.59 |
| Winogrande (5-shot) | 77.19 |
| GSM8K (5-shot) | 10.69 |
| DROP (3-shot) | 17.72 |