# Huggingface Trainer eval while training

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingface-trainer-eval-while-training%2F28650%3E%5C
**Category:** 🤗Transformers\
**Created:** [December 30, 2022, 5:40pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingface-trainer-eval-while-training%2F28650 "2022-12-30T17:40:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![liumaishen](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@liumaishen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fliumaishen)%5C
**Post date:** [December 30, 2022, 5:40pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingface-trainer-eval-while-training%2F28650%2F1 "2022-12-30T17:40:09Z")

</div>

when I ran this script [run\_mlm.py](https://github.com/huggingface/transformers/blob/main/examples/pytorch/language-modeling/run_mlm.py), I set do eval every 2000 steps, but after first 2000 steps training and start to eval，I got this problem：

```auto
    train_result = trainer.train(resume_from_checkpoint=checkpoint)
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer.py", line 1501, in train
    return inner_training_loop(
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer.py", line 1826, in _inner_training_loop
    self._maybe_log_save_evaluate(tr_loss, model, trial, epoch, ignore_keys_for_eval)
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer.py", line 2089, in _maybe_log_save_evaluate
    metrics = self.evaluate(ignore_keys=ignore_keys_for_eval)
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer.py", line 2796, in evaluate
    output = eval_loop(
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer.py", line 2974, in evaluation_loop
    loss, logits, labels = self.prediction_step(model, inputs, prediction_loss_only, ignore_keys=ignore_keys)
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer.py", line 3239, in prediction_step
    logits = nested_detach(logits)
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer_pt_utils.py", line 165, in nested_detach
    return type(tensors)(nested_detach(t) for t in tensors)
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer_pt_utils.py", line 165, in <genexpr>
    return type(tensors)(nested_detach(t) for t in tensors)
  File "/home/yzhang/anaconda3/envs/ke/lib/python3.8/site-packages/transformers/trainer_pt_utils.py", line 168, in nested_detach
    return tensors.detach()
AttributeError: 'float' object has no attribute 'detach'

```

This is a error in eval. My eval\_dataset has the same structure with train\_dataset.  
How should I do？  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsgugger)%5C
**Post date:** [December 31, 2022, 6:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingface-trainer-eval-while-training%2F28650%2F2 "2022-12-31T06:23:47Z")

</div>

Could you provide us the exact command you ran to launch this script?
