提交 08e5dab2 authored 作者: Frederic Bastien's avatar Frederic Bastien

add profile of theano.grad

上级 43875391
......@@ -654,6 +654,9 @@ class ProfileStats(object):
# The validation time is a subset of optimizer_time
assert self.validate_time < self.optimizer_time
def summary_globals(self, file):
print >> file, 'Time in all call to theano.grad() %es' % theano.gradient.grad_time
def summary_memory(self, file, N=None):
fct_memory = {} # fgraph->dict(node->[outputs size])
fct_shapes = {} # fgraph->dict(node->[outputs shapes]))
......@@ -1209,6 +1212,7 @@ class ProfileStats(object):
def summary(self, file=sys.stderr, n_ops_to_print=20,
n_apply_to_print=20):
self.summary_function(file)
self.summary_globals(file)
local_time = sum(self.apply_time.values())
if local_time > 0:
self.summary_class(file, n_ops_to_print)
......
......@@ -10,6 +10,7 @@ __docformat__ = "restructuredtext en"
import __builtin__
from itertools import izip
import logging
import time
import warnings
_logger = logging.getLogger('theano.gradient')
......@@ -36,6 +37,8 @@ tensor = None
_msg_retType = 'op.grad(...) returned a non-list'
grad_time = 0
def format_as(use_list, use_tuple, outputs):
"""
......@@ -412,6 +415,7 @@ def grad(cost, wrt, consider_constant=None,
or Variable in all cases.
"""
t0 = time.time()
global tensor
if tensor is None:
from theano import tensor
......@@ -556,8 +560,12 @@ def grad(cost, wrt, consider_constant=None,
rval = tuple(rval)
elif not using_list:
rval, = rval
t1 = time.time()
global grad_time
grad_time = t1 - t0
return rval
def subgraph_grad(wrt, end, start=None, cost=None, details=False):
'''
With respect to `wrt`, computes gradients of cost and/or from
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论