Skip to content

Vulkan: serialize non-finite floats using flatc's spelling - #22307

Open
msluszniak wants to merge 1 commit into
pytorch:mainfrom
msluszniak:ms/vulkan-serialize-nonfinite-floats
Open

Vulkan: serialize non-finite floats using flatc's spelling#22307
msluszniak wants to merge 1 commit into
pytorch:mainfrom
msluszniak:ms/vulkan-serialize-nonfinite-floats

Conversation

@msluszniak

@msluszniak msluszniak commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #22305.

The Vulkan graph is serialized by dumping it to JSON with Python's json module and handing that to flatc. The two disagree on how to spell the non-finite floats: Python emits Infinity / -Infinity / NaN, and flatc accepts none of them. Any model whose graph carries a non-finite scalar therefore fails to lower, with the -inf fill value of a transformer attention mask being the common source. all-MiniLM-L6-v2 and CLIP ViT-B/32 both partition cleanly and then die with:

schema.json:1: 6012: error: cannot parse value starting with: -

which names a byte offset inside a deleted temporary file and points at nothing in the model.

flatc does accept inf and -inf (checked against flatc 24.3.25; nan, NaN, infinity are all rejected), so the infinities round-trip exactly. The decompile direction needs the inverse rewrite, since flatc writes bare inf tokens that json.load will not parse; string literals are stepped over so a shader or key name containing "inf" is left alone. FlatBuffers JSON has no spelling for NaN at all, so that case raises with a message naming the problem rather than emitting JSON flatc cannot read.

Test plan

Three new cases in backends/vulkan/test/test_serialization.py: an exact round-trip of -inf / inf / a finite value, the NaN error, and a string literal containing "inf" surviving the decode rewrite untouched.

pytest backends/vulkan/test/test_serialization.py
7 passed

Verified end to end that sentence-transformers/all-MiniLM-L6-v2 now lowers through VulkanPartitioner (14 delegate blobs, 3/3 runs at PYTHONHASHSEED=0), where before it failed 3/3.

cc @SS-JIA @manuelcandales @digantdesai @cbilgin

The Vulkan graph is serialized by dumping it to JSON with Python's json
module and handing that to flatc. The two disagree on how to spell the
non-finite floats: Python emits Infinity / -Infinity / NaN, and flatc
accepts none of them. Any model whose graph carries a non-finite scalar
therefore fails to lower, with the -inf fill value of a transformer
attention mask being the common source. all-MiniLM-L6-v2 and CLIP
ViT-B/32 both partition cleanly and then die here:

  schema.json:1: 6012: error: cannot parse value starting with: -

The error points at a byte offset inside a temporary file, so nothing
connects it back to the model.

flatc does accept "inf" and "-inf", so emit those. The decompile
direction needs the inverse rewrite, since flatc writes bare inf tokens
that json.load will not parse; string literals are stepped over so a
shader or key name containing "inf" is left alone. FlatBuffers JSON has
no spelling for NaN at all, so raise there rather than emitting JSON
that flatc cannot read.

Adds round-trip coverage for the infinities, the NaN error, and the
string-literal case.
@msluszniak
msluszniak requested a review from SS-JIA as a code owner August 29, 2026 14:27
@pytorch-bot pytorch-bot Bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label Aug 29, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 15 Awaiting Approval

As of commit a581771 with merge base c27baa8 (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 Aug 29, 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.

msluszniak added a commit to software-mansion-labs/executorch that referenced this pull request Aug 30, 2026
vulkan_graph_serialize.py: the flatc JSON dialect has no spelling for
Python's Infinity/NaN, so a graph carrying a non-finite float failed to
serialize. Emit inf/-inf the way flatc parses them, and reject NaN
explicitly rather than writing something flatc cannot read back.

utils.py: OpRepSets used num_tensors_in_node() == 1 to decide that
meta["val"] is a bare FakeTensor, but that helper counts tensors rather
than nesting, so an op declared to return Tensor[] that happens to
produce exactly one lands there with a one-element list and crashes the
partitioner. Unwrap it.

Backports of upstream pytorch/executorch#22307 and #22308.
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. module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Vulkan] Cannot serialize a graph containing a non-finite float, so attention-mask models never lower

2 participants