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

[multiprocessing] Add paddle.incubate.multiprocessing for sharing tensors between python processes. #37302

Merged
merged 17 commits into from
Mar 14, 2022

Conversation

ZHUI
Copy link
Collaborator

@ZHUI ZHUI commented Nov 17, 2021

PR types

New features

PR changes

Others

Describe

Add paddle.incubate.multiprocessing for tensor sharing between python process.

This PR aims give an initial version of paddle.incubate.multiprocessing which support both CPU and GPU tensor.
Here are some TODOs for this PR. The full RoadMap is at the end of this PR。

  • Support FlickerPickle for tensor passing
  • Support passing CPU tensor on linux
  • Support passing CUDA tensor using cudaIpcMemHandle on linux
  • Full test of all tensor behavior

Useage

import paddle
import paddle.multiprocessing as mp

paddle.set_device("cpu")

def fill_tensor(queue, event):
    data = queue.get()
    data[:] = 5
    event.set()

tensor = paddle.zeros([5, 5], dtype="float32")
queue = mp.Queue()
event = mp.Event()
queue.put(tensor)

process = ctx.Process(target=fill_tensor, args=(queue, event))
process.daemon = True
process.start()
event.wait(30)
print(tensor)
# Tensor(shape=[5, 5], dtype=float32, place=CPUPlace, stop_gradient=True,
#        [[5., 5., 5., 5., 5.],
#         [5., 5., 5., 5., 5.],
#         [5., 5., 5., 5., 5.],
#         [5., 5., 5., 5., 5.],
#         [5., 5., 5., 5., 5.]])
process.join(1)

Paddle.multiprocessing RoadMap

Sharing CPU Tensor.

  • Support global reference counts for IPC CPU tensor

platform

  • linux
  • mac
  • win32

other

  • support file descriptor mode on linux

Sharing GPU Tensor.

  • Support cudaIpcMemHandle GPU tensor
  • Support global reference counts for IPC GPU tensor.

other

  • Support ROCM
  • Support cudaIpcEventHandle

Influence on Paddle Framework

  • Networks Define
  • Data Struct of paddle
  • Operator
  • Data I/O
  • Executor
  • Distributed training
  • Model saving
  • Inference

Application

  • Support DataLoader

@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Nov 21, 2021
@PaddlePaddle PaddlePaddle unlocked this conversation Nov 21, 2021
@paddle-bot-old
Copy link

Sorry to inform you that 2f5a055's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Jan 25, 2022
@PaddlePaddle PaddlePaddle unlocked this conversation Jan 25, 2022
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Jan 26, 2022
@PaddlePaddle PaddlePaddle unlocked this conversation Jan 26, 2022
@PaddlePaddle PaddlePaddle deleted a comment from paddle-bot-old bot Jan 27, 2022
Shixiaowei02
Shixiaowei02 previously approved these changes Feb 14, 2022
@ZHUI ZHUI marked this pull request as ready for review February 15, 2022 05:31
@ZHUI ZHUI requested a review from wawltor February 28, 2022 13:03
@ZHUI ZHUI changed the title [multiprocessing] Add paddle.multiprocessing for sharing tensors between python processes. [multiprocessing] Add paddle.incubate.multiprocessing for sharing tensors between python processes. Feb 28, 2022
@ZHUI ZHUI removed the request for review from wawltor March 3, 2022 09:18
@@ -131,4 +131,7 @@ cc_library(virtual_memory_auto_growth_best_fit_allocator SRCS virtual_memory_aut
if(NOT WIN32)
cc_library(mmap_allocator SRCS mmap_allocator.cc DEPS allocator)
cc_test(mmap_allocator_test SRCS mmap_allocator_test.cc DEPS mmap_allocator allocator)
if (WITH_GPU)
Copy link
Contributor

Choose a reason for hiding this comment

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

这块需要限制成非WIN32吗? 下面cuda_ipc_allocator在define的时候限制了非WIN32

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

没有尝试,cmake里这么写,也可以减少 WIN32下的编译问题

paddle/fluid/memory/allocation/cuda_ipc_allocator.cc Outdated Show resolved Hide resolved
paddle/fluid/memory/allocation/cuda_ipc_allocator.h Outdated Show resolved Hide resolved
paddle/fluid/pybind/pybind.cc Outdated Show resolved Hide resolved
paddle/fluid/pybind/pybind.cc Show resolved Hide resolved
paddle/fluid/pybind/pybind.cc Show resolved Hide resolved
if tensor.place.is_cpu_place() or tensor.place.is_gpu_place(
) or tensor.place.is_cuda_pinned_place():
if type(tensor) == paddle.fluid.framework.ParamBase:
metadata = copy.deepcopy(tensor.__dict__)
Copy link
Contributor

Choose a reason for hiding this comment

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

这里有个疑问,为啥知识对Parameter类型进行deep copy了?或者说这里对persisable类型要进行deep copy

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

因为 Parameter 的一些属性比较多,对于普通的Tensor我们只单独记录了 stop_gradients 属性,

Copy link
Contributor

@wawltor wawltor left a comment

Choose a reason for hiding this comment

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

LGTM

@ZHUI ZHUI requested a review from XiaoguangHu01 March 10, 2022 06:06
Copy link
Contributor

@XieYunshen XieYunshen left a comment

Choose a reason for hiding this comment

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

LGTM for set_tests_properties(test_paddle_multiprocessing PROPERTIES TIMEOUT 120)

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

LGTM for skipIf

@ZHUI ZHUI requested a review from zhiqiu March 10, 2022 06:44
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@ZHUI
Copy link
Collaborator Author

ZHUI commented Feb 9, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants