Datasets:
ArXiv:
License:
File size: 3,916 Bytes
79c32b1 | 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | """
launch.py — run an authors' training script UNMODIFIED on a trajectory-level subset.
The ONLY intervention anywhere in this reproduction: d4rl.qlearning_dataset is
monkey-patched to return the trajectory-level subset (see subset_loader.py).
StBR main.py, SPOT main.py and SPOT train_vae.py are executed verbatim via runpy
with their own --config files and defaults.
Examples
--------
# Full StBR run (repo defaults: 1M steps, eval every 10k):
python launch.py --repo /workspace/StBR --entry main.py \
--config configs/offline/hopper-medium.yml --method stbr --fraction 0.25 \
--seed 0 --out /out/stbr_f0.25_s0
# SPOT = train VAE on the SAME subset first, then the policy:
python launch.py --repo /workspace/SPOT --entry train_vae.py \
--method spot --fraction 0.25 --seed 0 --out /out/spot_f0.25_s0_vae \
--extra_args --env hopper --dataset medium
python launch.py --repo /workspace/SPOT --entry main.py \
--config configs/offline/hopper-medium.yml --method spot --fraction 0.25 \
--seed 0 --out /out/spot_f0.25_s0
--max_timesteps/--eval_freq are smoke-test conveniences ONLY; full runs omit them
and use the repo defaults.
"""
import argparse
import json
import os
import runpy
import sys
import time
def main():
p = argparse.ArgumentParser()
p.add_argument('--repo', required=True)
p.add_argument('--entry', default='main.py')
p.add_argument('--config', default=None)
p.add_argument('--method', required=True, choices=['stbr', 'spot'])
p.add_argument('--fraction', type=float, default=1.0)
p.add_argument('--seed', type=int, default=0)
p.add_argument('--subset_seed', type=int, default=None,
help='seed for the trajectory sampling; defaults to --seed')
p.add_argument('--max_timesteps', type=int, default=None)
p.add_argument('--eval_freq', type=int, default=None)
p.add_argument('--extra_args', nargs='*', default=[])
p.add_argument('--out', required=True)
a = p.parse_args()
os.makedirs(a.out, exist_ok=True)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import d4rl
import subset_loader
subset_loader.set_original(d4rl.qlearning_dataset)
if a.fraction < 1.0:
sseed = a.subset_seed if a.subset_seed is not None else a.seed
subset_loader.configure(fraction=a.fraction, seed=sseed,
out_dir=os.path.join(a.out, 'subset_recipe'))
d4rl.qlearning_dataset = subset_loader.patched_qlearning_dataset
argv = [a.entry]
if a.config:
argv += ['--config', a.config]
argv += ['--seed', str(a.seed)]
if a.max_timesteps is not None:
argv += ['--max_timesteps', str(int(a.max_timesteps))]
if a.eval_freq is not None:
argv += ['--eval_freq', str(int(a.eval_freq))]
argv += list(a.extra_args)
sys.argv = argv
os.chdir(a.repo)
t0 = time.time()
status = 'completed'
try:
runpy.run_path(a.entry, run_name='__main__')
except SystemExit as e:
status = f'exited code={e.code}'
except BaseException as e:
status = f'failed: {type(e).__name__}: {e}'
raise
finally:
with open(os.path.join(a.out, 'meta.json'), 'w') as fh:
json.dump({
'method': a.method, 'entry': a.entry, 'config': a.config,
'fraction': a.fraction, 'seed': a.seed,
'subset_seed': a.subset_seed if a.subset_seed is not None else a.seed,
'max_timesteps_override': a.max_timesteps,
'eval_freq_override': a.eval_freq,
'argv_after_config': argv,
'wall_time_sec': round(time.time() - t0, 1),
'status': status,
}, fh, indent=2)
print(f'[launch] {a.method} f={a.fraction} seed={a.seed} finished: {status} '
f'in {(time.time() - t0) / 60:.1f} min', flush=True)
if __name__ == '__main__':
main()
|