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


Python memonger.share_grad_blobs方法代碼示例

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


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

示例1: add_parameter_update_ops

# 需要導入模塊: from caffe2.python import memonger [as 別名]
# 或者: from caffe2.python.memonger import share_grad_blobs [as 別名]
def add_parameter_update_ops(model):
    raise NotImplementedError #remove this from the function stub
    


# ## Part 7: Gradient Optimization
# 
# If you run the network as is you may have issues with memory. Without memory optimization we could reduce the batch size, but we shouldn't have to do that. Caffe2 has a `memonger` function for this purpose which will find ways to reuse gradients that we created. Below is a reference implementation.
# 
# ```python
# def optimize_gradient_memory(model, loss):
#     model.net._net = memonger.share_grad_blobs(
#         model.net,
#         loss,
#         set(model.param_to_grad.values()),
#         # Due to memonger internals, we need a namescope here. Let's make one up; we'll need it later!
#         namescope="imonaboat",
#         share_activations=False)
# ```
# 
# ### Task: Implement memonger
# We're going to use the reference for help here, otherwise it is a little difficult to cover for the scope of this tutorial. The function is ready to go for you, but you should still soak up what's been done in this function. One of the key gotchas here is making sure you give it a namescope so that you can access the gradients you'll be creating in the next step. This name can be anything.
# 

# In[ ]:


# LAB WORK AREA FOR PART 7 
開發者ID:facebookarchive,項目名稱:tutorials,代碼行數:30,代碼來源:Multi-GPU_Training.py

示例2: optimize_gradient_memory

# 需要導入模塊: from caffe2.python import memonger [as 別名]
# 或者: from caffe2.python.memonger import share_grad_blobs [as 別名]
def optimize_gradient_memory(model, loss):
    model.net._net = memonger.share_grad_blobs(
        model.net,
        loss,
        set(model.param_to_grad.values()),
        namescope="imonaboat",
        share_activations=False,
        )
    


# In[ ]:


# SOLUTION for Part 8 
開發者ID:facebookarchive,項目名稱:tutorials,代碼行數:17,代碼來源:Multi-GPU_Training.py

示例3: optimize_memory

# 需要導入模塊: from caffe2.python import memonger [as 別名]
# 或者: from caffe2.python.memonger import share_grad_blobs [as 別名]
def optimize_memory(model):
    """Save GPU memory through blob sharing."""
    for device in range(cfg.NUM_GPUS):
        namescope = 'gpu_{}/'.format(device)
        losses = [namescope + l for l in model.losses]
        model.net._net = memonger.share_grad_blobs(
            model.net,
            losses,
            set(model.param_to_grad.values()),
            namescope,
            share_activations=cfg.MEMONGER_SHARE_ACTIVATIONS
        ) 
開發者ID:yihui-he,項目名稱:KL-Loss,代碼行數:14,代碼來源:train.py

示例4: optimize_gradient_memory

# 需要導入模塊: from caffe2.python import memonger [as 別名]
# 或者: from caffe2.python.memonger import share_grad_blobs [as 別名]
def optimize_gradient_memory(model, loss):
        """A naive implementation of memory optimization

        :param model_helper.ModelHelper model: Model to add update parameters operators for.
        :param list loss: A list of losses.
        """

        model.net._net = memonger.share_grad_blobs(
            model.net,
            loss,
            set(model.param_to_grad.values()),
            namescope='',
            share_activations=False,
        ) 
開發者ID:HewlettPackard,項目名稱:dlcookbook-dlbs,代碼行數:16,代碼來源:model.py

示例5: optimize_memory

# 需要導入模塊: from caffe2.python import memonger [as 別名]
# 或者: from caffe2.python.memonger import share_grad_blobs [as 別名]
def optimize_memory(model):
    from caffe2.python import memonger
    for device in range(cfg.NUM_GPUS):
        namescope = 'gpu_{}/'.format(device)
        losses = [namescope + l for l in model.losses]
        model.net._net = memonger.share_grad_blobs(
            model.net,
            losses,
            set(model.param_to_grad.values()),
            namescope,
            share_activations=cfg.MEMONGER_SHARE_ACTIVATIONS) 
開發者ID:facebookresearch,項目名稱:DetectAndTrack,代碼行數:13,代碼來源:train_net.py


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