





"""simple docstring"""
import torch
import torch.nn.functional as F

from diffusers import VQDiffusionScheduler

from .test_schedulers import SchedulerCommonTest






class lowerCamelCase__  (    lowercase__				):
   __UpperCAmelCase        =					(VQDiffusionScheduler,)



   def    _UpperCAmelCase	(       self      ,   **snake_case	) ->    Dict:







      """simple docstring"""
      lowercase    :			Tuple  =       {
          'num_vec_classes': 4_0_9_7,
          'num_train_timesteps': 1_0_0,
      }

      config.update(**_A	)
      return config



   def    _UpperCAmelCase	(       self      ,   snake_case	) ->    Optional[Any]:







      """simple docstring"""
      lowercase    :			Dict  =       4
      lowercase    :			List[str]  =       8
      lowercase    :			Optional[int]  =       8

      lowercase    :			str  =       torch.randint(0      ,   _A      ,   (batch_size, height * width)	)

      return sample



   @property
   def    _UpperCAmelCase	(       self	) ->    Optional[int]:







      """simple docstring"""
      assert False



   def    _UpperCAmelCase	(       self      ,   snake_case	) ->    Optional[int]:







      """simple docstring"""
      def model(snake_case      ,   snake_case      ,   *snake_case	):
         lowercase    :			Optional[int]  =       sample.shape
         lowercase    :			Union[str, Any]  =       torch.rand((batch_size, num_vec_classes - 1, num_latent_pixels)	)
         lowercase    :			str  =       F.log_softmax(logits.double()      ,   dim=1	).float()
         return return_value

      return model



   def    _UpperCAmelCase	(       self	) ->    Dict:







      """simple docstring"""
      for timesteps in [2, 5, 1_0_0, 1_0_0_0]:
         self.check_over_configs(num_train_timesteps=_A	)



   def    _UpperCAmelCase	(       self	) ->    List[Any]:







      """simple docstring"""
      for num_vec_classes in [5, 1_0_0, 1_0_0_0, 4_0_0_0]:
         self.check_over_configs(num_vec_classes=_A	)



   def    _UpperCAmelCase	(       self	) ->    str:







      """simple docstring"""
      for t in [0, 5_0, 9_9]:
         self.check_over_forward(time_step=_A	)





   def    _UpperCAmelCase	(       self	) ->    Any:







      """simple docstring"""
      pass









"""simple docstring"""
import argparse

from . import (
    BertConfig,
    BertGenerationConfig,
    BertGenerationDecoder,
    BertGenerationEncoder,
    load_tf_weights_in_bert_generation,
    logging,
)


logging.set_verbosity_info()




def 			__snake_case						(      __A ,__A ,__A ,__A ,__A    )		->				Optional[int]:
   # Initialise PyTorch model
   lowercase    :			Optional[Any]  =       BertConfig.from_pretrained(
       """bert-large-cased""" ,vocab_size=__A ,max_position_embeddings=512 ,is_decoder=__A ,add_cross_attention=__A ,)
   lowercase    :			List[str]  =       bert_config.to_dict()
   del bert_config_dict["type_vocab_size"]
   lowercase    :			Tuple  =       BertGenerationConfig(**__A    )
   if is_encoder:
      lowercase    :			Dict  =       BertGenerationEncoder(__A    )
   else:
      lowercase    :			Dict  =       BertGenerationDecoder(__A    )
   print(F'''Building PyTorch model from configuration: {config}'''    )

   # Load weights from tf checkpoint
   load_tf_weights_in_bert_generation(
       __A ,__A ,model_class="""bert""" ,is_encoder_named_decoder=__A ,is_encoder=__A ,)

   # Save pytorch-model
   print(F'''Save PyTorch model and config to {pytorch_dump_path}'''    )
   model.save_pretrained(__A    )


if __name__ == "__main__":
   lowerCAmelCase:	Dict							      =argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       "--tf_hub_path", default=None, type=str, required=True, help="Path to the TensorFlow checkpoint path."
   )
   parser.add_argument(
       "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
   )
   parser.add_argument(
       "--is_encoder_named_decoder",
       action="store_true",
       help="If decoder has to be renamed to encoder in PyTorch model.",
   )
   parser.add_argument("--is_encoder", action="store_true", help="If model is an encoder.")
   parser.add_argument("--vocab_size", default=50358, type=int, help="Vocab size of model")
   lowerCAmelCase:	Optional[int]							      =parser.parse_args()
   convert_tf_checkpoint_to_pytorch(
       args.tf_hub_path,
       args.pytorch_dump_path,
       args.is_encoder_named_decoder,
       args.vocab_size,
       is_encoder=args.is_encoder,
   )


