Skip to content

fix(dynamicemb): keep each table's local_hbm_for_values budget in fused groups - #534

Merged
jiashuy merged 3 commits into
NVIDIA:mainfrom
tiankongdeguiji:fix/per-table-hbm-budget
Nov 9, 2026
Merged

jiashuy merged 3 commits into
NVIDIA:mainfrom
tiankongdeguiji:fix/per-table-hbm-budget

Conversation

@tiankongdeguiji

Copy link
Copy Markdown
Contributor

Summary

The fused-module HBM split used one ratio — sum(local_hbm_for_values) / sum(value bytes) — applied to every table of the group, so a planner allocation of 10% / 90% became 50% / 50% after fusion.

  • _create_cache_storage: when a fused group does not fit its summed budget, each table now keeps min(1, its own budget / its own bytes) of its rows in HBM, in both the caching and the hybrid layout. The layout decision itself is unchanged and still taken for the group on the sums — a group whose rows fit the summed budget is still HBM-only — so table fusion is preserved.
  • create_table_state placed the whole group's value buffers on the host whenever options[0].local_hbm_for_values == 0; it now does so only when every table's budget is zero, so a table with a budget is not moved to host memory by an unrelated groupmate.
  • get_group_value_bytes_by_tier (the planner's mirror of that runtime) now reports sum(min(bytes_i, budget_i)) as HBM when the group does not fit, instead of the summed budget. Charging the summed budget understated the host tier by whatever budget one table could not spend on its own rows — the unsafe direction for plan approval.

Behavior change

A table whose budget exceeds its size no longer lends the spare to groupmates once the group does not fit; a table left at the default budget of 0 keeps the one-bucket floor. A group that does fit its summed budget is unaffected (still HBM-only), which is the case where covering a groupmate still happens.

Tests

  • New test/unit_tests/test_per_table_hbm_budget.py (registered in test/unit_test.sh): per-table shares in CACHING and HYBRID, the zero-budget groupmate, and the group-level HBM-only fit. Every case fails on the previous code (both tables get the same 26624-row share instead of 4096 / 49152, and HBM rows land in host buffers).
  • test_planner_plan_cost.py: the lending tests moved to the fits-its-budget case; new tests pin the 10% / 90% split and the no-lending-when-it-does-not-fit case.
  • All green on 4x A10 with the extension built from this branch:
    • test_per_table_hbm_budget.py + test_planner_plan_cost.py + test_planner_placement.py: 89 passed
    • test_no_eviction_row_indexing.py + test_expansion_value_capacity.py: 35 passed
    • test_batched_dynamic_embedding_tables_v2.py: 390 passed, 4 skipped
    • test_hybrid_storage_export.sh: 17 passed
    • test_alignment.py at world sizes 1 and 4: 1200 passed, 240 skipped each
    • test_table_row_wise.sh: all 11 configurations (2- and 4-GPU)

Note: the runtime hunks here are identical to ones that also landed on feat/global-bucket-layout (b9ca916) while this change was being prepared; whichever merges first, the other reconciles without conflict.

🤖 Generated with Claude Code

The fused-module HBM split used one ratio, sum(local_hbm_for_values) /
sum(value bytes), applied to every table of the group, so a planner
allocation of 10%/90% became 50%/50% after fusion. When a fused group
does not fit its summed budget, each table now keeps min(1, its own
budget / its own bytes) of its rows in HBM, in both the caching and the
hybrid layout. The layout decision itself is unchanged and still taken
for the group on the sums: a group whose rows fit the summed budget is
HBM-only, so table fusion is preserved.

create_table_state placed the whole group's value buffers on the host
whenever options[0] had no budget; it now takes the host only when every
table's budget is zero, so a table with a budget is not moved to host
memory by an unrelated groupmate.

get_group_value_bytes_by_tier, the planner's mirror of that runtime, now
reports sum(min(bytes_i, budget_i)) as HBM when the group does not fit.
Charging the summed budget under-stated the host tier by whatever one
table could not spend on its own rows -- the unsafe direction for plan
approval.

A table whose budget exceeds its size no longer lends the spare to
groupmates in a splitting group; a table left at the default budget of 0
keeps the one-bucket floor.

Co-Authored-By: Claude Code <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The changes affect DynamicEmb memory allocation and planning for workloads that use fused tables.

Fix the per-table cache overflow path and the outstanding minimum-bucket estimate before merging.

Findings

  1. P1 Small caches lose batch rows ▶
  2. P1 Planner misses minimum buckets ▶

Summary

Keeps each fused table's own HBM share when the group does not fit entirely in HBM.

  • Fused tables keep their own HBM share when the group must split.
  • The planner counts the HBM and host bytes fused groups will use.
  • Zero-budget tables turn caching off before fused groups are built.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into fix/per-table-h..." · Reviewed by Greptile

tiankongdeguiji added a commit to tiankongdeguiji/recsys-examples that referenced this pull request Nov 4, 2026
… (PR NVIDIA#534)

b9ca916 unintentionally carried the runtime half of the per-table HBM
budget change: those edits were sitting uncommitted in this tree while
the hash_bucket review findings were being addressed, and a commit takes
whole files. The change is unrelated to hash_bucket and is under review
as NVIDIA#534, which also carries the planner-side
mirror it needs to stay consistent.

This restores _create_cache_storage's shared cap_scale split,
create_table_state's options[0] host placement, and the
DynamicEmb_APIs.md row, exactly as they were before b9ca916.

Co-Authored-By: Claude Code <[email protected]>

@jiashuy jiashuy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the configuration is set inappropriately—specifically, where caching=True but global_hbm_for_values=0—the resulting cache will contain only a single bucket. Even with an overflow buffer, such a cache is highly susceptible to overflow, which causes errors in the current implementation. Given this, should we add a check to automatically set caching to false whenever the HBM budget is 0 (the default value)?

A zero-budget table fused with a positive-budget one got a one-bucket
cache: 1024 resident rows and a finite overflow of 3072, which a batch
with more unique keys than that cannot enter -- while _prefetch_cache_path
assumes every admitted key can. Take caching off such a table when its
resolved HBM value budget is zero, with a warning, before anything reads
the field: the planner does it in _prepare_dynemb_table_options, so
grouping and the cost model see the layout the table will really get, and
direct construction does it before the grouped-key check. A positive
local_hbm_for_values keeps caching however global_hbm_for_values is set,
which direct construction never reads.

A group of zero-budget tables now takes the existing non-caching host/PS
paths instead of being refused as "Can't use caching mode", and a group
left mixed by the normalization is refused by name, since one fused
module cannot hold both layouts.

test_alignment drops its "caching with zero global HBM is invalid" skip:
those 240 combinations now run and pass as host-only modules.

Co-Authored-By: Claude Code <[email protected]>

@jiashuy jiashuy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread corelib/dynamicemb/test/unit_test.sh Resolved
@greptile-apps

greptile-apps Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@jiashuy
jiashuy merged commit aa0556a into NVIDIA:main Nov 9, 2026
1 check passed
shijieliu added a commit to shijieliu/recsys-examples that referenced this pull request Nov 9, 2026
Merge main up to d03198c (NVIDIA#536, NVIDIA#534, NVIDIA#529, NVIDIA#527, NVIDIA#526).

- NVIDIA#527 sends empty weights for an empty input under index dedup, the
  change this branch made in shard/embedding.py: the merge keeps main's
  docstring and comments and this branch's needs_counters, the same
  condition.
- NVIDIA#529 adds PrefetchState.key_map_generation and _slots_after_rehash,
  and looks a prefetched batch's slots up again in its backward when a
  later prefetch rehashed the table. Git put _slots_after_rehash between
  PrefetchState's fields and this branch's record_stream, which then fell
  out of the class without a conflict; the merge puts it back. The
  lookup's row map (out_rows, grad_rows) only says where rows go, and the
  forward's load_from_flat_by reads value rows, which a storage keeps
  through a rehash.
- NVIDIA#534 (each table's HBM budget in fused groups), NVIDIA#536 (erase_by_score
  for lru_lfu tables, per named table) and NVIDIA#526 (VMMTensor frees after
  the queued work) merge without conflicts.

Every file of test/unit_test.sh passes on one node, each group's .sh
files with its DYNAMICEMB_TEST_GROUP, and so does the HSTU end-to-end
test on one node and on 2. On 2 nodes test_hier_dist.py (122),
test_hier_overflow.py (79) and test_hier_pipeline.py (45) pass, and on 4
nodes test_hier_dist.py (122).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants