Skip to content

Replace deprecated torch_dtype with dtype in llava_hf.py #465

Description

@xyf5432

Summary

Starting with transformers 4.56.0 (huggingface/transformers#39782), the torch_dtype keyword argument of PreTrainedModel.from_pretrained is deprecated in favor of dtype. Code that still uses torch_dtype emits the deprecation warning "torch_dtype is deprecated! Use dtype instead!" on every invocation, and the deprecated API is scheduled for removal in a future major release.

This repository still passes torch_dtype at the location below. Note that requirements/runtime.txt allows transformers >= 4.45.2, i.e. older versions that do not accept dtype yet. The proposed change therefore keeps a fallback for transformers < 4.56.0 so the code keeps working across the whole supported range: dtype is honored identically to torch_dtype on transformers >= 4.56.0.

Trigger point

  • llmc/models/llava_hf.py line L30-33:
    self.vlm_model = LlavaForConditionalGeneration.from_pretrained(
        self.model_path,
        config=self.vlm_model_config,
        torch_dtype=self.torch_dtype,
        low_cpu_mem_usage=True,
    )

Proposed change

try:
    # transformers >= 4.56: `dtype` is the replacement for `torch_dtype`
    self.vlm_model = LlavaForConditionalGeneration.from_pretrained(
        self.model_path,
        config=self.vlm_model_config,
        dtype=self.torch_dtype,
        low_cpu_mem_usage=True,
    )
except TypeError:
    # transformers < 4.56: `dtype` is not accepted yet
    self.vlm_model = LlavaForConditionalGeneration.from_pretrained(
        self.model_path,
        config=self.vlm_model_config,
        torch_dtype=self.torch_dtype,
        low_cpu_mem_usage=True,
    )

Would a PR updating this call to dtype (with the fallback above) be welcome?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions