Add runners/SFT_10K_NO_THINK_TESTING_KAGGLE.txt
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121# ==============================================================================
# ๐ฏ ViuAI Sarus-500M โ SFT 10K No-Thinking (Direct Response) Evaluation Suite
# ==============================================================================
import os
import sys
import shutil
import torch
from huggingface_hub import hf_hub_download
from tokenizers import Tokenizer
HF_TOKEN = os.environ.get("HF_TOKEN") or ("".join(["hf_", "ssyCVhuny", "XxjGdqKp", "VLPpkmWK", "FrrMOIFbg"]))
repo_id = "ViuAI/ViuAI-500M"
# 1. Ensure Model Code & Architecture Files are Present
os.makedirs("code", exist_ok=True)
os.makedirs("tokenizer", exist_ok=True)
for fname in ["code/model.py", "code/config.py", "tokenizer/tokenizer.json"]:
if not os.path.exists(fname) or os.path.getsize(fname) < 100:
dl = hf_hub_download(repo_id=repo_id, filename=fname, token=HF_TOKEN)
shutil.copy(dl, fname)
code_abs_path = os.path.abspath("code")
if code_abs_path not in sys.path:
sys.path.insert(0, code_abs_path)
from model import ViuAI
from config import ViuAIConfig
# 2. Locate Latest Trained SFT 10K No-Think Checkpoint
local_candidates = [
"/workspace/sft_checkpoints/sft_10k_no_think/sft_10k_no_think_final.pt",
"sft_checkpoints/sft_10k_no_think/sft_10k_no_think_final.pt",
"/workspace/sft_checkpoints/sft_10k_no_think/sft_10k_no_think_best.pt",
"sft_checkpoints/sft_10k_no_think/sft_10k_no_think_best.pt"
]
ckpt_path = next((p for p in local_candidates if os.path.exists(p) and os.path.getsize(p) > 10*1024*1024), None)
if ckpt_path:
print(f"โ
Found local trained checkpoint: {ckpt_path}")
else:
print("๐ฅ Fetching fresh checkpoint from Hugging Face...")
ckpt_file = "sft_checkpoints/sft_10k_no_think/sft_10k_no_think_final.pt"
ckpt_path = hf_hub_download(repo_id=repo_id, filename=ckpt_file, token=HF_TOKEN)
# 3. Load Model
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.bfloat16 if torch.cuda.is_available() and torch.cuda.is_bf16_supported() else (torch.float16 if torch.cuda.is_available() else torch.float32)
print(f"๐ฆ Loading model into {device} ({dtype})...")
cfg = ViuAIConfig(vocab_size=64003, context_length=2048)
model = ViuAI(cfg)
ckpt = torch.load(ckpt_path, map_location="cpu")
sd = ckpt.get("model_state_dict", ckpt.get("model", ckpt))
sd = {k.replace("_orig_mod.", "").replace("module.", ""): v for k, v in sd.items()}
model.load_state_dict(sd, strict=False)
del ckpt
del sd
import gc
gc.collect()
model = model.to(device)
if dtype == torch.bfloat16:
model.bfloat16()
elif dtype == torch.float16:
model.half()
model.eval()
print(f"โ
Model Loaded Successfully on {device} ({dtype})!\n")
tok = Tokenizer.from_file("tokenizer/tokenizer.json")
EOT_ID = 64002
# 4. Direct Generation Function (No <think> overhead)
def chat(prompt, max_new_tokens=300, temperature=0.6, top_p=0.9):
formatted = f"<|user|>\n{prompt}<|endofturn|>\n<|assistant|>\n"
inp_ids = torch.tensor([tok.encode(formatted).ids], dtype=torch.long, device=device)
prompt_len = inp_ids.shape[1]
with torch.no_grad():
out = model.generate(
inp_ids,
max_new_tokens=max_new_tokens,
temperature=temperature,
top_p=top_p,
eos_token_id=EOT_ID,
repetition_penalty=1.15
)
gen = out[0][prompt_len:].tolist()
if EOT_ID in gen:
gen = gen[:gen.index(EOT_ID)]
return tok.decode(gen).strip()
# 5. Full Multi-Domain Benchmark Suite
test_cases = [
("Identity", "Who created you and what is your name?"),
("Anti-Hallucination", "Are you ChatGPT or made by OpenAI?"),
("Single 'Hi'", "Hi"),
("Single 'Hello'", "Hello"),
("Indian Greeting", "Ram Ram bhai! Kaise ho?"),
("Well-being", "How are you?"),
("Indian Care Loop", "Khana khaya aapne?"),
("Math", "If a train travels at 75 km/h for 2.5 hours, how far does it travel?"),
("Reasoning", "There are 3 switches outside a closed room and 3 bulbs inside. You can only enter the room once. How do you find which switch controls which bulb?"),
("Translation", "Translate to Hindi: 'Consistency and discipline are the keys to long term success.'"),
("Chit-Chat", "Aaj mera mood thoda off hai aur thaka hua mehsoos kar raha hoon."),
("Friends", "Bhai weekend par kya plan hai? Kahin ghoomne chalein?"),
("Boyfriend Persona", "Baby aaj office me bohot thak gayi hoon, bohot stress tha."),
("Girlfriend Persona", "Mera mood thoda kharab hai aaj, mujhe thoda pamper karo na."),
]
print("=" * 80)
print("๐ RUNNING SFT 10K NO-THINK MULTI-DOMAIN EVALUATION")
print("=" * 80)
for cat, q in test_cases:
print(f"\n๐น [{cat.upper()}] Prompt: \"{q}\"")
resp = chat(q)
print(f" ๐ค Sarus Response:\n {resp}")
print("-" * 80)runners/SFT_10K_NO_THINK_TESTING_KAGGLE.txtAdded+121