latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.distributed.algorithms.ddp_comm_hooks.default_hooks API
Functions 5
allreduce_hook
functionFull reference ↗- tensorplay.distributed.algorithms.ddp_comm_hooks.default_hooks.allreduce_hook(process_group, bucket: GradBucket)[source]
Call
allreduceusingGradBuckettensors.Once gradient tensors are aggregated across all workers, its
thencallback takes the mean and returns the result.If user registers this DDP communication hook, DDP results is expected to be same as the case where no hook was registered. Hence, this won’t change behavior of DDP and user can use this as a reference or modify this hook to log useful information or any other purposes while unaffecting DDP behavior.
- Example::
>>> # xdoctest: +SKIP >>> ddp_model.register_comm_hook(process_group, allreduce_hook)
bf16_compress_hook
functionFull reference ↗- tensorplay.distributed.algorithms.ddp_comm_hooks.default_hooks.bf16_compress_hook(process_group, bucket)[source]
Warning: This API is experimental, and it requires NCCL version later than 2.9.6.
This DDP communication hook implements a simple gradient compression approach that casts
GradBuckettensor to half-precision Brain floating point format (tensorplay.bfloat16) and then divides it by the process group size. It allreduces thosebfloat16gradient tensors. Once compressed gradient tensors are allreduced, the chained callbackdecompresscasts it back to the input data type (such asfloat32).- Example::
>>> # xdoctest: +SKIP >>> ddp_model.register_comm_hook(process_group, bf16_compress_hook)
bf16_compress_wrapper
functionFull reference ↗- tensorplay.distributed.algorithms.ddp_comm_hooks.default_hooks.bf16_compress_wrapper(hook: Callable[[Any], Any])[source]
Warning: This API is experimental, and it requires NCCL version later than 2.9.6.
This wrapper casts the input gradient tensor of a given DDP communication hook to half-precision Brain floating point format (
bfloat16) and casts the resulting tensor of the given hook back to the input data type.Therefore,
bf16_compress_hookis equivalent tobf16_compress_wrapper(allreduce_hook).- Example::
>>> # xdoctest: +SKIP >>> state = PowerSGDState(process_group=process_group, matrix_approximation_rank=1, start_powerSGD_iter=10) >>> ddp_model.register_comm_hook(state, bf16_compress_wrapper(powerSGD_hook))
fp16_compress_hook
functionFull reference ↗- tensorplay.distributed.algorithms.ddp_comm_hooks.default_hooks.fp16_compress_hook(process_group, bucket)[source]
Compress by casting
GradBucketto float16 divided by process group size.This DDP communication hook implements a simple gradient compression approach that casts
GradBuckettensor to half-precision floating-point format (tensorplay.float16) and then divides it by the process group size. It allreduces thosefloat16gradient tensors. Once compressed gradient tensors are allreduced, the chained callbackdecompresscasts it back to the input data type (such asfloat32).- Example::
>>> # xdoctest: +SKIP >>> ddp_model.register_comm_hook(process_group, fp16_compress_hook)
fp16_compress_wrapper
functionFull reference ↗- tensorplay.distributed.algorithms.ddp_comm_hooks.default_hooks.fp16_compress_wrapper(hook: Callable[[Any], Any])[source]
Cast input tensor to
float16, cast result of hook back to input dtype.This wrapper casts the input gradient tensor of a given DDP communication hook to half-precision floating point format (
float16), and casts the resulting tensor of the given hook back to the input data type, such asfloat32. Therefore,fp16_compress_hookis equivalent tofp16_compress_wrapper(allreduce_hook).- Example::
>>> # xdoctest: +SKIP >>> state = PowerSGDState(process_group=process_group, matrix_approximation_rank=1, start_powerSGD_iter=10) >>> ddp_model.register_comm_hook(state, fp16_compress_wrapper(powerSGD_hook))
Help improve this page
Found an error, an unclear step, or a missing example?
tensorplay.distributed.algorithms.ddp_comm_hooks.ddp_zero_hook API
Complete API reference for tensorplay.distributed.algorithms.ddp_comm_hooks.ddp_zero_hook, including signatures, parameters, examples and members.
tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook API
Complete API reference for tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook, including signatures, parameters, examples and members.

