21
21
from ..initializer import force_init_on_cpu
22
22
from .ops import logical_and , logical_not , logical_or
23
23
import numpy
24
+ import warnings
24
25
from functools import reduce
25
26
26
27
__all__ = [
@@ -276,11 +277,14 @@ class ParallelDo(object):
276
277
avg_cost = fluid.layers.mean(x=cost)
277
278
278
279
.. warning::
279
-
280
+
280
281
It will be soon deprecated, please use ParallelExecutor instead.
281
282
"""
282
283
283
284
def __init__ (self , places , use_nccl = False , name = None ):
285
+ warnings .warn (
286
+ "API ParallelDo is deprecated since 0.15.0. Please use ParallelExecutor instead." ,
287
+ Warning )
284
288
self .helper = LayerHelper ("parallel_do" , name = name )
285
289
self .inputs = []
286
290
self .places = places
@@ -339,7 +343,7 @@ def get_parameters(self):
339
343
340
344
return [parent_block .var (name ) for name in params ]
341
345
342
- def complete_op (self ):
346
+ def _complete_op (self ):
343
347
main_program = self .helper .main_program
344
348
current_block = main_program .current_block ()
345
349
parent_block = self .parent_block ()
@@ -395,7 +399,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
395
399
if exc_type is not None :
396
400
return False
397
401
self .rnn .status = StaticRNN .AFTER_RNN_BLOCK
398
- self .rnn .complete_op ()
402
+ self .rnn ._complete_op ()
399
403
return super (BlockGuardWithCompletion , self ).__exit__ (exc_type , exc_val ,
400
404
exc_tb )
401
405
@@ -471,7 +475,7 @@ def memory(self,
471
475
if shape is None or batch_ref is None :
472
476
raise ValueError (
473
477
"if init is None, memory at least need shape and batch_ref" )
474
- parent_block = self .parent_block ()
478
+ parent_block = self ._parent_block ()
475
479
var_name = unique_name .generate ("@" .join (
476
480
[self .helper .name , "memory_boot" ]))
477
481
boot_var = parent_block .create_var (
@@ -528,7 +532,7 @@ def step_output(self, o):
528
532
outputs = {'Out' : tmp_o },
529
533
attrs = {'dtype' : o .dtype })
530
534
531
- out_var = self .parent_block ().create_var (
535
+ out_var = self ._parent_block ().create_var (
532
536
name = tmp_o .name ,
533
537
shape = [self .seq_len ] + list (tmp_o .shape ),
534
538
dtype = tmp_o .dtype )
@@ -544,7 +548,7 @@ def update_memory(self, mem, var):
544
548
raise TypeError ("update memory should take variables" )
545
549
self .memories [mem .name ].mem = var
546
550
547
- def parent_block (self ):
551
+ def _parent_block (self ):
548
552
prog = self .helper .main_program
549
553
parent_idx = prog .current_block ().parent_idx
550
554
assert parent_idx >= 0
@@ -561,10 +565,10 @@ def __call__(self, *args, **kwargs):
561
565
else :
562
566
return self .outputs
563
567
564
- def complete_op (self ):
568
+ def _complete_op (self ):
565
569
main_program = self .helper .main_program
566
570
rnn_block = main_program .current_block ()
567
- parent_block = self .parent_block ()
571
+ parent_block = self ._parent_block ()
568
572
569
573
local_inputs = set ()
570
574
@@ -644,7 +648,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
644
648
if exc_type is not None :
645
649
return False
646
650
self .while_op .status = While .AFTER_WHILE_BLOCK
647
- self .while_op .complete ()
651
+ self .while_op ._complete ()
648
652
return super (WhileGuard , self ).__exit__ (exc_type , exc_val , exc_tb )
649
653
650
654
@@ -691,7 +695,7 @@ def __init__(self, cond, name=None):
691
695
def block (self ):
692
696
return WhileGuard (self )
693
697
694
- def complete (self ):
698
+ def _complete (self ):
695
699
main_program = self .helper .main_program
696
700
while_block = main_program .current_block ()
697
701
parent_block = main_program .block (main_program .current_block ()
@@ -816,21 +820,21 @@ def max_sequence_len(rank_table):
816
820
817
821
818
822
def lod_tensor_to_array (x , table ):
819
- """
823
+ """
820
824
Convert a LoDTensor to a LoDTensorArray.
821
825
822
- This function split a LoDTesnor to a LoDTensorArray according to its LoD
823
- information. LoDTensorArray is an alias of C++ std::vector<LoDTensor> in
824
- PaddlePaddle. The generated LoDTensorArray of this function can be further read
825
- or written by `read_from_array()` and `write_to_array()` operators. However,
826
- this function is generally an internal component of PaddlePaddle `DynamicRNN`.
826
+ This function split a LoDTesnor to a LoDTensorArray according to its LoD
827
+ information. LoDTensorArray is an alias of C++ std::vector<LoDTensor> in
828
+ PaddlePaddle. The generated LoDTensorArray of this function can be further read
829
+ or written by `read_from_array()` and `write_to_array()` operators. However,
830
+ this function is generally an internal component of PaddlePaddle `DynamicRNN`.
827
831
Users should not use it directly.
828
832
829
833
Args:
830
834
x (Variable|list): The LoDTensor to be converted to a LoDTensorArray.
831
835
table (ParamAttr|list): The variable that stores the level of lod
832
836
which is ordered by sequence length in
833
- descending order. It is generally generated
837
+ descending order. It is generally generated
834
838
by `layers.lod_rank_table()` API.
835
839
836
840
Returns:
@@ -1064,9 +1068,9 @@ def array_read(array, i):
1064
1068
Given:
1065
1069
1066
1070
array = [0.6, 0.1, 0.3, 0.1]
1067
-
1071
+
1068
1072
And:
1069
-
1073
+
1070
1074
i = 2
1071
1075
1072
1076
Then:
@@ -1173,9 +1177,9 @@ def array_length(array):
1173
1177
1174
1178
class ConditionalBlockGuard (BlockGuard ):
1175
1179
"""
1176
- ConditionalBlockGuard is derived from BlockGuard. It is dedicated for
1177
- holding a ConditionalBlock, and helping users entering and exiting the
1178
- ConditionalBlock via Python's 'with' keyword. However, ConditionalBlockGuard
1180
+ ConditionalBlockGuard is derived from BlockGuard. It is dedicated for
1181
+ holding a ConditionalBlock, and helping users entering and exiting the
1182
+ ConditionalBlock via Python's 'with' keyword. However, ConditionalBlockGuard
1179
1183
is generally an internal component of IfElse, users should not use it directly.
1180
1184
"""
1181
1185
@@ -1929,7 +1933,7 @@ def is_empty(x, cond=None, **ignored):
1929
1933
1930
1934
Args:
1931
1935
x (Variable): The Variable to be tested.
1932
- cond (Variable|None): Output parameter. Returns the test result
1936
+ cond (Variable|None): Output parameter. Returns the test result
1933
1937
of given 'x'. Default: None
1934
1938
1935
1939
Returns:
0 commit comments