





import argparse
import json
import os

import fairseq
import torch
from fairseq.data import Dictionary

from transformers import (
    WavaVecaConfig,
    WavaVecaCTCTokenizer,
    WavaVecaFeatureExtractor,
    WavaVecaForCTC,
    WavaVecaForPreTraining,
    WavaVecaProcessor,
    logging,
)
from transformers.models.wavaveca.modeling_wavaveca import WavaVecaForSequenceClassification


logging.set_verbosity_info()
__lowercase       :List[Any]       =  logging.get_logger(__name__)

__lowercase       :int       =  {
    "post_extract_proj": "feature_projection.projection",
    "encoder.pos_conv.0": "encoder.pos_conv_embed.conv",
    "self_attn.k_proj": "encoder.layers.*.attention.k_proj",
    "self_attn.v_proj": "encoder.layers.*.attention.v_proj",
    "self_attn.q_proj": "encoder.layers.*.attention.q_proj",
    "self_attn.out_proj": "encoder.layers.*.attention.out_proj",
    "self_attn_layer_norm": "encoder.layers.*.layer_norm",
    "fc1": "encoder.layers.*.feed_forward.intermediate_dense",
    "fc2": "encoder.layers.*.feed_forward.output_dense",
    "final_layer_norm": "encoder.layers.*.final_layer_norm",
    "encoder.layer_norm": "encoder.layer_norm",
    "adapter_layer": "encoder.layers.*.adapter_layer",
    "w2v_model.layer_norm": "feature_projection.layer_norm",
    "quantizer.weight_proj": "quantizer.weight_proj",
    "quantizer.vars": "quantizer.codevectors",
    "project_q": "project_q",
    "final_proj": "project_hid",
    "w2v_encoder.proj": "lm_head",
    "mask_emb": "masked_spec_embed",
    "pooling_layer.linear": "projector",
    "pooling_layer.projection": "classifier",
}
__lowercase       :Union[str, Any]       =  [
    "lm_head",
    "quantizer.weight_proj",
    "quantizer.codevectors",
    "project_q",
    "project_hid",
    "projector",
    "classifier",
]







def       UpperCAmelCase							(     _lowerCamelCase      :  Optional[Any]     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				Any   =					{}
						with open(_lowerCamelCase			,   "r"     ) as file:
												for line_number, line in enumerate(_lowerCamelCase     ):
																		SCREAMING_SNAKE_CASE__     :				Dict   =					line.strip()
																		if line:
																								SCREAMING_SNAKE_CASE__     :				Optional[int]   =					line.split()
																								SCREAMING_SNAKE_CASE__     :				Dict   =					line_number
																								SCREAMING_SNAKE_CASE__     :				Dict   =					words[0]
																								SCREAMING_SNAKE_CASE__     :				List[str]   =					value
						return result







def       UpperCAmelCase							(     _lowerCamelCase      :  Tuple			,   _lowerCamelCase      :  Optional[Any]			,   _lowerCamelCase      :  str			,   _lowerCamelCase      :  Any			,   _lowerCamelCase      :  Optional[int]     ):





						'''simple docstring'''


						for attribute in key.split("."     ):
												SCREAMING_SNAKE_CASE__     :				Dict   =					getattr(_lowerCamelCase			,   _lowerCamelCase     )

						SCREAMING_SNAKE_CASE__     :				str   =					None
						for param_key in PARAM_MAPPING.keys():
												if full_name.endswith(_lowerCamelCase     ):
																		SCREAMING_SNAKE_CASE__     :				List[str]   =					PARAM_MAPPING[full_name.split("."     )[-1]]
																		SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					"param"

						if weight_type is not None and weight_type != "param":
												SCREAMING_SNAKE_CASE__     :				Optional[int]   =					getattr(_lowerCamelCase			,   _lowerCamelCase     ).shape
						elif weight_type is not None and weight_type == "param":
												SCREAMING_SNAKE_CASE__     :				str   =					hf_pointer
												for attribute in hf_param_name.split("."     ):
																		SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					getattr(_lowerCamelCase			,   _lowerCamelCase     )
												SCREAMING_SNAKE_CASE__     :				int   =					shape_pointer.shape

												# let's reduce dimension
												SCREAMING_SNAKE_CASE__     :				List[Any]   =					value[0]
						else:
												SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					hf_pointer.shape

						if hf_shape != value.shape:
												raise ValueError(
												    f"""Shape of hf {key + '.' + weight_type if weight_type is not None else ''} is {hf_shape}, but should be"""
												    f""" {value.shape} for {full_name}"""     )

						if weight_type == "weight":
												SCREAMING_SNAKE_CASE__     :				int   =					value
						elif weight_type == "weight_g":
												SCREAMING_SNAKE_CASE__     :				List[Any]   =					value
						elif weight_type == "weight_v":
												SCREAMING_SNAKE_CASE__     :				List[Any]   =					value
						elif weight_type == "bias":
												SCREAMING_SNAKE_CASE__     :				Optional[int]   =					value
						elif weight_type == "param":
												for attribute in hf_param_name.split("."     ):
																		SCREAMING_SNAKE_CASE__     :				List[str]   =					getattr(_lowerCamelCase			,   _lowerCamelCase     )
												SCREAMING_SNAKE_CASE__     :				Dict   =					value
						else:
												SCREAMING_SNAKE_CASE__     :				Any   =					value

						logger.info(f"""{key + '.' + weight_type if weight_type is not None else ''} was initialized from {full_name}."""     )







def       UpperCAmelCase							(     _lowerCamelCase      :  Optional[int]			,   _lowerCamelCase      :  Any			,   _lowerCamelCase      :  Dict			,   _lowerCamelCase      :  List[str]			,   _lowerCamelCase      :  Optional[Any]     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				Optional[int]   =					None
						for param_key in PARAM_MAPPING.keys():
												if full_name.endswith(_lowerCamelCase     ):
																		SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					PARAM_MAPPING[full_name.split("."     )[-1]]
																		SCREAMING_SNAKE_CASE__     :				Dict   =					"param"

						if weight_type is not None and weight_type != "param":
												SCREAMING_SNAKE_CASE__     :				Any   =					".".join([key, weight_type]     )
						elif weight_type is not None and weight_type == "param":
												SCREAMING_SNAKE_CASE__     :				List[str]   =					".".join([key, hf_param_name]     )
						else:
												SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					key

						SCREAMING_SNAKE_CASE__     :				int   =					value if "lm_head" in full_key else value[0]


__lowercase       :Optional[Any]       =  {
    "W_a": "linear_1.weight",
    "W_b": "linear_2.weight",
    "b_a": "linear_1.bias",
    "b_b": "linear_2.bias",
    "ln_W": "norm.weight",
    "ln_b": "norm.bias",
}







def       UpperCAmelCase							(     _lowerCamelCase      :  Tuple			,   _lowerCamelCase      :  List[str]			,   _lowerCamelCase      :  Union[str, Any]=None			,   _lowerCamelCase      :  List[Any]=None     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				List[str]   =					False
						for key, mapped_key in MAPPING.items():
												SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					"wav2vec2." + mapped_key if mapped_key not in TOP_LEVEL_KEYS else mapped_key
												if key in name or key.split("w2v_model."     )[-1] == name.split("."     )[0]:
																		SCREAMING_SNAKE_CASE__     :				List[Any]   =					True
																		if "*" in mapped_key:
																								SCREAMING_SNAKE_CASE__     :				Any   =					name.split(_lowerCamelCase     )[0].split("."     )[-2]
																								SCREAMING_SNAKE_CASE__     :				Dict   =					mapped_key.replace("*"			,   _lowerCamelCase     )
																		if "weight_g" in name:
																								SCREAMING_SNAKE_CASE__     :				List[str]   =					"weight_g"
																		elif "weight_v" in name:
																								SCREAMING_SNAKE_CASE__     :				str   =					"weight_v"
																		elif "bias" in name:
																								SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					"bias"
																		elif "weight" in name:
																								# TODO: don't match quantizer.weight_proj
																								SCREAMING_SNAKE_CASE__     :				List[Any]   =					"weight"
																		else:
																								SCREAMING_SNAKE_CASE__     :				Dict   =					None
																		if hf_dict is not None:
																								rename_dict(_lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase     )
																		else:
																								set_recursively(_lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase     )
																		return is_used
						return is_used







def       UpperCAmelCase							(     _lowerCamelCase      :  Union[str, Any]			,   _lowerCamelCase      :  Union[str, Any]			,   _lowerCamelCase      :  Union[str, Any]     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				List[Any]   =					[]
						SCREAMING_SNAKE_CASE__     :				Optional[int]   =					fairseq_model.state_dict()

						SCREAMING_SNAKE_CASE__     :				List[Any]   =					hf_model.wavaveca.feature_extractor

						for name, value in fairseq_dict.items():
												SCREAMING_SNAKE_CASE__     :				List[Any]   =					False
												if "conv_layers" in name:
																		load_conv_layer(
																		    _lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase			,   hf_model.config.feat_extract_norm == "group"			,   )
																		SCREAMING_SNAKE_CASE__     :				List[str]   =					True
												else:
																		SCREAMING_SNAKE_CASE__     :				Any   =					load_wavaveca_layer(_lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase     )
												if not is_used:
																		unused_weights.append(_lowerCamelCase     )

						logger.warning(f"""Unused weights: {unused_weights}"""     )







def       UpperCAmelCase							(     _lowerCamelCase      :  Any			,   _lowerCamelCase      :  Optional[int]			,   _lowerCamelCase      :  Optional[Any]			,   _lowerCamelCase      :  Optional[int]			,   _lowerCamelCase      :  Any     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				Tuple   =					full_name.split("conv_layers."     )[-1]
						SCREAMING_SNAKE_CASE__     :				Optional[int]   =					name.split("."     )
						SCREAMING_SNAKE_CASE__     :				str   =					int(items[0]     )
						SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					int(items[1]     )

						if type_id == 0:
												if "bias" in name:
																		if value.shape != feature_extractor.conv_layers[layer_id].conv.bias.data.shape:
																								raise ValueError(
																								    f"""{full_name} has size {value.shape}, but"""
																								    f""" {feature_extractor.conv_layers[layer_id].conv.bias.data.shape} was found."""     )
																		SCREAMING_SNAKE_CASE__     :				List[str]   =					value
																		logger.info(f"""Feat extract conv layer {layer_id} was initialized from {full_name}."""     )
												elif "weight" in name:
																		if value.shape != feature_extractor.conv_layers[layer_id].conv.weight.data.shape:
																								raise ValueError(
																								    f"""{full_name} has size {value.shape}, but"""
																								    f""" {feature_extractor.conv_layers[layer_id].conv.weight.data.shape} was found."""     )
																		SCREAMING_SNAKE_CASE__     :				str   =					value
																		logger.info(f"""Feat extract conv layer {layer_id} was initialized from {full_name}."""     )
						elif (type_id == 2 and not use_group_norm) or (type_id == 2 and layer_id == 0 and use_group_norm):
												if "bias" in name:
																		if value.shape != feature_extractor.conv_layers[layer_id].layer_norm.bias.data.shape:
																								raise ValueError(
																								    f"""{full_name} has size {value.shape}, but"""
																								    f""" {feature_extractor.conv_layers[layer_id].layer_norm.bias.data.shape} was found."""     )
																		SCREAMING_SNAKE_CASE__     :				Dict   =					value
																		logger.info(f"""Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}."""     )
												elif "weight" in name:
																		if value.shape != feature_extractor.conv_layers[layer_id].layer_norm.weight.data.shape:
																								raise ValueError(
																								    f"""{full_name} has size {value.shape}, but"""
																								    f""" {feature_extractor.conv_layers[layer_id].layer_norm.weight.data.shape} was found."""     )
																		SCREAMING_SNAKE_CASE__     :				List[Any]   =					value
																		logger.info(f"""Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}."""     )
						else:
												unused_weights.append(_lowerCamelCase     )







@torch.no_grad()
def       UpperCAmelCase							(     _lowerCamelCase      :  Tuple			,   _lowerCamelCase      :  int			,   _lowerCamelCase      :  Any=None			,   _lowerCamelCase      :  int=None			,   _lowerCamelCase      :  Dict=True			,   _lowerCamelCase      :  Dict=False     ):





						'''simple docstring'''


						if config_path is not None:
												SCREAMING_SNAKE_CASE__     :				Optional[int]   =					WavaVecaConfig.from_pretrained(_lowerCamelCase     )
						else:
												SCREAMING_SNAKE_CASE__     :				List[str]   =					WavaVecaConfig()

						if is_seq_class:
												SCREAMING_SNAKE_CASE__     :				Dict   =					read_txt_into_dict(_lowerCamelCase     )
												SCREAMING_SNAKE_CASE__     :				str   =					idalabel
												SCREAMING_SNAKE_CASE__     :				Optional[int]   =					WavaVecaForSequenceClassification(_lowerCamelCase     )
												SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					WavaVecaFeatureExtractor(
												    feature_size=1			,   sampling_rate=16_000			,   padding_value=0			,   do_normalize=_lowerCamelCase			,   return_attention_mask=_lowerCamelCase			,   )
												feature_extractor.save_pretrained(_lowerCamelCase     )

						elif is_finetuned:
												if dict_path:
																		SCREAMING_SNAKE_CASE__     :				Tuple   =					Dictionary.load(_lowerCamelCase     )

																		# important change bos & pad token id since CTC symbol is <pad> and
																		# not <s> as in fairseq
																		SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					target_dict.pad_index
																		SCREAMING_SNAKE_CASE__     :				List[Any]   =					target_dict.bos_index
																		SCREAMING_SNAKE_CASE__     :				Dict   =					target_dict.eos_index
																		SCREAMING_SNAKE_CASE__     :				List[str]   =					len(target_dict.symbols     )
																		SCREAMING_SNAKE_CASE__     :				Optional[int]   =					os.path.join(_lowerCamelCase			,   "vocab.json"     )
																		if not os.path.isdir(_lowerCamelCase     ):
																								logger.error("--pytorch_dump_folder_path ({}) should be a directory".format(_lowerCamelCase     )     )
																								return
																		os.makedirs(_lowerCamelCase			,   exist_ok=_lowerCamelCase     )
																		SCREAMING_SNAKE_CASE__     :				Any   =					target_dict.indices

																		# fairseq has the <pad> and <s> switched
																		SCREAMING_SNAKE_CASE__     :				List[str]   =					0
																		SCREAMING_SNAKE_CASE__     :				List[Any]   =					1
																		with open(_lowerCamelCase			,   "w"			,   encoding="utf-8"     ) as vocab_handle:
																								json.dump(_lowerCamelCase			,   _lowerCamelCase     )
																		SCREAMING_SNAKE_CASE__     :				Any   =					WavaVecaCTCTokenizer(
																		    _lowerCamelCase			,   unk_token=target_dict.unk_word			,   pad_token=target_dict.pad_word			,   bos_token=target_dict.bos_word			,   eos_token=target_dict.eos_word			,   word_delimiter_token="|"			,   do_lower_case=_lowerCamelCase			,   )
																		SCREAMING_SNAKE_CASE__     :				int   =					True if config.feat_extract_norm == "layer" else False
																		SCREAMING_SNAKE_CASE__     :				List[str]   =					WavaVecaFeatureExtractor(
																		    feature_size=1			,   sampling_rate=16_000			,   padding_value=0			,   do_normalize=_lowerCamelCase			,   return_attention_mask=_lowerCamelCase			,   )
																		SCREAMING_SNAKE_CASE__     :				Any   =					WavaVecaProcessor(feature_extractor=_lowerCamelCase			,   tokenizer=_lowerCamelCase     )
																		processor.save_pretrained(_lowerCamelCase     )

												SCREAMING_SNAKE_CASE__     :				int   =					WavaVecaForCTC(_lowerCamelCase     )
						else:
												SCREAMING_SNAKE_CASE__     :				List[Any]   =					WavaVecaForPreTraining(_lowerCamelCase     )

						if is_finetuned or is_seq_class:
												SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					fairseq.checkpoint_utils.load_model_ensemble_and_task(
												    [checkpoint_path]			,   arg_overrides={"data": "/".join(dict_path.split("/"     )[:-1]     )}     )
						else:
												SCREAMING_SNAKE_CASE__     :				List[str]   =					argparse.Namespace(task="audio_pretraining"     )
												SCREAMING_SNAKE_CASE__     :				List[str]   =					fairseq.tasks.setup_task(_lowerCamelCase     )

												SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Any   =					fairseq.checkpoint_utils.load_model_ensemble_and_task([checkpoint_path]			,   task=_lowerCamelCase     )

						SCREAMING_SNAKE_CASE__     :				Dict   =					model[0].eval()

						recursively_load_weights(_lowerCamelCase			,   _lowerCamelCase			,   not is_finetuned     )

						hf_wavavec.save_pretrained(_lowerCamelCase     )


if __name__ == "__main__":
				__lowercase       :str       =  argparse.ArgumentParser()
				parser.add_argument("--pytorch_dump_folder_path", default=None, type=str, help="Path to the output PyTorch model.")
				parser.add_argument("--checkpoint_path", default=None, type=str, help="Path to fairseq checkpoint")
				parser.add_argument("--dict_path", default=None, type=str, help="Path to dict of fine-tuned model")
				parser.add_argument("--config_path", default=None, type=str, help="Path to hf config.json of model to convert")
				parser.add_argument(
				    "--not_finetuned", action="store_true", help="Whether the model to convert is a fine-tuned model or not"
				)
				parser.add_argument(
				    "--is_seq_class",
				    action="store_true",
				    help="Whether the model to convert is a fine-tuned sequence classification model or not",
				)
				__lowercase       :List[str]       =  parser.parse_args()

				__lowercase       :Dict       =  not args.not_finetuned and not args.is_seq_class
				convert_wavaveca_checkpoint(
				    args.checkpoint_path,
				    args.pytorch_dump_folder_path,
				    args.config_path,
				    args.dict_path,
				    is_finetuned,
				    args.is_seq_class,
				)






import gc
import unittest

from diffusers import FlaxControlNetModel, FlaxStableDiffusionControlNetPipeline
from diffusers.utils import is_flax_available, load_image, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
				import jax
				import jax.numpy as jnp
				from flax.jax_utils import replicate
				from flax.training.common_utils import shard



@slow
@require_flax
class    _a     (				unittest.TestCase							):






							"""simple docstring"""

							def      A_  (      self				:     Dict    )	->List[Any]:
													# clean up the VRAM after each test
													super().tearDown()
													gc.collect()

							def      A_  (      self				:     Dict    )	->Tuple:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Dict   =					FlaxControlNetModel.from_pretrained(
													    "lllyasviel/sd-controlnet-canny"							,	from_pt=a							,	dtype=jnp.bfloataa    )
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Dict   =					FlaxStableDiffusionControlNetPipeline.from_pretrained(
													    "runwayml/stable-diffusion-v1-5"							,	controlnet=a							,	from_pt=a							,	dtype=jnp.bfloataa    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					controlnet_params

													SCREAMING_SNAKE_CASE__     :				Dict   =					"bird"
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					jax.device_count()
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					pipe.prepare_text_inputs([prompts] * num_samples    )

													SCREAMING_SNAKE_CASE__     :				Dict   =					load_image(
													    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/bird_canny.png"    )
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					pipe.prepare_image_inputs([canny_image] * num_samples    )

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					jax.random.PRNGKey(0    )
													SCREAMING_SNAKE_CASE__     :				int   =					jax.random.split(a							,	jax.device_count()    )

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					replicate(a    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					shard(a    )
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					shard(a    )

													SCREAMING_SNAKE_CASE__     :				Dict   =					pipe(
													    prompt_ids=a							,	image=a							,	params=a							,	prng_seed=a							,	num_inference_steps=50							,	jit=a							,	).images
													assert images.shape == (jax.device_count(), 1, 7_68, 5_12, 3)

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					images[0, 2_53:2_56, 2_53:2_56, -1]

													SCREAMING_SNAKE_CASE__     :				Tuple   =					jnp.asarray(jax.device_get(image_slice.flatten()    )    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					jnp.array(
													    [0.16_7969, 0.11_6699, 0.08_1543, 0.15_4297, 0.13_2812, 0.10_8887, 0.16_9922, 0.16_9922, 0.20_5078]    )
													print(f"""output_slice: {output_slice}"""    )
													assert jnp.abs(output_slice - expected_slice    ).max() < 1E-2






							def      A_  (      self				:     List[Any]    )	->Optional[Any]:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				int   =					FlaxControlNetModel.from_pretrained(
													    "lllyasviel/sd-controlnet-openpose"							,	from_pt=a							,	dtype=jnp.bfloataa    )
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[int]   =					FlaxStableDiffusionControlNetPipeline.from_pretrained(
													    "runwayml/stable-diffusion-v1-5"							,	controlnet=a							,	from_pt=a							,	dtype=jnp.bfloataa    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					controlnet_params

													SCREAMING_SNAKE_CASE__     :				Any   =					"Chef in the kitchen"
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					jax.device_count()
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					pipe.prepare_text_inputs([prompts] * num_samples    )

													SCREAMING_SNAKE_CASE__     :				Dict   =					load_image(
													    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/pose.png"    )
													SCREAMING_SNAKE_CASE__     :				str   =					pipe.prepare_image_inputs([pose_image] * num_samples    )

													SCREAMING_SNAKE_CASE__     :				Any   =					jax.random.PRNGKey(0    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					jax.random.split(a							,	jax.device_count()    )

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					replicate(a    )
													SCREAMING_SNAKE_CASE__     :				Tuple   =					shard(a    )
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					shard(a    )

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					pipe(
													    prompt_ids=a							,	image=a							,	params=a							,	prng_seed=a							,	num_inference_steps=50							,	jit=a							,	).images
													assert images.shape == (jax.device_count(), 1, 7_68, 5_12, 3)

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]    )
													SCREAMING_SNAKE_CASE__     :				str   =					images[0, 2_53:2_56, 2_53:2_56, -1]

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					jnp.asarray(jax.device_get(image_slice.flatten()    )    )
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					jnp.array(
													    [[0.27_1484, 0.26_1719, 0.27_5391, 0.27_7344, 0.27_9297, 0.29_1016, 0.29_4922, 0.30_2734, 0.30_2734]]    )
													print(f"""output_slice: {output_slice}"""    )
													assert jnp.abs(output_slice - expected_slice    ).max() < 1E-2