# tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook API Source: https://www.tensorplay.cn/docs/api/tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.html ## Functions 1 [#](#api-tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.post_localSGD_hook) ### post_localSGD_hook function[Full reference ↗](/docs/generated/tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.post_localSGD_hook.html) ```python tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.post_localSGD_hook(state: PostLocalSGDState, bucket: GradBucket) ``` Run post-localSGD algorithm. This DDP communication hook is used for running post-localSGD algorithm, by combining with a model averaging component (e.g., [PeriodicModelAverager](/docs/generated/tensorplay.distributed.algorithms.model_averaging.PeriodicModelAverager.html#tensorplay.distributed.algorithms.model_averaging.PeriodicModelAverager)) that runs after the optimizer step. Parameters: - state ([PostLocalSGDState](/docs/generated/tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.PostLocalSGDState.html#tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.PostLocalSGDState)) – State information to run post-localSGD. Users mainly need to tune start_localSGD_iter to determine when to start local SGD. - bucket (dist.GradBucket) – Bucket that stores a 1D flattened gradient tensor that batches multiple per-variable tensors. Note that since DDP comm hook only supports single process single device mode, only exactly one tensor is stored in this bucket. Returns: Future handler of the communication, which updates the gradients in place. Example:: ``` >>> # xdoctest: +SKIP >>> state = PostLocalSGDState(process_group=process_group, subgroup=subgroup, start_localSGD_iter=10) >>> ddp_model.register_comm_hook(state, post_localSGD_hook) >>> # Also need to establish a model averaging module and run model averaging after ``optimizer.step()``. ``` ## Classes 1 [#](#api-tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.PostLocalSGDState) ### PostLocalSGDState class[Full reference ↗](/docs/generated/tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.PostLocalSGDState.html) ```python class tensorplay.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook.PostLocalSGDState(process_group, subgroup, start_localSGD_iter, post_local_gradient_allreduce=True) ``` Store state for all-reducing gradients globally until given step, then locally after. Stores the state for all-reducing gradients globally using process_group until step start_localSGD_iter, and all-reducing gradients locally using subgroup afterwards. If process_group is None, the global process group will be used. If subgroup is None, the intra-node process group on each machine will be used. Additionally, post_local_gradient_allreduce may be worth tuning, because both true and false may give a faster convergence. ```python maybe_increase_iter(bucket) ``` Track iterations and trigger log message at start of local SGD.