Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
2b9b1a0
adding one extra epoch since set_weight can be executed at the epoch …
Apr 7, 2025
9cf13ba
temporarily run only 1 test
Apr 7, 2025
b626be4
replace runner
Apr 7, 2025
146dd0e
wait 1 second
Apr 7, 2025
3a6a702
add retry
Apr 7, 2025
a5d00aa
add retry
Apr 7, 2025
e9c0647
bring back 60 sec wait
Apr 7, 2025
a832e21
oops, wrong exception
Apr 7, 2025
c819fd7
wait extra epoch to give the chain additional time to reveal weights
Apr 7, 2025
4ec302d
extend except
Apr 7, 2025
1d1dd58
remove commented code
Apr 7, 2025
6196c43
bring back all tests
Apr 7, 2025
bbe14de
add retry logic to `use_and_wait_for_next_nonce` helper
Apr 7, 2025
1b9b29d
add TimeoutError
Apr 7, 2025
4451c65
wait 2 epoch + 1 block to guaranty
Apr 7, 2025
b531a45
use self-hosted runner
Apr 7, 2025
109518b
ruff
Apr 8, 2025
1acf4fd
sleep from 0.25 to 3.0 seconds for use_and_wait_for_next_nonce.the ch…
Apr 8, 2025
56cfbc8
add timeout
Apr 8, 2025
ade2042
wait 2 epoch before metagraph
Apr 8, 2025
b39f9f6
reduce max-parallel
Apr 8, 2025
fa6e60e
separate steps
Apr 8, 2025
d1e7a01
set max-parallel=32
Apr 8, 2025
9d5a399
add wait 1 epoch (bc fast block is too fast)
Apr 8, 2025
9517416
test
Apr 8, 2025
3419218
increase epoch (10 * 0.25 is too fast), add waiting for 1 block after…
Apr 8, 2025
2052a4a
add wait after validator run
Apr 8, 2025
32a5f4d
remove wait_interval
Apr 8, 2025
c87e97b
new
Apr 8, 2025
54d3117
add waiting time for commit weights
Apr 8, 2025
ce165b7
add waiting time for commit weights
Apr 8, 2025
42dffa2
increase timout for validator.set_weights.wait()
Apr 8, 2025
8640c52
set longer tempo
Apr 8, 2025
0e54b85
add debug
Apr 8, 2025
01150b2
just flaky tests
Apr 8, 2025
c5088a0
use default tempo
Apr 8, 2025
32cb5c4
use retry
Apr 8, 2025
6b60341
add wait epoch
Apr 8, 2025
3dc057d
test incentive as it is for debug
Apr 8, 2025
1916204
subtensor.wait_for_block(DURATION_OF_START_CALL * 2)
Apr 8, 2025
991219e
try to set weights in the beginning of the epoch
Apr 8, 2025
0a52e43
add wait_for_block
Apr 8, 2025
089f30b
add debug
Apr 8, 2025
679f7ab
increase sleep in case of waiting nonce
Apr 8, 2025
ddb9f6b
remove wait
Apr 8, 2025
b6628c1
sleep 0.25
Apr 8, 2025
14ebd6e
sleep 3
Apr 8, 2025
ec5aec1
try to fix commit weights
Apr 8, 2025
ccb8f9b
try to fix set weights
Apr 8, 2025
b178f2e
try to fix test_commit (increase final wait)
Apr 8, 2025
7e73e85
increase Validator wait_for timeout
Apr 8, 2025
e63253f
oops
Apr 8, 2025
81cf799
incentive
Apr 8, 2025
2277cfd
remove unnecessary netuid from `next_tempo` (bug if subnet number is …
Apr 8, 2025
2102639
fixed `test_incentive.py` (subtensor issue)
Apr 8, 2025
c8b0415
fix `Using CPython 3.13.2 interpreter error: Failed to fetch: `https:…
Apr 8, 2025
d19bc8a
debug for `use_and_wait_for_next_nonce` + sleep: float = 0.25
Apr 8, 2025
e839e54
debug to `e2e_test_utils.py`
Apr 8, 2025
8a84cb5
increase timeout to avoid `asyncio.exceptions.TimeoutError`
Apr 8, 2025
b979e9c
increase timeout to avoid `asyncio.exceptions.TimeoutError`
Apr 8, 2025
c46b96d
pypi was on maintenance
Apr 8, 2025
5081de1
review fix
Apr 8, 2025
c30d86e
add debug fix for `test_commit_weights_uses_next_nonce`
Apr 8, 2025
0af421d
add debug fix for `test_commit_weights_uses_next_nonce`
Apr 8, 2025
ba2696f
all tests back
Apr 8, 2025
f130879
limited tests
Apr 8, 2025
59074b1
logging, waiting, limited tests
Apr 8, 2025
98de614
ruff
Apr 8, 2025
b9c5b37
Merge branch 'staging' into fix/roman/hope-incentive-passed-always
basfroman Apr 8, 2025
31ca484
>
Apr 8, 2025
914b53c
all tests
Apr 8, 2025
dd3b3b7
try use SubtensorCI runner
Apr 8, 2025
3dcc570
add tricky waiter to `test_set_weights.py`
Apr 8, 2025
a39f502
add 2 tricky waiter to `test_set_weights.py`
Apr 8, 2025
16dc7ef
add 120 second to waiters
Apr 8, 2025
a5b18e5
bring back `ubuntu-latest`
Apr 8, 2025
b053d98
skip flaky test
Apr 8, 2025
aee1c53
oops
Apr 9, 2025
d1266f0
epoch 3 come
Apr 9, 2025
33e40bd
test_set_weights.py to non-fast-block
Apr 9, 2025
e378733
test_commit_reveal_v3.py to non-fast-block
Apr 9, 2025
18271af
limit tests
Apr 9, 2025
17d061d
test_commit_weights.py to non-fast block
Apr 9, 2025
631a468
Put the version in a single place (toml)
thewhaleking Apr 9, 2025
e4e32df
add log to miner and validator
Apr 10, 2025
0d74ba4
add wait_for to miner start ,wrapp tests result info while
Apr 10, 2025
0f2f825
Merge branch 'staging' into fix/roman/hope-incentive-passed-always
basfroman Apr 10, 2025
893f8cd
origin
Apr 10, 2025
fc99a31
set period for set_weights as tempo
Apr 10, 2025
e1627ef
update test
Apr 10, 2025
9c9bdba
fix neurons call
Apr 10, 2025
17723e1
fix neurons call
Apr 10, 2025
cf0f1f9
fix neurons call
Apr 10, 2025
b7902db
add period argument to set_weights and related calls + fixed tests
Apr 10, 2025
ec5ca29
cleanup
Apr 10, 2025
c1dbc05
add get_next_epoch_start_block
Apr 10, 2025
b70e713
add get_next_epoch_start_block
Apr 10, 2025
2821722
test_commit_weights.py + test_set_weights.py
Apr 10, 2025
ef7d8c5
add commit from template-repo (fix for test_incentive)
Apr 10, 2025
eb50744
add period to `set_weights` in `test_set_weights.py`
Apr 10, 2025
1f7e89c
add period to `set_weights` in `test_set_weights.py`
Apr 10, 2025
2fd2024
Update README.md
sashaphmn Apr 10, 2025
2855b70
add 3 attempts to run validator
Apr 10, 2025
161d146
increase wait time for `test_commit_weights.py`
Apr 10, 2025
104d709
try speedup, especially py3.13 based tests
Apr 10, 2025
a121e5a
all tests back and tests :fingers_crossed: :fingers_crossed:
Apr 10, 2025
77c5321
oops with CRv3
Apr 10, 2025
f8f5b89
convert `wait_for_new_nonce` to sync
Apr 10, 2025
ed39a0f
ubuntu-latest is faster 🏎️
Apr 10, 2025
164d275
test_commit_reveal_v3.py -> fast block correction
Apr 10, 2025
8d3b237
debug subtensor.set_weights regarding nonce
Apr 10, 2025
da6d17f
convert `use_and_wait_for_next_nonce` to decorator and add retry to c…
Apr 10, 2025
8ac2b52
fix assertion
Apr 10, 2025
64b40a5
pass `wait_for_inclusion=True` - we have to be make sure with multipl…
Apr 10, 2025
b3d2efa
cleanup + debug ✅
Apr 10, 2025
7c6ae27
cover all type exceptions with decorator. anyway they come to the log
Apr 10, 2025
dfb77b2
Adds compatibility for torch 2.6.0+
thewhaleking Apr 10, 2025
633783e
Adds compatibility for torch 2.6.0+
thewhaleking Apr 10, 2025
7a04186
Update bittensor/core/async_subtensor.py
basfroman Apr 10, 2025
977966e
Update bittensor/core/subtensor.py
basfroman Apr 10, 2025
bf02150
add debug in case UnknownError to format_error_message
Apr 10, 2025
c0b9c37
fix typo
Apr 10, 2025
a3fff16
Update requiresments/torch.txt file
thewhaleking Apr 10, 2025
10df0c2
argument
Apr 10, 2025
40476b1
Remove requirements directory, change workflows to not use this.
thewhaleking Apr 10, 2025
74b5a1f
Update uv sync to not install cubit
thewhaleking Apr 10, 2025
3b5845e
bumping pytest* version
Apr 10, 2025
d573744
extend logic of `format_error_message`
Apr 10, 2025
66e4f6a
Fix extras
thewhaleking Apr 10, 2025
9e1bff9
replace order in format_error_message
Apr 10, 2025
936214f
extend debug
Apr 10, 2025
86be8ec
Limit extras
thewhaleking Apr 10, 2025
0024a19
add waiting 1 epoch after setting `weights_rate_limit`
Apr 10, 2025
c8a5aff
add different weights generator
Apr 10, 2025
1427d77
test multiple times 3 tests
Apr 10, 2025
e7449a8
try short name - works with local runner
Apr 10, 2025
8a9e988
name uses just static names
Apr 10, 2025
5a998bb
remove specific commit
Apr 10, 2025
39288bb
Merge pull request #2795 from opentensor/fix/roman/hope-incentive-pas…
basfroman Apr 11, 2025
9e7458d
Merge branch 'staging' into feat/thewhaleking/remove-requirements-dir
basfroman Apr 11, 2025
a816685
Merge branch 'staging' into feat/thewhaleking/torch-2.6.0-compat
basfroman Apr 11, 2025
b09aec0
Merge branch 'staging' into patch-2
basfroman Apr 11, 2025
e1be218
Merge branch 'staging' into feat/roman/add-get_next_epoch_start_block
basfroman Apr 11, 2025
7e49e25
Merge pull request #2808 from opentensor/feat/roman/add-get_next_epoc…
basfroman Apr 11, 2025
e9b5234
Merge branch 'staging' into feat/thewhaleking/torch-2.6.0-compat
basfroman Apr 11, 2025
e1ad0c3
Merge branch 'staging' into feat/thewhaleking/remove-requirements-dir
basfroman Apr 11, 2025
a70bee8
Merge pull request #2811 from opentensor/feat/thewhaleking/torch-2.6.…
basfroman Apr 11, 2025
a77df26
Merge branch 'staging' into feat/thewhaleking/remove-requirements-dir
Apr 11, 2025
9b6d63e
Merge branch 'staging' into patch-2
basfroman Apr 11, 2025
8799239
Update README.md
sashaphmn Apr 11, 2025
0f7a0ee
f Update CONTRIBUTING.md
Hack666r Apr 11, 2025
f4a6fe5
Merge branch 'staging' into f
thewhaleking Apr 11, 2025
4c00111
Update requirements checking.
thewhaleking Apr 11, 2025
14936be
Typo
thewhaleking Apr 11, 2025
e2d9a3e
Test (will be reverted)
thewhaleking Apr 11, 2025
d756fdb
Typo
thewhaleking Apr 11, 2025
f63bb3e
Remove unused extra
thewhaleking Apr 11, 2025
38d3ccb
Merge pull request #2813 from Hack666r/f
basfroman Apr 11, 2025
954c7c0
Merge branch 'staging' into patch-2
basfroman Apr 11, 2025
50afd13
Merge branch 'staging' into feat/thewhaleking/remove-requirements-dir
basfroman Apr 11, 2025
faca6a9
Merge pull request #2809 from sashaphmn/patch-2
basfroman Apr 11, 2025
67197f6
Merge branch 'staging' into feat/thewhaleking/remove-requirements-dir
basfroman Apr 11, 2025
0932415
sometimes it's still flaky because the chain returns data with time o…
Apr 11, 2025
62f76f7
Merge branch 'staging' into fix/roman/add-more-time-to-crv3-test
basfroman Apr 11, 2025
ec1683e
Merge pull request #2816 from opentensor/fix/roman/add-more-time-to-c…
basfroman Apr 11, 2025
154cc5c
Update CONTRIBUTING.md
sashaphmn Apr 12, 2025
cde5aa1
Merge branch 'staging' into feat/thewhaleking/remove-requirements-dir
basfroman Apr 14, 2025
4e9fb0f
Merge remote-tracking branch 'origin/staging' into feat/thewhaleking/…
thewhaleking Apr 14, 2025
fd9029e
Merge branch 'feat/thewhaleking/remove-requirements-dir' into feat/th…
thewhaleking Apr 14, 2025
237bd6f
Update test config.
thewhaleking Apr 14, 2025
86d4367
Merge pull request #2812 from opentensor/feat/thewhaleking/remove-req…
thewhaleking Apr 14, 2025
f59afd3
Merge branch 'staging' into feat/thewhaleking/version-in-one-place
thewhaleking Apr 14, 2025
685edf5
Update CONTRIBUTING.md
sashaphmn Apr 14, 2025
c7dcb68
Removed 'file' param from dependabot.yml
thewhaleking Apr 14, 2025
d6507a0
Merge remote-tracking branch 'origin/feat/thewhaleking/version-in-one…
thewhaleking Apr 14, 2025
a0eb836
Updated other reference
thewhaleking Apr 14, 2025
64db9e1
Merge branch 'staging' into patch-3
thewhaleking Apr 14, 2025
074f0f1
Merge pull request #2806 from opentensor/feat/thewhaleking/version-in…
thewhaleking Apr 14, 2025
a941e06
Merge branch 'staging' into patch-3
thewhaleking Apr 14, 2025
025d13a
Merge pull request #2820 from opentensor/patch-3
ibraheem-abe Apr 14, 2025
7996f27
updates changelog
ibraheem-abe Apr 14, 2025
07e6b63
Merge pull request #2821 from opentensor/changelog/9.3.1a1
ibraheem-abe Apr 14, 2025
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
55 changes: 6 additions & 49 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade uv
uv pip install ruff -c requirements/dev.txt
uv pip install ruff

- save_cache:
name: Save cached ruff venv
Expand Down Expand Up @@ -68,9 +68,7 @@ jobs:
name: Install dependencies and Check compatibility
command: |
if [ "$REQUIREMENTS_CHANGED" == "true" ]; then
sudo apt-get update
sudo apt-get install -y jq curl
./scripts/check_compatibility.sh << parameters.python_version >>
python -m pip install ".[dev,cli]" --dry-run --python-version << parameters.python_version >> --no-deps
else
echo "Skipping compatibility checks..."
fi
Expand All @@ -87,31 +85,19 @@ jobs:
steps:
- checkout

- restore_cache:
name: Restore cached venv
keys:
- v2-pypi-py<< parameters.python-version >>-{{ checksum "requirements/prod.txt" }}+{{ checksum "requirements/dev.txt" }}
- v2-pypi-py<< parameters.python-version >>

- run:
name: Update & Activate venv
command: |
python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade uv
uv sync --all-extras --dev

- save_cache:
name: Save cached venv
paths:
- "venv/"
key: v2-pypi-py<< parameters.python-version >>-{{ checksum "requirements/prod.txt" }}+{{ checksum "requirements/dev.txt" }}
uv sync --extra dev --dev

- run:
name: Install Bittensor
command: |
. .venv/bin/activate
uv sync --all-extras --dev
uv sync --extra dev --dev

- run:
name: Instantiate Mock Wallet
Expand Down Expand Up @@ -178,32 +164,20 @@ jobs:
steps:
- checkout

- restore_cache:
name: Restore cached venv
keys:
- v2-pypi-py<< parameters.python-version >>-{{ checksum "requirements/prod.txt" }}+{{ checksum "requirements/dev.txt" }}
- v2-pypi-py<< parameters.python-version >>

- run:
name: Update & Activate venv
command: |
python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade uv
uv sync --all-extras --dev
uv sync --extra dev --dev
uv pip install flake8

- save_cache:
name: Save cached venv
paths:
- "env/"
key: v2-pypi-py<< parameters.python-version >>-{{ checksum "requirements/prod.txt" }}+{{ checksum "requirements/dev.txt" }}

- run:
name: Install Bittensor
command: |
. .venv/bin/activate
uv sync --all-extras --dev
uv sync --extra dev --dev

- run:
name: Lint with flake8
Expand Down Expand Up @@ -235,18 +209,6 @@ jobs:
uv pip install --upgrade coveralls
coveralls --finish --rcfile .coveragerc || echo "Failed to upload coverage"

check-version-updated:
docker:
- image: cimg/python:3.10
steps:
- checkout

- run:
name: Version is updated
command: |
[[ $(git diff-tree --no-commit-id --name-only -r HEAD..master | grep bittensor/__init__.py | wc -l) == 1 ]] && echo "bittensor/__init__.py has changed"
[[ $(git diff-tree --no-commit-id --name-only -r HEAD..master | grep VERSION | wc -l) == 1 ]] && echo "VERSION has changed"

check-changelog-updated:
docker:
- image: cimg/python:3.10
Expand Down Expand Up @@ -323,11 +285,6 @@ workflows:

release-branches-requirements:
jobs:
- check-version-updated:
filters:
branches:
only:
- /^(release|hotfix)/.*/
- check-changelog-updated:
filters:
branches:
Expand Down
3 changes: 1 addition & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: ""
file: "requirements/prod.txt"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 0 # Only security updates will be opened as PRs
8 changes: 5 additions & 3 deletions .github/workflows/e2e-subtensor-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
id: get-tests
run: |
test_files=$(find tests/e2e_tests -name "test*.py" | jq -R -s -c 'split("\n") | map(select(. != ""))')
# keep it here for future debug
# test_files=$(find tests/e2e_tests -type f -name "test*.py" | grep -E 'test_(incentive|commit_weights|set_weights)\.py$' | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "::set-output name=test-files::$test_files"
shell: bash

Expand All @@ -61,7 +63,7 @@ jobs:
path: subtensor-localnet.tar

# Job to run tests in parallel
run:
run-e2e-test:
name: ${{ matrix.test-file }} / Python ${{ matrix.python-version }}
needs:
- find-tests
Expand All @@ -70,7 +72,7 @@ jobs:
timeout-minutes: 45
strategy:
fail-fast: false # Allow other matrix jobs to run even if this job fails
max-parallel: 32 # Set the maximum number of parallel jobs (same as we have cores in SubtensorCI runner)
max-parallel: 32 # Set the maximum number of parallel jobs (same as we have cores in ubuntu-latest runner)
matrix:
os:
- ubuntu-latest
Expand All @@ -89,7 +91,7 @@ jobs:
uses: astral-sh/setup-uv@v4

- name: install dependencies
run: uv sync --all-extras --dev
run: uv sync --extra dev --dev

- name: Download Cached Docker Image
uses: actions/download-artifact@v4
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 9.3.1a1 /2025-04-14

## What's Changed
* Release/9.3.0 by @ibraheem-abe in https://github.com/opentensor/bittensor/pull/2805
* Fix for flaky behavior of `test_incentive`, `test_commit_weights` and `test_set_weights` by @basfroman in https://github.com/opentensor/bittensor/pull/2795
* Add `get_next_epoch_start_block` method to Async/Subtensor by @basfroman in https://github.com/opentensor/bittensor/pull/2808
* Adds compatibility for torch 2.6.0+ by @thewhaleking in https://github.com/opentensor/bittensor/pull/2811
* f Update CONTRIBUTING.md by @Hack666r in https://github.com/opentensor/bittensor/pull/2813
* docs: replaced discord link with documentation by @sashaphmn in https://github.com/opentensor/bittensor/pull/2809
* sometimes it's still flaky because the chain returns data with time offset by @basfroman in https://github.com/opentensor/bittensor/pull/2816
* Remove requirements directory by @thewhaleking in https://github.com/opentensor/bittensor/pull/2812
* version in one place by @thewhaleking in https://github.com/opentensor/bittensor/pull/2806
* Update CONTRIBUTING hyperlinks by @thewhaleking in https://github.com/opentensor/bittensor/pull/2820

## New Contributors
* @Hack666r made their first contribution in https://github.com/opentensor/bittensor/pull/2813

**Full Changelog**: https://github.com/opentensor/bittensor/compare/v9.3.0...v9.3.1a1

## 9.3.0 /2025-04-09

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

## Internet-scale Neural Networks <!-- omit in toc -->

[Discord](https://discord.gg/qasY3HA9F9) • [Network](https://taostats.io/) • [Research](https://bittensor.com/whitepaper)
[Discord](https://discord.gg/qasY3HA9F9) • [Network](https://taostats.io/) • [Research](https://bittensor.com/whitepaper) • [Documentation](https://docs.bittensor.com)

</div>

Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

35 changes: 35 additions & 0 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,38 @@ async def get_neuron_for_pubkey_and_subnet(
reuse_block=reuse_block,
)

async def get_next_epoch_start_block(
self,
netuid: int,
block: Optional[int] = None,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> Optional[int]:
"""
Calculates the first block number of the next epoch for the given subnet.

If `block` is not provided, the current chain block will be used. Epochs are
determined based on the subnet's tempo (i.e., blocks per epoch). The result
is the block number at which the next epoch will begin.

Args:
netuid (int): The unique identifier of the subnet.
block (Optional[int], optional): The reference block to calculate from.
If None, uses the current chain block height.
block_hash (Optional[int]): The blockchain block number at which to perform the query.
reuse_block (bool): Whether to reuse the last-used blockchain block hash.


Returns:
int: The block number at which the next epoch will start.
"""
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
if not block_hash and reuse_block:
block_hash = self.substrate.last_block_hash
block = await self.substrate.get_block_number(block_hash=block_hash)
tempo = await self.tempo(netuid=netuid, block_hash=block_hash)
return (((block // tempo) + 1) * tempo) + 1 if tempo else None

async def get_owned_hotkeys(
self,
coldkey_ss58: str,
Expand Down Expand Up @@ -3813,6 +3845,7 @@ async def set_weights(
wait_for_finalization: bool = False,
max_retries: int = 5,
block_time: float = 12.0,
period: int = 5,
):
"""
Sets the inter-neuronal weights for the specified neuron. This process involves specifying the influence or
Expand All @@ -3833,6 +3866,7 @@ async def set_weights(
``False``.
max_retries (int): The number of maximum attempts to set weights. Default is ``5``.
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.
period (int, optional): The period in seconds to wait for extrinsic inclusion or finalization. Defaults to 5.

Returns:
tuple[bool, str]: ``True`` if the setting of weights is successful, False otherwise. And `msg`, a string
Expand Down Expand Up @@ -3907,6 +3941,7 @@ async def _blocks_weight_limit() -> bool:
version_key=version_key,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
)
except Exception as e:
logging.error(f"Error setting weights: {e}")
Expand Down
3 changes: 3 additions & 0 deletions bittensor/core/extrinsics/asyncex/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ async def set_weights_extrinsic(
version_key: int = 0,
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
period: int = 5,
) -> tuple[bool, str]:
"""Sets the given weights and values on chain for wallet hotkey account.

Expand All @@ -302,6 +303,7 @@ async def set_weights_extrinsic(
returns ``False`` if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool): If set, waits for the extrinsic to be finalized on the chain before returning
``True``, or returns ``False`` if the extrinsic fails to be finalized within the timeout.
period (int, optional): The period in seconds to wait for extrinsic inclusion or finalization. Defaults to 5.

Returns:
success (bool): Flag is ``True`` if extrinsic was finalized or included in the block. If we did not wait for
Expand Down Expand Up @@ -331,6 +333,7 @@ async def set_weights_extrinsic(
version_key=version_key,
wait_for_finalization=wait_for_finalization,
wait_for_inclusion=wait_for_inclusion,
period=period,
)

if not wait_for_finalization and not wait_for_inclusion:
Expand Down
3 changes: 3 additions & 0 deletions bittensor/core/extrinsics/set_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def set_weights_extrinsic(
version_key: int = 0,
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
period: int = 5,
) -> tuple[bool, str]:
"""Sets the given weights and values on chain for wallet hotkey account.

Expand All @@ -106,6 +107,7 @@ def set_weights_extrinsic(
returns ``False`` if the extrinsic fails to enter the block within the timeout.
wait_for_finalization (bool): If set, waits for the extrinsic to be finalized on the chain before returning
``True``, or returns ``False`` if the extrinsic fails to be finalized within the timeout.
period (int, optional): The period in seconds to wait for extrinsic inclusion or finalization. Defaults to 5.

Returns:
success (bool): Flag is ``True`` if extrinsic was finalized or included in the block. If we did not wait for
Expand Down Expand Up @@ -135,6 +137,7 @@ def set_weights_extrinsic(
version_key=version_key,
wait_for_finalization=wait_for_finalization,
wait_for_inclusion=wait_for_inclusion,
period=period,
)

if not wait_for_finalization and not wait_for_inclusion:
Expand Down
29 changes: 27 additions & 2 deletions bittensor/core/metagraph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import contextlib
import copy
import os
import pickle
Expand All @@ -11,6 +12,7 @@
import numpy as np
from async_substrate_interface.errors import SubstrateRequestException
from numpy.typing import NDArray
from packaging import version

from bittensor.core import settings
from bittensor.core.chain_data import (
Expand Down Expand Up @@ -143,6 +145,27 @@ def latest_block_path(dir_path: str) -> str:
return latest_file_full_path


def safe_globals():
"""
Context manager to load torch files for version 2.6+
"""
if version.parse(torch.__version__).release < version.parse("2.6").release:
return contextlib.nullcontext()

np_core = (
np._core if version.parse(np.__version__) >= version.parse("2.0.0") else np.core
)
allow_list = [
np_core.multiarray._reconstruct,
np.ndarray,
np.dtype,
type(np.dtype(np.uint32)),
np.dtypes.Float32DType,
bytes,
]
return torch.serialization.safe_globals(allow_list)


class MetagraphMixin(ABC):
"""
The metagraph class is a core component of the Bittensor network, representing the neural graph that forms the
Expand Down Expand Up @@ -1124,7 +1147,8 @@ def load_from_path(self, dir_path: str) -> "MetagraphMixin":
"""

graph_file = latest_block_path(dir_path)
state_dict = torch.load(graph_file)
with safe_globals():
state_dict = torch.load(graph_file)
self.n = torch.nn.Parameter(state_dict["n"], requires_grad=False)
self.block = torch.nn.Parameter(state_dict["block"], requires_grad=False)
self.uids = torch.nn.Parameter(state_dict["uids"], requires_grad=False)
Expand Down Expand Up @@ -1256,7 +1280,8 @@ def load_from_path(self, dir_path: str) -> "MetagraphMixin":
try:
import torch as real_torch

state_dict = real_torch.load(graph_filename)
with safe_globals():
state_dict = real_torch.load(graph_filename)
for key in METAGRAPH_STATE_DICT_NDARRAY_KEYS:
state_dict[key] = state_dict[key].detach().numpy()
del real_torch
Expand Down
5 changes: 3 additions & 2 deletions bittensor/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
__version__ = "9.3.0"

import os
import importlib.metadata
import re
from pathlib import Path

Expand All @@ -15,6 +14,8 @@
WALLETS_DIR = USER_BITTENSOR_DIR / "wallets"
MINERS_DIR = USER_BITTENSOR_DIR / "miners"

__version__ = importlib.metadata.version("bittensor")


if not READ_ONLY:
# Create dirs if they don't exist
Expand Down
Loading
Loading