I tried that too but still the error is same.

example = torch.rand(1, 3, 224, 224)
example = example.cuda()
model_trace = torch.jit.trace(modelx, example)

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!