Skip to content

Create DynamicEmbStorage when zero local hbm; reset _prefetch_outstanding_keys only in reset_cache_states - #354

Merged
shijieliu merged 2 commits into
NVIDIA:mainfrom
jiashuy:fix_zero_local_hbm
Apr 10, 2026
Merged

shijieliu merged 2 commits into
NVIDIA:mainfrom
jiashuy:fix_zero_local_hbm

Conversation

@jiashuy

@jiashuy jiashuy commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

Description

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@jiashuy jiashuy changed the title Fix zero local hbm Create DynamicEmbStorage when zero local hbm; set _prefetch_outstanding_keys to zero only when reset cache Apr 10, 2026
@jiashuy jiashuy changed the title Create DynamicEmbStorage when zero local hbm; set _prefetch_outstanding_keys to zero only when reset cache Create DynamicEmbStorage when zero local hbm; reset _prefetch_outstanding_keys only when reset cache Apr 10, 2026
@jiashuy jiashuy changed the title Create DynamicEmbStorage when zero local hbm; reset _prefetch_outstanding_keys only when reset cache Create DynamicEmbStorage when zero local hbm; reset _prefetch_outstanding_keys only in reset_cache_states Apr 10, 2026
@greptile-apps

greptile-apps Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two issues: (1) a logic bug where setting local_hbm_for_values=0 in non-caching mode would incorrectly fall through to HybridStorage creation (with a zero-scale HBM tier) instead of cleanly routing to host-only DynamicEmbStorage, and (2) a display bug in _print_memory_consume where float division (/) was used instead of integer division (//), causing even sub-MB tables to always display in MB units. The fix adds an explicit local_hbm <= 0 guard in the non-caching branch and extends the parametrized test to cover the zero-HBM case.

Confidence Score: 5/5

Safe to merge — the core logic fix is correct and the new test case validates the zero-HBM path end-to-end.

All findings are P2 (style/minor): a redundant defensive guard and a pre-existing display format note. The zero-HBM fix correctly routes to host-only DynamicEmbStorage and is well-covered by the added parametrize case. No data correctness or runtime issues were found.

No files require special attention.

Important Files Changed

Filename Overview
corelib/dynamicemb/dynamicemb/batched_dynamicemb_tables.py Adds local_hbm <= 0 guard in non-caching path to route zero-HBM configs to host-only DynamicEmbStorage; also fixes float-vs-integer division in _print_memory_consume; the total_memory > 0 guard in cap_scale is always true in context
corelib/dynamicemb/test/test_batched_dynamic_embedding_tables_v2.py Adds (False, None, 0) parametrize case and corresponding assertion branch for zero-HBM non-caching storage type check
corelib/dynamicemb/test/unit_tests/test_alignment.sh New shell script that runs alignment unit tests via torchrun with 1, 4, and 8 processes; straightforward test runner with no logic concerns

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[_create_cache_storage] --> B{total_memory > local_hbm?}
    B -- No --> E[HBM-only: DynamicEmbStorage\nwith original options]
    B -- Yes --> C{caching=True?}
    C -- Yes --> F{local_hbm <= 0?}
    F -- Yes --> G[raise ValueError:\nHBM too small for caching]
    F -- No --> H[DynamicEmbCache\n+ DynamicEmbStorage/PS backend]
    C -- No --> I{local_hbm <= 0?}
    I -- Yes --> J[NEW: host-only\nDynamicEmbStorage/PS\nlocal_hbm_for_values=0]
    I -- No --> K[HybridStorage:\nHBM tier + host tier]
Loading

Comments Outside Diff (2)

  1. corelib/dynamicemb/dynamicemb/batched_dynamicemb_tables.py, line 251-255 (link)

    P2 Display format always resolved to MB before the fix

    With float division (/), any total_memory > 0 produced a non-zero float (e.g., 1 / 1048576 ≈ 9.5e-7), so the condition was always True and KB_ was never selected. The // fix is correct. Worth noting: F is chosen from the first table processed, so if the first table is sub-MB but later tables are large, all tables will display in KB even when MB would be clearer. This is a pre-existing design choice and not introduced here, but it may be worth addressing separately.

  2. corelib/dynamicemb/dynamicemb/batched_dynamicemb_tables.py, line 513 (link)

    P2 total_memory > 0 guard is dead code in this branch

    At this point the code is inside both if total_memory > local_hbm: (line 503) and has verified local_hbm > 0 (the <= 0 branch raised/branched before reaching here), so total_memory > local_hbm > 0 is guaranteed — total_memory > 0 is always true. The same applies to line 563 in the HybridStorage path. The guards are harmless but misleading.

Reviews (1): Last reviewed commit: "reset _prefetch_outstanding_keys only re..." | Re-trigger Greptile

@jiashuy

jiashuy commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator Author

CI

@jiashuy
jiashuy requested review from JacoCheung and shijieliu April 10, 2026 07:06
@shijieliu
shijieliu merged commit dd62399 into NVIDIA:main Apr 10, 2026
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