C1W1 Assertion error. using cuda

In get_noise function i did pass the argument device=‘cuda’ but, it is throwing assertion error.

Hi @meazi, Welcome to the community.

I believe that in the get_noise method you are not creating the noise tensor in the correct device. You can create your noise tensor in the right device in either of the following two ways:

  1. You can use the device argument of torch.randn method so that your noise tensor is created in the right device. For instance, torch.randn(10, 10, device = device).
  2. You can use “to” method to transfer any pytorch tensor to the correct device. For instance, torch.randn(10, 10).to(device)

Let me know if you still face any issues.

Thank you for your responce. I did pass the device argument like that. It still throws the error. can the error be because i dont have NVIDEA driver?

In the test_gen_noise method, can you print the following statement before the assert statement and paste the output here in this thread so that I can help you better.

print("Noise Device:", str(noise.device), "   Target:", device)

After running the cell, make sure you delete this print statement because it may cause failure while submitting the assignment.


My guess is that you have mistakenly hardcoded device = “cuda” while creating the random noise tensor. As the output is telling that the target device is cpu but your random noise is created in gpu. Make sure that you are creating the random noise in the get_noise method as follows:

random_tensor = torch.randn(n_samples, z_dim, device = device)

@28utkarsh I used this code


Hi @meazi ,

Remove the first line device = “cuda” because every time the code will create the tensor in GPU.

You can see that in the test_gen_noise method that it is passing the device type either cpu or gpu. That test case makes sure that the tensor is created in the correct device.

Hello @28utkarsh thank you very much. It worked.