提交 b5772416 authored 作者: sentient07's avatar sentient07

Added print_profile2

上级 c396d611
...@@ -5,6 +5,7 @@ import logging ...@@ -5,6 +5,7 @@ import logging
import pdb import pdb
import time import time
from six.moves import xrange from six.moves import xrange
from collections import deque
import theano import theano
from theano.compat import OrderedDict from theano.compat import OrderedDict
...@@ -13,7 +14,7 @@ from theano.compile import optdb ...@@ -13,7 +14,7 @@ from theano.compile import optdb
from theano.compile.ops import shape_i from theano.compile.ops import shape_i
from theano.gof import (local_optimizer, EquilibriumDB, TopoOptimizer, from theano.gof import (local_optimizer, EquilibriumDB, TopoOptimizer,
SequenceDB, Optimizer, DB, toolbox, graph) SequenceDB, Optimizer, DB, toolbox, graph)
from gof.opt import ChangeTracker from theano.gof.opt import ChangeTracker, NavigatorOptimizer
from theano.gof.optdb import LocalGroupDB from theano.gof.optdb import LocalGroupDB
from theano.ifelse import IfElse from theano.ifelse import IfElse
...@@ -254,7 +255,7 @@ gpu_seqopt.register('InputToGpuArrayOptimizer', InputToGpuOptimizer(), ...@@ -254,7 +255,7 @@ gpu_seqopt.register('InputToGpuArrayOptimizer', InputToGpuOptimizer(),
0, 'fast_run', 'fast_compile', 'merge') 0, 'fast_run', 'fast_compile', 'merge')
class GraphToGPU(Optimizer, NavigatorOptimizer): class GraphToGPU(NavigatorOptimizer):
""" """
Transfer the graph as a whole to GPU instead of transfering node by node. Transfer the graph as a whole to GPU instead of transfering node by node.
""" """
...@@ -262,6 +263,7 @@ class GraphToGPU(Optimizer, NavigatorOptimizer): ...@@ -262,6 +263,7 @@ class GraphToGPU(Optimizer, NavigatorOptimizer):
def __init__(self, local_optimizers_all, local_optimizers_map): def __init__(self, local_optimizers_all, local_optimizers_map):
self.local_optimizers_all = local_optimizers_all self.local_optimizers_all = local_optimizers_all
self.local_optimizers_map = local_optimizers_map self.local_optimizers_map = local_optimizers_map
self.failure_callback = None
def add_requirements(self, fgraph): def add_requirements(self, fgraph):
fgraph.attach_feature(toolbox.ReplaceValidate()) fgraph.attach_feature(toolbox.ReplaceValidate())
...@@ -277,6 +279,7 @@ class GraphToGPU(Optimizer, NavigatorOptimizer): ...@@ -277,6 +279,7 @@ class GraphToGPU(Optimizer, NavigatorOptimizer):
local_opt_timing = [] local_opt_timing = []
io_toposort_timing = [] io_toposort_timing = []
nb_nodes = [] nb_nodes = []
time_opts = {}
node_created = {} node_created = {}
process_count = {} process_count = {}
# Building a new graph # Building a new graph
...@@ -289,17 +292,17 @@ class GraphToGPU(Optimizer, NavigatorOptimizer): ...@@ -289,17 +292,17 @@ class GraphToGPU(Optimizer, NavigatorOptimizer):
for i in fgraph.variables: for i in fgraph.variables:
if isinstance(i, theano.Constant): if isinstance(i, theano.Constant):
mapping[i] = i mapping[i] = i
for node in fgraph.toposort():
for lopt in (self.local_optimizers_all + for lopt in (self.local_optimizers_all +
self.local_optimizers_map.get(type(node.op), []) + self.local_optimizers_map.get(type(node.op), []) +
self.local_optimizers_map.get(node.op, [])): self.local_optimizers_map.get(node.op, [])):
process_count.setdefault(copt, 0) process_count.setdefault(lopt, 0)
global_process_count.setdefault(opt, 0) global_process_count.setdefault(lopt, 0)
time_opts.setdefault(opt, 0) time_opts.setdefault(lopt, 0)
node_created.setdefault(opt, 0) node_created.setdefault(lopt, 0)
topo_t0 = time.time() topo_t0 = time.time()
q = deque(graph.io_toposort(fgraph.inputs, start_from)) q = deque(graph.io_toposort(fgraph.inputs, fgraph.outputs))
io_toposort_timing.append(time.time() - topo_t0) io_toposort_timing.append(time.time() - topo_t0)
nb_nodes.append(len(q)) nb_nodes.append(len(q))
max_nb_nodes = max(max_nb_nodes, len(q)) max_nb_nodes = max(max_nb_nodes, len(q))
...@@ -342,9 +345,6 @@ class GraphToGPU(Optimizer, NavigatorOptimizer): ...@@ -342,9 +345,6 @@ class GraphToGPU(Optimizer, NavigatorOptimizer):
nb = change_tracker.nb_imported nb = change_tracker.nb_imported
process_count[lopt] += 1 process_count[lopt] += 1
global_process_count[lopt] += 1 global_process_count[lopt] += 1
t_opt = time.time()
lopt_change = self.process_node(fgraph, node, lopt)
time_opts[lopt] += time.time() - t_opt
node_created[lopt] += change_tracker.nb_imported - nb node_created[lopt] += change_tracker.nb_imported - nb
if move_to_GPU: if move_to_GPU:
try: try:
...@@ -435,7 +435,7 @@ class GraphToGPU(Optimizer, NavigatorOptimizer): ...@@ -435,7 +435,7 @@ class GraphToGPU(Optimizer, NavigatorOptimizer):
process_count = {} process_count = {}
for o in (opt.local_optimizers_all + for o in (opt.local_optimizers_all +
list(opt.local_optimizers_map.get(type(node.op), [])) + list(opt.local_optimizers_map.get(type(node.op), [])) +
list(opt.local_optimizers_map.get(node.op, [])) +): list(opt.local_optimizers_map.get(node.op, []))):
process_count.setdefault(o, 0) process_count.setdefault(o, 0)
for count in loop_process_count: for count in loop_process_count:
for o, v in iteritems(count): for o, v in iteritems(count):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论