Skip to content

Conversation

jerryzh168
Copy link
Contributor

Summary:
This PR adds support for FixedQParamsQuantizationSpec:

dataclass(eq=True, frozen=True)
class FixedQParamsQuantizationSpec(QuantizationSpecBase):
    dtype: torch.dtype
    scale: float
    zero_point: int
    quant_min: Optional[int] = None
    quant_max: Optional[int] = None
    qscheme: Optional[torch.qscheme] = None

This is useful to define quantization spec for operators like sigmoid which has predefined and fixed scale/zero_point

Test Plan:

buck2 test mode/opt caffe2/test:quantization_pt2e -- 'caffe2/test:quantization_pt2e'
buck2 test mode/opt caffe2/test:quantization_pt2e -- --exact 'caffe2/test:quantization_pt2e - test_fixed_qparams_qspec (quantization.pt2e.test_quantize_pt2e.TestQuantizePT2E)'

Reviewed By: kimishpatel

Differential Revision: D46153082

@pytorch-bot pytorch-bot bot added the release notes: quantization release notes category label May 27, 2023
@pytorch-bot
Copy link

pytorch-bot bot commented May 27, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit cced745:
💚 Looks good so far! There are no failures yet. 💚

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

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D46153082

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D46153082

quant_min=0,
quant_max=255,
qscheme=torch.per_tensor_affine,
scale=2.0 / 256.0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @jerryzh168, May I ask a question about this fixed scale and zp value of sigmoid? The output range of sigmoid is among 0-1, so why we set the fixed scale as 2.0 / 256.0 and fixed zp as 128.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh sorry I think this is not correct, I was trying to copy from https://github.com/pytorch/pytorch/blob/main/torch/ao/quantization/backend_config/_common_operator_config_utils.py but was writing down the wrong parameters, thanks for the comment!

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D46153082

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D46153082

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D46153082

…02439)

Summary:
Pull Request resolved: pytorch#102439

This PR adds support for FixedQParamsQuantizationSpec:

```
dataclass(eq=True, frozen=True)
class FixedQParamsQuantizationSpec(QuantizationSpecBase):
    dtype: torch.dtype
    scale: float
    zero_point: int
    quant_min: Optional[int] = None
    quant_max: Optional[int] = None
    qscheme: Optional[torch.qscheme] = None
```

This is useful to define quantization spec for operators like sigmoid which has predefined and fixed scale/zero_point

Test Plan:
```
buck2 test mode/opt caffe2/test:quantization_pt2e -- 'caffe2/test:quantization_pt2e'
buck2 test mode/opt caffe2/test:quantization_pt2e -- --exact 'caffe2/test:quantization_pt2e - test_fixed_qparams_qspec (quantization.pt2e.test_quantize_pt2e.TestQuantizePT2E)'
```

Reviewed By: kimishpatel

Differential Revision: D46153082

fbshipit-source-id: efe352792d9b178648423da04264b89f7bf35923
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D46153082

@jerryzh168 jerryzh168 added the suppress-bc-linter Suppresses the failures of API backward-compatibility linter (Lint/bc_linter) label May 30, 2023
@facebook-github-bot
Copy link
Contributor

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 30, 2023
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request fb-exported Merged release notes: quantization release notes category suppress-bc-linter Suppresses the failures of API backward-compatibility linter (Lint/bc_linter)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants