Skip to content

Allow for model kwargs when loading transformers from pretrained #754

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

Merged
merged 4 commits into from
May 21, 2025

Conversation

NathanHB
Copy link
Member

No description provided.

@NathanHB NathanHB requested a review from Copilot May 20, 2025 14:13
@NathanHB NathanHB linked an issue May 20, 2025 that may be closed by this pull request
@HuggingFaceDocBuilderDev
Copy link
Collaborator

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.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the TransformersModelConfig to accept arbitrary keyword arguments when loading a pretrained Hugging Face model, removes the hardcoded generation_size setting, and updates the internal loader to pass through these custom kwargs.

  • Introduce model_loading_kwargs in the config
  • Remove the generation_size field
  • Update _create_auto_model to merge and pass model_loading_kwargs instead of a local kwargs dict
Comments suppressed due to low confidence (1)

src/lighteval/models/transformers/transformers_model.py:139

  • Removing the generation_size field is a breaking change for users. Consider deprecating it first or updating documentation and release notes to guide consumers through the migration.
generation_size: PositiveInt = 256

Comment on lines 387 to 388
if "quantization_config" not in pretrained_config.to_dict():
kwargs["quantization_config"] = quantization_config
self.config.model_loading_kwargs["quantization_config"] = quantization_config
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

Mutating config.model_loading_kwargs in place can lead to unexpected state if _create_auto_model is called multiple times. Consider merging into a local dict and passing that to from_pretrained.

Copilot uses AI. Check for mistakes.

NathanHB and others added 2 commits May 20, 2025 16:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@NathanHB NathanHB requested a review from Copilot May 20, 2025 15:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces support for passing custom keyword arguments when loading pretrained transformer models, enabling more flexible configuration of model loading. It also replaces the fixed "generation_size" parameter with a more general "model_loading_kwargs" field.

  • Removed the fixed generation_size parameter.
  • Added a new model_loading_kwargs field to the configuration.
  • Updated the auto model creation to copy the provided kwargs.
Comments suppressed due to low confidence (1)

src/lighteval/models/transformers/transformers_model.py:139

  • The removal of the fixed generation_size parameter may be a breaking change. If this change is intentional, please update the documentation to clarify the impact on users and ensure that all dependent functionalities are adjusted accordingly.
-    generation_size: PositiveInt = 256

@NathanHB NathanHB self-assigned this May 20, 2025
@NathanHB NathanHB added the feature/enhancement New feature/request label May 20, 2025
@NathanHB NathanHB requested a review from clefourrier May 20, 2025 15:27
@NathanHB NathanHB merged commit ce1dbb5 into main May 21, 2025
5 checks passed
hynky1999 pushed a commit that referenced this pull request May 22, 2025
## Pull Request Overview

This PR introduces support for passing custom keyword arguments when loading pretrained transformer models, enabling more flexible configuration of model loading. It also replaces the fixed "generation_size" parameter with a more general "model_loading_kwargs" field.
- Removed the fixed generation_size parameter.
- Added a new model_loading_kwargs field to the configuration.
- Updated the auto model creation to copy the provided kwargs.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* suggestion from copilot

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/enhancement New feature/request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FT] better support for model loading args in transformers
3 participants