


'''simple docstring'''

import unittest

import numpy as np
import timeout_decorator  # noqa

from transformers import OPTConfig, is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, slow

from ...generation.test_flax_utils import FlaxGenerationTesterMixin
from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor


if is_flax_available():
       import os

       # The slow tests are often failing with OOM error on GPU
       # This makes JAX allocate exactly what is needed on demand, and deallocate memory that is no longer needed
       # but will be slower as stated here https://jax.readthedocs.io/en/latest/gpu_memory_allocation.html
       __lowercase:		Dict							=     "platform"

       import jax
       import jax.numpy as jnp

       from transformers import FlaxOPTForCausalLM, FlaxOPTModel, GPTaTokenizer



def        SCREAMING_SNAKE_CASE__(		_UpperCamelCase      :				Any    ,		_UpperCamelCase      :				List[Any]    ,		_UpperCamelCase      :				List[Any]=None    ,		_UpperCamelCase      :				Dict=None   )		->					Tuple:





   '''simple docstring'''







   if attention_mask is None:
      UpperCamelCase__ 						=						np.where(input_ids != config.pad_token_id    ,		1    ,		0   )
   return {
       "input_ids": input_ids,
       "attention_mask": attention_mask,
   }







@require_flax
class  UpperCAmelCase :

 def __init__( self :	Any,					a_ :	List[Any],					a_ :	Tuple=13,					a_ :	Optional[int]=7,					a_ :	str=True,					a_ :	str=False,					a_ :	List[Any]=99,					a_ :	Optional[Any]=16,					a_ :	Union[str, Any]=2,					a_ :	List[Any]=4,					a_ :	Tuple=4,					a_ :	Any="gelu",					a_ :	Any=0.1,					a_ :	Tuple=0.1,					a_ :	List[str]=20,					a_ :	int=2,					a_ :	Optional[int]=1,					a_ :	Dict=0,					a_ :	Tuple=16,					a_ :	int=16,					a_ :	int=0.02,					):





    """simple docstring"""



    UpperCamelCase__ 						=						parent
    UpperCamelCase__ 						=						batch_size
    UpperCamelCase__ 						=						seq_length
    UpperCamelCase__ 						=						is_training
    UpperCamelCase__ 						=						use_labels
    UpperCamelCase__ 						=						vocab_size
    UpperCamelCase__ 						=						hidden_size
    UpperCamelCase__ 						=						num_hidden_layers
    UpperCamelCase__ 						=						num_attention_heads
    UpperCamelCase__ 						=						intermediate_size
    UpperCamelCase__ 						=						hidden_act
    UpperCamelCase__ 						=						hidden_dropout_prob
    UpperCamelCase__ 						=						attention_probs_dropout_prob
    UpperCamelCase__ 						=						max_position_embeddings
    UpperCamelCase__ 						=						eos_token_id
    UpperCamelCase__ 						=						pad_token_id
    UpperCamelCase__ 						=						bos_token_id
    UpperCamelCase__ 						=						embed_dim
    UpperCamelCase__ 						=						word_embed_proj_dim
    UpperCamelCase__ 						=						initializer_range
    UpperCamelCase__ 						=						False

 def 		lowercase_						( self :	Tuple					):





    """simple docstring"""



    UpperCamelCase__ 						=						np.clip(ids_tensor([self.batch_size, self.seq_length - 1],					self.vocab_size					),					3,					self.vocab_size					)
    UpperCamelCase__ 						=						np.concatenate((input_ids, 2 * np.ones((self.batch_size, 1),					dtype=np.intaa					)),					-1					)

    UpperCamelCase__ 						=						OPTConfig(
        vocab_size=self.vocab_size,					hidden_size=self.hidden_size,					num_hidden_layers=self.num_hidden_layers,					num_attention_heads=self.num_attention_heads,					ffn_dim=self.intermediate_size,					dropout=self.hidden_dropout_prob,					attention_dropout=self.attention_probs_dropout_prob,					max_position_embeddings=self.max_position_embeddings,					eos_token_id=self.eos_token_id,					bos_token_id=self.bos_token_id,					pad_token_id=self.pad_token_id,					embed_dim=self.embed_dim,					is_encoder_decoder=a_,					word_embed_proj_dim=self.word_embed_proj_dim,					initializer_range=self.initializer_range,					use_cache=a_,					)
    UpperCamelCase__ 						=						prepare_opt_inputs_dict(a_,					a_					)
    return config, inputs_dict

 def 		lowercase_						( self :	Any					):





    """simple docstring"""



    UpperCamelCase__						,		UpperCamelCase__ 						=						self.prepare_config_and_inputs()
    return config, inputs_dict

 def 		lowercase_						( self :	Any,					a_ :	Optional[Any],					a_ :	List[str],					a_ :	Optional[Any]					):





    """simple docstring"""



    UpperCamelCase__ 						=						20
    UpperCamelCase__ 						=						model_class_name(a_					)

    UpperCamelCase__ 						=						inputs_dict["input_ids"]
    UpperCamelCase__ 						=						inputs_dict["attention_mask"]

    UpperCamelCase__ 						=						model.init_cache(input_ids.shape[0],					a_					)
    UpperCamelCase__ 						=						jnp.ones((input_ids.shape[0], max_length),					dtype="i4"					)

    UpperCamelCase__ 						=						jnp.broadcast_to(
        jnp.arange(input_ids.shape[-1] - 1					)[None, :],					(input_ids.shape[0], input_ids.shape[-1] - 1),					)
    UpperCamelCase__ 						=						model(
        input_ids[:, :-1],					attention_mask=a_,					past_key_values=a_,					position_ids=a_,					)

    UpperCamelCase__ 						=						jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]],					dtype="i4"					)
    UpperCamelCase__ 						=						model(
        input_ids[:, -1:],					attention_mask=a_,					past_key_values=outputs_cache.past_key_values,					position_ids=a_,					)

    UpperCamelCase__ 						=						model(a_					)

    UpperCamelCase__ 						=						np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])					)					)
    self.parent.assertTrue(diff < 1e-3,					msg=f'Max diff is {diff}'					)

 def 		lowercase_						( self :	Optional[Any],					a_ :	Optional[Any],					a_ :	str,					a_ :	str					):





    """simple docstring"""



    UpperCamelCase__ 						=						20
    UpperCamelCase__ 						=						model_class_name(a_					)

    UpperCamelCase__						,		UpperCamelCase__ 						=						(
        inputs_dict["input_ids"],
        inputs_dict["attention_mask"],
    )

    UpperCamelCase__ 						=						jnp.concatenate(
        [
            attention_mask,
            jnp.zeros((attention_mask.shape[0], max_length - attention_mask.shape[1])					),
        ],					axis=-1,					)

    UpperCamelCase__ 						=						model.init_cache(input_ids.shape[0],					a_					)
    UpperCamelCase__ 						=						jnp.broadcast_to(
        jnp.arange(input_ids.shape[-1] - 1					)[None, :],					(input_ids.shape[0], input_ids.shape[-1] - 1),					)

    UpperCamelCase__ 						=						model(
        input_ids[:, :-1],					attention_mask=a_,					past_key_values=a_,					position_ids=a_,					)
    UpperCamelCase__ 						=						jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]],					dtype="i4"					)
    UpperCamelCase__ 						=						model(
        input_ids[:, -1:],					past_key_values=outputs_cache.past_key_values,					attention_mask=a_,					position_ids=a_,					)

    UpperCamelCase__ 						=						model(a_,					attention_mask=a_					)

    UpperCamelCase__ 						=						np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])					)					)
    self.parent.assertTrue(diff < 1e-3,					msg=f'Max diff is {diff}'					)







