mirror of
https://github.com/wassname/peft.git
synced 2026-09-10 12:20:21 +08:00
add and fix tests
This commit is contained in:
@@ -297,3 +297,25 @@ class PeftCommonTester:
|
||||
with self.assertRaises(TypeError):
|
||||
# check if `generate` raises an error if no positional arguments are passed
|
||||
_ = model.generate(inputs["input_ids"])
|
||||
|
||||
def _test_generate_half_prec(self, model_id, config_cls, config_kwargs):
|
||||
if config_cls not in (LoraConfig, PrefixTuningConfig):
|
||||
return
|
||||
|
||||
model = self.transformers_class.from_pretrained(model_id, torch_dtype=torch.bfloat16)
|
||||
config = config_cls(
|
||||
base_model_name_or_path=model_id,
|
||||
**config_kwargs,
|
||||
)
|
||||
model = get_peft_model(model, config)
|
||||
model = model.to(self.torch_device)
|
||||
|
||||
input_ids = torch.LongTensor([[1, 1, 1], [2, 1, 2]]).to(self.torch_device)
|
||||
attention_mask = torch.LongTensor([[1, 1, 1], [1, 0, 1]]).to(self.torch_device)
|
||||
|
||||
# check if `generate` works
|
||||
_ = model.generate(input_ids=input_ids, attention_mask=attention_mask)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
# check if `generate` raises an error if no positional arguments are passed
|
||||
_ = model.generate(input_ids, attention_mask=attention_mask)
|
||||
|
||||
Reference in New Issue
Block a user