|
24 | 24 |
|
25 | 25 | from peft import AutoPeftModel, LoraConfig, PeftModel, TrainableTokensConfig, get_peft_model |
26 | 26 | from peft.tuners.trainable_tokens.layer import TrainableTokensLayer |
27 | | -from peft.utils import TrainableTokensWrapper, get_peft_model_state_dict |
| 27 | +from peft.utils import TrainableTokensWrapper, get_peft_model_state_dict, is_transformers_ge_v5 |
28 | 28 |
|
29 | 29 | from .testing_utils import hub_online_once |
30 | 30 |
|
@@ -1200,6 +1200,7 @@ def test_untied_model_dict_no_ensure(self, model_weight_untied, trainable_token_ |
1200 | 1200 | # They should NOT share delta parameters (model doesn't have tied weights) |
1201 | 1201 | assert embed_adapter.trainable_tokens_delta is not lm_head_adapter.trainable_tokens_delta |
1202 | 1202 |
|
| 1203 | + @pytest.mark.skipif(not is_transformers_ge_v5, reason="Test requires transformers v5+ dict format for _tied_weights_keys") |
1203 | 1204 | def test_composite_model_multiple_embed_tokens_specific_targeting(self): |
1204 | 1205 | """Test that users can specify full paths to disambiguate multiple embed_tokens layers. |
1205 | 1206 |
|
@@ -1239,13 +1240,7 @@ def __init__(self): |
1239 | 1240 | # Add a config attribute for PEFT |
1240 | 1241 | self.config = config1 |
1241 | 1242 |
|
1242 | | - # Avoid mixing list-format (transformers <v5) and dict-format _tied_weights_keys. |
1243 | | - # Set sub-models to None when they use list format, then use dict at composite level. |
1244 | | - if isinstance(self.m1._tied_weights_keys, list): |
1245 | | - self.m1._tied_weights_keys = None |
1246 | | - self.m2._tied_weights_keys = None |
1247 | | - |
1248 | | - # Dict format correctly represents independent tied weights within each sub-model |
| 1243 | + # Use dict format to correctly represent independent tied weights within each sub-model |
1249 | 1244 | self._tied_weights_keys = { |
1250 | 1245 | "m1.decoder.embed_tokens.weight": "m1.encoder.embed_tokens.weight", |
1251 | 1246 | "m2.decoder.embed_tokens.weight": "m2.encoder.embed_tokens.weight", |
|
0 commit comments