Esempio n. 1
0
 def assign_fn(value_def: oft.Numpy.Placeholder(value.shape, dtype=dtype)):
     var = flow.get_variable(
         name="var",
         shape=value.shape,
         dtype=dtype,
         initializer=flow.constant_initializer(0),
     )
     flow.assign(var, value_def)
Esempio n. 2
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)
         # do no use `w` again because it's delegated by `ref` and `value`
         # W_mutable = W_mutable + 1
         flow.assign(ref, ref + ones)
         return value
Esempio n. 3
0
 def Foo():
     with flow.scope.placement("gpu", "0:1"):
         x = flow.get_variable(
             "x",
             shape=(2, 5),
             dtype=flow.float,
             initializer=flow.random_uniform_initializer(minval=0, maxval=1),
             trainable=False,
         )
     with flow.scope.placement("gpu", "0:2"):
         y = flow.get_variable(
             "y",
             shape=(2, 5),
             dtype=flow.float,
             initializer=flow.constant_initializer(0),
             trainable=False,
         )
         flow.assign(y, x)
     return y
Esempio n. 4
0
 def update_moving(moving, this_batch):
     moving_identity = flow.identity(moving)
     flow.assign(
         moving,
         momentum * moving_identity + (1 - momentum) * this_batch)
Esempio n. 5
0
        def copyQNetToQnetT():
            with flow.scope.placement(self.device_tag_, "0:0-0"):
                (
                    t_conv1_weight,
                    t_conv1_bias,
                    t_conv2_weight,
                    t_conv2_bias,
                    t_fc1_weight,
                    t_fc1_bias,
                    t_fc2_weight,
                    t_fc2_bias,
                ) = getQNetParams(var_name_prefix="QNet", is_train=True)
                (
                    p_conv1_weight,
                    p_conv1_bias,
                    p_conv2_weight,
                    p_conv2_bias,
                    p_fc1_weight,
                    p_fc1_bias,
                    p_fc2_weight,
                    p_fc2_bias,
                ) = getQNetParams(var_name_prefix="QNetT", is_train=False)

                flow.assign(p_conv1_weight, t_conv1_weight)
                flow.assign(p_conv1_bias, t_conv1_bias)
                flow.assign(p_conv2_weight, t_conv2_weight)
                flow.assign(p_conv2_bias, t_conv2_bias)
                flow.assign(p_fc1_weight, t_fc1_weight)
                flow.assign(p_fc1_bias, t_fc1_bias)
                flow.assign(p_fc2_weight, t_fc2_weight)
                flow.assign(p_fc2_bias, t_fc2_bias)
Esempio n. 6
0
def copyQNetToQnetT():
    with flow.scope.placement(DEVICE_TAG, "0:0-%d" % (DEVICE_NUM - 1)):
        t_conv1_weight, t_conv1_bias, t_conv2_weight, t_conv2_bias, t_fc1_weight, t_fc1_bias, t_fc2_weight, t_fc2_bias = \
            getQNetParams(var_name_prefix = "QNet", is_train = True)
        p_conv1_weight, p_conv1_bias, p_conv2_weight, p_conv2_bias, p_fc1_weight, p_fc1_bias, p_fc2_weight, p_fc2_bias = \
            getQNetParams(var_name_prefix = "QNetT", is_train = False)

        flow.assign(p_conv1_weight, t_conv1_weight)
        flow.assign(p_conv1_bias, t_conv1_bias)
        flow.assign(p_conv2_weight, t_conv2_weight)
        flow.assign(p_conv2_bias, t_conv2_bias)
        flow.assign(p_fc1_weight, t_fc1_weight)
        flow.assign(p_fc1_bias, t_fc1_bias)
        flow.assign(p_fc2_weight, t_fc2_weight)
        flow.assign(p_fc2_bias, t_fc2_bias)