Skip to content

Conversation

larryliu0820
Copy link
Contributor

This pull request introduces significant changes to how model constants (weights) are packaged and loaded in the CUDA backend, improving modularity and flexibility. It also updates the runner APIs to support more flexible loading modes and bumps PyTorch commit pins and nightly version references.

Packaging and Loading Model Constants:

  • Model constants are now separated from the .so file and stored as a binary blob on disk, rather than being packaged directly into the shared object. The preprocessing logic in cuda_backend.py is updated to handle the new file outputs and manage cleanup. [1] [2]
  • The C++ CUDA backend (cuda_backend.cpp) now loads the new weights blob from the named data map and feeds it into the model container using a newly added API function. The buffer is freed immediately after use for better resource management. [1] [2]

API and Infrastructure Updates:

  • A new function pointer type, AOTInductorModelUpdateConstantsFromBlobFunc, is added to the delegate handle structure in aoti_delegate_handle.h to support updating model constants from a binary blob. [1] [2]
  • The CUDA backend now loads this new symbol from the shared object at runtime.

Runner API Improvements:

  • The multimodal runner API is updated to accept a Module::LoadMode parameter, allowing for more flexible loading options such as memory mapping. This change is propagated through helper functions and their headers. [1] [2] [3] [4]

Dependency Updates:

  • The PyTorch commit pin is updated in .ci/docker/ci_commit_pins/pytorch.txt and the nightly version is bumped in torch_pin.py for compatibility with the new packaging logic. [1] [2]

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 16, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure, 77 Pending, 1 Unrelated Failure

As of commit 989def3 with merge base 4cff294 (image):

NEW FAILURE - The following job has failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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 Oct 16, 2025
@larryliu0820 larryliu0820 added the release notes: desktop for desktop/laptop workstream label Oct 16, 2025
raise RuntimeError(
f"Could not find .wrapper.so file in compiled paths, got {paths}"
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if existence/non-existence of blob_path matches the options

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only check for blob_path is None if package_constant_on_disk_format option is set to "binary_blob"

@larryliu0820 larryliu0820 marked this pull request as ready for review October 16, 2025 06:08
Comment on lines +179 to +184
// Feed the weights blob into the container. Under the hood it's copying
// weights, so we should free the buffer immediately.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the weights are mmapped, so this isn't halving the maximum amount of weights we can handle, right? even so, seems unfortunate that we have to copy and therefore can't keep them simply mmapped though; peak CPU memory now needs to hold them, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't halving the maximum amount of weights we can handle, right?

Good point, let me test this on my RTX 5080.

seems unfortunate that we have to copy and therefore can't keep them simply mmapped though

Yeah would be good if aoti can just take it without copying.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah would be good if aoti can just take it without copying.

I might be missing something here, but I assume you're mmaping into the CPU memory right? AOTI copies it into the CUDA memory, and since we're running this on CUDA, we have to copy it to CUDA some time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a mmap equivalent on CUDA? If so, on ET side we can create a dataloader to directly load into CUDA memory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can use GPUDirect Storage.

@larryliu0820 larryliu0820 force-pushed the aoti_option_2 branch 3 times, most recently from 8caec09 to a443c08 Compare October 17, 2025 17:25
@larryliu0820 larryliu0820 merged commit 0673d86 into main Oct 17, 2025
284 of 294 checks passed
@larryliu0820 larryliu0820 deleted the aoti_option_2 branch October 17, 2025 20:05
JacobSzwejbka pushed a commit that referenced this pull request Oct 18, 2025
This pull request introduces significant changes to how model constants
(weights) are packaged and loaded in the CUDA backend, improving
modularity and flexibility. It also updates the runner APIs to support
more flexible loading modes and bumps PyTorch commit pins and nightly
version references.

**Packaging and Loading Model Constants:**

* Model constants are now separated from the `.so` file and stored as a
binary blob on disk, rather than being packaged directly into the shared
object. The preprocessing logic in `cuda_backend.py` is updated to
handle the new file outputs and manage cleanup.
[[1]](diffhunk://#diff-5b5ea2257772b3aba04b2534f5ea1429a0c631bfd25a7ef531f526e76c471d7aL149-R153)
[[2]](diffhunk://#diff-5b5ea2257772b3aba04b2534f5ea1429a0c631bfd25a7ef531f526e76c471d7aL165-R211)
* The C++ CUDA backend (`cuda_backend.cpp`) now loads the new weights
blob from the named data map and feeds it into the model container using
a newly added API function. The buffer is freed immediately after use
for better resource management.
[[1]](diffhunk://#diff-a4b17eccf1aa933837671c5184e02bc815d934a362344bb2b17b789cdfaa5375R153-R154)
[[2]](diffhunk://#diff-a4b17eccf1aa933837671c5184e02bc815d934a362344bb2b17b789cdfaa5375R183-R195)

**API and Infrastructure Updates:**

* A new function pointer type,
`AOTInductorModelUpdateConstantsFromBlobFunc`, is added to the delegate
handle structure in `aoti_delegate_handle.h` to support updating model
constants from a binary blob.
[[1]](diffhunk://#diff-0598c198d53bf756f6013186ea3155f15ddef247aa863e83ef30f27991b3a0a7R74-R78)
[[2]](diffhunk://#diff-0598c198d53bf756f6013186ea3155f15ddef247aa863e83ef30f27991b3a0a7R95)
* The CUDA backend now loads this new symbol from the shared object at
runtime.

**Runner API Improvements:**

* The multimodal runner API is updated to accept a `Module::LoadMode`
parameter, allowing for more flexible loading options such as memory
mapping. This change is propagated through helper functions and their
headers.
[[1]](diffhunk://#diff-0ac16dbe4eaefa08e21fbda582fe2cd2b482f43aaedfc1bf2f31becf5e7bb843L322-R322)
[[2]](diffhunk://#diff-005ac94c6b217e02d652aafc206d36b2ec1190af36aa0a632fd406975dfc2600L271-R272)
[[3]](diffhunk://#diff-005ac94c6b217e02d652aafc206d36b2ec1190af36aa0a632fd406975dfc2600L281-R284)
[[4]](diffhunk://#diff-ac7a381a7828a6f1a543d2beab4cf503c2d3547ab86821c8e1777df9305108aaL143-R144)

**Dependency Updates:**

* The PyTorch commit pin is updated in
`.ci/docker/ci_commit_pins/pytorch.txt` and the nightly version is
bumped in `torch_pin.py` for compatibility with the new packaging logic.
[[1]](diffhunk://#diff-e873e85ae7aa52ebeadb13a27cf83eff1891b1011e27f94ec040eb8407893c5eL1-R1)
[[2]](diffhunk://#diff-9665391232bd21d4ee0a293cbc7f76d99db902ab1e6e045a59f9a132325babc9L2-R2)
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. release notes: desktop for desktop/laptop workstream

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants