Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a condition for nested_detach #31852

Closed
2 of 4 tasks
haikuoxin opened this issue Jul 9, 2024 · 0 comments · Fixed by #31855
Closed
2 of 4 tasks

Add a condition for nested_detach #31852

haikuoxin opened this issue Jul 9, 2024 · 0 comments · Fixed by #31855

Comments

@haikuoxin
Copy link
Contributor

System Info

When use Trainer to train a VLM like 'internlm/internlm-xcomposer2-vl-7b' with evaluation_strategy, an AttributeError error will be triggered like below:

trainer.train()
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer.py", line 1553, in train
    return inner_training_loop(
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer.py", line 1927, in _inner_training_loop
    self._maybe_log_save_evaluate(tr_loss, model, trial, epoch, ignore_keys_for_eval)
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer.py", line 2254, in _maybe_log_save_evaluate
    metrics = self.evaluate(ignore_keys=ignore_keys_for_eval)
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer.py", line 2968, in evaluate
    output = eval_loop(
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer.py", line 3157, in evaluation_loop
    loss, logits, labels = self.prediction_step(model, inputs, prediction_loss_only, ignore_keys=ignore_keys)
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer.py", line 3347, in prediction_step
    labels = nested_detach(tuple(inputs.get(name) for name in self.label_names))
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer_pt_utils.py", line 166, in nested_detach
    return type(tensors)(nested_detach(t) for t in tensors)
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer_pt_utils.py", line 166, in <genexpr>
    return type(tensors)(nested_detach(t) for t in tensors)
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer_pt_utils.py", line 168, in nested_detach
    return type(tensors)({k: nested_detach(t) for k, t in tensors.items()})
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer_pt_utils.py", line 168, in <dictcomp>
    return type(tensors)({k: nested_detach(t) for k, t in tensors.items()})
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer_pt_utils.py", line 166, in nested_detach
    return type(tensors)(nested_detach(t) for t in tensors)
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer_pt_utils.py", line 166, in <genexpr>
    return type(tensors)(nested_detach(t) for t in tensors)
  File "/root/anaconda3/envs/sharegpt4v/lib/python3.10/site-packages/transformers/trainer_pt_utils.py", line 169, in nested_detach
    return tensors.detach()
AttributeError: 'str' object has no attribute 'detach'

Who can help?

@muellerzr

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

  1. load the model and tokenizer with from_pretrained method
  2. set training_args
  3. build train_dataset and eval_dataset, the dataset return Dict[str, str]
  4. create a trainer with Trainer API then trainer.train()

Expected behavior

Model should be train normally

haikuoxin added a commit to haikuoxin/transformers that referenced this issue Jul 9, 2024
amyeroberts pushed a commit that referenced this issue Jul 10, 2024
amyeroberts pushed a commit to amyeroberts/transformers that referenced this issue Jul 19, 2024
MHRDYN7 pushed a commit to MHRDYN7/transformers that referenced this issue Jul 23, 2024
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this issue Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant