Skip to content
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
Binary file added docs/img/sigmoid_steepness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 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;
AlphaSigmoidSteepness: u16 = 10.0
AlphaSigmoidSteepness: i16 = 1000
Kappa: u16 = 32_767; // 0.5 = 65535/2
MaxAllowedUids: u16 = 1024;
Issuance: u64 = 0;
Expand Down Expand Up @@ -48,7 +48,7 @@ WeightsSetRateLimit: u64 = 100;
### netuid 3 (causallmnext)
```rust
Rho: u16 = 10;
AlphaSigmoidSteepness: u16 = 10.0
AlphaSigmoidSteepness: i16 = 1000
Kappa: u16 = 32_767; // 0.5 = 65535/2
MaxAllowedUids: u16 = 4096;
Issuance: u64 = 0;
Expand Down
24 changes: 21 additions & 3 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ pub mod pallet {
MaxAllowedUIdsLessThanCurrentUIds,
/// The maximum value for bonds moving average is reached
BondsMovingAverageMaxReached,
/// Only root can set negative sigmoid steepness values
NegativeSigmoidSteepness,
}
/// Enum for specifying the type of precompile operation.
#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, Eq, Debug, Copy)]
Expand Down Expand Up @@ -1560,20 +1562,36 @@ pub mod pallet {
/// # Arguments
/// * `origin` - The origin of the call, which must be the root account.
/// * `netuid` - The unique identifier for the subnet.
/// * `steepness` - The new steepness for the alpha sigmoid function.
/// * `steepness` - The Steepness for the alpha sigmoid function. (range is 0-int16::MAX,
/// negative values are reserved for future use)
///
/// # Errors
/// * `BadOrigin` - If the caller is not the root account.
/// * `SubnetDoesNotExist` - If the specified subnet does not exist.
/// * `NegativeSigmoidSteepness` - If the steepness is negative and the caller is
/// root.
/// # Weight
/// Weight is handled by the `#[pallet::weight]` attribute.
#[pallet::call_index(68)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_alpha_sigmoid_steepness(
origin: OriginFor<T>,
netuid: NetUid,
steepness: u16,
steepness: i16,
) -> DispatchResult {
ensure_root(origin)?;
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin.clone(), netuid)?;

ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);

let is_root = ensure_root(origin).is_ok();
ensure!(
is_root || steepness >= 0,
Error::<T>::NegativeSigmoidSteepness
);

pallet_subtensor::Pallet::<T>::set_alpha_sigmoid_steepness(netuid, steepness);

log::debug!(
Expand Down
2 changes: 1 addition & 1 deletion pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ parameter_types! {
pub const TransactionByteFee: Balance = 100;
pub const SDebug:u64 = 1;
pub const InitialRho: u16 = 30;
pub const InitialAlphaSigmoidSteepness: u16 = 10;
pub const InitialAlphaSigmoidSteepness: i16 = 1000;
pub const InitialKappa: u16 = 32_767;
pub const InitialTempo: u16 = 0;
pub const SelfOwnership: u64 = 2;
Expand Down
59 changes: 59 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,65 @@ fn test_sudo_set_liquid_alpha_enabled() {
});
}

