Exemple #1
0
import sys
from utils import dict_product, iwt, generate_configs

with open("../src/MuJoCo.json") as f:
    BASE_CONFIG = json.load(f)

PARAMS = {
    "game": ["Walker2d-v2"],
    "mode": ["ppo"],
    "out_dir": ["lstm_ppo_walker/agents"],
    "norm_rewards": ["returns"],
    "initialization": ["orthogonal"],
    "anneal_lr": [True],
    "value_clipping": [True],
    "ppo_lr_adam": [1e-3],
    "val_lr": [3e-2],
    "cpu": [True],
    "advanced_logging": [False],
    "save_iters": [20],
    "train_steps": [976],
    "robust_ppo_eps": [0.05], # used for attack
    "history_length": [100],
    "use_lstm_val": [True],
    "adv_clip_eps": [0.4],
    "adv_entropy_coeff": [0.0],
    "adv_ppo_lr_adam": [1e-3],
    "adv_val_lr": [1e-2],
}

generate_configs(BASE_CONFIG, PARAMS)
    print('...Testing...')
    test(config)

    # _ = utils.save_results(config, train_acc_per_epoch, test_acc_per_epoch, test_only, save_test)


if __name__ == '__main__':
    # with torch.autograd.profiler.profile(use_cuda=True) as prof:
    parser = argparse.ArgumentParser()
    parser.add_argument("--dataset", type=str, default="MNIST")
    parser.add_argument("-hr_test", type=float, default=None)
    parser.add_argument("-config", type=str, required=True)
    parser.add_argument("-colab", action="store_true")
    parser.add_argument("-jit", action="store_true",
                        default=False)  # can't plot results computed with jit
    args = parser.parse_args()
    hr_test = args.hr_test
    # assert hr_test in [None, "1", "2"], "hr_test must be 1, 2 or None!!!"
    run_configs = utils.load_run_config(args.config)
    configs = utils.generate_configs(
        run_configs, hr_test, args.colab, args.config,
        args.jit)  # list of configurations (=dict) to be trained
    time0 = time()  # total run time
    for i, conf in enumerate(configs):
        print(f'\n[{i + 1}/{len(configs)}] {conf["save_dir"]}')
        try:
            utils.reset_seed(conf['random_seed'])
            main(conf)
        except Exception as e:
            raise
    print('End')
import json

import sys
from utils import dict_product, iwt, generate_configs

with open("../src/MuJoCo.json") as f:
    BASE_CONFIG = json.load(f)

from walker_atla_ppo_lstm_best import PARAMS as params

PARAMS = {
    "mode": ["adv_sa_ppo"],
    "out_dir": ["robust_atla_ppo_lstm_walker/agents"],
    "robust_ppo_eps": [0.05],
    "robust_ppo_reg": [0.3],
    "robust_ppo_eps_scheduler_opts": ["start=1,length=1831"],
    "robust_ppo_beta": [1.0],
    "robust_ppo_beta_scheduler_opts": ["same"],  # Using the same scheduler as eps scheduler
    "robust_ppo_detach_stdev": [False],
    "robust_ppo_method": ["sgld"],
    "robust_ppo_pgd_steps": [2],
    "adv_clip_eps": [0.2, 0.4],
    "adv_entropy_coeff": [3e-4],
    "adv_ppo_lr_adam": [1e-2],
    "adv_val_lr": [1e-2],
}

params.update(PARAMS)

generate_configs(BASE_CONFIG, params)
Exemple #4
0
    if not test_only:
        print('...Training...')
        train_acc_per_epoch = train(config)

    print('...Testing...')
    test_acc_per_epoch = test(config)

    _ = utils.save_results(config, train_acc_per_epoch, test_acc_per_epoch, test_only, save_test)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--dataset", type=str, default="MNIST")
    parser.add_argument("-test_only", action="store_true")
    parser.add_argument("-save_test", action="store_true")
    args = parser.parse_args()
    test_only, save_test = args.test_only, args.save_test
    run_configs = utils.load_run_config('run_config.json')
    np.random.seed(run_configs['random_seed'])  # allows reproducibility
    torch.manual_seed(run_configs['random_seed'])  # allows reproducibility
    configs = utils.generate_configs(run_configs, test_only)  # list of configurations (=dict) to be trained
    time0 = time()  # total run time
    for i, conf in enumerate(configs):
        print(f'[{i + 1}/{len(configs)}] {conf["save_dir"]}')
        try:
            main(conf)
        except Exception as e:
            raise
    print('End')