


import shutil
import tempfile
import unittest

from transformers import (
    SPIECE_UNDERLINE,
    AddedToken,
    BatchEncoding,
    NllbTokenizer,
    NllbTokenizerFast,
    is_torch_available,
)
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


A							:					Union[str, Any]     			=     get_tests_dir('fixtures/test_sentencepiece.model')


if is_torch_available():
	from transformers.models.mam_aaa.modeling_mam_aaa import shift_tokens_right

A							:					int     			=     256047
A							:					int     			=     256145






@require_sentencepiece
@require_tokenizers
class     UpperCamelCase(  _a     ,							unittest.TestCase   ):
					snake_case_		:				int										=	NllbTokenizer
					snake_case_		:				int										=	NllbTokenizerFast
					snake_case_		:				List[str]										=	True
					snake_case_		:				Union[str, Any]										=	True
					snake_case_		:				Any										=	{}


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple						)			->	Optional[Any]:




											'''simple docstring'''

											super().setUp()

											# We have a SentencePiece fixture for testing
											__snake_case				=		NllbTokenizer(SCREAMING_SNAKE_CASE     ,    keep_accents=SCREAMING_SNAKE_CASE						)
											tokenizer.save_pretrained(self.tmpdirname						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		int						)			->	Tuple:




											'''simple docstring'''

											__snake_case				=		NllbTokenizer(SCREAMING_SNAKE_CASE     ,    keep_accents=SCREAMING_SNAKE_CASE						)

											__snake_case				=		tokenizer.tokenize("This is a test"						)
											self.assertListEqual(SCREAMING_SNAKE_CASE     ,    ["▁This", "▁is", "▁a", "▁t", "est"]						)

											self.assertListEqual(
											    tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE						)     ,    [value + tokenizer.fairseq_offset for value in [2_8_5, 4_6, 1_0, 1_7_0, 3_8_2]]     ,    )

											__snake_case				=		tokenizer.tokenize("I was born in 92000, and this is falsé."						)
											self.assertListEqual(
											    SCREAMING_SNAKE_CASE     ,    [
											        SPIECE_UNDERLINE + "I",
											        SPIECE_UNDERLINE + "was",
											        SPIECE_UNDERLINE + "b",
											        "or",
											        "n",
											        SPIECE_UNDERLINE + "in",
											        SPIECE_UNDERLINE + "",
											        "9",
											        "2",
											        "0",
											        "0",
											        "0",
											        ",",
											        SPIECE_UNDERLINE + "and",
											        SPIECE_UNDERLINE + "this",
											        SPIECE_UNDERLINE + "is",
											        SPIECE_UNDERLINE + "f",
											        "al",
											        "s",
											        "é",
											        ".",
											    ]     ,    )
											__snake_case				=		tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE						)
											self.assertListEqual(
											    SCREAMING_SNAKE_CASE     ,    [
											        value + tokenizer.fairseq_offset
											        for value in [8, 2_1, 8_4, 5_5, 2_4, 1_9, 7, 2, 6_0_2, 3_4_7, 3_4_7, 3_4_7, 3, 1_2, 6_6, 4_6, 7_2, 8_0, 6, 2, 4]
											    ]     ,    )

											__snake_case				=		tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE						)
											self.assertListEqual(
											    SCREAMING_SNAKE_CASE     ,    [
											        SPIECE_UNDERLINE + "I",
											        SPIECE_UNDERLINE + "was",
											        SPIECE_UNDERLINE + "b",
											        "or",
											        "n",
											        SPIECE_UNDERLINE + "in",
											        SPIECE_UNDERLINE + "",
											        "<unk>",
											        "2",
											        "0",
											        "0",
											        "0",
											        ",",
											        SPIECE_UNDERLINE + "and",
											        SPIECE_UNDERLINE + "this",
											        SPIECE_UNDERLINE + "is",
											        SPIECE_UNDERLINE + "f",
											        "al",
											        "s",
											        "<unk>",
											        ".",
											    ]     ,    )


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[Any]						)			->	Optional[Any]:




											'''simple docstring'''

											__snake_case				=		(self.rust_tokenizer_class, "hf-internal-testing/tiny-random-nllb", {})
											for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																	with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''						):
																							__snake_case				=		self.rust_tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)
																							__snake_case				=		self.tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)

																							__snake_case				=		tempfile.mkdtemp()

																							__snake_case				=		tokenizer_r.save_pretrained(SCREAMING_SNAKE_CASE						)
																							__snake_case				=		tokenizer_p.save_pretrained(SCREAMING_SNAKE_CASE						)

																							# Checks it save with the same files + the tokenizer.json file for the fast one
																							self.assertTrue(any("tokenizer.json" in f for f in tokenizer_r_files						)						)
																							__snake_case				=		tuple(f for f in tokenizer_r_files if "tokenizer.json" not in f						)
																							self.assertSequenceEqual(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)

																							# Checks everything loads correctly in the same way
																							__snake_case				=		tokenizer_r.from_pretrained(SCREAMING_SNAKE_CASE						)
																							__snake_case				=		tokenizer_p.from_pretrained(SCREAMING_SNAKE_CASE						)

																							# Check special tokens are set accordingly on Rust and Python
																							for key in tokenizer_pp.special_tokens_map:
																													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)						)

																							shutil.rmtree(SCREAMING_SNAKE_CASE						)

																							# Save tokenizer rust, legacy_format=True
																							__snake_case				=		tempfile.mkdtemp()

																							__snake_case				=		tokenizer_r.save_pretrained(SCREAMING_SNAKE_CASE     ,    legacy_format=SCREAMING_SNAKE_CASE						)
																							__snake_case				=		tokenizer_p.save_pretrained(SCREAMING_SNAKE_CASE						)

																							# Checks it save with the same files
																							self.assertSequenceEqual(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)

																							# Checks everything loads correctly in the same way
																							__snake_case				=		tokenizer_r.from_pretrained(SCREAMING_SNAKE_CASE						)
																							__snake_case				=		tokenizer_p.from_pretrained(SCREAMING_SNAKE_CASE						)

																							# Check special tokens are set accordingly on Rust and Python
																							for key in tokenizer_pp.special_tokens_map:
																													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)						)

																							shutil.rmtree(SCREAMING_SNAKE_CASE						)

																							# Save tokenizer rust, legacy_format=False
																							__snake_case				=		tempfile.mkdtemp()

																							__snake_case				=		tokenizer_r.save_pretrained(SCREAMING_SNAKE_CASE     ,    legacy_format=SCREAMING_SNAKE_CASE						)
																							__snake_case				=		tokenizer_p.save_pretrained(SCREAMING_SNAKE_CASE						)

																							# Checks it saved the tokenizer.json file
																							self.assertTrue(any("tokenizer.json" in f for f in tokenizer_r_files						)						)

																							# Checks everything loads correctly in the same way
																							__snake_case				=		tokenizer_r.from_pretrained(SCREAMING_SNAKE_CASE						)
																							__snake_case				=		tokenizer_p.from_pretrained(SCREAMING_SNAKE_CASE						)

																							# Check special tokens are set accordingly on Rust and Python
																							for key in tokenizer_pp.special_tokens_map:
																													self.assertTrue(hasattr(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)						)

																							shutil.rmtree(SCREAMING_SNAKE_CASE						)


					@require_torch
					def 							SCREAMING_SNAKE_CASE_  (						self	:		int						)			->	List[Any]:




											'''simple docstring'''

											if not self.test_seqaseq:
																	return

											__snake_case				=		self.get_tokenizers()
											for tokenizer in tokenizers:
																	with self.subTest(f'''{tokenizer.__class__.__name__}'''						):
																							# Longer text that will definitely require truncation.
																							__snake_case				=		[
																							    " UN Chief Says There Is No Military Solution in Syria",
																							    " Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for"
																							    " Syria is that 'there is no military solution' to the nearly five-year conflict and more weapons"
																							    " will only worsen the violence and misery for millions of people.",
																							]
																							__snake_case				=		[
																							    "Şeful ONU declară că nu există o soluţie militară în Siria",
																							    "Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al"
																							    " Rusiei pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi"
																							    " că noi arme nu vor face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.",
																							]
																							try:
																													__snake_case				=		tokenizer.prepare_seqaseq_batch(
																													    src_texts=SCREAMING_SNAKE_CASE     ,    tgt_texts=SCREAMING_SNAKE_CASE     ,    max_length=3     ,    max_target_length=1_0     ,    return_tensors="pt"     ,    src_lang="eng_Latn"     ,    tgt_lang="ron_Latn"     ,    )
																							except NotImplementedError:
																													return
																							self.assertEqual(batch.input_ids.shape[1]     ,    3						)
																							self.assertEqual(batch.labels.shape[1]     ,    1_0						)
																							# max_target_length will default to max_length if not specified
																							__snake_case				=		tokenizer.prepare_seqaseq_batch(
																							    SCREAMING_SNAKE_CASE     ,    tgt_texts=SCREAMING_SNAKE_CASE     ,    max_length=3     ,    return_tensors="pt"						)
																							self.assertEqual(batch.input_ids.shape[1]     ,    3						)
																							self.assertEqual(batch.labels.shape[1]     ,    3						)

																							__snake_case				=		tokenizer.prepare_seqaseq_batch(
																							    src_texts=SCREAMING_SNAKE_CASE     ,    max_length=3     ,    max_target_length=1_0     ,    return_tensors="pt"						)
																							self.assertEqual(batch_encoder_only.input_ids.shape[1]     ,    3						)
																							self.assertEqual(batch_encoder_only.attention_mask.shape[1]     ,    3						)
																							self.assertNotIn("decoder_input_ids"     ,    SCREAMING_SNAKE_CASE						)


					@unittest.skip("Unfortunately way too slow to build a BPE with SentencePiece."						)
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Optional[int]:




											'''simple docstring'''

											pass






					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]						)			->	Dict:




											'''simple docstring'''

											for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																	with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''						):
																							__snake_case				=		[AddedToken("<special>"     ,    lstrip=SCREAMING_SNAKE_CASE						)]

																							__snake_case				=		self.rust_tokenizer_class.from_pretrained(
																							    SCREAMING_SNAKE_CASE     ,    additional_special_tokens=SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)
																							__snake_case				=		tokenizer_r.encode("Hey this is a <special> token"						)

																							__snake_case				=		tokenizer_r.encode("<special>"     ,    add_special_tokens=SCREAMING_SNAKE_CASE						)[0]

																							self.assertTrue(special_token_id in r_output						)

																							if self.test_slow_tokenizer:
																													__snake_case				=		self.rust_tokenizer_class.from_pretrained(
																													    SCREAMING_SNAKE_CASE     ,    additional_special_tokens=SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE     ,    )
																													__snake_case				=		self.tokenizer_class.from_pretrained(
																													    SCREAMING_SNAKE_CASE     ,    additional_special_tokens=SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)

																													__snake_case				=		tokenizer_p.encode("Hey this is a <special> token"						)

																													__snake_case				=		tokenizer_cr.encode("Hey this is a <special> token"						)

																													self.assertEqual(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)
																													self.assertEqual(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)
																													self.assertTrue(special_token_id in p_output						)
																													self.assertTrue(special_token_id in cr_output						)






