Views
No views yet
1pip install -q --upgrade transformers accelerate
2pip install autoawq1import torch
2from transformers import AutoTokenizer, AwqConfig, AutoModelForCausalLM, pipeline
3from huggingface_hub import login
4
5#This code below is if you are using a hugging face token on google colab.
6from google.colab import userdata
7my_token = userdata.get("HF_TOKEN")
8login(my_token)
9
10model_name = "UCLA-EMC/Meta-Llama-3.1-8B-AWQ-INT4"
11
12quantization_config = AwqConfig(
13bits=4,
14fuse_max_seq_len=512, # Note: Update this as per your use-case
15do_fuse=True,
16)
17
18tokenizer = AutoTokenizer.from_pretrained(model_id)
19model = AutoModelForCausalLM.from_pretrained(
20model_name,
21torch_dtype=torch.float16,
22low_cpu_mem_usage=True,
23device_map="auto",
24quantization_config=quantization_config
25)
26
27tokenizer = AutoTokenizer.from_pretrained(model_id)
28model = AutoModelForCausalLM.from_pretrained(
29model_name,
30torch_dtype=torch.float16,
31low_cpu_mem_usage=True,
32device_map="auto",
33quantization_config=quantization_config
34)
35
36text_generator = pipeline(
37'text-generation',
38model = model,
39tokenizer = tokenizer,
40max_new_tokens=456,
41)
42
43def get_response(prompt):
44response = text_generator(prompt)
45gen_text = response[0]['generated_text']
46return gen_text
47
48prompt = "generate python code to make a bar graph"
49llama_response = get_response(prompt)
50print(llama_response)