-
Notifications
You must be signed in to change notification settings - Fork 131
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
rf.Cond and rf.Loop for eager frameworks #1282
Comments
So the current interface in returnn_common is this, right?
(And the whole point is to execute only one of the graphs defined in mod_true_case / mod_false_case.) I haven't used it myself, so this is already not totally clear to me. From the code I see that entering the context manager and assigning to true and false will trigger switching the "name_ctx", which will collect separate subnetworks created between enter and true / between true and false, right? So what about doing it similar to
Was this considered to be too verbose for return_common? Or am I missing something about this name_ctx? At least this would work for eager frameworks too, you can just call one of the functions right away. But this is an important issue. If people don't care for the graph based case and writing
in eager mode works, then they will probably do it. Or if we make it impossible they will consider not using the frontend at all because pure PyTorch is simpler. So there is the risk when writing the frontend framework-independent that we end up with the union of all limitations of the different frameworks. |
Right.
No, this is not specific to the net dict construction. This can work for any graph based frameworks. We simply need to switch to the right control flow context (TF control flow v1) or sub graph (TF control flow v2) (which corresponds to being inside the true or false branch inside
Yes, that is another possibility. I will add this to the list above. I personally found this as too verbose and ugly, that's why I did not want to use it for RC. I thought by using such context manager, it looks simpler. But now considering this issue here, it's maybe actually a good solution, as it would be very straightforward, both for eager-based and graph-based frameworks.
If If y = mod_true_case(x) if cond.raw_tensor.numpy() else mod_false_case(x) But once the user accesses |
So, any opinions? I currently tend to the TF-like APIs (so |
So we implemented |
I want to collect some thoughts on possible options to implement
rf.Cond
andrf.Loop
(like RCnn.Cond
andnn.Loop
) for the RETURNN frontend (import returnn.frontend as rf
, #1120). This is not straight-forward for eager-mode frameworks where it should execute directly.Rewrite Python AST, based on current RC API. But when? When
rf.Cond
is called, is it too late? Must use a func decorator?Pro:
Con:
Redesign the API of
Cond
andLoop
to support both cases (eager-mode and graph-mode) well?Pro:
Con:
Design:
In the backend, have an extra check for the control flow context in all functions, and ignore execution when not in right scope.
Pro:
Con:
Use a similar interface like
tf.cond
andtf.while_loop
, using function callbacks.Pro:
Contra:
The text was updated successfully, but these errors were encountered: