




from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


UpperCAmelCase_									=	logging.get_logger(__name__)

# General docstring
UpperCAmelCase_									=	'RegNetConfig'

# Base docstring
UpperCAmelCase_									=	'facebook/regnet-y-040'
UpperCAmelCase_									=	[1, 1_088, 7, 7]

# Image classification docstring
UpperCAmelCase_									=	'facebook/regnet-y-040'
UpperCAmelCase_									=	'tabby, tabby cat'

UpperCAmelCase_									=	[
    'facebook/regnet-y-040',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]





class     lowerCamelCase__(					tf.keras.layers.Layer):
      def __init__(				self: Optional[Any]    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int = 3    ,       UpperCamelCase_: int = 1    ,       UpperCamelCase_: int = 1    ,       UpperCamelCase_: Optional[str] = "relu"    ,       **UpperCamelCase_: List[str]    ,       ):
             super().__init__(**UpperCamelCase_   )
             # The padding and conv has been verified in
             # https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
             __lowerCamelCase   =						tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2   )
             __lowerCamelCase   =						tf.keras.layers.ConvaD(
                 filters=UpperCamelCase_    ,       kernel_size=UpperCamelCase_    ,       strides=UpperCamelCase_    ,       padding="""VALID"""    ,       groups=UpperCamelCase_    ,       use_bias=UpperCamelCase_    ,       name="""convolution"""    ,       )
             __lowerCamelCase   =						tf.keras.layers.BatchNormalization(epsilon=1E-5    ,       momentum=0.9    ,       name="""normalization"""   )
             __lowerCamelCase   =						ACTaFN[activation] if activation is not None else tf.identity




      def 			lowerCAmelCase__						(				self: str    ,       UpperCamelCase_: Union[str, Any]   ):
             __lowerCamelCase   =						self.convolution(self.padding(UpperCamelCase_   )   )
             __lowerCamelCase   =						self.normalization(UpperCamelCase_   )
             __lowerCamelCase   =						self.activation(UpperCamelCase_   )
             return hidden_state





class     lowerCamelCase__(					tf.keras.layers.Layer):
      def __init__(				self: Union[str, Any]    ,       UpperCamelCase_: RegNetConfig    ,       **UpperCamelCase_: Tuple   ):
             super().__init__(**UpperCamelCase_   )
             __lowerCamelCase   =						config.num_channels
             __lowerCamelCase   =						TFRegNetConvLayer(
                 out_channels=config.embedding_size    ,       kernel_size=3    ,       stride=2    ,       activation=config.hidden_act    ,       name="""embedder"""    ,       )




      def 			lowerCAmelCase__						(				self: Optional[int]    ,       UpperCamelCase_: Any   ):
             __lowerCamelCase   =						shape_list(UpperCamelCase_   )[1]
             if tf.executing_eagerly() and num_channels != self.num_channels:
                    raise ValueError(
                        """Make sure that the channel dimension of the pixel values match with the one set in the configuration."""   )

             # When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
             # So change the input format from `NCHW` to `NHWC`.
             # shape = (batch_size, in_height, in_width, in_channels=num_channels)
             __lowerCamelCase   =						tf.transpose(UpperCamelCase_    ,       perm=(0, 2, 3, 1)   )
             __lowerCamelCase   =						self.embedder(UpperCamelCase_   )
             return hidden_state





class     lowerCamelCase__(					tf.keras.layers.Layer):
      def __init__(				self: Optional[Any]    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int = 2    ,       **UpperCamelCase_: List[Any]   ):
             super().__init__(**UpperCamelCase_   )
             __lowerCamelCase   =						tf.keras.layers.ConvaD(
                 filters=UpperCamelCase_    ,       kernel_size=1    ,       strides=UpperCamelCase_    ,       use_bias=UpperCamelCase_    ,       name="""convolution"""   )
             __lowerCamelCase   =						tf.keras.layers.BatchNormalization(epsilon=1E-5    ,       momentum=0.9    ,       name="""normalization"""   )




      def 			lowerCAmelCase__						(				self: Optional[int]    ,       UpperCamelCase_: tf.Tensor    ,       UpperCamelCase_: bool = False   ):
             return self.normalization(self.convolution(UpperCamelCase_   )    ,       training=UpperCamelCase_   )





class     lowerCamelCase__(					tf.keras.layers.Layer):
      def __init__(				self: str    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int    ,       **UpperCamelCase_: str   ):
             super().__init__(**UpperCamelCase_   )
             __lowerCamelCase   =						tf.keras.layers.GlobalAveragePoolingaD(keepdims=UpperCamelCase_    ,       name="""pooler"""   )
             __lowerCamelCase   =						[
                 tf.keras.layers.ConvaD(filters=UpperCamelCase_    ,       kernel_size=1    ,       activation="""relu"""    ,       name="""attention.0"""   ),
                 tf.keras.layers.ConvaD(filters=UpperCamelCase_    ,       kernel_size=1    ,       activation="""sigmoid"""    ,       name="""attention.2"""   ),
             ]




      def 			lowerCAmelCase__						(				self: List[Any]    ,       UpperCamelCase_: str   ):
             # [batch_size, h, w, num_channels] -> [batch_size, 1, 1, num_channels]
             __lowerCamelCase   =						self.pooler(UpperCamelCase_   )
             for layer_module in self.attention:
                    __lowerCamelCase   =						layer_module(UpperCamelCase_   )
             __lowerCamelCase   =						hidden_state * pooled
             return hidden_state





class     lowerCamelCase__(					tf.keras.layers.Layer):
      def __init__(				self: Union[str, Any]    ,       UpperCamelCase_: RegNetConfig    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int = 1    ,       **UpperCamelCase_: Any   ):
             super().__init__(**UpperCamelCase_   )
             __lowerCamelCase   =						in_channels != out_channels or stride != 1
             __lowerCamelCase   =						max(1    ,       out_channels // config.groups_width   )
             __lowerCamelCase   =						(
                 TFRegNetShortCut(UpperCamelCase_    ,       stride=UpperCamelCase_    ,       name="""shortcut"""   )
                 if should_apply_shortcut
                 else tf.keras.layers.Activation("""linear"""    ,       name="""shortcut"""   )
             )
             # `self.layers` instead of `self.layer` because that is a reserved argument.
             __lowerCamelCase   =						[
                 TFRegNetConvLayer(UpperCamelCase_    ,       kernel_size=1    ,       activation=config.hidden_act    ,       name="""layer.0"""   ),
                 TFRegNetConvLayer(
                     UpperCamelCase_    ,       stride=UpperCamelCase_    ,       groups=UpperCamelCase_    ,       activation=config.hidden_act    ,       name="""layer.1"""   ),
                 TFRegNetConvLayer(UpperCamelCase_    ,       kernel_size=1    ,       activation=UpperCamelCase_    ,       name="""layer.2"""   ),
             ]
             __lowerCamelCase   =						ACTaFN[config.hidden_act]




      def 			lowerCAmelCase__						(				self: str    ,       UpperCamelCase_: Union[str, Any]   ):
             __lowerCamelCase   =						hidden_state
             for layer_module in self.layers:
                    __lowerCamelCase   =						layer_module(UpperCamelCase_   )
             __lowerCamelCase   =						self.shortcut(UpperCamelCase_   )
             hidden_state += residual
             __lowerCamelCase   =						self.activation(UpperCamelCase_   )
             return hidden_state





class     lowerCamelCase__(					tf.keras.layers.Layer):
      def __init__(				self: Any    ,       UpperCamelCase_: RegNetConfig    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int = 1    ,       **UpperCamelCase_: int   ):
             super().__init__(**UpperCamelCase_   )
             __lowerCamelCase   =						in_channels != out_channels or stride != 1
             __lowerCamelCase   =						max(1    ,       out_channels // config.groups_width   )
             __lowerCamelCase   =						(
                 TFRegNetShortCut(UpperCamelCase_    ,       stride=UpperCamelCase_    ,       name="""shortcut"""   )
                 if should_apply_shortcut
                 else tf.keras.layers.Activation("""linear"""    ,       name="""shortcut"""   )
             )
             __lowerCamelCase   =						[
                 TFRegNetConvLayer(UpperCamelCase_    ,       kernel_size=1    ,       activation=config.hidden_act    ,       name="""layer.0"""   ),
                 TFRegNetConvLayer(
                     UpperCamelCase_    ,       stride=UpperCamelCase_    ,       groups=UpperCamelCase_    ,       activation=config.hidden_act    ,       name="""layer.1"""   ),
                 TFRegNetSELayer(UpperCamelCase_    ,       reduced_channels=int(round(in_channels / 4   )   )    ,       name="""layer.2"""   ),
                 TFRegNetConvLayer(UpperCamelCase_    ,       kernel_size=1    ,       activation=UpperCamelCase_    ,       name="""layer.3"""   ),
             ]
             __lowerCamelCase   =						ACTaFN[config.hidden_act]




      def 			lowerCAmelCase__						(				self: Dict    ,       UpperCamelCase_: str   ):
             __lowerCamelCase   =						hidden_state
             for layer_module in self.layers:
                    __lowerCamelCase   =						layer_module(UpperCamelCase_   )
             __lowerCamelCase   =						self.shortcut(UpperCamelCase_   )
             hidden_state += residual
             __lowerCamelCase   =						self.activation(UpperCamelCase_   )
             return hidden_state





class     lowerCamelCase__(					tf.keras.layers.Layer):
      def __init__(				self: List[str]    ,       UpperCamelCase_: RegNetConfig    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int    ,       UpperCamelCase_: int = 2    ,       UpperCamelCase_: int = 2    ,       **UpperCamelCase_: Tuple   ):
             super().__init__(**UpperCamelCase_   )

             __lowerCamelCase   =						TFRegNetXLayer if config.layer_type == """x""" else TFRegNetYLayer
             __lowerCamelCase   =						[
                 # downsampling is done in the first layer with stride of 2
                 layer(UpperCamelCase_    ,       UpperCamelCase_    ,       UpperCamelCase_    ,       stride=UpperCamelCase_    ,       name="""layers.0"""   ),
                 *[layer(UpperCamelCase_    ,       UpperCamelCase_    ,       UpperCamelCase_    ,       name=F'layers.{i+1}'   ) for i in range(depth - 1   )],
             ]




      def 			lowerCAmelCase__						(				self: str    ,       UpperCamelCase_: str   ):
             for layer_module in self.layers:
                    __lowerCamelCase   =						layer_module(UpperCamelCase_   )
             return hidden_state





class     lowerCamelCase__(					tf.keras.layers.Layer):
      def __init__(				self: List[Any]    ,       UpperCamelCase_: RegNetConfig    ,       **UpperCamelCase_: Dict   ):
             super().__init__(**UpperCamelCase_   )
             __lowerCamelCase   =						[]
             # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
             self.stages.append(
                 TFRegNetStage(
                     UpperCamelCase_    ,       config.embedding_size    ,       config.hidden_sizes[0]    ,       stride=2 if config.downsample_in_first_stage else 1    ,       depth=config.depths[0]    ,       name="""stages.0"""    ,       )   )
             __lowerCamelCase   =						zip(config.hidden_sizes    ,       config.hidden_sizes[1:]   )
             for i, ((in_channels, out_channels), depth) in enumerate(zip(UpperCamelCase_    ,       config.depths[1:]   )   ):
                    self.stages.append(TFRegNetStage(UpperCamelCase_    ,       UpperCamelCase_    ,       UpperCamelCase_    ,       depth=UpperCamelCase_    ,       name=F'stages.{i+1}'   )   )




      def 			lowerCAmelCase__						(				self: int    ,       UpperCamelCase_: tf.Tensor    ,       UpperCamelCase_: bool = False    ,       UpperCamelCase_: bool = True   ):
             __lowerCamelCase   =						() if output_hidden_states else None

             for stage_module in self.stages:
                    if output_hidden_states:
                           __lowerCamelCase   =						hidden_states + (hidden_state,)

                    __lowerCamelCase   =						stage_module(UpperCamelCase_   )

             if output_hidden_states:
                    __lowerCamelCase   =						hidden_states + (hidden_state,)

             if not return_dict:
                    return tuple(v for v in [hidden_state, hidden_states] if v is not None   )

             return TFBaseModelOutputWithNoAttention(last_hidden_state=UpperCamelCase_    ,       hidden_states=UpperCamelCase_   )





@keras_serializable
class     lowerCamelCase__(					tf.keras.layers.Layer):
      UpperCAmelCase__      :	Union[str, Any]    		=   RegNetConfig
      def __init__(				self: str    ,       UpperCamelCase_: str    ,       **UpperCamelCase_: List[str]   ):
             super().__init__(**UpperCamelCase_   )
             __lowerCamelCase   =						config
             __lowerCamelCase   =						TFRegNetEmbeddings(UpperCamelCase_    ,       name="""embedder"""   )
             __lowerCamelCase   =						TFRegNetEncoder(UpperCamelCase_    ,       name="""encoder"""   )
             __lowerCamelCase   =						tf.keras.layers.GlobalAveragePoolingaD(keepdims=UpperCamelCase_    ,       name="""pooler"""   )




      @unpack_inputs
      def 			lowerCAmelCase__						(				self: Optional[int]    ,       UpperCamelCase_: tf.Tensor    ,       UpperCamelCase_: Optional[bool] = None    ,       UpperCamelCase_: Optional[bool] = None    ,       UpperCamelCase_: bool = False    ,       ):
             __lowerCamelCase   =						(
                 output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
             )
             __lowerCamelCase   =						return_dict if return_dict is not None else self.config.use_return_dict

             __lowerCamelCase   =						self.embedder(UpperCamelCase_    ,       training=UpperCamelCase_   )

             __lowerCamelCase   =						self.encoder(
                 UpperCamelCase_    ,       output_hidden_states=UpperCamelCase_    ,       return_dict=UpperCamelCase_    ,       training=UpperCamelCase_   )

             __lowerCamelCase   =						encoder_outputs[0]
             __lowerCamelCase   =						self.pooler(UpperCamelCase_   )

             # Change to NCHW output format have uniformity in the modules
             __lowerCamelCase   =						tf.transpose(UpperCamelCase_    ,       perm=(0, 3, 1, 2)   )
             __lowerCamelCase   =						tf.transpose(UpperCamelCase_    ,       perm=(0, 3, 1, 2)   )

             # Change the other hidden state outputs to NCHW as well
             if output_hidden_states:
                    __lowerCamelCase   =						tuple([tf.transpose(UpperCamelCase_    ,       perm=(0, 3, 1, 2)   ) for h in encoder_outputs[1]]   )

             if not return_dict:
                    return (last_hidden_state, pooled_output) + encoder_outputs[1:]

             return TFBaseModelOutputWithPoolingAndNoAttention(
                 last_hidden_state=UpperCamelCase_    ,       pooler_output=UpperCamelCase_    ,       hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states    ,       )





class     lowerCamelCase__(					__lowerCamelCase):
      UpperCAmelCase__      :	Optional[Any]    		=   RegNetConfig
      UpperCAmelCase__      :	str    		=   'regnet'
      UpperCAmelCase__      :	Union[str, Any]    		=   'pixel_values'
      @property
      def 			lowerCAmelCase__						(				self: Tuple   ):
             return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 2_24, 2_24)    ,       dtype=tf.floataa   )}



