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
5 changes: 5 additions & 0 deletions corelib/dynamicemb/dynamicemb/batched_dynamicemb_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,9 @@ def _create_score(self):
self._scores[table_name] = 1
elif option.score_strategy == DynamicEmbScoreStrategy.CUSTOMIZED:
option.evict_strategy = DynamicEmbEvictStrategy.CUSTOMIZED
elif option.score_strategy == DynamicEmbScoreStrategy.LFU:
option.evict_strategy = DynamicEmbEvictStrategy.LFU
self._scores[table_name] = 1

def _update_score(self):
for table_name, option in zip(self._table_names, self._dynamicemb_options):
Expand All @@ -689,6 +692,8 @@ def _update_score(self):
self._scores[table_name] = 0
else:
self._scores[table_name] = new_score
elif option.score_strategy == DynamicEmbScoreStrategy.LFU:
self._scores[table_name] = 1

def incremental_dump(
self,
Expand Down
1 change: 1 addition & 0 deletions corelib/dynamicemb/dynamicemb/dynamicemb_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class DynamicEmbScoreStrategy(enum.IntEnum):
TIMESTAMP = 0
STEP = 1
CUSTOMIZED = 2
LFU = 3


# Configs used as keys to group HKV variables(considering kernel behaviors, result type).
Expand Down
18 changes: 9 additions & 9 deletions corelib/dynamicemb/src/dynamic_emb_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ void insert_and_evict(
bool unique_key = true,
bool ignore_evict_strategy = false) {

if (not score and table->evict_strategy() == EvictStrategy::kCustomized) {
throw std::invalid_argument("Must specify the score when evict strategy is customized.");
if (not score and (table->evict_strategy() == EvictStrategy::kCustomized || table->evict_strategy() == EvictStrategy::kLfu)) {
throw std::invalid_argument("Must specify the score when evict strategy is customized or LFU.");
}
auto stream = at::cuda::getCurrentCUDAStream().stream();
if (table->evict_strategy() == EvictStrategy::kCustomized) {
if (table->evict_strategy() == EvictStrategy::kCustomized || table->evict_strategy() == EvictStrategy::kLfu) {
auto&& option = at::TensorOptions().dtype(at::kUInt64).device(keys.device());
// broadcast scores
at::Tensor bc_scores = at::empty({static_cast<int64_t>(n)}, option);
Expand Down Expand Up @@ -188,8 +188,8 @@ void find_or_insert(std::shared_ptr<dyn_emb::DynamicVariableBase> table,
bool ignore_evict_strategy = false
)
{
if (not score and table->evict_strategy() == EvictStrategy::kCustomized) {
throw std::invalid_argument("Must specify the score when evict strategy is customized.");
if (not score and (table->evict_strategy() == EvictStrategy::kCustomized || table->evict_strategy() == EvictStrategy::kLfu)) {
throw std::invalid_argument("Must specify the score when evict strategy is customized or LFU.");
}
if (n == 0) return;
auto stream = at::cuda::getCurrentCUDAStream().stream();
Expand All @@ -203,7 +203,7 @@ void find_or_insert(std::shared_ptr<dyn_emb::DynamicVariableBase> table,

auto found_tensor_data_ptr = found_tensor.data_ptr<bool>();

if (table->evict_strategy() == EvictStrategy::kCustomized) {
if (table->evict_strategy() == EvictStrategy::kCustomized || table->evict_strategy() == EvictStrategy::kLfu) {
auto&& option = at::TensorOptions().dtype(at::kUInt64).device(keys.device());
// broadcast scores
at::Tensor bc_scores = at::empty({static_cast<int64_t>(n)}, option);
Expand All @@ -226,15 +226,15 @@ void find_or_insert_pointers(
const std::optional<uint64_t> score = std::nullopt,
bool unique_key = true,
bool ignore_evict_strategy = false) {
if (not score and table->evict_strategy() == EvictStrategy::kCustomized) {
throw std::invalid_argument("Must specify the score when evict strategy is customized.");
if (not score and (table->evict_strategy() == EvictStrategy::kCustomized || table->evict_strategy() == EvictStrategy::kLfu)) {
throw std::invalid_argument("Must specify the score when evict strategy is customized or LFU.");
}
if (n == 0) return;
auto stream = at::cuda::getCurrentCUDAStream().stream();
auto values_data_ptr = reinterpret_cast<void**>(values.data_ptr<int64_t>());
auto found_tensor_data_ptr = founds.data_ptr<bool>();

if (table->evict_strategy() == EvictStrategy::kCustomized) {
if (table->evict_strategy() == EvictStrategy::kCustomized || table->evict_strategy() == EvictStrategy::kLfu) {
auto&& option = at::TensorOptions().dtype(at::kUInt64).device(keys.device());
// broadcast scores
at::Tensor bc_scores = at::empty({static_cast<int64_t>(n)}, option);
Expand Down
1 change: 1 addition & 0 deletions corelib/dynamicemb/src/dynamic_variable_base.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ std::shared_ptr<DynamicVariableBase> VariableFactory::create(
const OptimizerType optimizer_type = OptimizerType::Null) {
// TODO:check input datetype , now only support key type is int64_t uint64_t ,
// value type float
printf("create dynamic variable base\n");
std::shared_ptr<DynamicVariableBase> table;
DISPATCH_INTEGER_DATATYPE_FUNCTION(key_type, key_t, [&] {
DISPATCH_FLOAT_DATATYPE_FUNCTION(value_type, value_t, [&] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include"hkv_variable.cuh"
namespace dyn_emb{
template class HKVVariable<int64_t, __half, EvictStrategy::kLfu>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include"hkv_variable.cuh"
namespace dyn_emb{
template class HKVVariable<int64_t, __nv_bfloat16, EvictStrategy::kLfu>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include"hkv_variable.cuh"
namespace dyn_emb{
template class HKVVariable<int64_t, float, EvictStrategy::kLfu>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include"hkv_variable.cuh"
namespace dyn_emb{
template class HKVVariable<uint64_t, __half, EvictStrategy::kLfu>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include"hkv_variable.cuh"
namespace dyn_emb{
template class HKVVariable<uint64_t, __nv_bfloat16, EvictStrategy::kLfu>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include"hkv_variable.cuh"
namespace dyn_emb{
template class HKVVariable<uint64_t, float, EvictStrategy::kLfu>;
}
1 change: 1 addition & 0 deletions corelib/dynamicemb/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ enum class EvictStrategy : uint32_t {
switch (EVICT_TYPE) { \
CASE_ENUM_USING_HINT(EvictStrategy::kLru, HINT, __VA_ARGS__) \
CASE_ENUM_USING_HINT(EvictStrategy::kCustomized, HINT, __VA_ARGS__) \
CASE_ENUM_USING_HINT(EvictStrategy::kLfu, HINT, __VA_ARGS__) \
default: \
exit(EXIT_FAILURE); \
}
Expand Down
Loading