



import collections
import inspect
import unittest

from transformers import FocalNetConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch
    from torch import nn

    from transformers import (
        FocalNetBackbone,
        FocalNetForImageClassification,
        FocalNetForMaskedImageModeling,
        FocalNetModel,
    )
    from transformers.models.focalnet.modeling_focalnet import FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
    from PIL import Image

    from transformers import AutoImageProcessor



class 							lowerCAmelCase_						:
       def __init__(     self,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_=13,     SCREAMING_SNAKE_CASE_=32,     SCREAMING_SNAKE_CASE_=2,     SCREAMING_SNAKE_CASE_=3,     SCREAMING_SNAKE_CASE_=16,     SCREAMING_SNAKE_CASE_=[32, 64, 128],     SCREAMING_SNAKE_CASE_=[1, 2, 1],     SCREAMING_SNAKE_CASE_=[2, 2, 4],     SCREAMING_SNAKE_CASE_=2,     SCREAMING_SNAKE_CASE_=2.0,     SCREAMING_SNAKE_CASE_=True,     SCREAMING_SNAKE_CASE_=0.0,     SCREAMING_SNAKE_CASE_=0.0,     SCREAMING_SNAKE_CASE_=0.1,     SCREAMING_SNAKE_CASE_="gelu",     SCREAMING_SNAKE_CASE_=False,     SCREAMING_SNAKE_CASE_=True,     SCREAMING_SNAKE_CASE_=0.02,     SCREAMING_SNAKE_CASE_=1e-5,     SCREAMING_SNAKE_CASE_=True,     SCREAMING_SNAKE_CASE_=None,     SCREAMING_SNAKE_CASE_=True,     SCREAMING_SNAKE_CASE_=10,     SCREAMING_SNAKE_CASE_=8,     SCREAMING_SNAKE_CASE_=["stage1", "stage2"],     SCREAMING_SNAKE_CASE_=[1, 2],     )	->						int:
          UpperCamelCase       :    Optional[int]		      =      parent
          UpperCamelCase       :    str		      =      batch_size
          UpperCamelCase       :    Optional[Any]		      =      image_size
          UpperCamelCase       :    Any		      =      patch_size
          UpperCamelCase       :    Optional[Any]		      =      num_channels
          UpperCamelCase       :    Optional[int]		      =      embed_dim
          UpperCamelCase       :    Any		      =      hidden_sizes
          UpperCamelCase       :    Union[str, Any]		      =      depths
          UpperCamelCase       :    Dict		      =      num_heads
          UpperCamelCase       :    Optional[int]		      =      window_size
          UpperCamelCase       :    Optional[Any]		      =      mlp_ratio
          UpperCamelCase       :    Any		      =      qkv_bias
          UpperCamelCase       :    int		      =      hidden_dropout_prob
          UpperCamelCase       :    Dict		      =      attention_probs_dropout_prob
          UpperCamelCase       :    List[Any]		      =      drop_path_rate
          UpperCamelCase       :    Dict		      =      hidden_act
          UpperCamelCase       :    Optional[int]		      =      use_absolute_embeddings
          UpperCamelCase       :    List[Any]		      =      patch_norm
          UpperCamelCase       :    List[str]		      =      layer_norm_eps
          UpperCamelCase       :    Dict		      =      initializer_range
          UpperCamelCase       :    int		      =      is_training
          UpperCamelCase       :    Any		      =      scope
          UpperCamelCase       :    Any		      =      use_labels
          UpperCamelCase       :    Dict		      =      type_sequence_label_size
          UpperCamelCase       :    int		      =      encoder_stride
          UpperCamelCase       :    Union[str, Any]		      =      out_features
          UpperCamelCase       :    Dict		      =      out_indices
       def    snake_case_			(     self			)	->						int:
          UpperCamelCase       :    Optional[Any]		      =      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

          UpperCamelCase       :    Any		      =      None
          if self.use_labels:
             UpperCamelCase       :    List[Any]		      =      ids_tensor([self.batch_size],     self.type_sequence_label_size			)

          UpperCamelCase       :    Optional[int]		      =      self.get_config()

          return config, pixel_values, labels
       def    snake_case_			(     self			)	->						Tuple:
          return FocalNetConfig(
              image_size=self.image_size,     patch_size=self.patch_size,     num_channels=self.num_channels,     embed_dim=self.embed_dim,     hidden_sizes=self.hidden_sizes,     depths=self.depths,     num_heads=self.num_heads,     window_size=self.window_size,     mlp_ratio=self.mlp_ratio,     qkv_bias=self.qkv_bias,     hidden_dropout_prob=self.hidden_dropout_prob,     attention_probs_dropout_prob=self.attention_probs_dropout_prob,     drop_path_rate=self.drop_path_rate,     hidden_act=self.hidden_act,     use_absolute_embeddings=self.use_absolute_embeddings,     path_norm=self.patch_norm,     layer_norm_eps=self.layer_norm_eps,     initializer_range=self.initializer_range,     encoder_stride=self.encoder_stride,     out_features=self.out_features,     out_indices=self.out_indices,     )
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			)	->						Any:
          UpperCamelCase       :    int		      =      FocalNetModel(config=SCREAMING_SNAKE_CASE_			)
          model.to(SCREAMING_SNAKE_CASE_			)
          model.eval()
          UpperCamelCase       :    List[str]		      =      model(SCREAMING_SNAKE_CASE_			)

          UpperCamelCase       :    Dict		      =      ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths			) - 1))
          UpperCamelCase       :    Optional[Any]		      =      int(config.embed_dim * 2 ** (len(config.depths			) - 1)			)

          self.parent.assertEqual(result.last_hidden_state.shape,     (self.batch_size, expected_seq_len, expected_dim)			)
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			)	->						Union[str, Any]:
          UpperCamelCase       :    str		      =      FocalNetBackbone(config=SCREAMING_SNAKE_CASE_			)
          model.to(SCREAMING_SNAKE_CASE_			)
          model.eval()
          UpperCamelCase       :    Dict		      =      model(SCREAMING_SNAKE_CASE_			)

          # verify feature maps
          self.parent.assertEqual(len(result.feature_maps			),     len(config.out_features			)			)
          self.parent.assertListEqual(list(result.feature_maps[0].shape			),     [self.batch_size, self.image_size, 8, 8]			)

          # verify channels
          self.parent.assertEqual(len(model.channels			),     len(config.out_features			)			)
          self.parent.assertListEqual(model.channels,     config.hidden_sizes[:-1]			)

          # verify backbone works with out_features=None
          UpperCamelCase       :    Dict		      =      None
          UpperCamelCase       :    Tuple		      =      FocalNetBackbone(config=SCREAMING_SNAKE_CASE_			)
          model.to(SCREAMING_SNAKE_CASE_			)
          model.eval()
          UpperCamelCase       :    Optional[int]		      =      model(SCREAMING_SNAKE_CASE_			)

          # verify feature maps
          self.parent.assertEqual(len(result.feature_maps			),     1			)
          self.parent.assertListEqual(list(result.feature_maps[0].shape			),     [self.batch_size, self.image_size * 2, 4, 4]			)

          # verify channels
          self.parent.assertEqual(len(model.channels			),     1			)
          self.parent.assertListEqual(model.channels,     [config.hidden_sizes[-1]]			)
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			)	->						Optional[Any]:
          UpperCamelCase       :    Any		      =      FocalNetForMaskedImageModeling(config=SCREAMING_SNAKE_CASE_			)
          model.to(SCREAMING_SNAKE_CASE_			)
          model.eval()
          UpperCamelCase       :    Optional[Any]		      =      model(SCREAMING_SNAKE_CASE_			)
          self.parent.assertEqual(
              result.reconstruction.shape,     (self.batch_size, self.num_channels, self.image_size, self.image_size)			)

          # test greyscale images
          UpperCamelCase       :    str		      =      1
          UpperCamelCase       :    List[Any]		      =      FocalNetForMaskedImageModeling(SCREAMING_SNAKE_CASE_			)
          model.to(SCREAMING_SNAKE_CASE_			)
          model.eval()

          UpperCamelCase       :    Union[str, Any]		      =      floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
          UpperCamelCase       :    Optional[Any]		      =      model(SCREAMING_SNAKE_CASE_			)
          self.parent.assertEqual(result.reconstruction.shape,     (self.batch_size, 1, self.image_size, self.image_size)			)
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			)	->						List[str]:
          UpperCamelCase       :    List[str]		      =      self.type_sequence_label_size
          UpperCamelCase       :    Union[str, Any]		      =      FocalNetForImageClassification(SCREAMING_SNAKE_CASE_			)
          model.to(SCREAMING_SNAKE_CASE_			)
          model.eval()
          UpperCamelCase       :    Tuple		      =      model(SCREAMING_SNAKE_CASE_,     labels=SCREAMING_SNAKE_CASE_			)
          self.parent.assertEqual(result.logits.shape,     (self.batch_size, self.type_sequence_label_size)			)

          # test greyscale images
          UpperCamelCase       :    Any		      =      1
          UpperCamelCase       :    Optional[Any]		      =      FocalNetForImageClassification(SCREAMING_SNAKE_CASE_			)
          model.to(SCREAMING_SNAKE_CASE_			)
          model.eval()

          UpperCamelCase       :    Dict		      =      floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
          UpperCamelCase       :    int		      =      model(SCREAMING_SNAKE_CASE_			)
          self.parent.assertEqual(result.logits.shape,     (self.batch_size, self.type_sequence_label_size)			)






       def    snake_case_			(     self			)	->						Union[str, Any]:
          UpperCamelCase       :    Union[str, Any]		      =      self.prepare_config_and_inputs()

          UpperCamelCase      ,	UpperCamelCase      ,	UpperCamelCase       :    int		      =      config_and_inputs
          UpperCamelCase       :    Dict		      =      {'pixel_values': pixel_values}
          return config, inputs_dict






