feat: support broadcasting picklable objects in idist.broadcast - #3832
zongyang078 wants to merge 1 commit into
Conversation
|
@vfdev-5 one design question. I only documented it with a |
|
@zongyang078 thanks for raising this point. I had to read the pytorch docstring until the end yesterday :(
(https://docs.pytorch.org/docs/2.14/distributed.html#torch.distributed.broadcast_object_list) I'm now hesitating to use it as it may not output what user is expecting... |
|
Agreed — the CPU round trip is worse than just the device mismatch. I looked into the pytree route: I'm not sure how you'd weigh the trade-offs, though. It costs one collective per leaf plus one for the spec instead of a single one. And it narrows the feature: a leaf that is not a tensor/number/str — a custom class instance, say — is a pytree leaf, so keeping "any picklable object" would need a pickle fallback for those leaves only, with tensors still taking the native path. If it would help, I can push it as a second commit here so the two approaches can be compared side by side. |
|
@zongyang078 thanks for digging into that! I was then checking your original PR with specification for list/mappings and you use all_gather object list route, but as we may doubt this I would like to run some benchmarks: A vs B where (if you would like to help with that) |
Related to #1757, prerequisite for #3789. Follows @vfdev-5's suggestion in #3789 (comment).
Description:
idist.broadcastonly handlestorch.Tensor, numbers,strandpathlib.Path, and raisesTypeErrorotherwise, whileidist.all_gatheralready falls back to an object collective. This givesbroadcastthe same capability viatorch.distributed.broadcast_object_list._do_broadcast_object_listonComputationModel:dist.broadcast_object_listfor native,hvd.broadcast_objectfor horovod,NotImplementedErrorfor xla (as with_do_all_gather_object)ComputationModel.broadcastdispatches to it for any input that is not a tensor/number/str/PathAnyin theidist.broadcasttypehint;broadcastandall_gatherdocstrings now document picklable-object support_setup_placeholdernow also returns the input type tag agreed on by every rank. An object input has no meaningful placeholder, so a non-source rank cannot decide from its own value which collective the source is about to call — it has to branch on the negotiated tag instead. Details in the code comments.Behaviour change:
broadcastno longer raisesTypeError("Unhandled input type"). The test asserting that now asserts a successful object broadcast, except on xla where it assertsNotImplementedError.Check list: