[PEFT] introducing adapter_kwargs for loading adapters from different Hub location (subfolder, revision) than the base model (#26270)
* make use of adapter_revision * v1 adapter kwargs * fix CI * fix CI * fix CI * fixup * add BC * Update src/transformers/integrations/peft.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * fixup * change it to error * Update src/transformers/modeling_utils.py * Update src/transformers/modeling_utils.py * fixup * change * Update src/transformers/integrations/peft.py --------- Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
This commit is contained in:
@@ -351,3 +351,30 @@ class PeftIntegrationTester(unittest.TestCase, PeftTesterMixin):
|
||||
|
||||
# dummy generation
|
||||
_ = model.generate(input_ids=dummy_input)
|
||||
|
||||
def test_peft_from_pretrained_hub_kwargs(self):
|
||||
"""
|
||||
Tests different combinations of PEFT model + from_pretrained + hub kwargs
|
||||
"""
|
||||
peft_model_id = "peft-internal-testing/tiny-opt-lora-revision"
|
||||
|
||||
# This should not work
|
||||
with self.assertRaises(OSError):
|
||||
_ = AutoModelForCausalLM.from_pretrained(peft_model_id)
|
||||
|
||||
adapter_kwargs = {"revision": "test"}
|
||||
|
||||
# This should work
|
||||
model = AutoModelForCausalLM.from_pretrained(peft_model_id, adapter_kwargs=adapter_kwargs)
|
||||
self.assertTrue(self._check_lora_correctly_converted(model))
|
||||
|
||||
model = OPTForCausalLM.from_pretrained(peft_model_id, adapter_kwargs=adapter_kwargs)
|
||||
self.assertTrue(self._check_lora_correctly_converted(model))
|
||||
|
||||
adapter_kwargs = {"revision": "main", "subfolder": "test_subfolder"}
|
||||
|
||||
model = AutoModelForCausalLM.from_pretrained(peft_model_id, adapter_kwargs=adapter_kwargs)
|
||||
self.assertTrue(self._check_lora_correctly_converted(model))
|
||||
|
||||
model = OPTForCausalLM.from_pretrained(peft_model_id, adapter_kwargs=adapter_kwargs)
|
||||
self.assertTrue(self._check_lora_correctly_converted(model))
|
||||
|
||||
Reference in New Issue
Block a user