snnlab.sim.accelerator_forward
Complete declared API of the accelerator_forward module, with signatures, data fields, validation and source.
Bounded forward-only accelerator validation. This check compares graph and legacy forward outputs on the same accelerator under an explicit tolerance policy; it does not cover training, checkpoint trajectories or cross-device equality.
The signatures, defaults, fields, docstrings and implementation excerpts below are generated from the Python source. Annotations are shown as declared; unannotated means the source supplies no type annotation. These pages document callable surfaces, including legacy support utilities, without promising backend support for every declaration.
| Symbol | Kind |
|---|---|
| ForwardAcceleratorResult | class |
| run_forward_accelerator_check | function |
| main | function |
ForwardAcceleratorResult
Result record for the bounded forward accelerator fixture and its conformance report.
Class decorators: dataclass(frozen=True).
Dataclass constructor parameters. Factory defaults are shown as field declarations; omit these arguments to create fresh values per instance:
ForwardAcceleratorResult(device: str, snnlang_reproducibility: ConformanceReport, legacy_graph_parity: ConformanceReport)Declared fields, including fields inherited from local data classes:
| Field | Annotation | Default | Meaning |
|---|---|---|---|
device | str | required | Requested or resolved tensor execution device. |
snnlang_reproducibility | ConformanceReport | required | Stored member of this data contract; see the class docstring and serialization methods. |
legacy_graph_parity | ConformanceReport | required | Stored member of this data contract; see the class docstring and serialization methods. |
ForwardAcceleratorResult.passed
Decorators: property.
def ForwardAcceleratorResult.passed(self) -> boolReturn annotation: bool.
Return expressions (branch-dependent; names refer to the linked implementation):
self.snnlang_reproducibility.passed and self.legacy_graph_parity.passedImplementation
def passed(self) -> bool:
return self.snnlang_reproducibility.passed and self.legacy_graph_parity.passedForwardAcceleratorResult.to_dict
def ForwardAcceleratorResult.to_dict(self) -> dict[str, Any]Return annotation: dict[str, Any].
Return expressions (branch-dependent; names refer to the linked implementation):
{'device': self.device, 'passed': self.passed, 'tolerances': {'atol': ATOL, 'rtol': RTOL}, 'snnlang_reproducibility': self.snnlang_reproducibility.to_dict(), 'legacy_graph_parity': self.legacy_graph_parity.to_dict()}Implementation
def to_dict(self) -> dict[str, Any]:
return {
"device": self.device,
"passed": self.passed,
"tolerances": {"atol": ATOL, "rtol": RTOL},
"snnlang_reproducibility": self.snnlang_reproducibility.to_dict(),
"legacy_graph_parity": self.legacy_graph_parity.to_dict(),
}ForwardAcceleratorResult.require_passed
def ForwardAcceleratorResult.require_passed(self) -> NoneReturn annotation: None.
Implementation
def require_passed(self) -> None:
self.snnlang_reproducibility.require_passed()
self.legacy_graph_parity.require_passed()Complete class implementation
class ForwardAcceleratorResult:
device: str
snnlang_reproducibility: ConformanceReport
legacy_graph_parity: ConformanceReport
@property
def passed(self) -> bool:
return self.snnlang_reproducibility.passed and self.legacy_graph_parity.passed
def to_dict(self) -> dict[str, Any]:
return {
"device": self.device,
"passed": self.passed,
"tolerances": {"atol": ATOL, "rtol": RTOL},
"snnlang_reproducibility": self.snnlang_reproducibility.to_dict(),
"legacy_graph_parity": self.legacy_graph_parity.to_dict(),
}
def require_passed(self) -> None:
self.snnlang_reproducibility.require_passed()
self.legacy_graph_parity.require_passed()run_forward_accelerator_check
def run_forward_accelerator_check(device: str) -> ForwardAcceleratorResultRun the bounded graph/legacy forward conformance fixture on the selected accelerator and return its named comparison report.
| Parameter | Annotation | Default | Meaning |
|---|---|---|---|
device | str | required | Requested or resolved tensor execution device. |
Return annotation: ForwardAcceleratorResult.
Return expressions (branch-dependent; names refer to the linked implementation):
ForwardAcceleratorResult(device=str(resolved), snnlang_reproducibility=reproducibility, legacy_graph_parity=parity)Explicit exceptions in this implementation; called helpers may raise additional errors:
| Explicit exception expression |
|---|
ValueError('MPS was requested but is unavailable') |
ValueError('CUDA was requested but is unavailable') |
ValueError(f'accelerator device expected mps or cuda, got {device!r}') |
Implementation
def run_forward_accelerator_check(device: str) -> ForwardAcceleratorResult:
resolved = torch.device(device)
if resolved.type == "mps" and not torch.backends.mps.is_available():
raise ValueError("MPS was requested but is unavailable")
if resolved.type == "cuda" and not torch.cuda.is_available():
raise ValueError("CUDA was requested but is unavailable")
if resolved.type not in {"mps", "cuda"}:
raise ValueError(f"accelerator device expected mps or cuda, got {device!r}")
with tempfile.TemporaryDirectory(prefix="snnlang-forward-") as scratch:
root = Path(scratch)
first = _subprocess_forward("graph", device, root / "graph-first.pt")
second = _subprocess_forward("graph", device, root / "graph-second.pt")
legacy = _subprocess_forward("legacy", device, root / "legacy.pt")
reproducibility = compare_conformance_layers(
"snnlang-same-accelerator-forward",
{"forward": first},
{"forward": second},
policies=_policies(first),
)
parity = compare_conformance_layers(
"legacy-snnlang-same-accelerator-forward",
{"forward": legacy},
{"forward": first},
policies=_policies(legacy),
)
return ForwardAcceleratorResult(
device=str(resolved),
snnlang_reproducibility=reproducibility,
legacy_graph_parity=parity,
)main
def main() -> NoneCommand entry point for the bounded accelerator validation utility.
Return annotation: None.
Return expressions (branch-dependent; names refer to the linked implementation):
NoneImplementation
def main() -> None:
parser = argparse.ArgumentParser(
description="Check graph repeatability and legacy parity for one forward PING case."
)
parser.add_argument("--device", required=True, choices=("mps", "cuda"))
parser.add_argument("--worker", choices=("graph", "legacy"), help=argparse.SUPPRESS)
parser.add_argument("--output", type=Path, help=argparse.SUPPRESS)
args = parser.parse_args()
if args.worker:
if args.output is None:
parser.error("--worker requires --output")
_run_worker(args.worker, args.device, args.output)
return
if args.output is not None:
parser.error("--output requires --worker")
result = run_forward_accelerator_check(args.device)
print(json.dumps(result.to_dict(), indent=2, sort_keys=True))
result.require_passed()Constants and type aliases
Initial source expressions are shown, not evaluated runtime values. Legacy configuration may mutate module defaults.