Skip to content

[executorch][cuda] Write a weight storage the methods share only once - #23950

Merged
Gasoonjia merged 1 commit into
gh/Gasoonjia/53/origfrom
gh/Gasoonjia/54/orig
Oct 18, 2026
Merged

Gasoonjia merged 1 commit into
gh/Gasoonjia/53/origfrom
gh/Gasoonjia/54/orig

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #23738 by @Gasoonjia
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/Gasoonjia/54/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/Gasoonjia/54/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/Gasoonjia/53/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/Gasoonjia/54/orig
Differential Revision: D124713681
@diff-train-skip-merge

Pull Request resolved: #23738

A multi-method CUDA export compiles every method against one `CudaWeightCollector`, so a storage the methods share (all of the model's weights, for a batching export) is stored under one `cuda_fqn_weight:<device>:<FQN>` key. But every method's `materialize` still copied each storage from the GPU to the host in 8 MB chunks, SHA-256'd it on one core, and wrote it to a temp file; only then did the `NamedDataStore` drop the duplicate. For an 18 GB model that is ~90 s per method (measured on 2 GiB: copy 1.9 s, SHA-256 5.9 s, write 1.3 s), all of it thrown away after the first method.

The collector now remembers a fingerprint of each CUDA storage it has written, by storage key. A later method's storage under the same key is fingerprinted on the GPU first; if it matches, its write is skipped and the method's manifest points at the stored entry. Otherwise it is written and added exactly as before, so a changed storage still fails with the store's "Duplicate key ... with different data".

The fingerprint is the storage's size, two independent random linear hashes of its 8-byte words (int64, chunk order kept significant) and its trailing bytes: ~0.8 s for 18 GB on an A100, and a single flipped bit changes it. Library-local constants (`_tensor_constant*`, keyed per shared library), off-graph KV entries and CPU storages keep the existing path.

Full Muse Glimmer 30B batching export (`export_solo_batching.py`, 10 methods; A100; empty Triton and Inductor caches), stacked on D124496888:

| | before | this diff |
|---|---|---|
| total | 135.1 min | 125.7 min |
| main thread in `cuda_weight_collector` | ~21.4 min | ~7.7 min |
| per method after the first (AOTI), min | 13.2 / 13.3 / 9.7 / 12.3 / 14.5 / 19.0 / 10.6 / 2.6 | 13.6 / 12.1 / 8.3 / 11.3 / 13.2 / 17.0 / 8.9 / 1.0 |

(forward_2 .. forward_64, forward_others, sample. forward_1 writes everything once, as before.) Most of what is left in later methods is the collector's `trim_host_memory` (`gc.collect` + `malloc_trim`).

The weight file is byte-identical with and without this diff (`aoti_cuda_blob.ptd`, 17,856,903,936 bytes, same SHA-256), and so is every method's weight manifest; only the methods' compiled libraries differ, as between any two cold exports. The export generates the same tokens (greedy, a 512-token prompt and 4 x 2k prompts) at the same speed (62.5 vs 62.7 tok/s; 110.0 vs 111.3).
ghstack-source-id: 451021040
@exported-using-ghexport

Differential Revision: [D124713681](https://our.internmc.facebook.com/intern/diff/D124713681/)
@pytorch-bot

pytorch-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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

@Gasoonjia
Gasoonjia added this pull request to stack #23954 October 18, 2026 07:47
@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 Oct 18, 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.

@Gasoonjia
Gasoonjia merged commit c0c1693 into main Oct 18, 2026
266 of 273 checks passed
@Gasoonjia
Gasoonjia deleted the gh/Gasoonjia/54/orig branch October 18, 2026 07:49
@pytorchbot
pytorchbot deployed to upload-benchmark-results October 18, 2026 10:11 — with GitHub Actions Active

This branch was successfully deployed

2 active deployments
upload-benchmark-results — 6bbf8d4c Deployed Oct 18, 2026 by pytorchbot via upload-benchmark-results #20985
cadence — 6bbf8d4c Deployed Oct 18, 2026 by pytorchbot via hifi-op-test / hifi4 #33966
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.

2 participants