From 6e805a2ed17f1a2b3efb001a19f626c01f579254 Mon Sep 17 00:00:00 2001 From: megemini Date: Wed, 21 Aug 2024 16:17:11 +0800 Subject: [PATCH] =?UTF-8?q?[Typing]=20=E4=BF=AE=E5=A4=8D=20`shard=5Foptimi?= =?UTF-8?q?zer`=20=E4=BB=A5=E5=8F=8A=E7=A4=BA=E4=BE=8B=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=A0=87=E6=B3=A8=E9=94=99=E8=AF=AF=20(#6752?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Fix] typing * [Fix] typing and ex run timeout --- python/paddle/audio/datasets/esc50.py | 5 +++-- python/paddle/audio/datasets/tess.py | 5 +++-- .../paddle/distributed/auto_parallel/api.py | 2 +- .../communication/stream/all_to_all.py | 4 ++-- python/paddle/geometric/sampling/neighbors.py | 2 +- python/paddle/io/dataloader/dataset.py | 4 ++-- python/paddle/vision/transforms/transforms.py | 22 +++++++++---------- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/python/paddle/audio/datasets/esc50.py b/python/paddle/audio/datasets/esc50.py index 6ab4b85087f9f..9980ad5895f88 100644 --- a/python/paddle/audio/datasets/esc50.py +++ b/python/paddle/audio/datasets/esc50.py @@ -64,10 +64,11 @@ class ESC50(AudioClassificationDataset): .. code-block:: python + >>> # doctest: +TIMEOUT(60) >>> import paddle >>> mode = 'dev' - >>> esc50_dataset = paddle.audio.datasets.ESC50(mode=mode, + >>> esc50_dataset = paddle.audio.datasets.ESC50(mode=mode, # type: ignore[arg-type] ... feat_type='raw') >>> for idx in range(5): ... audio, label = esc50_dataset[idx] @@ -80,7 +81,7 @@ class ESC50(AudioClassificationDataset): [220500] 36 [220500] 19 - >>> esc50_dataset = paddle.audio.datasets.ESC50(mode=mode, + >>> esc50_dataset = paddle.audio.datasets.ESC50(mode=mode, # type: ignore[arg-type] ... feat_type='mfcc', ... n_mfcc=40) >>> for idx in range(5): diff --git a/python/paddle/audio/datasets/tess.py b/python/paddle/audio/datasets/tess.py index a4e91afd563f8..def08bff92abc 100644 --- a/python/paddle/audio/datasets/tess.py +++ b/python/paddle/audio/datasets/tess.py @@ -53,10 +53,11 @@ class TESS(AudioClassificationDataset): .. code-block:: python + >>> # doctest: +TIMEOUT(60) >>> import paddle >>> mode = 'dev' - >>> tess_dataset = paddle.audio.datasets.TESS(mode=mode, + >>> tess_dataset = paddle.audio.datasets.TESS(mode=mode, # type: ignore[arg-type] ... feat_type='raw') >>> for idx in range(5): ... audio, label = tess_dataset[idx] @@ -64,7 +65,7 @@ class TESS(AudioClassificationDataset): ... print(audio.shape, label) ... # [audio_data_length] , label_id - >>> tess_dataset = paddle.audio.datasets.TESS(mode=mode, + >>> tess_dataset = paddle.audio.datasets.TESS(mode=mode, # type: ignore[arg-type] ... feat_type='mfcc', ... n_mfcc=40) >>> for idx in range(5): diff --git a/python/paddle/distributed/auto_parallel/api.py b/python/paddle/distributed/auto_parallel/api.py index f4a67c3d72cc2..cdd0e322bba93 100644 --- a/python/paddle/distributed/auto_parallel/api.py +++ b/python/paddle/distributed/auto_parallel/api.py @@ -1447,7 +1447,7 @@ def __call__(self, key: str, param: Tensor, accumulator: Tensor) -> Tensor: def shard_optimizer( optimizer: Optimizer, - shard_fn: Callable[[str, Layer, ProcessMesh], None] | None = None, + shard_fn: Callable[[str, Tensor, Tensor], Tensor] | None = None, ) -> _ShardOptimizer: """ diff --git a/python/paddle/distributed/communication/stream/all_to_all.py b/python/paddle/distributed/communication/stream/all_to_all.py index 9f0e468a3357c..9e213144fdaf6 100644 --- a/python/paddle/distributed/communication/stream/all_to_all.py +++ b/python/paddle/distributed/communication/stream/all_to_all.py @@ -319,7 +319,7 @@ def alltoall_single( >>> else: ... data = paddle.to_tensor([2, 3]) >>> task = dist.stream.alltoall_single(output, data, sync_op=False) - >>> task.wait() # type: ignore[union-attr] + >>> task.wait() >>> out = output.numpy() >>> print(out) >>> # [0, 2] (2 GPUs, out for rank 0) @@ -339,7 +339,7 @@ def alltoall_single( ... out_split_sizes, ... in_split_sizes, ... sync_op=False) - >>> task.wait() # type: ignore[union-attr] + >>> task.wait() >>> out = output.numpy() >>> print(out) >>> # [[0., 0.], [1., 1.]] (2 GPUs, out for rank 0) diff --git a/python/paddle/geometric/sampling/neighbors.py b/python/paddle/geometric/sampling/neighbors.py index f305a40f26583..e0937fcf268dd 100644 --- a/python/paddle/geometric/sampling/neighbors.py +++ b/python/paddle/geometric/sampling/neighbors.py @@ -133,7 +133,7 @@ def sample_neighbors( >>> row = paddle.to_tensor(row, dtype="int64") >>> colptr = paddle.to_tensor(colptr, dtype="int64") >>> nodes = paddle.to_tensor(nodes, dtype="int64") - >>> out_neighbors, out_count = paddle.geometric.sample_neighbors(row, colptr, nodes, sample_size=sample_size) + >>> out_neighbors, out_count = paddle.geometric.sample_neighbors(row, colptr, nodes, sample_size=sample_size, return_eids=False) """ diff --git a/python/paddle/io/dataloader/dataset.py b/python/paddle/io/dataloader/dataset.py index e1c7cd95edd8d..d1b6ae9edf911 100755 --- a/python/paddle/io/dataloader/dataset.py +++ b/python/paddle/io/dataloader/dataset.py @@ -65,7 +65,7 @@ class Dataset(Generic[_T]): >>> from paddle.io import Dataset >>> # define a random dataset - >>> class RandomDataset(Dataset): + >>> class RandomDataset(Dataset): # type: ignore[type-arg] ... def __init__(self, num_samples): ... self.num_samples = num_samples ... @@ -438,7 +438,7 @@ class ChainDataset(IterableDataset[Any]): >>> # define a random dataset - >>> class RandomDataset(IterableDataset): + >>> class RandomDataset(IterableDataset): # type: ignore[type-arg] ... def __init__(self, num_samples): ... self.num_samples = num_samples ... diff --git a/python/paddle/vision/transforms/transforms.py b/python/paddle/vision/transforms/transforms.py index c63228d9864b0..e7916dcf4bab6 100644 --- a/python/paddle/vision/transforms/transforms.py +++ b/python/paddle/vision/transforms/transforms.py @@ -387,7 +387,7 @@ class ToTensor(BaseTransform[_InputT, "Tensor"]): >>> img_arr = ((paddle.rand((4, 5, 3)) * 255.).astype('uint8')).numpy() >>> fake_img = Image.fromarray(img_arr) >>> transform = T.ToTensor() - >>> tensor = transform(fake_img) + >>> tensor = transform(fake_img) # type: ignore[call-overload] >>> print(tensor.shape) [3, 4, 5] >>> print(tensor.dtype) @@ -530,7 +530,7 @@ class RandomResizedCrop(BaseTransform[_InputT, _RetT]): >>> transform = RandomResizedCrop(224) >>> fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.size) (224, 224) @@ -736,7 +736,7 @@ class CenterCrop(BaseTransform[_InputT, _RetT]): >>> transform = CenterCrop(224) >>> fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.size) (224, 224) @@ -985,7 +985,7 @@ class Transpose(BaseTransform[_InputT, _RetT]): >>> transform = Transpose() >>> fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.shape) (3, 300, 320) @@ -1089,7 +1089,7 @@ class ContrastTransform(BaseTransform[_InputT, _RetT]): >>> transform = ContrastTransform(0.4) >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.size) (224, 224) @@ -1138,7 +1138,7 @@ class SaturationTransform(BaseTransform[_InputT, _RetT]): >>> transform = SaturationTransform(0.4) >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.size) (224, 224) """ @@ -1184,7 +1184,7 @@ class HueTransform(BaseTransform[_InputT, _RetT]): >>> transform = HueTransform(0.4) >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.size) (224, 224) @@ -1239,7 +1239,7 @@ class ColorJitter(BaseTransform[_InputT, _RetT]): >>> transform = ColorJitter(0.4, 0.4, 0.4, 0.4) >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.size) (224, 224) @@ -1480,7 +1480,7 @@ class Pad(BaseTransform[_InputT, _RetT]): >>> transform = Pad(2) >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.size) (228, 228) """ @@ -1778,7 +1778,7 @@ class RandomRotation(BaseTransform[_InputT, _RetT]): >>> transform = RandomRotation(90) >>> fake_img = Image.fromarray((np.random.rand(200, 150, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(fake_img.size) (150, 200) """ @@ -2012,7 +2012,7 @@ class Grayscale(BaseTransform[_InputT, _RetT]): >>> transform = Grayscale() >>> fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8)) - >>> fake_img = transform(fake_img) + >>> fake_img = transform(fake_img) # type: ignore[call-overload] >>> print(np.array(fake_img).shape) (224, 224) """