diff --git a/examples/flax/question-answering/run_qa.py b/examples/flax/question-answering/run_qa.py index e072f3f75b..220400c300 100644 --- a/examples/flax/question-answering/run_qa.py +++ b/examples/flax/question-answering/run_qa.py @@ -545,7 +545,7 @@ def main(): # region Tokenizer check: this script requires a fast tokenizer. if not isinstance(tokenizer, PreTrainedTokenizerFast): - raise ValueError( + raise TypeError( "This example script only works for models that have a fast tokenizer. Check out the big table of models at" " https://huggingface.co/transformers/index.html#supported-frameworks to find the model types that meet" " this requirement" diff --git a/examples/pytorch/question-answering/run_qa.py b/examples/pytorch/question-answering/run_qa.py index 1a617d6a87..0a1985ce8a 100755 --- a/examples/pytorch/question-answering/run_qa.py +++ b/examples/pytorch/question-answering/run_qa.py @@ -356,7 +356,7 @@ def main(): # Tokenizer check: this script requires a fast tokenizer. if not isinstance(tokenizer, PreTrainedTokenizerFast): - raise ValueError( + raise TypeError( "This example script only works for models that have a fast tokenizer. Check out the big table of models at" " https://huggingface.co/transformers/index.html#supported-frameworks to find the model types that meet" " this requirement" diff --git a/examples/pytorch/token-classification/run_ner.py b/examples/pytorch/token-classification/run_ner.py index ce89fcef5d..e6b9ee8bbe 100755 --- a/examples/pytorch/token-classification/run_ner.py +++ b/examples/pytorch/token-classification/run_ner.py @@ -398,7 +398,7 @@ def main(): # Tokenizer check: this script requires a fast tokenizer. if not isinstance(tokenizer, PreTrainedTokenizerFast): - raise ValueError( + raise TypeError( "This example script only works for models that have a fast tokenizer. Check out the big table of models at" " https://huggingface.co/transformers/index.html#supported-frameworks to find the model types that meet" " this requirement" diff --git a/examples/tensorflow/question-answering/run_qa.py b/examples/tensorflow/question-answering/run_qa.py index aaf8cadca9..2acf7cb062 100755 --- a/examples/tensorflow/question-answering/run_qa.py +++ b/examples/tensorflow/question-answering/run_qa.py @@ -377,7 +377,7 @@ def main(): # region Tokenizer check: this script requires a fast tokenizer. if not isinstance(tokenizer, PreTrainedTokenizerFast): - raise ValueError( + raise TypeError( "This example script only works for models that have a fast tokenizer. Check out the big table of models at" " https://huggingface.co/transformers/index.html#supported-frameworks to find the model types that meet" " this requirement" diff --git a/src/transformers/image_transforms.py b/src/transformers/image_transforms.py index 38acfc250a..deb988171a 100644 --- a/src/transformers/image_transforms.py +++ b/src/transformers/image_transforms.py @@ -416,7 +416,7 @@ def normalize( The channel dimension format of the input image. If unset, will use the inferred format from the input. """ if not isinstance(image, np.ndarray): - raise ValueError("image must be a numpy array") + raise TypeError("image must be a numpy array") if input_data_format is None: input_data_format = infer_channel_dimension_format(image) diff --git a/src/transformers/integrations/integration_utils.py b/src/transformers/integrations/integration_utils.py index fa5f2da11e..2b7fd9e756 100755 --- a/src/transformers/integrations/integration_utils.py +++ b/src/transformers/integrations/integration_utils.py @@ -768,7 +768,7 @@ class WandbLogModel(str, Enum): @classmethod def _missing_(cls, value: Any) -> "WandbLogModel": if not isinstance(value, str): - raise ValueError(f"Expecting to have a string `WANDB_LOG_MODEL` setting, but got {type(value)}") + raise TypeError(f"Expecting to have a string `WANDB_LOG_MODEL` setting, but got {type(value)}") if value.upper() in ENV_VARS_TRUE_VALUES: raise DeprecationWarning( f"Setting `WANDB_LOG_MODEL` as {os.getenv('WANDB_LOG_MODEL')} is deprecated and will be removed in " diff --git a/src/transformers/modeling_tf_utils.py b/src/transformers/modeling_tf_utils.py index 5f70e4e2b9..4669971098 100644 --- a/src/transformers/modeling_tf_utils.py +++ b/src/transformers/modeling_tf_utils.py @@ -185,7 +185,7 @@ def keras_serializable(cls): else: initializer(self, config, *args, **kwargs) else: - raise ValueError("Must pass either `config` (PretrainedConfig) or `config` (dict)") + raise TypeError("Must pass either `config` (PretrainedConfig) or `config` (dict)") self._config = config self._kwargs = kwargs diff --git a/src/transformers/modeling_utils.py b/src/transformers/modeling_utils.py index dc6926d43f..61110e926d 100644 --- a/src/transformers/modeling_utils.py +++ b/src/transformers/modeling_utils.py @@ -2088,7 +2088,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, PushToHubMixin, PeftAdapterMi def __init__(self, config: PretrainedConfig, *inputs, **kwargs): super().__init__() if not isinstance(config, PretrainedConfig): - raise ValueError( + raise TypeError( f"Parameter config in `{self.__class__.__name__}(config)` should be an instance of class " "`PretrainedConfig`. To create a model from a pretrained model use " f"`model = {self.__class__.__name__}.from_pretrained(PRETRAINED_MODEL_NAME)`" diff --git a/src/transformers/models/aria/modular_aria.py b/src/transformers/models/aria/modular_aria.py index 95e3bad057..f6303b4d38 100644 --- a/src/transformers/models/aria/modular_aria.py +++ b/src/transformers/models/aria/modular_aria.py @@ -999,7 +999,7 @@ class AriaProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") if images is not None: image_inputs = self.image_processor(images, **output_kwargs["images_kwargs"]) diff --git a/src/transformers/models/aria/processing_aria.py b/src/transformers/models/aria/processing_aria.py index 07a684cd76..d694e59242 100644 --- a/src/transformers/models/aria/processing_aria.py +++ b/src/transformers/models/aria/processing_aria.py @@ -120,7 +120,7 @@ class AriaProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") if images is not None: image_inputs = self.image_processor(images, **output_kwargs["images_kwargs"]) diff --git a/src/transformers/models/clip/tokenization_clip_fast.py b/src/transformers/models/clip/tokenization_clip_fast.py index 4de1504a80..c859d4572d 100644 --- a/src/transformers/models/clip/tokenization_clip_fast.py +++ b/src/transformers/models/clip/tokenization_clip_fast.py @@ -81,7 +81,7 @@ class CLIPTokenizerFast(PreTrainedTokenizerFast): ) if not isinstance(self.backend_tokenizer.pre_tokenizer, pre_tokenizers.Sequence): - raise ValueError( + raise TypeError( "The `backend_tokenizer` provided does not match the expected format. The CLIP tokenizer has been" " heavily modified from transformers version 4.17.0. You need to convert the tokenizer you are using" " to be compatible with this version.The easiest way to do so is" diff --git a/src/transformers/models/gemma3/processing_gemma3.py b/src/transformers/models/gemma3/processing_gemma3.py index eaa0ab3b76..0cfd7a466e 100644 --- a/src/transformers/models/gemma3/processing_gemma3.py +++ b/src/transformers/models/gemma3/processing_gemma3.py @@ -97,7 +97,7 @@ class Gemma3Processor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") image_inputs = {} if images is not None: diff --git a/src/transformers/models/grounding_dino/image_processing_grounding_dino.py b/src/transformers/models/grounding_dino/image_processing_grounding_dino.py index cf18dd43a1..d56a24cb57 100644 --- a/src/transformers/models/grounding_dino/image_processing_grounding_dino.py +++ b/src/transformers/models/grounding_dino/image_processing_grounding_dino.py @@ -831,7 +831,7 @@ def _scale_boxes(boxes, target_sizes): elif isinstance(target_sizes, torch.Tensor): image_height, image_width = target_sizes.unbind(1) else: - raise ValueError("`target_sizes` must be a list, tuple or torch.Tensor") + raise TypeError("`target_sizes` must be a list, tuple or torch.Tensor") scale_factor = torch.stack([image_width, image_height, image_width, image_height], dim=1) scale_factor = scale_factor.unsqueeze(1).to(boxes.device) diff --git a/src/transformers/models/grounding_dino/image_processing_grounding_dino_fast.py b/src/transformers/models/grounding_dino/image_processing_grounding_dino_fast.py index 93f68f415e..695b65629a 100644 --- a/src/transformers/models/grounding_dino/image_processing_grounding_dino_fast.py +++ b/src/transformers/models/grounding_dino/image_processing_grounding_dino_fast.py @@ -307,7 +307,7 @@ def _scale_boxes(boxes, target_sizes): elif isinstance(target_sizes, torch.Tensor): image_height, image_width = target_sizes.unbind(1) else: - raise ValueError("`target_sizes` must be a list, tuple or torch.Tensor") + raise TypeError("`target_sizes` must be a list, tuple or torch.Tensor") scale_factor = torch.stack([image_width, image_height, image_width, image_height], dim=1) scale_factor = scale_factor.unsqueeze(1).to(boxes.device) diff --git a/src/transformers/models/grounding_dino/modular_grounding_dino.py b/src/transformers/models/grounding_dino/modular_grounding_dino.py index 7ebd170d42..e49a79fdde 100644 --- a/src/transformers/models/grounding_dino/modular_grounding_dino.py +++ b/src/transformers/models/grounding_dino/modular_grounding_dino.py @@ -40,7 +40,7 @@ def _scale_boxes(boxes, target_sizes): elif isinstance(target_sizes, torch.Tensor): image_height, image_width = target_sizes.unbind(1) else: - raise ValueError("`target_sizes` must be a list, tuple or torch.Tensor") + raise TypeError("`target_sizes` must be a list, tuple or torch.Tensor") scale_factor = torch.stack([image_width, image_height, image_width, image_height], dim=1) scale_factor = scale_factor.unsqueeze(1).to(boxes.device) diff --git a/src/transformers/models/llava/processing_llava.py b/src/transformers/models/llava/processing_llava.py index 3d1cfc61e6..5bac76cb44 100644 --- a/src/transformers/models/llava/processing_llava.py +++ b/src/transformers/models/llava/processing_llava.py @@ -145,7 +145,7 @@ class LlavaProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") # try to expand inputs in processing if we have the necessary parts prompt_strings = text diff --git a/src/transformers/models/llava_next/processing_llava_next.py b/src/transformers/models/llava_next/processing_llava_next.py index 05efc60fcd..c5760aa169 100644 --- a/src/transformers/models/llava_next/processing_llava_next.py +++ b/src/transformers/models/llava_next/processing_llava_next.py @@ -149,7 +149,7 @@ class LlavaNextProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") prompt_strings = text if image_inputs: diff --git a/src/transformers/models/llava_next_video/processing_llava_next_video.py b/src/transformers/models/llava_next_video/processing_llava_next_video.py index dd039ff024..b50aee5af2 100644 --- a/src/transformers/models/llava_next_video/processing_llava_next_video.py +++ b/src/transformers/models/llava_next_video/processing_llava_next_video.py @@ -176,7 +176,7 @@ class LlavaNextVideoProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") if image_inputs: image_sizes = iter(image_inputs["image_sizes"]) diff --git a/src/transformers/models/llava_onevision/processing_llava_onevision.py b/src/transformers/models/llava_onevision/processing_llava_onevision.py index a3f2e28359..5a17455a52 100644 --- a/src/transformers/models/llava_onevision/processing_llava_onevision.py +++ b/src/transformers/models/llava_onevision/processing_llava_onevision.py @@ -157,7 +157,7 @@ class LlavaOnevisionProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") image_inputs = video_inputs = {} diff --git a/src/transformers/models/mllama/image_processing_mllama.py b/src/transformers/models/mllama/image_processing_mllama.py index f918908c3d..01ae14c9f5 100644 --- a/src/transformers/models/mllama/image_processing_mllama.py +++ b/src/transformers/models/mllama/image_processing_mllama.py @@ -473,7 +473,7 @@ def to_channel_dimension_format( The image with the channel dimension set to `channel_dim`. """ if not isinstance(image, np.ndarray): - raise ValueError(f"Input image must be of type np.ndarray, got {type(image)}") + raise TypeError(f"Input image must be of type np.ndarray, got {type(image)}") if input_channel_dim is None: input_channel_dim = infer_channel_dimension_format(image) diff --git a/src/transformers/models/myt5/tokenization_myt5.py b/src/transformers/models/myt5/tokenization_myt5.py index e262a70fca..251e3d602b 100644 --- a/src/transformers/models/myt5/tokenization_myt5.py +++ b/src/transformers/models/myt5/tokenization_myt5.py @@ -48,7 +48,7 @@ class ByteRewriter: with open(rewriting_rules, "r") as f: rewriting_rules = json.load(f) elif not isinstance(rewriting_rules, dict): - raise ValueError( + raise TypeError( f"rewriting_rules should be either a path to json file or a dict, got {type(rewriting_rules)}" ) diff --git a/src/transformers/models/owlv2/image_processing_owlv2.py b/src/transformers/models/owlv2/image_processing_owlv2.py index 33a14adfb0..0db195ba16 100644 --- a/src/transformers/models/owlv2/image_processing_owlv2.py +++ b/src/transformers/models/owlv2/image_processing_owlv2.py @@ -86,7 +86,7 @@ def _scale_boxes(boxes, target_sizes): elif isinstance(target_sizes, torch.Tensor): image_height, image_width = target_sizes.unbind(1) else: - raise ValueError("`target_sizes` must be a list, tuple or torch.Tensor") + raise TypeError("`target_sizes` must be a list, tuple or torch.Tensor") # for owlv2 image is padded to max size unlike owlvit, that's why we have to scale boxes to max size max_size = torch.max(image_height, image_width) diff --git a/src/transformers/models/owlvit/image_processing_owlvit.py b/src/transformers/models/owlvit/image_processing_owlvit.py index 8d3448e688..4bf9306c56 100644 --- a/src/transformers/models/owlvit/image_processing_owlvit.py +++ b/src/transformers/models/owlvit/image_processing_owlvit.py @@ -82,7 +82,7 @@ def _scale_boxes(boxes, target_sizes): elif isinstance(target_sizes, torch.Tensor): image_height, image_width = target_sizes.unbind(1) else: - raise ValueError("`target_sizes` must be a list, tuple or torch.Tensor") + raise TypeError("`target_sizes` must be a list, tuple or torch.Tensor") scale_factor = torch.stack([image_width, image_height, image_width, image_height], dim=1) scale_factor = scale_factor.unsqueeze(1).to(boxes.device) diff --git a/src/transformers/models/phi4_multimodal/processing_phi4_multimodal.py b/src/transformers/models/phi4_multimodal/processing_phi4_multimodal.py index b9a97391e9..58c6619ba1 100644 --- a/src/transformers/models/phi4_multimodal/processing_phi4_multimodal.py +++ b/src/transformers/models/phi4_multimodal/processing_phi4_multimodal.py @@ -128,7 +128,7 @@ class Phi4MultimodalProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") image_token = self.tokenizer.image_token audio_token = self.tokenizer.audio_token diff --git a/src/transformers/models/phimoe/configuration_phimoe.py b/src/transformers/models/phimoe/configuration_phimoe.py index 5fea626c30..80fefd3dc9 100644 --- a/src/transformers/models/phimoe/configuration_phimoe.py +++ b/src/transformers/models/phimoe/configuration_phimoe.py @@ -181,13 +181,11 @@ class PhimoeConfig(PretrainedConfig): rope_scaling_short_mscale = self.rope_scaling.get("short_mscale", None) rope_scaling_long_mscale = self.rope_scaling.get("long_mscale", None) if not isinstance(rope_scaling_short_mscale, (int, float)): - raise ValueError( + raise TypeError( f"`rope_scaling`'s short_mscale field must be a number, got {rope_scaling_short_mscale}" ) if not isinstance(rope_scaling_long_mscale, (int, float)): - raise ValueError( - f"`rope_scaling`'s long_mscale field must be a number, got {rope_scaling_long_mscale}" - ) + raise TypeError(f"`rope_scaling`'s long_mscale field must be a number, got {rope_scaling_long_mscale}") rope_config_validation(self) diff --git a/src/transformers/models/pixtral/processing_pixtral.py b/src/transformers/models/pixtral/processing_pixtral.py index 16ebaa0d55..b38c5917d7 100644 --- a/src/transformers/models/pixtral/processing_pixtral.py +++ b/src/transformers/models/pixtral/processing_pixtral.py @@ -188,7 +188,7 @@ class PixtralProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") # try to expand inputs in processing if we have the necessary parts prompt_strings = text diff --git a/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py b/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py index c9584dfe3a..8174f22af2 100644 --- a/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py +++ b/src/transformers/models/qwen2_5_omni/modeling_qwen2_5_omni.py @@ -3247,7 +3247,7 @@ class TorchActivation1d(nn.Module): ): super().__init__() if not callable(activation): - raise ValueError("Activation function must be callable") + raise TypeError("Activation function must be callable") self.act = activation self.upsample = UpSample1d(up_ratio, up_kernel_size) self.downsample = DownSample1d(down_ratio, down_kernel_size) diff --git a/src/transformers/models/qwen2_5_omni/modular_qwen2_5_omni.py b/src/transformers/models/qwen2_5_omni/modular_qwen2_5_omni.py index cfd0e29c97..5b501cf7f9 100644 --- a/src/transformers/models/qwen2_5_omni/modular_qwen2_5_omni.py +++ b/src/transformers/models/qwen2_5_omni/modular_qwen2_5_omni.py @@ -3533,7 +3533,7 @@ class TorchActivation1d(nn.Module): ): super().__init__() if not callable(activation): - raise ValueError("Activation function must be callable") + raise TypeError("Activation function must be callable") self.act = activation self.upsample = UpSample1d(up_ratio, up_kernel_size) self.downsample = DownSample1d(down_ratio, down_kernel_size) diff --git a/src/transformers/models/sam/image_processing_sam.py b/src/transformers/models/sam/image_processing_sam.py index c431bb72ca..7591da5af9 100644 --- a/src/transformers/models/sam/image_processing_sam.py +++ b/src/transformers/models/sam/image_processing_sam.py @@ -668,7 +668,7 @@ class SamImageProcessor(BaseImageProcessor): if isinstance(masks[i], np.ndarray): masks[i] = torch.from_numpy(masks[i]) elif not isinstance(masks[i], torch.Tensor): - raise ValueError("Input masks should be a list of `torch.tensors` or a list of `np.ndarray`") + raise TypeError("Input masks should be a list of `torch.tensors` or a list of `np.ndarray`") interpolated_mask = F.interpolate(masks[i], target_image_size, mode="bilinear", align_corners=False) interpolated_mask = interpolated_mask[..., : reshaped_input_sizes[i][0], : reshaped_input_sizes[i][1]] interpolated_mask = F.interpolate(interpolated_mask, original_size, mode="bilinear", align_corners=False) @@ -1119,7 +1119,7 @@ def _generate_crop_boxes( """ if isinstance(image, list): - raise ValueError("Only one image is allowed for crop generation.") + raise TypeError("Only one image is allowed for crop generation.") image = to_numpy_array(image) original_size = get_image_size(image, input_data_format) diff --git a/src/transformers/models/video_llava/processing_video_llava.py b/src/transformers/models/video_llava/processing_video_llava.py index d0b061892d..d7aababe6f 100644 --- a/src/transformers/models/video_llava/processing_video_llava.py +++ b/src/transformers/models/video_llava/processing_video_llava.py @@ -152,7 +152,7 @@ class VideoLlavaProcessor(ProcessorMixin): if isinstance(text, str): text = [text] elif not isinstance(text, list) and not isinstance(text[0], str): - raise ValueError("Invalid input text. Please provide a string, or a list of strings") + raise TypeError("Invalid input text. Please provide a string, or a list of strings") data = {} if images is not None: diff --git a/src/transformers/models/vitpose/image_processing_vitpose.py b/src/transformers/models/vitpose/image_processing_vitpose.py index 77cd0c92d7..32c048a8a9 100644 --- a/src/transformers/models/vitpose/image_processing_vitpose.py +++ b/src/transformers/models/vitpose/image_processing_vitpose.py @@ -133,7 +133,7 @@ def get_keypoint_predictions(heatmaps: np.ndarray) -> tuple[np.ndarray, np.ndarr Scores (confidence) of the keypoints. """ if not isinstance(heatmaps, np.ndarray): - raise ValueError("Heatmaps should be np.ndarray") + raise TypeError("Heatmaps should be np.ndarray") if heatmaps.ndim != 4: raise ValueError("Heatmaps should be 4-dimensional") diff --git a/src/transformers/pipelines/text2text_generation.py b/src/transformers/pipelines/text2text_generation.py index c9333b760d..8952b58208 100644 --- a/src/transformers/pipelines/text2text_generation.py +++ b/src/transformers/pipelines/text2text_generation.py @@ -150,7 +150,7 @@ class Text2TextGenerationPipeline(Pipeline): args = (prefix + args[0],) padding = False else: - raise ValueError( + raise TypeError( f" `args[0]`: {args[0]} have the wrong format. The should be either of type `str` or type `list`" ) inputs = self.tokenizer(*args, padding=padding, truncation=truncation, return_tensors=self.framework) diff --git a/src/transformers/quantizers/auto.py b/src/transformers/quantizers/auto.py index b332550b42..7cda893e3c 100644 --- a/src/transformers/quantizers/auto.py +++ b/src/transformers/quantizers/auto.py @@ -252,7 +252,7 @@ def register_quantization_config(method: str): raise ValueError(f"Config '{method}' already registered") if not issubclass(cls, QuantizationConfigMixin): - raise ValueError("Config must extend QuantizationConfigMixin") + raise TypeError("Config must extend QuantizationConfigMixin") AUTO_QUANTIZATION_CONFIG_MAPPING[method] = cls return cls diff --git a/src/transformers/quantizers/quantizer_bnb_8bit.py b/src/transformers/quantizers/quantizer_bnb_8bit.py index e1391426ec..e7d914170e 100644 --- a/src/transformers/quantizers/quantizer_bnb_8bit.py +++ b/src/transformers/quantizers/quantizer_bnb_8bit.py @@ -214,7 +214,7 @@ class Bnb8BitHfQuantizer(HfQuantizer): old_value = getattr(module, tensor_name) if not isinstance(module._parameters[tensor_name], bnb.nn.Int8Params): - raise ValueError(f"Parameter `{tensor_name}` should only be a `bnb.nn.Int8Params` instance.") + raise TypeError(f"Parameter `{tensor_name}` should only be a `bnb.nn.Int8Params` instance.") if ( old_value.device == torch.device("meta") and target_device not in ["meta", torch.device("meta")] diff --git a/src/transformers/tokenization_utils_base.py b/src/transformers/tokenization_utils_base.py index 200bf478ed..51bcc9a321 100644 --- a/src/transformers/tokenization_utils_base.py +++ b/src/transformers/tokenization_utils_base.py @@ -2184,7 +2184,7 @@ class PreTrainedTokenizerBase(SpecialTokensMixin, PushToHubMixin): added_tokens_decoder[int(idx)] = token added_tokens_map[str(token)] = token else: - raise ValueError( + raise TypeError( f"Found a {token.__class__} in the saved `added_tokens_decoder`, should be a dictionary or an AddedToken instance" ) else: diff --git a/src/transformers/trainer.py b/src/transformers/trainer.py index cd0cc7d7da..6dc2a11436 100755 --- a/src/transformers/trainer.py +++ b/src/transformers/trainer.py @@ -701,7 +701,7 @@ class Trainer: os.makedirs(self.args.output_dir, exist_ok=True) if not callable(self.data_collator) and callable(getattr(self.data_collator, "collate_batch", None)): - raise ValueError("The `data_collator` should be a simple callable (function, class with `__call__`).") + raise TypeError("The `data_collator` should be a simple callable (function, class with `__call__`).") if args.max_steps > 0 and args.num_train_epochs > 0: logger.info("max_steps is given, it will override any value given in num_train_epochs") @@ -1346,7 +1346,7 @@ class Trainer: raise ValueError(f"You need to define `optim_target_modules` to use {optimizer_name} optimizers") if not isinstance(args.optim_target_modules, (list, str)): - raise ValueError( + raise TypeError( f"`optim_target_modules` must be a list of strings, a regex string, or 'all-linear'. Got: {args.optim_target_modules}" ) diff --git a/src/transformers/utils/import_utils.py b/src/transformers/utils/import_utils.py index 93c4d971ac..f56182d2a5 100644 --- a/src/transformers/utils/import_utils.py +++ b/src/transformers/utils/import_utils.py @@ -2383,7 +2383,7 @@ def requires(*, backends=()): """ if not isinstance(backends, tuple): - raise ValueError("Backends should be a tuple.") + raise TypeError("Backends should be a tuple.") applied_backends = [] for backend in backends: diff --git a/src/transformers/utils/quantization_config.py b/src/transformers/utils/quantization_config.py index 70c0b034a5..d6f4dd4663 100644 --- a/src/transformers/utils/quantization_config.py +++ b/src/transformers/utils/quantization_config.py @@ -1649,7 +1649,7 @@ class TorchAoConfig(QuantizationConfigMixin): from torchao.quantization.quant_api import AOBaseConfig if not isinstance(self.quant_type, AOBaseConfig): - raise ValueError( + raise TypeError( f"quant_type must be either a string or an AOBaseConfig instance, got {type(self.quant_type)}" ) else: diff --git a/src/transformers/video_utils.py b/src/transformers/video_utils.py index 8282a25d08..6ac415eb35 100644 --- a/src/transformers/video_utils.py +++ b/src/transformers/video_utils.py @@ -629,7 +629,7 @@ def convert_to_rgb( The channel dimension format of the input video. If unset, will use the inferred format from the input. """ if not isinstance(video, np.ndarray): - raise ValueError(f"Video has to be a numpy array to convert to RGB format, but found {type(video)}") + raise TypeError(f"Video has to be a numpy array to convert to RGB format, but found {type(video)}") # np.array usually comes with ChannelDimension.LAST so leet's convert it if input_data_format is None: diff --git a/tests/models/clip/test_tokenization_clip.py b/tests/models/clip/test_tokenization_clip.py index fca53f07cd..f1bd8dd353 100644 --- a/tests/models/clip/test_tokenization_clip.py +++ b/tests/models/clip/test_tokenization_clip.py @@ -174,7 +174,7 @@ class CLIPTokenizationTest(TokenizerTesterMixin, unittest.TestCase): def test_log_warning(self): # Test related to the breaking change introduced in transformers v4.17.0 # We need to check that an error in raised when the user try to load a previous version of the tokenizer. - with self.assertRaises(ValueError) as context: + with self.assertRaises(TypeError) as context: self.get_rust_tokenizer("robot-test/old-clip-tokenizer") self.assertTrue( diff --git a/tests/models/grounding_dino/test_modeling_grounding_dino.py b/tests/models/grounding_dino/test_modeling_grounding_dino.py index 953255797b..8d94a42100 100644 --- a/tests/models/grounding_dino/test_modeling_grounding_dino.py +++ b/tests/models/grounding_dino/test_modeling_grounding_dino.py @@ -61,7 +61,7 @@ def generate_fake_bounding_boxes(n_boxes): """Generate bounding boxes in the format (center_x, center_y, width, height)""" # Validate the input if not isinstance(n_boxes, int): - raise ValueError("n_boxes must be an integer") + raise TypeError("n_boxes must be an integer") if n_boxes <= 0: raise ValueError("n_boxes must be a positive integer") diff --git a/tests/models/sam/test_processor_sam.py b/tests/models/sam/test_processor_sam.py index 15cd2b0297..852df56f99 100644 --- a/tests/models/sam/test_processor_sam.py +++ b/tests/models/sam/test_processor_sam.py @@ -154,7 +154,7 @@ class SamProcessorTest(ProcessorTesterMixin, unittest.TestCase): self.assertEqual(masks[0].shape, (1, 3, 1764, 2646)) dummy_masks = [[1, 0], [0, 1]] - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): masks = processor.post_process_masks(dummy_masks, np.array(original_sizes), np.array(reshaped_input_size)) def test_rle_encoding(self): diff --git a/tests/models/sam_hq/test_processor_samhq.py b/tests/models/sam_hq/test_processor_samhq.py index 9f24cc7ab4..89a642ba60 100644 --- a/tests/models/sam_hq/test_processor_samhq.py +++ b/tests/models/sam_hq/test_processor_samhq.py @@ -163,5 +163,5 @@ class SamHQProcessorTest(ProcessorTesterMixin, unittest.TestCase): self.assertEqual(masks[0].shape, (1, 3, 1764, 2646)) dummy_masks = [[1, 0], [0, 1]] - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): masks = processor.post_process_masks(dummy_masks, np.array(original_sizes), np.array(reshaped_input_size)) diff --git a/tests/pipelines/test_pipelines_text2text_generation.py b/tests/pipelines/test_pipelines_text2text_generation.py index 6a664e9aab..31a91ea848 100644 --- a/tests/pipelines/test_pipelines_text2text_generation.py +++ b/tests/pipelines/test_pipelines_text2text_generation.py @@ -81,7 +81,7 @@ class Text2TextGenerationPipelineTests(unittest.TestCase): ], ) - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): generator(4) @require_torch diff --git a/tests/test_image_transforms.py b/tests/test_image_transforms.py index c2f44120e2..313dc099f1 100644 --- a/tests/test_image_transforms.py +++ b/tests/test_image_transforms.py @@ -246,7 +246,7 @@ class ImageTransformsTester(unittest.TestCase): # Test that exception is raised if inputs are incorrect # Not a numpy array image - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): normalize(5, 5, 5) # Number of mean values != number of channels