Successfully added DQN (Deep Q-Network) support alongside existing PPO implementation in the ray_utilities framework.
-
Added
--algorithmCLI argument to_DefaultSetupArgumentParser:- Choices:
'ppo'(default) |'dqn' - Type:
AlwaysRestore(persists in checkpoints) - Short form:
-algo
- Choices:
-
Refactored parser classes (Latest Change):
- Created
_BaseRLlibArgumentParser: Common parameters for all RLlib algorithms (train_batch_size_per_learner,lr) - Created
PPOArgumentParser: PPO-specific parameters (minibatch_size,num_epochs) with validation logic - Created
DQNArgumentParser: DQN-specific parameters (target_network_update_freq,tau,epsilon,double_q,dueling) - Refactored
RLlibArgumentParser: Now inherits from bothPPOArgumentParserandDQNArgumentParserusing multiple inheritance- Eliminates code duplication
- Automatically includes all parameters from both algorithm parsers
- Maintains backward compatibility
- Created
-
Algorithm-specific validations:
- PPO: minibatch_size warnings and adjustments
- DQN: No specific validations currently (replay buffer handled by RLlib)
-
Added imports for DQN classes
-
Created
_get_algorithm_classes()classmethod:- Returns
(DQNConfig, DQN)whenargs.algorithm == "dqn" - Returns
(PPOConfig, PPO)otherwise
- Returns
-
Updated
_config_from_args():- Dynamically selects config class based on algorithm
- Only applies gradient accumulation learner for PPO
-
Created
DQNSetupclass:- Similar structure to
PPOSetup - Type-safe with
DQNConfigandDQNclasses - Full docstring with examples
- Similar structure to
- Added algorithm detection in training configuration
- Conditional training params:
- PPO:
minibatch_size,num_epochs,use_critic,clip_param,entropy_coeff,use_gae - DQN:
target_network_update_freq,num_steps_sampled_before_learning_starts,tau,epsilon,double_q,dueling
- PPO:
- Both algorithms share:
gamma,lr,train_batch_size_per_learner,grad_clip
_EnvRunnerParser
└── _BaseRLlibArgumentParser (common: train_batch_size_per_learner, lr)
├── PPOArgumentParser (adds: minibatch_size, num_epochs)
├── DQNArgumentParser (adds: target_network_update_freq, tau, epsilon, etc.)
└── RLlibArgumentParser (multiple inheritance from PPO + DQN)
Key Design:
RLlibArgumentParseruses multiple inheritance from bothPPOArgumentParserandDQNArgumentParser- This eliminates code duplication - all parameter definitions and CLI argument setup are inherited
- Only the conditional validation logic in
process_args()is implemented - Backward compatible - existing code using
RLlibArgumentParsercontinues to work unchanged - New specialized parsers (
PPOArgumentParser,DQNArgumentParser) available for algorithm-specific code
python experiments/default_training.py --env CartPole-v1
# or explicitly:
python experiments/default_training.py --env CartPole-v1 --algorithm ppopython experiments/default_training.py --env CartPole-v1 --algorithm dqnpython experiments/default_training.py \
--algorithm dqn \
--env CartPole-v1 \
--target_network_update_freq 1000 \
--num_steps_sampled_before_learning_starts 5000 \
--tau 0.001 \
--epsilon "[(0, 1.0), (50000, 0.01)]" \
--double_q \
--dueling# PPO Setup
from ray_utilities.setup import PPOSetup
setup = PPOSetup()
# DQN Setup
from ray_utilities.setup import DQNSetup
setup = DQNSetup()
# Dynamic Setup (detects from args)
from ray_utilities.setup import AlgorithmSetup
setup = AlgorithmSetup() # Uses args.algorithm to choose- Testing: Create comprehensive tests for DQN setup and training
- Dynamic batch/buffer sizing: Verify compatibility with off-policy DQN
- Callbacks: Ensure all callbacks work with both algorithms
- Gradient accumulation for DQN: Implement if needed
- Type hints: Update
algorithm_return.pyandmetrics.pyfor DQN-specific metrics (replay buffer stats) - Documentation: Update user guides and examples
- Additional algorithms: Consider SAC, TD3, or other algorithms following this pattern
- Warnings: Make batch size warnings conditional on algorithm
-
Single parser with both parameter sets: Rather than creating separate parsers, we include all parameters in
RLlibArgumentParserand only use relevant ones per algorithm. -
Dynamic algorithm selection: Config and algorithm classes are determined at runtime based on
args.algorithm, not at import time. -
Backward compatibility: Default behavior (PPO) unchanged, DQN opt-in via
--algorithm dqn. -
Checkpoint compatibility: Algorithm choice is
AlwaysRestore, ensuring restored experiments use the same algorithm.
| Feature | PPO | DQN |
|---|---|---|
| Type | On-policy | Off-policy |
| Experience | Immediate sampling | Replay buffer |
| Update frequency | After each batch | Configurable |
| Key params | minibatch_size, num_epochs | epsilon, replay_buffer_config |
| Target network | No | Yes (soft update via tau) |
| Exploration | Policy entropy | Epsilon-greedy |