U
    &c                     @   s`  d Z ddlZddl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mZmZ ddlmZ eeZd	d
iZG dd dejjjZG dd dejjjZG dd dejjjZG dd dejjjZG dd dejjjZeG dd dejjjZG dd deZdZ dZ!ede G dd deZ"G dd dejjjZ#ed e G d!d" d"eZ$dS )#z TF 2.0 Transformer XL model.
    N   )TransfoXLConfig)add_start_docstrings add_start_docstrings_to_callable)TFAdaptiveSoftmaxMask)TFPreTrainedModelget_initializerkeras_serializable
shape_list)BatchEncodingztransfo-xl-wt103z7https://cdn.huggingface.co/transfo-xl-wt103-tf_model.h5c                       s&   e Zd Z fddZdddZ  ZS )TFPositionalEmbeddingc                    s.   t  jf | ddtd|d|   | _d S )Nr   i'  r   g       @)super__init__tfrangeinv_freq)selfZdembkwargs	__class__ G/tmp/pip-unpacked-wheel-ymerj3tt/transformers/modeling_tf_transfo_xl.pyr   '   s    zTFPositionalEmbedding.__init__Nc                 C   sr   t d|| j}t t |t |gd}|d k	rXt |d d d d d f d|dgS |d d d d d f S d S )Nzi,j->ijr   )r   einsumr   concatsincosZtile)r   pos_seqbszZsinusoid_inppos_embr   r   r   call,   s
    $zTFPositionalEmbedding.call)N__name__
__module____qualname__r   r    __classcell__r   r   r   r   r   &   s   r   c                       s(   e Zd Zd fdd	Zd	ddZ  ZS )
TFPositionwiseFFFh㈵>{Gz?c                    s   t  jf | || _|| _|| _tjjj|t	|tj
jdd| _tjj|| _tjjj|t	|dd| _tjj|| _tjjj|dd| _|| _d S )NzCoreNet_._0)kernel_initializerZ
activationnamezCoreNet_._3)r)   r*   
layer_normepsilonr*   )r   r   d_modeld_innerdropoutr   keraslayersDenser   nnZrelulayer_1Dropoutdrop_1layer_2drop_2LayerNormalizationr+   	pre_lnorm)r   r.   r/   r0   r;   layer_norm_epsiloninit_stdr   r   r   r   r   7   s       zTFPositionwiseFF.__init__c                 C   s   | j rJ| |}| |}| j||d}| |}| j||d}|| }n>| |}| j||d}| |}| j||d}| || }|S )Ntraining)r;   r+   r5   r7   r8   r9   )r   inpr?   core_outoutputr   r   r   r    I   s    





zTFPositionwiseFF.call)Fr'   r(   )Fr!   r   r   r   r   r&   6   s   r&   c                
       s<   e Zd Zd fdd	Z fdd	Zd
d ZdddZ  ZS )"TFRelPartialLearnableMultiHeadAttnr   NFr'   r(   c                    s  t  jf | || _|| _|| _|| _|| _tjj	j
d| | t|ddd| _tjj	|| _tjj	|| _tjj	j
|t|ddd| _tjj	j|dd| _d|d	  | _|	| _|
d k	r|d k	r|
| _|| _nd | _d | _tjj	j
| j| j t|dd
d| _d S )N   Fqkv_net)r)   Zuse_biasr*   o_netr+   r,   r         ?r_net)r   r   output_attentionsn_headr.   d_headr0   r   r1   r2   r3   r   rE   r6   dropdropattrF   r:   r+   scaler;   r_r_biasr_w_biasrH   )r   rJ   r.   rK   r0   rM   tgt_lenext_lenmem_lenr;   rO   rP   rI   r<   r=   r   r   r   r   r   b   sD    
      
   z+TFRelPartialLearnableMultiHeadAttn.__init__c                    s\   | j d ks| jd krL| j| j| jfdddd| _ | j| j| jfdddd| _t | d S )NzerosTrO   shapeZinitializerZ	trainabler*   rP   )rO   rP   
add_weightrJ   rK   r   buildr   input_shaper   r   r   rX      s    
   
   z(TFRelPartialLearnableMultiHeadAttn.buildc                 C   s   t |}t|ddgddgddgddgg}t||d d |d |d |d g}t|ddddgddddg}t||}|S )Nr   r      rD   r   )r
   r   padreshapeslice)r   xZx_sizer   r   r   
_rel_shift   s    $(z-TFRelPartialLearnableMultiHeadAttn._rel_shiftc                 C   s  |\}}}}}t |d t |d t |d   }}	}
|d k	rt||gd}| jrf| | |}n
| |}| |}tj|ddd\}}}|| d  }nB| jr| | |}n
| |}| |}tj|ddd\}}}t |d }t|||
| j	| j
f}t|||
| j	| j
f}t|||
| j	| j
f}t||	| j	| j
f}|| j }td||}|| j }td||}| |}|| }|| j }|d k	r|d d d d d d f }|d|  d|  }tjj|dd}| j||d	}|d k	r|| }td
||}t |}t||d |d | j	| j
 f}| |}| j||d	}| jrb|| g}n| || g}| jr|| |S )Nr   r   rD   r   Zaxiszibnd,jbnd->ijbnzibnd,jnd->ijbngꌠ9Y>)Fr>   zijbn,jbnd->ibnd)r
   r   r   r;   rE   r+   rH   splitr]   rJ   rK   rP   r   rO   r`   rN   r4   ZsoftmaxrM   rF   rL   rI   append)r   inputsr?   wr	attn_maskmems	head_maskqlenZrlenr   catZw_headsZr_head_kZw_head_qZw_head_kZw_head_vklenZ	rw_head_qZACZ	rr_head_qZBDZ
