Repository navigation
Keep dtype and device in TextEncoder.prepend_bos_index / append_eos_index for tensor input - #3108
Open
sungbin1015 wants to merge 1 commit into
Open
sungbin1015 wants to merge 1 commit into
sungbin1015 wants to merge 1 commit into
Conversation
…ndex for tensor input
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.
What does this PR do?
When
TextEncoder.prepend_bos_index/append_eos_indexget a tensor, the BOS/EOS index is built withtorch.Tensor([...]), which is float32 on the CPU.torch.catthen promotes the whole result to float, so encoded token ids come back as floats:Feeding that into an
nn.Embeddingfails with "Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int", which is presumably why the integration tests andg2p/dataio.pycall.long()on the result. The index tensor is also always created on the CPU, so a CUDA input should hit a device mismatch intorch.cat(I only have a CPU box, so I checked that with ametatensor, not a GPU). I switched both tox.new_tensor(...)so the result keeps the input's dtype and device, and added a test that uses thedevicefixture. I left the existing.long()calls alone; they're harmless now.No breaking changes unless someone relied on getting floats back. The encoder tests, its doctests and the ASR_seq2seq integration test pass locally (CPU only).
Didn't find this reported; the only other open PR touching
encoder.py(#3102) just carries thelimited_labelset_from_iterablechange from #3095.Before submitting
PR review
Reviewer checklist