





"""simple docstring"""




import argparse

import requests
import torch
from PIL import Image

from transformers import ViTMAEConfig, ViTMAEForPreTraining, ViTMAEImageProcessor
def 					_A	(		SCREAMING_SNAKE_CASE					:       str						):





  """simple docstring"""



  if "cls_token" in name:
    a__     : int  =name.replace("cls_token"	,	"vit.embeddings.cls_token"						)
  if "mask_token" in name:
    a__     : Any  =name.replace("mask_token"	,	"decoder.mask_token"						)
  if "decoder_pos_embed" in name:
    a__     : Dict  =name.replace("decoder_pos_embed"	,	"decoder.decoder_pos_embed"						)
  if "pos_embed" in name and "decoder" not in name:
    a__     : Any  =name.replace("pos_embed"	,	"vit.embeddings.position_embeddings"						)
  if "patch_embed.proj" in name:
    a__     : Union[str, Any]  =name.replace("patch_embed.proj"	,	"vit.embeddings.patch_embeddings.projection"						)
  if "patch_embed.norm" in name:
    a__     : Union[str, Any]  =name.replace("patch_embed.norm"	,	"vit.embeddings.norm"						)
  if "decoder_blocks" in name:
    a__     : int  =name.replace("decoder_blocks"	,	"decoder.decoder_layers"						)
  if "blocks" in name:
    a__     : Optional[Any]  =name.replace("blocks"	,	"vit.encoder.layer"						)
  if "attn.proj" in name:
    a__     : Dict  =name.replace("attn.proj"	,	"attention.output.dense"						)
  if "attn" in name:
    a__     : int  =name.replace("attn"	,	"attention.self"						)
  if "norm1" in name:
    a__     : Union[str, Any]  =name.replace("norm1"	,	"layernorm_before"						)
  if "norm2" in name:
    a__     : Optional[Any]  =name.replace("norm2"	,	"layernorm_after"						)
  if "mlp.fc1" in name:
    a__     : Any  =name.replace("mlp.fc1"	,	"intermediate.dense"						)
  if "mlp.fc2" in name:
    a__     : Optional[int]  =name.replace("mlp.fc2"	,	"output.dense"						)
  if "decoder_embed" in name:
    a__     : Tuple  =name.replace("decoder_embed"	,	"decoder.decoder_embed"						)
  if "decoder_norm" in name:
    a__     : Any  =name.replace("decoder_norm"	,	"decoder.decoder_norm"						)
  if "decoder_pred" in name:
    a__     : Optional[int]  =name.replace("decoder_pred"	,	"decoder.decoder_pred"						)
  if "norm.weight" in name and "decoder" not in name:
    a__     : Union[str, Any]  =name.replace("norm.weight"	,	"vit.layernorm.weight"						)
  if "norm.bias" in name and "decoder" not in name:
    a__     : Dict  =name.replace("norm.bias"	,	"vit.layernorm.bias"						)

  return name
def 					_A	(		SCREAMING_SNAKE_CASE					:       Any	,	SCREAMING_SNAKE_CASE					:       Dict						):





  """simple docstring"""



  for key in orig_state_dict.copy().keys():
    a__     : List[str]  =orig_state_dict.pop(SCREAMING_SNAKE_CASE						)

    if "qkv" in key:
      a__     : Union[str, Any]  =key.split("."						)
      a__     : Union[str, Any]  =int(key_split[1]						)
      if "decoder_blocks" in key:
        a__     : int  =config.decoder_hidden_size
        a__     : List[str]  ="decoder.decoder_layers."
        if "weight" in key:
          a__     : Dict  =val[:dim, :]
          a__     : int  =val[dim : dim * 2, :]
          a__     : List[str]  =val[-dim:, :]
        elif "bias" in key:
          a__     : Union[str, Any]  =val[:dim]
          a__     : Tuple  =val[dim : dim * 2]
          a__     : Dict  =val[-dim:]
      else:
        a__     : Union[str, Any]  =config.hidden_size
        a__     : str  ="vit.encoder.layer."
        if "weight" in key:
          a__     : Tuple  =val[:dim, :]
          a__     : Any  =val[dim : dim * 2, :]
          a__     : Tuple  =val[-dim:, :]
        elif "bias" in key:
          a__     : Optional[int]  =val[:dim]
          a__     : Optional[int]  =val[dim : dim * 2]
          a__     : Any  =val[-dim:]

    else:
      a__     : int  =val

  return orig_state_dict
def 					_A	(		SCREAMING_SNAKE_CASE					:       Optional[Any]	,	SCREAMING_SNAKE_CASE					:       str						):





  """simple docstring"""



  a__     : Optional[Any]  =ViTMAEConfig()
  if "large" in checkpoint_url:
    a__     : int  =1_024
    a__     : Optional[Any]  =4_096
    a__     : Union[str, Any]  =24
    a__     : Union[str, Any]  =16
  elif "huge" in checkpoint_url:
    a__     : int  =14
    a__     : Tuple  =1_280
    a__     : Tuple  =5_120
    a__     : int  =32
    a__     : Optional[int]  =16

  a__     : int  =ViTMAEForPreTraining(SCREAMING_SNAKE_CASE						)

  a__     : Optional[int]  =torch.hub.load_state_dict_from_url(SCREAMING_SNAKE_CASE	,	map_location="cpu"						)["model"]

  a__     : Union[str, Any]  =ViTMAEImageProcessor(size=config.image_size						)

  a__     : Tuple  =convert_state_dict(SCREAMING_SNAKE_CASE	,	SCREAMING_SNAKE_CASE						)

  model.load_state_dict(SCREAMING_SNAKE_CASE						)
  model.eval()

  a__     : List[str]  ="https://user-images.githubusercontent.com/11435359/147738734-196fd92f-9260-48d5-ba7e-bf103d29364d.jpg"

  a__     : List[Any]  =Image.open(requests.get(SCREAMING_SNAKE_CASE	,	stream=SCREAMING_SNAKE_CASE						).raw						)
  a__     : Optional[int]  =ViTMAEImageProcessor(size=config.image_size						)
  a__     : List[str]  =image_processor(images=SCREAMING_SNAKE_CASE	,	return_tensors="pt"						)

  # forward pass
  torch.manual_seed(2						)
  a__     : Tuple  =model(**SCREAMING_SNAKE_CASE						)
  a__     : Optional[int]  =outputs.logits

  if "large" in checkpoint_url:
    a__     : Union[str, Any]  =torch.tensor(
        [[-0.7_3_0_9, -0.7_1_2_8, -1.0_1_6_9], [-1.0_1_6_1, -0.9_0_5_8, -1.1_8_7_8], [-1.0_4_7_8, -0.9_4_1_1, -1.1_9_1_1]]						)
  elif "huge" in checkpoint_url:
    a__     : List[str]  =torch.tensor(
        [[-1.1_5_9_9, -0.9_1_9_9, -1.2_2_2_1], [-1.1_9_5_2, -0.9_2_6_9, -1.2_3_0_7], [-1.2_1_4_3, -0.9_3_3_7, -1.2_2_6_2]]						)
  else:
    a__     : Optional[int]  =torch.tensor(
        [[-0.9_1_9_2, -0.8_4_8_1, -1.1_2_5_9], [-1.1_3_4_9, -1.0_0_3_4, -1.2_5_9_9], [-1.1_7_5_7, -1.0_4_2_9, -1.2_7_2_6]]						)

  # verify logits
  assert torch.allclose(logits[0, :3, :3]	,	SCREAMING_SNAKE_CASE	,	atol=1e-4						)

  print(f'''Saving model to {pytorch_dump_folder_path}'''						)
  model.save_pretrained(SCREAMING_SNAKE_CASE						)

  print(f'''Saving image processor to {pytorch_dump_folder_path}'''						)
  image_processor.save_pretrained(SCREAMING_SNAKE_CASE						)


if __name__ == "__main__":
     UpperCAmelCase     :     List[str]							=	argparse.ArgumentParser()
     # Required parameters
     parser.add_argument(
         """--checkpoint_url""",
         default="""https://dl.fbaipublicfiles.com/mae/visualize/mae_visualize_vit_base.pth""",
         type=str,
         help="""URL of the checkpoint you'd like to convert.""",
     )
     parser.add_argument(
         """--pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model directory."""
     )

     UpperCAmelCase     :     List[str]							=	parser.parse_args()
     convert_vit_mae_checkpoint(args.checkpoint_url, args.pytorch_dump_folder_path)













from __future__ import annotations

import math
def 					_A	(		SCREAMING_SNAKE_CASE					:       int						):





  """simple docstring"""



  if num <= 0:
    a__     : List[str]  =f'''{num}: Invalid input, please enter a positive integer.'''
    raise ValueError(SCREAMING_SNAKE_CASE						)

  a__     : Union[str, Any]  =[True] * (num + 1)
  a__     : Union[str, Any]  =[]
  a__     : str  =2
  a__     : Any  =int(math.sqrt(SCREAMING_SNAKE_CASE						)						)

  while start <= end:
    # If start is a prime
    if sieve[start] is True:
      prime.append(SCREAMING_SNAKE_CASE						)

      # Set multiples of start be False
      for i in range(start * start	,	num + 1	,	SCREAMING_SNAKE_CASE						):
        if sieve[i] is True:
          a__     : Optional[int]  =False

    start += 1

  for j in range(end + 1	,	num + 1						):
    if sieve[j] is True:
      prime.append(SCREAMING_SNAKE_CASE						)

  return prime


if __name__ == "__main__":
     print(prime_sieve(int(input("""Enter a positive integer: """).strip())))