attn_scoreZattn_mask_tZ	attn_probZattn_vecZattn_vec_sizesZattn_outoutputsr   r   r   r       sZ    (









"

z'TFRelPartialLearnableMultiHeadAttn.call)
r   NNNFNNFr'   r(   )F)r"   r#   r$   r   rX   r`   r    r%   r   r   r   r   rC   a   s             5

rC   c                
       s(   e Zd Zd
 fdd	Zddd	Z  ZS )!TFRelPartialLearnableDecoderLayerN        Fr'   r(   c                    sR   t  jf | t||||||||	|
|||||dd| _t||||
||dd| _d S )Ndec_attn)rQ   rR   rS   rM   r;   rP   rO   r=   rI   r<   r*   pos_ff)r;   r=   r<   r*   )r   r   rC   rp   r&   rq   )r   rJ   r.   rK   r/   r0   rQ   rR   rS   rM   r;   rP   rO   rI   r<   r=   r   r   r   r   r      s6    z*TFRelPartialLearnableDecoderLayer.__init__c                 C   sN   |\}}}}}| j |||||g|d}| j|d |d}	|	g|dd   }
|
S )Nr>   r   r   )rp   rq   )r   rd   r?   Zdec_inprf   dec_attn_maskrh   ri   Zattn_outputsZ	ff_outputrm   r   r   r   r    ,  s
    z&TFRelPartialLearnableDecoderLayer.call)
NNNro   FNNFr'   r(   )Fr!   r   r   r   r   rn      s             0rn   c                       s2   e Zd Zd
 fdd	Z fddZdd	 Z  ZS )TFAdaptiveEmbeddingr   r(   Fc              
      s   t  jf | || _|| _|| _||g | _|| _|| _|d | _dg| j | _	g | _
g | _|dkrjtnftt| jD ]V}	| j	|	 | j	|	d   }
}|||	  }| j
tjjj||
 |t|d|	d qxd S )NrG   r   r   zemb_layers_._{})Zembeddings_initializerr*   )r   r   n_tokend_embedr=   cutoffsdiv_vald_proj	emb_scalecutoff_ends
emb_layers	emb_projsNotImplementedErrorr   lenrc   r   r1   r2   Z	Embeddingr   format)r   rt   ru   rx   rv   rw   r=   sample_softmaxr   il_idxr_idxd_emb_ir   r   r   r   7  s0    
zTFAdaptiveEmbedding.__init__c              
      s`   t t| jD ]@}| j| j|  }| j| j|| jft	| j
dd|d qt | d S )NTzemb_projs_._{}rU   )r   r~   rv   ru   rw   r|   rc   rW   rx   r   r=   r   r   rX   )r   rZ   r   r   r   r   r   rX   W  s    zTFAdaptiveEmbedding.buildc              
   C   s  | j dkrtnt|d}tt|d | jg}tt| j	D ]}| j
| | j
|d   }}||k||k @ }t||| }| j| |}	td|	| j| }	tjt|tjd}
|t|
|	tjt|tjd7 }qBt|| jg }t||}|| j9 }|S )Nr   )r   r   z	id,de->ie)Zdtype)rw   r}   r   r]   rT   r
   rx   r   r~   rv   rz   Zboolean_maskr{   r   r|   castwhereZint64Z
scatter_ndry   )r   r@   Zinp_flatZemb_flatr   r   r   Zmask_iZinp_iZemb_iZmask_idxZembed_shapeembedr   r   r   r    d  s     
$
zTFAdaptiveEmbedding.call)r   r(   Fr"   r#   r$   r   rX   r    r%   r   r   r   r   rs   6  s    rs   c                       sn   e Zd ZeZ fddZ fddZdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd ZdddZ  ZS )TFTransfoXLMainLayerc                    s  t  jf | |j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
| _
t|j|j|j|j|j|jdd| _tjj|j| _|j| _|j| _|j| _|j| _|j|j |j | _|j| _g | _|jdkrPt|jD ]p}| jt|j|j|j	|j|j|j|j|j|j |j!| j
rd n| j"| j
r,d n| j#| j|j$|jd%|d qnt&|j'| _'|j(| _(| jdkrt)| jdd| _*nt&d S )Nword_emb)rw   r=   r*   r   zlayers_._{})rQ   rR   rS   rM   r;   rP   rO   rI   r<   r=   r*   r   r*   )+r   r   rI   output_hidden_states
vocab_sizert   ru   r.   rJ   rK   untie_rrs   rv   rw   r=   r   r   r1   r2   r6   r0   rL   n_layerrQ   rS   rR   Zmax_klen	attn_typer   rc   rn   r/   rM   r;   rP   rO   r<   r   r}   same_length	clamp_lenr   r   )r   configr   r   r   r   r   r     sl    
zTFTransfoXLMainLayer.__init__c                    sN   | j s>| j| j| jfdddd| _| j| j| jfdddd| _t | d S )NrT   TrP   rU   rO   )r   rW   rJ   rK   rP   rO   r   rX   rY   r   r   r   rX     s    
   
   zTFTransfoXLMainLayer.buildc                 C   s   | j S Nr   r   r   r   r   get_input_embeddings  s    z)TFTransfoXLMainLayer.get_input_embeddingsc                 C   s   | j S r   r   )r   Znew_num_tokensr   r   r   _resize_token_embeddings  s    z-TFTransfoXLMainLayer._resize_token_embeddingsc                 C   s
   d| _ d S )Nr   )r   r   r   r   r   backward_compatible  s    z(TFTransfoXLMainLayer.backward_compatiblec                 C   s   || _ || _|| _d S r   )rQ   rS   rR   r   rQ   rR   rS   r   r   r   reset_length  s    z!TFTransfoXLMainLayer.reset_lengthc                 C   s   t d S r   )r}   )r   Zheadsr   r   r   _prune_heads  s    z!TFTransfoXLMainLayer._prune_headsc                 C   sH   | j dkr@g }t| jD ]"}t| j || jg}|| q|S d S d S )Nr   )rS   r   r   r   rT   r.   rc   )r   r   rh   r   emptyr   r   r   	init_mems  s    
zTFTransfoXLMainLayer.init_memsc           
      C   s   |d krd S t |t |ks$tdg }|td|d | j  }td|| j }tt |D ]:}tj|| || gdd}	t|	 |	|	||  q\|S )Nzlen(hids) != len(mems)r   ra   )
r~   AssertionErrormaxrR   rS   r   r   r   Zstop_gradientrc   )
r   hidsrh   mlenrj   new_memsZend_idxZbeg_idxr   rk   r   r   r   _update_mems  s    
z!TFTransfoXLMainLayer._update_memsNFc                 C   s  t |ttfrt|d }t|dkr*|d n|}t|dkrB|d n|}t|dkrZ|d n|}t|dkstdnVt |ttfr|d}|d|}|d	|}|d
|}t|dkstdn|}|d k	r|d k	rtdn\|d k	r
t	j
|dd}t|\}}n6|d k	r8t	j
|dd}t|d d \}}ntd|d krT| |}|d k	rdtnd g| j }|d k	r|}	n
| |}	|d k	rt|d d nd}
|
| }t	||g}t	j|dd}t	j|dd}t	||
g}t	||| gd}| jrPt	j|dd}t	|d d d |f | | |d d |d f gd}g }g }| jdkr&t	|d dd}| jdkrt	|| j}| |}| j|	|d}| j||d}t| jD ]b\}}|| |d krd n|| }||||||| g|d}|d }| jr||d  qnt| j||d}|  |||
|}t	j
|dd|g}| j!r|| tdd |D }|| | jrtdd |D }|| |S )Nr   r   r[   rD      Too many inputs.	input_idsrh   ri   inputs_embedszDYou cannot specify both input_ids and inputs_embeds at the same time)r   r   permr   r   r[   z5You have to specify either input_ids or inputs_embedsr   g      r>   c                 s   s   | ]}t j|d dV  qdS )r   r   Nr   	transpose.0tr   r   r   	<genexpr>j  s     z,TFTransfoXLMainLayer.call.<locals>.<genexpr>c                 s   s   | ]}t j|d dV  qdS ))r[   rD   r   r   r   Nr   r   r   r   r   r   n  s     )"
isinstancetuplelistr~   r   dictr   get
ValueErrorr   r   r
   r   r}   r   r   ZonesZlinalgZ	band_partrT   r   r   r   r   r   Zminimumr   rL   	enumerater2   rc   rI   r   r   )r   rd   rh   ri   r   r?   r   rj   r   r   r   rl   rg   Zmask_uZmask_diaZattn_mask_padrr   Zmask_lr   Z
attentionsr   r   rA   r   ZlayerZmems_iZlayer_outputsr   rm   r   r   r   r      s    








8




zTFTransfoXLMainLayer.call)NNNF)r"   r#   r$   r   config_classr   rX   r   r   r   r   r   r   r   r    r%   r   r   r   r   r   ~  s   D
r   c                   @   s   e Zd ZdZeZeZdZdS )TFTransfoXLPreTrainedModelz An abstract class to handle weights initialization and
        a simple interface for downloading and loading pretrained models.
    transformerN)	r"   r#   r$   __doc__r   r   *TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_MAPZpretrained_model_archive_mapZbase_model_prefixr   r   r   r   r   s  s   r   a  

    .. note::

        TF 2.0 models accepts two formats as inputs:

            - having all inputs as keyword arguments (like PyTorch models), or
            - having all inputs as a list, tuple or dict in the first positional arguments.

        This second option is useful when using :obj:`tf.keras.Model.fit()` method which currently requires having
        all the tensors in the first argument of the model call function: :obj:`model(inputs)`.

        If you choose this second option, there are three possibilities you can use to gather all the input Tensors
        in the first positional argument :

        - a single Tensor with input_ids only and nothing else: :obj:`model(inputs_ids)`
        - a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
          :obj:`model([input_ids, attention_mask])` or :obj:`model([input_ids, attention_mask, token_type_ids])`
        - a dictionary with one or several input Tensors associated to the input names given in the docstring:
          :obj:`model({'input_ids': input_ids, 'token_type_ids': token_type_ids})`

    Parameters:
        config (:class:`~transformers.TransfoXLConfig`): 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 :meth:`~transformers.PreTrainedModel.from_pretrained` method to load the model weights.
a  
    Args:
        input_ids (:obj:`tf.Tensor` or :obj:`Numpy array` of shape :obj:`(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using :class:`transformers.TransfoXLTokenizer`.
            See :func:`transformers.PreTrainedTokenizer.encode` and
            :func:`transformers.PreTrainedTokenizer.encode_plus` for details.

            `What are input IDs? <../glossary.html#input-ids>`__
        mems (:obj:`List[tf.Tensor]` of length :obj:`config.n_layers`):
            Contains pre-computed hidden-states (key and values in the attention blocks) as computed by the model
            (see `mems` output below). Can be used to speed up sequential decoding. The token ids which have their mems
            given to this model should not be passed as input ids as they have already been computed.
        head_mask (:obj:`tf.Tensor` or :obj:`Numpy array` of shape :obj:`(num_heads,)` or :obj:`(num_layers, num_heads)`, `optional`, defaults to :obj:`None`):
            Mask to nullify selected heads of the self-attention modules.
            Mask values selected in ``[0, 1]``:
            :obj:`1` indicates the head is **not masked**, :obj:`0` indicates the head is **masked**.
        input_embeds (:obj:`tf.Tensor` or :obj:`Numpy array` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`, defaults to :obj:`None`):
            Optionally, instead of passing :obj:`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.
z]The bare Bert Model transformer outputing raw hidden-states without any specific head on top.c                       s,   e Zd Z fddZeedd Z  ZS )TFTransfoXLModelc                    s&   t  j|f|| t|dd| _d S )Nr   r   )r   r   r   r   )r   r   rd   r   r   r   r   r     s    zTFTransfoXLModel.__init__c                 K   s   | j |f|}|S )a  
    Return:
        :obj:`tuple(tf.Tensor)` comprising various elements depending on the configuration (:class:`~transformers.TransfoXLConfig`) and inputs:
        last_hidden_state (:obj:`tf.Tensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the last layer of the model.
        mems (:obj:`List[tf.Tensor]` of length :obj:`config.n_layers`):
            Contains pre-computed hidden-states (key and values in the attention blocks).
            Can be used (see `mems` input) to speed up sequential decoding. The token ids which have their past given to this model
            should not be passed as input ids as they have already been computed.
        hidden_states (:obj:`tuple(tf.Tensor)`, `optional`, returned when ``config.output_hidden_states=True``):
            Tuple of :obj:`tf.Tensor` (one for the output of the embeddings + one for the output of each layer)
            of shape :obj:`(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (:obj:`tuple(tf.Tensor)`, `optional`, returned when ``config.output_attentions=True``):
            Tuple of :obj:`tf.Tensor` (one for each layer) of shape
            :obj:`(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.

    Examples::

        import tensorflow as tf
        from transformers import TransfoXLTokenizer, TFTransfoXLModel

        tokenizer = TransfoXLTokenizer.from_pretrained('transfo-xl-wt103')
        model = TFTransfoXLModel.from_pretrained('transfo-xl-wt103')
        input_ids = tf.constant(tokenizer.encode("Hello, my dog is cute", add_special_tokens=True))[None, :]  # Batch size 1
        outputs = model(input_ids)
        last_hidden_states, mems = outputs[:2]

        )r   )r   rd   r   rm   r   r   r   r      s    #zTFTransfoXLModel.call)r"   r#   r$   r   r   TRANSFO_XL_INPUTS_DOCSTRINGr    r%   r   r   r   r   r     s   r   c                       s0   e Zd Z fddZ fddZdd Z  ZS )TFTransfoXLLMHeadc                    s    t  jf | |j| _|| _d S r   )r   r   r   input_embeddings)r   r   r   r   r   r   r   r     s    zTFTransfoXLLMHead.__init__c                    s(   | j | jfdddd| _t | d S )NrT   TbiasrU   )rW   r   r   r   rX   rY   r   r   r   rX     s    zTFTransfoXLLMHead.buildc                 C   s   | j |dd}|| j }|S )NZlinear)mode)r   r   )r   Zhidden_statesr   r   r   r      s    
zTFTransfoXLLMHead.callr   r   r   r   r   r     s   r   zThe Transformer-XL Model with a language modeling head on top
    (adaptive softmax with weights tied to the adaptive input embeddings)c                       sN   e Zd Z fddZdd Zdd Zdd ZeedddZ	dd Z
  ZS )TFTransfoXLLMHeadModelc                    sX   t  | t|dd| _|j| _| jdks4tdt|j|j|j	|j
|jdd| _d S )Nr   r   r   zSampling from the softmax is not implemented yet. Please look at issue: #3310: https://github.com/huggingface/transformers/issues/3310crit)rw   r*   )r   r   r   r   r   r   r   r   ru   r.   rv   rw   r   )r   r   r   r   r   r     s         zTFTransfoXLLMHeadModel.__init__c                 C   s    t | jjdkr| jjd S dS )z9 Double-check if you are using adaptive softmax.
        r   r   N)r~   r   Z
out_layersr   r   r   r   get_output_embeddings  s    z,TFTransfoXLLMHeadModel.get_output_embeddingsc                 C   s   | j ||| d S r   )r   r   r   r   r   r   r     s    z#TFTransfoXLLMHeadModel.reset_lengthc                 C   s   | j |S r   )r   r   )r   r   r   r   r   r     s    z TFTransfoXLLMHeadModel.init_memsNFc                 C   s~  t |ttfr|d }t|dkr*|d n|}t|dkrB|d n|}t|dkrZ|d n|}t|dkrr|d n|}t|dkstdn^t |tr|d}|d	|}|d
|}|d|}|d|}t|dkstdn|}|dk	r
t|dd \}}	nt|dd \}}	| j||||g|d}
|
d }|dd|	 df }|
dd }| j	||g|d}|g| }|S )a  
    Return:
        :obj:`tuple(tf.Tensor)` comprising various elements depending on the configuration (:class:`~transformers.TransfoXLConfig`) and inputs:
        prediction_scores (:obj:`tf.Tensor` of shape :obj:`(batch_size, sequence_length, config.vocab_size)`):
            Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
        mems (:obj:`List[tf.Tensor]` of length :obj:`config.n_layers`):
            Contains pre-computed hidden-states (key and values in the attention blocks).
            Can be used (see `past` input) to speed up sequential decoding. The token ids which have their past given to this model
            should not be passed as input ids as they have already been computed.
        hidden_states (:obj:`tuple(tf.Tensor)`, `optional`, returned when ``config.output_hidden_states=True``):
            Tuple of :obj:`tf.Tensor` (one for the output of the embeddings + one for the output of each layer)
            of shape :obj:`(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (:obj:`tuple(tf.Tensor)`, `optional`, returned when ``config.output_attentions=True``):
            Tuple of :obj:`tf.Tensor` (one for each layer) of shape
            :obj:`(batch_size, num_heads, sequence_length, sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.

    Examples::

        import tensorflow as tf
        from transformers import TransfoXLTokenizer, TFTransfoXLLMHeadModel

        tokenizer = TransfoXLTokenizer.from_pretrained('transfo-xl-wt103')
        model = TFTransfoXLLMHeadModel.from_pretrained('transfo-xl-wt103')
        input_ids = tf.constant(tokenizer.encode("Hello, my dog is cute", add_special_tokens=True))[None, :]  # Batch size 1
        outputs = model(input_ids)
        prediction_scores, mems = outputs[:2]

        r   r   r[   rD   r      r   r   rh   ri   r   labelsNr>   )
r   r   r   r~   r   r   r   r
   r   r   )r   rd   rh   ri   r   r   r?   r   r   rQ   Ztransformer_outputsZlast_hiddenZpred_hidrm   Zsoftmax_outputr   r   r   r      s2    #



zTFTransfoXLLMHeadModel.callc                 K   s   d|i}|r||d< |S )Nrd   rh   r   )r   rd   ZpastZmodel_kwargsr   r   r   prepare_inputs_for_generationW  s    z4TFTransfoXLLMHeadModel.prepare_inputs_for_generation)NNNNF)r"   r#   r$   r   r   r   r   r   r   r    r   r%   r   r   r   r   r     s   Cr   )%r   loggingZ
tensorflowr   Zconfiguration_transfo_xlr   Z
file_utilsr   r   Z modeling_tf_transfo_xl_utilitiesr   Zmodeling_tf_utilsr   r   r	   r
   Ztokenization_utilsr   	getLoggerr"   loggerr   r1   r2   ZLayerr   r&   rC   rn   rs   r   r   ZTRANSFO_XL_START_DOCSTRINGr   r   r   r   r   r   r   r   <module>   sD   
 + ;H u
,