-
Notifications
You must be signed in to change notification settings - Fork 4
Add option to use Compute Horde #68
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
Merged
ap-choji
merged 1 commit into
deval-core:v1.5.0_staging
from
backend-developers-ltd:compute-horde
Mar 5, 2025
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .git/ | ||
| .venv/ | ||
| **/__pycache__/ | ||
| **/*.pyc |
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
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,124 @@ | ||
| import pickle | ||
| import time | ||
|
|
||
| import bittensor as bt | ||
| from compute_horde_sdk.v1 import ( | ||
| ComputeHordeClient as SDKComputeHordeClient, | ||
| InlineInputVolume, | ||
| HuggingfaceInputVolume, | ||
| ExecutorClass, | ||
| ComputeHordeJobStatus, | ||
| ) | ||
|
|
||
| from deval.contest import DeValContest | ||
| from deval.model.model_state import ModelState | ||
| from deval.compute_horde_settings import ( | ||
| COMPUTE_HORDE_ARTIFACT_OUTPUT_PATH, | ||
| COMPUTE_HORDE_FACILITATOR_URL, | ||
| COMPUTE_HORDE_JOB_NAMESPACE, | ||
| COMPUTE_HORDE_VALIDATOR_HOTKEY, | ||
| COMPUTE_HORDE_EXECUTOR_CLASS, | ||
| COMPUTE_HORDE_JOB_DOCKER_IMAGE, | ||
| COMPUTE_HORDE_JOB_TIMEOUT, | ||
| COMPUTE_HORDE_ARTIFACTS_DIR, | ||
| COMPUTE_HORDE_VOLUME_MODEL_PATH, | ||
| COMPUTE_HORDE_VOLUME_TASK_REPO_DIR, | ||
| COMPUTE_HORDE_VOLUME_MINER_STATE_DIR, | ||
| COMPUTE_HORDE_VOLUME_MINER_STATE_FILENAME, | ||
| COMPUTE_HORDE_VOLUME_TASK_REPO_FILENAME, | ||
| ) | ||
| from deval.task_repository import TaskRepository | ||
|
|
||
| _REQUIRED_SETTINGS = ( | ||
| "COMPUTE_HORDE_JOB_NAMESPACE", | ||
| "COMPUTE_HORDE_JOB_DOCKER_IMAGE", | ||
| "COMPUTE_HORDE_VALIDATOR_HOTKEY", | ||
| ) | ||
|
|
||
|
|
||
| class ComputeHordeClient: | ||
| def __init__(self, keypair: bt.Keypair): | ||
| missing_settings = [ | ||
| setting for setting in _REQUIRED_SETTINGS if not globals().get(setting) | ||
| ] | ||
| if missing_settings: | ||
| raise ValueError( | ||
| f"Required settings: {', '.join(missing_settings)} are not set. " | ||
| "Please set them in your .env file." | ||
| ) | ||
|
|
||
| self.keypair = keypair | ||
| self.executor_class = ( | ||
| ExecutorClass(COMPUTE_HORDE_EXECUTOR_CLASS) | ||
| if COMPUTE_HORDE_EXECUTOR_CLASS | ||
| else ExecutorClass.always_on__llm__a6000 | ||
| ) | ||
| self.client = SDKComputeHordeClient( | ||
| hotkey=self.keypair, | ||
| compute_horde_validator_hotkey=COMPUTE_HORDE_VALIDATOR_HOTKEY, | ||
| **( | ||
| {"facilitator_url": COMPUTE_HORDE_FACILITATOR_URL} | ||
| if COMPUTE_HORDE_FACILITATOR_URL | ||
| else {} | ||
| ), | ||
| ) | ||
|
|
||
| async def run_epoch_on_compute_horde( | ||
| self, | ||
| contest: DeValContest, | ||
| miner_state: ModelState, | ||
| task_repo: TaskRepository, | ||
| ) -> ModelState: | ||
| task_repo_pkl = pickle.dumps(task_repo) | ||
|
|
||
| bt.logging.info("Running organic job on Compute Horde.") | ||
|
|
||
| job = await self.client.create_job( | ||
| executor_class=self.executor_class, | ||
| job_namespace=COMPUTE_HORDE_JOB_NAMESPACE, | ||
| docker_image=COMPUTE_HORDE_JOB_DOCKER_IMAGE, | ||
| args=[ | ||
| "poetry", | ||
| "run", | ||
| "python", | ||
| "neurons/compute_horde_entrypoint.py", | ||
| "--timeout", | ||
| str(contest.timeout), | ||
| ], | ||
| artifacts_dir=COMPUTE_HORDE_ARTIFACTS_DIR, | ||
| # TODO: Pin huggingface volume revision. | ||
| input_volumes={ | ||
| COMPUTE_HORDE_VOLUME_MINER_STATE_DIR: InlineInputVolume.from_file_contents( | ||
| COMPUTE_HORDE_VOLUME_MINER_STATE_FILENAME, pickle.dumps(miner_state) | ||
| ), | ||
| COMPUTE_HORDE_VOLUME_TASK_REPO_DIR: InlineInputVolume.from_file_contents( | ||
| COMPUTE_HORDE_VOLUME_TASK_REPO_FILENAME, task_repo_pkl | ||
| ), | ||
| COMPUTE_HORDE_VOLUME_MODEL_PATH: HuggingfaceInputVolume( | ||
| repo_id=miner_state.get_model_url() | ||
| ), | ||
| }, | ||
| ) | ||
|
|
||
| start = time.time() | ||
|
|
||
| await job.wait(timeout=COMPUTE_HORDE_JOB_TIMEOUT) | ||
|
|
||
| time_took = time.time() - start | ||
|
|
||
| if job.result is None: | ||
| raise RuntimeError("Job result is None. Check logs for more details.") | ||
|
|
||
| bt.logging.info(job.result.stdout) | ||
|
|
||
| if job.status != ComputeHordeJobStatus.COMPLETED: | ||
| raise RuntimeError( | ||
| f"Job status is {job.status}. Check logs for more details." | ||
| ) | ||
|
|
||
| bt.logging.success(f"Job finished in {time_took} seconds") | ||
|
|
||
| model_state_pkl = job.result.artifacts[COMPUTE_HORDE_ARTIFACT_OUTPUT_PATH] | ||
|
|
||
| miner_state: ModelState = pickle.loads(model_state_pkl) | ||
| return miner_state |
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,28 @@ | ||
| import os | ||
|
|
||
| from dotenv import load_dotenv, find_dotenv | ||
|
|
||
| load_dotenv(find_dotenv()) | ||
|
|
||
| COMPUTE_HORDE_VALIDATOR_HOTKEY = os.environ.get("COMPUTE_HORDE_VALIDATOR_HOTKEY") | ||
| COMPUTE_HORDE_EXECUTOR_CLASS = os.environ.get("COMPUTE_HORDE_EXECUTOR_CLASS") | ||
| COMPUTE_HORDE_FACILITATOR_URL = os.environ.get("COMPUTE_HORDE_FACILITATOR_URL") | ||
| COMPUTE_HORDE_JOB_DOCKER_IMAGE = os.environ.get("COMPUTE_HORDE_JOB_DOCKER_IMAGE") | ||
| COMPUTE_HORDE_JOB_NAMESPACE = os.environ.get("COMPUTE_HORDE_JOB_NAMESPACE") | ||
| COMPUTE_HORDE_JOB_TIMEOUT = int(os.environ.get("COMPUTE_HORDE_JOB_TIMEOUT", 10 * 60)) | ||
|
|
||
| COMPUTE_HORDE_VOLUME_MINER_STATE_DIR = "/volume/miner_state" | ||
| COMPUTE_HORDE_VOLUME_MINER_STATE_FILENAME = "miner_state.pkl" | ||
| COMPUTE_HORDE_VOLUME_MINER_STATE_PATH = os.path.join( | ||
| COMPUTE_HORDE_VOLUME_MINER_STATE_DIR, COMPUTE_HORDE_VOLUME_MINER_STATE_FILENAME | ||
| ) | ||
| COMPUTE_HORDE_VOLUME_TASK_REPO_DIR = "/volume/task_repo" | ||
| COMPUTE_HORDE_VOLUME_TASK_REPO_FILENAME = "task_repo.pkl" | ||
| COMPUTE_HORDE_VOLUME_TASK_REPO_PATH = os.path.join( | ||
| COMPUTE_HORDE_VOLUME_TASK_REPO_DIR, COMPUTE_HORDE_VOLUME_TASK_REPO_FILENAME | ||
| ) | ||
| COMPUTE_HORDE_VOLUME_MODEL_PATH = "/volume/model" | ||
| COMPUTE_HORDE_ARTIFACTS_DIR = "/artifacts" | ||
| COMPUTE_HORDE_ARTIFACT_OUTPUT_PATH = os.path.join( | ||
| COMPUTE_HORDE_ARTIFACTS_DIR, "output.pkl" | ||
| ) |
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes seem unnecessary? it's reducing code lines but obfuscating the log (i.e., unable to tease out if missing or a mismatch)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it this way so that it's possible to do some of the checks before we have the model hash or miner coldkey from docker (to avoid downloading the model here and in compute horde later too, like in my other comment). I changed the caller code to account for that: https://github.com/deval-core/De-Val/pull/68/files/6e8da07badffeac501b426c2f19285ff18af1f5d#diff-274d3bc59fd308b41d1dcd439b1385875eb9dbf11c1dfe915c3f596c3907cb15R185-R192
but if you'd like it to be done in a different way I'll see what I can do