I have a similar error that I think is arising when I try to use sklearn’s roc_auc_score:
Exception has occurred: TypeError
Caught TypeError in replica 0 on device 0.
Original Traceback (most recent call last):
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/torch/nn/parallel/parallel_apply.py", line 61, in _worker
    output = module(*input, **kwargs)
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/pytorch_lightning/overrides/data_parallel.py", line 77, in forward
    output = super().forward(*inputs, **kwargs)
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/pytorch_lightning/overrides/base.py", line 57, in forward
    output = self.module.validation_step(*inputs, **kwargs)
  File "/home/ubuntu/deep-behavior-embedding/src/model/lightning_model.py", line 144, in validation_step
    auc = roc_auc_score(y_true=y, y_score=torch.sigmoid(x))
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 63, in inner_f
    return f(*args, **kwargs)
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/sklearn/metrics/_ranking.py", line 522, in roc_auc_score
    y_type = type_of_target(y_true)
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/sklearn/utils/multiclass.py", line 261, in type_of_target
    if is_multilabel(y):
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/sklearn/utils/multiclass.py", line 147, in is_multilabel
    y = np.asarray(y)
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/numpy/core/_asarray.py", line 102, in asarray
    return array(a, dtype, copy=False, order=order)
  File "/home/ubuntu/deep-behavior-embedding/.virtualenv/lib/python3.7/site-packages/torch/_tensor.py", line 643, in __array__
    return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
  File "/home/ubuntu/deep-behavior-embedding/finetune.py", line 108, in <module>
    trainer.fit(model, datamodule=dm)

The code is here:
    def validation_step(self, batch, batch_idx):
        x = batch['src']
        y = batch['label']
        mask = batch['mask']

        x = self.base_model(x, mask)
        x = self.linear(x).mean(axis=1).squeeze(1)
        
        loss = F.binary_cross_entropy_with_logits(input=x,
                               target=y)
        self.log('val_loss', loss)
        try:
            auc = roc_auc_score(y_true=y, y_score=torch.sigmoid(x))
            self.log('auc', auc)
        except ValueError:
            self.log('auc', 0)
        return loss


Should I be converting to numpy arrays? I’m afraid this might slow things down.