Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multitask prompt tuning other inits #8

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions tests/test_multitask_prompt_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,34 @@ def test_bf16_inference(self) -> None:
mpt = mpt.to(self.torch_device)
_ = mpt.generate(input_ids=input_ids, task_ids=task_ids)

def test_generate_text_with_random_init(self) -> None:
model = LlamaForCausalLM(self._create_test_llama_config())

config = self._create_multitask_prompt_tuning_config()
config.prompt_tuning_init = MultitaskPromptTuningInit.RANDOM

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)
task_ids = torch.LongTensor([0]).to(self.torch_device)

# check if `generate` works
_ = model.generate(input_ids=input_ids, attention_mask=attention_mask, task_ids=task_ids)

with self.assertRaises(ValueError):
# check if `generate` raises an error if task_ids are not passed
_ = model.generate(input_ids, attention_mask=attention_mask)

@parameterized.expand(
[
MultitaskPromptTuningInit.TEXT,
MultitaskPromptTuningInit.AVERAGE_SOURCE_TASKS,
MultitaskPromptTuningInit.EXACT_SOURCE_TASK,
MultitaskPromptTuningInit.ONLY_SOURCE_SHARED,
],
)
def test_generate_text(self, prompt_tuning_init) -> None:
def test_generate_text_with_other_init(self, prompt_tuning_init) -> None:
with tempfile.TemporaryDirectory() as tmp_dirname:
model = LlamaForCausalLM(self._create_test_llama_config())
model = get_peft_model(model, self._create_multitask_prompt_tuning_config())
Expand All @@ -273,6 +292,7 @@ def test_generate_text(self, prompt_tuning_init) -> None:
prompt_tuning_init=prompt_tuning_init,
prompt_tuning_init_state_dict_path=os.path.join(tmp_dirname, WEIGHTS_NAME),
)
model = LlamaForCausalLM(self._create_test_llama_config())
model = get_peft_model(model, config)
model = model.to(self.torch_device)

Expand All @@ -283,6 +303,6 @@ def test_generate_text(self, prompt_tuning_init) -> None:
# check if `generate` works
_ = model.generate(input_ids=input_ids, attention_mask=attention_mask, task_ids=task_ids)

with self.assertRaises(TypeError):
# check if `generate` raises an error if no positional arguments are passed
with self.assertRaises(ValueError):
# check if `generate` raises an error if task_ids are not passed
_ = model.generate(input_ids, attention_mask=attention_mask)