
    fTh,                     J   S SK r S SKrS SKrS SKJr  S SKJrJrJrJ	r	J
r
  S SKrSSKJrJrJrJr  SSKJr  \" S5      R)                  5       S-  r/ S	QrS
SSSS.rS1rS1rSSSSSS.r\R6                  " S5      r " S S5      r " S S5      r " S S5      r " S S5      r 1 S kr!S! r"S" r#S# r$S$ r%S% r&S?S& jr'S'\\(\\)   4   4S( jr*S) r+S*\S+\,S'\-4S, jr.S- r/S.\	\)\\)   4   S'\-4S/ jr0S0 r1S@S1 jr2S2 r3S3 r4S4 r5S5 r6S6 r7S7 r8S8 r9S9 r:S: r;SAS; jr<SBS< jr=SCSSSS=.S> jjr>g)D    N)Path)ListOptionalTupleUnionget_args   )MODELS_TO_PIPELINE#PIPELINE_TASKS_TO_SAMPLE_DOCSTRINGSPT_SAMPLE_DOCSTRINGS_prepare_output_docstrings)ModelOutputsrctransformers)zconfiguration_*.pyzmodeling_*.pyztokenization_*.pyzprocessing_*.pyzimage_processing_*_fast.pyzimage_processing_*.pyzfeature_extractor_*.py)image_processing_autoIMAGE_PROCESSOR_MAPPING_NAMES)feature_extraction_autoFEATURE_EXTRACTOR_MAPPING_NAMES)processing_autoPROCESSOR_MAPPING_NAMES)configuration_autoCONFIG_MAPPING_NAMES)image_processor_classfeature_extractor_classprocessor_classconfig_class
preprocessImageProcessorFastOpenAIGPTConfigXCLIPConfigKosmos2ConfigDonutSwinConfig	EsmConfig)openaizx-clipkosmos2donutesmfoldz*\[(.+?)\]\((https://huggingface\.co/.+?)\)c                       \ rS rSrSSS.rSSS.rSSS.rSSS.rSSS.rS	SS.r	S
SS.r
SSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSrg)ImageProcessorArgsH   z
    Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
    passing in images with pixel values between 0 and 1, set `do_rescale=False`.
    Ndescriptionshapez
    Video to preprocess. Expects a single or batch of videos with pixel values ranging from 0 to 255. If
    passing in videos with pixel values between 0 and 1, set `do_rescale=False`.
    z&
    Whether to resize the image.
    z>
    Describes the maximum input dimensions to the model.
    zP
    Whether to default to a square image when resizing, if size is an int.
    z
    Resampling filter to use if resizing the image. This can be one of the enum `PILImageResampling`. Only
    has an effect if `do_resize` is set to `True`.
    z+
    Whether to center crop the image.
    z@
    Size of the output image after applying `center_crop`.
    z'
    Whether to rescale the image.
    zR
    Rescale factor to rescale the image by if `do_rescale` is set to `True`.
    z)
    Whether to normalize the image.
    ze
    Image mean to use for normalization. Only has an effect if `do_normalize` is set to `True`.
    zw
    Image standard deviation to use for normalization. Only has an effect if `do_normalize` is set to
    `True`.
    z.
    Whether to convert the image to RGB.
    zU
    Returns stacked tensors if set to `pt, otherwise returns a list of tensors.
    zc
    Only `ChannelDimension.FIRST` is supported. Added for compatibility with slow processors.
    a  
    The channel dimension format for the input image. If unset, the channel dimension format is inferred
    from the input image. Can be one of:
    - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
    - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
    - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
    zf
    The device to process the images on. If unset, the device is inferred from the input images.
     )__name__
__module____qualname____firstlineno__imagesvideos	do_resizesizedefault_to_squareresampledo_center_crop	crop_size
do_rescalerescale_factordo_normalize
image_mean	image_stddo_convert_rgbreturn_tensorsdata_formatinput_data_formatdevice__static_attributes__r.       S/var/www/auris/envauris/lib/python3.13/site-packages/transformers/utils/args_doc.pyr)   r)   H   s6    F F 	I 	D 	 H 	N 	I 	J 	N 	L 	J I 	N 	N 	K 	 	FrF   r)   c                      \ rS rSrSSS.rSSS.rSSS.rSSS.rS	SS.rS
SS.r	SSS.r
SSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rSSS.rS SS.rS!S"S.rS#SS.rS$SS.rS%SS.rS&SS.rS'S(S.rS)S(S.r S*SS.r!S+SS.r"S,SS.r#S-S.S.r$S/SS.r%S0SS.r&S1S2S.r'S3S4S.r(S5r)g)6	ModelArgs   a7  
    Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
    config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
    (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
    z(of shape `(batch_size, sequence_length)`r+   aC  
    Calculate logits for the last `num_logits_to_keep` tokens. If `0`, calculate logits for all
    `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
    token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
    Na"  
    Indices of input sequence tokens in the vocabulary. Padding will be ignored by default.

    Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
    [`PreTrainedTokenizer.__call__`] for details.

    [What are input IDs?](../glossary#input-ids)
    a  
    Float values of input raw speech waveform. Values can be obtained by loading a `.flac` or `.wav` audio file
    into an array of type `List[float]` or a `numpy.ndarray`, *e.g.* via the soundfile library (`pip install
    soundfile`). To prepare the array into `input_values`, the [`AutoProcessor`] should be used for padding and
    conversion into a tensor of type `torch.FloatTensor`. See [`{processor_class}.__call__`] for details.
    z
    Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

    - 1 for tokens that are **not masked**,
    - 0 for tokens that are **masked**.

    [What are attention masks?](../glossary#attention-mask)
    z
    Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

    - 1 indicates the head is **not masked**,
    - 0 indicates the head is **masked**.
    z4of shape `(num_heads,)` or `(num_layers, num_heads)`z
    Mask to nullify selected heads of the cross-attention modules. Mask values selected in `[0, 1]`:

    - 1 indicates the head is **not masked**,
    - 0 indicates the head is **masked**.
    z"of shape `(num_layers, num_heads)`z
    Mask to avoid performing attention on certain token indices. By default, a causal mask will be used, to
    make sure the model can only look at previous inputs in order to predict the future.
    z/of shape `(batch_size, target_sequence_length)`z
    Mask to nullify selected heads of the attention modules in the decoder. Mask values selected in `[0, 1]`:

    - 1 indicates the head is **not masked**,
    - 0 indicates the head is **masked**.
    z4of shape `(decoder_layers, decoder_attention_heads)`z
    Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
    if the model is configured as a decoder.
    z5of shape `(batch_size, sequence_length, hidden_size)`a,  
    Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
    the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:

    - 1 for tokens that are **not masked**,
    - 0 for tokens that are **masked**.
    a  
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0, 1]`:

    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.

    [What are token type IDs?](../glossary#token-type-ids)
    z
    Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0, config.n_positions - 1]`.

    [What are position IDs?](../glossary#position-ids)
    a~  
    Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
    blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
    returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.

    Two formats are allowed:
        - a [`~cache_utils.Cache`] instance, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache);
        - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
        shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
        cache format.

    The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
    legacy cache format will be returned.

    If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
    have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
    of shape `(batch_size, sequence_length)`.
    z2
    deprecated in favor of `past_key_values`
    a  
    Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
    is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
    model's internal embedding lookup matrix.
    a  
    Indices of decoder input sequence tokens in the vocabulary.

    Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
    [`PreTrainedTokenizer.__call__`] for details.

    [What are decoder input IDs?](../glossary#decoder-input-ids)
    a(  
    Optionally, instead of passing `decoder_input_ids` you can choose to directly pass an embedded
    representation. If `past_key_values` is used, optionally only the last `decoder_inputs_embeds` have to be
    input (see `past_key_values`). This is useful if you want more control over how to convert
    `decoder_input_ids` indices into associated vectors than the model's internal embedding lookup matrix.

    If `decoder_input_ids` and `decoder_inputs_embeds` are both unset, `decoder_inputs_embeds` takes the value
    of `inputs_embeds`.
    z<of shape `(batch_size, target_sequence_length, hidden_size)`z
    If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
    `past_key_values`).
    z
    Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
    tensors for more detail.
    z
    Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
    more detail.
    zU
    Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
    a  
    Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
    this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
    the complete sequence length.
    zof shape `(sequence_length)`z9 input to the layer of shape `(batch, seq_len, embed_dim)zD
    Whether to interpolate the pre-trained position encodings.
    z
    Tuple containing the cosine and sine positional embeddings of shape `(batch_size, seq_len, head_dim)`,
    with `head_dim` being the embedding dimension of each attention head.
    a  
    Model configuration class with all the parameters of the model. Initializing with a config file does not
    load the weights associated with the model, only the configuration. Check out the
    [`~PreTrainedModel.from_pretrained`] method to load the model weights.
    a  
    Labels for position (index) of the start of the labelled span for computing the token classification loss.
    Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
    are not taken into account for computing the loss.
    zof shape `(batch_size,)`a  
    Labels for position (index) of the end of the labelled span for computing the token classification loss.
    Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
    are not taken into account for computing the loss.
    aB  
    Tuple consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*: `attentions`)
    `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) is a sequence of
    hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
    z
    Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
    should not be returned during inference.
    a  
    If an `int`, compute logits for the last `logits_to_keep` tokens. If `0`, calculate logits for all
    `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
    token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
    If a `torch.Tensor`, must be 1D corresponding to the indices to keep in the sequence length dimension.
    This is useful when using packed tensor format (single dimension for batch and sequence length).
    a  
    The tensors corresponding to the input images. Pixel values can be obtained using
    [`{image_processor_class}`]. See [`{image_processor_class}.__call__`] for details ([`{processor_class}`] uses
    [`{image_processor_class}`] for processing images).
    z=of shape `(batch_size, num_channels, image_size, image_size)`z
    The index of the layer to select the vision feature. If multiple indices are provided,
    the vision feature of the corresponding indices will be concatenated to form the
    vision features.
    z
    The feature selection strategy used to select the vision feature from the vision backbone.
    Can be one of `"default"` or `"full"`.
    zU
    The sizes of the images in the batch, being (height, width) for each image.
    zof shape `(batch_size, 2)`a  
    Mask to avoid performing attention on padding pixel values. Mask values selected in `[0, 1]`:

    - 1 for pixels that are real (i.e. **not masked**),
    - 0 for pixels that are padding (i.e. **masked**).

    [What are attention masks?](../glossary#attention-mask)
    z&of shape `(batch_size, height, width)`r.   )*r/   r0   r1   r2   labelsnum_logits_to_keep	input_idsinput_valuesattention_mask	head_maskcross_attn_head_maskdecoder_attention_maskdecoder_head_maskencoder_hidden_statesencoder_attention_masktoken_type_idsposition_idspast_key_valuespast_key_valueinputs_embedsdecoder_input_idsdecoder_inputs_embeds	use_cacheoutput_attentionsoutput_hidden_statesreturn_dictcache_positionhidden_statesinterpolate_pos_encodingposition_embeddingsconfigstart_positionsend_positionsencoder_outputsoutput_router_logitslogits_to_keeppixel_valuesvision_feature_layervision_feature_select_strategyimage_sizes
pixel_maskrE   r.   rF   rG   rI   rI      s   
 <F
  <
I <L <
N HI 6 C H I <	 <
N
 <L$ 'O. 	N
 IM C
 P I   	K
 0N WM 	  
 F
 ,O
 ,M
 O  	N
 QL
  &" .	K :
JrF   rI   c                   d    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrSrSrSrSrSrSrSrSrg)ClassDocstringi3  a  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.
    zd
    The bare {model_name} Model outputting raw hidden-states without any specific head on top.
    zJ
    The {model_name} Model with a specified pretraining head on top.
    zf
    The bare {model_name} Decoder outputting raw hidden-states without any specific head on top.
    zh
    The bare {model_name} Text Model outputting raw hidden-states without any specific head on to.
    zk
    The {model_name} Model with a sequence classification/regression head on top e.g. for GLUE tasks.
    z
    The {model_name} transformer with a span classification head on top for extractive question-answering tasks like
    SQuAD (a linear layer on top of the hidden-states output to compute `span start logits` and `span end logits`).
    z
    The {model_name} Model with a multiple choice classification head on top (a linear layer on top of the pooled output and a
    softmax) e.g. for RocStories/SWAG tasks.
    zI
    The {model_name} Model with a `language modeling` head on top."
    z
    The {model_name} transformer with a token classification head on top (a linear layer on top of the hidden-states
    output) e.g. for Named-Entity-Recognition (NER) tasks.
    z{
    The {model_name} Model for token generation conditioned on other modalities (e.g. image-text-to-text generation).
    z>
    The {model_name} Model for causal language modeling.
    z9
    Constructs a fast {model_name} image processor.
    z$
    The {model_name} backbone.
    z\
    The {model_name} Model with an image classification head on top e.g. for ImageNet.
    zf
    The {model_name} Model with a semantic segmentation head on top e.g. for ADE20K, CityScapes.
    z{
    The {model_name} Model with an audio classification head on top (a linear layer on top of the pooled
    output).
    zl
    The {model_name} Model with a frame classification head on top for tasks like Speaker Diarization.
    z]
    The {model_name} Model with a distribution head on top for time-series forecasting.
    zm
    The {model_name} Model with a projection layer on top (a linear layer on top of the pooled output).
    r.   N)r/   r0   r1   r2   PreTrainedModelModelForPreTrainingDecoder	TextModelForSequenceClassificationForQuestionAnsweringForMultipleChoiceForMaskedLMForTokenClassificationForConditionalGenerationForCausalLMr   BackboneForImageClassificationForSemanticSegmentationForAudioClassificationForAudioFrameClassificationForPredictionWithProjectionrE   r.   rF   rG   rq   rq   3  s    OENGI!

K
 KH
#MNrF   rq   c                   D    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrg)
ClassAttrsi  z
    A string indicating the attribute associated to the base model in derived classes of the same architecture adding modules on top of the base model.
    a  
    Whether the model supports gradient checkpointing or not. Gradient checkpointing is a memory-saving technique that trades compute for memory, by storing only a subset of activations (checkpoints) and recomputing the activations that are not stored during the backward pass.
    ab  
    Layers of modules that should not be split across devices should be added to `_no_split_modules`. This can be useful for modules that contains skip connections or other operations that are not compatible with splitting the module across devices. Setting this attribute will enable the use of `device_map="auto"` in the `from_pretrained` method.
    zu
    A list of keys to ignore when moving inputs or outputs between devices when using the `accelerate` library.
    zS
    Whether the model's attention implementation supports FlashAttention 2.0.
    zd
    Whether the model's attention implementation supports SDPA (Scaled Dot Product Attention).
    zN
    Whether the model's attention implementation supports FlexAttention.
    zM
    Whether the model supports a `Cache` instance as `past_key_values`.
    z\
    Whether the model supports a `QuantoQuantizedCache` instance as `past_key_values`.
    zS
    Whether the model supports a `StaticCache` instance as `past_key_values`.
    z
    Whether the model supports attention interface functions. This flag signal that the model can be used as an efficient backend in TGI and vLLM.
    za
    A list of `state_dict` keys that are potentially tied to another key in the state_dict.
    r.   N)r/   r0   r1   r2   base_model_prefixsupports_gradient_checkpointing_no_split_modules_skip_keys_device_placement_supports_flash_attn_2_supports_sdpa_supports_flex_attn_supports_cache_class_supports_quantized_cache_supports_static_cache_supports_attention_backend_tied_weights_keysrE   r.   rF   rG   r   r     sa    '##N!#rF   r   >   argsselfkwargsdeprecated_argumentsc                 V    [        U R                  R                  S5      5      S-
  S-  $ )N.r	      )lenr1   split)funcs    rG   get_indent_levelr     s(    !!'',-1Q66rF   c                     SR                  U R                  5        Vs/ s H  o"R                  5       PM     sn5      n [        R                  " U SU-  5      $ s  snf )L
Adjust the indentation of a docstring to match the specified indent level.

 )join
splitlineslstriptextwrapindent)	docstringindent_levellines      rG   equalize_indentr     sL    
 		Y5I5I5KL5KT;;=5KLMI??9cL&899 Ms   Ac                 ^    [         R                  " [         R                  " U 5      SU-  5      $ )r   r   )r   r   dedent)r   r   s     rG   set_min_indentr     s#     ??8??95s\7IJJrF   c                     [         R                  " S5      nUR                  U 5      nU(       a  SUR                  S5      -   $ g )Nz(of shape\s*(?:`.*?`|\(.*?\)))r   r	   recompilesearchgroup)r   shape_patternmatchs      rG   parse_shaper     s:    JJ@AM  +EU[[^##rF   c                     [         R                  " S5      nUR                  U 5      nU(       a  SUR                  S5      -   $ g )Nz(defaults to \s*[^)]*)r   r	   r   )r   default_patternr   s      rG   parse_defaultr     s:    jj!:;O""9-EU[[^##rF   c                     [         R                  " SU 5      nU(       a&  XR                  5       S nU SUR                  5        n OSn[         R                  " S[         R                  5      nUR                  U 5      nU(       a   UR                  S5      R                  S5      OU nUR                  S5      S   R                  5       S:X  a#  SR                  UR                  S5      SS 5      nUR                  S5      S	   R                  5       S
:X  d&  UR                  S5      S	   R                  5       S:X  a#  SR                  UR                  S5      SS 5      n[        US	5      n0 nU(       a  [         R                  " SU SU S3[         R                  [         R                  -  5      nUR                  U5       H  nUR                  S5      n	UR                  S5      n
UR                  S5      nSU;   n[        U5      n[        U5      nUR                  S5      R                  5       n[         R                  " SSUS5      nSU 3nU
UUUUUS.Xy'   M     U(       a  U(       a  SU-   n[        US	5      nXs4$ )aE  
Parse the docstring to extract the Args section and return it as a dictionary.
The docstring is expected to be in the format:
Args:
    arg1 (type): Description of arg1.
    arg2 (type): Description of arg2.

# This function will also return the remaining part of the docstring after the Args section.
Returns:/Example:
...
z(?m)^([ \t]*)(?=Example|Return)N z(?:Args:)(\n.*)?(\n)?$r	   r   z"""r   zr"""z^\s{0,z;}(\w+)\s*\(\s*([^, \)]*)(\s*.*?)\s*\)\s*:\s*((?:(?!\n^\s{0,z}\w+\s*\().)*)      optionalr   ^z    )typer,   r   r-   defaultadditional_info)r   r   startr   DOTALLr   r   r   stripr   r   	MULTILINEfinditerr   r   sub)r   max_indent_levelr   remainder_docstringargs_pattern
args_matchargs_sectionparamsparam_pattern
param_name
param_typer   r   r-   r   param_descriptions                   rG   parse_docstringr     sY    II8)DE'8o.	 ::7CL$$Y/J7A:##A&--d3yL$#))+u4yy!3!3D!9#2!>?$"((*f48J8J48PQR8S8Y8Y8[_d8dyy!3!3D!9!"!=>!,2LF

'((efvew  xG  HII$

 #++L9EQJQJ#kk!nO!_4H0E#O4G %A 4 4 6 "tW6G K"$%6$7 8"0$"#2"F :* %"%88()<a@&&rF   returnc                 2   [        U 5      nUS:X  a   [        X5      U 4$ U Vs/ s H  n[	        XA5      S   PM     nn[        U5      nU(       a  X%R                  S5         n X`4$ ! [         a!  n[        [        U 5      U5      U 4s SnA$ SnAff = fs  snf )z
Check if a "nested" type hint contains a specific target type,
return the first-level type containing the target_type if found.
r.   Nr   T)r   
issubclass	Exceptionr   contains_typeanyindex)	type_hinttarget_typer   _argfound_type_tuple
found_types          rG   r   r     s    
 IDrz	Gi5y@@ GKKdsc7:dK%&J//56	    	Gd9o{;YFF	GKs"   A& B&
B0BBBc                    [         R                  " U 5      nUR                  [        R                  R
                  5      S   S:w  a  gUR                  [        R                  R
                  5      S   n[         H}  nUR                  S5      S   nSU;   a  UR                  S5      S   OSnUR                  U5      (       d  MK  UR                  U5      (       d  Mc  U[        U5      [        U5      *  nUs  $    [        SU 35        g	)
z6
Get the model name from the file path of the object.
modelsNr   *r   r   uE   🚨 Something went wrong trying to find the model name in the path: model)inspectgetsourcefiler   ospathsepAUTODOC_FILES
startswithendswithr   print)objr   	file_name	file_typer   endmodel_name_lowercases          rG   get_model_namer   1  s       %Dzz"''++r"h.

277;;'+I"	$Q'*-*:iooc"2&&&9+=+=c+B+B#,SZ3s8)#D '' # 	UVZU[\]rF   placeholders
model_namec                     SSK Jn  0 nU  H`  nU[        ;   d  M  [        [        U[        U   S   5      [        U   S   5      U   n[	        U[
        [        45      (       a  US   nXSU'   Mb     U$ )z>
Get the dictionary of placeholders for the given model name.
r   autor	   )transformers.modelsr   PLACEHOLDER_TO_AUTO_MODULEgetattr
isinstancelisttuple)r   r   auto_moduleplaceholders_dictplaceholderplace_holder_values         rG   get_placeholders_dictr  D  s    
 8#44!(%?%LQ%OP*;7:" " ,tUm<<%7%:"-?k* $ rF   c                   ^  [        [        R                  " SSR                  U 4S jT  5       5      5      5      nU(       d  T $ [	        X!5      nT  Ho  nT U   S   n[        R                  " SU5      nU Vs/ s H  ofU;   d  M
  UPM     nnU(       a%  UR
                  " S0 U Vs0 s H  ofX6   _M	     snD6nUT U   S'   Mq     T $ s  snf s  snf )z
Replaces placeholders such as {image_processor_class} in the docstring with the actual values,
deducted from the model name and the auto modules.
z{(.*?)}r   c              3   4   >#    U  H  nTU   S    v   M     g7f)r,   Nr.   ).0r   r   s     rG   	<genexpr>(format_args_docstring.<locals>.<genexpr>`  s     6`[_TWtCy7O[_s   r,   r.   )setr   findallr   r  format)r   r   r   r  r   new_argr  s   `      rG   format_args_docstringr  Z  s     rzz*bgg6`[_6`.abcL .lG s)M*zz*g67Ch|VgGg|hnnugs'tgsXc5F5S(Sgs'tuG#*S	-   K i'ts   7	CC%Cargs_classesc                     [        U [        [        45      (       a(  0 nU  H  nUR                  UR                  5        M      U$ U R                  $ N)r   r   r   update__dict__)r  args_classes_dict
args_classs      rG   source_args_docr  s  sI    ,u..&J$$Z%8%89 '     rF   c                     S nU R                   n[        R                  U5      nU H/  u  pEUR                  S5      (       a  US S nSU 3nXV:X  d  M,  Un  U$    U$ )N/r   zhttps://huggingface.co/)__doc___re_checkpointr  r   )r   
checkpointconfig_sourcecheckpoints	ckpt_name	ckpt_linkckpt_link_from_names          rG    get_checkpoint_from_config_classr"  |  sz    J !((M ((7K !,	c""!#2I !8	{C+"J !, rF   c                 R    SnU R                   S:X  a  SU S3n[        XCS-   5      nU$ )Nr   forwardzThe [`a  `] forward method, overrides the `__call__` special method.

        <Tip>

        Although the recipe for forward pass needs to be defined within this function, one should call the [`Module`]
        instance afterwards instead of this since the former takes care of running the pre and post processing steps while
        the latter silently ignores them.

        </Tip>

        r   )r/   r   )r   
class_nameparent_classr   intro_docstrings        rG   add_intro_docstringr(    s=    O}}	!%j\ 
2	 
 */!;KLrF   c                    SSK Jn  Ub  [        U5      nO[        U 5      nU(       a@  U[        [        U[        S   S   5      [        S   S   5      ;  a  UR                  SS5      nU R                  R                  S5      S   nUc  SnO. [        [        U[        S   S   5      [        S   S   5      U   nX4U4$ ! [         a)    U[        ;   a  [        U   n N#S	n[        S
U S35         N6f = f)z
Extract model information from a function or its parent class.

Args:
    func (`function`): The function to extract information from
    parent_class (`class`): Optional parent class of the function
r   r   Nr   r	   r   -r   ModelConfigu   🚨 Config not found for zM. You can manually add it to HARDCODED_CONFIG_FOR_MODELS in utils/args_doc.py)r   r   r   r   r   replacer1   r   KeyErrorHARDCODED_CONFIG_FOR_MODELSr   )r   r&  r  r   r%  r   s         rG   _get_model_infor/    s+    8 -l;-d3  4G7GJK">215= !  4;;CE ""((-a0J #	"%?%OPQ%RS*>:1= #$L  \99  	#'BB:;OP,01E0F  GT  U	s   -B> >C1C10C1c                 X   SnU R                   [        R                  R                  :w  a  U R                   nS[	        U5      ;   a:  SR                  [	        U5      R                  S5      5      R                  SS5      nOf[        US5      (       aT  UR                  R                  SS5      R                  SS5       S	U R                   R                   3nUS
   S	:X  a  USS nO SU;   a  [        R                   " SSU5      nSU;   a  [        R                   " SSU5      nSnXC4$ SnXC4$ )z
Process and format a parameter's type annotation.

Args:
    param (`inspect.Parameter`): The parameter from the function signature
    param_name (`str`): The name of the parameter
    func (`function`): The function the parameter belongs to
Ftypingr   typing.transformers.~r0   builtinsr   r   r	   N
ForwardRefForwardRef\('([\w.]+)'\)\1r   Optional\[(.*?)\]T)
annotationr   	Parameteremptystrr   r   r,  hasattrr0   r/   r   r1   __code__co_filenamer   r   )paramr   r   r   r   s        rG   _process_parameter_typerB    s6    H7,,222%%
s:&Z!6!6y!ABJJ?\_`JZ..&1199/3OWWXbdfghhijojzjz  kD  kD  jE  FJ!}#'^
 :% ;UJOJ# 4eZHJH  
rF   c                 8   SnSnSnSnSn	X;   aV  US:X  a  X   R                  SS5      b  X   S   nX   S   nX   S   nU(       a  UOSnX   S   =(       d    Sn	X   S    S	3nO&X;   a  X    S   nU(       a  S
U-   OSnX    S   nSn	OSnU(       a  SOSn
X:XyXX4$ )a  
Get parameter documentation details from the appropriate source.
Tensor shape, optional status and description are taken from the custom docstring in priority if available.
Type is taken from the function signature first, then from the custom docstring if missing from the signature

Args:
    param_name (`str`): Name of the parameter
    documented_params (`dict`): Dictionary of documented parameters (manually specified in the docstring)
    source_args_dict (`dict`): Default source args dictionary to use if not in documented_params
    param_type (`str`): Current parameter type (may be updated)
    optional (`bool`): Whether the parameter is optional (may be updated)
Nr   Tr   r   r-   r   r,   r   r   Fz, *optional*)get)r   documented_paramssource_args_dictr   r   r,   r-   shape_stringis_documentedr   optional_strings              rG   _get_parameter_inforJ    s     KELMO& 1 = A A&$ O [*6v>J$0<!-g6 %u2+78IJPb*6}EFbI		' ,W5&+sU{&2=A )1orO{aarF   c           
         Sn[        [        [        /5      n0 nU R                  R	                  5        GH  u  pU	[
        ;   dP  U
R                  [        R                  R                  :X  d(  U
R                  [        R                  R                  :X  a  Mb  [        XU5      u  pSnU
R                  [        R                  :w  a&  U
R                  b  S[        U
R                  5       S3n[        XX{U5      u  pnnnnU(       az  U	S:X  a&  US:X  a  SU S3nO SUR!                  S5      S    S3nOUS:X  a   SU;   a  UOSU S3nU(       a  U	 S	U U S
U 3nOU	 S	U U U U S
U 3nU[+        UUS-   5      -  nGMJ  U(       a  UOSUUU(       a  UOSUS.X'   UR-                  SU	 SUR$                   SUR&                  R(                   S35        GM     Xh4$ )a  
Process all regular parameters (not kwargs parameters) from the function signature.

Args:
    sig (`inspect.Signature`): Function signature
    func (`function`): Function the parameters belong to
    class_name (`str`): Name of the class
    documented_params (`dict`): Dictionary of parameters that are already documented
    indent_level (`int`): Indentation level
    undocumented_parameters (`list`): List to append undocumented parameters to
r   , defaults to ``re   z[`z`]r   r    ():   z<fill_type>z
    <fill_description>)r   r   r-   r,   r      🚨 `` is part of zZ's signature, but not documented. Make sure to add it to the docstring of the function in )r  rI   r)   
parametersitemsARGS_TO_IGNOREkindr   r;  VAR_POSITIONALVAR_KEYWORDrB  r   _emptyr=  rJ  r   r   r1   r?  r@  r   append)sigr   r%  rE  r   undocumented_parametersr   rF  missing_argsr   rA  r   r   param_defaultrI  rG  r   r,   rH  param_docstrings                       rG   _process_regular_parametersr`  "  s>    I&	3E'FGL ^^113
 .(zzW..===zzW..:::  7u$O
 ==GNN*u}}/H-c%--.@-ACMat+;b
^
\?KQ^ X%##%j\!4J#%j&6&6s&;B&?%@!CJr!e'*j'8*Q>OJ%/L:,>OrR]Q^"_ "l"ZL>OP]^`al`mn   q  I '1
m$%.9{?Y((L$ $**M$2C2C1D  E_  `d  `m  `m  `y  `y  _z  z{  |c 4j ""rF   c                     SnUnSnU(       d=  X    H'  nUS:X  a  US-  nM  US:X  d  M  US-  nUS:X  d  M%  Sn  O   US-  nU(       d  M=  U$ )Nr   F(r	   )Tr.   )linesline_endparenthesis_countsig_line_end	found_sigchars         rG   find_sig_linerj  j  sq    LI'Ds{!Q&!!Q&!$) $I ( 	 i rF   c                   ^ Sn[        [        5      nUR                  [        ;   n	U	(       d  Tb  [	        U4S j[
         5       5      n	U	(       Ga  U R                  R                  5        V
Vs/ s H1  u  pUR                  [        R                  R                  :X  d  M/  UPM3     nn
nU GH  nUR                  [        R                  R                  :X  a  M.  UR                  R                  S   R                  nUb  [!        U5      u  pJUb  [#        XC5      nUR                  R                  S   R$                  R                  5        GH  u  nn['        U5      nSnSU;   a1  SR)                  UR+                  S5      5      R-                  SS5      nO'UR-                  SS5      R-                  S	S5       S
U 3nSU;   a  [.        R0                  " SSU5      nSU;   a  [.        R0                  " SSU5      nSnSnTb$  ['        [3        TUS5      5      nUS:w  a  SU S3OSn[5        XUUU5      u  nnnnnnU(       a  US:X  aJ  [7        SU SUR                  R                  S   R8                   SUR:                  R<                   S35        SU;   a  UOSU S3nU(       a  U[?        U SU U SU 3US-   5      -  nGMy  U[?        U SU U U U SU 3US-   5      -  nGM  URA                  SU SUR                  R                  S   R8                   SUR:                  R<                   S
35        GM     GM     U$ s  snn
f )a  
Process **kwargs parameters if needed.

Args:
    sig (`inspect.Signature`): Function signature
    func (`function`): Function the parameters belong to
    parent_class (`class`): Parent class of the function
    model_name_lowercase (`str`): Lowercase model name
    documented_kwargs (`dict`): Dictionary of kwargs that are already documented
    indent_level (`int`): Indentation level
    undocumented_parameters (`list`): List to append undocumented parameters to
r   c              3   @   >#    U  H  oTR                   ;   v   M     g 7fr  r/   )r  unroll_kwargs_classr&  s     rG   r	  -_process_kwargs_parameters.<locals>.<genexpr>  s      
Ti=P<#8#88Tis   r   Fr1  r2  r3  r4  r5  r   r6  r7  r8  r   r9  TrL  rM  u   🚨 z for z	 in file z has no typerN  rO  rP  rQ  rR  zN, but not documented. Make sure to add it to the docstring of the function in )!r  r)   r/   UNROLL_KWARGS_METHODSr   UNROLL_KWARGS_CLASSESrS  rT  rV  r   r;  rX  r:  r<  __args__r  r   r  __annotations__r=  r   r   r,  r   r   r   rJ  r   r1   r?  r@  r   rZ  )r[  r   r&  r   documented_kwargsr   r\  r   rF  unroll_kwargsr   kwargs_paramkwargs_parameterskwarg_paramkwargs_documentationr   param_type_annotationr   r   r^  rI  rG  r   r,   rH  s     `                      rG   _process_kwargs_parametersr{  {  s    I&'9: MM%::M\5 
Ti
 
  $'>>#7#7#9
#9  G$5$5$A$AA #9 	 

 -K%%):):)@)@@ $/#9#9#B#B1#E#M#M #/'67K'L$!'3(=>O(f% 6A5K5K5T5TUV5W5g5g5m5m5o1
1 !67
  z)!#)9)9))D!E!M!Mo_b!cJ$.$6$6$L$T$TU_ac$d#eefgqfr!sJ:-!#(CUJ!WJ+!#(<eZ!PJ#H !#+$'j"(M$NMJW[]J]om_A$FceM (
GWYcemn g
O\?KYf !!R'#J<u[5K5K5T5TUV5W5d5d4eenoso|o|  pI  pI  oJ  JV  W 03j/@*UVFWJ&!^)l"ZL8IK=Y(1,& 	
 "^)l"ZLFWXeWffhithuv(1,& 	
 ,22 M+:P:P:Y:YZ[:\:i:i9j  ky  z~  zG  zG  zS  zS  yT  TU  VY 6p -z E
s   ..M Mc           	         [        SUS-   5      n/ n0 n	0 n
U b  [        U 5      u  pUb  [        X5      n	[        XX9Xh5      u  pX{-  n[	        XXTXU5      nX}-  n[        U5      S:  a  [        SR                  U5      5        U$ )a  
Process the parameters section of the docstring.

Args:
    func_documentation (`str`): Existing function documentation (manually specified in the docstring)
    sig (`inspect.Signature`): Function signature
    func (`function`): Function the parameters belong to
    class_name (`str`): Name of the class the function belongs to
    model_name_lowercase (`str`): Lowercase model name
    parent_class (`class`): Parent class of the function (if any)
    indent_level (`int`): Indentation level
zArgs:
r   r   r   )r   r   r  r`  r{  r   r   r   )func_documentationr[  r   r%  r   r&  r   r   r\  rE  rt  r_  r]  kwargs_docstrings                 rG   _process_parameters_sectionr    s      y,*:;I  %0?@R0S-+ 56G ^ %@:,%!O  I 2<7HXo !I "#a'dii/01rF   c                    SnU b  [         R                  " SU 5      =nbv  [         R                  " SU 5      nU(       a3  XR                  5       UR                  5        nXR                  5       S n OXR                  5       S nSn [        XCS-   5      nX@4$ UR                  bd  UR                  [
        R                  :w  aF  [        UR                  [        5      u  px[        XUS9nUR                  SS5      n[        XCS-   5      nX@4$ )a/  
Process the returns section of the docstring.

Args:
    func_documentation (`str`): Existing function documentation (manually specified in the docstring)
    sig (`inspect.Signature`): Function signature
    config_class (`str`): Config class for the model
    indent_level (`int`): Indentation level
r   Nz(?m)^([ \t]*)(?=Return)(?m)^([ \t]*)(?=Example)r   )	add_intror2  )r   r   r   r   return_annotationr   rY  r   r   r   r,  )	r}  r[  r   r   return_docstringmatch_start	match_endr  r  s	            rG   _process_returns_sectionr  
  s     	&II&@BTUU[bII9;MN	12C2C2E	HYZ!3OO4E4G!H12C2C2E2GH!#)*:1<LM // 
			*s/D/D/V'4S5J5JK'X$	56Gajk+33IrB)*:1<LM//rF   c           
      \   SSK Jn  Sn	U bC  [        R                  " SU 5      =n
(       a%  X
R	                  5       S n	S[        XS-   5      -   n	U	$ UGc?  UGb;  SS	R                  [        R                  " 5       5       S
3n[        R                  " X5      nUR                  R                  nU=nc   [        X   5      nUbd  Ub?  SnUR#                  5       n[        U   R%                  UUSSSSSS9n[        UUS-   5      n	U	$ ['        SU SUR(                   SU S35         U	$ [*         Hc  n[-        UR.                  U5      nUUR                  5       ;   d  M/  [*        U   n[0        U   R%                  UUSSSSS9n[        UUS-   5      n	  U	$    U	$ ! [         a    U[        ;   a  UR                  R                  n[        U   nUUR                  5       ;   aL  UR!                  5        VVs/ s H  u  nnUU:X  d  M  UPM     Os  snnf snnS   nUU;   a  [        UU   5      n GNlf = f)a  
Process the example section of the docstring.

Args:
    func_documentation (`str`): Existing function documentation (manually specified in the docstring)
    func (`function`): Function being processed
    parent_class (`class`): Parent class of the function
    class_name (`str`): Name of the class
    model_name_lowercase (`str`): Lowercase model name
    config_class (`str`): Config class for the model
    checkpoint: Checkpoint to use in examples
    indent_level (`int`): Indentation level
r   r   r   Nr  r   r   rb  |rc  z...      z<mask>)model_classr  expected_outputexpected_lossqa_target_start_indexqa_target_end_indexmasku   🚨 No checkpoint found for r   zB. Please add a `checkpoint` arg to `auto_docstring` or add one in z's docstring)r  r  r  r  r  r  )r   r   r   r   r   r   r   r   keysr   CONFIG_MAPPINGr"  r-  r.  r   valuesrT  r   r  r   r/   r
   r   modeling_autor   )r}  r   r&  r%  r   r   r  r   r  example_docstringr   task
model_taskr  checkpoint_exampler   config_class_namekvmodel_name_for_auto_configexample_annotationname_model_list_for_taskmodel_list_for_taskpipeline_names                           rG   _process_example_sectionr  -  s   " 8 %BII>Y[m4n+n5+n.{{}? >2CTUEU#VVz w 
	"6"BCHH16689:!<YYt0
$77FF #-,5%EnFj%k"  !!-%'"!'')%9$%?%F%F *1$)"'*,(*! &G &" %33E|VWGW$X!, ) 3J<q  PR  S_  R`  `l  m(  -?(&-k.G.GIa&b#!4!;!;!==$67O$PM)L])[)b)b$.#5(-&+.0,. *c *& )77I<Z[K[(\% -? e  '+FF+6+I+I+^+^((CDX(Y%(,@,G,G,II*>*D*D*F6*F$!Q!O`J`A*F662 6G1Q ./I J2.s%   1F AH+.H?H"H+*H+c           
      r   [         R                  " U 5      n[        U 5      n[        X5      u  pxn	U R                  n
Ub  U
b  [        X6S-   5      S-   U
-   n
OUb  Un
Ub  [        X&S-   5      nO
[        XXS9nU[        XXXqU5      -  n[        XX5      u  pX-  n[        U
U UUUU	UU5      nX-  nXl        U $ )z1
Wrapper that automatically generates docstring.
r   r   )r%  r&  r   )
r   	signaturer   r/  r  r   r(  r  r  r  )r   r&  custom_introcustom_argsr  r[  r   r   r%  r   r}  r   r  r  s                 rG   auto_method_docstringr    s    

D
!C#D)L 6ET5X2l#5#A+K9IJTQTff		 ( "<1AB	'l
	
 ,3GWc I
 ,D,( !I 1	 "I LKrF   c           	      j   SSK Jn  [        U R                  XS9R                  R                  SS5      n[        U 5      n[        U 5      nU(       a>  SR                  UR                  S5       Vs/ s H  oR                  5       PM     sn5      OSn	U(       a@  U[        [        U[        S	   S   5      [        S	   S
   5      ;  a  UR                  SS5      n[        R                  " SSR                  [        R                   R#                  5       5       S3U R$                  5      n
U
/ :X  aG  U R                  c:  Uc7  ['        SU R$                   S[        R                   R#                  5        35      eU
/ :w  d  UGb  U
(       a  U
S   OSn
Ub'  [)        X5      nUR+                  S5      (       d  US-  nO#U	c  SnO[        [        U
5      R-                  U	S9n[/        U5      (       a  [1        U U5      OSnU
S:w  a5  SS U R2                   5       ;   a  U[1        [        R4                   U5      -  nU[1        SU 3U5      -  nSnU R                   R7                  5        H  u  p[9        U5      (       a  M  UR;                  S5      (       a  M/  UR<                  R$                  S:X  a  SnO[?        U5      R$                  nU
(       a  SU
;   a  ['        S5      e[        [@        US5      nUc  M  U[1        U SU SU 3S5      -  nM     O[C        SU R$                   S35        WU l        U $ s  snf )ze
Wrapper that automatically generates a docstring for classes based on their attributes and methods.
r   r   )r&  r  zArgs:zParameters:r   r   Nr   r	   r*  rb  r  z)$rM  z?` is not part of the auto doc. Here are the available classes: r   r   )r   rr   c              3   8   #    U  H  oR                   v   M     g 7fr  rm  )r  xs     rG   r	  'auto_class_docstring.<locals>.<genexpr>  s     >_S^azzS^s   __propertyConfigz%Config should have explicit docstringz (`z`): z/You used `@auto_class_docstring` decorator on `zF` but this class is not part of the AutoMappings. Remove the decorator)"r   r   r  __init__r  r,  r   r   r   r   titler   r   r   r  rq   r  r  r/   
ValueErrorr   r   r  r   r   __mro__rr   rT  callabler   	__class__r   r   r   )clsr  r  r  r  docstring_initr   r   r  model_name_titlename	pre_blockr   	attr_docs	attr_name
attr_value	attr_typeindented_docs                     rG   auto_class_docstringr    s   
 8*3<<cckkssN $C(L)#.Ymsxx4H4N4Ns4S T4Sq4S TUsw 4G7GJK">215= !  4;;CE::388N$;$;$@$@$BCDBGVDrzckk)l.B~\]k]t]t]y]y]{\|}
 	
 rz\-tAwD#'CI%%d++T!	%I5<<HX<YIDG	NNNi[<@XZ	$$):>_SVS^S^>_)_>+I+I*J\ZZI^b(8$9<HH		 &)\\%7%7%9!IJ''	0D0DT0J0J''00J> *I $Z 0 9 9IH,$%LMM&z9dC+9+S4P\~0^`a!bbI &:" 	=cll^  LR  S	
 CKJm !Us   0L0)r  r  r  c                :   ^^^ UUU4S jnU (       a  U" U 5      $ U$ )a  
Automatically generates docstrings for classes and methods in the Transformers library.

This decorator can be used in the following forms:
@auto_docstring
def my_function(...):
    ...
or
@auto_docstring()
def my_function(...):
    ...
or
@auto_docstring(custom_intro="Custom intro", ...)
def my_function(...):
    ...

Args:
    custom_intro (str, optional): Custom introduction text to add to the docstring. This will replace the default
        introduction text generated by the decorator before the Args section.
    checkpoint (str, optional): Checkpoint name to use in the docstring. This should be automatically inferred from the
        model configuration class, but can be overridden if needed.
c                    > [        U R                  R                  S5      5      S:  a  [        U TTTS9$ [	        U TTTS9$ )Nr   r	   )r  r  r  )r   r1   r   r  r  )r   r  r  r  s    rG   auto_docstring_decorator0auto_docstring.<locals>.auto_docstring_decorator  sM    s%%c*+a/(<T^  (S_lvwwrF   r.   )r   r  r  r  r  s    ``` rG   auto_docstringr    s    0x ',,##rF   )r   )Nr   )NNNN)NNNr  )?r   r   r   pathlibr   r1  r   r   r   r   r   regexr   docr
   r   r   r   genericr   resolvePATH_TO_TRANSFORMERSr   r   rp  rq  r.  r   r  r)   rI   rq   r   rU  r   r   r   r   r   r   boolobjectr   r   r=  dictr  r  r  r"  r(  r/  rB  rJ  r`  rj  r{  r  r  r  r  r  r  r.   rF   rG   <module>r     s     	   9 9   ! E{**,~=  X]EB	   
  
    IJE EP` `FW Wt% %R D7
:K>'B!U4&9I3I-J !$& # $ ,2!%V(<"= !$ !.&-:` D'bTE#P"^B+\ 0FVr3lBJ#$TtPT #$rF   