unlimiformer: ImportError: cannot import name 'Unlimiformer' from 'unlimiformer'
Hi, I’ve been trying to run inference using the model checkpoints on HF by following the code in inference-example.py.
I’m using Google Colab and I’m cloning the whole repository. However, when I try to run the code, I get the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
[<ipython-input-9-ea5aa8573cba>](https://localhost:8080/#) in <cell line: 1>()
----> 1 from unlimiformer import Unlimiformer
2 from random_training_unlimiformer import RandomTrainingUnlimiformer
3 from usage import UnlimiformerArguments, training_addin
4
5 from transformers import BartForConditionalGeneration, AutoTokenizer
ImportError: cannot import name 'Unlimiformer' from 'unlimiformer' (unknown location)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
I’ve tried multiple things but nothing seems to work:
- Restarting runtime
- Deleting runtime & creating a new one
- Adding the directory to PATH
- Changing to directory using
%cd /content/unlimiformer/src
- Moving the files to
/content/
I’m not sure what I’m missing here. It seems to be such a minor issue but I’m out here pulling my hair out trying to figure why it isn’t working. If someone can help me out I’d really appreciate it. Thanks!
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18
@urialon @SharkWipf I’ve just tried it again and it works now… this is very weird. I hope I’m not going to have this issue anymore! Thanks for helping me out!
Ah, I think that’s the problem, since you’re running from what I assume is an “interactive” shell,
cwd
is not necessarily the import path. Looking closer at your original error message, it says(unknown location)
too.Could you post the output of
? It should tell you exactly where Python is looking when importing packages I believe.
EDIT: Locally ran, interactive vs script:
You need the
unlimiformer.py
file (src/unlimiformer.py
) to be in the same folder as your project (or have it installed in your Python env) for it to be able to import it.