Unverified Commit acf365a8 authored by guoshzhao's avatar guoshzhao Committed by GitHub
Browse files

Benchmarks: Add Feature - Set reduce type for current benchmarks' metrics. (#149)

**Description**
Set reduce type for current benchmarks' metrics, including model benchmarks and ShardingMatmul.
parent bc1a61b9
...@@ -22,6 +22,7 @@ from superbench.common.utils import logger ...@@ -22,6 +22,7 @@ from superbench.common.utils import logger
from superbench.benchmarks import DistributedImpl, DistributedBackend, BenchmarkRegistry, ReturnCode from superbench.benchmarks import DistributedImpl, DistributedBackend, BenchmarkRegistry, ReturnCode
from superbench.benchmarks.micro_benchmarks import MicroBenchmark from superbench.benchmarks.micro_benchmarks import MicroBenchmark
from superbench.benchmarks.context import Enum from superbench.benchmarks.context import Enum
from superbench.benchmarks.reducer import ReduceType
class ShardingMode(Enum): class ShardingMode(Enum):
...@@ -256,7 +257,7 @@ class ShardingMatmul(MicroBenchmark): ...@@ -256,7 +257,7 @@ class ShardingMatmul(MicroBenchmark):
return False return False
metric = '{}'.format(mode) metric = '{}'.format(mode)
if not self._process_numeric_result(metric, elapse_times): if not self._process_numeric_result(metric, elapse_times, reduce_type=ReduceType.MAX):
return False return False
logger.info( logger.info(
......
...@@ -12,6 +12,7 @@ from superbench.common.utils import logger ...@@ -12,6 +12,7 @@ from superbench.common.utils import logger
from superbench.benchmarks import Precision, ModelAction, DistributedImpl, DistributedBackend, BenchmarkType, ReturnCode from superbench.benchmarks import Precision, ModelAction, DistributedImpl, DistributedBackend, BenchmarkType, ReturnCode
from superbench.benchmarks.base import Benchmark from superbench.benchmarks.base import Benchmark
from superbench.benchmarks.context import Enum from superbench.benchmarks.context import Enum
from superbench.benchmarks.reducer import ReduceType
class Optimizer(Enum): class Optimizer(Enum):
...@@ -358,7 +359,7 @@ class ModelBenchmark(Benchmark): ...@@ -358,7 +359,7 @@ class ModelBenchmark(Benchmark):
metric = 'steptime_{}_{}'.format(model_action, precision) metric = 'steptime_{}_{}'.format(model_action, precision)
self._result.add_raw_data(metric, step_times) self._result.add_raw_data(metric, step_times)
avg = statistics.mean(step_times) avg = statistics.mean(step_times)
self._result.add_result(metric, avg) self._result.add_result(metric, avg, reduce_type=ReduceType.MAX if model_action is ModelAction.TRAIN else None)
# The unit of step time is millisecond, use it to calculate the throughput with the unit samples/sec. # The unit of step time is millisecond, use it to calculate the throughput with the unit samples/sec.
millisecond_per_second = 1000 millisecond_per_second = 1000
...@@ -366,7 +367,7 @@ class ModelBenchmark(Benchmark): ...@@ -366,7 +367,7 @@ class ModelBenchmark(Benchmark):
metric = 'throughput_{}_{}'.format(model_action, precision) metric = 'throughput_{}_{}'.format(model_action, precision)
self._result.add_raw_data(metric, throughput) self._result.add_raw_data(metric, throughput)
avg = statistics.mean(throughput) avg = statistics.mean(throughput)
self._result.add_result(metric, avg) self._result.add_result(metric, avg, reduce_type=ReduceType.MIN if model_action is ModelAction.TRAIN else None)
return True return True
......
...@@ -220,7 +220,7 @@ def test_train(): ...@@ -220,7 +220,7 @@ def test_train():
'"steptime_train_float32": [[2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0]], ' '"steptime_train_float32": [[2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0]], '
'"throughput_train_float32": [[16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0]]}, ' '"throughput_train_float32": [[16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0]]}, '
'"result": {"steptime_train_float32": [2.0], "throughput_train_float32": [16000.0]}, ' '"result": {"steptime_train_float32": [2.0], "throughput_train_float32": [16000.0]}, '
'"reduce": {"steptime_train_float32": null, "throughput_train_float32": null}}' '"reduce": {"steptime_train_float32": "max", "throughput_train_float32": "min"}}'
) )
assert (benchmark._preprocess()) assert (benchmark._preprocess())
assert (benchmark._ModelBenchmark__train(Precision.FLOAT32)) assert (benchmark._ModelBenchmark__train(Precision.FLOAT32))
...@@ -296,8 +296,8 @@ def test_benchmark(): ...@@ -296,8 +296,8 @@ def test_benchmark():
'"throughput_train_float16": [[16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0]]}, ' '"throughput_train_float16": [[16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0, 16000.0]]}, '
'"result": {"steptime_train_float32": [2.0], "throughput_train_float32": [16000.0], ' '"result": {"steptime_train_float32": [2.0], "throughput_train_float32": [16000.0], '
'"steptime_train_float16": [2.0], "throughput_train_float16": [16000.0]}, ' '"steptime_train_float16": [2.0], "throughput_train_float16": [16000.0]}, '
'"reduce": {"steptime_train_float32": null, "throughput_train_float32": null, ' '"reduce": {"steptime_train_float32": "max", "throughput_train_float32": "min", '
'"steptime_train_float16": null, "throughput_train_float16": null}}' '"steptime_train_float16": "max", "throughput_train_float16": "min"}}'
) )
assert (benchmark.serialized_result == expected_serialized_result) assert (benchmark.serialized_result == expected_serialized_result)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment