/usr/local/lib64/python3.6/site-packages/torch/nn/modules/__pycache__
NameSizeModeActions
activation.cpython-36.pyc476350644editdlrm
adaptive.cpython-36.pyc97250644editdlrm
batchnorm.cpython-36.pyc310390644editdlrm
channelshuffle.cpython-36.pyc19010644editdlrm
container.cpython-36.pyc279700644editdlrm
conv.cpython-36.pyc577890644editdlrm
distance.cpython-36.pyc36840644editdlrm
dropout.cpython-36.pyc103100644editdlrm
flatten.cpython-36.pyc58130644editdlrm
fold.cpython-36.pyc128070644editdlrm
instancenorm.cpython-36.pyc188080644editdlrm
lazy.cpython-36.pyc116900644editdlrm
linear.cpython-36.pyc101880644editdlrm
loss.cpython-36.pyc914650644editdlrm
module.cpython-36.pyc665300644editdlrm
normalization.cpython-36.pyc113600644editdlrm
padding.cpython-36.pyc222170644editdlrm
pixelshuffle.cpython-36.pyc43980644editdlrm
pooling.cpython-36.pyc532030644editdlrm
rnn.cpython-36.pyc446530644editdlrm
sparse.cpython-36.pyc209560644editdlrm
transformer.cpython-36.pyc207370644editdlrm
upsampling.cpython-36.pyc107800644editdlrm
utils.cpython-36.pyc25280644editdlrm
_functions.cpython-36.pyc54410644editdlrm
__init__.cpython-36.pyc52360644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/modules/__pycache__/batchnorm.cpython-36.pyc (31039B)
3 Egh@s ddlmZmZddlZddlmZddlmZmZmZddl m Z ddl m Z dd l mZdd lmZdd lmZGd d d eZGdddeZGdddeeZGdddeZGdddeeZGdddeZGdddeeZGdddeZGdddeeZGdddeZdS) )OptionalAnyN)Tensor) ParameterUninitializedParameterUninitializedBuffer) functional)init) SyncBatchNorm)LazyModuleMixin)ModulecseZdZUdZdZdddddgZee e e  e  deeee e d d fd d Zd dddZd dddZddZddZfddZZS) _NormBasez+Common base of _InstanceNorm and _BatchNormrtrack_running_statsmomentumeps num_featuresaffineh㈵>皙?TN)rrrrrreturnc s||d}tt|j||_||_||_||_||_|jrftt j |f||_ tt j |f||_ n|j dd|j dd|jr|jdt j|f||jdt j|f||||jdt jd dt jid d |jD|n$|jdd|jdd|jdd|jdS) N)devicedtypeweightbias running_mean running_varnum_batches_trackedrrcSsi|]\}}|dkr||qS)r).0kvrrF/usr/local/lib64/python3.6/site-packages/torch/nn/modules/batchnorm.py 9sz&_NormBase.__init__..)r)superr__init__rrrrrrtorchemptyrrZregister_parameterZregister_bufferZzerosZonestensorlongitemsreset_parameters) selfrrrrrrrfactory_kwargs) __class__rr#r&s2      z_NormBase.__init__)rcCs*|jr&|jj|jjd|jjdS)Nr )rrZzero_rZfill_r)r-rrr#reset_running_statsAs  z_NormBase.reset_running_statscCs*|j|jr&tj|jtj|jdS)N)r0rr Zones_rZzeros_r)r-rrr#r,Is z_NormBase.reset_parameterscCstdS)N)NotImplementedError)r-inputrrr#_check_input_dimOsz_NormBase._check_input_dimcCsdjf|jS)Nzj{num_features}, eps={eps}, momentum={momentum}, affine={affine}, track_running_stats={track_running_stats})format__dict__)r-rrr# extra_reprRsz_NormBase.extra_reprc sf|jdd}|dks|dkrF|jrF|d} | |krFtjdtjd|| <tt|j|||||||dS)Nversionrrr)r)getrr'r)r*r%r_load_from_state_dict) r-Z state_dictprefixZlocal_metadatastrictZ missing_keysZunexpected_keysZ error_msgsr7Znum_batches_tracked_key)r/rr#r9Xs  z_NormBase._load_from_state_dict)rrTTNN)__name__ __module__ __qualname____doc___versionZ __constants__intrfloatrrboolrrr&r0r,r3r6r9 __classcell__rr)r/r#rs(  rcs.eZdZd fdd Zeeddd ZZS) _BatchNormh㈵>皙?TNc s*||d}tt|j|||||f|dS)N)rr)r%rEr&) r-rrrrrrrr.)r/rr#r&ws  z_BatchNorm.__init__)r2rc Cs|j||jdkrd}n|j}|jrb|jrb|jdk rb|jd|_|jdkr\dt|j}n|j}|jrnd}n|jdko|jdk}tj ||j s|jr|jnd|j s|jr|jnd|j |j |||j S)Ngr g?T) r3rtrainingrrrBrrF batch_normrrr)r-r2exponential_average_factor bn_trainingrrr#forwards.      z_BatchNorm.forward)rFrGTTNN)r<r=r>r&rrMrDrr)r/r#rEvsrEcsNeZdZUeed ddfdd Zddfdd Zddd d ZZ S) _LazyNormBaseh㈵>皙?TN)rcs||d}tt|jd||ddf|||_||_|jrPtf||_tf||_|jrtf||_ tf||_ t j ddt j idd|jD|_dS)N)rrrFrcSsi|]\}}|dkr||qS)rr)r r!r"rrr#r$sz*_LazyNormBase.__init__..)r)r%rNr&rrrrrrrrr'r)r*r+r)r-rrrrrrr.)r/rr#r&s$      z_LazyNormBase.__init__cs"|j r|jdkrtjdS)Nr)has_uninitialized_paramsrr%r,)r-)r/rr#r,sz_LazyNormBase.reset_parameterscCs|jr|jd|_|jrZt|jts*tt|jts:t|jj |jf|jj |jf|j r|j j |jf|j j |jf|j dS)Nr )rQshaperr isinstancerrAssertionErrorrZ materializerrrr,)r-r2rrr#initialize_parameterss z#_LazyNormBase.initialize_parameters)rOrPTTNN) r<r=r>rrrr&r,rUrDrr)r/r#rNs rNc@seZdZdZddZdS) BatchNorm1da Applies Batch Normalization over a 2D or 3D input (a mini-batch of 1D inputs with optional additional channel dimension) as described in the paper `Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift `__ . .. math:: y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta The mean and standard-deviation are calculated per-dimension over the mini-batches and :math:`\gamma` and :math:`\beta` are learnable parameter vectors of size `C` (where `C` is the input size). By default, the elements of :math:`\gamma` are set to 1 and the elements of :math:`\beta` are set to 0. The standard-deviation is calculated via the biased estimator, equivalent to `torch.var(input, unbiased=False)`. Also by default, during training this layer keeps running estimates of its computed mean and variance, which are then used for normalization during evaluation. The running estimates are kept with a default :attr:`momentum` of 0.1. If :attr:`track_running_stats` is set to ``False``, this layer then does not keep running estimates, and batch statistics are instead used during evaluation time as well. .. note:: This :attr:`momentum` argument is different from one used in optimizer classes and the conventional notion of momentum. Mathematically, the update rule for running statistics here is :math:`\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t`, where :math:`\hat{x}` is the estimated statistic and :math:`x_t` is the new observed value. Because the Batch Normalization is done over the `C` dimension, computing statistics on `(N, L)` slices, it's common terminology to call this Temporal Batch Normalization. Args: num_features: :math:`C` from an expected input of size :math:`(N, C, L)` or :math:`L` from input of size :math:`(N, L)` eps: a value added to the denominator for numerical stability. Default: 1e-5 momentum: the value used for the running_mean and running_var computation. Can be set to ``None`` for cumulative moving average (i.e. simple average). Default: 0.1 affine: a boolean value that when set to ``True``, this module has learnable affine parameters. Default: ``True`` track_running_stats: a boolean value that when set to ``True``, this module tracks the running mean and variance, and when set to ``False``, this module does not track such statistics, and initializes statistics buffers :attr:`running_mean` and :attr:`running_var` as ``None``. When these buffers are ``None``, this module always uses batch statistics. in both training and eval modes. Default: ``True`` Shape: - Input: :math:`(N, C)` or :math:`(N, C, L)` - Output: :math:`(N, C)` or :math:`(N, C, L)` (same shape as input) Examples:: >>> # With Learnable Parameters >>> m = nn.BatchNorm1d(100) >>> # Without Learnable Parameters >>> m = nn.BatchNorm1d(100, affine=False) >>> input = torch.randn(20, 100) >>> output = m(input) cCs.|jdkr*|jdkr*tdj|jdS)Nrz'expected 2D or 3D input (got {}D input))dim ValueErrorr4)r-r2rrr#r3)szBatchNorm1d._check_input_dimN)r<r=r>r?r3rrrr#rVsArVc@seZdZdZeZddZdS)LazyBatchNorm1da6A :class:`torch.nn.BatchNorm1d` module with lazy initialization of the ``num_features`` argument of the :class:`BatchNorm1d` that is inferred from the ``input.size(1)``. The attributes that will be lazily initialized are `weight`, `bias`, `running_mean` and `running_var`. Check the :class:`torch.nn.modules.lazy.LazyModuleMixin` for further documentation on lazy modules and their limitations. Args: eps: a value added to the denominator for numerical stability. Default: 1e-5 momentum: the value used for the running_mean and running_var computation. Can be set to ``None`` for cumulative moving average (i.e. simple average). Default: 0.1 affine: a boolean value that when set to ``True``, this module has learnable affine parameters. Default: ``True`` track_running_stats: a boolean value that when set to ``True``, this module tracks the running mean and variance, and when set to ``False``, this module does not track such statistics, and initializes statistics buffers :attr:`running_mean` and :attr:`running_var` as ``None``. When these buffers are ``None``, this module always uses batch statistics. in both training and eval modes. Default: ``True`` cCs.|jdkr*|jdkr*tdj|jdS)NrrWz'expected 2D or 3D input (got {}D input))rXrYr4)r-r2rrr#r3Lsz LazyBatchNorm1d._check_input_dimN)r<r=r>r?rV cls_to_becomer3rrrr#rZ0srZc@seZdZdZddZdS) BatchNorm2da Applies Batch Normalization over a 4D input (a mini-batch of 2D inputs with additional channel dimension) as described in the paper `Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift `__ . .. math:: y = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta The mean and standard-deviation are calculated per-dimension over the mini-batches and :math:`\gamma` and :math:`\beta` are learnable parameter vectors of size `C` (where `C` is the input size). By default, the elements of :math:`\gamma` are set to 1 and the elements of :math:`\beta` are set to 0. The standard-deviation is calculated via the biased estimator, equivalent to `torch.var(input, unbiased=False)`. Also by default, during training this layer keeps running estimates of its computed mean and variance, which are then used for normalization during evaluation. The running estimates are kept with a default :attr:`momentum` of 0.1. If :attr:`track_running_stats` is set to ``False``, this layer then does not keep running estimates, and batch statistics are instead used during evaluation time as well. .. note:: This :attr:`momentum` argument is different from one used in optimizer classes and the conventional notion of momentum. Mathematically, the update rule for running statistics here is :math:`\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t`, where :math:`\hat{x}` is the estimated statistic and :math:`x_t` is the new observed value. Because the Batch Normalization is done over the `C` dimension, computing statistics on `(N, H, W)` slices, it's common terminology to call this Spatial Batch Normalization. Args: num_features: :math:`C` from an expected input of size :math:`(N, C, H, W)` eps: a value added to the denominator for numerical stability. Default: 1e-5 momentum: the value used for the running_mean and running_var computation. Can be set to ``None`` for cumulative moving average (i.e. simple average). Default: 0.1 affine: a boolean value that when set to ``True``, this module has learnable affine parameters. Default: ``True`` track_running_stats: a boolean value that when set to ``True``, this module tracks the running mean and variance, and when set to ``False``, this module does not track such statistics, and initializes statistics buffers :attr:`running_mean` and :attr:`running_var` as ``None``. When these buffers are ``None``, this module always uses batch statistics. in both training and eval modes. Default: ``True`` Shape: - Input: :math:`(N, C, H, W)` - Output: :math:`(N, C, H, W)` (same shape as input) Examples:: >>> # With Learnable Parameters >>> m = nn.BatchNorm2d(100) >>> # Without Learnable Parameters >>> m = nn.BatchNorm2d(100, affine=False) >>> input = torch.randn(20, 100, 35, 45) >>> output = m(input) cCs"|jdkrtdj|jdS)Nz!expected 4D input (got {}D input))rXrYr4)r-r2rrr#r3s zBatchNorm2d._check_input_dimN)r<r=r>r?r3rrrr#r\SsAr\c@seZdZdZeZddZdS)LazyBatchNorm2da6A :class:`torch.nn.BatchNorm2d` module with lazy initialization of the ``num_features`` argument of the :class:`BatchNorm2d` that is inferred from the ``input.size(1)``. The attributes that will be lazily initialized are `weight`, `bias`, `running_mean` and `running_var`. Check the :class:`torch.nn.modules.lazy.LazyModuleMixin` for further documentation on lazy modules and their limitations. Args: eps: a value added to the denominator for numerical stability. Default: 1e-5 momentum: the value used for the running_mean and running_var computation. Can be set to ``None`` for cumulative moving average (i.e. simple average). Default: 0.1 affine: a boolean value that when set to ``True``, this module has learnable affine parameters. Default: ``True`` track_running_stats: a boolean value that when set to ``True``, this module tracks the running mean and variance, and when set to ``False``, this module does not track such statistics, and initializes statistics buffers :attr:`running_mean` and :attr:`running_var` as ``None``. When these buffers are ``None``, this module always uses batch statistics. in both training and eval modes. Default: ``True`` cCs"|jdkrtdj|jdS)Nr]z!expected 4D input (got {}D input))rXrYr4)r-r2rrr#r3s z LazyBatchNorm2d._check_input_dimN)r<r=r>r?r\r[r3rrrr#r^sr^c@seZdZdZddZdS) BatchNorm3da Applies Batch Normalization over a 5D input (a mini-batch of 3D inputs with additional channel dimension) as described in the paper `Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift `__ . .. math:: y = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta The mean and standard-deviation are calculated per-dimension over the mini-batches and :math:`\gamma` and :math:`\beta` are learnable parameter vectors of size `C` (where `C` is the input size). By default, the elements of :math:`\gamma` are set to 1 and the elements of :math:`\beta` are set to 0. The standard-deviation is calculated via the biased estimator, equivalent to `torch.var(input, unbiased=False)`. Also by default, during training this layer keeps running estimates of its computed mean and variance, which are then used for normalization during evaluation. The running estimates are kept with a default :attr:`momentum` of 0.1. If :attr:`track_running_stats` is set to ``False``, this layer then does not keep running estimates, and batch statistics are instead used during evaluation time as well. .. note:: This :attr:`momentum` argument is different from one used in optimizer classes and the conventional notion of momentum. Mathematically, the update rule for running statistics here is :math:`\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t`, where :math:`\hat{x}` is the estimated statistic and :math:`x_t` is the new observed value. Because the Batch Normalization is done over the `C` dimension, computing statistics on `(N, D, H, W)` slices, it's common terminology to call this Volumetric Batch Normalization or Spatio-temporal Batch Normalization. Args: num_features: :math:`C` from an expected input of size :math:`(N, C, D, H, W)` eps: a value added to the denominator for numerical stability. Default: 1e-5 momentum: the value used for the running_mean and running_var computation. Can be set to ``None`` for cumulative moving average (i.e. simple average). Default: 0.1 affine: a boolean value that when set to ``True``, this module has learnable affine parameters. Default: ``True`` track_running_stats: a boolean value that when set to ``True``, this module tracks the running mean and variance, and when set to ``False``, this module does not track such statistics, and initializes statistics buffers :attr:`running_mean` and :attr:`running_var` as ``None``. When these buffers are ``None``, this module always uses batch statistics. in both training and eval modes. Default: ``True`` Shape: - Input: :math:`(N, C, D, H, W)` - Output: :math:`(N, C, D, H, W)` (same shape as input) Examples:: >>> # With Learnable Parameters >>> m = nn.BatchNorm3d(100) >>> # Without Learnable Parameters >>> m = nn.BatchNorm3d(100, affine=False) >>> input = torch.randn(20, 100, 35, 45, 10) >>> output = m(input) cCs"|jdkrtdj|jdS)Nz!expected 5D input (got {}D input))rXrYr4)r-r2rrr#r3s zBatchNorm3d._check_input_dimN)r<r=r>r?r3rrrr#r_sBr_c@seZdZdZeZddZdS)LazyBatchNorm3da6A :class:`torch.nn.BatchNorm3d` module with lazy initialization of the ``num_features`` argument of the :class:`BatchNorm3d` that is inferred from the ``input.size(1)``. The attributes that will be lazily initialized are `weight`, `bias`, `running_mean` and `running_var`. Check the :class:`torch.nn.modules.lazy.LazyModuleMixin` for further documentation on lazy modules and their limitations. Args: eps: a value added to the denominator for numerical stability. Default: 1e-5 momentum: the value used for the running_mean and running_var computation. Can be set to ``None`` for cumulative moving average (i.e. simple average). Default: 0.1 affine: a boolean value that when set to ``True``, this module has learnable affine parameters. Default: ``True`` track_running_stats: a boolean value that when set to ``True``, this module tracks the running mean and variance, and when set to ``False``, this module does not track such statistics, and initializes statistics buffers :attr:`running_mean` and :attr:`running_var` as ``None``. When these buffers are ``None``, this module always uses batch statistics. in both training and eval modes. Default: ``True`` cCs"|jdkrtdj|jdS)Nr`z!expected 5D input (got {}D input))rXrYr4)r-r2rrr#r3!s z LazyBatchNorm3d._check_input_dimN)r<r=r>r?r_r[r3rrrr#rasrac sfeZdZdZdeeeeeeeddfdd Z d d Z d d Z e e d ddZ edddZZS)r aApplies Batch Normalization over a N-Dimensional input (a mini-batch of [N-2]D inputs with additional channel dimension) as described in the paper `Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift `__ . .. math:: y = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta The mean and standard-deviation are calculated per-dimension over all mini-batches of the same process groups. :math:`\gamma` and :math:`\beta` are learnable parameter vectors of size `C` (where `C` is the input size). By default, the elements of :math:`\gamma` are sampled from :math:`\mathcal{U}(0, 1)` and the elements of :math:`\beta` are set to 0. The standard-deviation is calculated via the biased estimator, equivalent to `torch.var(input, unbiased=False)`. Also by default, during training this layer keeps running estimates of its computed mean and variance, which are then used for normalization during evaluation. The running estimates are kept with a default :attr:`momentum` of 0.1. If :attr:`track_running_stats` is set to ``False``, this layer then does not keep running estimates, and batch statistics are instead used during evaluation time as well. .. note:: This :attr:`momentum` argument is different from one used in optimizer classes and the conventional notion of momentum. Mathematically, the update rule for running statistics here is :math:`\hat{x}_\text{new} = (1 - \text{momentum}) \times \hat{x} + \text{momentum} \times x_t`, where :math:`\hat{x}` is the estimated statistic and :math:`x_t` is the new observed value. Because the Batch Normalization is done for each channel in the ``C`` dimension, computing statistics on ``(N, +)`` slices, it's common terminology to call this Volumetric Batch Normalization or Spatio-temporal Batch Normalization. Currently :class:`SyncBatchNorm` only supports :class:`~torch.nn.DistributedDataParallel` (DDP) with single GPU per process. Use :meth:`torch.nn.SyncBatchNorm.convert_sync_batchnorm()` to convert :attr:`BatchNorm*D` layer to :class:`SyncBatchNorm` before wrapping Network with DDP. Args: num_features: :math:`C` from an expected input of size :math:`(N, C, +)` eps: a value added to the denominator for numerical stability. Default: ``1e-5`` momentum: the value used for the running_mean and running_var computation. Can be set to ``None`` for cumulative moving average (i.e. simple average). Default: 0.1 affine: a boolean value that when set to ``True``, this module has learnable affine parameters. Default: ``True`` track_running_stats: a boolean value that when set to ``True``, this module tracks the running mean and variance, and when set to ``False``, this module does not track such statistics, and initializes statistics buffers :attr:`running_mean` and :attr:`running_var` as ``None``. When these buffers are ``None``, this module always uses batch statistics. in both training and eval modes. Default: ``True`` process_group: synchronization of stats happen within each process group individually. Default behavior is synchronization across the whole world Shape: - Input: :math:`(N, C, +)` - Output: :math:`(N, C, +)` (same shape as input) .. note:: Synchronization of batchnorm statistics occurs only while training, i.e. synchronization is disabled when ``model.eval()`` is set or if ``self.training`` is otherwise ``False``. Examples:: >>> # With Learnable Parameters >>> m = nn.SyncBatchNorm(100) >>> # creating process group (optional) >>> # ranks is a list of int identifying rank ids. >>> ranks = list(range(8)) >>> r1, r2 = ranks[:4], ranks[4:] >>> # Note: every rank calls into new_group for every >>> # process group created, even if that rank is not >>> # part of the group. >>> process_groups = [torch.distributed.new_group(pids) for pids in [r1, r2]] >>> process_group = process_groups[0 if dist.get_rank() <= 3 else 1] >>> # Without Learnable Parameters >>> m = nn.BatchNorm3d(100, affine=False, process_group=process_group) >>> input = torch.randn(20, 100, 35, 45, 10) >>> output = m(input) >>> # network is nn.BatchNorm layer >>> sync_bn_network = nn.SyncBatchNorm.convert_sync_batchnorm(network, process_group) >>> # only single gpu per process is currently supported >>> ddp_sync_bn_network = torch.nn.parallel.DistributedDataParallel( >>> sync_bn_network, >>> device_ids=[args.local_rank], >>> output_device=args.local_rank) h㈵>皙?TN)rrrrr process_grouprc s0||d} tt|j|||||f| ||_dS)N)rr)r%r r&rd) r-rrrrrrdrrr.)r/rr#r&s  zSyncBatchNorm.__init__cCs"|jdkrtdj|jdS)Nrz*expected at least 2D input (got {}D input))rXrYr4)r-r2rrr#r3s zSyncBatchNorm._check_input_dimcCs|jddkrtddS)Nr rz9SyncBatchNorm number of input channels should be non-zero)sizerY)r-r2rrr#_check_non_zero_input_channelssz,SyncBatchNorm._check_non_zero_input_channels)r2rc CsZ|jstd|j||j||jdkr2d}n|j}|jr~|jr~|jdk sRt|jd|_|jdkrxd|jj }n|j}|jrd}n|j dko|j dk}|j s|jr|j nd}|j s|jr|j nd}|o|j}|rt j jj}|jr|j}t j j|}|dk}|s,tj||||j|j|||jS|s6ttj||j|j|||j||| SdS)Nz0SyncBatchNorm expected input tensor to be on GPUgr g?T)Zis_cudarYr3rfrrHrrrTitemrrr'Z distributedgroupZWORLDrdZget_world_sizerIrJrrrsync_batch_normapply) r-r2rKrLrrZ need_syncrdZ world_sizerrr#rMs\           zSyncBatchNorm.forwardc Cs|}t|tjjjjrtjj|j|j|j |j |j |}|j r`tj |j |_ |j|_WdQRX|j|_|j|_|j|_t|dr|j|_x(|jD]\}}|j||j||qW~|S)a Helper function to convert all :attr:`BatchNorm*D` layers in the model to :class:`torch.nn.SyncBatchNorm` layers. Args: module (nn.Module): module containing one or more :attr:`BatchNorm*D` layers process_group (optional): process group to scope synchronization, default is the whole world Returns: The original :attr:`module` with the converted :class:`torch.nn.SyncBatchNorm` layers. If the original :attr:`module` is a :attr:`BatchNorm*D` layer, a new :class:`torch.nn.SyncBatchNorm` layer object will be returned instead. Example:: >>> # Network with nn.BatchNorm layer >>> module = torch.nn.Sequential( >>> torch.nn.Linear(20, 100), >>> torch.nn.BatchNorm1d(100), >>> ).cuda() >>> # creating process group (optional) >>> # ranks is a list of int identifying rank ids. >>> ranks = list(range(8)) >>> r1, r2 = ranks[:4], ranks[4:] >>> # Note: every rank calls into new_group for every >>> # process group created, even if that rank is not >>> # part of the group. >>> process_groups = [torch.distributed.new_group(pids) for pids in [r1, r2]] >>> process_group = process_groups[0 if dist.get_rank() <= 3 else 1] >>> sync_bn_module = torch.nn.SyncBatchNorm.convert_sync_batchnorm(module, process_group) Nqconfig)rSr'nnmodulesZ batchnormrEr rrrrrZno_gradrrrrrhasattrrkZnamed_childrenZ add_moduleconvert_sync_batchnorm)clsmodulerdZ module_outputnamechildrrr#ros.#  z$SyncBatchNorm.convert_sync_batchnorm)rbrcTTNNN)N)r<r=r>r?rArBrCrrr&r3rfrrM classmethodrorDrr)r/r#r &scQr )typingrrr'rZtorch.nn.parameterrrrr rIr Z _functionsr riZlazyr rqrrrErNrVrZr\r^r_rarrrr#s$      hA/J#H!I!