
    6bi&                       S r SSKrSSKrSSKrSSKrSSKJs  Jr  SSK	J
r
  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r"  SSK#J$r$  SSK#J%r%  SSK#J&r&  SSK'J(r)  SSK*J+r+   " S S\RX                  5      r-S r.S r/S r0S r1S r2S r3S r4S&S  jr5S&S! jr6S" r7 " S# S$\Rp                  5      r9S% r:g)'zHA `Network` is way to compose layers: the topological form of a `Model`.    N)backend)
layout_map)
base_layer)base_layer_utils)functional_utils)input_layer)
input_spec)node)training)training_utils)serialization_lib)serialization)
json_utils)network_serialization)utils)generic_utils)
tf_inspect)tf_utils)
tf_logging)doc_controlsc                     ^  \ rS rSrSr\" \R                  " S\R                  R                  5      5      r
\R                  R                  R                  S$U 4S jj5       r\R                  R                  R                  S 5       r\S 5       r\S 5       r\S 5       r\R*                  S	 5       r\S
 5       r\S 5       rS r\S 5       rS%U 4S jjrS&U 4S jjrS r\S 5       rS r\R@                  S'S j5       r!S r"S(S jr#S'S jr$S r%S r&\'RP                  S 5       r)S r*S r+S&S jr,S r-S r.S r/S  r0\S! 5       r1S)U 4S" jjr2S#r3U =r4$ )*
Functional1   a
  A `Functional` model is a `Model` defined as a directed graph of layers.

Three types of `Model` exist: subclassed `Model`, `Functional` model,
and `Sequential` (a special case of `Functional`).
In general, more TF-Keras features are supported with `Functional`
than with subclassed `Model`s, specifically:

- Model cloning (`keras.models.clone`)
- Serialization (`model.get_config()/from_config`, `model.to_json()`
- Whole-model saving (`model.save()`)

A `Functional` model can be instantiated by passing two arguments to
`__init__`. The first argument is the `keras.Input` Tensors that represent
the inputs to the model. The second argument specifies the output
tensors that represent the outputs of this model. Both arguments can be a
nested structure of tensors.

Example:

```
inputs = {'x1': keras.Input(shape=(10,)), 'x2': keras.Input(shape=(1,))}
t = keras.layers.Dense(1, activation='relu')(inputs['x1'])
outputs = keras.layers.Add()([t, inputs['x2'])
model = keras.Model(inputs, outputs)
```

A `Functional` model constructed using the Functional API can also include
raw TensorFlow functions, with the exception of functions that create
Variables or assign ops.

Example:

```python
inputs = keras.Input(shape=(10,))
x = keras.layers.Dense(1)(inputs)
outputs = tf.nn.relu(x)
model = keras.Model(inputs, outputs)
```

A new `Functional` model can also be created by using the
intermediate tensors. This enables you to quickly extract sub-components
of the model.

Example:

```python
inputs = keras.Input(shape=(None, None, 3))
processed = keras.layers.RandomCrop(width=32, height=32)(inputs)
conv = keras.layers.Conv2D(filters=2, kernel_size=3)(processed)
pooling = keras.layers.GlobalAveragePooling2D()(conv)
feature = keras.layers.Dense(10)(pooling)

full_model = keras.Model(inputs, feature)
backbone = keras.Model(processed, conv)
activations = keras.Model(conv, feature)
```

Note that the `backbone` and `activations` models are not
created with `keras.Input` objects, but with the tensors that are originated
from `keras.Input` objects. Under the hood, the layers and weights will
be shared across these models, so that user can train the `full_model`, and
use `backbone` or `activations` to do feature extraction.
The inputs and outputs of the model can be nested structures of tensors as
well, and the created models are standard `Functional` model that support
all the existing API.

Args:
  inputs: List of input tensors (must be created via `tf.keras.Input()` or
    originated from `tf.keras.Input()`).
  outputs: List of output tensors.
  name: String, optional. Name of the model.
  trainable: Boolean, optional. If the model's variables should be
    trainable.
)_layer_call_argspecs_output_mask_cache_output_tensor_cache_output_shape_cachec                   > UR                  SS5      nU(       a  g [        R                  " U0 5        [        TU ]  X4S9  [
        R                  R                  R                  5       (       aj  [        [
        R                  R                  U5       Vs/ s H  n[        R                  " U5      PM     sn5      (       d  [        R                  " X5      u  pU R                  X5        g s  snf )N	skip_initFname	trainable)popr   validate_kwargssuper__init__tfcompatv1#executing_eagerly_outside_functionsallnestflattenr   is_input_keras_tensorclone_graph_nodes_init_graph_network)	selfinputsoutputsr!   r"   kwargsr   t	__class__s	           X/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/engine/functional.pyr&   Functional.__init__   s     JJ{E2	%%fb1d8
 99<<;;==  WW__V44 %::1=4  #3"D"D# 	  1s    C)c                 
   SU l         [        U[        5      (       a1  [        [        R
                  R                  U5      5      S:X  a  US   n[        U[        5      (       a1  [        [        R
                  R                  U5      5      S:X  a  US   nXl        X l        [        R
                  R                  U5      U l	        [        R
                  R                  U5      U l
        [        R
                  R                  U R                  5      (       d  SU l        O[        U R                  [        [        45      (       a)  [        S U R                   5       5      (       d  SU l        O][        U R                  [        5      (       a7  [        S U R                  R!                  5        5       5      (       d  SU l        OSU l        [        R"                  R$                  R'                  5       (       dA  [        S U R                   5       5      (       a   [(        R*                  " U R                  5        U R-                  5         SU l        [        R
                  R1                  S U5      U l        SU l        SU R6                  l        SU R6                  l        SU l        / U l        / U l         / U l!        / U l"        0 U l#        0 U l$        0 U l%        U R                   HK  nURL                  u  nnnU R@                  RO                  U5        U RD                  RO                  XEU45        MM     U R                   H[  nURL                  u  nnnUS:X  d   eUS:X  d   eU R>                  RO                  U5        U RB                  RO                  XEU45        M]     [Q        U R                  U R                  5      u  pxpXpl)        Xl*        Xl+        0 U l,        U RV                   H0  n[Z        R\                  " UR^                  5      U RX                  U'   M2     U Ra                  5         / U l1        / U l2        / U l3        / U l4        U R>                   H  nU Rb                  RO                  URj                  5        URl                  (       d  M;  U Rd                  RO                  URj                  5        U Rh                  RO                  URn                  5        U Rf                  RO                  URp                  5        M     U Rs                  5         U Ru                  U R                  5        [v        Rx                  " U Rz                  5        U R|                  b!  [~        R                  " X R|                  5        g g )	NT   r   c              3   `   #    U  H$  n[         R                  R                  U5      v   M&     g 7fNr'   r,   	is_nested.0r5   s     r7   	<genexpr>1Functional._init_graph_network.<locals>.<genexpr>   s'      H
*=QBGGa  *=   ,.c              3   `   #    U  H$  n[         R                  R                  U5      v   M&     g 7fr<   r=   r?   s     r7   rA   rB      s&      ?
*FQBGGa  *FrC   Fc              3   D   #    U  H  n[        US 5      (       + v   M     g7f)_keras_historyN)hasattrr@   tensors     r7   rA   rB      s!      DP&GF$4555Ls    c                     U R                   $ r<   )shape)xs    r7   <lambda>0Functional._init_graph_network.<locals>.<lambda>   s    agg    )A_is_graph_network
isinstancelistlenr'   r,   r-   _nested_inputs_nested_outputsr2   r3   r>   _enable_dict_to_input_mappingtupleanydictvaluesr(   r)   r*   r   create_keras_history"_validate_graph_inputs_and_outputsbuiltmap_structure_build_input_shape _compute_output_and_mask_jointly
_call_specexpects_training_argexpects_mask_arg	_autocast_input_layers_output_layers_input_coordinates_output_coordinatesr   r   r   rF   append_map_graph_network_network_nodes_nodes_by_depth_self_tracked_trackablesr   r   getfullargspeccall_set_output_namesinput_names_feed_input_names_feed_inputs_feed_input_shapesr!   is_placeholder_batch_input_shapeinput_compute_tensor_usage_count_set_save_specr   assert_no_legacy_layerslayers_layout_maplayout_map_lib_map_functional_model_variable)r1   r2   r3   rL   layer
node_indextensor_indexnodesnodes_by_depthr{   _s              r7   r0   Functional._init_graph_network   sy   
 "& fd##BGGOOF,C(D(IAYFgt$$RWW__W-E)F!)KajG$&ggoof-www/
 ww  !4!45515D.++dE];;C H
*.*=*=H
 E
 E
 26D.++T223 ?
*.*=*=*D*D*F?
 <
 <
 26D.16D.yy||??AA DHLL   !55d6J6JK//1 
"$''"7"7v#
 15- 04,+/(  "$#%  #%$&!#%  A
   	&&u-$$++U,MN  A
   	 ?"?1$$$%%e,##**E|+LM  ,>KK,
(v $-(.%$&!22E/9/H/H

0D%%e, 3 	 !#"$''E##EJJ/###&&--ejj9 ''..u/G/GH!!((5 ( 	((*D//0((5
 '99&& (rO   c                     U R                   $ )a&  Retrieves the input tensor(s) of a layer.

Only applicable if the layer has exactly one input,
i.e. if it is connected to one incoming layer.

Returns:
    Input tensor or list of input tensors.

Raises:
  RuntimeError: If called in Eager mode.
  AttributeError: If no inbound nodes are found.
)rT   r1   s    r7   rw   Functional.input3  s     """rO   c                 r    [         R                  R                  [        R                  U R
                  5      $ )a  Retrieves the input shape(s) of a layer.

Only applicable if the layer has exactly one input,
i.e. if it is connected to one incoming layer, or if all inputs
have the same shape.

Returns:
    Input shape, as an integer shape tuple
    (or list of shape tuples, one tuple per input tensor).

Raises:
    AttributeError: if the layer has no defined input_shape.
    RuntimeError: if called in Eager mode.
)r'   r,   r^   r   	int_shaperw   r   s    r7   input_shapeFunctional.input_shapeC  s%      ww$$W%6%6

CCrO   c           	         [        U S5      (       a  U R                  $ [        U R                  [        [
        [        45      (       a-  [        U R                  5      [        U R                  5      :w  a  g [        U R                  [        5      (       a`  [        U R                  R                  5       5      nU Vs/ s H/  n[        R                  " [        U R                  U   5      SUS9PM1     sn$ U R                   Vs/ s H@  n[        R                  " [        U5      SUR                  R                  R                   S9PMB     sn$ s  snf s  snf )N_manual_input_specT)rK   allow_last_axis_squeezer!   )rG   r   rQ   rT   rY   rR   rW   rS   r2   sortedkeysr	   	InputSpecshape_with_no_batch_sizerF   r   r!   )r1   namesr!   rL   s       r7   r	   Functional.input_specU  s3   4-..***d))D$+>??CE
E
 d))4004..3356E " "D $$243F3Ft3LM,0
 " "  %A $$215,0))//44
 % s   ;6EAEc                     Xl         g r<   )r   )r1   values     r7   r	   r   v  s    "'rO   c                     U R                   $ )aI  Retrieves the output tensor(s) of a layer.

Only applicable if the layer has exactly one output,
i.e. if it is connected to one incoming layer.

Returns:
  Output tensor or list of output tensors.

Raises:
  AttributeError: if the layer is connected to more than one incoming
    layers.
  RuntimeError: if called in Eager mode.
)rU   r   s    r7   outputFunctional.outputz  s     ###rO   c                 r    [         R                  R                  [        R                  U R
                  5      $ )ac  Retrieves the output shape(s) of a layer.

Only applicable if the layer has one output,
or if all outputs have the same shape.

Returns:
    Output shape, as an integer shape tuple
    (or list of shape tuples, one tuple per output tensor).

Raises:
    AttributeError: if the layer has no defined output shape.
    RuntimeError: if called in Eager mode.
)r'   r,   r^   r   r   r   r   s    r7   output_shapeFunctional.output_shape  s%     ww$$W%6%6DDrO   c                 B   / n[        5       n0 nU R                   H{  nUR                  nXR;   aE  UR                  UR                  S5      nUR                   SU 3nUS-   X4R                  '   XR;   a  ME  UR	                  U5        UR                  U5        M}     Xl        g)zAssigns unique names to the Network's outputs.

Output layers with multiple output tensors would otherwise lead to
duplicate names in self.output_names.
r:   r   N)setrf   r!   getaddri   output_names)r1   
uniquifiedr   prefix_countr   proposalexisting_counts          r7   rp   Functional._set_output_names  s     
u((EzzH*!-!1!1%**a!@#jj\>*:;+9A+=ZZ( * X&h' ) 'rO   c                     Sn[         R                  " 5       n[        U R                  5       H+  u  p4 UR                  (       a  UUSU-  '   US-  nXBSU-  '   M-     U$ ! [
         a     Nf = f)zBDictionary of layer dependencies to be included in the checkpoint.r   zlayer_with_weights-%dr:   zlayer-%d)collectionsOrderedDict	enumerater{   weights
ValueError)r1   weight_layer_indexdependencieslayer_indexr   s        r7   _layer_checkpoint_dependencies)Functional._layer_checkpoint_dependencies  s     "..0"+DKK"8K==  !/2DD '!+& 6;k12# #9$    s   A
A+*A+c                 `   > U R                   nUR                  [        TU ]  " U40 UD65        U$ r<   )r   updater%   _trackable_children)r1   	save_typer4   r   r6   s       r7   r   Functional._trackable_children  s1    ::EG7	LVLMrO   c                 |   > U(       a  UR                  U5      $ U R                  nX;   a  X1   $ [        TU ]  U5      $ r<   )r   r   r%   _lookup_dependency)r1   r!   cached_dependencieslayer_dependenciesr6   s       r7   r   Functional._lookup_dependency  sD    &**400 "@@%%++w)$//rO   c                     U R                   nUR                  5        VVs0 s H  u  p4XC_M	     nnnU H  nXe;   d  M
  U R                  XV   US9  M     gs  snnf )z@Handles layer checkpoint dependencies that are added after init.)r!   	trackableN)r   items_handle_deferred_dependencies)r1   r{   layer_checkpoint_dependencieskvlayer_to_namer   s          r7   #_handle_deferred_layer_dependencies.Functional._handle_deferred_layer_dependencies  sb    (,(K(K%*G*M*M*OP*O$!*OPE%22&- 3   Qs   Ac                     gNT r   s    r7   _should_compute_maskFunctional._should_compute_mask  s    rO   c                 b    U R                  XS9n[        R                  R                  S U5      $ )N)maskc                     [        U SS 5      $ )N_keras_mask)getattr)r5   s    r7   rM   )Functional.compute_mask.<locals>.<lambda>  s    ga5rO   )_run_internal_graphr'   r,   r^   )r1   r2   r   output_tensorss       r7   compute_maskFunctional.compute_mask  s3     11&1Dww$$5~
 	
rO   c                 "    U R                  XUS9$ )a,  Calls the model on new inputs.

In this case `call` just reapplies
all ops in the graph to the new inputs
(e.g. build a new computational graph from the provided inputs).

Args:
    inputs: A tensor or list of tensors.
    training: Boolean or boolean scalar tensor, indicating whether to
        run the `Network` in training mode or inference mode.
    mask: A mask or list of masks. A mask can be
        either a tensor or None (no mask).

Returns:
    A tensor if there is a single output, or
    a list of tensors if there are more than one outputs.
)r   r   )r   )r1   r2   r   r   s       r7   ro   Functional.call  s    & '''MMrO   c                 F   [         R                  " USS9n[        [        R                  R                  U5      5      [        [        R                  R                  U R                  5      5      :w  a%  [        SU S[        U R                  5       S35      e [        [         R                  " USS95      nX R                  ;   a  U R                  U   $  0 n[        U R                  [        R                  R                  U5      5       H  u  pEUR                  S-   nXSU'   M     [        U R                  R                  5       5      nUR                  SS9  [        U5      S	:  Ga(  U GH  nU R                  U   n	U	 GHl  n
U
R                   nX@R                  ;   a  M!  / nU
R"                  S
   n[        R                  R                  U5       HW  nUR$                  nUR                   R                  SUR&                  < SUR(                  < 3-   nUR+                  X?   5        MY     [        R                  R-                  X5      n[         R                  " USS9nUR/                  U5      n[         R                  " USS9nUR0                  R3                  U
5      n[5        [        R                  R                  U5      5       H  u  nnUR                  SU SU 3-   nXSU'   M!     GMo     GM     / n[7        [        U R8                  5      5       H>  nU R:                  U   u  nnnUR                  SU SU 3-   nUR+                  X6   5        M@     [        R                  R-                  U R<                  U5      nUU R                  W'   W$ ! [         a     GNf = f)NF)	to_tupleszInvalid `input_shape` argument z: the model expects z input tensors.T_0_0reverser:   r   r   )r   convert_shapesrS   r'   r,   r-   re   r   rW   r   zipr!   rR   rl   r   sortr   	call_argsrF   r   r   ri   pack_sequence_ascompute_output_shape_inbound_nodesindexr   rangerf   rh   rU   )r1   r   	cache_keylayers_to_output_shapesr   rK   	shape_key
depth_keysdepthr   r
   layer_input_shapeslayer_inputslayer_inputkhinput_layer_keylayer_output_shapesr   joutput_shapesir   s                         r7   r   Functional.compute_output_shape  sm   --kUKrww{+,GGOOD../1
 
 1+ ?%%(););%<$= >!! 
	''tDI 444//	:: 5 #% <
LE
 

V+I16I.
 $..3356
%z?Q#,,U3!D JJE 2 22 !)+&#'>>!#4L')ww|'D(77*,((--MMOO; + +113D (E *,)A)A$*&
 *2)@)@*d*& +0*D*D*+' +3*A*A+u+' "'!5!5!;!;D!AJ$-(;<%5 %*JJ1ZL!1E$E	=B	:	%G " $X M3t2234262J2J12M/z<!JJ1ZL,)HH	$$%<%GH 5 GG44$$mM 3@D$$Y/ U  	 	s   ;N 
N N c                     U(       d[  U R                   R                  nU R                   [        :X  a  Sn[        R                  " [
        R                  " U5      US9U l        g Xl        g )NModel)
zero_based)r6   __name__r   r   unique_object_namer   to_snake_case_name)r1   r!   r   cls_names       r7   _init_set_nameFunctional._init_set_namef  sP    ~~..H~~+ # 33++H5*DJ JrO   c                 T  ^ U R                  U5      nUc  S/[        U5      -  nOU R                  U5      n[        X5       H  u  pSX5l        M     0 mU R                  n[        U R
                  U5       H3  u  pxU R                  XS9n[        [        U5      5      n	U/Xi   -  TU	'   M5     U R                  n
[        U
R                  5       5      nUR                  SS9  U H  nX   nU H  nUR                  (       a  M  [        U4S jUR                   5       5      (       a  M<  UR!                  T5      u  nnUR"                  " U0 UD6n[        UR$                  [&        R(                  R+                  U5      5       H  u  pU/Xi   -  TU	'   M     M     M     / nU R,                   HR  n[        [        U5      5      n	U	T;   d   S[        U5      -   5       eUR/                  TU	   R1                  5       5        MT     [&        R(                  R3                  U R4                  U5      $ )a  Computes output tensors for new inputs.

# Note:
    - Can be run on non-Keras tensors.

Args:
    inputs: Tensor or nested structure of Tensors.
    training: Boolean learning phase.
    mask: (Optional) Tensor or nested structure of Tensors.

Returns:
    output_tensors
N)	ref_inputTr   c              3   ,   >#    U  H	  oT;  v   M     g 7fr<   r   )r@   t_idtensor_dicts     r7   rA   1Functional._run_internal_graph.<locals>.<genexpr>  s     O;N4;.;Ns   zCould not compute output )_flatten_to_reference_inputsrS   r   r   _tensor_usage_countr2   _conform_to_reference_inputstridrl   rR   r   r   is_inputrX   flat_input_idsmap_argumentsr   flat_output_idsr'   r,   r-   r3   ri   r#   r   rU   )r1   r2   r   r   masksinput_ttensor_usage_countrL   yx_idr   r   r   r   r
   argsr4   r3   r   r  s                      @r7   r   Functional._run_internal_graphs  s    226:<FS[(E55d;E /MG"& 0 !55V,DA000@Ar!u:D!"&8&> >K -
 --.--/0
%E")E==O4;N;NOOO#11+>f**d5f5  #(("''//'*B GD *+.@.F(FK%    $ Ar!u:D;&L(Cc!f(LL&!!+d"3"7"7"9: 
 ww''(<(<nMMrO   c           	      2   U R                   (       Ga)  [        U[        5      (       Ga  U R                  n[        R
                  R                  U5      (       d  U R                  /n[        U[        5      (       a  [        UR                  5       5      nO/U Vs/ s H"  oDR                  R                  R                  PM$     nn[        U5      [        U5      :  aJ  [        R                  " SR                  UR                  5        Vs/ s H  oUU;  d  M
  UPM     sn5      SS9   U Vs/ s H  oQU   PM	     sn$ [        R
                  R#                  U5      $ s  snf s  snf s  snf ! [          a"    [        R
                  R#                  U5      s $ f = f)z1Maps `tensors` to their respective `keras.Input`.zdInput dict contained keys {} which did not match any model input. They will be ignored by the model.   )
stacklevel)rV   rQ   rY   rT   r'   r,   r>   r   r   rF   r   r!   rS   warningswarnformatKeyErrorr-   )r1   tensors
ref_inputsref_input_namesinpns         r7   r  'Functional._flatten_to_reference_inputs  sN   ---*Wd2K2K,,J77$$Z00"112
*d++ #)):"; >H#=Gc&&,,11Z   # 7|c/22FFLf$+LLNONq6NNOG  !0 -<<Oq
O<< www''1# P = 0www//0s6   )E		E E 'E* +E%9E* %E* *)FFc                    [        U[        R                  5      (       a  UR                  nUR                  nUR                  nUR                  n[        USS5      nUbP  UbM  XFS-   :X  a  US   S:X  a  [        R                  " USS9nO&XFS-
  :X  a  US   S:X  a  [        R                  " USS9nUb  Xql        [        R                  " XR                  S9nU$ [        R                  " U5      (       aM  [        USS5      n[        USS5      n	U	b0  Ub-  X:w  a(  U	[        R                  :w  a  [        R                  " XS9nU$ )z,Set shape and dtype based on `keras.Input`s.rF   Nr:   )axisdtyper&  )rQ   r'   TensorrK   rankr   squeezeexpand_dimsrF   castr&  r   is_extension_typevariant)
r1   rI   r   t_shapet_rank	ref_shaperef_rankkeras_historytensor_dtyperef_input_dtypes
             r7   r  &Functional._conform_to_reference_input  s*   fbii(( llG\\F!I ~~H#F,<dCM!h&: \)gbkQ.>ZZR8F !|+	"0B^^F<F((5% WWV??;F  ''// #67D9L%i$?O+ , 3#rzz1?rO   c                    U R                   U R                  S.n[        R                  " 5       (       a  [        R
                  " [        XS95      $ [        U R                  5      (       a  [        R
                  " [        XS95      nU$ [        UR                  5       5      n[        U SS5      (       a%  UR                  U R                  R                  5        [        R                   " U R"                  5      nUR$                  S:w  a9  X"R'                  UR(                  SS  5      -
   H  nUR+                  US 5        M     U$ )Nr    )config_auto_get_configFr4   r:   )r!   r"   saved_model_utilsin_tf_saved_model_scopecopydeepcopyget_network_confighas_functional_like_constructorr6   r   r   r   r   _auto_configr7  r   rn   r&   varkwintersectionr  r#   )r1   r7  	xtra_argsargspeckeys        r7   
get_configFunctional.get_config  s     II

 4466 ==!3D!HII +4>>:: ]]#5d#JKF  FKKM*It/77d//667 //>G}}($'='=gll12>N'OOCJJsD) PrO   c                    0 nU R                    H  n[        R                  R                  R	                  U5      R                  5       u  nnU Hg  n[        U[        R                  5      (       d  M$  XE   nSR                  U Vs/ s H  owR                  PM     sn5      nXQUR                  S-   U-   '   Mi     M     U$ s  snf )N.)
r{   r'   __internal__trackingObjectGraphViewbreadth_first_traversalrQ   Variablejoinr!   )	r1   resultr   descendantsobject_paths_dict
descendanttrackable_referencesr5   object_paths	            r7   get_weight_pathsFunctional.get_weight_paths  s    [[E ((88%%'! *
j"++66+<+H("%(()=>)=A)=>#K >H5::+k9: * !  ?s   B?c           
      |   [        U R                   Vs1 s H  n[        U5      iM     sn5      [        U R                  5      :w  a  [        SU R                   35      eU R                   H  n[	        US5      (       d(  U R
                  R                  n[        SU SU S35      eUR                  R                  n[        UR                  5      S:  d3  UR                  (       d  M~  UR                  S   R                  (       a  M  U R
                  R                  n[        R                  " U SU R                   S	UR                   S
U 35        M     [        U R                   Vs/ s H-  n[        R                   " UR                  R                  5      PM/     sn5      nUR#                  S5        [        U5      S:  a"  [        R                  " S[%        U5       35        U R&                   H;  n[	        US5      (       a  M  U R
                  R                  n[        SU SU 35      e   gs  snf s  snf )z4Validates the inputs and outputs of a Graph Network.zThe list of inputs passed to the model contains the same input multiple times. All inputs should only appear once.Received inputs=rF   zInput tensors to a z8 model must come from `tf.keras.Input`. Received inputs=z# (missing previous layer metadata).r:   r   z model inputs must come from `tf.keras.Input` (thus holding past layer metadata). They cannot be the output of a previous non-Input layer. Here, a tensor specified as input to "z6" was not an Input tensor, it was generated by layer "zx".
Note that input tensors are instantiated via `tensor = tf.keras.Input(shape)`.
The tensor that caused the issue was: NzEFound incompatible static batch sizes among the inputs. Batch sizes: zOutput tensors of a z] model must be the output of a TensorFlow `Layer` (thus holding past layer metadata). Found: )rS   r2   r	  r   rG   r6   r   rF   r   r   r
  loggingwarningr!   r   r   get_static_batch_sizediscardr   r3   )r1   r   rL   r   r   input_batch_sizess         r7   r\   -Functional._validate_graph_inputs_and_outputs1  s#    t{{+{!1{+,DKK0@@# $(;;-1  A1.//>>22 )( 4''(c)LN  $$**E5''(1,$$$U-A-A!-D-M-M-M>>22j !!
 "& ,227** >= >?C	A! <   $A 44Q5E5E5K5KL$
 	!!$' !A%OO((./@(A'BD
 A1.//>>22 *8* 5BBCF  g ,Ns   H4+4H9c                 J  ^^ [         R                  R                  U5      n[        R                  " U5        0 mU R
                  R                  5        H'  u  p4TR                  U Vs0 s H  oUU_M     sn5        M)     U(       d9  [         R                  R                  U Vs/ s H  ofR                  PM     sn5      n[        U[        TR                  5       5      -   5      mUU4S jn[        R                  " U5      nSn	U(       a  U	S-  n	U	S:  a  [        S5      eUR                  S5      nU" U5      nUc  UR                  U5        ML  [!        UR"                  R$                  UR"                  R                  R'                  U5      5      n
XR(                  ;  a>  UTU'   U R(                  R+                  U
5        U R
                  U   R                  U5        U(       a  M  [        U R,                  5      n/ nU Ht  nXk;  d  M
  U R,                  R                  U5        UR                  U5        [.        R0                  " UR2                  5      U R4                  U'   UR+                  U5        Mv     U R7                  U5        U R9                  5         gs  snf s  snf )a  Inserts Layers into the Network after Network creation.

This is only valid for TF-Keras Graph Networks.  Layers added via this
function will be included in the `call` computation and `get_config` of
this Network.  They will not be added to the Network's outputs.

Args:
  layers: Arbitrary nested structure of Layers. Layers must be reachable
    from one or more of the `keras.Input` Tensors that correspond to
    this Network's inputs.
  relevant_nodes: Nodes from the Layers that should be considered part
    of this Network. If `None`, all Nodes will be considered part of
    this Network.

Raises:
  ValueError: If the layers depend on `Input`s not found in this Model.
c                    > SnU R                  5        H5  u  p#  nUR                  U   nUT;   a  [        UTU   5      nM-  UT;  a  M5    g   US-
  $ )z5Gets the minimum depth at which node can be computed.r   Nr:   )iterate_inboundr   min)r
   	min_depthr   node_idr   inbound_nodenetwork_nodesnode_to_depths         r7   _get_min_depth1Functional._insert_layers.<locals>._get_min_depth  sg    I(,(<(<(>$1$33G<=0 #I}\/J KI!6   )? q= rO   r   r:   i'  z6Layers could not be added due to missing dependencies.N)r'   r,   r-   r   rz   rl   r   r   r   r   rR   r   r;  r   r#   ri   _make_node_keyr   r!   r   rk   r   rm   r   rn   ro   r   r   rx   )r1   r{   relevant_nodesr   r   r
   r   rg  unprocessed_nodesr   node_key	layer_setdeferred_layersre  rf  s                @@r7   _insert_layersFunctional._insert_layersp  s<   $ (((0 00668LE  %!@%$+%!@A 9 WW__39:6%%%6:N NT-2D2D2F-GGH	!  !IIn5FA 5y L  %((+D"4(E}!((.%

!:!:!@!@!FH 222&+d###''1$$U+2248)  . 556	E%--44U;&&u-3=3L3LJJ4))%0 e$  	00A((*} "A
 ;s   (J
#J c           
         [         R                  " 5       n[        S U R                   5       5      n[	        U R
                  R                  5       5      nUR                  SS9  USS nU GH!  nU R
                  U    GH	  n[        R                  R                  UR                  5       Vs1 s H  n[        [        U5      5      iM     nnUR                  U5      (       d  Mg  [        R                  R                  UR                  5       H"  nU[        [        U5      5      ==   S-  ss'   M$     [        R                  R                  UR                  5       H&  nUR!                  [        [        U5      5      5        M(     GM     GM$     U R                   H"  nU[        [        U5      5      ==   S-  ss'   M$     Xl        gs  snf )a  Compute the #. of tensor usages for all the output tensors of layers.

The computed tensor usage count is saved as `self._tensor_usage_count`.
This is later used for saving memory in eager computation by releasing
no-longer-needed tensors as early as possible.
c              3   J   #    U  H  n[        [        U5      5      v   M     g 7fr<   )r  r	  rH   s     r7   rA   9Functional._compute_tensor_usage_count.<locals>.<genexpr>  s     JkFBvJks   !#Tr   r:   N)r   Counterr   r2   rR   rl   r   r   r'   r,   r-   keras_inputsr  r	  issubsetr3   r   r  )	r1   r  available_tensorsr   r   r
   rI   input_tensorsoutput_tensors	            r7   rx   &Functional._compute_tensor_usage_count  sk    )002JdkkJJ$..3356
%^
E,,U3 #%''//$2C2C"D!"D 6
O"D  ! !))*;<<"$''//$2C2C"D*3r&z?;q@; #E *,)F)--c"]2C.DE *G 4   llFs2f:/14/ # $6 !s   -G
c                     g r<   r   r   s    r7   _assert_weights_created"Functional._assert_weights_created  s     	rO   c                     [        U R                  U/5      u  p#[        R                  " SUR                  S9nU" U5        UR                  UR                  5        UR                  U5        U R                  X25        g )NF)unconditionalr&  )	_map_subgraph_networkr2   r   AddLossr&  extendinbound_nodesri   ro  )r1   symbolic_loss	new_nodes
new_layersadd_loss_layers        r7   _graph_network_add_loss"Functional._graph_network_add_loss  sq     5KK-!
	
 $++}':':
 	}%556.)J2rO   c                     [        U R                  U/5      u  pE[        R                  " X#UR                  S9nU" U5        UR                  UR                  5        UR                  U5        U R                  XT5        g )Nr%  )	r  r2   r   	AddMetricr&  r  r  ri   ro  )r1   r   aggregationr!   r  r  add_metric_layers          r7   _graph_network_add_metric$Functional._graph_network_add_metric  sm     5dkkE7 K	%//U[[
 	)778*+J2rO   c                 .    [         R                  " U 5      $ r<   )r   NetworkSavedModelSaverr   s    r7   _trackable_saved_model_saver'Functional._trackable_saved_model_saver  s    $;;DAArO   c                 J   > [        U SS5      (       a  Sn[        TU ]	  X5      $ )N_has_explicit_input_shapeTF)r   r%   _get_save_spec)r1   dynamic_batchinputs_onlyr6   s      r7   r  Functional._get_save_spec  s*    44d;; "Mw%mAArO   )rd   r_   r`   rV   rr   rt   rs   rg   re   rP   r   r   r   rT   rU   rk   rl   rh   rf   r   r   r   rm   r  r]   rq   r2   r   r3   r   )
checkpointr<   NN)T)TT)5r   
__module____qualname____firstlineno____doc__	frozenset	itertoolschaintraining_libr   _TF_MODULE_IGNORED_PROPERTIESr'   rI  rJ   no_automatic_dependency_trackingr&   r0   propertyrw   r   r	   setterr   r   rp   r   r   r   r   r   r   r   do_not_doc_inheritablero   r   r   r   r  r  r   defaultrE  rU  r\   ro  rx   r|  r  r  r  r  __static_attributes____classcell__r6   s   @r7   r   r   1   s   I^ %. <<	

%! __>>2 ?24 __>>H ?HT # # D D"  @ ( ( $ $  E E '&  2
0  
 ((N )N(`D:Nx&(P&P  >$=~T+l6@
33 B BB BrO   r   c                 $    U S-   [        U5      -   $ )Nz_ib-)r  )
layer_namer   s     r7   ri  ri    s    Z00rO   c                   ^ [        U5      u  nmU Vs1 s HF  n[        UR                  R                  UR                  R                  R                  U5      5      iMH     nn0 n0 n[        U5       H  nUR                  US5      nUR                  UR                  S5      n[        Xx5      nXvUR                  '   XuU'   UR                   H&  n	UR                  U	S5      n[        US-   U5      XY'   M(     M     U  HX  n
U
R                  S   nX;  d  M  SXk'   STU'   SX[R                  S   '   UR                  [        UR                  S5      5        MZ     [        R                  " [        5      nUR!                  5        H  u  p7X   R#                  U5        M     [        R                  " [        5      nUR!                  5        H  u  pX   R#                  U5        M     [        UR%                  5       5      nUR'                  SS9  / nU H+  nX   nUR'                  U4S jS9  UR)                  U5        M-     [        UR%                  5       5      nUR'                  SS9  [+        5       nU  H  nUR                  [-        U5      5        M     / nU H  nX    H  nUR                  nU(       d  M  UR.                  (       a  M+  [0        R2                  R5                  UR6                  5       H0  n[-        U5      U;  d  M  [9        SU S	UR                   S
U 35      e   [0        R2                  R5                  UR:                  5       H  nUR                  [-        U5      5        M     UR#                  UR                  5        M     M     U Vs/ s H  oR                  PM     nnU H9  nUR=                  U5      S:w  d  M  [9        SU SUR=                  U5       S35      e   XLUU4$ s  snf s  snf )a  Validates a network's topology and gather its layers and nodes.

Args:
  inputs: List of input tensors.
  outputs: List of outputs tensors.

Returns:
  A tuple `(nodes, nodes_by_depth, layers, layers_by_depth)`.
  - nodes: list of Node instances.
  - nodes_by_depth: dict mapping ints (depth) to lists of node instances.
  - layers: list of Layer instances.
  - layers_by_depth: dict mapping ints (depth) to lists of layer instances.

Raises:
  ValueError: In case the network is not valid (e.g. disconnected graph).
r   r:   r#  Tr   c                    > TU    $ r<   r   )rL   layer_indicess    r7   rM   $_map_graph_network.<locals>.<lambda>c  s
    M!,<rO   )rD  z3Graph disconnected: cannot obtain value for tensor z at layer "z>". The following previous layers were accessed without issue: z
The name "z
" is used z6 times in the model. All layer names should be unique.)
_build_mapri  r   r!   r   r   reversed
setdefaultr   maxparent_nodesrF   r   r   defaultdictrR   r   ri   r   r   r  r   r	  r
  r'   r,   r-   ru  r   r3   count)r2   r3   nodes_in_decreasing_depthr
   re  nodes_depthslayers_depthsr   previous_depthnode_depr  r   r   layers_by_depthr   r   r{   layers_for_depthcomputable_tensorsrL   layers_with_complete_input	all_namesr!   r  s                          @r7   rj   rj     s   & 0:'/B,} .-D 	tzz

(A(A(G(G(MN-  
 LM23''a0 '**4::q9
 E*$)djj!"T
 ))H)--h:N%(N%CL" *# 40 ,,Q/+)*M&)+M+&:;L33A67n[-=-=qAB  !,,T2N#))+$$T* , "--d3O%++-%%e, . o**,-JOODO! F*1 	"<=&'  n))+,JOODO!
 r!u%  "$")DJJEuT]]]):):;A!u$66(&&'SEJJ< @..H-IK  < 6A&**2a51 7*11%**= * $ *00I0??4 A%TF*Y__T-B,C DH H   &/AAIz 1s   AO3O8c                     [        5       n[        5       n/ n0 n[        R                  R                  U 5       H  n[	        UUUUU5        M     X44$ )a  This method topologically sorts nodes in order from inputs to outputs.

It uses a depth-first search to topologically sort nodes that appear in the
_keras_history connectivity metadata of `outputs`.

Args:
  outputs: the output tensors whose _keras_history metadata should be
    walked. This may be an arbitrary nested structure.

Returns:
  A tuple like (ordered_nodes, layer_to_first_traversal_index)
  ordered_nodes: list of nodes appearing in the keras history, topologically
    sorted from original inputs to the `outputs`.
    (If outputs have different sets of ancestors, the inputs to one output
    may appear after a different output).
  layer_to_first_traversal_index:
    A dict mapping layer to the traversal index in the DFS where it is
    seen. Note: if a layer is shared by several nodes, the dict will only
    store the index corresponding to the *first* time the layer seen.
)r   r'   r,   r-   _build_map_helper)r3   finished_nodesnodes_in_progressr  r  r   s         r7   r  r    sW    * UN "M''//'*%	
 + %33rO   c                    U R                   u  nnnUR                  U   nX;   a  gX;   a  [        SU  SUR                   S35      eXT;  a  [	        U5      XE'   UR                  U5        UR                  (       d"  UR                   H  n [        U UUUU5        M     UR                  U5        UR                  U5        UR                  U5        g)z"Recursive helper for `_build_map`.NzTensor z from layer "z" is part of a cycle.)rF   r   r   r!   rS   r   r
  ru  r  removeri   )	rI   r  r  r  r  r   r   r   r
   s	            r7   r  r    s     			
+D   fX]5::,6KL
 	

 !"=1 $==''F!) ( tT"$$T*rO   c                 ,   [         R                  R                  R                  5       (       d  [        R
                  " U5        [        X5      u  p#pB[         R                  R                  UR                  5        Vs/ s H  oUPM     sn5      U4$ s  snf )zReturns the nodes and layers in the topology from `inputs` to `outputs`.

Args:
  inputs: List of input tensors.
  outputs: List of output tensors.

Returns:
  A tuple of List{Node] and List[Layer].
)
r'   r(   r)   r*   r   r[   rj   r,   r-   rZ   )r2   r3   r   r   r{   r   s         r7   r  r    sm     99<<;;==--g6#5f#F Av77??~/D/D/FG/FeE/FGH&PPGs   =Bc                    [        U S5      (       d  [        U [        5      $ U R                  (       a>  [        U [        5      =(       a'    [        U R                  S   [        R
                  5      $ [        U [        5      $ )zCReturns True if the first layer node should not be saved or loaded.rm   r   )rG   rQ   r   rm   input_layer_module
InputLayer)r   s    r7   _should_skip_first_noder    sl    
 5455 %,,%%uj) ..q13E3P3P	
 %,,rO   c                 z   UR                  5        Vs/ s H  o"U R                  ;  d  M  UPM     nnU(       ax  [        R                  R	                  UR                  5        Vs/ s H.  n[        U5      (       a  UR                  SS OUR                  PM0     sn5      nU R                  X45        U $ s  snf s  snf )z?Adds layers that are not connected to the outputs to the model.r:   N)rZ   r{   r'   r,   r-   r  r  ro  )modelcreated_layersr   ancillary_layersrj  s        r7   connect_ancillary_layersr    s     *0022%5<<6O2   
 ,224	 5E +511 ##AB'(() 5	
 	->L
s   B3B3$5B8c                 0  ^^^^^^^ T=(       d    [         R                  " 5       m0 m0 m[         R                  " [        5      mU4S jmU4S jmUUUUU4S jnUUUU4S jnU S    H  nU" U5        M     T(       as  U S    Ha  nTUS      nUT;   d  M  TR	                  U5      nU(       d  M-  US   nU" Xh5      (       a  UR	                  S5        OUTU'   MX  U(       a  M4  Mc     T(       a  Ms  / n	/ n
[
        R                  " U S   S	S
9n[        R                  R                  U5       Hu  nUR                  5       u  pnUT;   d   eTU   nT" Xm5      nUR                  U   R                  nU	R                  [        R                  R                  U5      U   5        Mw     [
        R                  " U S   S	S
9n[        R                  R                  U5       Hu  nUR                  5       u  pnUT;   d   eTU   nT" Xm5      nUR                  U   R                  nU
R                  [        R                  R                  U5      U   5        Mw     [        R                  R                  X5      n	[        R                  R                  UU
5      n
XT4$ )a[  Reconstructs graph from config object.

Args:
  config: Dictionary returned from Network.get_config()
  custom_objects: Optional dictionary mapping names (strings) to custom
    classes or functions to be considered during deserialization.
  created_layers: Optional dictionary mapping names to Layer objects. Any
    layer not in this dictionary will be created and added to the dict.
    This function will add new nodes to all layers (excluding InputLayers),
    instead of re-using pre-existing nodes in the layers.

Returns:
  Tuple of (input tensors, output tensors, dictionary of created layers)
c                    > [        U [        R                  5      (       a  gTR                  U R                  U4S5      $ )zBReturns node index in layer (might differ from config_node_index).r   N)rQ   r  r  r   r!   )r   config_node_indexnode_index_maps     r7   get_node_index/reconstruct_from_config.<locals>.get_node_index8  s7    e/::;;!!5::/@"A4HHrO   c                 |   >^ UU4S jn[         R                  " U SS9n [        R                  R	                  X 5      $ )z0Deserializes TF-Keras Tensors passed to `call`..c                 &  > [        U [        R                  5      (       ap  U R                  5       n U S   nU S   nU S   nTU   nT" XB5      nUc  [        eUR
                  U   n[        R                  R                  UR                  5      U   $ U $ )z7Deserializes a single TF-Keras Tensor passed to `call`.r   r:   r  )
rQ   r   ListWrapperas_list
IndexErrorr   r'   r,   r-   r3   )	r5   r  r   r   r   new_node_indexr
   r  	layer_maps	          r7   _deserialize_keras_tensor^reconstruct_from_config.<locals>._deserialize_keras_tensors.<locals>._deserialize_keras_tensorA  s    !X1122IIKqT
qT
 t!*-!/!B!) %$++N;wwt||4\BBHrO   Twrap)r   convert_inner_node_datar'   r,   r^   )r4   r  r  r  s    ` r7   _deserialize_keras_tensors;reconstruct_from_config.<locals>._deserialize_keras_tensors>  s2    	0 11&tDww$$%>GGrO   c                   > / n[         R                  R                  U5       GHl  nUR                  5       n[	        U5      S:X  a  0 nO*[	        U5      S:X  a  US   n T" UT5      nO[        S5      eUS   [        R                  :w  am  US   nUS   nUS   nTU   nT" X5      nUc    gUR                  U   n	UR                  [         R                  R                  U	R                  5      U   5        M  US   S:X  d   e[	        U5      S:  d   eUS   n
[        U
[        5      (       aQ  [	        U
5      S:X  aB  U
S   [        R                  :X  a+  UR                  [        R                   " U
S   5      5        GM[  UR                  U
5        GMo     [         R                  R#                  X5      nUb  [%        U S	5      (       a  U R&                  (       d  [(        R*                  " U5      nU " U40 WD6n[         R                  R                  U5      S   R,                  R.                  nUTU R0                  TU    4'   TU ==   S-  ss'   g
! [
         a       gf = f)a$  Deserialize a node.

Args:
    layer: layer instance.
    node_data: Nested structure of `ListWrapper`.

Returns:
    Whether the node was processed (i.e. the layer was called on the
    inputs specified by the node data)

Raises:
    ValueError: In case of improperly formatted `node_data`.
      Fz"Improperly formatted model config.r   r:   r  r#  #_preserve_input_structure_in_configT)r'   r,   r-   r  rS   r  r   node_module_CONSTANT_VALUEr   ri   r3   rQ   rW   _COMPOSITE_TYPEr   decoder   rG   r  r   unnest_if_single_tensorrF   r   r!   )r   	node_datarx  
input_datar4   inbound_layer_nameinbound_node_indexinbound_tensor_indexinbound_layerrd  	const_valr   output_indexr  r  r  node_count_by_layerr  s                r7   process_node-reconstruct_from_config.<locals>.process_node\  sX    ''//)4J#++-J:!#ZA%#A!7OF
 !!EFF!} ; ;;%/]"%/]"'1!}$ ./A B%3!&" &- ,;;<NO$$GGOOL$8$89:NO "!}***:!+++&qM	y%00I!+!!(C(CC "(():):9Q<)HI!((3[ 5\ 00J $E#HII@@ 0 H H!! #=;F;N 77??>:nZZ 
  078  &!+&w " ! !s   	I
IIc                    > U S   nUT;   a  TU   nOSSK Jn  U" U TS9nUTU'   [        [        U5      5      TU'   U S   n[        R
                  " USS9nU H  nT	U   R                  U5        M     g)	zDeserializes a layer, then call it on appropriate inputs.

Args:
    layer_data: layer config dict.

Raises:
    ValueError: In case of improperly formatted `layer_data` dict.
r!   r   )deserialize)custom_objectsr  Tr  N)tf_keras.src.layersr  intr  r   r  ri   )

layer_datar  r   deserialize_layerinbound_nodes_datar  r  r  r  rk  s
         r7   process_layer.reconstruct_from_config.<locals>.process_layer  s      '
'":.E M%jPE).N:&%()@)G%HE" (8%==T
 ,I
 e$++I6 ,rO   r{   r!   r   input_layersTr  output_layers)r   r   r  rR   r#   r   r  r'   r,   r-   r  r   r   ri   r   )r7  r  r  r  r  r  r   layer_nodesr  rx  r   r  r  r   r   layer_output_tensorsr  r  r  r  r  rk  s    ``              @@@@@r7   reconstruct_from_configr
    s     $@{'>'>'@N
 N $//5IH<R Rh 7  7F X&
j! '  *J":f#56E))/33E:!k +AI#E55#* 4?)%0 "k	 + 
 MN33~TL ggool3
/9/A/A/C,
^+++z*#E6
$33J?NNGGOO01,?	
 4 44dM ggoom4
/9/A/A/C,
^+++z*#E6
$33J?NNGGOO01,?	
 5 GG,,\IMWW--m^LN.88rO   c                    U=(       d    0 n[         R                  nSn[        U SS5      (       a  [        R                  nSnU=(       d    UnU R                  US'   0 nU R
                   He  n[        U5      (       a  SOSn[        UR                  5       H5  u  p[        UR                  U5      n
XR                  ;   d  M,  XuU
'   US-  nM7     Mg     / n[        R                  " 5          U R
                   H  n/ n[        UR                  5       Hf  u  p[        UR                  U5      n
XR                  ;   d  M,  U	R                  (       a  M?  U	R                  [        U5      nUR                  U5        Mh     [        U[         5      (       a  U(       a  SUl        U" U5      nUR                  US'   XS'   UR                  U5        M     XS'   S	S	S	5        / n[%        ['        U R(                  5      5       Hs  nU R*                  U   u  nnn[        UR                  U5      n
XR                  ;  a  M=  XZ   nUR                  [,        R.                  " UR                  UU/5      5        Mu     [0        R2                  R5                  U R6                  U5      n[0        R2                  R9                  U5      (       d  U/n[,        R:                  " U5      nXS
'   / n[%        ['        U R<                  5      5       Hs  nU R>                  U   u  nnn[        UR                  U5      n
XR                  ;  a  M=  XZ   nUR                  [,        R.                  " UR                  UU/5      5        Mu     [0        R2                  R5                  U R@                  U5      n[0        R2                  R9                  U5      (       d  U/n[,        R:                  " U5      nUUS'   U$ ! , (       d  f       GN= f)a0  Build the config, which consists of the node graph and serialized layers.

Args:
  network: A Network object.
  serialize_layer_fn: Function used to serialize layers.
  config: A dict to append more config entries into. If None, start with a
      new dict for the config.

Returns:
  Config dictionary.
Fuse_legacy_configTr!   r:   r   r  r{   Nr  r  )!r   serialize_keras_objectr   r   r!   r{   r  r   r   ri  rk   SharedObjectSavingScoper
  	serializeri   rQ   r   r  r   rS   re   rg   r   r  r'   r,   r   rT   r>   r  rf   rh   rU   )networkserialize_layer_fnr7  serialize_obj_fnset_layers_legacynode_conversion_mapr   
kept_nodesoriginal_node_indexr
   rl  layer_configsfiltered_inbound_nodesr  layer_configmodel_inputsr   r   r   r  model_outputss                        r7   r=  r=  
  ss    \rF(??w+U33(?? +?/?\\F6N1%88Qa
)253G3G)H%%ejj2EFH1110:H-a
	 *I   M		.	.	0^^E%'"-6u7K7K-L)#)%**6IJ555dmmm !%&(;!I +11)< .M %,,1B*.'-e4L#(::L ,B)  .# $$ )x' 
1, L3w,,-.*1*D*DQ*G'z<!%**j9111,6  %**nl!KL	
 / 77++L 77\**$~33LAL)>M3w--./*1*E*Ea*H'z<!%**j9111,6  %**nl!KL	
 0 GG,,M 77]++&44]CM+F?Mw 
1	0s   *AO!=O!BO!!
O0c                     U R                   R                  c  g U R                   R                  5       nU(       a  S US'   U$ )Nr   )rK   r(  r  )rL   rK   s     r7   r   r   g  s4    ww||GGOOEaLrO   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )ModuleWrapperip  zFWrapper for `tf.Module`s to support the Functional and Sequential API.c                   > [         TU ]  " S0 UD6  Uc'  [        US5      (       a  SnO[        US5      (       a  SnUb  [        X5      (       d  [        U SU 35      eXl        X l        [        X5      n[        R                  " U5      nSUR                  ;   =(       d    UR                  SLU R                  l        SUR                  ;   =(       d    UR                  SLU R                  l        g)a  Initializes the wrapper Layer for this module.

Args:
  module: The `tf.Module` instance to be wrapped.
  method_name: (Optional) str. The name of the method to use as the
    forward pass of the module. If not set, becomes '__call__' if
    defined, or 'call'. Defaults to `None`.
  **kwargs: Additional keywrod arguments. See `tf.keras.layers.Layer`.

Raises:
  ValueError: If `method` is not defined on `module`.
N__call__ro   z is not defined on object r   r   r   )r%   r&   rG   r   _module_method_namer   r   rn   r  r@  ra   rb   rc   )r1   modulemethod_namer4   methodmethod_arg_specr6   s         r7   r&   ModuleWrapper.__init__s  s     	"6"vz**((($gf&B&B},FvhOPP' -$33F;/... 1$$D0 	,
 o***Oo.C.C4.O 	(rO   c                     SU;   a"  U R                   (       d  UR                  S5        SU;   a"  U R                  (       d  UR                  S5        [        U R                  U R
                  5      " U0 UD6$ )Nr   r   )_expects_training_argr#   _expects_mask_argr   r!  r"  )r1   r  r4   s      r7   ro   ModuleWrapper.call  s[    (B(BJJz"VD$:$:JJvt||T%6%67HHHrO   )r"  r!  r<   )	r   r  r  r  r  r&   ro   r  r  r  s   @r7   r  r  p  s    P"
HI IrO   r  c                     [         R                  " U R                  5      R                  SS  n[         R                  " [        R                  5      R                  SS  nX:X  a  gg)Nr:   TF)r   rn   r&   r  r   )cls	init_argsfunctional_init_argss      r7   r>  r>    sX    ))#,,7<<QR@I%44Z5H5HINN	 (rO   r  );r  r   r;  r  r  tensorflow.compat.v2r(   v2r'   tf_keras.srcr   tf_keras.src.dtensorr   r}   tf_keras.src.enginer   r   r   r   r  r	   r
   r  r   r  r   tf_keras.src.savingr   tf_keras.src.saving.legacyr   &tf_keras.src.saving.legacy.saved_modelr   r   r   r9  tf_keras.src.utilsr   r   r   tensorflow.python.platformr   rX  tensorflow.tools.docsr   r   r   ri  rj   r  r  r  r  r  r
  r=  r   Layerr  r>  r   rO   r7   <module>r<     s     O     ! !   = * 0 0 A * 3 8 . 1 4 = H M , ) ' = .[B## [B|1xBv!4H++\Q"-*&n9bZz,IJ$$ ,I^rO   