@@ -110,6 +110,9 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
110110 std::optional<std::vector<double >> feature_score_counter_decay_rates,
111111 std::optional<std::vector<int64_t >> training_id_eviction_trigger_count,
112112 std::optional<std::vector<int64_t >> training_id_keep_count,
113+ std::optional<std::vector<int8_t >>
114+ enable_eviction_for_feature_score_eviction_policy, // 0: no eviction,
115+ // 1: evict
113116 std::optional<std::vector<double >> l2_weight_thresholds,
114117 std::optional<std::vector<int64_t >> embedding_dims,
115118 std::optional<double > threshold_calculation_bucket_stride = 0.2 ,
@@ -129,6 +132,8 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
129132 training_id_eviction_trigger_count_(
130133 std::move (training_id_eviction_trigger_count)),
131134 training_id_keep_count_(std::move(training_id_keep_count)),
135+ enable_eviction_for_feature_score_eviction_policy_(
136+ std::move (enable_eviction_for_feature_score_eviction_policy)),
132137 l2_weight_thresholds_(l2_weight_thresholds),
133138 embedding_dims_(embedding_dims),
134139 threshold_calculation_bucket_stride_(
@@ -212,6 +217,7 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
212217 CHECK (threshold_calculation_bucket_stride_.has_value ());
213218 CHECK (threshold_calculation_bucket_num_.has_value ());
214219 CHECK (ttls_in_mins_.has_value ());
220+ CHECK (enable_eviction_for_feature_score_eviction_policy_.has_value ());
215221 LOG (INFO) << " eviction config, trigger mode:"
216222 << to_string (trigger_mode_) << eviction_trigger_stats_log
217223 << " , strategy: " << to_string (trigger_strategy_)
@@ -223,7 +229,9 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
223229 << " , threshold_calculation_bucket_num: "
224230 << threshold_calculation_bucket_num_.value ()
225231 << " , feature_score_counter_decay_rates: "
226- << feature_score_counter_decay_rates_.value ();
232+ << feature_score_counter_decay_rates_.value ()
233+ << " , enable_eviction_for_feature_score_eviction_policy: "
234+ << enable_eviction_for_feature_score_eviction_policy_.value ();
227235 return ;
228236 }
229237
@@ -281,6 +289,8 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
281289 std::optional<std::vector<double >> feature_score_counter_decay_rates_;
282290 std::optional<std::vector<int64_t >> training_id_eviction_trigger_count_;
283291 std::optional<std::vector<int64_t >> training_id_keep_count_;
292+ std::optional<std::vector<int8_t >>
293+ enable_eviction_for_feature_score_eviction_policy_;
284294 std::optional<int64_t > total_id_eviction_trigger_count_;
285295 std::optional<std::vector<double >> l2_weight_thresholds_;
286296 std::optional<std::vector<int64_t >> embedding_dims_;
@@ -984,6 +994,8 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
984994 const std::vector<int64_t >& training_id_eviction_trigger_count,
985995 const std::vector<int64_t >& training_id_keep_count,
986996 const std::vector<int64_t >& ttls_in_mins,
997+ const std::vector<int8_t >&
998+ enable_eviction_for_feature_score_eviction_policy,
987999 const double threshold_calculation_bucket_stride,
9881000 const int64_t threshold_calculation_bucket_num,
9891001 int64_t interval_for_insufficient_eviction_s,
@@ -1003,6 +1015,8 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
10031015 training_id_eviction_trigger_count_ (training_id_eviction_trigger_count),
10041016 training_id_keep_count_ (training_id_keep_count),
10051017 ttls_in_mins_ (ttls_in_mins),
1018+ enable_eviction_for_feature_score_eviction_policy_ (
1019+ enable_eviction_for_feature_score_eviction_policy),
10061020 threshold_calculation_bucket_stride_ (
10071021 threshold_calculation_bucket_stride),
10081022 num_buckets_ (threshold_calculation_bucket_num),
@@ -1071,6 +1085,13 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
10711085 protected:
10721086 bool evict_block (weight_type* block, int sub_table_id, int shard_id)
10731087 override {
1088+ int8_t enable_eviction =
1089+ enable_eviction_for_feature_score_eviction_policy_[sub_table_id];
1090+ if (enable_eviction == 0 ) {
1091+ // If enable_eviction is set to 0, we don't evict any block.
1092+ return false ;
1093+ }
1094+
10741095 double ttls_threshold = ttls_in_mins_[sub_table_id];
10751096 if (ttls_threshold > 0 ) {
10761097 auto current_time = FixedBlockPool::current_timestamp ();
@@ -1145,6 +1166,15 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
11451166
11461167 void compute_thresholds_from_buckets () {
11471168 for (size_t table_id = 0 ; table_id < num_tables_; ++table_id) {
1169+ int8_t enable_eviction =
1170+ enable_eviction_for_feature_score_eviction_policy_[table_id];
1171+ if (enable_eviction == 0 ) {
1172+ // If enable_eviction is set to 0, we don't evict any block.
1173+ thresholds_[table_id] = 0.0 ;
1174+ evict_modes_[table_id] = EvictMode::NONE;
1175+ continue ;
1176+ }
1177+
11481178 int64_t total = 0 ;
11491179
11501180 if (ttls_in_mins_[table_id] > 0 ) {
@@ -1209,7 +1239,8 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
12091239 << " threshold bucket: " << threshold_bucket
12101240 << " actual evict count: " << acc_count
12111241 << " target evict count: " << evict_count
1212- << " total count: " << total;
1242+ << " total count: " << total
1243+ << " evict mode: " << to_string (evict_modes_[table_id]);
12131244
12141245 for (int table_id = 0 ; table_id < num_tables_; ++table_id) {
12151246 this ->metrics_ .eviction_threshold_with_dry_run [table_id] =
@@ -1226,6 +1257,16 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
12261257 THRESHOLD // blocks with scores below the computed threshold will be
12271258 // evicted
12281259 };
1260+ inline std::string to_string (EvictMode mode) {
1261+ switch (mode) {
1262+ case EvictMode::NONE:
1263+ return " NONE" ;
1264+ case EvictMode::ONLY_ZERO:
1265+ return " ONLY_ZERO" ;
1266+ case EvictMode::THRESHOLD:
1267+ return " THRESHOLD" ;
1268+ }
1269+ }
12291270 std::vector<EvictMode> evict_modes_;
12301271
12311272 const int num_tables_ = static_cast <int >(this ->sub_table_hash_cumsum_.size());
@@ -1240,6 +1281,7 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
12401281 // eviction.
12411282
12421283 const std::vector<int64_t >& ttls_in_mins_; // Time-to-live for eviction.
1284+ const std::vector<int8_t >& enable_eviction_for_feature_score_eviction_policy_;
12431285 std::vector<std::vector<std::vector<size_t >>>
12441286 local_buckets_per_shard_per_table_;
12451287 std::vector<std::vector<size_t >> local_blocks_num_per_shard_per_table_;
@@ -1489,6 +1531,7 @@ std::unique_ptr<FeatureEvict<weight_type>> create_feature_evict(
14891531 config->training_id_eviction_trigger_count_ .value (),
14901532 config->training_id_keep_count_ .value (),
14911533 config->ttls_in_mins_ .value (),
1534+ config->enable_eviction_for_feature_score_eviction_policy_ .value (),
14921535 config->threshold_calculation_bucket_stride_ .value (),
14931536 config->threshold_calculation_bucket_num_ .value (),
14941537 config->interval_for_insufficient_eviction_s_ ,
0 commit comments