MCPcopy Create free account
hub / github.com/RightNow-AI/autokernel / cmd_record

Function cmd_record

orchestrate.py:476–574  ·  view source on GitHub ↗

Record an experiment result for a kernel. *status* is one of: kept, revert, failed, crash, timeout

(state: dict, kernel_file: str, throughput_tflops: float, status: str, description: str)

Source from the content-addressed store, hash-verified

474
475
476def cmd_record(state: dict, kernel_file: str, throughput_tflops: float, status: str, description: str) -> None:
477 """
478 Record an experiment result for a kernel.
479
480 *status* is one of: kept, revert, failed, crash, timeout
481 """
482 kernels = state["kernels"]
483
484 # Find the kernel entry
485 target = None
486 for k in kernels:
487 if k["file"] == kernel_file or Path(k["file"]).name == Path(kernel_file).name:
488 target = k
489 break
490
491 if target is None:
492 print(f"ERROR: Kernel '{kernel_file}' not found in orchestration state.")
493 print("Known kernels:")
494 for k in kernels:
495 print(f" {k['file']}")
496 sys.exit(1)
497
498 # Normalize status
499 status_lower = status.strip().lower()
500 is_kept = status_lower in ("kept", "keep", "improved")
501 is_revert = status_lower in ("revert", "reverted", "slower", "same")
502 is_failure = status_lower in ("failed", "fail", "crash", "error", "timeout")
503
504 # Update experiment counts
505 target["experiments_run"] += 1
506
507 if is_kept:
508 target["experiments_kept"] += 1
509 target["consecutive_reverts"] = 0
510 # Update best if improved
511 if target["best_tflops"] is None or throughput_tflops > target["best_tflops"]:
512 target["best_tflops"] = throughput_tflops
513 # Set baseline on first kept result if not already set
514 if target["baseline_tflops"] is None:
515 target["baseline_tflops"] = throughput_tflops
516 elif is_revert:
517 target["consecutive_reverts"] += 1
518 # First experiment sets the baseline even on revert
519 if target["baseline_tflops"] is None:
520 target["baseline_tflops"] = throughput_tflops
521 if target["best_tflops"] is None:
522 target["best_tflops"] = throughput_tflops
523 elif is_failure:
524 target["consecutive_reverts"] += 1
525 else:
526 # Unknown status -- treat as revert
527 print(f"WARNING: Unrecognized status '{status}', treating as revert.")
528 target["consecutive_reverts"] += 1
529
530 # Compute speedup
531 if target["baseline_tflops"] and target["best_tflops"] and target["baseline_tflops"] > 0:
532 target["speedup"] = round(target["best_tflops"] / target["baseline_tflops"], 3)
533

Callers 1

mainFunction · 0.85

Calls 2

_append_result_rowFunction · 0.85
save_stateFunction · 0.85

Tested by

no test coverage detected