Skip to content

Commit

Permalink
Fix edge case of empty embedding tables
Browse files Browse the repository at this point in the history
Summary:
ATT
Currently python interface for fbgemm doesn't support grouped embedding tables with all empty rows, due to the hash size calculation (log(0)). This just adds a special case for they're all empty, set hash_size_cumsum to be zero.

Should be pretty low risk as currently no one uses this module that hits that conditional.

Reviewed By: colin2328, xing-liu

Differential Revision: D32514857

fbshipit-source-id: a0cd1d282c8f48ebe8cd390b6a4bca227a79fdf1
  • Loading branch information
YLGH authored and facebook-github-bot committed Dec 14, 2021
1 parent a65f189 commit c036c4f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions fbgemm_gpu/fbgemm_gpu/split_table_batched_embeddings_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ def __init__( # noqa C901
)

hash_size_cumsum = [0] + list(accumulate(rows))
self.total_hash_size_bits = int(log2(float(hash_size_cumsum[-1])) + 1)
if hash_size_cumsum[-1] == 0:
self.total_hash_size_bits: int = 0
else:
self.total_hash_size_bits: int = int(log2(float(hash_size_cumsum[-1])) + 1)
# The last element is to easily access # of rows of each table by
# hash_size_cumsum[t + 1] - hash_size_cumsum[t]
hash_size_cumsum = [hash_size_cumsum[t] for t in self.feature_table_map] + [
Expand Down Expand Up @@ -1362,7 +1365,10 @@ def __init__(
assert self.D_offsets.numel() == T + 1

hash_size_cumsum = [0] + list(accumulate(rows))
self.total_hash_size_bits = int(log2(float(hash_size_cumsum[-1])) + 1)
if hash_size_cumsum[-1] == 0:
self.total_hash_size_bits: int = 0
else:
self.total_hash_size_bits: int = int(log2(float(hash_size_cumsum[-1])) + 1)
# The last element is to easily access # of rows of each table by
# hash_size_cumsum[t + 1] - hash_size_cumsum[t]
hash_size_cumsum = [hash_size_cumsum[t] for t in feature_table_map] + [
Expand Down

0 comments on commit c036c4f

Please sign in to comment.