Skip to main content

Proof of Training SDK for submitting and verifying model training metadata on blockchain.

Project description

ProofOfTraining Python SDK

The ProofOfTraining Python SDK provides a convenient way to interact with the ProofOfTraining smart contract on the blockchain network. It allows you to submit and retrieve model metadata using the ProofOfTraining protocol.

Installation

To install the ProofOfTraining Python SDK, use the following command:

pip install proof-of-training

Usage

Initializing the ProofOfTraining object

To start using the ProofOfTraining SDK, you need to create an instance of the ProofOfTrain class by providing the following parameters:

  • rpc_url: The RPC URL of the blockchain network to connect for submitting and verifying metadata.
  • public_key: The public key of the user, used to identify the sender of the transactions.
  • private_key: The private key of the user, used for signing transactions to ensure security and authenticity.
from proof_of_training import ProofOfTraining

rpc_url = "https://rpc.testnet.rss3.io"
public_key = "0x1234567890123456789012345678901234567890"
private_key = "your-private-key"

pot = ProofOfTraining(rpc_url, public_key, private_key)

Submitting Model Metadata

To submit model metadata to the blockchain, use the submit_proof method of the ProofOfTrain object. This method takes the following parameters:

  • model_id: The unique identifier of the model.
  • metadata: An instance of ModelMetadata containing the model's metadata.
  • gas (optional): The gas limit for the transaction (default: 500000).
  • gas_price (optional): The gas price in gwei (default: 50).
  • wait_for_receipt (optional): Whether to wait for the transaction to be confirmed (default: False).
from proof_of_training import ModelMetadata

model_id = "your-model-id"
metadata = ModelMetadata(
    model_name="Model Name",
    model_md5="d4c2e8a2b3cb1a9c0a7b7f4c5a9a3b2e",
    model_url="https://huggingface.co/bert-base-uncased",
    dataset_url="https://huggingface.co/datasets/glue",
    training_params={"epochs": 3, "batch_size": 32},
    training_date="2024-05-27",
    model_version="1.0",
    author="Hugging Face",
    description="BERT base model, uncased version, trained on the GLUE dataset."
)

tx_hash = pot.submit_proof(model_id, metadata, wait_for_receipt=False)
print(f"Transaction hash: {tx_hash}")

If wait_for_receipt is set to False (which is the default), the submit_proof method will return the transaction hash. You can use this hash to track the status of the transaction later.

If wait_for_receipt is set to True, the method will wait for the transaction to be confirmed on the blockchain and return the transaction receipt.

tx_receipt = pot.submit_proof(model_id, metadata, wait_for_receipt=True)
print(f"Transaction receipt: {tx_receipt}")

Retrieving Model Metadata

To retrieve the metadata for a specific model from the blockchain, use the get_proof method of the ProofOfTrain object. This method takes the model_id parameter, which is the unique identifier of the model.

model_id = "your-model-id"
metadata = pot.get_proof(model_id)

if metadata:
    print(f"Model ID: {model_id}")
    print(f"Model Name: {metadata.model_name}")
    print(f"Model MD5: {metadata.model_md5}")
    print(f"Model URL: {metadata.model_url}")
    print(f"Dataset URL: {metadata.dataset_url}")
    print(f"Training Params: {metadata.training_params}")
    print(f"Training Date: {metadata.training_date}")
    print(f"Model Version: {metadata.model_version}")
    print(f"Author: {metadata.author}")
    print(f"Description: {metadata.description}")
else:
    print(f"Model with ID {model_id} not found.")

Error Handling

The SDK handles common errors that may occur during the interaction with the blockchain network. If an error occurs, an appropriate exception will be raised with a descriptive error message.

License

This SDK is released under the MIT License.

Contributing

Contributions to the ProofOfTraining Python SDK are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proof_of_training-0.7.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

proof_of_training-0.7.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file proof_of_training-0.7.0.tar.gz.

File metadata

  • Download URL: proof_of_training-0.7.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/22.4.0

File hashes

Hashes for proof_of_training-0.7.0.tar.gz
Algorithm Hash digest
SHA256 0de6950c7987b41a4b715437cdb3f8a4b97d96184221486ea5fda2cd87a1915c
MD5 d954c68a3f0c89378d65f6c20b478e15
BLAKE2b-256 cb343ed81c4df2eaa2b72fba7d331c8637c506c4f8665a310cc542649a0c7dbb

See more details on using hashes here.

File details

Details for the file proof_of_training-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for proof_of_training-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f2d22cc77f7ff090138f79f621c348f2389c054537333afbba15e66b4f7aee0
MD5 6157fdf78350524d37d080c07e83e2e1
BLAKE2b-256 1cc9faafb0022ded50a0c91b69ee32a2b8b62cb6f12edb9447b40395176b1a1c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page