Skip to content

[Bug] Compile cache miss typing.Any #2874

Closed

Description

@Apolsus

when execute:

from unsloth import FastLanguageModel  # unsloth must import before trl
from omegaconf import OmegaConf
from trl import SFTTrainer, SFTConfig

from data.dataset import get_dataset

NUM_GPUS = 8

config = OmegaConf.load("conf/default.yaml")
print(config)
# 加载模型
model, tokenizer = FastLanguageModel.from_pretrained(
    config.model.pretrained_model,
    max_seq_length=config.data.max_length,
    load_in_4bit=False,
    load_in_8bit=False,
    full_finetuning=True,  # We have full finetuning now!
)

raise error:

Traceback (most recent call last):
  File "/usr/local/miniconda3/lib/python3.10/site-packages/unsloth_zoo/compiler.py", line 433, in create_new_function
    new_module, old_path = import_module(compile_folder, name)
  File "/usr/local/miniconda3/lib/python3.10/site-packages/unsloth_zoo/compiler.py", line 428, in import_module
    new_module = importlib.import_module(name)
  File "/usr/local/miniconda3/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/export/App/training_platform/PinoModel/unsloth_compiled_cache/Linear_peft_forward.py", line 42, in <module>
    def unsloth_forward(self, x: torch.Tensor, *args: Any, **kwargs: Any) -> torch.Tensor:
NameError: name 'Any' is not defined. Did you mean: 'any'?

unsloth: 2025.6.12
unsloth-zoo: 2025.6.8

Activity

  1. woct0rdho commented on Jul 3, 2025

    @woct0rdho
  2. wasimysaid commented on Jul 3, 2025

    @wasimysaid
    Collaborator

    same thing

  3. Apolsus commented on Jul 3, 2025

    @Apolsus
    Author

    A quick fix is adding this code before loading models

    from typing import Any
    import builtins
    

    Note that this is not a permanent solution

  4. Datta0 commented on Jul 4, 2025

    @Datta0
    Contributor

    Hey @Apolsus can you please share the generated Linear_peft_forward.py file? Ideally it should have from peft.tuners.lora.layer import (Any, F, nn, torch) which should take care of the imports
    Also would be helpful if you can point me to the version of peft you're using

  5. rtylecek commented on Jul 4, 2025

    @rtylecek

    Same issue here. I am getting only from peft.tuners.lora.inc import (torch) in Linear_peft_forward.py

    Full header:

    """
    2025.6.8
    2025.6.12
    4.52.4
    0.19.0
    __UNSLOTH_VERSIONING__
    """
    
    torch_compile_options = {'epilogue_fusion': True, 'max_autotune': False, 'shape_padding': True, 'trace.enabled': False, 'triton.cudagraphs': False, 'debug': False, 'dce': True, 'memory_planning': True, 'coordinate_descent_tuning': False, 'trace.graph_diagram': False, 'compile_threads': 24, 'combo_kernels': False, 'group_fusion': True, 'disable_progress': True, 'verbose_progress': False, 'triton.multi_kernel': False, 'triton.use_block_ptr': False, 'triton.enable_persistent_tma_matmul': True, 'triton.autotune_at_compile_time': True}
    from torch import Tensor
    import torch
    import torch.nn as nn
    from torch.nn import functional as F
    from peft.tuners.lora.inc import (torch)`
    
  6. antoinedelplace commented on Jul 4, 2025

    @antoinedelplace

    A quick fix is adding this code before loading models

    from typing import Any
    import builtins
    

    Note that this is not a permanent solution

    I did

    import builtins
    from typing import Any
    
    builtins.Any = Any
    

    before

    from unsloth import FastVisionModel
    

    to make it work.

  7. rolandtannous commented on Jul 10, 2025

    @rolandtannous
    Contributor

    @antoinedelplace @rtylecek @Apolsus @Shine1i

    we just made a new release that should solve this problem for you.
    If you're running the code on a local vm, make sure to upgrade your install of unsloth via

    pip install --force-reinstall --upgrade unsloth-zoo
    pip install --force-reinstall --upgrade unsloth
    On the other hand, If you're running the notebooks on colab no need to do introduce any changes to the install cells as the notebook will grab the newest version from pypi for you anyway.

    Make sure to leave a comment if this doesn't work out for you with the necessary details and code snippets that would allow us to reproduce the errors you're observing and we'll take it from there.

  8. danielhanchen commented on Jul 17, 2025

    @danielhanchen
    Member

    Yep please update Unsloth:

    pip install --upgrade --force-reinstall --no-cache-dir --no-deps unsloth unsloth_zoo
    
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

    bugfixed - pending confirmation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions