Model Validators (Peers)

Main logic for interfacing model validators (peers) hosting machine learning models

Outline


Add Model Peer

Once the user has begun running their node within the AI Model Hosting network, a peer_id will be returned. Once returned, users can then store their peer data on the blockchain to begin accruing rewards.

pub fn add_model_peer(
    origin: OriginFor<T>, 
    model_id: u32, 
    peer_id: PeerId, 
    ip: Vec<u8>,
    port: u16,
    stake_to_be_added: u128
) -> DispatchResult

Parameters

  • model_id: The key of the model. This can be found through querying ModelPaths using the model path.

  • peer_id: The ID of the peer running a node to host a model. This is returned when a peer is successfully added.

    • The peer_id must abide by the following possible formats

      • The peer_id must be between 32 and 128 characters.

      • Starting with a Qm - Peer ID (sha256) encoded as a raw base58btc multihash.

      • Starting with a 1 - Peer ID (ed25519, using the "identity" multihash) encoded as a raw base58btc multihash.

      • Starting with a e or b or z or m - Peer ID (sha256) encoded as a CID.

  • ip: The IP address of the server.

    • This is required to call the network to ensure the machine-learning model is being hosted.

    • If a call to the peer IP address is unsuccessful it will incrementally increase the account's peer error count.

    • If an account peer has surpassed the maximum allowed errors, they risk being removed as a model peer across all models they host on the blockchain.

  • port: The port of the server a peer is required to have open for socket calls. This is used alongside the IP.

  • stake_to_be_added: The balance to stake towards a specific model.

    • There is a minimum required stake balance per peer.

Storage

Information

  • Each model validator must stake a minimum required balance towards the model they are hosting up to the maximum model peer stake balance.

  • Each account can host one peer per model.

  • If removed by either consensus or self, the stake balance will not be available for removal until enough epochs have passed based on MinRequiredUnstakeEpochs. This is also applied to re-adding a model peer after removing themselves through remove_model_peer(). If an account removes its model peer, it must wait for the MinRequiredUnstakeEpochs to re-add a model peer.

  • The account must not surpass the MaxAccountPenaltyCount.

Note

  • When adding your model peer manually or through the CLI, anyone can claim your peer_id. When performing the transaction to store your model peer on the blockchain, ensure it's successful. In case it isn't successful, try again or check if the peer_id is already in use. If it is already in use, remove your node from the DHT, re-add a new node to host the model to get a new peer_id, and try again.


Update Model Peer

A peer can update their peer_id if they're able to submit consensus. This is primarily meant for updating the peer_id if a model peer's hosting model goes down and the node needs to be restarted under a new peer_id.

pub fn update_model_peer(
    origin: OriginFor<T>, 
    model_id: u32, 
    peer_id: PeerId,
) -> DispatchResult

Parameters

  • model_id: The key of the model. This can be found through querying ModelPaths using the model path.

  • peer_id: The ID of the peer running a node to host a model. This is returned when a peer is successfully added.

    • The peer_id must abide by the following possible formats

      • The peer_id must be between 32 and 128 characters.

      • Starting with a Qm - Peer ID (sha256) encoded as a raw base58btc multihash.

      • Starting with a 1 - Peer ID (ed25519, using the "identity" multihash) encoded as a raw base58btc multihash.

      • Starting with a e or b or z or m - Peer ID (sha256) encoded as a CID.

Storage

Information

  • Peers must be able to submit consensus, otherwise, they should remove the peer and add a new peer.


Remove Model Peer

A peer can remove their blockchain-registered model peer. Once removed, users can remove their stake towards that model or up to their minimum required balance. Once removed, they can unstake their stake balance towards that model after the required epochs have passed based on MinRequiredUnstakeEpochs.

pub fn remove_model_peer(
    origin: OriginFor<T>, 
    model_id: u32, 
) -> DispatchResult

Parameters

Information

  • If a model peer reaches its consensus inclusion epoch, they can only remove themselves during the span of blocks at the beginning of an epoch following the consensus steps, represented as a percent based on RemoveModelPeerEpochPercentage.

    • If a model peer is added and hasn't reached their consensus inclusion epoch, they can remove themselves freely.

  • Removing stake balance towards a model must be done separately through the remove_stake() function.

  • When removing a server from contributing to hosting an AI model, it is important to remove the model peer from the blockchain's storage using remove_model_peer().

    • By not removing the model peer, there is a risk of the accounts penalty count increasing due to not being in consensus and will increase the AccountPenaltyCount.


Update Port

pub fn update_port(
    origin: OriginFor<T>, 
    model_path: Vec<u8>, 
    port: u16,
) -> DispatchResult

Parameters

  • model_path: The path of the open-sourced hugging face model.

  • port: The port of the server that is required to be open for socket calls of the peer hosting the model.

Last updated