{"id":13706148,"url":"https://github.com/neuralinternet/ni-compute","last_synced_at":"2025-05-05T20:30:27.643Z","repository":{"id":207634690,"uuid":"703538575","full_name":"neuralinternet/ni-compute","owner":"neuralinternet","description":"governed by techno optimists—building the compute layer for decentralized artificial intelligence | powered by $NI","archived":false,"fork":false,"pushed_at":"2025-02-26T19:58:52.000Z","size":53125,"stargazers_count":59,"open_issues_count":6,"forks_count":41,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-02-26T20:22:36.935Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.neuralinternet.ai","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neuralinternet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-11T12:35:20.000Z","updated_at":"2025-02-26T18:20:14.000Z","dependencies_parsed_at":"2025-02-26T20:22:45.178Z","dependency_job_id":null,"html_url":"https://github.com/neuralinternet/ni-compute","commit_stats":null,"previous_names":["neuralinternet/compute-subnet","neuralinternet/nicompute-subnet","neuralinternet/nicompute","neuralinternet/ni-compute"],"tags_count":15,"template":false,"template_full_name":"opentensor/bittensor-subnet-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuralinternet%2Fni-compute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuralinternet%2Fni-compute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuralinternet%2Fni-compute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuralinternet%2Fni-compute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neuralinternet","download_url":"https://codeload.github.com/neuralinternet/ni-compute/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252570823,"owners_count":21769728,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T22:00:52.575Z","updated_at":"2025-05-05T20:30:22.626Z","avatar_url":"https://github.com/neuralinternet.png","language":"Python","funding_links":[],"categories":["Registered Subnets"],"sub_categories":[],"readme":"# Compute Subnet\n\n[![Discord Chat](https://img.shields.io/discord/308323056592486420.svg)](https://discord.gg/bittensor)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n---\n\n### The Incentivized Internet\n\n[Discord](https://discord.gg/bittensor) • [Network](https://taostats.io/) • [Research](https://bittensor.com/whitepaper)\n\nThis repository contains all the necessary files and functions to define Bittensor's Compute Subnet. It enables running miners on netuid 15 in Bittensor's test network or netuid 27 in Bittensor's main network.\n\n## Introduction\n\nThis repository serves as a compute-composable subnet, integrating various cloud platforms (e.g., Runpod, Lambda, AWS) into a cohesive unit. Its purpose is to enable higher-level cloud platforms to offer seamless compute composability across different underlying platforms. With the proliferation of cloud platforms, there's a growing need for a subnet that can seamlessly integrate these platforms, allowing efficient resource sharing and allocation. This compute-composable subnet empowers nodes to contribute computational power, with validators ensuring the integrity and efficiency of the shared resources.\n\n### File Structure\n\n- `compute/protocol.py`: Defines the wire-protocol used by miners and validators.\n- `neurons/miner.py`: Defines the miner's behavior in responding to requests from validators.\n- `neurons/validator.py`: Defines the validator's behavior in requesting information from miners and determining scores.\n\n## Installation\n\nThis repository requires python3.8 or higher. To install, simply clone this repository and install the requirements. You are limited to one external IP per UID. There is automatic blacklisting in place if validators detect anomalous behavior. \n\n### Bittensor\n\n```bash\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/opentensor/bittensor/master/scripts/install.sh)\"\n```\n\n## Dependencies - Validators / Miners\n\n```bash\ngit clone https://github.com/neuralinternet/Compute-Subnet.git\ncd Compute-Subnet\npython3 -m pip install -r requirements.txt\npython3 -m pip install -e .\n```\n\n## Extra dependencies - Miners\n\n### Hashcat\n\n```bash\n# Minimal hashcat version \u003e= v6.2.6\nwget https://hashcat.net/files/hashcat-6.2.6.tar.gz\ntar xzvf hashcat-6.2.6.tar.gz\ncd hashcat-6.2.6/\nmake\nmake install  # prefixed by sudo if not in the sudoers\nhashcat --version\n```\n\n### Cuda\n\n```bash\n# Recommended cuda version: 12.3\nwget https://developer.download.nvidia.com/compute/cuda/12.3.1/local_installers/cuda-repo-ubuntu2204-12-3-local_12.3.1-545.23.08-1_amd64.deb\ndpkg -i cuda-repo-ubuntu2204-12-3-local_12.3.1-545.23.08-1_amd64.deb\ncp /var/cuda-repo-ubuntu2204-12-3-local/cuda-*-keyring.gpg /usr/share/keyrings/\napt-get update\napt-get -y install cuda-toolkit-12-3\napt-get -y install -y cuda-drivers\n\n# Valid for x64 architecture. Consult nvidia documentation for any other architecture.\nexport CUDA_VERSION=cuda-12.3\nexport PATH=$PATH:/usr/local/$CUDA_VERSION/bin\nexport LD_LIBRARY_PATH=/usr/local/$CUDA_VERSION/lib64\n\necho \"\"\u003e\u003e~/.bashrc\necho \"PATH=$PATH\"\u003e\u003e~/.bashrc\necho \"LD_LIBRARY_PATH=$LD_LIBRARY_PATH\"\u003e\u003e~/.bashrc\n\nreboot  # Changes might need a restart depending on the system\n\nnvidia-smi\nnvcc --version\n\n# Version should match\n```\n\n### Docker\n\nTo run a miner, you must [install](https://docs.docker.com/engine/install/ubuntu) and start the docker service.\n\n```bash\nsudo apt install docker.io -y\nsudo apt install docker-compose -y\nsudo systemctl start docker\nsudo apt install at\ndocker run hello-world  # Must not return you any error.\n```\n\nTo run a docker container for allocation, user must be added to docker group to run without sudo command.\n\n```bash\nsudo groupadd docker\nsudo usermod -aG docker $USER\nsudo systemctl restart docker\n```\n\n### Nvidia toolkit\n\nTo run a container for allocation, nvidia toolkit for docker needs to be installed.\n\n```bash\nsudo apt-get install -y nvidia-container-toolkit\nsudo apt install -y nvidia-docker2\n```\n\n### WanDB\n\nTo log into the wandb project named opencompute from neuralinternet, miners and validators need a wandb API key.\nRename the `.env.example` file to `.env` and replace the placeholder with your actual API key.\n\n### Running subtensor locally\n\n```bash\ngit clone https://github.com/opentensor/subtensor.git\ncd subtensor\ndocker-compose up --detach\n```\n\nIf you have more complicated needs, see the [subtensor](https://github.com/opentensor/subtensor/) repo for more details and understanding.\n\n\n---\n\n# Running a Miner / Validator\n\nPrior to running a miner or validator, you must [create a wallet](https://github.com/opentensor/docs/blob/main/reference/btcli.md)\nand [register the wallet to a netuid](https://github.com/opentensor/docs/blob/main/subnetworks/registration.md). \nOnce you have done so, you can run the miner and validator with the following commands.\n\n## Running Miner\n\nA dedicated medium article is available [here](https://medium.com/@neuralinternet/how-to-run-a-compute-miner-82498b93e7e1)\n\nMiners contribute processing resources, notably GPU (Graphics Processing Unit) and CPU (Central Processing Unit)\ninstances, to facilitate optimal performance in essential GPU and CPU-based computing tasks. The system operates on a\nperformance-based reward mechanism, where miners are incentivized through a tiered reward structure correlated to the\nprocessing capability of their hardware. High-performance devices are eligible for increased compensation, reflecting\ntheir greater contribution to the network's computational throughput. Emphasizing the integration of GPU instances is\ncritical due to their superior computational power, particularly in tasks demanding parallel processing capabilities.\nConsequently, miners utilizing GPU instances are positioned to receive substantially higher rewards compared to their\nCPU counterparts, in alignment with the greater processing power and efficiency GPUs bring to the network.\n\nThe primary contribution of miners lies in providing their resources to the validator. The management of these resources' \nreservations is entirely handled on the validator's side. A validator has the capability to allocate and deallocate a miner's \nresource based on availability and demand. Currently, the maximum duration of allocation for each reservation is limited to 60 days. \nThis mechanism guarantees a dynamic and efficient distribution of computational power, accommodating the fluctuating demands across the network.\n\nImportant: It's crucial to ensure that port 4444 is open on the host machine to grant validators access to the allocated resource on the miner.\n\n\n```bash\n# To run the miner\ncd neurons\npython -m miner.py \n    --netuid \u003cyour netuid\u003e  # The subnet id you want to connect to\n    --subtensor.network \u003cyour chain url\u003e  # blockchain endpoint you want to connect\n    --wallet.name \u003cyour miner wallet\u003e # name of your wallet\n    --wallet.hotkey \u003cyour miner hotkey\u003e # hotkey name of your wallet\n    --logging.debug # Run in debug mode, alternatively --logging.trace for trace mode\n```\n\n## Running Validator\n\nValidators hold the critical responsibility of rigorously assessing and verifying the computational capabilities of\nminers. This multifaceted evaluation process commences with validators requesting miners to provide comprehensive\nperformance data, which includes not only processing speeds and efficiencies but also critical metrics like Random\nAccess Memory (RAM) capacity and disk space availability.\n\nThe inclusion of RAM and disk space measurements is vital, as these components significantly impact the overall\nperformance and reliability of the miners' hardware. RAM capacity influences the ability to handle large or multiple\ntasks simultaneously, while adequate disk space ensures sufficient storage.\n\nFollowing the receipt of this detailed hardware and performance information, validators proceed to test the miners'\ncomputational integrity. This is achieved by presenting them with complex hashing challenges, designed to evaluate the\nprocessing power and reliability of the miners' systems. Validators adjust the difficulty of these problems based on the\ncomprehensive performance profile of each miner, including their RAM and disk space metrics.\n\nIn addition to measuring the time taken by miners to resolve these problems, validators meticulously verify the accuracy\nof the responses. This thorough examination of both speed and precision, complemented by the assessment of RAM and disk\nspace utilization, forms the crux of the evaluation process.\n\nBased on this extensive analysis, validators update the miners' scores, reflecting a holistic view of their\ncomputational capacity, efficiency, and hardware quality. This score then determines the miner's weight within the\nnetwork, directly influencing their potential rewards and standing.\nThis scoring process, implemented through a Python script, considers various factors including CPU, GPU, hard disk, and\nRAM performance. The script's structure and logic are outlined below:\n\n## Understanding the Score Calculation Process\n\n**The scoring system has been updated, if you want to check the old hardware mechanism:** [Hardware scoring](docs/hardware_scoring.md)\n\nThe score calculation function determines a miner's performance based on various factors:\n\n**Successful Problem Resolution**: The success rate of solving challenges in the last 24 hours. Score range: (0,100).\n\n**Problem Difficulty**: This measures the complexity of the solved tasks. The code restricts this difficulty to a minimum and maximum allowed value. Score range: (0,100).\n\n**Elapsed Time**: The time taken to solve the problem impacts the score. A shorter time results in a higher score. Score range: (0,100).\n\n**Failure Penalty**: The failure rate of solving the last 20 challenges. Score range: (0,100).\n\n**Allocation Score**: Miners that have allocated machine resources receive the maximum challenge score and an additional allocation score, which is proportional to their average challenge difficulty. Score range: (0,100).\n\n**Scoring Weights**: Each score component is weighted with the corresponding weight before being added to the total score.\n\n- Successful Problem Resolution Weight = 1.0\n- Problem Difficulty Weight = 1.0\n- Elapsed Time Weight = 0.5\n- Failure Penalty Weight = 0.5\n- Allocation Weight = 0.4\n\n**Total Score**:\n\n- Score (not allocated) = (Successful Problem Resolution * Resolution Weight) + (Problem Difficulty * Difficulty Weight) + (Elapsed Time * Time Weight) - (Failure Penalty * Penalty Weight)\n- Score (allocated) = Maximum Challenge Score + (Allocation Score * Allocation Weight)\n\n### Example 1: Miner A's Weighted Total Score\n\n- **Successful Problem Resolution**: 95%\n- **Problem Difficulty**: 7\n- **Elapsed Time**: 4.6 seconds\n- **Failure Penalty**: 2.6%\n- **Allocation**: True\n\nTotal Score = Score (allocated) = 264.6\n\n### Example 2: Miner B's Weighted Total Score\n\n- **Successful Problem Resolution**: 92%\n- **Problem Difficulty**: 9\n- **Elapsed Time**: 16 seconds\n- **Failure Penalty**: 3.1%\n- **Allocation**: False\n\nTotal Score = Score (not allocated) = 193.7\n\n```bash\n# To run the validator\ncd neurons\npython -m validator.py \n    --netuid \u003cyour netuid\u003e # The subnet id you want to connect to\n    --subtensor.network \u003cyour chain url\u003e # blockchain endpoint you want to connect\n    --wallet.name \u003cyour validator wallet\u003e  # name of your wallet\n    --wallet.hotkey \u003cyour validator hotkey\u003e # hotkey name of your wallet\n    --logging.debug # Run in debug mode, alternatively --logging.trace for trace mode\n```\n\n## Resource Allocation Mechanism\n\nThe allocation mechanism within subnet 27 is designed to optimize the utilization of computational resources\neffectively. Key aspects of this mechanism include:\n\n1. **Resource Requirement Analysis:** The mechanism begins by analyzing the specific resource requirements of each task,\n   including CPU, GPU, memory, and storage needs.\n\n2. **Miner Selection:** Based on the analysis, the mechanism selects suitable miners that meet the resource\n   requirements. This selection process considers the current availability, performance history, and network weights of\n   the miners.\n\n3. **Dynamic Allocation:** The allocation of tasks to miners is dynamic, allowing for real-time adjustments based on\n   changing network conditions and miner performance.\n\n4. **Efficiency Optimization:** The mechanism aims to maximize network efficiency by matching the most suitable miners\n   to each task, ensuring optimal use of the network's computational power.\n\n5. **Load Balancing:** It also incorporates load balancing strategies to prevent overburdening individual miners,\n   thereby maintaining a healthy and sustainable network ecosystem.\n\nThrough these functionalities, the allocation mechanism ensures that computational resources are utilized efficiently\nand effectively, contributing to the overall robustness and performance of the network.\n\nValidators can send requests to reserve access to resources from miners by specifying the specs manually in the\nin `register.py` and running this script: https://github.com/neuralinternet/Compute-Subnet/blob/main/neurons/register.py\nfor example:\n```{'cpu':{'count':1}, 'gpu':{'count':1}, 'hard_disk':{'capacity':10737418240}, 'ram':{'capacity':1073741824}}```\n\n## Options\n\nAll the list arguments are now using coma separator.\n\n- `--netuid`: (Optional) The chain subnet uid. Default: 27.\n- `--auto_update`: (Optional) Auto update the repository. Default: True.\n- `--blacklist.exploiters`: (Optional) Automatically use the list of internal exploiters hotkeys. Default: True.\n- `--blacklist.hotkeys \u003chotkey_0,hotkey_1,...\u003e`: (Optional) List of hotkeys to blacklist. Default: [].\n- `--blacklist.coldkeys \u003ccoldkey_0,coldkey_1,...\u003e`: (Optional) List of coldkeys to blacklist. Default: [].\n- `--whitelist.hotkeys \u003chotkey_0,hotkey_1,...\u003e`: (Optional) List of hotkeys to whitelist. Default: [].\n- `--whitelist.coldkeys \u003ccoldkey_0,coldkey_1,...\u003e`: (Optional) List of coldkeys to whitelist. Default: [].\n\n## Validators options\n\n---\nFlags that you can use with the validator script.\n\n- `--validator.whitelist.unrecognized`: (Optional) Whitelist the unrecognized miners. Default: False.\n- `--validator.perform.hardware.query \u003cbool\u003e`: (Optional) Perform the specs query - useful to register to a miner's machine. Default: True.\n- `--validator.challenge.batch.size \u003csize\u003e`: (Optional) Batch size that perform the challenge queries - For lower hardware specifications you might want to use a different batch_size than default. Keep in mind the lower is the batch_size the longer it will take to perform all challenge queries. Default: 256.\n- `--validator.specs.batch.size \u003csize\u003e`: (Optional) Batch size that perform the specs queries - For lower hardware specifications you might want to use a different batch_size than default. Keep in mind the lower is the batch_size the longer it will take to perform all challenge queries. Default: 64.\n- `--validator.force.update.prometheus`: (Optional) Force the try-update of prometheus version. Default: False.\n- `--validator.whitelist.updated.threshold`: (Optional) Total quorum before starting the whitelist. Default: 60. (%)\n\n## Miners options\n\n---\n\n- `--miner.hashcat.path \u003cpath\u003e`: (Optional) The path of the hashcat binary. Default: hashcat.\n- `--miner.hashcat.workload.profile \u003cprofile\u003e`: (Optional) Performance to apply with hashcat profile: 1 Low, 2 Economic, 3 High, 4 Insane. Run `hashcat -h` for more information. Default: 3.\n- `--miner.hashcat.extended.options \u003coptions\u003e`: (Optional) Any extra options you found usefull to append to the hascat runner (I'd perhaps recommend -O). Run `hashcat -h` for more information. Default: ''.\n- `--miner.whitelist.not.enough.stake`: (Optional) Whitelist the validators without enough stake. Default: False.\n- `--miner.whitelist.not.updated`: (Optional) Whitelist validators not using the last version of the code. Default: False.\n- `--miner.whitelist.updated.threshold`: (Optional) Total quorum before starting the whitelist. Default: 60. (%)\n\n## Benchmarking the machine\n### Benchmarking hashcat's performance directly:\n```bash\nhashcat -b -m 610\n```\n\nOutput\n```\nSpeed.#1.........: 12576.1 MH/s (75.69ms) @ Accel:8 Loops:1024 Thr:1024 Vec:1\nSpeed.#2.........: 12576.1 MH/s (75.69ms) @ Accel:8 Loops:1024 Thr:1024 Vec:1\n...\n...\n```\n\nRecommended minimum hashrate for the current difficulty: \u003e= 3000 MH/s.\n\nDifficulty will increase over time.\n\n### Benchmarking the system using challenge emulations:\n```bash\ncd compute-subnet\npython3 ./test-scripts/benchmark.py\n```\n\n\u003e \"What challenge difficulties would you like to benchmark?\"\n\nAny positive integer or list of positive integers ranging from the minimum challenge difficulty (6) to the maximum challenge difficulty (12) can be entered. An invalid entry will default to the minimum or maximum challenge difficulty based on whichever is closer. Entering ```all``` will add 1 challenge of each available difficulty to the benchmark list.\n\nExample challenge difficulty selections:\n```bash\nExample 1: 6\nExample 2: 7 8 9\nExample 3: 10, 11, 12\nExample 4: all\n```\n\u003e \"How many benchmarks would you like to perform?\"\n\nAny positive integer \u003e 0, ```n```, can be used. This will benchmark each entered difficulty ```n``` times.\\\nExample:\n```bash\nDifficulties = [6, 7, 8]\nBenchmarks to perform = 2\nBenchmarks performed: [6, 6, 7, 7, 8, 8]\n```\n\n\u003e \"What hashcat workload profile (1, 2, 3, or 4) would you like to use?\"\n\nA workload profile from 1 to 4 can be used. An invalid or empty entry will default to workload profile 3.\n\n\u003e \"Enter any extra hashcat options to use. Leave this empty to use the recommended -O option. Enter None for no extended options.\"\n\nEnter any additional options for hashcat to use. It's recommended to use the ```-O``` option by either explicitly stating it or submitting a blank entry, which will use ```-O``` by default. Enter ```None``` to exclude all extra hashcat options. Additional options can be listed with the command ```hashcat -h```.\n\n![alt text](\u003cminer_benchmark_sample.png\u003e)\n\n## Troubleshooting\n\n\u003e \"I don't receive any request, 'Challenge' or 'Specs', what could be the reason ?\"\n\nMost probably you are running into a **network issue**. \n- check your ports \n- check your firewall\n\n\u003e \"I have been deregistered, why ?\"\n\nThere might be a thousand reason for this. Ensure your script is running correctly.\nOtherwise, the simplest answer is the following: **competition is really hard over the network**.\nMaybe people are running stronger devices than you, maybe you had internet issues, maybe you did not isolate your environment and another script that you ran broke it, etc.\n\n\n## Action todo for updates\n\n__**No action required when using auto-update flag**__.\n\n```sh\ngit pull\npython -m pip install -r requirements.txt\npython -m pip install -e .\npm2 restart \u003cid\u003e\n```\n\nException for 1.3.10:\n```sh\ngit pull\n\npython -m pip install -e .\npython -m pip install --no-deps -r requirements-compute.txt\npm2 restart \u003cid\u003e\n```\n\n## License\n\nThis repository is licensed under the MIT License.\n\n```text\n# The MIT License (MIT)\n# Copyright © 2023 Neural Internet\n\n# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n# documentation files (the “Software”), to deal in the Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,\n# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n# The above copyright notice and this permission notice shall be included in all copies or substantial portions of\n# the Software.\n\n# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO\n# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n# DEALINGS IN THE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuralinternet%2Fni-compute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuralinternet%2Fni-compute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuralinternet%2Fni-compute/lists"}