当前位置: 首页>>代码示例>>Python>>正文


Python ReduceAddCoalesced.apply方法代码示例

本文整理汇总了Python中torch.nn.parallel._functions.ReduceAddCoalesced.apply方法的典型用法代码示例。如果您正苦于以下问题:Python ReduceAddCoalesced.apply方法的具体用法?Python ReduceAddCoalesced.apply怎么用?Python ReduceAddCoalesced.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torch.nn.parallel._functions.ReduceAddCoalesced的用法示例。


在下文中一共展示了ReduceAddCoalesced.apply方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: forward

# 需要导入模块: from torch.nn.parallel._functions import ReduceAddCoalesced [as 别名]
# 或者: from torch.nn.parallel._functions.ReduceAddCoalesced import apply [as 别名]
def forward(self, inputs, *targets, **kwargs):
        # input should be already scatterd
        # scattering the targets instead

        if not self.device_ids:
            return self.module(inputs, *targets, **kwargs)

        targets, kwargs = self.scatter(targets, kwargs, self.device_ids)
        if len(self.device_ids) == 1:
            return self.module(inputs, *targets, **kwargs)
        replicas = self.replicate(self.module, self.device_ids[:len(inputs)])
        outputs = self.criterion_apply(replicas, inputs, targets, kwargs)
        return ReduceAddCoalesced.apply(
            self.device_ids[0],
            len(outputs),
            *outputs) / len(outputs) 
开发者ID:PistonY,项目名称:torch-toolbox,代码行数:18,代码来源:EncodingDataParallel.py

示例2: _data_parallel_master

# 需要导入模块: from torch.nn.parallel._functions import ReduceAddCoalesced [as 别名]
# 或者: from torch.nn.parallel._functions.ReduceAddCoalesced import apply [as 别名]
def _data_parallel_master(self, intermediates):
        """Reduce the sum and square-sum, compute the statistics, and broadcast it."""

        # Always using same "device order" makes the ReduceAdd operation faster.
        # Thanks to:: Tete Xiao (http://tetexiao.com/)
        intermediates = sorted(intermediates, key=lambda i: i[1].sum.get_device())

        to_reduce = [i[1][:2] for i in intermediates]
        to_reduce = [j for i in to_reduce for j in i]  # flatten
        target_gpus = [i[1].sum.get_device() for i in intermediates]

        sum_size = sum([i[1].sum_size for i in intermediates])
        sum_, ssum = ReduceAddCoalesced.apply(target_gpus[0], 2, *to_reduce)
        mean, inv_std = self._compute_mean_std(sum_, ssum, sum_size)

        broadcasted = Broadcast.apply(target_gpus, mean, inv_std)

        outputs = []
        for i, rec in enumerate(intermediates):
            outputs.append((rec[0], _MasterMessage(*broadcasted[i * 2:i * 2 + 2])))

        return outputs 
开发者ID:clovaai,项目名称:overhaul-distillation,代码行数:24,代码来源:batchnorm.py

示例3: _data_parallel_master

# 需要导入模块: from torch.nn.parallel._functions import ReduceAddCoalesced [as 别名]
# 或者: from torch.nn.parallel._functions.ReduceAddCoalesced import apply [as 别名]
def _data_parallel_master(self, intermediates):
        """Reduce the sum and square-sum, compute the statistics, and broadcast it."""
        intermediates = sorted(intermediates, key=lambda i: i[1].sum.get_device())

        to_reduce = [i[1][:2] for i in intermediates]
        to_reduce = [j for i in to_reduce for j in i]  # flatten
        target_gpus = [i[1].sum.get_device() for i in intermediates]

        sum_size = sum([i[1].sum_size for i in intermediates])
        sum_, ssum = ReduceAddCoalesced.apply(target_gpus[0], 2, *to_reduce)

        mean, inv_std = self._compute_mean_std(sum_, ssum, sum_size)

        broadcasted = Broadcast.apply(target_gpus, mean, inv_std)

        outputs = []
        for i, rec in enumerate(intermediates):
            outputs.append((rec[0], _MasterMessage(*broadcasted[i*2:i*2+2])))

        return outputs 
开发者ID:XiaLiPKU,项目名称:EMANet,代码行数:22,代码来源:batchnorm.py

示例4: _data_parallel_master

# 需要导入模块: from torch.nn.parallel._functions import ReduceAddCoalesced [as 别名]
# 或者: from torch.nn.parallel._functions.ReduceAddCoalesced import apply [as 别名]
def _data_parallel_master(self, intermediates):
        """Reduce the sum and square-sum, compute the statistics, and broadcast it."""

        # Always using same "device order" makes the ReduceAdd operation faster.
        # Thanks to:: Tete Xiao (http://tetexiao.com/)
        intermediates = sorted(intermediates, key=lambda i: i[1].sum.get_device())

        to_reduce = [i[1][:2] for i in intermediates]
        to_reduce = [j for i in to_reduce for j in i]  # flatten
        target_gpus = [i[1].sum.get_device() for i in intermediates]

        sum_size = sum([i[1].sum_size for i in intermediates])
        sum_, ssum = ReduceAddCoalesced.apply(target_gpus[0], 2, *to_reduce)
        mean, inv_std = self._compute_mean_std(sum_, ssum, sum_size)

        broadcasted = Broadcast.apply(target_gpus, mean, inv_std)

        outputs = []
        for i, rec in enumerate(intermediates):
            outputs.append((rec[0], _MasterMessage(*broadcasted[i*2:i*2+2])))

        return outputs 
开发者ID:hualin95,项目名称:Deeplab-v3plus,代码行数:24,代码来源:batchnorm.py

示例5: batchnormtrain

# 需要导入模块: from torch.nn.parallel._functions import ReduceAddCoalesced [as 别名]
# 或者: from torch.nn.parallel._functions.ReduceAddCoalesced import apply [as 别名]
def batchnormtrain(input, mean, std, gamma, beta):
    r"""Applies Batch Normalization over a 3d input that is seen as a
    mini-batch.

    .. _encoding.batchnormtrain:

    .. math::

        y = \frac{x - \mu[x]}{ \sqrt{var[x] + \epsilon}} * \gamma + \beta

    Shape:
        - Input: :math:`(N, C)` or :math:`(N, C, L)`
        - Output: :math:`(N, C)` or :math:`(N, C, L)` (same shape as input)

    """
    return _batchnormtrain.apply(input, mean, std, gamma, beta) 
开发者ID:openseg-group,项目名称:openseg.pytorch,代码行数:18,代码来源:module.py

示例6: _data_parallel_master

# 需要导入模块: from torch.nn.parallel._functions import ReduceAddCoalesced [as 别名]
# 或者: from torch.nn.parallel._functions.ReduceAddCoalesced import apply [as 别名]
def _data_parallel_master(self, intermediates):
    """Reduce the sum and square-sum, compute the statistics, and broadcast it."""

    # Always using same "device order" makes the ReduceAdd operation faster.
    # Thanks to:: Tete Xiao (http://tetexiao.com/)
    intermediates = sorted(intermediates, key=lambda i: i[1].sum.get_device())

    to_reduce = [i[1][:2] for i in intermediates]
    to_reduce = [j for i in to_reduce for j in i]  # flatten
    target_gpus = [i[1].sum.get_device() for i in intermediates]

    sum_size = sum([i[1].sum_size for i in intermediates])
    sum_, ssum = ReduceAddCoalesced.apply(target_gpus[0], 2, *to_reduce)
    mean, inv_std = self._compute_mean_std(sum_, ssum, sum_size)

    broadcasted = Broadcast.apply(target_gpus, mean, inv_std)

    outputs = []
    for i, rec in enumerate(intermediates):
      outputs.append((rec[0], _MasterMessage(*broadcasted[i*2:i*2+2])))

    return outputs 
开发者ID:PRBonn,项目名称:lidar-bonnetal,代码行数:24,代码来源:batchnorm.py


注:本文中的torch.nn.parallel._functions.ReduceAddCoalesced.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。