Skip to content

Failed to create dynamic compiled modules and RecursionError: maximum recursion depth [FIXED] #1925

Closed

Description

@micDKpara

🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!

RuntimeError Traceback (most recent call last)
in <cell line: 0>()
----> 1 from unsloth import FastLanguageModel
2 import torch
3
4
5 max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!

6 frames
/usr/local/lib/python3.11/dist-packages/unsloth_zoo/compiler.py in create_new_function(name, new_source, model_location, functions, prepend, append, overwrite, add_torch_compile)
294 if overwrite or not os.path.isfile(file_location):
295 while not os.path.isfile(file_location):
--> 296 if trials == 1000: raise RuntimeError("Unsloth: Failed to create dynamic compiled modules!")
297 trials += 1
298 time.sleep(0.01)

RuntimeError: Unsloth: Failed to create dynamic compiled modules!

Activity

  1. chishti055nsu commented on Mar 6, 2025

    @chishti055nsu

    Having same problem
    How to solv this ?

  2. spydaz commented on Mar 6, 2025

    @spydaz

    Same !! I tried loads of things even loading the nightly source code !

    i think perhaps a cuda issue ? it kept also saying it needed to be imported first ???

  3. dustinwloring1988 commented on Mar 6, 2025

    @dustinwloring1988

    this seems to have happened after the last update use an older version might help

  4. spydaz commented on Mar 6, 2025

    @spydaz

    this is a live error on all notebooks !

  5. artnoage commented on Mar 6, 2025

    @artnoage

    I have the same issue. The problem is with the march updates. Versions until Feb work fine. I tried it with various machines A6000 A100 H100 and also using a requrements file taken from a notebook that doesnt produce the error nothing fixed it.

  6. kozzy97 commented on Mar 6, 2025

    @kozzy97

    +1

  7. gweesin commented on Mar 6, 2025

    @gweesin

    pip install unsloth==2025.2.14 unsloth_zoo==2025.2.7 also works for me.

  8. harshalmore31 commented on Mar 6, 2025

    @harshalmore31

    Having same problem

  9. nvjob commented on Mar 6, 2025

    @nvjob

    On runpod, the same problem, I tried everything I could, everything worked before, I thought I was doing something wrong, it turns out that something broke in the repository. #1923

  10. Dillion commented on Mar 6, 2025

    @Dillion

    !pip install unsloth==2025.3.6 unsloth_zoo==2025.3.4 works on colab, thats yesterday's release

  11. nvjob commented on Mar 6, 2025

    @nvjob

    pip install unsloth==2025.2.14 unsloth_zoo==2025.2.7 also works for me.

    Thank you very much!

  12. eshita-3104 commented on Mar 6, 2025

    @eshita-3104

    !pip install unsloth==2025.3.6 unsloth_zoo==2025.3.4 works on colab, thats yesterday's release

    This worked for me too, thanks!:)

  13. LudWittg commented on Mar 6, 2025

    @LudWittg

    !pip install unsloth==2025.3.6 unsloth_zoo==2025.3.4 works on colab, thats yesterday's release

    This worked fine for me on Colab.

    However,

    pip install unsloth==2025.2.14 unsloth_zoo==2025.2.7 also works for me.

    didn't on Colab (oddly, but I haven’t looked into it—and I don’t plan to).

  14. nvjob commented on Mar 6, 2025

    @nvjob

    unsloth==2025.2.14 unsloth_zoo==2025.2.7
    Unfortunately, this version also has an error, but a different.
    No label_names provided for model class PeftModelForCausalLM. Since PeftModel hides base models input arguments, if label_names is not given, label_names can't be set automatically within Trainer. Note that empty label_names list will be used instead.
    #1788

    unsloth==2025.3.6 unsloth_zoo==2025.3.4
    In runpod, this version doesn't work either.

  15. 14 remaining items

  16. pinned this issue on Mar 6, 2025
  17. danielhanchen commented on Mar 6, 2025

    @danielhanchen
    Member

    Sorry on the issue guys again!

  18. Strong-Gavin commented on Mar 7, 2025

    @Strong-Gavin

    I upgraded unsloth and unsloth to the latest versions. The code I wrote runs normally. However, I used llama_factory and then accelerated it with unlsoth, but I still got the same error. Failed to create dynamic compiled. I modified the code of unsloth_zoo according to the issue in llama_factory and it can run normally. But I don't know if this is a bug of unsloth or llama_factory。
    the issue of llama_factory:
    hiyouga/LlamaFactory#7177
    hiyouga/LlamaFactory#7170 (comment)

  19. vreamer commented on Mar 7, 2025

    @vreamer

    I'm still facing the issue after running this

    pip install --upgrade --force-reinstall --no-deps unsloth unsloth_zoo

  20. micDKpara commented on Mar 7, 2025

    @micDKpara
    Author

    Sorry on the issue guys again!

    Thanks Daniel 💯 /

  21. micDKpara commented on Mar 7, 2025

    @micDKpara
    Author

    I'm still facing the issue after running this

    pip install --upgrade --force-reinstall --no-deps unsloth unsloth_zoo

    I do this and it worked in Colab:::

    Do this only in Colab notebooks! Otherwise use pip install unsloth

    !pip install --no-deps bitsandbytes accelerate xformers==0.0.29 peft trl triton
    !pip install --upgrade unsloth_zoo==2025.3.7
    !pip install sentencepiece protobuf datasets huggingface_hub hf_transfer
    !pip install --upgrade unsloth==2025.3.8
    
  22. CurtiusSimplus commented on Mar 7, 2025

    @CurtiusSimplus

    This from above: !pip install --no-deps bitsandbytes accelerate xformers==0.0.29 peft trl triton
    !pip install --upgrade unsloth_zoo==2025.3.7
    !pip install sentencepiece protobuf datasets huggingface_hub hf_transfer
    !pip install --upgrade unsloth==2025.3.8

    Works perfectly AFAIK.

    Running a Nemo Finetune right now ...

    Thanks again folks. You do good work.

  23. CurtiusSimplus commented on Mar 7, 2025

    @CurtiusSimplus

    Sorry on the issue guys again!

    Bro ... You have NOTHING to have sorrow over ... You are Johnny on the Spot about these things.

    Thank You.

  24. shimmyshimmer commented on Mar 11, 2025

    @shimmyshimmer
    Member

    This from above: !pip install --no-deps bitsandbytes accelerate xformers==0.0.29 peft trl triton !pip install --upgrade unsloth_zoo==2025.3.7 !pip install sentencepiece protobuf datasets huggingface_hub hf_transfer !pip install --upgrade unsloth==2025.3.8

    Works perfectly AFAIK.

    Running a Nemo Finetune right now ...

    Thanks again folks. You do good work.

    Great to hear and glad it worked!

  25. artnoage commented on Mar 13, 2025

    @artnoage

    So after the last couple of updates I dont get this errror. However I want to share something that I noticed. The same exactly enviroment will run for me with jupyter but not directly (dircetly it will give the error). I had this issue with many gpus, including vast and runpod. Since the error is resolved, I am really really curious what caused it first place. My belief is that some kind of overwriting was forbidden in some cases, but jupyter isolated enough to allow this.

  26. edwardlee4948 commented on Mar 19, 2025

    @edwardlee4948

    Error still persists in version 2025.3.12 of unsloth-zoo.

    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:493: SyntaxWarning: invalid escape sequence '\s'
    left = re.match("[\s\n]{4,}", leftover).span()[1]
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:921: SyntaxWarning: invalid escape sequence '*'
    .replace("", "*").replace("^", "^")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:921: SyntaxWarning: invalid escape sequence '^'
    .replace("
    ", "*").replace("^", "^")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:922: SyntaxWarning: invalid escape sequence '-'
    .replace("-", "-").replace("", "_")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:922: SyntaxWarning: invalid escape sequence '_'
    .replace("-", "-").replace("
    ", "_")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:923: SyntaxWarning: invalid escape sequence ':'
    .replace(":", ":").replace("+", "+")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:923: SyntaxWarning: invalid escape sequence '+'
    .replace(":", ":").replace("+", "+")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:924: SyntaxWarning: invalid escape sequence '.'
    .replace(".", ".").replace(",", ",")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:924: SyntaxWarning: invalid escape sequence ','
    .replace(".", ".").replace(",", ",")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:925: SyntaxWarning: invalid escape sequence '('
    .replace("(", "(").replace(")", ")")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:925: SyntaxWarning: invalid escape sequence ')'
    .replace("(", "(").replace(")", ")")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:926: SyntaxWarning: invalid escape sequence '['
    .replace("[", "[").replace("]", "]")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:926: SyntaxWarning: invalid escape sequence ']'
    .replace("[", "[").replace("]", "]")
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1015: SyntaxWarning: invalid escape sequence '_'
    if "loss_function" in cross_entropy_find and "loss_function" not in forward:
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1017: SyntaxWarning: invalid escape sequence '_'
    elif "loss_function" not in cross_entropy_find and "loss_function" in forward:
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1053: SyntaxWarning: invalid escape sequence '.'
    if "logits = outputs.logits" in cross_entropy_find:
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1160: SyntaxWarning: invalid escape sequence ':'
    r"for ([^\s]{1,}) in " + modulelist_item + ":[\n]" +
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1364: SyntaxWarning: invalid escape sequence '('
    regex_find = f"{call_class}(([^)]{{1,}}))"
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1364: SyntaxWarning: invalid escape sequence ')'
    regex_find = f"{call_class}(([^)]{{1,}}))"
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1370: SyntaxWarning: invalid escape sequence '('
    regex_find = "def forward(([^)]{1,}))"
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1471: SyntaxWarning: invalid escape sequence ')'
    inherited_modules = re.findall(r"class ([^\s]{1,})(" + inherited_class + ")", full_source)
    /.venv/lib/python3.12/site-packages/unsloth_zoo/compiler.py:1514: SyntaxWarning: invalid escape sequence '('
    called = re.findall(r"[\s]{1,}" + re.escape(function) + "(.+?)", full_source, flags = re.DOTALL)
    /.venv/lib/python3.12/site-packages/unsloth_zoo/peft_utils.py:222: SyntaxWarning: invalid escape sequence '.'
    name = re.sub(".([\d]{1,}).", r"[\1].", name)

  27. unpinned this issue on Apr 29, 2025
  28. added a commit that references this issue on May 14, 2026
  29. danielhanchen commented on Jun 18, 2026

    @danielhanchen
    Member

    This should be fixed now - sorry on the delay - please update with uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir - if it's not fixed yet, it'll be in the next pip / PyPI release - if it's still not working after that, please open another issue - appreciate it again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    URGENT BUGfixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions