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

A few fixes #22

Merged
merged 9 commits into from
Oct 25, 2023
Merged

A few fixes #22

merged 9 commits into from
Oct 25, 2023

Conversation

dacorvo
Copy link
Collaborator

@dacorvo dacorvo commented Oct 25, 2023

While debugging the OPT model, I found out that a few things were not working as expected when batching inputs.

For a start, is_contiguous was never called (and dispatched) because it must be overloaded directly in subclasses (would need to check how many methods are actually needed in Tensor subclasses).

Then, I realized that the chain of aten operations when torch Function is disabled in the Tensor subclass was not necessarily equivalent to their "functional" counterparts.

A good example is torch.matmul: if I disable torch Function for QTensor and invoke torch.matmul, I end up with a sequence of operations that does not check if inputs are contiguous, which leads to failures when the modeling code is not bullet-proof.

Finally, the calibration code was not strictly correct, as during calibration we were always using the "optimal" scale for inputs and outputs where it should be the "current" scale evaluated using a momentum.

The torch.Tensor implementation seems to deal with non-contiguous inputs
just fine, but if we don't overload it for QTensor and let instead the
chain of aten operations flow, it starts with a sequence of expand/view
calls that are not compatible with non-contiguous inputs.
It is better to overload matmul anyway, as we might be able to call directly
an optimized kernel here.
@dacorvo dacorvo merged commit 5935f29 into main Oct 25, 2023
@dacorvo dacorvo deleted the a_few_fixes branch October 25, 2023 14:08
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.

1 participant