mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[torch/multiprocessing] Use multiprocessing.reduction.register ForkingPickler.register to register custom tensor and storage reductions (#135030)
Right now `multiprocessing.reduction.register()` is simply an alias to `multiprocessing.reduction.ForkingPickler.register()` https://github.com/python/cpython/blame/main/Lib/multiprocessing/reduction.py#L56, but the top-level `register()` function exposes less of the internal details of `multiprocessing.reduction` module. Pull Request resolved: https://github.com/pytorch/pytorch/pull/135030 Approved by: https://github.com/albanD
This commit is contained in:
committed by
PyTorch MergeBot
parent
a0c7029a75
commit
abd16a8c64
@ -2,7 +2,7 @@
|
||||
import multiprocessing
|
||||
import os
|
||||
import threading
|
||||
from multiprocessing.reduction import ForkingPickler
|
||||
from multiprocessing import reduction
|
||||
from multiprocessing.util import register_after_fork
|
||||
from typing import Union
|
||||
|
||||
@ -626,22 +626,22 @@ def reduce_storage(storage):
|
||||
|
||||
|
||||
def init_reductions():
|
||||
ForkingPickler.register(torch.cuda.Event, reduce_event)
|
||||
reduction.register(torch.cuda.Event, reduce_event)
|
||||
|
||||
for t in torch._storage_classes:
|
||||
if t.__name__ == "UntypedStorage":
|
||||
ForkingPickler.register(t, reduce_storage)
|
||||
reduction.register(t, reduce_storage)
|
||||
else:
|
||||
ForkingPickler.register(t, reduce_typed_storage_child)
|
||||
reduction.register(t, reduce_typed_storage_child)
|
||||
|
||||
ForkingPickler.register(torch.storage.TypedStorage, reduce_typed_storage)
|
||||
reduction.register(torch.storage.TypedStorage, reduce_typed_storage)
|
||||
|
||||
for t in torch._tensor_classes:
|
||||
ForkingPickler.register(t, reduce_tensor)
|
||||
reduction.register(t, reduce_tensor)
|
||||
|
||||
# TODO: Maybe this should be in tensor_classes? :)
|
||||
ForkingPickler.register(torch.Tensor, reduce_tensor)
|
||||
reduction.register(torch.Tensor, reduce_tensor)
|
||||
|
||||
from torch.nn.parameter import Parameter
|
||||
|
||||
ForkingPickler.register(Parameter, reduce_tensor)
|
||||
reduction.register(Parameter, reduce_tensor)
|
||||
|
Reference in New Issue
Block a user