POPGym provides 13 different memory models designed to work with RLlib. You can use these models by specifying them in the custom_model field of your RLlib configuration. You can inspect available hyperparameters using MODEL_CONFIG and BASE_CONFIG on the model class.
When configuring a model like GRU, you can override several architectural components in custom_model_config, including:
preprocessor: An MLP feeding the memory model.preprocessor_input_size and preprocessor_output_size: Dimensions for the preprocessor.hidden_size: The size of the recurrent state.postprocessor: An MLP following the memory model.postprocessor_output_size: Output dimension of the postprocessor.actor and critic: The actor and critic network branches.- GRU-specific parameters like
num_recurrent_layers.
Note that when using temporal backpropagation, parameters like max_seq_len, sgd_minibatch_size, train_batch_size, rollout_fragment_length, and horizon should be scaled relative to your Backpropagation Through Time (BPTT) size.
import popgym
import ray
from torch import nn
from popgym.baselines.ray_models.ray_gru import GRU
# Inspect hyperparameters
print(GRU.MODEL_CONFIG)
print(GRU.BASE_CONFIG)
bptt_size = 1024
config = {
"model": {
"max_seq_len": bptt_size,
"custom_model": GRU,
"custom_model_config": {
"preprocessor_input_size": 128,
"preprocessor_output_size": 64,
"preprocessor": nn.Sequential(nn.Linear(128, 64), nn.ReLU()),
"hidden_size": 128,
"postprocessor": nn.Sequential(nn.Linear(128, 64), nn.ReLU()),
"postprocessor_output_size": 64,
"actor": nn.Linear(64, 64),
"critic": nn.Linear(64, 64),
"num_recurrent_layers": 1,
},
},
"sgd_minibatch_size": bptt_size * 4,
"train_batch_size": bptt_size * 8,
"env": "popgym-ConcentrationEasy-v0",
"rollout_fragment_length": bptt_size,
"framework": "torch",
"horizon": bptt_size,
"batch_mode": "complete_episodes",
}
ray.tune.run("PPO", config=config, stop={"timesteps_total": 50_000})