I have somehow solved the issue - not sure why, but it runs when my custom trainer is the following. I also updated torch to the newest version, i.e. 1.10
class TrainerCustom(transformers.Trainer):
    # def __init__(self):
    #     super().__init__()

    def __init__(self, weights, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # initialize weights from argument
        self.weights = weights

    def compute_loss(self, model, inputs, return_outputs=False):
        """
        How the loss is computed by Trainer. By default, all models return the loss in the first element.
        Subclass and override for custom behavior.
        """
        labels = inputs.pop("labels").long()

        outputs = model(**inputs)

        print("LABELS:", labels)

        # Save past state if it exists
        if self.args.past_index >= 0:
            self._past = outputs[self.args.past_index]

        loss_func = torch.nn.CrossEntropyLoss(weight = self.weights.to(labels.device))

        loss = loss_func(outputs.get('logits'), labels)

        print("loss:", loss)

        return (loss, outputs) if return_outputs else loss```