Skip to content

Commit cd2ccc2

Browse files
authored
Merge pull request #2548 from opentensor/release/8.5.1
Release/8.5.1
2 parents f3c68ef + 4c74af0 commit cd2ccc2

File tree

12 files changed

+80
-103
lines changed

12 files changed

+80
-103
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 8.5.1 /2024-12-16
4+
5+
## What's Changed
6+
* 8.5.0 bugfixes by @thewhaleking in https://github.com/opentensor/bittensor/pull/2541
7+
* Removes substrate call in format_error_message by @thewhaleking in https://github.com/opentensor/bittensor/pull/2542
8+
* Remove torch from the weights calls by @thewhaleking in https://github.com/opentensor/bittensor/pull/2543
9+
* optional arg fix by @thewhaleking in https://github.com/opentensor/bittensor/pull/2544
10+
* async cr3 not implemented by @thewhaleking in https://github.com/opentensor/bittensor/pull/2545
11+
* Backmerge master to staging 851 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2546
12+
* Adds retry in CRv3 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2547
13+
14+
**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.5.0...v8.5.1
15+
316
## 8.5.0 /2024-12-12
417

518
## What's Changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.5.0
1+
8.5.1

bittensor/core/async_subtensor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,9 +1596,11 @@ async def set_weights(
15961596
15971597
This function is crucial in shaping the network's collective intelligence, where each neuron's learning and contribution are influenced by the weights it sets towards others【81†source】.
15981598
"""
1599-
if self.commit_reveal_enabled(netuid=netuid) is True:
1599+
if (await self.commit_reveal_enabled(netuid=netuid)) is True:
16001600
# go with `commit reveal v3` extrinsic
1601-
raise NotImplemented("Not implemented yet for AsyncSubtensor. Coming soon.")
1601+
raise NotImplementedError(
1602+
"Not implemented yet for AsyncSubtensor. Coming soon."
1603+
)
16021604
else:
16031605
# go with classic `set weights extrinsic`
16041606
uid = await self.get_uid_for_hotkey_on_subnet(

bittensor/core/errors.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717

1818
from __future__ import annotations
1919

20-
from bittensor.core.synapse import Synapse
20+
from typing import Optional, TYPE_CHECKING
2121

22+
from substrateinterface.exceptions import SubstrateRequestException
2223

23-
class ChainError(BaseException):
24+
if TYPE_CHECKING:
25+
from bittensor.core.synapse import Synapse
26+
27+
28+
class ChainError(SubstrateRequestException):
2429
"""Base error for any chain related errors."""
2530

2631

@@ -81,7 +86,9 @@ class InvalidRequestNameError(Exception):
8186

8287

8388
class SynapseException(Exception):
84-
def __init__(self, message="Synapse Exception", synapse: "Synapse" | None = None):
89+
def __init__(
90+
self, message="Synapse Exception", synapse: Optional["Synapse"] = None
91+
):
8592
self.message = message
8693
self.synapse = synapse
8794
super().__init__(self.message)
@@ -123,7 +130,7 @@ class SynapseDendriteNoneException(SynapseException):
123130
def __init__(
124131
self,
125132
message="Synapse Dendrite is None",
126-
synapse: "Synapse" | None = None,
133+
synapse: Optional["Synapse"] = None,
127134
):
128135
self.message = message
129136
super().__init__(self.message, synapse)

bittensor/core/extrinsics/async_weights.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from bittensor.core.settings import version_as_int
1010
from bittensor.utils import format_error_message
1111
from bittensor.utils.btlogging import logging
12-
from bittensor.utils.registration import torch, use_torch
1312

1413
if TYPE_CHECKING:
1514
from bittensor_wallet import Wallet
1615
from bittensor.core.async_subtensor import AsyncSubtensor
16+
from bittensor.utils.registration import torch
1717

1818

1919
async def _do_set_weights(
@@ -106,16 +106,10 @@ async def set_weights_extrinsic(
106106
success (bool): Flag is ``true`` if extrinsic was finalized or included in the block. If we did not wait for finalization / inclusion, the response is ``true``.
107107
"""
108108
# First convert types.
109-
if use_torch():
110-
if isinstance(uids, list):
111-
uids = torch.tensor(uids, dtype=torch.int64)
112-
if isinstance(weights, list):
113-
weights = torch.tensor(weights, dtype=torch.float32)
114-
else:
115-
if isinstance(uids, list):
116-
uids = np.array(uids, dtype=np.int64)
117-
if isinstance(weights, list):
118-
weights = np.array(weights, dtype=np.float32)
109+
if isinstance(uids, list):
110+
uids = np.array(uids, dtype=np.int64)
111+
if isinstance(weights, list):
112+
weights = np.array(weights, dtype=np.float32)
119113

120114
# Reformat and normalize.
121115
weight_uids, weight_vals = weight_utils.convert_weights_and_uids_for_emit(

bittensor/core/extrinsics/commit_reveal.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
from bittensor.utils import format_error_message
1010
from bittensor.utils.btlogging import logging
1111
from bittensor.utils.networking import ensure_connected
12-
from bittensor.utils.registration import torch, use_torch
1312
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
1413

1514
if TYPE_CHECKING:
1615
from bittensor_wallet import Wallet
1716
from bittensor.core.subtensor import Subtensor
17+
from bittensor.utils.registration import torch
1818

1919

2020
@ensure_connected
@@ -74,9 +74,7 @@ def _do_commit_reveal_v3(
7474
if response.is_success:
7575
return True, None
7676
else:
77-
return False, format_error_message(
78-
response.error_message, substrate=self.substrate
79-
)
77+
return False, format_error_message(response.error_message)
8078

8179

8280
def commit_reveal_v3_extrinsic(
@@ -107,16 +105,10 @@ def commit_reveal_v3_extrinsic(
107105
"""
108106
try:
109107
# Convert uids and weights
110-
if use_torch():
111-
if isinstance(uids, list):
112-
uids = torch.tensor(uids, dtype=torch.int64)
113-
if isinstance(weights, list):
114-
weights = torch.tensor(weights, dtype=torch.float32)
115-
else:
116-
if isinstance(uids, list):
117-
uids = np.array(uids, dtype=np.int64)
118-
if isinstance(weights, list):
119-
weights = np.array(weights, dtype=np.float32)
108+
if isinstance(uids, list):
109+
uids = np.array(uids, dtype=np.int64)
110+
if isinstance(weights, list):
111+
weights = np.array(weights, dtype=np.float32)
120112

121113
# Reformat and normalize.
122114
uids, weights = convert_weights_and_uids_for_emit(uids, weights)

bittensor/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1616
# DEALINGS IN THE SOFTWARE.
1717

18-
__version__ = "8.5.0"
18+
__version__ = "8.5.1"
1919

2020
import os
2121
import re

bittensor/core/subtensor.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def query_runtime_api(
505505
self,
506506
runtime_api: str,
507507
method: str,
508-
params: Optional[Union[list[int], dict[str, int]]],
508+
params: Optional[Union[list[int], dict[str, int]]] = None,
509509
block: Optional[int] = None,
510510
) -> Optional[str]:
511511
"""
@@ -956,13 +956,13 @@ def get_neuron_certificate(
956956

957957
@networking.ensure_connected
958958
def neuron_for_uid(
959-
self, uid: Optional[int], netuid: int, block: Optional[int] = None
959+
self, uid: int, netuid: int, block: Optional[int] = None
960960
) -> "NeuronInfo":
961961
"""
962962
Retrieves detailed information about a specific neuron identified by its unique identifier (UID) within a specified subnet (netuid) of the Bittensor network. This function provides a comprehensive view of a neuron's attributes, including its stake, rank, and operational status.
963963
964964
Args:
965-
uid (Optional[int]): The unique identifier of the neuron.
965+
uid (int): The unique identifier of the neuron.
966966
netuid (int): The unique identifier of the subnet.
967967
block (Optional[int]): The blockchain block number for the query.
968968
@@ -1814,23 +1814,36 @@ def set_weights(
18141814
18151815
This function is crucial in shaping the network's collective intelligence, where each neuron's learning and contribution are influenced by the weights it sets towards others【81†source】.
18161816
"""
1817+
retries = 0
1818+
success = False
1819+
uid = self.get_uid_for_hotkey_on_subnet(wallet.hotkey.ss58_address, netuid)
1820+
18171821
if self.commit_reveal_enabled(netuid=netuid) is True:
18181822
# go with `commit reveal v3` extrinsic
1819-
return commit_reveal_v3_extrinsic(
1820-
subtensor=self,
1821-
wallet=wallet,
1822-
netuid=netuid,
1823-
uids=uids,
1824-
weights=weights,
1825-
version_key=version_key,
1826-
wait_for_inclusion=wait_for_inclusion,
1827-
wait_for_finalization=wait_for_finalization,
1828-
)
1823+
message = "No attempt made. Perhaps it is too soon to commit weights!"
1824+
while (
1825+
self.blocks_since_last_update(netuid, uid) # type: ignore
1826+
> self.weights_rate_limit(netuid) # type: ignore
1827+
and retries < max_retries
1828+
and success is False
1829+
):
1830+
logging.info(
1831+
f"Committing weights for subnet #{netuid}. Attempt {retries + 1} of {max_retries}."
1832+
)
1833+
success, message = commit_reveal_v3_extrinsic(
1834+
subtensor=self,
1835+
wallet=wallet,
1836+
netuid=netuid,
1837+
uids=uids,
1838+
weights=weights,
1839+
version_key=version_key,
1840+
wait_for_inclusion=wait_for_inclusion,
1841+
wait_for_finalization=wait_for_finalization,
1842+
)
1843+
retries += 1
1844+
return success, message
18291845
else:
18301846
# go with classic `set weights` logic
1831-
uid = self.get_uid_for_hotkey_on_subnet(wallet.hotkey.ss58_address, netuid)
1832-
retries = 0
1833-
success = False
18341847
message = "No attempt made. Perhaps it is too soon to set weights!"
18351848
while (
18361849
self.blocks_since_last_update(netuid, uid) # type: ignore

bittensor/utils/axon_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
NANOSECONDS_IN_SECOND = 1_000_000_000
2222

2323

24-
def allowed_nonce_window_ns(current_time_ns: int, synapse_timeout: Optional[float]):
24+
def allowed_nonce_window_ns(
25+
current_time_ns: int, synapse_timeout: Optional[float] = None
26+
) -> int:
2527
"""
2628
Calculates the allowed window for a nonce in nanoseconds.
2729

tests/unit_tests/extrinsics/test_async_weights.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -278,53 +278,6 @@ async def test_set_weights_extrinsic_exception(subtensor, mocker):
278278
assert message == "Unexpected error"
279279

280280

281-
@pytest.mark.asyncio
282-
async def test_set_weights_extrinsic_if_use_torch(subtensor, mocker):
283-
"""Tests set_weights_extrinsic when use_torch is True."""
284-
# Preps
285-
fake_wallet = mocker.Mock(autospec=Wallet)
286-
fake_netuid = 1
287-
fake_uids = [1, 2, 3]
288-
fake_weights = [0.1, 0.2, 0.7]
289-
290-
mocked_use_torch = mocker.patch.object(
291-
async_weights, "use_torch", return_value=True
292-
)
293-
mocked_torch_tensor = mocker.patch.object(
294-
async_weights.torch, "tensor", return_value=mocker.Mock()
295-
)
296-
297-
mocked_do_set_weights = mocker.patch.object(
298-
async_weights, "_do_set_weights", return_value=(False, "Test error message")
299-
)
300-
mocked_convert_weights_and_uids_for_emit = mocker.patch.object(
301-
async_weights.weight_utils,
302-
"convert_weights_and_uids_for_emit",
303-
return_value=(mocker.Mock(), mocker.Mock()),
304-
)
305-
306-
# Call
307-
result, message = await async_weights.set_weights_extrinsic(
308-
subtensor=subtensor,
309-
wallet=fake_wallet,
310-
netuid=fake_netuid,
311-
uids=fake_uids,
312-
weights=fake_weights,
313-
wait_for_inclusion=True,
314-
wait_for_finalization=True,
315-
)
316-
317-
# Asserts
318-
mocked_do_set_weights.assert_called_once()
319-
mocked_use_torch.assert_called_once()
320-
mocked_convert_weights_and_uids_for_emit.assert_called()
321-
mocked_torch_tensor.assert_called_with(
322-
fake_weights, dtype=async_weights.torch.float32
323-
)
324-
assert result is False
325-
assert message == "Test error message"
326-
327-
328281
@pytest.mark.asyncio
329282
async def test_do_commit_weights_success(subtensor, mocker):
330283
"""Tests _do_commit_weights when the commit is successful."""

0 commit comments

Comments
 (0)