Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

main.py 1.9 KB

You have to be logged in to leave a comment. Sign In
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
  1. import gym
  2. import torch.optim as optim
  3. from dqn_model import DQN
  4. from dqn_learn import OptimizerSpec, dqn_learing
  5. from utils.gym import get_env, get_wrapper_by_name
  6. from utils.schedule import LinearSchedule
  7. from utils.saved_state import try_to_find_saved_state
  8. BATCH_SIZE = 32
  9. GAMMA = 0.99
  10. SCHEDULER_GAMMA = 0.999986
  11. REPLAY_BUFFER_SIZE = 1000000
  12. LEARNING_STARTS = 50000
  13. LEARNING_FREQ = 4
  14. FRAME_HISTORY_LEN = 4
  15. TARGER_UPDATE_FREQ = 10000
  16. LEARNING_RATE = 0.00075
  17. ALPHA = 0.95
  18. EPS = 0.01
  19. def main(env, num_timesteps):
  20. def stopping_criterion(env):
  21. # notice that here t is the number of steps of the wrapped env,
  22. # which is different from the number of steps in the underlying env
  23. return get_wrapper_by_name(env, "Monitor").get_total_steps() >= num_timesteps
  24. optimizer_spec = OptimizerSpec(
  25. constructor=optim.RMSprop,
  26. kwargs=dict(lr=LEARNING_RATE, alpha=ALPHA, eps=EPS),
  27. )
  28. exploration_schedule = LinearSchedule(1000000, 0.1)
  29. dqn_learing(
  30. env=env,
  31. q_func=DQN,
  32. optimizer_spec=optimizer_spec,
  33. exploration=exploration_schedule,
  34. stopping_criterion=stopping_criterion,
  35. replay_buffer_size=REPLAY_BUFFER_SIZE,
  36. batch_size=BATCH_SIZE,
  37. gamma=GAMMA,
  38. learning_starts=LEARNING_STARTS,
  39. learning_freq=LEARNING_FREQ,
  40. frame_history_len=FRAME_HISTORY_LEN,
  41. target_update_freq=TARGER_UPDATE_FREQ,
  42. save_path=try_to_find_saved_state(),
  43. gamma_scheduler = SCHEDULER_GAMMA
  44. )
  45. if __name__ == '__main__':
  46. # Get Atari games.
  47. benchmark = gym.benchmark_spec('Atari40M')
  48. # Change the index to select a different game.
  49. task = benchmark.tasks[3]
  50. # Run training
  51. seed = 0 # Use a seed of zero (you may want to randomize the seed!)
  52. env = get_env(task, seed)
  53. print(task)
  54. print(task.max_timesteps)
  55. main(env, task.max_timesteps)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...