ezkl_artifact - Infernet ML
Description: Infernet ML Documentation

Skip to content

# Module: `ezkl_artifact`

## `ArtifactGenerationArgs`

Bases: `BaseModel`

Arguments for generating the proof artifacts.

Attributes:

Name | Type | Description
--- | --- | ---
`onnx_path` | `Path` | Path to the ONNX model
`input_visibility` | `str` | Visibility of the input
`output_visibility` | `str` | Visibility of the output
`param_visibility` | `str` | Visibility of the parameters

Source code in `src/infernet_ml/zk/ezkl/ezkl_artifact.py`

    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    class ArtifactGenerationArgs(BaseModel):
        """
        Arguments for generating the proof artifacts.

        Attributes:
            onnx_path (Path): Path to the ONNX model
            input_visibility (str): Visibility of the input
            output_visibility (str): Visibility of the output
            param_visibility (str): Visibility of the parameters
        """

        onnx_path: Path
        input_visibility: str
        output_visibility: str
        param_visibility: str

## `EZKLArtifact`

Bases: `BaseModel`

A base class to represent the artifacts generated or used by the EZKL library. It also has utility methods to upload the artifacts to the Arweave network, Huggingface Hub, or a local directory.

Attributes:

Name | Type | Description
--- | --- | ---
`compiled_model_path` | `Path` | Path to the compiled model
`settings_path` | `Path` | Path to the settings
`onnx_path` | `Path` | Path to the ONNX model
`calibration_path` | `Path` | Path to the calibration file
`srs_path` | `Path` | Path to the SRS file
`verifier_key_path` | `Path` | Path to the verifier key
`prover_key_path` | `Path` | Path to the prover key

Source code in `src/infernet_ml/zk/ezkl/ezkl_artifact.py`

    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    class EZKLArtifact(BaseModel):
        """
        A base class to represent the artifacts generated or used by the EZKL library.
        It also has utility methods to upload the artifacts to the Arweave network,
        Huggingface Hub, or a local directory.

        Attributes:
            compiled_model_path (Path): Path to the compiled model
            settings_path (Path): Path to the settings
            onnx_path (Path): Path to the ONNX model
            calibration_path (Path): Path to the calibration file
            srs_path (Path): Path to the SRS file
            verifier_key_path (Path): Path to the verifier key
            prover_key_path (Path): Path to the prover key

        """

        compiled_model_path: Path
        settings_path: Path
        onnx_path: Path
        calibration_path: Path
        srs_path: Path
        verifier_key_path: Path
        prover_key_path: Path

## `generate_ezkl_artifacts(args)` `async`

Generate artifacts for a model.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`args` | `ArtifactGenerationArgs` | Arguments for generating artifacts | required

Returns:

Name | Type | Description
--- | --- | ---
`EZKLArtifact` | `EZKLArtifact` | An instance of the EZKLArtifact class

Source code in `src/infernet_ml/zk/ezkl/ezkl_artifact.py`

     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    async def generate_ezkl_artifacts(args: ArtifactGenerationArgs) -> EZKLArtifact:
        """
        Generate artifacts for a model.

        Args:
            args (ArtifactGenerationArgs): Arguments for generating artifacts

        Returns:
            EZKLArtifact: An instance of the EZKLArtifact class
        """
        py_run_args = ezkl.PyRunArgs()
        py_run_args.input_visibility = args.input_visibility
        py_run_args.output_visibility = args.output_visibility
        py_run_args.param_visibility = args.param_visibility
        dummy_input = generate_dummy_input(args.onnx_path)
        data_array = list(dummy_input.values())[0].reshape([-1]).tolist()
        onnx_path = args.onnx_path
        settings_path = onnx_path.parent / "settings.json"
        srs_path = onnx_path.parent / "srs_file.srs"
        calibration_path = onnx_path.parent / "calibration.json"
        data_path = onnx_path.parent / "data.json"
        compiled_model_path = onnx_path.parent / "model.compiled"
        data = dict(input_data=[data_array])

        # Serialize data into file:
        json.dump(data, open(calibration_path, "w"))
        json.dump(data, open(data_path, "w"))
        res = ezkl.gen_settings(onnx_path, settings_path, py_run_args)

        assert res is True
        await ezkl.calibrate_settings(
            calibration_path, onnx_path, settings_path, "resources"
        )

        res = ezkl.compile_circuit(onnx_path, compiled_model_path, settings_path)
        assert res is True

        res = await ezkl.get_srs(
            settings_path, srs_path=settings_path.parent / "srs_file.srs"
        )
        assert res is True

        vk_path = settings_path.parent / "test.vk"
        pk_path = settings_path.parent / "test.pk"
        res = ezkl.setup(
            compiled_model_path, vk_path=vk_path, pk_path=pk_path, srs_path=srs_path
        )
        assert res is True
        assert os.path.isfile(vk_path)
        assert os.path.isfile(pk_path)

        return EZKLArtifact(
            compiled_model_path=compiled_model_path,
            settings_path=settings_path,
            onnx_path=onnx_path,
            calibration_path=calibration_path,
            srs_path=srs_path,
            verifier_key_path=vk_path,
            prover_key_path=pk_path,
        )