Skip to content

Refactor test for alignment; add get_sharded_table_capacity - #348

Merged
shijieliu merged 4 commits into
NVIDIA:mainfrom
jiashuy:dynamicemb_alignment
Apr 10, 2026
Merged

shijieliu merged 4 commits into
NVIDIA:mainfrom
jiashuy:dynamicemb_alignment

Conversation

@jiashuy

@jiashuy jiashuy commented Apr 8, 2026 •

Copy link
Copy Markdown
Collaborator

Rewrite test/unit_tests/test_alignment.py: drop memory-report helpers and ad-hoc theory vs DMP comparison; add pytest-parametric checks for planner options (max_capacity, local_hbm) vs get_sharded_table_capacity/get_table_value_bytes, and cache/storage value tensor shapes vs hashtable metadata. Invoke via test/unit_tests/test_alignment.sh; unit_test.sh calls the shell wrapper.

API: replace public get_sharded_table_shape with get_sharded_table_capacity; introduce internal _sharded_table_bucket_layout for planner; update get_table_value_bytes, docs, and call sites.
Made-with: Cursor

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 force-pushed the dynamicemb_alignment branch 2 times, most recently from 5b45946 to c89d3eb Compare April 8, 2026 07:55
@jiashuy

jiashuy commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI

@jiashuy jiashuy changed the title Refactor test to alignment; add get_sharded_table_capacity Refactor test for alignment; add get_sharded_table_capacity Apr 8, 2026
@greptile-apps

greptile-apps Bot commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors test_alignment.py into a comprehensive pytest-parametric test suite, replaces the get_sharded_table_shape public API with get_sharded_table_capacity (returning a scalar int instead of a tuple), and introduces the internal _sharded_table_bucket_layout helper consumed by the planner. Call sites in the example, dump/load tests, and hybrid-storage tests are updated accordingly.

  • P1 – duplicate test entry: test/unit_tests/test_hybrid_storage_export.sh appears twice in FWD_BWD_TEST_FILES in unit_test.sh (lines 4 and 12), causing that test script to run twice in every CI run.

Confidence Score: 4/5

Safe to merge after fixing the duplicate test entry in unit_test.sh; all other changes are correct.

One P1 defect: the duplicate test_hybrid_storage_export.sh entry in unit_test.sh causes that script to run twice in every CI pass, wasting resources. All other changes — the API rename, planner refactor, and new parametric tests — are logically correct and well-structured.

corelib/dynamicemb/test/unit_test.sh — duplicate FWD_BWD_TEST_FILES entry at line 12.

Important Files Changed

Filename Overview
corelib/dynamicemb/test/unit_test.sh Adds test_alignment.sh to FWD_BWD_TEST_FILES, but accidentally duplicates the existing test_hybrid_storage_export.sh entry, causing it to run twice every CI run.
corelib/dynamicemb/dynamicemb/dynamicemb_config.py Replaces get_sharded_table_shape (tuple) with get_sharded_table_capacity (scalar int) and extracts internal _sharded_table_bucket_layout; logic is correct and consistent with the planner.
corelib/dynamicemb/test/unit_tests/test_alignment.py Full rewrite into parametric pytest suite; correctly checks max_capacity vs get_sharded_table_capacity, local_hbm ceiling math, and value-buffer shapes against hashtable metadata for all storage/cache combinations.
corelib/dynamicemb/dynamicemb/planner/planner.py Switches to _sharded_table_bucket_layout for bucket layout; _prepare_dynemb_table_options logic unchanged and consistent with the new helper.
corelib/dynamicemb/dynamicemb/init.py Exports get_sharded_table_capacity in place of get_sharded_table_shape; all updated correctly.
corelib/dynamicemb/test/unit_tests/test_alignment.sh Shell wrapper runs pytest via torchrun for world sizes 1, 4, and 8; set -e correctly propagates failures.
corelib/dynamicemb/DynamicEmb_APIs.md Documentation updated to reflect the new get_sharded_table_capacity API and _sharded_table_bucket_layout internal rename; accurate and consistent with the code.
corelib/dynamicemb/test/unit_tests/test_hybrid_storage_export.py Updated import to use get_sharded_table_capacity and _sharded_table_bucket_layout; call sites aligned with new API.
corelib/dynamicemb/test/unit_tests/test_embedding_dump_load.py Imports updated to use get_sharded_table_capacity and _sharded_table_bucket_layout; no logic changes.
corelib/dynamicemb/example/example.py Call site updated from get_sharded_table_shape to get_sharded_table_capacity; straightforward API rename.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["get_sharded_table_capacity(config, world_size, bucket_capacity)"]
    B["_sharded_table_bucket_layout(config, world_size, bucket_capacity)"]
    C{bucket_capacity == MAX_BUCKET_CAPACITY?}
    D["return (1, align(shard_rows, BUCKET_ALIGNMENT))"]
    E{bucket_capacity valid & aligned?}
    F["ValueError"]
    G["table_cap = align(shard_rows, bucket_capacity)\nnum_buckets = table_cap // bucket_capacity\nreturn (num_buckets, bucket_capacity)"]
    H["return num_buckets * effective_bucket"]
    A --> B
    B --> C
    C -- Yes --> D
    C -- No --> E
    E -- No --> F
    E -- Yes --> G
    D --> H
    G --> H
    I["_prepare_dynemb_table_options (planner)"]
    I --> B
    B --> J["opts.bucket_capacity = effective_bucket\nopts.max_capacity = num_buckets x effective_bucket\nopts.local_hbm = ceil(global_hbm / world_size)"]
    K["get_table_value_bytes"]
    K --> A
    A --> L["total_rows = capacity_per_rank x world_size\nbytes = element_size x (dim + optim_dim) x total_rows"]
Loading

Reviews (6): Last reviewed commit: "Fix initialization error thron by DataLo..." | Re-trigger Greptile

@jiashuy
jiashuy requested a review from shijieliu April 9, 2026 02:37
@jiashuy
jiashuy force-pushed the dynamicemb_alignment branch from a655b60 to bc8ea10 Compare April 9, 2026 02:39
jiashuy added 2 commits April 9, 2026 15:05
Rewrite test/unit_tests/test_alignment.py: drop memory-report helpers and ad-hoc theory vs DMP comparison; add pytest-parametric checks for planner options (max_capacity, local_hbm) vs get_sharded_table_capacity/get_table_value_bytes, and cache/storage value tensor shapes vs hashtable metadata. Invoke via test/unit_tests/test_alignment.sh; unit_test.sh calls the shell wrapper.

API: replace public get_sharded_table_shape with get_sharded_table_capacity; introduce internal _sharded_table_bucket_layout for planner; update get_table_value_bytes, docs, and call sites.
Made-with: Cursor
@shijieliu
shijieliu force-pushed the dynamicemb_alignment branch from bc8ea10 to 797387d Compare April 9, 2026 07:05
@shijieliu
shijieliu merged commit 68015e7 into NVIDIA:main Apr 10, 2026
JacoCheung pushed a commit to JacoCheung/recsys-examples that referenced this pull request Apr 10, 2026
* dynamicemb: refactor test_alignment; add get_sharded_table_capacity

Rewrite test/unit_tests/test_alignment.py: drop memory-report helpers and ad-hoc theory vs DMP comparison; add pytest-parametric checks for planner options (max_capacity, local_hbm) vs get_sharded_table_capacity/get_table_value_bytes, and cache/storage value tensor shapes vs hashtable metadata. Invoke via test/unit_tests/test_alignment.sh; unit_test.sh calls the shell wrapper.

API: replace public get_sharded_table_shape with get_sharded_table_capacity; introduce internal _sharded_table_bucket_layout for planner; update get_table_value_bytes, docs, and call sites.
Made-with: Cursor

* Enhance test_alignment.sh

* use get_sharded_table_capacity in example.py

* Fix initialization error thron by DataLoader by avoiding CUDA context clone
JacoCheung pushed a commit to JacoCheung/recsys-examples that referenced this pull request Apr 10, 2026
* dynamicemb: refactor test_alignment; add get_sharded_table_capacity

Rewrite test/unit_tests/test_alignment.py: drop memory-report helpers and ad-hoc theory vs DMP comparison; add pytest-parametric checks for planner options (max_capacity, local_hbm) vs get_sharded_table_capacity/get_table_value_bytes, and cache/storage value tensor shapes vs hashtable metadata. Invoke via test/unit_tests/test_alignment.sh; unit_test.sh calls the shell wrapper.

API: replace public get_sharded_table_shape with get_sharded_table_capacity; introduce internal _sharded_table_bucket_layout for planner; update get_table_value_bytes, docs, and call sites.
Made-with: Cursor

* Enhance test_alignment.sh

* use get_sharded_table_capacity in example.py

* Fix initialization error thron by DataLoader by avoiding CUDA context clone
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