Skip to content

Commit

Permalink
move Tensor debug_layer to NameCtx
Browse files Browse the repository at this point in the history
This is for preparation of RETURNN Tensor usage.
#252
  • Loading branch information
albertz committed Feb 28, 2023
1 parent 3fd39b0 commit dd89f94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 5 additions & 6 deletions nn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def __init__(
# Do not assign name_ctx.layer{_ref} yet because we potentially could raise exceptions later.
assert name_ctx.layer_ref is None
assert name_ctx.layer is None
self.debug_layer = None
self.extra_dependencies = [] # type: List[Tensor]

if is_ref:
Expand Down Expand Up @@ -959,13 +958,13 @@ def _get_sub_layer(layer: Tensor, name: str, *, data: Data) -> Tensor:
"""
out = layer.raw_tensor.get_child_layer_ref(name, data=data)
if nn.is_debug_eager_mode_enabled():
assert layer.debug_layer
assert layer.raw_tensor.debug_layer
import returnn.tf.layers.base

assert isinstance(layer.debug_layer, returnn.tf.layers.base.LayerBase)
sub_layer = layer.debug_layer.get_sub_layer(name)
assert isinstance(layer.raw_tensor.debug_layer, returnn.tf.layers.base.LayerBase)
sub_layer = layer.raw_tensor.debug_layer.get_sub_layer(name)
assert sub_layer and sub_layer.output.dim_tags == out.data.dim_tags
out.debug_layer = sub_layer
out.raw_tensor.debug_layer = sub_layer
out.data = sub_layer.output
return out

Expand Down Expand Up @@ -1090,7 +1089,7 @@ def _add_layer(name: str, layer_class: Type[LayerBase], **layer_desc) -> LayerBa
layer = net.construct_layer(net_dict=net_dict, name=out_name, add_layer=_add_layer)

if nn.is_debug_eager_mode_enabled():
tensor.debug_layer = layer
tensor.raw_tensor.debug_layer = layer

return layer.output

Expand Down
1 change: 1 addition & 0 deletions nn/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def __init__(
self.layer_ref = None # type: Optional[nn.Tensor]
self.layer = None # type: Optional[nn.Tensor]
self.layer_dict = None # type: Optional[nn.LayerDictRaw]
self.debug_layer = None # type: Optional[nn.LayerBase]
self._enter_stack_frames = None # type: Optional[Set[types.FrameType]]
self.is_subnet = False # it says whether it can have children
self._subnet_main_output = None # type: Optional[nn.Tensor] # when this is via SubnetworkLayer
Expand Down

0 comments on commit dd89f94

Please sign in to comment.