Skip to content

Refactor foreach binary ops tests with scalars to use OpInfo#51058

Closed
izdeby wants to merge 29 commits intogh/izdeby/75/basefrom
gh/izdeby/75/head
Closed

Refactor foreach binary ops tests with scalars to use OpInfo#51058
izdeby wants to merge 29 commits intogh/izdeby/75/basefrom
gh/izdeby/75/head

Conversation

@izdeby
Copy link
Copy Markdown
Contributor

@izdeby izdeby commented Jan 25, 2021

Stack from ghstack:


Updated foreach binary ops tests with scalars to use OpInfo

Differential Revision: D26103905

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jan 25, 2021

💊 CI failures summary and remediations

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


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-scanned failure(s)

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.

@izdeby izdeby mentioned this pull request Jan 26, 2021
@izdeby izdeby changed the title refactor foreach binary ops tests with scalars to use OpInfo Refactor foreach binary ops tests with scalars to use OpInfo Jan 26, 2021
-----
Updated foreach binary ops tests with scalars to use OpInfo

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

[ghstack-poisoned]
Iurii Zdebskyi added 5 commits January 27, 2021 09:23
-----
Updated foreach binary ops tests with scalars to use OpInfo

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
izdeby pushed a commit that referenced this pull request Feb 4, 2021
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
Iurii Zdebskyi and others added 16 commits February 18, 2021 12:15
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
Copy link
Copy Markdown
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

Logic looks correct. I had two comments:

  1. I'm not sure what is happening with the float16 testing (added an in-line comment)
  2. In the old code, we had some checks for various error messages that would be raised. Those checks don't exist anymore in the OpInfo tests. Do you think it would be worth it to add some new, non-OpInfo test that tests for the various error message? I am thinking of something like:
def test_error_messages(self, device):
    # test subtraction with booleans raises a nice error message

    # test addition with LongTensors but with floating-point alpha raises a nice error message
    
    # ...

There are probably better ways to organize this. I'm OK if you want to handle adding tests for the error messages in a follow-up later to unblock progress here

"""Early version of a specialized OpInfo for foreach binary functions"""
def __init__(self,
name,
dtypes=all_types_and(torch.bool, torch.half, torch.bfloat16),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(no action required) Err, it's a little weird that "all_types" doesn't mean "all possible dtypes". But I suppose that's a pre-existing problem

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, i agree, Its super confusing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is incredibly confusing, sorry. It corresponds to the internal dispatch macro 1:1, though.

Comment on lines +159 to +161
# Mimics cuda kernel dtype flow. With fp16/bf16 input, runs in fp32 and casts output back to fp16/bf16.
dtype = torch.float32 if (self.device_type == 'cuda' and
(dtype is torch.float16 or dtype is torch.bfloat16)) else dtype
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't we want to test that torch.float16 tensors are accepted by these APIs? What does "Mimics cuda kernel dtype flow." mean? (Maybe this just needs a better explanation)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is needed to pass the precision check. We don't process half and bfloat16 directly, but convert it to float. [1] [2]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm I see, thanks for the references. Wouldn't it be better to

  1. Run the foreach op in with inputs of the original dtype (float16)
  2. Convert inputs to the updated dtype (float32), run the reference (PyTorch op in a for-loop), then convert outputs back to float 16
  3. Compare the result of 1 and 2

This way we can still test that the foreach APIs accept float16 and bfloat16 tensors without erroring out.

-----
Updated foreach binary ops tests with scalars to use OpInfo

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

[ghstack-poisoned]
@izdeby izdeby requested a review from zou3519 April 1, 2021 17:30
@facebook-github-bot
Copy link
Copy Markdown
Contributor

Hi @izdeby!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@ngimel ngimel removed their request for review May 30, 2021 23:39
@zou3519 zou3519 removed their request for review June 28, 2021 13:31
@mruberry mruberry closed this Jan 24, 2022
@facebook-github-bot facebook-github-bot deleted the gh/izdeby/75/head branch February 24, 2022 15:17
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.

5 participants