@require_torch
@require_sentencepiece
@require_tokenizers
class     UpperCamelCase(  unittest.TestCase   ):
					snake_case_		:				Optional[Any]										=	"""facebook/nllb-200-distilled-600M"""
					snake_case_		:				Optional[Any]										=	[
					    """ UN Chief Says There Is No Military Solution in Syria""",
					    """ Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for Syria is that \"there is no military solution\" to the nearly five-year conflict and more weapons will only worsen the violence and misery for millions of people.""",
					]
					snake_case_		:				List[str]										=	[
					    """Şeful ONU declară că nu există o soluţie militară în Siria""",
					    """Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al Rusiei"""
					    """ pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi că noi arme nu vor"""
					    """ face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.""",
					]
					snake_case_		:				int										=	[
					    25_6047,
					    1_6297,
					    13_4408,
					    8165,
					    24_8066,
					    1_4734,
					    950,
					    1135,
					    10_5721,
					    3573,
					    83,
					    2_7352,
					    108,
					    4_9486,
					    2,
					]


					@classmethod
					def 							SCREAMING_SNAKE_CASE_  (						cls	:		Optional[Any]						)			->	str:




											'''simple docstring'''

											__snake_case				=		NllbTokenizer.from_pretrained(
											    cls.checkpoint_name     ,    src_lang="eng_Latn"     ,    tgt_lang="ron_Latn"						)
											__snake_case				=		1
											return cls


					def 							SCREAMING_SNAKE_CASE_  (						self	:		str						)			->	List[Any]:




											'''simple docstring'''

											self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["ace_Arab"]     ,    2_5_6_0_0_1						)
											self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["ace_Latn"]     ,    2_5_6_0_0_2						)
											self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["fra_Latn"]     ,    2_5_6_0_5_7						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Any:




											'''simple docstring'''

											__snake_case				=		self.tokenizer.batch_encode_plus(self.src_text						).input_ids[0]
											self.assertListEqual(self.expected_src_tokens     ,    SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]						)			->	Union[str, Any]:




											'''simple docstring'''

											self.assertIn(SCREAMING_SNAKE_CASE     ,    self.tokenizer.all_special_ids						)
											# fmt: off
											__snake_case				=		[RO_CODE, 4_2_5_4, 9_8_0_6_8, 1_1_2_9_2_3, 3_9_0_7_2, 3_9_0_9, 7_1_3, 1_0_2_7_6_7, 2_6, 1_7_3_1_4, 3_5_6_4_2, 1_4_6_8_3, 3_3_1_1_8, 2_0_2_2, 6_6_9_8_7, 2, 2_5_6_0_4_7]
											# fmt: on

											__snake_case				=		self.tokenizer.decode(SCREAMING_SNAKE_CASE     ,    skip_special_tokens=SCREAMING_SNAKE_CASE						)
											__snake_case				=		self.tokenizer.decode(generated_ids[1:]     ,    skip_special_tokens=SCREAMING_SNAKE_CASE						)
											self.assertEqual(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)
											self.assertNotIn(self.tokenizer.eos_token     ,    SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	Dict:




											'''simple docstring'''

											__snake_case				=		["this is gunna be a long sentence " * 2_0]
											assert isinstance(src_text[0]     ,    SCREAMING_SNAKE_CASE						)
											__snake_case				=		1_0
											__snake_case				=		self.tokenizer(SCREAMING_SNAKE_CASE     ,    max_length=SCREAMING_SNAKE_CASE     ,    truncation=SCREAMING_SNAKE_CASE						).input_ids[0]
											self.assertEqual(ids[-1]     ,    2						)
											self.assertEqual(ids[0]     ,    SCREAMING_SNAKE_CASE						)
											self.assertEqual(len(SCREAMING_SNAKE_CASE						)     ,    SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Tuple:




											'''simple docstring'''

											self.assertListEqual(self.tokenizer.convert_tokens_to_ids(["<mask>", "ar_AR"]						)     ,    [2_5_6_2_0_3, 3]						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Union[str, Any]						)			->	int:




											'''simple docstring'''

											__snake_case				=		tempfile.mkdtemp()
											__snake_case				=		self.tokenizer.fairseq_tokens_to_ids
											self.tokenizer.save_pretrained(SCREAMING_SNAKE_CASE						)
											__snake_case				=		NllbTokenizer.from_pretrained(SCREAMING_SNAKE_CASE						)
											self.assertDictEqual(new_tok.fairseq_tokens_to_ids     ,    SCREAMING_SNAKE_CASE						)


					@require_torch
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[Any]						)			->	str:




											'''simple docstring'''

											__snake_case				=		self.tokenizer(
											    self.src_text     ,    text_target=self.tgt_text     ,    padding=SCREAMING_SNAKE_CASE     ,    truncation=SCREAMING_SNAKE_CASE     ,    max_length=len(self.expected_src_tokens						)     ,    return_tensors="pt"     ,    )
											__snake_case				=		shift_tokens_right(
											    batch["labels"]     ,    self.tokenizer.pad_token_id     ,    self.tokenizer.lang_code_to_id["ron_Latn"]						)

											self.assertIsInstance(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)

											self.assertEqual((2, 1_5)     ,    batch.input_ids.shape						)
											self.assertEqual((2, 1_5)     ,    batch.attention_mask.shape						)
											__snake_case				=		batch.input_ids.tolist()[0]
											self.assertListEqual(self.expected_src_tokens     ,    SCREAMING_SNAKE_CASE						)
											self.assertEqual(SCREAMING_SNAKE_CASE     ,    batch.decoder_input_ids[0, 0]						)  # EOS
											# Test that special tokens are reset
											self.assertEqual(self.tokenizer.prefix_tokens     ,    [EN_CODE]						)
											self.assertEqual(self.tokenizer.suffix_tokens     ,    [self.tokenizer.eos_token_id]						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]						)			->	int:




											'''simple docstring'''

											__snake_case				=		self.tokenizer(self.src_text     ,    padding=SCREAMING_SNAKE_CASE     ,    truncation=SCREAMING_SNAKE_CASE     ,    max_length=3     ,    return_tensors="pt"						)
											__snake_case				=		self.tokenizer(
											    text_target=self.tgt_text     ,    padding=SCREAMING_SNAKE_CASE     ,    truncation=SCREAMING_SNAKE_CASE     ,    max_length=1_0     ,    return_tensors="pt"						)
											__snake_case				=		targets["input_ids"]
											__snake_case				=		shift_tokens_right(
											    SCREAMING_SNAKE_CASE     ,    self.tokenizer.pad_token_id     ,    decoder_start_token_id=self.tokenizer.lang_code_to_id[self.tokenizer.tgt_lang]     ,    )

											self.assertEqual(batch.input_ids.shape[1]     ,    3						)
											self.assertEqual(batch.decoder_input_ids.shape[1]     ,    1_0						)


					@require_torch
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	str:




											'''simple docstring'''

											__snake_case				=		self.tokenizer._build_translation_inputs(
											    "A test"     ,    return_tensors="pt"     ,    src_lang="eng_Latn"     ,    tgt_lang="fra_Latn"						)

											self.assertEqual(
											    nested_simplify(SCREAMING_SNAKE_CASE						)     ,    {
											        # A, test, EOS, en_XX
											        "input_ids": [[2_5_6_0_4_7, 7_0, 7_3_5_6, 2]],
											        "attention_mask": [[1, 1, 1, 1]],
											        # ar_AR
											        "forced_bos_token_id": 2_5_6_0_5_7,
											    }     ,    )






					@require_torch
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Any:




											'''simple docstring'''

											__snake_case				=		True
											__snake_case				=		self.tokenizer(
											    "UN Chief says there is no military solution in Syria"     ,    src_lang="eng_Latn"     ,    tgt_lang="fra_Latn"						)
											self.assertEqual(
											    inputs.input_ids     ,    [1_6_2_9_7, 1_3_4_4_0_8, 2_5_6_5_3, 6_3_7_0, 2_4_8, 2_5_4, 1_0_3_9_2_9, 9_4_9_9_5, 1_0_8, 4_9_4_8_6, 2, 2_5_6_0_4_7]						)

											__snake_case				=		False
											__snake_case				=		self.tokenizer(
											    "UN Chief says there is no military solution in Syria"     ,    src_lang="eng_Latn"     ,    tgt_lang="fra_Latn"						)
											self.assertEqual(
											    inputs.input_ids     ,    [2_5_6_0_4_7, 1_6_2_9_7, 1_3_4_4_0_8, 2_5_6_5_3, 6_3_7_0, 2_4_8, 2_5_4, 1_0_3_9_2_9, 9_4_9_9_5, 1_0_8, 4_9_4_8_6, 2]						)









import random
import unittest

import numpy as np
import torch

from diffusers import (
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionUpscalePipeline,
    PNDMScheduler,
)
from diffusers.utils import floats_tensor
from diffusers.utils.testing_utils import (
    is_onnx_available,
    load_image,
    nightly,
    require_onnxruntime,
    require_torch_gpu,
)

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
	import onnxruntime as ort






class     UpperCamelCase(  _a     ,							unittest.TestCase   ):
					# TODO: is there an appropriate internal test set?
					snake_case_		:				Dict										=	"""ssube/stable-diffusion-x4-upscaler-onnx"""


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict     ,    SCREAMING_SNAKE_CASE	:		List[str]=0						)			->	Union[str, Any]:




											'''simple docstring'''

											__snake_case				=		floats_tensor((1, 3, 1_2_8, 1_2_8)     ,    rng=random.Random(SCREAMING_SNAKE_CASE						)						)
											__snake_case				=		torch.manual_seed(SCREAMING_SNAKE_CASE						)
											__snake_case				=		{
											    "prompt": "A painting of a squirrel eating a burger",
											    "image": image,
											    "generator": generator,
											    "num_inference_steps": 3,
											    "guidance_scale": 7.5,
											    "output_type": "numpy",
											}
											return inputs


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	List[str]:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

											__snake_case				=		self.get_dummy_inputs()
											__snake_case				=		pipe(**SCREAMING_SNAKE_CASE						).images
											__snake_case				=		image[0, -3:, -3:, -1].flatten()

											# started as 128, should now be 512
											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		np.array(
											    [0.6974782, 0.68902093, 0.70135885, 0.7583618, 0.7804545, 0.7854912, 0.78667426, 0.78743863, 0.78070223]						)
											assert np.abs(image_slice - expected_slice						).max() < 1e-1


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Optional[Any]:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											__snake_case				=		PNDMScheduler.from_config(pipe.scheduler.config     ,    skip_prk_steps=SCREAMING_SNAKE_CASE						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

											__snake_case				=		self.get_dummy_inputs()
											__snake_case				=		pipe(**SCREAMING_SNAKE_CASE						).images
											__snake_case				=		image[0, -3:, -3:, -1]

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		np.array(
											    [0.6898892, 0.59240556, 0.52499527, 0.58866215, 0.52258235, 0.52572715, 0.62414473, 0.6174387, 0.6214964]						)
											assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-1


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	Optional[int]:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											__snake_case				=		DPMSolverMultistepScheduler.from_config(pipe.scheduler.config						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

											__snake_case				=		self.get_dummy_inputs()
											__snake_case				=		pipe(**SCREAMING_SNAKE_CASE						).images
											__snake_case				=		image[0, -3:, -3:, -1]

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		np.array(
											    [0.7659278, 0.76437664, 0.75579107, 0.7691116, 0.77666986, 0.7727672, 0.7758664, 0.7812226, 0.76942515]						)

											assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-1


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Dict:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											__snake_case				=		EulerDiscreteScheduler.from_config(pipe.scheduler.config						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

											__snake_case				=		self.get_dummy_inputs()
											__snake_case				=		pipe(**SCREAMING_SNAKE_CASE						).images
											__snake_case				=		image[0, -3:, -3:, -1]

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		np.array(
											    [0.6974782, 0.68902093, 0.70135885, 0.7583618, 0.7804545, 0.7854912, 0.78667426, 0.78743863, 0.78070223]						)
											assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-1






					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]						)			->	List[str]:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											__snake_case				=		EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

											__snake_case				=		self.get_dummy_inputs()
											__snake_case				=		pipe(**SCREAMING_SNAKE_CASE						).images
											__snake_case				=		image[0, -3:, -3:, -1]

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		np.array(
											    [0.77424496, 0.773601, 0.7645288, 0.7769598, 0.7772739, 0.7738688, 0.78187233, 0.77879584, 0.767043]						)

											assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-1






@nightly
@require_onnxruntime
@require_torch_gpu
class     UpperCamelCase(  unittest.TestCase   ):


					@property
					def 							SCREAMING_SNAKE_CASE_  (						self	:		str						)			->	List[Any]:




											'''simple docstring'''

											return (
											    "CUDAExecutionProvider",
											    {
											        "gpu_mem_limit": "15000000000",  # 15GB
											        "arena_extend_strategy": "kSameAsRequested",
											    },
											)


					@property
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple						)			->	Tuple:




											'''simple docstring'''

											__snake_case				=		ort.SessionOptions()
											__snake_case				=		False
											return options


					def 							SCREAMING_SNAKE_CASE_  (						self	:		int						)			->	Optional[int]:




											'''simple docstring'''

											__snake_case				=		load_image(
											    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
											    "/img2img/sketch-mountains-input.jpg"						)
											__snake_case				=		init_image.resize((1_2_8, 1_2_8)						)
											# using the PNDM scheduler by default
											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(
											    "ssube/stable-diffusion-x4-upscaler-onnx"     ,    provider=self.gpu_provider     ,    sess_options=self.gpu_options     ,    )
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

											__snake_case				=		"A fantasy landscape, trending on artstation"

											__snake_case				=		torch.manual_seed(0						)
											__snake_case				=		pipe(
											    prompt=SCREAMING_SNAKE_CASE     ,    image=SCREAMING_SNAKE_CASE     ,    guidance_scale=7.5     ,    num_inference_steps=1_0     ,    generator=SCREAMING_SNAKE_CASE     ,    output_type="np"     ,    )
											__snake_case				=		output.images
											__snake_case				=		images[0, 2_5_5:2_5_8, 3_8_3:3_8_6, -1]

											assert images.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		np.array([0.4883, 0.4947, 0.4980, 0.4975, 0.4982, 0.4980, 0.5000, 0.5006, 0.4972]						)
											# TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

											assert np.abs(image_slice.flatten() - expected_slice						).max() < 2e-2






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple						)			->	Optional[int]:




											'''simple docstring'''

											__snake_case				=		load_image(
											    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
											    "/img2img/sketch-mountains-input.jpg"						)
											__snake_case				=		init_image.resize((1_2_8, 1_2_8)						)
											__snake_case				=		LMSDiscreteScheduler.from_pretrained(
											    "ssube/stable-diffusion-x4-upscaler-onnx"     ,    subfolder="scheduler"						)
											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(
											    "ssube/stable-diffusion-x4-upscaler-onnx"     ,    scheduler=SCREAMING_SNAKE_CASE     ,    provider=self.gpu_provider     ,    sess_options=self.gpu_options     ,    )
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

											__snake_case				=		"A fantasy landscape, trending on artstation"

											__snake_case				=		torch.manual_seed(0						)
											__snake_case				=		pipe(
											    prompt=SCREAMING_SNAKE_CASE     ,    image=SCREAMING_SNAKE_CASE     ,    guidance_scale=7.5     ,    num_inference_steps=2_0     ,    generator=SCREAMING_SNAKE_CASE     ,    output_type="np"     ,    )
											__snake_case				=		output.images
											__snake_case				=		images[0, 2_5_5:2_5_8, 3_8_3:3_8_6, -1]

											assert images.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		np.array(
											    [0.50173753, 0.50223356, 0.502039, 0.50233036, 0.5023725, 0.5022601, 0.5018758, 0.50234085, 0.50241566]						)
											# TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

											assert np.abs(image_slice.flatten() - expected_slice						).max() < 2e-2





