




# Copyright (c) 2021-, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

####################################################################################################

#
# Note: If when running this conversion script you're getting an exception:
#     ModuleNotFoundError: No module named 'megatron.model.enums'
# you need to tell python where to find the clone of Megatron-LM, e.g.:
#
# cd /tmp
# git clone https://github.com/NVIDIA/Megatron-LM
# PYTHONPATH=/tmp/Megatron-LM python src/transformers/models/megatron_gpt2/convert_megatron_gpt2_checkpoint.py ...
#
# if you already have it cloned elsewhere, simply adjust the path to the existing path
#
# If the training was done using a Megatron-LM fork, e.g.,
# https://github.com/microsoft/Megatron-DeepSpeed/ then chances are that you need to have that one
# in your path, i.e., /path/to/Megatron-DeepSpeed/
#

import argparse
import os
import re
import zipfile

import torch

from transformers import AutoTokenizer, GPTaConfig




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase=0 ):
				# Format the message.
				if name is None:
								__magic_name__						:						List[str]										=None
				else:
								__magic_name__						:						Optional[Any]										=""".""" * max(0						,  spaces - 2 ) + """# {:""" + str(50 - spaces ) + """s}"""
								__magic_name__						:						Optional[int]										=fmt.format(lowerCamelCase )

				# Print and recurse (if needed).
				if isinstance(lowerCamelCase						,  lowerCamelCase ):
								if msg is not None:
												print(lowerCamelCase )
								for k in val.keys():
												recursive_print(lowerCamelCase						,  val[k]						,  spaces + 2 )
				elif isinstance(lowerCamelCase						,  torch.Tensor ):
								print(lowerCamelCase						,  """:"""						,  val.size() )
				else:
								print(lowerCamelCase						,  """:"""						,  lowerCamelCase )




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase ):
				# Permutes layout of param tensor to [num_splits * num_heads * hidden_size, :]
				# for compatibility with later versions of NVIDIA Megatron-LM.
				# The inverse operation is performed inside Megatron-LM to read checkpoints:
				# https://github.com/NVIDIA/Megatron-LM/blob/v2.4/megatron/checkpointing.py#L209
				# If param is the weight tensor of the self-attention block, the returned tensor
				# will have to be transposed one more time to be read by HuggingFace GPT2.
				__magic_name__						:						Union[str, Any]										=param.size()
				if checkpoint_version == 1.0:
								# version 1.0 stores [num_heads * hidden_size * num_splits, :]
								__magic_name__						:						int										=(num_heads, hidden_size, num_splits) + input_shape[1:]
								__magic_name__						:						List[str]										=param.view(*lowerCamelCase )
								__magic_name__						:						List[Any]										=param.transpose(0						,  2 )
								__magic_name__						:						int										=param.transpose(1						,  2 ).contiguous()
				elif checkpoint_version >= 2.0:
								# other versions store [num_heads * num_splits * hidden_size, :]
								__magic_name__						:						Any										=(num_heads, num_splits, hidden_size) + input_shape[1:]
								__magic_name__						:						int										=param.view(*lowerCamelCase )
								__magic_name__						:						str										=param.transpose(0						,  1 ).contiguous()
				__magic_name__						:						List[Any]										=param.view(*lowerCamelCase )
				return param




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase ):
				# The converted output model.
				__magic_name__						:						Optional[int]										={}

				# old versions did not store training args
				__magic_name__						:						Any										=input_state_dict.get("""args"""						,  lowerCamelCase )
				if ds_args is not None:
								# do not make the user write a config file when the exact dimensions/sizes are already in the checkpoint
								# from pprint import pprint
								# pprint(vars(ds_args))

								__magic_name__						:						List[str]										=ds_args.padded_vocab_size
								__magic_name__						:						List[str]										=ds_args.max_position_embeddings
								__magic_name__						:						List[Any]										=ds_args.hidden_size
								__magic_name__						:						Union[str, Any]										=ds_args.num_layers
								__magic_name__						:						Tuple										=ds_args.num_attention_heads
								__magic_name__						:						List[str]										=ds_args.ffn_hidden_size
								# pprint(config)

				# The number of heads.
				__magic_name__						:						Dict										=config.n_head
				# The hidden_size per head.
				__magic_name__						:						int										=config.n_embd // config.n_head
				# Megatron-LM checkpoint version
				if "checkpoint_version" in input_state_dict.keys():
								__magic_name__						:						Union[str, Any]										=input_state_dict["""checkpoint_version"""]
				else:
								__magic_name__						:						Any										=0.0

				# The model.
				__magic_name__						:						Dict										=input_state_dict["""model"""]
				# The language model.
				__magic_name__						:						Tuple										=model["""language_model"""]
				# The embeddings.
				__magic_name__						:						List[str]										=lm["""embedding"""]

				# The word embeddings.
				__magic_name__						:						str										=embeddings["""word_embeddings"""]["""weight"""]
				# Truncate the embedding table to vocab_size rows.
				__magic_name__						:						Dict										=word_embeddings[: config.vocab_size, :]
				__magic_name__						:						Optional[int]										=word_embeddings

				# The position embeddings.
				__magic_name__						:						str										=embeddings["""position_embeddings"""]["""weight"""]
				# Read the causal mask dimension (seqlen). [max_sequence_length, hidden_size]
				__magic_name__						:						Union[str, Any]										=pos_embeddings.size(0 )
				if n_positions != config.n_positions:
								raise ValueError(
								    F"pos_embeddings.max_sequence_length={n_positions} and config.n_positions={config.n_positions} don't match" )
				# Store the position embeddings.
				__magic_name__						:						Optional[int]										=pos_embeddings

				# The transformer.
				__magic_name__						:						Dict										=lm["""transformer"""] if """transformer""" in lm.keys() else lm["""encoder"""]

				# The regex to extract layer names.
				__magic_name__						:						List[str]										=re.compile(R"""layers\.(\d+)\.([a-z0-9_.]+)\.([a-z]+)""" )

				# The simple map of names for "automated" rules.
				__magic_name__						:						List[Any]										={
				    """attention.dense""": """.attn.c_proj.""",
				    """self_attention.dense""": """.attn.c_proj.""",
				    """mlp.dense_h_to_4h""": """.mlp.c_fc.""",
				    """mlp.dense_4h_to_h""": """.mlp.c_proj.""",
				}

				# Extract the layers.
				for key, val in transformer.items():
								# Match the name.
								__magic_name__						:						List[Any]										=layer_re.match(lowerCamelCase )

								# Stop if that's not a layer
								if m is None:
												break

								# The index of the layer.
								__magic_name__						:						str										=int(m.group(1 ) )
								# The name of the operation.
								__magic_name__						:						Dict										=m.group(2 )
								# Is it a weight or a bias?
								__magic_name__						:						Dict										=m.group(3 )

								# The name of the layer.
								__magic_name__						:						List[str]										=F"transformer.h.{layer_idx}"

								# For layernorm(s), simply store the layer norm.
								if op_name.endswith("""layernorm""" ):
												__magic_name__						:						List[Any]										="""ln_1""" if op_name.startswith("""input""" ) else """ln_2"""
												__magic_name__						:						Optional[int]										=val

								# Transpose the QKV matrix.
								elif (
								    op_name == "attention.query_key_value" or op_name == "self_attention.query_key_value"
								) and weight_or_bias == "weight":
												# Insert a tensor of 1x1xDxD bias.
												__magic_name__						:						Optional[Any]										=torch.tril(torch.ones((n_positions, n_positions)						,  dtype=torch.floataa ) ).view(
												    1						,  1						,  lowerCamelCase						,  lowerCamelCase )
												__magic_name__						:						Dict										=causal_mask

												# Insert a "dummy" tensor for masked_bias.
												__magic_name__						:						Any										=torch.tensor(-1E4						,  dtype=torch.floataa )
												__magic_name__						:						Dict										=masked_bias

												__magic_name__						:						List[str]										=fix_query_key_value_ordering(lowerCamelCase						,  lowerCamelCase						,  3						,  lowerCamelCase						,  lowerCamelCase )
												# Megatron stores (3*D) x D but transformers-GPT2 expects D x 3*D.
												__magic_name__						:						Optional[Any]										=out_val.transpose(0						,  1 ).contiguous()
												# Store.
												__magic_name__						:						Any										=out_val

								# Transpose the bias.
								elif (
								    op_name == "attention.query_key_value" or op_name == "self_attention.query_key_value"
								) and weight_or_bias == "bias":
												__magic_name__						:						Dict										=fix_query_key_value_ordering(lowerCamelCase						,  lowerCamelCase						,  3						,  lowerCamelCase						,  lowerCamelCase )
												# Store. No change of shape.
												__magic_name__						:						Union[str, Any]										=out_val

								# Transpose the weights.
								elif weight_or_bias == "weight":
												__magic_name__						:						Tuple										=megatron_to_transformers[op_name]
												__magic_name__						:						List[str]										=val.transpose(0						,  1 )

								# Copy the bias.
								elif weight_or_bias == "bias":
												__magic_name__						:						Optional[int]										=megatron_to_transformers[op_name]
												__magic_name__						:						Dict										=val

    # DEBUG.
				assert config.n_layer == layer_idx + 1

				# The final layernorm.
				__magic_name__						:						Any										=transformer["""final_layernorm.weight"""]
				__magic_name__						:						Tuple										=transformer["""final_layernorm.bias"""]

				# For LM head, transformers' wants the matrix to weight embeddings.
				__magic_name__						:						int										=word_embeddings

				# It should be done!
				return output_state_dict




def 		lowerCAmelCase_ (						):
				# Create the argument parser.
				__magic_name__						:						Union[str, Any]										=argparse.ArgumentParser()
				parser.add_argument("""--print-checkpoint-structure"""						,  action="""store_true""" )
				parser.add_argument(
				    """path_to_checkpoint"""						,  type=lowerCamelCase						,  help="""Path to the checkpoint file (.zip archive or direct .pt file)"""						,  )
				parser.add_argument(
				    """--config_file"""						,  default=""""""						,  type=lowerCamelCase						,  help="""An optional config json file describing the pre-trained model."""						,  )
				__magic_name__						:						Any										=parser.parse_args()

				# Extract the basename.
				__magic_name__						:						Tuple										=os.path.dirname(args.path_to_checkpoint )

				# Load the model.
				# the .zip is very optional, let's keep it for backward compatibility
				print(F"Extracting PyTorch state dictionary from {args.path_to_checkpoint}" )
				if args.path_to_checkpoint.endswith(""".zip""" ):
								with zipfile.ZipFile(args.path_to_checkpoint						,  """r""" ) as checkpoint:
												with checkpoint.open("""release/mp_rank_00/model_optim_rng.pt""" ) as pytorch_dict:
																__magic_name__						:						Optional[Any]										=torch.load(lowerCamelCase						,  map_location="""cpu""" )
				else:
								__magic_name__						:						Dict										=torch.load(args.path_to_checkpoint						,  map_location="""cpu""" )

				__magic_name__						:						Optional[Any]										=input_state_dict.get("""args"""						,  lowerCamelCase )

				# Read the config, or default to the model released by NVIDIA.
				if args.config_file == "":
								if ds_args is not None:
												if ds_args.bias_gelu_fusion:
																__magic_name__						:						Optional[Any]										="""gelu_fast"""
												elif ds_args.openai_gelu:
																__magic_name__						:						Optional[Any]										="""gelu_new"""
												else:
																__magic_name__						:						List[Any]										="""gelu"""
								else:
												# in the very early days this used to be "gelu_new"
												__magic_name__						:						Dict										="""gelu_new"""

								# Spell out all parameters in case the defaults change.
								__magic_name__						:						Any										=GPTaConfig(
								    vocab_size=50257						,  n_positions=1024						,  n_embd=1024						,  n_layer=24						,  n_head=16						,  n_inner=4096						,  activation_function=lowerCamelCase						,  resid_pdrop=0.1						,  embd_pdrop=0.1						,  attn_pdrop=0.1						,  layer_norm_epsilon=1E-5						,  initializer_range=0.0_2						,  summary_type="""cls_index"""						,  summary_use_proj=lowerCamelCase						,  summary_activation=lowerCamelCase						,  summary_proj_to_labels=lowerCamelCase						,  summary_first_dropout=0.1						,  scale_attn_weights=lowerCamelCase						,  use_cache=lowerCamelCase						,  bos_token_id=50256						,  eos_token_id=50256						,  )
				else:
								__magic_name__						:						Optional[int]										=GPTaConfig.from_json_file(args.config_file )

				__magic_name__						:						Tuple										=["""GPT2LMHeadModel"""]

				# Convert.
				print("""Converting""" )
				__magic_name__						:						int										=convert_megatron_checkpoint(lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase )

				# Print the structure of converted state dict.
				if args.print_checkpoint_structure:
								recursive_print(lowerCamelCase						,  lowerCamelCase )

				# Add tokenizer class info to config
				# see https://github.com/huggingface/transformers/issues/13906)
				if ds_args is not None:
								__magic_name__						:						Union[str, Any]										=ds_args.tokenizer_type
								if tokenizer_type == "GPT2BPETokenizer":
												__magic_name__						:						List[Any]										="""gpt2"""
								elif tokenizer_type == "PretrainedFromHF":
												__magic_name__						:						Optional[Any]										=ds_args.tokenizer_name_or_path
								else:
												raise ValueError(F"Unrecognized tokenizer_type {tokenizer_type}" )
				else:
								__magic_name__						:						List[Any]										="""gpt2"""

				__magic_name__						:						Dict										=AutoTokenizer.from_pretrained(lowerCamelCase )
				__magic_name__						:						Tuple										=type(lowerCamelCase ).__name__
				__magic_name__						:						List[Any]										=tokenizer_class

				# Store the config to file.
				print("""Saving config""" )
				config.save_pretrained(lowerCamelCase )

				# Save tokenizer based on args
				print(F"Adding {tokenizer_class} tokenizer files" )
				tokenizer.save_pretrained(lowerCamelCase )

				# Store the state_dict to file.
				__magic_name__						:						Optional[int]										=os.path.join(lowerCamelCase						,  """pytorch_model.bin""" )
				print(F"Saving checkpoint to \"{output_checkpoint_file}\"" )
				torch.save(lowerCamelCase						,  lowerCamelCase )


####################################################################################################

if __name__ == "__main__":
							main()

####################################################################################################










from typing import Dict, List, Optional, Union

import numpy as np

from .feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from .utils import PaddingStrategy, TensorType, is_tf_tensor, is_torch_tensor, logging, to_numpy


UpperCAmelCase_		:					Dict          =  logging.get_logger(__name__)




class 		__A   (      UpperCamelCase__      ):

						def __init__(		self :List[str]     ,			__snake_case :int     ,			__snake_case :int     ,			__snake_case :float     ,			**__snake_case :Optional[Any]			):
										'''simple docstring'''

										__magic_name__						:						List[Any]										=feature_size
										__magic_name__						:						Union[str, Any]										=sampling_rate
										__magic_name__						:						List[Any]										=padding_value

										__magic_name__						:						List[str]										=kwargs.pop("""padding_side"""     ,			"""right"""			)
										__magic_name__						:						Tuple										=kwargs.pop("""return_attention_mask"""     ,			__snake_case			)

										super().__init__(**__snake_case			)

						def      A__    (		self :Any     ,			__snake_case :Union[
						        BatchFeature,
						        List[BatchFeature],
						        Dict[str, BatchFeature],
						        Dict[str, List[BatchFeature]],
						        List[Dict[str, BatchFeature]],
						    ]     ,			__snake_case :Union[bool, str, PaddingStrategy] = True     ,			__snake_case :Optional[int] = None     ,			__snake_case :bool = False     ,			__snake_case :Optional[int] = None     ,			__snake_case :Optional[bool] = None     ,			__snake_case :Optional[Union[str, TensorType]] = None     ,			):
										'''simple docstring'''

										if isinstance(__snake_case     ,			(list, tuple)			) and isinstance(processed_features[0]     ,			(dict, BatchFeature)			):
														__magic_name__						:						Union[str, Any]										={
														    key: [example[key] for example in processed_features] for key in processed_features[0].keys()
														}

										# The model's main input name, usually `input_values`, has be passed for padding
										if self.model_input_names[0] not in processed_features:
														raise ValueError(
														    """You should supply an instance of `transformers.BatchFeature` or list of `transformers.BatchFeature`"""
														    f" to this method that includes {self.model_input_names[0]}, but you provided"
														    f" {list(processed_features.keys()			)}"			)

										__magic_name__						:						int										=processed_features[self.model_input_names[0]]
										__magic_name__						:						Union[str, Any]										=(
										    return_attention_mask if return_attention_mask is not None else self.return_attention_mask
										)

										if len(__snake_case			) == 0:
														if return_attention_mask:
																		__magic_name__						:						List[str]										=[]
														return processed_features

										# If we have PyTorch/TF tensors or lists as inputs, we cast them as Numpy arrays
										# and rebuild them afterwards if no return_tensors is specified
										# Note that we lose the specific device the tensor may be on for PyTorch

										__magic_name__						:						Optional[int]										=required_input[0]
										if isinstance(__snake_case     ,			(list, tuple)			):
														# first_element might be an empty list/tuple in some edge cases so we grab the first non empty element.
														__magic_name__						:						Optional[Any]										=0
														while len(required_input[index]			) == 0:
																		index += 1
														if index < len(__snake_case			):
																		__magic_name__						:						List[str]										=required_input[index][0]

										if return_tensors is None:
														if is_tf_tensor(__snake_case			):
																		__magic_name__						:						int										="""tf"""
														elif is_torch_tensor(__snake_case			):
																		__magic_name__						:						str										="""pt"""
														elif isinstance(__snake_case     ,			(int, float, list, tuple, np.ndarray)			):
																		__magic_name__						:						List[Any]										="""np"""
														else:
																		raise ValueError(
																		    f"type of {first_element} unknown: {type(__snake_case			)}. "
																		    """Should be one of a python, numpy, pytorch or tensorflow object."""			)

										for key, value in processed_features.items():
														if isinstance(value[0]     ,			(int, float)			):
																		__magic_name__						:						List[str]										=to_numpy(__snake_case			)
														else:
																		__magic_name__						:						str										=[to_numpy(__snake_case			) for v in value]

        # Convert padding_strategy in PaddingStrategy
										__magic_name__						:						Dict										=self._get_padding_strategies(padding=__snake_case     ,			max_length=__snake_case			)

										__magic_name__						:						Optional[Any]										=processed_features[self.model_input_names[0]]

										__magic_name__						:						Dict										=len(__snake_case			)
										if not all(len(__snake_case			) == batch_size for v in processed_features.values()			):
														raise ValueError("""Some items in the output dictionary have a different batch size than others."""			)

										__magic_name__						:						Optional[int]										=[]
										for i in range(__snake_case			):
														__magic_name__						:						Any										={k: v[i] for k, v in processed_features.items()}
														# truncation
														__magic_name__						:						List[str]										=self._truncate(
														    __snake_case     ,			max_length=__snake_case     ,			pad_to_multiple_of=__snake_case     ,			truncation=__snake_case     ,			)
														truncated_inputs.append(__snake_case			)

										if padding_strategy == PaddingStrategy.LONGEST:
														# make sure that `max_length` cannot be longer than the longest truncated length
														__magic_name__						:						Optional[int]										=max(len(input_slice[self.model_input_names[0]]			) for input_slice in truncated_inputs			)
														__magic_name__						:						Tuple										=PaddingStrategy.MAX_LENGTH

										__magic_name__						:						str										={}
										for i in range(__snake_case			):
														# padding
														__magic_name__						:						List[str]										=self._pad(
														    truncated_inputs[i]     ,			max_length=__snake_case     ,			padding_strategy=__snake_case     ,			pad_to_multiple_of=__snake_case     ,			return_attention_mask=__snake_case     ,			)

														for key, value in outputs.items():
																		if key not in batch_outputs:
																						__magic_name__						:						Dict										=[]
																		if value.dtype is np.dtype(np.floataa			):
																						__magic_name__						:						Optional[int]										=value.astype(np.floataa			)
																		batch_outputs[key].append(__snake_case			)

										return BatchFeature(__snake_case     ,			tensor_type=__snake_case			)

						def      A__    (		self :Any     ,			__snake_case :Union[Dict[str, np.ndarray], BatchFeature]     ,			__snake_case :Optional[int] = None     ,			__snake_case :PaddingStrategy = PaddingStrategy.DO_NOT_PAD     ,			__snake_case :Optional[int] = None     ,			__snake_case :Optional[bool] = None     ,			):
										'''simple docstring'''

										__magic_name__						:						Dict										=processed_features[self.model_input_names[0]]

										if padding_strategy == PaddingStrategy.LONGEST:
														__magic_name__						:						Any										=len(__snake_case			)

										if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
														__magic_name__						:						Dict										=((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of

										__magic_name__						:						List[Any]										=padding_strategy != PaddingStrategy.DO_NOT_PAD and len(__snake_case			) < max_length

										if return_attention_mask and "attention_mask" not in processed_features:
														__magic_name__						:						int										=np.ones(len(__snake_case			)     ,			dtype=np.intaa			)

										if needs_to_be_padded:
														__magic_name__						:						List[Any]										=max_length - len(__snake_case			)
														if self.padding_side == "right":
																		if return_attention_mask:
																						__magic_name__						:						str										=np.pad(
																						    processed_features["""attention_mask"""]     ,			(0, difference)			)
																		__magic_name__						:						Tuple										=((0, difference), (0, 0)) if self.feature_size > 1 else (0, difference)
																		__magic_name__						:						str										=np.pad(
																		    __snake_case     ,			__snake_case     ,			"""constant"""     ,			constant_values=self.padding_value			)
														elif self.padding_side == "left":
																		if return_attention_mask:
																						__magic_name__						:						str										=np.pad(
																						    processed_features["""attention_mask"""]     ,			(difference, 0)			)
																		__magic_name__						:						Optional[int]										=((difference, 0), (0, 0)) if self.feature_size > 1 else (difference, 0)
																		__magic_name__						:						List[Any]										=np.pad(
																		    __snake_case     ,			__snake_case     ,			"""constant"""     ,			constant_values=self.padding_value			)
														else:
																		raise ValueError("""Invalid padding strategy:""" + str(self.padding_side			)			)

										return processed_features

						def      A__    (		self :Optional[Any]     ,			__snake_case :Union[Dict[str, np.ndarray], BatchFeature]     ,			__snake_case :Optional[int] = None     ,			__snake_case :Optional[int] = None     ,			__snake_case :Optional[bool] = None     ,			):
										'''simple docstring'''

										if not truncation:
														return processed_features
										elif truncation and max_length is None:
														raise ValueError("""When setting ``truncation=True``, make sure that ``max_length`` is defined."""			)

										__magic_name__						:						Union[str, Any]										=processed_features[self.model_input_names[0]]

										# find `max_length` that fits `pad_to_multiple_of`
										if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
														__magic_name__						:						List[str]										=((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of

										__magic_name__						:						Any										=len(__snake_case			) > max_length

										if needs_to_be_truncated:
														__magic_name__						:						List[Any]										=processed_features[self.model_input_names[0]][:max_length]
														if "attention_mask" in processed_features:
																		__magic_name__						:						List[str]										=processed_features["""attention_mask"""][:max_length]

										return processed_features


						def      A__    (		self :List[Any]     ,			__snake_case :str=False     ,			__snake_case :Optional[int]=None			):
										'''simple docstring'''

										if padding is not False:
														if padding is True:
																		__magic_name__						:						Union[str, Any]										=PaddingStrategy.LONGEST  # Default to pad to the longest sequence in the batch
														elif not isinstance(__snake_case     ,			__snake_case			):
																		__magic_name__						:						Optional[int]										=PaddingStrategy(__snake_case			)
														elif isinstance(__snake_case     ,			__snake_case			):
																		__magic_name__						:						Any										=padding
										else:
														__magic_name__						:						Any										=PaddingStrategy.DO_NOT_PAD

										# Set max length if needed
										if max_length is None:
														if padding_strategy == PaddingStrategy.MAX_LENGTH:
																		raise ValueError(
																		    f"When setting ``padding={PaddingStrategy.MAX_LENGTH}``, make sure that max_length is defined"			)

        # Test if we have a padding value
										if padding_strategy != PaddingStrategy.DO_NOT_PAD and (self.padding_value is None):
														raise ValueError(
														    """Asking to pad but the feature_extractor does not have a padding value. Please select a value to use"""
														    """ as `padding_value`. For example: `feature_extractor.padding_value = 0.0`."""			)

										return padding_strategy




