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

Function main

imperative/python/megengine/tools/compare_binary_iodump.py:80–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

78
79
80def main():
81 parser = argparse.ArgumentParser(
82 description=(
83 "compare tensor dumps generated BinaryOprIODump plugin, "
84 "it can compare two dirs or two single files"
85 ),
86 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
87 )
88 parser.add_argument("input0", help="dirname or filename")
89 parser.add_argument("input1", help="dirname or filename")
90 parser.add_argument(
91 "-e", "--max-err", type=float, default=1e-3, help="max allowed error"
92 )
93 parser.add_argument(
94 "-s", "--stop-on-error", action="store_true", help="do not compare "
95 )
96 args = parser.parse_args()
97
98 files0 = set()
99 files1 = set()
100 if os.path.isdir(args.input0):
101 assert os.path.isdir(args.input1)
102 name0 = set()
103 name1 = set()
104 for i in os.listdir(args.input0):
105 files0.add(str(Path(args.input0) / i))
106 name0.add(i)
107
108 for i in os.listdir(args.input1):
109 files1.add(str(Path(args.input1) / i))
110 name1.add(i)
111
112 assert name0 == name1, "dir files mismatch: a-b={} b-a={}".format(
113 name0 - name1, name1 - name0
114 )
115 else:
116 files0.add(args.input0)
117 files1.add(args.input1)
118 files0 = sorted(files0)
119 files1 = sorted(files1)
120
121 for i, j in zip(files0, files1):
122 val0, name0 = load_tensor_binary(i)
123 val1, name1 = load_tensor_binary(j)
124 name = "{}: \n{}\n{}\n".format(
125 i, "\n ".join(textwrap.wrap(name0)), "\n ".join(textwrap.wrap(name1))
126 )
127 try:
128 check(val0, val1, name, args.max_err)
129 except Exception as exc:
130 if args.stop_on_error:
131 raise exc
132 print(exc)
133
134
135if __name__ == "__main__":

Callers 1

Calls 8

strFunction · 0.85
load_tensor_binaryFunction · 0.85
printFunction · 0.85
joinMethod · 0.80
checkFunction · 0.70
addMethod · 0.45
formatMethod · 0.45
wrapMethod · 0.45

Tested by

no test coverage detected