Add file size check: reject oversized .onnx before validation, --strict_size stops run on violation
Browse files
neurogolf_solver/validators.py
CHANGED
|
@@ -1,14 +1,22 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""Model validation utilities."""
|
| 3 |
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import onnxruntime as ort
|
| 6 |
from .data_loader import to_onehot
|
| 7 |
-
from .constants import MAX_ARCGEN_VALIDATE
|
| 8 |
|
| 9 |
|
| 10 |
def validate(path, td, providers):
|
| 11 |
-
"""Validate ONNX model against task data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
opts = ort.SessionOptions()
|
| 14 |
opts.log_severity_level = 3
|
|
@@ -33,6 +41,9 @@ def validate(path, td, providers):
|
|
| 33 |
|
| 34 |
def validate_raw(raw_bytes, td, providers):
|
| 35 |
"""Validate ONNX model from raw bytes."""
|
|
|
|
|
|
|
|
|
|
| 36 |
try:
|
| 37 |
opts = ort.SessionOptions()
|
| 38 |
opts.log_severity_level = 3
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""Model validation utilities."""
|
| 3 |
|
| 4 |
+
import os
|
| 5 |
import numpy as np
|
| 6 |
import onnxruntime as ort
|
| 7 |
from .data_loader import to_onehot
|
| 8 |
+
from .constants import MAX_ARCGEN_VALIDATE, MAX_ONNX_FILESIZE
|
| 9 |
|
| 10 |
|
| 11 |
def validate(path, td, providers):
|
| 12 |
+
"""Validate ONNX model against task data.
|
| 13 |
+
Returns False immediately if file exceeds 1.44MB."""
|
| 14 |
+
# Size check FIRST — before wasting time on inference
|
| 15 |
+
try:
|
| 16 |
+
if os.path.getsize(path) > MAX_ONNX_FILESIZE:
|
| 17 |
+
return False
|
| 18 |
+
except OSError:
|
| 19 |
+
return False
|
| 20 |
try:
|
| 21 |
opts = ort.SessionOptions()
|
| 22 |
opts.log_severity_level = 3
|
|
|
|
| 41 |
|
| 42 |
def validate_raw(raw_bytes, td, providers):
|
| 43 |
"""Validate ONNX model from raw bytes."""
|
| 44 |
+
# Size check
|
| 45 |
+
if len(raw_bytes) > MAX_ONNX_FILESIZE:
|
| 46 |
+
return False
|
| 47 |
try:
|
| 48 |
opts = ort.SessionOptions()
|
| 49 |
opts.log_severity_level = 3
|