Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experimental] Add a RuntimeOption to set inter and intra op threadpool sizes #410

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

VivekPanyam
Copy link
Collaborator

@VivekPanyam VivekPanyam commented Aug 7, 2020

Summary:

Allow users to configure intra-op and inter-op thread pool sizes for the underlying frameworks.

Note: This API is experimental and may change in the future.

Test Plan:

@@ -93,7 +93,7 @@ void check_tf_status(const tensorflow::Status &status)
}

// Get TF session options given Neuropod RuntimeOptions
tensorflow::SessionOptions get_tf_opts(const RuntimeOptions & /*unused*/)
tensorflow::SessionOptions get_tf_opts(const RuntimeOptions &runtime_opts)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related. Some thoughts. RuntimeOption is used now in C++, C and Java API (and could be Python too). We need to keep it in sync. I have seen that Tensorflow using Proto declaration in such cases and then generates struct for languages.

We may use similar approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense - definitely something to look into.

I don't like TF's approach with options for their C API though. They basically require a buffer with a serialized proto as input. This makes it fairly complicated to set options directly from C.

@VivekPanyam VivekPanyam marked this pull request as ready for review January 26, 2021 07:53
@VivekPanyam VivekPanyam changed the title Add a RuntimeOption to set inter and intra op threadpool sizes [Experimental] Add a RuntimeOption to set inter and intra op threadpool sizes Jan 26, 2021
@VivekPanyam VivekPanyam changed the base branch from master to fix_build March 24, 2021 23:58
@codecov
Copy link

codecov bot commented Mar 25, 2021

Codecov Report

Attention: Patch coverage is 45.71429% with 19 lines in your changes missing coverage. Please review.

Project coverage is 87.83%. Comparing base (5f0f371) to head (726d6fb).
Report is 52 commits behind head on master.

Files with missing lines Patch % Lines
source/neuropod/backends/tensorflow/tf_backend.cc 35.00% 13 Missing ⚠️
...rce/neuropod/backends/torchscript/torch_backend.cc 60.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #410      +/-   ##
==========================================
- Coverage   88.04%   87.83%   -0.22%     
==========================================
  Files         106      106              
  Lines        6893     6928      +35     
==========================================
+ Hits         6069     6085      +16     
- Misses        824      843      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from fix_build to master April 2, 2021 23:58
// See https://pytorch.org/docs/stable/notes/cpu_threading_torchscript_inference.html#runtime-api
if (options.experimental_inter_op_parallelism_threads != 0)
{
at::set_num_interop_threads(static_cast<int32_t>(options.experimental_inter_op_parallelism_threads));
Copy link
Contributor

Choose a reason for hiding this comment

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

As I see, there is a torch::set_num_interop_threads that is supposed to be "public". Minor, but I think it is issue still.

Copy link
Contributor

Choose a reason for hiding this comment

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

same about other.


if (options.experimental_intra_op_parallelism_threads != 0)
{
at::set_num_threads(static_cast<int32_t>(options.experimental_intra_op_parallelism_threads));
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to give access to get_num_* somehow. User sets runtime (or not), then starts neuropod execution and should be able to check what are the settings are used, it is important for "default" case, when system sets value and also for IPE case where models share it.

#if CAFFE2_NIGHTLY_VERSION >= 20190808
// Set intra and inter op parallelism
// See https://pytorch.org/docs/stable/notes/cpu_threading_torchscript_inference.html#runtime-api
if (options.experimental_inter_op_parallelism_threads != 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

For Interop case, it allows to set several times only for TBB case. For our case, if there are 2nd IPE model with non-zero value, it will fail. As I see in code, for non-TBB cases, it sets atomic var and I think it can be done here as well. I'd save still possibility to change it for TBB case. I am thinking about building libtorch for TBB, we have a Torchscript model/use case where TBB's "better" concurrency can be critical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants