
"""simple docstring"""





import tempfile
import unittest

import numpy as np

from diffusers import (
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionPipeline,
    PNDMScheduler,
)
from diffusers.utils.testing_utils import is_onnx_available, nightly, require_onnxruntime, require_torch_gpu

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
				import onnxruntime as ort






class     _UpperCAmelCase(    lowerCamelCase      ,     unittest.TestCase	):
		lowercase__						=      'hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline'



		def 						UpperCAmelCase							(					self				,		__a=0)       ->       Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase							 =  np.random.RandomState(__a)
							_UpperCamelCase							 =  {
							    '''prompt''': '''A painting of a squirrel eating a burger''',
							    '''generator''': generator,
							    '''num_inference_steps''': 2,
							    '''guidance_scale''': 7.5,
							    '''output_type''': '''numpy''',
							}
							return inputs



		def 						UpperCAmelCase							(					self)       ->       int:






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint				,		provider='''CPUExecutionProvider''')
							pipe.set_progress_bar_config(disable=__a)

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

							assert image.shape == (1, 1_28, 1_28, 3)
							_UpperCamelCase							 =  np.array([0.6_5072, 0.5_8492, 0.4_8219, 0.5_5521, 0.5_3180, 0.5_5939, 0.5_0697, 0.3_9800, 0.4_6455])

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



		def 						UpperCAmelCase							(					self)       ->       str:






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint				,		provider='''CPUExecutionProvider''')
							_UpperCamelCase							 =  PNDMScheduler.from_config(pipe.scheduler.config				,		skip_prk_steps=__a)
							pipe.set_progress_bar_config(disable=__a)

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

							assert image.shape == (1, 1_28, 1_28, 3)
							_UpperCamelCase							 =  np.array([0.6_5863, 0.5_9425, 0.4_9326, 0.5_6313, 0.5_3875, 0.5_6627, 0.5_1065, 0.3_9777, 0.4_6330])

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



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






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint				,		provider='''CPUExecutionProvider''')
							_UpperCamelCase							 =  LMSDiscreteScheduler.from_config(pipe.scheduler.config)
							pipe.set_progress_bar_config(disable=__a)

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

							assert image.shape == (1, 1_28, 1_28, 3)
							_UpperCamelCase							 =  np.array([0.5_3755, 0.6_0786, 0.4_7402, 0.4_9488, 0.5_1869, 0.4_9819, 0.4_7985, 0.3_8957, 0.4_4279])

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



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






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint				,		provider='''CPUExecutionProvider''')
							_UpperCamelCase							 =  EulerDiscreteScheduler.from_config(pipe.scheduler.config)
							pipe.set_progress_bar_config(disable=__a)

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

							assert image.shape == (1, 1_28, 1_28, 3)
							_UpperCamelCase							 =  np.array([0.5_3755, 0.6_0786, 0.4_7402, 0.4_9488, 0.5_1869, 0.4_9819, 0.4_7985, 0.3_8957, 0.4_4279])

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



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






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint				,		provider='''CPUExecutionProvider''')
							_UpperCamelCase							 =  EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
							pipe.set_progress_bar_config(disable=__a)

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

							assert image.shape == (1, 1_28, 1_28, 3)
							_UpperCamelCase							 =  np.array([0.5_3817, 0.6_0812, 0.4_7384, 0.4_9530, 0.5_1894, 0.4_9814, 0.4_7984, 0.3_8958, 0.4_4271])

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



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






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint				,		provider='''CPUExecutionProvider''')
							_UpperCamelCase							 =  DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
							pipe.set_progress_bar_config(disable=__a)

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

							assert image.shape == (1, 1_28, 1_28, 3)
							_UpperCamelCase							 =  np.array([0.5_3895, 0.6_0808, 0.4_7933, 0.4_9608, 0.5_1886, 0.4_9950, 0.4_8053, 0.3_8957, 0.4_4200])

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



		def 						UpperCAmelCase							(					self)       ->       Any:






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint				,		provider='''CPUExecutionProvider''')
							pipe.set_progress_bar_config(disable=__a)

							_UpperCamelCase							 =  self.get_dummy_inputs()
							_UpperCamelCase							 =  3 * [inputs['''prompt''']]

							# forward
							_UpperCamelCase							 =  pipe(**__a)
							_UpperCamelCase							 =  output.images[0, -3:, -3:, -1]

							_UpperCamelCase							 =  self.get_dummy_inputs()
							_UpperCamelCase							 =  3 * [inputs.pop('''prompt''')]

							_UpperCamelCase							 =  pipe.tokenizer(
							    __a				,		padding='''max_length'''				,		max_length=pipe.tokenizer.model_max_length				,		truncation=__a				,		return_tensors='''np'''				,		)
							_UpperCamelCase							 =  text_inputs['''input_ids''']

							_UpperCamelCase							 =  pipe.text_encoder(input_ids=text_inputs.astype(np.intaa))[0]

							_UpperCamelCase							 =  prompt_embeds

							# forward
							_UpperCamelCase							 =  pipe(**__a)
							_UpperCamelCase							 =  output.images[0, -3:, -3:, -1]

							assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()).max() < 1e-4




		def 						UpperCAmelCase							(					self)       ->       Dict:






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint				,		provider='''CPUExecutionProvider''')
							pipe.set_progress_bar_config(disable=__a)

							_UpperCamelCase							 =  self.get_dummy_inputs()
							_UpperCamelCase							 =  3 * ['''this is a negative prompt''']
							_UpperCamelCase							 =  negative_prompt
							_UpperCamelCase							 =  3 * [inputs['''prompt''']]

							# forward
							_UpperCamelCase							 =  pipe(**__a)
							_UpperCamelCase							 =  output.images[0, -3:, -3:, -1]

							_UpperCamelCase							 =  self.get_dummy_inputs()
							_UpperCamelCase							 =  3 * [inputs.pop('''prompt''')]

							_UpperCamelCase							 =  []
							for p in [prompt, negative_prompt]:
												_UpperCamelCase							 =  pipe.tokenizer(
												    __a				,		padding='''max_length'''				,		max_length=pipe.tokenizer.model_max_length				,		truncation=__a				,		return_tensors='''np'''				,		)
												_UpperCamelCase							 =  text_inputs['''input_ids''']

												embeds.append(pipe.text_encoder(input_ids=text_inputs.astype(np.intaa))[0])

							_UpperCamelCase ,  _UpperCamelCase							 =  embeds

							# forward
							_UpperCamelCase							 =  pipe(**__a)
							_UpperCamelCase							 =  output.images[0, -3:, -3:, -1]

							assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()).max() < 1e-4






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



		@property
		def 						UpperCAmelCase							(					self)       ->       str:






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



		@property
		def 						UpperCAmelCase							(					self)       ->       Tuple:






							'''simple docstring'''
							_UpperCamelCase							 =  ort.SessionOptions()
							_UpperCamelCase							 =  False
							return options



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






							'''simple docstring'''
							# using the PNDM scheduler by default
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(
							    '''CompVis/stable-diffusion-v1-4'''				,		revision='''onnx'''				,		safety_checker=__a				,		feature_extractor=__a				,		provider=self.gpu_provider				,		sess_options=self.gpu_options				,		)
							sd_pipe.set_progress_bar_config(disable=__a)

							_UpperCamelCase							 =  '''A painting of a squirrel eating a burger'''
							np.random.seed(0)
							_UpperCamelCase							 =  sd_pipe([prompt]				,		guidance_scale=6.0				,		num_inference_steps=10				,		output_type='''np''')
							_UpperCamelCase							 =  output.images

							_UpperCamelCase							 =  image[0, -3:, -3:, -1]

							assert image.shape == (1, 5_12, 5_12, 3)
							_UpperCamelCase							 =  np.array([0.0452, 0.0390, 0.0087, 0.0350, 0.0617, 0.0364, 0.0544, 0.0523, 0.0720])

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



		def 						UpperCAmelCase							(					self)       ->       int:






							'''simple docstring'''
							_UpperCamelCase							 =  DDIMScheduler.from_pretrained(
							    '''runwayml/stable-diffusion-v1-5'''				,		subfolder='''scheduler'''				,		revision='''onnx''')
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(
							    '''runwayml/stable-diffusion-v1-5'''				,		revision='''onnx'''				,		scheduler=__a				,		safety_checker=__a				,		feature_extractor=__a				,		provider=self.gpu_provider				,		sess_options=self.gpu_options				,		)
							sd_pipe.set_progress_bar_config(disable=__a)

							_UpperCamelCase							 =  '''open neural network exchange'''
							_UpperCamelCase							 =  np.random.RandomState(0)
							_UpperCamelCase							 =  sd_pipe([prompt]				,		guidance_scale=7.5				,		num_inference_steps=10				,		generator=__a				,		output_type='''np''')
							_UpperCamelCase							 =  output.images
							_UpperCamelCase							 =  image[0, -3:, -3:, -1]

							assert image.shape == (1, 5_12, 5_12, 3)
							_UpperCamelCase							 =  np.array([0.2867, 0.1974, 0.1481, 0.7294, 0.7251, 0.6667, 0.4194, 0.5642, 0.6486])

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



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






							'''simple docstring'''
							_UpperCamelCase							 =  LMSDiscreteScheduler.from_pretrained(
							    '''runwayml/stable-diffusion-v1-5'''				,		subfolder='''scheduler'''				,		revision='''onnx''')
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(
							    '''runwayml/stable-diffusion-v1-5'''				,		revision='''onnx'''				,		scheduler=__a				,		safety_checker=__a				,		feature_extractor=__a				,		provider=self.gpu_provider				,		sess_options=self.gpu_options				,		)
							sd_pipe.set_progress_bar_config(disable=__a)

							_UpperCamelCase							 =  '''open neural network exchange'''
							_UpperCamelCase							 =  np.random.RandomState(0)
							_UpperCamelCase							 =  sd_pipe([prompt]				,		guidance_scale=7.5				,		num_inference_steps=10				,		generator=__a				,		output_type='''np''')
							_UpperCamelCase							 =  output.images
							_UpperCamelCase							 =  image[0, -3:, -3:, -1]

							assert image.shape == (1, 5_12, 5_12, 3)
							_UpperCamelCase							 =  np.array([0.2306, 0.1959, 0.1593, 0.6549, 0.6394, 0.5408, 0.5065, 0.6010, 0.6161])

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



		def 						UpperCAmelCase							(					self)       ->       Dict:






							'''simple docstring'''
							_UpperCamelCase							 =  0

							def test_callback_fn(__a				,		__a				,		__a) -> None:
												_UpperCamelCase							 =  True
												nonlocal number_of_steps
												number_of_steps += 1
												if step == 0:
																	assert latents.shape == (1, 4, 64, 64)
																	_UpperCamelCase							 =  latents[0, -3:, -3:, -1]
																	_UpperCamelCase							 =  np.array(
																	    [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167])

																	assert np.abs(latents_slice.flatten() - expected_slice).max() < 1e-3
												elif step == 5:
																	assert latents.shape == (1, 4, 64, 64)
																	_UpperCamelCase							 =  latents[0, -3:, -3:, -1]
																	_UpperCamelCase							 =  np.array(
																	    [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875])

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

							_UpperCamelCase							 =  False

							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(
							    '''runwayml/stable-diffusion-v1-5'''				,		revision='''onnx'''				,		safety_checker=__a				,		feature_extractor=__a				,		provider=self.gpu_provider				,		sess_options=self.gpu_options				,		)
							pipe.set_progress_bar_config(disable=__a)

							_UpperCamelCase							 =  '''Andromeda galaxy in a bottle'''

							_UpperCamelCase							 =  np.random.RandomState(0)
							pipe(
							    prompt=__a				,		num_inference_steps=5				,		guidance_scale=7.5				,		generator=__a				,		callback=__a				,		callback_steps=1				,		)
							assert test_callback_fn.has_been_called
							assert number_of_steps == 6




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






							'''simple docstring'''
							_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(
							    '''runwayml/stable-diffusion-v1-5'''				,		revision='''onnx'''				,		safety_checker=__a				,		feature_extractor=__a				,		provider=self.gpu_provider				,		sess_options=self.gpu_options				,		)
							assert isinstance(__a				,		__a)
							assert pipe.safety_checker is None

							_UpperCamelCase							 =  pipe('''example prompt'''				,		num_inference_steps=2).images[0]
							assert image is not None

							# check that there's no error when saving a pipeline with one of the models being None
							with tempfile.TemporaryDirectory() as tmpdirname:
												pipe.save_pretrained(__a)
												_UpperCamelCase							 =  OnnxStableDiffusionPipeline.from_pretrained(__a)

							# sanity check that the pipeline still works
							assert pipe.safety_checker is None
							_UpperCamelCase							 =  pipe('''example prompt'''				,		num_inference_steps=2).images[0]
							assert image is not None








"""simple docstring"""





from typing import List, Union

import numpy as np

from ..tokenization_utils import TruncationStrategy
from ..utils import add_end_docstrings, logging
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, ChunkPipeline


_a														=		logging.get_logger(__name__)






class     _UpperCAmelCase(    lowerCamelCase	):



		def 						UpperCAmelCase							(					self				,		__a)       ->       Tuple:






							'''simple docstring'''
							if isinstance(__a				,		__a):
												_UpperCamelCase							 =  [label.strip() for label in labels.split(''',''') if label.strip()]
							return labels




		def __call__(					self				,		__a				,		__a				,		__a)       ->       Optional[int]:






							'''simple docstring'''
							if len(__a) == 0 or len(__a) == 0:
												raise ValueError('''You must include at least one label and at least one sequence.''')
							if hypothesis_template.format(labels[0]) == hypothesis_template:
												raise ValueError(
												    (
												        '''The provided hypothesis_template "{}" was not able to be formatted with the target labels. '''
												        '''Make sure the passed template includes formatting syntax such as {{}} where the label should go.'''
												    ).format(__a))

							if isinstance(__a				,		__a):
												_UpperCamelCase							 =  [sequences]

							_UpperCamelCase							 =  []
							for sequence in sequences:
												sequence_pairs.extend([[sequence, hypothesis_template.format(__a)] for label in labels])

							return sequence_pairs, sequences






@add_end_docstrings(lowerCamelCase	)
class     _UpperCAmelCase(    lowerCamelCase	):



		def __init__(					self				,		__a=ZeroShotClassificationArgumentHandler()				,		*__a				,		**__a)       ->       List[str]:






							'''simple docstring'''
							_UpperCamelCase							 =  args_parser
							super().__init__(*__a				,		**__a)
							if self.entailment_id == -1:
												logger.warning(
												    '''Failed to determine \'entailment\' label id from the label2id mapping in the model config. Setting to '''
												    '''-1. Define a descriptive label2id mapping in the model config to ensure correct outputs.''')



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






							'''simple docstring'''
							for label, ind in self.model.config.labelaid.items():
												if label.lower().startswith('''entail'''):
																	return ind
							return -1



		def 						UpperCAmelCase							(					self				,		__a				,		__a=True				,		__a=True				,		__a=TruncationStrategy.ONLY_FIRST				,		**__a)       ->       List[Any]:






							'''simple docstring'''
							_UpperCamelCase							 =  self.framework
							if self.tokenizer.pad_token is None:
												# Override for tokenizers not supporting padding
												logger.error(
												    '''Tokenizer was not supporting padding necessary for zero-shot, attempting to use '''
												    ''' `pad_token=eos_token`''')
												_UpperCamelCase							 =  self.tokenizer.eos_token
							try:
												_UpperCamelCase							 =  self.tokenizer(
												    __a				,		add_special_tokens=__a				,		return_tensors=__a				,		padding=__a				,		truncation=__a				,		)
							except Exception as e:
												if "too short" in str(__a):
																	# tokenizers might yell that we want to truncate
																	# to a value that is not even reached by the input.
																	# In that case we don't want to truncate.
																	# It seems there's not a really better way to catch that
																	# exception.

																	_UpperCamelCase							 =  self.tokenizer(
																	    __a				,		add_special_tokens=__a				,		return_tensors=__a				,		padding=__a				,		truncation=TruncationStrategy.DO_NOT_TRUNCATE				,		)
												else:
																	raise e

							return inputs



		def 						UpperCAmelCase							(					self				,		**__a)       ->       Any:






							'''simple docstring'''
							if kwargs.get('''multi_class'''				,		__a) is not None:
												_UpperCamelCase							 =  kwargs['''multi_class''']
												logger.warning(
												    '''The `multi_class` argument has been deprecated and renamed to `multi_label`. '''
												    '''`multi_class` will be removed in a future version of Transformers.''')
							_UpperCamelCase							 =  {}
							if "candidate_labels" in kwargs:
												_UpperCamelCase							 =  self._args_parser._parse_labels(kwargs['''candidate_labels'''])
							if "hypothesis_template" in kwargs:
												_UpperCamelCase							 =  kwargs['''hypothesis_template''']

							_UpperCamelCase							 =  {}
							if "multi_label" in kwargs:
												_UpperCamelCase							 =  kwargs['''multi_label''']
							return preprocess_params, {}, postprocess_params



		def __call__(					self				,		__a				,		*__a				,		**__a				,		)       ->       int:






							'''simple docstring'''
							if len(__a) == 0:
												pass
							elif len(__a) == 1 and "candidate_labels" not in kwargs:
												_UpperCamelCase							 =  args[0]
							else:
												raise ValueError(F'''Unable to understand extra arguments {args}''')

							return super().__call__(__a				,		**__a)



		def 						UpperCAmelCase							(					self				,		__a				,		__a=None				,		__a="This example is {}.")       ->       Dict:






							'''simple docstring'''
							_UpperCamelCase ,  _UpperCamelCase							 =  self._args_parser(__a				,		__a				,		__a)

							for i, (candidate_label, sequence_pair) in enumerate(zip(__a				,		__a)):
												_UpperCamelCase							 =  self._parse_and_tokenize([sequence_pair])

												yield {
												    "candidate_label": candidate_label,
												    "sequence": sequences[0],
												    "is_last": i == len(__a) - 1,
												    **model_input,
												}



		def 						UpperCAmelCase							(					self				,		__a)       ->       List[Any]:






							'''simple docstring'''
							_UpperCamelCase							 =  inputs['''candidate_label''']
							_UpperCamelCase							 =  inputs['''sequence''']
							_UpperCamelCase							 =  {k: inputs[k] for k in self.tokenizer.model_input_names}
							_UpperCamelCase							 =  self.model(**__a)

							_UpperCamelCase							 =  {
							    '''candidate_label''': candidate_label,
							    '''sequence''': sequence,
							    '''is_last''': inputs['''is_last'''],
							    **outputs,
							}
							return model_outputs




		def 						UpperCAmelCase							(					self				,		__a				,		__a=False)       ->       Dict:






							'''simple docstring'''
							_UpperCamelCase							 =  [outputs['''candidate_label'''] for outputs in model_outputs]
							_UpperCamelCase							 =  [outputs['''sequence'''] for outputs in model_outputs]
							_UpperCamelCase							 =  np.concatenate([output['''logits'''].numpy() for output in model_outputs])
							_UpperCamelCase							 =  logits.shape[0]
							_UpperCamelCase							 =  len(__a)
							_UpperCamelCase							 =  N // n
							_UpperCamelCase							 =  logits.reshape((num_sequences, n, -1))

							if multi_label or len(__a) == 1:
												# softmax over the entailment vs. contradiction dim for each label independently
												_UpperCamelCase							 =  self.entailment_id
												_UpperCamelCase							 =  -1 if entailment_id == 0 else 0
												_UpperCamelCase							 =  reshaped_outputs[..., [contradiction_id, entailment_id]]
												_UpperCamelCase							 =  np.exp(__a) / np.exp(__a).sum(-1				,		keepdims=__a)
												_UpperCamelCase							 =  scores[..., 1]
							else:
												# softmax the "entailment" logits over all candidate labels
												_UpperCamelCase							 =  reshaped_outputs[..., self.entailment_id]
												_UpperCamelCase							 =  np.exp(__a) / np.exp(__a).sum(-1				,		keepdims=__a)

							_UpperCamelCase							 =  list(reversed(scores[0].argsort()))
							return {
							    "sequence": sequences[0],
							    "labels": [candidate_labels[i] for i in top_inds],
							    "scores": scores[0, top_inds].tolist(),
							}






