當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。