当前位置: 首页>>代码示例>>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;未经允许,请勿转载。