Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions alf/trainers/policy_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,7 @@ def __init__(self, config: TrainerConfig, ddp_rank: int = -1):
# Make sure the BN statistics of different processes are synced
# https://pytorch.org/docs/stable/generated/torch.nn.SyncBatchNorm.html#torch.nn.SyncBatchNorm
# This conversion needs to be performed before wrapping modules with DDP.
self._algorithm = torch.nn.SyncBatchNorm.convert_sync_batchnorm(
self._algorithm)
self._algorithm = common.convert_sync_batchnorm(self._algorithm)

# Create a thread env to expose subprocess gin/alf configurations
# which otherwise will be marked as "inoperative". Only created when
Expand Down
9 changes: 9 additions & 0 deletions alf/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,3 +1714,12 @@ def get_unused_port(start, end=65536, n=1):
if process_locks:
for process_lock in process_locks:
process_lock.release()


try:
import timm
# timm models may contain BatchNormAct2d, which is not supported by torch.nn.SyncBatchNorm.
# Need to use timm's convert_sync_batchnorm.
convert_sync_batchnorm = timm.layers.convert_sync_batchnorm
except ImportError:
convert_sync_batchnorm = torch.nn.SyncBatchNorm.convert_sync_batchnorm