UpperCAmelCase_									=	r'\n    Parameters:\n    This model is a Tensorflow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular Tensorflow Module and refer to the Tensorflow documentation for all matter related to general usage and\n    behavior.\n        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n'

UpperCAmelCase_									=	r'\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConveNextImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'





@add_start_docstrings(
    'The bare RegNet model outputting raw features without any specific head on top.' ,     __lowerCamelCase ,     )
class     lowerCamelCase__(					__lowerCamelCase):
      def __init__(				self: Optional[Any]    ,       UpperCamelCase_: RegNetConfig    ,       *UpperCamelCase_: List[str]    ,       **UpperCamelCase_: Any   ):
             super().__init__(UpperCamelCase_    ,       *UpperCamelCase_    ,       **UpperCamelCase_   )
             __lowerCamelCase   =						TFRegNetMainLayer(UpperCamelCase_    ,       name="""regnet"""   )




      @unpack_inputs
      @add_start_docstrings_to_model_forward(UpperCamelCase_   )
      @add_code_sample_docstrings(
          checkpoint=_CHECKPOINT_FOR_DOC    ,       output_type=UpperCamelCase_    ,       config_class=_CONFIG_FOR_DOC    ,       modality="""vision"""    ,       expected_output=_EXPECTED_OUTPUT_SHAPE    ,       )
      def 			lowerCAmelCase__						(				self: Tuple    ,       UpperCamelCase_: tf.Tensor    ,       UpperCamelCase_: Optional[bool] = None    ,       UpperCamelCase_: Optional[bool] = None    ,       UpperCamelCase_: int=False    ,       ):
             __lowerCamelCase   =						(
                 output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
             )
             __lowerCamelCase   =						return_dict if return_dict is not None else self.config.use_return_dict

             __lowerCamelCase   =						self.regnet(
                 pixel_values=UpperCamelCase_    ,       output_hidden_states=UpperCamelCase_    ,       return_dict=UpperCamelCase_    ,       training=UpperCamelCase_    ,       )
             if not return_dict:
                    return (outputs[0],) + outputs[1:]

             return TFBaseModelOutputWithPoolingAndNoAttention(
                 last_hidden_state=outputs.last_hidden_state    ,       pooler_output=outputs.pooler_output    ,       hidden_states=outputs.hidden_states    ,       )





