Skip to content
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

Loop not simple enough in some cases #151

Open
albertz opened this issue May 6, 2022 · 1 comment
Open

Loop not simple enough in some cases #151

albertz opened this issue May 6, 2022 · 1 comment
Milestone

Comments

@albertz
Copy link
Member

albertz commented May 6, 2022

This is maybe a collection of multiple issues.

Consider the example from the test case test_loop_axis_indices:

class _Net(nn.Module):
  @nn.scoped
  def __call__(self, x: nn.Tensor, *, axis: nn.Dim) -> nn.Tensor:
    loop = nn.Loop(axis=axis)
    indices = nn.range_over_dim(axis)
    loop.state.x = nn.zeros([nn.batch_dim, x.feature_dim], dtype=indices.dtype)
    with loop:
      i = loop.unstack(indices)
      loop.state.x = loop.state.x + i
      loop.stack(i)  # loop needs some dummy output currently...
    return loop.state.x

There are multiple problems here:

  • The nn.range_over_dim is too complicated just to get the running index i in the loop. In RETURNN, we have :i for that. Although that support of :i is a bit incomplete, so it might make sense to use a RangeInAxesLayer internally. But this could stay internally, and we could introduce sth like loop.i.
  • The loop.stack(i) in the end is a workaround because there must be some stacked output. This is RecLayer without accumulated output but just last frame returnn#1029.
@albertz albertz added this to the first-release milestone May 6, 2022
albertz referenced this issue May 6, 2022
We probably should simplify this later.
@albertz
Copy link
Member Author

albertz commented May 8, 2022

Note on i: Internally, we cannot always use nn.range_in_axis. This is only possible when the length is already known. If the length is not known, it has to be dynamic somehow. It's not clear what the best solution is.

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

No branches or pull requests

1 participant