@require_torch
class 							lowerCAmelCase_						(    a__			,       a__			,       unittest.TestCase				):
       UpperCAmelCase__							:   Any  	=    (
           (
               FocalNetModel,
               FocalNetForImageClassification,
               FocalNetForMaskedImageModeling,
               FocalNetBackbone,
           )
           if is_torch_available()
           else ()
       )
       UpperCAmelCase__							:   Optional[int]  	=    (
           {"feature-extraction": FocalNetModel, "image-classification": FocalNetForImageClassification}
           if is_torch_available()
           else {}
       )
       UpperCAmelCase__							:   str  	=    False

       UpperCAmelCase__							:   List[str]  	=    False
       UpperCAmelCase__							:   str  	=    False
       UpperCAmelCase__							:   Dict  	=    False
       UpperCAmelCase__							:   Optional[int]  	=    False
       def    snake_case_			(     self			)	->						Union[str, Any]:
          UpperCamelCase       :    Union[str, Any]		      =      FocalNetModelTester(self			)
          UpperCamelCase       :    Optional[int]		      =      ConfigTester(self,     config_class=SCREAMING_SNAKE_CASE_,     embed_dim=37,     has_text_modality=SCREAMING_SNAKE_CASE_			)
       def    snake_case_			(     self			)	->						Any:
          self.create_and_test_config_common_properties()
          self.config_tester.create_and_test_config_to_json_string()
          self.config_tester.create_and_test_config_to_json_file()
          self.config_tester.create_and_test_config_from_and_save_pretrained()
          self.config_tester.create_and_test_config_with_num_labels()
          self.config_tester.check_config_can_be_init_without_params()
          self.config_tester.check_config_arguments_init()
       def    snake_case_			(     self			)	->						Optional[Any]:
          return
       def    snake_case_			(     self			)	->						Optional[int]:
          UpperCamelCase       :    Optional[Any]		      =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_			)
       def    snake_case_			(     self			)	->						List[Any]:
          UpperCamelCase       :    str		      =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_backbone(*SCREAMING_SNAKE_CASE_			)
       def    snake_case_			(     self			)	->						Dict:
          UpperCamelCase       :    str		      =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_image_modeling(*SCREAMING_SNAKE_CASE_			)
       def    snake_case_			(     self			)	->						Union[str, Any]:
          UpperCamelCase       :    List[str]		      =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE_			)
       @unittest.skip(reason='FocalNet does not use inputs_embeds'			)
       def    snake_case_			(     self			)	->						Optional[Any]:
          pass
       @unittest.skip(reason='FocalNet does not use feedforward chunking'			)
       def    snake_case_			(     self			)	->						Tuple:
          pass
       def    snake_case_			(     self			)	->						Dict:
          UpperCamelCase      ,	UpperCamelCase       :    int		      =      self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes[:-1]:
             UpperCamelCase       :    Dict		      =      model_class(SCREAMING_SNAKE_CASE_			)
             self.assertIsInstance(model.get_input_embeddings(),     (nn.Module)			)
             UpperCamelCase       :    List[str]		      =      model.get_output_embeddings()
             self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE_,     nn.Linear			)			)
       def    snake_case_			(     self			)	->						str:
          UpperCamelCase      ,	UpperCamelCase       :    int		      =      self.model_tester.prepare_config_and_inputs_for_common()

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

             UpperCamelCase       :    str		      =      ['pixel_values']
             self.assertListEqual(arg_names[:1],     SCREAMING_SNAKE_CASE_			)
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			)	->						int:
          UpperCamelCase       :    Union[str, Any]		      =      model_class(SCREAMING_SNAKE_CASE_			)
          model.to(SCREAMING_SNAKE_CASE_			)
          model.eval()

          with torch.no_grad():
             UpperCamelCase       :    Union[str, Any]		      =      model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			)			)

          UpperCamelCase       :    Tuple		      =      outputs.hidden_states

          UpperCamelCase       :    Optional[int]		      =      getattr(
              self.model_tester,     'expected_num_hidden_layers',     len(self.model_tester.depths			) + 1			)
          self.assertEqual(len(SCREAMING_SNAKE_CASE_			),     SCREAMING_SNAKE_CASE_			)

          # FocalNet has a different seq_length
          UpperCamelCase       :    List[Any]		      =      (
              config.patch_size
              if isinstance(config.patch_size,     collections.abc.Iterable			)
              else (config.patch_size, config.patch_size)
          )

          UpperCamelCase       :    List[Any]		      =      (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

          self.assertListEqual(
              list(hidden_states[0].shape[-2:]			),     [num_patches, self.model_tester.embed_dim],     )

          UpperCamelCase       :    str		      =      outputs.reshaped_hidden_states
          self.assertEqual(len(SCREAMING_SNAKE_CASE_			),     SCREAMING_SNAKE_CASE_			)

          UpperCamelCase      ,	UpperCamelCase      ,	UpperCamelCase      ,	UpperCamelCase       :    int		      =      reshaped_hidden_states[0].shape
          UpperCamelCase       :    Dict		      =      (
              reshaped_hidden_states[0].view(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     height * width			).permute(0,     2,     1			)
          )
          self.assertListEqual(
              list(reshaped_hidden_states.shape[-2:]			),     [num_patches, self.model_tester.embed_dim],     )
       def    snake_case_			(     self			)	->						int:
          UpperCamelCase      ,	UpperCamelCase       :    Union[str, Any]		      =      self.model_tester.prepare_config_and_inputs_for_common()

          UpperCamelCase       :    Tuple		      =      (
              self.model_tester.image_size
              if isinstance(self.model_tester.image_size,     collections.abc.Iterable			)
              else (self.model_tester.image_size, self.model_tester.image_size)
          )

          for model_class in self.all_model_classes[:-1]:
             UpperCamelCase       :    Optional[Any]		      =      True
             self.check_hidden_states_output(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			)

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             UpperCamelCase       :    Optional[int]		      =      True

             self.check_hidden_states_output(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			)
       def    snake_case_			(     self			)	->						Optional[Any]:
          UpperCamelCase      ,	UpperCamelCase       :    Dict		      =      self.model_tester.prepare_config_and_inputs_for_common()
          UpperCamelCase       :    Any		      =      3

          UpperCamelCase       :    str		      =      (
              self.model_tester.image_size
              if isinstance(self.model_tester.image_size,     collections.abc.Iterable			)
              else (self.model_tester.image_size, self.model_tester.image_size)
          )
          UpperCamelCase       :    Dict		      =      (
              config.patch_size
              if isinstance(config.patch_size,     collections.abc.Iterable			)
              else (config.patch_size, config.patch_size)
          )

          UpperCamelCase       :    str		      =      image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
          UpperCamelCase       :    str		      =      image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

          for model_class in self.all_model_classes[:-1]:
             UpperCamelCase       :    List[str]		      =      True
             self.check_hidden_states_output(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     (padded_height, padded_width)			)

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             UpperCamelCase       :    int		      =      True
             self.check_hidden_states_output(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_,     (padded_height, padded_width)			)
       @slow
       def    snake_case_			(     self			)	->						List[Any]:
          for model_name in FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             UpperCamelCase       :    Tuple		      =      FocalNetModel.from_pretrained(SCREAMING_SNAKE_CASE_			)
             self.assertIsNotNone(SCREAMING_SNAKE_CASE_			)






       def    snake_case_			(     self			)	->						Optional[Any]:
          UpperCamelCase      ,	UpperCamelCase       :    Any		      =      self.model_tester.prepare_config_and_inputs_for_common()

          UpperCamelCase       :    List[str]		      =      _config_zero_init(SCREAMING_SNAKE_CASE_			)
          for model_class in self.all_model_classes:
             UpperCamelCase       :    Any		      =      model_class(config=SCREAMING_SNAKE_CASE_			)
             for name, param in model.named_parameters():
                if "embeddings" not in name and param.requires_grad:
                   self.assertIn(
                       ((param.data.mean() * 1e9).round() / 1e9).item(),     [0.0, 1.0],     msg=F"""Parameter {name} of model {model_class} seems not properly initialized""",     )






@require_vision
@require_torch
class 							lowerCAmelCase_						(    unittest.TestCase				):
       @cached_property
       def    snake_case_			(     self			)	->						Dict:
          # TODO update organization
          return AutoImageProcessor.from_pretrained('microsoft/focalnet-tiny'			) if is_vision_available() else None






       @slow
       def    snake_case_			(     self			)	->						Dict:
          UpperCamelCase       :    str		      =      FocalNetForImageClassification.from_pretrained('microsoft/focalnet-tiny'			).to(SCREAMING_SNAKE_CASE_			)
          UpperCamelCase       :    int		      =      self.default_image_processor

          UpperCamelCase       :    Dict		      =      Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'			)
          UpperCamelCase       :    Optional[int]		      =      image_processor(images=SCREAMING_SNAKE_CASE_,     return_tensors='pt'			).to(SCREAMING_SNAKE_CASE_			)

          # forward pass
          with torch.no_grad():
             UpperCamelCase       :    Dict		      =      model(**SCREAMING_SNAKE_CASE_			)

          # verify the logits
          UpperCamelCase       :    int		      =      torch.Size((1, 1000)			)
          self.assertEqual(outputs.logits.shape,     SCREAMING_SNAKE_CASE_			)
          UpperCamelCase       :    Union[str, Any]		      =      torch.tensor([0.21_66, -0.43_68, 0.21_91]			).to(SCREAMING_SNAKE_CASE_			)
          self.assertTrue(torch.allclose(outputs.logits[0, :3],     SCREAMING_SNAKE_CASE_,     atol=1e-4			)			)
          self.assertTrue(outputs.logits.argmax(dim=-1			).item(),     281			)






@require_torch
class 							lowerCAmelCase_						(    a__			,       unittest.TestCase				):
       UpperCAmelCase__							:   List[Any]  	=    (FocalNetBackbone,) if is_torch_available() else ()
       UpperCAmelCase__							:   str  	=    FocalNetConfig

       UpperCAmelCase__							:   Any  	=    False
       def    snake_case_			(     self			)	->						Any:
          UpperCamelCase       :    Any		      =      FocalNetModelTester(self			)







import argparse
import logging
import sys
from unittest.mock import patch

import run_glue_deebert

from transformers.testing_utils import TestCasePlus, get_gpu_count, require_torch_non_multi_gpu, slow


logging.basicConfig(level=logging.DEBUG)

_SCREAMING_SNAKE_CASE     :					int      =       logging.getLogger()
def      UpperCAmelCase__		():



     """simple docstring"""






     snake_case											=							argparse.ArgumentParser()
     parser.add_argument('''-f'''							)
     snake_case											=							parser.parse_args()
     return args.f

class     A__   (       snake_case__      ):







    """simple docstring"""

    def 						a_     (			self       ):
         snake_case											=							logging.StreamHandler(sys.stdout       )
         logger.addHandler(__snake_case       )
    def 						a_     (			self     ,   __snake_case       ):
         snake_case											=							get_gpu_count()

         if n_gpu > 1:
              pass
              # XXX: doesn't quite work with n_gpu > 1 https://github.com/huggingface/transformers/issues/10560
              # script = f"{self.examples_dir_str}/research_projects/deebert/run_glue_deebert.py"
              # distributed_args = f"-m torch.distributed.launch --nproc_per_node={n_gpu} {script}".split()
              # cmd = [sys.executable] + distributed_args + args
              # execute_subprocess_async(cmd, env=self.get_env())
              # XXX: test the results - need to save them first into .json file
         else:
              args.insert(0     ,   '''run_glue_deebert.py'''       )
              with patch.object(__snake_case     ,   '''argv'''     ,   __snake_case       ):
                   snake_case											=							run_glue_deebert.main()
                   for value in result.values():
                        self.assertGreaterEqual(__snake_case     ,   0.666       )




    @slow
    @require_torch_non_multi_gpu
    def 						a_     (			self       ):
         snake_case											=							'''
            --model_type roberta
            --model_name_or_path roberta-base
            --task_name MRPC
            --do_train
            --do_eval
            --do_lower_case
            --data_dir ./tests/fixtures/tests_samples/MRPC/
            --max_seq_length 128
            --per_gpu_eval_batch_size=1
            --per_gpu_train_batch_size=8
            --learning_rate 2e-4
            --num_train_epochs 3
            --overwrite_output_dir
            --seed 42
            --output_dir ./examples/deebert/saved_models/roberta-base/MRPC/two_stage
            --plot_data_dir ./examples/deebert/results/
            --save_steps 0
            --overwrite_cache
            --eval_after_first_stage
            '''.split()
         self.run_and_check(__snake_case       )

         snake_case											=							'''
            --model_type roberta
            --model_name_or_path ./examples/deebert/saved_models/roberta-base/MRPC/two_stage
            --task_name MRPC
            --do_eval
            --do_lower_case
            --data_dir ./tests/fixtures/tests_samples/MRPC/
            --output_dir ./examples/deebert/saved_models/roberta-base/MRPC/two_stage
            --plot_data_dir ./examples/deebert/results/
            --max_seq_length 128
            --eval_each_highway
            --eval_highway
            --overwrite_cache
            --per_gpu_eval_batch_size=1
            '''.split()
         self.run_and_check(__snake_case       )

         snake_case											=							'''
            --model_type roberta
            --model_name_or_path ./examples/deebert/saved_models/roberta-base/MRPC/two_stage
            --task_name MRPC
            --do_eval
            --do_lower_case
            --data_dir ./tests/fixtures/tests_samples/MRPC/
            --output_dir ./examples/deebert/saved_models/roberta-base/MRPC/two_stage
            --plot_data_dir ./examples/deebert/results/
            --max_seq_length 128
            --early_exit_entropy 0.1
            --eval_highway
            --overwrite_cache
            --per_gpu_eval_batch_size=1
            '''.split()
         self.run_and_check(__snake_case       )




