Skip to content

Very slow model instantiation #37712

@rvorias

Description

@rvorias

System Info

transformers version: 4.51.3

  • Platform: Linux-6.8.0-57-generic-x86_64-with-glibc2.35
  • Python version: 3.10.12
  • Huggingface_hub version: 0.30.2
  • Safetensors version: 0.5.3
  • Accelerate version: not installed
  • 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?:
  • Using GPU in script?:
  • GPU type: NVIDIA RTX 4000 SFF Ada Generation

Who can help?

No response

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

import torch
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM 


device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32

model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)

this is the culprit:

safetensors_convert_space_url = "https://safetensors-convert.hf.space"

update: when interrupting the process, it seems to be more likely it's stuck here: File "/home/vd/.venv/lib/python3.10/site-packages/torch/serialization.py", line 1888, in load_tensor zip_file.get_storage_from_record(name, numel, torch.UntypedStorage) KeyboardInterrupt

Rollback to 4.46.1 does not have this issue.

Expected behavior

NOT take 5 mins to create model instance.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions