-
Notifications
You must be signed in to change notification settings - Fork 130
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
TensorFlow 2 compatibility: draft #283
Comments
Some update here: I pushed some initial TF 2 support already to master. The main logic is in |
I consider this as complete now. All tests should pass now. Please open a new issue if anything does not work. |
Small final update: Since commit 5aabe21, all relevant TF 2 test cases run through now, and are part of Travis now. |
How to make SpecAug work with TF 2? The changes are tf.random_uniform to tf.random.uniform and tf.log to tf.math.log. |
Yes, of course all your custom TF code in your config needs to be adopted for TF 2. Most code will work as is. And otherwise the changes are very minor. In all cases, it should always work by just using |
I want to list all possible options we have to implement this.
First some references:
enable_v2_behavior
andtensorflow.compat.v2
(since TF 1.14).import lingvo.compat as tf
.In any case, also for TF 2, we would use graph-mode, not eager mode.
The current goal:
I don't really see this question answered in the migration guide. Maybe the answer is that there simply is no "best practice" for this.
We could maybe do sth like this:
However, that has some drawbacks:
TFUtil.py
, and then simply dofrom TFUtil import tf
everywhere. But this is somewhat ugly.We could maybe do sth like this:
This might be more clean. But I'm not sure if this is the way to go. Or how other people do it.
Also, instead of calling
disable_v2_behavior
, we could maybe just calldisable_eager_execution
. But that might make some other code more difficult to make compatible for both TF 1 and TF 2.Or we could go the other way around, and use
enable_v2_behavior
in TF 1, and alsotensorflow.compat.v2
. But this works only since TF 1.14.How do other bigger projects solve this?
Or maybe the answer is that this would be way too much effort, and so they simply migrate directly to TF 2?
Another aspect, but this might be less important for now: If it would be possible to also support JAX, or make the transition easy, that would be nice.
The solution now, as implemented in
TFCompat.py
, which is already in master:So instead of using
tf.compat.v1.XXX
, you would useTFCompat.v1.XXX
in your code (when needed). This works even on very old TF versions wheretf.compat.v1
does not exist.(In new code for optional new features, you could directly use
tf.XXX
ortf.compat.v1.XXX
ortf.compat.v2.XXX
(or whatever you want) (see contributing).)The process of supporting all features of RETURNN in TF 2 is now work-in-progress. Many parts already work correctly.
At some later point, once we drop all TF <1.14 support or so, we could simply replace all
TFCompat.v1
usage bytf.compat.v1
.Once we drop TF 1 support completely, we could slowly (gradually) replace all
tf.compat.v1
(orTFCompat.v1
) usage by new TF 2 variants.The text was updated successfully, but these errors were encountered: