tinygrad / tinygrad

You like pytorch? You like micrograd? You love tinygrad! ❤️
MIT License
26.31k stars 2.89k forks source link

`__setitem__` raises "self operand of augmented assign must be contiguous" even though it is #6352

Open obadakhalili opened 2 weeks ago

obadakhalili commented 2 weeks ago

Code

N = Tensor.zeros((3, 3)).contiguous()

for i in range(3):
  for j in range(3):
    N[i][j] += 1

Expectation

N to be a 3x3 matrix of 1's.

Reality

tinygrad throws RuntimeError: self operand of augmented assign must be contiguous.

Cheapshot003 commented 2 weeks ago

Doesn't Tensor.zeros((3, )) just create a 1D array of size 3?

obadakhalili commented 2 weeks ago

thanks for noting this typo @Cheapshot003. however, the issue persists.

Cheapshot003 commented 2 weeks ago

Can confirm the issue. It works when you do N[i, j] = N[i, j] + 1

Should be investigated by someone who knows the internals better

obadakhalili commented 2 weeks ago

that is a nice workaround but it is very slow. I think this is a separate issue of indexing being very slow.

gordbegli commented 1 week ago

This still isn't ideal, but a faster workaround for some scenarios is to create a numpy array, perform inplace assignments on it, then convert it into a Tensor.