def op_function(x: tp.Numpy.Placeholder(input.shape, dtype=value_type)): with flow.scope.placement(device_type, "0:0"): x += flow.get_variable( name="input", shape=input.shape, dtype=value_type, initializer=flow.zeros_initializer(), ) out = flow.reflection_pad2d(x, padding) flow.optimizer.SGD( flow.optimizer.PiecewiseConstantScheduler([], [0]), momentum=0 ).minimize(out) flow.watch_diff(x, _compare_diff) return out
def op_function(x: tp.Numpy.Placeholder(input.shape, dtype=flow.float32)): with flow.scope.placement(device_type, "0:0"): x_var = flow.get_variable( name="input", shape=input.shape, dtype=flow.float32, initializer=flow.constant_initializer(0), ) x_var = flow.cast_to_current_logical_view(x_var) input_x = x_var + x x_fp32 = flow.cast(input_x, flow.float32) x_fp16 = flow.cast(input_x, dtype=flow.float16) y_fp16 = flow.reflection_pad2d(x_fp16, padding) y_fp32 = flow.cast(y_fp16, dtype=flow.float32) flow.optimizer.SGD( flow.optimizer.PiecewiseConstantScheduler([], [0]), momentum=0 ).minimize(y_fp32) flow.watch_diff(x_fp32, _compare_diff) return y_fp32