未验证 提交 ea91ca2f 编写于 作者: Z Zhong Hui 提交者: GitHub

[Eager] Add hierarchical_sigmoid yaml (#44638)

上级 ae25ab56
......@@ -135,7 +135,7 @@ class BaseAPI(object):
'double': 'double',
'bool': 'bool',
'str': 'const std::string&',
'str[] ': 'const std::vector<std::string>&',
'str[]': 'const std::vector<std::string>&',
'Place': 'const Place&',
'DataLayout': 'DataLayout',
'DataType': 'DataType',
......
......@@ -1038,6 +1038,18 @@
func : hard_swish
backward : hard_swish_grad
# hierarchical_sigmoid
- api : hierarchical_sigmoid
args : (Tensor x, Tensor w, Tensor label, Tensor path, Tensor code, Tensor bias, int num_classes, bool remote_prefetch, int trainer_id, int64_t[] height_sections, str[] epmap, str[] table_names, bool is_sparse)
output : Tensor(out), Tensor(pre_out), Tensor(w_out)
infer_meta :
func : HierarchicalSigmoidInferMeta
optional: path, code, bias
kernel :
func : hierarchical_sigmoid
data_type : x
backward : hierarchical_sigmoid_grad
# histogram
- api : histogram
args : (Tensor x, int64_t bins, int min, int max)
......
......@@ -935,6 +935,17 @@
func : hard_swish_grad
inplace : (out_grad -> x_grad)
- backward_api : hierarchical_sigmoid_grad
forward : hierarchical_sigmoid (Tensor x, Tensor w, Tensor label, Tensor path, Tensor code, Tensor bias, int num_classes, bool remote_prefetch, int trainer_id, int64_t[] height_sections, str[] epmap, str[] table_names, bool is_sparse) -> Tensor(out), Tensor(pre_out), Tensor(w_out)
args : (Tensor x, Tensor w, Tensor label, Tensor path, Tensor code, Tensor bias, Tensor pre_out, Tensor out_grad, int num_classes, bool remote_prefetch, int trainer_id, int64_t[] height_sections, str[] epmap, str[] table_names, bool is_sparse)
output : Tensor(x_grad), Tensor(w_grad), Tensor(bias_grad)
infer_meta :
func : GeneralTernaryGradInferMeta
param : [x ,w, bias]
optional: path, code, bias
kernel :
func : hierarchical_sigmoid_grad
- backward_api : huber_loss_grad
forward : huber_loss (Tensor input, Tensor label, float delta) -> Tensor(out), Tensor(residual)
args : (Tensor residual, Tensor out_grad, float delta)
......@@ -2396,7 +2407,7 @@
backward : unsqueeze_double_grad
- backward_api : warpctc_grad
forward : warpctc (Tensor logits, Tensor label, Tensor logits_length, Tensor labels_length, int blank, bool norm_by_times) -> Tensor(loss), Tensor(warpctcgrad)
forward : warpctc (Tensor logits, Tensor label, Tensor logits_length, Tensor labels_length, int blank, bool norm_by_times) -> Tensor(loss), Tensor(warpctcgrad)
args : (Tensor logits, Tensor logits_length, Tensor warpctcgrad, Tensor loss_grad, int blank, bool norm_by_times)
output : Tensor(logits_grad)
infer_meta :
......
......@@ -172,10 +172,30 @@ def hsigmoidWithCustomTree(x, w, path_table, path_code, label, bias,
return pre_output, out
def python_api(input,
weight,
label,
path_table=None,
path_code=None,
bias=None,
num_classes=-1,
is_sparse=False,
remote_prefetch=False):
assert is_sparse == remote_prefetch, "is_sparse is equal to remote_prefetch in dygraph."
return paddle.nn.functional.hsigmoid_loss(input, label, num_classes, weight,
bias, path_table, path_code,
is_sparse)
python_out_sig = ["Out"]
class TestHSigmoidOp(OpTest):
def setUp(self):
self.op_type = "hierarchical_sigmoid"
self.python_api = python_api
self.python_out_sig = python_out_sig
num_classes = 101
feature_size = 5
batch_size = 20
......@@ -193,11 +213,12 @@ class TestHSigmoidOp(OpTest):
self.user_grads = hsigmoid_grad(x, w, label, bias, num_classes)
def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)
def test_check_grad(self):
self.check_grad(['X', 'W', 'Bias'], ['Out'],
user_defined_grads=self.user_grads)
user_defined_grads=self.user_grads,
check_eager=True)
@skip_check_grad_ci(
......@@ -208,6 +229,8 @@ class TestHSigmoidOpSparse(OpTest):
def setUp(self):
self.op_type = "hierarchical_sigmoid"
self.python_api = python_api
self.python_out_sig = python_out_sig
num_classes = 6 #using 1,2,3,4,5,6 to build a huffman tree and select 1,2,5,6 as sample
feature_size = 8
batch_size = 4
......@@ -237,7 +260,7 @@ class TestHSigmoidOpSparse(OpTest):
self.outputs = {'PreOut': pre_output, 'Out': out}
def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)
class TestHSigmoidOpWithSparseGrad(unittest.TestCase):
......@@ -318,6 +341,8 @@ class TestHSigmoidOpWithCostumTree(OpTest):
def setUp(self):
self.op_type = "hierarchical_sigmoid"
self.python_api = python_api
self.python_out_sig = python_out_sig
num_classes = 6 #using 1,2,3,4,5,6 to build a huffman tree and select 1,2,5,6 as sample
feature_size = 8
batch_size = 4
......@@ -347,10 +372,12 @@ class TestHSigmoidOpWithCostumTree(OpTest):
self.outputs = {'PreOut': pre_output, 'Out': out}
def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)
def test_check_grad(self):
self.check_grad(['Bias', 'X', 'W'], ['Out'], no_grad_set=set('Label'))
self.check_grad(['Bias', 'X', 'W'], ['Out'],
no_grad_set=set('Label'),
check_eager=True)
@skip_check_grad_ci(
......@@ -361,6 +388,8 @@ class TestHSigmoidOpWithCostumTreeWithoutBias(OpTest):
def setUp(self):
self.op_type = "hierarchical_sigmoid"
self.python_api = python_api
self.python_out_sig = python_out_sig
num_classes = 6 #using 1,2,3,4,5,6 to build a huffman tree and select 1,2,5,6 as sample
feature_size = 8
batch_size = 4
......@@ -394,10 +423,12 @@ class TestHSigmoidOpWithCostumTreeWithoutBias(OpTest):
self.outputs = {'PreOut': pre_output, 'Out': out}
def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)
def test_check_grad(self):
self.check_grad(['X', 'W'], ['Out'], no_grad_set=set('Label'))
self.check_grad(['X', 'W'], ['Out'],
no_grad_set=set('Label'),
check_eager=True)
class TestHSigmoidLossAPI(unittest.TestCase):
......
......@@ -920,7 +920,11 @@ def hsigmoid_loss(input,
# [2.11009121]
# [1.92374969]]
"""
if in_dygraph_mode():
out, _, _ = _C_ops.final_state_hierarchical_sigmoid(
input, weight, label, path_table, path_code, bias, num_classes,
is_sparse, 0, [], [], [], is_sparse)
return out
if _non_static_mode():
out, _, _ = _C_ops.hierarchical_sigmoid(input, weight, label,
path_table, path_code, bias,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册