
    #i݆                       d dl mZ d dlZd dlZd dlmZ 	 d dlmZ d dl
mZmZ d dlmZ d dlmZmZ d dlmZmZmZmZ d d	lmZ d d
lmZ d dlmZmZ  ej<                  e      Z  G d de      Z!e!Z"y# e$ r	 d dl	mZ Y cw xY w)    )annotationsN)Path)Self)Tensornn)logging)format_modalityinfer_batch_modality)MODALITY_TO_PROCESSOR_ARGModality	PairInputSingleInput)InputModule)Module)import_from_stringload_dir_pathc                      e Zd ZU ddhZg dZded<   dZ	 	 	 d	 	 	 	 	 	 	 	 	 d fdZedd       Z	d	 Z
	 d	 	 	 	 	 dd
ZdddZe	 	 d	 	 	 	 	 	 	 	 	 dd       Z	 	 d	 	 	 	 	 	 	 ddZddZddZd dZd!d"dZ	 	 	 d#	 	 	 	 	 	 	 d$dZe	 	 	 	 	 d%	 	 	 	 	 	 	 	 	 	 	 	 	 d&d       Zed        Zed d       Zej0                  d'd       Z xZS )(Routertaskmodality)default_routeallow_empty_keyroute_mappingsz	list[str]config_keyszrouter_config.jsonc                   t         |           |t        |      dk(  rt        d      |,||vr(t        d| dt	        |j                                      t        j                  |j                         D ci c]  \  }}|t        j                  |  c}}      | _
        |rG|j                         D ]4  \  \  }}}	|	|vst        d|	 dt	        |j                                       |r$|"t        t        |j                                     }|| _        || _        |rU|j                         D 
ci c]1  \  \  }}}
|t        |t               rt!        t#        |            n|f|
3 c}
}}| _        yi | _        yc c}}w c c}
}}w )a^4  
        This model allows creating flexible SentenceTransformer models that dynamically route inputs to different
        processing modules based on:

        1. Task type (e.g., "query" or "document") for asymmetric retrieval models
        2. Modality (e.g., "text", "image", or ("text", "image")) for crossmodal or multimodal models
        3. Combination of both for complex routing scenarios

        Tips:

        - The ``task`` argument in ``model.encode()`` specifies which route to use
        - ``model.encode_query()`` and ``model.encode_document()`` are convenient shorthands for ``task="query"`` and ``task="document"``
        - Modality is automatically inferred from input data (text strings, PIL Images, etc.)
        - You can override automatic inference by passing ``modality`` in ``model.encode()`` (and its variants) explicitly

        Route Priority:

        1. Exact match: ``(task, modality)`` - e.g., ``("query", "text")``
        2. Task with any modality: ``(task, None)`` - e.g., ``("query", None)``
        3. Any task with modality: ``(None, modality)`` - e.g., ``(None, "image")``
        4. Catch-all: ``(None, None)``
        5. Direct lookup by task name in ``sub_modules``
        6. Direct lookup by modality name in ``sub_modules``
        7. Fall back to ``default_route`` if set

        In the below examples, the ``Router`` model is used to create asymmetric models with different encoders for
        queries and documents. In these examples, the "query" route is efficient (e.g., using SparseStaticEmbedding),
        while the "document" route uses a more complex model (e.g. a Transformers module). This allows for efficient
        query encoding while still using a powerful document encoder, but the combinations are not limited to this.

        Example:
            ::

                from sentence_transformers import SentenceTransformer
                from sentence_transformers.sentence_transformer.modules import Router, Normalize

                # Use a regular SentenceTransformer for the document embeddings, and a static embedding model for the query embeddings
                document_embedder = SentenceTransformer("mixedbread-ai/mxbai-embed-large-v1")
                query_embedder = SentenceTransformer("sentence-transformers/static-retrieval-mrl-en-v1")
                router = Router.for_query_document(
                    query_modules=list(query_embedder.children()),
                    document_modules=list(document_embedder.children()),
                )
                normalize = Normalize()

                # Create an asymmetric model with different encoders for queries and documents
                model = SentenceTransformer(
                    modules=[router, normalize],
                )

                # ... requires more training to align the vector spaces

                # Use the query & document routes
                query_embedding = model.encode_query("What is the capital of France?")
                document_embedding = model.encode_document("Paris is the capital of France.")

            ::

                from sentence_transformers.sparse_encoder.modules import Router, SparseStaticEmbedding, SpladePooling, Transformer
                from sentence_transformers.sparse_encoder import SparseEncoder

                # Load an asymmetric model with different encoders for queries and documents
                doc_encoder = Transformer("opensearch-project/opensearch-neural-sparse-encoding-doc-v3-distill", transformer_task="fill-mask")
                router = Router.for_query_document(
                    query_modules=[
                        SparseStaticEmbedding.from_json(
                            "opensearch-project/opensearch-neural-sparse-encoding-doc-v3-distill",
                            tokenizer=doc_encoder.tokenizer,
                            frozen=True,
                        ),
                    ],
                    document_modules=[
                        doc_encoder,
                        SpladePooling(pooling_strategy="max", activation_function="log1p_relu"),
                    ],
                )

                model = SparseEncoder(modules=[router], similarity_fn_name="dot")

                query = "What's the weather in ny now?"
                document = "Currently New York is rainy."

                query_embed = model.encode_query(query)
                document_embed = model.encode_document(document)

                sim = model.similarity(query_embed, document_embed)
                print(f"Similarity: {sim}")

                # Visualize top tokens for each text
                top_k = 10
                print(f"Top tokens {top_k} for each text:")

                decoded_query = model.decode(query_embed, top_k=top_k)
                decoded_document = model.decode(document_embed)

                for i in range(min(top_k, len(decoded_query))):
                    query_token, query_score = decoded_query[i]
                    doc_score = next((score for token, score in decoded_document if token == query_token), 0)
                    if doc_score != 0:
                        print(f"Token: {query_token}, Query score: {query_score:.4f}, Document score: {doc_score:.4f}")

                '''
                Similarity: tensor([[11.1105]], device='cuda:0')
                Top tokens 10 for each text:
                Token: ny, Query score: 5.7729, Document score: 0.8049
                Token: weather, Query score: 4.5684, Document score: 0.9710
                Token: now, Query score: 3.5895, Document score: 0.4720
                Token: ?, Query score: 3.3313, Document score: 0.0286
                Token: what, Query score: 2.7699, Document score: 0.0787
                Token: in, Query score: 0.4989, Document score: 0.0417
                '''

            Multimodal Example:

            ::

                from PIL import Image
                from sentence_transformers import SentenceTransformer
                from sentence_transformers.sentence_transformer.modules import Dense, Pooling, Router, Transformer

                # Create separate encoders for different modalities
                text_encoder = Transformer("sentence-transformers/all-MiniLM-L6-v2")
                # Project to 768 dims to match image encoder
                text_dense = Dense(text_encoder.get_embedding_dimension(), 768, module_input_name="token_embeddings")
                image_encoder = Transformer(
                    "ModernVBERT/modernvbert",
                    model_kwargs={"trust_remote_code": True},
                    processor_kwargs={"trust_remote_code": True},
                    config_kwargs={"trust_remote_code": True},
                )
                pooling = Pooling(text_encoder.get_embedding_dimension())

                # Route based on modality
                router = Router(
                    sub_modules={
                        "text": [text_encoder, text_dense],
                        "image": [image_encoder],
                    },
                    route_mappings={
                        (None, "text"): "text",  # Any task with text goes to text encoder
                        (None, ("text", "image")): "image",  # Any task with text-image together goes to image encoder
                    },
                )

                model = SentenceTransformer(modules=[router, pooling])

                # Modality is automatically inferred
                text_embedding = model.encode("A photo of a cat")
                multimodal_embedding = model.encode({"text": "A photo of a <image>", "image": Image.open("cat.jpg")})

                # Compute the similarity; it'll be poor as the model hasn't yet been trained
                similarity = model.similarity(text_embedding, multimodal_embedding)

            Hybrid Asymmetric + Multimodal Example:

            ::

                from sentence_transformers import SentenceTransformer
                from sentence_transformers.sentence_transformer.modules import Router

                # Different encoders for query text, document text, and images
                router = Router(
                    sub_modules={
                        "query_text": [query_text_modules],
                        "doc_text": [document_text_modules],
                        "image": [image_modules],
                    },
                    route_mappings={
                        ("query", "text"): "query_text",        # Query text uses efficient encoder
                        ("document", "text"): "doc_text",       # Document text uses powerful encoder
                        (None, ("text", "image")): "image",     # Any text-image together goes to image encoder
                    },
                )

                model = SentenceTransformer(modules=[router])

                # Explicit task + automatic modality inference
                query_embedding = model.encode_query("Find images of cats")
                doc_embedding = model.encode_document("Article about cats")
                multimodal_embedding = model.encode({"text": "A photo of a cat", "image": Image.open("cat.jpg")})

        .. note::

            When training models with the :class:`~sentence_transformers.base.modules.Router` module, you must use the
            ``router_mapping`` argument in the :class:`~sentence_transformers.sentence_transformer.training_args.SentenceTransformerTrainingArguments`
            or :class:`~sentence_transformers.sparse_encoder.training_args.SparseEncoderTrainingArguments` to map the
            training dataset columns to the correct route ("query" or "document"). For example, if your training dataset(s)
            have ``["question", "positive", "negative"]`` columns, then you can use the following mapping::

                args = SparseEncoderTrainingArguments(
                    ...,
                    router_mapping={
                        "question": "query",
                        "positive": "document",
                        "negative": "document",
                    }
                )

            Additionally, it is common to use a different learning rate for the different routes. For this, you should
            use the ``learning_rate_mapping`` argument in the :class:`~sentence_transformers.sentence_transformer.training_args.SentenceTransformerTrainingArguments`
            or :class:`~sentence_transformers.sparse_encoder.training_args.SparseEncoderTrainingArguments` to map parameter patterns
            to their learning rates. For example, if you want to use a learning rate of ``1e-3`` for an SparseStaticEmbedding module and
            ``2e-5`` for the rest of the model, you can do this::

                args = SparseEncoderTrainingArguments(
                    ...,
                    learning_rate=2e-5,
                    learning_rate_mapping={
                        r"SparseStaticEmbedding\.*": 1e-3,
                    }
                )

        Args:
            sub_modules: Mapping of route keys to lists of modules. Each key corresponds to a specific route name
                (e.g., "text_query", "text_document", "image", "multimodal"). Each route contains a list of modules
                that will be applied sequentially when that route is selected.
            default_route: The default route to use if no task type or modality is specified. If None, an exception
                will be thrown if no task type is specified. If ``allow_empty_key`` is True, the first key in
                sub_modules will be used as the default route. Defaults to None.
            allow_empty_key: If True, allows the default route to be set to the first key in `sub_modules` if
                ``default_route`` is None. Defaults to True.
            route_mappings: Optional dictionary mapping (task, modality) tuples to route keys in sub_modules.
                This enables sophisticated routing logic based on combinations of task and modality:

                - Use ``None`` as a wildcard for either task or modality to create catch-all rules
                - Modality can be a string (e.g., ``"text"``, ``"image"``) or tuple (e.g., ``("text", "image")``)
                - Routes are resolved with a priority order (see **Route Resolution Priority** above)
                - All mapped routes must exist in ``sub_modules`` (validated at initialization)

                Example mappings::

                    {
                        # Exact matches (highest priority)
                        ("query", "text"): "efficient_text_encoder",
                        ("document", "text"): "powerful_text_encoder",

                        # Task with any modality
                        ("query", None): "query_encoder",  # All query tasks

                        # Any task with specific modality
                        (None, "image"): "image_encoder",  # All image inputs
                        (None, ("text", "image")): "multimodal_encoder",  # Multimodal inputs

                        # Catch-all (lowest priority)
                        (None, None): "default_encoder",
                    }

                If not provided, the router will attempt direct lookup using the task or modality as the route key
                in ``sub_modules``, then fall back to ``default_route``.
        Nr   z+The sub_modules dictionary cannot be empty.zDefault route 'z' not found in route keys: z$route_mappings contains mapping to 'z1' which is not in sub_modules. Available routes: )super__init__len
ValueErrorlistkeysr   
ModuleDictitems
Sequentialsub_modulesnextiterr   r   
isinstancetuplesortedr   )selfr%   r   r   r   
route_namemodulesr   r   target_routeroute	__class__s              z/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/sentence_transformers/base/modules/router.pyr   zRouter.__init__   s   B 	#k"2a"7JKK$k)I}o=XY]^i^n^n^pYqXrstt==LWL]L]L_`5HZZ00`

 2@2F2F2H . x,{2$>|n M--1+2B2B2D-E,FH  }4 k&6&6&8!9:M*.  0>/C/C/E +$T8e *Xu2MuVH-.S[\^cc 	  	' a(s   ;F
86Fc                    t        | j                  j                         D ch c]  }t        |d   ddg      D ]  }|  c}}t              S c c}}w )zBThe union of modalities supported by all sub-module input modules.r   
modalitiestext)key)r*   r%   valuesgetattrstr)r+   r/   r   s      r1   r3   zRouter.modalitiesA  sf      "--446 'a, I  
 
 	
s   A
c           	        | j                   j                         D cg c]  }d|	 }}| j                  j                         D ]]  \  }}||j                  d|       ||j                  dt	        |             =|j                  d|dt	        |      d       _ |syt        |      dk(  r|d   S d	j                  |d d
       dz   |d
   z   S c c}w )Nztask=z	modality=z(task=, modality=)    r   , z and )r%   r!   r   appendr	   r   join)r+   nameroutesr   r   s        r1   _get_routes_stringzRouter._get_routes_stringM  s    /3/?/?/D/D/FGtE$"GG"11668 	ZND(dX./	/(*C)FGHthk/(:S9VVWXY	Z [A!9yy%/&*<< Hs   Cc                   t        |t              rt        t        |            }||f| j                  v r| j                  ||f   S |df| j                  v r| j                  |df   S d|f| j                  v r| j                  d|f   S d| j                  v r| j                  d   S |r|| j                  v r|S |r|| j                  v r|S |t        d| d| j                                y)a/  
        Resolve the route key based on task and modality.

        Args:
            task: The task type (e.g., "query", "document")
            modality: The modality (e.g., "text", "image", ("text", "image"))

        Returns:
            The resolved route key, or None if no route is found
        NNNzNo route found for task type 'z'. Available routes: )r(   r)   r*   r   r%   r   rD   )r+   r   r   s      r1   _resolve_route_namezRouter._resolve_route_name]  s    h&VH-.H (t222&&h'788 $<4...&&d|44 (t222&&h'788 4...&&|44 DD,,,K D$4$44O=dVCXY]YpYpYrXstuu     c           	     x   | j                  ||      }|| j                  }|V| j                  rt        d      |t	        |      nd }d|d|d}|d| j                          dz  }|dz  }t        |      || j                  vr2t        d| d	t        | j                  j                                      |S )
Nr   r   zvYou must provide a `router_mapping` argument on the training arguments, or set a default route in the `Router` module.z#Could not determine route for task=r:   z. zAvailable routes: zgConsider specifying the `task` parameter in `model.encode`, or setting a default route in the `Router`.zResolved route 'z6' not found in sub_modules. Available submodule keys: )	rG   r   trainingr   r	   rD   r%   r    r!   )r+   r   r   r/   modality_display	error_msgs         r1   _resolve_routezRouter._resolve_route  s    ((dX(F =&&E =}} E 
 =E<Px8VZ=dX[QaPddfgI-d.E.E.G-HKKI  C  CIY''((("5')_`deieueuezeze|`}_~  rH   c                     | ||d||      S )a  
        Creates a Router model specifically for query and document modules, allowing convenient usage via `model.encode_query`
        and `model.encode_document`.

        Args:
            query_modules: List of modules to be applied for the "query" task type.
            document_modules: List of modules to be applied for the "document" task type.
            default_route: The default route to use if no task type is specified. If None, an exception will be thrown
                if no task type is specified. If ``allow_empty_key`` is True, the first key in sub_modules will be used as
                the default route. Defaults to "document".
            allow_empty_key: If True, allows the default route to be set to the first key in `sub_modules` if
                ``default_route`` is None. Defaults to True.

        Returns:
            Router: An instance of the Router model with the specified query and document modules.
        )querydocument)r%   r   r    )clsquery_modulesdocument_modulesr   r   s        r1   for_query_documentzRouter.for_query_document  s     0 "/=MN'+
 	
rH   c           	     P   ||j                  dd      }||j                  dd      }| j                  ||      }||d<   ||d<   | j                  |   D ]H  }|j                         D ci c]"  \  }}t	        |d      r||j
                  v r||$ }	}} ||fi |	}J |S c c}}w )a  Route ``features`` through the resolved sub-module pipeline.

        Resolves the route from ``task`` and ``modality`` (falling back to values stored in
        ``features`` if not provided), then sequentially applies all modules in the matched route.

        Args:
            features: Input features dictionary (e.g. from :meth:`preprocess`).
            task: Task type used for routing (e.g. ``"query"``, ``"document"``).
                Falls back to ``features["task"]`` if not provided.
            modality: Modality used for routing (e.g. ``"text"``, ``"image"``).
                Falls back to ``features["modality"]`` if not provided.
            **kwargs: Extra keyword arguments forwarded to each sub-module's ``forward``
                (filtered by each module's ``forward_kwargs``).

        Returns:
            The features dictionary after passing through all modules in the resolved route.
        Nr   r   rJ   forward_kwargs)getrN   r%   r#   hasattrrX   )
r+   featuresr   r   kwargsr/   moduler5   valuemodule_kwargss
             r1   forwardzRouter.forward  s    2 <<<-D ||J5H ###A v%z&&u- 	9F #),,.C6#34@U@U9U U
M 
 h8-8H	9 s   +'B"c                @    t         j                  j                  |       S N)r   r   __repr__)r+   s    r1   rc   zRouter.__repr__  s     yy!!$''rH   c                    g }| j                   |j                  d| j                          | j                  r|j                  d| j                          dj                  |      S )Nzdefault_route=zroute_mappings=r>   )r   r@   r   rA   )r+   partss     r1   
extra_reprzRouter.extra_repr  s_    )LL>$*<*<)?@ALL?4+>+>*?@AyyrH   c           
     T   g }| j                   j                         D ]I  }t        |      D ]9  }dD ]0  }t        ||      s|j	                   t        ||                     n 9 I K |sy t        t        |            dkD  r"t        j                  dt        |       d       |d   S )N)get_embedding_dimension get_sentence_embedding_dimensionget_word_embedding_dimensionr=   z7Different embedding dimensions detected across routes: z. Using the first value.r   )
r%   r6   reversedrZ   r@   r7   r   setloggerwarning_once)r+   dimsr%   r]   rB   s        r1   rh   zRouter.get_embedding_dimension  s    ++224 	K";/  	D
 vt,$9GFD$9$;<	 	 s4y>AI#d)Tlm AwrH   c           	        i }i }i }| j                   j                         D ]  \  }}g ||<   t        |      D ]k  \  }	}
| d|	 dt        |
      j                   }|
||<   t        |
      j
                   dt        |
      j                   ||<   ||   j                  |       m  |j                         D ][  \  }}
t        j                  j                  |t        |            }t        j                  |d       	  |
j                  |fd|i| ] | j                         }d|v r8|d   r3|d   j                         D ci c]  \  }}t        |      | c}}|d<   t        t        j                  j                  || j                         dd	      5 }t#        j$                  |||d
|d       d d d        y # t        $ r |
j                  |       Y #w xY wc c}}w # 1 sw Y   y xY w)N_.T)exist_oksafe_serializationr   wutf8)encoding)types	structure
parameters   )indent)r%   r#   	enumeratetype__name__
__module__r@   ospathrA   r8   makedirssave	TypeErrorget_config_dictopenconfig_file_namejsondump)r+   output_pathrt   r\   model_lookupmodel_typesmodel_structurerB   models
module_idxmodelmodel_id
model_pathconfig_dictr5   r^   fOuts                    r1   r   zRouter.save  s    ,,224 	7LD&$&OD!%.v%6 7!
E"V1ZL$u+2F2F1GH).X&+/;+A+A*B!DKDXDXCY(ZH%%,,X6	7	7  ,113 	'OHek3x=AJKK
T2'

:W:LWPVW		' **,{*{;K/LOZ[kOlOrOrOt,ueSXu_,uK()"'',,{D,A,ABCRXY 		]aII(!0"-
 		 		  '

:&' -v		 		s$   >F=GG$=GG$G-c                   |rt        |d   t              ro|mt        d |D              }|t        t        j                               z  s;t        |      dkD  rt        d      |j                         }|D cg c]  }||   	 }}||r	 t        || j                        }| j                  ||      }| j                  |   d   }	 |	j                  |fd|i|}
||
d<   |||
d	<   |
S c c}w # t        t        f$ r Y ^w xY w)
a  Resolve the route from ``task`` and ``modality``, then delegate preprocessing to the
        first module of the matched route. The returned dictionary includes ``"task"`` and (if
        available) ``"modality"`` keys so that :meth:`forward` can route without re-inference.
        r   c              3  J   K   | ]  }|j                         D ]  }|   y wrb   )r!   ).0r4   r5   s      r1   	<genexpr>z$Router.preprocess.<locals>.<genexpr>Q  s"     JDdiikJsCJCJs   !#r=   zYou cannot pass a list of dictionaries with different task types. Please ensure all dictionaries have the same task type key, or pass non-dictionary inputs while providing the `task` argument.)supported_modalitiesrJ   promptr   r   )r(   dictrl   r   r!   r   r   popr
   r3   r   rN   r%   
preprocess)r+   inputsr   r   r   r\   	dict_keyssampler/   input_module	tokenizeds              r1   r   zRouter.preprocessB  s&    jD1dlJFJJI$=$B$B$D EEy>A%$?  !}}5;<6&,<< /T__] ###A''.q1+L++FL6LVL	 	&$,Ij!% = 	* s   7C)
C. .D ?D c           
     T   ||||d} | j                   d||d|}	|	s | j                   d|d|d|}	i }
|	d   j                         D ]E  \  }}t        |      }	  |j                  |fdt	        ||      j                         i||}||
|<   G i }|	d   j                         D ](  \  }}g ||<   |D ]  }||   j                  |
|           * |	d   j                         }d	|v rB|d	   r=i }|d	   j                         D ]   \  }}	 d
d l
}|j                  |      }|||<   " ||d	<    | |fi |}|S # t        $ r: t        d|t	        ||      j                         d|}|j                  |      }Y w xY w# t        t        f$ r t        j                  d| d       Y w xY w)N)tokencache_folderrevisionlocal_files_only)model_name_or_path	subfolderzconfig.json)r   config_filenamer   rx   r   ry   rz   r   r   z#Could not parse route_mapping key: z. Skipping.rR   )load_configr#   r   loadr   as_posixr   r   r@   copyastliteral_evalr   SyntaxErrorrm   warning)rS   r   r   r   r   r   r   r\   
hub_kwargsconfigr-   r   
model_typemodule_classr]   
local_pathr   key_namemodels_listrz   r   key_strr^   r   	key_tupler   s                             r1   r   zRouter.loadp  sL    (  0	

 !j4FR[j_ij$S__ #5}`imwF $*7O$9$9$; 	' Hj#5j#AL7***&26y(2K2T2T2VZdhn !'GH	' %+K%8%>%>%@ 	D!Hk(*OH%' D)001BCD	D L)..0
z)j9I.JN",-=">"D"D"F 	__ # 0 0 9I05N9-	_ ,:J'(O2z2=  7* '9T)U]E^EgEgEimw
 &**:6	72 #K0 _NN%H	Q\#]^_s%   /D6
E<6A E98E9<(F'&F'c                    | j                   j                         D ].  }|d   }t        |d      s|j                  "|j                  c S  y )Nr   	tokenizer)r%   r6   rZ   r   )r+   r%   r   s      r1   r   zRouter.tokenizer  sQ      ++224 	.K(3AL|[1l6L6L6X#---	. rH   c                H   t               }| j                  j                         D ]7  }|d   }|st        |d      s|j                  x}s'|j                  |       9 |sy t        |      dk(  r|j                         S t        j                  d| d       t        |      S )Nr   max_seq_lengthr=   z$Different max_seq_lengths detected: z. Using the maximum value.)rl   r%   r6   rZ   r   addr   r   rm   rn   max)r+   max_seq_lengthsr-   r   r   s        r1   r   zRouter.max_seq_length  s     %''..0 	8G(/
L7<1AB%1%@%@@>@#''7		8 !Q&"&&(("FFWWq rs''rH   c                   g }| j                   j                         D ])  \  }}|s	t        |d   d      s|j                  |       + t	        |      dk(  rt
        j                  d       y |D ]  }| j                   |   d   }||_         y )Nr   r   z2No modules have a max_seq_length attribute to set.)r%   r#   rZ   r@   r   rm   r   r   )r+   r^   has_max_seq_length_keysr5   r   r   s         r1   r   zRouter.max_seq_length  s     #%++113 	4KC'&)-=>'..s3	4 &'1,NNOP* 	0C(,(8(8(=a(@L*/L'	0rH   )NTN)
r%   zdict[str, list[Module]]r   
str | Noner   boolr   zAdict[tuple[str | None, str | tuple[str, ...] | None], str] | NonereturnNone)r   zlist[Modality]rF   )r   r   r   str | tuple[str, ...] | Noner   r   )rQ   T)
rT   list[Module]rU   r   r   r   r   r   r   r   )r[   dict[str, Tensor]r   r   r   r   r   r   )r   r8   )r   z
int | None)T)r   r8   rt   r   )NNN)r   zlist[SingleInput | PairInput]r   r   r   r   r   zModality | None)r<   NNNF)r   r8   r   r8   r   zbool | str | Noner   r   r   r   r   r   r   r   )r   r   )r   r   __qualname__rX   r   __annotations__r   r   propertyr3   rD   rG   rN   classmethodrV   r`   rc   rf   rh   r   r   r   r   r   setter__classcell__)r0   s   @r1   r   r      s!   j)NSKS+
 %) $\`b
,b
 "b
 	b

 Zb
 
b
H	 	
 	
=" QU--1M-	-^8 
 %/ $
#
 '
 "	

 
 

 
@  15	.#. . /	. 
.`(
 0%T "$(,-, , 	,
 ",\  #'#'#!&;; ; !	;
 !; ; ; 
; ;z   ( ($ 0 0rH   r   )#
__future__r   r   r   pathlibr   typingr   ImportErrortyping_extensionstorchr   r   transformers.utilsr   #sentence_transformers.base.modalityr	   r
   )sentence_transformers.base.modality_typesr   r   r   r   /sentence_transformers.base.modules.input_moduler   )sentence_transformers.base.modules.moduler   sentence_transformers.utilr   r   
get_loggerr   rm   r   AsymrR   rH   r1   <module>r      sp    "  	 '  & U q q G < H			H	%@0[ @0H g  '&'s   A2 2B ?B 