Skip to content

Commit 1d3b5fe

Browse files
authored
Move circuit weights into metadata (#52)
1 parent 7ea190a commit 1d3b5fe

File tree

12 files changed

+64
-47
lines changed

12 files changed

+64
-47
lines changed

docs/custom_circuit_integrations.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,18 @@ There are three primary functions which must be implemented.
7373

7474
This file is responsible for describing the circuit's properties, and contains both optional and required fields.
7575

76-
| Field | Type | Description | Required |
77-
| ----------------- | --------------- | ------------------------------------------------------------------------------------ | -------- |
78-
| `name` | `string` | The name of the circuit. ||
79-
| `description` | `string` | A short description of the circuit. ||
80-
| `author` | `string` | The author of the circuit. ||
81-
| `version` | `string` | The version of the circuit. ||
82-
| `proof_system` | [`ProofSystem`] | The proof system used by the circuit. ||
83-
| `type` | [`CircuitType`] | The type of circuit. New circuits should use `PROOF_OF_COMPUTATION` by default ||
84-
| `external_files` | `dict` | A dictionary of external files required by the circuit. ||
85-
| `netuid` | `int` | For Proof of Weights, the netuid of the target subnet. ||
86-
| `weights_version` | `int` | For Proof of Weights, the version of subnet weights that the circuit corresponds to. ||
76+
| Field | Type | Description | Required |
77+
| ------------------------- | --------------- | ------------------------------------------------------------------------------------ | -------- |
78+
| `name` | `string` | The name of the circuit. ||
79+
| `description` | `string` | A short description of the circuit. ||
80+
| `author` | `string` | The author of the circuit. ||
81+
| `version` | `string` | The version of the circuit. ||
82+
| `proof_system` | [`ProofSystem`] | The proof system used by the circuit. ||
83+
| `type` | [`CircuitType`] | The type of circuit. New circuits should use `PROOF_OF_COMPUTATION` by default ||
84+
| `external_files` | `dict` | A dictionary of external files required by the circuit. ||
85+
| `netuid` | `int` | For Proof of Weights, the netuid of the target subnet. ||
86+
| `weights_version` | `int` | For Proof of Weights, the version of subnet weights that the circuit corresponds to. ||
87+
| `benchmark_choice_weight` | `float` | The probability of the circuit being selected for benchmark request. ||
8788

8889
[See it's class definition here for more information](https://github.com/inference-labs-inc/omron-subnet/blob/main/neurons/execution_layer/circuit.py#L100)
8990

@@ -120,7 +121,7 @@ Ensure all the following files are copied into this directory or are listed in t
120121

121122
### Adding benchmark requests
122123

123-
The last step after adding your circuit is to add an allocation of benchmark requests to the circuit. This is done through a modification to the `neurons/constants.py` file. In the `CIRCUIT_WEIGHTS` dictionary, add a new key-value pair where the key is the `SHA256` hash of the circuit's verification key, and the value is the percentage of requests that should be allocated to the circuit. Percentages should be between 0 and 1 and do not need to sum to 1. A reasonable starting point is 0.20 for each circuit. The omron team will adjust these weights as necessary to ensure a healthy distribution of requests across all circuits.
124+
The last step after adding your circuit is to add an allocation of benchmark requests to the circuit. This is done through a modification to the circuit `metadata.json` file. The `benchmark_choice_weight` value is the percentage of requests that should be allocated to the circuit. Percentages should be between 0 and 1 and sum of them for all models do not need to be equal to 1. A reasonable starting point is 0.20 for each circuit. The omron team will adjust these weights as necessary to ensure a healthy distribution of requests across all circuits.
124125

125126
A higher percentage will result in more requests being allocated to the circuit, increasing the circuit's optimization pressure.
126127

@@ -129,9 +130,8 @@ A higher percentage will result in more requests being allocated to the circuit,
129130
To update an existing circuit:
130131

131132
1. Follow the same steps as adding a new circuit, which will result in a new verification key hash
132-
2. In the `CIRCUIT_WEIGHTS` dictionary, set the old circuit's allocation to 0.0
133-
3. Add the new circuit with the desired benchmark allocation
134-
4. Open a PR with these changes
133+
2. Add the new circuit with the desired benchmark allocation
134+
3. Open a PR with these changes
135135

136136
## Querying a circuit
137137

neurons/_validator/core/request_pipeline.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
from __future__ import annotations
2-
from _validator.pow.proof_of_weights_handler import ProofOfWeightsHandler
3-
import bittensor as bt
2+
3+
import copy
44
import random
5-
from protocol import ProofOfWeightsSynapse, QueryZkProof
65

7-
from _validator.scoring.score_manager import ScoreManager
6+
import bittensor as bt
7+
88
from _validator.api import ValidatorAPI
99
from _validator.config import ValidatorConfig
10+
from _validator.core.request import Request
11+
from _validator.models.request_type import RequestType
12+
from _validator.pow.proof_of_weights_handler import ProofOfWeightsHandler
13+
from _validator.scoring.score_manager import ScoreManager
14+
from _validator.utils.hash_guard import HashGuard
1015
from constants import (
1116
BATCHED_PROOF_OF_WEIGHTS_MODEL_ID,
12-
CIRCUIT_WEIGHTS,
1317
SINGLE_PROOF_OF_WEIGHTS_MODEL_ID,
1418
)
1519
from deployment_layer.circuit_store import circuit_store
1620
from execution_layer.circuit import Circuit, CircuitType
1721
from execution_layer.generic_input import GenericInput
18-
from _validator.utils.hash_guard import HashGuard
19-
from _validator.core.request import Request
22+
from protocol import ProofOfWeightsSynapse, QueryZkProof
2023
from utils.wandb_logger import safe_log
21-
from _validator.models.request_type import RequestType
22-
import copy
2324

2425

2526
class RequestPipeline:
@@ -124,13 +125,16 @@ def select_circuit_for_benchmark(self) -> Circuit:
124125
"""
125126
Select a circuit for benchmarking using weighted random selection.
126127
"""
127-
128-
circuit_id = random.choices(
129-
list(CIRCUIT_WEIGHTS.keys()), weights=list(CIRCUIT_WEIGHTS.values()), k=1
128+
circuits = list(circuit_store.circuits.values())
129+
130+
return random.choices(
131+
circuits,
132+
weights=[
133+
(circuit.metadata.benchmark_choice_weight or 0) for circuit in circuits
134+
],
135+
k=1,
130136
)[0]
131137

132-
return circuit_store.get_circuit(circuit_id)
133-
134138
def format_for_query(
135139
self, inputs: dict[str, object], circuit: Circuit
136140
) -> dict[str, object]:

neurons/cli_parser.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ def init_config(role: Optional[str] = None):
8787
default=False,
8888
help="Whether to run the miner in localnet mode.",
8989
)
90+
parser.add_argument(
91+
"--timeout",
92+
default=120,
93+
type=int,
94+
help="Timeout for requests in seconds (default: 120)",
95+
)
9096
parser.add_argument(
9197
"--external-model-dir",
9298
default=None,
@@ -123,7 +129,6 @@ def init_config(role: Optional[str] = None):
123129
config.eth_wallet = (
124130
config.eth_wallet if config.eth_wallet is not None else "0x002"
125131
)
126-
config.timeout = config.timeout if config.timeout is None else 120
127132
config.disable_wandb = True
128133
config.verbose = config.verbose if config.verbose is None else True
129134
config.max_workers = config.max_workers or 1
@@ -140,6 +145,9 @@ def init_config(role: Optional[str] = None):
140145
else:
141146
config.full_path_models = os.path.join(config.full_path, "models")
142147

148+
if config.whitelisted_public_keys:
149+
config.whitelisted_public_keys = config.whitelisted_public_keys.split(",")
150+
143151
os.makedirs(config.full_path, exist_ok=True)
144152
os.makedirs(config.full_path_score, exist_ok=True)
145153
os.makedirs(config.full_path_models, exist_ok=True)
@@ -267,6 +275,13 @@ def _validator_config():
267275
),
268276
)
269277

278+
parser.add_argument(
279+
"--whitelisted-public-keys",
280+
type=str,
281+
default=None,
282+
help="A comma-separated list of public keys to whitelist for external requests.",
283+
)
284+
270285
parser.add_argument(
271286
"--certificate-path",
272287
type=str,

neurons/constants.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ class Roles:
6868
MAX_PROOFS_TO_LOG = 0
6969
# Era period for proof of weights (mortality of the pow log)
7070
PROOF_OF_WEIGHTS_LIFESPAN = 2
71-
# Weights that determine the probability of selecting a circuit for benchmarking
72-
CIRCUIT_WEIGHTS = {
73-
"1d60d545b7c5123fd60524dcbaf57081ca7dc4a9ec36c892927a3153328d17c0": 0,
74-
"33b92394b18412622adad75733a6fc659b4e202b01ee8a5465958a6bad8ded62": 0.20,
75-
"37320fc74fec80805eedc8e92baf3c58842a2cb2a4ae127ad6e930f0c8441c7a": 0,
76-
"a4bcecaf699fd9212600a1f2fcaa40c444e1aeaab409ea240a38c33ed356f4e2": 0.20,
77-
"a849500803abdbb86a9460e18684a6411dc7ae0b75f1f6330e3028081a497dea": 0.20,
78-
"e84b2e5f223621fa20078eb9f920d8d4d3a4ff95fa6e2357646fdbb43a2557c9": 0.20,
79-
"8dcff627a782525ea86196941a694ffbead179905f0cd4550ddc3df9e2b90924": 0.20,
80-
}
8171
# Maximum signature lifespan for WebSocket requests
8272
MAX_SIGNATURE_LIFESPAN = 300
8373
# Whitelisted public keys (ss58 addresses) we accept external requests from by default

neurons/deployment_layer/model_1d60d545b7c5123fd60524dcbaf57081ca7dc4a9ec36c892927a3153328d17c0/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"proof_system": "JOLT",
77
"netuid": 27,
88
"type": "proof_of_weights",
9-
"external_files": {}
9+
"external_files": {},
10+
"benchmark_choice_weight": 0
1011
}

neurons/deployment_layer/model_33b92394b18412622adad75733a6fc659b4e202b01ee8a5465958a6bad8ded62/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"type": "proof_of_weights",
1010
"external_files": {
1111
"pk.key": "https://storage.omron.ai/33b92394b18412622adad75733a6fc659b4e202b01ee8a5465958a6bad8ded62/pk.key"
12-
}
12+
},
13+
"benchmark_choice_weight": 0.2
1314
}

