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

makemore/lecture4/backprop/dC #57

Open
we89 opened this issue Jun 26, 2024 · 2 comments
Open

makemore/lecture4/backprop/dC #57

we89 opened this issue Jun 26, 2024 · 2 comments

Comments

@we89
Copy link

we89 commented Jun 26, 2024

dC = torch.zeros_like(C)
for k in range(Xb.shape[0]):
    dC[Xb[k]] += demb[k]

I don't know why it is `wrong.
And the correct answer is:

dC = torch.zeros_like(C)
for k in range(Xb.shape[0]):
    for j in range(Xb.shape[1]):
        ix = Xb[k,j]
        dC[ix] += demb[k,j]
@Mountagha
Copy link

What is your question. Can you elaborate more clearly ?

@junqi-lu
Copy link

It's an issue about how PyTorch (or numpy?) manages in-place operations and advanced indexing with repeating indices, it seems PyTorch only adds the last corresponding row from src to the specified index.

So if Xb[0]=[1,1,1], dC[1] will add the last row of demb[0], which is demb[0][2], not to accumulate demb[0][0], demb[0][1] and demb[0][2].

You can find more in this.

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

3 participants