Skip to content

Make table_ptrs_dev persistent - #356

Merged
shijieliu merged 2 commits into
NVIDIA:mainfrom
jiashuy:persistent_table_ptrs
Apr 13, 2026
Merged

shijieliu merged 2 commits into
NVIDIA:mainfrom
jiashuy:persistent_table_ptrs

Conversation

@jiashuy

@jiashuy jiashuy commented Apr 13, 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 commented Apr 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI

@jiashuy
jiashuy requested a review from shijieliu April 13, 2026 02:28
@greptile-apps

greptile-apps Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR caches the table-pointer tensor as table_ptrs_dev inside DynamicEmbTableState instead of re-creating it on every forward/backward call, eliminating repeated CUDA allocations on the hot path. The persistent tensor is refreshed in-place via copy_() inside _expand_tables_impl after all extend() calls and before the migration loop, which is the only code path that can change data_ptr() values.

Confidence Score: 5/5

Safe to merge — change is a straightforward performance optimization with correct refresh ordering and no remaining issues.

All existing call sites are updated, the persistent tensor is refreshed at the only location where data_ptr() can change (_expand_tables_impl after all extend() calls), and the refresh is correctly ordered before the migration loop. No P0/P1 issues found; the previous thread concern about refresh ordering has been addressed.

No files require special attention.

Important Files Changed

Filename Overview
corelib/dynamicemb/dynamicemb/key_value_table.py Adds table_ptrs_dev field to DynamicEmbTableState, initializes it in create_table_state, refreshes it after all extend() calls in _expand_tables_impl, and replaces all ad-hoc get_table_ptrs(state) calls with the cached field.
corelib/dynamicemb/dynamicemb/batched_dynamicemb_function.py Removes get_table_ptrs import and replaces its call in fused_update_for_flat_table with the persistent state.table_ptrs_dev.

Sequence Diagram

sequenceDiagram
    participant C as create_table_state
    participant E as _expand_tables_impl
    participant F as load/store_from_flat*
    participant B as backward (fused_update)

    C->>C: get_table_ptrs(tables, device)
    C-->>S: state.table_ptrs_dev = tensor

    note over E: expand triggered
    E->>E: tables[i].extend(...)
    E->>E: state.table_ptrs_dev.copy_(get_table_ptrs(...))
    E->>F: load_from_flat_single_table (uses table_ptrs_dev)
    E->>F: store_to_flat_single_table (uses table_ptrs_dev)

    B->>B: fused_update_for_flat_table (uses state.table_ptrs_dev)
Loading

Reviews (2): Last reviewed commit: "update table ptrs once table extended" | Re-trigger Greptile

@jiashuy

jiashuy commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator Author

CI

@shijieliu
shijieliu merged commit c462dec into NVIDIA:main Apr 13, 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