特征准入与淘汰
使用流程介绍
本节介绍如何使用特征准入与淘汰进行训练,涉及FeatureSpec模式与自动改图模式。

开启淘汰功能后,不支持片上内存侧动态扩容。
图1 特征准入与淘汰使用流程

关键步骤介绍
- 在FeatureSpec模式下,请参考FeatureSpec进行配置。
- 在自动改图模式下,请参考自动改图进行配置。
- 环境变量USE_COMBINE_FAAE控制是否合表统计次数。
- 提供一个CPU算子set_threshold支持在训练过程中更改准入阈值。
如果set_threshold的第一个入参值为“0”,表示修改对应的emb表为特征不累加模式(准入阈值不变,但是特征计数不再累加,使用历史值)。
示例代码
- FeatureSpec模式。
1 2 3 4 5 6 7 8 9
feature_spec_list = [FeatureSpec("user_ids", feat_count=cfg.user_feat_cnt, table_name="user_table", access_threshold=access_threshold, eviction_threshold=eviction_threshold, faae_coefficient=1), FeatureSpec("item_ids", feat_count=cfg.item_feat_cnt, table_name="item_table", access_threshold=access_threshold, eviction_threshold=eviction_threshold, faae_coefficient=4), FeatureSpec("timestamp", is_timestamp=True)]
hook_evict = EvictHook(evict_enable=True, evict_time_interval=24*60*60, evict_step_interval=10000)
- 自动改图模式。
config_for_user_table = dict(access_threshold=cfg.access_threshold, eviction_threshold=cfg.eviction_threshold, faae_coefficient=1)
embedding = sparse_lookup(hash_table, feature, send_count, dim=None, is_train=is_train, access_and_evict_config=config_for_user_table , name=hash_table.table_name + "_lookup", modify_graph=modify_graph) hook_evict = EvictHook(evict_enable=True, evict_time_interval=24*60*60, evict_step_interval=10000)
- 更改准入阈值。
1 2 3 4 5 6 7
from mx_rec.util.ops import import_host_pipeline_ops thres_tensor = tf.constant(60, dtype=tf.int32) set_threshold_op = import_host_pipeline_ops().set_threshold(thres_tensor, emb_name=self.table_list[0].table_name, ids_name=self.table_list[0].table_name + "_lookup") with tf.Session() as sess: sess.run(set_threshold_op)
父主题: 训练功能特性流程