Skip to content

Commit

Permalink
add bonds_penalty admin-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Jan 20, 2025
1 parent 4d91ec4 commit 43a13cf
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 41 deletions.
8 changes: 5 additions & 3 deletions hyperparameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TxRateLimit: u64 = 1; // [1 @ 64,888]
### netuid 1 (text_prompting)
```rust
Rho: u16 = 10;
Kappa: u16 = 32_767; // 0.5 = 65535/2
Kappa: u16 = 32_767; // 0.5 = 65535/2
MaxAllowedUids: u16 = 1024;
Issuance: u64 = 0;
MinAllowedWeights: u16 = 8;
Expand All @@ -32,10 +32,11 @@ ActivityCutoff: u16 = 5000;
MaxRegistrationsPerBlock: u16 = 1;
PruningScore : u16 = u16::MAX;
BondsMovingAverage: u64 = 900_000;
BondsPenalty: u16 = 0;
WeightsVersionKey: u64 = 1020;
MinDifficulty: u64 = 10_000_000;
MaxDifficulty: u64 = u64::MAX / 4;
ServingRateLimit: u64 = 10;
ServingRateLimit: u64 = 10;
Burn: u64 = 1_000_000_000; // 1 tao
MinBurn: u64 = 1_000_000_000; // 1 tao
MaxBurn: u64 = 100_000_000_000; // 100 tao
Expand All @@ -45,7 +46,7 @@ WeightsSetRateLimit: u64 = 100;
### netuid 3 (causallmnext)
```rust
Rho: u16 = 10;
Kappa: u16 = 32_767; // 0.5 = 65535/2
Kappa: u16 = 32_767; // 0.5 = 65535/2
MaxAllowedUids: u16 = 4096;
Issuance: u64 = 0;
MinAllowedWeights: u16 = 50;
Expand All @@ -70,6 +71,7 @@ ActivityCutoff: u16 = 5000; // [5000 @ 7,163]
MaxRegistrationsPerBlock: u16 = 1;
PruningScore : u16 = u16::MAX;
BondsMovingAverage: u64 = 900_000;
BondsPenalty: u16 = 0;
WeightsVersionKey: u64 = 400;
MinDifficulty: u64 = 10_000_000;
MaxDifficulty: u64 = u64::MAX / 4;
Expand Down
8 changes: 8 additions & 0 deletions pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ mod benchmarks {
_(RawOrigin::Root, 1u16/*netuid*/, 100u64/*bonds_moving_average*/)/*sudo_set_bonds_moving_average*/;
}

#[benchmark]
fn sudo_set_bonds_penalty() {
pallet_subtensor::Pallet::<T>::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/);

#[extrinsic_call]
_(RawOrigin::Root, 1u16/*netuid*/, 100u16/*bonds_penalty*/)/*sudo_set_bonds_penalty*/;
}

#[benchmark]
fn sudo_set_max_allowed_validators() {
pallet_subtensor::Pallet::<T>::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/);
Expand Down
25 changes: 25 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,31 @@ pub mod pallet {
Ok(())
}

/// The extrinsic sets the bonds penalty for a subnet.
/// It is only callable by the root account or subnet owner.
/// The extrinsic will call the Subtensor pallet to set the bonds penalty.
#[pallet::call_index(60)]
#[pallet::weight(<T as Config>::WeightInfo::sudo_set_bonds_penalty())]
pub fn sudo_set_bonds_penalty(
origin: OriginFor<T>,
netuid: u16,
bonds_penalty: u16,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;

ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);
pallet_subtensor::Pallet::<T>::set_bonds_penalty(netuid, bonds_penalty);
log::debug!(
"BondsPenalty( netuid: {:?} bonds_penalty: {:?} ) ",
netuid,
bonds_penalty
);
Ok(())
}

/// The extrinsic sets the maximum registrations per block for a subnet.
/// It is only callable by the root account.
/// The extrinsic will call the Subtensor pallet to set the maximum registrations per block.
Expand Down
14 changes: 7 additions & 7 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,26 +746,26 @@ fn test_sudo_set_bonds_penalty() {
new_test_ext().execute_with(|| {
let netuid: u16 = 1;
let to_be_set: u16 = 10;
add_network(netuid, 10);
let init_value: u16 = SubtensorModule::get_bonds_penalty(netuid);
add_network(netuid, 10, 0);
assert_eq!(
SubtensorModule::sudo_set_bonds_penalty(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(0)),
AdminUtils::sudo_set_bonds_penalty(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
to_be_set
),
Err(DispatchError::BadOrigin.into())
Err(DispatchError::BadOrigin)
);
assert_eq!(
SubtensorModule::sudo_set_bonds_penalty(
AdminUtils::sudo_set_bonds_penalty(
<<Test as Config>::RuntimeOrigin>::root(),
netuid + 1,
to_be_set
),
Err(Error::<Test>::NetworkDoesNotExist.into())
Err(Error::<Test>::SubnetDoesNotExist.into())
);
assert_eq!(SubtensorModule::get_bonds_penalty(netuid), init_value);
assert_ok!(SubtensorModule::sudo_set_bonds_penalty(
assert_ok!(AdminUtils::sudo_set_bonds_penalty(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
Expand Down
27 changes: 27 additions & 0 deletions pallets/admin-utils/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub trait WeightInfo {
fn sudo_set_weights_set_rate_limit() -> Weight;
fn sudo_set_weights_version_key() -> Weight;
fn sudo_set_bonds_moving_average() -> Weight;
fn sudo_set_bonds_penalty() -> Weight;
fn sudo_set_max_allowed_validators() -> Weight;
fn sudo_set_difficulty() -> Weight;
fn sudo_set_adjustment_interval() -> Weight;
Expand Down Expand Up @@ -182,6 +183,19 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: SubtensorModule NetworksAdded (r:1 w:0)
/// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured)
/// Storage: SubtensorModule BondsPenalty (r:0 w:1)
/// Proof Skipped: SubtensorModule BondsPenalty (max_values: None, max_size: None, mode: Measured)
fn sudo_set_bonds_penalty() -> Weight {
// Proof Size summary in bytes:
// Measured: `1111`
// Estimated: `4697`
// Minimum execution time: 46_099_000 picoseconds.
Weight::from_parts(47_510_000, 4697)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: SubtensorModule NetworksAdded (r:1 w:0)
/// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured)
/// Storage: SubtensorModule MaxAllowedUids (r:1 w:0)
/// Proof Skipped: SubtensorModule MaxAllowedUids (max_values: None, max_size: None, mode: Measured)
/// Storage: SubtensorModule MaxAllowedValidators (r:0 w:1)
Expand Down Expand Up @@ -559,6 +573,19 @@ impl WeightInfo for () {
}
/// Storage: SubtensorModule NetworksAdded (r:1 w:0)
/// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured)
/// Storage: SubtensorModule BondsPenalty (r:0 w:1)
/// Proof Skipped: SubtensorModule BondsPenalty (max_values: None, max_size: None, mode: Measured)
fn sudo_set_bonds_penalty() -> Weight {
// Proof Size summary in bytes:
// Measured: `1111`
// Estimated: `4697`
// Minimum execution time: 46_099_000 picoseconds.
Weight::from_parts(47_510_000, 4697)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: SubtensorModule NetworksAdded (r:1 w:0)
/// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured)
/// Storage: SubtensorModule MaxAllowedUids (r:1 w:0)
/// Proof Skipped: SubtensorModule MaxAllowedUids (max_values: None, max_size: None, mode: Measured)
/// Storage: SubtensorModule MaxAllowedValidators (r:0 w:1)
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/epoch/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ pub fn weighted_median_col_sparse(
}

// Element-wise interpolation of two matrices: Result = A + ratio * (B - A).
// ratio is has intended range [0, 1]
// ratio has intended range [0, 1]
// ratio=0: Result = A
// ratio=1: Result = B
#[allow(dead_code)]
Expand Down Expand Up @@ -1055,7 +1055,7 @@ pub fn interpolate(mat1: &[Vec<I32F32>], mat2: &[Vec<I32F32>], ratio: I32F32) ->
}

// Element-wise interpolation of two sparse matrices: Result = A + ratio * (B - A).
// ratio is has intended range [0, 1]
// ratio has intended range [0, 1]
// ratio=0: Result = A
// ratio=1: Result = B
#[allow(dead_code)]
Expand Down
10 changes: 5 additions & 5 deletions pallets/subtensor/src/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ fn test_512_graph_random_weights() {
for interleave in 0..3 {
// server-self weight off/on
for server_self in [false, true] {
for bonds_penalty in vec![0, u16::MAX / 2, u16::MAX] {
for bonds_penalty in [0, u16::MAX / 2, u16::MAX] {
let (validators, servers) = distribute_nodes(
validators_n as usize,
network_n as usize,
Expand All @@ -783,9 +783,9 @@ fn test_512_graph_random_weights() {
epochs,
1,
server_self,
&vec![],
&[],
false,
&vec![],
&[],
false,
true,
interleave as u64,
Expand Down Expand Up @@ -814,9 +814,9 @@ fn test_512_graph_random_weights() {
epochs,
1,
server_self,
&vec![],
&[],
false,
&vec![],
&[],
false,
true,
interleave as u64,
Expand Down
48 changes: 24 additions & 24 deletions pallets/subtensor/src/tests/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1803,18 +1803,18 @@ fn test_math_interpolate() {
assert_mat_compare(&result, &target, I32F32::from_num(0));

let target: Vec<f32> = vec![
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
];
let ratio = I32F32::from_num(0.9999998808);
let target = vec_to_mat_fixed(&target, 4, false);
Expand Down Expand Up @@ -1925,18 +1925,18 @@ fn test_math_interpolate_sparse() {
assert_sparse_mat_compare(&result, &target, I32F32::from_num(0));

let target: Vec<f32> = vec![
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.9999998808,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
0.999_999_9,
];
let ratio = I32F32::from_num(0.9999998808);
let target = vec_to_sparse_mat_fixed(&target, 4, false);
Expand Down

0 comments on commit 43a13cf

Please sign in to comment.