Issue when customizing loss in Trainer
Hi everyone,

I am a student and therefore not yet very familiar with the way issues report work on git, so I aplogize in advance if this is not the proper place to post this message.
I'm trying to customize the loss to use a weighted CrossEntropyLoss, I browsed the issues reports and saw that this matter was already mentionned and a solution was brought by the developpers (I think it was @sgugger) of the Transformers library, I tried to follow their code snipets as much as possible but always ended up with the same error.

I'm working with the last version of Transformers and this is my code:

```
config = AutoConfig.from_pretrained("bert-base-cased", num_labels=2, finetuning_task="SST-2")

# Test with modified trainer for weighted CrossEntropyLoss

model = AutoModelForSequenceClassification.from_pretrained(
        "dmis-lab/biobert-base-cased-v1.1",
        from_tf=False,
        config=config)

from torch import FloatTensor

classDistribution_raw = [97, 3]
classDistribution = [0.8, 0.2]
normedWeights = [1 - (x / sum(classDistribution)) for x in classDistribution]
normedWeights = FloatTensor(normedWeights).cuda()

from torch.nn import CrossEntropyLoss

class MyTrainer(Trainer):
    def compute_loss(self, model, inputs, return_outputs=False):
        
        if "labels" in inputs:
          labels = inputs.pop("labels")
        
        outputs = model(**inputs)
        logits = outputs.logits
        loss_function = CrossEntropyLoss(weight = normedWeights)

        if self.args.past_index >= 0:
            self._past = outputs[self.args.past_index]

        if labels is not None:
            loss = loss_function(logits, labels)
        else:
            # We don't use .loss here since the model may return tuples instead of ModelOutput.
            loss = outputs["loss"] if isinstance(outputs, dict) else outputs[0]

        return (loss, outputs) if return_outputs else loss

trainer = MyTrainer(
        model=model,
        args=training_args,
        train_dataset=train_dataset,
        eval_dataset=eval_dataset,
        compute_metrics=compute_metrics_fn,
        tokenizer=tokenizer,
    )
```
And this is the error I keep getting:
`'NoneType' object has no attribute 'detach'`

I'm probably doing something wrong but I can't understand what.

Thanks in advance for your answers, I stay availble if u need any more details about my set up or my code,
Best regards,
Arthur Ledaguenel
I think you may be experiencing a bug that was fixed since then (I would need the whole error message to be sure) so before we dive further, could you see if an [install from source](https://huggingface.co/transformers/installation.html#installing-from-source) solves your problem?<|||||>Hi @sgugger,

Thank you very much for the quick answer, I tested with the installation from source and he it worked !