Adds an unsafe internal fastpath for oplayer construction in TF1 graphs due to specific requests.
PiperOrigin-RevId: 342905795 Change-Id: I8385e5730a060b460e0e156886a3bdd0cbc3070c
This commit is contained in:
parent
b2d1af50b9
commit
da495851f9
@ -189,6 +189,19 @@ def create_keras_history(tensors):
|
||||
return created_layers
|
||||
|
||||
|
||||
# Unsafe Internal attribute.
|
||||
# If True, Keras will not evaluate the constant-foldable inputs to tf op
|
||||
# layers in TF1 graphs. This *might* speed up model construction time in
|
||||
# certain settings, but it means
|
||||
# the models will not be serializable/deserializable via get_config
|
||||
# (Only via Savedmodels). It may also change the semantics of whether
|
||||
# generated random numbers are generated once and re-used, or recomputed
|
||||
# each time.
|
||||
# Note: This path triggers for TPUEstimators / xla compiled graphs regardless
|
||||
# of this setting.
|
||||
_UNSAFE_GRAPH_OP_LAYER_CREATION = False
|
||||
|
||||
|
||||
def _create_keras_history_helper(tensors, processed_ops, created_layers):
|
||||
"""Helper method for `create_keras_history`.
|
||||
|
||||
@ -238,7 +251,7 @@ def _create_keras_history_helper(tensors, processed_ops, created_layers):
|
||||
not ops.executing_eagerly_outside_functions())
|
||||
using_xla = control_flow_util.GraphOrParentsInXlaContext(
|
||||
ops.get_default_graph())
|
||||
if ds_with_session or using_xla:
|
||||
if ds_with_session or using_xla or _UNSAFE_GRAPH_OP_LAYER_CREATION:
|
||||
# In Legacy Graph mode, evaluating here makes Session be
|
||||
# configured improperly. The downside of this is that saving
|
||||
# via `get_config` breaks, but SavedModel still works.
|
||||
|
Loading…
Reference in New Issue
Block a user