





import math
from typing import Callable, List, Optional, Union

import numpy as np
import PIL
import torch
from PIL import Image
from transformers import CLIPTextModel, CLIPTokenizer

from diffusers.models import AutoencoderKL, UNetaDConditionModel
from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale import StableDiffusionUpscalePipeline
from diffusers.schedulers import DDIMScheduler, DDPMScheduler, LMSDiscreteScheduler, PNDMScheduler

def 				SCREAMING_SNAKE_CASE__							(	snake_case__	:List[Any]      ,				snake_case__	:List[Any]      ,				snake_case__	:Any=[]  )   ->    Any:
  _lowercase						    =			size[0] - overlap_pixels * 2
  _lowercase						    =			size[1] - overlap_pixels * 2
  for letter in ["l", "r"]:
    if letter in remove_borders:
      size_x += overlap_pixels
  for letter in ["t", "b"]:
    if letter in remove_borders:
      size_y += overlap_pixels
  _lowercase						    =			np.ones((size_y, size_x)      ,				dtype=np.uinta  ) * 255
  _lowercase						    =			np.pad(snake_case__      ,				mode='linear_ramp'      ,				pad_width=snake_case__      ,				end_values=0  )

  if "l" in remove_borders:
    _lowercase						    =			mask[:, overlap_pixels : mask.shape[1]]
  if "r" in remove_borders:
    _lowercase						    =			mask[:, 0 : mask.shape[1] - overlap_pixels]
  if "t" in remove_borders:
    _lowercase						    =			mask[overlap_pixels : mask.shape[0], :]
  if "b" in remove_borders:
    _lowercase						    =			mask[0 : mask.shape[0] - overlap_pixels, :]
  return mask

def 				SCREAMING_SNAKE_CASE__							(	snake_case__	:Optional[Any]      ,				snake_case__	:List[str]      ,				snake_case__	:List[str]  )   ->    Dict:
  return max(snake_case__      ,				min(snake_case__      ,				snake_case__  )  )

def 				SCREAMING_SNAKE_CASE__							(	snake_case__	:[int]      ,				snake_case__	:[int]      ,				snake_case__	:[int]  )   ->    Optional[Any]:
  return (
      clamp(rect[0]      ,				min[0]      ,				max[0]  ),
      clamp(rect[1]      ,				min[1]      ,				max[1]  ),
      clamp(rect[2]      ,				min[0]      ,				max[0]  ),
      clamp(rect[3]      ,				min[1]      ,				max[1]  ),
  )

def 				SCREAMING_SNAKE_CASE__							(	snake_case__	:[int]      ,				snake_case__	:int      ,				snake_case__	:[int]  )   ->    Dict:
  _lowercase						    =			list(snake_case__  )
  rect[0] -= overlap
  rect[1] -= overlap
  rect[2] += overlap
  rect[3] += overlap
  _lowercase						    =			clamp_rect(snake_case__      ,				[0, 0]      ,				[image_size[0], image_size[1]]  )
  return rect

def 				SCREAMING_SNAKE_CASE__							(	snake_case__	:Tuple      ,				snake_case__	:int      ,				snake_case__	:Dict      ,				snake_case__	:str  )   ->    Tuple:
  _lowercase						    =			Image.new('RGB'      ,				(tile.size[0] + original_slice, tile.size[1])  )
  result.paste(
      original_image.resize((tile.size[0], tile.size[1])      ,				Image.BICUBIC  ).crop(
          (slice_x, 0, slice_x + original_slice, tile.size[1])  )      ,				(0, 0)      ,				)
  result.paste(snake_case__      ,				(original_slice, 0)  )
  return result

def 				SCREAMING_SNAKE_CASE__							(	snake_case__	:Tuple      ,				snake_case__	:Tuple  )   ->    List[str]:
  _lowercase						    =			(original_image_slice * 4, 0, tile.size[0], tile.size[1])
  _lowercase						    =			tile.crop(snake_case__  )
  return tile

def 				SCREAMING_SNAKE_CASE__							(	snake_case__	:List[str]      ,				snake_case__	:Optional[int]  )   ->    Tuple:
  _lowercase						    =			n % d
  return n - divisor





class 					A_					(   UpperCAmelCase						):







       """simple docstring"""





       def __init__(     self						:						str    ,__A						:						AutoencoderKL    ,__A						:						CLIPTextModel    ,__A						:						CLIPTokenizer    ,__A						:						UNetaDConditionModel    ,__A						:						DDPMScheduler    ,__A						:						Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]    ,__A						:						int = 350    ,)    ->       Union[str, Any]:
         super().__init__(
             vae=__A    ,text_encoder=__A    ,tokenizer=__A    ,unet=__A    ,low_res_scheduler=__A    ,scheduler=__A    ,max_noise_level=__A    ,)







       def  __UpperCAmelCase			(     self						:						Dict    ,__A						:						Dict    ,__A						:						Tuple    ,__A						:						List[Any]    ,__A						:						str    ,__A						:						Optional[Any]    ,__A						:						Union[str, Any]    ,__A						:						Optional[int]    ,**__A						:						List[Any]	)    ->       int:
         torch.manual_seed(0	)
         _lowercase						    =			(
             min(image.size[0] - (tile_size + original_image_slice)    ,x * tile_size	),
             min(image.size[1] - (tile_size + original_image_slice)    ,y * tile_size	),
             min(image.size[0]    ,(x + 1) * tile_size	),
             min(image.size[1]    ,(y + 1) * tile_size	),
         )
         _lowercase						    =			add_overlap_rect(__A    ,__A    ,image.size	)
         _lowercase						    =			image.crop(__A	)
         _lowercase						    =			((crop_rect[0] + ((crop_rect[2] - crop_rect[0]) / 2)) / image.size[0]) * tile.size[0]
         _lowercase						    =			translated_slice_x - (original_image_slice / 2)
         _lowercase						    =			max(0    ,__A	)
         _lowercase						    =			squeeze_tile(__A    ,__A    ,__A    ,__A	)
         _lowercase						    =			to_input.size
         _lowercase						    =			to_input.resize((tile_size, tile_size)    ,Image.BICUBIC	)
         _lowercase						    =			super(__A    ,self	).__call__(image=__A    ,**__A	).images[0]
         _lowercase						    =			upscaled_tile.resize((orig_input_size[0] * 4, orig_input_size[1] * 4)    ,Image.BICUBIC	)
         _lowercase						    =			unsqueeze_tile(__A    ,__A	)
         _lowercase						    =			upscaled_tile.resize((tile.size[0] * 4, tile.size[1] * 4)    ,Image.BICUBIC	)
         _lowercase						    =			[]
         if x == 0:
           remove_borders.append('l'	)
         elif crop_rect[2] == image.size[0]:
           remove_borders.append('r'	)
         if y == 0:
           remove_borders.append('t'	)
         elif crop_rect[3] == image.size[1]:
           remove_borders.append('b'	)
         _lowercase						    =			Image.fromarray(
             make_transparency_mask(
                 (upscaled_tile.size[0], upscaled_tile.size[1])    ,tile_border * 4    ,remove_borders=__A	)    ,mode='L'    ,)
         final_image.paste(
             __A    ,(crop_rect_with_overlap[0] * 4, crop_rect_with_overlap[1] * 4)    ,__A	)







       @torch.no_grad()
       def __call__(     self						:						List[Any]    ,__A						:						Union[str, List[str]]    ,__A						:						Union[PIL.Image.Image, List[PIL.Image.Image]]    ,__A						:						int = 75    ,__A						:						float = 9.0    ,__A						:						int = 50    ,__A						:						Optional[Union[str, List[str]]] = None    ,__A						:						Optional[int] = 1    ,__A						:						float = 0.0    ,__A						:						Optional[torch.Generator] = None    ,__A						:						Optional[torch.FloatTensor] = None    ,__A						:						Optional[Callable[[int, int, torch.FloatTensor], None]] = None    ,__A						:						int = 1    ,__A						:						int = 128    ,__A						:						int = 32    ,__A						:						int = 32    ,)    ->       int:
         _lowercase						    =			Image.new('RGB'    ,(image.size[0] * 4, image.size[1] * 4)	)
         _lowercase						    =			math.ceil(image.size[0] / tile_size	)
         _lowercase						    =			math.ceil(image.size[1] / tile_size	)
         _lowercase						    =			tcx * tcy
         _lowercase						    =			0
         for y in range(__A	):
           for x in range(__A	):
             self._process_tile(
                 __A    ,__A    ,__A    ,__A    ,__A    ,__A    ,__A    ,prompt=__A    ,num_inference_steps=__A    ,guidance_scale=__A    ,noise_level=__A    ,negative_prompt=__A    ,num_images_per_prompt=__A    ,eta=__A    ,generator=__A    ,latents=__A    ,)
             current_count += 1
             if callback is not None:
               callback({'progress': current_count / total_tile_count, 'image': final_image}	)
         return final_image

def 				SCREAMING_SNAKE_CASE__							(	)   ->    List[Any]:
  # Run a demo
  _lowercase						    =			'stabilityai/stable-diffusion-x4-upscaler'
  _lowercase						    =			StableDiffusionTiledUpscalePipeline.from_pretrained(snake_case__      ,				revision='fp16'      ,				torch_dtype=torch.floataa  )
  _lowercase						    =			pipe.to('cuda'  )
  _lowercase						    =			Image.open('../../docs/source/imgs/diffusers_library.jpg'  )

  def callback(snake_case__	:int  ):
    print(F"""progress: {obj["progress"]:.4f}"""  )
    obj["image"].save('diffusers_library_progress.jpg'  )

  _lowercase						    =			pipe(image=snake_case__      ,				prompt='Black font, white background, vector'      ,				noise_level=40      ,				callback=snake_case__  )
  final_image.save('diffusers_library.jpg'  )


if __name__ == "__main__":
      main()




import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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 (
         MODEL_FOR_PRETRAINING_MAPPING,
         AlbertForMaskedLM,
         AlbertForMultipleChoice,
         AlbertForPreTraining,
         AlbertForQuestionAnswering,
         AlbertForSequenceClassification,
         AlbertForTokenClassification,
         AlbertModel,
     )
     from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST
class    __UpperCamelCase			:

 """simple docstring"""



 def __init__(	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=1_3		,				SCREAMING_SNAKE_CASE=7		,				SCREAMING_SNAKE_CASE=True		,				SCREAMING_SNAKE_CASE=True		,				SCREAMING_SNAKE_CASE=True		,				SCREAMING_SNAKE_CASE=True		,				SCREAMING_SNAKE_CASE=9_9		,				SCREAMING_SNAKE_CASE=1_6		,				SCREAMING_SNAKE_CASE=3_6		,				SCREAMING_SNAKE_CASE=6		,				SCREAMING_SNAKE_CASE=6		,				SCREAMING_SNAKE_CASE=6		,				SCREAMING_SNAKE_CASE=3_7		,				SCREAMING_SNAKE_CASE="gelu"		,				SCREAMING_SNAKE_CASE=0.1		,				SCREAMING_SNAKE_CASE=0.1		,				SCREAMING_SNAKE_CASE=5_1_2		,				SCREAMING_SNAKE_CASE=1_6		,				SCREAMING_SNAKE_CASE=2		,				SCREAMING_SNAKE_CASE=0.02		,				SCREAMING_SNAKE_CASE=3		,				SCREAMING_SNAKE_CASE=4		,				SCREAMING_SNAKE_CASE=None		,				) ->			Union[str, Any]:
  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__												= embedding_size
  a__												= hidden_size
  a__												= num_hidden_layers
  a__												= num_hidden_groups
  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 						_UpperCAmelCase       (	self      ) ->			List[str]:
  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 						_UpperCAmelCase       (	self      ) ->			Any:
  return AlbertConfig(
      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		,				initializer_range=self.initializer_range		,				num_hidden_groups=self.num_hidden_groups		,				)

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      ) ->			Optional[int]:
  a__												= AlbertModel(config=SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()
  a__												= model(SCREAMING_SNAKE_CASE		,				attention_mask=SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE      )
  a__												= model(SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE      )
  a__												= model(SCREAMING_SNAKE_CASE      )
  self.parent.assertEqual(result.last_hidden_state.shape		,				(self.batch_size, self.seq_length, self.hidden_size)      )
  self.parent.assertEqual(result.pooler_output.shape		,				(self.batch_size, self.hidden_size)      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      ) ->			List[Any]:
  a__												= AlbertForPreTraining(config=SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()
  a__												= model(
      SCREAMING_SNAKE_CASE		,				attention_mask=SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				labels=SCREAMING_SNAKE_CASE		,				sentence_order_label=SCREAMING_SNAKE_CASE		,				)
  self.parent.assertEqual(result.prediction_logits.shape		,				(self.batch_size, self.seq_length, self.vocab_size)      )
  self.parent.assertEqual(result.sop_logits.shape		,				(self.batch_size, config.num_labels)      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      ) ->			Dict:
  a__												= AlbertForMaskedLM(config=SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()
  a__												= model(SCREAMING_SNAKE_CASE		,				attention_mask=SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				labels=SCREAMING_SNAKE_CASE      )
  self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.seq_length, self.vocab_size)      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      ) ->			Any:
  a__												= AlbertForQuestionAnswering(config=SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()
  a__												= model(
      SCREAMING_SNAKE_CASE		,				attention_mask=SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				start_positions=SCREAMING_SNAKE_CASE		,				end_positions=SCREAMING_SNAKE_CASE		,				)
  self.parent.assertEqual(result.start_logits.shape		,				(self.batch_size, self.seq_length)      )
  self.parent.assertEqual(result.end_logits.shape		,				(self.batch_size, self.seq_length)      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      ) ->			Union[str, Any]:
  a__												= self.num_labels
  a__												= AlbertForSequenceClassification(SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()
  a__												= model(SCREAMING_SNAKE_CASE		,				attention_mask=SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				labels=SCREAMING_SNAKE_CASE      )
  self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.num_labels)      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      ) ->			Tuple:
  a__												= self.num_labels
  a__												= AlbertForTokenClassification(config=SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()
  a__												= model(SCREAMING_SNAKE_CASE		,				attention_mask=SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				labels=SCREAMING_SNAKE_CASE      )
  self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.seq_length, self.num_labels)      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      ) ->			Optional[int]:
  a__												= self.num_choices
  a__												= AlbertForMultipleChoice(config=SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()
  a__												= input_ids.unsqueeze(1      ).expand(-1		,				self.num_choices		,				-1      ).contiguous()
  a__												= token_type_ids.unsqueeze(1      ).expand(-1		,				self.num_choices		,				-1      ).contiguous()
  a__												= input_mask.unsqueeze(1      ).expand(-1		,				self.num_choices		,				-1      ).contiguous()
  a__												= model(
      SCREAMING_SNAKE_CASE		,				attention_mask=SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				labels=SCREAMING_SNAKE_CASE		,				)
  self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.num_choices)      )



 def 						_UpperCAmelCase       (	self      ) ->			Tuple:
  a__												= self.prepare_config_and_inputs()
  (
      (
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			
  )												= config_and_inputs
  a__												= {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
  return config, inputs_dict





@require_torch
class    __UpperCamelCase			(       _lowercase	,	_lowercase	,	unittest.TestCase				):

 """simple docstring"""



 _lowercase   :    List[str]      						=					(
     (
         AlbertModel,
         AlbertForPreTraining,
         AlbertForMaskedLM,
         AlbertForMultipleChoice,
         AlbertForSequenceClassification,
         AlbertForTokenClassification,
         AlbertForQuestionAnswering,
     )
     if is_torch_available()
     else ()
 )
 _lowercase   :    List[str]      						=					(
     {
         '''feature-extraction''': AlbertModel,
         '''fill-mask''': AlbertForMaskedLM,
         '''question-answering''': AlbertForQuestionAnswering,
         '''text-classification''': AlbertForSequenceClassification,
         '''token-classification''': AlbertForTokenClassification,
         '''zero-shot''': AlbertForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 _lowercase   :    List[str]      						=					True

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=False      ) ->			List[str]:
  a__												= super()._prepare_for_class(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				return_labels=SCREAMING_SNAKE_CASE      )

  if return_labels:
   if model_class in get_values(SCREAMING_SNAKE_CASE      ):
    a__												= torch.zeros(
        (self.model_tester.batch_size, self.model_tester.seq_length)		,				dtype=torch.long		,				device=SCREAMING_SNAKE_CASE      )
    a__												= torch.zeros(
        self.model_tester.batch_size		,				dtype=torch.long		,				device=SCREAMING_SNAKE_CASE      )
  return inputs_dict

 def 						_UpperCAmelCase       (	self      ) ->			Dict:
  a__												= AlbertModelTester(self      )
  a__												= ConfigTester(self		,				config_class=SCREAMING_SNAKE_CASE		,				hidden_size=3_7      )

 def 						_UpperCAmelCase       (	self      ) ->			Union[str, Any]:
  self.config_tester.run_common_tests()

 def 						_UpperCAmelCase       (	self      ) ->			Union[str, Any]:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			Union[str, Any]:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			Any:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			List[Any]:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			Union[str, Any]:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			Optional[Any]:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			List[Any]:
  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(*SCREAMING_SNAKE_CASE      )



 @slow
 def 						_UpperCAmelCase       (	self      ) ->			List[str]:
  for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   a__												= AlbertModel.from_pretrained(SCREAMING_SNAKE_CASE      )
   self.assertIsNotNone(SCREAMING_SNAKE_CASE      )





@require_torch
class    __UpperCamelCase			(       unittest.TestCase				):

 """simple docstring"""



 @slow
 def 						_UpperCAmelCase       (	self      ) ->			Optional[Any]:
  a__												= AlbertModel.from_pretrained('''albert-base-v2'''      )
  a__												= torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]      )
  a__												= torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
  with torch.no_grad():
   a__												= model(SCREAMING_SNAKE_CASE		,				attention_mask=SCREAMING_SNAKE_CASE      )[0]
  a__												= torch.Size((1, 1_1, 7_6_8)      )
  self.assertEqual(output.shape		,				SCREAMING_SNAKE_CASE      )
  a__												= torch.tensor(
      [[[-0.65_13, 1.50_35, -0.27_66], [-0.65_15, 1.50_46, -0.27_80], [-0.65_12, 1.50_49, -0.27_84]]]      )

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





