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] - unpack error in CUDA extension tutorial #2687

Open
aurada opened this issue Nov 18, 2023 · 0 comments · May be fixed by #2688
Open

[BUG] - unpack error in CUDA extension tutorial #2687

aurada opened this issue Nov 18, 2023 · 0 comments · May be fixed by #2688
Labels

Comments

@aurada
Copy link

aurada commented Nov 18, 2023

Add Link

https://pytorch.org/tutorials/advanced/cpp_extension.html

Describe the bug

Code to reproduce the issue.

import time

import torch

batch_size = 16
input_features = 32
state_size = 128

# Check if CUDA (GPU) is available
if torch.cuda.is_available():
    # Set the device to CUDA
    device = torch.device("cuda")
    print("CUDA is available. Using GPU.")
else:
    # If CUDA is not available, fall back to CPU
    device = torch.device("cpu")
    print("CUDA is not available. Using CPU.")

X = torch.randn(batch_size, input_features, device=device)
h = torch.randn(batch_size, state_size, device=device)
C = torch.randn(batch_size, state_size, device=device)

rnn = LLTM(input_features, state_size).to(device)

forward = 0
backward = 0
for _ in range(2):
    start = time.time()
    new_h, new_C = rnn(X, (h, C))
    forward += time.time() - start

    start = time.time()
    (new_h.sum() + new_C.sum()).backward()
    backward += time.time() - start

print('Forward: {:.3f} s | Backward {:.3f} s'.format(forward, backward))

Error info:

Traceback (most recent call last):
  File "toy_model.py", line 74, in <module>
    (new_h.sum() + new_C.sum()).backward()
  File "/home/username/miniconda3/envs/tmp/lib/python3.8/site-packages/torch/_tensor.py", line 492, in backward
    torch.autograd.backward(
  File "/home/username/miniconda3/envs/tmp/lib/python3.8/site-packages/torch/autograd/__init__.py", line 251, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
  File "/home/username/miniconda3/envs/tmp/lib/python3.8/site-packages/torch/autograd/function.py", line 288, in apply
    return user_fn(self, *args)
  File "toy_model.py", line 25, in backward
    d_old_h, d_input, d_weights, d_bias, d_old_cell = outputs
ValueError: too many values to unpack (expected 5)

Describe your environment

  • Platform: Ubuntu
  • CUDA: yes
  • Pytorch Version: 2.1.0+cu118
@aurada aurada added the bug label Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant