Ejemplo n.º 1
0
 def Foo() -> tp.Numpy:
     with flow.scope.placement("cpu", device_name):
         w = flow.get_variable(
             "w",
             shape=(10,),
             dtype=flow.float,
             initializer=flow.constant_initializer(0),
         )
         ones = flow.constant_like(w, value=1.0, dtype=flow.float)
         (ref, value) = flow.experimental.ssp_variable_proxy(
             w, buffer_size=buffer_size
         )
         flow.assign(ref, ref + ones)
         return value
Ejemplo n.º 2
0
 def Foo() -> tp.Numpy:
     with flow.scope.placement(
         "cpu", device_name
     ), flow.experimental.scope.config(
         ssp_num_stages=buffer_size, ssp_stage_id=0
     ):
         w = flow.get_variable(
             "w",
             shape=(10,),
             dtype=flow.float,
             initializer=flow.constant_initializer(0),
         )
         loss = w + flow.constant_like(w, value=0.0, dtype=flow.float)
         flow.optimizer.SGD(
             flow.optimizer.PiecewiseConstantScheduler([], [-10.0]), momentum=0
         ).minimize(loss)
         return loss
Ejemplo n.º 3
0
 def FuseBnAddReluJob(x: oft.Numpy.Placeholder(
     shape, dtype=in_type)) -> oft.Numpy:
     addend = flow.constant_like(x, 2)
     with flow.scope.placement(device, "0:0-0"):
         x = (flow.get_variable(
             "x1",
             shape=shape,
             dtype=in_type,
             initializer=flow.random_uniform_initializer(minval=-10,
                                                         maxval=10),
             trainable=True,
         ) + x)
         loss = flow.nn.relu(_batch_norm(x, last=False) + addend) + 1
         flow.optimizer.SGD(flow.optimizer.PiecewiseConstantScheduler(
             [], [0.0001]),
                            momentum=0).minimize(loss)
         return loss
Ejemplo n.º 4
0
 def ConstantLikeJob(x: oft.Numpy.Placeholder(x.shape)):
     return flow.constant_like(x, value=value, dtype=dtype)