Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoModel failed with empty tensor error #36579

Open
4 tasks
jiqing-feng opened this issue Mar 6, 2025 · 1 comment · May be fixed by #36581
Open
4 tasks

AutoModel failed with empty tensor error #36579

jiqing-feng opened this issue Mar 6, 2025 · 1 comment · May be fixed by #36581
Labels

Comments

@jiqing-feng
Copy link
Contributor

System Info

Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.

  • transformers version: 4.50.0.dev0
  • Platform: Linux-4.18.0-553.16.1.el8_10.x86_64-x86_64-with-glibc2.35
  • Python version: 3.10.12
  • Huggingface_hub version: 0.28.1
  • Safetensors version: 0.5.2
  • Accelerate version: 1.4.0.dev0
  • Accelerate config: - compute_environment: LOCAL_MACHINE
    - distributed_type: MULTI_CPU
    - mixed_precision: bf16
    - use_cpu: True
    - debug: False
    - num_processes: 4
    - machine_rank: 0
    - num_machines: 4
    - main_process_ip: 127.0.0.1
    - main_process_port: 29500
    - rdzv_backend: static
    - same_network: True
    - main_training_function: main
    - enable_cpu_affinity: False
    - ipex_config: {'ipex': False}
    - mpirun_config: {'mpirun_ccl': '1', 'mpirun_hostfile': '/home/jiqingfe/jiqing_hf/HuggingFace/tests/workloads/fine-tune/hostfile'}
    - downcast_bf16: no
    - tpu_use_cluster: False
    - tpu_use_sudo: False
    - tpu_env: []
  • DeepSpeed version: not installed
  • PyTorch version (GPU?): 2.6.0+cpu (False)
  • 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?:

Who can help?

@SunMarc @ArthurZucker @Rocketknight1

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

Run the following codes:

from transformers import AutoModel

model = AutoModel.from_pretrained("meta-llama/Llama-3.1-8B-Instruct", device_map="auto")

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jiqingfe/transformers/src/transformers/models/auto/auto_factory.py", line 564, in from_pretrained
    return model_class.from_pretrained(
  File "/home/jiqingfe/transformers/src/transformers/modeling_utils.py", line 271, in _wrapper
    return func(*args, **kwargs)
  File "/home/jiqingfe/transformers/src/transformers/modeling_utils.py", line 4535, in from_pretrained
    dispatch_model(model, **device_map_kwargs)
  File "/home/jiqingfe/accelerate/src/accelerate/big_modeling.py", line 496, in dispatch_model
    model.to(device)
  File "/home/jiqingfe/transformers/src/transformers/modeling_utils.py", line 3262, in to
    return super().to(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1343, in to
    return self._apply(convert)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 903, in _apply
    module._apply(fn)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 930, in _apply
    param_applied = fn(param)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1336, in convert
    raise NotImplementedError(
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty() instead of torch.nn.Module.to() when moving module from meta to a different device.

Expected behavior

Expect got a base model.

@jiqing-feng jiqing-feng added the bug label Mar 6, 2025
@SunMarc SunMarc linked a pull request Mar 6, 2025 that will close this issue
@SunMarc
Copy link
Member

SunMarc commented Mar 6, 2025

Fixed above. thanks for the report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants