code: 
  
  
  import unittest
  
  from transformers.testing_utils import is_torch_available, require_torch, tooslow
  
  from ...generation.test_utils import torch_device
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
  	import torch
  
  	from transformers import (
  	    CpmAntConfig,
  	    CpmAntForCausalLM,
  	    CpmAntModel,
  	    CpmAntTokenizer,
  	)
  
  
  
  
  
  @require_torch
  class 					snake_case__  :
  
  
  
  
  
  	def __init__(  self				,    UpperCamelCase_				,    UpperCamelCase_=2				,    UpperCamelCase_=8				,    UpperCamelCase_=True				,    UpperCamelCase_=False				,    UpperCamelCase_=False				,    UpperCamelCase_=False				,    UpperCamelCase_=False				,    UpperCamelCase_=99				,    UpperCamelCase_=32				,    UpperCamelCase_=3				,    UpperCamelCase_=4				,    UpperCamelCase_=37				,    UpperCamelCase_=32				,    UpperCamelCase_=128				,    UpperCamelCase_=8				,    UpperCamelCase_=8				,    UpperCamelCase_=8				,    UpperCamelCase_=1.0				,    UpperCamelCase_=True				,    )		->			Union[str, Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   List[str]			=	parent
  								a_       :   Optional[Any]			=	batch_size
  								a_       :   Optional[int]			=	seq_length
  								a_       :   List[Any]			=	is_training
  								a_       :   List[str]			=	use_token_type_ids
  								a_       :   Optional[Any]			=	use_input_mask
  								a_       :   Any			=	use_labels
  								a_       :   Tuple			=	use_mc_token_ids
  								a_       :   Union[str, Any]			=	vocab_size
  								a_       :   int			=	hidden_size
  								a_       :   List[str]			=	num_hidden_layers
  								a_       :   Tuple			=	num_attention_heads
  								a_       :   List[str]			=	intermediate_size
  								a_       :   List[Any]			=	num_buckets
  								a_       :   List[Any]			=	max_distance
  								a_       :   Any			=	prompt_length
  								a_       :   Any			=	prompt_types
  								a_       :   List[str]			=	segment_types
  								a_       :   Union[str, Any]			=	init_std
  								a_       :   Any			=	return_dict
  
  
  
  
  
  	def     A				(  self							)		->			List[str]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   int			=	{}
  								a_       :   Any			=	ids_tensor([self.batch_size, self.seq_length]				,    self.vocab_size							).type(torch.intaa							)
  								a_       :   Any			=	False
  
  								a_       :   Dict			=	self.get_config()
  
  								return (config, input_ids)
  
  
  
  
  
  	def     A				(  self							)		->			Union[str, Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								return CpmAntConfig(
  								    vocab_size=self.vocab_size				,    hidden_size=self.hidden_size				,    num_hidden_layers=self.num_hidden_layers				,    num_attention_heads=self.num_attention_heads				,    dim_ff=self.intermediate_size				,    position_bias_num_buckets=self.num_buckets				,    position_bias_max_distance=self.max_distance				,    prompt_types=self.prompt_types				,    prompt_length=self.prompt_length				,    segment_types=self.segment_types				,    use_cache=UpperCamelCase_				,    init_std=self.init_std				,    return_dict=self.return_dict				,    )
  
  
  
  
  
  	def     A				(  self				,    UpperCamelCase_				,    UpperCamelCase_				,    *UpperCamelCase_							)		->			Union[str, Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Dict			=	CpmAntModel(config=UpperCamelCase_							)
  								model.to(UpperCamelCase_							)
  								model.eval()
  
  								a_       :   Tuple			=	model(**UpperCamelCase_							).last_hidden_state
  
  								self.parent.assertEqual(hidden_states.shape				,    (self.batch_size, self.seq_length, config.hidden_size)							)
  
  
  
  
  
  	def     A				(  self				,    UpperCamelCase_				,    UpperCamelCase_				,    *UpperCamelCase_							)		->			Union[str, Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   int			=	CpmAntForCausalLM(UpperCamelCase_							)
  								model.to(UpperCamelCase_							)
  								a_       :   Optional[int]			=	input_ids["""input_ids"""].to(UpperCamelCase_							)
  								model.eval()
  
  								a_       :   Optional[Any]			=	model(**UpperCamelCase_							)
  								self.parent.assertEqual(
  								    model_output.logits.shape				,    (self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length)				,    )
  
  
  
  
  
  	def     A				(  self							)		->			int:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_		,				a_       :   Tuple			=	self.prepare_config_and_inputs()
  								return config, inputs_dict
  
  
  
  
  
  @require_torch
  class 					snake_case__  ( __A      ,    __A      ,    unittest.TestCase       ):
  	UpperCAmelCase   :							List[str]         = (CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
  	UpperCAmelCase   :							List[str]         = (
  	    {"""feature-extraction""": CpmAntModel, """text-generation""": CpmAntForCausalLM} if is_torch_available() else {}
  	)
  
  	UpperCAmelCase   :							int         = False
  	UpperCAmelCase   :							List[Any]         = False
  	UpperCAmelCase   :							str         = False
  	UpperCAmelCase   :							Union[str, Any]         = False
  	UpperCAmelCase   :							Optional[int]         = False
  
  
  
  
  
  	def     A				(  self							)		->			Optional[Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Any			=	CpmAntModelTester(self							)
  								a_       :   Union[str, Any]			=	ConfigTester(self				,    config_class=UpperCamelCase_							)
  
  
  
  
  
  	def     A				(  self							)		->			List[Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								self.config_tester.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.check_config_can_be_init_without_params()
  								self.config_tester.check_config_arguments_init()
  
  
  
  
  
  	def     A				(  self							)		->			List[str]:
  								"""simple docstring"""
  
  
  
  
  
  
  								unittest.skip("""CPMAnt doesn't support input_embeds."""							)(self.test_inputs_embeds							)
  
  
  
  
  
  	def     A				(  self							)		->			Optional[Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								unittest.skip(
  								    """CPMAnt doesn't support retain grad in hidden_states or attentions, because prompt management will peel off the output.hidden_states from graph.\
                   So is attentions. We strongly recommand you use loss to tune model."""							)(self.test_retain_grad_hidden_states_attentions							)
  
  
  
  
  
  	def     A				(  self							)		->			str:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_		,				a_       :   Any			=	self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_cpmant_model(UpperCamelCase_				,    UpperCamelCase_							)
  
  
  
  
  
  	def     A				(  self							)		->			List[str]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_		,				a_       :   int			=	self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_lm_head_model(UpperCamelCase_				,    UpperCamelCase_							)
  
  
  
  
  
  @require_torch
  class 					snake_case__  ( unittest.TestCase       ):
  
  
  
  
  
  	@tooslow
  	def     A				(  self							)		->			Any:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Optional[Any]			=	"""今天天气真好！"""
  								a_       :   str			=	"""openbmb/cpm-ant-10b"""
  								a_       :   Tuple			=	CpmAntModel.from_pretrained(UpperCamelCase_							)
  								a_       :   str			=	CpmAntTokenizer.from_pretrained(UpperCamelCase_							)
  								a_       :   List[str]			=	tokenizer(UpperCamelCase_				,    return_tensors="""pt"""							)
  								a_       :   Union[str, Any]			=	model(**UpperCamelCase_							).last_hidden_state
  
  								a_       :   Union[str, Any]			=	torch.tensor(
  								    [[[6.1708, 5.9244, 1.0835], [6.5207, 6.2893, -11.3324], [-1.0107, -0.0576, -5.9577]]]				,    )
  								self.assertTrue(torch.allclose(hidden_states[:, :3, :3]				,    UpperCamelCase_				,    atol=1e-2							)							)
  
  
  
  
  
  @require_torch
  class 					snake_case__  ( unittest.TestCase       ):
  
  
  
  
  
  	@tooslow
  	def     A				(  self							)		->			Optional[Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Optional[Any]			=	"""今天天气真好！"""
  								a_       :   Optional[Any]			=	"""openbmb/cpm-ant-10b"""
  								a_       :   Tuple			=	CpmAntForCausalLM.from_pretrained(UpperCamelCase_							)
  								a_       :   Optional[Any]			=	CpmAntTokenizer.from_pretrained(UpperCamelCase_							)
  								a_       :   int			=	tokenizer(UpperCamelCase_				,    return_tensors="""pt"""							)
  								a_       :   Any			=	model(**UpperCamelCase_							).logits
  
  								a_       :   str			=	torch.tensor(
  								    [[[-6.4267, -6.4083, -6.3958], [-5.8802, -5.9447, -5.7811], [-5.3896, -5.4820, -5.4295]]]				,    )
  								self.assertTrue(torch.allclose(hidden_states[:, :3, :3]				,    UpperCamelCase_				,    atol=1e-2							)							)
  
  
  
  
  
  	@tooslow
  	def     A				(  self							)		->			Any:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Any			=	"""openbmb/cpm-ant-10b"""
  								a_       :   Optional[Any]			=	CpmAntForCausalLM.from_pretrained(UpperCamelCase_							)
  								a_       :   List[str]			=	CpmAntTokenizer.from_pretrained(UpperCamelCase_							)
  								a_       :   Tuple			=	"""今天天气不错，"""
  								a_       :   Optional[int]			=	"""今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的"""
  								a_       :   Dict			=	tokenizer(UpperCamelCase_				,    return_tensors="""pt"""							)
  								a_       :   List[Any]			=	model.generate(**UpperCamelCase_							)
  								a_       :   Optional[Any]			=	tokenizer.batch_decode(UpperCamelCase_							)
  								self.assertEqual(UpperCamelCase_				,    UpperCamelCase_							)
  
  
  
  
  
  	@tooslow
  	def     A				(  self							)		->			int:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   List[str]			=	"""openbmb/cpm-ant-10b"""
  								a_       :   int			=	CpmAntForCausalLM.from_pretrained(UpperCamelCase_							)
  								a_       :   Dict			=	CpmAntTokenizer.from_pretrained(UpperCamelCase_							)
  								a_       :   Any			=	["""今天天气不错，""", """新年快乐，万事如意！"""]
  								a_       :   Any			=	[
  								    """今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的""",
  								    """新年快乐，万事如意！在这辞旧迎新的美好时刻，我谨代表《农村新技术》杂志社全体同仁，向一直以来关心、支持《农村新技术》杂志发展的各级领导、各界朋友和广大读者致以最诚挚的""",
  								]
  								a_       :   str			=	tokenizer(UpperCamelCase_				,    return_tensors="""pt"""				,    padding=UpperCamelCase_							)
  								a_       :   List[Any]			=	model.generate(**UpperCamelCase_							)
  								a_       :   Dict			=	tokenizer.batch_decode(UpperCamelCase_							)
  								self.assertEqual(UpperCamelCase_				,    UpperCamelCase_							)
  
  
  
style_context: 
  
  
  import copy
  from typing import Dict, Optional
  
  from ...configuration_utils import PretrainedConfig
  from ...utils import logging
  from ..auto import CONFIG_MAPPING
  
  
  SCREAMING_SNAKE_CASE : List[str]          =    logging.get_logger(__name__)
  
  SCREAMING_SNAKE_CASE : List[Any]          =    {
      "shi-labs/oneformer_ade20k_swin_tiny": (
          "https://huggingface.co/shi-labs/oneformer_ade20k_swin_tiny/blob/main/config.json"
      ),
      # See all OneFormer models at https://huggingface.co/models?filter=oneformer
  }
  
  
  
  
  
  class 					snake_case__  ( __A       ):
  	UpperCAmelCase   :							Tuple         = """oneformer"""
  	UpperCAmelCase   :							Union[str, Any]         = {"""hidden_size""": """hidden_dim"""}
  
  
  
  
  
  	def __init__(  self				,    UpperCamelCase_ = None				,    UpperCamelCase_ = 255				,    UpperCamelCase_ = 150				,    UpperCamelCase_ = 0.1				,    UpperCamelCase_ = 2.0				,    UpperCamelCase_ = 5.0				,    UpperCamelCase_ = 5.0				,    UpperCamelCase_ = 0.5				,    UpperCamelCase_ = 0.07				,    UpperCamelCase_ = 12544				,    UpperCamelCase_ = 3.0				,    UpperCamelCase_ = 0.75				,    UpperCamelCase_ = 0.02				,    UpperCamelCase_ = 1.0				,    UpperCamelCase_ = 1e-05				,    UpperCamelCase_ = False				,    UpperCamelCase_ = True				,    UpperCamelCase_ = True				,    UpperCamelCase_ = [4, 8, 16, 32]				,    UpperCamelCase_ = 77				,    UpperCamelCase_ = 256				,    UpperCamelCase_ = 77				,    UpperCamelCase_ = 6				,    UpperCamelCase_ = 49408				,    UpperCamelCase_ = 2				,    UpperCamelCase_ = 16				,    UpperCamelCase_ = 256				,    UpperCamelCase_ = 256				,    UpperCamelCase_ = 256				,    UpperCamelCase_ = 1024				,    UpperCamelCase_ = "GN"				,    UpperCamelCase_ = 6				,    UpperCamelCase_ = 10				,    UpperCamelCase_ = True				,    UpperCamelCase_ = 8				,    UpperCamelCase_ = 0.1				,    UpperCamelCase_ = 2048				,    UpperCamelCase_ = False				,    UpperCamelCase_ = False				,    UpperCamelCase_ = 2				,    UpperCamelCase_ = 4				,    **UpperCamelCase_				,    )		->			List[Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								if backbone_config is None:
  															logger.info("""`backbone_config` is unset. Initializing the config with the default `Swin` backbone."""							)
  															a_       :   Tuple			=	CONFIG_MAPPING["""swin"""](
  															    image_size=224				,    in_channels=3				,    patch_size=4				,    embed_dim=96				,    depths=[2, 2, 6, 2]				,    num_heads=[3, 6, 12, 24]				,    window_size=7				,    drop_path_rate=0.3				,    use_absolute_embeddings=UpperCamelCase_				,    out_features=["""stage1""", """stage2""", """stage3""", """stage4"""]				,    )
  								elif isinstance(UpperCamelCase_				,    UpperCamelCase_							):
  															a_       :   str			=	backbone_config.get("""model_type"""							)
  															a_       :   Optional[Any]			=	CONFIG_MAPPING[backbone_model_type]
  															a_       :   List[Any]			=	config_class.from_dict(UpperCamelCase_							)
  
  								a_       :   str			=	backbone_config
  
  								a_       :   List[str]			=	ignore_value
  								a_       :   Optional[int]			=	num_queries
  								a_       :   Optional[Any]			=	no_object_weight
  								a_       :   List[Any]			=	class_weight
  								a_       :   Union[str, Any]			=	mask_weight
  								a_       :   Union[str, Any]			=	dice_weight
  								a_       :   Optional[Any]			=	contrastive_weight
  								a_       :   Any			=	contrastive_temperature
  								a_       :   Optional[int]			=	train_num_points
  								a_       :   Tuple			=	oversample_ratio
  								a_       :   str			=	importance_sample_ratio
  								a_       :   List[Any]			=	init_std
  								a_       :   int			=	init_xavier_std
  								a_       :   List[Any]			=	layer_norm_eps
  								a_       :   Optional[int]			=	is_training
  								a_       :   List[Any]			=	use_auxiliary_loss
  								a_       :   str			=	output_auxiliary_logits
  								a_       :   Dict			=	strides
  								a_       :   List[Any]			=	task_seq_len
  								a_       :   int			=	text_encoder_width
  								a_       :   List[Any]			=	text_encoder_context_length
  								a_       :   List[str]			=	text_encoder_num_layers
  								a_       :   Union[str, Any]			=	text_encoder_vocab_size
  								a_       :   Optional[Any]			=	text_encoder_proj_layers
  								a_       :   Optional[int]			=	text_encoder_n_ctx
  								a_       :   Optional[Any]			=	conv_dim
  								a_       :   str			=	mask_dim
  								a_       :   Optional[Any]			=	hidden_dim
  								a_       :   Any			=	encoder_feedforward_dim
  								a_       :   Dict			=	norm
  								a_       :   List[Any]			=	encoder_layers
  								a_       :   int			=	decoder_layers
  								a_       :   Any			=	use_task_norm
  								a_       :   Union[str, Any]			=	num_attention_heads
  								a_       :   List[str]			=	dropout
  								a_       :   List[Any]			=	dim_feedforward
  								a_       :   Union[str, Any]			=	pre_norm
  								a_       :   Dict			=	enforce_input_proj
  								a_       :   Tuple			=	query_dec_layers
  								a_       :   Any			=	common_stride
  								a_       :   List[str]			=	decoder_layers
  
  								super().__init__(**UpperCamelCase_							)
  
  
  
  
  
  	def     A				(  self							)		->			Dict[str, any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Dict			=	copy.deepcopy(self.__dict__							)
  								a_       :   Any			=	self.backbone_config.to_dict()
  								a_       :   Union[str, Any]			=	self.__class__.model_type
  								return output
  
  
  