Open oObelix opened 8 months ago
I found this error on my macOS
cc @tomaarsen
gonna piggy back off this, I had a very similar error that was also about the model.config
File "/opt/conda/lib/python3.10/runpy.py", line 187, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/opt/conda/lib/python3.10/runpy.py", line 110, in _get_module_details __import__(pkg_name) File "/home/jupyter/setfit_test.py", line 39, in <module> trainer.train() File "/opt/conda/lib/python3.10/site-packages/setfit/trainer.py", line 410, in train self.train_embeddings(*full_parameters, args=args) File "/opt/conda/lib/python3.10/site-packages/setfit/trainer.py", line 462, in train_embeddings self._train_sentence_transformer( File "/opt/conda/lib/python3.10/site-packages/setfit/trainer.py", line 570, in _train_sentence_transformer self.control = self.callback_handler.on_train_begin(args, self.state, self.control) File "/opt/conda/lib/python3.10/site-packages/transformers/trainer_callback.py", line 370, in on_train_begin return self.call_event("on_train_begin", args, state, control) File "/opt/conda/lib/python3.10/site-packages/transformers/trainer_callback.py", line 414, in call_event result = getattr(callback, event)( File "/opt/conda/lib/python3.10/site-packages/transformers/integrations/integration_utils.py", line 635, in on_train_begin model_config_json = model.config.to_json_string() AttributeError: 'dict' object has no attribute 'to_json_string'
when I tried to run the setfit example. What seems to have fixed this for me is to downgrade huggingface hub pip install huggingface_hub==0.20.3
with this version it is working both on my Mac with cpu as well as on google cloud with cuda. Hope that helps :)
I had the same issue with the NeptuneCallback. Worked locally, but got the error in a Docker container on the cloud.
It seems pretty weird to me, because there is no model passed to the on_train_begin
here and the model
is set to None
by default in the callback here, so I think you can just overwrite the class method and delete these lines here.
Or maybe you can catch the AttributeError
like this:
if hasattr(model, "config") and model.config is not None:
try:
model_config = model.config.to_dict()
except AttributeError:
model_config = model.config
combined_dict = {**model_config, **combined_dict}
This solved my case, because somehow there really was a dict
with the model.config
, but I could not see why this happened.
I also had to rewrite the on_init_end
and on_save
methods of the NeptuneCallback
, because of conflicts like these.
In my case, this error popped up after enabling wandb
logging.
@tomaarsen I submitted a draft PR on the transformers
repository. I wonder if that is the best place to fix the issue.
Getting the same issue as @davhin when running in a vertexAI notebook (google cloud), but not when run locally
Same issue on Windows 10, Python 3.10.13
Same issue on Ubunutu 22.04 and Pop!_OS 22.04.
transformers
version: 4.38.2Issue arose following the SetFit quickstart guide. Crash on step 4:
trainer.train()
***** Running training *****
Num unique pairs = 144
Batch size = 32
Num epochs = 10
Total optimization steps = 50
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[17], line 1
----> 1 trainer.train()
File ~/projects/NLP/intentionclassification/.venv/lib/python3.10/site-packages/setfit/trainer.py:410, in Trainer.train(self, args, trial, **kwargs)
405 train_parameters = self.dataset_to_parameters(self.train_dataset)
406 full_parameters = (
407 train_parameters + self.dataset_to_parameters(self.eval_dataset) if self.eval_dataset else train_parameters
408 )
--> 410 self.train_embeddings(*full_parameters, args=args)
411 self.train_classifier(*train_parameters, args=args)
File ~/projects/NLP/intentionclassification/.venv/lib/python3.10/site-packages/setfit/trainer.py:462, in Trainer.train_embeddings(self, x_train, y_train, x_eval, y_eval, args)
459 logger.info(f" Total optimization steps = {total_train_steps}")
461 warmup_steps = math.ceil(total_train_steps * args.warmup_proportion)
--> 462 self._train_sentence_transformer(
463 self.model.model_body,
464 train_dataloader=train_dataloader,
465 eval_dataloader=eval_dataloader,
466 args=args,
467 loss_func=loss_func,
468 warmup_steps=warmup_steps,
469 )
File ~/projects/NLP/intentionclassification/.venv/lib/python3.10/site-packages/setfit/trainer.py:570, in Trainer._train_sentence_transformer(self, model_body, train_dataloader, eval_dataloader, args, loss_func, warmup_steps)
568 else:
569 self.state.max_steps = len(train_dataloader) * args.embedding_num_epochs
--> 570 self.control = self.callback_handler.on_train_begin(args, self.state, self.control)
571 steps_per_epoch = len(train_dataloader)
573 if args.use_amp:
File ~/projects/NLP/intentionclassification/.venv/lib/python3.10/site-packages/transformers/trainer_callback.py:370, in CallbackHandler.on_train_begin(self, args, state, control)
368 def on_train_begin(self, args: TrainingArguments, state: TrainerState, control: TrainerControl):
369 control.should_training_stop = False
--> 370 return self.call_event("on_train_begin", args, state, control)
File ~/projects/NLP/intentionclassification/.venv/lib/python3.10/site-packages/transformers/trainer_callback.py:414, in CallbackHandler.call_event(self, event, args, state, control, **kwargs)
412 def call_event(self, event, args, state, control, **kwargs):
413 for callback in self.callbacks:
--> 414 result = getattr(callback, event)(
415 args,
416 state,
417 control,
418 model=self.model,
419 tokenizer=self.tokenizer,
420 optimizer=self.optimizer,
421 lr_scheduler=self.lr_scheduler,
422 train_dataloader=self.train_dataloader,
423 eval_dataloader=self.eval_dataloader,
424 **kwargs,
425 )
426 # A Callback can skip the return of `control` if it doesn't change it.
427 if result is not None:
File ~/projects/NLP/intentionclassification/.venv/lib/python3.10/site-packages/transformers/integrations/integration_utils.py:1035, in MLflowCallback.on_train_begin(self, args, state, control, model, **kwargs)
1033 def on_train_begin(self, args, state, control, model=None, **kwargs):
1034 if not self._initialized:
-> 1035 self.setup(args, state, model)
File ~/projects/NLP/intentionclassification/.venv/lib/python3.10/site-packages/transformers/integrations/integration_utils.py:1009, in MLflowCallback.setup(self, args, state, model)
1007 combined_dict = args.to_dict()
1008 if hasattr(model, "config") and model.config is not None:
-> 1009 model_config = model.config.to_dict()
1010 combined_dict = {**model_config, **combined_dict}
1011 combined_dict = flatten_dict(combined_dict) if self._flatten_params else combined_dict
AttributeError: 'dict' object has no attribute 'to_dict'```
remove duplicate keys from your config.json
I had the same problem but after a full 2 hour debugging noticed I have upgraded my transformers
from 4.37.2
which the model was initially trained to 4.41
. I reverted back the transformers to its initial version (You can find it in the model config.json
) and the error was resolved.
System Info
Python 3.11.8
Who can help?
No response
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
Expected behavior
Hello! How to pass this error? In my case all work locally on macOs, but didn't work on same data in Docker container.. Didn't work in container FROM --platform=linux/amd64 python:3.11-slim (Linux 027a6910b09d 6.4.16-linuxkit huggingface/transformers#1 SMP PREEMPT Sat Sep 23 13:36:48 UTC 2023 x86_64 GNU/Linux) but work on debian-buster-slim (Linux 12-slim 6.4.16-linuxkit huggingface/transformers#1 SMP PREEMPT Sat Sep 23 13:36:48 UTC 2023 aarch64 GNU/Linux).