- Notifications
You must be signed in to change notification settings - Fork26.3k
[precompile] Support external data for serialization.#170846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
zhxchen17 wants to merge2 commits intogh/zhxchen17/6/baseChoose a base branch fromgh/zhxchen17/6/head
base:gh/zhxchen17/6/base
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+179 −12
Conversation
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
Under some corner cases, users don't directly pass us a free functionor module.forward. Instead, there're multiple levels of wrappers andcaptured closures applied to module.forward, so we end up serialzing quitea few captured data from the compiled function's closure. This is not greatwhen things like torch.nn.Module end up being captured in function's closure,and we shouldn't serialize the whole module in this case.To solve this issue, we specially handle the common cases when the followingobjects are being saved:1. torch.nn.Module2. Nested functions.When these data are being serialized, we will mark these as "external data"since they may contain unserialzable and untrackable states which isusually easier to be maintained from user side. So the a call to save_compiled_function()looks like the following:```result: AOTCompileSaveResult = compiled_fn.save_compiled_function("/path")```On the loading side, user are supposed to provide the external data dict. If any keyis missing, load_compiled_function will throw an error.```torch.compiler.load_compiled_function(f, external_data={...})```Note that it's not ideal for user to compile a typical function like this, so thisis only meant for power users for whom rewriting model is harder than maintainingthis data map.[ghstack-poisoned] This was referencedDec 19, 2025
pytorch-botbot commentedDec 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
🔗 Helpful Links🧪 See artifacts and rendered test results athud.pytorch.org/pr/170846
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (3 Unrelated Failures)As of commit50513d7 with merge basec0ffe54 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but was present on the merge base:👉Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
zhxchen17 added a commit that referenced this pull requestDec 19, 2025
Under some corner cases, users don't directly pass us a free functionor module.forward. Instead, there're multiple levels of wrappers andcaptured closures applied to module.forward, so we end up serialzing quitea few captured data from the compiled function's closure. This is not greatwhen things like torch.nn.Module end up being captured in function's closure,and we shouldn't serialize the whole module in this case.To solve this issue, we specially handle the common cases when the followingobjects are being saved:1. torch.nn.Module2. Nested functions.When these data are being serialized, we will mark these as "external data"since they may contain unserialzable and untrackable states which isusually easier to be maintained from user side. So the a call to save_compiled_function()looks like the following:```result: AOTCompileSaveResult = compiled_fn.save_compiled_function("/path")```On the loading side, user are supposed to provide the external data dict. If any keyis missing, load_compiled_function will throw an error.```torch.compiler.load_compiled_function(f, external_data={...})```Note that it's not ideal for user to compile a typical function like this, so thisis only meant for power users for whom rewriting model is harder than maintainingthis data map.ghstack-source-id:ce464f5Pull Requestresolved:#170846Under some corner cases, users don't directly pass us a free functionor module.forward. Instead, there're multiple levels of wrappers andcaptured closures applied to module.forward, so we end up serialzing quitea few captured data from the compiled function's closure. This is not greatwhen things like torch.nn.Module end up being captured in function's closure,and we shouldn't serialize the whole module in this case.To solve this issue, we specially handle the common cases when the followingobjects are being saved:1. torch.nn.Module2. Nested functions.When these data are being serialized, we will mark these as "external data"since they may contain unserialzable and untrackable states which isusually easier to be maintained from user side. So the a call to save_compiled_function()looks like the following:```result: AOTCompileSaveResult = compiled_fn.save_compiled_function("/path")```On the loading side, user are supposed to provide the external data dict. If any keyis missing, load_compiled_function will throw an error.```torch.compiler.load_compiled_function(f, external_data={...})```Note that it's not ideal for user to compile a typical function like this, so thisis only meant for power users for whom rewriting model is harder than maintainingthis data map.cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo[ghstack-poisoned]zhxchen17 added a commit that referenced this pull requestDec 19, 2025
Under some corner cases, users don't directly pass us a free functionor module.forward. Instead, there're multiple levels of wrappers andcaptured closures applied to module.forward, so we end up serialzing quitea few captured data from the compiled function's closure. This is not greatwhen things like torch.nn.Module end up being captured in function's closure,and we shouldn't serialize the whole module in this case.To solve this issue, we specially handle the common cases when the followingobjects are being saved:1. torch.nn.Module2. Nested functions.When these data are being serialized, we will mark these as "external data"since they may contain unserialzable and untrackable states which isusually easier to be maintained from user side. So the a call to save_compiled_function()looks like the following:```result: AOTCompileSaveResult = compiled_fn.save_compiled_function("/path")```On the loading side, user are supposed to provide the external data dict. If any keyis missing, load_compiled_function will throw an error.```torch.compiler.load_compiled_function(f, external_data={...})```Note that it's not ideal for user to compile a typical function like this, so thisis only meant for power users for whom rewriting model is harder than maintainingthis data map.ghstack-source-id:a393674Pull Requestresolved:#170846Sign up for freeto 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.
Uh oh!
There was an error while loading.Please reload this page.
Stack fromghstack (oldest at bottom):
Under some corner cases, users don't directly pass us a free function
or module.forward. Instead, there're multiple levels of wrappers and
captured closures applied to module.forward, so we end up serialzing quite
a few captured data from the compiled function's closure. This is not great
when things like torch.nn.Module end up being captured in function's closure,
and we shouldn't serialize the whole module in this case.
To solve this issue, we specially handle the common cases when the following
objects are being saved:
When these data are being serialized, we will mark these as "external data"
since they may contain unserialzable and untrackable states which is
usually easier to be maintained from user side. So the a call to save_compiled_function()
looks like the following:
On the loading side, user are supposed to provide the external data dict. If any key
is missing, load_compiled_function will throw an error.
Note that it's not ideal for user to compile a typical function like this, so this
is only meant for power users for whom rewriting model is harder than maintaining
this data map.
cc@voznesenskym@penguinwu@EikanWang@jgong5@Guobing-Chen@XiaobingSuper@zhuhaozhe@blzheng@wenzhe-nrv@jiayisunx@kadeng@chauhang@amjames@Lucaskabela@jataylo