
"""simple docstring"""







from __future__ import annotations

import os
import tempfile
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import is_tensorflow_text_available, is_tf_available
from transformers.testing_utils import require_tensorflow_text, require_tf, slow

from ..test_modeling_tf_common import floats_tensor
from .test_framework_agnostic import GenerationIntegrationTestsMixin


if is_tf_available():
		import tensorflow as tf

		from transformers import (
		    AutoTokenizer,
		    TFAutoModelForCausalLM,
		    TFAutoModelForSeqaSeqLM,
		    TFAutoModelForSpeechSeqaSeq,
		    TFAutoModelForVisionaSeq,
		    TFBartForConditionalGeneration,
		    TFLogitsProcessorList,
		    TFMinLengthLogitsProcessor,
		    tf_top_k_top_p_filtering,
		)

if is_tensorflow_text_available():
		import tensorflow_text as text







@require_tf
class 							__magic_name__     (		unittest.TestCase   ):





					def 							lowerCAmelCase      (				self   :							str    ):
												__snake_case     			=       tf.convert_to_tensor(
												    [
												        [
												            8.2220991,  # 3rd highest value; idx. 0
												            -0.5620044,
												            5.23229752,
												            4.0386393,
												            -6.8798378,
												            -0.54785802,
												            -3.2012153,
												            2.92777176,
												            1.88171953,
												            7.35341276,  # 5th highest value; idx. 9
												            8.43207833,  # 2nd highest value; idx. 10
												            -9.85711836,
												            -5.96209236,
												            -1.13039161,
												            -7.1115294,
												            -0.8369633,
												            -5.3186408,
												            7.06427407,
												            0.81369344,
												            -0.82023817,
												            -5.9179796,
												            0.58813443,
												            -6.99778438,
												            4.71551189,
												            -0.18771637,
												            7.44020759,  # 4th highest value; idx. 25
												            9.38450987,  # 1st highest value; idx. 26
												            2.12662941,
												            -9.32562038,
												            2.35652522,
												        ],  # cummulative prob of 5 highest values <= 0.6
												        [
												            0.58425518,
												            4.53139238,
												            -5.57510464,
												            -6.28030699,
												            -7.19529503,
												            -4.02122551,
												            1.39337037,
												            -6.06707057,
												            1.59480517,
												            -9.643119,
												            0.03907799,
												            0.67231762,
												            -8.88206726,
												            6.27115922,  # 4th highest value; idx. 13
												            2.28520723,
												            4.82767506,
												            4.30421368,
												            8.8275313,  # 2nd highest value; idx. 17
												            5.44029958,  # 5th highest value; idx. 18
												            -4.4735794,
												            7.38579536,  # 3rd highest value; idx. 20
												            -2.91051663,
												            2.61946077,
												            -2.5674762,
												            -9.48959302,
												            -4.02922645,
												            -1.35416918,
												            9.67702323,  # 1st highest value; idx. 27
												            -5.89478553,
												            1.85370467,
												        ],  # cummulative prob of 5 highest values <= 0.6
												    ]							,						dtype=tf.floataa							,						)

												__snake_case     			=       tf.convert_to_tensor(
												    [[0, 0], [0, 9], [0, 10], [0, 25], [0, 26], [1, 13], [1, 17], [1, 18], [1, 20], [1, 27]]							,						dtype=tf.intaa							,						)  # expected non filtered idx as noted above

												__snake_case     			=       tf.convert_to_tensor(
												    [8.222099, 7.3534126, 8.432078, 7.4402075, 9.38451, 6.271159, 8.827531, 5.4402995, 7.3857956, 9.677023]							,						dtype=tf.floataa							,						)  # expected non filtered values as noted above

												__snake_case     			=       tf_top_k_top_p_filtering(__A							,						top_k=10							,						top_p=0.6							,						min_tokens_to_keep=4    )

												__snake_case     			=       output[output != -float("inf"    )]
												__snake_case     			=       tf.cast(
												    tf.where(tf.not_equal(__A							,						tf.constant(-float("inf"    )							,						dtype=tf.floataa    )    )    )							,						dtype=tf.intaa							,						)

												tf.debugging.assert_near(__A							,						__A							,						rtol=1e-12    )
												tf.debugging.assert_equal(__A							,						__A    )







@require_tf
class 							__magic_name__     (		unittest.TestCase      ,		lowercase__   ):

					if is_tf_available():
										_SCREAMING_SNAKE_CASE       :					Union[str, Any]     							=   {
										    'AutoModelForCausalLM': TFAutoModelForCausalLM,
										    'AutoModelForSpeechSeq2Seq': TFAutoModelForSpeechSeqaSeq,
										    'AutoModelForSeq2SeqLM': TFAutoModelForSeqaSeqLM,
										    'AutoModelForVision2Seq': TFAutoModelForVisionaSeq,
										    'LogitsProcessorList': TFLogitsProcessorList,
										    'MinLengthLogitsProcessor': TFMinLengthLogitsProcessor,
										    'create_tensor_fn': tf.convert_to_tensor,
										    'floats_tensor': floats_tensor,
										    'return_tensors': 'tf',
										}





					@slow
					def 							lowerCAmelCase      (				self   :							int    ):
												# TF-only test: tf.saved_model export
												__snake_case     			=       TFAutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2"    )
												__snake_case     			=       2
												__snake_case     			=       2







												class 							__magic_name__     (		tf.Module   ):





																	def __init__(				self   :							Tuple							,						snake_case_   :							Optional[int]    ):
																								super(__A							,						self    ).__init__()
																								__snake_case     			=       model





																	@tf.function(
																	    input_signature=(
																	        tf.TensorSpec((None, input_length)							,						tf.intaa							,						name="input_ids"    ),
																	        tf.TensorSpec((None, input_length)							,						tf.intaa							,						name="attention_mask"    ),
																	    )							,						jit_compile=__A							,						)
																	def 							lowerCAmelCase      (				self   :							Optional[Any]							,						snake_case_   :							str							,						snake_case_   :							int    ):
																								__snake_case     			=       self.model.generate(
																								    input_ids=__A							,						attention_mask=__A							,						max_new_tokens=__A							,						return_dict_in_generate=__A							,						)
																								return {"sequences": outputs["sequences"]}




												__snake_case     			=       [[2, 0], [102, 103]]
												__snake_case     			=       [[1, 0], [1, 1]]
												__snake_case     			=       DummyModel(model=__A    )
												with tempfile.TemporaryDirectory() as tmp_dir:
																			tf.saved_model.save(__A							,						__A							,						signatures={"serving_default": dummy_model.serving}    )
																			__snake_case     			=       tf.saved_model.load(__A    ).signatures["serving_default"]
																			for batch_size in range(1							,						len(__A    ) + 1    ):
																										__snake_case     			=       {
																										    "input_ids": tf.constant(dummy_input_ids[:batch_size]    ),
																										    "attention_mask": tf.constant(dummy_attention_masks[:batch_size]    ),
																										}
																										__snake_case     			=       serving_func(**__A    )["sequences"]
																										__snake_case     			=       test_model.generate(**__A							,						max_new_tokens=__A    )
																										tf.debugging.assert_equal(__A							,						__A    )





					@slow
					def 							lowerCAmelCase      (				self   :							List[Any]    ):
												# TF-only test: tf.saved_model export
												__snake_case     			=       TFAutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2"    )
												__snake_case     			=       1
												__snake_case     			=       2







												class 							__magic_name__     (		tf.Module   ):





																	def __init__(				self   :							Tuple							,						snake_case_   :							Union[str, Any]    ):
																								super(__A							,						self    ).__init__()
																								__snake_case     			=       model





																	@tf.function(
																	    input_signature=(
																	        tf.TensorSpec((batch_size, None)							,						tf.intaa							,						name="input_ids"    ),
																	        tf.TensorSpec((batch_size, None)							,						tf.intaa							,						name="attention_mask"    ),
																	    )							,						jit_compile=__A							,						)
																	def 							lowerCAmelCase      (				self   :							int							,						snake_case_   :							Dict							,						snake_case_   :							Any    ):
																								__snake_case     			=       self.model.generate(
																								    input_ids=__A							,						attention_mask=__A							,						max_new_tokens=__A							,						return_dict_in_generate=__A							,						)
																								return {"sequences": outputs["sequences"]}




												__snake_case     			=       [[2], [102, 103]]
												__snake_case     			=       [[1], [1, 1]]
												__snake_case     			=       DummyModel(model=__A    )
												with tempfile.TemporaryDirectory() as tmp_dir:
																			tf.saved_model.save(__A							,						__A							,						signatures={"serving_default": dummy_model.serving}    )
																			__snake_case     			=       tf.saved_model.load(__A    ).signatures["serving_default"]
																			for input_row in range(len(__A    )    ):
																										__snake_case     			=       {
																										    "input_ids": tf.constant([dummy_input_ids[input_row]]    ),
																										    "attention_mask": tf.constant([dummy_attention_masks[input_row]]    ),
																										}
																										__snake_case     			=       serving_func(**__A    )["sequences"]
																										__snake_case     			=       test_model.generate(**__A							,						max_new_tokens=__A    )
																										tf.debugging.assert_equal(__A							,						__A    )





					@slow
					@require_tensorflow_text
					def 							lowerCAmelCase      (				self   :							Optional[Any]    ):
												# TF-only test: tf.saved_model export
												with tempfile.TemporaryDirectory() as tmp_dir:
																			# file needed to load the TF tokenizer
																			hf_hub_download(repo_id="google/flan-t5-small"							,						filename="spiece.model"							,						local_dir=__A    )







																			class 							__magic_name__     (		tf.keras.layers.Layer   ):





																								def __init__(				self   :							int    ):
																															super().__init__()
																															__snake_case     			=       text.SentencepieceTokenizer(
																															    model=tf.io.gfile.GFile(os.path.join(__A							,						"spiece.model"    )							,						"rb"    ).read()    )
																															__snake_case     			=       TFAutoModelForSeqaSeqLM.from_pretrained("hf-internal-testing/tiny-random-t5"    )





																								def 							lowerCAmelCase      (				self   :							Dict							,						snake_case_   :							Dict							,						*snake_case_   :							Any							,						**snake_case_   :							int    ):
																															__snake_case     			=       self.tokenizer.tokenize(__A    )
																															__snake_case			,   __snake_case     			=       text.pad_model_inputs(
																															    __A							,						max_seq_length=64							,						pad_value=self.model.config.pad_token_id    )
																															__snake_case     			=       self.model.generate(input_ids=__A							,						attention_mask=__A    )
																															return self.tokenizer.detokenize(__A    )




																			__snake_case     			=       CompleteSentenceTransformer()
																			__snake_case     			=       tf.keras.layers.Input(shape=(1,)							,						dtype=tf.string							,						name="inputs"    )
																			__snake_case     			=       complete_model(__A    )
																			__snake_case     			=       tf.keras.Model(__A							,						__A    )
																			keras_model.save(__A    )





					def 							lowerCAmelCase      (				self   :							Dict    ):
												# Has PT equivalent: this test relies on random sampling
												__snake_case     			=       {
												    "do_sample": True,
												    "num_beams": 1,
												    "top_p": 0.7,
												    "top_k": 10,
												    "temperature": 0.7,
												}
												__snake_case     			=       14

												__snake_case     			=       AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-gpt2"    )
												__snake_case     			=       "Hello, my dog is cute and"
												__snake_case     			=       tokenizer(__A							,						return_tensors="tf"    )
												__snake_case     			=       TFAutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2"    )

												__snake_case     			=       638
												# forces the generation to happen on CPU, to avoid GPU-related quirks
												with tf.device(":/CPU:0"    ):
																			tf.random.set_seed(0    )
																			__snake_case     			=       model.generate(**__A							,						eos_token_id=__A							,						**__A    )
												self.assertTrue(expectation == len(generated_tokens[0]    )    )

												__snake_case     			=       [638, 198]
												with tf.device(":/CPU:0"    ):
																			tf.random.set_seed(0    )
																			__snake_case     			=       model.generate(**__A							,						eos_token_id=__A							,						**__A    )
												self.assertTrue(expectation == len(generated_tokens[0]    )    )





					def 							lowerCAmelCase      (				self   :							str    ):
												# Has PT equivalent: ample use of framework-specific code
												__snake_case     			=       AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-bart"    )
												__snake_case     			=       "Hugging Face is a technology company based in New York and Paris."
												__snake_case     			=       bart_tokenizer(__A							,						return_tensors="tf"    ).input_ids
												__snake_case     			=       TFBartForConditionalGeneration.from_pretrained("hf-internal-testing/tiny-random-bart"    )
												__snake_case     			=       bart_model.generate(__A    ).numpy()







												class 							__magic_name__     (		lowercase__   ):





																	def 							lowerCAmelCase      (				self   :							Optional[Any]							,						snake_case_   :							Union[str, Any]							,						snake_case_   :							Any=None							,						**snake_case_   :							Optional[int]    ):
																								return super().call(__A							,						**__A    )




												__snake_case     			=       FakeBart.from_pretrained("hf-internal-testing/tiny-random-bart"    )
												__snake_case     			=       bart_model.generate(__A							,						foo="bar"    ).numpy()
												self.assertTrue(np.array_equal(__A							,						__A    )    )







												class 							__magic_name__     (		bart_model.model.encoder.__class__   ):





																	def 							lowerCAmelCase      (				self   :							List[Any]							,						snake_case_   :							Optional[int]							,						**snake_case_   :							Union[str, Any]    ):
																								return super().call(__A							,						**__A    )




												__snake_case     			=       FakeEncoder(bart_model.config							,						bart_model.model.shared    )
												__snake_case     			=       fake_encoder

												# Normal generation still works (the output will be different because the encoder weights are different)
												__snake_case     			=       bart_model.generate(__A    ).numpy()
												with self.assertRaises(__A    ):
																			# FakeEncoder.call() accepts **kwargs -> no filtering -> value error due to unexpected input "foo"
																			bart_model.generate(__A							,						foo="bar"    )


