
from datasets.utils.patching import _PatchedModuleObj, patch_submodule

from . import _test_patching






def  __SCREAMING_SNAKE_CASE				(  ):
							import os as original_os
							from os import path as original_path
							from os import rename as original_rename
							from os.path import dirname as original_dirname
							from os.path import join as original_join

							assert _test_patching.os is original_os
							assert _test_patching.path is original_path
							assert _test_patching.join is original_join

							assert _test_patching.renamed_os is original_os
							assert _test_patching.renamed_path is original_path
							assert _test_patching.renamed_join is original_join

							_snake_case       =  """__test_patch_submodule_mock__"""
							with patch_submodule(_test_patching							, """os.path.join"""							, _SCREAMING_SNAKE_CASE				):
														# Every way to access os.path.join must be patched, and the rest must stay untouched

														# check os.path.join
														assert isinstance(_test_patching.os							, _PatchedModuleObj				)
														assert isinstance(_test_patching.os.path							, _PatchedModuleObj				)
														assert _test_patching.os.path.join is mock

														# check path.join
														assert isinstance(_test_patching.path							, _PatchedModuleObj				)
														assert _test_patching.path.join is mock

														# check join
														assert _test_patching.join is mock

														# check that the other attributes are untouched
														assert _test_patching.os.rename is original_rename
														assert _test_patching.path.dirname is original_dirname
														assert _test_patching.os.path.dirname is original_dirname

														# Even renamed modules or objects must be patched

														# check renamed_os.path.join
														assert isinstance(_test_patching.renamed_os							, _PatchedModuleObj				)
														assert isinstance(_test_patching.renamed_os.path							, _PatchedModuleObj				)
														assert _test_patching.renamed_os.path.join is mock

														# check renamed_path.join
														assert isinstance(_test_patching.renamed_path							, _PatchedModuleObj				)
														assert _test_patching.renamed_path.join is mock

														# check renamed_join
														assert _test_patching.renamed_join is mock

														# check that the other attributes are untouched
														assert _test_patching.renamed_os.rename is original_rename
														assert _test_patching.renamed_path.dirname is original_dirname
														assert _test_patching.renamed_os.path.dirname is original_dirname

							# check that everthing is back to normal when the patch is over

							assert _test_patching.os is original_os
							assert _test_patching.path is original_path
							assert _test_patching.join is original_join

							assert _test_patching.renamed_os is original_os
							assert _test_patching.renamed_path is original_path
							assert _test_patching.renamed_join is original_join






def  __SCREAMING_SNAKE_CASE				(  ):
							assert _test_patching.open is open

							_snake_case       =  """__test_patch_submodule_builtin_mock__"""
							# _test_patching has "open" in its globals
							assert _test_patching.open is open
							with patch_submodule(_test_patching							, """open"""							, _SCREAMING_SNAKE_CASE				):
														assert _test_patching.open is mock

							# check that everthing is back to normal when the patch is over

							assert _test_patching.open is open






def  __SCREAMING_SNAKE_CASE				(  ):
							_snake_case       =  """__test_patch_submodule_missing_mock__"""
							with patch_submodule(_test_patching							, """pandas.read_csv"""							, _SCREAMING_SNAKE_CASE				):
														pass






def  __SCREAMING_SNAKE_CASE				(  ):
							_snake_case       =  """__test_patch_submodule_missing_builtin_mock__"""
							# _test_patching doesn't have "len" in its globals
							assert getattr(_test_patching							, """len"""							, _SCREAMING_SNAKE_CASE				) is None
							with patch_submodule(_test_patching							, """len"""							, _SCREAMING_SNAKE_CASE				):
														assert _test_patching.len is mock
							assert _test_patching.len is len






def  __SCREAMING_SNAKE_CASE				(  ):
							_snake_case       =  """__test_patch_submodule_start_and_stop_mock__"""
							_snake_case       =  patch_submodule(_test_patching							, """open"""							, _SCREAMING_SNAKE_CASE				)
							assert _test_patching.open is open
							patch.start()
							assert _test_patching.open is mock
							patch.stop()
							assert _test_patching.open is open






def  __SCREAMING_SNAKE_CASE				(  ):
							from os import rename as original_rename
							from os.path import dirname as original_dirname
							from os.path import join as original_join

							_snake_case       =  """__test_patch_submodule_successive_join__"""
							_snake_case       =  """__test_patch_submodule_successive_dirname__"""
							_snake_case       =  """__test_patch_submodule_successive_rename__"""
							assert _test_patching.os.path.join is original_join
							assert _test_patching.os.path.dirname is original_dirname
							assert _test_patching.os.rename is original_rename

							with patch_submodule(_test_patching							, """os.path.join"""							, _SCREAMING_SNAKE_CASE				):
														with patch_submodule(_test_patching							, """os.rename"""							, _SCREAMING_SNAKE_CASE				):
																					with patch_submodule(_test_patching							, """os.path.dirname"""							, _SCREAMING_SNAKE_CASE				):
																												assert _test_patching.os.path.join is mock_join
																												assert _test_patching.os.path.dirname is mock_dirname
																												assert _test_patching.os.rename is mock_rename

    # try another order
							with patch_submodule(_test_patching							, """os.rename"""							, _SCREAMING_SNAKE_CASE				):
														with patch_submodule(_test_patching							, """os.path.join"""							, _SCREAMING_SNAKE_CASE				):
																					with patch_submodule(_test_patching							, """os.path.dirname"""							, _SCREAMING_SNAKE_CASE				):
																												assert _test_patching.os.path.join is mock_join
																												assert _test_patching.os.path.dirname is mock_dirname
																												assert _test_patching.os.rename is mock_rename

							assert _test_patching.os.path.join is original_join
							assert _test_patching.os.path.dirname is original_dirname
							assert _test_patching.os.rename is original_rename






def  __SCREAMING_SNAKE_CASE				(  ):
							_snake_case       =  """__test_patch_submodule_doesnt_exist_mock__"""
							with patch_submodule(_test_patching							, """__module_that_doesn_exist__.__attribute_that_doesn_exist__"""							, _SCREAMING_SNAKE_CASE				):
														pass
							with patch_submodule(_test_patching							, """os.__attribute_that_doesn_exist__"""							, _SCREAMING_SNAKE_CASE				):
														pass

'''simple docstring'''
import inspect
import tempfile
import unittest

from huggingface_hub import hf_hub_download

from transformers import is_torch_available
from transformers.testing_utils import is_flaky, require_torch, slow, torch_device

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


__lowerCAmelCase												=	1E-4

if is_torch_available():
				import torch

				from transformers import AutoformerConfig, AutoformerForPrediction, AutoformerModel
				from transformers.models.autoformer.modeling_autoformer import AutoformerDecoder, AutoformerEncoder


@require_torch
class       _lowerCAmelCase   :







							'''simple docstring'''

							def __init__(self  ,  UpperCAmelCase  ,  UpperCAmelCase=16  ,  UpperCAmelCase=13  ,  UpperCAmelCase=7  ,  UpperCAmelCase=14  ,  UpperCAmelCase=10  ,  UpperCAmelCase=19  ,  UpperCAmelCase=5  ,  UpperCAmelCase=4  ,  UpperCAmelCase=True  ,  UpperCAmelCase=16  ,  UpperCAmelCase=2  ,  UpperCAmelCase=4  ,  UpperCAmelCase=4  ,  UpperCAmelCase="gelu"  ,  UpperCAmelCase=0.1  ,  UpperCAmelCase=0.1  ,  UpperCAmelCase=[1, 2, 3, 4, 5]  ,  UpperCAmelCase=25  ,  UpperCAmelCase=5  ,  )					->       int:
														_snake_case       =  d_model
														_snake_case       =  parent
														_snake_case       =  batch_size
														_snake_case       =  prediction_length
														_snake_case       =  context_length
														_snake_case       =  cardinality
														_snake_case       =  num_time_features
														_snake_case       =  lags_sequence
														_snake_case       =  embedding_dimension
														_snake_case       =  is_training
														_snake_case       =  hidden_size
														_snake_case       =  num_hidden_layers
														_snake_case       =  num_attention_heads
														_snake_case       =  intermediate_size
														_snake_case       =  hidden_act
														_snake_case       =  hidden_dropout_prob
														_snake_case       =  attention_probs_dropout_prob

														_snake_case       =  context_length
														_snake_case       =  prediction_length + label_length
														_snake_case       =  label_length

														_snake_case       =  moving_average
														_snake_case       =  autocorrelation_factor

							def 	lowercase							(self  )					->       str:
														return AutoformerConfig(
														    d_model=self.d_model  ,  encoder_layers=self.num_hidden_layers  ,  decoder_layers=self.num_hidden_layers  ,  encoder_attention_heads=self.num_attention_heads  ,  decoder_attention_heads=self.num_attention_heads  ,  encoder_ffn_dim=self.intermediate_size  ,  decoder_ffn_dim=self.intermediate_size  ,  dropout=self.hidden_dropout_prob  ,  attention_dropout=self.attention_probs_dropout_prob  ,  prediction_length=self.prediction_length  ,  context_length=self.context_length  ,  label_length=self.label_length  ,  lags_sequence=self.lags_sequence  ,  num_time_features=self.num_time_features  ,  num_static_categorical_features=1  ,  cardinality=[self.cardinality]  ,  embedding_dimension=[self.embedding_dimension]  ,  moving_average=self.moving_average  ,  )

							def 	lowercase							(self  ,  UpperCAmelCase  )					->       Tuple:
														_snake_case       =  config.context_length + max(config.lags_sequence  )

														_snake_case       =  ids_tensor([self.batch_size, 1]  ,  config.cardinality[0]  )
														_snake_case       =  floats_tensor([self.batch_size, _past_length, config.num_time_features]  )
														_snake_case       =  floats_tensor([self.batch_size, _past_length]  )
														_snake_case       =  floats_tensor([self.batch_size, _past_length]  ) > 0.5

														# decoder inputs
														_snake_case       =  floats_tensor([self.batch_size, config.prediction_length, config.num_time_features]  )
														_snake_case       =  floats_tensor([self.batch_size, config.prediction_length]  )

														_snake_case       =  {
														    """past_values""": past_values,
														    """static_categorical_features""": static_categorical_features,
														    """past_time_features""": past_time_features,
														    """past_observed_mask""": past_observed_mask,
														    """future_time_features""": future_time_features,
														    """future_values""": future_values,
														}
														return inputs_dict

							def 	lowercase							(self  )					->       int:
														_snake_case       =  self.get_config()
														_snake_case       =  self.prepare_autoformer_inputs_dict(UpperCAmelCase  )
														return config, inputs_dict

							def 	lowercase							(self  )					->       List[Any]:
														_snake_case,							_snake_case       =  self.prepare_config_and_inputs()
														return config, inputs_dict





							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  )					->       Tuple:
														_snake_case       =  AutoformerModel(config=UpperCAmelCase  ).to(UpperCAmelCase  ).eval()
														_snake_case       =  model(**UpperCAmelCase  )

														_snake_case       =  outputs.encoder_last_hidden_state
														_snake_case       =  outputs.last_hidden_state

														with tempfile.TemporaryDirectory() as tmpdirname:
																					_snake_case       =  model.get_encoder()
																					encoder.save_pretrained(UpperCAmelCase  )
																					_snake_case       =  AutoformerEncoder.from_pretrained(UpperCAmelCase  ).to(UpperCAmelCase  )

														_snake_case,							_snake_case,							_snake_case,							_snake_case,							_snake_case       =  model.create_network_inputs(**UpperCAmelCase  )
														_snake_case,							_snake_case       =  model.decomposition_layer(transformer_inputs[:, : config.context_length, ...]  )

														_snake_case       =  torch.cat(
														    (transformer_inputs[:, : config.context_length, ...], feature[:, : config.context_length, ...])  ,  dim=-1  ,  )
														_snake_case       =  encoder(inputs_embeds=UpperCAmelCase  )[0]
														self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1e-3  )

														_snake_case       =  (
														    torch.mean(transformer_inputs[:, : config.context_length, ...]  ,  dim=1  )
														    .unsqueeze(1  )
														    .repeat(1  ,  config.prediction_length  ,  1  )
														)
														_snake_case       =  torch.zeros(
														    [transformer_inputs.shape[0], config.prediction_length, transformer_inputs.shape[2]]  ,  device=enc_input.device  ,  )

														_snake_case       =  torch.cat(
														    (
														        torch.cat((seasonal_input[:, -config.label_length :, ...], zeros)  ,  dim=1  ),
														        feature[:, config.context_length - config.label_length :, ...],
														    )  ,  dim=-1  ,  )
														_snake_case       =  torch.cat(
														    (
														        torch.cat((trend_input[:, -config.label_length :, ...], mean)  ,  dim=1  ),
														        feature[:, config.context_length - config.label_length :, ...],
														    )  ,  dim=-1  ,  )

														with tempfile.TemporaryDirectory() as tmpdirname:
																					_snake_case       =  model.get_decoder()
																					decoder.save_pretrained(UpperCAmelCase  )
																					_snake_case       =  AutoformerDecoder.from_pretrained(UpperCAmelCase  ).to(UpperCAmelCase  )

														_snake_case       =  decoder(
														    trend=UpperCAmelCase  ,  inputs_embeds=UpperCAmelCase  ,  encoder_hidden_states=UpperCAmelCase  ,  )[0]

														self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1e-3  )


@require_torch
class       _lowerCAmelCase   (   __snake_case					,							__snake_case					,							unittest.TestCase				):







							'''simple docstring'''

							lowerCAmelCase_ 						=						(AutoformerModel, AutoformerForPrediction) if is_torch_available() else ()
							lowerCAmelCase_ 						=						(AutoformerForPrediction,) if is_torch_available() else ()
							lowerCAmelCase_ 						=						{"feature-extraction": AutoformerModel} if is_torch_available() else {}
							lowerCAmelCase_ 						=						False
							lowerCAmelCase_ 						=						False
							lowerCAmelCase_ 						=						False
							lowerCAmelCase_ 						=						False
							lowerCAmelCase_ 						=						False
							lowerCAmelCase_ 						=						False

							def 	lowercase							(self  )					->       List[Any]:
														_snake_case       =  AutoformerModelTester(self  )
														_snake_case       =  ConfigTester(self  ,  config_class=UpperCAmelCase  ,  has_text_modality=UpperCAmelCase  )

							def 	lowercase							(self  )					->       List[Any]:
														self.config_tester.run_common_tests()

							def 	lowercase							(self  )					->       Any:
														_snake_case,							_snake_case       =  self.model_tester.prepare_config_and_inputs()
														for model_class in self.all_model_classes:
																					_snake_case       =  model_class(UpperCAmelCase  )

																					with tempfile.TemporaryDirectory() as tmpdirname:
																												model.save_pretrained(UpperCAmelCase  )
																												_snake_case,							_snake_case       =  model_class.from_pretrained(UpperCAmelCase  ,  output_loading_info=UpperCAmelCase  )
																					self.assertEqual(info["""missing_keys"""]  ,  []  )

							def 	lowercase							(self  )					->       List[Any]:
														_snake_case       =  self.model_tester.prepare_config_and_inputs_for_common()
														self.model_tester.check_encoder_decoder_model_standalone(*UpperCAmelCase  )

							@unittest.skip(reason="""Model has no tokens embeddings"""  )
							def 	lowercase							(self  )					->       Tuple:
														pass

							def 	lowercase							(self  )					->       Any:
														_snake_case       =  inspect.signature(getattr(UpperCAmelCase  ,  """forward"""  )  )
														# The main input is the name of the argument after `self`
														_snake_case       =  list(model_signature.parameters.keys()  )[1]
														self.assertEqual(AutoformerModel.main_input_name  ,  UpperCAmelCase  )

							def 	lowercase							(self  )					->       List[Any]:
														_snake_case,							_snake_case       =  self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					_snake_case       =  model_class(UpperCAmelCase  )
																					_snake_case       =  inspect.signature(model.forward  )
																					# signature.parameters is an OrderedDict => so arg_names order is deterministic
																					_snake_case       =  [*signature.parameters.keys()]

																					_snake_case       =  [
																					    """past_values""",
																					    """past_time_features""",
																					    """past_observed_mask""",
																					    """static_categorical_features""",
																					    """static_real_features""",
																					    """future_values""",
																					    """future_time_features""",
																					]

																					if model.__class__.__name__ in ["AutoformerForPrediction"]:
																												expected_arg_names.append("""future_observed_mask"""  )

																					expected_arg_names.extend(
																					    [
																					        """decoder_attention_mask""",
																					        """head_mask""",
																					        """decoder_head_mask""",
																					        """cross_attn_head_mask""",
																					        """encoder_outputs""",
																					        """past_key_values""",
																					        """output_hidden_states""",
																					        """output_attentions""",
																					        """use_cache""",
																					        """return_dict""",
																					    ]  )

																					self.assertListEqual(arg_names[: len(UpperCAmelCase  )]  ,  UpperCAmelCase  )

							def 	lowercase							(self  )					->       List[Any]:
														_snake_case,							_snake_case       =  self.model_tester.prepare_config_and_inputs_for_common()
														_snake_case       =  True

														_snake_case       =  getattr(self.model_tester  ,  """seq_length"""  ,  UpperCAmelCase  )
														_snake_case       =  getattr(self.model_tester  ,  """decoder_seq_length"""  ,  UpperCAmelCase  )
														_snake_case       =  getattr(self.model_tester  ,  """encoder_seq_length"""  ,  UpperCAmelCase  )
														_snake_case       =  getattr(self.model_tester  ,  """d_model"""  ,  UpperCAmelCase  )
														_snake_case       =  getattr(self.model_tester  ,  """num_attention_heads"""  ,  UpperCAmelCase  )
														_snake_case       =  d_model // num_attention_heads

														for model_class in self.all_model_classes:
																					_snake_case       =  True
																					_snake_case       =  False
																					_snake_case       =  True
																					_snake_case       =  model_class(UpperCAmelCase  )
																					model.to(UpperCAmelCase  )
																					model.eval()
																					with torch.no_grad():
																												_snake_case       =  model(**self._prepare_for_class(UpperCAmelCase  ,  UpperCAmelCase  )  )
																					_snake_case       =  outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
																					self.assertEqual(len(UpperCAmelCase  )  ,  self.model_tester.num_hidden_layers  )

																					# check that output_attentions also work using config
																					del inputs_dict["output_attentions"]
																					_snake_case       =  True
																					_snake_case       =  model_class(UpperCAmelCase  )
																					model.to(UpperCAmelCase  )
																					model.eval()
																					with torch.no_grad():
																												_snake_case       =  model(**self._prepare_for_class(UpperCAmelCase  ,  UpperCAmelCase  )  )
																					_snake_case       =  outputs.encoder_attentions
																					self.assertEqual(len(UpperCAmelCase  )  ,  self.model_tester.num_hidden_layers  )

																					self.assertListEqual(
																					    list(attentions[0].shape[-3:]  )  ,  [self.model_tester.num_attention_heads, encoder_seq_length, dim]  ,  )
																					_snake_case       =  len(UpperCAmelCase  )

																					_snake_case       =  7

																					if "last_hidden_state" in outputs:
																												correct_outlen += 1

																					if "trend" in outputs:
																												correct_outlen += 1

																					if "past_key_values" in outputs:
																												correct_outlen += 1  # past_key_values have been returned

																					if "loss" in outputs:
																												correct_outlen += 1

																					if "params" in outputs:
																												correct_outlen += 1

																					self.assertEqual(UpperCAmelCase  ,  UpperCAmelCase  )

																					# decoder attentions
																					_snake_case       =  outputs.decoder_attentions
																					self.assertIsInstance(UpperCAmelCase  ,  (list, tuple)  )
																					self.assertEqual(len(UpperCAmelCase  )  ,  self.model_tester.num_hidden_layers  )
																					self.assertListEqual(
																					    list(decoder_attentions[0].shape[-3:]  )  ,  [self.model_tester.num_attention_heads, decoder_seq_length, dim]  ,  )

																					# cross attentions
																					_snake_case       =  outputs.cross_attentions
																					self.assertIsInstance(UpperCAmelCase  ,  (list, tuple)  )
																					self.assertEqual(len(UpperCAmelCase  )  ,  self.model_tester.num_hidden_layers  )
																					self.assertListEqual(
																					    list(cross_attentions[0].shape[-3:]  )  ,  [self.model_tester.num_attention_heads, decoder_seq_length, dim]  ,  )

														# Check attention is always last and order is fine
														_snake_case       =  True
														_snake_case       =  True
														_snake_case       =  model_class(UpperCAmelCase  )
														model.to(UpperCAmelCase  )
														model.eval()
														with torch.no_grad():
																					_snake_case       =  model(**self._prepare_for_class(UpperCAmelCase  ,  UpperCAmelCase  )  )

														self.assertEqual(out_len + 2  ,  len(UpperCAmelCase  )  )

														_snake_case       =  outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions

														self.assertEqual(len(UpperCAmelCase  )  ,  self.model_tester.num_hidden_layers  )
														self.assertListEqual(
														    list(self_attentions[0].shape[-3:]  )  ,  [self.model_tester.num_attention_heads, encoder_seq_length, dim]  ,  )





							@is_flaky()
							def 	lowercase							(self  )					->       List[Any]:
														super().test_retain_grad_hidden_states_attentions()






def  __SCREAMING_SNAKE_CASE				(  _SCREAMING_SNAKE_CASE="train-batch.pt"				):
							_snake_case       =  hf_hub_download(repo_id="""hf-internal-testing/tourism-monthly-batch"""							, filename=_SCREAMING_SNAKE_CASE							, repo_type="""dataset"""				)
							_snake_case       =  torch.load(_SCREAMING_SNAKE_CASE							, map_location=_SCREAMING_SNAKE_CASE				)
							return batch


@require_torch
@slow
class       _lowerCAmelCase   (   unittest.TestCase				):







							'''simple docstring'''

							def 	lowercase							(self  )					->       Union[str, Any]:
														_snake_case       =  AutoformerModel.from_pretrained("""huggingface/autoformer-tourism-monthly"""  ).to(UpperCAmelCase  )
														_snake_case       =  prepare_batch()

														with torch.no_grad():
																					_snake_case       =  model(
																					    past_values=batch["""past_values"""]  ,  past_time_features=batch["""past_time_features"""]  ,  past_observed_mask=batch["""past_observed_mask"""]  ,  static_categorical_features=batch["""static_categorical_features"""]  ,  future_values=batch["""future_values"""]  ,  future_time_features=batch["""future_time_features"""]  ,  )[0]

														_snake_case       =  torch.Size(
														    (64, model.config.prediction_length + model.config.label_length, model.config.feature_size)  )
														self.assertEqual(output.shape  ,  UpperCAmelCase  )

														_snake_case       =  torch.tensor(
														    [[0.3593, -1.3398, 0.6330], [0.2279, 1.5396, -0.1792], [0.0450, 1.3225, -0.2335]]  ,  device=UpperCAmelCase  )
														self.assertTrue(torch.allclose(output[0, :3, :3]  ,  UpperCAmelCase  ,  atol=UpperCAmelCase  )  )

							def 	lowercase							(self  )					->       str:
														_snake_case       =  AutoformerForPrediction.from_pretrained("""huggingface/autoformer-tourism-monthly"""  ).to(UpperCAmelCase  )
														_snake_case       =  prepare_batch("""val-batch.pt"""  )
														with torch.no_grad():
																					_snake_case       =  model(
																					    past_values=batch["""past_values"""]  ,  past_time_features=batch["""past_time_features"""]  ,  past_observed_mask=batch["""past_observed_mask"""]  ,  static_categorical_features=batch["""static_categorical_features"""]  ,  ).encoder_last_hidden_state
														_snake_case       =  torch.Size((64, model.config.context_length, model.config.d_model)  )
														self.assertEqual(output.shape  ,  UpperCAmelCase  )

														_snake_case       =  torch.tensor(
														    [[-0.0734, -0.9036, 0.8358], [4.7186, 2.4113, 1.9581], [1.7953, 2.3558, 1.2970]]  ,  device=UpperCAmelCase  )
														self.assertTrue(torch.allclose(output[0, :3, :3]  ,  UpperCAmelCase  ,  atol=UpperCAmelCase  )  )





							def 	lowercase							(self  )					->       Optional[int]:
														_snake_case       =  AutoformerForPrediction.from_pretrained("""huggingface/autoformer-tourism-monthly"""  ).to(UpperCAmelCase  )
														_snake_case       =  prepare_batch("""val-batch.pt"""  )
														with torch.no_grad():
																					_snake_case       =  model.generate(
																					    static_categorical_features=batch["""static_categorical_features"""]  ,  past_time_features=batch["""past_time_features"""]  ,  past_values=batch["""past_values"""]  ,  future_time_features=batch["""future_time_features"""]  ,  past_observed_mask=batch["""past_observed_mask"""]  ,  )
														_snake_case       =  torch.Size((64, model.config.num_parallel_samples, model.config.prediction_length)  )
														self.assertEqual(outputs.sequences.shape  ,  UpperCAmelCase  )

														_snake_case       =  torch.tensor([3130.6763, 4056.5293, 7053.0786]  ,  device=UpperCAmelCase  )
														_snake_case       =  outputs.sequences.mean(dim=1  )
														self.assertTrue(torch.allclose(mean_prediction[0, -3:]  ,  UpperCAmelCase  ,  rtol=1e-1  )  )