[bugfix] fix dtype warning#6219
Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| if version.parse(transformers.__version__) >= version.parse('4.56'): | ||
| model_kwargs['dtype'] = torch_dtype | ||
| else: | ||
| model_kwargs['torch_dtype'] = torch_dtype |
There was a problem hiding this comment.
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.
torch_dtypeis deprecated! Usedtypeinstead!huggingface/transformers#39782