diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c52420179..2f850bb076 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 6.12.1 / 2024-05-17 + +## What's Changed +* Hotfix if the subnet UID is not in the Subnets + + +**Full Changelog**: https://github.com/opentensor/bittensor/compare/v6.12.0...fd2442db8bb8aad55ced2ac3b748b04ebdc73292 + + ## 6.12.0 / 2024-04-29 diff --git a/VERSION b/VERSION index d4e6cb4293..ff61e18689 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.12.0 +6.12.1 diff --git a/bittensor/__init__.py b/bittensor/__init__.py index 93d2aa4ca6..3f5c1d99ec 100644 --- a/bittensor/__init__.py +++ b/bittensor/__init__.py @@ -28,7 +28,7 @@ # Bittensor code and protocol version. -__version__ = "6.12.0" +__version__ = "6.12.1" version_split = __version__.split(".") __version_as_int__: int = ( diff --git a/bittensor/utils/weight_utils.py b/bittensor/utils/weight_utils.py index 0c5c944a0e..9190da4896 100644 --- a/bittensor/utils/weight_utils.py +++ b/bittensor/utils/weight_utils.py @@ -22,6 +22,8 @@ import bittensor from typing import Tuple, List +from bittensor.btlogging import logging + U32_MAX = 4294967295 U16_MAX = 65535 @@ -123,11 +125,14 @@ def convert_root_weight_uids_and_vals_to_tensor( for uid_j, wij in list(zip(uids, weights)): if uid_j in subnets: index_s = subnets.index(uid_j) + row_weights[index_s] = float( + wij + ) # assumes max-upscaled values (w_max = U16_MAX). else: - raise Exception("Incorrect Subnet {uid_j} in {subnets}") - row_weights[index_s] = float( - wij - ) # assumes max-upscaled values (w_max = U16_MAX). + logging.warning( + f"Incorrect Subnet uid {uid_j} in Subnets {subnets}. The subnet is unavailable at the moment." + ) + continue row_sum = row_weights.sum() if row_sum > 0: row_weights /= row_sum # normalize diff --git a/tests/unit_tests/utils/test_utils.py b/tests/unit_tests/utils/test_utils.py index 0875d921e0..42c08bd6a7 100644 --- a/tests/unit_tests/utils/test_utils.py +++ b/tests/unit_tests/utils/test_utils.py @@ -17,6 +17,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +import logging import torch import bittensor.utils.weight_utils as weight_utils import pytest @@ -230,19 +231,38 @@ def test_convert_root_weight_uids_and_vals_to_tensor_edge_cases( @pytest.mark.parametrize( "test_id, n, uids, weights, subnets, exception", [ - ("error-1", 3, [1, 3], [100, 200], [1, 2], Exception), # uid not in subnets - ("error-2", 3, [1, 2, 3], [100, 200], [1], Exception), # More uids than subnets + # uid not in subnets + ( + "error-1", + 3, + [1, 3], + [100, 200], + [1, 2], + "The subnet is unavailable at the moment.", + ), + # More uids than subnets + ( + "error-2", + 3, + [1, 2, 3], + [100, 200], + [1], + "The subnet is unavailable at the moment.", + ), ], ) def test_convert_root_weight_uids_and_vals_to_tensor_error_cases( - test_id, n, uids, weights, subnets, exception + test_id, n, uids, weights, subnets, exception, caplog ): - # Act and Assert - with pytest.raises(exception): + with caplog.at_level(logging.WARNING): weight_utils.convert_root_weight_uids_and_vals_to_tensor( n, uids, weights, subnets ) - print(f"Failed {test_id}") + + assert any( + exception in record.message and record.levelname == "WARNING" + for record in caplog.records + ) @pytest.mark.parametrize( diff --git a/tests/unit_tests/utils/test_weight_utils.py b/tests/unit_tests/utils/test_weight_utils.py index 0875d921e0..42c08bd6a7 100644 --- a/tests/unit_tests/utils/test_weight_utils.py +++ b/tests/unit_tests/utils/test_weight_utils.py @@ -17,6 +17,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +import logging import torch import bittensor.utils.weight_utils as weight_utils import pytest @@ -230,19 +231,38 @@ def test_convert_root_weight_uids_and_vals_to_tensor_edge_cases( @pytest.mark.parametrize( "test_id, n, uids, weights, subnets, exception", [ - ("error-1", 3, [1, 3], [100, 200], [1, 2], Exception), # uid not in subnets - ("error-2", 3, [1, 2, 3], [100, 200], [1], Exception), # More uids than subnets + # uid not in subnets + ( + "error-1", + 3, + [1, 3], + [100, 200], + [1, 2], + "The subnet is unavailable at the moment.", + ), + # More uids than subnets + ( + "error-2", + 3, + [1, 2, 3], + [100, 200], + [1], + "The subnet is unavailable at the moment.", + ), ], ) def test_convert_root_weight_uids_and_vals_to_tensor_error_cases( - test_id, n, uids, weights, subnets, exception + test_id, n, uids, weights, subnets, exception, caplog ): - # Act and Assert - with pytest.raises(exception): + with caplog.at_level(logging.WARNING): weight_utils.convert_root_weight_uids_and_vals_to_tensor( n, uids, weights, subnets ) - print(f"Failed {test_id}") + + assert any( + exception in record.message and record.levelname == "WARNING" + for record in caplog.records + ) @pytest.mark.parametrize(