diff --git a/tests/e2e/patched/test_phi_multipack.py b/tests/e2e/patched/test_phi_multipack.py index e32ab48a25..eefd912e71 100644 --- a/tests/e2e/patched/test_phi_multipack.py +++ b/tests/e2e/patched/test_phi_multipack.py @@ -33,8 +33,9 @@ def test_ft_packed(self, temp_dir): "trust_remote_code": True, "model_type": "PhiForCausalLM", "tokenizer_type": "AutoTokenizer", - "sequence_len": 1024, + "sequence_len": 2048, "sample_packing": True, + "pad_to_sequence_len": True, "load_in_8bit": False, "adapter": None, "val_set_size": 0.1, @@ -69,3 +70,54 @@ def test_ft_packed(self, temp_dir): train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta) assert (Path(temp_dir) / "pytorch_model.bin").exists() + + @with_temp_dir + def test_qlora_packed(self, temp_dir): + # pylint: disable=duplicate-code + cfg = DictDefault( + { + "base_model": "microsoft/phi-1_5", + "trust_remote_code": True, + "model_type": "PhiForCausalLM", + "tokenizer_type": "AutoTokenizer", + "sequence_len": 2048, + "sample_packing": True, + "pad_to_sequence_len": True, + "load_in_8bit": False, + "adapter": "qlora", + "lora_r": 64, + "lora_alpha": 32, + "lora_dropout": 0.05, + "lora_target_linear": True, + "val_set_size": 0.1, + "special_tokens": { + "pad_token": "<|endoftext|>", + }, + "datasets": [ + { + "path": "mhenrichsen/alpaca_2k_test", + "type": "alpaca", + }, + ], + "dataset_shard_num": 10, + "dataset_shard_idx": 0, + "num_epochs": 1, + "micro_batch_size": 1, + "gradient_accumulation_steps": 1, + "output_dir": temp_dir, + "learning_rate": 0.00001, + "optimizer": "adamw_bnb_8bit", + "lr_scheduler": "cosine", + "max_steps": 20, + "eval_steps": 10, + "save_steps": 10, + "bf16": "auto", + } + ) + + normalize_config(cfg) + cli_args = TrainerCliArgs() + dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args) + + train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta) + assert (Path(temp_dir) / "adapter_model.bin").exists() diff --git a/tests/e2e/test_phi.py b/tests/e2e/test_phi.py index 74b9d64039..bdc9c8dff0 100644 --- a/tests/e2e/test_phi.py +++ b/tests/e2e/test_phi.py @@ -25,7 +25,7 @@ class TestPhi(unittest.TestCase): """ @with_temp_dir - def test_phi2_ft(self, temp_dir): + def test_phi_ft(self, temp_dir): # pylint: disable=duplicate-code cfg = DictDefault( { @@ -33,7 +33,7 @@ def test_phi2_ft(self, temp_dir): "trust_remote_code": True, "model_type": "AutoModelForCausalLM", "tokenizer_type": "AutoTokenizer", - "sequence_len": 512, + "sequence_len": 2048, "sample_packing": False, "load_in_8bit": False, "adapter": None, @@ -60,7 +60,6 @@ def test_phi2_ft(self, temp_dir): "max_steps": 10, "save_steps": 10, "eval_steps": 10, - "save_safetensors": True, "bf16": "auto", } ) @@ -70,3 +69,53 @@ def test_phi2_ft(self, temp_dir): train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta) assert (Path(temp_dir) / "pytorch_model.bin").exists() + + @with_temp_dir + def test_phi_qlora(self, temp_dir): + # pylint: disable=duplicate-code + cfg = DictDefault( + { + "base_model": "microsoft/phi-1_5", + "trust_remote_code": True, + "model_type": "AutoModelForCausalLM", + "tokenizer_type": "AutoTokenizer", + "sequence_len": 2048, + "sample_packing": False, + "load_in_8bit": False, + "adapter": "qlora", + "lora_r": 64, + "lora_alpha": 32, + "lora_dropout": 0.05, + "lora_target_linear": True, + "val_set_size": 0.1, + "special_tokens": { + "pad_token": "<|endoftext|>", + }, + "datasets": [ + { + "path": "mhenrichsen/alpaca_2k_test", + "type": "alpaca", + }, + ], + "dataset_shard_num": 10, + "dataset_shard_idx": 0, + "num_epochs": 1, + "micro_batch_size": 1, + "gradient_accumulation_steps": 1, + "output_dir": temp_dir, + "learning_rate": 0.00001, + "optimizer": "paged_adamw_8bit", + "lr_scheduler": "cosine", + "flash_attention": True, + "max_steps": 10, + "save_steps": 10, + "eval_steps": 10, + "bf16": "auto", + } + ) + normalize_config(cfg) + cli_args = TrainerCliArgs() + dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args) + + train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta) + assert (Path(temp_dir) / "adapter_model.bin").exists()