@add_start_docstrings(
    '\n    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    ' ,     __lowerCamelCase ,     )
class     lowerCamelCase__(					__lowerCamelCase ,     __lowerCamelCase):
      def __init__(				self: Optional[int]    ,       UpperCamelCase_: RegNetConfig    ,       *UpperCamelCase_: Union[str, Any]    ,       **UpperCamelCase_: Dict   ):
             super().__init__(UpperCamelCase_    ,       *UpperCamelCase_    ,       **UpperCamelCase_   )
             __lowerCamelCase   =						config.num_labels
             __lowerCamelCase   =						TFRegNetMainLayer(UpperCamelCase_    ,       name="""regnet"""   )
             # classification head
             __lowerCamelCase   =						[
                 tf.keras.layers.Flatten(),
                 tf.keras.layers.Dense(config.num_labels    ,       name="""classifier.1"""   ) if config.num_labels > 0 else tf.identity,
             ]




      @unpack_inputs
      @add_start_docstrings_to_model_forward(UpperCamelCase_   )
      @add_code_sample_docstrings(
          checkpoint=_IMAGE_CLASS_CHECKPOINT    ,       output_type=UpperCamelCase_    ,       config_class=_CONFIG_FOR_DOC    ,       expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT    ,       )
      def 			lowerCAmelCase__						(				self: Any    ,       UpperCamelCase_: tf.Tensor = None    ,       UpperCamelCase_: tf.Tensor = None    ,       UpperCamelCase_: bool = None    ,       UpperCamelCase_: bool = None    ,       UpperCamelCase_: List[str]=False    ,       ):
             __lowerCamelCase   =						(
                 output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
             )
             __lowerCamelCase   =						return_dict if return_dict is not None else self.config.use_return_dict

             __lowerCamelCase   =						self.regnet(
                 UpperCamelCase_    ,       output_hidden_states=UpperCamelCase_    ,       return_dict=UpperCamelCase_    ,       training=UpperCamelCase_   )

             __lowerCamelCase   =						outputs.pooler_output if return_dict else outputs[1]

             __lowerCamelCase   =						self.classifier[0](UpperCamelCase_   )
             __lowerCamelCase   =						self.classifier[1](UpperCamelCase_   )

             __lowerCamelCase   =						None if labels is None else self.hf_compute_loss(labels=UpperCamelCase_    ,       logits=UpperCamelCase_   )

             if not return_dict:
                    __lowerCamelCase   =						(logits,) + outputs[2:]
                    return ((loss,) + output) if loss is not None else output

             return TFSequenceClassifierOutput(loss=UpperCamelCase_    ,       logits=UpperCamelCase_    ,       hidden_states=outputs.hidden_states   )







import json
import os
from datetime import date
from pathlib import Path

from tabulate import DataRow, TableFormat, tabulate


UpperCAmelCase_									=	TableFormat(
    lineabove=None,
    linebelowheader=None,
    linebetweenrows=None,
    linebelow=None,
    headerrow=DataRow('', '|', '|'),
    datarow=DataRow('', '|', '|'),
    padding=1,
    with_header_hide=None,
)


UpperCAmelCase_									=	[]
UpperCAmelCase_									=	[]

UpperCAmelCase_									=	{'type': 'section', 'text': {'type': 'plain_text', 'text': 'No failed tests! 🤗', 'emoji': True}}

UpperCAmelCase_									=	[
    {
        'type': 'header',
        'text': {
            'type': 'plain_text',
            'text': f"""🤗 Accelerate nightly {os.environ.get("TEST_TYPE", "")} test results""",
            'emoji': True,
        },
    }
]

UpperCAmelCase_									=	0
for log in Path().glob('*.log'):
       UpperCAmelCase_									=	0
       with open(log, 'r') as f:
              for line in f:
                     UpperCAmelCase_									=	json.loads(line)
                     if line.get('nodeid', '') != "":
                            UpperCAmelCase_									=	line['nodeid']
                            if line.get('duration', None) is not None:
                                   UpperCAmelCase_									=	f"""{line["duration"]:.4f}"""
                                   if line.get('outcome', '') == "failed":
                                          section_num_failed += 1
                                          failed.append([test, duration, log.name.split('_')[0]])
                                          total_num_failed += 1
       group_info.append([str(log), section_num_failed, failed])
       UpperCAmelCase_									=	[]
       log.unlink()

