Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions api/tests/add_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,16 @@ def build_graph(self, config):
@benchmark_registry.register("add_n")
class TorchAddN(PytorchOpBenchmarkBase):
def build_graph(self, config):
input_list = []
input_0 = self.variable(
name='input_' + str(0),
shape=config.inputs_shape[0],
dtype=config.inputs_dtype[0])
result = input_0
input_list.append(input_0)
for i in range(1, len(config.inputs_shape)):
inputs = []
for i in range(len(config.inputs_shape)):
input_i = self.variable(
name='input_' + str(i),
shape=config.inputs_shape[i],
dtype=config.inputs_dtype[i])
result = torch.add(result, input_i)
input_list.append(input_i)

self.feed_list = input_list
inputs.append(input_i)
inputs = torch.stack(inputs, dim=0)
result = torch.sum(inputs, axis=0)
self.feed_list = inputs
self.fetch_list = [result]


Expand Down
47 changes: 47 additions & 0 deletions api/tests/categorical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from common_import import *


@benchmark_registry.register("categorical")
class CategoricalConfig(APIConfig):
def __init__(self):
super(CategoricalConfig, self).__init__("categorical")
self.feed_spec = {"range": [-5, -0.1]}


@benchmark_registry.register("categorical")
class PaddleCategorical(PaddleOpBenchmarkBase):
def build_graph(self, config):
logits = self.variable(
name="logits",
shape=config.logits_shape,
dtype=config.logits_dtype)
result = paddle.distribution.Categorical(logits)
counts = result.sample([100])
self.feed_list = [logits]
self.fetch_list = [counts]


@benchmark_registry.register("categorical")
class TorchCategorical(PytorchOpBenchmarkBase):
def build_graph(self, config):
logits = self.variable(
name="logits",
shape=config.logits_shape,
dtype=config.logits_dtype)
result = torch.distributions.categorical.Categorical(
logits=torch.tensor(logits))
counts = result.sample([100])
self.feed_list = [logits]
self.fetch_list = [counts]


@benchmark_registry.register("categorical")
class TFCategoricall(TensorflowOpBenchmarkBase):
def build_graph(self, config):
logits = self.variable(
name='logits',
shape=config.logits_shape,
dtype=config.logits_dtype)
counts = tf.random.categorical(logits, 100)
self.feed_list = [logits]
self.fetch_list = [counts]
56 changes: 56 additions & 0 deletions api/tests_v2/configs/add_n.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,60 @@
"type": "list<Variable>"
}
}
}, {
"op": "add_n",
"param_info": {
"inputs": {
"inputs0": {
"dtype": "float16",
"shape": "[-1L, 256L]",
"type": "Variable"
},
"inputs1": {
"dtype": "float16",
"shape": "[-1L, 256L]",
"type": "Variable"
},
"type": "list<Variable>"
}
}
}, {
"op": "add_n",
"param_info": {
"inputs": {
"inputs0": {
"dtype": "float16",
"shape": "[-1L, 256L]",
"type": "Variable"
},
"type": "list<Variable>"
}
}
}, {
"op": "add_n",
"param_info": {
"inputs": {
"inputs0": {
"dtype": "float16",
"shape": "[-1L, 256L]",
"type": "Variable"
},
"inputs1": {
"dtype": "float16",
"shape": "[-1L, 256L]",
"type": "Variable"
},
"inputs2": {
"dtype": "float16",
"shape": "[-1L, 256L]",
"type": "Variable"
},
"inputs3": {
"dtype": "float16",
"shape": "[-1L, 256L]",
"type": "Variable"
},
"type": "list<Variable>"
}
}
}]
10 changes: 10 additions & 0 deletions api/tests_v2/configs/categorical.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[{
"op": "categorical",
"param_info": {
"logits": {
"dtype": "float32",
"shape": "[524288L, 23L]",
"type": "Variable"
}
}
}]