


import json
import os
import re
import unicodedata
from json.encoder import INFINITY
from typing import Any, Dict, List, Optional, Tuple, Union

import numpy as np
import regex

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...tokenization_utils_base import BatchEncoding
from ...utils import TensorType, is_flax_available, is_tf_available, is_torch_available, logging
from ...utils.generic import _is_jax, _is_numpy


_snake_case  :	List[str]			      =       logging.get_logger(__name__)

_snake_case  :	Union[str, Any]			      =       {
    "artists_file": "artists.json",
    "lyrics_file": "lyrics.json",
    "genres_file": "genres.json",
}

_snake_case  :	Tuple			      =       {
    "artists_file": {
        "jukebox": "https://huggingface.co/ArthurZ/jukebox/blob/main/artists.json",
    },
    "genres_file": {
        "jukebox": "https://huggingface.co/ArthurZ/jukebox/blob/main/genres.json",
    },
    "lyrics_file": {
        "jukebox": "https://huggingface.co/ArthurZ/jukebox/blob/main/lyrics.json",
    },
}

_snake_case  :	str			      =       {
    "jukebox": 512,
}

class        a	(_lowerCAmelCase   ):




							"""simple docstring"""


							__UpperCAmelCase					:							Any  						=						VOCAB_FILES_NAMES
							__UpperCAmelCase					:							List[Any]  						=						PRETRAINED_VOCAB_FILES_MAP
							__UpperCAmelCase					:							Tuple  						=						PRETRAINED_LYRIC_TOKENS_SIZES
							__UpperCAmelCase					:							Dict  						=						["input_ids", "attention_mask"]

							def __init__(							self :						Union[str, Any]					,			lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						str					,			lowerCamelCase :						Dict					,			lowerCamelCase :						int=["v3", "v2", "v2"]					,			lowerCamelCase :						Tuple=512					,			lowerCamelCase :						str=5					,			lowerCamelCase :						int="<|endoftext|>"					,			**lowerCamelCase :						List[Any]					,			)			->					List[str]:
														__snake_case	:    List[Any]											=     AddedToken(lowerCamelCase					,			lstrip=lowerCamelCase					,			rstrip=lowerCamelCase       ) if isinstance(lowerCamelCase					,			lowerCamelCase       ) else unk_token
														super().__init__(
														    unk_token=lowerCamelCase					,			n_genres=lowerCamelCase					,			version=lowerCamelCase					,			max_n_lyric_tokens=lowerCamelCase					,			**lowerCamelCase					,			)
														__snake_case	:    List[str]											=     version
														__snake_case	:    Dict											=     max_n_lyric_tokens
														__snake_case	:    Optional[Any]											=     n_genres

														with open(lowerCamelCase					,			encoding="utf-8"       ) as vocab_handle:
																					__snake_case	:    Dict											=     json.load(lowerCamelCase       )

														with open(lowerCamelCase					,			encoding="utf-8"       ) as vocab_handle:
																					__snake_case	:    Tuple											=     json.load(lowerCamelCase       )

														with open(lowerCamelCase					,			encoding="utf-8"       ) as vocab_handle:
																					__snake_case	:    List[str]											=     json.load(lowerCamelCase       )

														__snake_case	:    Optional[Any]											=     R"[^A-Za-z0-9.,:;!?\-'\"()\[\] \t\n]+"
														# In v2, we had a n_vocab=80 and in v3 we missed + and so n_vocab=79 of characters.
														if len(self.lyrics_encoder       ) == 79:
																					__snake_case	:    Dict											=     oov.replace(R"\-'"					,			R"\-+'"       )

														__snake_case	:    Optional[Any]											=     regex.compile(lowerCamelCase       )
														__snake_case	:    Any											=     {v: k for k, v in self.artists_encoder.items()}
														__snake_case	:    List[str]											=     {v: k for k, v in self.genres_encoder.items()}
														__snake_case	:    Optional[Any]											=     {v: k for k, v in self.lyrics_encoder.items()}

							@property
							def 					__snake_case      (							self :						Any       )			->					Dict:
														return len(self.artists_encoder       ) + len(self.genres_encoder       ) + len(self.lyrics_encoder       )

							def 					__snake_case      (							self :						Dict       )			->					Dict:
														return dict(self.artists_encoder					,			self.genres_encoder					,			self.lyrics_encoder       )

							def 					__snake_case      (							self :						List[Any]					,			lowerCamelCase :						Any					,			lowerCamelCase :						int					,			lowerCamelCase :						Dict       )			->					List[str]:
														__snake_case	:    List[Any]											=     [self.artists_encoder.get(lowerCamelCase					,			0       ) for artist in list_artists]
														for genres in range(len(lowerCamelCase       )       ):
																					__snake_case	:    Optional[int]											=     [self.genres_encoder.get(lowerCamelCase					,			0       ) for genre in list_genres[genres]]
																					__snake_case	:    Optional[int]											=     list_genres[genres] + [-1] * (self.n_genres - len(list_genres[genres]       ))

														__snake_case	:    Any											=     [[self.lyrics_encoder.get(lowerCamelCase					,			0       ) for character in list_lyrics[0]], [], []]
														return artists_id, list_genres, lyric_ids

							def 					__snake_case      (							self :						Optional[int]					,			lowerCamelCase :						int       )			->					Tuple:
														return list(lowerCamelCase       )

							def 					__snake_case      (							self :						Optional[int]					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						Union[str, Any]					,			lowerCamelCase :						Dict					,			**lowerCamelCase :						Dict       )			->					int:
														__snake_case				,    __snake_case				,    __snake_case	:    List[Any]											=     self.prepare_for_tokenization(lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase       )
														__snake_case	:    List[Any]											=     self._tokenize(lowerCamelCase       )
														return artist, genre, lyrics

							def 					__snake_case      (							self :						List[Any]					,			lowerCamelCase :						str					,			lowerCamelCase :						str					,			lowerCamelCase :						str					,			lowerCamelCase :						bool = False       )			->					Tuple[str, str, str, Dict[str, Any]]:
														for idx in range(len(self.version       )       ):
																					if self.version[idx] == "v3":
																												__snake_case	:    str											=     artists[idx].lower()
																												__snake_case	:    Tuple											=     [genres[idx].lower()]
																					else:
																												__snake_case	:    Optional[Any]											=     self._normalize(artists[idx]       ) + ".v2"
																												__snake_case	:    int											=     [
																												    self._normalize(lowerCamelCase       ) + ".v2" for genre in genres[idx].split("_"       )
																												]  # split is for the full dictionary with combined genres

														if self.version[0] == "v2":
																					__snake_case	:    str											=     regex.compile(R"[^A-Za-z0-9.,:;!?\-'\"()\[\] \t\n]+"       )
																					__snake_case	:    List[Any]											=     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,:;!?-+'\"()[] \t\n"
																					__snake_case	:    Optional[Any]											=     {vocab[index]: index + 1 for index in range(len(lowerCamelCase       )       )}
																					__snake_case	:    Union[str, Any]											=     0
																					__snake_case	:    Optional[int]											=     len(lowerCamelCase       ) + 1
																					__snake_case	:    Optional[Any]											=     self.vocab
																					__snake_case	:    Optional[Any]											=     {v: k for k, v in self.vocab.items()}
																					__snake_case	:    Tuple											=     ""
														else:
																					__snake_case	:    List[Any]											=     regex.compile(R"[^A-Za-z0-9.,:;!?\-+'\"()\[\] \t\n]+"       )

														__snake_case	:    Any											=     self._run_strip_accents(lowerCamelCase       )
														__snake_case	:    Optional[int]											=     lyrics.replace("\\"					,			"\n"       )
														__snake_case	:    Union[str, Any]											=     self.out_of_vocab.sub(""					,			lowerCamelCase       ), [], []
														return artists, genres, lyrics

							def 					__snake_case      (							self :						str					,			lowerCamelCase :						str       )			->					Optional[int]:
														__snake_case	:    List[str]											=     unicodedata.normalize("NFD"					,			lowerCamelCase       )
														__snake_case	:    List[str]											=     []
														for char in text:
																					__snake_case	:    str											=     unicodedata.category(lowerCamelCase       )
																					if cat == "Mn":
																												continue
																					output.append(lowerCamelCase       )
														return "".join(lowerCamelCase       )

							def 					__snake_case      (							self :						int					,			lowerCamelCase :						str       )			->					str:
														__snake_case	:    Optional[int]											=     (
														    [chr(lowerCamelCase       ) for i in range(ord("a"       )					,			ord("z"       ) + 1       )]
														    + [chr(lowerCamelCase       ) for i in range(ord("A"       )					,			ord("Z"       ) + 1       )]
														    + [chr(lowerCamelCase       ) for i in range(ord("0"       )					,			ord("9"       ) + 1       )]
														    + ["."]
														)
														__snake_case	:    int											=     frozenset(lowerCamelCase       )
														__snake_case	:    List[str]											=     re.compile(R"_+"       )
														__snake_case	:    int											=     "".join([c if c in accepted else "_" for c in text.lower()]       )
														__snake_case	:    Dict											=     pattern.sub("_"					,			lowerCamelCase       ).strip("_"       )
														return text

							def 					__snake_case      (							self :						List[Any]					,			lowerCamelCase :						List[str]       )			->					str:
														return " ".join(lowerCamelCase       )

							def 					__snake_case      (							self :						List[Any]					,			lowerCamelCase :						List[str]					,			lowerCamelCase :						Optional[Union[str, TensorType]] = None					,			lowerCamelCase :						bool = False       )			->					Union[str, Any]:
														# Convert to TensorType
														if not isinstance(lowerCamelCase					,			lowerCamelCase       ):
																					__snake_case	:    Dict											=     TensorType(lowerCamelCase       )

														# Get a function reference for the correct framework
														if tensor_type == TensorType.TENSORFLOW:
																					if not is_tf_available():
																												raise ImportError(
																												    "Unable to convert output to TensorFlow tensors format, TensorFlow is not installed."       )
																					import tensorflow as tf

																					__snake_case	:    List[str]											=     tf.constant
																					__snake_case	:    Any											=     tf.is_tensor
														elif tensor_type == TensorType.PYTORCH:
																					if not is_torch_available():
																												raise ImportError("Unable to convert output to PyTorch tensors format, PyTorch is not installed."       )
																					import torch

																					__snake_case	:    List[Any]											=     torch.tensor
																					__snake_case	:    Tuple											=     torch.is_tensor
														elif tensor_type == TensorType.JAX:
																					if not is_flax_available():
																												raise ImportError("Unable to convert output to JAX tensors format, JAX is not installed."       )
																					import jax.numpy as jnp  # noqa: F811

																					__snake_case	:    List[str]											=     jnp.array
																					__snake_case	:    List[str]											=     _is_jax
														else:
																					__snake_case	:    List[Any]											=     np.asarray
																					__snake_case	:    Any											=     _is_numpy

														# Do the tensor conversion in batch

														try:
																					if prepend_batch_axis:
																												__snake_case	:    Tuple											=     [inputs]

																					if not is_tensor(lowerCamelCase       ):
																												__snake_case	:    int											=     as_tensor(lowerCamelCase       )
														except:  # noqa E722
																					raise ValueError(
																					    "Unable to create tensor, you should probably activate truncation and/or padding "
																					    "with 'padding=True' 'truncation=True' to have batched tensors with the same length."       )

														return inputs

							def __call__(							self :						Union[str, Any]					,			lowerCamelCase :						Tuple					,			lowerCamelCase :						Dict					,			lowerCamelCase :						List[str]=""					,			lowerCamelCase :						Any="pt"       )			->					BatchEncoding:
														__snake_case	:    List[Any]											=     [0, 0, 0]
														__snake_case	:    Tuple											=     [artist] * len(self.version       )
														__snake_case	:    Optional[int]											=     [genres] * len(self.version       )

														__snake_case				,    __snake_case				,    __snake_case	:    Dict											=     self.tokenize(lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase       )
														__snake_case				,    __snake_case				,    __snake_case	:    List[Any]											=     self._convert_token_to_id(lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase       )

														__snake_case	:    List[str]											=     [-INFINITY] * len(full_tokens[-1]       )
														__snake_case	:    int											=     [
														    self.convert_to_tensors(
														        [input_ids + [artists_id[i]] + genres_ids[i] + full_tokens[i]]					,			tensor_type=lowerCamelCase       )
														    for i in range(len(self.version       )       )
														]
														return BatchEncoding({"input_ids": input_ids, "attention_masks": attention_masks}       )

							def 					__snake_case      (							self :						Union[str, Any]					,			lowerCamelCase :						str					,			lowerCamelCase :						Optional[str] = None       )			->					Tuple[str]:
														if not os.path.isdir(lowerCamelCase       ):
																					logger.error(F'Vocabulary path ({save_directory}) should be a directory'       )
																					return

														__snake_case	:    List[str]											=     os.path.join(
														    lowerCamelCase					,			(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["artists_file"]       )
														with open(lowerCamelCase					,			"w"					,			encoding="utf-8"       ) as f:
																					f.write(json.dumps(self.artists_encoder					,			ensure_ascii=lowerCamelCase       )       )

														__snake_case	:    Union[str, Any]											=     os.path.join(
														    lowerCamelCase					,			(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["genres_file"]       )
														with open(lowerCamelCase					,			"w"					,			encoding="utf-8"       ) as f:
																					f.write(json.dumps(self.genres_encoder					,			ensure_ascii=lowerCamelCase       )       )

														__snake_case	:    Union[str, Any]											=     os.path.join(
														    lowerCamelCase					,			(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["lyrics_file"]       )
														with open(lowerCamelCase					,			"w"					,			encoding="utf-8"       ) as f:
																					f.write(json.dumps(self.lyrics_encoder					,			ensure_ascii=lowerCamelCase       )       )

														return (artists_file, genres_file, lyrics_file)






							def 					__snake_case      (							self :						Tuple					,			lowerCamelCase :						Any					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						Optional[Any]       )			->					Union[str, Any]:
														__snake_case	:    Any											=     self.artists_decoder.get(lowerCamelCase       )
														__snake_case	:    Tuple											=     [self.genres_decoder.get(lowerCamelCase       ) for genre in genres_index]
														__snake_case	:    Optional[Any]											=     [self.lyrics_decoder.get(lowerCamelCase       ) for character in lyric_index]
														return artist, genres, lyrics





import importlib.metadata
import warnings
from copy import deepcopy

from packaging import version

from ..utils import logging
from .import_utils import is_accelerate_available, is_bitsandbytes_available


if is_bitsandbytes_available():
			import bitsandbytes as bnb
			import torch
			import torch.nn as nn

			from ..pytorch_utils import ConvaD

if is_accelerate_available():
			from accelerate import init_empty_weights
			from accelerate.utils import find_tied_parameters

_snake_case  :	Any			      =       logging.get_logger(__name__)







def        lowerCAmelCase_  (      __lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase=None							,			__lowerCamelCase=None			):
							# Recurse if needed
							if "." in tensor_name:
														__snake_case	:    Tuple											=     tensor_name.split("."			)
														for split in splits[:-1]:
																					__snake_case	:    List[str]											=     getattr(__lowerCamelCase							,			__lowerCamelCase			)
																					if new_module is None:
																												raise ValueError(F'{module} has no attribute {split}.'			)
																					__snake_case	:    Optional[int]											=     new_module
														__snake_case	:    Union[str, Any]											=     splits[-1]

							if tensor_name not in module._parameters and tensor_name not in module._buffers:
														raise ValueError(F'{module} does not have a parameter or a buffer named {tensor_name}.'			)
							__snake_case	:    Optional[int]											=     tensor_name in module._buffers
							__snake_case	:    List[str]											=     getattr(__lowerCamelCase							,			__lowerCamelCase			)

							if old_value.device == torch.device("meta"			) and device not in ["meta", torch.device("meta"			)] and value is None:
														raise ValueError(F'{tensor_name} is on the meta device, we need a `value` to put in on {device}.'			)

							__snake_case	:    List[Any]											=     False
							__snake_case	:    Optional[int]											=     False
							if is_buffer or not is_bitsandbytes_available():
														__snake_case	:    Dict											=     False
														__snake_case	:    Optional[int]											=     False
							else:
														__snake_case	:    Any											=     hasattr(bnb.nn							,			"Params4bit"			) and isinstance(module._parameters[tensor_name]							,			bnb.nn.Paramsabit			)
														__snake_case	:    Union[str, Any]											=     isinstance(module._parameters[tensor_name]							,			bnb.nn.IntaParams			)

							if is_abit or is_abit:
														__snake_case	:    Union[str, Any]											=     module._parameters[tensor_name]
														if param.device.type != "cuda":
																					if value is None:
																												__snake_case	:    Any											=     old_value.to(__lowerCamelCase			)
																					elif isinstance(__lowerCamelCase							,			torch.Tensor			):
																												__snake_case	:    int											=     value.to("cpu"			)
																												if value.dtype == torch.inta:
																																			__snake_case	:    Optional[int]											=     version.parse(importlib.metadata.version("bitsandbytes"			)			) > version.parse(
																																			    "0.37.2"			)
																																			if not is_abit_serializable:
																																										raise ValueError(
																																										    "Detected int8 weights but the version of bitsandbytes is not compatible with int8 serialization. "
																																										    "Make sure to download the latest `bitsandbytes` version. `pip install --upgrade bitsandbytes`."			)
																					else:
																												__snake_case	:    Optional[int]											=     torch.tensor(__lowerCamelCase							,			device="cpu"			)

																					# Support models using `Conv1D` in place of `nn.Linear` (e.g. gpt2) by transposing the weight matrix prior to quantization.
																					# Since weights are saved in the correct "orientation", we skip transposing when loading.
																					if issubclass(module.source_cls							,			__lowerCamelCase			) and fpaa_statistics is None:
																												__snake_case	:    List[Any]											=     new_value.T

																					__snake_case	:    Tuple											=     old_value.__dict__
																					if is_abit:
																												__snake_case	:    List[str]											=     bnb.nn.IntaParams(__lowerCamelCase							,			requires_grad=__lowerCamelCase							,			**__lowerCamelCase			).to(__lowerCamelCase			)
																					elif is_abit:
																												__snake_case	:    Optional[int]											=     bnb.nn.Paramsabit(__lowerCamelCase							,			requires_grad=__lowerCamelCase							,			**__lowerCamelCase			).to(__lowerCamelCase			)

																					__snake_case	:    Dict											=     new_value
																					if fpaa_statistics is not None:
																												setattr(module.weight							,			"SCB"							,			fpaa_statistics.to(__lowerCamelCase			)			)

							else:
														if value is None:
																					__snake_case	:    Tuple											=     old_value.to(__lowerCamelCase			)
														elif isinstance(__lowerCamelCase							,			torch.Tensor			):
																					__snake_case	:    Dict											=     value.to(__lowerCamelCase			)
														else:
																					__snake_case	:    List[Any]											=     torch.tensor(__lowerCamelCase							,			device=__lowerCamelCase			)

														if is_buffer:
																					__snake_case	:    Optional[Any]											=     new_value
														else:
																					__snake_case	:    int											=     nn.Parameter(__lowerCamelCase							,			requires_grad=old_value.requires_grad			)
																					__snake_case	:    Tuple											=     new_value







def        lowerCAmelCase_  (      __lowerCamelCase							,			__lowerCamelCase=None							,			__lowerCamelCase=None							,			__lowerCamelCase=None							,			__lowerCamelCase=False			):
							for name, module in model.named_children():
														if current_key_name is None:
																					__snake_case	:    List[Any]											=     []
														current_key_name.append(__lowerCamelCase			)

														if (isinstance(__lowerCamelCase							,			nn.Linear			) or isinstance(__lowerCamelCase							,			__lowerCamelCase			)) and name not in modules_to_not_convert:
																					# Check if the current key is not in the `modules_to_not_convert`
																					if not any(key in ".".join(__lowerCamelCase			) for key in modules_to_not_convert			):
																												with init_empty_weights():
																																			if isinstance(__lowerCamelCase							,			__lowerCamelCase			):
																																										__snake_case				,    __snake_case	:    Union[str, Any]											=     module.weight.shape
																																			else:
																																										__snake_case	:    List[Any]											=     module.in_features
																																										__snake_case	:    Tuple											=     module.out_features

																																			if quantization_config.quantization_method() == "llm_int8":
																																										__snake_case	:    Tuple											=     bnb.nn.LinearabitLt(
																																										    __lowerCamelCase							,			__lowerCamelCase							,			module.bias is not None							,			has_fpaa_weights=quantization_config.llm_inta_has_fpaa_weight							,			threshold=quantization_config.llm_inta_threshold							,			)
																																										__snake_case	:    List[str]											=     True
																																			else:
																																										if (
																																										    quantization_config.llm_inta_skip_modules is not None
																																										    and name in quantization_config.llm_inta_skip_modules
																																										):
																																																	pass
																																										else:
																																																	__snake_case	:    Optional[int]											=     bnb.nn.Linearabit(
																																																	    __lowerCamelCase							,			__lowerCamelCase							,			module.bias is not None							,			quantization_config.bnb_abit_compute_dtype							,			compress_statistics=quantization_config.bnb_abit_use_double_quant							,			quant_type=quantization_config.bnb_abit_quant_type							,			)
																																																	__snake_case	:    int											=     True
                    # Store the module class in case we need to transpose the weight later
																																			__snake_case	:    str											=     type(__lowerCamelCase			)
																																			# Force requires grad to False to avoid unexpected errors
																																			model._modules[name].requires_grad_(__lowerCamelCase			)
														if len(list(module.children()			)			) > 0:
																					__snake_case				,    __snake_case	:    Tuple											=     _replace_with_bnb_linear(
																					    __lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase							,			has_been_replaced=__lowerCamelCase							,			)
														# Remove the last key for recursion
														current_key_name.pop(-1			)
							return model, has_been_replaced







def        lowerCAmelCase_  (      __lowerCamelCase							,			__lowerCamelCase=None							,			__lowerCamelCase=None							,			__lowerCamelCase=None			):
							__snake_case	:    List[str]											=     ["lm_head"] if modules_to_not_convert is None else modules_to_not_convert
							__snake_case				,    __snake_case	:    Any											=     _replace_with_bnb_linear(
							    __lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase			)

							if not has_been_replaced:
														logger.warning(
														    "You are loading your model in 8bit or 4bit but no linear modules were found in your model."
														    " Please double check your model architecture, or submit an issue on github if you think this is"
														    " a bug."			)

							return model







def        lowerCAmelCase_  (      *__lowerCamelCase							,			**__lowerCamelCase			):
							warnings.warn(
							    "`replace_8bit_linear` will be deprecated in a future version, please use `replace_with_bnb_linear` instead"							,			__lowerCamelCase							,			)
							return replace_with_bnb_linear(*__lowerCamelCase							,			**__lowerCamelCase			)







def        lowerCAmelCase_  (      *__lowerCamelCase							,			**__lowerCamelCase			):
							warnings.warn(
							    "`set_module_8bit_tensor_to_device` will be deprecated in a future version, please use `set_module_quantized_tensor_to_device` instead"							,			__lowerCamelCase							,			)
							return set_module_quantized_tensor_to_device(*__lowerCamelCase							,			**__lowerCamelCase			)







def        lowerCAmelCase_  (      __lowerCamelCase			):
							__snake_case	:    Optional[int]											=     deepcopy(__lowerCamelCase			)  # this has 0 cost since it is done inside `init_empty_weights` context manager`
							tied_model.tie_weights()

							__snake_case	:    Any											=     find_tied_parameters(__lowerCamelCase			)
							# For compatibility with Accelerate < 0.18
							if isinstance(__lowerCamelCase							,			__lowerCamelCase			):
														__snake_case	:    Dict											=     sum(list(tied_params.values()			)							,			[]			) + list(tied_params.keys()			)
							else:
														__snake_case	:    Any											=     sum(__lowerCamelCase							,			[]			)
							__snake_case	:    Optional[int]											=     len(__lowerCamelCase			) > 0

							# Check if it is a base model
							__snake_case	:    Dict											=     not hasattr(__lowerCamelCase							,			model.base_model_prefix			)

							# Ignore this for base models (BertModel, GPT2Model, etc.)
							if (not has_tied_params) and is_base_model:
														return []

							# otherwise they have an attached head
							__snake_case	:    Optional[int]											=     list(model.named_children()			)
							__snake_case	:    List[str]											=     [list_modules[-1][0]]

							# add last module together with tied weights
							__snake_case	:    int											=     set(__lowerCamelCase			) - set(__lowerCamelCase			)
							__snake_case	:    Optional[Any]											=     list(set(__lowerCamelCase			)			) + list(__lowerCamelCase			)

							# remove ".weight" from the keys
							__snake_case	:    Optional[Any]											=     [".weight", ".bias"]
							__snake_case	:    Any											=     []
							for name in list_untouched:
														for name_to_remove in names_to_remove:
																					if name_to_remove in name:
																												__snake_case	:    Optional[int]											=     name.replace(__lowerCamelCase							,			""			)
														filtered_module_names.append(__lowerCamelCase			)

							return filtered_module_names

