Skip to content

[executorch][native-vulkan] Run bf16 methods in f32 on the Vulkan engine - #25095

Open
digantdesai wants to merge 1 commit into
gh/digantdesai/211/basefrom
gh/digantdesai/211/head
Open

digantdesai wants to merge 1 commit into
gh/digantdesai/211/basefrom
gh/digantdesai/211/head

Conversation

@digantdesai

@digantdesai digantdesai commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

ET-VK has no bf16 storage, so the Native Vulkan engine rejected every bf16 method when it compiled. It now runs them in f32 on the device, the way it already runs int64 as int32. device_dtype maps BFloat16 to Float, and bf16 constants are widened to f32 host copies at load, next to the int64 narrowing. The method still reports bf16 from input_dtype and output_dtype, so callers pass and receive bf16 as before.

A bf16 tensor holds bf16 values at the host boundary whatever the host dtype: set_input rounds BFloat16 or Float host data to bf16, and get_output rounds the f32 result to the nearest bf16 before writing BFloat16 or Float. Other host dtypes are rejected. Between ops, values stay f32, so a method with several ops skips the bf16 rounding eager applies after each one, and its results match eager within bf16 tolerance rather than exactly. For example, (1 + 2^-8) - 1 returns 2^-8, where eager returns 0.

Every widened constant stays on the heap until prepack releases it, so loading a bf16 model needs about twice its bf16 weight size in extra host memory.

Memory planning now sizes each request by its device dtype, which doubles bf16 requests and halves int64 ones. ET-VK sizes each shared object from the tensors bound to it, so this only keeps the planner's ordering consistent with the device sizes. buffer_attention_fits also counts SDPA attention weights at the device element size, so a bf16 attention no longer picks buffer storage up to twice the storage buffer limit.

LowerRMSNorm also accepts bf16 norms, which now run the f32 et_vk.rms_norm kernel. Quantized linears and embeddings with bf16 scales still fail, because FuseQuantizedLinear and FuseQuantizedEmbedding match only f32 and f16 scales.

Authored with Claude Code.

Differential Revision: D131119348

NOTE FOR REVIEWERS: This PR has internal Meta-specific changes or comments, please review them on Phabricator!

[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label Nov 14, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures

As of commit 1e7adcb with merge base 925c1bd (image):

NEW FAILURES - The following jobs have failed:

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

@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.

This branch was previously deployed

1 inactive deployment
cadence — 1e7adcba Deployed Nov 14, 2026 by digantdesai via hifi-op-test / hifi4 #38410
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. meta-exported 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.

1 participant