Views
No views yet
CohereForAI/aya-expanse-8b model using the AWQ method in 4-bit precision.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, AwqConfig
3
4# Set up device
5device = torch.device('cuda:1') # Remember to use the correct device here
6
7# Load model and tokenizer
8model_name = "kevinbazira/aya-expanse-8b-awq-4bit"
9tokenizer = AutoTokenizer.from_pretrained(model_name)
10quantization_config = AwqConfig(version="exllama")
11model = AutoModelForCausalLM.from_pretrained(
12 model_name,
13 device_map={"": device.index},
14 quantization_config=quantization_config
15)
16
17# Prepare input
18# https://huggingface.co/docs/transformers/en/pad_truncation
19input_text = "Add your prompt here."
20inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding="max_length", max_length=64)
21inputs = {key: value.to(device) for key, value in inputs.items()}
22
23# Perform text generation
24# https://huggingface.co/docs/transformers/en/main_classes/text_generation
25outputs = model.generate(
26 **inputs,
27 num_return_sequences=1,
28 min_new_tokens=64,
29 max_new_tokens=64,
30 do_sample=False,
31 use_cache=True,
32 num_beams=1
33)
34
35# Decode and print the output
36print(tokenizer.decode(outputs[0], skip_special_tokens=True))

contact@kevinbazira.com. I'll be happy to help!