UpperCAmelCase_									=	''
UpperCAmelCase_									=	[]
if total_num_failed > 0:
       for name, num_failed, failed_tests in group_info:
              if num_failed > 0:
                     if num_failed == 1:
                            message += f"*{name[1:]}: {num_failed} failed test*\n"
                     else:
                            message += f"*{name[1:]}: {num_failed} failed tests*\n"
                     UpperCAmelCase_									=	[]
                     UpperCAmelCase_									=	{}
                     for test in failed_tests:
                            UpperCAmelCase_									=	test[0].split('::')
                            UpperCAmelCase_									=	data[0].split('/')[-1]
                            if data[0] not in filesafailed:
                                   UpperCAmelCase_									=	[data[1:]]
                            else:
                                   filesafailed[data[0]] += [data[1:]]
                            failed_table.append(data)

                     UpperCAmelCase_									=	[test[0] for test in failed_table]
                     UpperCAmelCase_									=	list(set(files))
                     # Count number of instances in failed_tests
                     UpperCAmelCase_									=	[]
                     for file in individual_files:
                            table.append([file, len(filesafailed[file])])

                     UpperCAmelCase_									=	tabulate(
                         table,
                         headers=['Test Location', 'Num Failed'],
                         tablefmt=hf_table_format,
                         stralign='right',
                     )
                     message += f"\n```\n{failed_table}\n```"
                     all_filesafailed.append(filesafailed)
       if len(message) > 3_000:
              UpperCAmelCase_									=	'Too many failed tests, please see the full report in the Action results.'
              UpperCAmelCase_									=	len(err) + 10
              UpperCAmelCase_									=	message[: 3_000 - offset] + f"""\n...\n```\n{err}"""
       print(f"""### {message}""")
else:
       UpperCAmelCase_									=	'No failed tests! 🤗'
       print(f"""## {message}""")
       payload.append(no_error_payload)

if os.environ.get('TEST_TYPE', '') != "":
       from slack_sdk import WebClient

       UpperCAmelCase_									=	WebClient(token=os.environ['SLACK_API_TOKEN'])
       if message != "No failed tests! 🤗":
              UpperCAmelCase_									=	{
                  'type': 'section',
                  'text': {
                      'type': 'mrkdwn',
                      'text': message,
                  },
              }
              payload.append(md_report)
              UpperCAmelCase_									=	{
                  'type': 'section',
                  'text': {
                      'type': 'mrkdwn',
                      'text': '*For more details:*',
                  },
                  'accessory': {
                      'type': 'button',
                      'text': {
                          'type': 'plain_text',
                          'text': 'Check Action results',
                          'emoji': True,
                      },
                      'url': f"""https://github.com/{os.environ["GITHUB_REPOSITORY"]}/actions/runs/{os.environ["GITHUB_RUN_ID"]}""",
                  },
              }
              payload.append(action_button)
              UpperCAmelCase_									=	{
                  'type': 'context',
                  'elements': [
                      {
                          'type': 'plain_text',
                          'text': f"""Nightly {os.environ.get("TEST_TYPE")} test results for {date.today()}""",
                      }
                  ],
              }
              payload.append(date_report)
       UpperCAmelCase_									=	client.chat_postMessage(channel='#accelerate-ci-daily', text=message, blocks=payload)
       UpperCAmelCase_									=	response.data['ts']
       for failed_file in all_filesafailed:
              for test_location, test_failures in failed_file.items():
                     # Keep only the first instance of the test name
                     UpperCAmelCase_									=	''
                     for i, row in enumerate(test_failures):
                            if row[0] != test_class:
                                   UpperCAmelCase_									=	row[0]
                            else:
                                   UpperCAmelCase_									=	''

                     UpperCAmelCase_									=	{
                         'type': 'section',
                         'text': {
                             'type': 'mrkdwn',
                             'text': f"""Test location: {test_location}\n```\n{tabulate(test_failures, headers=["Class", "Test"], tablefmt=hf_table_format, stralign="right")}\n```""",
                         },
                     }

                     client.chat_postMessage(
                         channel='#accelerate-ci-daily',
                         thread_ts=ts,
                         blocks=[payload],
                     )

