Vulkan: size texture-vs-buffer choice by the bound, not the trace hint - #22401
Open
msluszniak wants to merge 1 commit into
Open
Vulkan: size texture-vs-buffer choice by the bound, not the trace hint#22401msluszniak wants to merge 1 commit into
msluszniak wants to merge 1 commit into
Conversation
filter_invalid_reprs() decides whether a tensor can live in a texture by comparing required_image_extents(tensor_val.shape) against the device limits. For a symbolic dimension that comparison resolves at the dim's *hint* -- the size of the example the model happened to be traced with -- rather than the maximum its exported range allows. So a model traced with a small example picks a texture that is only valid at that size, and silently produces wrong results once it runs larger. Nothing raises. Repro: the Supertonic TTS text encoder, dynamic T in [8, 512], always executed at T=512 on a Galaxy S26 Ultra (Adreno 840). Only the trace-time example length differs; the edge graphs are identical (552 nodes, same ops, same literal args, same symbolic shapes): traced at T= 64 cosine 0.537966 .pte 18147970 bytes traced at T=128 cosine 0.537966 .pte 18147970 bytes (identical file) traced at T=192 cosine 0.999414 .pte 18149890 bytes traced at T=512 cosine 0.999414 .pte 18149890 bytes (identical file) The emitted binaries cluster exactly on the correctness boundary, which is what identifies this as a lowering decision rather than a bad kernel. With this change the T=64 export emits the 18149890-byte artifact and scores 0.999414. Evaluating the bound instead also covers the unbounded case: a dim with no finite upper bound cannot be shown to fit any texture, so it falls back to buffer storage. Measured on Supertonic (CPU reference reproduced by the XNNPACK delegate at cosine 1.000000): text_encoder 0.406303 -> 0.999414 vector_estimator 0.994432 -> 0.999994 vocoder 0.016757 -> 0.999977
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22401
Note: Links to docs will display an error until the docs builds have been completed.
|
msluszniak
added a commit
to software-mansion-labs/executorch
that referenced
this pull request
Sep 1, 2026
Backport of pytorch/executorch#22401. filter_invalid_reprs() compares required_image_extents(tensor_val.shape) against the device texture limits. For a symbolic dim that resolves at the dim's HINT (the example the model was traced with), not the maximum its range allows, so a model traced with a small example picks a texture only valid at that size and silently computes garbage when run larger. Supertonic text encoder, dynamic T in [8,512], always run at T=512, identical edge graphs (552 nodes, zero differing args): traced T=64/128 cosine 0.537966 traced T=192+ cosine 0.999414 With the fix the T=64 export matches T=192+ exactly. Combined with the clamp guard, on S26 Ultra vs a CPU reference XNNPACK reproduces at 1.000000: text_encoder 0.406303 -> 0.999414 vector_estimator 0.994432 -> 0.999994 vocoder 0.016757 -> 0.999977
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.
Summary
filter_invalid_reprs()decides whether a tensor can live in a texture by comparingrequired_image_extents(tensor_val.shape)against the device limits. For a symbolic dimension that comparison resolves at the dim's hint -- the size of the example the model happened to be traced with -- rather than the maximum its exported range allows.A model traced with a small example therefore picks a texture that is only valid at that size, and silently produces wrong results once it runs larger. Nothing raises.
This matters in practice because exporters conventionally trace with a small example input while declaring a large dynamic max, so the failing combination is the common one.
Reproduction
The Supertonic TTS text encoder (
Supertone/supertonic-3), dynamicTin[8, 512], always executed at T=512 on a Galaxy S26 Ultra (Adreno 840). Only the trace-time example length differs, and the edge graphs are identical -- 552call_functionnodes, same ops, same literal args, same symbolic shapes, zero differing nodes:The emitted binaries cluster exactly on the correctness boundary, which is what identifies this as a lowering decision rather than a bad kernel. With this change the T=64 export emits the 18149890-byte artifact and scores 0.999414.
Evaluating the bound also handles the unbounded case: a dim with no finite upper bound cannot be shown to fit any texture, so it falls back to buffer storage.
Test plan
Measured on Supertonic sub-models, against a CPU reference that the XNNPACK delegate reproduces at cosine 1.000000:
Partitioner/lowering-side only, so no runtime rebuild is needed to reproduce the failure or the fix.
Note: the vocoder and vector_estimator numbers above also require #22399 (clamp with a symbolic bound), which is an instance of the same underlying theme -- a value derived from a dynamic dimension being read once at build time. This PR is independent of that one and touches a different file.
cc @SS-JIA @manuelcandales @digantdesai @cbilgin