





from math import ceil






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Any					,   UpperCamelCase__:							List[str]    ):
		SCREAMING_SNAKE_CASE__			=      list(range(0					,   UpperCamelCase__    )    )

		SCREAMING_SNAKE_CASE__			=      [item for sublist in list(device_map.values()    ) for item in sublist]

		# Duplicate check
		SCREAMING_SNAKE_CASE__			=      []
		for i in device_map_blocks:
				if device_map_blocks.count(UpperCamelCase__    ) > 1 and i not in duplicate_blocks:
						duplicate_blocks.append(UpperCamelCase__    )
    # Missing blocks
		SCREAMING_SNAKE_CASE__			=      [i for i in blocks if i not in device_map_blocks]
		SCREAMING_SNAKE_CASE__			=      [i for i in device_map_blocks if i not in blocks]

		if len(UpperCamelCase__    ) != 0:
				raise ValueError(
				    """Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device."""
				    """ These attention blocks were specified more than once: """ + str(UpperCamelCase__    )    )
		if len(UpperCamelCase__    ) != 0:
				raise ValueError(
				    """There are attention blocks for this model that are not specified in the device_map. Add these attention """
				    """blocks to a device on the device_map: """ + str(UpperCamelCase__    )    )
		if len(UpperCamelCase__    ) != 0:
				raise ValueError(
				    """The device_map contains more attention blocks than this model has. Remove these from the device_map:"""
				    + str(UpperCamelCase__    )    )






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Optional[int]					,   UpperCamelCase__:							Optional[Any]    ):
		SCREAMING_SNAKE_CASE__			=      list(range(UpperCamelCase__    )    )
		SCREAMING_SNAKE_CASE__			=      int(ceil(n_layers / len(UpperCamelCase__    )    )    )
		SCREAMING_SNAKE_CASE__			=      [layers[i : i + n_blocks] for i in range(0					,   UpperCamelCase__					,   UpperCamelCase__    )]

		return dict(zip(UpperCamelCase__					,   UpperCamelCase__    )    )






# Copyright 2023 The HuggingFace Team. 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.

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowerCamelCase   				=			{
    'configuration_xmod': [
        'XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'XmodConfig',
        'XmodOnnxConfig',
    ],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase   				=			[
	    'XMOD_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'XmodForCausalLM',
	    'XmodForMaskedLM',
	    'XmodForMultipleChoice',
	    'XmodForQuestionAnswering',
	    'XmodForSequenceClassification',
	    'XmodForTokenClassification',
	    'XmodModel',
	    'XmodPreTrainedModel',
	]

if TYPE_CHECKING:
	from .configuration_xmod import XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP, XmodConfig, XmodOnnxConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_xmod import (
		    XMOD_PRETRAINED_MODEL_ARCHIVE_LIST,
		    XmodForCausalLM,
		    XmodForMaskedLM,
		    XmodForMultipleChoice,
		    XmodForQuestionAnswering,
		    XmodForSequenceClassification,
		    XmodForTokenClassification,
		    XmodModel,
		    XmodPreTrainedModel,
		)

else:
	import sys

	_lowerCamelCase   				=			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)