Convert Official Weights#

Open In Colab

Setup#

[1]:
MODE = "local"  # "colab" | "colab-dev" | "local"
[ ]:
if MODE == "colab":
    !pip install -q lczerolens
elif MODE == "colab-dev":
    !rm -r lczerolens
    !git clone https://github.com/Xmaster6y/lczerolens -b main
    !pip install -q ./lczerolens
[ ]:
!gdown 1erxB3tULDURjpPhiPWVGr6X986Q8uE6U -O leela-network.pb.gz

To convert a network you’ll need to have installed the lc0 binaries (takes about 10 minutes):

[4]:
!pip install -q git+https://github.com/LeelaChessZero/lc0
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
  Building wheel for lczero_bindings (pyproject.toml) ... done

Convert a Model#

You can convert networks to onnx using the official lc0 binaries or by using the backends module:

[6]:
from lczerolens import backends

output = backends.convert_to_onnx("leela-network.pb.gz", "leela-network.onnx")
print(output)

Format
~~~~~~
            Weights encoding: LINEAR16
                       Input: INPUT_CLASSICAL_112_PLANE
                     Network: NETWORK_SE_WITH_HEADFORMAT
                      Policy: POLICY_CONVOLUTION
                       Value: VALUE_WDL

Weights
~~~~~~~
                      Blocks: 6
                   SE blocks: 6
                     Filters: 64
                      Policy: Convolution
           Policy activation: ACTIVATION_DEFAULT
                       Value: WDL
                         MLH: Absent
Converting Leela network to the ONNX.

ONNX interface
~~~~~~~~~~~~~~
                   Data type: FLOAT
                Input planes: /input/planes
                  Output WDL: /output/wdl
               Output Policy: /output/policy
Done.

See Move Prediction to see how to use the converted network.

Note#

Only the latest networks are supported. To convert older weights, you should build the associated binaries.