Spaces:
Runtime error
Runtime error
File size: 2,115 Bytes
a560c26 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# coding=utf-8
# Copyright 2023 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Main file for running the model trainer."""
from absl import app
from absl import flags
from absl import logging
from clu import platform
import jax
from ml_collections import config_flags
import tensorflow as tf
from invariant_slot_attention.lib import trainer
FLAGS = flags.FLAGS
config_flags.DEFINE_config_file(
"config", None, "Config file.")
flags.DEFINE_string("workdir", None, "Work unit directory.")
flags.DEFINE_string("jax_backend_target", None, "JAX backend target to use.")
flags.mark_flags_as_required(["config", "workdir"])
def main(argv):
del argv
# Hide any GPUs from TensorFlow. Otherwise TF might reserve memory and make
# it unavailable to JAX.
tf.config.experimental.set_visible_devices([], "GPU")
if FLAGS.jax_backend_target:
logging.info("Using JAX backend target %s", FLAGS.jax_backend_target)
jax.config.update("jax_xla_backend", "tpu_driver")
jax.config.update("jax_backend_target", FLAGS.jax_backend_target)
logging.info("JAX host: %d / %d", jax.host_id(), jax.host_count())
logging.info("JAX devices: %r", jax.devices())
# Add a note so that we can tell which task is which JAX host.
platform.work_unit().set_task_status(
f"host_id: {jax.host_id()}, host_count: {jax.host_count()}")
platform.work_unit().create_artifact(platform.ArtifactType.DIRECTORY,
FLAGS.workdir, "workdir")
trainer.train_and_evaluate(FLAGS.config, FLAGS.workdir)
if __name__ == "__main__":
app.run(main)
|