Files
AL1-model-B/mlb/verify_base.py

22 lines
937 B
Python
Raw Permalink Normal View History

import os
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.environ["HF_HOME"] = os.path.join(HERE, "hf_cache")
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL = "Qwen/Qwen3-0.6B"
device = "mps" if torch.backends.mps.is_available() else "cpu"
tok = AutoTokenizer.from_pretrained(MODEL)
model = AutoModelForCausalLM.from_pretrained(MODEL, dtype=torch.float32).to(device)
print("device:", device)
print("params:", sum(p.numel() for p in model.parameters()))
print("chat_template set:", tok.chat_template is not None)
msgs = [{"role": "user", "content": "Reply with exactly: pong"}]
text = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True, enable_thinking=False)
ids = tok(text, return_tensors="pt").to(device)
out = model.generate(**ids, max_new_tokens=16, do_sample=False)
print("OUT:", tok.decode(out[0][ids.input_ids.shape[1]:], skip_special_tokens=True))