





import argparse
import os

import torch

from transformers import FlavaImageCodebook, FlavaImageCodebookConfig




def _a (  SCREAMING_SNAKE_CASE__      :  Tuple			,				SCREAMING_SNAKE_CASE__      :  str			,				SCREAMING_SNAKE_CASE__      :  Union[str, Any]			,				SCREAMING_SNAKE_CASE__      :  Optional[int]       )	->    Union[str, Any]:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						s.rsplit(SCREAMING_SNAKE_CASE__			,				SCREAMING_SNAKE_CASE__       )
							return new.join(SCREAMING_SNAKE_CASE__       )




def _a (  SCREAMING_SNAKE_CASE__      :  str       )	->    Optional[Any]:

							'''simple docstring'''






							return sum(param.float().sum() if "encoder.embeddings" not in key else 0 for key, param in state_dict.items()       )




def _a (  SCREAMING_SNAKE_CASE__      :  Optional[int]       )	->    Optional[int]:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      int     =						{}

							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						["group_1", "group_2", "group_3", "group_4"]
							for key, value in state_dict.items():
														for group_key in group_keys:
																					if group_key in key:
																												SCREAMING_SNAKE_CASE__       :      List[Any]     =						key.replace(f'''{group_key}.'''			,				f'''{group_key}.group.'''       )

														if "res_path" in key:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						key.replace("res_path."			,				"res_path.path."       )

														if key.endswith(".w"       ):
																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						rreplace(SCREAMING_SNAKE_CASE__			,				".w"			,				".weight"			,				1       )
														if key.endswith(".b"       ):
																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						rreplace(SCREAMING_SNAKE_CASE__			,				".b"			,				".bias"			,				1       )

														SCREAMING_SNAKE_CASE__       :      Tuple     =						value.float()

							return upgrade




@torch.no_grad()
def _a (  SCREAMING_SNAKE_CASE__      :  Optional[Any]			,				SCREAMING_SNAKE_CASE__      :  List[Any]			,				SCREAMING_SNAKE_CASE__      :  Optional[int]=None			,				SCREAMING_SNAKE_CASE__      :  Optional[int]=True       )	->    Dict:

							'''simple docstring'''






							from dall_e import Encoder

							SCREAMING_SNAKE_CASE__       :      str     =						Encoder()
							if os.path.exists(SCREAMING_SNAKE_CASE__       ):
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						torch.load(SCREAMING_SNAKE_CASE__       )
							else:
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						torch.hub.load_state_dict_from_url(SCREAMING_SNAKE_CASE__       )

							if isinstance(SCREAMING_SNAKE_CASE__			,				SCREAMING_SNAKE_CASE__       ):
														SCREAMING_SNAKE_CASE__       :      int     =						ckpt.state_dict()
							encoder.load_state_dict(SCREAMING_SNAKE_CASE__       )

							if config_path is not None:
														SCREAMING_SNAKE_CASE__       :      Tuple     =						FlavaImageCodebookConfig.from_pretrained(SCREAMING_SNAKE_CASE__       )
							else:
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						FlavaImageCodebookConfig()

							SCREAMING_SNAKE_CASE__       :      str     =						FlavaImageCodebook(SCREAMING_SNAKE_CASE__       ).eval()
							SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						encoder.state_dict()

							SCREAMING_SNAKE_CASE__       :      int     =						upgrade_state_dict(SCREAMING_SNAKE_CASE__       )
							hf_model.load_state_dict(SCREAMING_SNAKE_CASE__       )
							SCREAMING_SNAKE_CASE__       :      List[str]     =						hf_model.state_dict()
							SCREAMING_SNAKE_CASE__       :      Tuple     =						count_parameters(SCREAMING_SNAKE_CASE__       )
							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						count_parameters(SCREAMING_SNAKE_CASE__       )

							assert torch.allclose(SCREAMING_SNAKE_CASE__			,				SCREAMING_SNAKE_CASE__			,				atol=1E-3       )

							if save_checkpoint:
														hf_model.save_pretrained(SCREAMING_SNAKE_CASE__       )
							else:
														return hf_state_dict


if __name__ == "__main__":
		_lowerCamelCase :    List[Any]  							= 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 flava checkpoint''')
		parser.add_argument('''--config_path''', default=None, type=str, help='''Path to hf config.json of model to convert''')
		_lowerCamelCase :    List[Any]  							= parser.parse_args()

		convert_dalle_checkpoint(args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path)













import qiskit




def _a (  SCREAMING_SNAKE_CASE__      :  int			,				SCREAMING_SNAKE_CASE__      :  int       )	->    qiskit.result.counts.Counts:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						qiskit.Aer.get_backend("aer_simulator"       )

							# Create a Quantum Circuit acting on the q register
							SCREAMING_SNAKE_CASE__       :      List[Any]     =						qiskit.QuantumCircuit(SCREAMING_SNAKE_CASE__			,				SCREAMING_SNAKE_CASE__       )

							# Apply X (NOT) Gate to Qubits 0 & 1
							circuit.x(0       )
							circuit.x(1       )

							# Map the quantum measurement to the classical bits
							circuit.measure([0, 1]			,				[0, 1]       )

							# Execute the circuit on the qasm simulator
							SCREAMING_SNAKE_CASE__       :      int     =						qiskit.execute(SCREAMING_SNAKE_CASE__			,				SCREAMING_SNAKE_CASE__			,				shots=10_00       )

							# Return the histogram data of the results of the experiment.
							return job.result().get_counts(SCREAMING_SNAKE_CASE__       )


if __name__ == "__main__":
		_lowerCamelCase :    List[str]  							= single_qubit_measure(2, 2)
		print(f"Total count for various states are: {counts}")






