
    ϑiN                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r
SSKrSSKJr  SSKJr  SSKJr  SSKJr  SS	/r\" \\R*                  S
S9rSq " S S5      r " S S	\5      rg)zFleet Utils.    N)base)
get_logger)
HDFSClient   )utils	FleetUtil	GPUPSUtilz&%(asctime)s %(levelname)s: %(message)s)fmtc            
       N   \ rS rSrSrS6S jrS rS rS r\	R                  " 5       \	R                  " 5       S4S jr\	R                  " 5       S	S
S4S jr\	R                  " 5       S	S
4S jrS rS7S jrS7S jr0 S4S jr  S8S jr0 SS4S jr  S9S jrS rS rS rS rS rS:S jrS rS r  S;S  jr   S<S! jr S=S" jr  S=S# jr! S=S$ jr"S% r#\	R                  " 5       S	S
S&S'S(S)S*S+4	S, jr$\	R                  " 5       S	S
S&S'S(S)S*S+S4
S- jr%S. r&S/ r'S0 r(S1 r)S2 r*S3 r+S4 r,S5r-g)>r   +   a=  
FleetUtil provides some common functions for users' convenience.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.rank0_print("my log")

c                 z    Xl         US:X  a	  SSKJn  Uqg US:X  a	  SSKJn  Uqg US:X  a  SSKJq  g [        S5      e)Npslibr   )fleet
transpilerpscorez3Please choose one mode from ["pslib", "transpiler"])mode8paddle.incubate.distributed.fleet.parameter_server.pslibr   Hpaddle.incubate.distributed.fleet.parameter_server.distribute_transpilerpaddle.distributed
ValueError)selfr   fleet_pslibfleet_transpilers       l/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/incubate/distributed/fleet/fleet_util.py__init__FleetUtil.__init__9   sI    	7?  E\! %EX0E     c                     [         R                  5       S:w  a  g[        U5        [        R                  R                  5         g)a@  
Worker of rank 0 print some log.

Args:
    s(str): string to print

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.rank0_print("my log")

r   N)r   worker_indexprintsysstdoutflushr   ss     r   rank0_printFleetUtil.rank0_printP   s/      1$a

r   c                 `    [         R                  5       S:w  a  g[        R                  U5        g)aG  
Worker of rank 0 print some log info.

Args:
    s(str): string to log

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.rank0_info("my log info")

r   N)r   r   _loggerinfor$   s     r   
rank0_infoFleetUtil.rank0_infoe   s#      1$Qr   c                 `    [         R                  5       S:w  a  g[        R                  U5        g)aJ  
Worker of rank 0 print some log error.

Args:
    s(str): string to log

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.rank0_error("my log error")

r   N)r   r   r)   errorr$   s     r   rank0_errorFleetUtil.rank0_errory   s$      1$ar   int64c                     UR                  U5      R                  5       n[        R                  " UR	                  5       5      R                  U5      nUR                  Xc5        g)aA  
Set tensor of a Variable to zero.

Args:
    var_name(str): name of Variable
    scope(Scope): Scope object, default is base.global_scope()
    place(Place): Place object, default is base.CPUPlace()
    param_type(str): param data type, default is int64

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> # doctest: +SKIP('dependency on custom variables')
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.set_zero(myvar.name, myscope)

N)var
get_tensornpzeros	_get_dimsastypeset)r   var_namescopeplace
param_typeparamparam_arrays          r   set_zeroFleetUtil.set_zero   sG    4 		(#..0hhu0188D		+%r   _generated_var_2_generated_var_3 c                 T    U R                  XU5      nU R                  U SU 35        g)a  
Print global auc of all distributed workers.

Args:
    scope(Scope): Scope object, default is base.global_scope()
    stat_pos(str): name of auc pos bucket Variable
    stat_neg(str): name of auc neg bucket Variable
    print_prefix(str): prefix of print auc

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> # doctest: +SKIP('dependency on custom variables')
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.print_global_auc(myscope, stat_pos=stat_pos.name,
        ...                           stat_neg=stat_neg.name)

        >>> # below is part of model
        >>> emb = my_slot_net(slots, label) # emb can be fc layer of size 1
        >>> similarity_norm = paddle.nn.functional.sigmoid(paddle.clip(
        ...     emb, min=-15.0, max=15.0), name="similarity_norm")
        >>> binary_predict = paddle.concat(input=[
        ...     paddle.subtract(
        ...         paddle.ceil(similarity_norm),
        ...         similarity_norm),
        ...     similarity_norm],
        ...     axis=1)
        >>> auc, batch_auc, [batch_stat_pos, batch_stat_neg, stat_pos,
        ...     stat_neg] = paddle.static.auc(input=binary_predict,
        ...                                   label=label,curve='ROC',
        ...                                   num_thresholds=4096)

z global auc = N)get_global_aucr&   )r   r;   stat_posstat_negprint_prefix	auc_values         r   print_global_aucFleetUtil.print_global_auc   s0    T ''B	L>	{CDr   c                 F   UR                  U5      b  UR                  U5      c  U R                  S5        gU R                  S:X  a  [        R	                  5         O[        R
                  R                  5         [        R                  " UR                  U5      R                  5       5      n[        R                  " UR                  5      nUR                  S5      n[        R                  " U5      S-  n[        R
                  R                  XF5        UR                  U5      n[        R                  " UR                  U5      R                  5       5      n[        R                  " UR                  5      nUR                  S5      n[        R                  " U5      S-  n	[        R
                  R                  Xy5        U	R                  U5      n	[        US   5      n
SnSnSnSnSnSn[        U
5       HF  nU
S-
  U-
  nXFS   U   -   nXS   U   -  nXyS   U   -   nXS   U   -  nXU-
  XL-   -  S-  -  nUnUnMH     SnXG-  S:X  d  US:X  a  S	nOXU-  -  nU R                  S:X  a  [        R	                  5         U$ [        R
                  R                  5         U$ )
a  
Get global auc of all distributed workers.

Args:
    scope(Scope): Scope object, default is base.global_scope()
    stat_pos(str): name of auc pos bucket Variable
    stat_neg(str): name of auc neg bucket Variable

Returns:
    auc_value(float), total_ins_num(int)

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> # doctest: +SKIP('dependency on custom variables')
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> auc_value, _ = fleet_util.get_global_auc(myscope,
        ...                                          stat_pos=stat_pos,
        ...                                          stat_neg=stat_neg)

Nnot found auc bucketr   r           r      g      ?)find_varr&   r   r   barrier_worker_role_maker_barrier_workerr5   arrayr4   shapereshapecopy_all_reducelenrange)r   r;   rG   rH   posold_pos_shape
global_posnegold_neg_shape
global_neg
num_bucketareanew_posnew_negtotal_ins_numiindexrJ   s                     r   rF   FleetUtil.get_global_auc   s\   : >>(#+u~~h/G/O3499   "--/hhu~~h/::<=+kk"oWWS\A%
%%c6''6
 hhu~~h/::<=+kk"oWWS\A%
%%c6''6
 A'
z"ANQ&EqM%00G]511MqM%00G]511Ms]s}599DCC # 	9>]a/Ic	*I99   "  --/r   c                 .    [         R                  X5        g)a  
load pslib model to one table

Args:
    table_id(int): load model to one table, default is None, which mean
                   load all table.
    path(str): model path

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.load_fleet_model_one_table(1, path="hdfs:/my/model/path")
N)r   load_one_table)r   table_idpaths      r   load_fleet_model_one_table$FleetUtil.load_fleet_model_one_table.  s    " 	X,r   c                 *    [         R                  XS9  g)a  
load pslib model

Args:
    path(str): model path
    mode(str): 0 or 1, which means load checkpoint or delta model,
               default is 0

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()

        >>> fleet_util.load_fleet_model("hdfs:/my/model/path")

        >>> fleet_util.load_fleet_model("hdfs:/my/model/path", mode=0)

r   N)r   init_serverr   rn   r   s      r   load_fleet_modelFleetUtil.load_fleet_modelA  s    * 	$*r   c                 ,    [         R                  SXS9  g)a  
save pslib model

Args:
    path(str): model path
    mode(str): 0 or 1, which means save checkpoint or delta model,
               default is 0

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_fleet_model("hdfs:/my/model/path")

Nrr   )r   save_persistablesrt   s      r   save_fleet_modelFleetUtil.save_fleet_modelX  s    $ 	d6r   patchc	                    [         R                  " 5       n	US:X  a  [        U5      U	S'   OlUS:X  a+  [        [        [        R                  " 5       5      5      U	S'   O;[        SU S35        Sn[        [        [        R                  " 5       5      5      U	S'   [        U5      U	S'   UR                  S5      (       d  UR                  S5      (       a  X3R                  S	5      S
-   S  nXcR                  S5      -   S-   U	S'   SU	S'   SU	S'   SU	S'   SU	S'   XYS'   [        R                  " S5      R                  5       R                  5       n
[        R                  " S5      R                  5       R                  5       nUR                  U
5      nUR                  S5      nUS:w  a
  US:w  a  XU n
XS'   SU	S'   UR                  S5      S-   U-   S-   U	S '   [        [        R                  5       5      U	S!'   [        R                   " U	5      $ )"Nr   idr{   warning: unknown mode , set it to patchkeyhdfs:afs::r   //000input111111record_count2partition_typedefault_job_namejob_namefeasignins_tagins_pathzecho -n ${JOB_ID}zecho -n ${INSTANCE_ID}z--rO   job_idrD   monitor_data	/monitor/.txtmonitor_pathmpi_size)collectionsOrderedDictstrinttimer    
startswithfindrstripospopenreadstripr   
worker_numjsondumps)r   output_pathday
model_pathxbox_base_key	data_pathhadoop_fs_namer   r   	xbox_dictjob_id_with_hostinstance_id	start_posend_poss                 r   _get_xbox_strFleetUtil._get_xbox_strl  s     ++-	6>!-0IdOW_!#diik"23IdO*4&0ABCD!#diik"23IdO}-	%  ))Z-B-B6-J-J#OOC$81$<$>?J+.?.?.DDvM	'$,	.!&)	"# 2	*(	) )*88$78==?EEGhh78==?EEG$$%56	""4(?w"}*W=.($&	.!s#k1C7&@ 	.! !$E$4$4$6 7	*zz)$$r   $HADOOP_HOMEc	           	         [        U5      n[        U5      n[        U5      nUS:w  a  SU SU S3n	UR                  S5      U	-   n
OSU S3n	UR                  S5      U	-   n
[        R	                  5       S:X  Ga  US-   U-   nU SU SU
 SU SS 3	nUUS.n[        X}5      nUR                  U5      (       Gaa  UR                  U5      nUR                  S5      nU Vs/ s H  nUR                  S5      S   PM     nnU Vs/ s H  nUR                  S5      S   PM     nnS	n[        [        U5      5       H?  n[        U5      [        UU   5      :X  d  M   [        U5      [        UU   5      :X  d  M=  S
n  O   U(       d{  [        US5       nUR                  US-   5        UR                  US-   5        SSS5        UR                  U5        UR                  X5        U R                  SU SU SU S35        OqU R                  SU SU SU S35        OU[        US5       nUR                  US-   5        SSS5        UR                  X5        U R                  SU SU SU S35        U R                   S:X  a  [        R#                  5         g[        R$                  R'                  5         gs  snf s  snf ! , (       d  f       GN= f! , (       d  f       N= f)a  
write donefile when save model

Args:
    output_path(str): output path
    day(str|int): training day
    pass_id(str|int): training pass id
    xbox_base_key(str|int): xbox base key
    hadoop_fs_name(str): hdfs/afs fs name
    hadoop_fs_ugi(str): hdfs/afs fs ugi
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"
    donefile_name(str): donefile name, default is "donefile.txt"

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.write_model_donefile(output_path="hdfs:/my/output",
        ...                                 day=20190723,
        ...                                 pass_id=66,
        ...                                 xbox_base_key=int(time.time()),
        ...                                 hadoop_fs_name="hdfs://xxx",
        ...                                 hadoop_fs_ugi="user,passwd")

-1r   /0/r   	zfs.default.namezhadoop.job.ugi
   FTwNwrite   succeed
not write 	 because  already existsr   )r   r   r   r   r   r   is_filecatsplitr\   r[   openwritedeleteuploadr/   r   rS   rT   rU   )r   r   r   pass_idr   r   hadoop_fs_ugihadoop_homedonefile_namesuffix_namer   donefile_pathcontentconfigsclientpre_contentpre_content_listrh   day_list	pass_listexistfs                         r   write_model_donefileFleetUtil.write_model_donefile  s   L #hg,M*d?cU!G9A.K$++C0;>JcU#,K$++C0;>J1$'#-=MRbBwir!MG#1"/G  5F~~m,,$jj7#.#4#4T#: 6FG6FAGGDM!,6FG7GH7G!QWWT]1-7G	Hs8}-A3x3x{#33G!!I 9 !% . mS1Qd 23$/ 2 MM-0MM-=$$ QwiqxH $$$]O9SE7) L! !
 --GGGdN+ .m9  SE7)1]O8D 99   "--/C HH 21 .-s$   J2J7)J<%K<
K
KNc                 (   [        U5      n[        U5      n[        U5      nSnUS:w  a%  SnSU SU S3nUR                  S5      U-   nU
c  Sn
O!SnSU S3nUR                  S5      U-   nU
c  S	n
[        U[        5      (       a  S
R                  U5      n[        R                  5       S:X  Ga  US-   U
-   nU R                  UUUUUU0 US9nUUS.n[        U	U5      nUR                  U5      (       Gac  UR                  U5      n[        R                  " UR                  S5      S   5      nUS   R                  S5      S   nUS   R                  S5      S   R                  S5      S   nSn[        U5      [        U5      :  d0  [        U5      [        U5      :X  a  [        U5      [        U5      ::  a  SnU(       d{  [        U
S5       nUR!                  US-   5        UR!                  US-   5        SSS5        UR#                  U5        UR%                  X5        U R'                  SU SU SU
 S35        OqU R'                  SU
 SU SU S35        OU[        U
S5       nUR!                  US-   5        SSS5        UR%                  X5        U R'                  SU SU SU
 S35        U R(                  S:X  a  [        R+                  5         g[        R,                  R/                  5         g! , (       d  f       GN= f! , (       d  f       N= f)a$  
write delta donefile or xbox base donefile

Args:
    output_path(str): output path
    day(str|int): training day of model
    pass_id(str|int): training pass id of model
    xbox_base_key(str|int): xbox base key
    data_path(str|list): training data path
    hadoop_fs_name(str): hdfs/afs fs name
    hadoop_fs_ugi(str): hdfs/afs fs ugi
    monitor_data(dict): metrics
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"
    donefile_name(str): donefile name, default is None"

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.write_xbox_donefile(
        ...     output_path="hdfs:/my/output/",
        ...     day=20190722,
        ...     pass_id=1,
        ...     xbox_base_key=int(time.time()),
        ...     data_path="hdfs:/my/data/",
        ...     hadoop_fs_name="hdfs://xxx",
        ...     hadoop_fs_ugi="user,passwd",
        ...     monitor_data={})

Nr   r{   r   /delta-xbox_patch_done.txtr   /base/xbox_base_done.txt,r   r   r   r   r   rO   r   -FTr   r   r   r   r   r   r   r   )r   r   r   
isinstancelistjoinr   r   r   r   r   r   r   loadsr   r   r   r   r   r/   r   rS   rT   rU   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   xbox_strr   r   r   	last_dictlast_day	last_passr   r   s                           r   write_xbox_donefileFleetUtil.write_xbox_donefile  s   Z #hg,M*d?DcU''!4K$++C0;>J$ 5DcU&/K$++C0;>J$ 4i&&+I1$'#-=M)) * 	H $2"/G  W5F~~m,,$jj7 JJ{'8'8'>r'BC	$W-33C8<%g.44S9"=CCCHL	Hs8},3x3x=0GI6 EmS1Qd 2340 2 MM-0MM-=$$ QwiqxH $$$]O9SE7) L! !
 --GGHtO, .m9  SE7)1]O8D 99   "--// 21 .-s   )K1$L1
L 
Lc	                 $   [        U5      n[        U5      n[        U5      nU	R                  SS5      n
U	R                  SS5      nUS:w  a"  SU SU SUS S	3nUR                  S5      U-   nOSU S
US S	3nUR                  S5      U-   n[        R                  5       S:X  a  US-   U-   nUUS.n[        X5      nUR                  U5      (       a  U R                  SU S35        OUSU
 SU S3n[        US5       nUR                  U5        SSS5        UR                  X5        U R                  SU S35        U R                  S:X  a  [        R                  5         g[        R                  R                  5         g! , (       d  f       Nx= f)a  
write cache donefile

Args:
    output_path(str): output path
    day(str|int): training day of model
    pass_id(str|int): training pass id of model
    key_num(str|int): save cache return value
    hadoop_fs_name(str): hdfs/afs fs name
    hadoop_fs_ugi(str): hdfs/afs fs ugi
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"
    donefile_name(str): donefile name, default is "sparse_cache.meta"
    kwargs(dict): user defined properties
                  file_num(int): cache file num
                  table_id(int): cache table id

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.write_cache_donefile(
        ...     output_path="hdfs:/my/output/",
        ...     day=20190722,
        ...     pass_id=1,
        ...     key_num=123456,
        ...     hadoop_fs_name="hdfs://xxx",
        ...     hadoop_fs_ugi="user,passwd")

file_num   rm   r   r   r   r   03_cacher   r   not write because r   file_prefix:part
part_num:	
key_num:r   r   Nr   r   r   )r   r   getr   r   r   r   r   r/   r   r   r   r   rS   rT   rU   )r   r   r   r   key_numr   r   r   r   kwargsr   rm   r   r   r   r   r   meta_strr   s                      r   write_cache_donefileFleetUtil.write_cache_donefilep  s   V #hg,g,::j"-::j!,d?cU''!HR=GK$++C0;>JcU&"V<K$++C0;>J1$&,}<M#1"/G  5F~~m,,  (G 9
*WIUWX--GGH% .m8  6-!AB99   "--/ .-s   =F
Fc                     [        U5      n[        U5      nSU SU S3nX-   nU R                  SU 35        U R                  U5        U R                  S5        g)a  
load pslib model

Args:
    output_path(str): output path
    day(str|int): training day
    pass_id(str|int): training pass id

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.load_model("hdfs:/my/path", 20190722, 88)

r   zgoing to load_model zload_model doneN)r   r/   ru   )r   r   r   r   r   	load_paths         r   
load_modelFleetUtil.load_model  se    $ #hg,#ay*-	/	{;<i(*+r   c                     [        U5      n[        U5      nSU SU S3nX-   nU R                  SU 35        U R                  U5        U R                  S5        g)a  
save pslib model

Args:
    output_path(str): output path
    day(str|int): training day
    pass_id(str|int): training pass id

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_model("hdfs:/my/path", 20190722, 88)

r   going to save_model zsave_model doneN)r   r&   ry   r   r   r   r   r   r   s         r   
save_modelFleetUtil.save_model  se    $ #hg,#ay* .
/
|<=j)*+r   c                     [        U5      nSU S3nX-   nU R                  SU 35        [        R                  SUSS9  U R                  S5        g)ak  
save batch model

Args:
    output_path(str): output path
    day(str|int): training day

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_batch_model("hdfs:/my/path", 20190722)

r   r   r   Nr   rr   zsave_batch_model doner   r&   r   rx   r   r   r   r   r   s        r   save_batch_modelFleetUtil.save_batch_model  s\    " #h#cl .
/
|<=jq901r   c                     [        U5      n[        U5      nSU SU S3nX-   nU R                  SU 35        [        R                  SUSS9  U R                  S5        g)a  
save delta model

Args:
    output_path(str): output path
    day(str|int): training day
    pass_id(str|int): training pass id

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_delta_model("hdfs:/my/path", 20190722, 88)

r   r   zgoing to save_delta_model Nr   rr   zsave_delta_model doner  r  s         r   save_delta_modelFleetUtil.save_delta_model
  sl    $ #hg,#ggYa0 .
5j\BCjq901r   c                     [        U5      nSU S3nX-   nU R                  SU-   5        [        R                  SUSS9  U R                  S5        g)as  
save xbox base model

Args:
    output_path(str): output path
    day(str|int): training day

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_xbox_base_model("hdfs:/my/path", 20190722)

r   r   zgoing to save_xbox_base_model NrQ   rr   zsave_xbox_base_model doner  r  s        r   save_xbox_base_modelFleetUtil.save_xbox_base_model$  sZ    " #h#fo .
9JFGjq945r   c                    [        U5      n[        U5      n[        U5      nUR                  SS5      nSU SU 3nUR                  S5      U-   nU R	                  SU 35        [
        R                  SXUS9n	U R	                  S5        U	$ )	a?  
save cache model

Args:
    output_path(str): output path
    day(str|int): training day
    pass_id(str|int): training pass id
    mode(str|int): save mode
    kwargs(dict): user defined properties
                  table_id(int): table id to save cache

Returns:
    key_num(int): cache key num

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_cache_model("hdfs:/my/path", 20190722, 88)

rm   r   r   r   zgoing to save_cache_model Nr   rm   zsave_cache_model done)r   r   r   r   r&   r   save_cache_model)
r   r   r   r   r   r   rm   r   r   r   s
             r   r  FleetUtil.save_cache_model<  s    0 #hg,4y::j!,#ggY/ '',{:
5j\BC((*( ) 
 	01r   c                     [        U5      nUR                  SS5      nSU S3nUR                  S5      U-   nU R                  SU 35        [        R                  SUSUS9nU R                  S	5        U$ )
a#  
save cache model

Args:
    output_path(str): output path
    day(str|int): training day
    pass_id(str|int): training pass id
    kwargs(dict): user defined properties
                  table_id(int): table id to save cache

Returns:
    key_num(int): cache key num

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_cache_base_model("hdfs:/my/path", 20190722)

rm   r   r   z/basezgoing to save_cache_base_model NrQ   r  zsave_cache_base_model done)r   r   r   r&   r   r  )r   r   r   r   rm   r   r   r   s           r   save_cache_base_modelFleetUtil.save_cache_base_modela  s    . #h::j!,#en '',{:
::,GH((*1x ) 
 	56r   c                    U R                   S:X  a  [        R                  5         O[        R                  R	                  5         [        R                  R                  5       (       GaJ  [        [        U5      5      n[        R                  S   U   R                  5       R                  n[        R                  S   U   n0 nU H$  nSU;  a  M  XW    H  nSU[        U5      '   M     M&     U H  n	[        U	R                  5      U;  a  M  / n
[        S[        U	R                  5      5       HI  nU	R                  U   nUR!                  U5      c  [#        SU-   S-   S	-   5      eU
R%                  U5        MK     [        R&                  R)                  U[        U	R                  5      U
5        M     [        R                  R	                  5         g)
a  
pull all dense params in trainer of rank 0

Args:
    scope(Scope): base Scope
    program(Program): base Program

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> # doctest: +SKIP('dependency on custom variables')
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.pull_all_dense_params(my_scope, my_program)

r   program_id_to_workerprogram_configsdenser   Nzvar z not found in scope zwhen pull dense)r   r   rS   rT   rU   is_first_workerr   r}   	_opt_infoget_descdense_tabler   rm   r\   r[   dense_variable_namerR   r   append
_fleet_ptr
pull_dense)r   r;   programprog_idtables	prog_confprog_tablesr   rm   tablevar_name_listrh   r:   s                r   pull_all_dense_paramsFleetUtil.pull_all_dense_params  s   $ 99   "--/,,.."W+&G 67@ 
 (9:7CIK #% )H12KH. !/ !
  u~~&k9 "q#e&?&?"@AA$88;H~~h/7("&'45 00  "((2 B   ++3u~~.  " 	))+r   c           	         [        U5      n[        U5      nSnU R                  X#5        [        R                  5       S:X  a  [        R
                  " U5         [        R                  R                  R                  UUUUUR                  5       S9  SSS5        U	U
S.n[        X5      nUS:X  a	  U SU S3nOU SU S	U S
3nUR                  U5      (       d  UR                  U5        UR                  UUSSS9  U R                  S:X  a  [        R!                  5         g[        R"                  R%                  5         g! , (       d  f       N= f)a  
save paddle inference model, and upload to hdfs dnn_plugin path

Args:
    executor(Executor): base Executor
    scope(Scope): base Scope
    program(Program): base Program
    feeded_vars(list[Variable]): feed vars
    target_vars(list[variable]): fetch vars
    output_path(str): hdfs/afs output path
    day(str|int): training day
    pass_id(str|int): training pass
    hadoop_fs_name(str): hadoop fs name
    hadoop_fs_ugi(str): hadoop fs ugi
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"
    save_combine(bool): whether to save in a file or separate files,
                        default is True

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> # doctest: +SKIP('dependency on custom variables')
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_paddle_inference_model(exe,
        ...                                        join_scope,
        ...                                        join_program,
        ...                                        feeded_vars,
        ...                                        target_vars,
        ...                                        "hdfs:/my/output/path/",
        ...                                        day=20190727,
        ...                                        pass_id=6,
        ...                                        hadoop_fs_name="xxx",
        ...                                        hadoop_fs_ugi="xxx,xxx")
inference_modelr   )r"  Nr   r   r   /base/dnn_plugin/r   /dnn_plugin/   Tmulti_processes	overwriter   )r   r)  r   r   r   scope_guardpaddlestaticiosave_inference_modelcloner   is_existmakedirsr   r   rS   rT   rU   )r   executorr;   r"  feeded_varstarget_varsr   r   r   r   r   r   save_combine
model_namer   r   dests                    r   save_paddle_inference_model%FleetUtil.save_paddle_inference_model  s/   f #hg,&
""521$!!%(  55#MMO 6  ) $2"/G  5F$%au,=>%auGG9LI??4((%MM*dAMN99   "--/7 )(s   :E
Ec           	      J   [        U5      n[        U5      nU R                  X#5        [        R                  5       S:X  Ga
  U Vs/ s H!  oR	                  5       R                  U5      PM#     nn[        R                  " U5         U(       a+  [        R                  R                  R                  USX>US9  O([        R                  R                  R                  XX>S9  SSS5        UU	S.n[        X5      nUS:X  a	  U SU S	3nOU SU S
U S3nUR                  U5      (       d  UR                  U5        UR                  UUSSS9  U R                   S:X  a  [        R#                  5         g[        R$                  R'                  5         gs  snf ! , (       d  f       N= f)a
  
save paddle model, and upload to hdfs dnn_plugin path

Args:
    executor(Executor): base Executor
    scope(Scope): base Scope
    program(Program): base Program
    model_name(str): save model local dir or filename
    output_path(str): hdfs/afs output path
    day(str|int): training day
    pass_id(str|int): training pass
    hadoop_fs_name(str): hadoop fs name
    hadoop_fs_ugi(str): hadoop fs ugi
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"
    var_names(list): save persistable var names, default is None
    save_combine(bool): whether to save in a file or separate files,
                        default is True

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> # doctest: +SKIP('dependency on custom variables')
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.save_paddle_params(exe,
        ...                               join_scope,
        ...                               join_program,
        ...                               "paddle_dense.model.0",
        ...                               "hdfs:/my/output/path/",
        ...                               day=20190727,
        ...                               pass_id=6,
        ...                               hadoop_fs_name="xxx",
        ...                               hadoop_fs_ugi="xxx,xxx",
        ...                               var_names=join_all_var_names)
        >>> fleet_util.save_paddle_params(exe,
        ...                               join_scope,
        ...                               join_program,
        ...                               "paddle_dense.model.usr.0",
        ...                               "hdfs:/my/output/path/",
        ...                               day=20190727,
        ...                               pass_id=6,
        ...                               hadoop_fs_name="xxx",
        ...                               hadoop_fs_ugi="xxx,xxx",
        ...                               var_names=join_user_var_names)
        >>> fleet_util.save_paddle_params(exe,
        ...                               join_scope,
        ...                               join_program,
        ...                               "paddle_dense.model.item.0",
        ...                               "hdfs:/my/output/path/",
        ...                               day=20190727,
        ...                               pass_id=6,
        ...                               hadoop_fs_name="xxx",
        ...                               hadoop_fs_ugi="xxx,xxx",
        ...                               var_names=join_user_item_names)

r   z./)varsfilename)rD  Nr   r   r   r-  r   r.  r/  Tr0  r   )r   r)  r   r   global_blockr3   r   r3  r4  r5  r6  	save_varsr   r9  mkdirsr   r   rS   rT   rU   )r   r;  r;   r"  r?  r   r   r   r   r   r   	var_namesr>  rh   rD  r   r   r@  s                     r   save_paddle_paramsFleetUtil.save_paddle_params  so   P #hg,""521$;DE9a((*..q19DE!!%(MM$$.. $Z /  MM$$.. g /  ) $2"/G  5F$%au,=>%auGG9LI??4((d#MM*dAMN99   "--/9 F((s   (FAF
F"c                    US-   nUUS.n[        XF5      nUR                  U5      (       d!  SS[        [        R                  " 5       5      /$ UR	                  U5      n[
        R                  " UR                  S5      S   5      n	[        U	S   R                  S5      S   5      n
SR                  U	S   R                  S5      SS 5      n[        U	S	   5      nXU/$ )
a|  
get last saved base xbox info from xbox_base_done.txt

Args:
    output_path(str): output path
    hadoop_fs_name(str): hdfs/afs fs_name
    hadoop_fs_ugi(str): hdfs/afs fs_ugi
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"

Returns:
    [last_save_day, last_path, xbox_base_key]
    last_save_day(int): day of saved model
    last_path(str): model path
    xbox_base_key(int): xbox key

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> last_save_day, last_path, xbox_base_key = \
        ...     fleet_util.get_last_save_xbox_base("hdfs:/my/path",
        ...                                        hadoop_fs_name="hdfs://xxx",
        ...                                        hadoop_fs_ugi="user,passwd")

/xbox_base_done.txtr   rO   r   r   r   r   Nr   	r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   	last_pathr   s                r   get_last_save_xbox_base!FleetUtil.get_last_save_xbox_base{  s    D $&;;-+
 K1~~m,,C		,--jj/JJ{006r:;	y)//4R89HHYw/55c:3B?@	Ie,-]33r   c                 "   US-   nUUS.n[        XF5      nUR                  U5      (       d"  SSS[        [        R                  " 5       5      /$ UR	                  U5      n[
        R                  " UR                  S5      S   5      n	[        U	S   R                  S5      S   5      n
[        U	S   R                  S5      S	   R                  S
5      S   5      nSR                  U	S   R                  S5      SS 5      n[        U	S   5      nXX/$ )a  
get last saved xbox info from xbox_patch_done.txt

Args:
    output_path(str): output path
    hadoop_fs_name(str): hdfs/afs fs_name
    hadoop_fs_ugi(str): hdfs/afs fs_ugi
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"

Returns:
    [last_save_day, last_save_pass, last_path, xbox_base_key]
    last_save_day(int): day of saved model
    last_save_pass(int): pass id of saved
    last_path(str): model path
    xbox_base_key(int): xbox key

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> last_save_day, last_save_pass, last_path, xbox_base_key = \
        ...     fleet_util.get_last_save_xbox("hdfs:/my/path",
        ...                                   hadoop_fs_name="hdfs://xxx",
        ...                                   hadoop_fs_ugi="user,passwd")

/xbox_patch_done.txtr   rO   rD   r   r   r   r   r   r   Nr   rN  )r   r   r   r   r   r   r   r   r   r   r   r   rO  r   s                 r   get_last_save_xboxFleetUtil.get_last_save_xbox  s   F $&<<-+
 K1~~m,,BDIIK 011jj/JJ{006r:;	y)//4R89	'*005b9??DRHI	HHYw/55c:3B?@	Ie,-Y>>r   c                 v   SnSnSnUS-   nUUS.n	[        XI5      n
U
R                  U5      (       d"  SSS[        [        R                  " 5       5      /$ U
R	                  U5      nUR                  S5      S   R                  S5      n[        US   5      n[        US   5      nUS	   n[        US
   5      nXVX|/$ )a  
get last saved model info from donefile.txt

Args:
    output_path(str): output path
    hadoop_fs_name(str): hdfs/afs fs_name
    hadoop_fs_ugi(str): hdfs/afs fs_ugi
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"

Returns:
    [last_save_day, last_save_pass, last_path, xbox_base_key]
    last_save_day(int): day of saved model
    last_save_pass(int): pass id of saved
    last_path(str): model path
    xbox_base_key(int): xbox key

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> last_save_day, last_save_pass, last_path, xbox_base_key = \
        ...     fleet_util.get_last_save_model("hdfs:/my/path",
        ...                                    hadoop_fs_name="hdfs://xxx",
        ...                                    hadoop_fs_ugi="user,passwd")

rO   rD   /donefile.txtr   r   r   r   r   rQ   r   )r   r   r   r   r   r   )r   r   r   r   r   last_save_daylast_save_passrO  r   r   r   r   r   s                r   get_last_save_modelFleetUtil.get_last_save_model  s    F 	#o5-+
 K1~~m,,BDIIK 011**]+--%b)//5GAJWQZAJ	GAJyHHr   c                    Sn[         R                  " U[        U5      5      (       d  [        S5      e[        R
                  " SU-   5      R                  5       R                  S5      n[         R                  " U[        U5      5      (       d  [        S5      e[        R
                  " SU-   5      R                  5       R                  S5      n[        U5      n[        U5      n[        US   5      [        US   5      -
  S-   S	-  U-  nXt-  n[        US   5      n	[        US   5      n
Sn/ n[        U5       HS  nUS	-  nUS	-  nX:  d  X:  a  X-  nM  U(       a  UR                  US
 5        OUR                  US
 US
 35        X-  nMU     Sn/ n[        U5       HD  nUR                  / 5        [        XU-   5       H  nUU   R                  UU   5        M     X-  nMF     U$ )a  
get online pass interval

Args:
    days(str): days to train
    hours(str): hours to train
    split_interval(int|str): split interval
    split_per_pass(int}str): split per pass
    is_data_hourly_placed(bool): is data hourly placed

Returns:
    online_pass_interval(list)

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> online_pass_interval = fleet_util.get_online_pass_interval(
        ...     days="{20190720..20190729}",
        ...     hours="{0..23}",
        ...     split_interval=5,
        ...     split_per_pass=2,
        ...     is_data_hourly_placed=False)

z!^\d+|{[0-9]+}|{[0-9]+\.\.[0-9]+}$zdays format is not rightzecho -n r   zhours format is not rightrO   r   r   <   02)re	fullmatchr   	Exceptionr   r   r   r   r   r\   r  )r   dayshourssplit_intervalsplit_per_passis_data_hourly_placedpatternsplits_per_daypass_per_dayleft_train_hourright_train_hourstart
split_pathrh   hmonline_pass_intervaljs                     r   get_online_pass_interval"FleetUtil.get_online_pass_interval  s   < 7||GSY//677xx
T)*//177<||GSZ00788e+,11399#>^,^,r^c%(m+a/25G 	 &7eAh-uRy>
~&AA
A"a&:'$!!QrF,!!QrF1R&/2#E ' !|$A ''+5."89$Q'..z!}= :#E	 % $#r   sqrerrabserrprobqr]   totalc
                 	  ^ TR                  U5      b  TR                  U5      c  U R                  S5        S/S-  $ TR                  U5      c  U R                  SU 35        S/S-  $ TR                  U5      c  U R                  SU 35        S/S-  $ TR                  U5      c  U R                  SU 35        S/S-  $ TR                  U5      c  U R                  SU 35        S/S-  $ TR                  U5      c  U R                  SU 35        S/S-  $ TR                  U	5      c  U R                  S	U	 35        S/S-  $ U R                  S
:X  a  [        R	                  5         O[        R
                  R                  5         U R                  TX#5      n
[        R                  " TR                  U5      R                  5       5      n[        R                  " UR                  5      nUR                  S5      n[        R                  " U5      S-  n[        R
                  R                  X5        UR                  U5      n[        R                  " TR                  U5      R                  5       5      n[        R                  " UR                  5      nUR                  S5      n[        R                  " U5      S-  n[        R
                  R                  UU5        UR                  U5      n[        US   5      nU4S jnU" U5      nU" U5      nU" U5      nU" U5      nU" U5      nU" U	5      nUU-
  nUU-  n[         R"                  " UU-  5      nUU-  nUU-  nUU-  nSn[%        US:  5      (       a  UU-  nSn Sn!Sn"Sn#Sn$Sn%Sn&Sn'Sn(Sn)Sn*Sn+Sn,Sn-Sn.['        U5       H  n/US   U/   n&US   U/   US   U/   -   n'[)        U/5      U-  n([%        U(U -
  5      U-:  a  U(n Sn!Sn"Sn#U!U'-  n!U"U(U'-  -  n"U#U&-  n#U!S:X  a  M^  U"U!-  n)U)S:X  a  Mk  [         R"                  " SU)-
  U)U!-  -  5      n*U*U.:  d  M  U#U!-  n+[%        U+U)-  S-
  5      n,U$U,U!-  -  n$U%U!-  n%Sn M     U%S:  a  U$U%-  OSn0U
U0UUUUUU[+        U5      /	$ )am
  
get global metrics, including auc, bucket_error, mae, rmse,
actual_ctr, predicted_ctr, copc, mean_predict_qvalue, total_ins_num.

Args:
    scope(Scope): Scope object, default is base.global_scope()
    stat_pos_name(str): name of auc pos bucket Variable
    stat_neg_name(str): name of auc neg bucket Variable
    sqrerr_name(str): name of sqrerr Variable
    abserr_name(str): name of abserr Variable
    prob_name(str): name of prob Variable
    q_name(str): name of q Variable
    pos_ins_num_name(str): name of pos ins num Variable
    total_ins_num_name(str): name of total ins num Variable

Returns:
    [auc, bucket_error, mae, rmse, actual_ctr, predicted_ctr, copc,
     mean_predict_qvalue, total_ins_num]

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> # doctest: +SKIP('dependency on custom variables')
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> metric_list = fleet_util.get_global_metrics(myscope,
        ...                                             stat_pos.name,
        ...                                             stat_neg.name,
        ...                                             local_sqrerr.name,
        ...                                             local_abserr.name,
        ...                                             local_prob.name,
        ...                                             local_q.name,
        ...                                             local_pos_ins.name,
        ...                                             local_total_ins.name)

        >>> # below is part of example model
        >>> label = paddle.static.data(name="click", shape=[-1, 1],\
        ...     dtype="int64")
        >>> emb = my_slot_net(slots, label) # emb can be fc layer of size 1
        >>> similarity_norm = paddle.nn.functional.sigmoid(paddle.clip(\
        ...     emb, min=-15.0, max=15.0), name="similarity_norm")\
        >>> binary_predict = paddle.concat(input=[\
        ...     paddle.subtract(\
        ...         paddle.ceil(similarity_norm), similarity_norm),\
        ...     similarity_norm], axis=1)
        >>> auc, batch_auc, [batch_stat_pos, batch_stat_neg, stat_pos, \
        ...     stat_neg] = paddle.static.auc(input=binary_predict,\
        ...                                  label=label, curve='ROC',\
        ...                                  num_thresholds=4096)
        >>> local_sqrerr, local_abserr, local_prob, local_q, local_pos_ins,\
        ...     local_total_ins = paddle.static.ctr_metric_bundle(\
        ...         similarity_norm, label)

NrN   	   not found sqrerr_name=not found abserr_name=not found prob_name=not found q_name=not found pos_ins_num_name=not found total_ins_num_name=r   rO   r   c                 h  > [         R                  " TR                  U 5      R                  5       5      n[         R                  " UR                  5      nUR                  S5      n[         R                  " U5      S-  n[        R                  R                  X5        UR                  U5      nUS   $ )NrO   r   )
r5   rV   rR   r4   rW   rX   rY   r   rT   rZ   )namemetricold_metric_shapeglobal_metricr;   s       r   
get_metric0FleetUtil.get_global_metrics.<locals>.get_metric  s    XXennT2==?@F!xx5^^B'FGGFOa/M))&@)112BCM ##r   rP   gư>g      g{Gz?g?r   )rR   r&   r   r   rS   rT   rU   rF   r5   rV   r4   rW   rX   rY   rZ   r[   mathsqrtabsr\   floatr   )1r   r;   stat_pos_namestat_neg_namesqrerr_nameabserr_name	prob_nameq_namepos_ins_num_nametotal_ins_num_nameaucr]   r^   r_   r`   ra   rb   rc   r  global_sqrerrglobal_abserrglobal_probglobal_q_valuepos_ins_numrg   neg_ins_nummaermsereturn_actual_ctrpredicted_ctrmean_predict_qvaluecopclast_ctrimpression_sumctr_sum	click_sum	error_sumerror_countclickshowctr
adjust_ctrrelative_error
actual_ctrrelative_ctr_error
k_max_spank_relative_error_boundrh   bucket_errors1    `                                               r   get_global_metricsFleetUtil.get_global_metrics[  s   H NN=)1~~m,4346A:^^K(05k]CD6A:^^K(05k]CD6A:^^I&.3I;?@6A:^^F#+09:6A:^^,-5:;K:LMN6A:^^./7/0B/CD 6A: 99   "--/ !!%Fhhu~~m4??AB+kk"oWWS\A%
%%c6''6
hhu~~m4??AB+kk"oWWS\A%
%%c:6''6
A'
	$ #;/";/ +#F+ !!12"#56#k1m+yy67'-7#m3,}<}t#$$$}4D 		

 
!%z"AqM!$Ea=#jmA&66D(Z'C3>"Z/!$	d"NsTz!GI" >1JQ!YYZJ$?@N  66&7
%(j)@1)D%E"/.@@	~-3 #6 3>/y;.s 

 
	
r   c                    UR                  U5      b  UR                  U5      c  U R                  S5        gUR                  U5      c  U R                  SU 35        gUR                  U5      c  U R                  SU 35        gUR                  U5      c  U R                  SU 35        gUR                  U5      c  U R                  SU 35        gUR                  U5      c  U R                  SU 35        gUR                  U	5      c  U R                  SU	 35        gU R                  UUUUUUUUU	5	      u	  nnnnnnnnnU R                  U
 S	US
 SUS
 SUS
 SUS
 SUS
 SUS
 SUS
 SUS
 SU 35        g)a	  
print global metrics, including auc, bucket_error, mae, rmse,
actual_ctr, predicted_ctr, copc, mean_predict_qvalue, total_ins_num.

Args:
    scope(Scope): Scope object, default is base.global_scope()
    stat_pos_name(str): name of auc pos bucket Variable
    stat_neg_name(str): name of auc neg bucket Variable
    sqrerr_name(str): name of sqrerr Variable
    abserr_name(str): name of abserr Variable
    prob_name(str): name of prob Variable
    q_name(str): name of q Variable
    pos_ins_num_name(str): name of pos ins num Variable
    total_ins_num_name(str): name of total ins num Variable
    print_prefix(str): print prefix

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> # doctest: +SKIP('dependency on custom variables')
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> fleet_util.print_global_metrics(myscope,
        ...                                 stat_pos.name,
        ...                                 stat_neg.name,
        ...                                 local_sqrerr.name,
        ...                                 local_abserr.name,
        ...                                 local_prob.name,
        ...                                 local_q.name,
        ...                                 local_pos_ins.name,
        ...                                 local_total_ins.name)

        >>> # below is part of model
        >>> label = paddle.static.data(name="click", shape=[-1, 1],\
        ...     dtype="int64")
        >>> emb = my_slot_net(slots, label) # emb can be fc layer of size 1
        >>> similarity_norm = paddle.nn.functional.sigmoid(paddle.clip(\
        ...     emb, min=-15.0, max=15.0), name="similarity_norm")\
        >>> binary_predict = paddle.concat(input=[\
        ...     paddle.subtract(\
        ...         paddle.ceil(similarity_norm), similarity_norm),\
        ...     similarity_norm], axis=1)
        >>> auc, batch_auc, [batch_stat_pos, batch_stat_neg, stat_pos, \
        ...     stat_neg] = paddle.static.auc(input=binary_predict,\
        ...                                  label=label, curve='ROC',\
        ...                                  num_thresholds=4096)
        >>> local_sqrerr, local_abserr, local_prob, local_q, local_pos_ins, \
        ...     local_total_ins = paddle.static.ctr_metric_bundle(\
        ...         similarity_norm, label)

NrN   r{  r|  r}  r~  r  r  z global AUC=z.6fz BUCKET_ERROR=z MAE=z RMSE=z Actual_CTR=z Predicted_CTR=z COPC=z MEAN Q_VALUE=z Ins number=)rR   r&   r  )r   r;   r  r  r  r  r  r  r  r  rI   r  r  r  r  r  r  r  r  rg   s                       r   print_global_metricsFleetUtil.print_global_metrics*  s   D NN=)1~~m,434^^K(05k]CD^^K(05k]CD^^I&.3I;?@^^F#+09:^^,-5:;K:LMN^^./7/0B/CD  ##


	
 	nLS	S?QQVWZ[^V_ `:\*S)9WZH[ \:^,?+DLQ^P_a	
r   c                 0    [         R                  " XU5      $ N)r   program_type_trans)r   prog_dirprog_fnis_texts       r   r  FleetUtil.program_type_trans  s    ''7CCr   c                 .    [         R                  " X5      $ r  )r   load_program)r   model_filenamer  s      r   r  FleetUtil.load_program  s    !!.::r   c                 p    U R                  X5      n[        R                  " UR                  5       X45        g)zdraw program from fileN)r  r   graphvizrF  )r   r  r  
output_diroutput_filenamer"  s         r   draw_from_program_file FleetUtil.draw_from_program_file  s+     ##N<w++-zKr   c                 N    [         R                  " UR                  5       X#5        g)zdraw ProgramN)r   r  rF  )r   r"  r  output_names       r   draw_from_programFleetUtil.draw_from_program  s    w++-zGr   c                    U R                  UR                  UR                  5      nU R                  UR                  UR                  5      nUR
                  (       aE  [        R                  R                  UR                  5      nU R                  X4UR                  5        [        R                  " X#5      nU(       a  [        R                  S5        U$ [        R                  S5        U$ )Nzcheck_programs succeed.zBcheck_programs failed. pruned program and train program not match!)r  train_prog_pathis_text_train_programpruned_prog_pathis_text_pruned_programdrawr   rn   dirnamer  draw_out_namer   check_pruned_program_varsr)   r*   )r   config
train_progpruned_prog
pruned_dirress         r   check_two_programsFleetUtil.check_two_programs  s    &&""F$@$@

 ''##V%B%B
 ;;)@)@AJ"")=)= --jFLL23
 
 LLT 
r   c           	         [         R                  S5        [        R                  " UR                  UR
                  UR                  UR                  UR                  UR                  UR                  5      n[         R                  S5        U$ )Nzstart check_vars_and_dump.zcheck_vars_and_dump succeed.)r)   r*   r   check_saved_vars_try_dumpdump_model_dirdump_program_filenameis_text_dump_programfeed_configfetch_config
batch_sizesave_params_filename)r   r  resultss      r   check_vars_and_dumpFleetUtil.check_vars_and_dump  sr    1211!!((''''
 	34r   c                 R    U R                  X5      n[        R                  " XC5        g)a  
Parse program.proto into a more readable format.
This function will generate three files:
output_dir/vars_all.log,
output_dir/vars_persistable.log,
output_dir/ops.log.

Args:
    prog_path(str): proto file path to be parsed.
    is_text(bool): proto file is human-readale format or not(binary).
    output_dir(str): output dir.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import FleetUtil
        >>> fleet_util = FleetUtil()
        >>> program_path = "./program.pbtxt"
        >>> is_text = True
        >>> output_dir = "/tmp/"
        >>> fleet_util.parse_program_proto(program_path, is_text, output_dir)
N)r  r   parse_program)r   	prog_pathr  r  r"  s        r   parse_program_protoFleetUtil.parse_program_proto  s"    0 ##I7G0r   rr   )r   )r   )r   donefile.txt)r   sparse_cache.meta)r   )r   T)r   NT)r   ).__name__
__module____qualname____firstlineno____doc__r   r&   r+   r/   r   global_scopeCPUPlacer@   rK   rF   ro   ru   ry   r   r   r   r   r   r  r  r
  r  r  r  r)  rA  rJ  rP  rT  rZ  rr  r  r  r  r  r  r  r  r  r  __static_attributes__ r   r   r   r   +   s   .*(. !mmo&@ !##+E^ !##	Tl-&+.78 *%h #$]0P "w0B #)L0\,4,4202460#J D5,F #T0B #i0` #/4l #1?p #4IlD$P !(("M
b !(("u
nD;LH*1r   c                      ^  \ rS rSrSrSU 4S jjrS rS rS rS r	S	 r
 SS
 jr0 SS4S jr SS jr0 S4S jrSrU =r$ )r	   i  a<  
GPUPSUtil provides some common functions for users' convenience.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.rank0_print("my log")
Nc                 0   > [         TU ]  U5        Xl        g r  )superr   _afs)r   	fs_clientr   	__class__s      r   r   GPUPSUtil.__init__  s    	r   c                 <    U R                   R                  XX45        g)a  
init for fs config

Args:
    fs_name(str): fs name
    fs_user(str): fs user
    fs_passwd(str): fs password
    fs_conf(str): fs and afs conf path

Returns:
    None

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.init(20190722, 88, 88, "./afs.conf")
N)r  init)r   fs_namefs_user	fs_passwdfs_confs        r   r  GPUPSUtil.init  s    * 			w<r   c                     Xl         g)a  
set fs_client for fs config

Args:
    fs_client(AFSClient): fs_client object

Returns:
    None

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> from paddle.distributed.fleet.utils.fs import AFSClient
        >>> hdfs_client = AFSClient()
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.set_fsclient(hdfs_client)
Nr  )r   r  s     r   set_fsclientGPUPSUtil.set_fsclient  s	    ( 	r   c                 V   US-   nU R                   R                  U5      (       d!  SS[        [        R                  " 5       5      /$ U R                   R	                  US5        Sn[        SS5       nUR                  5       nSSS5        UR                  5       n[        R                  " UR                  S5      S   5      n[        US	   R                  S
5      S   5      nS
R                  US	   R                  S
5      SS 5      n[        US   5      nXgU/$ ! , (       d  f       N= f)a  
get last saved base xbox info from xbox_base_done.txt

Args:
    output_path(str): output path

Returns:
    [last_save_day, last_path, xbox_base_key]
    last_save_day(int): day of saved model
    last_path(str): model path
    xbox_base_key(int): xbox key

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> from paddle.distributed.fleet.utils.fs import AFSClient
        >>> hdfs_client = AFSClient()
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.set_fsclient(hdfs_client)
        >>> last_save_day, last_path, xbox_base_key = \
        ...     fleet_util.get_last_save_xbox_base("hdfs:/my/path")

rM  rO   z./xbox_base_done.txtrD   r   rNr   r   r   r   r   )r  r   r   r   downloadr   r   r   r   r   r   r   )	r   r   r   r   r   r   r   rO  r   s	            r   rP  !GPUPSUtil.get_last_save_xbox_base0  s   4 $&;;yy  //C		,--		=*@A&,&&(K -!'')JJ{006r:;	y)//4R89HHYw/55c:3B?@	Ie,-]33 -,s   1D
D(c                    US-   nU R                   R                  U5      (       d"  SSS[        [        R                  " 5       5      /$ U R                   R	                  US5        Sn[        SS5       nUR                  5       nSSS5        UR                  5       n[        R                  " UR                  S5      S   5      n[        US   R                  S	5      S
   5      n[        US   R                  S	5      S   R                  S5      S   5      nS	R                  US   R                  S	5      SS 5      n[        US   5      n	[        R                  " S5        XgX/$ ! , (       d  f       N= f)a)  
get last saved xbox info from xbox_patch_done.txt

Args:
    output_path(str): output path

Returns:
    [last_save_day, last_save_pass, last_path, xbox_base_key]
    last_save_day(int): day of saved model
    last_save_pass(int): pass id of saved
    last_path(str): model path
    xbox_base_key(int): xbox key

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> from paddle.distributed.fleet.utils.fs import AFSClient
        >>> hdfs_client = AFSClient()
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.set_fsclient(hdfs_client)
        >>> last_save_day, last_save_pass, last_path, xbox_base_key = \
        ...     fleet_util.get_last_save_xbox("hdfs:/my/path")

rS  rO   rD   r   r
  Nr   r   r   r   r   r   r   )r  r   r   r   r  r   r   r   r   r   r   r   r   remove)
r   r   r   r   r   r   r   r   rO  r   s
             r   rT  GPUPSUtil.get_last_save_xboxZ  sD   6 $&<<yy  //BDIIK 011		=*?@'-&&(K .!'')JJ{006r:;	y)//4R89	'*005b9??DRHI	HHYw/55c:3B?@	Ie,-
		'(Y>> .-s   2E##
E1c                 8   SnSnSnUS-   nU R                   R                  U5      (       d"  SSS[        [        R                  " 5       5      /$ U R                   R	                  US5        Sn[        SS5       nUR                  5       nSSS5        UR                  5       R                  S5      S   R                  S	5      n[        US
   5      n[        US   5      nUS   n[        US   5      n[        R                  " S5        X#XH/$ ! , (       d  f       N= f)a$  
get last saved model info from donefile.txt

Args:
    output_path(str): output path

Returns:
    [last_save_day, last_save_pass, last_path, xbox_base_key]
    last_save_day(int): day of saved model
    last_save_pass(int): pass id of saved
    last_path(str): model path
    xbox_base_key(int): xbox key

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> from paddle.distributed.fleet.utils.fs import AFSClient
        >>> hdfs_client = AFSClient()
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.set_fsclient(hdfs_client)
        >>> last_save_day, last_save_pass, last_path, xbox_base_key = \
        ...     fleet_util.get_last_save_model("hdfs:/my/path")

rO   rD   rW  z./donefile.txtr  r
  Nr   r   r   r   rQ   r   )r  r   r   r   r  r   r   r   r   r   r  )	r   r   rX  rY  rO  r   r   r   r   s	            r   rZ  GPUPSUtil.get_last_save_model  s    6 	#o5yy  //BDIIK 011		=*:;.#&!ffhG '--/''-b177=GAJWQZAJ	GAJ
		.!yHH '&s   8D
Dc           	      J   [        U5      n[        U5      n[        U5      nUS:w  a  SU SU S3nUR                  S5      U-   nOSU S3nUR                  S5      U-   n[        R	                  5       S:X  Gam  US-   U-   nU SU SU SU SS 3	n	U R
                  R                  U5      (       Ga  U R
                  R                  X5        Sn
[        US5       nUR                  5       n
SSS5        U
R                  5       R                  S	5      nU Vs/ s H  oR                  S5      S   PM     nnU Vs/ s H  oR                  S5      S
   PM     nn[        R                  " U5        Sn[        [        U5      5       H=  n[        U5      [        X   5      :X  d  M  [        U5      [        X   5      :X  d  M;  Sn  O   U(       d  [        US5       nUR!                  U
R                  5       S	-   5        UR!                  U	S	-   5        SSS5        U R
                  R#                  U5        U R
                  R%                  XX5        U R'                  SU SU SU S35        gU R'                  SU SU SU S35        g[        US5       nUR!                  U	S	-   5        SSS5        U R
                  R%                  XX5        U R'                  SU SU SU S35        gg! , (       d  f       GN= fs  snf s  snf ! , (       d  f       N= f! , (       d  f       Ns= f)al  
write donefile when save model

Args:
    output_path(str): output path
    day(str|int): training day
    pass_id(str|int): training pass id
    xbox_base_key(str|int): xbox base key
    donefile_name(str): donefile name, default is "donefile.txt"

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> from paddle.distributed.fleet.utils.fs import AFSClient
        >>> hdfs_client = AFSClient()
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.set_fsclient(hdfs_client)
        >>> fleet_util.write_model_donefile(output_path="hdfs:/my/output",
        ...                                 day=20190723,
        ...                                 pass_id=66,
        ...                                 xbox_base_key=int(time.time()))

r   r   r   r   r   rD   r
  Nr   r   FTr   r   r   r   r   r   r   )r   r   r   r   r   r  r   r  r   r   r   r   r   r  r\   r[   r   r   r   r/   )r   r   r   r   r   r   r   r   r   r   r   r   r   rh   r   r   r   s                    r   r   GPUPSUtil.write_model_donefile  s   B #hg,M*d?cU!G9A.K$++C0;>JcU#,K$++C0;>J1$'#-=MRbBwir!MGyy  //		""=@ --"#&&(K .#.#4#4#6#<#<T#B 6FG6FGGDM!,6FG7GH7G!WWT]1-7G	H		-(s8}-A3x3x{#33G!I 9 !% . mS1Q 1 1 3d :;$/ 2 II$$]3II$$]B$$ QwiqxH $$$]O9SE7) L! !
 --GGGdN+ .		  >  SE7)1]O8DK % .- HH 21 .-s0   K'K9:K>7LL'
K6
L
L"r   c                    [        U5      n[        U5      n[        U5      nSnUS:w  a%  SnSU SU S3nUR                  S5      U-   nU
c  Sn
O!SnSU S3nUR                  S5      U-   nU
c  S	n
[        U[        5      (       a  S
R                  U5      n[        R                  5       S:X  Ga  US-   U
-   nU R                  UUUUUU0 US9nU R                  R                  U5      (       Ga  U R                  SU S35        U R                  R                  X5        Sn[        U
S5       nUR                  5       nSSS5        [        R                   " UR#                  5       R%                  S5      S   5      nUS   R%                  S5      S   nUS   R%                  S5      S   R%                  S5      S   n[&        R(                  " U
5        U R                  SU
 S35        Sn[        U5      [        U5      :  d0  [        U5      [        U5      :X  a  [        U5      [        U5      ::  a  SnU(       d  [        U
S5       nUR+                  UR#                  5       S-   5        UR+                  US-   5        SSS5        U R                  R-                  U5        U R                  R/                  X5        U R                  SU SU SU
 S35        gU R                  SU
 SU SU S35        g[        U
S5       nUR+                  US-   5        SSS5        U R                  R/                  X5        U R1                  SU SU SU
 S35        gg! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       Ni= f) a  
write delta donefile or xbox base donefile

Args:
    output_path(str): output path
    day(str|int): training day of model
    pass_id(str|int): training pass id of model
    xbox_base_key(str|int): xbox base key
    data_path(str|list): training data path
    monitor_data(dict): metrics
    hadoop_home(str): hadoop home, default is "$HADOOP_HOME"
    donefile_name(str): donefile name, default is None"

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> from paddle.distributed.fleet.utils.fs import AFSClient
        >>> hdfs_client = AFSClient()
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.set_fsclient(hdfs_client)
        >>> fleet_util.write_xbox_donefile(
        ...     output_path="hdfs:/my/output/",
        ...     day=20190722,
        ...     pass_id=1,
        ...     xbox_base_key=int(time.time()),
        ...     data_path="hdfs:/my/data/",
        ...     monitor_data={})

Nr   r{   r   r   r   r   r   r   r   r   r   zexist r   rD   r
  r   rO   r   r   r   r   zremove FTr   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r  r9  r+   r  r   r   r   r   r   r   r   r  r   r   r   r/   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                         r   r   GPUPSUtil.write_xbox_donefile  sV   X #hg,M*d?DcU''!4K$++C0;>J$ 5DcU&/K$++C0;>J$ 4i&&+I1$'#-=M)) * 	H yy!!-00&x @A		""=@ --"#&&(K . JJ{'8'8':'@'@'Fr'JK	$W-33C8<%g.44S9"=CCCHL			-('- ABHs8},3x3x=0GI6 EmS1Q 1 1 3d :;40 2 II$$]3II$$]BOO QwiqxH OO$]O9SE7) L! !
 --GGHtO, .		  >  SE7)1]O8De %" .-  21 .-s$   ,M7M%>M6
M"%
M36
Nc                    [        U5      n[        U5      n[        U5      nUR                  SS5      nUR                  SS5      nUS:w  a"  SU SU SUS S	3n	UR                  S5      U	-   n
OSU S
US S	3n	UR                  S5      U	-   n
[        R                  5       S:X  a  U
S-   U-   nU R                  R                  U5      (       a  U R                  SU S35        gSU SU S3n[        US5       nUR                  U5        SSS5        U R                  R                  X[5        U R                  SU S35        gg! , (       d  f       N@= f)a  
write cache donefile

Args:
    output_path(str): output path
    day(str|int): training day of model
    pass_id(str|int): training pass id of model
    key_num(str|int): save cache return value
    donefile_name(str): donefile name, default is "sparse_cache.meta"
    kwargs(dict): user defined properties
                  file_num(int): cache file num
                  table_id(int): cache table id

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:DISTRIBUTED)
        >>> from paddle.incubate.distributed.fleet.fleet_util import GPUPSUtil
        >>> from paddle.distributed.fleet.utils.fs import AFSClient
        >>> hdfs_client = AFSClient()
        >>> fleet_util = GPUPSUtil()
        >>> fleet_util.set_fsclient(hdfs_client)
        >>> fleet_util.write_cache_donefile(
        ...     output_path="hdfs:/my/output/",
        ...     day=20190722,
        ...     pass_id=1,
        ...     key_num=123456)

r   r   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   Nr   r   )r   r   r   r   r   r   r  r   r/   r   r   r   )r   r   r   r   r   r   r   r   rm   r   r   r   r   r   s                 r   r   GPUPSUtil.write_cache_donefile}  s]   L #hg,g,::j"-::j!,d?cU''!HR=GK$++C0;>JcU&"V<K$++C0;>J1$&,}<Myy  //  (G 9
*WIUWX--GGH% .		  >  6-!AB % .-s   7E
Er{   c	                 &   [         R                  " 5       n	US:X  a  [        U5      U	S'   OlUS:X  a+  [        [        [        R                  " 5       5      5      U	S'   O;[        SU S35        Sn[        [        [        R                  " 5       5      5      U	S'   [        U5      U	S'   UR                  S5      (       d  UR                  S5      (       a  X3R                  S	5      S
-   S  nXcR                  S5      -   S-   U	S'   SU	S'   SU	S'   SU	S'   SU	S'   XYS'   [        R                  R                  SS5      U	S'   SU	S'   UR                  S5      S-   U-   S-   U	S'   [        [        R                  5       5      U	S'   [        R                  " U	5      $ )Nr   r}   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   PADDLE_JOB_IDrD   r   r   r   r   r   r   )r   r   r   r   r   r    r   r   r   r   environr   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   s
             r   r   GPUPSUtil._get_xbox_str  s     ++-	6>!-0IdOW_!#diik"23IdO*4&0ABCD!#diik"23IdO}-	%  ))Z-B-B6-J-J#OOC$81$<$>?J+.?.?.DDvM	'$,	.!&)	"# 2	*(	) )* jjnn_bA	($&	.!s#k1C7&@ 	.! !$E$4$4$6 7	*zz)$$r   r  )Nr   )r  )r  )r  r  r  r  r  r   r  r  rP  rT  rZ  r   r   r   r   r  __classcell__)r  s   @r   r	   r	     sf    

=.,(4T*?X+If %S| "sv *?CR $% $%r   )r  r   r   loggingr  r   r_  r!   r   numpyr5   r4  r   paddle.base.log_helperr   !paddle.distributed.fleet.utils.fsr   rD   r   __all__r  INFOr)   r   r   r	   r  r   r   <module>r#     sv         	 	 
     - 8 
$
gll H 	C1 C1L6q%	 q%r   