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] 修改一些错误的类型标注以及示例代码 #65452

Merged
merged 6 commits into from
Jun 26, 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/device/cuda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def empty_cache():
>>> import paddle
>>> paddle.device.set_device('gpu')

>>> tensor = paddle.randn([512, 512, 512], "float")
>>> tensor = paddle.randn([512, 512, 512], "float64")
>>> del tensor
>>> paddle.device.cuda.empty_cache()
'''
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/distribution/bernoulli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def sample(self, shape):
>>> import paddle
>>> from paddle.distribution import Bernoulli

>>> rv = Bernoulli(paddle.full((1), 0.3))
>>> rv = Bernoulli(paddle.full([1], 0.3))
>>> print(rv.sample([100]).shape)
[100, 1]

Expand Down Expand Up @@ -205,7 +205,7 @@ def rsample(self, shape, temperature=1.0):
>>> paddle.seed(1)
>>> from paddle.distribution import Bernoulli

>>> rv = Bernoulli(paddle.full((1), 0.3))
>>> rv = Bernoulli(paddle.full([1], 0.3))
>>> print(rv.sample([100]).shape)
[100, 1]

Expand Down
4 changes: 2 additions & 2 deletions python/paddle/framework/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def save(obj, path, protocol=4, **configs):
>>> paddle.save(layer_state_dict, "emb.pdparams")

>>> scheduler = paddle.optimizer.lr.NoamDecay(
... d_model=0.01, warmup_steps=100, verbose=True)
... d_model=100, warmup_steps=100, verbose=True)
>>> adam = paddle.optimizer.Adam(
... learning_rate=scheduler,
... parameters=emb.parameters())
Expand Down Expand Up @@ -1044,7 +1044,7 @@ def load(path, **configs):
>>> paddle.save(layer_state_dict, "emb.pdparams")

>>> scheduler = paddle.optimizer.lr.NoamDecay(
... d_model=0.01, warmup_steps=100, verbose=True)
... d_model=100, warmup_steps=100, verbose=True)
>>> adam = paddle.optimizer.Adam(
... learning_rate=scheduler,
... parameters=emb.parameters())
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/nn/layer/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __delitem__(self, key: str) -> None:
def __len__(self) -> int:
return len(self._sub_layers)

def __iter__(self) -> Iterator[Layer]:
def __iter__(self) -> Iterator[str]:
return iter(self._sub_layers)

def __contains__(self, key: str) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions python/paddle/static/nn/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def accuracy(input, label, k=1, correct=None, total=None):
>>> paddle.seed(2023)
>>> paddle.enable_static()
>>> data = static.data(name="input", shape=[-1, 32, 32], dtype="float32")
>>> label = static.data(name="label", shape=[-1,1], dtype="int")
>>> label = static.data(name="label", shape=[-1,1], dtype="int64")
>>> fc_out = static.nn.fc(x=data, size=10)
>>> predict = F.softmax(x=fc_out)
>>> result = static.accuracy(input=predict, label=label, k=5)
Expand Down Expand Up @@ -196,7 +196,7 @@ def auc(

>>> paddle.seed(2023)
>>> data = paddle.static.data(name="input", shape=[-1, 32,32], dtype="float32")
>>> label = paddle.static.data(name="label", shape=[-1], dtype="int")
>>> label = paddle.static.data(name="label", shape=[-1], dtype="int64")
>>> fc_out = paddle.static.nn.fc(x=data, size=2)
>>> predict = paddle.nn.functional.softmax(x=fc_out)
>>> result=paddle.static.auc(input=predict, label=label)
Expand Down Expand Up @@ -225,7 +225,7 @@ def auc(

>>> paddle.seed(2023)
>>> data = paddle.static.data(name="input", shape=[-1, 32,32], dtype="float32")
>>> label = paddle.static.data(name="label", shape=[-1], dtype="int")
>>> label = paddle.static.data(name="label", shape=[-1], dtype="int64")
>>> ins_tag_weight = paddle.static.data(name='ins_tag_weight', shape=[-1,16], lod_level=0, dtype='float64')
>>> fc_out = paddle.static.nn.fc(x=data, size=2)
>>> predict = paddle.nn.functional.softmax(x=fc_out)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/static/nn/sequence_lod.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def sequence_softmax(input, use_cudnn=False, name=None):
>>> paddle.enable_static()

>>> x = paddle.static.data(name='x', shape=[7, 1],
dtype='float32', lod_level=1)
... dtype='float32', lod_level=1)
>>> x_sequence_softmax_1 = paddle.static.nn.sequence_softmax(input=x)

>>> y = paddle.static.data(name='y', shape=[7],
Expand Down
6 changes: 4 additions & 2 deletions python/paddle/tensor/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1739,12 +1739,14 @@ def triu_(
@overload
def meshgrid(
args: Sequence[paddle.Tensor], name: str | None = None
) -> paddle.Tensor:
) -> list[paddle.Tensor]:
...


@overload
def meshgrid(*args: paddle.Tensor, name: str | None = None) -> paddle.Tensor:
def meshgrid(
*args: paddle.Tensor, name: str | None = None
) -> list[paddle.Tensor]:
...


Expand Down
5 changes: 1 addition & 4 deletions python/paddle/vision/models/vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from typing import (
TYPE_CHECKING,
Any,
Literal,
TypedDict,
)
Expand Down Expand Up @@ -119,9 +118,7 @@ def forward(self, x: Tensor) -> Tensor:
return x


def make_layers(
cfg: dict[str, list[Any]], batch_norm: bool = False
) -> Sequential:
def make_layers(cfg: list[object], batch_norm: bool = False) -> Sequential:
layers = []
in_channels = 3
for v in cfg:
Expand Down
32 changes: 22 additions & 10 deletions python/paddle/vision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,23 +1604,35 @@ class RandomAffine(BaseTransform[_InputT, _RetT]):
[3, 256, 300]
"""

degrees: Sequence[float]
translate: tuple[float, float] | None
scale: tuple[float, float] | None
shear: float | Sequence[float] | None
degrees: float | list[float] | tuple[float, float]
translate: list[float] | tuple[float, float] | None
scale: list[float] | tuple[float, float] | None
shear: (
float
| list[float]
| tuple[float, float]
| tuple[float, float, float, float]
| None
)
interpolation: _InterpolationPil | _InterpolationCv2
fill: Size3
center: tuple[float, float]
center: list[float] | tuple[float, float]

def __init__(
self,
degrees: float | Sequence[float],
translate: tuple[float, float] | None = None,
scale: tuple[float, float] | None = None,
shear: float | Sequence[float] | None = None,
degrees: float | list[float] | tuple[float, float],
translate: list[float] | tuple[float, float] | None = None,
scale: list[float] | tuple[float, float] | None = None,
shear: (
float
| list[float]
| tuple[float, float]
| tuple[float, float, float, float]
| None
) = None,
interpolation: _InterpolationPil | _InterpolationCv2 = 'nearest',
fill: Size3 = 0,
center: tuple[float, float] = None,
center: list[float] | tuple[float, float] = None,
keys: _TransformInputKeys | None = None,
) -> None:
self.degrees = _setup_angle(degrees, name="degrees", req_sizes=(2,))
Expand Down