Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit add_n categorical test script and json #1577

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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]
91 changes: 91 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,95 @@
"type": "list<Variable>"
}
}
}, {
"op": "add_n",
"param_info": {
"inputs": {
"inputs0": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"inputs1": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"type": "list<Variable>"
}
}
}, {
"op": "add_n",
"param_info": {
"inputs": {
"inputs0": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"inputs1": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"inputs2": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"inputs3": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"inputs4": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"inputs5": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"inputs6": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"inputs7": {
"dtype": "float16",
"shape": "[1L]",
"type": "Variable"
},
"type": "list<Variable>"
}
}
liuruyan marked this conversation as resolved.
Show resolved Hide resolved
}, {
"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"
}
}
}]