Skip to content

Implement public API InferenceMode and its error handling#55008

Closed
ailzhang wants to merge 1 commit intopytorch:masterfrom
ailzhang:export-D27443229
Closed

Implement public API InferenceMode and its error handling#55008
ailzhang wants to merge 1 commit intopytorch:masterfrom
ailzhang:export-D27443229

Conversation

@ailzhang
Copy link
Contributor

@ailzhang ailzhang commented Mar 30, 2021

Summary:
Pull Request resolved: #53343

For easier review, here's a diff between the version before revert. https://www.internalfb.com/phabricator/paste/view/P363902707

Test Plan: Imported from OSS

Differential Revision: D27443229

Pulled By: ailzhang

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Mar 30, 2021

💊 CI failures summary and remediations

As of commit e2a7069 (more details on the Dr. CI page):


  • 3/3 failures possibly* introduced in this PR
    • 1/3 non-scanned failure(s)

🕵️ 1 new failure recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See CircleCI build pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-build-x86_32 (1/1)

Step: "pytorch android gradle build only x86_32 (for PR)" (full log | diagnosis details | 🔁 rerun)

Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
Mar 31 08:01:30 2021-03-31T08:01:12.988+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant android-jni attribute artifactType value {artifactType=android-jni, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant android-lint attribute artifactType value {artifactType=android-lint, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant android-manifest attribute artifactType value {artifactType=android-manifest, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant android-navigation-json attribute artifactType value {artifactType=android-navigation-json, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant android-public-res attribute artifactType value {artifactType=android-public-res, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant android-res attribute artifactType value {artifactType=android-res, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant android-symbol attribute artifactType value {artifactType=android-symbol, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant android-symbol-with-package-name attribute artifactType value {artifactType=android-symbol-with-package-name, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.LoggingAttributeMatchingExplanationBuilder] Candidate configuration ':pytorch_android:releaseRuntimeElements' variant jar attribute artifactType value {artifactType=jar, com.android.build.api.attributes.BuildTypeAttr=release, com.android.build.api.attributes.VariantAttr=release, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime} doesn't requested value android-classes-jar
Mar 31 08:01:30 2021-03-31T08:01:12.989+0000 [DEBUG] [org.gradle.internal.component.model.ComponentAttributeMatcher] Selected matches [configuration ':pytorch_android:releaseRuntimeElements' variant android-classes-jar] from candidates [configuration ':pytorch_android:releaseRuntimeElements' variant android-aar-metadata, configuration ':pytorch_android:releaseRuntimeElements' variant android-assets, configuration ':pytorch_android:releaseRuntimeElements' variant android-classes-directory, configuration ':pytorch_android:releaseRuntimeElements' variant android-classes-jar, configuration ':pytorch_android:releaseRuntimeElements' variant android-compiled-dependencies-resources, configuration ':pytorch_android:releaseRuntimeElements' variant android-consumer-proguard-rules, configuration ':pytorch_android:releaseRuntimeElements' variant android-java-res, configuration ':pytorch_android:releaseRuntimeElements' variant android-jni, configuration ':pytorch_android:releaseRuntimeElements' variant android-lint, configuration ':pytorch_android:releaseRuntimeElements' variant android-manifest, configuration ':pytorch_android:releaseRuntimeElements' variant android-navigation-json, configuration ':pytorch_android:releaseRuntimeElements' variant android-public-res, configuration ':pytorch_android:releaseRuntimeElements' variant android-res, configuration ':pytorch_android:releaseRuntimeElements' variant android-symbol, configuration ':pytorch_android:releaseRuntimeElements' variant android-symbol-with-package-name, configuration ':pytorch_android:releaseRuntimeElements' variant jar] for {artifactType=android-classes-jar, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debug2021-03-31T08:01:13.422+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Could not determine the dependencies of task ':test_app:lintVitalResnet18LocalBaseRelease'.
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not resolve all artifacts for configuration ':test_app:mnetLocalBaseDebugAndroidTestCompileClasspath'.
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]    > Could not resolve com.facebook.soloader:nativeloader:0.8.0.
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Required by:
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]          project :test_app
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]       > No cached version of com.facebook.soloader:nativeloader:0.8.0 available for offline mode.
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]       > No cached version of com.facebook.soloader:nativeloader:0.8.0 available for offline mode.
Mar 31 08:01:30 2021-03-31T08:01:13.423+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]       > No cached version of com.facebook.soloader:nativeloader:0.8.0 available for offline mode.

1 failure not recognized by patterns:

Job Step Action
GitHub Actions quick-checks Ensure correct trailing newlines 🔁 rerun

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 to the (internal) Dr. CI Users group.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D27443229

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D27443229

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D27443229

@ailzhang ailzhang requested review from bhosmer and ezyang March 30, 2021 23:57
@ailzhang
Copy link
Contributor Author

ailzhang commented Mar 31, 2021

Changes compared to the version before reland: https://gist.github.com/ailzhang/86abc3b72da4b2ec598a983fa52b7476

Copy link

@bhosmer bhosmer left a comment

Choose a reason for hiding this comment

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

THANKS for the diff from the earlier version! 😁 This LGTM but interested in your take on a) framing the scheme a little more generally and b) encapsulating the xor so callsites don't need to remember to do it etc. (per inline comments).

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D27443229

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D27443229

Copy link

@bhosmer bhosmer left a comment

Choose a reason for hiding this comment

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

Thanks!

)

