



'''simple docstring'''





from typing import Optional

from torch import nn

from .transformer_ad import TransformeraDModel, TransformeraDModelOutput

class   _A   ( nn.Module	):


						'''simple docstring'''





						def __init__(	self	:							List[str]							,      lowerCamelCase	:							int = 16							,      lowerCamelCase	:							int = 88							,      lowerCamelCase	:							Optional[int] = None							,      lowerCamelCase	:							int = 1							,      lowerCamelCase	:							float = 0.0							,      lowerCamelCase	:							int = 32							,      lowerCamelCase	:							Optional[int] = None							,      lowerCamelCase	:							bool = False							,      lowerCamelCase	:							Optional[int] = None							,      lowerCamelCase	:							Optional[int] = None							,      lowerCamelCase	:							str = "geglu"							,      lowerCamelCase	:							Optional[int] = None							,      ):






							'''simple docstring'''



							super().__init__()
							__lowercase		       =			nn.ModuleList(
							    [
							        TransformeraDModel(
							            num_attention_heads=__UpperCamelCase							,      attention_head_dim=__UpperCamelCase							,      in_channels=__UpperCamelCase							,      num_layers=__UpperCamelCase							,      dropout=__UpperCamelCase							,      norm_num_groups=__UpperCamelCase							,      cross_attention_dim=__UpperCamelCase							,      attention_bias=__UpperCamelCase							,      sample_size=__UpperCamelCase							,      num_vector_embeds=__UpperCamelCase							,      activation_fn=__UpperCamelCase							,      num_embeds_ada_norm=__UpperCamelCase							,      )
							        for _ in range(2	)
							    ]	)

							# Variables that can be set by a pipeline:

							# The ratio of transformer1 to transformer2's output states to be combined during inference
							__lowercase		       =			0.5

							# The shape of `encoder_hidden_states` is expected to be
							# `(batch_size, condition_lengths[0]+condition_lengths[1], num_features)`
							__lowercase		       =			[77, 257]

							# Which transformer to use to encode which condition.
							# E.g. `(1, 0)` means that we'll use `transformers[1](conditions[0])` and `transformers[0](conditions[1])`
							__lowercase		       =			[1, 0]



						def     _snake_case	(	self	:							Optional[int]							,      lowerCamelCase	:							Any							,      lowerCamelCase	:							List[Any]							,      lowerCamelCase	:							Union[str, Any]=None							,      lowerCamelCase	:							Union[str, Any]=None							,      lowerCamelCase	:							Tuple=None							,      lowerCamelCase	:							bool = True							,      ):






							'''simple docstring'''



							__lowercase		       =			hidden_states

							__lowercase		       =			[]
							__lowercase		       =			0
							# attention_mask is not used yet
							for i in range(2	):
								# for each of the two transformers, pass the corresponding condition tokens
								__lowercase		       =			encoder_hidden_states[:, tokens_start : tokens_start + self.condition_lengths[i]]
								__lowercase		       =			self.transformer_index_for_condition[i]
								__lowercase		       =			self.transformers[transformer_index](
								    __UpperCamelCase							,      encoder_hidden_states=__UpperCamelCase							,      timestep=__UpperCamelCase							,      cross_attention_kwargs=__UpperCamelCase							,      return_dict=__UpperCamelCase							,      )[0]
								encoded_states.append(encoded_state - input_states	)
								tokens_start += self.condition_lengths[i]

							__lowercase		       =			encoded_states[0] * self.mix_ratio + encoded_states[1] * (1 - self.mix_ratio)
							__lowercase		       =			output_states + input_states

							if not return_dict:
								return (output_states,)

							return TransformeraDModelOutput(sample=__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


snake_case__					:     List[str]    		=   {
    """configuration_mgp_str""": ["""MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MgpstrConfig"""],
    """processing_mgp_str""": ["""MgpstrProcessor"""],
    """tokenization_mgp_str""": ["""MgpstrTokenizer"""],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	snake_case__					:     Dict    		=   [
	    """MGP_STR_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """MgpstrModel""",
	    """MgpstrPreTrainedModel""",
	    """MgpstrForSceneTextRecognition""",
	]

if TYPE_CHECKING:
	from .configuration_mgp_str import MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP, MgpstrConfig
	from .processing_mgp_str import MgpstrProcessor
	from .tokenization_mgp_str import MgpstrTokenizer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_mgp_str import (
		    MGP_STR_PRETRAINED_MODEL_ARCHIVE_LIST,
		    MgpstrForSceneTextRecognition,
		    MgpstrModel,
		    MgpstrPreTrainedModel,
		)
else:
	import sys

	snake_case__					:     Union[str, Any]    		=   _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



