
    sgu                     2   d 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
Z
ddlmZ ddlmZmZmZ ddlmZmZmZ ddlmZ ddlmZmZ dd	l
mZ d
dlmZmZmZ d
dlm Z m!Z! d
dl"m#Z#m$Z$m%Z% ddl&m'Z'  e%jP                  e)      Z*dZ+dZ,dZ-dZ.ej^                  fdej`                  de1deejd                     fdZ3 G d de	jh                        Z5 G d de	jh                        Z6 G d de	jh                        Z7 G d de	jh                        Z8 G d  d!e       Z9 G d" d#e	jh                        Z: G d$ d%e	jh                        Z; e#d&e-       G d' d(e9             Z< e!e<e+ee,        G d) d*e	jh                        Z= e#d+e-       G d, d-e9             Z> e!e>e+ee,       y).zFlax BLOOM model.    N)partial)OptionalTuple)
FrozenDictfreezeunfreeze)combine_masksdot_product_attention_weightsmake_causal_masktanh)flatten_dictunflatten_dict)lax   )FlaxBaseModelOutput-FlaxBaseModelOutputWithPastAndCrossAttentionsFlaxCausalLMOutput)FlaxPreTrainedModelappend_call_sample_docstring)add_start_docstrings%add_start_docstrings_to_model_forwardlogging   )BloomConfigzbigscience/bloomr   a  

    This model inherits from [`FlaxPreTrainedModel`]. 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 Flax Linen
    [flax.nn.Module](https://flax.readthedocs.io/en/latest/_autosummary/flax.nn.module.html) subclass. Use it as a
    regular Flax Module and refer to the Flax documentation for all matter related to general usage and behavior.

    Finally, this model supports inherent JAX features such as:

    - [Just-In-Time (JIT) compilation](https://jax.readthedocs.io/en/latest/jax.html#just-in-time-compilation-jit)
    - [Automatic Differentiation](https://jax.readthedocs.io/en/latest/jax.html#automatic-differentiation)
    - [Vectorization](https://jax.readthedocs.io/en/latest/jax.html#vectorization-vmap)
    - [Parallelization](https://jax.readthedocs.io/en/latest/jax.html#parallelization-pmap)

    Parameters:
        config ([`BloomConfig`]): 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 [`~FlaxPreTrainedModel.from_pretrained`] method to load the model weights.
        dtype (`jax.numpy.dtype`, *optional*, defaults to `jax.numpy.float32`):
            The data type of the computation. Can be one of `jax.numpy.float32`, `jax.numpy.float16` (on GPUs) and
            `jax.numpy.bfloat16` (on TPUs).

            This can be used to enable mixed-precision training or half-precision inference on GPUs or TPUs. If
            specified all the computation will be performed with the given `dtype`.

            **Note that this only specifies the dtype of the computation and does not influence the dtype of model
            parameters.**

            If you wish to change the dtype of the model parameters, see [`~FlaxPreTrainedModel.to_fp16`] and
            [`~FlaxPreTrainedModel.to_bf16`].
a  
    Args:
        input_ids (`numpy.ndarray` of shape `(batch_size, input_ids_length)`):
            `input_ids_length` = `sequence_length`. Indices of input sequence tokens in the vocabulary.

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

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`numpy.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            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)
        past_key_values (`Dict[str, np.ndarray]`, *optional*, returned by `init_cache` or when passing previous `past_key_values`):
            Dictionary of pre-computed hidden-states (key and values in the attention blocks) that can be used for fast
            auto-regressive decoding. Pre-computed key and value hidden-states are of shape *[batch_size, max_length]*.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
attention_mask	num_headsdtypec                    | j                   \  }}dt        j                  t        j                  |            z  }t	        j
                  ddt        j                  |      dz
   z   z  t        j                        }t	        j                  dd|z   t        j                        }t        j                  j                  ||      }||k7  rt	        j
                  ddt        j                  d|z        dz
   z   z  t        j                        }	t        |||z
        }
t	        j                  ddd|
z  z   dt        j                        }t	        j                  |t        j                  j                  |	|      gd      }| j                  d      dz
  | z  dddddf   }|d	   |z  }t	        j                  |d      }t	        j                  ||      S )
a{  
    Flax implementation of the BLOOM Alibi tensor. BLOOM Alibi tensor is not causal as the original paper mentions, it
    relies on a translation invariance of softmax for quick implementation: with l being a tensor, and a fixed value
    `softmax(l+a) = softmax(l)`. Based on
    https://github.com/ofirpress/attention_with_linear_biases/blob/a35aaca144e0eb6b789dfcb46784c4b8e31b7983/fairseq/models/transformer.py#L742
    Link to paper: https://arxiv.org/abs/2108.12409

    Args:
        attention_mask (`jnp.ndarray`):
            Token-wise attention mask, this should be of shape `(batch_size, max_seq_len)`.
        num_heads (`int`):
            Number of attention heads.
        dtype (`jnp.dtype`, *optional*, defaults to `jnp.float32`):
            The data type (dtype) of the output tensor.

    Returns: Alibi tensor of shape `(batch_size * num_heads, 1, max_seq_len)`.
       r   r   r   r   axisN).N)shapemathfloorlog2jnparrayfloat32arangejaxr   powmincatcumsumexpand_dimsasarray)r   r   r   
batch_size
seq_lengthclosest_power_of_2basepowersslopes
extra_basenum_remaining_headsextra_powersarange_tensoralibis                 `/var/www/html/venv/lib/python3.12/site-packages/transformers/models/bloom/modeling_flax_bloom.pybuild_alibi_tensorr@   o   s   $ ,11J
djj9)=>>99QQDII.@$AA$E"FFGHPSP[P[\DZZ111EFWW[[v&FY&YYqqdii<N8N.ORS.S,T'T%UV^a^i^ij
!"4iBT6TUzz!Q-@)@%@!3;;W&#''++j,"GHqQ %+++4q8NJAtUVJWM9-EOOE*E;;ue$$    c                       e Zd ZU eed<   ej                  Zej                  ed<   d Zd Z	d Z
ej                  d        Z	 	 	 	 dded	ed
efdZy)FlaxBloomAttentionconfigr   c                    | j                   j                  | _        | j                   j                  | _        | j                  | j                  z  | _        | j
                  t        j                  u| _        | j                  | j                  z  | j                  k7  r&t        d| j                   d| j                   d      t        t        j                  | j
                  t        j                  j                  j                  | j                   j                               } || j                  dz        | _         || j                        | _        t        j&                  | j                   j(                        | _        y )NzC`hidden_size` must be divisible by `num_heads` (got `hidden_size`: z and `num_heads`: z).r   kernel_initr   )rate)rD   hidden_sizen_headr   head_dimr   r)   r+   attention_softmax_in_fp32
ValueErrorr   nnDenser-   initializersnormalinitializer_rangequery_key_valuedenseDropouthidden_dropoutresid_dropout)selfrT   s     r?   setupzFlaxBloomAttention.setup   s!   ;;22++((DNN:)-3;;)F&==4>>)T-=-==UVZVfVfUg h  $/r3 
 HH**++224;;3P3PQ
  %T%5%5%9:4++,
ZZT[[-G-GHrA   c                 v    |j                  |j                  d d | j                  | j                  dz  fz         S )Nr$   r   )reshaper%   r   rK   rX   hidden_statess     r?   _split_headszFlaxBloomAttention._split_heads   s;    $$]%8%8"%=QUQ^Q^abQb@c%cddrA   c                 Z    |j                  |j                  d d | j                  fz         S )Nr    )r[   r%   rI   r\   s     r?   _merge_headszFlaxBloomAttention._merge_heads   s.    $$]%8%8!%<@P@P?R%RSSrA   c                 (   | j                  dd      }| j                  ddt        j                  |j                  |j
                        }| j                  ddt        j                  |j                  |j
                        }| j                  ddd       }|r|j                  j                  ^ }	}
}}|j                  }dt        |	      z  |ddfz   }t        j                  |j                  ||      }t        j                  |j                  ||      }||_        ||_        |j                  d   }|j                  |z   |_        t        j                  t        j                  |
      ||z   k  t        |	      d||
fz         }t        ||      }|||fS )	a[  
        This function takes projected key, value states from a single input token and concatenates the states to cached
        states from previous steps. This function is slighly adapted from the official Flax repository:
        https://github.com/google/flax/blob/491ce18759622506588784b4fca0e4bf05f8c8cd/flax/linen/attention.py#L252
        cache
cached_keycached_valuecache_indexc                  L    t        j                  dt         j                        S )Nr   r!   )r)   r*   int32 rA   r?   <lambda>z:FlaxBloomAttention._concatenate_to_cache.<locals>.<lambda>   s    CIIaWZW`W`Da rA   )r   r   r   )has_variablevariabler)   zerosr%   r   valuelenr   dynamic_update_slicebroadcast_tor,   tupler	   )rX   keyrm   queryr   is_initializedrc   rd   re   
batch_dims
max_lengthr   depth_per_head	cur_indexindicesnum_updated_cache_vectorspad_masks                    r?   _concatenate_to_cachez(FlaxBloomAttention._concatenate_to_cache   st    **7LA]]7L#))SYYPSPYPYZ
}}WnciiV[VaVabmmG]<abAKAQAQAWAW>ZY#))IS_,	1a/@@G**:+;+;S'JC,,\-?-?PE"J!&L(-A% + 1 14M MK ''

:&5N)NNj!Q(A:$NNH +8^DNE>))rA   Ndeterministic
init_cacheoutput_attentionsc           	      R   |j                   d d \  }}	| j                  |      }
| j                  |
      }
t        j                  |
dd      \  }}}t        |d      }| j                  dd      r| j                  d   d	   nd
}| j                  dd      rH| j                  d   d   j                   d   }t        j                  j                  |d
d
|d
fdd|	|f      }t        j                  ||f|j                   dd  z         }t        j                  t        j                  |d      |j                         }t        ||      }d }|s*| j                  j                  dkD  r| j!                  d      }| j                  dd      s|r| j#                  ||||      \  }}}t        j$                  | j&                        j(                  }t        j*                  |d
kD  t        j,                  |j                   d      j/                  | j&                        t        j,                  |j                   |      j/                  | j&                              }||z   }| j0                  rt        j2                  n| j&                  }t5        ||||| j                  j                  ||      }| j0                  r|j/                  | j&                        }t        j6                  d||      }| j9                  |      }| j;                  |      }| j=                  ||      }||z   }|r||f}|S |f}|S )Nr    r   r$   r"   boolr!   rb   rc   re   r   r   )g        dropout)biasdropout_rngdropout_rater}   r   z...hqk,...khd->...qhdr}   )r%   rS   r^   r)   splitr   rj   	variablesr-   r   dynamic_slicerp   r2   r	   rD   attention_dropoutmake_rngr|   finfor   r/   selectfullastyperL   r+   r
   einsumr`   rT   rW   )rX   r]   residualr>   r   r}   r~   r   r4   r5   	fused_qkvrs   rr   rm   causal_attention_maskcausal_attention_mask_shiftmax_decoder_lengthr   
mask_valueattention_biasattention_dtypeattn_weightsattn_outputoutputss                           r?   __call__zFlaxBloomAttention.__call__   s    "/!4!4Ra!8
J ((7	%%i0	IIi<sE 0v N 7;6G6GQ]6^DNN7#M2de 	$
 Wl3!%!8!F!L!LQ!O$'GG$9$9%A2A6Az#56%! !$ 0 0!J=3H3N3Nqr3R#R!
 ))#//.x*XZoZuZuv&~7LM!>!>!D--	2K Wl3z)-)C)CCPUWe)f&C YYtzz*..
QHH^))3/66tzzBHH^)):6==djjI
 (%/ *.)G)G#++TZZ4#66'!
 ))'..tzz:Ljj!8,N''4jj-((M(R!H,1B;- JUrA   NTFF)__name__
__module____qualname__r   __annotations__r)   r+   r   rY   r^   r`   rN   compactr|   r   r   rh   rA   r?   rC   rC      sz    {{E399"I,eT ZZ* *J " "'T T T  TrA   rC   c                       e Zd Zd Zd Zy)	BloomGELUc                 .    t         j                  | _        y N)r)   r+   r   rX   s    r?   rY   zBloomGELU.setup3  s    [[
rA   c                 H    |dz  dt        d|z  dd|z  |z  z   z        z   z  S )Ng      ?g      ?g e3E?r   gHm?r   )rX   xs     r?   r   zBloomGELU.__call__6  s2    3w#Z!^q8a<!;K7K%L MMNNrA   N)r   r   r   rY   r   rh   rA   r?   r   r   2  s    !OrA   r   c                   b    e Zd ZU eed<   ej                  Zej                  ed<   d Zdde	fdZ
y)FlaxBloomMLPrD   r   c                    | j                   j                  }t        j                  j                  j                  | j                   j                        }t        j                  d|z  | j                  |      | _	        t        j                  || j                  |      | _
        t        j                  | j                   j                        | _        t               | _        y )N   rF   )rD   rI   r-   rN   rP   rQ   rR   rO   r   dense_h_to_4hdense_4h_to_hrU   rV   r   act)rX   rI   rG   s      r?   rY   zFlaxBloomMLP.setup>  s    kk--ff))001N1NOXXa+oTZZU`aXXkQ\] jj)C)CD;rA   r}   c                     | j                  |      }| j                  |      }| j                  |      }||z   }| j                  ||      }|S )Nr   )r   r   r   rV   )rX   r]   r   r}   intermediate_outputs        r?   r   zFlaxBloomMLP.__call__H  sX    **=9/"00?1H<++,?}+]rA   N)Tr   r   r   r   r   r)   r+   r   rY   r   r   rh   rA   r?   r   r   :  s+    {{E399"	t 	rA   r   c                   r    e Zd ZU eed<   ej                  Zej                  ed<   d Z	 	 	 	 d	de	de	de	fdZ
y)
FlaxBloomBlockrD   r   c                    t        j                  | j                  j                  | j                        | _        t        | j                  | j                        | _        t        j                  | j                  j                  | j                        | _        t        | j                  | j                        | _
        | j                  j                  | _        | j                  j                  | _        y )Nepsilonr   r!   )rN   	LayerNormrD   layer_norm_epsilonr   input_layernormrC   self_attentionpost_attention_layernormr   mlp(apply_residual_connection_post_layernormrV   r   s    r?   rY   zFlaxBloomBlock.setupX  s    !||DKK4R4RZ^ZdZde0DJJO(*T[[=[=[cgcmcm(n%4::>8<8l8l5"kk88rA   Nr}   r~   r   c           	         | j                  |      }| j                  r|}n|}| j                  |||||||      }	|	d   }
|	dd  }| j                  |
      }| j                  r|}n|
}| j	                  |||      }|f|z   }|S )N)r   r>   r   r}   r~   r   r   r   r   )r   r   r   r   r   )rX   r]   r>   r   r}   r~   r   layernorm_outputr   attn_outputsattention_outputr   post_layernormoutputs                 r?   r   zFlaxBloomBlock.__call__c  s      //> 88'H$H **)'!/ + 
 (?qr"667GH 88%H'H.(-P)g%rA   r   r   rh   rA   r?   r   r   T  sP    {{E399"	9 " "',
 , ,  ,rA   r   c                   d    e Zd ZU dZeZdZdZej                  e
d<   ddej                  dfded	ed
edej                  def
 fdZddej&                  j(                  d	ededefdZd Z ee      	 	 	 	 	 	 	 	 ddededej&                  j(                  dedee   dee   dee   fd       Z xZS )FlaxBloomPreTrainedModelz
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    transformerNmodule_class)r   r   r   TrD   input_shapeseedr   _do_initc                 Z     | j                   d||d|}t        | 	  ||||||       y )N)rD   r   )r   r   r   r   rh   )r   super__init__)	rX   rD   r   r   r   r   kwargsmodule	__class__s	           r?   r   z!FlaxBloomPreTrainedModel.__init__  s=     #""H&HH[tSXcklrA   rngparamsreturnc                    t        j                  |d      }t        j                  |      }t        j                  j                  |      \  }}||d}| j                  j                  |||d      d   }	|dt        t        |	            }	t        t        |            }| j                  D ]
  }
|	|
   ||
<    t               | _
        t        t        |            S |	S )Ni4r!   )r   r   F)return_dictr   )r)   rl   	ones_liker-   randomr   r   initr   r   _missing_keyssetr   r   )rX   r   r   r   	input_idsr   
params_rngr   rngsrandom_paramsmissing_keys              r?   init_weightsz%FlaxBloomPreTrainedModel.init_weights  s    IIk6	y1"%**"2"23"7
K$=((y.V[(\]ef(-)@AM!(6"23F#11 A&3K&@{#A!$D.011  rA   c                     t        j                  ||fd      }t        j                  |      }| j                  j	                  t
        j                  j                  d      ||dd      }t        |d         S )aW  
        Args:
            batch_size (`int`):
                batch_size used for fast auto-regressive decoding. Defines the batch size of the initialized cache.
            max_length (`int`):
                maximum possible length for auto-regressive decoding. Defines the sequence length of the initialized
                cache.
        r   r!   r   FT)r   r~   rb   )	r)   onesr   r   r   r-   r   PRNGKeyr   )rX   r4   rv   r   r   init_variabless         r?   r~   z#FlaxBloomPreTrainedModel.init_cache  sm     HHj*5TB	y1))JJq!9n%\` * 
 w/00rA   past_key_valuesr   trainr   output_hidden_statesr   c
                 b   ||n| j                   j                  }||n| j                   j                  }|	|	n| j                   j                  }	|j                  \  }
}|t        j                  |
|f      }i }|||d<   d|xs | j                  i}|r	||d<   dg}nd}| j                  j                  |t        j                  |d      t        j                  |d      | d|||	||
      }||	r|\  }}t        |d         |d<   |S |"|	s |\  }}|d d	 t        |d         fz   |d	d  z   }|S )
Nr   r   rb   Fr   r!   )r   mutabler   r   )rD   r   r   use_return_dictr%   r)   r   r   r   applyr*   r   )rX   r   r   r   r   r   r   r   r   r   r4   sequence_lengthr   inputsr   r   s                   r?   r   z!FlaxBloomPreTrainedModel.__call__  sz    2C1N-TXT_T_TqTq$8$D $++JjJj 	 &1%<k$++B]B]&/oo#
O! XXz?&CDN ")DOF1dkk2
 -F7OiGG++##IIit,IInD1I  $ 
 &;'.$G_)1/'2J)KG%&N('.$G_bqkXog.F%G$IIGTUTVKWGrA   r   )NNNNFNNN)r   r   r   __doc__r   config_classbase_model_prefixr   rN   Moduler   r)   r+   r   intr   r   r   r-   r   r   r   r   r~   r   BLOOM_INPUTS_DOCSTRINGdictr   r   __classcell__)r   s   @r?   r   r     s7   
 L%"L"))"
 $;;
m
m 
m 	
m
 yy
m 
m!

 2 2 ! !PZ !fp !&1$ ++AB  $*.,0/3&*= 	=
 = ZZ''= = $D>= 'tn= d^= C=rA   r   c            	       x    e Zd ZU eed<   ej                  Zej                  ed<   d Z	 	 	 	 	 d
de	de	de	de	fd	Z
y)FlaxBloomBlockCollectionrD   r   c           	          t        | j                  j                        D cg c]-  }t        | j                  t	        |      | j
                        / c}| _        y c c}w )N)namer   )rangerD   num_hidden_layersr   strr   layers)rX   layer_numbers     r?   rY   zFlaxBloomBlockCollection.setup  sH     !&dkk&C&C D
 4;;S->djjQ
 
s   2ANr}   r~   r   r   c           	          |rdnd }|rdnd }	t        | j                  j                        D ]6  }
|r|	|fz  }	 | j                  |
   ||||||      }|d   }|s.||d   fz  }8 ||	|f}|S )Nrh   )r>   r   r}   r~   r   r   r   )r   rD   r   r  )rX   r]   r>   r   r}   r~   r   r   all_attentionsall_hidden_statesr  layer_outputsr   s                r?   r   z!FlaxBloomBlockCollection.__call__  s      1d"6BD!$++"?"?@ 	6L#!m%55!5DKK5-+%"3M *!,M =#3"55	6$ !"3^DrA   )NTFFFr   rh   rA   r?   r   r     s]    {{E399"
 " "'%*!
 ! !  ! #!rA   r   c            	       |    e Zd ZU eed<   ej                  Zej                  ed<   d Z	 	 	 	 	 	 	 d
de	de	de	de	fd	Z
y)FlaxBloomModulerD   r   c                 r   | j                   j                  | _        t        j                  | j                   j
                  | j                  t        j                  j                  j                  | j                   j                        | j                        | _        t        j                  | j                   j                  | j                        | _        t        | j                   | j                        | _        t        j                  | j                   j                  | j                        | _        y )Nstddev)embedding_initr   r   r!   )rD   rI   	embed_dimrN   Embed
vocab_sizer-   rP   rQ   rR   r   word_embeddingsr   r   word_embeddings_layernormr   hln_fr   s    r?   rY   zFlaxBloomModule.setup@  s    00  "xxKK""NN66..55T[[=Z=Z5[**	 
 *,dkk>\>\dhdndn)o& *$++TZZH LL)G)GtzzZ	rA   Nr~   r   r   r   c           	         | j                  |      }| j                  |      }	t        || j                  j                  |	j
                        }
| j                  |	|
|||||      }|d   }	| j                  |	      }	|r|d   |	fz   }|	|f|dd  z   }n	|	f|dd  z   }|st        d |d   |d   fD              S t        |	|d   |d         S )	Nr!   )r>   r   r}   r~   r   r   r   r   r    c              3   &   K   | ]	  }||  y wr   rh   ).0vs     r?   	<genexpr>z+FlaxBloomModule.__call__.<locals>.<genexpr>y  s     OqOs   r$   )last_hidden_stater]   
attentions)
r  r  r@   rD   rJ   r   r  r  rq   r   )rX   r   r   r}   r~   r   r   r   inputs_embedsr]   r>   r   r  s                r?   r   zFlaxBloomModule.__call__T  s    ,,Y766}E #>4;;3E3E]M`M`a&&)'!!5/  
  
		-0 '
m-= =$&78712;FG$&4GOWQZ$=OOO<+!!*r{
 	
rA   )NNTFFFTr   rh   rA   r?   r	  r	  <  sd    {{E399"[,  "'%* +

 +
  +
 #+
 +
rA   r	  z_The bare Bloom Model transformer outputting raw hidden-states without any specific head on top.c                       e Zd ZeZy)FlaxBloomModelN)r   r   r   r	  r   rh   rA   r?   r  r    s	     #LrA   r  c                   |    e Zd ZU eed<   ej                  Zej                  ed<   d Z	 	 	 	 	 dde	de	de	de	de	f
d	Z
y
)FlaxBloomForCausalLMModulerD   r   c                 @   t        | j                  | j                        | _        t	        j
                  | j                  j                  d| j                  t        j                  j                  j                  | j                  j                              | _        y )Nr!   Fr  )use_biasr   rG   )r	  rD   r   r   rN   rO   r  r-   rP   rQ   rR   lm_headr   s    r?   rY   z FlaxBloomForCausalLMModule.setup  se    *4;;djjIxxKK""**++22$++:W:W2X	
rA   r}   r~   r   r   r   c           	      x   | j                  |||||||      }|d   }	| j                  j                  rJ| j                   j                  d   d   d   j                  }
| j
                  j                  dd|
ii|	      }n| j                  |	      }|s	|f|dd  z   S t        ||j                  |j                        S )	N)r   r}   r~   r   r   r   r   r   r  	embeddingkernelr   )logitsr]   r  )
r   rD   tie_word_embeddingsr   Tr#  r   r   r]   r  )rX   r   r   r}   r~   r   r   r   r   r]   shared_kernel	lm_logitss               r?   r   z#FlaxBloomForCausalLMModule.__call__  s     "")'!/!5# # 
  
;;** ,,66x@ARST_`bbM**Hx6O+PR_`I]3I<'!"+--!'BWBWdkdvdvwwrA   N)TFFFTr   rh   rA   r?   r   r     sm    {{E399"
 # "'%* x 	x
 x  x #x xrA   r   z
    The Bloom Model transformer with a language modeling head on top (linear layer with weights tied to the input
    embeddings).
    c                   >    e Zd ZeZddeej                     fdZd Z	y)FlaxBloomForCausalLMNr   c                     |j                   \  }}| j                  ||      }t        j                  ||fd      }|t	        j
                  ||d      }||dS )Nr   r!   )r   r   )r   r   )r%   r~   r)   r   r   ro   )rX   r   rv   r   r4   r5   r   extended_attention_masks           r?   prepare_inputs_for_generationz2FlaxBloomForCausalLM.prepare_inputs_for_generation  sh    !*
J//*jA
 #&((J
+C4"P%&)&>&>?VXfhn&o#  /5
 	
rA   c                 $    |j                   |d<   |S )Nr   )r   )rX   model_outputsmodel_kwargss      r?   update_inputs_for_generationz1FlaxBloomForCausalLM.update_inputs_for_generation  s    *7*G*G&'rA   r   )
r   r   r   r   r   r   r-   Arrayr0  r4  rh   rA   r?   r-  r-    s'     .L
S[\_\e\eSf 
$rA   r-  )?r   r&   	functoolsr   typingr   r   
flax.linenlinenrN   r-   	jax.numpynumpyr)   flax.core.frozen_dictr   r   r   r	   r
   r   flax.linen.activationr   flax.traverse_utilr   r   r   modeling_flax_outputsr   r   r   modeling_flax_utilsr   r   utilsr   r   r   configuration_bloomr   
get_loggerr   logger_CHECKPOINT_FOR_DOC_CONFIG_FOR_DOCBLOOM_START_DOCSTRINGr   r+   ndarrayr   r   r@   r   rC   r   r   r   r   r   r	  r  r   r-  rh   rA   r?   <module>rI     s      "  
  > > U U & ;  
 U Y Y , 
		H	%( ! F < bealal '%s{{ '%s '%8TWT]T]K^ '%TV VrO		 O299 4;RYY ;|y2 yx+ryy +\C
bii C
L e
#- #
# ^-@BUWf g,x ,x^  3 4 13FHZ\k lrA   