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

Remove [None, :] #2418

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Remove [None, :] #2418

wants to merge 1 commit into from

Conversation

gab-chen
Copy link
Contributor

@gab-chen gab-chen commented Dec 24, 2022

Description of changes:
Minor code cleaning.
The [None, :] is unnecessary, because without [None, :] PyTorch broadcasting will also prepend 1 to the dimensions of torch.arange()'s output.

I tested the change by removing the [None, :] and running the masked_softmax()code below in 11.3.2.1.
The output are the same as when we have [None, :], in terms of the numbers of masked and unmasked elements.
I pasted the output below. You can compare it with the output on the website.

masked_softmax(torch.rand(2, 2, 4), torch.tensor([2, 3]))
tensor([[[0.5670, 0.4330, 0.0000, 0.0000],
         [0.5983, 0.4017, 0.0000, 0.0000]],

        [[0.4297, 0.3518, 0.2185, 0.0000],
         [0.3578, 0.3347, 0.3075, 0.0000]]])
masked_softmax(torch.rand(2, 2, 4), torch.tensor([[1, 3], [2, 4]]))
tensor([[[1.0000, 0.0000, 0.0000, 0.0000],
         [0.4129, 0.3338, 0.2533, 0.0000]],

        [[0.4291, 0.5709, 0.0000, 0.0000],
         [0.2964, 0.2290, 0.1903, 0.2844]]])

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

@d2l-bot
Copy link
Member

d2l-bot commented Dec 24, 2022

Job d2l-en/PR-2418/1 is complete.
Check the results at http://preview.d2l.ai/d2l-en/PR-2418/

@d2l-bot
Copy link
Member

d2l-bot commented Dec 24, 2022

Job d2l-en/PR-2418/2 is complete.
Check the results at http://preview.d2l.ai/d2l-en/PR-2418/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants