deepak-tnega/slm-rl-colab
0
deepak-tnega/slm-rl-colab
PEFT LoRA adapter that warm-starts Space Invaders play for LiquidAI/LFM2.5-1.2B-Instruct in the SLM-RL workshop.
Paste deepak-tnega/slm-rl-colab as the playground adapter URL (and usually the same id as the dataset URL).
Install
pip install "transformers>=4.46" peft accelerate torchLoad with transformers + PEFT
Weights live under the adapter/ subfolder — pass subfolder="adapter".
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE = "LiquidAI/LFM2.5-1.2B-Instruct"
ADAPTER = "deepak-tnega/slm-rl-colab" # this repo
device = (
"cuda" if torch.cuda.is_available()
else "mps" if torch.backends.mps.is_available()
else "cpu"
)
dtype = torch.bfloat16 if device != "cpu" else torch.float32
tokenizer = AutoTokenizer.from_pretrained(BASE)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
model = AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=dtype)
model = PeftModel.from_pretrained(model, ADAPTER, subfolder="adapter")
model.to(device).eval()
messages = [
{"role": "system", "content": "You play Space Invaders. Reply with ACTION: <id>."},
{"role": "user", "content": "Legal actions: 1) NOOP 2) UP\nChoose."},
]
prompt = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, tokenize=False,
)
inputs = tokenizer(prompt, return_tensors="pt").to(device)
with torch.inference_mode():
out = model.generate(**inputs, max_new_tokens=24, do_sample=False)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))Download only the adapter files
from huggingface_hub import snapshot_download
path = snapshot_download("deepak-tnega/slm-rl-colab", allow_patterns="adapter/*")
# then: PeftModel.from_pretrained(base_model, f"{path}/adapter")Workshop / SLM-RL CLI
slm-rl evolve --game space-invaders \
--dataset-url deepak-tnega/slm-rl-colab-data \
--adapter-url deepak-tnega/slm-rl-colab \
--generations 2Train metrics (if recorded)
{
"eval": {
"episodes": 8,
"intervention_rate": 0.0,
"invalid_rate": 0.0,
"mean_entropy": null,
"mean_score": 0.4375,
"primary": 0.4375,
"win_rate": 0.0
},
"gate": {
"promoted": true,
"reason": "primary 0.3958 -> 0.4375, invalid_rate 0.0000, intervention_rate 0.0000"
},
"train": {
"entropy": 2.7633667588233948,
"frac_reward_zero_std": 0.375,
"kl": 0.3395535312592983,
"loss": -0.02336353361606598,
"num_prompts": 16,
"reward": -0.03125
}
}Trained with SLM-RL.
