winglian commited on
Commit
6dc68a6
1 Parent(s): 7de6a56

use temp_dir kwarg instead

Browse files
tests/e2e/test_fused_llama.py CHANGED
@@ -27,7 +27,7 @@ class TestFusedLlama(unittest.TestCase):
27
  """
28
 
29
  @with_temp_dir
30
- def test_fft_packing(self, output_dir):
31
  # pylint: disable=duplicate-code
32
  cfg = DictDefault(
33
  {
@@ -52,7 +52,7 @@ class TestFusedLlama(unittest.TestCase):
52
  "num_epochs": 2,
53
  "micro_batch_size": 2,
54
  "gradient_accumulation_steps": 1,
55
- "output_dir": output_dir,
56
  "learning_rate": 0.00001,
57
  "optimizer": "adamw_torch",
58
  "lr_scheduler": "cosine",
@@ -70,4 +70,4 @@ class TestFusedLlama(unittest.TestCase):
70
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
71
 
72
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
73
- assert (Path(output_dir) / "pytorch_model.bin").exists()
 
27
  """
28
 
29
  @with_temp_dir
30
+ def test_fft_packing(self, temp_dir):
31
  # pylint: disable=duplicate-code
32
  cfg = DictDefault(
33
  {
 
52
  "num_epochs": 2,
53
  "micro_batch_size": 2,
54
  "gradient_accumulation_steps": 1,
55
+ "output_dir": temp_dir,
56
  "learning_rate": 0.00001,
57
  "optimizer": "adamw_torch",
58
  "lr_scheduler": "cosine",
 
70
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
71
 
72
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
73
+ assert (Path(temp_dir) / "pytorch_model.bin").exists()
tests/e2e/test_lora_llama.py CHANGED
@@ -25,7 +25,7 @@ class TestLoraLlama(unittest.TestCase):
25
  """
26
 
27
  @with_temp_dir
28
- def test_lora(self, output_dir):
29
  # pylint: disable=duplicate-code
30
  cfg = DictDefault(
31
  {
@@ -53,7 +53,7 @@ class TestLoraLlama(unittest.TestCase):
53
  "num_epochs": 2,
54
  "micro_batch_size": 8,
55
  "gradient_accumulation_steps": 1,
56
- "output_dir": output_dir,
57
  "learning_rate": 0.00001,
58
  "optimizer": "adamw_torch",
59
  "lr_scheduler": "cosine",
@@ -64,10 +64,10 @@ class TestLoraLlama(unittest.TestCase):
64
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
65
 
66
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
67
- assert (Path(output_dir) / "adapter_model.bin").exists()
68
 
69
  @with_temp_dir
70
- def test_lora_packing(self, output_dir):
71
  # pylint: disable=duplicate-code
72
  cfg = DictDefault(
73
  {
@@ -97,7 +97,7 @@ class TestLoraLlama(unittest.TestCase):
97
  "num_epochs": 2,
98
  "micro_batch_size": 8,
99
  "gradient_accumulation_steps": 1,
100
- "output_dir": output_dir,
101
  "learning_rate": 0.00001,
102
  "optimizer": "adamw_torch",
103
  "lr_scheduler": "cosine",
@@ -108,10 +108,10 @@ class TestLoraLlama(unittest.TestCase):
108
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
109
 
110
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
111
- assert (Path(output_dir) / "adapter_model.bin").exists()
112
 
113
  @with_temp_dir
114
- def test_lora_gptq(self, output_dir):
115
  # pylint: disable=duplicate-code
116
  cfg = DictDefault(
117
  {
@@ -145,7 +145,7 @@ class TestLoraLlama(unittest.TestCase):
145
  "save_steps": 0.5,
146
  "micro_batch_size": 8,
147
  "gradient_accumulation_steps": 1,
148
- "output_dir": output_dir,
149
  "learning_rate": 0.00001,
150
  "optimizer": "adamw_torch",
151
  "lr_scheduler": "cosine",
@@ -156,4 +156,4 @@ class TestLoraLlama(unittest.TestCase):
156
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
157
 
158
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
159
- assert (Path(output_dir) / "adapter_model.bin").exists()
 
25
  """
26
 
27
  @with_temp_dir
28
+ def test_lora(self, temp_dir):
29
  # pylint: disable=duplicate-code
30
  cfg = DictDefault(
31
  {
 
53
  "num_epochs": 2,
54
  "micro_batch_size": 8,
55
  "gradient_accumulation_steps": 1,
56
+ "output_dir": temp_dir,
57
  "learning_rate": 0.00001,
58
  "optimizer": "adamw_torch",
59
  "lr_scheduler": "cosine",
 
64
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
65
 
66
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
67
+ assert (Path(temp_dir) / "adapter_model.bin").exists()
68
 
69
  @with_temp_dir
70
+ def test_lora_packing(self, temp_dir):
71
  # pylint: disable=duplicate-code
72
  cfg = DictDefault(
73
  {
 
97
  "num_epochs": 2,
98
  "micro_batch_size": 8,
99
  "gradient_accumulation_steps": 1,
100
+ "output_dir": temp_dir,
101
  "learning_rate": 0.00001,
102
  "optimizer": "adamw_torch",
103
  "lr_scheduler": "cosine",
 
108
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
109
 
110
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
111
+ assert (Path(temp_dir) / "adapter_model.bin").exists()
112
 
113
  @with_temp_dir
114
+ def test_lora_gptq(self, temp_dir):
115
  # pylint: disable=duplicate-code
116
  cfg = DictDefault(
117
  {
 
145
  "save_steps": 0.5,
146
  "micro_batch_size": 8,
147
  "gradient_accumulation_steps": 1,
148
+ "output_dir": temp_dir,
149
  "learning_rate": 0.00001,
150
  "optimizer": "adamw_torch",
151
  "lr_scheduler": "cosine",
 
156
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
157
 
158
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
159
+ assert (Path(temp_dir) / "adapter_model.bin").exists()
tests/e2e/test_mistral.py CHANGED
@@ -27,7 +27,7 @@ class TestMistral(unittest.TestCase):
27
  """
28
 
29
  @with_temp_dir
30
- def test_lora(self, output_dir):
31
  # pylint: disable=duplicate-code
32
  cfg = DictDefault(
33
  {
@@ -55,7 +55,7 @@ class TestMistral(unittest.TestCase):
55
  "num_epochs": 2,
56
  "micro_batch_size": 2,
57
  "gradient_accumulation_steps": 1,
58
- "output_dir": output_dir,
59
  "learning_rate": 0.00001,
60
  "optimizer": "adamw_torch",
61
  "lr_scheduler": "cosine",
@@ -69,10 +69,10 @@ class TestMistral(unittest.TestCase):
69
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
70
 
71
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
72
- assert (Path(output_dir) / "adapter_model.bin").exists()
73
 
74
  @with_temp_dir
75
- def test_ft(self, output_dir):
76
  # pylint: disable=duplicate-code
77
  cfg = DictDefault(
78
  {
@@ -94,7 +94,7 @@ class TestMistral(unittest.TestCase):
94
  "num_epochs": 2,
95
  "micro_batch_size": 2,
96
  "gradient_accumulation_steps": 1,
97
- "output_dir": output_dir,
98
  "learning_rate": 0.00001,
99
  "optimizer": "adamw_torch",
100
  "lr_scheduler": "cosine",
@@ -112,4 +112,4 @@ class TestMistral(unittest.TestCase):
112
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
113
 
114
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
115
- assert (Path(output_dir) / "pytorch_model.bin").exists()
 
27
  """
28
 
29
  @with_temp_dir
30
+ def test_lora(self, temp_dir):
31
  # pylint: disable=duplicate-code
32
  cfg = DictDefault(
33
  {
 
55
  "num_epochs": 2,
56
  "micro_batch_size": 2,
57
  "gradient_accumulation_steps": 1,
58
+ "output_dir": temp_dir,
59
  "learning_rate": 0.00001,
60
  "optimizer": "adamw_torch",
61
  "lr_scheduler": "cosine",
 
69
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
70
 
71
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
72
+ assert (Path(temp_dir) / "adapter_model.bin").exists()
73
 
74
  @with_temp_dir
75
+ def test_ft(self, temp_dir):
76
  # pylint: disable=duplicate-code
77
  cfg = DictDefault(
78
  {
 
94
  "num_epochs": 2,
95
  "micro_batch_size": 2,
96
  "gradient_accumulation_steps": 1,
97
+ "output_dir": temp_dir,
98
  "learning_rate": 0.00001,
99
  "optimizer": "adamw_torch",
100
  "lr_scheduler": "cosine",
 
112
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
113
 
114
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
115
+ assert (Path(temp_dir) / "pytorch_model.bin").exists()
tests/e2e/test_mistral_samplepack.py CHANGED
@@ -27,7 +27,7 @@ class TestMistral(unittest.TestCase):
27
  """
28
 
29
  @with_temp_dir
30
- def test_lora_packing(self, output_dir):
31
  # pylint: disable=duplicate-code
32
  cfg = DictDefault(
33
  {
@@ -56,7 +56,7 @@ class TestMistral(unittest.TestCase):
56
  "num_epochs": 2,
57
  "micro_batch_size": 2,
58
  "gradient_accumulation_steps": 1,
59
- "output_dir": output_dir,
60
  "learning_rate": 0.00001,
61
  "optimizer": "adamw_torch",
62
  "lr_scheduler": "cosine",
@@ -70,10 +70,10 @@ class TestMistral(unittest.TestCase):
70
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
71
 
72
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
73
- assert (Path(output_dir) / "adapter_model.bin").exists()
74
 
75
  @with_temp_dir
76
- def test_ft_packing(self, output_dir):
77
  # pylint: disable=duplicate-code
78
  cfg = DictDefault(
79
  {
@@ -96,7 +96,7 @@ class TestMistral(unittest.TestCase):
96
  "num_epochs": 2,
97
  "micro_batch_size": 2,
98
  "gradient_accumulation_steps": 1,
99
- "output_dir": output_dir,
100
  "learning_rate": 0.00001,
101
  "optimizer": "adamw_torch",
102
  "lr_scheduler": "cosine",
@@ -114,4 +114,4 @@ class TestMistral(unittest.TestCase):
114
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
115
 
116
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
117
- assert (Path(output_dir) / "pytorch_model.bin").exists()
 
27
  """
28
 
29
  @with_temp_dir
30
+ def test_lora_packing(self, temp_dir):
31
  # pylint: disable=duplicate-code
32
  cfg = DictDefault(
33
  {
 
56
  "num_epochs": 2,
57
  "micro_batch_size": 2,
58
  "gradient_accumulation_steps": 1,
59
+ "output_dir": temp_dir,
60
  "learning_rate": 0.00001,
61
  "optimizer": "adamw_torch",
62
  "lr_scheduler": "cosine",
 
70
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
71
 
72
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
73
+ assert (Path(temp_dir) / "adapter_model.bin").exists()
74
 
75
  @with_temp_dir
76
+ def test_ft_packing(self, temp_dir):
77
  # pylint: disable=duplicate-code
78
  cfg = DictDefault(
79
  {
 
96
  "num_epochs": 2,
97
  "micro_batch_size": 2,
98
  "gradient_accumulation_steps": 1,
99
+ "output_dir": temp_dir,
100
  "learning_rate": 0.00001,
101
  "optimizer": "adamw_torch",
102
  "lr_scheduler": "cosine",
 
114
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
115
 
116
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
117
+ assert (Path(temp_dir) / "pytorch_model.bin").exists()
tests/e2e/test_phi.py CHANGED
@@ -25,7 +25,7 @@ class TestPhi(unittest.TestCase):
25
  """
26
 
27
  @with_temp_dir
28
- def test_ft(self, output_dir):
29
  # pylint: disable=duplicate-code
30
  cfg = DictDefault(
31
  {
@@ -55,7 +55,7 @@ class TestPhi(unittest.TestCase):
55
  "num_epochs": 1,
56
  "micro_batch_size": 1,
57
  "gradient_accumulation_steps": 1,
58
- "output_dir": output_dir,
59
  "learning_rate": 0.00001,
60
  "optimizer": "adamw_bnb_8bit",
61
  "lr_scheduler": "cosine",
@@ -67,10 +67,10 @@ class TestPhi(unittest.TestCase):
67
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
68
 
69
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
70
- assert (Path(output_dir) / "pytorch_model.bin").exists()
71
 
72
  @with_temp_dir
73
- def test_ft_packed(self, output_dir):
74
  # pylint: disable=duplicate-code
75
  cfg = DictDefault(
76
  {
@@ -100,7 +100,7 @@ class TestPhi(unittest.TestCase):
100
  "num_epochs": 1,
101
  "micro_batch_size": 1,
102
  "gradient_accumulation_steps": 1,
103
- "output_dir": output_dir,
104
  "learning_rate": 0.00001,
105
  "optimizer": "adamw_bnb_8bit",
106
  "lr_scheduler": "cosine",
@@ -112,4 +112,4 @@ class TestPhi(unittest.TestCase):
112
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
113
 
114
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
115
- assert (Path(output_dir) / "pytorch_model.bin").exists()
 
25
  """
26
 
27
  @with_temp_dir
28
+ def test_ft(self, temp_dir):
29
  # pylint: disable=duplicate-code
30
  cfg = DictDefault(
31
  {
 
55
  "num_epochs": 1,
56
  "micro_batch_size": 1,
57
  "gradient_accumulation_steps": 1,
58
+ "output_dir": temp_dir,
59
  "learning_rate": 0.00001,
60
  "optimizer": "adamw_bnb_8bit",
61
  "lr_scheduler": "cosine",
 
67
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
68
 
69
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
70
+ assert (Path(temp_dir) / "pytorch_model.bin").exists()
71
 
72
  @with_temp_dir
73
+ def test_ft_packed(self, temp_dir):
74
  # pylint: disable=duplicate-code
75
  cfg = DictDefault(
76
  {
 
100
  "num_epochs": 1,
101
  "micro_batch_size": 1,
102
  "gradient_accumulation_steps": 1,
103
+ "output_dir": temp_dir,
104
  "learning_rate": 0.00001,
105
  "optimizer": "adamw_bnb_8bit",
106
  "lr_scheduler": "cosine",
 
112
  dataset_meta = load_datasets(cfg=cfg, cli_args=cli_args)
113
 
114
  train(cfg=cfg, cli_args=cli_args, dataset_meta=dataset_meta)
115
+ assert (Path(temp_dir) / "pytorch_model.bin").exists()
tests/e2e/utils.py CHANGED
@@ -14,7 +14,7 @@ def with_temp_dir(test_func):
14
  temp_dir = tempfile.mkdtemp()
15
  try:
16
  # Pass the temporary directory to the test function
17
- test_func(temp_dir, *args, **kwargs)
18
  finally:
19
  # Clean up the directory after the test
20
  shutil.rmtree(temp_dir)
 
14
  temp_dir = tempfile.mkdtemp()
15
  try:
16
  # Pass the temporary directory to the test function
17
+ test_func(*args, temp_dir=temp_dir, **kwargs)
18
  finally:
19
  # Clean up the directory after the test
20
  shutil.rmtree(temp_dir)