|
| 1 | +import json |
| 2 | +import os |
| 3 | + |
| 4 | +from absl import app |
| 5 | +from absl import flags |
| 6 | +import jax |
| 7 | + |
| 8 | +SUBMISSION_PATH = 'prize_qualification_baselines/self_tuning/jax_nadamw_full_budget.py' |
| 9 | +EXPERIMENT_DIR = 'submissions/rolling_leaderboard/self_tuning/baseline' |
| 10 | +TUNING_SEARCH_SPACE = None |
| 11 | +FRAMEWORK = 'jax' |
| 12 | +TUNING_RULESET = 'self' |
| 13 | + |
| 14 | +flags.DEFINE_string('submission_path', |
| 15 | + SUBMISSION_PATH, |
| 16 | + 'Path to submission module.') |
| 17 | +flags.DEFINE_string('tuning_search_space', |
| 18 | + TUNING_SEARCH_SPACE, |
| 19 | + 'Path to tuning search space for submission module.') |
| 20 | +flags.DEFINE_string('experiment_dir', |
| 21 | + EXPERIMENT_DIR, |
| 22 | + 'Path to experiment dir where logs will be saved.') |
| 23 | +flags.DEFINE_enum( |
| 24 | + 'framework', |
| 25 | + FRAMEWORK, |
| 26 | + enum_values=['jax', 'pytorch'], |
| 27 | + help='Can be either pytorch or jax.') |
| 28 | +flags.DEFINE_integer('seed', 0, 'RNG seed to to generate study seeds from.') |
| 29 | +flags.DEFINE_enum( |
| 30 | + 'tuning_ruleset', |
| 31 | + TUNING_RULESET, |
| 32 | + enum_values=['external', 'self'], |
| 33 | + help='Which tuning ruleset to score this submission on. Can be external or self.' |
| 34 | +) |
| 35 | + |
| 36 | +FLAGS = flags.FLAGS |
| 37 | + |
| 38 | +MIN_INT = -2**(31) |
| 39 | +MAX_INT = 2**(31) - 1 |
| 40 | +NUM_TUNING_TRIALS = 5 # For external tuning ruleset |
| 41 | +NUM_STUDIES = 3 |
| 42 | + |
| 43 | +WORKLOADS = { |
| 44 | + "imagenet_resnet": {"dataset": "imagenet"}, |
| 45 | + "imagenet_vit": {"dataset": "imagenet"}, |
| 46 | + "fastmri": {"dataset": "fastmri"}, |
| 47 | + "ogbg": {"dataset": "ogbg"}, |
| 48 | + "wmt": {"dataset": "wmt"}, |
| 49 | + "librispeech_deepspeech": {"dataset": "librispeech"}, |
| 50 | + "criteo1tb": {"dataset": "criteo1tb"}, |
| 51 | + "librispeech_conformer": {"dataset": "librispeech"} |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +def main(_): |
| 56 | + workloads = WORKLOADS.keys() |
| 57 | + key = jax.random.key(FLAGS.seed) |
| 58 | + |
| 59 | + jobs = [] |
| 60 | + |
| 61 | + for workload in workloads: |
| 62 | + # Fold in hash(workload) mod(max(uint32)) |
| 63 | + workload_key = jax.random.fold_in(key, hash(workload) % (2**32 - 1)) |
| 64 | + for study_index in range(NUM_STUDIES): |
| 65 | + study_key = jax.random.fold_in(workload_key, study_index) |
| 66 | + if FLAGS.tuning_ruleset == 'external': |
| 67 | + for hparam_index in range(NUM_TUNING_TRIALS): |
| 68 | + run_key = jax.random.fold_in(study_key, hparam_index) |
| 69 | + seed = jax.random.randint(run_key, (1,), MIN_INT, MAX_INT)[0].item() |
| 70 | + print(seed) |
| 71 | + # Add job |
| 72 | + job = {} |
| 73 | + study_dir = os.path.join(FLAGS.experiment_dir, f"study_{study_index}") |
| 74 | + job['framework'] = FLAGS.framework |
| 75 | + job['workload'] = workload |
| 76 | + job['dataset'] = WORKLOADS[workload]['dataset'] |
| 77 | + job['submission_path'] = FLAGS.submission_path |
| 78 | + job['experiment_dir'] = study_dir |
| 79 | + job['rng_seed'] = seed |
| 80 | + job['tuning_ruleset'] = FLAGS.tuning_ruleset |
| 81 | + job['num_tuning_trials'] = NUM_TUNING_TRIALS |
| 82 | + job['hparam_start_index'] = hparam_index |
| 83 | + job['hparam_end_index'] = hparam_index + 1 |
| 84 | + job['tuning_search_space'] = FLAGS.tuning_search_space |
| 85 | + job['tuning_ruleset'] = FLAGS.tuning_ruleset |
| 86 | + jobs.append(job) |
| 87 | + print(job) |
| 88 | + |
| 89 | + else: |
| 90 | + run_key = study_key |
| 91 | + seed = jax.random.randint(run_key, (1,), MIN_INT, MAX_INT)[0].item() |
| 92 | + print(seed) |
| 93 | + # Add job |
| 94 | + job = {} |
| 95 | + study_dir = os.path.join(FLAGS.experiment_dir, f"study_{study_index}") |
| 96 | + job['framework'] = FLAGS.framework |
| 97 | + job['workload'] = workload |
| 98 | + job['dataset'] = WORKLOADS[workload]['dataset'] |
| 99 | + job['submission_path'] = FLAGS.submission_path |
| 100 | + job['experiment_dir'] = study_dir |
| 101 | + job['rng_seed'] = seed |
| 102 | + job['tuning_ruleset'] = FLAGS.tuning_ruleset |
| 103 | + job['num_tuning_trials'] = 1 |
| 104 | + |
| 105 | + jobs.append(job) |
| 106 | + print(job) |
| 107 | + |
| 108 | + # Convert job array to dict with job indices |
| 109 | + job_dict = {} |
| 110 | + for i, job in enumerate(jobs): |
| 111 | + job_dict[f"{i}"] = job |
| 112 | + |
| 113 | + with open('config.json', 'w') as f: |
| 114 | + json.dump(job_dict, f, indent=4) |
| 115 | + |
| 116 | + |
| 117 | +if __name__ == '__main__': |
| 118 | + app.run(main) |
0 commit comments