File: mul_gradient_benchmark.py

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (50 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download
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





import argparse
import numpy as np

from caffe2.python import core, workspace


def benchmark_mul_gradient(args):
    workspace.FeedBlob("dC", np.random.rand(args.m, args.n).astype(np.float32))
    workspace.FeedBlob("A", np.random.rand(args.m, args.n).astype(np.float32))
    workspace.FeedBlob("B", np.random.rand(args.n).astype(np.float32))

    net = core.Net("mynet")
    net.MulGradient(
        ["dC", "A", "B"],
        ["dC" if args.inplace else "dA", "dB"],
        broadcast=True,
        axis=1,
        allow_broadcast_fastpath=args.allow_broadcast_fastpath,
    )
    workspace.CreateNet(net)

    workspace.BenchmarkNet(net.Name(), 1, args.iteration, True)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="benchmark for MulGradient.")
    parser.add_argument(
        '-m', type=int, default=9508,
        help="The number of rows of A")
    parser.add_argument(
        "-n", type=int, default=80,
        help="The number of columns of A")
    parser.add_argument(
        '-i', "--iteration", type=int, default=100,
        help="The number of iterations.")
    parser.add_argument(
        "--inplace",
        action='store_true', help="Whether to perform the op in-place.")
    parser.add_argument(
        "--allow-broadcast-fastpath",
        action='store_true', help="Whether the broadcast fastpath is enabled.")
    args, extra_args = parser.parse_known_args()
    core.GlobalInit(['python'] + extra_args)
    benchmark_mul_gradient(args)