Nothing Special   »   [go: up one dir, main page]

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

Add OptionalRef; clamp: port to structured kernel #61361

Closed

Conversation

SplitInfinity
Copy link
@SplitInfinity SplitInfinity commented Jul 7, 2021

Stack from ghstack:

This PR ports the clamp kernel to the structured format. In addition, it introduces OptionalScalarRef as a replacement for c10::optional<Scalar>&. The latter, although it is a reference type, can still involve copying the contained Scalar (e.g. if the actual parameter is a Scalar or if a c10::optional<Scalar> is constructed just to call a kernel). OptionalScalarRef contains only a const Scalar&, and stores flag about whether the instance contains something inside the Scalar itself using a new tag.

For more information, see #55070.

Differential Revision: D29821533

For more information, see #55070.

[ghstack-poisoned]
@SplitInfinity SplitInfinity requested a review from ezyang as a code owner July 7, 2021 17:59
@facebook-github-bot facebook-github-bot added oncall: jit Add this issue/PR to JIT oncall triage queue cla signed labels Jul 7, 2021
@facebook-github-bot
Copy link
Contributor
facebook-github-bot commented Jul 7, 2021

💊 CI failures summary and remediations

As of commit 6bc0599 (more details on the Dr. CI page and at hud.pytorch.org/pr/61361):


  • 1/1 failures introduced in this PR

🕵️ 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_cuda11_1_cudnn8_py3_gcc7_build (1/1)

Step: "Build" (full log | diagnosis details | 🔁 rerun)

Jul 22 20:11:36 rm: cannot remove '/var/lib/jenkins/sccache_error.log': No such file or directory
Jul 22 20:11:36 ++++ extract_trap_cmd
Jul 22 20:11:36 ++++ printf '%s\n' ''
Jul 22 20:11:36 +++ printf '%s\n' cleanup
Jul 22 20:11:36 ++ trap -- '
Jul 22 20:11:36 cleanup' EXIT
Jul 22 20:11:36 ++ [[ pytorch-linux-xenial-cuda11.1-cudnn8-py3-gcc7-build != *pytorch-win-* ]]
Jul 22 20:11:36 ++ which sccache
Jul 22 20:11:36 ++ sccache --stop-server
Jul 22 20:11:36 ++ true
Jul 22 20:11:36 ++ rm /var/lib/jenkins/sccache_error.log
Jul 22 20:11:36 rm: cannot remove '/var/lib/jenkins/sccache_error.log': No such file or directory
Jul 22 20:11:36 ++ true
Jul 22 20:11:36 ++ [[ -n '' ]]
Jul 22 20:11:36 ++ [[ pytorch-linux-xenial-cuda11.1-cudnn8-py3-gcc7-build == *rocm* ]]
Jul 22 20:11:36 ++ SCCACHE_ERROR_LOG=/var/lib/jenkins/sccache_error.log
Jul 22 20:11:36 ++ SCCACHE_IDLE_TIMEOUT=1200
Jul 22 20:11:36 ++ RUST_LOG=sccache::server=error
Jul 22 20:11:36 ++ sccache --start-server
Jul 22 20:11:36 sccache: Starting the server...
Jul 22 20:11:36 ++ sccache --zero-stats
Jul 22 20:11:36 Compile requests                      0

1 job timed out:

  • pytorch_linux_xenial_cuda11_1_cudnn8_py3_gcc7_build

Preview docs built from this PR

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.

Click here to manually regenerate this comment.

SplitInfinity pushed a commit that referenced this pull request Jul 7, 2021
For more information, see #55070.

ghstack-source-id: 6929c6123d62195ab17674c7f30081a9d243c784
Pull Request resolved: #61361
@SplitInfinity SplitInfinity removed the request for review from ezyang July 7, 2021 19:52
For more information, see #55070.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 8, 2021
For more information, see #55070.

ghstack-source-id: f2b338ecce50b098e865b9fdf340ef0d5e96a946
Pull Request resolved: #61361
For more information, see #55070.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 8, 2021
For more information, see #55070.

ghstack-source-id: d553aa2b761f316a2fdb18abc495125719c10f23
Pull Request resolved: #61361
@makslevental
Copy link
Contributor

@SplitInfinity sorry just wondering: is this PR stalled? I'm kind of blocked on it (need out variant of relu). I looked at the CI logs and it looks like the error is due to some syntax in a file not touched by this diff:

image

https://github.com/pytorch/pytorch/pull/61361/checks?check_run_id=3022080451#step:5:15930

but I don't think you've changed any macros that are used in that file.

@SplitInfinity
Copy link
Author
SplitInfinity commented Jul 14, 2021

It is not stalled, I'm going to iterate on it and hopefully get all tests to pass today after submitting PSC.

@makslevental
Copy link
Contributor
makslevental commented Jul 14, 2021

It is not stalled, I'm going to iterate on it and hopefully get all tests to pass today after submitting PSC.

great. lmk if you need help getting it across the finish line

For more information, see #55070.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 15, 2021
For more information, see #55070.

ghstack-source-id: c40b4c0274b890c2e93170169be393db02910172
Pull Request resolved: #61361
torch/csrc/jit/runtime/static/ops.cpp Outdated Show resolved Hide resolved
c10/core/Scalar.cpp Outdated Show resolved Hide resolved
}

private:
const Scalar empty_;
Copy link
Author

Choose a reason for hiding this comment

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

The purpose of this member is so that scalar_ has something to refer to when the OptionalScalarRef instance refers to nothing. I tried to make it static in order to ensure there is only one instance per class and not per object, but I ran into linker errors I couldn't fix. I put the definition of said static member into Scalar.cpp and I suspect it there are some objects that include Scalar.h that aren't linked against whatever library Scalar.cpp ends up in. I dug through CMakeLists/Bazel files for a while but couldn't figure out how to fix this.

A fix for the above or another way to create something for scalar_ to refer to when the instance of OptionalScalarRef refers to nothing would be appreciated. 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

Since your fields here are private, it seems better to just store a Scalar*. Then we don't even need HAS_n.

c10/core/Scalar.h Outdated Show resolved Hide resolved
c10/core/Scalar.h Outdated Show resolved Hide resolved
@SplitInfinity SplitInfinity changed the title [WIP] clamp: port to structured kernel clamp: port to structured kernel Jul 15, 2021
@SplitInfinity SplitInfinity requested a review from ezyang July 15, 2021 17:40
c10/core/Scalar.h Outdated Show resolved Hide resolved
@ezyang
Copy link
Contributor
ezyang commented Jul 16, 2021

This looks substantively fine but seeing how the OptionalScalarRef implementation turned out I'm retracting my suggestion to you that a HAS_n tag would be good; you should just represent the nullary state with nullptr. I'm going to go ahead and approve this since I'm PTO tomorrow.

Copy link
Contributor
@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

please see comments

Comment on lines 562 to 564
Tensor temp(result);
at::clamp_max_outf(self, max.toScalar(), temp);
result.copy_(temp);
Copy link
Author
@SplitInfinity SplitInfinity Jul 17, 2021

Choose a reason for hiding this comment

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

This is another snippet I wanted to talk about. I would like to pass in result directly, but can't do that since the last parameter of at::clamp_max_outf is not const. None of the at::cpu:clamp_max variants have a const out parameter either...

Copy link
Author
@SplitInfinity SplitInfinity Jul 17, 2021

Choose a reason for hiding this comment

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

This kind of looks like #50953, but the function here is clamp_max, not clamp.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do a const cast

Copy link
Contributor

Choose a reason for hiding this comment

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

(Don't Tensor temp(result), that's an unnecessary refcount bump). In the terminal state clamp_min_outf takes a const argument and the const cast is unnecessary)

This PR ports the `clamp` kernel to the structured format. In addition, it introduces `OptionalScalarRef` as a replacement for `c10::optional<Scalar>&`. The latter, although it is a reference type, can still involve copying the contained `Scalar` (e.g. if the actual parameter is a `Scalar` or if a `c10::optional<Scalar>` is constructed just to call a kernel). `OptionalScalarRef` contains only a `const Scalar&`, and stores flag about whether the instance contains something inside the `Scalar` itself using a new tag.

For more information, see #55070.

[ghstack-poisoned]
This PR ports the `clamp` kernel to the structured format. In addition, it introduces `OptionalScalarRef` as a replacement for `c10::optional<Scalar>&`. The latter, although it is a reference type, can still involve copying the contained `Scalar` (e.g. if the actual parameter is a `Scalar` or if a `c10::optional<Scalar>` is constructed just to call a kernel). `OptionalScalarRef` contains only a `const Scalar&`, and stores flag about whether the instance contains something inside the `Scalar` itself using a new tag.

For more information, see #55070.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 17, 2021
For more information, see #55070.

ghstack-source-id: 645b6402214d46611bf69859e74920c9079f7bd6
Pull Request resolved: #61361
@@ -587,13 +587,16 @@ class optional : private OptionalBase<T> {
constexpr bool initialized() const noexcept {
return OptionalBase<T>::initialized();
}

public:
Copy link
Author

Choose a reason for hiding this comment

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

I had to make dataptr() public now that OptionalScalarRef stores const Scalar*. But it doesn't seem right to do this.

This PR ports the `clamp` kernel to the structured format. In addition, it introduces `OptionalScalarRef` as a replacement for `c10::optional<Scalar>&`. The latter, although it is a reference type, can still involve copying the contained `Scalar` (e.g. if the actual parameter is a `Scalar` or if a `c10::optional<Scalar>` is constructed just to call a kernel). `OptionalScalarRef` contains only a `const Scalar&`, and stores flag about whether the instance contains something inside the `Scalar` itself using a new tag.

For more information, see #55070.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 17, 2021
For more information, see #55070.

ghstack-source-id: 3ae0de358757292414a3047849fb6635d3ec7a1d
Pull Request resolved: #61361
@SplitInfinity SplitInfinity requested a review from ezyang July 17, 2021 04:34
@SplitInfinity
Copy link
Author

Rerequesting review because switching to Scalar* required making optional::dataptr() public and that seems imprudent.

This PR ports the `clamp` kernel to the structured format. In addition, it introduces `OptionalScalarRef` as a replacement for `c10::optional<Scalar>&`. The latter, although it is a reference type, can still involve copying the contained `Scalar` (e.g. if the actual parameter is a `Scalar` or if a `c10::optional<Scalar>` is constructed just to call a kernel). `OptionalScalarRef` contains only a `const Scalar&`, and stores flag about whether the instance contains something inside the `Scalar` itself using a new tag.

For more information, see #55070.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 19, 2021
For more information, see #55070.

ghstack-source-id: 0413f963557351e1a47c51fedc6691509a1e2e81
Pull Request resolved: #61361

operator bool() const {
return has_value();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

btw, if you hate optional's conversion to boolean, you could delete this implicit conversion and force people to write has_value() explicitly.

This PR ports the `clamp` kernel to the structured format. In addition, it introduces `OptionalScalarRef` as a replacement for `c10::optional<Scalar>&`. The latter, although it is a reference type, can still involve copying the contained `Scalar` (e.g. if the actual parameter is a `Scalar` or if a `c10::optional<Scalar>` is constructed just to call a kernel). `OptionalScalarRef` contains only a `const Scalar&`, and stores flag about whether the instance contains something inside the `Scalar` itself using a new tag.

For more information, see #55070.

[ghstack-poisoned]
@@ -60,7 +60,7 @@ void clamp_kernel_impl(TensorIterator& iter) {
});
}

void clamp_scalar_kernel_impl(TensorIterator& iter, Scalar min, Scalar max) {
void clamp_scalar_kernel_impl(TensorIteratorBase& iter, Scalar min, Scalar max) {
Copy link
Author

Choose a reason for hiding this comment

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

Hold on, shouldn't these be Scalar& to avoid copying Scalars around?

This PR ports the `clamp` kernel to the structured format. In addition, it introduces `OptionalScalarRef` as a replacement for `c10::optional<Scalar>&`. The latter, although it is a reference type, can still involve copying the contained `Scalar` (e.g. if the actual parameter is a `Scalar` or if a `c10::optional<Scalar>` is constructed just to call a kernel). `OptionalScalarRef` contains only a `const Scalar&`, and stores flag about whether the instance contains something inside the `Scalar` itself using a new tag.

For more information, see #55070.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 21, 2021
For more information, see #55070.

ghstack-source-id: cf4bfec0f315d69d2ccd8e3c1efe4b0faeefefd5
Pull Request resolved: #61361
@SplitInfinity SplitInfinity requested a review from ezyang July 21, 2021 16:51
This PR ports the `clamp` kernel to the structured format. In addition, it introduces `OptionalScalarRef` as a replacement for `c10::optional<Scalar>&`. The latter, although it is a reference type, can still involve copying the contained `Scalar` (e.g. if the actual parameter is a `Scalar` or if a `c10::optional<Scalar>` is constructed just to call a kernel). `OptionalScalarRef` contains only a `const Scalar&`, and stores flag about whether the instance contains something inside the `Scalar` itself using a new tag.

For more information, see #55070.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 21, 2021
For more information, see #55070.

ghstack-source-id: f85b1b36850429cc9e0359652a07e17a60043e7b
Pull Request resolved: #61361
@SplitInfinity
Copy link
Author

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

class OptionalRef {
public:
OptionalRef() : data_(nullptr) {}
OptionalRef(const T* data) : data_(data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably just get rid of this constructor at this point.

@ezyang ezyang changed the title clamp: port to structured kernel Add OptionalRef; clamp: port to structured kernel Jul 22, 2021
This PR ports the `clamp` kernel to the structured format. In addition, it introduces `OptionalScalarRef` as a replacement for `c10::optional<Scalar>&`. The latter, although it is a reference type, can still involve copying the contained `Scalar` (e.g. if the actual parameter is a `Scalar` or if a `c10::optional<Scalar>` is constructed just to call a kernel). `OptionalScalarRef` contains only a `const Scalar&`, and stores flag about whether the instance contains something inside the `Scalar` itself using a new tag.

For more information, see #55070.

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

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Jul 22, 2021
For more information, see #55070.

ghstack-source-id: 049ceaf86f3b0609f771e04bf043f8bcc560cbc5
Pull Request resolved: #61361
@facebook-github-bot
Copy link
Contributor

@SplitInfinity merged this pull request in 1d2ea76.

@facebook-github-bot facebook-github-bot deleted the gh/splitinfinity/150/head branch July 26, 2021 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed Merged oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants