Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions python/paddle/fluid/memory_optimization_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

sub_block_ops = ["while", "while_grad", "parallel_do", "parallel_do_grad"]

PRINT_LOG = False


class ControlFlowGraph(object):
def __init__(self, Program, ops, forward_num, skip_opt):
Expand Down Expand Up @@ -171,12 +173,14 @@ def check_var_validity(block_desc, x, is_forward):
# TODO(qijun): actually, we should compare dtype_to_size[x_dtype]
# and dtype_to_size[cache_dtype]
if x_dtype == cache_dtype:
print(("Hit Cache !!!! cache pool index "
"is %d, var name is %s, "
"cached var name is %s, "
"var shape is %s ") %
(index, x, cache_var,
str(cache_shape)))
if PRINT_LOG:
print(
("Hit Cache !!!! cache pool index "
"is %d, var name is %s, "
"cached var name is %s, "
"var shape is %s ") %
(index, x, cache_var,
str(cache_shape)))
self.pool.pop(index)
if x == cache_var:
break
Expand Down Expand Up @@ -277,7 +281,9 @@ def _get_cfgs(input_program):
return cfgs


def memory_optimize(input_program):
def memory_optimize(input_program, print_log=False):
global PRINT_LOG
PRINT_LOG = print_log
cfgs = _get_cfgs(input_program)
for cfg in cfgs:
cfg.memory_optimize()
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
sgd_optimizer = fluid.optimizer.SGD(learning_rate=0.01)
sgd_optimizer.minimize(avg_cost)

fluid.memory_optimize(fluid.default_main_program())
fluid.memory_optimize(fluid.default_main_program(), print_log=True)

BATCH_SIZE = 200

Expand Down