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][A-17] Add type annotations for conv layers #65183

Merged
merged 8 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion python/paddle/nn/functional/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
]
_DropoutMode: TypeAlias = Literal['upscale_in_train', 'downscale_in_infer']
_PaddingTensorMode: TypeAlias = Literal[
Copy link
Contributor

Choose a reason for hiding this comment

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

为啥要加 zeros? 我记得当时单独在 conv 里面加了一个

    _ConvPaddingMode: TypeAlias = Literal[
        "zero", "reflect", "replicate", "circular"
    ]

_PaddingTensorMode 是 constant ..._ConvPaddingModezeros ...

Copy link
Member

Choose a reason for hiding this comment

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

没必要区分到这种程度,而且这名字也很奇怪

"constant", "reflect", "replicate", "circular"
"zeros", "constant", "reflect", "replicate", "circular"
]
_PaddingSizeMode: TypeAlias = Literal[ # noqa: PYI047
'valid', 'same', 'VALID', 'SAME'
Expand Down
31 changes: 16 additions & 15 deletions python/paddle/nn/functional/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DataLayout1D,
DataLayout2D,
DataLayout3D,
DataLayoutND,
Size1,
Size2,
Size3,
Expand Down Expand Up @@ -127,20 +128,20 @@ def _update_padding_nd(padding, channel_last, num_dims):


def _conv_nd(
x,
weight,
bias=None,
stride=1,
padding=0,
x: Tensor,
weight: Tensor,
bias: Tensor | None = None,
stride: int | Sequence[int] = 1,
padding: _PaddingSizeMode | int | Sequence[int] | Sequence[Size2] = 0,
padding_algorithm=None,
dilation=1,
groups=1,
data_format="NCHW",
channel_dim=1,
op_type="conv2d",
use_cudnn=True,
name=None,
):
dilation: int | Sequence[int] = 1,
groups: int = 1,
data_format: DataLayoutND = "NCHW",
channel_dim: int = 1,
op_type: str = "conv2d",
use_cudnn: bool = True,
name: str | None = None,
) -> Tensor:
# Due to the poor performance of NHWC, we transpose the input to NCHW.
if in_dynamic_or_pir_mode() and op_type == "conv2d":
pre_bias = _C_ops.conv2d(
Expand Down Expand Up @@ -777,7 +778,7 @@ def conv1d_transpose(
weight: Tensor,
bias: Tensor | None = None,
stride: Size1 = 1,
padding: _PaddingSizeMode | Size1 | Size2 = 0,
padding: _PaddingSizeMode | Size1 | Size2 | Sequence[Size2] = 0,
output_padding: Size1 = 0,
groups: int = 1,
dilation: Size1 = 1,
Expand Down Expand Up @@ -1356,7 +1357,7 @@ def conv3d(
weight: Tensor,
bias: Tensor | None = None,
stride: Size3 = 1,
padding=0,
padding: _PaddingSizeMode | Size3 | Size6 | Sequence[Size2] = 0,
dilation: Size3 = 1,
groups: int = 1,
data_format: DataLayout3D = "NCDHW",
Expand Down
Loading