mirror of
https://github.com/wassname/peft.git
synced 2026-09-09 11:28:32 +08:00
add and fix tests
This commit is contained in:
@@ -83,3 +83,7 @@ class PeftDecoderModelTester(unittest.TestCase, PeftCommonTester):
|
||||
@parameterized.expand(PeftTestConfigManager.get_grid_parameters(FULL_GRID))
|
||||
def test_generate(self, test_name, model_id, config_cls, config_kwargs):
|
||||
self._test_generate(model_id, config_cls, config_kwargs)
|
||||
|
||||
@parameterized.expand(PeftTestConfigManager.get_grid_parameters(FULL_GRID))
|
||||
def test_generate_half_prec(self, test_name, model_id, config_cls, config_kwargs):
|
||||
self._test_generate_half_prec(model_id, config_cls, config_kwargs)
|
||||
|
||||
@@ -86,3 +86,7 @@ class PeftEncoderDecoderModelTester(unittest.TestCase, PeftCommonTester):
|
||||
@parameterized.expand(PeftTestConfigManager.get_grid_parameters(FULL_GRID, filter_params_func=skip_non_lora_or_pt))
|
||||
def test_generate(self, test_name, model_id, config_cls, config_kwargs):
|
||||
self._test_generate(model_id, config_cls, config_kwargs)
|
||||
|
||||
@parameterized.expand(PeftTestConfigManager.get_grid_parameters(FULL_GRID))
|
||||
def test_generate_half_prec(self, test_name, model_id, config_cls, config_kwargs):
|
||||
self._test_generate_half_prec(model_id, config_cls, config_kwargs)
|
||||
|
||||
@@ -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