freenode
AI & ML

PyTorch ONNX verify can miss NaN output mismatches

The export checker silently accepts NaN disagreements and rejects matching empty tensors.

PyTorch's ONNX export verification can report success when model outputs disagree on NaN, and it can fail when two empty results are identical.

The verify option on torch.onnx.export is meant to catch cases where an exported graph does not match the original PyTorch model. Comparing a NaN with a finite value produces a non-numeric difference, and the threshold checks never treat that as a failure, so the discrepancy is accepted. The same comparison returns infinity for two matching empty tensors, so verification rejects outputs that actually agree.

A contributor, dragonxia-ctrl, reproduced both behaviors on a CPU nightly build and offered to compare NaN positions explicitly, treat matching empty outputs as equal, and fail when the reported difference is not a finite number. They asked maintainers whether a mismatch should warn or raise an error before submitting the change. Testing so far is CPU-only, which covers these paths.

Developers who treat a passing verify run as proof that an ONNX export matches PyTorch can therefore ship a silent numeric mismatch, or chase a false failure on empty outputs.