Repository navigation
fix(dynamicemb): correct optimizer-state layout in padded-buffer update - #426
Conversation
…te (NVIDIA#419) The contiguous padded-buffer optimizer kernels (StorageMode.DEFAULT / HybridStorage without caching) assumed each optimizer state occupied the full max_emb_dim width. For tables with dim < max_emb_dim the Adam velocity (v) slot fell inside the kernel's momentum (m) region and was updated with the beta1 rule instead of beta2, corrupting v; the embedding update also read uninitialized padding as v. Make the padded-buffer kernels layout-aware: optimizer states start at a fixed max_emb_dim offset with per-row dim. Add OptimizierInput.state_offset (flat-table path keeps state_offset == dim; padded path uses max_emb_dim) and thread per-row table_ids/table_emb_dims through the padded-buffer update path (CUDA kernels, pybind, optimizer.py, and the backward caller). Add test/unit_tests/test_padded_buffer_optimizer.py covering Adam with mixed embedding dims. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
/build |
|
❌ Pipeline #55101861 -- failed
Result: 10/17 jobs passed |
Greptile SummaryThis PR fixes a state-layout corruption in the contiguous padded-buffer optimizer kernels (
Confidence Score: 5/5Safe to merge. The fix is mechanically correct and well-motivated: the load/store kernel layout in dynamic_emb_op.cu confirms that optimizer states land at [max_emb_dim, max_emb_dim+2*edim) in the padded buffer, which is exactly what the new state_offset=max_emb_dim + dim=edim parameterisation produces. The core corruption (v slot written with beta1 rule when edim < max_emb_dim) is definitively fixed and verified against the actual load/store kernel layout. The previously flagged all_dims_vec4 = (emb_dim % 4 == 0) issue is also resolved. The new test exercises both the vec4 and scalar Adam paths. The only gap is missing regression tests for AdaGrad and RowWiseAdaGrad, which share the same state_offset infrastructure. test/unit_tests/test_padded_buffer_optimizer.py — AdaGrad and RowWiseAdaGrad are not covered; a future regression could re-introduce the state pointer bug for those optimizers without failing any existing test. Important Files Changed
Reviews (4): Last reviewed commit: "perf(dynamicemb): return persistent host..." | Re-trigger Greptile |
…in padded update The NVIDIA#419 fix referenced storage._state.table_emb_dims in the padded-buffer backward path, but HybridStorage has no _state (it uses _hbm/_host tiers), raising AttributeError under StorageMode.DEFAULT with HybridStorage (e.g. test_lfu_scores). Add a Storage.embedding_dims(on_device=False) interface returning per-table embedding dims as an int64 tensor (CPU via table_emb_dims_cpu without a device sync, or the existing CUDA tensor). Implemented by DynamicEmbStorage (_state) and HybridStorage (_hbm tier, which produces the value buffer in find()). Backward now calls storage.embedding_dims(on_device=True) instead of reaching into a storage-specific attribute. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…zer kernels The padded-buffer host functions derived all_dims_vec4 from emb_dim % 4 (max_emb_dim only). After switching the kernels to per-row edim, a table whose edim is not a multiple of 4 but routed through the vec4 kernel (because max_emb_dim is) would have its m_vec.store spill past the m region into v with the beta1 rule — the same corruption NVIDIA#419 fixes. Only manifests with a vec4-aligned max_emb_dim plus a non-aligned table dim. Thread the per-table-correct flag (state.all_dims_vec4, which checks every dim and value_dim) into the four *_update_for_padded_buffer host functions / pybind args / optimizer.py wrappers, exposed via a new Storage.all_dims_vec4() interface (DynamicEmbStorage._state, HybridStorage._hbm). Parametrize the regression tests over an aligned mix [8,4] (vec4 path) and a misaligned mix [8,6] (scalar path). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…n padded update The four padded-buffer host functions checked grads/values with TORCH_CHECK but not the table_ids/table_emb_dims tensors added for the NVIDIA#419 fix. A CPU tensor passed accidentally (e.g. embedding_dims(on_device=False)) would be dereferenced as device memory inside the kernel, causing an opaque illegal-memory-access at runtime. Add explicit TORCH_CHECK(...is_cuda()) for a clear error at the entry point. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The '# adam state = 2 * max_emb_dim' comment could read as if each optimizer slot holds max_emb_dim live values. Clarify that the row stride is emb + m + v (each slot reserved max_emb_dim wide) while only the row's own edim values are live per slot, matching the module layout diagram. Co-Authored-By: Claude Opus 4.8 <[email protected]>
pre-commit (autoflake) removes the pass following the docstring in the new embedding_dims/all_dims_vec4 abstract methods; the docstring is a valid body. Co-Authored-By: Claude Opus 4.8 <[email protected]>
c3363f3 to
ac46393
Compare
|
/build |
|
❌ Pipeline #55518095 -- failed
Result: 12/17 jobs passed |
…age test ref The new Storage abstract methods were not implemented on PyDictStorage (the pure-Python reference Storage in test_batched_dynamic_embedding_tables_v2.py), so every test using it failed to instantiate the abstract class. Implement both from its existing _emb_dims/_value_dims. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
/build |
|
❌ Pipeline #55531091 -- failed
Result: 13/17 jobs passed |
…g_dims embedding_dims(on_device=False) previously built a fresh CPU tensor each call. Add a persistent table_emb_dims_host tensor on DynamicEmbTableState (built once in create_table_state) and return it; on_device=True returns the existing GPU table_emb_dims. table_emb_dims_cpu stays a List[int] for the per-table int lookups. PyDictStorage gets equivalent persistent _emb_dims_dev/_emb_dims_host members. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
/build |
|
❌ Pipeline #56181018 -- failed
Result: 4/6 jobs passed |
|
/build |
The contiguous padded-buffer optimizer kernels (StorageMode.DEFAULT / HybridStorage without caching) assumed each optimizer state occupied the full max_emb_dim width. For tables with dim < max_emb_dim the Adam velocity (v) slot fell inside the kernel's momentum (m) region and was updated with the beta1 rule instead of beta2, corrupting v; the embedding update also read uninitialized padding as v.
Make the padded-buffer kernels layout-aware: optimizer states start at a fixed max_emb_dim offset with per-row dim. Add OptimizierInput.state_offset (flat-table path keeps state_offset == dim; padded path uses max_emb_dim) and thread per-row table_ids/table_emb_dims through the padded-buffer update path (CUDA kernels, pybind, optimizer.py, and the backward caller).
Add test/unit_tests/test_padded_buffer_optimizer.py covering Adam with mixed embedding dims.
Description
Checklist