masa-finance / masa-bittensor

Bittensor Subnet Config
https://masa.ai
MIT License
0 stars 0 forks source link

Modularization of Miner/Validators tasks #71

Closed juanmanso closed 3 weeks ago

juanmanso commented 3 weeks ago

Refactor: Modularisation of tasks

Problem

Scaling more endpoints will make code complex, before we add more endpoints we will need to refactor this.

🎯 Goal

As we grow the codebase of the masa-bittensor repo, we write this RFC to document and open the conversation on the problematic that rose while integrating the Discord Profile and Web Scraper tasks to the Subnet.

🥅 What we want to achieve


🪨 Current state

Highest level

The repo has two main folders:

neurons implement the Miner and Validator classes which extended our masa custom implementation for usage. These are our entry point scripts for them to run.

Masa's Subnet Logic

Inside masa folder we can find most importatly:

⚠️ Problem

Everytime we want to add a new task, we need to:

Additionally, since the forwarder class is pretty much fixed in the steps it follows, custom behavior for each task is hard to achieve


🔬 Proposed solution

TL;DR:

juanmanso commented 3 weeks ago

First version of RFC is ready for comments:

TL;DR of proposal:

- services folder
    - has 1 request class per external service to the network
- utils folder
    - generic and deterministic uid fetchers (i.e. get_random_uids)
- api
    - validator_api which sets route and imports function to run upon request (from task)
- base
    - shared methods and attributes across neurons, miners and validators
        - Neuron's state management
        - Neuron's metagraph management
        - Validator's update weights logic
        - etc.
- Neurons
    - miner entry point for users that want to run miner node
    - validator entry point for users that want to run a validator node
- tasks folder (with subfolders, 1 for each):
    - Custom Synapse object → `protocol.py`
    - Custom types for the whole process (responses, query, etc.) → `types.py`
    - Miner logic → `miner.py`
        - Extends whichever Request class it needs (1 Request Class per External Service)
        - Process that request as required by task:
            - Extra calculations
            - Format to match Synapse response
    - Validator logic → `validator.py`
        - def forward()
            - Which miners (uids) to query based on its task
            - Perform synapse to miners
            - Handle responses
            - Score responses and update uid scores
            - Return actual respond to user
        - def reward()
            - how validate and score responses
        - def generate_response()
            - Based on responses and scores, generate final output for user
juanmanso commented 3 weeks ago

Moving it to review and getting to tinker the approach to share some snippets/env for review if that's eventually needed

juanmanso commented 3 weeks ago

Refactor: Modularisation of tasks

🎯 Goal

As we grow the codebase of the masa-bittensor repo, we write this RFC to document and open the conversation on the problematic that rose while integrating the Discord Profile and Web Scraper tasks to the Subnet.

🥅 What we want to achieve


🪨 Current state

Highest level

The repo has two main folders:

neurons implement the Miner and Validator classes which extended our masa custom implementation for usage. These are our entry point scripts for them to run.

Masa's Subnet Logic

Inside masa folder we can find most importatly:

⚠️ Problem

Everytime we want to add a new task, we need to:

Additionally, since the forwarder class is pretty much fixed in the steps it follows, custom behavior for each task is hard to achieve


🔬 Proposed solution

TL;DR:

juanmanso commented 3 weeks ago

Update on the code spike: https://masafinance.slack.com/archives/C0742F6KXB8/p1718194559616379

juanmanso commented 3 weeks ago

Closed since follow-up actions (issues) are defined and created.

Next step is set on masa-finance/bt-refactor-spike#1