bittensor.utils.weight_utils#
Conversion for weight between chain representation and np.array or torch.Tensor
Attributes#
Functions#
|
Normalizes the tensor x so that sum(x) = 1 and the max value is not greater than the limit. |
|
Converts weights and uids from chain representation into a np.array (inverse operation from convert_weights_and_uids_for_emit) |
|
Converts root weights and uids from chain representation into a np.array or torch FloatTensor (inverse operation from convert_weights_and_uids_for_emit) |
|
Converts bond and uids from chain representation into a np.array. |
|
Converts weights into integer u32 representation that sum to MAX_INT_WEIGHT. |
|
|
|
Generate a valid commit hash from the provided weights. |
Module Contents#
- bittensor.utils.weight_utils.U32_MAX = 4294967295#
- bittensor.utils.weight_utils.U16_MAX = 65535#
- bittensor.utils.weight_utils.normalize_max_weight(x, limit=0.1)[source]#
Normalizes the tensor x so that sum(x) = 1 and the max value is not greater than the limit. :param x: Tensor to be max_value normalized. :type x:
np.float32
:param limit: float:Max value after normalization.
- Returns:
Normalized x tensor.
- Return type:
y (
np.float32
)- Parameters:
x (Union[numpy.typing.NDArray[numpy.float32], bittensor.utils.registration.torch.FloatTensor])
limit (float)
- bittensor.utils.weight_utils.convert_weight_uids_and_vals_to_tensor(n, uids, weights)[source]#
Converts weights and uids from chain representation into a np.array (inverse operation from convert_weights_and_uids_for_emit) :param n: int:
number of neurons on network.
- Parameters:
uids (
List[int],
) – Tensor of uids as destinations for passed weights.weights (
List[int],
) – Tensor of weights.n (int)
- Returns:
Converted row weights.
- Return type:
row_weights ( np.float32 or torch.FloatTensor )
- bittensor.utils.weight_utils.convert_root_weight_uids_and_vals_to_tensor(n, uids, weights, subnets)[source]#
Converts root weights and uids from chain representation into a np.array or torch FloatTensor (inverse operation from convert_weights_and_uids_for_emit) :param n: int:
number of neurons on network.
- Parameters:
uids (
List[int],
) – Tensor of uids as destinations for passed weights.weights (
List[int],
) – Tensor of weights.subnets (
List[int],
) – list of subnets on the networkn (int)
- Returns:
Converted row weights.
- Return type:
row_weights ( np.float32 )
- bittensor.utils.weight_utils.convert_bond_uids_and_vals_to_tensor(n, uids, bonds)[source]#
Converts bond and uids from chain representation into a np.array. :param n: int:
number of neurons on network.
- Parameters:
uids (
List[int],
) – Tensor of uids as destinations for passed bonds.bonds (
List[int],
) – Tensor of bonds.n (int)
- Returns:
Converted row bonds.
- Return type:
row_bonds ( np.float32 )
- bittensor.utils.weight_utils.convert_weights_and_uids_for_emit(uids, weights)[source]#
Converts weights into integer u32 representation that sum to MAX_INT_WEIGHT. :param uids: Tensor of uids as destinations for passed weights. :type uids:
np.int64,
:param weights: Tensor of weights. :type weights:np.float32,
- Returns:
Uids as a list. weight_vals (List[int]):
Weights as a list.
- Return type:
weight_uids (List[int])
- Parameters:
uids (Union[numpy.typing.NDArray[numpy.int64], bittensor.utils.registration.torch.LongTensor])
weights (Union[numpy.typing.NDArray[numpy.float32], bittensor.utils.registration.torch.FloatTensor])
- bittensor.utils.weight_utils.process_weights_for_netuid(uids, weights, netuid, subtensor, metagraph=None, exclude_quantile=0)[source]#
- Parameters:
- Return type:
Union[Tuple[bittensor.utils.registration.torch.Tensor, bittensor.utils.registration.torch.FloatTensor], Tuple[numpy.typing.NDArray[numpy.int64], numpy.typing.NDArray[numpy.float32]]]