Skip to content

Commit 0dc4d53

Browse files
Remove parameterized as test extra dependency (#4315)
1 parent e2ab435 commit 0dc4d53

22 files changed

+216
-221
lines changed

.github/workflows/slow-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: |
4848
source .venv/bin/activate
4949
uv pip install ".[dev]"
50-
uv pip install pytest-reportlog parameterized
50+
uv pip install pytest-reportlog
5151
5252
- name: Run slow SFT tests on single GPU
5353
if: always()
@@ -95,7 +95,7 @@ jobs:
9595
run: |
9696
source .venv/bin/activate
9797
uv pip install ".[dev]"
98-
uv pip install pytest-reportlog parameterized
98+
uv pip install pytest-reportlog
9999
100100
- name: Run slow SFT tests on Multi GPU
101101
if: always()

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ scikit = [
7171
"scikit-learn"
7272
]
7373
test = [
74-
"parameterized",
7574
"pytest-cov",
7675
"pytest-rerunfailures==15.1",
7776
"pytest-xdist",
@@ -112,7 +111,6 @@ dev = [
112111
"bitsandbytes",
113112
# scikit: included in bco
114113
# test
115-
"parameterized",
116114
"pytest-cov",
117115
"pytest-rerunfailures==15.1",
118116
"pytest-xdist",

tests/slow/test_dpo_slow.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
# limitations under the License.
1414

1515
import gc
16-
import itertools
1716

1817
import pytest
1918
import torch
2019
from accelerate.utils.memory import release_memory
2120
from datasets import load_dataset
22-
from parameterized import parameterized
2321
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2422
from transformers.testing_utils import backend_empty_cache, require_torch_accelerator, torch_device
2523
from transformers.utils import is_peft_available
@@ -54,7 +52,9 @@ def teardown_method(self):
5452
backend_empty_cache(torch_device)
5553
gc.collect()
5654

57-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, DPO_LOSS_TYPES, DPO_PRECOMPUTE_LOGITS)))
55+
@pytest.mark.parametrize("pre_compute_logits", DPO_PRECOMPUTE_LOGITS)
56+
@pytest.mark.parametrize("loss_type", DPO_LOSS_TYPES)
57+
@pytest.mark.parametrize("model_id", MODELS_TO_TEST)
5858
def test_dpo_bare_model(self, model_id, loss_type, pre_compute_logits):
5959
"""
6060
A test that tests the simple usage of `DPOTrainer` using a bare model in full precision.
@@ -98,16 +98,10 @@ def test_dpo_bare_model(self, model_id, loss_type, pre_compute_logits):
9898

9999
release_memory(model, trainer)
100100

101-
@parameterized.expand(
102-
list(
103-
itertools.product(
104-
MODELS_TO_TEST,
105-
DPO_LOSS_TYPES,
106-
DPO_PRECOMPUTE_LOGITS,
107-
GRADIENT_CHECKPOINTING_KWARGS,
108-
)
109-
)
110-
)
101+
@pytest.mark.parametrize("gradient_checkpointing_kwargs", GRADIENT_CHECKPOINTING_KWARGS)
102+
@pytest.mark.parametrize("pre_compute_logits", DPO_PRECOMPUTE_LOGITS)
103+
@pytest.mark.parametrize("loss_type", DPO_LOSS_TYPES)
104+
@pytest.mark.parametrize("model_id", MODELS_TO_TEST)
111105
@require_peft
112106
def test_dpo_peft_model(self, model_id, loss_type, pre_compute_logits, gradient_checkpointing_kwargs):
113107
"""
@@ -160,16 +154,10 @@ def test_dpo_peft_model(self, model_id, loss_type, pre_compute_logits, gradient_
160154

161155
release_memory(model, trainer)
162156

163-
@parameterized.expand(
164-
list(
165-
itertools.product(
166-
MODELS_TO_TEST,
167-
DPO_LOSS_TYPES,
168-
DPO_PRECOMPUTE_LOGITS,
169-
GRADIENT_CHECKPOINTING_KWARGS,
170-
)
171-
)
172-
)
157+
@pytest.mark.parametrize("gradient_checkpointing_kwargs", GRADIENT_CHECKPOINTING_KWARGS)
158+
@pytest.mark.parametrize("pre_compute_logits", DPO_PRECOMPUTE_LOGITS)
159+
@pytest.mark.parametrize("loss_type", DPO_LOSS_TYPES)
160+
@pytest.mark.parametrize("model_id", MODELS_TO_TEST)
173161
@require_bitsandbytes
174162
@require_peft
175163
def test_dpo_peft_model_qlora(self, model_id, loss_type, pre_compute_logits, gradient_checkpointing_kwargs):

tests/slow/test_grpo_slow.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from accelerate.utils.memory import release_memory
2424
from datasets import Dataset, Features, Image, Value, load_dataset
2525
from packaging.version import Version
26-
from parameterized import parameterized
2726
from transformers import (
2827
AutoModelForCausalLM,
2928
AutoModelForImageTextToText,
@@ -64,7 +63,7 @@ def teardown_method(self):
6463
backend_empty_cache(torch_device)
6564
gc.collect()
6665

67-
@parameterized.expand(MODELS_TO_TEST)
66+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
6867
@require_liger_kernel
6968
def test_training_with_liger_grpo_loss(self, model_name):
7069
training_args = GRPOConfig(
@@ -104,7 +103,7 @@ def test_training_with_liger_grpo_loss(self, model_name):
104103

105104
release_memory(model, trainer)
106105

107-
@parameterized.expand(MODELS_TO_TEST)
106+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
108107
@require_liger_kernel
109108
@require_peft
110109
def test_training_with_liger_grpo_loss_and_peft(self, model_name):
@@ -168,7 +167,7 @@ def test_training_with_liger_grpo_loss_and_peft(self, model_name):
168167

169168
release_memory(model, trainer)
170169

171-
@parameterized.expand(MODELS_TO_TEST)
170+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
172171
def test_training_with_transformers_paged(self, model_name):
173172
"""Test that training works with transformers paged implementation (requires GPU)."""
174173
if Version(transformers.__version__) < Version("4.57.0"):
@@ -206,10 +205,11 @@ def test_training_with_transformers_paged(self, model_name):
206205

207206
release_memory(model, trainer)
208207

209-
@parameterized.expand(
208+
@pytest.mark.parametrize(
209+
"model_name",
210210
[
211-
("HuggingFaceTB/SmolVLM-Instruct",), # Only test the smaller model to avoid OOM
212-
]
211+
"HuggingFaceTB/SmolVLM-Instruct", # Only test the smaller model to avoid OOM
212+
],
213213
)
214214
@require_flash_attn
215215
@require_bitsandbytes

tests/slow/test_sft_slow.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
# limitations under the License.
1414

1515
import gc
16-
import itertools
1716

1817
import pytest
1918
import torch
2019
from accelerate.utils.memory import release_memory
2120
from datasets import load_dataset
22-
from parameterized import parameterized
2321
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2422
from transformers.testing_utils import (
2523
backend_empty_cache,
@@ -61,7 +59,8 @@ def teardown_method(self):
6159
backend_empty_cache(torch_device)
6260
gc.collect()
6361

64-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS)))
62+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
63+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
6564
def test_sft_trainer_str(self, model_name, packing):
6665
"""
6766
Simply tests if passing a simple str to `SFTTrainer` loads and runs the trainer as expected.
@@ -85,7 +84,8 @@ def test_sft_trainer_str(self, model_name, packing):
8584

8685
trainer.train()
8786

88-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS)))
87+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
88+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
8989
def test_sft_trainer_transformers(self, model_name, packing):
9090
"""
9191
Simply tests if passing a transformers model to `SFTTrainer` loads and runs the trainer as expected.
@@ -115,7 +115,8 @@ def test_sft_trainer_transformers(self, model_name, packing):
115115

116116
release_memory(model, trainer)
117117

118-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS)))
118+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
119+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
119120
@require_peft
120121
def test_sft_trainer_peft(self, model_name, packing):
121122
"""
@@ -151,7 +152,8 @@ def test_sft_trainer_peft(self, model_name, packing):
151152

152153
release_memory(model, trainer)
153154

154-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS)))
155+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
156+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
155157
def test_sft_trainer_transformers_mp(self, model_name, packing):
156158
"""
157159
Simply tests if passing a transformers model to `SFTTrainer` loads and runs the trainer as expected in mixed
@@ -183,7 +185,9 @@ def test_sft_trainer_transformers_mp(self, model_name, packing):
183185