neurons/deployment_layer/model_37320fc74fec80805eedc8e92baf3c58842a2cb2a4ae127ad6e930f0c8441c7a/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"version": "0.0.5",
66
"proof_system": "JOLT",
77
"type": "proof_of_computation",
8-
"external_files": {}
8+
"external_files": {},
9+
"benchmark_choice_weight": 0
910
}

neurons/deployment_layer/model_8dcff627a782525ea86196941a694ffbead179905f0cd4550ddc3df9e2b90924/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"type": "proof_of_computation",
88
"external_files": {
99
"pk.key": "https://storage.omron.ai/8dcff627a782525ea86196941a694ffbead179905f0cd4550ddc3df9e2b90924/pk.key"
10-
}
10+
},
11+
"benchmark_choice_weight": 0.2
1112
}

neurons/deployment_layer/model_a4bcecaf699fd9212600a1f2fcaa40c444e1aeaab409ea240a38c33ed356f4e2/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"type": "proof_of_weights",
1010
"external_files": {
1111
"pk.key": "https://storage.omron.ai/a4bcecaf699fd9212600a1f2fcaa40c444e1aeaab409ea240a38c33ed356f4e2/pk.key"
12-
}
12+
},
13+
"benchmark_choice_weight": 0.2
1314
}

neurons/deployment_layer/model_a849500803abdbb86a9460e18684a6411dc7ae0b75f1f6330e3028081a497dea/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"type": "proof_of_computation",
88
"external_files": {
99
"circuit.zkey": "https://storage.omron.ai/a849500803abdbb86a9460e18684a6411dc7ae0b75f1f6330e3028081a497dea/circuit.zkey"
10-
}
10+
},
11+
"benchmark_choice_weight": 0.2
1112
}

neurons/deployment_layer/model_e84b2e5f223621fa20078eb9f920d8d4d3a4ff95fa6e2357646fdbb43a2557c9/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"type": "proof_of_weights",
1010
"external_files": {
1111
"circuit.zkey": "https://storage.omron.ai/e84b2e5f223621fa20078eb9f920d8d4d3a4ff95fa6e2357646fdbb43a2557c9/circuit.zkey"
12-
}
12+
},
13+
"benchmark_choice_weight": 0.2
1314
}

neurons/execution_layer/circuit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class CircuitMetadata:
122122
external_files: dict[str, str]
123123
netuid: int | None = None
124124
weights_version: int | None = None
125+
benchmark_choice_weight: float | None = None
125126

126127
@classmethod
127128
def from_file(cls, metadata_path: str) -> CircuitMetadata:

0 commit comments

Comments
 (0)