@require_flax
class  UpperCAmelCase (       SCREAMING_SNAKE_CASE__		,			unittest.TestCase		,			SCREAMING_SNAKE_CASE__):
 _lowerCamelCase :					str    					=					(FlaxOPTModel, FlaxOPTForCausalLM) if is_flax_available() else ()
 _lowerCamelCase :					Optional[int]    					=					() if is_flax_available() else ()

 def 		lowercase_						( self :	str					):





    """simple docstring"""



    UpperCamelCase__ 						=						FlaxOPTModelTester(self					)

 def 		lowercase_						( self :	Any					):





    """simple docstring"""



    UpperCamelCase__						,		UpperCamelCase__ 						=						self.model_tester.prepare_config_and_inputs()
    for model_class in self.all_model_classes:
       self.model_tester.check_use_cache_forward(a_,					a_,					a_					)

 def 		lowercase_						( self :	Optional[int]					):





    """simple docstring"""



    UpperCamelCase__						,		UpperCamelCase__ 						=						self.model_tester.prepare_config_and_inputs()
    for model_class in self.all_model_classes:
       self.model_tester.check_use_cache_forward_with_attn_mask(a_,					a_,					a_					)

 @slow
 def 		lowercase_						( self :	List[Any]					):





    """simple docstring"""



    for model_class_name in self.all_model_classes:
       UpperCamelCase__ 						=						model_class_name.from_pretrained("facebook/opt-125m"					)
       UpperCamelCase__ 						=						np.ones((1, 1)					) * model.config.eos_token_id
       UpperCamelCase__ 						=						model(a_					)
       self.assertIsNotNone(a_					)







@require_sentencepiece
@require_flax
class  UpperCAmelCase (       unittest.TestCase):

 @slow
 def 		lowercase_						( self :	Dict					):





    """simple docstring"""



    UpperCamelCase__ 						=						FlaxOPTModel.from_pretrained("facebook/opt-350m"					)
    UpperCamelCase__ 						=						jnp.array([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]					)
    UpperCamelCase__ 						=						model(input_ids=a_					).last_hidden_state
    UpperCamelCase__ 						=						(1, 11, 512)
    self.assertEqual(output.shape,					a_					)
    UpperCamelCase__ 						=						jnp.array(
        [[-0.2_867, -1.9_256, -0.3_062], [-1.2_711, -0.1_337, -0.1_897], [0.4_109, 0.1_187, -1.3_142]]					)
    self.assertTrue(jnp.allclose(output[:, :3, :3],					a_,					atol=4e-2					)					)







@require_flax
@slow
class  UpperCAmelCase (       unittest.TestCase):

 def 		lowercase_						( self :	Optional[Any]					):





    """simple docstring"""



    super().setUp()
    UpperCamelCase__ 						=						"facebook/opt-350m"

 def 		lowercase_						( self :	str					):





    """simple docstring"""



    UpperCamelCase__ 						=						FlaxOPTForCausalLM.from_pretrained(self.path_model					)
    UpperCamelCase__ 						=						GPTaTokenizer.from_pretrained(self.path_model					)

    UpperCamelCase__ 						=						[
        "Today is a beautiful day and I want to",
        "In the city of",
        "Paris is the capital of France and",
        "Computers and mobile phones have taken",
    ]
    # verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False
    UpperCamelCase__ 						=						tokenizer(a_,					return_tensors="jax",					padding=a_,					add_special_tokens=a_					)
    UpperCamelCase__ 						=						model(inputs.input_ids,					attention_mask=inputs.attention_mask					)[0].mean(axis=-1					)
    UpperCamelCase__ 						=						jnp.array(
        [
            [1.3_851, -13.8_923, -10.5_229, -10.7_533, -0.2_309, -10.2_384, -0.5_365, -9.0_947, -5.1_670],
            [-4.7_073, -10.6_276, -3.9_415, -21.5_242, -0.2_822, -0.2_822, -0.2_822, -0.2_822, -0.2_822],
            [0.6_247, -3.4_229, -8.9_179, -1.4_297, -14.1_650, 1.4_146, -9.0_218, -0.2_703, -0.2_703],
            [6.4_783, -1.9_913, -10.7_926, -2.3_336, 1.5_092, -0.9_974, -6.8_213, 1.3_477, 1.3_477],
        ]					)
    self.assertTrue(jnp.allclose(a_,					a_,					atol=4e-2					)					)

    UpperCamelCase__ 						=						jax.jit(a_					)
    UpperCamelCase__ 						=						model(inputs.input_ids,					attention_mask=inputs.attention_mask					)[0].mean(axis=-1					)
    self.assertTrue(jnp.allclose(a_,					a_,					atol=4e-2					)					)







@require_flax
@slow
class  UpperCAmelCase (       unittest.TestCase):

 @property
 def 		lowercase_						( self :	Any					):





    """simple docstring"""



    return [
        "Today is a beautiful day and I want",
        "In the city of",
        "Paris is the capital of France and",
        "Computers and mobile phones have taken",
    ]

 def 		lowercase_						( self :	Union[str, Any]					):





    """simple docstring"""



    UpperCamelCase__ 						=						"facebook/opt-125m"

    UpperCamelCase__ 						=						[
        "Today is a beautiful day and I want to",
        "In the city of New York, the city",
        "Paris is the capital of France and the capital",
        "Computers and mobile phones have taken over the",
    ]

    UpperCamelCase__ 						=						[]

    UpperCamelCase__ 						=						FlaxOPTForCausalLM.from_pretrained(a_					)
    UpperCamelCase__ 						=						GPTaTokenizer.from_pretrained(a_					)

    for prompt in self.prompts:
       UpperCamelCase__ 						=						tokenizer(a_,					return_tensors="jax"					).input_ids

       UpperCamelCase__ 						=						model.generate(a_,					max_length=10					)
       UpperCamelCase__ 						=						generated_ids[0]

       UpperCamelCase__ 						=						tokenizer.batch_decode(a_,					skip_special_tokens=a_					)
       predicted_outputs += generated_string

    self.assertListEqual(a_,					a_					)

 def 		lowercase_						( self :	Any					):





    """simple docstring"""



    UpperCamelCase__ 						=						"facebook/opt-350m"

    UpperCamelCase__ 						=						[
        "Today is a beautiful day and I want to",
        "In the city of San Francisco, the city",
        "Paris is the capital of France and the capital",
        "Computers and mobile phones have taken over the",
    ]

    UpperCamelCase__ 						=						[]
    UpperCamelCase__ 						=						FlaxOPTForCausalLM.from_pretrained(a_					)
    UpperCamelCase__ 						=						GPTaTokenizer.from_pretrained(a_					)

    for prompt in self.prompts:
       UpperCamelCase__ 						=						tokenizer(a_,					return_tensors="jax"					).input_ids

       UpperCamelCase__ 						=						model.generate(a_,					max_length=10					)
       UpperCamelCase__ 						=						generated_ids[0]

       UpperCamelCase__ 						=						tokenizer.batch_decode(a_,					skip_special_tokens=a_					)
       predicted_outputs += generated_string

    self.assertListEqual(a_,					a_					)

 def 		lowercase_						( self :	Optional[int]					):





    """simple docstring"""



    UpperCamelCase__ 						=						"facebook/opt-125m"
    UpperCamelCase__ 						=						[
        "Today is a beautiful day and I want to thank",
        "In the city of Rome Canaver Canaver Canaver Canaver",
    ]
    UpperCamelCase__ 						=						FlaxOPTForCausalLM.from_pretrained(a_					)
    UpperCamelCase__ 						=						GPTaTokenizer.from_pretrained(a_					)
    UpperCamelCase__ 						=						tokenizer(
        [
            "Today is a beautiful day and I want to",
            "In the city of",
        ],					return_tensors="jax",					padding=a_,					)

    UpperCamelCase__ 						=						jax.jit(model.generate					)

    UpperCamelCase__ 						=						jit_generate(inputs["input_ids"],					attention_mask=inputs["attention_mask"]					).sequences

    UpperCamelCase__ 						=						tokenizer.batch_decode(a_,					skip_special_tokens=a_					)

    self.assertIsNotNone(a_,					a_					)

 def 		lowercase_						( self :	Any					):





    """simple docstring"""



    UpperCamelCase__ 						=						"facebook/opt-350m"

    UpperCamelCase__ 						=						GPTaTokenizer.from_pretrained(a_					)
    UpperCamelCase__ 						=						FlaxOPTForCausalLM.from_pretrained(a_					)

    UpperCamelCase__ 						=						"left"

    # use different length sentences to test batching
    UpperCamelCase__ 						=						[
        "Hello, my dog is a little",
        "Today, I",
    ]

    UpperCamelCase__ 						=						tokenizer(a_,					return_tensors="jax",					padding=a_					)
    UpperCamelCase__ 						=						inputs["input_ids"]

    UpperCamelCase__ 						=						model.generate(input_ids=a_,					attention_mask=inputs["attention_mask"],					trace=a_					)

    UpperCamelCase__ 						=						tokenizer(sentences[0],					return_tensors="jax"					).input_ids
    UpperCamelCase__ 						=						model.generate(input_ids=a_					)

    UpperCamelCase__ 						=						inputs_non_padded.shape[-1] - inputs["attention_mask"][-1].sum()
    UpperCamelCase__ 						=						tokenizer(sentences[1],					return_tensors="jax"					).input_ids
    UpperCamelCase__ 						=						model.generate(input_ids=a_,					max_length=model.config.max_length - num_paddings					)

    UpperCamelCase__ 						=						tokenizer.batch_decode(outputs[0],					skip_special_tokens=a_					)
    UpperCamelCase__ 						=						tokenizer.decode(output_non_padded[0][0],					skip_special_tokens=a_					)
    UpperCamelCase__ 						=						tokenizer.decode(output_padded[0][0],					skip_special_tokens=a_					)

    UpperCamelCase__ 						=						[
        "Hello, my dog is a little bit of a dork.\nI'm a little bit",
        "Today, I was in the middle of a conversation with a friend about the",
    ]
    self.assertListEqual(a_,					a_					)
    self.assertListEqual(a_,					[non_padded_sentence, padded_sentence]					)



