Skip to content

[COLAB] RuntimeError: Failed to import transformers.models.auto because of the following error (look up to see its traceback): module 'sentencepiece._sentencepiece' has no attribute 'delete_ImmutableSentencePieceText_ImmutableSentencePiece' #3121

Description

@HaikenEdge

Got the following error today while running with

!pip uninstall -y xformers
!pip install -U xformers
!pip install "lightning_utilities==0.8.0" "lightning_fabric==1.9.5"

in a new cell after the Requirements cell:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/dist-packages/transformers/utils/import_utils.py", line 1146, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 999, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/usr/local/lib/python3.12/dist-packages/transformers/models/__init__.py", line 15, in <module>
    from . import (
  File "/usr/local/lib/python3.12/dist-packages/transformers/models/mt5/__init__.py", line 29, in <module>
    from ..t5.tokenization_t5 import T5Tokenizer
  File "/usr/local/lib/python3.12/dist-packages/transformers/models/t5/tokenization_t5.py", line 24, in <module>
    import sentencepiece as spm
  File "/usr/local/lib/python3.12/dist-packages/sentencepiece/__init__.py", line 64, in <module>
    class ImmutableSentencePieceText_ImmutableSentencePiece(object):
  File "/usr/local/lib/python3.12/dist-packages/sentencepiece/__init__.py", line 70, in ImmutableSentencePieceText_ImmutableSentencePiece
    __swig_destroy__ = _sentencepiece.delete_ImmutableSentencePieceText_ImmutableSentencePiece
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'sentencepiece._sentencepiece' has no attribute 'delete_ImmutableSentencePieceText_ImmutableSentencePiece'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py", line 13, in <module>
    initialize.imports()
  File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/initialize.py", line 17, in imports
    import pytorch_lightning  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/pytorch_lightning/__init__.py", line 34, in <module>
    from pytorch_lightning.callbacks import Callback  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/pytorch_lightning/callbacks/__init__.py", line 14, in <module>
    from pytorch_lightning.callbacks.callback import Callback
  File "/usr/local/lib/python3.12/dist-packages/pytorch_lightning/callbacks/callback.py", line 25, in <module>
    from pytorch_lightning.utilities.types import STEP_OUTPUT
  File "/usr/local/lib/python3.12/dist-packages/pytorch_lightning/utilities/types.py", line 28, in <module>
    from torchmetrics import Metric
  File "/usr/local/lib/python3.12/dist-packages/torchmetrics/__init__.py", line 14, in <module>
    from torchmetrics import functional  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torchmetrics/functional/__init__.py", line 77, in <module>
    from torchmetrics.functional.text.bleu import bleu_score
  File "/usr/local/lib/python3.12/dist-packages/torchmetrics/functional/text/__init__.py", line 30, in <module>
    from torchmetrics.functional.text.bert import bert_score  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torchmetrics/functional/text/bert.py", line 24, in <module>
    from torchmetrics.functional.text.helper_embedding_metric import (
  File "/usr/local/lib/python3.12/dist-packages/torchmetrics/functional/text/helper_embedding_metric.py", line 26, in <module>
    from transformers import AutoModelForMaskedLM, AutoTokenizer, PreTrainedModel, PreTrainedTokenizerBase
  File "<frozen importlib._bootstrap>", line 1412, in _handle_fromlist
  File "/usr/local/lib/python3.12/dist-packages/transformers/utils/import_utils.py", line 1136, in __getattr__
    module = self._get_module(self._class_to_module[name])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/transformers/utils/import_utils.py", line 1148, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.models.auto because of the following error (look up to see its traceback):
module 'sentencepiece._sentencepiece' has no attribute 'delete_ImmutableSentencePieceText_ImmutableSentencePiece'
[Colab paid products ](https://colab.research.google.com/signup?utm_source=footer&utm_medium=link&utm_campaign=footer_links)- [Cancel contracts here](https://colab.research.google.com/cancel-subscription)

Anybody got a fix?

Activity

  1. Azura-13 commented on Jul 16, 2026

    @Azura-13

    Same
    @ [HaikenEdge] hey man, our thread from the other day was removed by admin because the issue was fixed, i can confirm that it ran normally (barring the xformers issue) yesterday.

    !pip install "lightning_utilities==0.8.0" "lightning_fabric==1.9.5"
    no longer needed, ran yesterday without it

    This however is a new issue and i have no idea what is broken =/

  2. HaikenEdge commented on Jul 16, 2026

    @HaikenEdge
    Author

    @ [HaikenEdge] hey man, our thread from the other day was removed by admin because the issue was fixed, i can confirm that it ran normally (barring the xformers issue) yesterday.

    It wasn't removed by admin. OP closed it.

  3. Azura-13 commented on Jul 16, 2026

    @Azura-13

    oh right, my mistake then, but it ran yesterday (several different times) without it, just the old:

    !pip uninstall -y xformers
    !pip install -U xformers

  4. HaikenEdge commented on Jul 16, 2026

    @HaikenEdge
    Author

    oh right, my mistake then, but it ran yesterday (several different times) without it, just the old:

    !pip uninstall -y xformers
    !pip install -U xformers

    I'll take your word for it. Can't check now because of the error in the OP.

  5. Azura-13 commented on Jul 16, 2026

    @Azura-13

    gemini:
    This is a critical compatibility issue caused by a breaking change in a recent sentencepiece library update.

    In recent releases, sentencepiece completely removed legacy C++ wrapper classes, including ImmutableSentencePieceText. However, the older version of transformers (or other dependencies) pre-installed or expected by thelastben's Stable Diffusion notebook is still looking for that specific attribute (delete_ImmutableSentencePieceText_ImmutableSentencePiece), causing the crash during boot.

  6. Azura-13 commented on Jul 16, 2026

    @Azura-13

    testing:
    !pip install "sentencepiece>=0.1.99,<0.2.0" --force-reinstall

  7. Azura-13 commented on Jul 16, 2026

    @Azura-13

    hey man im in

    !pip install "sentencepiece>=0.1.99,<0.2.0" --force-reinstall
    1st new cell

    !pip uninstall -y xformers
    !pip install -U xformers
    2nd new cell

  8. HaikenEdge commented on Jul 16, 2026

    @HaikenEdge
    Author

    hey man im in

    !pip install "sentencepiece>=0.1.99,<0.2.0" --force-reinstall 1st new cell

    !pip uninstall -y xformers !pip install -U xformers 2nd new cell

    Can confirm, seems to be working

  9. g-imconfused commented on Jul 17, 2026

    @g-imconfused

    hey man im in

    !pip install "sentencepiece>=0.1.99,<0.2.0" --force-reinstall 1st new cell

    !pip uninstall -y xformers !pip install -U xformers 2nd new cell

    Same problem this morning, and yep this worked for me, at least mostly. SD launched, but now I'm getting a 504 gateway timeout error when loading the webpage. Anyone seeing this? Not sure if it's related, but haven't seen this before now.

  10. g-imconfused commented on Jul 17, 2026

    @g-imconfused

    Update, page loaded after a few restarts, but image gen fails with this error:

    Traceback (most recent call last):
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 74, in f
        res = list(func(*args, **kwargs))
                   ^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 53, in f
        res = func(*args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 37, in f
        res = func(*args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/txt2img.py", line 109, in txt2img
        processed = processing.process_images(p)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/processing.py", line 847, in process_images
        res = process_images_inner(p)
              ^^^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/processing.py", line 1002, in process_images_inner
        x_samples_ddim = decode_latent_batch(p.sd_model, samples_ddim, target_device=devices.cpu, check_for_nans=True)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/processing.py", line 632, in decode_latent_batch
        sample = decode_first_stage(model, batch[i:i + 1])[0]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/sd_samplers_common.py", line 76, in decode_first_stage
        return samples_to_images_tensor(x, approx_index, model)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/sd_samplers_common.py", line 58, in samples_to_images_tensor
        x_sample = model.decode_first_stage(sample.to(model.first_stage_model.dtype))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/torch/utils/_contextlib.py", line 124, in decorate_context
        return func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stablediffusion/generative-models/sgm/models/diffusion.py", line 121, in decode_first_stage
        out = self.first_stage_model.decode(z)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stablediffusion/generative-models/sgm/models/autoencoder.py", line 315, in decode
        dec = self.decoder(z, **decoder_kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1779, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1790, in _call_impl
        return forward_call(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stablediffusion/generative-models/sgm/modules/diffusionmodules/model.py", line 722, in forward
        h = self.mid.attn_1(h, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1779, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1790, in _call_impl
        return forward_call(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stablediffusion/generative-models/sgm/modules/diffusionmodules/model.py", line 260, in forward
        h_ = self.attention(h_)
             ^^^^^^^^^^^^^^^^^^
      File "/content/gdrive/MyDrive/sd/stablediffusion/generative-models/sgm/modules/diffusionmodules/model.py", line 246, in attention
        out = xformers.ops.memory_efficient_attention(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/xformers/ops/fmha/__init__.py", line 311, in memory_efficient_attention
        return _memory_efficient_attention(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/xformers/ops/fmha/__init__.py", line 472, in _memory_efficient_attention
        return _memory_efficient_attention_forward(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/xformers/ops/fmha/__init__.py", line 491, in _memory_efficient_attention_forward
        op = _dispatch_fw(inp, False)
             ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/xformers/ops/fmha/dispatch.py", line 142, in _dispatch_fw
        return _run_priority_list(
               ^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.12/dist-packages/xformers/ops/fmha/dispatch.py", line 83, in _run_priority_list
        raise NotImplementedError(msg)
    NotImplementedError: No operator found for `memory_efficient_attention_forward` with inputs:
         query       : shape=(1, 16128, 1, 512) (torch.float32)
         key         : shape=(1, 16128, 1, 512) (torch.float32)
         value       : shape=(1, 16128, 1, 512) (torch.float32)
         attn_bias   : <class 'NoneType'>
         p           : 0.0
    `fa3F@0.0.0` is not supported because:
        max(query.shape[-1], value.shape[-1]) > 256
        requires device with capability <= (9, 0) but your GPU has capability (12, 0) (too new)
        dtype=torch.float32 (supported: {torch.float16, torch.bfloat16})
        operator wasn't built - see `python -m xformers.info` for more info
    `fa2F@2.5.7-pt` is not supported because:
        max(query.shape[-1], value.shape[-1]) > 256
        dtype=torch.float32 (supported: {torch.float16, torch.bfloat16})
    `cutlassF-pt` is not supported because:
        requires device with capability <= (9, 0) but your GPU has capability (12, 0) (too new)
    
  11. g-imconfused commented on Jul 17, 2026

    @g-imconfused

    Update, page loaded after a few restarts, but image gen fails with this error:

    Traceback (most recent call last):
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 74, in f
        res = list(func(*args, **kwargs))
    

    ...

    fa3F@0.0.0 is not supported because:
    max(query.shape[-1], value.shape[-1]) > 256
    requires device with capability <= (9, 0) but your GPU has capability (12, 0) (too new)
    dtype=torch.float32 (supported: {torch.float16, torch.bfloat16})
    operator wasn't built - see python -m xformers.info for more info
    fa2F@2.5.7-pt is not supported because:
    max(query.shape[-1], value.shape[-1]) > 256
    dtype=torch.float32 (supported: {torch.float16, torch.bfloat16})
    cutlassF-pt is not supported because:
    requires device with capability <= (9, 0) but your GPU has capability (12, 0) (too new)

    Update #2 - "GPU too new issue" confirmed, downgraded runtime to A100 from G4 and runs correctly. This is using the forked repo from markn333 referenced at #3117 though, and removing the 2nd new cel fix listed by Azura-13 above -

    !pip uninstall -y xformers
    !pip install -U xformers
    2nd new cell

    since this other repo already has a similar fix that seems to conflict with this.

    So not running on my preferred GPU, but running.

  12. HaikenEdge commented on Jul 17, 2026

    @HaikenEdge
    Author

    Update, page loaded after a few restarts, but image gen fails with this error:

    Traceback (most recent call last):
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 74, in f
        res = list(func(*args, **kwargs))
    

    ...

    fa3F@0.0.0 is not supported because:
    max(query.shape[-1], value.shape[-1]) > 256
    requires device with capability <= (9, 0) but your GPU has capability (12, 0) (too new)
    dtype=torch.float32 (supported: {torch.float16, torch.bfloat16})
    operator wasn't built - see python -m xformers.info for more info
    fa2F@2.5.7-pt is not supported because:
    max(query.shape[-1], value.shape[-1]) > 256
    dtype=torch.float32 (supported: {torch.float16, torch.bfloat16})
    cutlassF-pt is not supported because:
    requires device with capability <= (9, 0) but your GPU has capability (12, 0) (too new)

    Update #2 - "GPU too new issue" confirmed, downgraded runtime to A100 from G4 and runs correctly. This is using the forked repo from markn333 referenced at #3117 though, and removing the 2nd new cel fix listed by Azura-13 above -

    !pip uninstall -y xformers !pip install -U xformers 2nd new cell

    since this other repo already has a similar fix that seems to conflict with this.

    So not running on my preferred GPU, but running.

    If you're running somebody else's repo, you should post your issues there. I'm having no problems running this notebook using the fix by @Azura-13 .

  13. g-imconfused commented on Jul 17, 2026

    @g-imconfused

    If you're running somebody else's repo, you should post your issues there. I'm having no problems running this notebook using the fix by @Azura-13 .

    Right, had the same issue with this repo, that's why i posted here, Tried that repo next, saw the same thing and posted in that thread too. Not sure why I'm getting this if you're not, I figured was about the sentencepiece change but maybe not?

    I'll test this one again as well and see if it's still there

  14. HaikenEdge commented on Jul 17, 2026

    @HaikenEdge
    Author

    If you're running somebody else's repo, you should post your issues there. I'm having no problems running this notebook using the fix by @Azura-13 .

    Right, had the same issue with this repo, that's why i posted here, Tried that repo next, saw the same thing and posted in that thread too. Not sure why I'm getting this if you're not, I figured was about the sentencepiece change but maybe not?

    I'll test this one again as well and see if it's still there

    Also, probably worth mentioning that your previous 504 error was probably from Gradio being down.

  15. g-imconfused commented on Jul 17, 2026

    @g-imconfused

    If you're running somebody else's repo, you should post your issues there. I'm having no problems running this notebook using the fix by @Azura-13 .

    Right, had the same issue with this repo, that's why i posted here, Tried that repo next, saw the same thing and posted in that thread too. Not sure why I'm getting this if you're not, I figured was about the sentencepiece change but maybe not?
    I'll test this one again as well and see if it's still there

    Also, probably worth mentioning that your previous 504 error was probably from Gradio being down.

    yeah, possible

  16. HaikenEdge commented on Jul 17, 2026

    @HaikenEdge
    Author

    If you're running somebody else's repo, you should post your issues there. I'm having no problems running this notebook using the fix by @Azura-13 .

    Right, had the same issue with this repo, that's why i posted here, Tried that repo next, saw the same thing and posted in that thread too. Not sure why I'm getting this if you're not, I figured was about the sentencepiece change but maybe not?
    I'll test this one again as well and see if it's still there

    Also, probably worth mentioning that your previous 504 error was probably from Gradio being down.

    yeah, possible

    Almost certain. Gradio was down for 3 hours, 6 minutes today based on their own status checker found here:

    https://status.gradio.app/793595809#logs

  17. Azura-13 commented on Jul 17, 2026

    @Azura-13

    Hey guys, I'm not having any issues today with the above fix ^^

    However if you are having gradio issues you can make an Ngrok account (free) and get a Ngrok_token you can add to the 7th cell Start Sable Diffusion and use Ngrok servers.

    Hope This Helps

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions