
    9i.                     z    S SK r S SKrS SKJr  S SKJr  \R                  " 5       r " S S\5      r " S S\5      r	g)    N)PretrainedConfig)loggerc                      ^  \ rS rSrSr                        SU 4S jjr\S 5       r\S 5       rS r	S r
S rS	 rS
rU =r$ )PlugNLUConfig   plugNLUc                 \  > [         TU ]  " SSU0UD6  Xl        X l        X0l        X@l        XPl        Xpl        X`l        Xl	        Xl
        Xl        Xl        Xl        Xl        Xl        Xl        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        g Nlayer_norm_eps )super__init__
vocab_sizeoriginal_vocab_sizehidden_sizenum_hidden_layersnum_attention_heads
hidden_actintermediate_sizehidden_dropout_probattention_probs_dropout_probmax_position_embeddingstype_vocab_sizeinitializer_rangelr_decay_styleweight_decay	clip_gradwarmuppre_lnfp16fp32_layernormfp32_embeddinglayernorm_epsilonfp32_tokentypesdec_hidden_layersattn_separate)selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r#   r%   r&   kwargs	__class__s                             h/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/models/nlp/plug/configuration.pyr   PlugNLUConfig.__init__   s    4 	D(9DVD$#6 &!2#6 $!2#6 ,H)'>$.!2,("	,,!2.!2*    c                 h    [        5       nUR                  5        H  u  p4XBR                  U'   M     U$ )zAConstructs a `BertConfig` from a Python dictionary of parameters.)r   items__dict__)clsjson_objectconfigkeyvalues        r*   	from_dictPlugNLUConfig.from_dictS   s1     %++-JC#(OOC  .r,   c                     [        USSS9 nUR                  5       nSSS5        U R                  [        R                  " W5      5      $ ! , (       d  f       N3= f)z9Constructs a `BertConfig` from a json file of parameters.rzutf-8)encodingN)openreadr5   jsonloads)r0   	json_filereadertexts       r*   from_json_filePlugNLUConfig.from_json_file[   sC     )S73v;;=D 4}}TZZ-.. 43s   A


Ac                     U R                   R                  5       nUR                   R                  5        H  u  p4X2;   a  M  X@R                   U'   M     U $ )z;merge values a `BertConfig` from a json file of parameters.)r/   keysr.   )r'   args
local_keysr3   r4   s        r*   
merge_argsPlugNLUConfig.merge_argsb   sI    ]]'')
----/JC !&MM# 0 r,   c                 4    [        U R                  5       5      $ )N)strto_json_stringr'   s    r*   __repr__PlugNLUConfig.__repr__k   s    4&&())r,   c                 F    [         R                  " U R                  5      nU$ )z0Serializes this instance to a Python dictionary.)copydeepcopyr/   )r'   outputs     r*   to_dictPlugNLUConfig.to_dictn   s    t}}-r,   c                 P    [         R                  " U R                  5       SSS9S-   $ )z*Serializes this instance to a JSON string.   T)indent	sort_keys
)r<   dumpsrS   rL   s    r*   rK   PlugNLUConfig.to_json_strings   s     zz$,,.dCdJJr,   )r   r&   r   r%   r    r"   r!   r$   r   r   r   r   r   r#   r   r   r   r   r   r   r   r   r   r   ) T  R               gelu皙?rc         hn|?linear{Gz?      ?g镲?TTTFFgh㈵>   F)__name__
__module____qualname____firstlineno__
model_typer   classmethodr5   rA   rG   rM   rS   rK   __static_attributes____classcell__r)   s   @r*   r   r      s    J "%*!#%%(#("%(.1)-!"#* (" $ %!&#'#$$13+j   / /*
K Kr,   r   c                   d   ^  \ rS rSrSrSr                        SU 4S jjrSrU =r$ )PlugNLGConfigx   ap  
This is the configuration class to store the configuration of a [`PlugModel`]. It is used to instantiate a
PLUG understanding model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the PLUG
[PLUG](https://modelscope.cn/models/damo/nlp_plug_text-generation_27B/summary) architecture.

Configuration objects inherit from [`PlugNLUConfig`] and can be used to control the model outputs. Read the
documentation from [`PlugNLUConfig`] for more information.

Args:
    vocab_size (`int`, *optional*, defaults to 21504):
        Padded vocabulary size of the PLUG model for vocab tensor parallel. Defines the number of different tokens
        that can be represented by the `inputs_ids` passed when calling [`PlugModel`].
    original_vocab_size (`int`, *optional*, defaults to 21128):
        True vocabulary size of the PLUG model. Defines the number of different tokens that can be represented.
    hidden_size (`int`, *optional*, defaults to 8192):
        Dimensionality of the encoder layers and the pooler layer.
    num_hidden_layers (`int`, *optional*, defaults to 24):
        Number of hidden layers in the Transformer encoder.
    dec_hidden_layers (`int`, *optional*, defaults to 6):
        Number of hidden layers in the Transformer decoder.
    num_attention_heads (`int`, *optional*, defaults to 128):
        Number of attention heads for each attention layer in the Transformer encoder.
    intermediate_size (`int`, *optional*, defaults to 32768):
        Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
    hidden_act (`str`, *optional*, defaults to `"gelu"`):
        The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
        `"relu"`, `"selu"` and `"gelu_new"` are supported.
    hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
        The dropout ratio for all fully connected layers in the embeddings, encoder, and pooler.
    attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
        The dropout ratio for the Transformer Attention.
    max_position_embeddings (`int`, *optional*, defaults to 2048):
        The maximum sequence length that this model might ever be used with. Typically set this to something large
        just in case (e.g., 512 or 1024 or 2048).
    type_vocab_size (`int`, *optional*, defaults to 3):
        The vocabulary size of the `token_type_ids` passed when calling [`PlugModel`].
    initializer_range (`float`, *optional*, defaults to 0.00707):
        The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
    lr_decay_style (`str`, *optional*, defaults to 'linear'):
        The decay style of learning rate during fine-tunining. If string, `"linear"`, `"cosine"`, `"exponential"`,
        `"constant"`, `"None"` are supported.
    weight_decay (`float`, *optional*, defaults to 1e-2):
        Decoupled weight decay to apply.
    clip_grad (`float`, *optional*, defaults to 1.0):
        Maximum gradient norm for gradient clipping.
    warmup (`float`, *optional*, defaults to 0.01):
        Ratio of total training steps used for a linear warmup from 0 to `learning_rate`.
    pre_ln (`boolean`, *optional*, defaults to `True`):
        Whether or not to apply LayerNorm to the input instead of the output in the blocks.
    fp16 (`boolean`, *optional*, defaults to `True`):
        Whether to use fp16 16-bit (mixed) precision training instead of 32-bit training.
    fp32_layernorm (`boolean`, *optional*, defaults to `True`):
        Whether to use fp32 32-bit precision LayerNorm training while the argument `fp16` set to `True`.
    fp32_embedding (`boolean`, *optional*, defaults to `False`):
        Whether to use fp32 32-bit precision Embedding training while the argument `fp16` set to `True`.
    fp32_tokentypes (`boolean`, *optional*, defaults to `False`):
        Whether to use fp32 32-bit precision token types training while the argument `fp16` set to `True`.
    layernorm_epsilon (`float`, *optional*, defaults to 1e-5):
        The epsilon to use in the layer normalization layers.
    attn_separate (`boolean`, *optional*, defaults to `False`):
        Whether or not to separate query-key-value to query, key, value in the Attention.

Example:

>>> # The PLUG model has 27B parameters and usually need to run on multiple GPUs. The example given
>>> # here only initializes a slice of the model on a single GPU.
>>> # Check out the [`~DistributedPipeline.__init__`] method to initialize entire PLUG model.
>>> from modelscope.models.nlp.plug import PlugNLGConfig, PlugModel

>>> # Initializing a Plug configuration
>>> configuration = PlugNLGConfig()

>>> # Initializing a model from the configuration
>>> model = PlugModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
plugNLGc                 P  > [         TU ]  " SSU0UD6  Xl        X0l        X@l        X`l        Xl        Xpl        Xl        Xl	        Xl
        Xl        Xl        Xl        Xl        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        XPl        UU l        g r
   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   )r'   r   r   r   r   r%   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r#   r&   r(   r)   s                             r*   r   PlugNLGConfig.__init__   s    4 	D(9DVD$&!2#6 $!2#6 ,H)'>$.!2,("	,,!2.!2*r,   )r   r&   r   r%   r    r"   r!   r$   r   r   r   r   r   r#   r   r   r   r   r   r   r   r   r   )r\   r]   r^   r_   rj   r`   ra   rb   rc   rc   rd   re   rf   rg   rh   ri   rh   TTTFFg-q=F)	rk   rl   rm   rn   __doc__ro   r   rq   rr   rs   s   @r*   ru   ru   x   se    N` J "%*!#%#$%(#("%(.1)-!"#* (" $ %!&#($12+ 2+r,   ru   )
rP   r<   transformersr   modelscope.utilsr   logging
get_loggerr   ru   r   r,   r*   <module>r      sA   "   ) .				ZK$ ZKzE+M E+r,   