Skip to content

Commit

Permalink
🧲 Use our own require_bitsandbytes (#2370)
Browse files Browse the repository at this point in the history
* use our own require_bitsandbytes

* rephrase
  • Loading branch information
qgallouedec authored Nov 20, 2024
1 parent bb0afc2 commit 5626806
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion tests/slow/test_dpo_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
from datasets import load_dataset
from parameterized import parameterized
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from transformers.testing_utils import require_bitsandbytes, require_peft, require_torch_accelerator, torch_device
from transformers.testing_utils import require_peft, require_torch_accelerator, torch_device
from transformers.utils import is_peft_available

from trl import DPOConfig, DPOTrainer

from ..testing_utils import require_bitsandbytes
from .testing_constants import DPO_LOSS_TYPES, DPO_PRECOMPUTE_LOGITS, GRADIENT_CHECKPOINTING_KWARGS, MODELS_TO_TEST


Expand Down
2 changes: 1 addition & 1 deletion tests/slow/test_sft_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from parameterized import parameterized
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from transformers.testing_utils import (
require_bitsandbytes,
require_liger_kernel,
require_peft,
require_torch_accelerator,
Expand All @@ -33,6 +32,7 @@
from trl import SFTConfig, SFTTrainer
from trl.models.utils import setup_chat_format

from ..testing_utils import require_bitsandbytes
from .testing_constants import DEVICE_MAP_OPTIONS, GRADIENT_CHECKPOINTING_KWARGS, MODELS_TO_TEST, PACKING_OPTIONS


Expand Down
9 changes: 2 additions & 7 deletions tests/test_dpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@
PreTrainedTokenizerBase,
is_vision_available,
)
from transformers.testing_utils import (
require_bitsandbytes,
require_peft,
require_torch_gpu_if_bnb_not_multi_backend_enabled,
require_vision,
)
from transformers.testing_utils import require_peft, require_torch_gpu_if_bnb_not_multi_backend_enabled, require_vision

from trl import DPOConfig, DPOTrainer, FDivergenceType

from .testing_utils import require_no_wandb
from .testing_utils import require_bitsandbytes, require_no_wandb


if is_vision_available():
Expand Down
11 changes: 10 additions & 1 deletion tests/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
import random
import unittest

from transformers import is_sklearn_available, is_wandb_available
from transformers import is_bitsandbytes_available, is_sklearn_available, is_wandb_available

from trl import BaseBinaryJudge, BasePairwiseJudge, is_diffusers_available, is_llm_blender_available


# transformers.testing_utils contains a require_bitsandbytes function, but relies on pytest markers which we don't use
# in our test suite. We therefore need to implement our own version of this function.
def require_bitsandbytes(test_case):
"""
Decorator marking a test that requires bitsandbytes. Skips the test if bitsandbytes is not available.
"""
return unittest.skipUnless(is_bitsandbytes_available(), "test requires bitsandbytes")(test_case)


def require_diffusers(test_case):
"""
Decorator marking a test that requires diffusers. Skips the test if diffusers is not available.
Expand Down

0 comments on commit 5626806

Please sign in to comment.