-
Notifications
You must be signed in to change notification settings - Fork 122
DSperce integration #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
millioner
wants to merge
24
commits into
testnet
Choose a base branch
from
dsperse-intergration
base: testnet
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
DSperce integration #169
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
63c21cb
New dependencies
millioner b2e3ee9
First steps for DSperse integration. Doesn't work yet even close. Sti…
millioner bf36769
dslices files handling for models
millioner 150659d
Model metadata fix
millioner e5f2349
Adding dslice requests to the queue and processing them
millioner 3f5c1c1
Request generation fixes
millioner cc8d79b
Move DSperseManager to use it by miner
millioner 2110cfa
Proving slices on miner side
millioner 672920d
Verify dslice proofs in validator side
millioner bf901c6
Cleanup completed DSperse run
millioner 50f142b
Generate random input for DSLice request
millioner 14a9396
Log request type to console
millioner 1a9bafb
Removing dsperse run fix
millioner 2d23514
Option to disable metrics logging
millioner 80fbdee
Requests rescktheduling and a lot of refactoring
millioner 99f954e
Upgrade urllib3 to 2.6.2
millioner ecd5fea
Small fixes suggested by copilot
millioner c3cd0bd
Requests reskedjuling fixes :stuck_out_tongue_winking_eye:
millioner cb10e72
Check proof inputs before verifying
millioner 0e92ec3
Getting slice settings fix
millioner 59883d8
DSperse cleanup un exit
millioner f19be4f
Actual urls for slices
millioner 6897792
Compile DSlices if needed during pre-flight stage
millioner 8b6e359
Tiniest fix ever
millioner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import random | ||
| import os | ||
| import uuid | ||
| import tempfile | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from bittensor import logging | ||
| from dsperse.src.slice.utils.converter import Converter | ||
| from dsperse.src.run.runner import Runner | ||
|
|
||
| from constants import DSPERSE_SLICES_FILE_NAME | ||
| from deployment_layer.circuit_store import circuit_store | ||
| from execution_layer.circuit import CircuitType, Circuit | ||
| from _validator.models.dslice_request import DSliceQueuedProofRequest | ||
|
||
| from _validator.models.request_type import RequestType | ||
| from _validator.api import ValidatorAPI | ||
|
|
||
|
|
||
| class DSperseManager: | ||
| def __init__(self, api: ValidatorAPI): | ||
| self.api = api | ||
| self.circuits: list[Circuit] = [ | ||
| circuit | ||
| for circuit in circuit_store.circuits | ||
| if circuit.metadata.type == CircuitType.DSPERSE_PROOF_GENERATION | ||
| ] | ||
| self.runs = {} | ||
|
|
||
| def generate_dslice_requests(self) -> list: | ||
| """ | ||
| Generate DSlice requests for DSperse models. | ||
| Each DSlice request corresponds to one slice of a DSperse model. | ||
| """ | ||
| if self.api.stacked_requests_queue or not self.circuits: | ||
| # there are already requests stacked, do not generate new DSlice requests | ||
| return [] | ||
|
|
||
| circuit = random.choice(self.circuits) | ||
| run_uid = str(uuid.uuid4()) | ||
| logging.info( | ||
| f"Generating DSlice requests for circuit {circuit.metadata.name}... Run UID: {run_uid}" | ||
| ) | ||
|
|
||
| # TODO: ... | ||
| self.run_dsperse(circuit, run_uid) | ||
| dslice_requests = [] | ||
| # Logic to create DSlice requests goes here | ||
| return dslice_requests | ||
|
|
||
| def extract_slices(self, circuit: Circuit) -> Path: | ||
| """ | ||
| Extract slices from a DSperse circuit file. | ||
| Returns the path to the folder containing the extracted slices. | ||
| """ | ||
| dsperse_file_path = ( | ||
| Path(circuit.paths.external_base_path) / DSPERSE_SLICES_FILE_NAME | ||
| ) | ||
| dsperse_slices_folder = dsperse_file_path.with_suffix("") | ||
| # TODO: Check is already converted | ||
| Converter.convert( | ||
| path=dsperse_file_path, | ||
| output_type="dirs", | ||
| output_path=dsperse_slices_folder, | ||
| ) | ||
| return dsperse_slices_folder | ||
|
|
||
| def run_dsperse(self, circuit: Circuit, run_uid: str) -> None: | ||
| slices_path = self.extract_slices(circuit) | ||
|
|
||
| # Create temporary folder for run metadata | ||
| run_metadata_path = Path(tempfile.mkdtemp(prefix=f"dsperse_run_{run_uid}_")) | ||
| save_metadata_path = run_metadata_path / "metadata.json" | ||
| logging.info(f"Running DSperse model. Run metadata path: {run_metadata_path}") | ||
|
|
||
| # Generate benchmarking input JSON | ||
| input_json_path = run_metadata_path / "input.json" | ||
| with open(input_json_path, "w") as f: | ||
| json.dump(circuit.input_handler(RequestType.BENCHMARK).generate(), f) | ||
|
|
||
| # init runner and run the sliced model | ||
| runner = Runner( | ||
| run_metadata_path=run_metadata_path, save_metadata_path=save_metadata_path | ||
| ) | ||
| results = runner.run(input_json_path=input_json_path, slice_path=slices_path) | ||
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from _validator.models.base_rpc_request import QueuedRequestDataModel | ||
| from pydantic import Field | ||
|
|
||
|
|
||
| class DSliceQueuedProofRequest(QueuedRequestDataModel): | ||
| """ | ||
| Request for a DSperse slice. | ||
| """ | ||
|
|
||
| slice_num: str = Field(..., description="Num of the DSperse slice") | ||
| run_uid: str = Field(..., description="UID of the DSperse run") | ||
| outputs: dict = Field(..., description="Outputs of the DSperse slice") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.