Fixed the MultilabelTrainer document, which would cause a potential bug when executing the code originally documented. #13414
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
if train with the MultilabelTrainer documented in the original document
a bug that looks like this would appear:
File "~/anaconda3/lib/python3.8/site-packages/transformers/trainer.py", in train self._maybe_log_save_evaluate(tr_loss, model, trial, epoch) File "~/anaconda3/lib/python3.8/site-packages/transformers/trainer.py", in _maybe_log_save_evaluate metrics = self.evaluate() File "~/anaconda3/lib/python3.8/site-packages/transformers/trainer.py", in evaluate output = self.prediction_loop( File "~/anaconda3/lib/python3.8/site-packages/transformers/trainer.py", in prediction_loop loss, logits, labels = self.prediction_step(model, inputs, prediction_loss_only, ignore_keys=ignore_keys) File "~/anaconda3/lib/python3.8/site-packages/transformers/trainer.py", in prediction_step labels = nested_detach(tuple(inputs.get(name) for name in self.label_names)) File "~/anaconda3/lib/python3.8/site-packages/transformers/trainer_pt_utils.py", in nested_detach return type(tensors)(nested_detach(t) for t in tensors) File "~/anaconda3/lib/python3.8/site-packages/transformers/trainer_pt_utils.py", in <genexpr> return type(tensors)(nested_detach(t) for t in tensors) File "~/anaconda3/lib/python3.8/site-packages/transformers/trainer_pt_utils.py", in nested_detach return tensors.detach() AttributeError: 'NoneType' object has no attribute 'detach'
change the original code to below would effectively avoid this bug.