MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / main

Function main

tools/evaluation_model_parallelism.py:67–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65
66
67def main():
68 parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
69 parser.add_argument("--model_file", help="model file", required=True)
70 parser.add_argument(
71 "--load_and_run_file", help="path for load_and_run", required=True
72 )
73 args = parser.parse_args()
74
75 # init device
76 ssh = SshConnector()
77 ssh.setup(device["login_name"], device["ip"], device["port"])
78 # create test dir
79 workspace = "model_parallelism_test"
80 ssh.cmd(["mkdir -p {}".format(workspace)])
81 # copy load_and_run_file
82 ssh.copy([args.load_and_run_file], workspace)
83 # call test
84 model_file = args.model_file
85 # copy model file
86 ssh.copy([args.model_file], workspace)
87 m = model_file.split("\\")[-1]
88 # run single thread
89 result = []
90 thread_number = [1, 2, 4]
91 for b in thread_number:
92 cmd = []
93 cmd1 = "cd {} && ./load_and_run {} -multithread {} --fast-run --fast_run_algo_policy fastrun.cache --iter 1 --warmup-iter 1 --no-sanity-check --weight-preprocess".format(
94 workspace, m, b
95 )
96 cmd2 = "cd {} && ./load_and_run {} -multithread {} --fast_run_algo_policy fastrun.cache --iter 20 --warmup-iter 5 --no-sanity-check --weight-preprocess ".format(
97 workspace, m, b
98 )
99 cmd.append(cmd1)
100 cmd.append(cmd2)
101 raw_log = ssh.cmd(cmd)
102 # logging.debug(raw_log)
103 ret = get_finally_bench_resulut_from_log(raw_log)
104 logging.debug("model: {} with backend: {} result is: {}".format(m, b, ret))
105 result.append(ret)
106
107 thread_2 = result[0] / result[1]
108 thread_4 = result[0] / result[2]
109 if thread_2 > 1.6 or thread_4 > 3.0:
110 print(
111 "model: {} can has good parallelism. 2 thread is {}, 4 thread is {}".format(
112 m, thread_2, thread_4
113 )
114 )
115 else:
116 print(
117 "model: {} can has bad parallelism. 2 thread is {}, 4 thread is {}".format(
118 m, thread_2, thread_4
119 )
120 )
121
122
123if __name__ == "__main__":

Callers 1

Calls 8

setupMethod · 0.95
cmdMethod · 0.95
copyMethod · 0.95
printFunction · 0.85
SshConnectorClass · 0.70
formatMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected