From aa3ba41142ac1fddd4d52e0dcb354b66cafd1d79 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 22 Nov 2024 17:41:52 -0800 Subject: [PATCH 1/2] Fixes logging breaking when setting weights --- bittensor/utils/btlogging/loggingmachine.py | 28 ++++++++--------- bittensor/utils/weight_utils.py | 33 ++++++++++----------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index 8b5c3faa5b..5b41b47a8a 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -443,40 +443,40 @@ def __trace_on__(self) -> bool: """ return self.current_state_value == "Trace" - def trace(self, msg="", prefix="", suffix="", *args, **kwargs): + def trace(self, msg="", prefix="", suffix="", *args): """Wraps trace message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.trace(msg, *args, **kwargs) + self._logger.trace(msg, *args) - def debug(self, msg="", prefix="", suffix="", *args, **kwargs): + def debug(self, msg="", prefix="", suffix="", *args): """Wraps debug message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.debug(msg, *args, **kwargs) + self._logger.debug(msg, *args) - def info(self, msg="", prefix="", suffix="", *args, **kwargs): + def info(self, msg="", prefix="", suffix="", *args): """Wraps info message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.info(msg, *args, **kwargs) + self._logger.info(msg, *args) - def success(self, msg="", prefix="", suffix="", *args, **kwargs): + def success(self, msg="", prefix="", suffix="", *args): """Wraps success message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.success(msg, *args, **kwargs) + self._logger.success(msg, *args) - def warning(self, msg="", prefix="", suffix="", *args, **kwargs): + def warning(self, msg="", prefix="", suffix="", *args): """Wraps warning message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.warning(msg, *args, **kwargs) + self._logger.warning(msg, *args) - def error(self, msg="", prefix="", suffix="", *args, **kwargs): + def error(self, msg="", prefix="", suffix="", *args): """Wraps error message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.error(msg, *args, **kwargs) + self._logger.error(msg, *args) - def critical(self, msg="", prefix="", suffix="", *args, **kwargs): + def critical(self, msg="", prefix="", suffix="", *args): """Wraps critical message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.critical(msg, *args, **kwargs) + self._logger.critical(msg, *args) def exception(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps exception message with prefix and suffix.""" diff --git a/bittensor/utils/weight_utils.py b/bittensor/utils/weight_utils.py index feb281a04c..dc31184476 100644 --- a/bittensor/utils/weight_utils.py +++ b/bittensor/utils/weight_utils.py @@ -18,7 +18,6 @@ """Conversion for weight between chain representation and np.array or torch.Tensor""" import hashlib -import logging import typing from typing import Union, Optional @@ -256,10 +255,10 @@ def process_weights_for_netuid( """ logging.debug("process_weights_for_netuid()") - logging.debug("weights", *weights) - logging.debug("netuid", netuid) - logging.debug("subtensor", subtensor) - logging.debug("metagraph", metagraph) + logging.debug(f"weights: {weights}") + logging.debug(f"netuid {netuid}") + logging.debug(f"subtensor: {subtensor}") + logging.debug(f"metagraph: {metagraph}") # Get latest metagraph from chain if metagraph is None. if metagraph is None: @@ -278,9 +277,9 @@ def process_weights_for_netuid( quantile = exclude_quantile / U16_MAX min_allowed_weights = subtensor.min_allowed_weights(netuid=netuid) max_weight_limit = subtensor.max_weight_limit(netuid=netuid) - logging.debug("quantile", quantile) - logging.debug("min_allowed_weights", min_allowed_weights) - logging.debug("max_weight_limit", max_weight_limit) + logging.debug(f"quantile: {quantile}") + logging.debug(f"min_allowed_weights: {min_allowed_weights}") + logging.debug(f"max_weight_limit: {max_weight_limit}") # Find all non zero weights. non_zero_weight_idx = ( @@ -298,7 +297,7 @@ def process_weights_for_netuid( if use_torch() else np.ones((metagraph.n), dtype=np.int64) / metagraph.n ) - logging.debug("final_weights", *final_weights) + logging.debug(f"final_weights: {final_weights}") final_weights_count = ( torch.tensor(list(range(len(final_weights)))) if use_torch() @@ -321,7 +320,7 @@ def process_weights_for_netuid( else np.ones((metagraph.n), dtype=np.int64) * 1e-5 ) # creating minimum even non-zero weights weights[non_zero_weight_idx] += non_zero_weights - logging.debug("final_weights", *weights) + logging.debug(f"final_weights: {weights}") normalized_weights = normalize_max_weight(x=weights, limit=max_weight_limit) nw_arange = ( torch.tensor(list(range(len(normalized_weights)))) @@ -330,7 +329,7 @@ def process_weights_for_netuid( ) return nw_arange, normalized_weights - logging.debug("non_zero_weights", *non_zero_weights) + logging.debug(f"non_zero_weights: {non_zero_weights}") # Compute the exclude quantile and find the weights in the lowest quantile max_exclude = max(0, len(non_zero_weights) - min_allowed_weights) / len( @@ -342,21 +341,21 @@ def process_weights_for_netuid( if use_torch() else np.quantile(non_zero_weights, exclude_quantile) ) - logging.debug("max_exclude", max_exclude) - logging.debug("exclude_quantile", exclude_quantile) - logging.debug("lowest_quantile", lowest_quantile) + logging.debug(f"max_exclude: {max_exclude}") + logging.debug(f"exclude_quantile: {exclude_quantile}") + logging.debug(f"lowest_quantile: {lowest_quantile}") # Exclude all weights below the allowed quantile. non_zero_weight_uids = non_zero_weight_uids[lowest_quantile <= non_zero_weights] non_zero_weights = non_zero_weights[lowest_quantile <= non_zero_weights] - logging.debug("non_zero_weight_uids", *non_zero_weight_uids) - logging.debug("non_zero_weights", *non_zero_weights) + logging.debug(f"non_zero_weight_uids: {non_zero_weight_uids}") + logging.debug(f"non_zero_weights: {non_zero_weights}") # Normalize weights and return. normalized_weights = normalize_max_weight( x=non_zero_weights, limit=max_weight_limit ) - logging.debug("final_weights", *normalized_weights) + logging.debug(f"final_weights: {normalized_weights}") return non_zero_weight_uids, normalized_weights From bf92d2f91de4af15d22bd306ce20b76e9e28efdd Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 22 Nov 2024 17:44:46 -0800 Subject: [PATCH 2/2] Adds back kwargs --- bittensor/utils/btlogging/loggingmachine.py | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index 5b41b47a8a..8b5c3faa5b 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -443,40 +443,40 @@ def __trace_on__(self) -> bool: """ return self.current_state_value == "Trace" - def trace(self, msg="", prefix="", suffix="", *args): + def trace(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps trace message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.trace(msg, *args) + self._logger.trace(msg, *args, **kwargs) - def debug(self, msg="", prefix="", suffix="", *args): + def debug(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps debug message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.debug(msg, *args) + self._logger.debug(msg, *args, **kwargs) - def info(self, msg="", prefix="", suffix="", *args): + def info(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps info message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.info(msg, *args) + self._logger.info(msg, *args, **kwargs) - def success(self, msg="", prefix="", suffix="", *args): + def success(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps success message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.success(msg, *args) + self._logger.success(msg, *args, **kwargs) - def warning(self, msg="", prefix="", suffix="", *args): + def warning(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps warning message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.warning(msg, *args) + self._logger.warning(msg, *args, **kwargs) - def error(self, msg="", prefix="", suffix="", *args): + def error(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps error message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.error(msg, *args) + self._logger.error(msg, *args, **kwargs) - def critical(self, msg="", prefix="", suffix="", *args): + def critical(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps critical message with prefix and suffix.""" msg = _concat_message(msg, prefix, suffix) - self._logger.critical(msg, *args) + self._logger.critical(msg, *args, **kwargs) def exception(self, msg="", prefix="", suffix="", *args, **kwargs): """Wraps exception message with prefix and suffix."""