Skip to content

Commit ccf2403

Browse files
authored
Standardise processing requires (#50042)
* remove redundant requires * cleanup more requires * more cleanup * even more * and more
1 parent 0460c6d commit ccf2403

57 files changed

Lines changed: 55 additions & 161 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/transformers/models/chmv2/image_processing_chmv2.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from ...image_utils import ChannelDimension, ImageInput, PILImageResampling, SizeDict
3434
from ...modeling_outputs import DepthEstimatorOutput
3535
from ...processing_utils import ImagesKwargs, Unpack
36-
from ...utils import TensorType, auto_docstring, is_torch_available, requires_backends
36+
from ...utils import TensorType, auto_docstring, is_torch_available
3737

3838

3939
class CHMv2ImageProcessorKwargs(ImagesKwargs, total=False):
@@ -402,7 +402,6 @@ def post_process_depth_estimation(
402402
`List[Dict[str, TensorType]]`: A list of dictionaries of tensors representing the processed depth
403403
predictions.
404404
"""
405-
requires_backends(self, "torch")
406405

407406
predicted_depth = outputs.predicted_depth
408407

‎src/transformers/models/chmv2/modular_chmv2.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ...modeling_outputs import DepthEstimatorOutput
2626
from ...modeling_utils import PreTrainedModel
2727
from ...processing_utils import ImagesKwargs, Unpack
28-
from ...utils import TensorType, TransformersKwargs, auto_docstring, can_return_tuple, requires_backends
28+
from ...utils import TensorType, TransformersKwargs, auto_docstring, can_return_tuple
2929
from ..auto import AutoConfig
3030
from ..depth_anything.modeling_depth_anything import (
3131
DepthAnythingPreActResidualLayer,
@@ -166,7 +166,6 @@ def post_process_depth_estimation(
166166
`List[Dict[str, TensorType]]`: A list of dictionaries of tensors representing the processed depth
167167
predictions.
168168
"""
169-
requires_backends(self, "torch")
170169

171170
predicted_depth = outputs.predicted_depth
172171

‎src/transformers/models/conditional_detr/image_processing_pil_conditional_detr.py‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
validate_annotations,
5151
)
5252
from ...processing_utils import ImagesKwargs, Unpack
53-
from ...utils import TensorType, auto_docstring, is_torch_available, is_vision_available, logging, requires_backends
53+
from ...utils import TensorType, auto_docstring, is_torch_available, is_vision_available, logging
5454
from ...utils.import_utils import requires
5555

5656

@@ -862,7 +862,6 @@ def post_process_object_detection(
862862
`list[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
863863
in the batch as predicted by the model.
864864
"""
865-
requires_backends(self, ["torch"])
866865
out_logits, out_bbox = outputs.logits, outputs.pred_boxes
867866

868867
if target_sizes is not None:
@@ -929,7 +928,6 @@ def post_process_semantic_segmentation(
929928
`(height, width)`) and `segmentation_scores` (shape `(num_classes, height, width)`). In both cases,
930929
`(height, width)` corresponds to the target size (if `target_sizes` is specified).
931930
"""
932-
requires_backends(self, ["torch"])
933931
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes]
934932
masks_queries_logits = outputs.pred_masks # [batch_size, num_queries, height, width]
935933

@@ -1012,11 +1010,6 @@ def post_process_instance_segmentation(
10121010
- **label_id** -- An integer representing the label / semantic class id corresponding to `segment_id`.
10131011
- **score** -- Prediction score of segment with `segment_id`.
10141012
"""
1015-
if not is_torch_available():
1016-
raise ImportError("PyTorch is required for post-processing.")
1017-
import torch
1018-
from torch import nn
1019-
10201013
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1]
10211014
masks_queries_logits = outputs.pred_masks # [batch_size, num_queries, height, width]
10221015

@@ -1110,11 +1103,6 @@ def post_process_panoptic_segmentation(
11101103
logger.warning_once("`label_ids_to_fuse` unset. No instance will be fused.")
11111104
label_ids_to_fuse = set()
11121105

1113-
if not is_torch_available():
1114-
raise ImportError("PyTorch is required for post-processing.")
1115-
import torch
1116-
from torch import nn
1117-
11181106
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1]
11191107
masks_queries_logits = outputs.pred_masks # [batch_size, num_queries, height, width]
11201108

‎src/transformers/models/conditional_detr/modular_conditional_detr.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
TransformersKwargs,
3333
auto_docstring,
3434
logging,
35-
requires_backends,
3635
)
3736
from ...utils.generic import can_return_tuple, merge_with_config_defaults
3837
from ...utils.import_utils import requires
@@ -258,7 +257,6 @@ def post_process_object_detection(
258257
`list[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
259258
in the batch as predicted by the model.
260259
"""
261-
requires_backends(self, ["torch"])
262260
out_logits, out_bbox = outputs.logits, outputs.pred_boxes
263261

264262
if target_sizes is not None:
@@ -325,7 +323,6 @@ def post_process_semantic_segmentation(
325323
`(height, width)`) and `segmentation_scores` (shape `(num_classes, height, width)`). In both cases,
326324
`(height, width)` corresponds to the target size (if `target_sizes` is specified).
327325
"""
328-
requires_backends(self, ["torch"])
329326
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes]
330327
masks_queries_logits = outputs.pred_masks # [batch_size, num_queries, height, width]
331328

‎src/transformers/models/deepseek_ocr2/image_processing_pil_deepseek_ocr2.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
)
3838
from ...processing_utils import ImagesKwargs, Unpack
3939
from ...utils import TensorType, auto_docstring
40-
from ...utils.import_utils import requires
4140

4241

4342
class DeepseekOcr2ImageProcessorKwargs(ImagesKwargs, total=False):
@@ -139,7 +138,6 @@ def get_optimal_tiled_canvas(
139138
return best_grid
140139

141140

142-
@requires(backends=("vision",))
143141
@auto_docstring
144142
class DeepseekOcr2ImageProcessorPil(PilBackend):
145143
valid_kwargs = DeepseekOcr2ImageProcessorKwargs

‎src/transformers/models/deepseek_ocr2/modular_deepseek_ocr2.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
from ...processing_utils import Unpack
4242
from ...utils import TensorType, TransformersKwargs, auto_docstring, can_return_tuple, logging
4343
from ...utils.generic import merge_with_config_defaults
44-
from ...utils.import_utils import requires
4544
from ...utils.output_capturing import capture_outputs
4645
from ..deepseek_v2.configuration_deepseek_v2 import DeepseekV2Config
4746
from ..deepseek_v2.modeling_deepseek_v2 import (
@@ -317,7 +316,6 @@ def get_number_of_image_patches(self, height: int, width: int, images_kwargs: di
317316
return num_patches
318317

319318

320-
@requires(backends=("vision",))
321319
@auto_docstring
322320
class DeepseekOcr2ImageProcessorPil(GotOcr2ImageProcessorPil):
323321
image_mean = IMAGENET_STANDARD_MEAN

‎src/transformers/models/deformable_detr/image_processing_pil_deformable_detr.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
)
5050
from ...processing_utils import ImagesKwargs, Unpack
5151
from ...utils import TensorType, auto_docstring, is_torch_available, is_vision_available
52-
from ...utils.import_utils import requires, requires_backends
52+
from ...utils.import_utils import requires
5353

5454

5555
if is_vision_available():
@@ -696,7 +696,6 @@ def post_process_object_detection(
696696
`list[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
697697
in the batch as predicted by the model.
698698
"""
699-
requires_backends(self, ["torch"])
700699
out_logits, out_bbox = outputs.logits, outputs.pred_boxes
701700

702701
if target_sizes is not None:

‎src/transformers/models/deformable_detr/modular_deformable_detr.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
torch_compilable_check,
3838
)
3939
from ...utils.generic import can_return_tuple, merge_with_config_defaults
40-
from ...utils.import_utils import requires, requires_backends
40+
from ...utils.import_utils import requires
4141
from ...utils.output_capturing import OutputRecorder, capture_outputs
4242
from ..detr.image_processing_detr import DetrImageProcessor
4343
from ..detr.image_processing_pil_detr import DetrImageProcessorPil
@@ -155,7 +155,6 @@ def post_process_object_detection(
155155
`list[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
156156
in the batch as predicted by the model.
157157
"""
158-
requires_backends(self, ["torch"])
159158
out_logits, out_bbox = outputs.logits, outputs.pred_boxes
160159

161160
if target_sizes is not None:

‎src/transformers/models/depth_pro/image_processing_depth_pro.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
TensorType,
3333
auto_docstring,
3434
logging,
35-
requires_backends,
3635
)
3736

3837

@@ -88,7 +87,6 @@ def post_process_depth_estimation(
8887
target_sizes: TensorType | list[tuple[int, int]] | None = None,
8988
) -> list[dict[str, TensorType]]:
9089
"""Post-processes the raw depth predictions from the model."""
91-
requires_backends(self, "torch")
9290
predicted_depth = outputs.predicted_depth
9391
fov = outputs.field_of_view
9492
batch_size = len(predicted_depth)

‎src/transformers/models/detr/image_processing_pil_detr.py‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
if is_torch_available():
5959
import torch
60+
from torch import nn
6061

6162
if is_vision_available():
6263
import PIL.Image
@@ -861,11 +862,6 @@ def post_process_object_detection(
861862
`list[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
862863
in the batch as predicted by the model.
863864
"""
864-
if not is_torch_available():
865-
raise ImportError("PyTorch is required for post-processing.")
866-
import torch
867-
from torch import nn
868-
869865
out_logits, out_bbox = outputs.logits, outputs.pred_boxes
870866

871867
if target_sizes is not None:
@@ -929,11 +925,6 @@ def post_process_semantic_segmentation(
929925
`(height, width)`) and `segmentation_scores` (shape `(num_classes, height, width)`). In both cases,
930926
`(height, width)` corresponds to the target size (if `target_sizes` is specified).
931927
"""
932-
if not is_torch_available():
933-
raise ImportError("PyTorch is required for post-processing.")
934-
import torch
935-
from torch import nn
936-
937928
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1]
938929
masks_queries_logits = outputs.pred_masks # [batch_size, num_queries, height, width]
939930

@@ -1016,11 +1007,6 @@ def post_process_instance_segmentation(
10161007
- **label_id** -- An integer representing the label / semantic class id corresponding to `segment_id`.
10171008
- **score** -- Prediction score of segment with `segment_id`.
10181009
"""
1019-
if not is_torch_available():
1020-
raise ImportError("PyTorch is required for post-processing.")
1021-
import torch
1022-
from torch import nn
1023-
10241010
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1]
10251011
masks_queries_logits = outputs.pred_masks # [batch_size, num_queries, height, width]
10261012

@@ -1114,11 +1100,6 @@ def post_process_panoptic_segmentation(
11141100
logger.warning_once("`label_ids_to_fuse` unset. No instance will be fused.")
11151101
label_ids_to_fuse = set()
11161102

1117-
if not is_torch_available():
1118-
raise ImportError("PyTorch is required for post-processing.")
1119-
import torch
1120-
from torch import nn
1121-
11221103
class_queries_logits = outputs.logits # [batch_size, num_queries, num_classes+1]
11231104
masks_queries_logits = outputs.pred_masks # [batch_size, num_queries, height, width]
11241105

0 commit comments

Comments
 (0)