FelixPhilip's picture
Oracle weight assigning update
93f0901
raw
history blame
1.5 kB
from transformers import AutoTokenizer, AutoModelForCausalLM
class SmolLM:
def __init__(self, model_path="HuggingFaceTB/SmolLM2-1.7B-Instruct"):
self.available = True
try:
print(f"[INFO] Loading Oracle tokenizer from {model_path}")
self.tokenizer = AutoTokenizer.from_pretrained(model_path)
print(f"[INFO] Loading Oracle from {model_path}")
self.model = AutoModelForCausalLM.from_pretrained(model_path)
print("[INFO] Oracle loaded successfully")
except Exception as e:
print(f"[ERROR] Failed to load model '{model_path}': {e}")
self.available = False
def predict(self, prompt,max_length=512,max_new_tokens=150):
if not self.available:
print("[WARN] Oracle unavailable, returning default weight 0.5")
return "0.5"
try:
print(f"[INFO] Generating response for prompt: {prompt[:100]}...", flush=True)
inputs = self.tokenizer(prompt, return_tensors="pt", truncation=True, max_length=max_length)
outputs = self.model.generate(**inputs, max_length=inputs["input_ids"].shape[1]+max_new_tokens,num_return_sequences=1)
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
print(f"[INFO] Generated response: {response[:100]}...", flush=True)
return response
except Exception as e:
print(f"[ERROR] Oracle has failed: {e}")
return "0.5"