未验证 提交 d7668699 编写于 作者: L Leo Chen 提交者: GitHub

Polish usage of deprecated or private API in Dygraph (#4035)

上级 1fb663c5
...@@ -226,12 +226,8 @@ class DataParallel(layers.Layer): ...@@ -226,12 +226,8 @@ class DataParallel(layers.Layer):
grad_vars = [] grad_vars = []
for param in self._layers.parameters(): for param in self._layers.parameters():
# NOTE(zcd): The grad_ivar maybe no generated. # NOTE(zcd): The grad_ivar maybe no generated.
if param.trainable and param._ivar._grad_ivar(): if param.trainable and param._grad_ivar():
g_var = framework.Variable( g_var = param._grad_ivar()
block=self._helper.main_program.current_block(),
name=param._ivar._grad_name(),
stop_gradient=True,
ivar=param._ivar._grad_ivar())
grad_vars.append(g_var) grad_vars.append(g_var)
assert g_var not in grad_var_set assert g_var not in grad_var_set
grad_var_set.add(g_var) grad_var_set.add(g_var)
......
...@@ -367,7 +367,7 @@ class PositionEmbedding(dg.Layer): ...@@ -367,7 +367,7 @@ class PositionEmbedding(dg.Layer):
def set_weight(self, array): def set_weight(self, array):
assert self.embed._w.shape == list(array.shape), "shape does not match" assert self.embed._w.shape == list(array.shape), "shape does not match"
self.embed._w._ivar.value().get_tensor().set( self.embed._w.value().get_tensor().set(
array, fluid.framework._current_expected_place()) array, fluid.framework._current_expected_place())
def forward(self, indices, speaker_position_rate=None): def forward(self, indices, speaker_position_rate=None):
......
...@@ -486,8 +486,7 @@ def train(args): ...@@ -486,8 +486,7 @@ def train(args):
label_in = to_variable(data_dict["label_in"]) label_in = to_variable(data_dict["label_in"])
label_out = to_variable(data_dict["label_out"]) label_out = to_variable(data_dict["label_out"])
label_out._stop_gradient = True label_out.stop_gradient = True
label_out.trainable = False
img = to_variable(data_dict["pixel"]) img = to_variable(data_dict["pixel"])
...@@ -528,8 +527,7 @@ def train(args): ...@@ -528,8 +527,7 @@ def train(args):
label_in = to_variable(data_dict["label_in"]) label_in = to_variable(data_dict["label_in"])
label_out = to_variable(data_dict["label_out"]) label_out = to_variable(data_dict["label_out"])
label_out._stop_gradient = True label_out.stop_gradient = True
label_out.trainable = False
img = to_variable(data_dict["pixel"]) img = to_variable(data_dict["pixel"])
...@@ -549,8 +547,6 @@ def train(args): ...@@ -549,8 +547,6 @@ def train(args):
optimizer.minimize(avg_loss, grad_clip=grad_clip) optimizer.minimize(avg_loss, grad_clip=grad_clip)
ocr_attention.clear_gradients() ocr_attention.clear_gradients()
framework._dygraph_tracer()._clear_ops()
if batch_id > 0 and batch_id % 1000 == 0: if batch_id > 0 and batch_id % 1000 == 0:
print("epoch: {}, batch_id: {}, loss {}".format(epoch, batch_id, total_loss / args.batch_size / 1000)) print("epoch: {}, batch_id: {}, loss {}".format(epoch, batch_id, total_loss / args.batch_size / 1000))
......
...@@ -247,7 +247,7 @@ def eval(model, data): ...@@ -247,7 +247,7 @@ def eval(model, data):
img = to_variable(dy_x_data) img = to_variable(dy_x_data)
label = to_variable(y_data) label = to_variable(y_data)
label._stop_gradient = True label.stop_gradient = True
out = model(img) out = model(img)
#loss = fluid.layers.cross_entropy(input=out, label=label) #loss = fluid.layers.cross_entropy(input=out, label=label)
...@@ -335,7 +335,7 @@ def train_resnet(): ...@@ -335,7 +335,7 @@ def train_resnet():
img = to_variable(dy_x_data) img = to_variable(dy_x_data)
label = to_variable(y_data) label = to_variable(y_data)
label._stop_gradient = True label.stop_gradient = True
out = resnet(img) out = resnet(img)
loss = fluid.layers.cross_entropy(input=out, label=label) loss = fluid.layers.cross_entropy(input=out, label=label)
......
...@@ -336,7 +336,7 @@ def eval(model, data): ...@@ -336,7 +336,7 @@ def eval(model, data):
img = to_variable(dy_x_data) img = to_variable(dy_x_data)
label = to_variable(y_data) label = to_variable(y_data)
label._stop_gradient = True label.stop_gradient = True
out = model(img) out = model(img)
softmax_out = fluid.layers.softmax(out, use_cudnn=False) softmax_out = fluid.layers.softmax(out, use_cudnn=False)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册