Repository: huggingface/transformers
Pull request #35405 (2024-12-23 22:26:56)

Reuse "if not" logic in image_processing.
# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker
- vision models: @amyeroberts, @qubvel
- speech models: @ylacombe, @eustlb
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


zhanluxianshen: unexpected, ci error.

Patch:
diff --git a/src/transformers/agents/agent_types.py b/src/transformers/agents/agent_types.py
index f5be746265..75973777b9 100644
--- a/src/transformers/agents/agent_types.py
+++ b/src/transformers/agents/agent_types.py
@@ -19,7 +19,7 @@ import uuid
 
 import numpy as np
 
-from ..utils import is_soundfile_availble, is_torch_available, is_vision_available, logging
+from ..utils import is_soundfile_available, is_torch_available, is_vision_available, logging
 
 
 logger = logging.get_logger(__name__)
@@ -36,7 +36,7 @@ if is_torch_available():
 else:
     Tensor = object
 
-if is_soundfile_availble():
+if is_soundfile_available():
     import soundfile as sf
 
 
@@ -179,7 +179,7 @@ class AgentAudio(AgentType, str):
     def __init__(self, value, samplerate=16_000):
         super().__init__(value)
 
-        if not is_soundfile_availble():
+        if not is_soundfile_available():
             raise ImportError("soundfile must be installed in order to handle audio.")
 
         self._path = None
diff --git a/src/transformers/file_utils.py b/src/transformers/file_utils.py
index 2d9477727e..c13d506a61 100644
--- a/src/transformers/file_utils.py
+++ b/src/transformers/file_utils.py
@@ -105,7 +105,7 @@ from .utils import (
     is_sentencepiece_available,
     is_seqio_available,
     is_sklearn_available,
-    is_soundfile_availble,
+    is_soundfile_available,
     is_spacy_available,
     is_speech_available,
     is_tensor,
diff --git a/src/transformers/image_processing_base.py b/src/transformers/image_processing_base.py
index c5af652dec..a6ce7af3fa 100644
--- a/src/transformers/image_processing_base.py
+++ b/src/transformers/image_processing_base.py
@@ -381,8 +381,6 @@ class ImageProcessingMixin(PushToHubMixin):
             logger.info(
                 f"loading configuration file {image_processor_file} from cache at {resolved_image_processor_file}"
             )
-
-        if not is_local:
             if "auto_map" in image_processor_dict:
                 image_processor_dict["auto_map"] = add_model_info_to_auto_map(
                     image_processor_dict["auto_map"], pretrained_model_name_or_path
@@ -391,6 +389,7 @@ class ImageProcessingMixin(PushToHubMixin):
                 image_processor_dict["custom_pipelines"] = add_model_info_to_custom_pipelines(
                     image_processor_dict["custom_pipelines"], pretrained_model_name_or_path
                 )
+
         return image_processor_dict, kwargs
 
     @classmethod
diff --git a/src/transformers/utils/__init__.py b/src/transformers/utils/__init__.py
index 74b6d39fda..641899eb27 100755
--- a/src/transformers/utils/__init__.py
+++ b/src/transformers/utils/__init__.py
@@ -189,7 +189,7 @@ from .import_utils import (
     is_sentencepiece_available,
     is_seqio_available,
     is_sklearn_available,
-    is_soundfile_availble,
+    is_soundfile_available,
     is_spacy_available,
     is_speech_available,
     is_sudachi_available,
diff --git a/src/transformers/utils/import_utils.py b/src/transformers/utils/import_utils.py
index f880535dd6..5d18c5568a 100755
--- a/src/transformers/utils/import_utils.py
+++ b/src/transformers/utils/import_utils.py
@@ -1159,7 +1159,7 @@ def is_training_run_on_sagemaker():
     return "SAGEMAKER_JOB_NAME" in os.environ
 
 
-def is_soundfile_availble():
+def is_soundfile_available():
     return _soundfile_available
 
 


Test patch:
diff --git a/src/transformers/testing_utils.py b/src/transformers/testing_utils.py
index 00a7ee5966..6890a53688 100644
--- a/src/transformers/testing_utils.py
+++ b/src/transformers/testing_utils.py
@@ -116,7 +116,7 @@ from .utils import (
     is_scipy_available,
     is_sentencepiece_available,
     is_seqio_available,
-    is_soundfile_availble,
+    is_soundfile_available,
     is_spacy_available,
     is_sudachi_available,
     is_sudachi_projection_available,
@@ -1122,7 +1122,7 @@ def require_soundfile(test_case):
     These tests are skipped when soundfile isn't installed.
 
     """
-    return unittest.skipUnless(is_soundfile_availble(), "test requires soundfile")(test_case)
+    return unittest.skipUnless(is_soundfile_available(), "test requires soundfile")(test_case)
 
 
 def require_deepspeed(test_case):
diff --git a/tests/agents/test_agent_types.py b/tests/agents/test_agent_types.py
index 168ab1bbc9..5b54c83d0a 100644
--- a/tests/agents/test_agent_types.py
+++ b/tests/agents/test_agent_types.py
@@ -20,13 +20,13 @@ from pathlib import Path
 
 from transformers.agents.agent_types import AgentAudio, AgentImage, AgentText
 from transformers.testing_utils import get_tests_dir, require_soundfile, require_torch, require_vision
-from transformers.utils import is_soundfile_availble, is_torch_available, is_vision_available
+from transformers.utils import is_soundfile_available, is_torch_available, is_vision_available
 
 
 if is_torch_available():
     import torch
 
-if is_soundfile_availble():
+if is_soundfile_available():
     import soundfile as sf
 
 if is_vision_available():
diff --git a/tests/test_modeling_common.py b/tests/test_modeling_common.py
index 929bbb13a5..708a3a54e3 100755
--- a/tests/test_modeling_common.py
+++ b/tests/test_modeling_common.py
@@ -4255,7 +4255,7 @@ class ModelTesterMixin:
                     if isinstance(inp, torch.Tensor) and inp.dtype in [torch.float32, torch.float16]:
                         inputs_dict[name] = inp.to(torch.float16)
 
-                with torch.backends.cuda.sdp_kernel(enable_flash=True, enable_math=False, enable_mem_efficient=False):
+                with sdpa_kernel(enable_flash=True, enable_math=False, enable_mem_efficient=False):
                     _ = model(**inputs_dict)
 
     @require_non_xpu
@@ -4347,11 +4347,7 @@ class ModelTesterMixin:
                 model_sdpa = model_sdpa.eval()
 
                 with torch.no_grad():
-                    with torch.backends.cuda.sdp_kernel(
-                        enable_flash=False,
-                        enable_math=True,
-                        enable_mem_efficient=False,
-                    ):
+                    with sdpa_kernel(enable_flash=False, enable_math=True, enable_mem_efficient=False):
                         res_eager = model_eager(**inputs_dict, return_dict=False)[0]
                         res_sdpa = model_sdpa(**inputs_dict, return_dict=False)[0]