bittensor.utils.registration#

Submodules#

Attributes#

Classes#

LazyLoadedTorch

A lazy-loading proxy for the torch module.

POWSolution

A solution to the registration PoW problem.

Functions#

create_pow(subtensor, wallet, netuid[, ...])

Creates a proof of work for the given subtensor and wallet.

create_pow_async(subtensor, wallet, netuid[, ...])

Creates a proof of work for the given subtensor and wallet.

legacy_torch_api_compat(func)

Convert function operating on numpy Input&Output to legacy torch Input&Output API if use_torch() is True.

log_no_torch_error()

use_torch()

Force the use of torch over numpy for certain operations.

Package Contents#

class bittensor.utils.registration.LazyLoadedTorch#

A lazy-loading proxy for the torch module.

__bool__()#
__getattr__(name)#
class bittensor.utils.registration.POWSolution#

A solution to the registration PoW problem.

block_number: int#
difficulty: int#
is_stale(subtensor)#

Synchronous implementation. Returns True if the POW is stale.

This means the block the POW is solved for is within 3 blocks of the current block.

Parameters:

subtensor (bittensor.core.subtensor.Subtensor)

Return type:

bool

async is_stale_async(subtensor)#

Asynchronous implementation. Returns True if the POW is stale.

This means the block the POW is solved for is within 3 blocks of the current block.

Parameters:

subtensor (bittensor.core.async_subtensor.AsyncSubtensor)

Return type:

bool

nonce: int#
seal: bytes#
bittensor.utils.registration.create_pow(subtensor, wallet, netuid, output_in_place=True, cuda=False, dev_id=0, tpb=256, num_processes=None, update_interval=None, log_verbose=False)#

Creates a proof of work for the given subtensor and wallet.

Parameters:
  • subtensor (bittensor.core.subtensor.Subtensor) – The subtensor to create a proof of work for.

  • wallet (bittensor_wallet.Wallet) – The wallet to create a proof of work for.

  • netuid (int) – The netuid for the subnet to create a proof of work for.

  • output_in_place (bool) – If true, prints the progress of the proof of work to the console in-place. Meaning the progress is printed on the same lines. Default is True.

  • cuda (bool) – If true, uses CUDA to solve the proof of work. Default is False.

  • dev_id (Union[List[int], int]) – The CUDA device id(s) to use. If cuda is true and dev_id is a list, then multiple CUDA devices will be used to solve the proof of work. Default is 0.

  • tpb (int) – The number of threads per block to use when solving the proof of work. Should be a multiple of 32. Default is 256.

  • num_processes (Optional[int]) – The number of processes to use when solving the proof of work. If None, then the number of processes is equal to the number of CPU cores. Default is None.

  • update_interval (Optional[int]) – The number of nonces to run before checking for a new block. Default is None.

  • log_verbose (bool) – If true, prints the progress of the proof of work more verbosely. Default is False.

Returns:

The proof of work solution or None if the wallet is already registered or there is a different error.

Return type:

Optional[Dict[str, Any]]

Raises:

ValueError – If the subnet does not exist.

async bittensor.utils.registration.create_pow_async(subtensor, wallet, netuid, output_in_place=True, cuda=False, dev_id=0, tpb=256, num_processes=None, update_interval=None, log_verbose=False)#

Creates a proof of work for the given subtensor and wallet.

Parameters:
  • subtensor (bittensor.core.async_subtensor.AsyncSubtensor) – The subtensor object to use to get the block number, difficulty, and block hash.

  • wallet (bittensor_wallet.Wallet) – The wallet to create a proof of work for.

  • netuid (int) – The netuid for the subnet to create a proof of work for.

  • output_in_place (bool) – If true, prints the progress of the proof of work to the console in-place. Meaning the progress is printed on the same lines.

  • cuda (bool) – If true, uses CUDA to solve the proof of work.

  • dev_id (Union[list[int], int]) – The CUDA device id(s) to use. If cuda is true and dev_id is a list, then multiple CUDA devices will be used to solve the proof of work.

  • tpb (int) – The number of threads per block to use when solving the proof of work. Should be a multiple of 32.

  • num_processes (int) – The number of processes to use when solving the proof of work. If None, then the number of processes is equal to the number of CPU cores.

  • update_interval (int) – The number of nonces to run before checking for a new block.

  • log_verbose (bool) – If true, prints the progress of the proof of work more verbosely.

Returns:

The proof of work solution or None if the wallet is already registered or there is a different error.

Raises:

ValueError – If the subnet does not exist.

Return type:

bittensor.utils.registration.POWSolution

bittensor.utils.registration.legacy_torch_api_compat(func)#

Convert function operating on numpy Input&Output to legacy torch Input&Output API if use_torch() is True.

Parameters:

func (function) – Function with numpy Input/Output to be decorated.

Returns:

Decorated function.

Return type:

decorated (function)

bittensor.utils.registration.log_no_torch_error()#
bittensor.utils.registration.torch#
bittensor.utils.registration.use_torch()#

Force the use of torch over numpy for certain operations.

Return type:

bool