當前位置: 首頁>>代碼示例>>Python>>正文


Python comm.reduce_add_coalesced方法代碼示例

本文整理匯總了Python中torch.cuda.comm.reduce_add_coalesced方法的典型用法代碼示例。如果您正苦於以下問題:Python comm.reduce_add_coalesced方法的具體用法?Python comm.reduce_add_coalesced怎麽用?Python comm.reduce_add_coalesced使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.cuda.comm的用法示例。


在下文中一共展示了comm.reduce_add_coalesced方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: forward

# 需要導入模塊: from torch.cuda import comm [as 別名]
# 或者: from torch.cuda.comm import reduce_add_coalesced [as 別名]
def forward(ctx, num_inputs, *inputs):
        ctx.num_inputs = num_inputs
        ctx.target_gpus = [inputs[i].get_device() for i in range(0, len(inputs), num_inputs)]
        inputs = [inputs[i:i + num_inputs]
                 for i in range(0, len(inputs), num_inputs)]
        # sort before reduce sum
        inputs = sorted(inputs, key=lambda i: i[0].get_device())
        results = comm.reduce_add_coalesced(inputs, ctx.target_gpus[0])
        outputs = comm.broadcast_coalesced(results, ctx.target_gpus)
        return tuple([t for tensors in outputs for t in tensors]) 
開發者ID:speedinghzl,項目名稱:pytorch-segmentation-toolbox,代碼行數:12,代碼來源:encoding.py

示例2: backward

# 需要導入模塊: from torch.cuda import comm [as 別名]
# 或者: from torch.cuda.comm import reduce_add_coalesced [as 別名]
def backward(ctx, *inputs):
        inputs = [i.data for i in inputs]
        inputs = [inputs[i:i + ctx.num_inputs]
                 for i in range(0, len(inputs), ctx.num_inputs)]
        results = comm.reduce_add_coalesced(inputs, ctx.target_gpus[0])
        outputs = comm.broadcast_coalesced(results, ctx.target_gpus)
        return (None,) + tuple([Variable(t) for tensors in outputs for t in tensors]) 
開發者ID:speedinghzl,項目名稱:pytorch-segmentation-toolbox,代碼行數:9,代碼來源:encoding.py

示例3: forward

# 需要導入模塊: from torch.cuda import comm [as 別名]
# 或者: from torch.cuda.comm import reduce_add_coalesced [as 別名]
def forward(ctx, num_inputs, *inputs):
        ctx.num_inputs = num_inputs
        ctx.target_gpus = [inputs[i].get_device() for i in range(0, len(inputs), num_inputs)]
        inputs = [inputs[i:i + num_inputs]
                  for i in range(0, len(inputs), num_inputs)]
        # sort before reduce sum
        inputs = sorted(inputs, key=lambda i: i[0].get_device())
        results = comm.reduce_add_coalesced(inputs, ctx.target_gpus[0])
        outputs = comm.broadcast_coalesced(results, ctx.target_gpus)
        return tuple([t for tensors in outputs for t in tensors]) 
開發者ID:jason9693,項目名稱:MusicTransformer-pytorch,代碼行數:12,代碼來源:parallel.py

示例4: backward

# 需要導入模塊: from torch.cuda import comm [as 別名]
# 或者: from torch.cuda.comm import reduce_add_coalesced [as 別名]
def backward(ctx, *inputs):
        inputs = [i.data for i in inputs]
        inputs = [inputs[i:i + ctx.num_inputs]
                  for i in range(0, len(inputs), ctx.num_inputs)]
        results = comm.reduce_add_coalesced(inputs, ctx.target_gpus[0])
        outputs = comm.broadcast_coalesced(results, ctx.target_gpus)
        return (None,) + tuple([Variable(t) for tensors in outputs for t in tensors]) 
開發者ID:jason9693,項目名稱:MusicTransformer-pytorch,代碼行數:9,代碼來源:parallel.py

示例5: forward

# 需要導入模塊: from torch.cuda import comm [as 別名]
# 或者: from torch.cuda.comm import reduce_add_coalesced [as 別名]
def forward(ctx, destination, num_inputs, *grads):
        ctx.target_gpus = [grads[i].get_device() for i in range(0, len(grads), num_inputs)]

        grads = [grads[i:i + num_inputs]
                 for i in range(0, len(grads), num_inputs)]
        return comm.reduce_add_coalesced(grads, destination) 
開發者ID:roytseng-tw,項目名稱:Detectron.pytorch,代碼行數:8,代碼來源:_functions.py


注:本文中的torch.cuda.comm.reduce_add_coalesced方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。