From 9d12ca95e3ce0a490e8d8d52976f00b24c0a9142 Mon Sep 17 00:00:00 2001 From: xuwei06 Date: Wed, 14 Sep 2016 16:14:32 -0700 Subject: [PATCH] Further fix the memory for Hierarchical RNN Sequences should be sorted according to the number of subsequences they have. --- .../paddle/trainer_config_helpers/layers.py | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/python/paddle/trainer_config_helpers/layers.py b/python/paddle/trainer_config_helpers/layers.py index dfcabfdb843..bda0b4f5d60 100644 --- a/python/paddle/trainer_config_helpers/layers.py +++ b/python/paddle/trainer_config_helpers/layers.py @@ -21,7 +21,6 @@ from .evaluators import * from .poolings import MaxPooling, AvgPooling, BasePoolingType from .attrs import * from .default_decorators import * - try: import cPickle as pickle except ImportError: @@ -204,6 +203,25 @@ ERROR_CLIPPING = 'error_clipping_threshold' DROPOUT = 'drop_rate' +def check_input(input): + """ + Check input is a LayerOutput or list of LayerOutput or tuple of LayerOutput + if is a LayerOutput, + + :param input: The input layer. Could be a list/tuple of input layer. + :type input: LayerOutput|list|tuple + :return: list of LayerOutput + :rtype: list of LayerOutput + """ + + if isinstance(input, LayerOutput): + return [LayerOutput] + assert isinstance(input, list) + for inp in input: + assert isinstance(inp, LayerOutput) + return list(input) + + def layer_support(*attrs): def decorator(method): @functools.wraps(method) @@ -731,19 +749,27 @@ def fc_layer(input, size, act=None, name=None, return LayerOutput(name, LayerType.FC_LAYER, input, activation=act, size=size) + @wrap_name_default("print") def print_layer(input, name=None): """ Print the output value of input layers. This layer is useful for debugging. + + :param name: The Layer Name. + :type name: basestring + :param input: The input layer. Could be a list/tuple of input layer. + :type input: LayerOutput|list|tuple + :return: No return """ - assert isinstance(input, list) + check_input(input) Layer( name=name, type=LayerType.PRINT_LAYER, inputs=[l.name for l in input], ) - return LayerOutput(name, LayerType.PRINT_LAYER, input) + LayerOutput(name, LayerType.PRINT_LAYER, input) + @wrap_name_default("seq_pooling") @wrap_bias_attr_default(has_bias=False) -- GitLab