Views
No views yet
1from adapters import list_adapters, get_adapter_info
2from transformers import (
3 AutoTokenizer,
4 BitsAndBytesConfig,
5 AutoModelForCausalLM
6)
7from tqdm import tqdm
8import torch
9from huggingface_hub import login
10
11# log into hf to get access to the adapter
12login(token=hf_token)
13
14# init configs
15model_name = "mistralai/Mistral-7B-v0.3"
16device_map = {"":0}
17
18use_4bit = True
19bnb_4bit_compute_dtype = "float16"
20bnb_4bit_quant_type = "nf4"
21use_nested_quant = False
22
23compute_dtype = getattr(torch, bnb_4bit_compute_dtype)
24
25bnb_config = BitsAndBytesConfig(
26 load_in_4bit = use_4bit,
27 bnb_4bit_quant_type = bnb_4bit_quant_type,
28 bnb_4bit_compute_dtype = compute_dtype,
29 bnb_4bit_use_double_quant = use_nested_quant,)
30
31
32# load model and tokenizer
33tokenizer = AutoTokenizer.from_pretrained(model_name,trust_remote_code = True)
34
35model = AutoModelForCausalLM.from_pretrained(
36 model_name,
37 quantization_config = bnb_config,
38 device_map = device_map,
39)
40
41
42model.load_adapter("cemrtkn/llm-football-simulator")
43
44
45input_text = """This is a sequence of football match events.
46Time: 00:00:00.000 | Event: Half Start
47"""
48seq_list = input_text.split('\n')
49match_list = []
50for i in tqdm(range(5)):
51 input_text = '\n'.join(seq_list)
52 inputs = tokenizer(input_text, return_tensors="pt").to("cuda") # Ensure tensors are on the right device
53 # hacky way to generate
54 output = model.generate(**inputs, max_new_tokens=100, do_sample=True ,temperature=1, pad_token_id=tokenizer.eos_token_id)
55
56 prediction = tokenizer.decode(output[0], skip_special_tokens=True).split('\n')[-2]
57 print(prediction)