Skip to content

Commit 51acea2

Browse files
authored
Download srs kzg commitments on validator init (#71)
1 parent 29c6880 commit 51acea2

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

neurons/utils/pre_flight.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import cli_parser
1616
from constants import IGNORED_MODEL_HASHES
17-
from execution_layer.circuit import ProofSystem
1817

1918
from functools import partial
2019
from collections import OrderedDict
@@ -56,12 +55,14 @@ def run_shared_preflight_checks(role: Optional[Roles] = None):
5655
Exception: If any of the pre-flight checks fail.
5756
"""
5857

59-
preflight_checks = OrderedDict({
60-
"Syncing model files": partial(sync_model_files, role=role),
61-
"Ensuring Node.js version": ensure_nodejs_version,
62-
"Checking SnarkJS installation": ensure_snarkjs_installed,
63-
"Checking EZKL installation": ensure_ezkl_installed,
64-
})
58+
preflight_checks = OrderedDict(
59+
{
60+
"Syncing model files": partial(sync_model_files, role=role),
61+
"Ensuring Node.js version": ensure_nodejs_version,
62+
"Checking SnarkJS installation": ensure_snarkjs_installed,
63+
"Checking EZKL installation": ensure_ezkl_installed,
64+
}
65+
)
6566

6667
bt.logging.info(" PreFlight | Running pre-flight checks")
6768

@@ -176,6 +177,26 @@ def sync_model_files(role: Optional[Roles] = None):
176177
MODEL_DIR = os.path.join(os.path.dirname(__file__), "..", "deployment_layer")
177178
SYNC_LOG_PREFIX = " SYNC | "
178179

180+
loop = asyncio.get_event_loop()
181+
for logrows in range(1, 26):
182+
if os.path.exists(
183+
os.path.join(os.path.expanduser("~"), ".ezkl", "srs", f"kzg{logrows}.srs")
184+
):
185+
bt.logging.info(
186+
f"{SYNC_LOG_PREFIX}SRS for logrows={logrows} already exists, skipping..."
187+
)
188+
continue
189+
190+
try:
191+
loop.run_until_complete(download_srs(logrows))
192+
bt.logging.info(
193+
f"{SYNC_LOG_PREFIX}Successfully downloaded SRS for logrows={logrows}"
194+
)
195+
except Exception as e:
196+
bt.logging.error(
197+
f"{SYNC_LOG_PREFIX}Failed to download SRS for logrows={logrows}: {e}"
198+
)
199+
179200
for model_hash in os.listdir(MODEL_DIR):
180201
if not model_hash.startswith("model_"):
181202
continue
@@ -203,29 +224,6 @@ def sync_model_files(role: Optional[Roles] = None):
203224
SYNC_LOG_PREFIX + f"Failed to parse JSON from {metadata_file}"
204225
)
205226
continue
206-
# If it's an EZKL model, we'll try to download the SRS files
207-
if metadata.get("proof_system") == ProofSystem.EZKL:
208-
ezkl_settings_file = os.path.join(MODEL_DIR, model_hash, "settings.json")
209-
if not os.path.isfile(ezkl_settings_file):
210-
bt.logging.error(
211-
f"{SYNC_LOG_PREFIX}Settings file not found at {ezkl_settings_file} for {model_hash}. Skipping sync."
212-
)
213-
continue
214-
215-
try:
216-
with open(ezkl_settings_file, "r", encoding="utf-8") as f:
217-
logrows = json.load(f).get("run_args", {}).get("logrows")
218-
if logrows:
219-
loop = asyncio.get_event_loop()
220-
loop.run_until_complete(download_srs(logrows))
221-
bt.logging.info(
222-
f"{SYNC_LOG_PREFIX}Successfully downloaded SRS for logrows={logrows}"
223-
)
224-
except (json.JSONDecodeError, subprocess.CalledProcessError) as e:
225-
bt.logging.error(
226-
f"{SYNC_LOG_PREFIX}Failed to process settings or download SRS: {e}"
227-
)
228-
continue
229227

230228
external_files = metadata.get("external_files", {})
231229
for key, url in external_files.items():

0 commit comments

Comments
 (0)