



import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

    if is_vision_available():
        from transformers import MaskFormerImageProcessor

if is_vision_available():
    from PIL import Image
class  _A		:

  def __init__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE=2 ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=False ,					_SCREAMING_SNAKE_CASE=10 ,					_SCREAMING_SNAKE_CASE=3 ,					_SCREAMING_SNAKE_CASE=32 * 4 ,					_SCREAMING_SNAKE_CASE=32 * 6 ,					_SCREAMING_SNAKE_CASE=4 ,					_SCREAMING_SNAKE_CASE=32 ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     parent
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     batch_size
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     is_training
        SCREAMING_SNAKE_CASE_				:  List[str]           =     use_auxiliary_loss
        SCREAMING_SNAKE_CASE_				:  List[str]           =     num_queries
        SCREAMING_SNAKE_CASE_				:  Tuple           =     num_channels
        SCREAMING_SNAKE_CASE_				:  Any           =     min_size
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     max_size
        SCREAMING_SNAKE_CASE_				:  str           =     num_labels
        SCREAMING_SNAKE_CASE_				:  str           =     mask_feature_size

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]					).to(
            _A					)

        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     torch.ones([self.batch_size, self.min_size, self.max_size] ,					device=_A					)

        SCREAMING_SNAKE_CASE_				:  int           =     (
            torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size] ,					device=_A					) > 0.5
        ).float()
        SCREAMING_SNAKE_CASE_				:  Tuple           =     (torch.rand((self.batch_size, self.num_labels) ,					device=_A					) > 0.5).long()

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     self.get_config()
        return config, pixel_values, pixel_mask, mask_labels, class_labels

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return MaskFormerConfig.from_backbone_and_decoder_configs(
            backbone_config=SwinConfig(
                depths=[1, 1, 1, 1] ,					) ,					decoder_config=DetrConfig(
                decoder_ffn_dim=128 ,					num_queries=self.num_queries ,					decoder_attention_heads=2 ,					d_model=self.mask_feature_size ,					) ,					mask_feature_size=self.mask_feature_size ,					fpn_feature_size=self.mask_feature_size ,					num_channels=self.num_channels ,					num_labels=self.num_labels ,					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[Any]           =     self.prepare_config_and_inputs()
        SCREAMING_SNAKE_CASE_				:  Dict           =     {'pixel_values': pixel_values, 'pixel_mask': pixel_mask}
        return config, inputs_dict

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     output.encoder_hidden_states
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     output.pixel_decoder_hidden_states
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     output.transformer_decoder_hidden_states

        self.parent.assertTrue(len(_A					) ,					len(config.backbone_config.depths					)					)
        self.parent.assertTrue(len(_A					) ,					len(config.backbone_config.depths					)					)
        self.parent.assertTrue(len(_A					) ,					config.decoder_config.decoder_layers					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE=False					):





        """simple docstring"""







        with torch.no_grad():
              SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     MaskFormerModel(config=_A					)
              model.to(_A					)
              model.eval()

              SCREAMING_SNAKE_CASE_				:  int           =     model(pixel_values=_A ,					pixel_mask=_A					)
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     model(_A ,					output_hidden_states=_A					)
        # the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
        # encoder and pixel decoder
        self.parent.assertEqual(
            output.transformer_decoder_last_hidden_state.shape ,					(self.batch_size, self.num_queries, self.mask_feature_size) ,					)
        # let's ensure the other two hidden state exists
        self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None					)
        self.parent.assertTrue(output.encoder_last_hidden_state is not None					)

        if output_hidden_states:
              self.check_output_hidden_state(_A ,					_A					)



  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  int           =     MaskFormerForInstanceSegmentation(config=_A					)
        model.to(_A					)
        model.eval()

        def comm_check_on_output(_SCREAMING_SNAKE_CASE					):
              # let's still check that all the required stuff is there
              self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None					)
              self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None					)
              self.parent.assertTrue(result.encoder_last_hidden_state is not None					)
              # okay, now we need to check the logits shape
              # due to the encoder compression, masks have a //4 spatial size
              self.parent.assertEqual(
                  result.masks_queries_logits.shape ,					(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4) ,					)
              # + 1 for null class
              self.parent.assertEqual(
                  result.class_queries_logits.shape ,					(self.batch_size, self.num_queries, self.num_labels + 1)					)

        with torch.no_grad():
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     model(pixel_values=_A ,					pixel_mask=_A					)
              SCREAMING_SNAKE_CASE_				:  Dict           =     model(_A					)

              comm_check_on_output(_A					)

              SCREAMING_SNAKE_CASE_				:  List[Any]           =     model(
                  pixel_values=_A ,					pixel_mask=_A ,					mask_labels=_A ,					class_labels=_A					)

        comm_check_on_output(_A					)

        self.parent.assertTrue(result.loss is not None					)
        self.parent.assertEqual(result.loss.shape ,					torch.Size([1]					)					)

@require_torch
class  _A		(  snake_case__   ,     snake_case__   ,     unittest.TestCase):
  SCREAMING_SNAKE_CASE    :      Tuple       =  (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
  SCREAMING_SNAKE_CASE    :      Tuple       =  (
      {'''feature-extraction''': MaskFormerModel, '''image-segmentation''': MaskFormerForInstanceSegmentation}
      if is_torch_available()
      else {}
  )

  SCREAMING_SNAKE_CASE    :      List[Any]       =  False
  SCREAMING_SNAKE_CASE    :      int       =  False
  SCREAMING_SNAKE_CASE    :      Union[str, Any]       =  False
  SCREAMING_SNAKE_CASE    :      Any       =  False

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     MaskFormerModelTester(self					)
        SCREAMING_SNAKE_CASE_				:  str           =     ConfigTester(self ,					config_class=_A ,					has_text_modality=_A					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        self.config_tester.run_common_tests()

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     self.model_tester.prepare_config_and_inputs_for_common()
        self.model_tester.create_and_check_maskformer_model(_A ,					**_A ,					output_hidden_states=_A					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Dict           =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*_A					)

  @unittest.skip(reason='MaskFormer does not use inputs_embeds'					)
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        pass

  @unittest.skip(reason='MaskFormer does not have a get_input_embeddings method'					)
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        pass

  @unittest.skip(reason='MaskFormer is not a generative model'					)
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        pass

  @unittest.skip(reason='MaskFormer does not use token embeddings'					)
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        pass

  @require_torch_multi_gpu
  @unittest.skip(
      reason='MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'					)
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        pass

  @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'					)
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        pass

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
              SCREAMING_SNAKE_CASE_				:  Dict           =     model_class(_A					)
              SCREAMING_SNAKE_CASE_				:  str           =     inspect.signature(model.forward					)
              # signature.parameters is an OrderedDict => so arg_names order is deterministic
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     [*signature.parameters.keys()]

              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     ['pixel_values']
              self.assertListEqual(arg_names[:1] ,					_A					)

  @slow
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        for model_name in ["facebook/maskformer-swin-small-coco"]:
              SCREAMING_SNAKE_CASE_				:  int           =     MaskFormerModel.from_pretrained(_A					)
              self.assertIsNotNone(_A					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     (self.model_tester.min_size,) * 2
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     {
            'pixel_values': torch.randn((2, 3, *size) ,					device=_A					),
            'mask_labels': torch.randn((2, 10, *size) ,					device=_A					),
            'class_labels': torch.zeros(2 ,					10 ,					device=_A					).long(),
        }

        SCREAMING_SNAKE_CASE_				:  int           =     MaskFormerForInstanceSegmentation(MaskFormerConfig()					).to(_A					)
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     model(**_A					)
        self.assertTrue(outputs.loss is not None					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     self.model_tester.prepare_config_and_inputs_for_common()
        self.model_tester.create_and_check_maskformer_model(_A ,					**_A ,					output_hidden_states=_A					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
              SCREAMING_SNAKE_CASE_				:  int           =     model_class(_A					).to(_A					)
              SCREAMING_SNAKE_CASE_				:  Dict           =     model(**_A ,					output_attentions=_A					)
              self.assertTrue(outputs.attentions is not None					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        if not self.model_tester.is_training:
              return
        # only MaskFormerForInstanceSegmentation has the loss
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     self.all_model_classes[1]
        SCREAMING_SNAKE_CASE_				:  Tuple           =     self.model_tester.prepare_config_and_inputs()

        SCREAMING_SNAKE_CASE_				:  Tuple           =     model_class(_A					)
        model.to(_A					)
        model.train()

        SCREAMING_SNAKE_CASE_				:  Any           =     model(_A ,					mask_labels=_A ,					class_labels=_A					).loss
        loss.backward()



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     self.all_model_classes[1]
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     self.model_tester.prepare_config_and_inputs()
        SCREAMING_SNAKE_CASE_				:  str           =     True
        SCREAMING_SNAKE_CASE_				:  int           =     True

        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     model_class(_A					)
        model.to(_A					)
        model.train()

        SCREAMING_SNAKE_CASE_				:  str           =     model(_A ,					mask_labels=_A ,					class_labels=_A					)

        SCREAMING_SNAKE_CASE_				:  int           =     outputs.encoder_hidden_states[0]
        encoder_hidden_states.retain_grad()

        SCREAMING_SNAKE_CASE_				:  Dict           =     outputs.pixel_decoder_hidden_states[0]
        pixel_decoder_hidden_states.retain_grad()
        # we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
        SCREAMING_SNAKE_CASE_				:  List[str]           =     outputs.transformer_decoder_hidden_states[0]
        transformer_decoder_hidden_states.retain_grad()

        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     outputs.attentions[0]
        attentions.retain_grad()

        outputs.loss.backward(retain_graph=_A					)

        self.assertIsNotNone(encoder_hidden_states.grad					)
        self.assertIsNotNone(pixel_decoder_hidden_states.grad					)
        self.assertIsNotNone(transformer_decoder_hidden_states.grad					)
        self.assertIsNotNone(attentions.grad					)

lowerCAmelCase     :   Optional[Any]						     =  1e-4

def    A_  (							):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_				:  Dict           =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
      return image



@require_vision
@slow
class  _A		(  unittest.TestCase):

  @cached_property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return (
            MaskFormerImageProcessor.from_pretrained('facebook/maskformer-swin-small-coco'					)
            if is_vision_available()
            else None
        )

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  int           =     MaskFormerModel.from_pretrained('facebook/maskformer-swin-small-coco'					).to(_A					)
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     self.default_image_processor
        SCREAMING_SNAKE_CASE_				:  List[str]           =     prepare_img()
        SCREAMING_SNAKE_CASE_				:  Any           =     image_processor(_A ,					return_tensors='pt'					).to(_A					)
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     inputs['pixel_values'].shape
        # check size is divisible by 32
        self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0					)
        # check size
        self.assertEqual(_A ,					(1, 3, 800, 1088)					)

        with torch.no_grad():
              SCREAMING_SNAKE_CASE_				:  Dict           =     model(**_A					)

        SCREAMING_SNAKE_CASE_				:  List[Any]           =     torch.tensor(
            [[-0.0482, 0.9228, 0.4951], [-0.2547, 0.8017, 0.8527], [-0.0069, 0.3385, -0.0089]]					).to(_A					)
        self.assertTrue(
            torch.allclose(
                outputs.encoder_last_hidden_state[0, 0, :3, :3] ,					_A ,					atol=_A					)					)

        SCREAMING_SNAKE_CASE_				:  Any           =     torch.tensor(
            [[-0.8422, -0.8434, -0.9718], [-1.0144, -0.5565, -0.4195], [-1.0038, -0.4484, -0.1961]]					).to(_A					)
        self.assertTrue(
            torch.allclose(
                outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3] ,					_A ,					atol=_A					)					)

        SCREAMING_SNAKE_CASE_				:  Tuple           =     torch.tensor(
            [[0.2852, -0.0159, 0.9735], [0.6254, 0.1858, 0.8529], [-0.0680, -0.4116, 1.8413]]					).to(_A					)
        self.assertTrue(
            torch.allclose(
                outputs.transformer_decoder_last_hidden_state[0, :3, :3] ,					_A ,					atol=_A					)					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Tuple           =     (
            MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-swin-small-coco'					)
            .to(_A					)
            .eval()
        )
        SCREAMING_SNAKE_CASE_				:  List[str]           =     self.default_image_processor
        SCREAMING_SNAKE_CASE_				:  int           =     prepare_img()
        SCREAMING_SNAKE_CASE_				:  str           =     image_processor(_A ,					return_tensors='pt'					).to(_A					)
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     inputs['pixel_values'].shape
        # check size is divisible by 32
        self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0					)
        # check size
        self.assertEqual(_A ,					(1, 3, 800, 1088)					)

        with torch.no_grad():
              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     model(**_A					)
        # masks_queries_logits
        SCREAMING_SNAKE_CASE_				:  Tuple           =     outputs.masks_queries_logits
        self.assertEqual(
            masks_queries_logits.shape ,					(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4) ,					)
        SCREAMING_SNAKE_CASE_				:  int           =     [
            [-1.3737124, -1.7724937, -1.9364233],
            [-1.5977281, -1.9867939, -2.1523695],
            [-1.5795398, -1.9269832, -2.093942],
        ]
        SCREAMING_SNAKE_CASE_				:  Dict           =     torch.tensor(_A					).to(_A					)
        self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3] ,					_A ,					atol=_A					)					)
        # class_queries_logits
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     outputs.class_queries_logits
        self.assertEqual(
            class_queries_logits.shape ,					(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)					)
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     torch.tensor(
            [
                [1.6_512e00, -5.2_572e00, -3.3_519e00],
                [3.6_169e-02, -5.9_025e00, -2.9_313e00],
                [1.0_766e-04, -7.7_630e00, -5.1_263e00],
            ]					).to(_A					)
        self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3] ,					_A ,					atol=_A					)					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     (
            MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-resnet101-coco-stuff'					)
            .to(_A					)
            .eval()
        )
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     self.default_image_processor
        SCREAMING_SNAKE_CASE_				:  Any           =     prepare_img()
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     image_processor(_A ,					return_tensors='pt'					).to(_A					)
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     inputs['pixel_values'].shape
        # check size is divisible by 32
        self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0					)
        # check size
        self.assertEqual(_A ,					(1, 3, 800, 1088)					)

        with torch.no_grad():
              SCREAMING_SNAKE_CASE_				:  int           =     model(**_A					)
        # masks_queries_logits
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     outputs.masks_queries_logits
        self.assertEqual(
            masks_queries_logits.shape ,					(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4) ,					)
        SCREAMING_SNAKE_CASE_				:  Any           =     [[-0.9046, -2.6366, -4.6062], [-3.4179, -5.7890, -8.8057], [-4.9179, -7.6560, -10.7711]]
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     torch.tensor(_A					).to(_A					)
        self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3] ,					_A ,					atol=_A					)					)
        # class_queries_logits
        SCREAMING_SNAKE_CASE_				:  Any           =     outputs.class_queries_logits
        self.assertEqual(
            class_queries_logits.shape ,					(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)					)
        SCREAMING_SNAKE_CASE_				:  List[str]           =     torch.tensor(
            [[4.7188, -3.2585, -2.8857], [6.6871, -2.9181, -1.2487], [7.2449, -2.2764, -2.1874]]					).to(_A					)
        self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3] ,					_A ,					atol=_A					)					)



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     (
            MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-swin-small-coco'					)
            .to(_A					)
            .eval()
        )
        SCREAMING_SNAKE_CASE_				:  Any           =     self.default_image_processor

        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     image_processor(
            [np.zeros((3, 800, 1333)					), np.zeros((3, 800, 1333)					)] ,					segmentation_maps=[np.zeros((384, 384)					).astype(np.floataa					), np.zeros((384, 384)					).astype(np.floataa					)] ,					return_tensors='pt' ,					)

        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     inputs['pixel_values'].to(_A					)
        SCREAMING_SNAKE_CASE_				:  Any           =     [el.to(_A					) for el in inputs['mask_labels']]
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     [el.to(_A					) for el in inputs['class_labels']]

        with torch.no_grad():
              SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     model(**_A					)

        self.assertTrue(outputs.loss is not None					)









