From fc3b3c0a332a1671a0a9b047d38d84e937480cfa Mon Sep 17 00:00:00 2001 From: pangengzheng Date: Sun, 25 Jun 2023 15:36:56 +0800 Subject: [PATCH 1/4] exclude xpu --- paddle/phi/kernels/kps/elementwise_add_kernel.cu | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/paddle/phi/kernels/kps/elementwise_add_kernel.cu b/paddle/phi/kernels/kps/elementwise_add_kernel.cu index 31d1e4e32cf54..b3fe46a1cd310 100644 --- a/paddle/phi/kernels/kps/elementwise_add_kernel.cu +++ b/paddle/phi/kernels/kps/elementwise_add_kernel.cu @@ -72,14 +72,18 @@ void AddKernel(const Context& dev_ctx, const DenseTensor& x, const DenseTensor& y, DenseTensor* out) { +#ifdef PADDLE_WITH_CUDA if (x.dtype() == phi::DataType::FLOAT32 && (y.dtype() == phi::DataType::BFLOAT16 || y.dtype() == phi::DataType::FLOAT16)) { using Type = DataTypeToCppType::type; Float32Bfloat16OrFloat16AddCudaFunctor(dev_ctx, x, y, out); } else { +#endif AddCudaFunctor(dev_ctx, x, y, -1, out); +#ifdef PADDLE_WITH_CUDA } +#endif } template From f5d421816c89774b06095a0a2314872fc5e53bed Mon Sep 17 00:00:00 2001 From: pangengzheng Date: Thu, 7 Dec 2023 15:39:48 +0800 Subject: [PATCH 2/4] fix save and load doc and not expose api in checkpoint dir --- python/paddle/distributed/checkpoint/__init__.py | 8 -------- python/paddle/distributed/checkpoint/load_state_dict.py | 4 ++-- python/paddle/distributed/checkpoint/save_state_dict.py | 4 ++-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/python/paddle/distributed/checkpoint/__init__.py b/python/paddle/distributed/checkpoint/__init__.py index da89b737adfb8..595add0aed9e1 100644 --- a/python/paddle/distributed/checkpoint/__init__.py +++ b/python/paddle/distributed/checkpoint/__init__.py @@ -11,11 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -from .save_state_dict import save_state_dict -from .load_state_dict import load_state_dict - -__all__ = [ - "save_state_dict", - "load_state_dict", -] diff --git a/python/paddle/distributed/checkpoint/load_state_dict.py b/python/paddle/distributed/checkpoint/load_state_dict.py index 153c6764d70d6..58dc094c53766 100644 --- a/python/paddle/distributed/checkpoint/load_state_dict.py +++ b/python/paddle/distributed/checkpoint/load_state_dict.py @@ -361,7 +361,8 @@ def load_state_dict( coordinator_rank(int): The rank used to coordinate the checkpoint. Rank0 is used by default. Example: .. code-block:: python - >>> # doctest: +SKIP('Load state dict.') + + >>> # doctest: +REQUIRES(env:GPU) >>> import paddle >>> import paddle.distributed as dist >>> ckpt_path = "./checkpoint" @@ -380,7 +381,6 @@ def load_state_dict( [8 , 9 , 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 29, 30, 31]])} - >>> # doctest: -SKIP """ assert isinstance( state_dict, dict diff --git a/python/paddle/distributed/checkpoint/save_state_dict.py b/python/paddle/distributed/checkpoint/save_state_dict.py index 4b7f3665d86da..c774ab832d835 100644 --- a/python/paddle/distributed/checkpoint/save_state_dict.py +++ b/python/paddle/distributed/checkpoint/save_state_dict.py @@ -88,7 +88,8 @@ def save_state_dict( Examples: .. code-block:: python - >>> # doctest: +SKIP('Save state dict.') + + >>> # doctest: +REQUIRES(env:GPU) >>> import paddle >>> import paddle.distributed as dist >>> w1 = paddle.arange(32).reshape([4, 8]) @@ -96,7 +97,6 @@ def save_state_dict( >>> sharded_w1 = dist.shard_tensor(w1, mesh, [dist.Shard(0), dist.Replicate()]) >>> state_dict = {"w1": sharded_w1} >>> dist.save_state_dict(state_dict, "./checkpoint") - >>> # doctest: -SKIP """ assert isinstance( From 69ec51f2cde9fd898c29577efba738acc4ba8c32 Mon Sep 17 00:00:00 2001 From: pangengzheng Date: Fri, 8 Dec 2023 17:56:11 +0800 Subject: [PATCH 3/4] skip example --- python/paddle/distributed/checkpoint/load_state_dict.py | 3 ++- python/paddle/distributed/checkpoint/save_state_dict.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/python/paddle/distributed/checkpoint/load_state_dict.py b/python/paddle/distributed/checkpoint/load_state_dict.py index 58dc094c53766..d0f58c2e00354 100644 --- a/python/paddle/distributed/checkpoint/load_state_dict.py +++ b/python/paddle/distributed/checkpoint/load_state_dict.py @@ -362,7 +362,7 @@ def load_state_dict( Example: .. code-block:: python - >>> # doctest: +REQUIRES(env:GPU) + >>> # doctest: +SKIP('run in distributed mode.') >>> import paddle >>> import paddle.distributed as dist >>> ckpt_path = "./checkpoint" @@ -381,6 +381,7 @@ def load_state_dict( [8 , 9 , 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 29, 30, 31]])} + >>> # doctest: -SKIP """ assert isinstance( state_dict, dict diff --git a/python/paddle/distributed/checkpoint/save_state_dict.py b/python/paddle/distributed/checkpoint/save_state_dict.py index c774ab832d835..4e595d22d20b6 100644 --- a/python/paddle/distributed/checkpoint/save_state_dict.py +++ b/python/paddle/distributed/checkpoint/save_state_dict.py @@ -89,7 +89,7 @@ def save_state_dict( Examples: .. code-block:: python - >>> # doctest: +REQUIRES(env:GPU) + >>> # doctest: +SKIP('run in distributed mode') >>> import paddle >>> import paddle.distributed as dist >>> w1 = paddle.arange(32).reshape([4, 8]) @@ -97,6 +97,7 @@ def save_state_dict( >>> sharded_w1 = dist.shard_tensor(w1, mesh, [dist.Shard(0), dist.Replicate()]) >>> state_dict = {"w1": sharded_w1} >>> dist.save_state_dict(state_dict, "./checkpoint") + >>> # doctest: -SKIP """ assert isinstance( From 37b6b8640a97b67275f008d417a2611bcb230562 Mon Sep 17 00:00:00 2001 From: pangengzheng Date: Wed, 13 Dec 2023 15:01:04 +0800 Subject: [PATCH 4/4] fix doc --- python/paddle/distributed/checkpoint/load_state_dict.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/paddle/distributed/checkpoint/load_state_dict.py b/python/paddle/distributed/checkpoint/load_state_dict.py index d0f58c2e00354..d0dc742adbe21 100644 --- a/python/paddle/distributed/checkpoint/load_state_dict.py +++ b/python/paddle/distributed/checkpoint/load_state_dict.py @@ -354,11 +354,13 @@ def load_state_dict( ) -> None: """ Load the state_dict inplace from a checkpoint path. + Args: state_dict(Dict[str, paddle.Tensor]): The state_dict to load. It will be modified inplace after loading. path(str): The directory to load checkpoint files. process_group(paddle.distributed.collective.Group): ProcessGroup to be used for cross-rank synchronization. Use the default process group which contains all cards. coordinator_rank(int): The rank used to coordinate the checkpoint. Rank0 is used by default. + Example: .. code-block:: python