-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Implement torch.util.bottleneck #5216
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| torch.utils.bottleneck | ||
| =============== | ||
|
|
||
| .. currentmodule:: torch.utils.bottleneck | ||
|
|
||
| `torch.utils.bottleneck` is a tool that can be used as an initial step for | ||
| debugging bottlenecks in your program. It summarizes runs of your script with | ||
| the Python profiler and PyTorch's autograd profiler. | ||
|
|
||
| Run it on the command line with | ||
|
|
||
| :: | ||
|
|
||
| python -m torch.utils.bottleneck -- /path/to/source/script.py [args] | ||
|
|
||
| where [args] are any number of arguments to `script.py`, or run | ||
| ``python -m torch.utils.bottleneck -h`` for more usage instructions. | ||
|
|
||
| .. warning:: | ||
| Because your script will be profiled, please ensure that it exits in a | ||
| finite amount of time. | ||
|
|
||
| .. warning:: | ||
| Due to the asynchronous nature of CUDA kernels, when running against | ||
| CUDA code, the cProfile output and CPU-mode autograd profilers may | ||
| not show correct timings. In this case, the CUDA-mode autograd | ||
| profiler is better at assigning blame to the relevant operator(s). | ||
|
|
||
| For more complicated uses of the profilers (like in a multi-GPU case), | ||
| please see https://docs.python.org/3/library/profile.html | ||
| or :func:`torch.autograd.profiler.profile()` for more information. | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import torch | ||
|
|
||
| x = torch.ones((3, 3), requires_grad=True) | ||
| (3 * x).sum().backward() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import argparse | ||
| import torch | ||
|
|
||
| if __name__ == '__main__': | ||
| parser = argparse.ArgumentParser() | ||
|
|
||
| # Required args. Raises error if they aren't passed. | ||
| parser.add_argument('--foo', help='foo', required=True) | ||
| parser.add_argument('--bar', help='bar', required=True) | ||
| _ = parser.parse_args() | ||
|
|
||
| x = torch.ones((3, 3), requires_grad=True) | ||
| (3 * x).sum().backward() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import torch | ||
| import torch.nn as nn | ||
|
|
||
|
|
||
| class Model(nn.Module): | ||
| def __init__(self): | ||
| super(Model, self).__init__() | ||
| self.linear = nn.Linear(20, 20) | ||
|
|
||
| def forward(self, input): | ||
| out = self.linear(input[:, 10:30]) | ||
| return out.sum() | ||
|
|
||
|
|
||
| def main(): | ||
| data = torch.randn(10, 50).cuda() | ||
| model = Model().cuda() | ||
| optimizer = torch.optim.SGD(model.parameters(), lr=0.0001) | ||
| for i in range(10): | ||
| optimizer.zero_grad() | ||
| loss = model(data) | ||
| loss.backward() | ||
| optimizer.step() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
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
Empty file.
Oops, something went wrong.
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.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.