rogermt commited on
Commit
9e704d4
·
verified ·
1 Parent(s): 1963657

Fix 1: profiler.py — remove silent fallback, loud warning when onnx_tool missing

Browse files
Files changed (1) hide show
  1. neurogolf_solver/profiler.py +33 -8
neurogolf_solver/profiler.py CHANGED
@@ -1,5 +1,11 @@
1
  #!/usr/bin/env python3
2
- """Static profiling for ONNX models."""
 
 
 
 
 
 
3
 
4
  import onnx
5
  from onnx import numpy_helper
@@ -11,19 +17,36 @@ try:
11
  except ImportError:
12
  HAS_ONNX_TOOL = False
13
 
 
 
14
 
15
  def score_network(path):
16
- """Score network using official tool or fallback."""
 
 
 
 
 
17
  if HAS_ONNX_TOOL:
 
18
  try:
19
- return _score_network_official(path)
20
- except:
21
- pass
22
- return _static_profile(path)
 
 
 
 
 
 
 
 
23
 
24
 
25
  def _static_profile(path):
26
- """Static profiling fallback."""
 
27
  try:
28
  model = onnx.load(path)
29
  except:
@@ -49,7 +72,9 @@ def _static_profile(path):
49
  nbytes += a.nbytes
50
  except:
51
  pass
52
- if nd.op_type in BANNED_OPS:
 
 
53
  return None, None, None
54
  if nd.op_type == 'Conv' and len(nd.input) >= 2 and nd.input[1] in tensors:
55
  w = tensors[nd.input[1]]
 
1
  #!/usr/bin/env python3
2
+ """Static profiling for ONNX models.
3
+
4
+ Uses neurogolf_utils.score_network() (onnx_tool) when available — this is
5
+ the ONLY scoring that matches Kaggle. The static fallback is approximate
6
+ and prints a WARNING. If onnx_tool returns (None, None, None), the model
7
+ is REJECTED — do not submit it.
8
+ """
9
 
10
  import onnx
11
  from onnx import numpy_helper
 
17
  except ImportError:
18
  HAS_ONNX_TOOL = False
19
 
20
+ _WARNED_NO_ONNX_TOOL = False
21
+
22
 
23
  def score_network(path):
24
+ """Score network. Returns (macs, memory, params) or (None, None, None).
25
+
26
+ If onnx_tool is available: uses official scorer. (None,None,None) = REJECTED.
27
+ If onnx_tool is NOT available: uses static fallback with WARNING.
28
+ """
29
+ global _WARNED_NO_ONNX_TOOL
30
  if HAS_ONNX_TOOL:
31
+ # Official scorer — trust its result. Do NOT catch exceptions silently.
32
  try:
33
+ result = _score_network_official(path)
34
+ except Exception as e:
35
+ print(f"WARNING: onnx_tool score_network failed on {path}: {e}")
36
+ return None, None, None
37
+ return result
38
+ else:
39
+ if not _WARNED_NO_ONNX_TOOL:
40
+ print("WARNING: onnx_tool not installed. Scores are APPROXIMATE and may not match Kaggle.")
41
+ print("WARNING: Models that fail onnx_tool profiling will be REJECTED on Kaggle.")
42
+ print("WARNING: Run neurogolf_utils.verify_network() in a Kaggle notebook before submitting.")
43
+ _WARNED_NO_ONNX_TOOL = True
44
+ return _static_profile(path)
45
 
46
 
47
  def _static_profile(path):
48
+ """Static profiling fallback. APPROXIMATE — does not match Kaggle scoring.
49
+ Only used when onnx_tool is not installed."""
50
  try:
51
  model = onnx.load(path)
52
  except:
 
72
  nbytes += a.nbytes
73
  except:
74
  pass
75
+ # Banned op check — UPPERCASE to match Kaggle
76
+ if nd.op_type.upper() in {op.upper() for op in BANNED_OPS}:
77
+ print(f"WARNING: Banned op '{nd.op_type}' found in {path}")
78
  return None, None, None
79
  if nd.op_type == 'Conv' and len(nd.input) >= 2 and nd.input[1] in tensors:
80
  w = tensors[nd.input[1]]