Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tensorflow_gnn/runner/orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,20 @@ def apply_fn(ds,
drop_remainder,
global_batch_size)

def adapted_model_fn():
def adapted_model_fn(options = None):
if isinstance(preprocess_model.output, collections.abc.Sequence):
x, *_ = preprocess_model.output
else:
x = preprocess_model.output
m = task.adapt(model_fn(x.spec))
optimizer = optimizer_fn()
if options and options.policy:
# Cast logits to `tf.keras.backend.floatx()` for mixed_precision.
# For more details, see:
# https://www.tensorflow.org/guide/mixed_precision#building_the_model.
floatx = tf.keras.backend.floatx()
outputs = [tf.cast(o, dtype=floatx) for o in m.outputs]
m = tf.keras.Model(m.inputs, outputs)
if train_padding is None:
m.compile(optimizer, loss=task.losses(), metrics=task.metrics())
else:
Expand Down
8 changes: 0 additions & 8 deletions tensorflow_gnn/runner/trainers/keras_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,6 @@ def per_replica_ds_fn(input_context, *, delegate, repeat):
with self._strategy.scope():
model = model_fn()

if self._options and self._options.policy:
# Cast logits to `tf.keras.backend.floatx()` for mixed_precision.
# For more details, see:
# https://www.tensorflow.org/guide/mixed_precision#building_the_model.
floatx = tf.keras.backend.floatx()
outputs = [tf.cast(o, dtype=floatx) for o in model.outputs]
model = tf.keras.Model(model.inputs, outputs)

model.fit(
train_ds,
epochs=epochs,
Expand Down