





import math
import unittest

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

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    BioGptForCausalLM,
					    BioGptForSequenceClassification,
					    BioGptForTokenClassification,
					    BioGptModel,
					    BioGptTokenizer,
					)
					from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST


class   A			:
			'''simple docstring'''




			def __init__(			self   :    List[Any]							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    Union[str, Any]=13							,	__lowerCAmelCase   :    Any=7							,	__lowerCAmelCase   :    Optional[int]=True							,	__lowerCAmelCase   :    int=True							,	__lowerCAmelCase   :    Union[str, Any]=False							,	__lowerCAmelCase   :    Dict=True							,	__lowerCAmelCase   :    Dict=99							,	__lowerCAmelCase   :    List[Any]=32							,	__lowerCAmelCase   :    Tuple=5							,	__lowerCAmelCase   :    Tuple=4							,	__lowerCAmelCase   :    str=37							,	__lowerCAmelCase   :    Dict="gelu"							,	__lowerCAmelCase   :    str=0.1							,	__lowerCAmelCase   :    Any=0.1							,	__lowerCAmelCase   :    Any=5_12							,	__lowerCAmelCase   :    int=16							,	__lowerCAmelCase   :    str=2							,	__lowerCAmelCase   :    int=0.0_2							,	__lowerCAmelCase   :    List[str]=3							,	__lowerCAmelCase   :    Union[str, Any]=4							,	__lowerCAmelCase   :    Any=None							,	)	->	Optional[Any]:







					"""simple docstring"""






					A__        =   parent
					A__        =   batch_size
					A__        =   seq_length
					A__        =   is_training
					A__        =   use_input_mask
					A__        =   use_token_type_ids
					A__        =   use_labels
					A__        =   vocab_size
					A__        =   hidden_size
					A__        =   num_hidden_layers
					A__        =   num_attention_heads
					A__        =   intermediate_size
					A__        =   hidden_act
					A__        =   hidden_dropout_prob
					A__        =   attention_probs_dropout_prob
					A__        =   max_position_embeddings
					A__        =   type_vocab_size
					A__        =   type_sequence_label_size
					A__        =   initializer_range
					A__        =   num_labels
					A__        =   num_choices
					A__        =   scope






			def    a_       (			self   :    List[str]   )	->	List[Any]:







					"""simple docstring"""






					A__        =   ids_tensor([self.batch_size, self.seq_length]							,	self.vocab_size   )

					A__        =   None
					if self.use_input_mask:
							A__        =   random_attention_mask([self.batch_size, self.seq_length]   )

					A__        =   None
					if self.use_token_type_ids:
							A__        =   ids_tensor([self.batch_size, self.seq_length]							,	self.type_vocab_size   )

					A__        =   None
					A__        =   None
					A__        =   None
					if self.use_labels:
							A__        =   ids_tensor([self.batch_size]							,	self.type_sequence_label_size   )
							A__        =   ids_tensor([self.batch_size, self.seq_length]							,	self.num_labels   )
							A__        =   ids_tensor([self.batch_size]							,	self.num_choices   )

					A__        =   self.get_config()

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






			def    a_       (			self   :    Optional[int]   )	->	Optional[Any]:







					"""simple docstring"""






					return BioGptConfig(
					    vocab_size=self.vocab_size							,	hidden_size=self.hidden_size							,	num_hidden_layers=self.num_hidden_layers							,	num_attention_heads=self.num_attention_heads							,	intermediate_size=self.intermediate_size							,	hidden_act=self.hidden_act							,	hidden_dropout_prob=self.hidden_dropout_prob							,	attention_probs_dropout_prob=self.attention_probs_dropout_prob							,	max_position_embeddings=self.max_position_embeddings							,	type_vocab_size=self.type_vocab_size							,	is_decoder=__lowerCAmelCase							,	initializer_range=self.initializer_range							,	)






			def    a_       (			self   :    int							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    Optional[Any]							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    Optional[Any]							,	__lowerCAmelCase   :    List[str]   )	->	Dict:







					"""simple docstring"""






					A__        =   BioGptModel(config=__lowerCAmelCase   )
					model.to(__lowerCAmelCase   )
					model.eval()
					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase   )
					A__        =   model(__lowerCAmelCase   )
					self.parent.assertEqual(result.last_hidden_state.shape							,	(self.batch_size, self.seq_length, self.hidden_size)   )






			def    a_       (			self   :    Tuple							,	__lowerCAmelCase   :    Dict							,	__lowerCAmelCase   :    Dict							,	__lowerCAmelCase   :    Dict							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    Tuple							,	__lowerCAmelCase   :    int							,	__lowerCAmelCase   :    List[str]							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    List[Any]							,	)	->	Union[str, Any]:







					"""simple docstring"""






					A__        =   BioGptForCausalLM(config=__lowerCAmelCase   )
					model.to(__lowerCAmelCase   )
					model.eval()
					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase							,	token_type_ids=__lowerCAmelCase							,	labels=__lowerCAmelCase   )
					self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.seq_length, self.vocab_size)   )






			def    a_       (			self   :    List[Any]							,	__lowerCAmelCase   :    Optional[Any]							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    int							,	__lowerCAmelCase   :    Tuple							,	__lowerCAmelCase   :    Optional[int]							,	*__lowerCAmelCase   :    str   )	->	List[Any]:







					"""simple docstring"""






					A__        =   BioGptModel(config=__lowerCAmelCase   )
					model.to(__lowerCAmelCase   )
					model.eval()

					# create attention mask
					A__        =   torch.ones(input_ids.shape							,	dtype=torch.long							,	device=__lowerCAmelCase   )
					A__        =   self.seq_length // 2
					A__        =   0

					# first forward pass
					A__      ,			A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase   ).to_tuple()

					# create hypothetical next token and extent to next_input_ids
					A__        =   ids_tensor((self.batch_size, 1)							,	config.vocab_size   )

					# change a random masked slice from input_ids
					A__        =   ids_tensor((1,)							,	__lowerCAmelCase   ).item() + 1
					A__        =   ids_tensor((self.batch_size, 1)							,	config.vocab_size   ).squeeze(-1   )
					A__        =   random_other_next_tokens

					# append to next input_ids and attn_mask
					A__        =   torch.cat([input_ids, next_tokens]							,	dim=-1   )
					A__        =   torch.cat(
					    [attn_mask, torch.ones((attn_mask.shape[0], 1)							,	dtype=torch.long							,	device=__lowerCAmelCase   )]							,	dim=1							,	)

					# get two different outputs
					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase   )["""last_hidden_state"""]
					A__        =   model(__lowerCAmelCase							,	past_key_values=__lowerCAmelCase							,	attention_mask=__lowerCAmelCase   )["""last_hidden_state"""]

					# select random slice
					A__        =   ids_tensor((1,)							,	output_from_past.shape[-1]   ).item()
					A__        =   output_from_no_past[:, -1, random_slice_idx].detach()
					A__        =   output_from_past[:, 0, random_slice_idx].detach()

					# test that outputs are equal for slice
					self.parent.assertTrue(torch.allclose(__lowerCAmelCase							,	__lowerCAmelCase							,	atol=1e-3   )   )






			def    a_       (			self   :    int							,	__lowerCAmelCase   :    Union[str, Any]							,	__lowerCAmelCase   :    str							,	__lowerCAmelCase   :    List[Any]							,	__lowerCAmelCase   :    Optional[Any]							,	__lowerCAmelCase   :    Optional[Any]							,	*__lowerCAmelCase   :    Any   )	->	List[Any]:







					"""simple docstring"""






					A__        =   BioGptModel(config=__lowerCAmelCase   ).to(__lowerCAmelCase   ).eval()

					A__        =   torch.ones(input_ids.shape							,	dtype=torch.long							,	device=__lowerCAmelCase   )

					# first forward pass
					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase							,	use_cache=__lowerCAmelCase   )

					A__      ,			A__        =   outputs.to_tuple()

					# create hypothetical multiple next token and extent to next_input_ids
					A__        =   ids_tensor((self.batch_size, 3)							,	config.vocab_size   )
					A__        =   ids_tensor((self.batch_size, 3)							,	2   )

					# append to next input_ids and
					A__        =   torch.cat([input_ids, next_tokens]							,	dim=-1   )
					A__        =   torch.cat([attention_mask, next_attn_mask]							,	dim=-1   )

					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase   )["""last_hidden_state"""]
					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase							,	past_key_values=__lowerCAmelCase   )[
					    """last_hidden_state"""
					]

					# select random slice
					A__        =   ids_tensor((1,)							,	output_from_past.shape[-1]   ).item()
					A__        =   output_from_no_past[:, -3:, random_slice_idx].detach()
					A__        =   output_from_past[:, :, random_slice_idx].detach()

					self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]   )

					# test that outputs are equal for slice
					self.parent.assertTrue(torch.allclose(__lowerCAmelCase							,	__lowerCAmelCase							,	atol=1e-3   )   )






			def    a_       (			self   :    int							,	__lowerCAmelCase   :    List[Any]							,	__lowerCAmelCase   :    str							,	__lowerCAmelCase   :    Optional[Any]							,	__lowerCAmelCase   :    Optional[Any]							,	__lowerCAmelCase   :    Optional[Any]							,	*__lowerCAmelCase   :    List[Any]							,	__lowerCAmelCase   :    List[Any]=False   )	->	Dict:







					"""simple docstring"""






					A__        =   BioGptForCausalLM(__lowerCAmelCase   )
					model.to(__lowerCAmelCase   )
					if gradient_checkpointing:
							model.gradient_checkpointing_enable()

					A__        =   model(__lowerCAmelCase							,	labels=__lowerCAmelCase   )
					self.parent.assertEqual(result.loss.shape							,	()   )
					self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.seq_length, self.vocab_size)   )
					result.loss.backward()






			def    a_       (			self   :    Optional[Any]							,	__lowerCAmelCase   :    Union[str, Any]							,	*__lowerCAmelCase   :    str   )	->	str:







					"""simple docstring"""






					A__        =   BioGptModel(__lowerCAmelCase   )
					A__        =   model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers   )
					for key in model.state_dict().keys():
							if "c_proj" in key and "weight" in key:
									self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key]   ) - model_std   )							,	0.0_0_1   )
									self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]   ) - 0.0   )							,	0.0_1   )






			def    a_       (			self   :    str							,	__lowerCAmelCase   :    Any							,	__lowerCAmelCase   :    Optional[Any]							,	__lowerCAmelCase   :    Optional[Any]							,	__lowerCAmelCase   :    List[str]							,	__lowerCAmelCase   :    Optional[Any]							,	*__lowerCAmelCase   :    Union[str, Any]   )	->	Dict:







					"""simple docstring"""






					A__        =   self.num_labels
					A__        =   BioGptForTokenClassification(__lowerCAmelCase   )
					model.to(__lowerCAmelCase   )
					model.eval()
					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase							,	token_type_ids=__lowerCAmelCase   )
					self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.seq_length, self.num_labels)   )







			def    a_       (			self   :    Any   )	->	Any:







					"""simple docstring"""






					A__        =   self.prepare_config_and_inputs()
					(
					    (
					    A__
					)      ,			(
					    A__
					)      ,			(
					    A__
					)      ,			(
					    A__
					)      ,			(
					    A__
					)      ,			(
					    A__
					)      ,			(
					    A__
					)      ,			
					)        =   config_and_inputs
					A__        =   {"""input_ids""": input_ids, """attention_mask""": input_mask}
					return config, inputs_dict


@require_torch
class   A			(SCREAMING_SNAKE_CASE   ,     SCREAMING_SNAKE_CASE   ,     SCREAMING_SNAKE_CASE   ,     unittest.TestCase    ):
			'''simple docstring'''




			__lowerCamelCase	:       Optional[int]							=    (
			    (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
			    if is_torch_available()
			    else ()
			)
			__lowerCamelCase	:       Dict							=    (BioGptForCausalLM,) if is_torch_available() else ()
			__lowerCamelCase	:       List[str]							=    (
			    {
			        '''feature-extraction''': BioGptModel,
			        '''text-classification''': BioGptForSequenceClassification,
			        '''text-generation''': BioGptForCausalLM,
			        '''token-classification''': BioGptForTokenClassification,
			        '''zero-shot''': BioGptForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			__lowerCamelCase	:       List[Any]							=    False






			def    a_       (			self   :    int   )	->	Union[str, Any]:







					"""simple docstring"""






					A__        =   BioGptModelTester(self   )
					A__        =   ConfigTester(self							,	config_class=__lowerCAmelCase							,	hidden_size=37   )






			def    a_       (			self   :    List[str]   )	->	int:







					"""simple docstring"""






					self.config_tester.run_common_tests()






			def    a_       (			self   :    Tuple   )	->	Optional[Any]:







					"""simple docstring"""






					A__        =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__lowerCAmelCase   )






			def    a_       (			self   :    List[Any]   )	->	List[str]:







					"""simple docstring"""






					A__        =   self.model_tester.prepare_config_and_inputs()
					for type in ["absolute", "relative_key", "relative_key_query"]:
							A__        =   type
							self.model_tester.create_and_check_model(*__lowerCAmelCase   )






			def    a_       (			self   :    int   )	->	Tuple:







					"""simple docstring"""






					A__        =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_biogpt_model_attention_mask_past(*__lowerCAmelCase   )






			def    a_       (			self   :    int   )	->	List[str]:







					"""simple docstring"""






					A__        =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_forward_and_backwards(*__lowerCAmelCase							,	gradient_checkpointing=__lowerCAmelCase   )






			def    a_       (			self   :    List[Any]   )	->	Dict:







					"""simple docstring"""






					A__        =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_biogpt_model_past_large_inputs(*__lowerCAmelCase   )






			def    a_       (			self   :    Union[str, Any]   )	->	Optional[int]:







					"""simple docstring"""






					A__        =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_biogpt_weight_initialization(*__lowerCAmelCase   )






			def    a_       (			self   :    Tuple   )	->	Optional[Any]:







					"""simple docstring"""






					A__        =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_biogpt_for_token_classification(*__lowerCAmelCase   )






			@slow
			def    a_       (			self   :    List[Any]   )	->	Union[str, Any]:







					"""simple docstring"""






					A__        =   BioGptForCausalLM.from_pretrained("""microsoft/biogpt"""   )
					model.to(__lowerCAmelCase   )
					A__        =   BioGptTokenizer.from_pretrained("""microsoft/biogpt"""   )

					A__        =   """left"""

					# Define PAD Token = EOS Token = 50256
					A__        =   tokenizer.eos_token
					A__        =   model.config.eos_token_id

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

					A__        =   tokenizer(__lowerCAmelCase							,	return_tensors="""pt"""							,	padding=__lowerCAmelCase   )
					A__        =   inputs["""input_ids"""].to(__lowerCAmelCase   )

					A__        =   model.generate(
					    input_ids=__lowerCAmelCase							,	attention_mask=inputs["""attention_mask"""].to(__lowerCAmelCase   )							,	)

					A__        =   tokenizer(sentences[0]							,	return_tensors="""pt"""   ).input_ids.to(__lowerCAmelCase   )
					A__        =   model.generate(input_ids=__lowerCAmelCase   )

					A__        =   inputs_non_padded.shape[-1] - inputs["""attention_mask"""][-1].long().sum().cpu().item()
					A__        =   tokenizer(sentences[1]							,	return_tensors="""pt"""   ).input_ids.to(__lowerCAmelCase   )
					A__        =   model.generate(input_ids=__lowerCAmelCase							,	max_length=model.config.max_length - num_paddings   )

					A__        =   tokenizer.batch_decode(__lowerCAmelCase							,	skip_special_tokens=__lowerCAmelCase   )
					A__        =   tokenizer.decode(output_non_padded[0]							,	skip_special_tokens=__lowerCAmelCase   )
					A__        =   tokenizer.decode(output_padded[0]							,	skip_special_tokens=__lowerCAmelCase   )

					A__        =   [
					    """Hello, my dog is a little bit bigger than a little bit.""",
					    """Today, I have a good idea of how to use the information""",
					]
					self.assertListEqual(__lowerCAmelCase							,	__lowerCAmelCase   )
					self.assertListEqual(__lowerCAmelCase							,	[non_padded_sentence, padded_sentence]   )






			@slow
			def    a_       (			self   :    Union[str, Any]   )	->	Optional[Any]:







					"""simple docstring"""






					for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							A__        =   BioGptModel.from_pretrained(__lowerCAmelCase   )
							self.assertIsNotNone(__lowerCAmelCase   )






			def    a_       (			self   :    int   )	->	Any:







					"""simple docstring"""






					A__      ,			A__        =   self.model_tester.prepare_config_and_inputs_for_common()
					A__        =   3
					A__        =   input_dict["""input_ids"""]
					A__        =   input_ids.ne(1   ).to(__lowerCAmelCase   )
					A__        =   ids_tensor([self.model_tester.batch_size]							,	self.model_tester.type_sequence_label_size   )
					A__        =   BioGptForSequenceClassification(__lowerCAmelCase   )
					model.to(__lowerCAmelCase   )
					model.eval()
					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase							,	labels=__lowerCAmelCase   )
					self.assertEqual(result.logits.shape							,	(self.model_tester.batch_size, self.model_tester.num_labels)   )







			def    a_       (			self   :    Optional[Any]   )	->	Optional[int]:







					"""simple docstring"""






					A__      ,			A__        =   self.model_tester.prepare_config_and_inputs_for_common()
					A__        =   3
					A__        =   """multi_label_classification"""
					A__        =   input_dict["""input_ids"""]
					A__        =   input_ids.ne(1   ).to(__lowerCAmelCase   )
					A__        =   ids_tensor(
					    [self.model_tester.batch_size, config.num_labels]							,	self.model_tester.type_sequence_label_size   ).to(torch.float   )
					A__        =   BioGptForSequenceClassification(__lowerCAmelCase   )
					model.to(__lowerCAmelCase   )
					model.eval()
					A__        =   model(__lowerCAmelCase							,	attention_mask=__lowerCAmelCase							,	labels=__lowerCAmelCase   )
					self.assertEqual(result.logits.shape							,	(self.model_tester.batch_size, self.model_tester.num_labels)   )


@require_torch
class   A			(unittest.TestCase    ):
			'''simple docstring'''




			@slow
			def    a_       (			self   :    List[Any]   )	->	Optional[int]:







					"""simple docstring"""






					A__        =   BioGptForCausalLM.from_pretrained("""microsoft/biogpt"""   )
					A__        =   torch.tensor([[2, 48_05, 9, 6_56, 21]]   )
					A__        =   model(__lowerCAmelCase   )[0]

					A__        =   4_23_84

					A__        =   torch.Size((1, 5, vocab_size)   )
					self.assertEqual(output.shape							,	__lowerCAmelCase   )

					A__        =   torch.tensor(
					    [[[-9.5_2_3_6, -9.8_9_1_8, 1_0.4_5_5_7], [-1_1.0_4_6_9, -9.6_4_2_3, 8.1_0_2_2], [-8.8_6_6_4, -7.8_8_2_6, 5.5_3_2_5]]]   )

					self.assertTrue(torch.allclose(output[:, :3, :3]							,	__lowerCAmelCase							,	atol=1e-4   )   )







			@slow
			def    a_       (			self   :    Any   )	->	int:







					"""simple docstring"""






					A__        =   BioGptTokenizer.from_pretrained("""microsoft/biogpt"""   )
					A__        =   BioGptForCausalLM.from_pretrained("""microsoft/biogpt"""   )
					model.to(__lowerCAmelCase   )

					torch.manual_seed(0   )
					A__        =   tokenizer("""COVID-19 is"""							,	return_tensors="""pt"""   ).to(__lowerCAmelCase   )
					A__        =   model.generate(
					    **__lowerCAmelCase							,	min_length=1_00							,	max_length=10_24							,	num_beams=5							,	early_stopping=__lowerCAmelCase							,	)
					A__        =   tokenizer.decode(output_ids[0]							,	skip_special_tokens=__lowerCAmelCase   )

					A__        =   (
					    """COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the"""
					    """ causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and"""
					    """ territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),"""
					    """ and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and"""
					    """ more than 800,000 deaths."""
					)
					self.assertEqual(__lowerCAmelCase							,	__lowerCAmelCase   )










import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)


class   A			(unittest.TestCase    ):
			'''simple docstring'''




			def    a_       (			self   :    Any   )	->	Union[str, Any]:







					"""simple docstring"""






					A__        =   ["""a""", """b""", """c"""]

					# Defaults to last layer if both are None
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	__lowerCAmelCase							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[2]   )

					# Out indices set to match out features
					A__      ,			A__        =   get_aligned_output_features_output_indices(["""a""", """c"""]							,	__lowerCAmelCase							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[0, 2]   )

					# Out features set to match out indices
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	[0, 2]							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[0, 2]   )

					# Out features selected from negative indices
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	[-3, -1]							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[-3, -1]   )






			def    a_       (			self   :    Optional[Any]   )	->	Optional[Any]:







					"""simple docstring"""






					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 1)							,	__lowerCAmelCase   )

					# Out features must be a list
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(("""a""", """b""")							,	(0, 1)							,	["""a""", """b"""]   )

					# Out features must be a subset of stage names
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 1)							,	["""a"""]   )

					# Out indices must be a list or tuple
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(__lowerCAmelCase							,	0							,	["""a""", """b"""]   )

					# Out indices must be a subset of stage names
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(__lowerCAmelCase							,	(0, 1)							,	["""a"""]   )

					# Out features and out indices must be the same length
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0,)							,	["""a""", """b""", """c"""]   )

					# Out features should match out indices
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 2)							,	["""a""", """b""", """c"""]   )

					# Out features and out indices should be in order
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""b""", """a"""]							,	(0, 1)							,	["""a""", """b"""]   )

					# Check passes with valid inputs
					verify_out_features_out_indices(["""a""", """b""", """d"""]							,	(0, 1, -1)							,	["""a""", """b""", """c""", """d"""]   )







			def    a_       (			self   :    Union[str, Any]   )	->	List[str]:







					"""simple docstring"""






					A__        =   BackboneMixin()

					A__        =   ["""a""", """b""", """c"""]
					A__        =   ["""a""", """c"""]
					A__        =   [0, 2]

					# Check that the output features and indices are set correctly
					self.assertEqual(backbone.out_features							,	["""a""", """c"""]   )
					self.assertEqual(backbone.out_indices							,	[0, 2]   )

					# Check out features and indices are updated correctly
					A__        =   ["""a""", """b"""]
					self.assertEqual(backbone.out_features							,	["""a""", """b"""]   )
					self.assertEqual(backbone.out_indices							,	[0, 1]   )

					A__        =   [-3, -1]
					self.assertEqual(backbone.out_features							,	["""a""", """c"""]   )
					self.assertEqual(backbone.out_indices							,	[-3, -1]   )



