rak2315 commited on
Commit
c40e050
·
1 Parent(s): e630776

fix grader: other type penalty, gradient_not_zeroed loss check

Browse files
Files changed (1) hide show
  1. server/grader.py +8 -3
server/grader.py CHANGED
@@ -209,7 +209,7 @@ Respond with JSON only:
209
  def _check_bug_type(submitted: str, correct: str) -> bool:
210
  submitted_clean = submitted.strip().lower().replace(" ", "_").replace("-", "_")
211
  if submitted_clean == "other":
212
- return True
213
 
214
  correct_clean = correct.strip().lower()
215
  aliases = {
@@ -405,10 +405,15 @@ def _verify_fix(fixed_code: str, scenario: BugScenario, exec_output: str) -> tup
405
  return True, ""
406
 
407
  elif task == "gradient_not_zeroed":
408
- if "nan" in exec_output.lower():
409
- return False, "Loss is still NaN — gradients may still be accumulating."
410
  if not _zero_grad_before_backward_ast(fixed_code):
411
  return False, "optimizer.zero_grad() not found before loss.backward() in the loop."
 
 
 
 
 
 
 
412
  return True, ""
413
 
414
  elif task == "missing_eval_mode":
 
209
  def _check_bug_type(submitted: str, correct: str) -> bool:
210
  submitted_clean = submitted.strip().lower().replace(" ", "_").replace("-", "_")
211
  if submitted_clean == "other":
212
+ return False
213
 
214
  correct_clean = correct.strip().lower()
215
  aliases = {
 
405
  return True, ""
406
 
407
  elif task == "gradient_not_zeroed":
 
 
408
  if not _zero_grad_before_backward_ast(fixed_code):
409
  return False, "optimizer.zero_grad() not found before loss.backward() in the loop."
410
+ if "nan" in exec_output.lower():
411
+ return False, "Loss is still NaN — gradients may still be accumulating."
412
+ loss_values = re.findall(r"loss[:\s]+([\d.]+)", exec_output.lower())
413
+ if len(loss_values) >= 2:
414
+ first, last = float(loss_values[0]), float(loss_values[-1])
415
+ if last >= first * 0.95:
416
+ return False, f"Loss did not decrease: {first:.4f} → {last:.4f}. zero_grad may be missing or ineffective."
417
  return True, ""
418
 
419
  elif task == "missing_eval_mode":