You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ImportError: cannot import name 'FastLanguageModel' from partially initialized module 'unsloth' (most likely due to a circular import) #848
$ python unsloth.py
Traceback (most recent call last):
File "/home/ubuntu/unsloth.py", line 1, in <module>
from unsloth import FastLanguageModel
File "/home/ubuntu/unsloth.py", line 1, in <module>
from unsloth import FastLanguageModel
ImportError: cannot import name 'FastLanguageModel' from partially initialized module 'unsloth' (most likely due to a circular import) (/home/ubuntu/unsloth.py)
The error occurs during the import
from unsloth import FastLanguageModel
PS: I am using windows server 2022 with AMD64 architecture.
The same code is working fine on Google Colab though. Probably due to difference of architecture.
python3 unsloth.py
Traceback (most recent call last):
File "/home/user/unsloth/run.py", line 1, in
from unsloth import FastLanguageModel
File "/home/user/unsloth/run.py", line 1, in
from unsloth import FastLanguageModel
ImportError: cannot import name 'FastLanguageModel' from partially initialized module 'unsloth' (most likely due to a circular import) (/home/user/unsloth/run.py)
I am also getting this error on the first import line of the sample script. Ubuntu server 22.04, Python 3.10.12. The pip commands seem to complete successfully, but the script cannot import the module.
I use venv with Jupyter lab, but I was able to get the module to load with following setup steps. Also make sure that you don't have any files or directories in your working directory named unsloth or unsloth.py
python unsloth.py
But in your script, you're probably also importing the library named unsloth:
from unsloth import FastLanguageModel
So there's a naming conflict — Python thinks your script is trying to import itself.
Just try renaming unsloth.py to something else.
Even with the name change, the error keeps showing on. tried to reinstall unsloth, change the transformers version.
I don't know what is causing the problem, in my case i use win 11, py 3.10, latest transformer version.
it could be a problem related to the Torch + Cuda version confict with the latest version for transformers, i'm using cuda 12.6 and torch 2.6
Activity
danielhanchen commentedon Aug 2, 2024
Weird very weird on the circular import - do you know approximately which line, or was that just the only error msg?
SiddiqueFarhan commentedon Aug 6, 2024
The error occurs during the import
from unsloth import FastLanguageModel
PS: I am using windows server 2022 with AMD64 architecture.
The same code is working fine on Google Colab though. Probably due to difference of architecture.
emzaedu commentedon Aug 7, 2024
Same issue on WSL2 with Ubuntu
pip install --upgrade pip
pip install --upgrade --force-reinstall --no-cache-dir torch==2.2.0 triton
--index-url https://download.pytorch.org/whl/cu121
pip install "unsloth[cu121-torch220] @ git+https://github.com/unslothai/unsloth.git"
python3 unsloth.py
Traceback (most recent call last):
File "/home/user/unsloth/run.py", line 1, in
from unsloth import FastLanguageModel
File "/home/user/unsloth/run.py", line 1, in
from unsloth import FastLanguageModel
ImportError: cannot import name 'FastLanguageModel' from partially initialized module 'unsloth' (most likely due to a circular import) (/home/user/unsloth/run.py)
UPD:
pip install "unsloth[cu121-torch230] @ git+https://github.com/unslothai/unsloth.git"
run good for me
danielhanchen commentedon Aug 10, 2024
Ok weird - if more than one of you have the same issue, I'll need to flag this - sorry on the issue!
bigogre55 commentedon Aug 13, 2024
I am also getting this error on the first import line of the sample script. Ubuntu server 22.04, Python 3.10.12. The pip commands seem to complete successfully, but the script cannot import the module.
danielhanchen commentedon Aug 13, 2024
Ok will escalate as an urgent bug - I'm unsure why this is happening :( Colab seems to be fine :(
bigogre55 commentedon Aug 14, 2024
I use venv with Jupyter lab, but I was able to get the module to load with following setup steps. Also make sure that you don't have any files or directories in your working directory named unsloth or unsloth.py
I was able to install and load the module for pytorch 2.3.0 as well. both times it worked only after I also added the ipykernel package.
shimmyshimmer commentedon Oct 28, 2024
Hey guys is the issue still here? Thank you!
chengchengpei commentedon Oct 28, 2024
resolved. thanks
SalomonKisters commentedon Mar 23, 2025
having the issue again, none of the above fixes worked for me
Guedd commentedon Apr 3, 2025
same here facing the problem
dx2102 commentedon Apr 6, 2025
I think I got this.
You're running a training script called
unsloth:But in your script, you're probably also importing the library named unsloth:
So there's a naming conflict — Python thinks your script is trying to import itself.
Just try renaming
unsloth.pyto something else.Guedd commentedon Apr 8, 2025
Even with the name change, the error keeps showing on. tried to reinstall unsloth, change the transformers version.
I don't know what is causing the problem, in my case i use win 11, py 3.10, latest transformer version.
it could be a problem related to the Torch + Cuda version confict with the latest version for transformers, i'm using cuda 12.6 and torch 2.6
makhmudjon-inadullaev commentedon Aug 31, 2025
@dx2102 Thank you, changing file name resolved my issue!