|
| 1 | +from common_import import * |
| 2 | + |
| 3 | + |
| 4 | +@benchmark_registry.register("categorical") |
| 5 | +class CategoricalConfig(APIConfig): |
| 6 | + def __init__(self): |
| 7 | + super(CategoricalConfig, self).__init__("categorical") |
| 8 | + self.feed_spec = {"range": [-5, -0.1]} |
| 9 | + |
| 10 | + |
| 11 | +@benchmark_registry.register("categorical") |
| 12 | +class PaddleCategorical(PaddleOpBenchmarkBase): |
| 13 | + def build_graph(self, config): |
| 14 | + logits = self.variable( |
| 15 | + name="logits", |
| 16 | + shape=config.logits_shape, |
| 17 | + dtype=config.logits_dtype) |
| 18 | + result = paddle.distribution.Categorical(logits) |
| 19 | + counts = result.sample([100]) |
| 20 | + self.feed_list = [logits] |
| 21 | + self.fetch_list = [counts] |
| 22 | + |
| 23 | + |
| 24 | +@benchmark_registry.register("categorical") |
| 25 | +class TorchCategorical(PytorchOpBenchmarkBase): |
| 26 | + def build_graph(self, config): |
| 27 | + logits = self.variable( |
| 28 | + name="logits", |
| 29 | + shape=config.logits_shape, |
| 30 | + dtype=config.logits_dtype) |
| 31 | + result = torch.distributions.categorical.Categorical( |
| 32 | + logits=torch.tensor(logits)) |
| 33 | + counts = result.sample([100]) |
| 34 | + self.feed_list = [logits] |
| 35 | + self.fetch_list = [counts] |
| 36 | + |
| 37 | + |
| 38 | +@benchmark_registry.register("categorical") |
| 39 | +class TFCategoricall(TensorflowOpBenchmarkBase): |
| 40 | + def build_graph(self, config): |
| 41 | + logits = self.variable( |
| 42 | + name='logits', |
| 43 | + shape=config.logits_shape, |
| 44 | + dtype=config.logits_dtype) |
| 45 | + counts = tf.random.categorical(logits, 100) |
| 46 | + self.feed_list = [logits] |
| 47 | + self.fetch_list = [counts] |
0 commit comments