184186
release_memory(model, trainer)
185187

186-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS, GRADIENT_CHECKPOINTING_KWARGS)))
188+
@pytest.mark.parametrize("gradient_checkpointing_kwargs", GRADIENT_CHECKPOINTING_KWARGS)
189+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
190+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
187191
def test_sft_trainer_transformers_mp_gc(self, model_name, packing, gradient_checkpointing_kwargs):
188192
"""
189193
Simply tests if passing a transformers model to `SFTTrainer` loads and runs the trainer as expected in mixed
@@ -217,7 +221,9 @@ def test_sft_trainer_transformers_mp_gc(self, model_name, packing, gradient_chec
217221

218222
release_memory(model, trainer)
219223

220-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS, GRADIENT_CHECKPOINTING_KWARGS)))
224+
@pytest.mark.parametrize("gradient_checkpointing_kwargs", GRADIENT_CHECKPOINTING_KWARGS)
225+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
226+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
221227
@require_peft
222228
def test_sft_trainer_transformers_mp_gc_peft(self, model_name, packing, gradient_checkpointing_kwargs):
223229
"""
@@ -255,9 +261,10 @@ def test_sft_trainer_transformers_mp_gc_peft(self, model_name, packing, gradient
255261

256262
release_memory(model, trainer)
257263

258-
@parameterized.expand(
259-
list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS, GRADIENT_CHECKPOINTING_KWARGS, DEVICE_MAP_OPTIONS))
260-
)
264+
@pytest.mark.parametrize("device_map", DEVICE_MAP_OPTIONS)
265+
@pytest.mark.parametrize("gradient_checkpointing_kwargs", GRADIENT_CHECKPOINTING_KWARGS)
266+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
267+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
261268
@require_torch_multi_accelerator
262269
def test_sft_trainer_transformers_mp_gc_device_map(
263270
self, model_name, packing, gradient_checkpointing_kwargs, device_map
@@ -294,7 +301,9 @@ def test_sft_trainer_transformers_mp_gc_device_map(
294301

295302
release_memory(model, trainer)
296303

297-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS, GRADIENT_CHECKPOINTING_KWARGS)))
304+
@pytest.mark.parametrize("gradient_checkpointing_kwargs", GRADIENT_CHECKPOINTING_KWARGS)
305+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
306+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
298307
@require_peft
299308
@require_bitsandbytes
300309
def test_sft_trainer_transformers_mp_gc_peft_qlora(self, model_name, packing, gradient_checkpointing_kwargs):
@@ -335,7 +344,8 @@ def test_sft_trainer_transformers_mp_gc_peft_qlora(self, model_name, packing, gr
335344

336345
release_memory(model, trainer)
337346

338-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS)))
347+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
348+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
339349
@require_peft
340350
@require_bitsandbytes
341351
def test_sft_trainer_with_chat_format_qlora(self, model_name, packing):
@@ -375,7 +385,8 @@ def test_sft_trainer_with_chat_format_qlora(self, model_name, packing):
375385

