microsoft / Oscar

Oscar and VinVL
MIT License
1.04k stars 252 forks source link

ModuleNotFoundError: No module named 'transformers.pytorch_transformers' #59

Closed NguyenVanThanhHust closed 3 years ago

NguyenVanThanhHust commented 3 years ago

Hi, thank for your work.

I'm trying to finetune for image captioning task. When i run

python oscar/run_captioning.py \
    --model_name_or_path pretrained_models/base-vg-labels/ep_67_588997 \
    --do_train \
    --do_lower_case \
    --evaluate_during_training \
    --add_od_labels \
    --learning_rate 0.00003 \
    --per_gpu_train_batch_size 64 \
    --num_train_epochs 30 \
    --save_steps 5000 \
    --output_dir output/

I encounter this error

2021-02-04 06:41:10.151589: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64
2021-02-04 06:41:10.151621: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    from transformers.pytorch_transformers.modeling_utils import PreTrainedModel
ModuleNotFoundError: No module named 'transformers.pytorch_transformers'

I clone this repo with cmd

git clone https://github.com/microsoft/Oscar.git
git submodule init
git submodule update

How could i fix this issue?

brightbsit commented 3 years ago

Check if u have a transformers folder and files and put right directory path on the code.

NguyenVanThanhHust commented 3 years ago

Hi @brightbsit,

I have transformers folder, i git cloned that folder in above comment. I checked file in that folder too. There are folder pytorch_transformers.

And what do you mean about " put right directory path on the code"?

I clone from this git, both main and submodule. Am I supposed to put folder "transformers" somewhere else?

brightbsit commented 3 years ago

I also have the same error and change the path on the code.

change the line 5 in file "test.py". also "python setup.py build develop" might help.

NguyenVanThanhHust commented 3 years ago

How shoud i change that line ? This is line 5

from transformers.pytorch_transformers.modeling_utils import PreTrainedModel

What should i change it too?

brightbsit commented 3 years ago

Umm it depends on the folder states. I think i just add . In the beginning

NguyenVanThanhHust commented 3 years ago

Is this what you mean?

from .transformers.pytorch_transformers.modeling_utils import PreTrainedModel

If so then the error is:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    from .transformers.pytorch_transformers.modeling_utils import PreTrainedModel
ImportError: attempted relative import with no known parent package

And what do you mean about folder states? I leaves the folder structure as in git.

And python setup.py build develop doesn't work either.

brightbsit commented 3 years ago

I don't have any problem with the test. But I can't find test.py file on my oscar folder. Where did u get test.py file?

the code will be gone when you fix the path.

NguyenVanThanhHust commented 3 years ago

test.py is a file i created. Error happen when i run

python oscar/run_captioning.py \
    --model_name_or_path pretrained_models/base-vg-labels/ep_67_588997 \
    --do_train \
    --do_lower_case \
    --evaluate_during_training \
    --add_od_labels \
    --learning_rate 0.00003 \
    --per_gpu_train_batch_size 64 \
    --num_train_epochs 30 \
    --save_steps 5000 \
    --output_dir output/

I know error happended because of it can't import file.

To reduce time, i copy import code from oscar/run_captioning.py

To replicate error, you can run original cmd.

It creates exactly same error.

brightbsit commented 3 years ago

what is the error code when you type python setup.py build develop?

NguyenVanThanhHust commented 3 years ago

I don't see any error when i run sudo python3.7 setup.py build develop.

Thank you for your patience.

I just build a docker and run it in docker.

I suspect this error has something to do with call library.

alice-cool commented 3 years ago

pip uninstall transformers

Skyy93 commented 2 years ago

thank you @alice-cool