Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/6.12.1 #1902

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.12.0
6.12.1
2 changes: 1 addition & 1 deletion bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
13 changes: 9 additions & 4 deletions bittensor/utils/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import bittensor
from typing import Tuple, List

from bittensor.btlogging import logging

U32_MAX = 4294967295
U16_MAX = 65535

Expand Down Expand Up @@ -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
Expand Down
32 changes: 26 additions & 6 deletions tests/unit_tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
32 changes: 26 additions & 6 deletions tests/unit_tests/utils/test_weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down