Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
 
import argparse
from dataclasses import dataclass
 
import numpy as np
from benchmark import BenchmarkOp, add_arguments
 
 
@dataclass
class OpParam:
    batch_size: int
    seq_len: int
    hidden_size: int
    length: int
    data_type: type
 
 
class BenchmarkAttention(BenchmarkOp):
    def __init__(self, args):
        BenchmarkOp.__init__(self, args)
 
    @classmethod
    def create_inputs_outputs(cls, op_param):
        np.random.seed(0)
        input_data = np.random.rand(op_param.batch_size, op_param.seq_len, op_param.hidden_size).astype(
            op_param.data_type
        )
        weight = np.random.rand(op_param.hidden_size, op_param.length).astype(op_param.data_type)
        bias = np.random.rand(op_param.length).astype(op_param.data_type)
        mask_index = np.random.rand(op_param.batch_size, op_param.seq_len).astype(np.int32)
        output_data = np.random.rand(op_param.batch_size, op_param.seq_len, op_param.hidden_size).astype(
            op_param.data_type
        )
        inputs = {
            "INPUT": input_data,
            "WEIGHT": weight,
            "BIAS": bias,
            "MASK_INDEX": mask_index,
        }
        outputs = {"return_val": output_data}
        return inputs, outputs
 
    def create_cases(self):
        model = "models/attention_fp16.onnx" if self.args.precision == "fp16" else "models/attention_fp32.onnx"
        data_type = np.float16 if self.args.precision == "fp16" else np.float32
        # bert-base
        op_param = OpParam(1, 384, 768, 768 * 3, data_type)
        self.add_case(op_param, model)
 
    @classmethod
    def case_profile(cls, op_param, time):
        profile = f"(batch_size seq_len length) = ({op_param.batch_size} {op_param.seq_len} {op_param.length}), {time:7.4f} ms"
        return profile
 
 
def main():
    parser = argparse.ArgumentParser()
    add_arguments(parser)
    args = parser.parse_args()
    bm = BenchmarkAttention(args)
    bm.benchmark()
 
 
if __name__ == "__main__":
    main()