Convert Official Weights#

Open In Colab

Setup#

[ ]:
import importlib.util

DEV = True

if importlib.util.find_spec("google.colab") is not None:
    MODE = "colab-dev" if DEV else "colab"
else:
    MODE = "local"
[2]:
if MODE == "colab":
    %pip install -q lczerolens[backends,hf]
elif MODE == "colab-dev":
    !rm -r lczerolens
    !git clone https://github.com/Xmaster6y/lczerolens -b main
    %pip install -q ./lczerolens --extra backends --extra hf

Make sure to install the with the backends and hf extras. backends is required to convert the network to onnx and hf is required to load files from the Hugging Face Hub.

Convert a Model#

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

[3]:
from huggingface_hub import hf_hub_download
from lczerolens import backends

path = hf_hub_download("lczerolens/maia-1100", "model.pb.gz")

output = backends.convert_to_onnx(path, "maia-1100.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.