(model)
| 100 | |
| 101 | |
| 102 | def get_config(model): |
| 103 | global args |
| 104 | expreplay = ExpReplay( |
| 105 | predictor_io_names=(['state'], ['Qvalue']), |
| 106 | get_player=lambda: get_player(train=True), |
| 107 | num_parallel_players=NUM_PARALLEL_PLAYERS, |
| 108 | state_shape=model.state_shape, |
| 109 | batch_size=BATCH_SIZE, |
| 110 | memory_size=MEMORY_SIZE, |
| 111 | init_memory_size=INIT_MEMORY_SIZE, |
| 112 | update_frequency=UPDATE_FREQ, |
| 113 | history_len=FRAME_HISTORY, |
| 114 | state_dtype=model.state_dtype.as_numpy_dtype |
| 115 | ) |
| 116 | |
| 117 | # Set to other values if you need a different initial exploration |
| 118 | # (e.g., # if you're resuming a training half-way) |
| 119 | # expreplay.exploration = 1.0 |
| 120 | |
| 121 | return TrainConfig( |
| 122 | data=QueueInput(expreplay), |
| 123 | model=model, |
| 124 | callbacks=[ |
| 125 | ModelSaver(), |
| 126 | PeriodicTrigger( |
| 127 | RunOp(DQNModel.update_target_param, verbose=True), |
| 128 | every_k_steps=5000), # update target network every 5k steps |
| 129 | expreplay, |
| 130 | ScheduledHyperParamSetter('learning_rate', |
| 131 | [(0, 1e-3), (60, 5e-4), (400, 1e-4)]), |
| 132 | ScheduledHyperParamSetter( |
| 133 | ObjAttrParam(expreplay, 'exploration'), |
| 134 | [(0, 1), (10, 0.1), (400, 0.01)], # 1->0.1 in the first million steps |
| 135 | interp='linear'), |
| 136 | PeriodicTrigger(Evaluator( |
| 137 | args.num_eval, ['state'], ['Qvalue'], get_player), |
| 138 | every_k_epochs=5 if 'pong' in args.env.lower() else 10), # eval more frequently for easy games |
| 139 | ], |
| 140 | steps_per_epoch=STEPS_PER_EPOCH, |
| 141 | max_epoch=500, # a total of 50M state transition |
| 142 | ) |
| 143 | |
| 144 | |
| 145 | if __name__ == '__main__': |
no test coverage detected