Skip to content

[bugfix] fix dtype warning#6219

Merged
Jintao-Huang merged 3 commits intomodelscope:mainfrom
Jintao-Huang:fix_dtype_warning
Oct 20, 2025
Merged

[bugfix] fix dtype warning#6219
Jintao-Huang merged 3 commits intomodelscope:mainfrom
Jintao-Huang:fix_dtype_warning

Conversation

@Jintao-Huang
Copy link
Copy Markdown
Collaborator

torch_dtype is deprecated! Use dtype instead!

huggingface/transformers#39782

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Jintao-Huang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a deprecation warning within the transformers library by updating how the data type for model parameters is specified during loading. The change introduces version-aware logic, ensuring that the dtype parameter is used for newer transformers versions (4.56 and above) while maintaining compatibility with older versions that still expect torch_dtype. This update prevents future warnings and aligns the codebase with the latest API standards of the transformers library.

Highlights

  • Deprecation Warning Fix: Addressed a deprecation warning by updating the parameter used for specifying tensor data types from torch_dtype to dtype when loading models from the transformers library.
  • Version Compatibility: Implemented conditional logic to ensure backward compatibility, using dtype for transformers versions 4.56 and newer, and retaining torch_dtype for older versions.
  • Refactored Model Loading: Modified from_pretrained calls for AutoModelForSequenceClassification and other automodel_class instances to pass the data type parameter through model_kwargs, centralizing the version-dependent logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses the deprecation of torch_dtype in the transformers library by conditionally using dtype for versions 4.56 and newer. The changes in swift/llm/model/register.py are correct and effectively solve the issue for AutoModelForCausalLM and AutoModelForSequenceClassification.

However, the fix appears to be incomplete. I've left a comment on a related code block to point out that the function get_model_tokenizer_sentence_transformers in the same file also uses torch_dtype and should be updated to fully resolve the deprecation warnings.

Comment on lines +303 to +306
if version.parse(transformers.__version__) >= version.parse('4.56'):
model_kwargs['dtype'] = torch_dtype
else:
model_kwargs['torch_dtype'] = torch_dtype
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic correctly handles the torch_dtype deprecation. However, the fix seems incomplete as it misses another occurrence in this file.

The get_model_tokenizer_sentence_transformers function also uses the deprecated torch_dtype argument when calling SentenceTransformer, which will likely still produce a deprecation warning. To make this bugfix comprehensive, a similar version check should be applied there.

Additionally, get_model_tokenizer_sentence_transformers appears to ignore the model_kwargs argument passed to it, instead creating a new dictionary. This is likely a bug and should be addressed by using and updating the incoming model_kwargs dictionary, similar to the pattern used in get_model_tokenizer_from_local.

@Jintao-Huang Jintao-Huang merged commit f278882 into modelscope:main Oct 20, 2025
1 of 2 checks passed
Jintao-Huang added a commit that referenced this pull request Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants