Skip to content

Multiple dispatch failed for 'torch._ops.aten.to.dtype_layout';  #741

Closed

Description

@shins777

Hi I'm a beginner to fine tuning and unsloth.
When I ran the code in the notebook related to Llama 3 (8B) , I got the following error in generate the output.
I could not find out any similar cases in this issue report as well as in Google search.
Could you help me about what should I do to solve this issue ?

----[ Code ]-----
outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
tokenizer.batch_decode(outputs)

---[ Error message ] -----
TypeError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/accelerate/utils/operations.py in send_to_device(tensor, device, non_blocking, skip_keys)
157 try:
--> 158 return tensor.to(device, non_blocking=non_blocking)
159 except TypeError: # .to() doesn't accept non_blocking as kwarg

TypeError: Multiple dispatch failed for 'torch._ops.aten.to.dtype_layout'; all torch_dispatch handlers returned NotImplemented:

  • tensor subclass <class 'xformers.ops.fmha.attn_bias.LowerTriangularMask'>
    For more information, try re-running with TORCH_LOGS=not_implemented
    During handling of the above exception, another exception occurred:

Activity

  1. danielhanchen commented on Jul 7, 2024

    @danielhanchen
    Member

    Oh is this on a local machine? Apologies on the issue - if it is, please update Unsloth via:

    pip uninstall unsloth -y
    pip install --upgrade --force-reinstall --no-cache-dir git+https://github.com/unslothai/unsloth.git
  2. shins777 commented on Jul 7, 2024

    @shins777
    Author

    Thanks Daniel,
    Yes, you are right, I'm using L4 GPU in local system.
    After reinstalling the package, I've gotten another error below.


    ModuleNotFoundError Traceback (most recent call last)
    in <cell line: 1>()
    ----> 1 from unsloth import FastLanguageModel
    2 import torch
    3
    4 max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
    5 dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+

    5 frames
    /usr/local/lib/python3.10/dist-packages/unsloth/models/_utils.py in

    ModuleNotFoundError: No module named 'transformers.models.gemma2'

  3. shuodeng commented on Jul 9, 2024

    @shuodeng

    Seeing the same error: No module named 'transformers.models.gemma2' after uninstall and reinstall unsloth 2024.7

  4. keeth commented on Jul 9, 2024

    @keeth

    Seeing this error using a colab notebook for llama-3-8b. I noticed that one of the import lines has changed in the upstream notebook:

    pip install --no-deps xformers trl peft accelerate bitsandbytes
    

    is now

    pip install --no-deps xformers "trl<0.9.0" peft accelerate bitsandbytes
    

    could that be related?

  5. ashokgit commented on Jul 10, 2024

    @ashokgit

    Same issue in colab

  6. DanielLeung222 commented on Jul 10, 2024

    @DanielLeung222

    @ashokgit
    TypeError: Multiple dispatch failed for 'torch._ops.aten.to.dtype_layout'; all torch_dispatch handlers returned NotImplemented:

    tensor subclass <class 'xformers.ops.fmha.attn_bias.LowerTriangularMask'>
    For more information, try re-running with TORCH_LOGS=not_implemented
    During handling of the above exception, another exception occurred:

    If you have this error on colab, just downgrade xformers by
    !pip install --no-deps xformers==0.0.26.post1

    and it works for me

  7. ashokgit commented on Jul 10, 2024

    @ashokgit

    @ashokgit TypeError: Multiple dispatch failed for 'torch._ops.aten.to.dtype_layout'; all torch_dispatch handlers returned NotImplemented:

    tensor subclass <class 'xformers.ops.fmha.attn_bias.LowerTriangularMask'> For more information, try re-running with TORCH_LOGS=not_implemented During handling of the above exception, another exception occurred:

    If you have this error on colab, just downgrade xformers by !pip install --no-deps xformers==0.0.26.post1

    and it works for me

    Thanks a lot.

  8. regstuff commented on Jul 10, 2024

    @regstuff

    Hi I'm a beginner to fine tuning and unsloth. When I ran the code in the notebook related to Llama 3 (8B) , I got the following error in generate the output. I could not find out any similar cases in this issue report as well as in Google search. Could you help me about what should I do to solve this issue ?

    ----[ Code ]-----

    outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
    tokenizer.batch_decode(outputs)
    ---[ Error message ] ----- TypeError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/accelerate/utils/operations.py in send_to_device(tensor, device, non_blocking, skip_keys) 157 try: --> 158 return tensor.to(device, non_blocking=non_blocking) 159 except TypeError: # .to() doesn't accept non_blocking as kwarg

    TypeError: Multiple dispatch failed for 'torch._ops.aten.to.dtype_layout'; all torch_dispatch handlers returned NotImplemented:

    • tensor subclass <class 'xformers.ops.fmha.attn_bias.LowerTriangularMask'>
      For more information, try re-running with TORCH_LOGS=not_implemented
      During handling of the above exception, another exception occurred:

    Seeing this issue in colab as well with Mistral 7B

  9. danielhanchen commented on Jul 10, 2024

    @danielhanchen
    Member

    Apologies - can confirm the multiple dispatch issue - it seems like this issue is a combination of multiple issues - I can verify xformers updated to 0.0.27 just 10 hours ago, causing this exact issue.

    One temporary solution is to change the install instructions from:

    %%capture
    # Installs Unsloth, Xformers (Flash Attention) and all other packages!
    !pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
    !pip install --no-deps xformers "trl<0.9.0" peft accelerate bitsandbytes

    to

    %%capture
    # Installs Unsloth, Xformers (Flash Attention) and all other packages!
    !pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
    !pip install --no-deps "xformers<0.0.27" "trl<0.9.0" peft accelerate bitsandbytes
  10. danielhanchen commented on Jul 10, 2024

    @danielhanchen
    Member

    I just updated all notebooks to change the xformers version - apologies on the issue! On a local machine, please update Unsloth via:

    pip uninstall unsloth -y
    pip install --upgrade --force-reinstall --no-cache-dir git+https://github.com/unslothai/unsloth.git

    For Colab and Kaggle, reclick on the Colab link and open it in a new tab - sorry on the issue!

  11. shuodeng commented on Jul 12, 2024

    @shuodeng

    still seeing this error after uninstall and reinstall unsloth:

    import unsloth
    Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "venv/lib/python3.10/site-packages/unsloth/__init__.py", line 146, in <module>
       from .models import *
     File "venv/lib/python3.10/site-packages/unsloth/models/__init__.py", line 15, in <module>
       from .loader  import FastLanguageModel
     File "venv/lib/python3.10/site-packages/unsloth/models/loader.py", line 15, in <module>
       from .llama import FastLlamaModel, logger
     File "venv/lib/python3.10/site-packages/unsloth/models/llama.py", line 18, in <module>
       from ._utils import *
     File "venv/lib/python3.10/site-packages/unsloth/models/_utils.py", line 74, in <module>
       exec(f"from {config_filepath} import {config_filename}", globals())
     File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'transformers.models.gemma2'
    
  12. shins777 commented on Jul 14, 2024

    @shins777
    Author

    Thanks Daniel, It works. Appreciate your help.

  13. danielhanchen commented on Jul 18, 2024

    @danielhanchen
    Member

    @shuodeng You need to upgrade transformers

  14. unpinned this issue on Jul 25, 2024
  15. added
    fixed - pending confirmation
    and removed
    currently fixing
    URGENT BUG
    on Aug 12, 2024
  16. yurkoff-mv commented on Oct 10, 2024

    @yurkoff-mv

    Same problem:

    package                   Version
    ------------------------- --------------
    accelerate                0.34.2
    bitsandbytes              0.44.1
    datasets                  2.21.0
    flash-attn                2.6.3
    numpy                     1.26.4
    nvgpu                     0.10.0
    peft                      0.13.0
    pynvml                    11.5.3
    safetensors               0.4.5
    sentencepiece             0.2.0
    tokenizers                0.20.0
    torch                     2.3.1+cu121
    torchaudio                2.3.1+cu121
    torchtext                 0.18.0
    torchvision               0.18.1+cu121
    transformers              4.45.1
    trl                       0.11.1
    unsloth                   2024.9.post4
    xformers                  0.0.27
    
  17. 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

    fixed - pending confirmation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions