@@ -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_(
@@ -169,10 +174,17 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
169174 CHECK (
170175 training_id_eviction_trigger_count_.has_value () &&
171176 !training_id_eviction_trigger_count_.value ().empty ());
177+ CHECK (enable_eviction_for_feature_score_eviction_policy_.has_value ());
178+ const auto & enable_eviction_vec =
179+ enable_eviction_for_feature_score_eviction_policy_.value ();
172180 const auto & vec = training_id_eviction_trigger_count_.value ();
173181 eviction_trigger_stats_log = " , training_id_eviction_trigger_count: [" ;
174182 total_id_eviction_trigger_count_ = 0 ;
175183 for (size_t i = 0 ; i < vec.size (); ++i) {
184+ if (enable_eviction_vec[i] == 0 ) {
185+ throw std::runtime_error (
186+ " ID_COUNT trigger mode doesn't not support enable_eviction=False, please use FREE_MEM trigger mode instead" );
187+ }
176188 total_id_eviction_trigger_count_ =
177189 total_id_eviction_trigger_count_.value () + vec[i];
178190 if (vec[i] <= 0 ) {
@@ -212,6 +224,7 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
212224 CHECK (threshold_calculation_bucket_stride_.has_value ());
213225 CHECK (threshold_calculation_bucket_num_.has_value ());
214226 CHECK (ttls_in_mins_.has_value ());
227+ CHECK (enable_eviction_for_feature_score_eviction_policy_.has_value ());
215228 LOG (INFO) << " eviction config, trigger mode:"
216229 << to_string (trigger_mode_) << eviction_trigger_stats_log
217230 << " , strategy: " << to_string (trigger_strategy_)
@@ -223,7 +236,9 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
223236 << " , threshold_calculation_bucket_num: "
224237 << threshold_calculation_bucket_num_.value ()
225238 << " , feature_score_counter_decay_rates: "
226- << feature_score_counter_decay_rates_.value ();
239+ << feature_score_counter_decay_rates_.value ()
240+ << " , enable_eviction_for_feature_score_eviction_policy: "
241+ << enable_eviction_for_feature_score_eviction_policy_.value ();
227242 return ;
228243 }
229244
@@ -281,6 +296,8 @@ struct FeatureEvictConfig : public torch::jit::CustomClassHolder {
281296 std::optional<std::vector<double >> feature_score_counter_decay_rates_;
282297 std::optional<std::vector<int64_t >> training_id_eviction_trigger_count_;
283298 std::optional<std::vector<int64_t >> training_id_keep_count_;
299+ std::optional<std::vector<int8_t >>
300+ enable_eviction_for_feature_score_eviction_policy_;
284301 std::optional<int64_t > total_id_eviction_trigger_count_;
285302 std::optional<std::vector<double >> l2_weight_thresholds_;
286303 std::optional<std::vector<int64_t >> embedding_dims_;
@@ -984,6 +1001,8 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
9841001 const std::vector<int64_t >& training_id_eviction_trigger_count,
9851002 const std::vector<int64_t >& training_id_keep_count,
9861003 const std::vector<int64_t >& ttls_in_mins,
1004+ const std::vector<int8_t >&
1005+ enable_eviction_for_feature_score_eviction_policy,
9871006 const double threshold_calculation_bucket_stride,
9881007 const int64_t threshold_calculation_bucket_num,
9891008 int64_t interval_for_insufficient_eviction_s,
@@ -1003,6 +1022,8 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
10031022 training_id_eviction_trigger_count_ (training_id_eviction_trigger_count),
10041023 training_id_keep_count_ (training_id_keep_count),
10051024 ttls_in_mins_ (ttls_in_mins),
1025+ enable_eviction_for_feature_score_eviction_policy_ (
1026+ enable_eviction_for_feature_score_eviction_policy),
10061027 threshold_calculation_bucket_stride_ (
10071028 threshold_calculation_bucket_stride),
10081029 num_buckets_ (threshold_calculation_bucket_num),
@@ -1071,6 +1092,13 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
10711092 protected:
10721093 bool evict_block (weight_type* block, int sub_table_id, int shard_id)
10731094 override {
1095+ int8_t enable_eviction =
1096+ enable_eviction_for_feature_score_eviction_policy_[sub_table_id];
1097+ if (enable_eviction == 0 ) {
1098+ // If enable_eviction is set to 0, we don't evict any block.
1099+ return false ;
1100+ }
1101+
10741102 double ttls_threshold = ttls_in_mins_[sub_table_id];
10751103 if (ttls_threshold > 0 ) {
10761104 auto current_time = FixedBlockPool::current_timestamp ();
@@ -1145,6 +1173,15 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
11451173
11461174 void compute_thresholds_from_buckets () {
11471175 for (size_t table_id = 0 ; table_id < num_tables_; ++table_id) {
1176+ int8_t enable_eviction =
1177+ enable_eviction_for_feature_score_eviction_policy_[table_id];
1178+ if (enable_eviction == 0 ) {
1179+ // If enable_eviction is set to 0, we don't evict any block.
1180+ thresholds_[table_id] = 0.0 ;
1181+ evict_modes_[table_id] = EvictMode::NONE;
1182+ continue ;
1183+ }
1184+
11481185 int64_t total = 0 ;
11491186
11501187 if (ttls_in_mins_[table_id] > 0 ) {
@@ -1209,7 +1246,8 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
12091246 << " threshold bucket: " << threshold_bucket
12101247 << " actual evict count: " << acc_count
12111248 << " target evict count: " << evict_count
1212- << " total count: " << total;
1249+ << " total count: " << total
1250+ << " evict mode: " << to_string (evict_modes_[table_id]);
12131251
12141252 for (int table_id = 0 ; table_id < num_tables_; ++table_id) {
12151253 this ->metrics_ .eviction_threshold_with_dry_run [table_id] =
@@ -1226,6 +1264,16 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
12261264 THRESHOLD // blocks with scores below the computed threshold will be
12271265 // evicted
12281266 };
1267+ inline std::string to_string (EvictMode mode) {
1268+ switch (mode) {
1269+ case EvictMode::NONE:
1270+ return " NONE" ;
1271+ case EvictMode::ONLY_ZERO:
1272+ return " ONLY_ZERO" ;
1273+ case EvictMode::THRESHOLD:
1274+ return " THRESHOLD" ;
1275+ }
1276+ }
12291277 std::vector<EvictMode> evict_modes_;
12301278
12311279 const int num_tables_ = static_cast <int >(this ->sub_table_hash_cumsum_.size());
@@ -1240,6 +1288,7 @@ class FeatureScoreBasedEvict : public FeatureEvict<weight_type> {
12401288 // eviction.
12411289
12421290 const std::vector<int64_t >& ttls_in_mins_; // Time-to-live for eviction.
1291+ const std::vector<int8_t >& enable_eviction_for_feature_score_eviction_policy_;
12431292 std::vector<std::vector<std::vector<size_t >>>
12441293 local_buckets_per_shard_per_table_;
12451294 std::vector<std::vector<size_t >> local_blocks_num_per_shard_per_table_;
@@ -1489,6 +1538,7 @@ std::unique_ptr<FeatureEvict<weight_type>> create_feature_evict(
14891538 config->training_id_eviction_trigger_count_ .value (),
14901539 config->training_id_keep_count_ .value (),
14911540 config->ttls_in_mins_ .value (),
1541+ config->enable_eviction_for_feature_score_eviction_policy_ .value (),
14921542 config->threshold_calculation_bucket_stride_ .value (),
14931543 config->threshold_calculation_bucket_num_ .value (),
14941544 config->interval_for_insufficient_eviction_s_ ,
0 commit comments