exir: serialize non-finite floats in a form flatc accepts - #22152
Draft
psiddh wants to merge 1 commit into
Draft
Conversation
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.
🔗 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 JobAs of commit 20bea3b with merge base baafd7e ( CANCELLED JOB - The following job was cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python's json module emits
Infinity,-Infinity, andNaNfor 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 opaqueflatc 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.fullthat 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_filealready 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_compilerather 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.