DEADLOCK007X commited on
Commit
6fadedd
·
1 Parent(s): 8206a45

Update tinyllama_inference.py with improved evaluation and performance

Browse files
Files changed (1) hide show
  1. tinyllama_inference.py +7 -6
tinyllama_inference.py CHANGED
@@ -8,13 +8,14 @@ tokenizer, model = None, None
8
  def load_model():
9
  global tokenizer, model
10
  if tokenizer is None or model is None:
11
- model_name = "Salesforce/codegen-350M-mono" # Public model for code evaluation
 
12
  tokenizer = AutoTokenizer.from_pretrained(model_name)
13
  model = AutoModelForCausalLM.from_pretrained(model_name)
14
  return tokenizer, model
15
 
16
  def evaluate_code(question, code):
17
- # Updated prompt: explicitly instructs the model to output exactly valid JSON
18
  prompt = f"""You are an expert code evaluator.
19
  Evaluate the following solution for the given problem.
20
  Respond with exactly one JSON object (with no extra text) that has exactly two keys:
@@ -27,20 +28,20 @@ Solution: "{code}"
27
  """
28
  tokenizer, model = load_model()
29
  inputs = tokenizer(prompt, return_tensors="pt")
30
- # Adjust parameters for more deterministic and concise output
31
  outputs = model.generate(
32
  **inputs,
33
- max_new_tokens=60, # Fewer tokens to limit output length
34
  temperature=0.0, # Deterministic output
35
  pad_token_id=tokenizer.eos_token_id,
36
  do_sample=False
37
  )
38
  response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
39
 
40
- # Debug: print the raw response to logs if needed
41
  # print("Raw model response:", response_text)
42
 
43
- # Use regex to extract the first JSON object that starts with '{' and ends with '}'
44
  match = re.search(r'\{.*\}', response_text)
45
  if match:
46
  json_text = match.group(0)
 
8
  def load_model():
9
  global tokenizer, model
10
  if tokenizer is None or model is None:
11
+ # Use a DeepSeek model for code evaluation.
12
+ model_name = "deepseek-ai/deepseek-coder-1.3b" # Adjust to your chosen DeepSeek model
13
  tokenizer = AutoTokenizer.from_pretrained(model_name)
14
  model = AutoModelForCausalLM.from_pretrained(model_name)
15
  return tokenizer, model
16
 
17
  def evaluate_code(question, code):
18
+ # Updated prompt: instructs the model to output exactly valid JSON
19
  prompt = f"""You are an expert code evaluator.
20
  Evaluate the following solution for the given problem.
21
  Respond with exactly one JSON object (with no extra text) that has exactly two keys:
 
28
  """
29
  tokenizer, model = load_model()
30
  inputs = tokenizer(prompt, return_tensors="pt")
31
+ # Adjust parameters for concise and deterministic output
32
  outputs = model.generate(
33
  **inputs,
34
+ max_new_tokens=60, # Limit output length
35
  temperature=0.0, # Deterministic output
36
  pad_token_id=tokenizer.eos_token_id,
37
  do_sample=False
38
  )
39
  response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
40
 
41
+ # Debug: Uncomment the following line to print raw output if needed
42
  # print("Raw model response:", response_text)
43
 
44
+ # Use regex to extract the JSON object from the response
45
  match = re.search(r'\{.*\}', response_text)
46
  if match:
47
  json_text = match.group(0)