





'''simple docstring'''
import argparse
import json

import torch

from diffusers import AutoencoderKL, DDPMPipeline, DDPMScheduler, UNetaDModel, VQModel
def     lowercase__       (       __lowercase						:  Optional[Any]    ,  __lowercase						:  List[str]=1					)			->				Tuple:



							"""simple docstring"""






							if n_shave_prefix_segments >= 0:
														return ".".join(path.split('.'					)[n_shave_prefix_segments:]					)
							else:
														return ".".join(path.split('.'					)[:n_shave_prefix_segments]					)
def     lowercase__       (       __lowercase						:  int    ,  __lowercase						:  Any=0					)			->				Optional[int]:



							"""simple docstring"""






							__UpperCamelCase	=  []
							for old_item in old_list:
														__UpperCamelCase	=  old_item
														__UpperCamelCase	=  new_item.replace('block.'    ,  'resnets.'					)
														__UpperCamelCase	=  new_item.replace('conv_shorcut'    ,  'conv1'					)
														__UpperCamelCase	=  new_item.replace('in_shortcut'    ,  'conv_shortcut'					)
														__UpperCamelCase	=  new_item.replace('temb_proj'    ,  'time_emb_proj'					)

														__UpperCamelCase	=  shave_segments(__lowercase    ,  n_shave_prefix_segments=__lowercase					)

														mapping.append({'old': old_item, 'new': new_item}					)

							return mapping
def     lowercase__       (       __lowercase						:  List[str]    ,  __lowercase						:  Any=0    ,  __lowercase						:  List[str]=False					)			->				int:



							"""simple docstring"""






							__UpperCamelCase	=  []
							for old_item in old_list:
														__UpperCamelCase	=  old_item

														# In `model.mid`, the layer is called `attn`.
														if not in_mid:
																					__UpperCamelCase	=  new_item.replace('attn'    ,  'attentions'					)
														__UpperCamelCase	=  new_item.replace('.k.'    ,  '.key.'					)
														__UpperCamelCase	=  new_item.replace('.v.'    ,  '.value.'					)
														__UpperCamelCase	=  new_item.replace('.q.'    ,  '.query.'					)

														__UpperCamelCase	=  new_item.replace('proj_out'    ,  'proj_attn'					)
														__UpperCamelCase	=  new_item.replace('norm'    ,  'group_norm'					)

														__UpperCamelCase	=  shave_segments(__lowercase    ,  n_shave_prefix_segments=__lowercase					)
														mapping.append({'old': old_item, 'new': new_item}					)

							return mapping
def     lowercase__       (       __lowercase						:  Dict    ,  __lowercase						:  Optional[int]    ,  __lowercase						:  List[Any]    ,  __lowercase						:  Tuple=None    ,  __lowercase						:  Union[str, Any]=None    ,  __lowercase						:  Any=None					)			->				Union[str, Any]:



							"""simple docstring"""






							assert isinstance(__lowercase    ,  __lowercase					), "Paths should be a list of dicts containing 'old' and 'new' keys."

							if attention_paths_to_split is not None:
														if config is None:
																					raise ValueError('Please specify the config if setting \'attention_paths_to_split\' to \'True\'.'					)

														for path, path_map in attention_paths_to_split.items():
																					__UpperCamelCase	=  old_checkpoint[path]
																					__UpperCamelCase	=  old_tensor.shape[0] // 3

																					__UpperCamelCase	=  (-1, channels) if len(old_tensor.shape					) == 3 else (-1)

																					__UpperCamelCase	=  old_tensor.shape[0] // config.get('num_head_channels'    ,  1					) // 3

																					__UpperCamelCase	=  old_tensor.reshape((num_heads, 3 * channels // num_heads) + old_tensor.shape[1:]					)
																					__UpperCamelCase	=  old_tensor.split(channels // num_heads    ,  dim=1					)

																					__UpperCamelCase	=  query.reshape(__lowercase					).squeeze()
																					__UpperCamelCase	=  key.reshape(__lowercase					).squeeze()
																					__UpperCamelCase	=  value.reshape(__lowercase					).squeeze()

							for path in paths:
														__UpperCamelCase	=  path['new']

														if attention_paths_to_split is not None and new_path in attention_paths_to_split:
																					continue

														__UpperCamelCase	=  new_path.replace('down.'    ,  'down_blocks.'					)
														__UpperCamelCase	=  new_path.replace('up.'    ,  'up_blocks.'					)

														if additional_replacements is not None:
																					for replacement in additional_replacements:
																												__UpperCamelCase	=  new_path.replace(replacement['old']    ,  replacement['new']					)

														if "attentions" in new_path:
																					__UpperCamelCase	=  old_checkpoint[path['old']].squeeze()
														else:
																					__UpperCamelCase	=  old_checkpoint[path['old']]
def     lowercase__       (       __lowercase						:  List[Any]    ,  __lowercase						:  Any					)			->				int:



							"""simple docstring"""






							__UpperCamelCase	=  {}

							__UpperCamelCase	=  checkpoint['temb.dense.0.weight']
							__UpperCamelCase	=  checkpoint['temb.dense.0.bias']
							__UpperCamelCase	=  checkpoint['temb.dense.1.weight']
							__UpperCamelCase	=  checkpoint['temb.dense.1.bias']

							__UpperCamelCase	=  checkpoint['norm_out.weight']
							__UpperCamelCase	=  checkpoint['norm_out.bias']

							__UpperCamelCase	=  checkpoint['conv_in.weight']
							__UpperCamelCase	=  checkpoint['conv_in.bias']
							__UpperCamelCase	=  checkpoint['conv_out.weight']
							__UpperCamelCase	=  checkpoint['conv_out.bias']

							__UpperCamelCase	=  len({'.'.join(layer.split('.'					)[:2]					) for layer in checkpoint if 'down' in layer}					)
							__UpperCamelCase	=  {
							    layer_id: [key for key in checkpoint if F'''down.{layer_id}''' in key] for layer_id in range(__lowercase					)
							}

							__UpperCamelCase	=  len({'.'.join(layer.split('.'					)[:2]					) for layer in checkpoint if 'up' in layer}					)
							__UpperCamelCase	=  {layer_id: [key for key in checkpoint if F'''up.{layer_id}''' in key] for layer_id in range(__lowercase					)}

							for i in range(__lowercase					):
														__UpperCamelCase	=  (i - 1) // (config['layers_per_block'] + 1)

														if any('downsample' in layer for layer in down_blocks[i]					):
																					__UpperCamelCase	=  checkpoint[
																					    F'''down.{i}.downsample.op.weight'''
																					]
																					__UpperCamelCase	=  checkpoint[F'''down.{i}.downsample.op.bias''']
														#            new_checkpoint[f'down_blocks.{i}.downsamplers.0.op.weight'] = checkpoint[f'down.{i}.downsample.conv.weight']
														#            new_checkpoint[f'down_blocks.{i}.downsamplers.0.op.bias'] = checkpoint[f'down.{i}.downsample.conv.bias']

														if any('block' in layer for layer in down_blocks[i]					):
																					__UpperCamelCase	=  len(
																					    {'.'.join(shave_segments(__lowercase    ,  2					).split('.'					)[:2]					) for layer in down_blocks[i] if 'block' in layer}					)
																					__UpperCamelCase	=  {
																					    layer_id: [key for key in down_blocks[i] if F'''block.{layer_id}''' in key]
																					    for layer_id in range(__lowercase					)
																					}

																					if num_blocks > 0:
																												for j in range(config['layers_per_block']					):
																																			__UpperCamelCase	=  renew_resnet_paths(blocks[j]					)
																																			assign_to_checkpoint(__lowercase    ,  __lowercase    ,  __lowercase					)

														if any('attn' in layer for layer in down_blocks[i]					):
																					__UpperCamelCase	=  len(
																					    {'.'.join(shave_segments(__lowercase    ,  2					).split('.'					)[:2]					) for layer in down_blocks[i] if 'attn' in layer}					)
																					__UpperCamelCase	=  {
																					    layer_id: [key for key in down_blocks[i] if F'''attn.{layer_id}''' in key]
																					    for layer_id in range(__lowercase					)
																					}

																					if num_attn > 0:
																												for j in range(config['layers_per_block']					):
																																			__UpperCamelCase	=  renew_attention_paths(attns[j]					)
																																			assign_to_checkpoint(__lowercase    ,  __lowercase    ,  __lowercase    ,  config=__lowercase					)

							__UpperCamelCase	=  [key for key in checkpoint if 'mid.block_1' in key]
							__UpperCamelCase	=  [key for key in checkpoint if 'mid.block_2' in key]
							__UpperCamelCase	=  [key for key in checkpoint if 'mid.attn_1' in key]

							# Mid new 2
							__UpperCamelCase	=  renew_resnet_paths(__lowercase					)
							assign_to_checkpoint(
							    __lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[{'old': 'mid.', 'new': 'mid_new_2.'}, {'old': 'block_1', 'new': 'resnets.0'}]    ,  )

							__UpperCamelCase	=  renew_resnet_paths(__lowercase					)
							assign_to_checkpoint(
							    __lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[{'old': 'mid.', 'new': 'mid_new_2.'}, {'old': 'block_2', 'new': 'resnets.1'}]    ,  )

							__UpperCamelCase	=  renew_attention_paths(__lowercase    ,  in_mid=__lowercase					)
							assign_to_checkpoint(
							    __lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[{'old': 'mid.', 'new': 'mid_new_2.'}, {'old': 'attn_1', 'new': 'attentions.0'}]    ,  )

							for i in range(__lowercase					):
														__UpperCamelCase	=  num_up_blocks - 1 - i

														if any('upsample' in layer for layer in up_blocks[i]					):
																					__UpperCamelCase	=  checkpoint[
																					    F'''up.{i}.upsample.conv.weight'''
																					]
																					__UpperCamelCase	=  checkpoint[F'''up.{i}.upsample.conv.bias''']

														if any('block' in layer for layer in up_blocks[i]					):
																					__UpperCamelCase	=  len(
																					    {'.'.join(shave_segments(__lowercase    ,  2					).split('.'					)[:2]					) for layer in up_blocks[i] if 'block' in layer}					)
																					__UpperCamelCase	=  {
																					    layer_id: [key for key in up_blocks[i] if F'''block.{layer_id}''' in key] for layer_id in range(__lowercase					)
																					}

																					if num_blocks > 0:
																												for j in range(config['layers_per_block'] + 1					):
																																			__UpperCamelCase	=  {'old': F'''up_blocks.{i}''', 'new': F'''up_blocks.{block_id}'''}
																																			__UpperCamelCase	=  renew_resnet_paths(blocks[j]					)
																																			assign_to_checkpoint(__lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[replace_indices]					)

														if any('attn' in layer for layer in up_blocks[i]					):
																					__UpperCamelCase	=  len(
																					    {'.'.join(shave_segments(__lowercase    ,  2					).split('.'					)[:2]					) for layer in up_blocks[i] if 'attn' in layer}					)
																					__UpperCamelCase	=  {
																					    layer_id: [key for key in up_blocks[i] if F'''attn.{layer_id}''' in key] for layer_id in range(__lowercase					)
																					}

																					if num_attn > 0:
																												for j in range(config['layers_per_block'] + 1					):
																																			__UpperCamelCase	=  {'old': F'''up_blocks.{i}''', 'new': F'''up_blocks.{block_id}'''}
																																			__UpperCamelCase	=  renew_attention_paths(attns[j]					)
																																			assign_to_checkpoint(__lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[replace_indices]					)

							__UpperCamelCase	=  {k.replace('mid_new_2'    ,  'mid_block'					): v for k, v in new_checkpoint.items()}
							return new_checkpoint
def     lowercase__       (       __lowercase						:  List[Any]    ,  __lowercase						:  str					)			->				Dict:



							"""simple docstring"""






							__UpperCamelCase	=  {}

							__UpperCamelCase	=  checkpoint['encoder.norm_out.weight']
							__UpperCamelCase	=  checkpoint['encoder.norm_out.bias']

							__UpperCamelCase	=  checkpoint['encoder.conv_in.weight']
							__UpperCamelCase	=  checkpoint['encoder.conv_in.bias']
							__UpperCamelCase	=  checkpoint['encoder.conv_out.weight']
							__UpperCamelCase	=  checkpoint['encoder.conv_out.bias']

							__UpperCamelCase	=  checkpoint['decoder.norm_out.weight']
							__UpperCamelCase	=  checkpoint['decoder.norm_out.bias']

							__UpperCamelCase	=  checkpoint['decoder.conv_in.weight']
							__UpperCamelCase	=  checkpoint['decoder.conv_in.bias']
							__UpperCamelCase	=  checkpoint['decoder.conv_out.weight']
							__UpperCamelCase	=  checkpoint['decoder.conv_out.bias']

							__UpperCamelCase	=  len({'.'.join(layer.split('.'					)[:3]					) for layer in checkpoint if 'down' in layer}					)
							__UpperCamelCase	=  {
							    layer_id: [key for key in checkpoint if F'''down.{layer_id}''' in key] for layer_id in range(__lowercase					)
							}

							__UpperCamelCase	=  len({'.'.join(layer.split('.'					)[:3]					) for layer in checkpoint if 'up' in layer}					)
							__UpperCamelCase	=  {layer_id: [key for key in checkpoint if F'''up.{layer_id}''' in key] for layer_id in range(__lowercase					)}

							for i in range(__lowercase					):
														__UpperCamelCase	=  (i - 1) // (config['layers_per_block'] + 1)

														if any('downsample' in layer for layer in down_blocks[i]					):
																					__UpperCamelCase	=  checkpoint[
																					    F'''encoder.down.{i}.downsample.conv.weight'''
																					]
																					__UpperCamelCase	=  checkpoint[
																					    F'''encoder.down.{i}.downsample.conv.bias'''
																					]

														if any('block' in layer for layer in down_blocks[i]					):
																					__UpperCamelCase	=  len(
																					    {'.'.join(shave_segments(__lowercase    ,  3					).split('.'					)[:3]					) for layer in down_blocks[i] if 'block' in layer}					)
																					__UpperCamelCase	=  {
																					    layer_id: [key for key in down_blocks[i] if F'''block.{layer_id}''' in key]
																					    for layer_id in range(__lowercase					)
																					}

																					if num_blocks > 0:
																												for j in range(config['layers_per_block']					):
																																			__UpperCamelCase	=  renew_resnet_paths(blocks[j]					)
																																			assign_to_checkpoint(__lowercase    ,  __lowercase    ,  __lowercase					)

														if any('attn' in layer for layer in down_blocks[i]					):
																					__UpperCamelCase	=  len(
																					    {'.'.join(shave_segments(__lowercase    ,  3					).split('.'					)[:3]					) for layer in down_blocks[i] if 'attn' in layer}					)
																					__UpperCamelCase	=  {
																					    layer_id: [key for key in down_blocks[i] if F'''attn.{layer_id}''' in key]
																					    for layer_id in range(__lowercase					)
																					}

																					if num_attn > 0:
																												for j in range(config['layers_per_block']					):
																																			__UpperCamelCase	=  renew_attention_paths(attns[j]					)
																																			assign_to_checkpoint(__lowercase    ,  __lowercase    ,  __lowercase    ,  config=__lowercase					)

							__UpperCamelCase	=  [key for key in checkpoint if 'mid.block_1' in key]
							__UpperCamelCase	=  [key for key in checkpoint if 'mid.block_2' in key]
							__UpperCamelCase	=  [key for key in checkpoint if 'mid.attn_1' in key]

							# Mid new 2
							__UpperCamelCase	=  renew_resnet_paths(__lowercase					)
							assign_to_checkpoint(
							    __lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[{'old': 'mid.', 'new': 'mid_new_2.'}, {'old': 'block_1', 'new': 'resnets.0'}]    ,  )

							__UpperCamelCase	=  renew_resnet_paths(__lowercase					)
							assign_to_checkpoint(
							    __lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[{'old': 'mid.', 'new': 'mid_new_2.'}, {'old': 'block_2', 'new': 'resnets.1'}]    ,  )

							__UpperCamelCase	=  renew_attention_paths(__lowercase    ,  in_mid=__lowercase					)
							assign_to_checkpoint(
							    __lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[{'old': 'mid.', 'new': 'mid_new_2.'}, {'old': 'attn_1', 'new': 'attentions.0'}]    ,  )

							for i in range(__lowercase					):
														__UpperCamelCase	=  num_up_blocks - 1 - i

														if any('upsample' in layer for layer in up_blocks[i]					):
																					__UpperCamelCase	=  checkpoint[
																					    F'''decoder.up.{i}.upsample.conv.weight'''
																					]
																					__UpperCamelCase	=  checkpoint[
																					    F'''decoder.up.{i}.upsample.conv.bias'''
																					]

														if any('block' in layer for layer in up_blocks[i]					):
																					__UpperCamelCase	=  len(
																					    {'.'.join(shave_segments(__lowercase    ,  3					).split('.'					)[:3]					) for layer in up_blocks[i] if 'block' in layer}					)
																					__UpperCamelCase	=  {
																					    layer_id: [key for key in up_blocks[i] if F'''block.{layer_id}''' in key] for layer_id in range(__lowercase					)
																					}

																					if num_blocks > 0:
																												for j in range(config['layers_per_block'] + 1					):
																																			__UpperCamelCase	=  {'old': F'''up_blocks.{i}''', 'new': F'''up_blocks.{block_id}'''}
																																			__UpperCamelCase	=  renew_resnet_paths(blocks[j]					)
																																			assign_to_checkpoint(__lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[replace_indices]					)

														if any('attn' in layer for layer in up_blocks[i]					):
																					__UpperCamelCase	=  len(
																					    {'.'.join(shave_segments(__lowercase    ,  3					).split('.'					)[:3]					) for layer in up_blocks[i] if 'attn' in layer}					)
																					__UpperCamelCase	=  {
																					    layer_id: [key for key in up_blocks[i] if F'''attn.{layer_id}''' in key] for layer_id in range(__lowercase					)
																					}

																					if num_attn > 0:
																												for j in range(config['layers_per_block'] + 1					):
																																			__UpperCamelCase	=  {'old': F'''up_blocks.{i}''', 'new': F'''up_blocks.{block_id}'''}
																																			__UpperCamelCase	=  renew_attention_paths(attns[j]					)
																																			assign_to_checkpoint(__lowercase    ,  __lowercase    ,  __lowercase    ,  additional_replacements=[replace_indices]					)

							__UpperCamelCase	=  {k.replace('mid_new_2'    ,  'mid_block'					): v for k, v in new_checkpoint.items()}
							__UpperCamelCase	=  checkpoint['quant_conv.weight']
							__UpperCamelCase	=  checkpoint['quant_conv.bias']
							if "quantize.embedding.weight" in checkpoint:
														__UpperCamelCase	=  checkpoint['quantize.embedding.weight']
							__UpperCamelCase	=  checkpoint['post_quant_conv.weight']
							__UpperCamelCase	=  checkpoint['post_quant_conv.bias']

							return new_checkpoint


if __name__ == "__main__":
				a__							:							List[str]			=argparse.ArgumentParser()

				parser.add_argument(
				    '''--checkpoint_path''', default=None, type=str, required=True, help='''Path to the checkpoint to convert.'''
				)

				parser.add_argument(
				    '''--config_file''',
				    default=None,
				    type=str,
				    required=True,
				    help='''The config json file corresponding to the architecture.''',
				)

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

				a__							:							int			=parser.parse_args()
				a__							:							Tuple			=torch.load(args.checkpoint_path)

				with open(args.config_file) as f:
								a__							:							Optional[int]			=json.loads(f.read())

				# unet case
				a__							:							int			={key.split('''.''')[0] for key in checkpoint.keys()}
				if "encoder" in key_prefix_set and "decoder" in key_prefix_set:
								a__							:							Dict			=convert_vq_autoenc_checkpoint(checkpoint, config)
				else:
								a__							:							int			=convert_ddpm_checkpoint(checkpoint, config)

				if "ddpm" in config:
								del config["ddpm"]

				if config["_class_name"] == "VQModel":
								a__							:							List[str]			=VQModel(**config)
								model.load_state_dict(converted_checkpoint)
								model.save_pretrained(args.dump_path)
				elif config["_class_name"] == "AutoencoderKL":
								a__							:							Optional[int]			=AutoencoderKL(**config)
								model.load_state_dict(converted_checkpoint)
								model.save_pretrained(args.dump_path)
				else:
								a__							:							int			=UNetaDModel(**config)
								model.load_state_dict(converted_checkpoint)

								a__							:							str			=DDPMScheduler.from_config('''/'''.join(args.checkpoint_path.split('''/''')[:-1]))

								a__							:							List[Any]			=DDPMPipeline(unet=model, scheduler=scheduler)
								pipe.save_pretrained(args.dump_path)







'''simple docstring'''
import itertools
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa

import datasets
from datasets.table import table_cast


a__							:							Optional[Any]			=datasets.utils.logging.get_logger(__name__)

@dataclass
class 					snake_case					(   datasets.BuilderConfig	):




 """simple docstring"""



 SCREAMING_SNAKE_CASE_     : Optional[datasets.Features]      		=None






class 					snake_case					(   datasets.ArrowBasedBuilder	):




 """simple docstring"""



 SCREAMING_SNAKE_CASE_     : int      		=ArrowConfig






 def 	_lowerCamelCase (	self	:							List[str]     ):
        return datasets.DatasetInfo(features=self.config.features     )






 def 	_lowerCamelCase (	self	:							Union[str, Any]							,     __A	:							Dict     ):
        if not self.config.data_files:
               raise ValueError(f'''At least one data file must be specified, but got data_files={self.config.data_files}'''     )
        __UpperCamelCase	=  dl_manager.download_and_extract(self.config.data_files     )
        if isinstance(__A							,     (str, list, tuple)     ):
               __UpperCamelCase	=  data_files
               if isinstance(__A							,     __A     ):
                      __UpperCamelCase	=  [files]
               # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
               __UpperCamelCase	=  [dl_manager.iter_files(__A     ) for file in files]
               return [datasets.SplitGenerator(name=datasets.Split.TRAIN							,     gen_kwargs={'files': files}     )]
        __UpperCamelCase	=  []
        for split_name, files in data_files.items():
               if isinstance(__A							,     __A     ):
                      __UpperCamelCase	=  [files]
               # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
               __UpperCamelCase	=  [dl_manager.iter_files(__A     ) for file in files]
               # Infer features is they are stoed in the arrow schema
               if self.info.features is None:
                      for file in itertools.chain.from_iterable(__A     ):
                             with open(__A							,     'rb'     ) as f:
                                    __UpperCamelCase	=  datasets.Features.from_arrow_schema(pa.ipc.open_stream(__A     ).schema     )
                             break
               splits.append(datasets.SplitGenerator(name=__A							,     gen_kwargs={'files': files}     )     )
        return splits






 def 	_lowerCamelCase (	self	:							Any							,     __A	:							pa.Table     ):
        if self.info.features is not None:
               # more expensive cast to support nested features with keys in a different order
               # allows str <-> int/float or str to Audio for example
               __UpperCamelCase	=  table_cast(__A							,     self.info.features.arrow_schema     )
        return pa_table






 def 	_lowerCamelCase (	self	:							int							,     __A	:							Optional[Any]     ):
        for file_idx, file in enumerate(itertools.chain.from_iterable(__A     )     ):
               with open(__A							,     'rb'     ) as f:
                      try:
                             for batch_idx, record_batch in enumerate(pa.ipc.open_stream(__A     )     ):
                                    __UpperCamelCase	=  pa.Table.from_batches([record_batch]     )
                                    # Uncomment for debugging (will print the Arrow table size and elements)
                                    # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
                                    # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
                                    yield f'''{file_idx}_{batch_idx}''', self._cast_table(__A     )
                      except ValueError as e:
                             logger.error(f'''Failed to read file \'{file}\' with error {type(__A     )}: {e}'''     )
                             raise
