Repository navigation
[FEA] DynamicEmb: dump embedding checkpoint as its native dtype - #482
Merged
Merged
Conversation
Contributor
|
Collaborator
Author
|
/build |
Collaborator
|
❔ Pipeline #67092345 -- canceling
|
Collaborator
Author
|
/build |
Collaborator
|
❌ Pipeline #67094412 -- failed
Result: 14/17 jobs passed |
jiashuy
force-pushed
the
feat/dynamicemb-dump-multi-dtype
branch
from
September 11, 2026 03:18
02c0582 to
2f2000c
Compare
Collaborator
Author
|
/build |
Collaborator
|
✅ Pipeline #67299055 -- success
Result: 15/17 jobs passed |
Collaborator
Author
|
/build |
Collaborator
|
❌ Pipeline #67338765 -- failed
Result: 14/17 jobs passed |
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
force-pushed
the
feat/dynamicemb-dump-multi-dtype
branch
from
September 13, 2026 05:46
d0432b0 to
d9cbec8
Compare
shijieliu
approved these changes
Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Checklist