本文整理汇总了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
示例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
示例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
)
示例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,
)
示例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)