Skip to content

Read non-finite float values back from an ETDump - #22785

Open
Dev-next-gen wants to merge 1 commit into
pytorch:mainfrom
Dev-next-gen:etdump-non-finite-floats
Open

Read non-finite float values back from an ETDump#22785
Dev-next-gen wants to merge 1 commit into
pytorch:mainfrom
Dev-next-gen:etdump-non-finite-floats

Conversation

@Dev-next-gen

Copy link
Copy Markdown

Summary

I tried to round-trip an ETDump whose debug event holds a -inf double, and deserialize_from_etdump_flatcc failed with json.decoder.JSONDecodeError: Expecting value. The same happens for inf, nan, and for a Float value. A finite value round-trips fine.

The function turns the binary into JSON with flatc --json --strict-json and parses that with json.loads. flatc writes non-finite values as bare tokens: "double_val": -inf, inf, nan, and -nan when the sign bit is set (which is what 0.0 / 0.0 gives on x86). json.loads only understands Infinity, -Infinity and NaN, so a single non-finite value anywhere in the dump makes the whole file unreadable. The runtime logs double and float EValues into debug events as they are, so an attention mask filled with -inf or a NaN intermediate is enough for the Inspector to be unable to load the ETDump, which is the moment you most want to look at it.

The serialize direction already works since #22152, so this only touches the read side: before parsing, the flatc tokens are rewritten into the spellings json.loads accepts. String literals are matched first and copied through, so an event or run named "inf" or "nan" is left untouched. Nothing else calls _deserialize_from_json_to_etdump_flatcc, and JSON without those tokens is unchanged.

Test plan

I added test_serialize_non_finite_floats to devtools/etdump/tests/serialize_test.py. It puts inf in the Float and -inf in the Double of the sample dump and checks the round trip is equal, then checks a nan double comes back as NaN.

python -m unittest executorch.devtools.etdump.tests.serialize_test -v

Without the fix the new test errors with JSONDecodeError: Expecting value: line 81 column 30; with it both tests pass (flatc 24.3.25 built from the pinned third-party/flatbuffers commit, Python 3.12, Linux). Separately I patched a negative NaN (0xFFF8000000000000) into a serialized dump, checked flatc prints it as -nan, and confirmed it now reads back as NaN, and that event names "inf" and "nan" survive the rewrite. I did not run lintrunner locally.

This PR was written with the help of Claude Code.

deserialize_from_etdump_flatcc turns the binary into JSON with flatc and
then parses it with json.loads. flatc writes non-finite float and double
values as bare inf, -inf, nan and -nan, and json.loads accepts none of
those, so an ETDump holding a single infinite or NaN value raised
JSONDecodeError and the Inspector could not load it. The runtime logs
double and float EValues into debug events as they are, so a -inf mask
fill or a NaN output is enough to hit this.

Rewrite those tokens into the Infinity, -Infinity and NaN spellings
json.loads does accept before parsing, leaving string literals alone.
@pytorch-bot

pytorch-bot Bot commented Sep 13, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22785

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 14 Awaiting Approval

As of commit f35c68b with merge base 903696a (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 13, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants