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

[Typing][B-84] Add type annotations for python/paddle/nn/quant/stub.py #65807

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions python/paddle/nn/quant/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@

""" Define stub used in quantization."""

from __future__ import annotations

from typing import TYPE_CHECKING

from ..layer.layers import Layer

if TYPE_CHECKING:
from paddle import Tensor
from paddle.quantization import QuantConfig
from paddle.quantization.factory import QuanterFactory


class Stub(Layer):
r"""
Expand Down Expand Up @@ -66,11 +75,11 @@ class Stub(Layer):
)
"""

def __init__(self, observer=None):
def __init__(self, observer: QuanterFactory | None = None) -> None:
super().__init__()
self._observer = observer

def forward(self, input):
def forward(self, input: Tensor) -> Tensor:
return input


Expand All @@ -86,13 +95,13 @@ class QuanterStub(Layer):
q_config(QuantConfig): The quantization configuration for the current stub layer.
"""

def __init__(self, layer: Stub, q_config):
def __init__(self, layer: Stub, q_config: QuantConfig) -> None:
super().__init__()
self._observer = None
if layer._observer is not None:
self._observer = layer._observer._instance(layer)
elif q_config.activation is not None:
self._observer = q_config.activation._instance(layer)

def forward(self, input):
def forward(self, input: Tensor) -> Tensor:
return self._observer(input) if self._observer is not None else input