An open API service indexing awesome lists of open source software.

https://github.com/inference-labs-inc/subnet-2

Verifiable inference on Bittensor
https://github.com/inference-labs-inc/subnet-2

bittensor zk zkml

Last synced: 13 days ago
JSON representation

Verifiable inference on Bittensor

Awesome Lists containing this project

README

          

# **Subnet 2 [τ, β]**

[![Discord Chat](https://img.shields.io/discord/308323056592486420.svg?logo=discord)](https://discord.gg/bittensor)

### Proof of Inference

Autonomy unbridled.
Governed by math, not blind faith.

[Documentation](https://sn2-docs.inferencelabs.com/) • [Inference Labs](https://x.com/inference_labs) • [Stats](https://sn2-stats.inferencelabs.com/) • [Studio](https://sn2-studio.inferencelabs.com/) • [Dashboard](https://wandb.ai/inferencelabs/subnet-2)

Subnet 2 represents a significant stride in enhancing the Bittensor network, aiming to create the world's largest peer-to-peer **Verified** Intelligence network, by building a Proof-of-Inference system for the Bittensor network. This initiative aligns with the Opentensor foundation's criteria for innovative subnet solutions. zk-ML allows AI models to be converted into a unique 'fingerprint,' a circuit that can be used to verify that a model's prediction was generated by a specific AI model, thereby providing what we term as Proof-of-Inference.

The miner and validator are native Rust binaries communicating over both HTTP and QUIC (via [btlightning](https://github.com/inference-labs-inc/lightning)). Pre-built binaries are published as [GitHub releases](https://github.com/inference-labs-inc/subnet-2/releases); the binaries include a built-in auto-update mechanism that polls for new releases every 5 minutes and performs atomic binary replacement so PM2 restarts with the new version.

## Miners and Validators Functionality

### Incentive Mechanism and Reward Structure

Subnet 2 incentivizes miners and validators to contribute to the generation and validation of high-quality, secure, and efficient verified AI predictions using a specialized reward mechanism aligned with the unique aspects of zero-knowledge machine learning (zk-ML) and decentralized AI. Zero-knowledge proofs are generally more CPU computationally intensive and open the opportunity for non-GPU miners to participate, however the end goal is to further incentivize the development of proving systems optimized for GPU-based operations. The incentives are based around miners creating succinct and efficient models which can be circuitized with a zero-knowledge proving system.

The reward mechanism scores the initial AI predictions based on the cryptographic integrity and time to generate zk-proofs along with the outputs, rather than solely on end results. This approach reduces the computational burden on validators as zk-proofs confirm the source model and integrity of AI predictions efficiently.

### Miners

- Receive input data from validators on the subnet
- Generate predictions using custom, verifiable AI models that have been converted into zero-knowledge circuits
- Return the generated content to the requesting validator for validation and distribution

### Validators

- Produce input data and distribute requests for verified inference throughout miners participating on the subnet
- Confirm that miners are acting faithfully, by verifying the authenticity of the miner's returned zero-knowledge proof
- Score results from miners based on performance metrics such as proof size and response time

## Quickstart

### Prerequisites

| Tool | Description |
|------|-------------|
| [Rust](https://rustup.rs/) | Required to build from source. Install via `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \| sh` |
| [PM2](https://pm2.keymetrics.io/) | Process manager used to run and monitor the binaries in the background |
| [btcli](https://docs.bittensor.com/getting-started/installation) | CLI for interacting with the Bittensor network (wallet creation, registration) |

Alternatively, use Docker — no Rust toolchain needed. See the Docker instructions under [Run the Miner](#run-the-miner) and [Run the Validator](#run-the-validator) below.

### Install from pre-built binary

Automatically detects your platform, downloads the latest release, verifies the SHA256 checksum, and installs to `/usr/local/bin`:

```console
curl -fsSL https://raw.githubusercontent.com/inference-labs-inc/subnet-2/main/install.sh | bash
```

To install only the miner or validator:

```console
curl -fsSL https://raw.githubusercontent.com/inference-labs-inc/subnet-2/main/install.sh | bash -s -- sn2-miner
curl -fsSL https://raw.githubusercontent.com/inference-labs-inc/subnet-2/main/install.sh | bash -s -- sn2-validator
```

For testnet builds (from the `testnet` branch):

```console
curl -fsSL https://raw.githubusercontent.com/inference-labs-inc/subnet-2/testnet/install.sh | NETWORK=testnet bash
curl -fsSL https://raw.githubusercontent.com/inference-labs-inc/subnet-2/testnet/install.sh | NETWORK=testnet bash -s -- sn2-miner
curl -fsSL https://raw.githubusercontent.com/inference-labs-inc/subnet-2/testnet/install.sh | NETWORK=testnet bash -s -- sn2-validator
```

Or download manually from [GitHub Releases](https://github.com/inference-labs-inc/subnet-2/releases).

### Build from source

```console
git clone https://github.com/inference-labs-inc/subnet-2.git
cd subnet-2
cargo build --release --bin sn2-validator --bin sn2-miner
```

Binaries will be at `target/release/sn2-validator` and `target/release/sn2-miner`.

[Setup guide →](docs/shared_setup_steps.md)

### Register on the Subnet

```console
btcli subnet register --subtensor.network finney --netuid 2 --wallet.name {your_coldkey} --wallet.hotkey {your_hotkey}
```

### Run the Miner

Docker

#### With docker compose (recommended)

```yaml
---
services:

subnet-2-miner:
image: ghcr.io/inference-labs-inc/subnet-2:latest
restart: unless-stopped
ports:
- 8091:8091
volumes:
- {path_to_your_.bittensor_directory}:/home/subnet2/.bittensor
environment:
- PUID=1000
- HOME=/home/subnet2
labels:
- com.centurylinklabs.watchtower.enable=true
command: sn2-miner --wallet-name {your_miner_key_name} --wallet-hotkey {your_miner_hotkey_name} --netuid 2

watchtower:
image: containrrr/watchtower:latest
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
command: --interval 60 --cleanup --label-enable
```

#### With docker cli

```console
docker run -d \
--name subnet-2-miner \
-p 8091:8091 \
-v {path_to_your_.bittensor_directory}:/home/subnet2/.bittensor \
-e PUID=1000 \
-e HOME=/home/subnet2 \
--restart unless-stopped \
ghcr.io/inference-labs-inc/subnet-2:latest \
sn2-miner \
--wallet-name {your_miner_key_name} \
--wallet-hotkey {your_miner_hotkey_name} \
--netuid 2
```

#### With PM2

```console
make pm2-miner WALLET_NAME={your_miner_key_name} WALLET_HOTKEY={your_miner_hotkey_name}
```

Or directly (use `./sn2-miner` for pre-built binaries, `target/release/sn2-miner` for source builds):

```console
pm2 start ./sn2-miner --name subnet-2-miner --kill-timeout 3000 -- \
--wallet-name {your_miner_key_name} \
--wallet-hotkey {your_miner_hotkey_name} \
--netuid 2
```

### Run the Validator

Docker

#### With docker compose (recommended)

```yaml
---
services:

subnet-2-validator:
image: ghcr.io/inference-labs-inc/subnet-2:latest
restart: unless-stopped
ports:
- 8443:8443
- 9090:9090
volumes:
- {path_to_your_.bittensor_directory}:/home/subnet2/.bittensor
environment:
- PUID=1000
- HOME=/home/subnet2
labels:
- com.centurylinklabs.watchtower.enable=true
command: sn2-validator --wallet-name {validator_key_name} --wallet-hotkey {validator_hotkey_name} --netuid 2

watchtower:
image: containrrr/watchtower:latest
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
command: --interval 60 --cleanup --label-enable
```

#### With docker cli

```console
docker run -d \
--name subnet-2-validator \
-p 8443:8443 \
-p 9090:9090 \
-v {path_to_your_.bittensor_directory}:/home/subnet2/.bittensor \
-e PUID=1000 \
-e HOME=/home/subnet2 \
--restart unless-stopped \
ghcr.io/inference-labs-inc/subnet-2:latest \
sn2-validator \
--wallet-name {validator_key_name} \
--wallet-hotkey {validator_hotkey_name} \
--netuid 2
```

#### With PM2

```console
make pm2-validator WALLET_NAME={validator_key_name} WALLET_HOTKEY={validator_hotkey_name}
```

Or directly (use `./sn2-validator` for pre-built binaries, `target/release/sn2-validator` for source builds):

```console
pm2 start ./sn2-validator --name subnet-2-validator --kill-timeout 3000 -- \
--wallet-name {validator_key_name} \
--wallet-hotkey {validator_hotkey_name} \
--netuid 2
```

## Miner

Miners contribute to this subnet by providing compute to generate output from, and prove AI model inferences. Miners receive workloads from validators in the form of input data, perform verified inferences on those inputs and respond with output along with a zero-knowledge proof of inference.

### Hardware requirements

#### Minimum

| Component | Requirement |
| -------------- | ------------- |
| CPU | 8 core 3.2GHz |
| RAM | 32GB |
| Network Up | 400Mbps |
| Network Down | 400Mbps |
| Storage | 1TB |
| Storage Medium | NVMe SSD |

#### Recommended

> [!NOTE]
> Exceeding these requirements in terms of storage, network and CPU speed will most likely result in higher rewards due to performance incentivization.

| Component | Recommendation |
| -------------- | -------------- |
| CPU | 8 core 3.6GHz+ |
| RAM | 64GB+ |
| Network Up | 1Gbps |
| Network Down | 1Gbps |
| Storage | 2TB |
| Storage Medium | NVMe SSD |

## Validator

Validators are responsible for verifying model outputs as provided by miners, and updating that miner's score based on the verification results.

### Hardware requirements

#### Minimum

| Component | Requirement |
| ------------ | ------------- |
| CPU | 8 core 3.2GHz |
| RAM | 16GB |
| Network Up | 400Mbps |
| Network Down | 400Mbps |
| Storage | 1TB |

#### Recommended

| Component | Recommendation |
| -------------- | -------------- |
| CPU | 8 core 3.4GHz |
| RAM | 32GB |
| Network Up | 1+Gbps |
| Network Down | 1+Gbps |
| Storage | 2+TB |
| Storage Medium | SSD |

## Architecture

The codebase is organized as a Rust workspace with the following crates:

| Crate | Purpose |
|-------|---------|
| `sn2-types` | Shared types, constants, and protocol definitions |
| `sn2-chain` | Wallet, metagraph, registration, weights, and auto-update |
| `sn2-verify` | Proof verification via the [Expander](https://github.com/inference-labs-inc/Expander) backend |
| `sn2-validator` | Validator binary |
| `sn2-miner` | Miner binary |

Both binaries communicate with miners/validators over HTTP (axum) and QUIC ([btlightning](https://github.com/inference-labs-inc/lightning)). Chain interactions use [subxt](https://github.com/paritytech/subxt) for direct Substrate RPC.