-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Add GGUF support to T5-Encoder #36700
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
Conversation
Signed-off-by: Isotr0py <[email protected]>
Signed-off-by: Isotr0py <[email protected]>
|
Thanks @Isotr0py SG 🔥 ! Just have a small question |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
SunMarc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks !
src/transformers/modeling_utils.py
Outdated
| if gguf_file is not None: | ||
| model_kwargs.pop("gguf_file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was the issue here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use T5EncoderModel to initialize the model class instead of AutoModel:
text_encoder_2 = T5EncoderModel.from_pretrained(
t5_gguf,
gguf_file=t5_file,
torch_dtype=torch.bfloat16,
)Then there will raise an error because gguf_file appeared in model_kwargs:
Traceback (most recent call last):
File "/data/develop-projects/github-repos/transformers/check_t5.py", line 13, in <module>
text_encoder_2 = T5EncoderModel.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/develop-projects/github-repos/transformers/src/transformers/modeling_utils.py", line 272, in _wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/data/develop-projects/github-repos/transformers/src/transformers/modeling_utils.py", line 4377, in from_pretrained
model = cls(config, *model_args, **model_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: T5EncoderModel.__init__() got an unexpected keyword argument 'gguf_file'
I suspect the root issue is in another place, but haven't figured it out yet. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm this happens because you passed gguf_file in cls.config_class.from_pretrained( but indeed this is strange since we should pass gguf_file inside that method from the start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, if we don't pass gguf_file in cls.config_class.from_pretrained(, it will return default T5 config causing parameter shape mismatched:
Traceback (most recent call last):
File "/data/develop-projects/github-repos/transformers/check_t5.py", line 13, in <module>
text_encoder_2 = T5EncoderModel.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/develop-projects/github-repos/transformers/src/transformers/modeling_utils.py", line 272, in _wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/data/develop-projects/github-repos/transformers/src/transformers/modeling_utils.py", line 4430, in from_pretrained
) = cls._load_pretrained_model(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/develop-projects/github-repos/transformers/src/transformers/modeling_utils.py", line 4859, in _load_pretrained_model
disk_offload_index, cpu_offload_index = _load_state_dict_into_meta_model(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/develop-projects/github-repos/transformers/.venv/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/data/develop-projects/github-repos/transformers/src/transformers/modeling_utils.py", line 835, in _load_state_dict_into_meta_model
module.load_state_dict(
File "/data/develop-projects/github-repos/transformers/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 2581, in load_state_dict
raise RuntimeError(
RuntimeError: Error(s) in loading state_dict for Linear:
size mismatch for weight: copying a param with shape torch.Size([4096, 4096]) from checkpoint, the shape in current model is torch.Size([512, 512]).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is bit strange that we had to do this only now. Merging for now !
Signed-off-by: Isotr0py <[email protected]>
What does this PR do?
Fixes #33389 (comment)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@SunMarc @MekkCyber
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.