'''simple docstring'''

import os
import sys
from pathlib import Path

import torch

from transformers.testing_utils import TestCasePlus, execute_subprocess_async, require_torch_multi_gpu
from utils import load_json


__lowercase:		Union[str, Any]							=     torch.cuda.is_available()
__lowercase:		str							=     [" Sam ate lunch today.", "Sams lunch ingredients."]
__lowercase:		Optional[Any]							=     ["A very interesting story about what I ate for lunch.", "Avocado, celery, turkey, coffee"]
__lowercase:		Optional[int]							=     {
    "max_tokens_per_batch": None,
    "supervise_forward": True,
    "normalize_hidden": True,
    "label_smoothing": 0.2,
    "eval_max_gen_length": None,
    "eval_beams": 1,
    "val_metric": "loss",
    "save_top_k": 1,
    "adafactor": True,
    "early_stopping_patience": 2,
    "logger_name": "default",
    "length_penalty": 0.5,
    "cache_dir": "",
    "task": "summarization",
    "num_workers": 2,
    "alpha_hid": 0,
    "freeze_embeds": True,
    "enc_only": False,
    "tgt_suffix": "",
    "resume_from_checkpoint": None,
    "sortish_sampler": True,
    "student_decoder_layers": 1,
    "val_check_interval": 1.0,
    "output_dir": "",
    "fp16": False,  # TODO(SS): set this to CUDA_AVAILABLE if ci installs apex or start using native amp
    "no_teacher": False,
    "fp16_opt_level": "O1",
    "gpus": 1 if CUDA_AVAILABLE else 0,
    "n_tpu_cores": 0,
    "max_grad_norm": 1.0,
    "do_train": True,
    "do_predict": True,
    "accumulate_grad_batches": 1,
    "server_ip": "",
    "server_port": "",
    "seed": 42,
    "model_name_or_path": "sshleifer/bart-tiny-random",
    "config_name": "",
    "tokenizer_name": "facebook/bart-large",
    "do_lower_case": False,
    "learning_rate": 0.3,
    "lr_scheduler": "linear",
    "weight_decay": 0.0,
    "adam_epsilon": 1e-0_8,
    "warmup_steps": 0,
    "max_epochs": 1,
    "train_batch_size": 2,
    "eval_batch_size": 2,
    "max_source_length": 12,
    "max_target_length": 12,
    "val_max_target_length": 12,
    "test_max_target_length": 12,
    "fast_dev_run": False,
    "no_cache": False,
    "n_train": -1,
    "n_val": -1,
    "n_test": -1,
    "student_encoder_layers": 1,
    "freeze_encoder": False,
    "auto_scale_batch_size": False,
    "overwrite_output_dir": False,
    "student": None,
}



def        SCREAMING_SNAKE_CASE__(		_UpperCamelCase      :				Path    ,		_UpperCamelCase      :				list   )		->					Optional[Any]:





   '''simple docstring'''







   UpperCamelCase__ 						=						"\n".join(_UpperCamelCase   )
   Path(_UpperCamelCase   ).open("w"   ).writelines(_UpperCamelCase   )



