|
| 1 | +"""Creates a simple TVM modules.""" |
| 2 | + |
| 3 | +import argparse |
| 4 | +import os |
| 5 | +from os import path as osp |
| 6 | + |
| 7 | +import nnvm.compiler |
| 8 | +import nnvm.testing |
| 9 | +import tvm |
| 10 | + |
| 11 | + |
| 12 | +def main(): |
| 13 | + parser = argparse.ArgumentParser() |
| 14 | + parser.add_argument('-o', '--out-dir', default='.') |
| 15 | + opts = parser.parse_args() |
| 16 | + |
| 17 | + # from tutorials/nnvm_quick_start.py |
| 18 | + dshape = (1, 3, 224, 224) |
| 19 | + net, params = nnvm.testing.resnet.get_workload( |
| 20 | + layers=18, batch_size=dshape[0], image_shape=dshape[1:]) |
| 21 | + |
| 22 | + with nnvm.compiler.build_config(opt_level=3): |
| 23 | + graph, lib, params = nnvm.compiler.build( |
| 24 | + net, 'llvm --system-lib', shape={'data': dshape}, params=params) |
| 25 | + |
| 26 | + build_dir = osp.abspath(opts.out_dir) |
| 27 | + if not osp.isdir(build_dir): |
| 28 | + os.makedirs(build_dir, exist_ok=True) |
| 29 | + |
| 30 | + lib.save(osp.join(build_dir, 'model.bc')) |
| 31 | + with open(osp.join(build_dir, 'graph.json'), 'w') as f_graph_json: |
| 32 | + f_graph_json.write(graph.json()) |
| 33 | + with open(osp.join(build_dir, 'params.bin'), 'wb') as f_params: |
| 34 | + f_params.write(nnvm.compiler.save_param_dict(params)) |
| 35 | + |
| 36 | + |
| 37 | +if __name__ == '__main__': |
| 38 | + main() |
0 commit comments