add model_config support in TransformersModel #1168
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds support for the model_config parameter in the TransformersModel class. With this change, it's now possible to pass a dictionary containing specific configuration options for model loading (via AutoModelForCausalLM.from_pretrained or AutoModelForImageTextToText.from_pretrained), separating these settings from the kwargs used in the generate() method.
Highlights:
Quantization support: Enables the use of configurations such as quantization_config (e.g., for 4-bit quantization using BitsAndBytes), as well as other parameters like torch_dtype and device_map.
Flexible model initialization: Users can now customize model loading with a wide range of parameters without interfering with generation-specific arguments.
Clear separation of concerns: Model configuration is handled through the model_config dictionary, while generation parameters remain in **kwargs during the generate() call.
This update improves customization options during model initialization, making the framework more versatile and suitable for models requiring specific loading configurations.
Open to feedback — happy to refine the implementation as needed.
Example:
```python
>>> from transformers import BitsAndBytesConfig
>>> from smolagents import CodeAgent, TransformersModel