[pytorch][mobile] make sure mobile build work with dynamic dispatch#34038
Closed
ljk53 wants to merge 4 commits intogh/ljk53/109/basefrom
Closed
[pytorch][mobile] make sure mobile build work with dynamic dispatch#34038ljk53 wants to merge 4 commits intogh/ljk53/109/basefrom
ljk53 wants to merge 4 commits intogh/ljk53/109/basefrom
Conversation
Summary: Mobile build doesn't include autograd/VariableType dispatch. As the result AutoNonVariableTypeMode needs to be set in mobile runtime. With static dispatch this works is done inside generated jit-dispatch code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting it globally or setting it for wrong ops might break some `is_variable()` checks in the codebase. Thanks to the unification of Variable class and Tensor class, all is_variable() checks have been removed, so AutoNonVariableTypeMode can be set globally now. We never tested inference-only mobile build with dynamic dispatch. It seems that dynamic dispatch also requires setting AutoNonVariableTypeMode for our mobile build (where VariableType functions are not registered). Verified the end-to-end test works with this change: ``` TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh ``` [ghstack-poisoned]
ljk53
added a commit
that referenced
this pull request
Mar 1, 2020
Summary: Mobile build doesn't include autograd/VariableType dispatch. As the result AutoNonVariableTypeMode needs to be set in mobile runtime. With static dispatch this works is done inside generated jit-dispatch code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting it globally or setting it for wrong ops might break some `is_variable()` checks in the codebase. Thanks to the unification of Variable class and Tensor class, all is_variable() checks have been removed, so AutoNonVariableTypeMode can be set globally now. We never tested inference-only mobile build with dynamic dispatch. It seems that dynamic dispatch also requires setting AutoNonVariableTypeMode for our mobile build (where VariableType functions are not registered). Verified the end-to-end test works with this change: ``` TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh ``` ghstack-source-id: bf23a44 Pull Request resolved: #34038
💊 CircleCI build failures summary and remediationsAs of commit d67b04d (more details on the Dr. CI page): Commit d67b04d was recently pushed. Waiting for builds... This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 8 times. |
… dispatch" Summary: Mobile build doesn't include autograd/VariableType dispatch. As the result AutoNonVariableTypeMode needs to be set in mobile runtime. With static dispatch this works is done inside generated jit-dispatch code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting it globally or setting it for wrong ops might break some `is_variable()` checks in the codebase. Thanks to the unification of Variable class and Tensor class, all is_variable() checks have been removed, so AutoNonVariableTypeMode can be set globally now. We never tested inference-only mobile build with dynamic dispatch. It seems that dynamic dispatch also requires setting AutoNonVariableTypeMode for our mobile build (where VariableType functions are not registered). Verified the end-to-end test works with this change: ``` TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh ``` [ghstack-poisoned]
ezyang
approved these changes
Mar 2, 2020
… dispatch" Summary: Mobile build doesn't include autograd/VariableType dispatch. As the result AutoNonVariableTypeMode needs to be set in mobile runtime. With static dispatch this works is done inside generated jit-dispatch code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting it globally or setting it for wrong ops might break some `is_variable()` checks in the codebase. Thanks to the unification of Variable class and Tensor class, all is_variable() checks have been removed, so AutoNonVariableTypeMode can be set globally now. We never tested inference-only mobile build with dynamic dispatch. It seems that dynamic dispatch also requires setting AutoNonVariableTypeMode for our mobile build (where VariableType functions are not registered). Verified the end-to-end test works with this change: ``` TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh ``` Differential Revision: [D20193329](https://our.internmc.facebook.com/intern/diff/D20193329) [ghstack-poisoned]
… dispatch" Summary: Mobile build doesn't include autograd/VariableType dispatch. As the result AutoNonVariableTypeMode needs to be set in mobile runtime. With static dispatch this works is done inside generated jit-dispatch code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting it globally or setting it for wrong ops might break some `is_variable()` checks in the codebase. Thanks to the unification of Variable class and Tensor class, all is_variable() checks have been removed, so AutoNonVariableTypeMode can be set globally now. We never tested inference-only mobile build with dynamic dispatch. It seems that dynamic dispatch also requires setting AutoNonVariableTypeMode for our mobile build (where VariableType functions are not registered). Verified the end-to-end test works with this change: ``` TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh ``` Differential Revision: [D20193329](https://our.internmc.facebook.com/intern/diff/D20193329) [ghstack-poisoned]
Contributor
ttumiel
pushed a commit
to ttumiel/pytorch
that referenced
this pull request
Mar 4, 2020
…ytorch#34038) Summary: Pull Request resolved: pytorch#34038 Mobile build doesn't include autograd/VariableType dispatch. As the result AutoNonVariableTypeMode needs to be set in mobile runtime. With static dispatch this works is done inside generated jit-dispatch code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting it globally or setting it for wrong ops might break some `is_variable()` checks in the codebase. Thanks to the unification of Variable class and Tensor class, all is_variable() checks have been removed, so AutoNonVariableTypeMode can be set globally now. We never tested inference-only mobile build with dynamic dispatch. It seems that dynamic dispatch also requires setting AutoNonVariableTypeMode for our mobile build (where VariableType functions are not registered). Verified the end-to-end test works with this change: ``` TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh ``` Test Plan: Imported from OSS Differential Revision: D20193329 Pulled By: ljk53 fbshipit-source-id: cc98414d89d12463dc82b0cdde0b6160dafc0349
ljk53
added a commit
to ljk53/pytorch
that referenced
this pull request
Mar 9, 2020
…ytorch#34038) Summary: Pull Request resolved: pytorch#34038 Mobile build doesn't include autograd/VariableType dispatch. As the result AutoNonVariableTypeMode needs to be set in mobile runtime. With static dispatch this works is done inside generated jit-dispatch code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting it globally or setting it for wrong ops might break some `is_variable()` checks in the codebase. Thanks to the unification of Variable class and Tensor class, all is_variable() checks have been removed, so AutoNonVariableTypeMode can be set globally now. We never tested inference-only mobile build with dynamic dispatch. It seems that dynamic dispatch also requires setting AutoNonVariableTypeMode for our mobile build (where VariableType functions are not registered). Verified the end-to-end test works with this change: ``` TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh ``` Test Plan: Imported from OSS Differential Revision: D20193329 Pulled By: ljk53 fbshipit-source-id: cc98414d89d12463dc82b0cdde0b6160dafc0349
ljk53
added a commit
that referenced
this pull request
Mar 18, 2020
… mobile callsites There are three guards related to mobile build: * AutoGradMode * AutoNonVariableTypeMode * GraphOptimizerEnabledGuard Today we need set some of these guards before calling libtorch APIs because we customized mobile build to only support inference (for both OSS and most FB use cases) to optimize binary size. Several changes were made since 1.3 release so there are already inconsistent uses of these guards in the codebase. I did a sweep of all mobile related model loading & forward() call sites, trying to unify the use of these guards: Full JIT: still set all three guards. More specifically: * OSS: Fixed a bug of not setting the guard at model load time correctly in Android JNI. * FB: Not covered by this diff (as we are using mobile interpreter for most internal builds). Lite JIT (mobile interpreter): only needs AutoNonVariableTypeMode guard. AutoGradMode doesn't seem to be relevant (so removed from a few places) and GraphOptimizerEnabledGuard definitely not relevant (only full JIT has graph optimizer). More specifically: * OSS: At this point we are not committed to support Lite-JIT. For Android it shares the same code with FB JNI callsites. * FB: ** JNI callsites: Use the unified LiteJITCallGuard. ** For iOS/C++: manually set AutoNonVariableTypeMode for _load_for_mobile() & forward() callsites. Ideally we should avoid having to set AutoNonVariableTypeMode for mobile interpreter. It's currently needed for dynamic dispatch + inference-only mobile build (where variable kernels are not registered) - without the guard it will try to run `variable_fallback_kernel` and crash (PR #34038). The proper fix will take some time so using this workaround to unblock selective BUCK build which depends on dynamic dispatch. PS. The current status (of having to set AutoNonVariableTypeMode) should not block running FL model + mobile interpreter - if all necessary variable kernels are registered then it can call _load_for_mobile()/forward() against the FL model without setting the AutoNonVariableTypeMode guard. It's still inconvenient for JAVA callsites as it's set unconditionally inside JNI methods. Differential Revision: [D20498017](https://our.internmc.facebook.com/intern/diff/D20498017/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D20498017/)! [ghstack-poisoned]
ljk53
added a commit
that referenced
this pull request
Mar 18, 2020
… mobile callsites There are three guards related to mobile build: * AutoGradMode * AutoNonVariableTypeMode * GraphOptimizerEnabledGuard Today we need set some of these guards before calling libtorch APIs because we customized mobile build to only support inference (for both OSS and most FB use cases) to optimize binary size. Several changes were made since 1.3 release so there are already inconsistent uses of these guards in the codebase. I did a sweep of all mobile related model loading & forward() call sites, trying to unify the use of these guards: Full JIT: still set all three guards. More specifically: * OSS: Fixed a bug of not setting the guard at model load time correctly in Android JNI. * FB: Not covered by this diff (as we are using mobile interpreter for most internal builds). Lite JIT (mobile interpreter): only needs AutoNonVariableTypeMode guard. AutoGradMode doesn't seem to be relevant (so removed from a few places) and GraphOptimizerEnabledGuard definitely not relevant (only full JIT has graph optimizer). More specifically: * OSS: At this point we are not committed to support Lite-JIT. For Android it shares the same code with FB JNI callsites. * FB: ** JNI callsites: Use the unified LiteJITCallGuard. ** For iOS/C++: manually set AutoNonVariableTypeMode for _load_for_mobile() & forward() callsites. Ideally we should avoid having to set AutoNonVariableTypeMode for mobile interpreter. It's currently needed for dynamic dispatch + inference-only mobile build (where variable kernels are not registered) - without the guard it will try to run `variable_fallback_kernel` and crash (PR #34038). The proper fix will take some time so using this workaround to unblock selective BUCK build which depends on dynamic dispatch. PS. The current status (of having to set AutoNonVariableTypeMode) should not block running FL model + mobile interpreter - if all necessary variable kernels are registered then it can call _load_for_mobile()/forward() against the FL model without setting the AutoNonVariableTypeMode guard. It's still inconvenient for JAVA callsites as it's set unconditionally inside JNI methods. Differential Revision: [D20498017](https://our.internmc.facebook.com/intern/diff/D20498017/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D20498017/)! ghstack-source-id: 100385440 Pull Request resolved: #34958
facebook-github-bot
pushed a commit
that referenced
this pull request
Mar 19, 2020
… mobile callsites Summary: There are three guards related to mobile build: * AutoGradMode * AutoNonVariableTypeMode * GraphOptimizerEnabledGuard Today we need set some of these guards before calling libtorch APIs because we customized mobile build to only support inference (for both OSS and most FB use cases) to optimize binary size. Several changes were made since 1.3 release so there are already inconsistent uses of these guards in the codebase. I did a sweep of all mobile related model loading & forward() call sites, trying to unify the use of these guards: Full JIT: still set all three guards. More specifically: * OSS: Fixed a bug of not setting the guard at model load time correctly in Android JNI. * FB: Not covered by this diff (as we are using mobile interpreter for most internal builds). Lite JIT (mobile interpreter): only needs AutoNonVariableTypeMode guard. AutoGradMode doesn't seem to be relevant (so removed from a few places) and GraphOptimizerEnabledGuard definitely not relevant (only full JIT has graph optimizer). More specifically: * OSS: At this point we are not committed to support Lite-JIT. For Android it shares the same code with FB JNI callsites. * FB: ** JNI callsites: Use the unified LiteJITCallGuard. ** For iOS/C++: manually set AutoNonVariableTypeMode for _load_for_mobile() & forward() callsites. Ideally we should avoid having to set AutoNonVariableTypeMode for mobile interpreter. It's currently needed for dynamic dispatch + inference-only mobile build (where variable kernels are not registered) - without the guard it will try to run `variable_fallback_kernel` and crash (PR #34038). The proper fix will take some time so using this workaround to unblock selective BUCK build which depends on dynamic dispatch. PS. The current status (of having to set AutoNonVariableTypeMode) should not block running FL model + mobile interpreter - if all necessary variable kernels are registered then it can call _load_for_mobile()/forward() against the FL model without setting the AutoNonVariableTypeMode guard. It's still inconvenient for JAVA callsites as it's set unconditionally inside JNI methods. Test Plan: - CI Reviewed By: xta0 Differential Revision: D20498017 fbshipit-source-id: ba6740f66839a61790873df46e8e66e4e141c728
laurentdupin
pushed a commit
to laurentdupin/pytorch
that referenced
this pull request
Apr 24, 2026
…ytorch#34038) Summary: Pull Request resolved: pytorch#34038 Mobile build doesn't include autograd/VariableType dispatch. As the result AutoNonVariableTypeMode needs to be set in mobile runtime. With static dispatch this works is done inside generated jit-dispatch code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting it globally or setting it for wrong ops might break some `is_variable()` checks in the codebase. Thanks to the unification of Variable class and Tensor class, all is_variable() checks have been removed, so AutoNonVariableTypeMode can be set globally now. We never tested inference-only mobile build with dynamic dispatch. It seems that dynamic dispatch also requires setting AutoNonVariableTypeMode for our mobile build (where VariableType functions are not registered). Verified the end-to-end test works with this change: ``` TEST_CUSTOM_BUILD_DYNAMIC=1 test/mobile/custom_build/build.sh ``` Test Plan: Imported from OSS Differential Revision: D20193329 Pulled By: ljk53 fbshipit-source-id: cc98414d89d12463dc82b0cdde0b6160dafc0349
laurentdupin
pushed a commit
to laurentdupin/pytorch
that referenced
this pull request
Apr 24, 2026
… mobile callsites Summary: There are three guards related to mobile build: * AutoGradMode * AutoNonVariableTypeMode * GraphOptimizerEnabledGuard Today we need set some of these guards before calling libtorch APIs because we customized mobile build to only support inference (for both OSS and most FB use cases) to optimize binary size. Several changes were made since 1.3 release so there are already inconsistent uses of these guards in the codebase. I did a sweep of all mobile related model loading & forward() call sites, trying to unify the use of these guards: Full JIT: still set all three guards. More specifically: * OSS: Fixed a bug of not setting the guard at model load time correctly in Android JNI. * FB: Not covered by this diff (as we are using mobile interpreter for most internal builds). Lite JIT (mobile interpreter): only needs AutoNonVariableTypeMode guard. AutoGradMode doesn't seem to be relevant (so removed from a few places) and GraphOptimizerEnabledGuard definitely not relevant (only full JIT has graph optimizer). More specifically: * OSS: At this point we are not committed to support Lite-JIT. For Android it shares the same code with FB JNI callsites. * FB: ** JNI callsites: Use the unified LiteJITCallGuard. ** For iOS/C++: manually set AutoNonVariableTypeMode for _load_for_mobile() & forward() callsites. Ideally we should avoid having to set AutoNonVariableTypeMode for mobile interpreter. It's currently needed for dynamic dispatch + inference-only mobile build (where variable kernels are not registered) - without the guard it will try to run `variable_fallback_kernel` and crash (PR pytorch#34038). The proper fix will take some time so using this workaround to unblock selective BUCK build which depends on dynamic dispatch. PS. The current status (of having to set AutoNonVariableTypeMode) should not block running FL model + mobile interpreter - if all necessary variable kernels are registered then it can call _load_for_mobile()/forward() against the FL model without setting the AutoNonVariableTypeMode guard. It's still inconvenient for JAVA callsites as it's set unconditionally inside JNI methods. Test Plan: - CI Reviewed By: xta0 Differential Revision: D20498017 fbshipit-source-id: ba6740f66839a61790873df46e8e66e4e141c728
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
Sign up for free
to 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.
Stack from ghstack:
Summary:
Mobile build doesn't include autograd/VariableType dispatch. As the
result AutoNonVariableTypeMode needs to be set in mobile runtime.
With static dispatch this works is done inside generated jit-dispatch
code - AutoNonVariableTypeMode needs to be set on per-op basis. Setting
it globally or setting it for wrong ops might break some
is_variable()checks in the codebase.
Thanks to the unification of Variable class and Tensor class, all
is_variable() checks have been removed, so AutoNonVariableTypeMode can
be set globally now.
We never tested inference-only mobile build with dynamic dispatch. It
seems that dynamic dispatch also requires setting AutoNonVariableTypeMode
for our mobile build (where VariableType functions are not registered).
Verified the end-to-end test works with this change:
Differential Revision: D20193329