#[test]
fn test_sudo_set_alpha_sigmoid_steepness() {
new_test_ext().execute_with(|| {
let netuid = NetUid::from(1);
let to_be_set: i16 = 5000;
add_network(netuid, 10);
let init_value = SubtensorModule::get_alpha_sigmoid_steepness(netuid);
assert_eq!(
AdminUtils::sudo_set_alpha_sigmoid_steepness(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
to_be_set
),
Err(DispatchError::BadOrigin)
);
assert_eq!(
AdminUtils::sudo_set_alpha_sigmoid_steepness(
<<Test as Config>::RuntimeOrigin>::root(),
netuid.next(),
to_be_set
),
Err(Error::<Test>::SubnetDoesNotExist.into())
);

let owner = U256::from(10);
pallet_subtensor::SubnetOwner::<Test>::insert(netuid, owner);
assert_eq!(
AdminUtils::sudo_set_alpha_sigmoid_steepness(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
-to_be_set
),
Err(Error::<Test>::NegativeSigmoidSteepness.into())
);
assert_eq!(
SubtensorModule::get_alpha_sigmoid_steepness(netuid),
init_value
);
assert_ok!(AdminUtils::sudo_set_alpha_sigmoid_steepness(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
));
assert_eq!(
SubtensorModule::get_alpha_sigmoid_steepness(netuid),
to_be_set
);
assert_ok!(AdminUtils::sudo_set_alpha_sigmoid_steepness(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
-to_be_set
));
assert_eq!(
SubtensorModule::get_alpha_sigmoid_steepness(netuid),
-to_be_set
);
});
}

#[test]
fn test_set_alpha_values_dispatch_info_ok() {
new_test_ext().execute_with(|| {
Expand Down
7 changes: 3 additions & 4 deletions pallets/subtensor/src/epoch/run_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,10 +1298,9 @@ impl<T: Config> Pallet<T> {
// sigmoid = 1. / (1. + e^(-steepness * (combined_diff - 0.5)))
let sigmoid = one.saturating_div(
one.saturating_add(safe_exp(
I32F32::from_num(-1).saturating_mul(
alpha_sigmoid_steepness
.saturating_mul(combined_diff.saturating_sub(I32F32::from_num(0.5))),
),
alpha_sigmoid_steepness
.saturating_div(I32F32::from_num(-100))
.saturating_mul(combined_diff.saturating_sub(I32F32::from_num(0.5))),
)),
);
let alpha =
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ pub mod pallet {
}
#[pallet::type_value]
/// Default value for alpha sigmoid steepness.
pub fn DefaultAlphaSigmoidSteepness<T: Config>() -> u16 {
pub fn DefaultAlphaSigmoidSteepness<T: Config>() -> i16 {
T::InitialAlphaSigmoidSteepness::get()
}
#[pallet::type_value]
Expand Down Expand Up @@ -1292,7 +1292,7 @@ pub mod pallet {
#[pallet::storage]
/// --- MAP ( netuid ) --> AlphaSigmoidSteepness
pub type AlphaSigmoidSteepness<T> =
StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultAlphaSigmoidSteepness<T>>;
StorageMap<_, Identity, NetUid, i16, ValueQuery, DefaultAlphaSigmoidSteepness<T>>;
#[pallet::storage]
/// --- MAP ( netuid ) --> Kappa
pub type Kappa<T> = StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultKappa<T>>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/macros/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ mod config {
type InitialRho: Get<u16>;
/// AlphaSigmoidSteepness constant.
#[pallet::constant]
type InitialAlphaSigmoidSteepness: Get<u16>;
type InitialAlphaSigmoidSteepness: Get<i16>;
/// Kappa constant.
#[pallet::constant]
type InitialKappa: Get<u16>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod events {
/// Rho value is set.
RhoSet(NetUid, u16),
/// steepness of the sigmoid used to compute alpha values.
AlphaSigmoidSteepnessSet(NetUid, u16),
AlphaSigmoidSteepnessSet(NetUid, i16),
/// Kappa is set for a subnet.
KappaSet(NetUid, u16),
/// minimum allowed weight is set for a subnet.
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,7 @@ fn setup_yuma_3_scenario(netuid: NetUid, n: u16, sparse: bool, max_stake: u64, s
SubtensorModule::set_min_allowed_weights(netuid, 1);
SubtensorModule::set_max_weight_limit(netuid, u16::MAX);
SubtensorModule::set_bonds_penalty(netuid, 0);
SubtensorModule::set_alpha_sigmoid_steepness(netuid, 10);
SubtensorModule::set_alpha_sigmoid_steepness(netuid, 1000);
SubtensorModule::set_bonds_moving_average(netuid, 975_000);

// === Register
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ parameter_types! {
pub const TransactionByteFee: Balance = 100;
pub const SDebug:u64 = 1;
pub const InitialRho: u16 = 30;
pub const InitialAlphaSigmoidSteepness: u16 = 10;
pub const InitialAlphaSigmoidSteepness: i16 = 1000;
pub const InitialKappa: u16 = 32_767;
pub const InitialTempo: u16 = 360;
pub const SelfOwnership: u64 = 2;
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/utils/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ impl<T: Config> Pallet<T> {
(converted_low, converted_high)
}

pub fn set_alpha_sigmoid_steepness(netuid: NetUid, steepness: u16) {
pub fn set_alpha_sigmoid_steepness(netuid: NetUid, steepness: i16) {
AlphaSigmoidSteepness::<T>::insert(netuid, steepness);
}
pub fn get_alpha_sigmoid_steepness(netuid: NetUid) -> I32F32 {
Expand Down
24 changes: 21 additions & 3 deletions precompiles/src/solidity/subnet.abi
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,12 @@
"type": "uint16"
}
],
"name": "getServingRateLimit",
"name": "getAlphaSigmoidSteepness",
"outputs": [
{
"internalType": "uint64",
"internalType": "uint16",
"name": "",
"type": "uint64"
"type": "uint16"
}
],
"stateMutability": "view",
Expand Down Expand Up @@ -957,6 +957,24 @@
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "netuid",
"type": "uint16"
},
{
"internalType": "uint16",
"name": "steepness",
"type": "uint16"
}
],
"name": "setAlphaSigmoidSteepness",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
Expand Down
11 changes: 10 additions & 1 deletion precompiles/src/solidity/subnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ interface ISubnet {

function setRho(uint16 netuid, uint16 rho) external payable;

function getAlphaSigmoidSteepness(
uint16 netuid
) external view returns (unt16);

function setAlphaSigmoidSteepness(
uint16 netuid,
int16 steepness
) external payable;

function getActivityCutoff(uint16 netuid) external view returns (uint16);

function setActivityCutoff(
Expand Down Expand Up @@ -174,7 +183,7 @@ interface ISubnet {
function getBondsResetEnabled(uint16 netuid) external view returns (bool);

function setBondsResetEnabled(
uint16 netuid,
uint16 netuid,
bool bondsResetEnabled
) external payable;

Expand Down
6 changes: 2 additions & 4 deletions precompiles/src/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ where
#[precompile::public("getAlphaSigmoidSteepness(uint16)")]
#[precompile::view]
fn get_alpha_sigmoid_steepness(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<u16> {
Ok(pallet_subtensor::AlphaSigmoidSteepness::<R>::get(
NetUid::from(netuid),
))
Ok(pallet_subtensor::AlphaSigmoidSteepness::<R>::get(NetUid::from(netuid)) as u16)
}

#[precompile::public("setRho(uint16,uint16)")]
Expand All @@ -422,7 +420,7 @@ where
) -> EvmResult<()> {
let call = pallet_admin_utils::Call::<R>::sudo_set_alpha_sigmoid_steepness {
netuid: netuid.into(),
steepness,
steepness: (steepness as i16),
};

handle.try_dispatch_runtime_call::<R, _>(
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = 5;
// Configure the pallet subtensor.
parameter_types! {
pub const SubtensorInitialRho: u16 = 10;
pub const SubtensorInitialAlphaSigmoidSteepness: u16 = 1000;
pub const SubtensorInitialAlphaSigmoidSteepness: i16 = 1000;
pub const SubtensorInitialKappa: u16 = 32_767; // 0.5 = 65535/2
pub const SubtensorInitialMaxAllowedUids: u16 = 4096;
pub const SubtensorInitialIssuance: u64 = 0;
Expand Down
Loading