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

Assert if padding mask type is unexpected (#86353) #87106

Closed
wants to merge 1 commit into from

Conversation

zrphercule
Copy link
Contributor

Summary:
Pull Request resolved: #86353

Fix the issue described in
#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Differential Revision: D40129968

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 17, 2022

🔗 Helpful Links

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

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

✅ No Failures

As of commit 7ed2fcf:
💚 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: nn release notes category label Oct 17, 2022
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

@albanD albanD removed their request for review October 17, 2022 19:21
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 17, 2022
… & unit test (pytorch#87106)

Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Differential Revision: D40129968

fbshipit-source-id: 5fdfe5742d30344d12bf0faf11a0e93c12b8be76
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 17, 2022
… & unit test (pytorch#87106)

Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Differential Revision: D40129968

fbshipit-source-id: 1f7f4b3fded63fccb4fe211e873390a2267ce6af
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 17, 2022
… & unit test (pytorch#87106)

Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Differential Revision: D40129968

fbshipit-source-id: 2be6869f2f8a39c780fdfaf3fb16034c4726a571
Copy link
Contributor

@malfet malfet left a comment

Choose a reason for hiding this comment

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

LGTM, but please consider the posted feedback

@@ -443,6 +448,11 @@ def forward(self, src: Tensor, src_mask: Optional[Tensor] = None,
"""

# see Fig. 1 of https://arxiv.org/pdf/2002.04745v1.pdf
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps put the assertion above the comment (as Fig1 is unlikely to have anything to do with checks below

if src_key_padding_mask.dtype != torch.bool:
if not torch.is_floating_point(src_key_padding_mask):
raise AssertionError(
"only bool and floating type of key_padding_mask is supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

English is not my native, but isn't assertion discusses plural types, isn't it?

Suggested change
"only bool and floating type of key_padding_mask is supported")
"only bool and floating types of key_padding_mask are supported")

Comment on lines 451 to 453
if src_key_padding_mask is not None:
if src_key_padding_mask.dtype != torch.bool:
if not torch.is_floating_point(src_key_padding_mask):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider dismantling pyramid of doom by a bit

Suggested change
if src_key_padding_mask is not None:
if src_key_padding_mask.dtype != torch.bool:
if not torch.is_floating_point(src_key_padding_mask):
if src_key_padding_mask is not None:
_skpm_dtype = src_key_padding_mask.dtype
if _skpm_dtype != torch.bool and not _skpm_dtype.is_floating_point:

Comment on lines 1064 to 1068
if key_padding_mask is not None:
if key_padding_mask.dtype != torch.bool:
if not torch.is_floating_point(key_padding_mask):
raise AssertionError(
"only bool and floating type of key_padding_mask is supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

You are adding the same check thrice, which seems to warrant a convenience function

def _assert_if_tensor_is_not_float_or_bool(t: Optional[torch.Tensor], name: str) -> None:
    if t is None:
        return
   if t.dtype != torch.bool and not t.dtype.is_floating_point:
       raise AssertionError(f"only bool and floating types of {name} are supported")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good idea, but dont want to add new helper functions in this diff anymore in case it will break torch script :(

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 19, 2022
@mikekgfb
Copy link
Contributor

@pytorchbot merge

@malfet
Copy link
Contributor

malfet commented Oct 19, 2022

Also, please change title, as this PR is not 1.13 cherry pick, it simply targets master.
Something like: Assert if padding mask type is unexpected?

@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

The merge job was canceled. If you believe this is a mistake,then you can re trigger it through pytorch-bot.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 19, 2022
… & unit test (pytorch#87106)

Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Reviewed By: malfet

Differential Revision: D40129968

fbshipit-source-id: a46bc267d12bfc92b9a93cda5eb8409d6983a797
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 19, 2022
… & unit test (pytorch#87106)

Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Reviewed By: malfet

Differential Revision: D40129968

fbshipit-source-id: 4a3ac5750082b9b1806003e36b04edd96c36f538
@zrphercule zrphercule changed the title [PT1.13 cherry pick]Fix Transformer's issue when padding is long type & unit test (#86353) Assert if padding mask type is unexpected (#86353) Oct 19, 2022
zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 19, 2022
Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Reviewed By: malfet

Differential Revision: D40129968

fbshipit-source-id: abb38d9be37b93cad16ea9a5992926ec30965c2d
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 19, 2022
Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Reviewed By: malfet

Differential Revision: D40129968

fbshipit-source-id: 7e7ae6ceb0904f28811f291a2eadb0d406edebb3
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

@@ -1062,6 +1061,11 @@ def forward(self, query: Tensor, key: Tensor, value: Tensor, key_padding_mask: O
`batch_first` argument is ignored for unbatched inputs.
"""
is_batched = query.dim() == 3
if key_padding_mask is not None:
_skpm_dtype = key_padding_mask.dtype
if _skpm_dtype != torch.bool and not torch.is_floating_point(key_padding_mask):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why call a function rather than query the property directly?

Suggested change
if _skpm_dtype != torch.bool and not torch.is_floating_point(key_padding_mask):
if _skpm_dtype != torch.bool and not _skpm_dtype.is_floating_point:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@malfet I tagged you in phabricator. It is because some scripted tensors have really weird tensor dtype, like an "int" instead of torch.int. I pasted some links in pharicator, and msged you directly ;)

@@ -1062,6 +1061,11 @@ def forward(self, query: Tensor, key: Tensor, value: Tensor, key_padding_mask: O
`batch_first` argument is ignored for unbatched inputs.
"""
is_batched = query.dim() == 3
if key_padding_mask is not None:
_skpm_dtype = key_padding_mask.dtype
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable name supposed to start with first letter of long variable name, i.e. for key_padding_mask is should be _kpm_dtype

Suggested change
_skpm_dtype = key_padding_mask.dtype
_kpm_dtype = key_padding_mask.dtype

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol right

@zrphercule zrphercule added this to the 1.13.0 milestone Oct 20, 2022
Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Reviewed By: malfet

Differential Revision: D40129968

fbshipit-source-id: d7530d8c4548b9d3a3ef8b9740c93bee000ed809
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D40129968

@zrphercule
Copy link
Contributor Author

@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

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 3 additional jobs have failed, first few of them are: trunk ,trunk / linux-focal-rocm5.2-py3.7 / test (default, 2, 2, linux.rocm.gpu) ,trunk / cuda11.6-py3.10-gcc7-sm86 / test (default, 1, 4, linux.g5.4xlarge.nvidia.gpu)

Details for Dev Infra team Raised by workflow job

@ZainRizvi
Copy link
Contributor

@pytorchmergebot 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

zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 20, 2022
Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Reviewed By: malfet

Differential Revision: D40129968

fbshipit-source-id: d7530d8c4548b9d3a3ef8b9740c93bee000ed809
zrphercule added a commit to zrphercule/pytorch that referenced this pull request Oct 20, 2022
Summary:
Pull Request resolved: pytorch#87106

Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Reviewed By: malfet

Differential Revision: D40129968

fbshipit-source-id: d7530d8c4548b9d3a3ef8b9740c93bee000ed809
@zrphercule zrphercule deleted the export-D40129968 branch October 20, 2022 18:09
malfet pushed a commit that referenced this pull request Oct 20, 2022
Summary:
Pull Request resolved: #87106

Pull Request resolved: #86353

Fix the issue described in
#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Reviewed By: malfet

Differential Revision: D40129968

fbshipit-source-id: d7530d8c4548b9d3a3ef8b9740c93bee000ed809
sgrigory pushed a commit to sgrigory/pytorch that referenced this pull request Oct 28, 2022
)

Summary:
Pull Request resolved: pytorch#86353

Fix the issue described in
pytorch#86120

Test Plan: buck test mode/opt caffe2/test:test_transformers -- test_train_with_long_type_pad

Differential Revision: D40129968

Pull Request resolved: pytorch#87106
Approved by: https://github.com/malfet
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 fb-exported Merged release notes: nn release notes category topic: bc breaking topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants