[docs]defmain():""" Main function for command line ``python -m experimental_experiment.torch_bench.check_model``. """fromexperimental_experiment.argsimportget_parsed_argsscript_args=get_parsed_args("experimental_experiment.torch_bench.check_model",test=("optimizer","the scenario to test, optimizer runs onnxscript optimizations"),model=("","needs to be specified"),suffix=(".check","suffix added to the model"),verbose=(0,"verbosity"),description=__doc__,expose="test,suffix,model",)importosimportonnxassertos.path.exists(script_args.model),f"Model {script_args.model!r} does not exist."name,ext=os.path.splitext(script_args.model)output=f"{name}{script_args.suffix}{ext}"verbose=script_args.verboseifverbose:print(f"check model {script_args.model!r}")print(f"with command {script_args.test!r}")ifscript_args.test=="optimizer":fromonnxscriptimportoptimizerifverbose:print(f"loading model {script_args.model!r}")onx=onnx.load(script_args.model)ifverbose:print("optimize model")optimized=optimizer.optimize(onx)ifverbose:print("done")print(f"save into {output}")withopen(output,"wb")asf:f.write(optimized.SerializeToString())ifverbose:print("done")else:raiseAssertionError(f"Unsupported test {script_args.test!r}")