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

QuantTensor creation is slow #1163

Open
1 of 3 tasks
Giuseppe5 opened this issue Jan 20, 2025 · 0 comments
Open
1 of 3 tasks

QuantTensor creation is slow #1163

Giuseppe5 opened this issue Jan 20, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@Giuseppe5
Copy link
Collaborator

Giuseppe5 commented Jan 20, 2025

Describe the bug

Creating a QT is slow, and the reason is how we handle boolean values.

In particular, when creating a QT, for simplicity, IntQuantTensor, everything is casted to a Tensor.
This casting is always skipped except for training and signed, which are normally bool and then casted to boolean torch.Tensor.

I tried dropping this, making sure that training and signed are only bool, and not boolean tensors, but it breaks export #1140
To fix this, we would need to drop QT during export (the PR used to exist and was re-adapted for something else, but it is trivial).

Reproducibility

  • Can be reproduced consistently.
  • Difficult to reproduce.
  • Unable to reproduce.

To Reproduce

import torch
from brevitas.quant_tensor import IntQuantTensor
import time

value = torch.randn(1, 3, 5, 5)
scale = torch.randn(1, 3)
zp = torch.randn(1)
bit_width = torch.randn(1)
signed = True
training = True
start = time.time()
for _ in range(10000):
    qt = IntQuantTensor(value, scale, zp, bit_width, signed, training)
print(time.time() - start)

# 0.09406900405883789

signed = torch.tensor(signed, dtype=torch.bool)
training = torch.tensor(training, dtype=torch.bool)

start = time.time()
for _ in range(10000):
    qt = IntQuantTensor(value, scale, zp, bit_width, signed, training)
print(time.time() - start)

# 0.009476900100708008
@Giuseppe5 Giuseppe5 added the bug Something isn't working label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant