Skip to content

Strided masked reduction: mean (2nd try)#67088

Closed
pearu wants to merge 10 commits intogh/pearu/9/basefrom
gh/pearu/9/head
Closed

Strided masked reduction: mean (2nd try)#67088
pearu wants to merge 10 commits intogh/pearu/9/basefrom
gh/pearu/9/head

Conversation

@pearu
Copy link
Copy Markdown
Collaborator

@pearu pearu commented Oct 22, 2021

@pytorch-probot
Copy link
Copy Markdown

pytorch-probot bot commented Oct 22, 2021

CI Flow Status

⚛️ CI Flow

Ruleset - Version: v1
Ruleset - File: https://github.com/pytorch/pytorch/blob/171dd33e46afe178e6ebf68bf6cc62c37354e42c/.github/generated-ciflow-ruleset.json
PR ciflow labels: ciflow/default

Workflows Labels (bold enabled) Status
Triggered Workflows
linux-bionic-py3.6-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/noarch, ciflow/xla ✅ triggered
linux-vulkan-bionic-py3.6-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/vulkan ✅ triggered
linux-xenial-cuda11.3-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3-clang5-mobile-build ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile ✅ triggered
linux-xenial-py3-clang5-mobile-custom-build-dynamic ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile ✅ triggered
linux-xenial-py3-clang5-mobile-custom-build-static ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile ✅ triggered
linux-xenial-py3.6-clang7-asan ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/sanitizers ✅ triggered
linux-xenial-py3.6-clang7-onnx ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/onnx ✅ triggered
linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3.6-gcc7 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3.6-gcc7-bazel-test ciflow/all, ciflow/bazel, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
win-vs2019-cpu-py3 ciflow/all, ciflow/cpu, ciflow/default, ciflow/win ✅ triggered
win-vs2019-cuda11.3-py3 ciflow/all, ciflow/cuda, ciflow/default, ciflow/win ✅ triggered
Skipped Workflows
caffe2-linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux 🚫 skipped
docker-builds ciflow/all 🚫 skipped
libtorch-linux-xenial-cuda10.2-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux 🚫 skipped
libtorch-linux-xenial-cuda11.3-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux 🚫 skipped
linux-bionic-cuda10.2-py3.9-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/slow 🚫 skipped
linux-xenial-py3-clang5-mobile-code-analysis ciflow/all, ciflow/linux, ciflow/mobile 🚫 skipped
parallelnative-linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux 🚫 skipped
periodic-libtorch-linux-xenial-cuda11.1-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-xenial-cuda10.2-py3-gcc7-slow-gradcheck ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled, ciflow/slow, ciflow/slow-gradcheck 🚫 skipped
periodic-linux-xenial-cuda11.1-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-win-vs2019-cuda11.1-py3 ciflow/all, ciflow/cuda, ciflow/scheduled, ciflow/win 🚫 skipped

You can add a comment to the PR and tag @pytorchbot with the following commands:
# ciflow rerun, "ciflow/default" will always be added automatically
@pytorchbot ciflow rerun

# ciflow rerun with additional labels "-l <ciflow/label_name>", which is equivalent to adding these labels manually and trigger the rerun
@pytorchbot ciflow rerun -l ciflow/scheduled -l ciflow/slow

For more information, please take a look at the CI Flow Wiki.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Oct 22, 2021

🔗 Helpful links

💊 CI failures summary and remediations

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


💚 💚 Looks good so far! There are no failures yet. 💚 💚


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.

pearu added a commit that referenced this pull request Oct 22, 2021
pearu added a commit that referenced this pull request Oct 22, 2021
ghstack-source-id: 88fe849
Pull Request resolved: #67088
@pearu
Copy link
Copy Markdown
Collaborator Author

pearu commented Oct 22, 2021

I can reproduce the RuntimeError: cov(): weights sum to zero, can't be normalized error locally. It turns out that make_tensor in

fweights = make_tensor((num_observations,), device, torch.int, low=0, high=10, requires_grad=requires_grad)
produces a tensor with all items being zeros but such a tensor is invalid for fweights.
Using low=1 fixes the issue... Update: regenerating the cov sample fixes the issue, see #67039 .

pearu added a commit that referenced this pull request Oct 22, 2021
ghstack-source-id: a909057
Pull Request resolved: #67088
@pearu pearu requested review from cpuhrsch and ngimel October 22, 2021 19:57
pearu added a commit that referenced this pull request Oct 25, 2021
ghstack-source-id: fd34b77
Pull Request resolved: #67088
@cpuhrsch
Copy link
Copy Markdown
Contributor

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

facebook-github-bot pushed a commit that referenced this pull request Oct 26, 2021
Summary: Pull Request resolved: #67088

Test Plan: Imported from OSS

Reviewed By: pbelevich

Differential Revision: D31914868

Pulled By: cpuhrsch

fbshipit-source-id: beda9d32ea65bcae31c2c0181f95ad23c6631075
@ngimel
Copy link
Copy Markdown
Collaborator

ngimel commented Oct 26, 2021

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been reverted by 273ab55. To re-land this change, follow these steps.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been reverted by 526053706411ec3f2f8024849d951d6bf37b53a4. To re-land this change, follow these steps.

@pearu
Copy link
Copy Markdown
Collaborator Author

pearu commented Oct 26, 2021

The failure is likely related to numpy/numpy#18552 which has a fix available in numpy 1.20.2.
The resolution is to replace 1.20.0 with 1.20.2 in
https://github.com/pytorch/pytorch/pull/67088/files#diff-18a0c3e7cd07089b34760028c387d39de1aa393172f1d5f123692106b3a3d144R11079

@ngimel
Copy link
Copy Markdown
Collaborator

ngimel commented Oct 27, 2021

TIL about np.mean with where argument. @cpuhurch, @mruberry, should we be adding where to our reductions?

@pearu pearu reopened this Nov 1, 2021
pearu added a commit that referenced this pull request Nov 1, 2021
ghstack-source-id: 1437d5b
Pull Request resolved: #67088
@pearu
Copy link
Copy Markdown
Collaborator Author

pearu commented Nov 1, 2021

@cpuhrsch could you try importing this PR?

@cpuhrsch
Copy link
Copy Markdown
Contributor

cpuhrsch commented Nov 1, 2021

@ngimel NumPy defines the input to where in its general documentation for reductions as "A boolean array which is broadcasted to match the dimensions of array, and selects elements to include in the reduction."

I think that functionality is covered by the masked reduction RFC, but I could see us potentially wanting to add this for NumPy compatibility? There is also some discussion around using where in the RFC itself, but only to decide on the definition of the mask semantics (i.e. does True mean inclusion or exclusion).

@cpuhrsch
Copy link
Copy Markdown
Contributor

cpuhrsch commented Nov 1, 2021

Just for completeness note that the definition of mask differs between NumPy's MaskedArray and the where argument.

>>> npm1 = np.ma.masked_array([0., 1., 2.], [False, False, True])
>>> npm1
masked_array(data=[0.0, 1.0, --],
             mask=[False, False,  True],
       fill_value=1e+20)
>>> npm1.sum()
1.0
>>> np.sum([0., 1, 2], where=[False, False, True])
2.0

@ngimel
Copy link
Copy Markdown
Collaborator

ngimel commented Nov 1, 2021

@cpuhrsch I agree that where functionality is covered by the masked reduction RFC, my question was about adding it for better numpy compat.

@cpuhrsch
Copy link
Copy Markdown
Contributor

cpuhrsch commented Nov 1, 2021

@ngimel - Ideally we're pythonic in the sense of "one obvious way to do it", but I can also see that there's value in adding this feature for compatibility. I do worry though that we'll end up in a situation where people are doing the usual "masked out row" or "fully masked out" inputs and then run into gradient issues, which we're currently working on resolving via MaskedTensor.

@cpuhrsch
Copy link
Copy Markdown
Contributor

cpuhrsch commented Nov 1, 2021

@pearu - could you rebase?

pearu added a commit that referenced this pull request Nov 1, 2021
ghstack-source-id: 3b9a69c
Pull Request resolved: #67088
@pearu
Copy link
Copy Markdown
Collaborator Author

pearu commented Nov 1, 2021

@cpuhrsch rebase done.

@anjali411
Copy link
Copy Markdown
Contributor

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

facebook-github-bot pushed a commit that referenced this pull request Nov 1, 2021
Summary:
Pull Request resolved: #67088

Stack from [ghstack](https://github.com/ezyang/ghstack):
* __->__ #67088

Test Plan: Imported from OSS

Reviewed By: anjali411

Differential Revision: D32070264

Pulled By: cpuhrsch

fbshipit-source-id: 08a91550dd24fb0f51abf06591a0e26186c4f9f9
@facebook-github-bot facebook-github-bot deleted the gh/pearu/9/head branch December 2, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants