Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FactorizedEmbedding doesn't work with non-contiguous input #31

Closed
jemisjoky opened this issue Feb 21, 2023 · 2 comments
Closed

FactorizedEmbedding doesn't work with non-contiguous input #31

jemisjoky opened this issue Feb 21, 2023 · 2 comments

Comments

@jemisjoky
Copy link

I'm using version 0.4.0 of tensorly-torch and am running into an issue with non-contiguous inputs to a FactorizedEmbedding layer raising a runtime error. Here's a minimum working example:

import torch
from tltorch.factorized_layers import FactorizedEmbedding

embedding = FactorizedEmbedding(32, 16)
data = torch.randint(0, 32, (2, 3))
embedding(data.T)

Running this yields:

Traceback (most recent call last):
  File "tltorch_bug_mwe.py", line 6, in <module>
    embedding(data.T)
  File "/Users/jemis/opt/miniconda3/envs/tensorized3.8/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/jemis/opt/miniconda3/envs/tensorized3.8/lib/python3.8/site-packages/tltorch/factorized_layers/factorized_embedding.py", line 100, in forward
    flatenned_input = input.view(-1)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

Replacing input.view(-1) with input.reshape(-1) does indeed resolve this.

@JeanKossaifi
Copy link
Member

Thanks @jemisjoky and thanks for opening such a good issue with a clear snippet to reproduce the error and the proposed fix! It's fixed in 5f4d0e5

@jemisjoky
Copy link
Author

Thanks @JeanKossaifi!

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

No branches or pull requests

2 participants