"""simple docstring"""







import argparse
import json

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import ConvNextConfig, SegformerImageProcessor, UperNetConfig, UperNetForSemanticSegmentation
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE )  ->     List[str]:







							"""simple docstring"""


							__snake_case     			=       3_84
							if "tiny" in model_name:
														__snake_case     			=       [3, 3, 9, 3]
														__snake_case     			=       [96, 1_92, 3_84, 7_68]
							if "small" in model_name:
														__snake_case     			=       [3, 3, 27, 3]
														__snake_case     			=       [96, 1_92, 3_84, 7_68]
							if "base" in model_name:
														__snake_case     			=       [3, 3, 27, 3]
														__snake_case     			=       [1_28, 2_56, 5_12, 10_24]
														__snake_case     			=       5_12
							if "large" in model_name:
														__snake_case     			=       [3, 3, 27, 3]
														__snake_case     			=       [1_92, 3_84, 7_68, 15_36]
														__snake_case     			=       7_68
							if "xlarge" in model_name:
														__snake_case     			=       [3, 3, 27, 3]
														__snake_case     			=       [2_56, 5_12, 10_24, 20_48]
														__snake_case     			=       10_24

							# set label information
							__snake_case     			=       1_50
							__snake_case     			=       "huggingface/label-files"
							__snake_case     			=       "ade20k-id2label.json"
							__snake_case     			=       json.load(open(hf_hub_download(SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    repo_type="dataset" )							,    "r" ) )
							__snake_case     			=       {int(SCREAMING_SNAKE_CASE ): v for k, v in idalabel.items()}
							__snake_case     			=       {v: k for k, v in idalabel.items()}

							__snake_case     			=       ConvNextConfig(
							    depths=SCREAMING_SNAKE_CASE							,    hidden_sizes=SCREAMING_SNAKE_CASE							,    out_features=["stage1", "stage2", "stage3", "stage4"] )
							__snake_case     			=       UperNetConfig(
							    backbone_config=SCREAMING_SNAKE_CASE							,    auxiliary_in_channels=SCREAMING_SNAKE_CASE							,    num_labels=SCREAMING_SNAKE_CASE							,    idalabel=SCREAMING_SNAKE_CASE							,    labelaid=SCREAMING_SNAKE_CASE							,    )

							return config
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE )  ->     Optional[Any]:







							"""simple docstring"""


							__snake_case     			=       []

							# fmt: off
							# stem
							rename_keys.append(("backbone.downsample_layers.0.0.weight", "backbone.embeddings.patch_embeddings.weight") )
							rename_keys.append(("backbone.downsample_layers.0.0.bias", "backbone.embeddings.patch_embeddings.bias") )
							rename_keys.append(("backbone.downsample_layers.0.1.weight", "backbone.embeddings.layernorm.weight") )
							rename_keys.append(("backbone.downsample_layers.0.1.bias", "backbone.embeddings.layernorm.bias") )
							# stages
							for i in range(len(config.backbone_config.depths ) ):
														for j in range(config.backbone_config.depths[i] ):
																					rename_keys.append((F'''backbone.stages.{i}.{j}.gamma''', F'''backbone.encoder.stages.{i}.layers.{j}.layer_scale_parameter''') )
																					rename_keys.append((F'''backbone.stages.{i}.{j}.depthwise_conv.weight''', F'''backbone.encoder.stages.{i}.layers.{j}.dwconv.weight''') )
																					rename_keys.append((F'''backbone.stages.{i}.{j}.depthwise_conv.bias''', F'''backbone.encoder.stages.{i}.layers.{j}.dwconv.bias''') )
																					rename_keys.append((F'''backbone.stages.{i}.{j}.norm.weight''', F'''backbone.encoder.stages.{i}.layers.{j}.layernorm.weight''') )
																					rename_keys.append((F'''backbone.stages.{i}.{j}.norm.bias''', F'''backbone.encoder.stages.{i}.layers.{j}.layernorm.bias''') )
																					rename_keys.append((F'''backbone.stages.{i}.{j}.pointwise_conv1.weight''', F'''backbone.encoder.stages.{i}.layers.{j}.pwconv1.weight''') )
																					rename_keys.append((F'''backbone.stages.{i}.{j}.pointwise_conv1.bias''', F'''backbone.encoder.stages.{i}.layers.{j}.pwconv1.bias''') )
																					rename_keys.append((F'''backbone.stages.{i}.{j}.pointwise_conv2.weight''', F'''backbone.encoder.stages.{i}.layers.{j}.pwconv2.weight''') )
																					rename_keys.append((F'''backbone.stages.{i}.{j}.pointwise_conv2.bias''', F'''backbone.encoder.stages.{i}.layers.{j}.pwconv2.bias''') )
														if i > 0:
																					rename_keys.append((F'''backbone.downsample_layers.{i}.0.weight''', F'''backbone.encoder.stages.{i}.downsampling_layer.0.weight''') )
																					rename_keys.append((F'''backbone.downsample_layers.{i}.0.bias''', F'''backbone.encoder.stages.{i}.downsampling_layer.0.bias''') )
																					rename_keys.append((F'''backbone.downsample_layers.{i}.1.weight''', F'''backbone.encoder.stages.{i}.downsampling_layer.1.weight''') )
																					rename_keys.append((F'''backbone.downsample_layers.{i}.1.bias''', F'''backbone.encoder.stages.{i}.downsampling_layer.1.bias''') )

														rename_keys.append((F'''backbone.norm{i}.weight''', F'''backbone.hidden_states_norms.stage{i+1}.weight''') )
														rename_keys.append((F'''backbone.norm{i}.bias''', F'''backbone.hidden_states_norms.stage{i+1}.bias''') )

							# decode head
							rename_keys.extend(
							    [
							        ("decode_head.conv_seg.weight", "decode_head.classifier.weight"),
							        ("decode_head.conv_seg.bias", "decode_head.classifier.bias"),
							        ("auxiliary_head.conv_seg.weight", "auxiliary_head.classifier.weight"),
							        ("auxiliary_head.conv_seg.bias", "auxiliary_head.classifier.bias"),
							    ] )
							# fmt: on

							return rename_keys
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )  ->     str:







							"""simple docstring"""


							__snake_case     			=       dct.pop(SCREAMING_SNAKE_CASE )
							__snake_case     			=       val
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )  ->     Optional[int]:







							"""simple docstring"""


							__snake_case     			=       {
							    "upernet-convnext-tiny": "https://download.openmmlab.com/mmsegmentation/v0.5/convnext/upernet_convnext_tiny_fp16_512x512_160k_ade20k/upernet_convnext_tiny_fp16_512x512_160k_ade20k_20220227_124553-cad485de.pth",
							    "upernet-convnext-small": "https://download.openmmlab.com/mmsegmentation/v0.5/convnext/upernet_convnext_small_fp16_512x512_160k_ade20k/upernet_convnext_small_fp16_512x512_160k_ade20k_20220227_131208-1b1e394f.pth",
							    "upernet-convnext-base": "https://download.openmmlab.com/mmsegmentation/v0.5/convnext/upernet_convnext_base_fp16_512x512_160k_ade20k/upernet_convnext_base_fp16_512x512_160k_ade20k_20220227_181227-02a24fc6.pth",
							    "upernet-convnext-large": "https://download.openmmlab.com/mmsegmentation/v0.5/convnext/upernet_convnext_large_fp16_640x640_160k_ade20k/upernet_convnext_large_fp16_640x640_160k_ade20k_20220226_040532-e57aa54d.pth",
							    "upernet-convnext-xlarge": "https://download.openmmlab.com/mmsegmentation/v0.5/convnext/upernet_convnext_xlarge_fp16_640x640_160k_ade20k/upernet_convnext_xlarge_fp16_640x640_160k_ade20k_20220226_080344-95fc38c2.pth",
							}
							__snake_case     			=       model_name_to_url[model_name]
							__snake_case     			=       torch.hub.load_state_dict_from_url(SCREAMING_SNAKE_CASE							,    map_location="cpu" )["state_dict"]

							__snake_case     			=       get_upernet_config(SCREAMING_SNAKE_CASE )
							__snake_case     			=       UperNetForSemanticSegmentation(SCREAMING_SNAKE_CASE )
							model.eval()

							# replace "bn" => "batch_norm"
							for key in state_dict.copy().keys():
														__snake_case     			=       state_dict.pop(SCREAMING_SNAKE_CASE )
														if "bn" in key:
																					__snake_case     			=       key.replace("bn"							,    "batch_norm" )
														__snake_case     			=       val

							# rename keys
							__snake_case     			=       create_rename_keys(SCREAMING_SNAKE_CASE )
							for src, dest in rename_keys:
														rename_key(SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )

							model.load_state_dict(SCREAMING_SNAKE_CASE )

							# verify on image
							__snake_case     			=       "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg"
							__snake_case     			=       Image.open(requests.get(SCREAMING_SNAKE_CASE							,    stream=SCREAMING_SNAKE_CASE ).raw ).convert("RGB" )

							__snake_case     			=       SegformerImageProcessor()
							__snake_case     			=       processor(SCREAMING_SNAKE_CASE							,    return_tensors="pt" ).pixel_values

							with torch.no_grad():
														__snake_case     			=       model(SCREAMING_SNAKE_CASE )

							if model_name == "upernet-convnext-tiny":
														__snake_case     			=       torch.tensor(
														    [[-8.8_110, -8.8_110, -8.6_521], [-8.8_110, -8.8_110, -8.6_521], [-8.7_746, -8.7_746, -8.6_130]] )
							elif model_name == "upernet-convnext-small":
														__snake_case     			=       torch.tensor(
														    [[-8.8_236, -8.8_236, -8.6_771], [-8.8_236, -8.8_236, -8.6_771], [-8.7_638, -8.7_638, -8.6_240]] )
							elif model_name == "upernet-convnext-base":
														__snake_case     			=       torch.tensor(
														    [[-8.8_558, -8.8_558, -8.6_905], [-8.8_558, -8.8_558, -8.6_905], [-8.7_669, -8.7_669, -8.6_021]] )
							elif model_name == "upernet-convnext-large":
														__snake_case     			=       torch.tensor(
														    [[-8.6_660, -8.6_660, -8.6_210], [-8.6_660, -8.6_660, -8.6_210], [-8.6_310, -8.6_310, -8.5_964]] )
							elif model_name == "upernet-convnext-xlarge":
														__snake_case     			=       torch.tensor(
														    [[-8.4_980, -8.4_980, -8.3_977], [-8.4_980, -8.4_980, -8.3_977], [-8.4_379, -8.4_379, -8.3_412]] )
							print("Logits:"							,    outputs.logits[0, 0, :3, :3] )
							assert torch.allclose(outputs.logits[0, 0, :3, :3]							,    SCREAMING_SNAKE_CASE							,    atol=1e-4 )
							print("Looks ok!" )

							if pytorch_dump_folder_path is not None:
														print(F'''Saving model {model_name} to {pytorch_dump_folder_path}''' )
														model.save_pretrained(SCREAMING_SNAKE_CASE )
														print(F'''Saving processor to {pytorch_dump_folder_path}''' )
														processor.save_pretrained(SCREAMING_SNAKE_CASE )

							if push_to_hub:
														print(F'''Pushing model and processor for {model_name} to hub''' )
														model.push_to_hub(F'''openmmlab/{model_name}''' )
														processor.push_to_hub(F'''openmmlab/{model_name}''' )


if __name__ == "__main__":
		_SCREAMING_SNAKE_CASE	       =      argparse.ArgumentParser()
		# Required parameters
		parser.add_argument(
		    """--model_name""",
		    default="""upernet-convnext-tiny""",
		    type=str,
		    choices=[F"""upernet-convnext-{size}""" for size in ["""tiny""", """small""", """base""", """large""", """xlarge"""]],
		    help="""Name of the ConvNext UperNet model you'd like to convert.""",
		)
		parser.add_argument(
		    """--pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model directory."""
		)
		parser.add_argument(
		    """--push_to_hub""", action="""store_true""", help="""Whether or not to push the converted model to the 🤗 hub."""
		)

		_SCREAMING_SNAKE_CASE	       =      parser.parse_args()
		convert_upernet_checkpoint(args.model_name, args.pytorch_dump_folder_path, args.push_to_hub)
