






import numpy as np

from transformers import Pipeline


def        _a  (     UpperCamelCase_					:				str   ) ->   List[Any]:
						"""simple docstring"""







						lowerCAmelCase__       =						np.max(UpperCamelCase_    ,   axis=-1    ,   keepdims=UpperCamelCase_   )
						lowerCAmelCase__       =						np.exp(outputs - maxes   )
						return shifted_exp / shifted_exp.sum(axis=-1    ,   keepdims=UpperCamelCase_   )





class      lowercase__     (			_UpperCAmelCase	):

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







							'''simple docstring'''





							lowerCAmelCase__       =						{}
							if "second_text" in kwargs:
													lowerCAmelCase__       =						kwargs["second_text"]
							return preprocess_kwargs, {}, {}

	def 		UpperCAmelCase  (							self		,    __UpperCAmelCase		,    __UpperCAmelCase=None       )->					Tuple:







							'''simple docstring'''





							return self.tokenizer(__UpperCAmelCase		,    text_pair=__UpperCAmelCase		,    return_tensors=self.framework       )

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







							'''simple docstring'''





							return self.model(**__UpperCAmelCase       )


	def 		UpperCAmelCase  (							self		,    __UpperCAmelCase       )->					int:







							'''simple docstring'''





							lowerCAmelCase__       =						model_outputs.logits[0].numpy()
							lowerCAmelCase__       =						softmax(__UpperCAmelCase       )

							lowerCAmelCase__       =						np.argmax(__UpperCAmelCase       )
							lowerCAmelCase__       =						self.model.config.idalabel[best_class]
							lowerCAmelCase__       =						probabilities[best_class].item()
							lowerCAmelCase__       =						logits.tolist()
							return {"label": label, "score": score, "logits": logits}














import argparse

from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection

from diffusers import UnCLIPImageVariationPipeline, UnCLIPPipeline


if __name__ == "__main__":
	a_							=    argparse.ArgumentParser()

	parser.add_argument('''--dump_path''', default=None, type=str, required=True, help='''Path to the output model.''')

	parser.add_argument(
	    '''--txt2img_unclip''',
	    default='''kakaobrain/karlo-v1-alpha''',
	    type=str,
	    required=False,
	    help='''The pretrained txt2img unclip.''',
	)

	a_							=    parser.parse_args()

	a_							=    UnCLIPPipeline.from_pretrained(args.txtaimg_unclip)

	a_							=    CLIPImageProcessor()
	a_							=    CLIPVisionModelWithProjection.from_pretrained('''openai/clip-vit-large-patch14''')

	a_							=    UnCLIPImageVariationPipeline(
	    decoder=txtaimg.decoder,
	    text_encoder=txtaimg.text_encoder,
	    tokenizer=txtaimg.tokenizer,
	    text_proj=txtaimg.text_proj,
	    feature_extractor=feature_extractor,
	    image_encoder=image_encoder,
	    super_res_first=txtaimg.super_res_first,
	    super_res_last=txtaimg.super_res_last,
	    decoder_scheduler=txtaimg.decoder_scheduler,
	    super_res_scheduler=txtaimg.super_res_scheduler,
	)

	imgaimg.save_pretrained(args.dump_path)






