From 0734cdadb150b64e34617900d30f9f9813552b64 Mon Sep 17 00:00:00 2001 From: saiintbrisson Date: Sat, 20 Apr 2024 16:49:33 +0000 Subject: [PATCH] Revert "wip" This reverts commit 4ebda2a24725c5c234172d360a2e594f83f5484c. --- pallets/subspace/src/step/yuma.rs | 74 ++++++++++--------------------- 1 file changed, 24 insertions(+), 50 deletions(-) diff --git a/pallets/subspace/src/step/yuma.rs b/pallets/subspace/src/step/yuma.rs index a353e6995..5bd4cdf6d 100644 --- a/pallets/subspace/src/step/yuma.rs +++ b/pallets/subspace/src/step/yuma.rs @@ -80,24 +80,19 @@ impl YumaCalc { (is_inactive, !is_inactive) }) .unzip(); - log::warn!("Inactive: {inactive:?}"); - log::warn!("Active: {active:?}"); + log::trace!("Inactive: {inactive:?}"); + log::trace!("Active: {active:?}"); let mut weights = self.compute_weights(); - log::warn!("final weights: {weights:?}"); - let stake = self.compute_stake()?; - log::warn!("final stake: {stake:?}"); let new_permits: Vec = if let Some(max) = self.max_allowed_validators { is_topk(stake.as_ref(), max as usize) } else { vec![true; stake.as_ref().len()] }; - log::warn!("new permis: {new_permits:?}"); let active_stake = self.compute_active_stake(&inactive, &stake); - log::warn!("final active stake: {active_stake:?}"); let ConsensusAndTrust { consensus, @@ -266,17 +261,17 @@ impl YumaCalc { fn compute_weights(&self) -> WeightsVal { // Access network weights row unnormalized. let mut weights = Pallet::::get_weights_sparse(self.netuid); - log::warn!(" original weights: {weights:?}"); + log::trace!("W: {weights:?}"); if self.max_allowed_validators.is_some() { // Mask weights that are not from permitted validators. weights = mask_rows_sparse(&self.validator_forbids, &weights); - log::warn!(" no forbidden validator weights: {weights:?}"); + log::trace!("W (permit): {weights:?}"); } // Remove self-weight by masking diagonal. weights = mask_diag_sparse(&weights); - log::warn!(" no self-weight weights: {weights:?}"); + log::trace!("W (permit+diag): {weights:?}"); // Remove weights referring to deregistered modules. weights = vec_mask_sparse_matrix( @@ -285,11 +280,9 @@ impl YumaCalc { &self.block_at_registration, |updated, registered| updated <= registered, ); - log::warn!(" no deregistered modules weights: {weights:?}"); - + log::trace!("W (permit+diag+outdate): {weights:?}"); // Normalize remaining weights. inplace_row_normalize_sparse(&mut weights); - log::warn!(" normalized weights: {weights:?}"); WeightsVal::unchecked_from_inner(weights) } @@ -302,11 +295,10 @@ impl YumaCalc { stake.len() == self.module_count as usize, "unequal number of stakes and modules" ); - log::warn!(" original stake: {stake:?}"); inplace_normalize_64(&mut stake); - log::warn!(" normalized stake: {stake:?}"); + log::trace!("S: {:?}", &stake); Ok(StakeVal::unchecked_from_inner(vec_fixed64_to_fixed32( stake, ))) // range: I32F32(0, 1) @@ -314,21 +306,17 @@ impl YumaCalc { fn compute_active_stake(&self, inactive: &[bool], stake: &StakeVal) -> ActiveStake { let mut active_stake = stake.as_ref().clone(); - log::warn!(" original active stake: {active_stake:?}"); // Remove inactive stake. inplace_mask_vector(inactive, &mut active_stake); - log::warn!(" no inactive active stake: {active_stake:?}"); if self.max_allowed_validators.is_some() { // Remove non-validator stake. inplace_mask_vector(&self.validator_forbids, &mut active_stake); - log::warn!(" no non-validator active stake: {active_stake:?}"); } // Normalize active stake. inplace_normalize(&mut active_stake); - log::warn!(" normalized active stake: {active_stake:?}"); ActiveStake::unchecked_from_inner(active_stake) } @@ -338,6 +326,10 @@ impl YumaCalc { weights: &mut WeightsVal, active_stake: &ActiveStake, ) -> ConsensusAndTrust { + // Compute preranks: r_j = SUM(i) w_ij * s_i + let preranks = matmul_sparse(weights.as_ref(), active_stake.as_ref(), self.module_count); + log::trace!("R (before): {:?}", &preranks); + // Clip weights at majority consensus let consensus = weighted_median_col_sparse( active_stake.as_ref(), @@ -345,17 +337,12 @@ impl YumaCalc { self.module_count, self.kappa, ); - log::warn!("final consensus: {consensus:?}"); - + log::trace!("C: {:?}", &consensus); *weights = WeightsVal::unchecked_from_inner(col_clip_sparse(weights.as_ref(), &consensus)); - log::warn!("final consensus weights: {weights:?}"); - - // Compute preranks: r_j = SUM(i) w_ij * s_i - let preranks = matmul_sparse(weights.as_ref(), active_stake.as_ref(), self.module_count); - log::warn!("final preranks: {preranks:?}"); + log::trace!("W: {:?}", &weights); let validator_trust = row_sum_sparse(weights.as_ref()); - log::warn!("final validator trust: {validator_trust:?}"); + log::trace!("Tv: {:?}", &validator_trust); ConsensusAndTrust { consensus: ConsensusVal::unchecked_from_inner(consensus), @@ -372,17 +359,15 @@ impl YumaCalc { ) -> IncentivesAndTrust { // Compute ranks: r_j = SUM(i) w_ij * s_i. let ranks = matmul_sparse(weights.as_ref(), active_stake.as_ref(), self.module_count); - log::warn!("final ranks: {ranks:?}"); + log::trace!("R (after): {:?}", &ranks); // Compute server trust: ratio of rank after vs. rank before. let trust = vecdiv(&ranks, preranks.as_ref()); // range: I32F32(0, 1) - log::warn!("final trust: {ranks:?}"); + log::trace!("T: {:?}", &trust); let mut incentives = ranks.clone(); - log::warn!(" original incentives: {incentives:?}"); - inplace_normalize(&mut incentives); // range: I32F32(0, 1) - log::warn!(" normalized incentives: {incentives:?}"); + log::trace!("I (=R): {:?}", &incentives); IncentivesAndTrust { incentives: IncentivesVal::unchecked_from_inner(incentives), @@ -399,7 +384,7 @@ impl YumaCalc { ) -> BondsAndDividends { // Access network bonds. let mut bonds = Pallet::::get_bonds_sparse(self.netuid); - log::warn!(" original bonds: {bonds:?}"); + log::trace!("B: {:?}", &bonds); // Remove bonds referring to deregistered modules. bonds = vec_mask_sparse_matrix( @@ -408,43 +393,38 @@ impl YumaCalc { &self.block_at_registration, |updated, registered| updated <= registered, ); - log::warn!(" no deregistered modules bonds: {bonds:?}"); + log::trace!("B (outdatedmask): {:?}", &bonds); // Normalize remaining bonds: sum_i b_ij = 1. inplace_col_normalize_sparse(&mut bonds, self.module_count); - log::warn!(" normalized bonds: {bonds:?}"); + log::trace!("B (mask+norm): {:?}", &bonds); // Compute bonds delta column normalized. let mut bonds_delta = row_hadamard_sparse(weights.as_ref(), active_stake.as_ref()); // ΔB = W◦S (outdated W masked) - log::warn!(" original bonds delta: {bonds_delta:?}"); + log::trace!("ΔB: {:?}", &bonds_delta); // Normalize bonds delta. inplace_col_normalize_sparse(&mut bonds_delta, self.module_count); // sum_i b_ij = 1 - log::warn!(" normalized bonds delta: {bonds_delta:?}"); + log::trace!("ΔB (norm): {:?}", &bonds_delta); // Compute bonds moving average. let bonds_moving_average = I64F64::from_num(BondsMovingAverage::::get(self.netuid)) / I64F64::from_num(1_000_000); - log::warn!(" bonds moving average: {bonds_moving_average}"); let alpha = I32F32::from_num(1) - I32F32::from_num(bonds_moving_average); let mut ema_bonds = mat_ema_sparse(&bonds_delta, &bonds, alpha); - log::warn!(" original ema bonds: {ema_bonds:?}"); // Normalize EMA bonds. inplace_col_normalize_sparse(&mut ema_bonds, self.module_count); // sum_i b_ij = 1 - log::warn!(" normalized ema bonds: {ema_bonds:?}"); + log::trace!("emaB: {:?}", &ema_bonds); // Compute dividends: d_i = SUM(j) b_ij * inc_j. // range: I32F32(0, 1) let mut dividends = matmul_transpose_sparse(&ema_bonds, incentives.as_ref()); - log::warn!(" original dividends: {dividends:?}"); - inplace_normalize(&mut dividends); - log::warn!(" normalized dividends: {dividends:?}"); + log::trace!("D: {:?}", ÷nds); // Column max-upscale EMA bonds for storage: max_i w_ij = 1. inplace_col_max_upscale_sparse(&mut ema_bonds, self.module_count); - log::warn!(" upscaled ema bonds: {ema_bonds:?}"); BondsAndDividends { ema_bonds, @@ -469,13 +449,10 @@ impl YumaCalc { .zip(dividends.as_ref().iter()) .map(|(ii, di)| ii + di) .collect(); - log::warn!(" original combined emissions: {combined_emission:?}"); let emission_sum: I32F32 = combined_emission.iter().sum(); - log::warn!(" emission sum: {emission_sum:?}"); let mut normalized_server_emission = incentives.as_ref().clone(); // Servers get incentive. inplace_normalize_using_sum(&mut normalized_server_emission, emission_sum); - log::warn!(" normalized server emissions: {normalized_server_emission:?}"); let normalized_validator_emission: Cow<'a, [I32F32]>; let normalized_combined_emission: Cow<'a, [I32F32]>; @@ -511,14 +488,12 @@ impl YumaCalc { .map(|&se| I96F32::from_num(se) * to_be_emitted) .map(I96F32::to_num) .collect(); - log::warn!(" server emissions: {server_emissions:?}"); let validator_emissions: Vec = normalized_validator_emission .iter() .map(|&ve| I96F32::from_num(ve) * to_be_emitted) .map(I96F32::to_num) .collect(); - log::warn!(" validator_emissions: {validator_emissions:?}"); // Only used to track emission in storage. let combined_emissions: Vec = normalized_combined_emission @@ -526,7 +501,6 @@ impl YumaCalc { .map(|&ce| I96F32::from_num(ce) * to_be_emitted) .map(I96F32::to_num) .collect(); - log::warn!(" combined_emissions: {combined_emissions:?}"); log::trace!("nSE: {:?}", &normalized_server_emission); log::trace!("SE: {:?}", &server_emissions);