I am trying to run Trainer from Hugging face(pytorch) with arguments parser. My code looks like
if __name__ == '__main__':
parser = HfArgumentParser(TrainingArguments)
parser.add_argument('--model_name_or_path', type=str, required=True)
.
.
.
.
training_args = parser.parse_args()
print('args', training_args)
os.makedirs(training_args.output_dir, exist_ok=True)
random.seed(training_args.seed)
set_seed(training_args.seed)
dataset_train = ...
.
.
.
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataloader,
eval_dataset=val_dataloader)
trainer.train()
I am getting the following error:
Traceback (most recent call last):
File "main.py", line 250, in <module>
eval_dataset=val_dataloader)
File "C:\User\transformer\lib\site-
packages\transformers\trainer.py", line 316, in __init__
log_level = args.get_process_log_level()
AttributeError: 'Namespace' object has no attribute 'get_process_log_level
Any idea about this error and how to solved it?
First check that this works for you:
from transformers import TrainingArguments
args = TrainingArguments(output_dir='./')
args.get_process_log_level()
[out]:
20
If it doesn't then most probably the version of transformers
you have on C:\User\transformer\lib\site-packages\transformers
doesn't match the Trainer script you have. Then try to upgrade your transformers version pip install -U transformers
.
If you get the 20
output but when you run your script you're getting the error, then most probably the version of your transformers is from a previous version that doesn't have the get_process_log_level()
in the TrainingArguments
as a property.
Add this line at the top of your code and check that the
import sys; print(sys.executable)
you'll get something like
[out]:
C://something/somewhere/bin/python
and with that do this to upgrade the library to the right site-package location and python binary
C://something/somewhere/bin/python -m pip install -U transformers
After upgrading the script should run.