Skip to content

exir: serialize non-finite floats in a form flatc accepts - #22152

Draft
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:vulkan-inf-serialization
Draft

exir: serialize non-finite floats in a form flatc accepts#22152
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:vulkan-inf-serialization

Conversation

@psiddh

@psiddh psiddh commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Python's json module emits Infinity, -Infinity, and NaN for non-finite floats. Those literals are a Python extension rather than JSON, and flatc's parser rejects them, so any delegate graph holding a non-finite constant failed to serialize with an opaque flatc returned non-zero exit status 1.

This blocked Vulkan/WebGPU export for every causal-decoder LLM: the attention mask is built with a -inf fill, the partitioner claims the aten.full that carries it, and the value reaches the graph as a Double. It is independent of quantization mode, since the mask stays fp32 regardless of weight width.

flatc does accept the quoted forms "inf", "-inf", and "nan" for float fields, so the value was representable all along. Rewrite non-finite values into those before invoking flatc. _replace_infinity_in_json_file already does this on the decompile side for program.fbs; the compile side had no equivalent, and needs a different token because it sees Python's spelling rather than flatc's.

Fixing this in the shared _flatc_compile rather than in Vulkan's serializer covers the six backends that build flatbuffers by piping json.dumps output through flatc. Only Vulkan is confirmed to hit it today; the rest partition different op sets, so treat them as latent. Content with no non-finite values is returned unchanged and its file is left untouched, so the common path is unaffected. The rewrite parses the JSON instead of pattern-matching its text, which avoids corrupting string fields that happen to contain "Infinity".

Authored with assistance from Claude Code.

Python's json module emits `Infinity`, `-Infinity`, and `NaN` for non-finite
floats. Those literals are a Python extension rather than JSON, and flatc's
parser rejects them, so any delegate graph holding a non-finite constant failed
to serialize with an opaque `flatc returned non-zero exit status 1`.

This blocked Vulkan/WebGPU export for every causal-decoder LLM: the attention
mask is built with a -inf fill, the partitioner claims the `aten.full` that
carries it, and the value reaches the graph as a Double. It is independent of
quantization mode, since the mask stays fp32 regardless of weight width.

flatc does accept the quoted forms "inf", "-inf", and "nan" for float fields,
so the value was representable all along. Rewrite non-finite values into those
before invoking flatc. `_replace_infinity_in_json_file` already does this on
the decompile side for program.fbs; the compile side had no equivalent, and
needs a different token because it sees Python's spelling rather than flatc's.

Fixing this in the shared `_flatc_compile` rather than in Vulkan's serializer
covers the six backends that build flatbuffers by piping json.dumps output
through flatc. Only Vulkan is confirmed to hit it today; the rest partition
different op sets, so treat them as latent. Content with no non-finite values
is returned unchanged and its file is left untouched, so the common path is
unaffected. The rewrite parses the JSON instead of pattern-matching its text,
which avoids corrupting string fields that happen to contain "Infinity".

Authored with assistance from Claude Code.
@pytorch-bot

pytorch-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 Cancelled Job

As of commit 20bea3b with merge base baafd7e (image):

CANCELLED JOB - The following job was cancelled. Please retry:

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 Aug 25, 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.

1 participant