optimize#

Optimizes a model and writes a new binary ONNX file beside the input, reusing existing external weight files. The output path is required and must not exist.

onnx-light optimize model.onnx --output model.opt.onnx
python -m onnx_light optimize model.onnx -o model.opt.onnx --patterns L1,L2
onnx-light optimize model.onnx -o model.opt.onnx --patterns NotNot,CastCast
onnx-light optimize model.onnx -o model.opt.onnx --report optimization.txt

Command-line reference#

    usage: onnx-light optimize [-h] --output OUTPUT [--patterns NAMES]
                               [--report PATH]
                               [--function-pattern TEMPLATE REPLACEMENT]
                               [--function-pattern-as-function]
                               [--verbose [VERBOSE]]
                               model
    
    Applies graph optimizations and writes a new binary ONNX model in the same directory as the input, without rewriting existing weight files.
    
    positional arguments:
      model                 Path to the input ONNX model.
    
    options:
      -h, --help            show this help message and exit
      --output OUTPUT, -o OUTPUT
                            New output model path, in the same directory as the
                            input. Must not already exist.
      --patterns NAMES      Comma-separated pattern names or registered groups
                            (e.g. L1,L2 or NotNot,CastCast). Omit to use the
                            optimizer's default patterns. Names are case-
                            sensitive, not regexes.
      --report PATH         Export the optimization report as UTF-8 text to a new
                            file.
      --function-pattern TEMPLATE REPLACEMENT
                            Two quoted ONNX function texts parsed as a custom
                            FunctionPattern. Repeat to add patterns alongside the
                            selected or default patterns.
      --function-pattern-as-function
                            Emit local function calls for all --function-pattern
                            replacements instead of inlining.
      --verbose [VERBOSE], -v [VERBOSE]
                            Print progress.
    
    examples:
      onnx-light optimize model.onnx -o model.opt.onnx
      onnx-light optimize model.onnx -o model.opt.onnx --patterns L1,L2
      onnx-light optimize model.onnx -o model.opt.onnx --patterns NotNot,CastCast