Make BatchedUnaryEmbeddingBag constructible on meta/fake tensors - #6116
Open
atubo wants to merge 1 commit into
Open
Make BatchedUnaryEmbeddingBag constructible on meta/fake tensors#6116atubo wants to merge 1 commit into
atubo wants to merge 1 commit into
Conversation
Summary:
`BatchedUnaryEmbeddingBag.split_embedding_weights()` sliced `self.weight` using tensor-valued bounds read out of the `table_offsets_tensor` buffer. Meta and fake tensors carry shape but no data, so those reads lower to `aten::item`. Under a dispatch mode that fabricates placeholder scalars for value-less reads, both slice bounds come back as the same constant, so every slice collapses to shape `(0, 1)` and the `assert param.shape == (num_emb, 1)` in `init_parameters()` fails during construction. Because a bare `assert` carries no message, this surfaces as a blank-message exception.
`__init__` now computes the cumulative offsets once as a Python `list[int]` and derives `table_offsets_tensor` from it, giving a single source of truth. `split_embedding_weights()` slices with the Python ints, keeping shapes static.
Behavior on real devices is unchanged - same offsets, same `uniform_` bounds, same per-table slices, bit-identical initialization for a given seed. The change additionally removes `2*N*T` device-to-host syncs per `split_embedding_weights()` call on CUDA, and makes the module constructible under `torch.device("meta")` and FakeTensor, which model-analysis and export tooling depend on.
Differential Revision: D114802150
Contributor
|
@atubo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D114802150. |
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.
Summary:
BatchedUnaryEmbeddingBag.split_embedding_weights()slicedself.weightusing tensor-valued bounds read out of thetable_offsets_tensorbuffer. Meta and fake tensors carry shape but no data, so those reads lower toaten::item. Under a dispatch mode that fabricates placeholder scalars for value-less reads, both slice bounds come back as the same constant, so every slice collapses to shape(0, 1)and theassert param.shape == (num_emb, 1)ininit_parameters()fails during construction. Because a bareassertcarries no message, this surfaces as a blank-message exception.__init__now computes the cumulative offsets once as a Pythonlist[int]and derivestable_offsets_tensorfrom it, giving a single source of truth.split_embedding_weights()slices with the Python ints, keeping shapes static.Behavior on real devices is unchanged - same offsets, same
uniform_bounds, same per-table slices, bit-identical initialization for a given seed. The change additionally removes2*N*Tdevice-to-host syncs persplit_embedding_weights()call on CUDA, and makes the module constructible undertorch.device("meta")and FakeTensor, which model-analysis and export tooling depend on.Differential Revision: D114802150