Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add new setting num_of_buckets_per_alloc from HKV bata 12. #433

Merged
merged 2 commits into from
Jun 17, 2024
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
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ http_archive(
http_archive(
name = "hkv",
build_file = "//build_deps/toolchains/hkv:hkv.BUILD",
sha256 = "0535477e7cd82affa940468647c07caacd54d42a2c775cfdf199b3aa6e4f87a6",
strip_prefix = "HierarchicalKV-0.1.0-beta.11",
url = "https://github.com/NVIDIA-Merlin/HierarchicalKV/archive/refs/tags/v0.1.0-beta.11.tar.gz",
sha256 = "a73d7bea159173db2038f7c5215a7d1fbd5362adfb232fabde206dc64a1e817c",
strip_prefix = "HierarchicalKV-0.1.0-beta.12",
url = "https://github.com/NVIDIA-Merlin/HierarchicalKV/archive/refs/tags/v0.1.0-beta.12.tar.gz",
)

tf_configure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ def embedding_out_split(embedding_out_concat, input_split_dims):
return embedding_out


class Bucketize(tf.keras.layers.Layer):
Copy link
Member

@rhdong rhdong Jun 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks unused

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def __init__(self, boundaries, **kwargs):
self.boundaries = boundaries
super(Bucketize, self).__init__(**kwargs)

def build(self, input_shape):
# Be sure to call this somewhere!
super(Bucketize, self).build(input_shape)

def call(self, x, **kwargs):
return tf.raw_ops.Bucketize(input=x, boundaries=self.boundaries)

def get_config(self,):
config = {'boundaries': self.boundaries}
base_config = super(Bucketize, self).get_config()
return dict(list(base_config.items()) + list(config.items()))


class ChannelEmbeddingLayers(tf.keras.layers.Layer):

def __init__(self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,20 @@ class TableWrapper {
}
step_per_epoch_ = init_options.step_per_epoch;
mkv_options_.reserved_key_start_bit = init_options.reserved_key_start_bit;
static constexpr size_t default_chunk_buckets = 512;
size_t min_chunk_buckets = 1;
for (size_t pow_n = 1; pow_n <= 63; ++pow_n) {
if (mkv_options_.max_bucket_size * (1 << pow_n) >
mkv_options_.init_capacity) {
min_chunk_buckets = 1 << (pow_n - 1);
break;
}
}
mkv_options_.num_of_buckets_per_alloc =
mkv_options_.init_capacity >
(mkv_options_.max_bucket_size * default_chunk_buckets)
? default_chunk_buckets
: min_chunk_buckets;
curr_epoch_ = 0;
curr_step_ = 1;

Expand Down
Loading