Skip to content

[FEA] DynamicEmb: dump embedding checkpoint as its native dtype - #482

Merged
shijieliu merged 7 commits into
NVIDIA:mainfrom
jiashuy:feat/dynamicemb-dump-multi-dtype
Sep 14, 2026
Merged

shijieliu merged 7 commits into
NVIDIA:mainfrom
jiashuy:feat/dynamicemb-dump-multi-dtype

Conversation

@jiashuy

@jiashuy jiashuy commented Sep 9, 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 [FEA] DynamicEmb: dump embedding as its native dtype [FEA] DynamicEmb: dump embedding checkpoint as its native dtype Sep 9, 2026
@greptile-apps

greptile-apps Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no new actionable issues were introduced after the previous review, and all previous findings are resolved.

Summary

  • Records checkpoint dtype and embedding dimension in per-table metadata.
  • Validates value-file layouts and converts across runtime precisions during loading.
  • Preserves compatibility with legacy float32 checkpoints.
  • Extends native-dtype handling to inference and hybrid-storage paths.
  • Clarifies incremental replay compatibility, atomicity, sharding, and timestamp semantics.
  • Adds checkpoint precision, metadata-validation, and score-order regression coverage.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  T[Dynamic embedding table] --> E[Export native-dtype values]
  E --> V[Headerless value files]
  E --> M[Metadata: dtype and dimension]
  V --> R[Resolve checkpoint layout]
  M --> R
  L[Legacy checkpoint without layout metadata] --> F[Assume float32 and recover row width]
  F --> R
  R --> C{Runtime dtype matches?}
  C -->|Yes| I[Insert values]
  C -->|No| W[Warn and convert]
  W --> I
Loading

Reviews (10) · Last reviewed commit: "docs(dynamicemb): a repeated replay is n..."

@jiashuy

jiashuy commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

❔ Pipeline #67092345 -- canceling

Job Status Log
pre_check ❔ canceling view
train_build_x86 ❔ canceling view
train_build_arm64 ❔ canceling view
prepare-jet-b200-smoke 🚫 canceled view
prepare-jet-b200-inference 🚫 canceled view
prepare-jet-cw-dfw-e2e-benchmark 🚫 canceled view
build_whl 🚫 canceled view
dynamicemb_test_fwd_bwd_8gpus 🚫 canceled view
dynamicemb_test_load_dump_8gpus 🚫 canceled view
unit_test_1gpu_a100 🚫 canceled view
unit_test_1gpu_h100 🚫 canceled view
unit_test_4gpu 🚫 canceled view
unit_test_tp_4gpu 🚫 canceled view
L20_unit_test_1gpu 🚫 canceled view
inference_unit_test_1gpu 🚫 canceled view
inference_test_1gpu 🚫 canceled view
inference_test_nve_2605_1gpu 🚫 canceled view

View full pipeline

@jiashuy

jiashuy commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

❌ Pipeline #67094412 -- failed

Job Status Log
pre_check ❌ failed view
train_build_x86 ✅ success view
train_build_arm64 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ 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 ❌ failed view
inference_test_nve_2605_1gpu ✅ success view

Result: 14/17 jobs passed

View full pipeline

@jiashuy
jiashuy force-pushed the feat/dynamicemb-dump-multi-dtype branch from 02c0582 to 2f2000c Compare September 11, 2026 03:18
@jiashuy

jiashuy commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Pipeline #67299055 -- success

Job Status Log
pre_check ❌ failed view
train_build_x86 ✅ success view
train_build_arm64 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ 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
inference_test_nve_2605_1gpu ✅ success view

Result: 15/17 jobs passed

View full pipeline

@jiashuy

jiashuy commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

❌ Pipeline #67338765 -- failed

Job Status Log
pre_check ❌ failed view
train_build_x86 ✅ success view
train_build_arm64 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ 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 ❌ failed view
inference_test_1gpu ✅ success view
inference_test_nve_2605_1gpu ✅ success view

Result: 14/17 jobs passed

View full pipeline

jiashuy and others added 7 commits September 13, 2026 11:11
A dump upcast every value to fp32 on the way out and the loader read it
back by the same hardcoded constant, so a fp16 or bf16 table paid double
the checkpoint size to store bits it did not have. Write the table's own
emb_dtype instead, for embeddings and for the optimizer states that share
the value row.

That only works if a reader can tell what it is looking at. The value
files are bare row-major blobs with no header, and their length was the
only thing a loader had to go on -- with a fixed dtype that was enough to
recover the row count, and with a variable one it is not. So the dump now
records embedding_dtype, embedding_dim and optim_state_dtype in the
table's meta JSON, and resolve_checkpoint_value_layout reads the files by
them.

Checkpoints written before those keys existed are all fp32, and their dim
still follows from the file size, so they load unchanged. Either way the
resolved layout is reconciled against the file's actual size, which turns
a truncated or mis-typed value file into an error instead of a silently
misparsed table; the old check divided sizes and let a partial trailing
row through. A dim that disagrees with the runtime table is rejected. A
precision that disagrees is converted and warned about, because migrating
a checkpoint between precisions is a thing to support, not a mistake.

The meta dict is rebuilt and rewritten whole by rank 0 on each dump, and
a hybrid dump's second tier appends to the same files without rewriting
it -- so the layout keys are contributed at the one site that writes it,
and tiers with differing precisions are rejected rather than interleaved
into one file.

export_keys_values now returns the table's precision too, matching what
incremental_dump has always reported.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ible

Follow-up to the previous commit, which made a checkpoint's precision able
to differ from the table's without saying, at the point where the two meet,
which one wins.

_load_key_values assembled the stored row by concatenating the file's
embeddings with optimizer states that had already been pulled to the
table's dtype, and left the resulting dtype to torch.cat's type promotion.
That worked, but only because the cat widened the whole row and
store_to_flat_single_table narrowed it straight back -- a wider buffer
allocated and discarded, and a dtype a reader could only establish by
going and reading two other functions.

Normalize both inputs to state.emb_dtype up front, alongside the other
argument checks, so one dtype holds for the whole body. Converting
opt_states before pad_optimizer_states_from_checkpoint rather than after
converts the narrow checkpoint block instead of the widened runtime one,
and covers that function's one path that returns its input uncast.

HybridStorage.load already cast this way; the two now match.

Also drops the checkpoint-layout tests down to the two that carry their
weight: the precision round trip (fp32/fp16/bf16) and the legacy
no-layout-meta fallback.

Co-Authored-By: Claude Opus 5 <[email protected]>
… carry

The checkpoint-layout tests built their tables with SGD, which keeps no
per-row state, so opt_states stayed None through _load_key_values and the
tests never reached the branch the previous commit changed: the cast, the
widening, and the cat that assembles a stored row from two blocks.

Rowwise Adagrad reaches all of it, and reaches it harder than Adam would.
Its checkpoint state is one accumulator per row while its runtime state is
16 // itemsize elements -- 4 at fp32, 8 at fp16/bf16 -- so a load must
widen the block rather than copy it straight through, and the width it
widens to depends on the very dtype under test. Adam's two widths are
equal, so it would only ever take the copy-through path.

Dump and load with optim=True, or the optimizer file is never written and
none of the above happens. Assert the opt_values file's size against the
table's precision as well, so "optimizer states are stored at the table's
dtype" is checked against the bytes rather than against the string the
dump wrote into its own metadata.

Co-Authored-By: Claude Opus 5 <[email protected]>
…the other order

replay_increment compared score_strategy by physical word order, on the
reasoning that the configured tuple only ever decided checkpoint column
order. It decides the delta's column order too, and that is read back by a
different table than the one that wrote it.

A compound strategy's physical layout is fixed: (TIMESTAMP, LFU) and
(LFU, TIMESTAMP) both store the timestamp at word 0, so the two compare
equal and the pair is accepted. But _dump_score_block emits columns in the
source's configured order, while _replay_score_block picks which columns
are ages to rebase (_timestamp_score_columns) and how to permute them
(score_load_permutation) by position in the target's. Swap the two and a
frequency of 100 replayed at target_ts=1000 is rebased to 900 and written
into the timestamp word, while the timestamp's age lands in the frequency
word -- corrupting the threshold future incremental dumps select on and
the ordering eviction uses. The embeddings still land correctly, so
nothing downstream reports it.

Compare the strategy as configured. This also rejects the pair when only
the embedding is being replayed, where the order could not have hurt;
splitting on ReplayContent would buy that back at the cost of a
compatibility rule that depends on the call's arguments.

test_replay_accepts_swapped_score_order asserted the old behaviour, on the
premise that it ran "with no scores in flight" -- it ran with the default
ReplayContent.ALL, and only ever compared embeddings, which is why the
corrupted scores went unnoticed. Inverted to assert the rejection.

Co-Authored-By: Claude Opus 5 <[email protected]>
…ejected

replay_increment documented a ValueError as "raised before anything is
written", paired against a RuntimeError documented as the one that fires
mid-write. A caller reading those two together concludes a ValueError means
the model was left alone.

It means that for a module. A module validates every table it holds before
writing any of them -- deliberately, in two passes -- but a collection whose
tables do not all group together is several modules, and the collection-level
loop applies them one at a time. Tables differing in score strategy, caching,
dist_type or anything else in get_grouped_key end up in separate modules, so
this is an ordinary configuration rather than a corner. When a later module
rejects, the earlier ones have already erased and overwritten.

State the rule as it holds: a table is replayed only once it has matched the
delta's metadata, and one that does not match raises instead of being written.
Then scope the atomicity to the module, and tell a caller what a ValueError
does and does not let them assume -- the delta did not go in, the model is not
necessarily unchanged, and replaying the same delta again after fixing the
target is idempotent.

The design doc's rejection row claimed the same collection-wide guarantee, and
still described test_replay_accepts_swapped_score_order, which the previous
commit inverted. Both updated.

No behaviour change.

Co-Authored-By: Claude Opus 5 <[email protected]>
Three places told a reader a delta could be replayed into a differently
sized world: owned_key_mask said recomputing ownership with the target's
fan-out "is what lets a globally gathered delta be replayed into a
differently sized world", the design document offered an 8-rank dump going
into a 4-rank replica and called the resharding free, and the top-level
docstring said ownership was recomputed with "this model's" world size
without saying it had to equal the source's.

_replay_compatibility compares meta["world_size"] with the target's and
rejects a difference, so none of that was reachable. Nor should it be. A
slot_index names a position inside one rank's table and carries no rank of
its own, while the delta is all-gathered and therefore holds every source
rank's keys each with its own rank-local slot. Fold 8 ranks onto 4 and
target rank 0 receives both source rank 0's and source rank 4's keys: two
independent slot spaces of the same size landing in one table, where a pair
that happened to share a slot number now shares a slot and one overwrites
the other with nothing to report it. The capacity check forbids growing the
target to compensate, and growing it would not stop the collision.

So the check is right and the documentation was wrong. Say the world size
must match, say why, and point at a full checkpoint for resharding. Keep
what the ownership filter is actually for: recomputing it from the key,
rather than reading it off the delta, is what lets one gathered delta be
handed to every rank unchanged.

No behaviour change.

Co-Authored-By: Claude Opus 5 <[email protected]>
… score

The recovery note added two commits ago told a caller that had hit a
ValueError to fix the target and replay the same delta, "which is
idempotent". It is not, for the strategies that read their score off the
device clock.

A delta stores a timestamp column as an age, because %globaltimer is
per-device and resets across boots. Replay turns the age back into a score
against a timestamp it takes when it runs -- _apply_replay says as much:
"Timestamp-based tables read their score off the device clock, so there is
nothing to carry -- their restored keys are stamped with ``ts``". Two
replays read two clocks, so the second one stamps the keys later than the
first.

Everything else does repeat: the same keys, embeddings and optimizer
states, and LFU frequencies, STEP, CUSTOMIZED and NO_EVICTION row numbers
are carried verbatim. So say which is which rather than withdraw the
advice, and say what the drift costs -- a module already applied comes out
looking more recently used by however long the operator took to fix the
target, keeping its internal order (every key moved by the same amount)
but moving ahead of the keys the delta never touched, which is what decides
eviction order and what the next time-based incremental_dump selects.

No behaviour change.

Co-Authored-By: Claude Opus 5 <[email protected]>
@jiashuy
jiashuy force-pushed the feat/dynamicemb-dump-multi-dtype branch from d0432b0 to d9cbec8 Compare September 13, 2026 05:46
@shijieliu
shijieliu merged commit 5bc17ea into NVIDIA:main Sep 14, 2026
1 check passed
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