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

[StaticQuant] add a linear observer class and test #807

Merged
merged 1 commit into from
Sep 6, 2024
Merged

Conversation

drisspg
Copy link
Contributor

@drisspg drisspg commented Sep 4, 2024

Stacked PRs:


[StaticQuant] add a linear observer class and test

This adds a new flow for calculating static activation scales. Rough example of flow:

import torch
import torch.nn as nn
from torchao.quantization.linear_observer_tensor import insert_observers_
from torchao.quantization.observer import (
    AffineQuantizedMinMaxObserver,
    PerTensor,
    MappingType
)

# Create observers
input_observer = AffineQuantizedMinMaxObserver(
    MappingType.SYMMETRIC,
    torch.float8_e4m3fn,
    granularity_type=PerTensor(),
    eps=torch.finfo(torch.float32).eps,
    scale_dtype=torch.float,
    zero_point_dtype=torch.int,
    zero_point_domain=None,
)

# Create a linear module
linear_module = nn.Linear(10, 20)

# Convert the linear module's weight to an observed tensor
insert_observers_(linear_module, input_observer, weight_observer=None)

# The linear_module can now be used as usual, with observers calculating statistics
output = linear_module(torch.randn(10, 10))

# Get the scale and zero point of the input observer
scale, zero_point = linear_module.weight.input_observer.calculate_qparams()

Copy link

pytorch-bot bot commented Sep 4, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/807

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 96fe56a with merge base a1b3e67 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 4, 2024
drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from main to drisspg/stack/9 September 4, 2024 19:20
@drisspg drisspg changed the base branch from drisspg/stack/9 to main September 4, 2024 20:39
drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from main to drisspg/stack/9 September 4, 2024 20:39
@drisspg drisspg changed the base branch from drisspg/stack/9 to main September 4, 2024 20:42
drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from main to drisspg/stack/9 September 4, 2024 20:42
@drisspg drisspg changed the base branch from drisspg/stack/9 to main September 4, 2024 20:46
drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from main to drisspg/stack/9 September 4, 2024 20:46
@drisspg drisspg changed the base branch from drisspg/stack/9 to main September 4, 2024 20:50
drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from main to drisspg/stack/9 September 4, 2024 20:50
drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from drisspg/stack/9 to main September 4, 2024 22:12
drisspg added a commit that referenced this pull request Sep 4, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from drisspg/stack/10 to main September 5, 2024 05:04
drisspg added a commit that referenced this pull request Sep 5, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from main to drisspg/stack/10 September 5, 2024 05:05
@drisspg drisspg changed the base branch from drisspg/stack/10 to main September 5, 2024 18:22
drisspg added a commit that referenced this pull request Sep 5, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from main to drisspg/stack/10 September 5, 2024 18:22
@drisspg drisspg changed the base branch from drisspg/stack/10 to main September 5, 2024 18:29
drisspg added a commit that referenced this pull request Sep 5, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from main to drisspg/stack/10 September 5, 2024 18:30
@jainapurva jainapurva self-requested a review September 5, 2024 18:40
drisspg added a commit that referenced this pull request Sep 5, 2024
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg changed the base branch from drisspg/stack/10 to main September 5, 2024 18:46
drisspg added a commit that referenced this pull request Sep 5, 2024
stack-info: PR: #807, branch: drisspg/stack/8
Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, see some comments inline, please fix before landing

drisspg added a commit that referenced this pull request Sep 6, 2024
stack-info: PR: #807, branch: drisspg/stack/8
drisspg added a commit that referenced this pull request Sep 6, 2024
stack-info: PR: #807, branch: drisspg/stack/8
stack-info: PR: #807, branch: drisspg/stack/8
@drisspg drisspg merged commit 422301b into main Sep 6, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants