Ad
How To Measure Time Per Layer In Chainer
How can I measure the time taken by each layer? This should include both forward and backward pass.
For instance, in the case of VGG, I wanna know the time each of the layers takes. Part of the code is shown below.
h = F.relu(self.conv1_2(h))
h = F.max_pooling_2d(h, 2, 2)
h = F.relu(self.conv2_1(h))
h = F.relu(self.conv2_2(h))
h = F.max_pooling_2d(h, 2, 2)
Ad
Answer
In case of the forward pass you may try to monkey-patch the execution of the model something like this:
import time
from functools import wraps
def check_time(link_name, func):
@wraps(func)
def wrapper(*args, **kwargs):
t = time.time()
res = func(*arsg, **kwargs)
t = time.time() - t
print("Execution of {0} of the link {1} took {2:.3f} sec".format(func.__name__, link_name, t)
return res
for name, link in model.namedlinks(skipself=True):
link.forward = check_time(name, link.forward)
Since chainer follows the "define-by-run" strategy, the computation graph is constructed while you running the code, so the backward()
method is only defined on chainer.Function
instances. You would need to monkey-patch the according methods after each run, which would make you code quite slow, I guess.
Anyway, I hope, my code gives you an idea of how to do what you want.
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad