even better more structured throughput scheduling
Validate Operations / validate-operations (push) Has been cancelled
Validate Operations / validate-operations (push) Has been cancelled
plot adjustments validation adjustments
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from dataclasses import dataclass
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
VALIDATION_POLICY = "pointwise-and-relative-l2-v1"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class OutputComparison:
|
||||
passed: bool
|
||||
max_abs_diff: float
|
||||
relative_l2_error: float | None
|
||||
pointwise_passed: bool
|
||||
|
||||
|
||||
def compare_output_arrays(actual, expected, *, atol, rtol):
|
||||
"""Require pointwise tolerance and relative L2 tolerance for nonzero outputs."""
|
||||
if any(not math.isfinite(value) or value < 0 for value in (atol, rtol)):
|
||||
raise ValueError("output tolerances must be finite and non-negative")
|
||||
actual, expected = np.asarray(actual), np.asarray(expected)
|
||||
if actual.dtype.kind not in "biuf" or expected.dtype.kind not in "biuf":
|
||||
raise ValueError("output comparison requires real numeric arrays")
|
||||
if actual.shape != expected.shape:
|
||||
raise ValueError(f"output shapes differ: {actual.shape} != {expected.shape}")
|
||||
if not actual.size:
|
||||
return OutputComparison(True, 0.0, None, True)
|
||||
if not np.all(np.isfinite(actual)) or not np.all(np.isfinite(expected)):
|
||||
return OutputComparison(False, math.inf, None, False)
|
||||
if expected.dtype.kind in "biu":
|
||||
difference = np.abs(actual.astype(object) - expected.astype(object))
|
||||
passed = bool(np.array_equal(actual, expected))
|
||||
return OutputComparison(passed, float(difference.max()), None, passed)
|
||||
actual, expected = actual.astype(np.float64), expected.astype(np.float64)
|
||||
with np.errstate(over="ignore", invalid="ignore", divide="ignore"):
|
||||
difference = np.abs(actual - expected)
|
||||
pointwise = bool(np.all(difference <= atol + rtol * np.abs(expected)))
|
||||
scale = float(np.max(np.abs(expected)))
|
||||
relative = (float(np.linalg.norm(difference / scale) /
|
||||
np.linalg.norm(expected / scale)) if scale else None)
|
||||
# A zero reference has no relative scale. rtol=0 explicitly requests absolute-only checks.
|
||||
relative_passed = relative is None or rtol == 0 or relative <= rtol
|
||||
return OutputComparison(pointwise and relative_passed, float(difference.max()), relative, pointwise)
|
||||
@@ -10,11 +10,7 @@ MODELS = {
|
||||
"vgg8": SUITE / "vgg8/vgg8-mnist-reconstructed.onnx",
|
||||
"resnet18": SUITE / "resnet18/resnet18-v1-7.onnx",
|
||||
"resnet34": SUITE / "resnet34/resnet34-v1-7.onnx",
|
||||
"googlenet": SUITE / "googlenet/googlenet-12-pimsim-nn.onnx",
|
||||
"yolo11n": SUITE / "yolo11n/yolo11n-pimsim-nn.onnx",
|
||||
}
|
||||
FUNCTIONAL_MODELS = {
|
||||
**MODELS,
|
||||
"googlenet": SUITE / "googlenet/googlenet-12-no-lrn.onnx",
|
||||
"yolo11n": REPO / "validation/networks/yolo11n/depth_51/yolo11n_depth_51.onnx",
|
||||
}
|
||||
MODEL_NAMES = tuple(MODELS)
|
||||
|
||||
@@ -27,6 +27,12 @@ def read_raptor_instruction_count(path):
|
||||
|
||||
def parse_pimsim_nn_metrics(output):
|
||||
metrics = {"raw_output": output}
|
||||
if "using legacy full-duration throughput result" in output:
|
||||
metrics["fast_throughput_converged"] = False
|
||||
metrics["throughput_measurement"] = "full_duration_fallback"
|
||||
elif "Fast throughput converged; stopping early" in output:
|
||||
metrics["fast_throughput_converged"] = True
|
||||
metrics["throughput_measurement"] = "converged_windows"
|
||||
for name, pattern in _METRIC_PATTERNS.items():
|
||||
match = re.search(pattern, output)
|
||||
if match:
|
||||
|
||||
@@ -24,6 +24,7 @@ from .onnx_utils import (
|
||||
from .raptor import compile_with_raptor
|
||||
from .pimsim_nn import export_raptor_pimsim_artifact, parse_pimsim_nn_metrics, read_raptor_instruction_count
|
||||
from .subprocess_utils import run_command_with_reporter
|
||||
from .output_comparison import compare_output_arrays
|
||||
|
||||
STAGE_TITLES = (
|
||||
"Compile ONNX",
|
||||
@@ -465,34 +466,35 @@ def parse_pim_simulator_outputs(output_bin_path, outputs_descriptor):
|
||||
|
||||
|
||||
def validate_outputs(sim_arrays, runner_out_dir, outputs_descriptor, threshold, rtol, verbose):
|
||||
if len(sim_arrays) != len(outputs_descriptor):
|
||||
raise ValueError("simulator output count differs from the model output count")
|
||||
all_passed = True
|
||||
rows = []
|
||||
for sim_array, (oi, name, _, shape) in zip(sim_arrays, outputs_descriptor):
|
||||
for sim_array, (oi, name, elem_type, shape) in zip(sim_arrays, outputs_descriptor):
|
||||
csv_name = f"output{oi}_{sanitize_output_name(name)}.csv"
|
||||
runner_array = np.loadtxt(runner_out_dir / csv_name, delimiter=',', dtype=np.float32).reshape(shape)
|
||||
sim_array64 = sim_array.astype(np.float64)
|
||||
runner_array64 = runner_array.astype(np.float64)
|
||||
abs_diff = np.abs(sim_array64 - runner_array64)
|
||||
allowed_diff = threshold + rtol * np.abs(runner_array64)
|
||||
max_diff = float(np.max(abs_diff))
|
||||
passed = bool(np.all(abs_diff <= allowed_diff))
|
||||
rows.append((name, f"{max_diff:.6e}", passed))
|
||||
runner_array = np.loadtxt(runner_out_dir / csv_name, delimiter=',', dtype=_ONNX_TO_NP[elem_type]).reshape(shape)
|
||||
comparison = compare_output_arrays(sim_array, runner_array, atol=threshold, rtol=rtol)
|
||||
passed = comparison.passed
|
||||
relative = comparison.relative_l2_error
|
||||
rows.append((name, f"{comparison.max_abs_diff:.6e}",
|
||||
f"{relative:.6e}" if relative is not None else "N/A", passed))
|
||||
if not passed:
|
||||
all_passed = False
|
||||
|
||||
name_width = max(len("Output"), *(len(name) for name, _, _ in rows))
|
||||
diff_width = max(len("Max diff"), *(len(diff) for _, diff, _ in rows))
|
||||
name_width = max(len("Output"), *(len(name) for name, _, _, _ in rows))
|
||||
diff_width = max(len("Max diff"), *(len(diff) for _, diff, _, _ in rows))
|
||||
relative_width = max(len("Relative L2"), *(len(relative) for _, _, relative, _ in rows))
|
||||
result_width = len("Result")
|
||||
separator = f" +-{'-' * name_width}-+-{'-' * diff_width}-+-{'-' * result_width}-+"
|
||||
separator = f" +-{'-' * name_width}-+-{'-' * diff_width}-+-{'-' * relative_width}-+-{'-' * result_width}-+"
|
||||
|
||||
if verbose or not all_passed:
|
||||
print(separator)
|
||||
print(f" | {'Output'.ljust(name_width)} | {'Max diff'.ljust(diff_width)} | {'Result'} |")
|
||||
print(f" | {'Output'.ljust(name_width)} | {'Max diff'.ljust(diff_width)} | {'Relative L2'.ljust(relative_width)} | {'Result'} |")
|
||||
print(separator)
|
||||
for name, diff_text, passed in rows:
|
||||
for name, diff_text, relative, passed in rows:
|
||||
status_text = ("PASS" if passed else "FAIL").ljust(result_width)
|
||||
status = Fore.GREEN + status_text + Style.RESET_ALL if passed else Fore.RED + status_text + Style.RESET_ALL
|
||||
print(f" | {name.ljust(name_width)} | {diff_text.ljust(diff_width)} | {status} |")
|
||||
print(f" | {name.ljust(name_width)} | {diff_text.ljust(diff_width)} | {relative.ljust(relative_width)} | {status} |")
|
||||
print(separator)
|
||||
return all_passed
|
||||
|
||||
@@ -577,10 +579,9 @@ def validate_execution(
|
||||
f"Latency: {state['metrics']['latency_ms']:.2f} ms"
|
||||
if name == "latency" else
|
||||
f"Throughput: {state['metrics']['throughput']:.2f} samples/s")
|
||||
energy_unit = "pJ" if name == "latency" else "pJ/it"
|
||||
print_info(
|
||||
reporter, f"{metric}, Power: {state['metrics']['average_power_mw']:.2f} mW, "
|
||||
f"Energy: {state['metrics']['average_energy_pj']:.2f} {energy_unit}")
|
||||
reporter, f"{metric}, Average power: {state['metrics']['average_power_mw']:.2f} mW, "
|
||||
f"Energy per inference: {state['metrics']['average_energy_pj']:.2f} pJ/inference")
|
||||
except PimSimUnsupportedError as exc:
|
||||
state["pimsim_status"] = PIMSIM_UNSUPPORTED
|
||||
print_info(reporter, str(exc))
|
||||
|
||||
Reference in New Issue
Block a user