8000 ENH: Add a force argument to `numpy()` by HaoZeke · Pull Request #78564 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add a force argument to numpy() #78564

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

Closed
wants to merge 18 commits into from
Closed

Conversation

HaoZeke
Copy link
Collaborator
@HaoZeke HaoZeke commented May 31, 2022

Reopened to help with merge issues. See #59790 for full context.

Fixes #20778. Helps #71688.

Finalizes @martinPasen's force argument for Tensor.numpy(). It is set to False by default. If it's set to True then we:

  1. detatch the Tensor, if requires_grad == True
  2. move to cpu, if not on cpu already
  3. Uses .resolve_conj() if .is_conj() == True
  4. Uses .resolve_neg() if .is_neg() == True

cc @albanD

@facebook-github-bot
Copy link
Contributor
facebook-github-bot commented May 31, 2022

🔗 Helpful links

❌ 2 New Failures

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

Expand to see more
  • 2/2 failures introduced in this PR

🕵️ 2 new failures recognized by patterns

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

See GitHub Actions build trunk / linux-bionic-rocm5.1-py3.7 / test (default, 2, 2, linux.rocm.gpu) (1/2)

Step: "Set up job" (full log | diagnosis details | 🔁 rerun)

2022-05-31T20:46:56.2318912Z ##[error]The reque...igured HttpClient.Timeout of 100 seconds elapsing.
2022-05-31T20:41:15.0120205Z ##[endgroup]
2022-05-31T20:41:15.0123962Z Secret source: Actions
2022-05-31T20:41:15.0124542Z Prepare workflow directory
2022-05-31T20:41:15.1333898Z Prepare all required actions
2022-05-31T20:41:15.1598102Z Getting action download info
2022-05-31T20:41:15.6492322Z Download action repository 'pytorch/pytorch@master' (SHA:96c134854d4dbc418cdc0ec82959476ddac8068e)
2022-05-31T20:42:55.6886828Z ##[warning]Failed to download action 'https://api.github.com/repos/pytorch/pytorch/tarball/96c134854d4dbc418cdc0ec82959476ddac8068e'. Error: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
2022-05-31T20:42:55.6897854Z ##[warning]Back off 18.681 seconds before retry.
2022-05-31T20:44:54.3818242Z ##[warning]Failed to download action 'https://api.github.com/repos/pytorch/pytorch/tarball/96c134854d4dbc418cdc0ec82959476ddac8068e'. Error: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
2022-05-31T20:44:54.3822540Z ##[warning]Back off 21.833 seconds before retry.
2022-05-31T20:46:56.2318912Z ##[error]The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.

See GitHub Actions build trunk / linux-bionic-rocm5.1-py3.7 / test (default, 1, 2, linux.rocm.gpu) (2/2)

Step: "Set up job" (full log | diagnosis details | 🔁 rerun)

2022-05-31T20:47:03.8554861Z ##[error]The reque...igured HttpClient.Timeout of 100 seconds elapsing.
2022-05-31T20:41:15.0442630Z ##[endgroup]
2022-05-31T20:41:15.0445960Z Secret source: Actions
2022-05-31T20:41:15.0446445Z Prepare workflow directory
2022-05-31T20:41:15.1476430Z Prepare all required actions
2022-05-31T20:41:15.1782574Z Getting action download info
2022-05-31T20:41:15.4770493Z Download action repository 'pytorch/pytorch@master' (SHA:96c134854d4dbc418cdc0ec82959476ddac8068e)
2022-05-31T20:42:55.5305279Z ##[warning]Failed to download action 'https://api.github.com/repos/pytorch/pytorch/tarball/96c134854d4dbc418cdc0ec82959476ddac8068e'. Error: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
2022-05-31T20:42:55.5330094Z ##[warning]Back off 23.07 seconds before retry.
2022-05-31T20:44:58.6178024Z ##[warning]Failed to download action 'https://api.github.com/repos/pytorch/pytorch/tarball/96c134854d4dbc418cdc0ec
8000
82959476ddac8068e'. Error: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
2022-05-31T20:44:58.6181716Z ##[warning]Back off 25.214 seconds before retry.
2022-05-31T20:47:03.8554861Z ##[error]The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

Copy link
Collaborator
@albanD albanD left a comment

Choose a reason for hiding this comment

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

Looks good!
Thanks for the new PR.

@albanD albanD added the ciflow/trunk Trigger trunk jobs on your pull request label May 31, 2022
@albanD
Copy link
Collaborator
albanD commented Jun 1, 2022

@pytorchbot merge this please

@HaoZeke
Copy link
Collaborator Author
HaoZeke commented Jun 6, 2022

@janeyx99 could you look into the PyTorchBot issue?

@albanD
Copy link
Collaborator
albanD commented Jun 6, 2022

Ho I didn't realize the bot didn't merge that sorry!

@albanD
Copy link
Collaborator
albanD commented Jun 6, 2022

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

@github-actions
Copy link
Contributor
github-actions bot commented Jun 6, 2022

Hey @HaoZeke.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

@janeyx99
Copy link
Contributor
janeyx99 commented Jun 6, 2022

@janeyx99 could you look into the PyTorchBot issue?

Ah! We've migrated off the natural language commands and moved to a more CLI format--please check our wiki for the valid commands now: https://github.com/pytorch/pytorch/wiki/Bot-commands

facebook-github-bot pushed a commit that referenced this pull request Jun 7, 2022
Summary:
**Reopened** to help with merge issues. See #59790 for full context.

Fixes #20778. Helps #71688.

Finalizes martinPasen's force argument for `Tensor.numpy()`. It is set to False by default. If it's set to True then we:
1. detatch the Tensor, if requires_grad == True
2. move to cpu, if not on cpu already
3. Uses .resolve_conj() if .is_conj() == True
4. Uses .resolve_neg() if .is_neg() == True

cc albanD

Pull Request resolved: #78564
Approved by: https://github.com/albanD

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/3f58dd18dc6fc18ed82fb1632cea48373c0a7798

Reviewed By: seemethere

Differential Revision: D36935606

Pulled By: seemethere

fbshipit-source-id: dc2dd7f569feb8da29add55db3d1625241ff8d77
@vadimkantorov
Copy link
Contributor

@albanD Can we allow automatic detach / force = True when doing automatic numpy conversion?

E.g. when visualizing Torch tensors with matplotlib: plt.plot(x, y.requires_grad_()) will fail because y is not detached, but it's quite useful for visualization purposes.

@albanD
Copy link
Collaborator
albanD commented Jul 18, 2023

Do you have specific examples in mind?
The plotting code should be able to use force() explicitly there so that the end user doesn't have to specify it?

@vadimkantorov
Copy link
Contributor
6D40

My treatment is: the better and better Pytorch --> NumPy interop becomes, the more value is in doing detach (or even gpu->cpu) automatically (if want to protect, can add a readonly bit in NumPy tensors).

At least for PyTorch->matplotlib quick vis the explicit .numpy() calls do make the code less readable.

Device transfer is a bit more understandable, but why can't attached-to-graph tensors be passed for zero-copy NumPy conversion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged open source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support One step transform to numpy
8 participants
0