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 complex support for torch.mean [CUDA] #47048

Closed

Conversation

RockingJavaBean
Copy link
Contributor

Fixes #46982

@dr-ci
Copy link

dr-ci bot commented Oct 29, 2020

💊 CI failures summary and remediations

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


  • 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_vulkan_linux_bionic_py3_6_clang9_build (1/1)

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

Nov 06 16:53:16 sccache: error: couldn't connect to server
Nov 06 16:53:16 +++ eval 'extract_trap_cmd ' 
Nov 06 16:53:16 ++++ extract_trap_cmd 
Nov 06 16:53:16 ++++ printf '%s\n' '' 
Nov 06 16:53:16 +++ printf '%s\n' cleanup 
Nov 06 16:53:16 ++ trap -- ' 
Nov 06 16:53:16 cleanup' EXIT 
Nov 06 16:53:16 ++ [[ pytorch-vulkan-linux-bionic-py3.6-clang9-build != *pytorch-win-* ]] 
Nov 06 16:53:16 ++ which sccache 
Nov 06 16:53:16 ++ sccache --stop-server 
Nov 06 16:53:16 Stopping sccache server... 
Nov 06 16:53:16 sccache: error: couldn't connect to server 
Nov 06 16:53:16 sccache: caused by: Connection refused (os error 111) 
Nov 06 16:53:16 ++ true 
Nov 06 16:53:16 ++ rm /var/lib/jenkins/sccache_error.log 
Nov 06 16:53:16 rm: cannot remove '/var/lib/jenkins/sccache_error.log': No such file or directory 
Nov 06 16:53:16 ++ true 
Nov 06 16:53:16 ++ [[ pytorch-vulkan-linux-bionic-py3.6-clang9-build == *rocm* ]] 
Nov 06 16:53:16 ++ SCCACHE_ERROR_LOG=/var/lib/jenkins/sccache_error.log 
Nov 06 16:53:16 ++ SCCACHE_IDLE_TIMEOUT=1200 
Nov 06 16:53:16 ++ RUST_LOG=sccache::server=error 
Nov 06 16:53:16 ++ sccache --start-server 

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 on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 33 times.

@anjali411 anjali411 added the module: complex Related to complex number support in PyTorch label Oct 30, 2020
@RockingJavaBean RockingJavaBean changed the title [WIP] Enable complex numbers for torch.mean of CUDA path Enable complex numbers for torch.mean of CUDA path Oct 30, 2020
@ngimel ngimel added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Oct 30, 2020
@codecov
Copy link

codecov bot commented Nov 2, 2020

Codecov Report

Merging #47048 into master will increase coverage by 17.31%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           master   #47048       +/-   ##
===========================================
+ Coverage   35.95%   53.27%   +17.31%     
===========================================
  Files         438     2747     +2309     
  Lines       55454   254304   +198850     
===========================================
+ Hits        19939   135476   +115537     
- Misses      35515   118828    +83313     

@RockingJavaBean
Copy link
Contributor Author

@anjali411 Thanks so much for reviewing this PR.
The latest PR leverages the explicit template specialization to handle factor with complex tensors, instead of casting factor to scalar_t.
The CI checks all passed, please kindly help review.

@@ -36,26 +36,40 @@ static void std_var_kernel_cuda(TensorIterator& iter, bool unbiased, bool take_s

template <typename scalar_t, typename acc_t=scalar_t, typename out_t=scalar_t>
Copy link
Contributor

Choose a reason for hiding this comment

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

setting acc_t = typename c10::scalar_value_type<scalar_t>::type should resolve the issue here

c10::scalar_value_type<scalar_t>::type returns scalar_t for all non-complex dtypes and returns T for c10::complex<T>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks so much for the tip. The latest code now manipulates c10::scalar_value_type<acc_t>::type to get the type of the factor, the overload functions for complex numbers are not needed.

@anjali411
Copy link
Contributor

@anjali411 Thanks so much for reviewing this PR.
The latest PR leverages the explicit template specialization to handle factor with complex tensors, instead of casting factor to scalar_t.

Hi @RockingJavaBean I think we shouldn't need to define overload functions for complex types, after the change I suggested in my comment. But this PR looks great overall, and should be ready to merge after that change!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

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

@@ -514,7 +514,8 @@ def test_mean_dim(self):
self._test_dim_ops(
lambda t, d: t.mean(d),
lambda n, d: n.mean(d),
use_integral=False)
use_integral=False,
use_complex=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

This test doesn't run on CUDA. can you please extend the test for mean in tensor_op_tests to also test complex dtypes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, the tests for complex dtypes are added to tensor_op_tests.

Copy link
Contributor

@anjali411 anjali411 left a comment

Choose a reason for hiding this comment

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

let's update the CUDA test for mean to test complex dtypes as well

@RockingJavaBean
Copy link
Contributor Author

@anjali411 I'm really grateful for your tip on c10::scalar_value_type, and the tests for complex inputs of torch.mean function are updated.
Please kindly help review.

Copy link
Contributor

@anjali411 anjali411 left a comment

Choose a reason for hiding this comment

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

lgtm and the windows test failure is an upstream test failure

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

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

@anjali411 anjali411 changed the title Enable complex numbers for torch.mean of CUDA path Add complex support for torch.mean [CUDA] Nov 5, 2020
@RockingJavaBean
Copy link
Contributor Author

@anjali411 thanks so much for reviewing this PR, the CUDA tests for torch.mean passed before the upstream failure CI check terminated according to the circleci log.

test_mean_cuda_bfloat16 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.005s)
test_mean_cuda_complex128 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_cuda_complex64 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_cuda_float16 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_cuda_float32 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.003s)
test_mean_cuda_float64 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_dim_cuda_bfloat16 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_dim_cuda_complex128 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.005s)
test_mean_dim_cuda_complex64 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_dim_cuda_float16 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_dim_cuda_float32 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_dim_cuda_float64 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.003s)
test_mean_neg_dim_cuda_bfloat16 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.005s)
test_mean_neg_dim_cuda_complex128 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_neg_dim_cuda_complex64 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_neg_dim_cuda_float16 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_neg_dim_cuda_float32 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.004s)
test_mean_neg_dim_cuda_float64 (__main__.TestTensorDeviceOpsCUDA) ... ok (0.003s

@anjali411
Copy link
Contributor

@RockingJavaBean can you please rebase?

@RockingJavaBean
Copy link
Contributor Author

@anjali411 thank you so much for the kind reminder, I just rebased this PR with the latest code.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

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

@facebook-github-bot
Copy link
Contributor

@anjali411 merged this pull request in f90da88.

@RockingJavaBean RockingJavaBean deleted the torch_mean_complex branch November 10, 2020 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed Merged module: complex Related to complex number support in PyTorch open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mean_cuda not implemented for complex types
5 participants