Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4model_name = "Qwen/Qwen2.5-0.5B-Instruct"
5adapter_name = "arbyazra123/qwen2.5-0.5b-instruct-sumobot"
6
7# Load tokenizer
8tokenizer = AutoTokenizer.from_pretrained(model_name)
9
10# Load base model
11model = AutoModelForCausalLM.from_pretrained(
12 model_name,
13 device_map="auto", # or "cuda" if you have NVIDIA
14 torch_dtype="auto"
15)
16
17# Load LoRA adapter
18model = PeftModel.from_pretrained(model, adapter_name)
19
20# Merge LoRA into the base model (optional if you want a standalone model)
21model = model.merge_and_unload()
22
23# Inference with chat template
24messages = [
25 {"role": "system", "content": "You are a Sumobot assistant that decides actions based on game state."},
26 {"role": "user", "content": "Given this game state: AngleToEnemy=8.11, AngleToEnemyScore=0.99, DistanceToEnemyScore=0.81, NearBorderArenaScore=0.19, FacingToArena=-0.98."},
27]
28
29# Apply the tokenizer's built-in chat template
30chat_prompt = tokenizer.apply_chat_template(
31 messages,
32 tokenize=False,
33 add_generation_prompt=True
34)
35
36inputs = tokenizer(chat_prompt, return_tensors="pt").to(model.device)
37
38outputs = model.generate(
39 **inputs,
40 max_new_tokens=128
41)
42
43print(tokenizer.decode(outputs[0], skip_special_tokens=True))
441{
2 "messages": [
3 {
4 "role": "system",
5 "content": "You are a Sumobot assistant that decides actions based on game state."
6 },
7 {
8 "role": "user",
9 "content": "Given this game state: AngleToEnemy=-16.49, AngleToEnemyScore=0.96, DistanceToEnemyScore=0.77, NearBorderArenaScore=0.77, FacingToArena=-0.97."
10 },
11 {
12 "role": "assistant",
13 "content": "SK, DS, FWD0.13"
14 }
15 ]
16}1# Amount of dataset lines that will be compiled and converted to dataset.jsonl.
2# If -1, use all lines.
3max_dataset=10_000
4# max_dataset=-1 # Use all lines
5train_validation_ratio=0.9
6
7# Training args
8batches_per_device=4 # adjust based on GPU CUDA / MPS power. Using standard laptop RAM is suggested to set 1. Example (1,2,4,8)
9# batches_per_device=8
10num_train_epoch=2 # num train 2-3 is enough
11gradient_accumulation=12
12eval_accumulation=1
13learning_rate=5e-5
14save_every=0.5 #ratio
15log_every=10
16eval_ratio=20
17
18# LoRA
19rank=32
20alpha=64
21dropout=0.011@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}