Enable creating variables in loops.
PiperOrigin-RevId: 325509160
Change-Id: I1d73baf75d0be1b3707b1cfceb97e8b9a32162e4
diff --git a/RELEASE.md b/RELEASE.md
index f0c5907..5f0553c 100644
--- a/RELEASE.md
+++ b/RELEASE.md
@@ -106,6 +106,20 @@
True, the function may use type annotations to optimize the tracing
performance.
* Added support for `iter(DistributedDataset)` in AutoGraph `for` loops.
+ * AutoGraph now allows creating new symbols inside a TensorFLow loop, if
+ the values of these symbols at an iteration does not depend on the previous
+ iteration. These types of loops must run at least one iteration, and will
+ raise a runtime error otherwise.
+
+ Example:
+
+ ```
+ for batch in data:
+ outputs = train_step(batch)
+ tf.print('final outputs', outputs)
+ ```
+ See tensorflow/python/autograph/g3doc/reference/limitations.md for more
+ info.
* `tf.lite`:
* `DynamicBuffer::AddJoinedString()` will now add a separator if the first
string to be joined is empty.
diff --git a/tensorflow/python/autograph/operators/control_flow.py b/tensorflow/python/autograph/operators/control_flow.py
index 3418450..0106efd 100644
--- a/tensorflow/python/autograph/operators/control_flow.py
+++ b/tensorflow/python/autograph/operators/control_flow.py
@@ -973,7 +973,8 @@
"""
state_modified = False
- if not os.getenv('AUTOGRAPH_CREATE_SYMBOLS_IN_LOOPS', ''):
+ # TODO(mdan): Remove once the default option is stable.
+ if os.getenv('AUTOGRAPH_CREATE_SYMBOLS_IN_LOOPS', '1') == '0':
_verify_loop_init_vars(init_vars, symbol_names)
return False, init_vars