Expected u.is_cuda() to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)

              for cat in sem_class_to_idx.keys():
                  if cat == '__background__':
                    continue

                  car_category = sem_class_to_idx[cat]
                  car_mask = output[0, :, :, :].argmax(axis=0).detach().cpu().numpy()
                  car_mask_uint8 = 255 * np.uint8(car_mask == car_category)
                  car_mask_float = np.float32(car_mask == car_category)
                  target_layer = [layer]
                  targets = [SemanticSegmentationTarget(car_category, car_mask_float)]

                  with GradCAM(model=Attention_UNet(),
                              target_layers=target_layer,
                              # use_cuda=torch.cuda.is_available()
                              reshape_transform=True
                              # use_cuda = False
                              ) as cam:

                          grayscale_cam = cam(input_tensor=input_tensor.transpose(-1,-3),
                                              targets=targets)[0, :]
                          cam_image = show_cam_on_image( np.repeat([min_max_preprocess(img)], 3, axis=0).transpose(1,2,0), grayscale_cam, use_rgb=True)

                          list_img.append(cam_image)

I got error: RuntimeError Traceback (most recent call last)
in <cell line: 18>()
43 ) as cam:
44
—> 45 grayscale_cam = cam(input_tensor=input_tensor.transpose(-1,-3),
46 targets=targets)[0, :]
47 cam_image = show_cam_on_image( np.repeat([min_max_preprocess(img)], 3, axis=0).transpose(1,2,0), grayscale_cam, use_rgb=True)

/usr/local/lib/python3.10/dist-packages/mamba_ssm/ops/selective_scan_interface.py in forward(ctx, u, delta, A, B, C, D, z, delta_bias, delta_softplus, return_last_state)
40 C = rearrange(C, “b dstate l → b 1 dstate l”)
41 ctx.squeeze_C = True
—> 42 out, x, *rest = selective_scan_cuda.fwd(u, delta, A, B, C, D, z, delta_bias, delta_softplus)
43 ctx.delta_softplus = delta_softplus
44 ctx.has_z = z is not None

RuntimeError: Expected u.is_cuda() to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)

Looks like your model is on cuda but one of the inputs is not? check e.g., the device of the tensors passed such as input_tensor and whether they are all on gpu as expected

Thank. I added input_tensor.cuda() and still have the above problem

Unsure where and how you’ve added it, but keep in mind that cuda() and to() operations are not performed inplace on tensors. You would thus need to reassign the tensor via input_tensor = input_tensor.cuda().

1 Like