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

Factorized code for dC in makemore_part4_backprop.ipynb #29

Open
bzkhalil opened this issue Mar 5, 2023 · 1 comment
Open

Factorized code for dC in makemore_part4_backprop.ipynb #29

bzkhalil opened this issue Mar 5, 2023 · 1 comment

Comments

@bzkhalil
Copy link

bzkhalil commented Mar 5, 2023

First thanks a lot Andreij for the great series,
Here is the factorized version for dC
one_hot_Xb = F.one_hot(Xb,27).view((Xb.shape[0]*Xb.shape[1],27)).float()
dC = one_hot_Xb.T @ demb.view((demb.shape[0]*demb.shape[1],demb.shape[2]))

I came up with it mainly through shape comparaison, could you please look into it :-)

@marcdumon
Copy link

marcdumon commented May 16, 2023

Seems correct to me.
I came up with solution that is slightly slower but more clear:

Xb_1hot = F.one_hot(Xb, 27).float()  # 32 x 3 x 27   
d_C = torch.einsum('ijk,ijl->kl', Xb_1hot, d_emb))  # 27 x 10

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

No branches or pull requests

2 participants