Fix compatibility with newer transformers/PEFT versions#96
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the custom Mapperatorinator model initialization to be forward-compatible with newer transformers/PEFT versions that pass additional keyword arguments during from_pretrained construction.
Changes:
- Update
Mapperatorinator.__init__to accept**kwargsand forward them toPreTrainedModel. - Persist a
dtypekwarg onto the config soget_backbone_model()can read it when constructing the backbone model.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if not hasattr(config, 'dtype'): | ||
| config.dtype = kwargs.get('dtype', None) |
There was a problem hiding this comment.
The hasattr(config, 'dtype') guard means a user-provided dtype kwarg can be silently ignored on subsequent loads. After this change, configs saved once without a dtype will likely contain dtype=None; later from_pretrained(..., dtype=...) will not update it because the attribute already exists. Prefer applying the explicit kwarg when present (e.g., override when config.dtype is missing or None, and consider also checking torch_dtype since HF commonly uses that name).
| if not hasattr(config, 'dtype'): | |
| config.dtype = kwargs.get('dtype', None) | |
| explicit_dtype = kwargs.get("dtype", kwargs.get("torch_dtype", None)) | |
| if explicit_dtype is not None: | |
| config.dtype = explicit_dtype | |
| elif not hasattr(config, "dtype"): | |
| config.dtype = None |
Newer versions of transformers pass additional kwargs (like torch_dtype) to model __init__. This fixes two issues: 1. Accept **kwargs in Mapperatorinator.__init__ to avoid TypeError 2. Store dtype on config so get_backbone_model can read it from config instead of receiving it as a kwarg it doesn't expect
3b29f32 to
525d5a0
Compare
|
compatibility for newer versions might need more work than this, so I don't consider upgrading atm. PR can stay open for if i change my mind. |
Fixes compatibility issues when using newer versions of transformers and PEFT libraries.
Changes
Mapperatorinator.__init__: Accept**kwargsto handle additional keyword arguments passed by newer transformers versionsMapperatorinatorConfig: Storedtypekwarg on config object soget_backbone_modelcan access itContext
When using transformers >= 4.57 with PEFT >= 0.18, the model initialization fails because newer transformers passes additional kwargs (
dtype, etc.) that the custom__init__doesn't accept. These changes make the model forward-compatible.