





'''simple docstring'''




import pytest

from datasets.parallel import ParallelBackendConfig, parallel_backend
from datasets.utils.py_utils import map_nested

from .utils import require_dill_gt_0_3_2, require_joblibspark, require_not_windows






def 			_lowerCAmelCase     (    __snake_case    :					Optional[int]     )	->	str:  # picklable for multiprocessing
     return i + 1






@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 			_lowerCAmelCase     (    )	->	List[str]:
     with parallel_backend('spark'     ):
          assert ParallelBackendConfig.backend_name == "spark"

     __A		:					Any						=			[1, 2, 3]
     with pytest.raises(__snake_case     ):
          with parallel_backend('unsupported backend'     ):
               map_nested(__snake_case					,				__snake_case					,				num_proc=2     )

     with pytest.raises(__snake_case     ):
          with parallel_backend('unsupported backend'     ):
               map_nested(__snake_case					,				__snake_case					,				num_proc=-1     )







@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('num_proc'					,				[2, -1]     )
def 			_lowerCAmelCase     (    __snake_case    :					int     )	->	Tuple:
     __A		:					Optional[Any]						=			[1, 2]
     __A		:					int						=			{'a': 1, 'b': 2}
     __A		:					Dict						=			{'a': [1, 2], 'b': [3, 4]}
     __A		:					Optional[int]						=			{'a': {'1': 1}, 'b': 2}
     __A		:					List[Any]						=			{'a': 1, 'b': 2, 'c': 3, 'd': 4}
     __A		:					List[Any]						=			[2, 3]
     __A		:					Tuple						=			{'a': 2, 'b': 3}
     __A		:					List[Any]						=			{'a': [2, 3], 'b': [4, 5]}
     __A		:					List[Any]						=			{'a': {'1': 2}, 'b': 3}
     __A		:					List[Any]						=			{'a': 2, 'b': 3, 'c': 4, 'd': 5}

     with parallel_backend('spark'     ):
          assert map_nested(__snake_case					,				__snake_case					,				num_proc=__snake_case     ) == expected_map_nested_sa
          assert map_nested(__snake_case					,				__snake_case					,				num_proc=__snake_case     ) == expected_map_nested_sa
          assert map_nested(__snake_case					,				__snake_case					,				num_proc=__snake_case     ) == expected_map_nested_sa
          assert map_nested(__snake_case					,				__snake_case					,				num_proc=__snake_case     ) == expected_map_nested_sa
          assert map_nested(__snake_case					,				__snake_case					,				num_proc=__snake_case     ) == expected_map_nested_sa



'''simple docstring'''
import argparse

from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection

from diffusers import UnCLIPImageVariationPipeline, UnCLIPPipeline


if __name__ == "__main__":
		__snake_case				 =	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.''',
		)

		__snake_case				 =	parser.parse_args()

		__snake_case				 =	UnCLIPPipeline.from_pretrained(args.txtaimg_unclip)

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

		__snake_case				 =	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)