
    $j%                        d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 ddZdd
Z	 ddddddddd dZed             Zeej        fd            Zd Zg dZdS )!    )annotationsN)contextmanager)isclassreturnstrc                    t          |           s| j        } | j        }||t          j        j        k    r| j        S |dz   | j        z   S )aI  
    Gives a full name (package_name.class_name) for a class / object in Python. Will
    be used to load the correct classes from JSON files

    Args:
        obj: The object for which to get the full name, e.g. an instance of a class or the class itself.

    Returns:
        str: The full name of the object.

    Example:
        >>> from sentence_transformers.sentence_transformer.losses import MultipleNegativesRankingLoss
        >>> from sentence_transformers import SentenceTransformer
        >>> from sentence_transformers.util import fullname
        >>> model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
        >>> loss = MultipleNegativesRankingLoss(model)
        >>> fullname(loss)
        'sentence_transformers.sentence_transformer.losses.multiple_negatives_ranking.MultipleNegativesRankingLoss'
    N.)r   	__class__
__module__r   __name__)objmodules     g/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/sentence_transformers/util/misc.pyfullnamer      sM    ( 3<< m^F~3=#;;;|C<#,&&    dotted_pathtypec                   	 |                      dd          \  }}n"# t          $ r |  d}t          |          w xY wt          j                    5  t          j        dt                     	 t          j        |           }n$# t          $ r t          j        |          }Y nw xY wddd           n# 1 swxY w Y   	 t          ||          S # t          $ r d| d| d}t          |          w xY w)	a}  
    Import a dotted module path and return the attribute/class designated by the
    last name in the path. Raise ImportError if the import failed.

    Args:
        dotted_path (str): The dotted module path.

    Returns:
        Any: The attribute/class designated by the last name in the path.

    Raises:
        ImportError: If the import failed.

    Example:
        >>> import_from_string('sentence_transformers.sentence_transformer.losses.multiple_negatives_ranking.MultipleNegativesRankingLoss')
        <class 'sentence_transformers.sentence_transformer.losses.multiple_negatives_ranking.MultipleNegativesRankingLoss'>
    r	      z  doesn't look like a module pathignoreNzModule "z" does not define a "z" attribute/class)rsplit
ValueErrorImportErrorwarningscatch_warningssimplefilterDeprecationWarning	importlibimport_module	ExceptiongetattrAttributeError)r   module_path
class_namemsgr   s        r   import_from_stringr&   (   sp   $"-"4"4S!"<"<ZZ   >>>#
 
	 	"	" : :h(:;;;	:,[99FF 	: 	: 	:,[99FFF	:	: : : : : : : : : : : : : : :vz***   XXX:XXX#sJ    ;B2-BB2B# B2"B##B22B69B6>C #C1F)trust_remote_coderevisioncode_revisiontokencache_folderlocal_files_only	class_refmodel_name_or_path
str | Noner'   boolr(   r)   r*   bool | str | Noner+   r,   c          	        |                      d          rt          |           S |Q|st          j                            |          r0ddlm} 	  || ||||||          S # t          t          f$ r Y nw xY wt          |           S )a  
    Resolve a module class reference to a class object.

    For class refs in the ``sentence_transformers.*`` namespace, this imports directly via
    :func:`import_from_string`. For other class refs (e.g. repository-local custom classes
    like ``modeling_my_model.CustomTransformer``), it first tries
    :func:`transformers.dynamic_module_utils.get_class_from_dynamic_module` to fetch the
    modeling file from the model directory, then falls back to :func:`import_from_string`
    if dynamic loading is not applicable or fails.

    Dynamic loading is attempted when ``trust_remote_code`` is set, or when
    ``model_name_or_path`` resolves to a local directory (i.e. the user already has the
    file on disk and is implicitly trusted).

    Args:
        class_ref: Dotted class path. Either a fully-qualified ``sentence_transformers.*``
            path or a repository-local reference like ``modeling_<name>.<ClassName>``.
        model_name_or_path: Hub repo id or local directory used to source repository-local
            modeling files. Required for dynamic loading.
        trust_remote_code: Whether to permit dynamic loading from an unverified Hub repo.
        revision: Hub revision to fetch the modeling file from.
        code_revision: Optional separate revision pinning for the modeling code (overrides
            ``revision`` when set).
        token: Hugging Face Hub authentication token. Required for fetching modeling files
            from private repositories.
        cache_folder: Optional override for the Hugging Face Hub cache directory.
        local_files_only: If True, only use cached files and never reach out to the Hub.

    Returns:
        The resolved class.
    zsentence_transformers.Nr   )get_class_from_dynamic_module)r(   r)   r*   	cache_dirr,   )	
startswithr&   ospathexists!transformers.dynamic_module_utilsr3   OSErrorr   )	r-   r.   r'   r(   r)   r*   r+   r,   r3   s	            r   import_module_classr;   O   s    T 455 -!),,,%+<%Oa@b@b%SSSSSS	00"!+&!1    $ 	 	 	D	 i(((s   A! !A54A5c               #     K   ddl m} m}m}  |            }	 |r
 |              dV  |r |             dS dS # |r |             w w xY w)zN
    A context manager that will disable caching in the datasets library.
    r   )disable_cachingenable_cachingis_caching_enabledN)datasetsr=   r>   r?   )r=   r>   r?   is_originally_enableds       r   disable_datasets_cachingrB      s      
 MLLLLLLLLL..00  	O  	N	 	  	N	s	   8 Ac              #     K   t           j        j        j        }t          j        |            	 dV  t          j        |           dS # t          j        |           w xY w)z
    A context manager that will prevent any logging messages
    triggered during the body from being processed.

    Args:
        highest_level: the maximum logging level allowed.
    N)loggingrootmanagerdisable)highest_levelprevious_levels     r   disable_loggingrJ      s_       \)1NOM"""('''''''''s   A Ac                   t          | dd          5 }t          j        |          }t          |          }d d d            n# 1 swxY w Y   t	          |          dk    rq|d                             |           t          | ddd          5 }t          j        |          }|                    |           d d d            n# 1 swxY w Y   dS dS )	N zutf-8)newlineencodingr   wTF)opencsvreaderlistlenextendwriter	writerows)csv_pathadditional_datafrS   rowsrW   s         r   append_to_last_rowr]      s@   	hW	5	5	5 AF||               4yy1}}R((( (Cg>>> 	#!Z]]FT"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# t5s#   $AA
A*CC	C	)Dzalbert-base-v1zalbert-base-v2zalbert-large-v1zalbert-large-v2zalbert-xlarge-v1zalbert-xlarge-v2zalbert-xxlarge-v1zalbert-xxlarge-v2zbert-base-cased-finetuned-mrpczbert-base-casedzbert-base-chinesezbert-base-german-casedzbert-base-german-dbmdz-casedzbert-base-german-dbmdz-uncasedzbert-base-multilingual-casedzbert-base-multilingual-uncasedzbert-base-uncasedz3bert-large-cased-whole-word-masking-finetuned-squadz#bert-large-cased-whole-word-maskingzbert-large-casedz5bert-large-uncased-whole-word-masking-finetuned-squadz%bert-large-uncased-whole-word-maskingzbert-large-uncasedzcamembert-basectrlz%distilbert-base-cased-distilled-squadzdistilbert-base-casedzdistilbert-base-german-casedz"distilbert-base-multilingual-casedz'distilbert-base-uncased-distilled-squadz/distilbert-base-uncased-finetuned-sst-2-englishzdistilbert-base-uncased
distilgpt2zdistilroberta-basez
gpt2-largezgpt2-mediumzgpt2-xlgpt2z
openai-gptzroberta-base-openai-detectorzroberta-basezroberta-large-mnlizroberta-large-openai-detectorzroberta-largezt5-11bzt5-3bzt5-basezt5-largezt5-smallztransfo-xl-wt103zxlm-clm-ende-1024zxlm-clm-enfr-1024zxlm-mlm-100-1280zxlm-mlm-17-1280zxlm-mlm-en-2048zxlm-mlm-ende-1024zxlm-mlm-enfr-1024zxlm-mlm-enro-1024zxlm-mlm-tlm-xnli15-1024zxlm-mlm-xnli15-1024zxlm-roberta-basez)xlm-roberta-large-finetuned-conll02-dutchz+xlm-roberta-large-finetuned-conll02-spanishz+xlm-roberta-large-finetuned-conll03-englishz*xlm-roberta-large-finetuned-conll03-germanzxlm-roberta-largezxlnet-base-casedzxlnet-large-cased)r   r   )r   r   r   r   )N)r-   r   r.   r/   r'   r0   r(   r/   r)   r/   r*   r1   r+   r/   r,   r0   r   r   )
__future__r   rR   r   rD   r6   r   
contextlibr   inspectr   r   r&   r;   rB   CRITICALrJ   r]   ORIGINAL_TRANSFORMER_MODELS r   r   <module>rg      s<   " " " " " " 



      				  % % % % % %      ' ' ' '8$ $ $ $R &*>) $ $##">) >) >) >) >) >)B   " ")"2 ( ( ( ("  (E E E   r   