def        SCREAMING_SNAKE_CASE__(		_UpperCamelCase      :				Optional[Any]   )		->					List[str]:





   '''simple docstring'''







   for split in ["train", "val", "test"]:
      _dump_articles(os.path.join(_UpperCamelCase    ,		F'{split}.source'   )    ,		_UpperCamelCase   )
      _dump_articles(os.path.join(_UpperCamelCase    ,		F'{split}.target'   )    ,		_UpperCamelCase   )
   return tmp_dir







class  UpperCAmelCase (       SCREAMING_SNAKE_CASE__):

 @classmethod
 def 		lowercase_						( cls :	List[Any]					):





    """simple docstring"""



    return cls

 @require_torch_multi_gpu
 def 		lowercase_						( self :	List[Any]					):





    """simple docstring"""



    UpperCamelCase__ 						=						{
        "no_teacher": True,
        "freeze_encoder": True,
        "gpus": 2,
        "overwrite_output_dir": True,
        "sortish_sampler": True,
    }
    self._test_distiller_cli_fork(a_,					check_contents=a_					)

 def 		lowercase_						( self :	Tuple,					a_ :	Optional[Any],					a_ :	Optional[int]=True					):





    """simple docstring"""



    UpperCamelCase__ 						=						{
        "label_smoothing": 0.0,
        "early_stopping_patience": -1,
        "train_batch_size": 1,
        "eval_batch_size": 2,
        "max_epochs": 2,
        "alpha_mlm": 0.2,
        "alpha_ce": 0.8,
        "do_predict": True,
        "model_name_or_path": "sshleifer/tinier_bart",
        "teacher": CHEAP_ARGS["model_name_or_path"],
        "val_check_interval": 0.5,
    }
    default_updates.update(a_					)
    UpperCamelCase__ 						=						CHEAP_ARGS.copy()
    UpperCamelCase__ 						=						make_test_data_dir(tmp_dir=self.get_auto_remove_tmp_dir()					)
    UpperCamelCase__ 						=						self.get_auto_remove_tmp_dir()
    args_d.update(data_dir=a_,					output_dir=a_,					**a_					)

    def convert(a_ :	str,					a_ :	Any					):
       if k in ["tgt_suffix", "server_ip", "server_port", "out", "n_tpu_cores"]:
          return ""
       if v is False or v is None:
          return ""
       if v is True:  # or len(str(v))==0:
          return f'--{k}'
       return f'--{k}={v}'

    UpperCamelCase__ 						=						[x for x in (convert(a_,					a_					) for k, v in args_d.items()) if len(a_					)]
    UpperCamelCase__ 						=						[sys.executable, f'{self.test_file_dir}/distillation.py'] + cli_args
    execute_subprocess_async(a_,					env=self.get_env()					)

    UpperCamelCase__ 						=						os.listdir(a_					)
    UpperCamelCase__ 						=						{os.path.basename(a_					) for p in contents}
    UpperCamelCase__ 						=						[p for p in contents if p.endswith("ckpt"					)]
    assert len(a_					) > 0

    self.assertIn("test_generations.txt",					a_					)
    self.assertIn("test_results.txt",					a_					)

    # get the following from the module, (we don't have access to `model` here)
    UpperCamelCase__ 						=						os.path.join(a_,					"metrics.json"					)
    UpperCamelCase__ 						=						"rouge2"

    UpperCamelCase__ 						=						load_json(a_					)
    # {'test': [{'test_avg_loss': 10.63731575012207, 'test_avg_rouge1': 0.0, 'test_avg_rouge2': 0.0, 'test_avg_rougeL': 0.0, 'test_avg_gen_time': 0.1822289228439331, 'test_avg_gen_len': 142.0, 'step_count': 1}]}
    print(a_					)
    UpperCamelCase__ 						=						metrics["val"][-1]
    self.assertGreaterEqual(last_step_stats["val_avg_gen_time"],					0.01					)
    self.assertIsInstance(last_step_stats[f'val_avg_{val_metric}'],					a_					)
    self.assertEqual(len(metrics["test"]					),					1					)
    UpperCamelCase__ 						=						int(args_d["max_epochs"] * (1 / args_d["val_check_interval"]) / 2 + 1					)
    self.assertEqual(len(metrics["val"]					),					a_					)