import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, Features, Value
from .base import TaskTemplate
@dataclass(frozen=__magic_name__)
class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      str       =  field(default='''automatic-speech-recognition'''   ,     metadata={'''include_in_asdict_even_if_is_default''': True})
  SCREAMING_SNAKE_CASE    :      ClassVar[Features]       =  Features({'''audio''': Audio()})
  SCREAMING_SNAKE_CASE    :      ClassVar[Features]       =  Features({'''transcription''': Value('''string''')})
  SCREAMING_SNAKE_CASE    :      str       =  "audio"
  SCREAMING_SNAKE_CASE    :      str       =  "transcription"

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        if self.audio_column not in features:
              raise ValueError(f"Column {self.audio_column} is not present in features."					)
        if not isinstance(features[self.audio_column] ,					_SCREAMING_SNAKE_CASE					):
              raise ValueError(f"Column {self.audio_column} is not an Audio type."					)
        SCREAMING_SNAKE_CASE_				:  int           =     copy.deepcopy(self					)
        SCREAMING_SNAKE_CASE_				:  int           =     self.input_schema.copy()
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     features[self.audio_column]
        SCREAMING_SNAKE_CASE_				:  List[str]           =     input_schema
        return task_template



  @property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return {self.audio_column: "audio", self.transcription_column: "transcription"}






