Skip to content

Commit dadbe45

Browse files
authored
Merge pull request #11511 from panyx0718/doc2
Add doc for while and piecewise_decay op
2 parents 3a4b6cd + a219f3c commit dadbe45

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

python/paddle/fluid/layers/control_flow.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,29 @@ def __exit__(self, exc_type, exc_val, exc_tb):
654654

655655

656656
class While(object):
657+
"""
658+
while loop control flow.
659+
660+
Args:
661+
cond (Variable): condition used to compare.
662+
name (str): The name of this layer.
663+
664+
Examples:
665+
.. code-block:: python
666+
667+
d0 = layers.data("d0", shape=[10], dtype='float32')
668+
data_array = layers.array_write(x=d0, i=i)
669+
array_len = layers.fill_constant(shape=[1],dtype='int64', value=3)
670+
671+
cond = layers.less_than(x=i, y=array_len)
672+
while_op = layers.While(cond=cond)
673+
with while_op.block():
674+
d = layers.array_read(array=data_array, i=i)
675+
i = layers.increment(x=i, in_place=True)
676+
layers.array_write(result, i=i, array=d)
677+
layers.less_than(x=i, y=array_len, cond=cond)
678+
"""
679+
657680
BEFORE_WHILE_BLOCK = 0
658681
IN_WHILE_BLOCK = 1
659682
AFTER_WHILE_BLOCK = 2

python/paddle/fluid/layers/learning_rate_scheduler.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,27 @@ def polynomial_decay(learning_rate,
209209
def piecewise_decay(boundaries, values):
210210
"""Applies piecewise decay to the initial learning rate.
211211
212-
>>> boundaries = [10000, 20000]
213-
>>> values = [1.0, 0.5, 0.1]
214-
>>>
215-
>>> if step < 10000:
216-
>>> learning_rate = 1.0
217-
>>> elif 10000 <= step < 20000:
218-
>>> learning_rate = 0.5
219-
>>> else:
220-
>>> learning_rate = 0.1
212+
The algorithm can be described as the code below.
213+
214+
.. code-block:: python
215+
216+
boundaries = [10000, 20000]
217+
values = [1.0, 0.5, 0.1]
218+
if step < 10000:
219+
learning_rate = 1.0
220+
elif 10000 <= step < 20000:
221+
learning_rate = 0.5
222+
else:
223+
learning_rate = 0.1
224+
Args:
225+
boundaries: A list of steps numbers.
226+
values: A list of learning rate values that will be picked during
227+
different step boundaries.
228+
229+
Returns:
230+
The decayed learning rate.
231+
232+
221233
"""
222234

223235
if len(values) - len(boundaries) != 1:

0 commit comments

Comments
 (0)