MCPcopy Create free account
hub / github.com/NVIDIA/SOL-ExecBench / check_monkey_patch

Function check_monkey_patch

src/sol_execbench/core/bench/reward_hack.py:48–70  ·  view source on GitHub ↗

Detect if torch.cuda.Event.elapsed_time has been patched. Compares the current function identity against the address captured at module load time. Must be called before the timed section. Raises: RewardHackDetected: If the timing function has been replaced.

()

Source from the content-addressed store, hash-verified

46
47
48def check_monkey_patch() -> None:
49 """Detect if torch.cuda.Event.elapsed_time has been patched.
50
51 Compares the current function identity against the address captured at
52 module load time. Must be called before the timed section.
53
54 Raises:
55 RewardHackDetected: If the timing function has been replaced.
56 """
57 try:
58 import torch.cuda as _tc
59
60 if (
61 _ELAPSED_TIME_ADDR is not None
62 and id(_tc.Event.elapsed_time) != _ELAPSED_TIME_ADDR
63 ):
64 raise RewardHackDetected(
65 "torch.cuda.Event.elapsed_time has been monkey-patched"
66 )
67 except RewardHackDetected:
68 raise
69 except Exception:
70 pass
71
72
73def check_thread_injection(threads_before: int, threads_after: int) -> None:

Calls 1

RewardHackDetectedClass · 0.85