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

Enable bfloat16 for hardtanh_backward_cuda #91511

Closed
wants to merge 2 commits into from
Closed

Conversation

cchan
Copy link
Contributor

@cchan cchan commented Dec 29, 2022

I'm not sure why this was left out in the first place as all adjacent operations have both Half and BFloat16. Things seem to work as expected and this enables relu6 to be used in bfloat16 training. Hardtanh backward is super simple and precision is not relevant.

import torch
x_fp32 = torch.tensor([-1,2,4,7], requires_grad=True, dtype=torch.float32, device="cuda")
x_bf16 = torch.tensor([-1,2,4,7], requires_grad=True, dtype=torch.bfloat16, device="cuda")
torch.nn.functional.relu6(x_fp32).sum().backward()
torch.nn.functional.relu6(x_bf16).sum().backward()
assert (x_fp32.grad == x_bf16.grad).all()

Previously would fail with:

Traceback (most recent call last):
  File "test_hardtanh_patch.py", line 5, in <module>
    torch.nn.functional.relu6(x_bf16).sum().backward()
  File ".../lib/python3.8/site-packages/torch/_tensor.py", line 396, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
  File ".../lib/python3.8/site-packages/torch/autograd/__init__.py", line 173, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: "hardtanh_backward_cuda" not implemented for 'BFloat16'

@pytorch-bot
Copy link

pytorch-bot bot commented Dec 29, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/91511

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit b5ab130:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: cuda release notes category label Dec 29, 2022
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 29, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: cchan / name: Clive Chan (b4444c8)

@cchan
Copy link
Contributor Author

cchan commented Dec 29, 2022

cc @rohithkrn - just checking, do you recall if there was a reason to not add hardtanh_backward, like some test not passing? or just an oversight in this: #32065

@cchan
Copy link
Contributor Author

cchan commented Dec 30, 2022

@pytorchbot rebase

@pytorch-bot
Copy link

pytorch-bot bot commented Dec 30, 2022

You don't have permissions to rebase this PR, only people with write permissions may rebase PRs.

@rohithkrn
Copy link
Contributor

cc @rohithkrn - just checking, do you recall if there was a reason to not add hardtanh_backward, like some test not passing? or just an oversight in this: #32065

@cchan honestly don't remember. It's been a while.

@Chillee
Copy link
Contributor

Chillee commented Jan 6, 2023

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jan 6, 2023
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: This PR is too stale; the last push date was more than 3 days ago. Please rebase and try again. You can rebase by leaving the following comment on this PR:
@pytorchbot rebase

Details for Dev Infra team Raised by workflow job

@cchan
Copy link
Contributor Author

cchan commented Jan 7, 2023

@pytorchbot rebase

@pytorch-bot
Copy link

pytorch-bot bot commented Jan 7, 2023

You don't have permissions to rebase this PR, only people with write permissions may rebase PRs.

@ngimel
Copy link
Collaborator

ngimel commented Jan 7, 2023

@pytorchbot rebase

@pytorchmergebot
Copy link
Collaborator

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

@pytorchmergebot
Copy link
Collaborator

Successfully rebased patch-5 onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout patch-5 && git pull --rebase)

@ngimel
Copy link
Collaborator

ngimel commented Jan 9, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

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 Merged open source release notes: cuda release notes category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants