提交 2617ac9d 编写于 作者: D dzhwinter

"add doc string"

上级 bddd4bc0
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
from __future__ import print_function from __future__ import print_function
import unittest import unittest
import paddle.fluid as fluid
import paddle.fluid.layers as layers import paddle.fluid.layers as layers
import paddle.fluid.optimizer as optimizer import paddle.fluid.optimizer as optimizer
from paddle.fluid.framework import Program, program_guard from paddle.fluid.framework import Program, program_guard
...@@ -66,13 +67,16 @@ class TestMemoryTranspiler2(unittest.TestCase): ...@@ -66,13 +67,16 @@ class TestMemoryTranspiler2(unittest.TestCase):
print("after optimization") print("after optimization")
print(str(result_program)) print(str(result_program))
class TestMemoryTranspiler3(unittest.TestCase): class TestMemoryTranspiler3(unittest.TestCase):
def setUp(self): def setUp(self):
program = Program() program = Program()
with program_guard(program, startup_program=Program()): with program_guard(program, startup_program=Program()):
word = fluid.layers.data(name='word', shape=[1], dtype='int64') word = fluid.layers.data(name='word', shape=[1], dtype='int64')
emb = [fluid.layers.embedding(word, size=[65536, 256], param_attr='emb') emb = [
for _ in range(6)] fluid.layers.embedding(
word, size=[65536, 256], param_attr='emb') for _ in range(6)
]
left = emb.pop(0) left = emb.pop(0)
while len(emb) != 0: while len(emb) != 0:
......
...@@ -96,7 +96,6 @@ class ControlFlowGraph(object): ...@@ -96,7 +96,6 @@ class ControlFlowGraph(object):
self._live_out[i].remove(old_name) self._live_out[i].remove(old_name)
self._live_out[i].add(new_name) self._live_out[i].add(new_name)
def _dataflow_analyze(self): def _dataflow_analyze(self):
self._build_graph() self._build_graph()
live_in = defaultdict(set) live_in = defaultdict(set)
...@@ -121,8 +120,8 @@ class ControlFlowGraph(object): ...@@ -121,8 +120,8 @@ class ControlFlowGraph(object):
] ]
if can_optimize: if can_optimize:
for var_name in can_optimize: for var_name in can_optimize:
cache = (var_name, self._find_var( cache = (var_name, self._find_var(block_desc, var_name,
block_desc, var_name, is_forward).shape()) is_forward).shape())
if cache not in self.pool: if cache not in self.pool:
self.pool.append(cache) self.pool.append(cache)
...@@ -232,7 +231,7 @@ class ControlFlowGraph(object): ...@@ -232,7 +231,7 @@ class ControlFlowGraph(object):
] ]
for x, x_shape in out_pair: for x, x_shape in out_pair:
if (x, x_shape) in self.pool: if (x, x_shape) in self.pool:
raise ValueError("x in pool") raise ValueError("x in pool, %s, %s" % (x, x_shape))
# If x is both in uses and defs, it can not be optimized! # If x is both in uses and defs, it can not be optimized!
if x in self._uses[i]: if x in self._uses[i]:
continue continue
...@@ -240,9 +239,14 @@ class ControlFlowGraph(object): ...@@ -240,9 +239,14 @@ class ControlFlowGraph(object):
cache_var = cache_pair[0] cache_var = cache_pair[0]
cache_shape = cache_pair[1] cache_shape = cache_pair[1]
if not self._has_var(block_desc, cache_var, is_forward): if not self._has_var(block_desc, cache_var, is_forward):
raise ValueError("cache", cpt.to_text(cache_var), " Not exists!") raise ValueError("cache",
cpt.to_text(cache_var),
" Not exists!")
if x == cache_var: if x == cache_var:
raise ValueError("x : ", cpt.to_text(x), " cache : ", cpt.to_text(cache_var), " is same var!") raise ValueError("x : ",
cpt.to_text(x), " cache : ",
cpt.to_text(cache_var),
" is same var!")
x_dtype = self._find_var(block_desc, x, x_dtype = self._find_var(block_desc, x,
is_forward).dtype() is_forward).dtype()
...@@ -266,14 +270,14 @@ class ControlFlowGraph(object): ...@@ -266,14 +270,14 @@ class ControlFlowGraph(object):
# Rename the var to the cache var already with # Rename the var to the cache var already with
# memory allocated in order to reuse the memory. # memory allocated in order to reuse the memory.
_rename_arg_(self._ops, x, cache_var, begin_idx=i) _rename_arg_(self._ops, x, cache_var, begin_idx=i)
self._program.block(block_desc.id)._remove_var(cpt.to_text( self._program.block(block_desc.id).var(cpt.to_text(
x)) x)).desc = self._find_var(block_desc, cache_var,
is_forward)
self._update_graph(x, cache_var, begin_idx=i) self._update_graph(x, cache_var, begin_idx=i)
break break
self._fill_pool(i, is_forward) self._fill_pool(i, is_forward)
def _process_sub_block_pair(pdesc, sub_block_pair): def _process_sub_block_pair(pdesc, sub_block_pair):
"""Creates a list of tuple each of which tracks info of a subblock. """Creates a list of tuple each of which tracks info of a subblock.
...@@ -379,7 +383,7 @@ def memory_optimize(input_program, skip_opt_set=None, print_log=False, level=0): ...@@ -379,7 +383,7 @@ def memory_optimize(input_program, skip_opt_set=None, print_log=False, level=0):
Note: it doesn't not support subblock nested in subblock. Note: it doesn't not support subblock nested in subblock.
:param input_program: Input Program :param input_program(str): Input Program
:param print_log: whether to print debug log. :param print_log: whether to print debug log.
:param level: If level=0, reuse if the shape is completely equal, o :param level: If level=0, reuse if the shape is completely equal, o
:return: :return:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册