|
| 1 | +# Copyright 2024 The Flax Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Main file for running the NLP sequence tagging example. |
| 16 | +
|
| 17 | +This file is intentionally kept short to allow config-based execution. |
| 18 | +""" |
| 19 | + |
| 20 | +from absl import app |
| 21 | +from absl import flags |
| 22 | +import train |
| 23 | +from ml_collections import config_flags |
| 24 | + |
| 25 | + |
| 26 | +FLAGS = flags.FLAGS |
| 27 | + |
| 28 | +config_flags.DEFINE_config_file( |
| 29 | + 'config', |
| 30 | + 'configs/default.py', |
| 31 | + 'File path to the training hyperparameter configuration.', |
| 32 | + lock_config=True, |
| 33 | +) |
| 34 | + |
| 35 | + |
| 36 | +def main(argv): |
| 37 | + if len(argv) > 1: |
| 38 | + raise app.UsageError('Too many command-line arguments.') |
| 39 | + |
| 40 | + # Convert config to FLAGS for train.py compatibility |
| 41 | + config = FLAGS.config |
| 42 | + |
| 43 | + # Override FLAGS with config values |
| 44 | + FLAGS.model_dir = config.model_dir |
| 45 | + FLAGS.experiment = config.experiment |
| 46 | + FLAGS.batch_size = config.batch_size |
| 47 | + FLAGS.eval_frequency = config.eval_frequency |
| 48 | + FLAGS.num_train_steps = config.num_train_steps |
| 49 | + FLAGS.learning_rate = config.learning_rate |
| 50 | + FLAGS.weight_decay = config.weight_decay |
| 51 | + FLAGS.max_length = config.max_length |
| 52 | + FLAGS.random_seed = config.random_seed |
| 53 | + FLAGS.train = config.train |
| 54 | + FLAGS.dev = config.dev |
| 55 | + |
| 56 | + # Run the training |
| 57 | + train.main(argv) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == '__main__': |
| 61 | + app.run(main) |
0 commit comments