Issue importing models in jupyter notebooks 'No module named transformers.models.ipynb_checkpoints'
Author: mchaudrycupa
Pull request: no
Labels: name: bug

### System Info

The following error comes up: ModuleNotFoundError: No module named transformers.models.ipynb_checkpoints'

Packages:
ipykernel==6.29.5
- `transformers` version: 4.52.4
- Platform: Linux-5.10.226-214.880.amzn2.x86_64-x86_64-with-glibc2.39
- Python version: 3.10.16
- Huggingface_hub version: 0.31.4
- Safetensors version: 0.5.3
- Accelerate version: 1.7.0
- Accelerate config: 	not found
- DeepSpeed version: not installed
- PyTorch version (GPU?): 2.6.0+cu124 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: Tesla T4

I'm running the code in jupyter labs in a jupyter notebook.

The code I'm running is as follows:

` from transformers import AutoTokenizer, AutoModel, BitsAndBytesConfig

tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen3-Embedding-4B', padding_side='left')
model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-4B') `

Please let me know if there's any other information that'd be useful.

The whole error that comes up is:
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File [~/.local/lib/python3.10/site-packages/transformers/utils/import_utils.py:2045](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/utils/import_utils.py#line=2044), in _LazyModule.__getattr__(self, name)
   2044 try:
-> 2045     module = self._get_module(self._class_to_module[name])
   2046     value = getattr(module, name)

File [~/.local/lib/python3.10/site-packages/transformers/utils/import_utils.py:2075](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/utils/import_utils.py#line=2074), in _LazyModule._get_module(self, module_name)
   2074 except Exception as e:
-> 2075     raise e

File [~/.local/lib/python3.10/site-packages/transformers/utils/import_utils.py:2073](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/utils/import_utils.py#line=2072), in _LazyModule._get_module(self, module_name)
   2072 try:
-> 2073     return importlib.import_module("." + module_name, self.__name__)
   2074 except Exception as e:

File /usr/local/lib/python3.10/importlib/__init__.py:126, in import_module(name, package)
    125         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1050, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1027, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:992, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:241, in _call_with_frames_removed(f, *args, **kwds)

File <frozen importlib._bootstrap>:1050, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1027, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:1004, in _find_and_load_unlocked(name, import_)

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

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

ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 2
      1 tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen3-Embedding-4B', padding_side='left')
----> 2 model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-4B')
      3                                  #  ,
      4                                  #  quantization_config = bnb_config,
      5                                  # device_map = "auto")
      6 
      7 # We recommend enabling flash_attention_2 for better acceleration and memory saving.
      8 # model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-8B', attn_implementation="flash_attention_2", torch_dtype=torch.float16).cuda()

File [~/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py:568](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py#line=567), in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    564     return model_class.from_pretrained(
    565         pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
    566     )
    567 elif type(config) in cls._model_mapping.keys():
--> 568     model_class = _get_model_class(config, cls._model_mapping)
    569     if model_class.config_class == config.sub_configs.get("text_config", None):
    570         config = config.get_text_config()

File [~/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py:388](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py#line=387), in _get_model_class(config, model_mapping)
    387 def _get_model_class(config, model_mapping):
--> 388     supported_models = model_mapping[type(config)]
    389     if not isinstance(supported_models, (list, tuple)):
    390         return supported_models

File [~/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py:774](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py#line=773), in _LazyAutoMapping.__getitem__(self, key)
    772 if model_type in self._model_mapping:
    773     model_name = self._model_mapping[model_type]
--> 774     return self._load_attr_from_module(model_type, model_name)
    776 # Maybe there was several model types associated with this config.
    777 model_types = [k for k, v in self._config_mapping.items() if v == key.__name__]

File [~/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py:788](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py#line=787), in _LazyAutoMapping._load_attr_from_module(self, model_type, attr)
    786 if module_name not in self._modules:
    787     self._modules[module_name] = importlib.import_module(f".{module_name}", "transformers.models")
--> 788 return getattribute_from_module(self._modules[module_name], attr)

File [~/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py:700](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py#line=699), in getattribute_from_module(module, attr)
    698 if isinstance(attr, tuple):
    699     return tuple(getattribute_from_module(module, a) for a in attr)
--> 700 if hasattr(module, attr):
    701     return getattr(module, attr)
    702 # Some of the mappings have entries model_type -> object of another model type. In that case we try to grab the
    703 # object at the top level.

File [~/.local/lib/python3.10/site-packages/transformers/utils/import_utils.py:2048](https://j07z6gj046cgcjqn.ml-3cebfa69-400.cdp-prd.yss1-43mz.a2.cloudera.site/lab/tree/test/generic_notebooks/.local/lib/python3.10/site-packages/transformers/utils/import_utils.py#line=2047), in _LazyModule.__getattr__(self, name)
   2046         value = getattr(module, name)
   2047     except (ModuleNotFoundError, RuntimeError) as e:
-> 2048         raise ModuleNotFoundError(
   2049             f"Could not import module '{name}'. Are this object's requirements defined correctly?"
   2050         ) from e
   2052 elif name in self._modules:
   2053     try:

ModuleNotFoundError: Could not import module 'Qwen3Model'. Are this object's requirements defined correctly? 

### Who can help?

@ArthurZucker This may be relevant to you, apologies if not.

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

 from transformers import AutoTokenizer, AutoModel, BitsAndBytesConfig

tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen3-Embedding-4B', padding_side='left')
model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-4B') 

### Expected behavior

That the model is imported correctly

Comments:
Hi @mchaudrycupa, it seems like the error is `ModuleNotFoundError: Could not import module 'Qwen3Model'. Are this object's requirements defined correctly?`

Do you get the same error on other models?

> Hi [@mchaudrycupa](https://github.com/mchaudrycupa), it seems like the error is `ModuleNotFoundError: Could not import module 'Qwen3Model'. Are this object's requirements defined correctly?`
> 
> Do you get the same error on other models?



@Rocketknight1 Apologies I accidentally closed that comment - I've tried with qwen 3 embeddings 4 and 8B, and base qwen 3 8b and none of those work, however it seems to be working with 'Alibaba-NLP/gte-Qwen2-7B-instruct', I'll also try some other non-qwen models.

Sure! You may just need to install `transformers` from `main` to get new model support; try `pip install --upgrade git+https://github.com/huggingface/transformers.git`

I had tried that as a first step, then reinstalled v4.52.4 as that version worked when I tried in colab - but I'll try that again now

It's still not working now, even after restarting the CML (cloudera) session.

This is what the upgraded version shows up as:
- `transformers` version: 4.53.0.dev0
- Platform: Linux-5.10.226-214.880.amzn2.x86_64-x86_64-with-glibc2.39
- Python version: 3.10.16
- Huggingface_hub version: 0.31.4
- Safetensors version: 0.5.3
- Accelerate version: 1.7.0
- Accelerate config: 	not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.6.0+cu124 (CUDA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: Tesla T4

@Rocketknight1 Also, just to add, before I encoutered this error the qwen 3 8b embed model was working with transformers v4.52.2, but at some point it stopped working - I hadn't installed any packages or changed any package versions, it just stopped working

If it's any help, for qwen3 ('Qwen/Qwen3-Embedding-8B') the self._class_to_module dictionary from import_utils.py is:
{'Qwen3Config': 'configuration_qwen3', 'Qwen3ForTokenClassification': '.ipynb_checkpoints.modeling_qwen3-checkpoint', 'Qwen3ForQuestionAnswering': '.ipynb_checkpoints.modeling_qwen3-checkpoint', 'Qwen3ForSequenceClassification': '.ipynb_checkpoints.modeling_qwen3-checkpoint', 'Qwen3Model': '.ipynb_checkpoints.modeling_qwen3-checkpoint', 'Qwen3PreTrainedModel': '.ipynb_checkpoints.modeling_qwen3-checkpoint', 'Qwen3ForCausalLM': '.ipynb_checkpoints.modeling_qwen3-checkpoint'}

Whereas for qwen 2 (Alibaba-NLP/gte-Qwen2-7B-instruct) it's:
{'Qwen2Tokenizer': 'tokenization_qwen2', 'Qwen2Config': 'configuration_qwen2', 'Qwen2ForQuestionAnswering': 'modeling_qwen2', 'Qwen2ForTokenClassification': 'modeling_qwen2', 'Qwen2ForCausalLM': 'modeling_qwen2', 'Qwen2Model': 'modeling_qwen2', 'Qwen2ForSequenceClassification': 'modeling_qwen2', 'Qwen2PreTrainedModel': 'modeling_qwen2', 'Qwen2TokenizerFast': 'tokenization_qwen2_fast'}

Weird - I'm seeing other Qwen3 import issues [here](https://github.com/huggingface/transformers/issues/38291), but I can't reproduce them. Same in this case:

```python
from transformers import AutoTokenizer, AutoModel, BitsAndBytesConfig

tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen3-Embedding-4B', padding_side='left')
model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-4B')
```

I just installed from `main` and ran this code block in a notebook and it worked fine!

Can you see what your self._class_to_module dictionary is for qwen 3? Or do you know why mine might be incorrect?

I met the same issue here. Both `transformers-4.52.4` and `transformers-4.53.0.dev0` do not work in my environment, with the error **Could not import module 'Qwen3MoeForCausalLM'.** and **Could not import module 'Qwen3Model'.** for Qwen3 and Qwen3MoE.
I have upgraded torch, triton, accelerator to the latest version, but in vain.

However, as I downgrade to `transformers==4.51.1`, the problem is fixed.

Huh that is interesting, v4.51.1 is working for me as well. I tried the same steps wrt torch and triton, and got the same results.

What are you running it on? I'm using jupyter labs in Cloudera (CML), curious if that has anything to do with it

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

I also have that issue.
transformers==4.57.3

ModuleNotFoundError: Could not import module 'T5ForConditionalGeneration'. Are this object's requirements defined correctly?