Skip to content

Conversation

@miriambt
Copy link

Fixed an error in TabrModel when LongTensor is passed into a Linear layer expecting FloatTensor:

RuntimeError: mat1 and mat2 must have the same dtype, but got Long and Float.

This occurs in the forward() method of TabrModel at the line:

context_y_emb = self.label_encoder(candidate_y[context_idx][..., None])

Here, candidate_y[...] is a LongTensor, which causes a type mismatch when passed into nn.Linear, which expects a FloatTensor.

@dholzmueller
Copy link
Owner

Thanks for the PR! How did you manage to run into this error? For me the old code works just fine, but I don't know why.

@miriambt
Copy link
Author

I was running TabM_D_Classifier when the error occurred, and changing the input to .float() resolved it. However, while using TabR_S_D_Classifier today, I ran into the following error:

RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int; but got torch.FloatTensor instead (while checking arguments for embedding)

I believe I have now implemented a fix that handles both TabM_D_Classifier and TabR_S_D_Classifier correctly (see last commit). Before merging the changes, though, it would be great if you could test it with your data as well — just to make sure the fix does not resolve one issue while introducing another. Thanks!

@dholzmueller
Copy link
Owner

TabM should not be using this code at all. Can you provide a minimal reproducible example that triggers an error with the old code?

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

Successfully merging this pull request may close these issues.

2 participants