Skip to content

VariableLayer, change default add_batch_axis to False #764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 24, 2021

Conversation

albertz
Copy link
Member

@albertz albertz commented Nov 24, 2021

Fix #763.

As this should not have any influence on behavior, this does not need a new behavior version.

Fix #763.

As this should not have any influence on behavior,
this does not need a new behavior version.
@albertz
Copy link
Member Author

albertz commented Nov 24, 2021

The assumption that it should not have any influence (or rather that all other layers are bug free and feature complete) was invalid. (@Zettelkasten )

The test test_ScatterNdLayer_RangeLayer_RangeInAxisLayer fails.
Network:

net_dict = {
  "t": {
    "class": "range_in_axis", "axis": "t", "from": "data",
    "out_shape": {time_dim, ImplicitDynSizeDim(BatchDim)}},  # (T,)
  "range": {"class": "range", "limit": n_ts, "out_spatial_dim": ts_dim},  # (Ts,)
  "add_t": {
    "class": "combine", "kind": "add", "from": ["t", "range"],
    "out_shape": {time_dim, ts_dim, ImplicitDynSizeDim(BatchDim)}},  # (T,Ts)
  "t_rel_var": {"class": "variable", "shape": (ts_dim, n_out), "init": "glorot_uniform"},  # (B,Ts,D)
  "output": {"class": "scatter_nd", "from": "t_rel_var", "position": "add_t", "position_axis": -1,
             "output_dim_via_time_from": "data", "filter_invalid_indices": True}
}

Log:

layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'t_rel_var' output: Data{'t_rel_var_output', ['ts'(6),F|F't_rel_var:static:1'(11)]}
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'data' output: Data{'data', [B,T|'time'[B],F|F'in-feature'(7)]}
2021-11-24 15:15:03.524447: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'t' output: Data{'t_output', [T|'time'[B]], dtype='int32'}
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'range' output: Data{'range_output', [F|'ts'(6)], dtype='int32'}
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'add_t' output: Data{'add_t_output', [T|'time'[B],F|'ts'(6)], dtype='int32'}
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'output' output: Data{'output_output', [T|'time'[B],'time'[B?],F|F't_rel_var:static:1'(11)]}
EXCEPTION
Traceback (most recent call last):
  File "tests/test_TFNetworkLayer.py", line 5634, in <module>
    line: globals()[arg]()  # assume function and execute
    locals:
      globals = <builtin> <built-in function globals>
      arg = <local> 'test_ScatterNdLayer_RangeLayer_RangeInAxisLayer', len = 47
  File "tests/test_TFNetworkLayer.py", line 2509, in test_ScatterNdLayer_RangeLayer_RangeInAxisLayer
    line: assert out_layer.output.feature_dim_axis_or_unspecified is NotSpecified and out_layer.output.feature_dim_axis == 3
    locals:
      out_layer = <local> <ScatterNdLayer 'output' out_type=Data{[T|'time'[B],'time'[B?],F|F't_rel_var:static:1'(11)]}>
      out_layer.output = <local> Data{'output_output', [T|'time'[B],'time'[B?],F|F't_rel_var:static:1'(11)]}
      out_layer.output.feature_dim_axis_or_unspecified = <local> <class 'returnn.util.basic.NotSpecified'>
      NotSpecified = <global> <class 'returnn.util.basic.NotSpecified'>
      out_layer.output.feature_dim_axis = <local> 2
AssertionError

I assume some problem in ScatterNdLayer. I will look into that.

@albertz albertz force-pushed the albert-var-no-def-batch-763 branch 2 times, most recently from ed69229 to 76d4c3b Compare November 24, 2021 14:39
@albertz
Copy link
Member Author

albertz commented Nov 24, 2021

Ok, maybe just the test is a bit strange.
For reference, the layer log in current master:

layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'t_rel_var' output: Data{'t_rel_var_output', [B,'t_rel_var:static:0'(6),F|F't_rel_var:static:1'(11)]}
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'data' output: Data{'data', [B,T|'T'[B],F|F'F'(7)]}
2021-11-24 15:56:34.763191: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'t' output: Data{'t_output', [T|'T'[B]], dtype='int32'}
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'range' output: Data{'range_output', [F|'ts'(6)], dtype='int32'}
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'add_t' output: Data{'add_t_output', [T|'T'[B],F|'ts'(6)], dtype='int32'}
layer <network via test_ScatterNdLayer_RangeLayer_RangeInAxisLayer>/'output' output: Data{'output_output', [T|'T'[B],'T'[B],B,F|F't_rel_var:static:1'(11)]}

It looks correct that we have the T axis twice in the output.

This is a case where enforced unique dim tags (#632) would fail.

@albertz albertz force-pushed the albert-var-no-def-batch-763 branch from 76d4c3b to 6be2a5c Compare November 24, 2021 15:04
@albertz albertz marked this pull request as ready for review November 24, 2021 18:03
@albertz albertz requested a review from a team as a code owner November 24, 2021 18:03
@albertz albertz merged commit b974758 into master Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VariableLayer, use add_batch_axis=False by default
1 participant