Advices on some cases hard to remove cuda() call.
❓ Questions and Help
What is your question?
I understand that it's beneficial to remove .cuda() or .to() calls to make the code flexible. But I experience in some cases it's hard to know on what device my tensor is.
In the following code, my batch is raw strings, so the batch is passed as pure python list not tensor. In this case how can I use .type_as() to move my newly created tensor to relevant device? Help needed.
Code
def training_step(self, batch, batch_idx):
    x, y = batch # x = list(), not tensor.

    # put the z on the appropriate gpu or tpu core
    z = sample_noise()
    z = z.type_as(x.type()) # still I need to move z to relevant device depending on situation. What should I do?