Summary:
Pull Request resolved: pytorch#55008

reland of pytorch#53343

For easier review, here's a diff between the version before revert. https://www.internalfb.com/phabricator/paste/view/P361764610

Test Plan: Imported from OSS

Differential Revision: D27443229

Pulled By: ailzhang

fbshipit-source-id: faeaff3b6165b933c9f354d5f0344e38269fbb12
@facebook-github-bot
Copy link
Contributor

@ailzhang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@ailzhang merged this pull request in 43d4f3b.

ailzhang pushed a commit that referenced this pull request Apr 2, 2021
I tried to avoid creating new TLS, but InferenceMode::is_enabeld()
is in perf critical path (TensorImpl constructor) so it seems
worth adding one for it.
This PR reduces one sources of instruction count increased by
#55008.
```
 λ ~ python compare.py
<torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.FunctionCounts object at 0x7f59097ef310>
     100  0x0000000004854750
    -100  0x0000000004854760
   -4400  c10::impl::tls_is_dispatch_key_included(...)
```

[ghstack-poisoned]
ailzhang pushed a commit that referenced this pull request Apr 2, 2021
I tried to avoid creating new TLS, but InferenceMode::is_enabeld()
is in perf critical path (TensorImpl constructor) so it seems
worth adding one for it.
This PR reduces one sources of instruction count increased by
#55008.
```
 λ ~ python compare.py
<torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.FunctionCounts object at 0x7f59097ef310>
     100  0x0000000004854750
    -100  0x0000000004854760
   -4400  c10::impl::tls_is_dispatch_key_included(...)
```

Differential Revision: [D27539230](https://our.internmc.facebook.com/intern/diff/D27539230)

[ghstack-poisoned]
ailzhang pushed a commit that referenced this pull request Apr 2, 2021
I tried to avoid creating new TLS, but InferenceMode::is_enabeld()
is in perf critical path (TensorImpl constructor) so it seems
worth adding one for it.
This PR reduces one sources of instruction count increased by
#55008.
```
 λ ~ python compare.py
<torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.FunctionCounts object at 0x7f59097ef310>
     100  0x0000000004854750
    -100  0x0000000004854760
   -4400  c10::impl::tls_is_dispatch_key_included(...)
```

ghstack-source-id: 96dd9d5
Pull Request resolved: #55238
ailzhang pushed a commit that referenced this pull request Apr 5, 2021
I tried to avoid creating new TLS, but InferenceMode::is_enabeld()
is in perf critical path (TensorImpl constructor) so it seems
worth adding one for it.
This PR reduces one sources of instruction count increased by
#55008.
```
 λ ~ python compare.py
<torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.FunctionCounts object at 0x7f59097ef310>
     100  0x0000000004854750
    -100  0x0000000004854760
   -4400  c10::impl::tls_is_dispatch_key_included(...)
```

Differential Revision: [D27539230](https://our.internmc.facebook.com/intern/diff/D27539230)

[ghstack-poisoned]
ailzhang pushed a commit that referenced this pull request Apr 5, 2021
I tried to avoid creating new TLS, but InferenceMode::is_enabeld()
is in perf critical path (TensorImpl constructor) so it seems
worth adding one for it.
This PR reduces one sources of instruction count increased by
#55008.
```
 λ ~ python compare.py
<torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.FunctionCounts object at 0x7f59097ef310>
     100  0x0000000004854750
    -100  0x0000000004854760
   -4400  c10::impl::tls_is_dispatch_key_included(...)
```

ghstack-source-id: 84dce14
Pull Request resolved: #55238
ailzhang pushed a commit to ailzhang/pytorch that referenced this pull request Apr 6, 2021
Summary:
Pull Request resolved: pytorch#55238

I tried to avoid creating new TLS, but InferenceMode::is_enabeld()
is in perf critical path (TensorImpl constructor) so it seems
worth adding one for it.
This PR reduces one sources of instruction count increased by
pytorch#55008.
```
 λ ~ python compare.py
<torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.FunctionCounts object at 0x7f59097ef310>
     100  0x0000000004854750
    -100  0x0000000004854760
   -4400  c10::impl::tls_is_dispatch_key_included(...)
```

Test Plan: Imported from OSS

Reviewed By: ezyang

Differential Revision: D27539230

Pulled By: ailzhang

fbshipit-source-id: 54b0c141d59ac569a154a036b284001fca9fc560
facebook-github-bot pushed a commit that referenced this pull request Apr 7, 2021
Summary:
Pull Request resolved: #55424

Pull Request resolved: #55238

I tried to avoid creating new TLS, but InferenceMode::is_enabeld()
is in perf critical path (TensorImpl constructor) so it seems
worth adding one for it.
This PR reduces one sources of instruction count increased by
#55008.
```
 λ ~ python compare.py
<torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.FunctionCounts object at 0x7f59097ef310>
     100  0x0000000004854750
    -100  0x0000000004854760
   -4400  c10::impl::tls_is_dispatch_key_included(...)
```

Test Plan: Imported from OSS

Reviewed By: ezyang

Differential Revision: D27539230

Pulled By: ailzhang

fbshipit-source-id: e040877faef966dca3c2c3d5f9e9a80496c81415
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants