feat(*): Update bot and training

This commit is contained in:
Josh Creek
2023-09-30 10:53:03 +01:00
parent 834faef551
commit db103c128d
2 changed files with 7 additions and 2 deletions
+2 -1
View File
@@ -9,6 +9,7 @@ from agent import Agent
# from obs.default_obs import DefaultObs # from obs.default_obs import DefaultObs
from rlgym.utils.obs_builders import AdvancedObs from rlgym.utils.obs_builders import AdvancedObs
from rlgym_compat import GameState from rlgym_compat import GameState
from rlgym.utils.action_parsers import DiscreteAction
class Sarpy(BaseAgent): class Sarpy(BaseAgent):
@@ -19,7 +20,7 @@ class Sarpy(BaseAgent):
# Swap the obs builder if you are using a different one, RLGym's AdvancedObs is also available # Swap the obs builder if you are using a different one, RLGym's AdvancedObs is also available
self.obs_builder = AdvancedObs() self.obs_builder = AdvancedObs()
# Swap the action parser if you are using a different one, RLGym's Discrete and Continuous are also available # Swap the action parser if you are using a different one, RLGym's Discrete and Continuous are also available
self.act_parser = DefaultAction() self.act_parser = DiscreteAction()
# Your neural network logic goes inside the Agent class, go take a look inside src/agent.py # Your neural network logic goes inside the Agent class, go take a look inside src/agent.py
self.agent = Agent() self.agent = Agent()
# Adjust the tickskip if your agent was trained with a different value # Adjust the tickskip if your agent was trained with a different value
+5 -1
View File
@@ -54,7 +54,7 @@ if __name__ == "__main__": # Required for multiprocessing
fps = 120 / frame_skip fps = 120 / frame_skip
gamma = np.exp(np.log(0.5) / (fps * half_life_seconds)) # Quick mafs gamma = np.exp(np.log(0.5) / (fps * half_life_seconds)) # Quick mafs
agents_per_match = 2 agents_per_match = 2
num_instances = 4 num_instances = 10
target_steps = 100_000 target_steps = 100_000
steps = target_steps // (num_instances * agents_per_match) steps = target_steps // (num_instances * agents_per_match)
batch_size = steps batch_size = steps
@@ -109,6 +109,7 @@ if __name__ == "__main__": # Required for multiprocessing
env, env,
device="auto", # Need to set device again (if using a specific one) device="auto", # Need to set device again (if using a specific one)
) )
print("Loaded exit_save.zip model")
except: except:
model = PPO( model = PPO(
MlpPolicy, MlpPolicy,
@@ -124,6 +125,7 @@ if __name__ == "__main__": # Required for multiprocessing
verbose=3, # Print out all the info as we're going verbose=3, # Print out all the info as we're going
device="auto", # Uses GPU if available device="auto", # Uses GPU if available
) )
print("Created new model")
# Save model every so often # Save model every so often
# Divide by num_envs (number of agents) because callback only increments every time all agents have taken a step # Divide by num_envs (number of agents) because callback only increments every time all agents have taken a step
@@ -136,8 +138,10 @@ if __name__ == "__main__": # Required for multiprocessing
try: try:
while True: while True:
print("Learning...")
model.learn(25_000_000, callback=callback) model.learn(25_000_000, callback=callback)
model.save(f"{models_dir}/exit_save") model.save(f"{models_dir}/exit_save")
print("Saved exit_save model")
model.save(f"mmr_models/{model.num_timesteps}") model.save(f"mmr_models/{model.num_timesteps}")
except Exception as e: except Exception as e:
print(e) print(e)