Skip to content

Commit 234f8a1

Browse files
committed
rec functions also hidden
1 parent a570838 commit 234f8a1

File tree

2 files changed

+60
-60
lines changed

2 files changed

+60
-60
lines changed

nn/_generate_layers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
}
8282

8383
FunctionNameMap = {
84-
"source": "external_data", # but not used actually
84+
"source": "external_data", # but not used actually because blacklisted
8585
"norm": "normalize",
8686
"softmax_over_spatial": "softmax", # generic also for normal softmax on feature
8787
}
@@ -236,7 +236,8 @@ def setup():
236236
name = camel_case_to_snake_case(name.lstrip("_"))
237237
if name in FunctionNameMap:
238238
name = FunctionNameMap[name]
239-
if sig.layer_class.layer_class in LayersHidden:
239+
# Also see get_module_class_name_for_layer_class for the hidden logic.
240+
if sig.layer_class.layer_class in LayersHidden or sig.has_recurrent_state():
240241
name = "_" + name
241242
print("\n", file=f)
242243
print("# noinspection PyShadowingBuiltins,PyShadowingNames", file=f)
@@ -876,8 +877,7 @@ def get_module_class_name_for_layer_class(sig: LayerSignature) -> str:
876877
# LayersHidden is our explicit list.
877878
# When some layer is purely functional (is_functional), then we just make the function public
878879
# but keep the wrapped layer maker hidden.
879-
# When it has recurrent state, we either have a public function in case it is functional (no params),
880-
# or if not (e.g. RecLayer, TwoDLSTMLayer), we anyway better should use explicit public wrappers.
880+
# When it has recurrent state, we anyway better use explicit public wrappers.
881881
# https://github.com/rwth-i6/returnn_common/issues/31
882882
if layer_class.layer_class in LayersHidden or sig.is_functional() or sig.has_recurrent_state():
883883
return "_" + name # we make a public function for it, but the module is hidden

nn/_generated_layers.py

+56-56
Original file line numberDiff line numberDiff line change
@@ -1984,18 +1984,18 @@ def make_layer_dict(self,
19841984

19851985

19861986
# noinspection PyShadowingBuiltins,PyShadowingNames
1987-
def window(
1988-
source: LayerRef,
1989-
*,
1990-
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
1991-
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
1992-
window_size: int,
1993-
window_left: Optional[int] = NotSpecified,
1994-
window_right: Optional[int] = NotSpecified,
1995-
axis: str = NotSpecified,
1996-
padding: str = NotSpecified,
1997-
stride: int = NotSpecified,
1998-
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
1987+
def _window(
1988+
source: LayerRef,
1989+
*,
1990+
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
1991+
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
1992+
window_size: int,
1993+
window_left: Optional[int] = NotSpecified,
1994+
window_right: Optional[int] = NotSpecified,
1995+
axis: str = NotSpecified,
1996+
padding: str = NotSpecified,
1997+
stride: int = NotSpecified,
1998+
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
19991999
"""
20002000
Adds a window dimension.
20012001
By default, uses the time axis and goes over it with a sliding window.
@@ -2095,15 +2095,15 @@ def make_layer_dict(self,
20952095

20962096

20972097
# noinspection PyShadowingBuiltins,PyShadowingNames
2098-
def cumsum(
2099-
source: LayerRef,
2100-
*,
2101-
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
2102-
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
2103-
axis: str = NotSpecified,
2104-
additional_left_summand_per_element: Optional[Union[str, int, float]] = NotSpecified,
2105-
reverse: bool = NotSpecified,
2106-
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
2098+
def _cumsum(
2099+
source: LayerRef,
2100+
*,
2101+
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
2102+
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
2103+
axis: str = NotSpecified,
2104+
additional_left_summand_per_element: Optional[Union[str, int, float]] = NotSpecified,
2105+
reverse: bool = NotSpecified,
2106+
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
21072107
"""
21082108
Basically wraps tf.cumsum. Also supports that in the RecLayer.
21092109
@@ -6455,19 +6455,19 @@ def make_layer_dict(self,
64556455

64566456

64576457
# noinspection PyShadowingBuiltins,PyShadowingNames
6458-
def ken_lm_state(
6459-
source: LayerRef,
6460-
*,
6461-
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6462-
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6463-
lm_file: Any,
6464-
vocab_file: Optional[str] = NotSpecified,
6465-
vocab_unknown_label: str = NotSpecified,
6466-
bpe_merge_symbol: Optional[str] = NotSpecified,
6467-
input_step_offset: int = NotSpecified,
6468-
dense_output: bool = NotSpecified,
6469-
debug: bool = NotSpecified,
6470-
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
6458+
def _ken_lm_state(
6459+
source: LayerRef,
6460+
*,
6461+
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6462+
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6463+
lm_file: Any,
6464+
vocab_file: Optional[str] = NotSpecified,
6465+
vocab_unknown_label: str = NotSpecified,
6466+
bpe_merge_symbol: Optional[str] = NotSpecified,
6467+
input_step_offset: int = NotSpecified,
6468+
dense_output: bool = NotSpecified,
6469+
debug: bool = NotSpecified,
6470+
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
64716471
"""
64726472
Get next word (or subword) each frame,
64736473
accumulates string,
@@ -6565,14 +6565,14 @@ def make_layer_dict(self,
65656565

65666566

65676567
# noinspection PyShadowingBuiltins,PyShadowingNames
6568-
def edit_distance_table(
6569-
source: LayerRef,
6570-
*,
6571-
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6572-
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6573-
debug: bool = NotSpecified,
6574-
blank_idx: Optional[int] = NotSpecified,
6575-
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
6568+
def _edit_distance_table(
6569+
source: LayerRef,
6570+
*,
6571+
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6572+
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6573+
debug: bool = NotSpecified,
6574+
blank_idx: Optional[int] = NotSpecified,
6575+
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
65766576
"""
65776577
Given a source and a target, calculates the edit distance table between them.
65786578
Source can be inside a recurrent loop.
@@ -6730,13 +6730,13 @@ def make_layer_dict(self,
67306730

67316731

67326732
# noinspection PyShadowingBuiltins,PyShadowingNames
6733-
def unmask(
6734-
source: LayerRef,
6735-
*,
6736-
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6737-
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6738-
mask: LayerRef,
6739-
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
6733+
def _unmask(
6734+
source: LayerRef,
6735+
*,
6736+
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6737+
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
6738+
mask: LayerRef,
6739+
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
67406740
"""
67416741
This is meant to be used together with :class:`MaskedComputationLayer`,
67426742
which operates on input [B,T,D], and given a mask, returns [B,T',D'].
@@ -7002,13 +7002,13 @@ def make_layer_dict(self,
70027002

70037003

70047004
# noinspection PyShadowingBuiltins,PyShadowingNames
7005-
def cum_concat(
7006-
source: LayerRef,
7007-
*,
7008-
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
7009-
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
7010-
new_dim: DimensionTag,
7011-
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
7005+
def _cum_concat(
7006+
source: LayerRef,
7007+
*,
7008+
state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
7009+
initial_state: Optional[Union[LayerRef, Dict[str, LayerRef], NotSpecified]] = NotSpecified,
7010+
new_dim: DimensionTag,
7011+
name: Optional[Union[str, NameCtx]] = None) -> Tuple[Layer, Union[LayerRef, Any]]:
70127012
"""
70137013
Concatenates all previous frames of a time-axis.
70147014
Like :class:`CumsumLayer` uses `sum`, this layer uses `concat`.

0 commit comments

Comments
 (0)