



'''simple docstring'''





import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import (
       MODEL_FOR_PRETRAINING_MAPPING,
       MegatronBertForCausalLM,
       MegatronBertForMaskedLM,
       MegatronBertForMultipleChoice,
       MegatronBertForNextSentencePrediction,
       MegatronBertForPreTraining,
       MegatronBertForQuestionAnswering,
       MegatronBertForSequenceClassification,
       MegatronBertForTokenClassification,
       MegatronBertModel,
   )






class 					lowerCamelCase_    :
  """simple docstring"""




  def __init__( self      :	Tuple			,	_a      :	Dict			,	_a      :	Optional[Any]=13			,	_a      :	List[Any]=7			,	_a      :	List[str]=True			,	_a      :	Optional[int]=True			,	_a      :	Any=True			,	_a      :	Dict=True			,	_a      :	Optional[Any]=99			,	_a      :	List[Any]=64			,	_a      :	List[Any]=32			,	_a      :	Optional[int]=5			,	_a      :	int=4			,	_a      :	Optional[int]=37			,	_a      :	int="gelu"			,	_a      :	Tuple=0.1			,	_a      :	Tuple=0.1			,	_a      :	List[Any]=512			,	_a      :	Union[str, Any]=16			,	_a      :	str=2			,	_a      :	List[Any]=0.02			,	_a      :	Union[str, Any]=3			,	_a      :	Union[str, Any]=4			,	_a      :	Tuple=None			,	)					->					int:
    __lowerCamelCase       :       int           = parent
    __lowerCamelCase       :       Optional[int]           = batch_size
    __lowerCamelCase       :       List[str]           = seq_length
    __lowerCamelCase       :       Union[str, Any]           = is_training
    __lowerCamelCase       :       int           = use_input_mask
    __lowerCamelCase       :       str           = use_token_type_ids
    __lowerCamelCase       :       List[Any]           = use_labels
    __lowerCamelCase       :       List[str]           = vocab_size
    __lowerCamelCase       :       Optional[Any]           = hidden_size
    __lowerCamelCase       :       Any           = embedding_size
    __lowerCamelCase       :       int           = num_hidden_layers
    __lowerCamelCase       :       Optional[int]           = num_attention_heads
    __lowerCamelCase       :       Dict           = intermediate_size
    __lowerCamelCase       :       List[Any]           = hidden_act
    __lowerCamelCase       :       Tuple           = hidden_dropout_prob
    __lowerCamelCase       :       Optional[Any]           = attention_probs_dropout_prob
    __lowerCamelCase       :       List[Any]           = max_position_embeddings
    __lowerCamelCase       :       List[str]           = type_vocab_size
    __lowerCamelCase       :       Dict           = type_sequence_label_size
    __lowerCamelCase       :       int           = initializer_range
    __lowerCamelCase       :       Tuple           = num_labels
    __lowerCamelCase       :       int           = num_choices
    __lowerCamelCase       :       Any           = scope




  def 						_lowercase     ( self      :	List[str]   )					->					List[str]:
    __lowerCamelCase       :       Any           = ids_tensor([self.batch_size, self.seq_length]			,	self.vocab_size   )

    __lowerCamelCase       :       List[str]           = None
    if self.use_input_mask:
      __lowerCamelCase       :       Dict           = random_attention_mask([self.batch_size, self.seq_length]   )

    __lowerCamelCase       :       str           = None
    if self.use_token_type_ids:
      __lowerCamelCase       :       int           = ids_tensor([self.batch_size, self.seq_length]			,	self.type_vocab_size   )

    __lowerCamelCase       :       str           = None
    __lowerCamelCase       :       Optional[Any]           = None
    __lowerCamelCase       :       List[Any]           = None
    if self.use_labels:
      __lowerCamelCase       :       Tuple           = ids_tensor([self.batch_size]			,	self.type_sequence_label_size   )
      __lowerCamelCase       :       Optional[int]           = ids_tensor([self.batch_size, self.seq_length]			,	self.num_labels   )
      __lowerCamelCase       :       Tuple           = ids_tensor([self.batch_size]			,	self.num_choices   )

    __lowerCamelCase       :       int           = self.get_config()

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels




  def 						_lowercase     ( self      :	List[str]   )					->					Dict:
    return MegatronBertConfig(
        vocab_size=self.vocab_size			,	hidden_size=self.hidden_size			,	num_hidden_layers=self.num_hidden_layers			,	num_attention_heads=self.num_attention_heads			,	intermediate_size=self.intermediate_size			,	embedding_size=self.embedding_size			,	hidden_act=self.hidden_act			,	hidden_dropout_prob=self.hidden_dropout_prob			,	attention_probs_dropout_prob=self.attention_probs_dropout_prob			,	max_position_embeddings=self.max_position_embeddings			,	type_vocab_size=self.type_vocab_size			,	is_decoder=_a			,	initializer_range=self.initializer_range			,	)




  def 						_lowercase     ( self      :	Any			,	_a      :	Dict			,	_a      :	Optional[int]			,	_a      :	Optional[int]			,	_a      :	Optional[int]			,	_a      :	str			,	_a      :	Dict			,	_a      :	Optional[int]   )					->					Union[str, Any]:
    __lowerCamelCase       :       List[Any]           = MegatronBertModel(config=_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       Optional[Any]           = model(_a			,	attention_mask=_a			,	token_type_ids=_a   )
    __lowerCamelCase       :       Any           = model(_a			,	token_type_ids=_a   )
    __lowerCamelCase       :       Optional[int]           = model(_a   )

    self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.hidden_size)   )
    self.parent.assertEqual(result.pooler_output.shape			,	(self.batch_size, self.hidden_size)   )




  def 						_lowercase     ( self      :	Union[str, Any]			,	_a      :	List[str]			,	_a      :	str			,	_a      :	List[str]			,	_a      :	int			,	_a      :	List[str]			,	_a      :	Union[str, Any]			,	_a      :	Dict   )					->					List[Any]:
    __lowerCamelCase       :       Optional[int]           = MegatronBertForMaskedLM(config=_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       List[Any]           = model(_a			,	attention_mask=_a			,	token_type_ids=_a			,	labels=_a   )
    self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size)   )




  def 						_lowercase     ( self      :	Any			,	_a      :	List[str]			,	_a      :	Dict			,	_a      :	Dict			,	_a      :	int			,	_a      :	str			,	_a      :	int			,	_a      :	int   )					->					int:
    __lowerCamelCase       :       List[str]           = MegatronBertForCausalLM(config=_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       str           = model(_a			,	attention_mask=_a			,	token_type_ids=_a			,	labels=_a   )
    self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size)   )




  def 						_lowercase     ( self      :	Optional[int]			,	_a      :	Optional[int]			,	_a      :	Optional[int]			,	_a      :	Any			,	_a      :	Union[str, Any]			,	_a      :	Tuple			,	_a      :	str			,	_a      :	Optional[int]   )					->					List[Any]:
    __lowerCamelCase       :       List[Any]           = MegatronBertForNextSentencePrediction(config=_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       Dict           = model(
        _a			,	attention_mask=_a			,	token_type_ids=_a			,	labels=_a			,	)
    self.parent.assertEqual(result.logits.shape			,	(self.batch_size, 2)   )




  def 						_lowercase     ( self      :	List[str]			,	_a      :	str			,	_a      :	Union[str, Any]			,	_a      :	Optional[int]			,	_a      :	Optional[int]			,	_a      :	str			,	_a      :	Tuple			,	_a      :	Union[str, Any]   )					->					Tuple:
    __lowerCamelCase       :       str           = MegatronBertForPreTraining(config=_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       Dict           = model(
        _a			,	attention_mask=_a			,	token_type_ids=_a			,	labels=_a			,	next_sentence_label=_a			,	)
    self.parent.assertEqual(result.prediction_logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size)   )
    self.parent.assertEqual(result.seq_relationship_logits.shape			,	(self.batch_size, 2)   )




  def 						_lowercase     ( self      :	int			,	_a      :	List[Any]			,	_a      :	Tuple			,	_a      :	Optional[int]			,	_a      :	List[str]			,	_a      :	Union[str, Any]			,	_a      :	Any			,	_a      :	Any   )					->					Optional[Any]:
    __lowerCamelCase       :       Optional[int]           = MegatronBertForQuestionAnswering(config=_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       Dict           = model(
        _a			,	attention_mask=_a			,	token_type_ids=_a			,	start_positions=_a			,	end_positions=_a			,	)
    self.parent.assertEqual(result.start_logits.shape			,	(self.batch_size, self.seq_length)   )
    self.parent.assertEqual(result.end_logits.shape			,	(self.batch_size, self.seq_length)   )




  def 						_lowercase     ( self      :	Optional[int]			,	_a      :	int			,	_a      :	List[Any]			,	_a      :	Union[str, Any]			,	_a      :	Union[str, Any]			,	_a      :	Tuple			,	_a      :	int			,	_a      :	Dict   )					->					Union[str, Any]:
    __lowerCamelCase       :       Union[str, Any]           = self.num_labels
    __lowerCamelCase       :       Tuple           = MegatronBertForSequenceClassification(_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       List[str]           = model(_a			,	attention_mask=_a			,	token_type_ids=_a			,	labels=_a   )
    self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.num_labels)   )




  def 						_lowercase     ( self      :	str			,	_a      :	List[str]			,	_a      :	List[str]			,	_a      :	Dict			,	_a      :	List[Any]			,	_a      :	Optional[int]			,	_a      :	int			,	_a      :	Optional[Any]   )					->					Dict:
    __lowerCamelCase       :       Union[str, Any]           = self.num_labels
    __lowerCamelCase       :       Dict           = MegatronBertForTokenClassification(config=_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       Tuple           = model(_a			,	attention_mask=_a			,	token_type_ids=_a			,	labels=_a   )
    self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.num_labels)   )




  def 						_lowercase     ( self      :	Dict			,	_a      :	Optional[int]			,	_a      :	Union[str, Any]			,	_a      :	Optional[int]			,	_a      :	Tuple			,	_a      :	Any			,	_a      :	Tuple			,	_a      :	str   )					->					int:
    __lowerCamelCase       :       List[Any]           = self.num_choices
    __lowerCamelCase       :       Tuple           = MegatronBertForMultipleChoice(config=_a   )
    model.to(_a   )
    model.eval()
    __lowerCamelCase       :       Any           = input_ids.unsqueeze(1   ).expand(-1			,	self.num_choices			,	-1   ).contiguous()
    __lowerCamelCase       :       Optional[Any]           = token_type_ids.unsqueeze(1   ).expand(-1			,	self.num_choices			,	-1   ).contiguous()
    __lowerCamelCase       :       Optional[Any]           = input_mask.unsqueeze(1   ).expand(-1			,	self.num_choices			,	-1   ).contiguous()
    __lowerCamelCase       :       Optional[Any]           = model(
        _a			,	attention_mask=_a			,	token_type_ids=_a			,	labels=_a			,	)
    self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.num_choices)   )




  def 						_lowercase     ( self      :	List[Any]   )					->					List[Any]:
    __lowerCamelCase       :       Any           = self.prepare_config_and_inputs()
    (
        (
        __lowerCamelCase
    )       ,(
        __lowerCamelCase
    )       ,(
        __lowerCamelCase
    )       ,(
        __lowerCamelCase
    )       ,(
        __lowerCamelCase
    )       ,(
        __lowerCamelCase
    )       ,(
        __lowerCamelCase
    )       ,
    )       :       Optional[Any]           = config_and_inputs
    __lowerCamelCase       :       List[Any]           = {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
    return config, inputs_dict






@require_torch
class 					lowerCamelCase_    (				SCREAMING_SNAKE_CASE_   ,   SCREAMING_SNAKE_CASE_   ,   unittest.TestCase     ):
  """simple docstring"""




  a_												=(
      (
          MegatronBertModel,
          MegatronBertForMaskedLM,
          MegatronBertForCausalLM,
          MegatronBertForMultipleChoice,
          MegatronBertForNextSentencePrediction,
          MegatronBertForPreTraining,
          MegatronBertForQuestionAnswering,
          MegatronBertForSequenceClassification,
          MegatronBertForTokenClassification,
      )
      if is_torch_available()
      else ()
  )
  a_												=(
      {
          """feature-extraction""": MegatronBertModel,
          """fill-mask""": MegatronBertForMaskedLM,
          """question-answering""": MegatronBertForQuestionAnswering,
          """text-classification""": MegatronBertForSequenceClassification,
          """text-generation""": MegatronBertForCausalLM,
          """token-classification""": MegatronBertForTokenClassification,
          """zero-shot""": MegatronBertForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  a_												=True
  # test_resize_embeddings = False
  a_												=False




  def 						_lowercase     ( self      :	List[str]			,	_a      :	int			,	_a      :	Union[str, Any]			,	_a      :	Optional[Any]=False   )					->					Any:
    __lowerCamelCase       :       Optional[Any]           = super()._prepare_for_class(_a			,	_a			,	return_labels=_a   )

    if return_labels:
      if model_class in get_values(_a   ):
        __lowerCamelCase       :       str           = torch.zeros(
            (self.model_tester.batch_size, self.model_tester.seq_length)			,	dtype=torch.long			,	device=_a   )
        __lowerCamelCase       :       Union[str, Any]           = torch.zeros(
            self.model_tester.batch_size			,	dtype=torch.long			,	device=_a   )
    return inputs_dict




  def 						_lowercase     ( self      :	List[str]   )					->					List[Any]:
    __lowerCamelCase       :       Optional[Any]           = MegatronBertModelTester(self   )
    __lowerCamelCase       :       List[Any]           = ConfigTester(self			,	config_class=_a			,	hidden_size=37   )




  def 						_lowercase     ( self      :	Union[str, Any]   )					->					List[Any]:
    self.config_tester.run_common_tests()




  def 						_lowercase     ( self      :	Dict   )					->					Optional[Any]:
    __lowerCamelCase       :       int           = self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_megatron_bert_model(*_a   )




  def 						_lowercase     ( self      :	int   )					->					str:
    __lowerCamelCase       :       Tuple           = self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_megatron_bert_for_masked_lm(*_a   )




  def 						_lowercase     ( self      :	Optional[Any]   )					->					Dict:
    __lowerCamelCase       :       Optional[int]           = self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*_a   )




  def 						_lowercase     ( self      :	Optional[Any]   )					->					Dict:
    __lowerCamelCase       :       List[str]           = self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*_a   )




  def 						_lowercase     ( self      :	Optional[Any]   )					->					Any:
    __lowerCamelCase       :       int           = self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_megatron_bert_for_pretraining(*_a   )




  def 						_lowercase     ( self      :	Dict   )					->					Union[str, Any]:
    __lowerCamelCase       :       Any           = self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_megatron_bert_for_question_answering(*_a   )




  def 						_lowercase     ( self      :	Union[str, Any]   )					->					Optional[Any]:
    __lowerCamelCase       :       Tuple           = self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*_a   )




  def 						_lowercase     ( self      :	Tuple   )					->					List[Any]:
    __lowerCamelCase       :       int           = self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_megatron_bert_for_token_classification(*_a   )




def        a_     (							_lowerCAmelCase       )      ->      Optional[int]:
  return torch.tensor(
      _lowerCAmelCase       ,dtype=torch.long       ,device=_lowerCAmelCase       ,)


_UpperCamelCase											=						1e-4






@require_torch
@require_sentencepiece
@require_tokenizers
class 					lowerCamelCase_    (				unittest.TestCase     ):
  """simple docstring"""




  @slow
  @unittest.skip('Model is not available.'   )
  def 						_lowercase     ( self      :	Union[str, Any]   )					->					Optional[Any]:
    __lowerCamelCase       :       Any           = 'nvidia/megatron-bert-uncased-345m'
    if "MYDIR" in os.environ:
      __lowerCamelCase       :       List[Any]           = os.path.join(os.environ['MYDIR']			,	_a   )
    __lowerCamelCase       :       int           = MegatronBertModel.from_pretrained(_a   )
    model.to(_a   )
    model.half()
    __lowerCamelCase       :       Tuple           = _long_tensor([[101, 7110, 1005, 1056, 2023, 1_1333, 1_7413, 1029, 102]]   )
    with torch.no_grad():
      __lowerCamelCase       :       Union[str, Any]           = model(_a   )[0]
    __lowerCamelCase       :       Any           = torch.Size((1, 9, 1024)   )
    self.assertEqual(output.shape			,	_a   )

    __lowerCamelCase       :       Optional[int]           = [-0.6040, -0.2517, -0.1025, 0.3420, -0.6758, -0.0017, -0.1089, -0.1990, 0.5728]
    for ii in range(3   ):
      for jj in range(3   ):
        __lowerCamelCase       :       Tuple           = output[0, ii, jj]
        __lowerCamelCase       :       Dict           = expected[3 * ii + jj]
        __lowerCamelCase       :       Dict           = 'ii={} jj={} a={} b={}'.format(_a			,	_a			,	_a			,	_a   )
        self.assertTrue(math.isclose(_a			,	_a			,	rel_tol=_a			,	abs_tol=_a   )			,	msg=_a   )











'''simple docstring'''





import inspect
from typing import List, Optional, Tuple, Union

import numpy as np
import PIL
import torch
import torch.utils.checkpoint

from ...models import UNetaDModel, VQModel
from ...schedulers import (
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
)
from ...utils import PIL_INTERPOLATION, randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput

def        a_     (							_lowerCAmelCase       )      ->      str:
  __lowerCamelCase       ,__lowerCamelCase       :       List[Any]           = image.size
  __lowerCamelCase       ,__lowerCamelCase       :       List[str]           = (x - x % 32 for x in (w, h))  # resize to integer multiple of 32
  __lowerCamelCase       :       Optional[Any]           = image.resize((w, h)       ,resample=PIL_INTERPOLATION['lanczos']       )
  __lowerCamelCase       :       List[Any]           = np.array(_lowerCAmelCase       ).astype(np.floataa       ) / 255.0
  __lowerCamelCase       :       Optional[Any]           = image[None].transpose(0       ,3       ,1       ,2       )
  __lowerCamelCase       :       int           = torch.from_numpy(_lowerCAmelCase       )
  return 2.0 * image - 1.0






class 					lowerCamelCase_    (				SCREAMING_SNAKE_CASE_     ):
  """simple docstring"""




  def __init__( self      :	str			,	_a      :	VQModel			,	_a      :	UNetaDModel			,	_a      :	Union[
          DDIMScheduler,
          PNDMScheduler,
          LMSDiscreteScheduler,
          EulerDiscreteScheduler,
          EulerAncestralDiscreteScheduler,
          DPMSolverMultistepScheduler,
      ]			,	)					->					Optional[Any]:
    super().__init__()
    self.register_modules(vqvae=_a			,	unet=_a			,	scheduler=_a   )




  @torch.no_grad()
  def __call__( self      :	List[Any]			,	_a      :	Union[torch.Tensor, PIL.Image.Image] = None			,	_a      :	Optional[int] = 1			,	_a      :	Optional[int] = 100			,	_a      :	Optional[float] = 0.0			,	_a      :	Optional[Union[torch.Generator, List[torch.Generator]]] = None			,	_a      :	Optional[str] = "pil"			,	_a      :	bool = True			,	)					->					Union[Tuple, ImagePipelineOutput]:
    if isinstance(_a			,	PIL.Image.Image   ):
      __lowerCamelCase       :       Any           = 1
    elif isinstance(_a			,	torch.Tensor   ):
      __lowerCamelCase       :       Any           = image.shape[0]
    else:
      raise ValueError(f'`image` has to be of type `PIL.Image.Image` or `torch.Tensor` but is {type(_a   )}'   )

    if isinstance(_a			,	PIL.Image.Image   ):
      __lowerCamelCase       :       List[str]           = preprocess(_a   )

    __lowerCamelCase       ,__lowerCamelCase       :       List[str]           = image.shape[-2:]

    # in_channels should be 6: 3 for latents, 3 for low resolution image
    __lowerCamelCase       :       Union[str, Any]           = (batch_size, self.unet.config.in_channels // 2, height, width)
    __lowerCamelCase       :       Tuple           = next(self.unet.parameters()   ).dtype

    __lowerCamelCase       :       Optional[int]           = randn_tensor(_a			,	generator=_a			,	device=self.device			,	dtype=_a   )

    __lowerCamelCase       :       Optional[int]           = image.to(device=self.device			,	dtype=_a   )

    # set timesteps and move to the correct device
    self.scheduler.set_timesteps(_a			,	device=self.device   )
    __lowerCamelCase       :       Union[str, Any]           = self.scheduler.timesteps

    # scale the initial noise by the standard deviation required by the scheduler
    __lowerCamelCase       :       List[Any]           = latents * self.scheduler.init_noise_sigma

    # prepare extra kwargs for the scheduler step, since not all schedulers have the same signature.
    # eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers.
    # eta corresponds to η in DDIM paper: https://arxiv.org/abs/2010.02502
    # and should be between [0, 1]
    __lowerCamelCase       :       int           = 'eta' in set(inspect.signature(self.scheduler.step   ).parameters.keys()   )
    __lowerCamelCase       :       List[str]           = {}
    if accepts_eta:
      __lowerCamelCase       :       str           = eta

    for t in self.progress_bar(_a   ):
      # concat latents and low resolution image in the channel dimension.
      __lowerCamelCase       :       str           = torch.cat([latents, image]			,	dim=1   )
      __lowerCamelCase       :       Union[str, Any]           = self.scheduler.scale_model_input(_a			,	_a   )
      # predict the noise residual
      __lowerCamelCase       :       Optional[int]           = self.unet(_a			,	_a   ).sample
      # compute the previous noisy sample x_t -> x_t-1
      __lowerCamelCase       :       List[Any]           = self.scheduler.step(_a			,	_a			,	_a			,	**_a   ).prev_sample

    # decode the image latents with the VQVAE
    __lowerCamelCase       :       Union[str, Any]           = self.vqvae.decode(_a   ).sample
    __lowerCamelCase       :       Union[str, Any]           = torch.clamp(_a			,	-1.0			,	1.0   )
    __lowerCamelCase       :       List[str]           = image / 2 + 0.5
    __lowerCamelCase       :       Optional[Any]           = image.cpu().permute(0			,	2			,	3			,	1   ).numpy()

    if output_type == "pil":
      __lowerCamelCase       :       Tuple           = self.numpy_to_pil(_a   )

    if not return_dict:
      return (image,)

    return ImagePipelineOutput(images=_a   )