376386
release_memory(model, trainer)
377387

378-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS)))
388+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
389+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
379390
@require_liger_kernel
380391
def test_sft_trainer_with_liger(self, model_name, packing):
381392
"""
@@ -419,7 +430,8 @@ def cleanup_liger_patches(trainer):
419430
finally:
420431
cleanup_liger_patches(trainer)
421432

422-
@parameterized.expand(list(itertools.product(MODELS_TO_TEST, PACKING_OPTIONS)))
433+
@pytest.mark.parametrize("packing", PACKING_OPTIONS)
434+
@pytest.mark.parametrize("model_name", MODELS_TO_TEST)
423435
@require_torch_accelerator
424436
def test_train_offloading(self, model_name, packing):
425437
"""Test that activation offloading works with SFTTrainer."""

tests/test_bco_trainer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import torch
1919
from accelerate import Accelerator
2020
from datasets import load_dataset
21-
from parameterized import parameterized
2221
from transformers import AutoModel, AutoModelForCausalLM, AutoTokenizer
2322
from transformers.utils import is_peft_available
2423

@@ -33,15 +32,16 @@
3332

3433

3534
class TestBCOTrainer(TrlTestCase):
36-
@parameterized.expand(
35+
@pytest.mark.parametrize(
36+
"config_name",
3737
[
38-
("standard_preference",),
39-
("standard_implicit_prompt_preference",),
40-
("standard_unpaired_preference",),
41-
("conversational_preference",),
42-
("conversational_implicit_prompt_preference",),
43-
("conversational_unpaired_preference",),
44-
]
38+
"standard_preference",
39+
"standard_implicit_prompt_preference",
40+
"standard_unpaired_preference",
41+
"conversational_preference",
42+
"conversational_implicit_prompt_preference",
43+
"conversational_unpaired_preference",
44+
],
4545
)
4646
@require_sklearn
4747
def test_train(self, config_name):

tests/test_cpo_trainer.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
14+
import pytest
1615
import torch
1716
from datasets import load_dataset
18-
from parameterized import parameterized
1917
from transformers import AutoModelForCausalLM, AutoModelForSeq2SeqLM, AutoTokenizer
2018

2119
from trl import CPOConfig, CPOTrainer
@@ -37,7 +35,8 @@ def setup_method(self):
3735
self.t5_tokenizer = AutoTokenizer.from_pretrained(model_id)
3836
self.t5_tokenizer.chat_template = SIMPLE_CHAT_TEMPLATE
3937

40-
@parameterized.expand(
38+
@pytest.mark.parametrize(
39+
"name, loss_type, config_name",
4140
[
4241
("qwen", "sigmoid", "standard_preference"),
4342
("t5", "hinge", "standard_implicit_prompt_preference"),
@@ -46,7 +45,7 @@ def setup_method(self):
4645
("qwen", "simpo", "standard_preference"),
4746
("t5", "simpo", "standard_implicit_prompt_preference"),
4847
("qwen", "hinge", "conversational_preference"),
49-
]
48+
],
5049
)
5150
def test_cpo_trainer(self, name, loss_type, config_name):
5251
training_args = CPOConfig(
@@ -93,13 +92,14 @@ def test_cpo_trainer(self, name, loss_type, config_name):
9392
if param.sum() != 0: # ignore 0 biases
9493
assert not torch.equal(param, new_param)
9594

96-
@parameterized.expand(
95+
@pytest.mark.parametrize(
96+
"config_name",
9797
[
98-
("standard_preference",),
99-
("standard_implicit_prompt_preference",),
100-
("conversational_preference",),
101-
("conversational_implicit_prompt_preference",),
102-
]
98+
"standard_preference",
99+
"standard_implicit_prompt_preference",
100+
"conversational_preference",
101+
"conversational_implicit_prompt_preference",
102+
],
103103
)
104104
@require_peft
105105
def test_cpo_trainer_with_lora(self, config_name):

0 commit comments

Comments
 (0)