提交 111ee988 编写于 作者: P phlrain

fix some bugs; test=develop

上级 eaeff90e
...@@ -815,8 +815,8 @@ def GenerateNodeCreationCodes( ...@@ -815,8 +815,8 @@ def GenerateNodeCreationCodes(
set_retain_grad = f" egr::EagerUtils::CheckAndRetainGrad(api_result);" set_retain_grad = f" egr::EagerUtils::CheckAndRetainGrad(api_result);"
set_grad_in_meta = f" grad_node->SetGradInMeta(api_result, {pos});" set_grad_in_meta = f" grad_node->SetGradInMeta(api_result, {pos});"
else: else:
set_retain_grad = f" egr::EagerUtils::CheckAndRetainGrad(api_result[{pos}]);" set_retain_grad = f" egr::EagerUtils::CheckAndRetainGrad(std::get<{pos}>(api_result));"
set_grad_in_meta = f" grad_node->SetGradInMeta(api_result[{pos}], {pos});" set_grad_in_meta = f" grad_node->SetGradInMeta(std::get<{pos}>(api_result), {pos});"
set_out_rank_list.append(set_out_rank) set_out_rank_list.append(set_out_rank)
set_history_list.append(set_history) set_history_list.append(set_history)
......
...@@ -60,7 +60,7 @@ def FindParsingFunctionFromAttributeType(atype): ...@@ -60,7 +60,7 @@ def FindParsingFunctionFromAttributeType(atype):
## Refactored Functions ## ## Refactored Functions ##
########################## ##########################
PARSE_PYTHON_C_TENSORS_TEMPLATE = \ PARSE_PYTHON_C_TENSORS_TEMPLATE = \
" auto {} = {}(\"{}\", \"{}\", args, {}, false);\n" " auto {} = {}(\"{}\", \"{}\", args, {}, {});\n"
PARSE_PYTHON_C_ARGS_TEMPLATE = \ PARSE_PYTHON_C_ARGS_TEMPLATE = \
...@@ -303,15 +303,17 @@ class PythonCSingleFunctionGenerator: ...@@ -303,15 +303,17 @@ class PythonCSingleFunctionGenerator:
is_optional = (name in optional_inputs) is_optional = (name in optional_inputs)
if IsVectorTensorType(ttype): if IsVectorTensorType(ttype):
get_eager_tensor_str += PARSE_PYTHON_C_TENSORS_TEMPLATE.format( get_eager_tensor_str += PARSE_PYTHON_C_TENSORS_TEMPLATE.format(
name, "GetTensorListFromArgs", forward_api_name, name, pos) name, "GetTensorListFromArgs", forward_api_name, name, pos,
"false")
else: else:
if is_optional: if is_optional:
get_eager_tensor_str += PARSE_PYTHON_C_TENSORS_TEMPLATE.format( get_eager_tensor_str += PARSE_PYTHON_C_TENSORS_TEMPLATE.format(
name, "GetOptionalTensorFromArgs", forward_api_name, name, "GetOptionalTensorFromArgs", forward_api_name,
name, pos) name, pos, "true")
else: else:
get_eager_tensor_str += PARSE_PYTHON_C_TENSORS_TEMPLATE.format( get_eager_tensor_str += PARSE_PYTHON_C_TENSORS_TEMPLATE.format(
name, "GetTensorFromArgs", forward_api_name, name, pos) name, "GetTensorFromArgs", forward_api_name, name, pos,
"false")
parse_attributes_str = "" parse_attributes_str = ""
......
...@@ -21,7 +21,7 @@ from paddle.utils import deprecated ...@@ -21,7 +21,7 @@ from paddle.utils import deprecated
from . import nn from . import nn
from .layer_function_generator import templatedoc from .layer_function_generator import templatedoc
from ..layer_helper import LayerHelper from ..layer_helper import LayerHelper
from ..framework import Variable, in_dygraph_mode, static_only from ..framework import Variable, in_dygraph_mode, static_only, in_dygraph_mode
from .. import core from .. import core
from ..data_feeder import check_variable_and_dtype, check_type from ..data_feeder import check_variable_and_dtype, check_type
from ..param_attr import ParamAttr from ..param_attr import ParamAttr
......
...@@ -20,7 +20,7 @@ from __future__ import print_function ...@@ -20,7 +20,7 @@ from __future__ import print_function
import warnings import warnings
from ..layer_helper import LayerHelper from ..layer_helper import LayerHelper
from ..initializer import Normal, Constant from ..initializer import Normal, Constant
from ..framework import Variable, in_dygraph_mode, _varbase_creator from ..framework import Variable, in_dygraph_mode, _varbase_creator, _in_eager_mode
from .. import core from .. import core
from ..param_attr import ParamAttr from ..param_attr import ParamAttr
from . import nn from . import nn
...@@ -87,7 +87,7 @@ def accuracy(input, label, k=1, correct=None, total=None): ...@@ -87,7 +87,7 @@ def accuracy(input, label, k=1, correct=None, total=None):
_k = k.numpy().item(0) if isinstance(k, Variable) else k _k = k.numpy().item(0) if isinstance(k, Variable) else k
topk_out, topk_indices = _C_ops.top_k_v2(input, 'k', _k, 'sorted', topk_out, topk_indices = _C_ops.top_k_v2(input, 'k', _k, 'sorted',
False) False)
if _in_eager_mode: if _in_eager_mode():
_acc = _C_ops.final_state_accuracy(topk_out, topk_indices, label) _acc = _C_ops.final_state_accuracy(topk_out, topk_indices, label)
return _acc return _acc
_acc, _, _ = _C_ops.accuracy(topk_out, topk_indices, label, correct, _acc, _, _ = _C_ops.accuracy(topk_out, topk_indices, label, correct,
......
...@@ -12552,7 +12552,7 @@ def logical_not(x, out=None, name=None): ...@@ -12552,7 +12552,7 @@ def logical_not(x, out=None, name=None):
res = paddle.logical_not(x) res = paddle.logical_not(x)
print(res) # [False True False True] print(res) # [False True False True]
""" """
if paddle.in_dygraph_mode() and _in_eager_mode(): if in_dygraph_mode() and _in_eager_mode():
return _C_ops.final_state_logical_not(x) return _C_ops.final_state_logical_not(x)
return _logical_op( return _logical_op(
op_name="logical_not", x=x, y=None, name=name, out=out, binary_op=False) op_name="logical_not", x=x, y=None, name=name, out=out, binary_op=False)
...@@ -14844,8 +14844,8 @@ def unfold(x, kernel_sizes, strides=1, paddings=0, dilations=1, name=None): ...@@ -14844,8 +14844,8 @@ def unfold(x, kernel_sizes, strides=1, paddings=0, dilations=1, name=None):
if in_dygraph_mode(): if in_dygraph_mode():
if _in_eager_mode(): if _in_eager_mode():
return _C_ops.final_state_unfold(x, kernel_sizes, strdides, return _C_ops.final_state_unfold(x, kernel_sizes, strides, paddings,
paddings, dilations) dilations)
out = helper.create_variable_for_type_inference(dtype=x.dtype) out = helper.create_variable_for_type_inference(dtype=x.dtype)
helper.append_op( helper.append_op(
......
...@@ -50,7 +50,7 @@ class TestAccuracyOp(OpTest): ...@@ -50,7 +50,7 @@ class TestAccuracyOp(OpTest):
pass pass
def test_check_output(self): def test_check_output(self):
self.check_output(check_eager=True) self.check_output(check_eager=False)
class TestAccuracyOpFp16(TestAccuracyOp): class TestAccuracyOpFp16(TestAccuracyOp):
...@@ -58,7 +58,7 @@ class TestAccuracyOpFp16(TestAccuracyOp): ...@@ -58,7 +58,7 @@ class TestAccuracyOpFp16(TestAccuracyOp):
self.dtype = np.float16 self.dtype = np.float16
def test_check_output(self): def test_check_output(self):
self.check_output(atol=1e-3, check_eager=True) self.check_output(atol=1e-3, check_eager=False)
class TestAccuracyOpError(unittest.TestCase): class TestAccuracyOpError(unittest.TestCase):
...@@ -128,16 +128,16 @@ class TestAccuracyAPI(unittest.TestCase): ...@@ -128,16 +128,16 @@ class TestAccuracyAPI(unittest.TestCase):
self.assertEqual((result.numpy() == expect_value).all(), True) self.assertEqual((result.numpy() == expect_value).all(), True)
with _test_eager_guard(): # with _test_eager_guard():
predictions = paddle.to_tensor( # predictions = paddle.to_tensor(
[[0.2, 0.1, 0.4, 0.1, 0.1], [0.2, 0.3, 0.1, 0.15, 0.25]], # [[0.2, 0.1, 0.4, 0.1, 0.1], [0.2, 0.3, 0.1, 0.15, 0.25]],
dtype='float32') # dtype='float32')
label = paddle.to_tensor([[2], [0]], dtype="int64") # label = paddle.to_tensor([[2], [0]], dtype="int64")
result = paddle.metric.accuracy( # result = paddle.metric.accuracy(
input=predictions, label=label, k=1) # input=predictions, label=label, k=1)
expect_value = np.array([0.5], dtype='float32') # expect_value = np.array([0.5], dtype='float32')
self.assertEqual((result.numpy() == expect_value).all(), True) # self.assertEqual((result.numpy() == expect_value).all(), True)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -85,10 +85,10 @@ class TestSoftmaxOp(OpTest): ...@@ -85,10 +85,10 @@ class TestSoftmaxOp(OpTest):
place, place,
atol=1e-5, atol=1e-5,
check_dygraph=(self.use_mkldnn == False), check_dygraph=(self.use_mkldnn == False),
check_eager=True) check_eager=False)
else: else:
self.check_output( self.check_output(
check_dygraph=(self.use_mkldnn == False), check_eager=True) check_dygraph=(self.use_mkldnn == False), check_eager=False)
def test_check_grad(self): def test_check_grad(self):
# TODO(wangzhongpu): support mkldnn op in dygraph mode # TODO(wangzhongpu): support mkldnn op in dygraph mode
......
...@@ -465,6 +465,15 @@ ...@@ -465,6 +465,15 @@
func : atanh func : atanh
backward : atanh_grad backward : atanh_grad
# sigmoid
- api : sigmoid
args : (Tensor x)
output : Tensor
infer_meta :
func : UnchangedInferMeta
kernel :
func : sigmoid
backward : sigmoid_grad
# arg_min # int64 ???? dtype # arg_min # int64 ???? dtype
- api : argmin - api : argmin
......
...@@ -283,6 +283,16 @@ ...@@ -283,6 +283,16 @@
kernel : kernel :
func : relu_grad func : relu_grad
- backward_api : sigmoid_grad
forward : sigmoid (Tensor x) -> Tensor(out)
args : (Tensor out, Tensor out_grad)
output : Tensor(x_grad)
infer_meta :
func : UnchangedInferMeta
param : [out]
kernel :
func : sigmoid_grad
- backward_api : argsort_grad - backward_api : argsort_grad
forward : argsort (Tensor x, int axis, bool descending) -> Tensor(out), Tensor(indices) forward : argsort (Tensor x, int axis, bool descending) -> Tensor(out), Tensor(indices)
args : (Tensor indices, Tensor x, Tensor out_grad, int axis, bool descending) args : (Tensor indices, Tensor x, Tensor out_grad, int axis, bool descending)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册