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

[Bug] binary arithmetic with CUDA scalar #95

Closed
soodoshll opened this issue Feb 12, 2023 · 1 comment · Fixed by #109
Closed

[Bug] binary arithmetic with CUDA scalar #95

soodoshll opened this issue Feb 12, 2023 · 1 comment · Fixed by #109

Comments

@soodoshll
Copy link
Collaborator

In

It looks like in order to calculate a binary operator with a scalar on GPU, we need to first copy it to CPU (Is it expected? Will it affect the performance because of synchronization?). And the cpu() function raises an error saying we should first detach the variable in

return self.cpu().numpy().tolist()
.

If we add detach here, here comes the second problem. It looks like the .numpy(or to_dlpack) method does not support a tensor with only one element and shape []. The error message is like:

  File "/home/su/accdiff/thirdparty/hidet/python/hidet/graph/ops/definitions/arithmetic.py", line 529, in divide
    return binary_arithmetic(
  File "/home/su/accdiff/thirdparty/hidet/python/hidet/graph/ops/definitions/arithmetic.py", line 479, in binary_arithmetic
    x = x.dtype(x.item())
  File "/home/su/accdiff/thirdparty/hidet/python/hidet/graph/tensor.py", line 528, in item
    ret = self.squeeze(dims=list(range(len(self.shape)))).tolist()
  File "/home/su/accdiff/thirdparty/hidet/python/hidet/graph/tensor.py", line 488, in tolist
    ret = ret.numpy()
  File "/home/su/accdiff/thirdparty/hidet/python/hidet/graph/tensor.py", line 930, in numpy
    return np.from_dlpack(self)
  File "/home/su/accdiff/thirdparty/hidet/python/hidet/graph/tensor.py", line 467, in __dlpack__
    return to_dlpack(self)
  File "/home/su/accdiff/thirdparty/hidet/python/hidet/graph/impl/dlpack.py", line 251, in to_dlpack
    return DLManagedTensorContext(tensor).capsuled_dltensor()
  File "/home/su/accdiff/thirdparty/hidet/python/hidet/graph/impl/dlpack.py", line 229, in __init__
    data=tensor.storage.addr,
AttributeError: 'NoneType' object has no attribute 'addr'
@yaoyaoding
Copy link
Member

Thanks @soodoshll!

KTong821 added a commit to KTong821/hidet that referenced this issue Apr 24, 2024
Stable diffusion uses fundamentally the same positional embeddings, but
since timesteps change, a cache is not possible.

There's also small changes in tensor layouts and calculation parameters
between the diffusers version and the one from Llama, so I've recreated
it here for now. An abstract version that combines both version is TODO.

Towards hidet-org#57.
vadiklyutiy pushed a commit that referenced this issue Jul 22, 2024
Stable diffusion uses fundamentally the same positional embeddings, but
since timesteps change, a cache is not possible.

There's also small changes in tensor layouts and calculation parameters
between the diffusers version and the one from Llama, so I've recreated
it here for now. An abstract version that combines both version is TODO.

Towards #57.
vadiklyutiy pushed a commit that referenced this issue Jul 23, 2024
Stable diffusion uses fundamentally the same positional embeddings, but
since timesteps change, a cache is not possible.

There's also small changes in tensor layouts and calculation parameters
between the diffusers version and the one from Llama, so I've recreated
it here for now. An abstract version that combines both version is TODO.

Towards #57.
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 a pull request may close this issue.

2 participants