Dtensor support requires torch>=2.5.1
Author: winglian
Pull request: no
Labels: name: bug

### System Info

torch==2.4.1
transformers@main

### Who can help?

#36335 introduced an import on Dtensor https://github.com/huggingface/transformers/blob/main/src/transformers/modeling_utils.py#L44

but this doesn't exist on torch==2.4.1, but their is no guard around this import and setup.py lists torch>=2.0.

@ArthurZucker 

### 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

install torch==2.4.1
install transformers@main
attempt to load any prretained model
see axolotl ci https://github.com/axolotl-ai-cloud/axolotl/actions/runs/13578637245/job/37960393969

### Expected behavior

regular functionality so import from transformers doesn't fail

Comments:
Thanks for the report ! This will be fixed in the PR above 

additionally, there is also issue with torch.uint16 that available only for torch>=2.4

> additionally, there is also issue with torch.uint16 that available only for torch>=2.4

Can you share the traceback so that we can fix the issue ? 

@SunMarc, sure

requirements installation (2.2.0 is the last available for x86 macos torch, that is why i can not upgrade it)
```
pip install torch==2.2.0 torchvision "numpy<2.0" git+https://github.com/huggingface/transformers.git --extra-index-url https://download.pytorch.org/whl/cpu
```

code
```
from transformers import AutoProcessor, AutoModel
model_id = "google/siglip2-base-patch16-224"
model = AutoModel.from_pretrained(model_id)
```

trace
```
Traceback (most recent call last):
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 1883, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ea/miniconda3/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/models/siglip/modeling_siglip.py", line 32, in <module>
    from ...modeling_utils import PreTrainedModel
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/modeling_utils.py", line 524, in <module>
    "U16": torch.uint16,
           ^^^^^^^^^^^^
  File "/home/ea/work/py311/lib/python3.11/site-packages/torch/__init__.py", line 1932, in __getattr__
    raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
AttributeError: module 'torch' has no attribute 'uint16'

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

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py", line 563, in from_pretrained
    model_class = _get_model_class(config, cls._model_mapping)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py", line 388, in _get_model_class
    supported_models = model_mapping[type(config)]
                       ~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py", line 763, in __getitem__
    return self._load_attr_from_module(model_type, model_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py", line 777, in _load_attr_from_module
    return getattribute_from_module(self._modules[module_name], attr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py", line 693, in getattribute_from_module
    if hasattr(module, attr):
       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 1871, in __getattr__
    module = self._get_module(self._class_to_module[name])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ea/work/py311/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 1885, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.models.siglip.modeling_siglip because of the following error (look up to see its traceback):
module 'torch' has no attribute 'uint16'
```

Thanks for the report ! 

Here you go https://github.com/huggingface/transformers/pull/36520. Let me know if this fixes the issue !