|
| 1 | +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import paddle.trainer_config_helpers.networks as conf_nw |
| 16 | +import inspect |
| 17 | +from config_base import __convert_to_v2__ |
| 18 | + |
| 19 | +__all__ = [] |
| 20 | + |
| 21 | + |
| 22 | +def __initialize__(): |
| 23 | + for each_subnetwork in conf_nw.__all__: |
| 24 | + if each_subnetwork in ['inputs', 'outputs']: |
| 25 | + continue |
| 26 | + func = getattr(conf_nw, each_subnetwork) |
| 27 | + if hasattr(func, 'argspec'): |
| 28 | + argspec = func.argspec |
| 29 | + else: |
| 30 | + argspec = inspect.getargspec(func) |
| 31 | + if each_subnetwork == 'simple_attention': |
| 32 | + parents = ['encoded_sequence', 'encoded_proj', 'decoder_state'] |
| 33 | + else: |
| 34 | + parents = filter(lambda x: x.startswith('input'), argspec.args) |
| 35 | + assert len(parents) != 0, each_subnetwork |
| 36 | + v2_subnet = __convert_to_v2__( |
| 37 | + each_subnetwork, |
| 38 | + parent_names=parents, |
| 39 | + is_default_name='name' in argspec.args) |
| 40 | + globals()[each_subnetwork] = v2_subnet |
| 41 | + global __all__ |
| 42 | + __all__.append(each_subnetwork) |
| 43 | + |
| 44 | + |
| 45 | +__initialize__() |
0 commit comments