@@ -1156,16 +1156,14 @@ def complete(self):
1156
1156
1157
1157
class Switch (object ):
1158
1158
"""
1159
- **Switch Class**
1160
-
1161
- Many programming languages provide `switch` as a generalization of `if-elif-else`.
1162
- Switch class works just like a `if-elif-else`.
1159
+ Switch class works just like a `if-elif-else`. Can be used in learning rate scheduler
1160
+ to modify learning rate
1163
1161
1164
1162
The Semantics:
1165
1163
1166
1164
1. A `switch` control-flow checks cases one-by-one.
1167
1165
1168
- 2. The condition of each case is a boolean value, which is a scalar.
1166
+ 2. The condition of each case is a boolean value, which is a scalar Variable .
1169
1167
1170
1168
3. It runs the first matched case, or the default case if there is one.
1171
1169
@@ -1174,9 +1172,22 @@ class Switch(object):
1174
1172
Examples:
1175
1173
.. code-block:: python
1176
1174
1177
- with fluid.control_flow.Switch() as switch:
1175
+ lr = fluid.layers.tensor.create_global_var(
1176
+ shape=[1],
1177
+ value=0.0,
1178
+ dtype='float32',
1179
+ persistable=True,
1180
+ name="learning_rate")
1181
+ one_var = tensor.fill_constant(
1182
+ shape=[1], dtype='float32', value=1.0)
1183
+ two_var = tensor.fill_constant(
1184
+ shape=[1], dtype='float32', value=2.0)
1185
+
1186
+ with fluid.layers.control_flow.Switch() as switch:
1178
1187
with switch.case(global_step == zero_var):
1179
- fluid.tensor.assign(input=one_var, output=div_res)
1188
+ fluid.layers.tensor.assign(input=one_var, output=lr)
1189
+ with switch.default():
1190
+ fluid.layers.tensor.assign(input=two_var, output=lr)
1180
1191
1181
1192
"""
1182
1193
0 commit comments