Think·sync · inline

ONNX Inference

Classical ML, sync

Run ONNX models from Hugging Face deterministically. Returns inline.

0x0000000000000000000000000000000000000800Explorer
Sync inline. Returns inline tensor — no executor, no callback. Model ID MUST pin to 40-char commit hash (branches rejected).
Default Model ID is a placeholder. The chain’s ModelRegistry will reject @0x000…000. Replace with a real registered model id (hf/owner/repo/file.onnx@<40-hex-deployer>) before running. If no model is registered yet on Ritual testnet, you’ll need to register one first via the ONNX deployer workflow.
hf/owner/repo/file.onnx@<40-char-commit>
e.g. "[1,3,224,224]"
JSON array of numbers
to: 0x0000000000000000000000000000000000000800chainId 1979 · sync
Output
Click Run inference to call the ONNX precompile.
shape [1,4] · FLOAT32 (most common)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract ONNXInference {
    address constant ONNX = address(0x800);

    function infer(bytes memory tensorData) external view returns (bytes memory) {
        bytes memory input = abi.encode(
            bytes("hf/onnx/sample/identity.onnx@0000000000000000000000000000000000000000"),
            tensorData,
            uint8(2),
            uint8(0),
            uint8(2),
            uint8(0),
            uint8(1)
        );
        (bool ok, bytes memory result) = ONNX.staticcall(input);
        require(ok && result.length > 0, "onnx call failed");
        // Decode outer envelope: (bytes tensorEncoded, uint8 outArith, uint8 outScale, uint8 rounding)
        (bytes memory tensorEncoded, , , ) =
            abi.decode(result, (bytes, uint8, uint8, uint8));
        return tensorEncoded;
        // Inner tensor decode: (uint8 dtype, uint16[] shape, int32[] values)
    }
}