Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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/base
base:gh/zhxchen17/6/base
Choose a base branch
Loading
fromgh/zhxchen17/6/head

Conversation

@zhxchen17
Copy link
Contributor

@zhxchen17zhxchen17 commentedDec 19, 2025
edited by pytorch-botbot
Loading

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:

  1. torch.nn.Module
  2. Nested functions.

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:

result: AOTCompileSaveResult = compiled_fn.save_compiled_function("/path")

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.

torch.compiler.load_compiled_function(f, external_data={...})

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

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]
@pytorch-bot
Copy link

pytorch-botbot commentedDec 19, 2025
edited
Loading

🔗 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 (image):

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:#170846
@zhxchen17zhxchen17 added the topic: not user facingtopic category labelDec 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.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:#170846
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@bobrenjc93bobrenjc93Awaiting requested review from bobrenjc93

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@zhxchen17

[8]ページ先頭

©2009-2025 Movatter.jp