🧬Net
Overview
Net classes implement neural network architectures used as function approximators in RL algorithms. SLM Lab provides flexible, swappable networks that work with any algorithm.
Code: slm_lab/agent/net
Network Types
HydraMLPNet
Multiple vectors
Multi-head architectures
Multi-task learning
DuelingMLPNet
Vectors
Q-learning
LunarLander (value decomposition)
DuelingConvNet
Images
Q-learning
Atari (value decomposition)
TorchArc Architecture (v5.1+)
TorchArcNet builds networks from declarative YAML specs via torcharc. Instead of implicit hid_layers: [256, 256], you define exact PyTorch modules and dataflow:
net:
type: TorchArcNet
arc:
modules:
body:
Sequential:
- LazyLinear: {out_features: 256}
- ReLU:
- LazyLinear: {out_features: 256}
- ReLU:
graph:
input: x
modules:
body: [x]
output: bodyYAML anchors (& / *) eliminate copy-paste across environments—each spec shows only its overrides. All benchmark_arc/ specs use TorchArc. See the TorchArc page for the full guide.
Quick Selection Guide
For Q-learning algorithms (DQN family), consider Dueling variants for better value estimation.
Network Spec
Configure networks in the agent spec. TorchArcNet (recommended) uses YAML architecture definitions:
Common Parameters
Architecture
type
Network class
"TorchArcNet", "MLPNet", "ConvNet", "RecurrentNet"
hid_layers
Hidden layer sizes
[64, 64] (simple), [256, 256] (complex)
hid_layers_activation
Activation function
"relu", "tanh", "leaky_relu"
out_layer_activation
Output activation
null (none), "tanh"
init_fn
Weight initialization
"orthogonal_", "xavier_uniform_"
Actor-Critic Networks
shared
Share weights between actor/critic
true (Atari), false (MuJoCo)
use_same_optim
Use same optimizer for both
true, false
actor_optim_spec
Actor optimizer
{"name": "Adam", "lr": 3e-4}
critic_optim_spec
Critic optimizer
{"name": "Adam", "lr": 3e-4}
Training
clip_grad_val
Gradient clipping norm
0.5-10.0
loss_spec
Loss function
{"name": "MSELoss"}, {"name": "SmoothL1Loss"}
lr_scheduler_spec
Learning rate schedule
See below
ConvNet Parameters
normalize
Normalize pixel input by dividing by 255
false
batch_norm
Apply batch normalization after conv layers
true (ConvNet), false (DuelingConvNet)
Device
gpu
GPU usage
"auto" (detect), true (force), false (CPU only)
Learning Rate Schedules
Decay learning rate during training:
Available schedules:
"LinearToZero"- Linear decay from initial LR to 0"StepLR"- Step decay at fixed intervals"ExponentialLR"- Exponential decay
Example Specs
MLP for CartPole/MuJoCo
ConvNet for Atari (Nature CNN)
RecurrentNet for POMDPs
DQN Target Network
For DQN algorithms, a separate target network is created automatically:
Network Architecture Tips
CartPole / Simple Control
Small networks work well
tanhactivation is common for bounded outputs
MuJoCo / Continuous Control
Larger networks for complex dynamics
Orthogonal initialization helps with gradients
Atari / Image-Based
Nature CNN architecture is standard
shared: truefor actor-critic
Box2D (LunarLander, BipedalWalker)
Medium-sized networks
reluworks well
GPU Usage
SLM Lab handles GPU placement automatically:
For multi-GPU setups, see GPU Usage: PPO on Pong.
Last updated
Was this helpful?