Skip to content

Commit 8bdca4e

Browse files
committed
IterLayer, wip
1 parent 167951f commit 8bdca4e

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

returnn/tf/layers/rec.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,6 +4296,27 @@ def get_out_data_from_opts(cls, name, sources, sub_layer, **kwargs):
42964296
return subnet.layers[sub_layer].output
42974297

42984298

4299+
class IterLayer(LayerBase):
4300+
"""
4301+
This is supposed to be used inside a :class:`RecLayer`.
4302+
The input is supposed to be outside the rec layer (i.e. via ``base:``).
4303+
Uses tf.TensorArray and then unstack on the inputs to make it available per-frame.
4304+
This is an alternative to making some input to the rec layer,
4305+
such that the rec layer can have multiple inputs (as long as they have the same time dim).
4306+
"""
4307+
# TODO:
4308+
# I'm not really sure whether this layer is the best approach.
4309+
# We could also introduce a new syntax, like ``base-iter:`` instead of ``base:`` to do that,
4310+
# and then hide the logic inside RecLayer.
4311+
# Another problem: As there is no recurrent dependency on this layer (its only input is outside),
4312+
# it will be optimized out.
4313+
# In the optimized-out case, it would not use tf.TensorArray but simply copy the input.
4314+
# So then this is just equivalent to CopyLayer.
4315+
# TODO Why does CopyLayer actually not work already?
4316+
# See also the logic in get_input_moved_out inside _construct.
4317+
# TODO ...
4318+
4319+
42994320
class BaseChoiceLayer(LayerBase):
43004321
"""
43014322
This is a base-class for any layer which defines a new search choice,

0 commit comments

Comments
 (0)