Skip to content

Refactor _print_memory_consume to report real per-tier value bytes - #408

Merged
shijieliu merged 2 commits into
NVIDIA:mainfrom
jiashuy:mem_consume
May 29, 2026
Merged

shijieliu merged 2 commits into
NVIDIA:mainfrom
jiashuy:mem_consume

Conversation

@jiashuy

@jiashuy jiashuy commented May 29, 2026 •

Copy link
Copy Markdown
Collaborator
  • Add StorageLayout enum set explicitly by _create_cache_storage so the printed layout matches the code path that ran (no inference from buffer state, which only reflects options[0].local_hbm_for_values).
  • Read per-tier value bytes from the constructed ExtendableBuffer (init, post bucket-alignment) and options.max_capacity (peak); this fixes caching mode where the HBM cache duplicates the host backing — the old code reported HBM+DRAM=total_memory and missed the cache copy entirely. Also captures hybrid cap_scale + bucket-alignment rounding.
  • Switch to long-format tier-major output: one row per (tier, table), per-tier TOTAL rows. Full top/bottom/inter-tier borders; a blanked-tier-column rule frames each TOTAL row inside its block.
  • Extract _build_tier_block / _render_tier_table helpers so the print function only does dispatch + layout footnote.
  • Bytes formatter renders MB/KB as float with up to 3 decimals, trimming trailing zeros.

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.

- Add StorageLayout enum set explicitly by _create_cache_storage so the
  printed layout matches the code path that ran (no inference from buffer
  state, which only reflects options[0].local_hbm_for_values).
- Read per-tier value bytes from the constructed ExtendableBuffer
  (init, post bucket-alignment) and options.max_capacity (peak); this
  fixes caching mode where the HBM cache duplicates the host backing —
  the old code reported HBM+DRAM=total_memory and missed the cache copy
  entirely. Also captures hybrid cap_scale + bucket-alignment rounding.
- Switch to long-format tier-major output: one row per (tier, table),
  per-tier TOTAL rows. Full top/bottom/inter-tier borders; a
  blanked-tier-column rule frames each TOTAL row inside its block.
- Extract _build_tier_block / _render_tier_table helpers so the print
  function only does dispatch + layout footnote.
- Bytes formatter renders MB/KB as float with up to 3 decimals, trimming
  trailing zeros.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@jiashuy

jiashuy commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented May 29, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Pipeline #53012873 -- success

Job Status Log
pre_check ✅ success view
train_build ✅ success view
inference_build ✅ success view
tritonserver_build ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ✅ success view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ✅ success view
unit_test_1gpu_h100 ✅ success view
unit_test_4gpu ✅ success view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ✅ success view

Result: 13/14 jobs passed

View full pipeline

@greptile-apps

greptile-apps Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors _print_memory_consume to produce an accurate, per-tier memory report by introducing a StorageLayout enum set explicitly during storage construction, reading real byte counts from the built ExtendableBuffer rather than inferring from option fields, and switching to a long-format tier-major table layout with helper functions.

  • StorageLayout enum + explicit assignment: every code path in _create_cache_storage now sets self._storage_layout before calling the print function, eliminating the old inference from options[0].local_hbm_for_values that could misreport caching mode.
  • Per-tier byte accounting: _tier_bytes_from_state reads ExtendableBuffer.num_bytes() for init size and max_capacity * value_dim * element_size for peak, correctly capturing bucket-alignment rounding and caching's HBM/backing duplication.
  • Rendering helpers: _build_tier_block and _render_tier_table encapsulate formatting; the unhandled-layout else branch now raises ValueError immediately instead of silently running the wrong path.

Confidence Score: 5/5

Safe to merge; the refactored reporter is diagnostic-only and cannot affect training correctness or data integrity.

All storage-construction paths explicitly set _storage_layout before _print_memory_consume is called. The new raise ValueError on unrecognised layouts closes the silent-misreporting hole from the prior implementation. The only edge cases identified are either guarded upstream or cosmetic in impact and do not affect training or model state.

No files require special attention; changes are confined to the diagnostic print path and do not touch forward/backward pass logic.

Important Files Changed

Filename Overview
corelib/dynamicemb/dynamicemb/batched_dynamicemb_tables.py Replaces the old flat memory reporter with a per-tier, long-format table using a new StorageLayout enum; correctly handles caching, hybrid, HBM-only, and external-PS paths.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["_create_cache_storage()"] --> B{total_memory > local_hbm?}
    B -- No --> C[DynamicEmbStorage HBM_ONLY]
    B -- Yes --> D{caching?}
    D -- Yes --> E{PS?}
    E -- Yes --> F[PS + DynamicEmbCache CACHING_PS]
    E -- No --> G[DynamicEmbStorage + DynamicEmbCache CACHING]
    D -- No --> H{local_hbm <= 0?}
    H -- Yes --> I{PS?}
    I -- Yes --> J[PS storage HOST_PS]
    I -- No --> K[DynamicEmbStorage HOST_ONLY]
    H -- No --> L[HybridStorage HYBRID]
    C & F & G & J & K & L --> M["_print_memory_consume(storage, cache, layout, ...)"]
    M --> N{layout?}
    N -- HBM_ONLY --> O["_tier_bytes_from_state(storage._state)"]
    N -- HOST_ONLY --> P["_tier_bytes_from_state(storage._state)"]
    N -- HYBRID --> Q["_tier_bytes_from_state(_hbm) + _tier_bytes_from_state(_host)"]
    N -- CACHING --> R["_tier_bytes_from_state(cache._state) + _tier_bytes_from_state(storage._state)"]
    N -- CACHING_PS --> S["_tier_bytes_from_state(cache._state) + _tier_bytes_from_options(...)"]
    N -- HOST_PS --> T["_tier_bytes_from_options(...)"]
    N -- else --> U["raise ValueError"]
    O & P & Q & R & S & T --> V["_build_tier_block() _render_tier_table() print output"]
Loading

Reviews (2): Last reviewed commit: "Make StorageLayout dispatch in _print_me..." | Re-trigger Greptile

Replace the fallthrough `else:  # HOST_PS` with an explicit elif and a
trailing `else: raise ValueError(...)`. Future StorageLayout variants
that forget to add a matching branch now fail loudly instead of being
silently misreported as external PS.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@jiashuy
jiashuy requested a review from shijieliu May 29, 2026 05:24
@jiashuy

jiashuy commented May 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Current output:
Snipaste_2026-05-29_13-30-53

Snipaste_2026-05-29_13-29-45

@shijieliu
shijieliu merged commit 4883b3e into NVIDIA:main May 29, 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.

3 participants