S OFT T REE M AX : P OLICY G RADIENT WITH T REE S EARCH
A BSTRACT
Policy-gradient methods are widely used for learning control policies.
They can be easily distributed to multiple workers and reach state-of-the-art results in many domains.
Unfortunately, they exhibit large variance and subsequently suffer from high-sample complexity since they aggregate gradients over entire trajectories.
At the other extreme, planning methods, like tree search, optimize the policy using single-step transitions that consider future lookahead.
These approaches have been mainly considered for value-based algorithms.
Planning-based algorithms require a forward model and are computationally intensive at each step, but are more sample efficient.
In this work, we introduce SoftTreeMax, the first approach that integrates tree-search into policy gradient.
Traditionally, gradients are computed for single state-action pairs.
Instead, our tree-based policy structure leverages all gradients at the tree leaves in each environment step.
This allows us to reduce the variance of gradients by three orders of magnitude and to benefit from better sample complexity compared with standard policy gradient.
On
Atari, SoftTreeMax demonstrates up to 5x better performance in faster run-time compared with distributed PPO.
I NTRODUCTION
Nowadays, Policy Gradient (PG; Sutton et al. 1999) methods for Reinforcement Learning (RL;
Kaelbling et al. 1996) are often the first choice for environments that allow numerous interactions at a fast pace.
Their success is attributed to several reasons: they can be easily distributed to multiple workers, require no assumptions on an underlying value function, have both on-policy and off-policy variants, and more.
Despite their popularity, PG algorithms are also notoriously unstable because they compute gradients over entire trajectories (Liu et al., 2020; Xu et al., 2020).
As a result,
PG algorithms tend to be highly inefficient in terms of sample complexity.
Several solutions were proposed to mitigate this instability.
These include baseline subtraction (Greensmith et al., 2004;
Weaver & Tao, 2001; Thomas & Brunskill, 2017; Wu et al., 2018), anchor-point averaging (Papini et al., 2018), and other variance reduction techniques (Papini et al., 2018; Zhang et al., 2021; Shen et al., 2019; Pham et al., 2020).
Another family of algorithms that achieved state-of-the-art results in several challenging domains is based on expanding possible future trajectories using tree search (TS; Coulom 2006; Silver 2009).
Prominent examples from this family include UCT (Gelly & Wang, 2006),
Dreamer (Hafner et al., 2019), and MuZero (Schrittwieser et al., 2020).
TS-based algorithms rely on a forward model (accurate or learned) and substantially reduce sample complexity by offloading the information gain from sampling to planning.
Given a forward modhe main weakness of TS-based methods is that it is difficult to parallelize the learning process because expanding the tree is computationally expensive.
However, recent works proposed to leverage recent advances in GPU-based simulation and deep model learning for expanding the tree in parallel (Dalal et al., 2021; Rosenberg et al., 2022).
In this work, we build on top of those recent advances in parallel search and combine PG with TS by introducing a parameterized policy that incorporates tree expansion.
Our SoftTreeMax policy replaces the standard policy-logits of an action with the sum of all logits at the tree leaves that originate from that action.
The inference process thus amounts to a fast and efficient breadth-first search followed by vectorized neural network inference, all in the GPU.
During training, all gradients at the tree leaves are used for updating the policy, thus significantly mitigating the high variance of PG.
Our approach addresses a major limitation of TS methods, that their computational complexity grows exponentially with the size of the tree.
We reduce the complexity by limiting the width of the tree; we do so by sampling only the most promising nodes at each level.
This allows us to efficiently search Atari environments with trees that are 8 -level deep.
The fast search mechanism is enabled thanks to a GPU simulator that allows running multiple copies of Atari in parallel Dalton et al.
We then integrate the resulting SoftTreeMax into the widely used PPO (Schulman et al., 2017) and compare it to PPO in its distributed variant.
For a fair comparison, we also run the distributed PPO baseline with the parallel GPU emulator by (Dalton et al., 2020).
In all tested
Atari games, our results outperform the baseline and obtain up to 5x more reward.
As we show in
Section 4, the associated gradient variance is three orders of magnitude lower in all games.
P RELIMINARIES
We follow the standard notation by Puterman (2014).
We consider a discounted Markov Decision
Process (MDP) M
=
( S , A , P, r, γ ) , where S is a finite state space of size S ,
A is a finite action space of size A , r : S ×
A → [0 , 1] is the reward function, P : S ×
A → ∆ S is the transition function, and γ ∈ (0 , 1) is the discount factor.
Let π : S
→ A be a stationary policy, and V π ∈ R S be the value function of π defined by
V π ( s ) =
[Equation] [Equation] [Equation] [Equation]
| [Equation]
[Equation]
Our goal is to find the optimal policy π ⋆ such that, for every s ∈ S , [Equation] When the state space is very large, or continuous, a common practice is to use function approximation to represent the value function, the policy, or even the forward-model.
Following the prominent success of deep RL Mnih et al.
(2015) in recent years, deep neural networks are used nowadays almost exclusively in practice.
Depending on the RL algorithm, a loss function is defined and gradients on the network weights can be calculated.
2. P OLICY G RADIENT
PG schemes seek to maximize the cumulative reward as a function of the parameterized policy π θ ( a | s ) by performing gradient steps on θ .
For an observed trajectory τ = ( s 0 , a 0 , r 0 , s 1 , . . .
, s T , a T , r T , s T +1 ) , let r ( τ ) be the cumulative reward of a trajectory τ , and π θ ( τ ) to be probability of observing trajectory τ under policy π θ :
[Equation]
Using the likelihood ratio trick, we have
[Equation]
Subsequently, multiple trajectories can be sampled to apply stochastic gradient descent on the policy parameters θ forming the backbone of most PG algorithms.
When the action space is discrete, a commonly used parameterized policy is the soft-max applied over learned weights corresponding to each state-action pair:
[Equation]
where the weights are the output of a neural network with A heads, where the state is the input.
Softmax policies became a canonical part of PG (Zhang et al., 2021; Mei et al., 2020b; Li et al., 2021;
Schulman et al., 2017; Haarnoja et al., 2018).
Some alternatives have been proposed to soft-max (Mei et al., 2020a; Miahi et al., 2021) with relatively rare usage in practice.
Due to its popularity, we focus on a tree extension to the soft-max policy.
However, the method proposed here is general and can be applied trivially to other discrete or continuous parameterized policies.
2. T REE S EARCH
Planning with a TS is the process of using a forward model to consider possible future trajectories and decide on the best action at the root.
One famous such algorithm is Monte-Carlo TS (MCTS;
Browne et al.
used in AlphaGo Silver et al.
and MuZero Schrittwieser et al.
Other principal algorithms such as Value Iteration, Policy Iteration and DQN were also shown to give an improved performance with a tree search extensions (Efroni et al., 2019; Dalal et al., 2021).
The applicability of these extensions largely benefits from the GPU-based simulator which allows spanning the tree efficiently at each step.
This coincides with recently released simulators such as
Atari-CuLE (Dalton et al., 2020), IsaacGym (Makoviychuk et al., 2021) and Brax Freeman et al.
(2021) that support advancing multiple environments simultaneously on the GPU.
When such a simulator is out of reach, it is also possible learn a forward model Ha & Schmidhuber (2018);
Kim et al.
; Schrittwieser et al.
S OFT T REE M AX
We define a new parametric policy, SoftTreeMax, that operates as follows:
Given a state s 0 , expand a TS up to depth d to obtain H trajectories:
[Equation]
The actions can be chosen in any manner, where in our experiments we
consider all actions exhaustively and prune under-performing branches so we can reach bigger depths.
Feed all state-action pairs at the leaves into a policy network w θ at each branch to obtain the logits { (cid:80) d − 1 t =
γ t r ht + γ d w θ
( s hd , a hd ) } Hh =1 that correspond to each action at the root a h 0 .
The probability to sample an
action a {+
+} = a is a soft-max over all trajectories starting with a h
= a .
Mathematically:
[Equation]
where β is an inverse temperature parameter controlling the exploration intensity.
Remark 1.
SoftTreeMax is a natural planning-based generalization of soft-max: For d = 0 , it reduces to the standard soft-max.
When d → ∞ , the total weight of a trajectory is its infinitehorizon cumulative discounted reward.
Remark 2.
SoftTreeMax considers the sum of all action values at the leaves, corresponding to Qfunction based algorithms.
Instead, one could use a single-headed network w θ for correspondence with value-function based algorithms.
Remark 3.
We add the discounted cumulative reward to the calculated weights.
This exploits the additional reward information obtained from expanding the tree.
The resulting sum also corresponds to the Boltzmann exploration practice Sutton et al.
(1999) where the exponent mimics the Q-function.
Remark 4.
When β → 0 and the same number of trajectories is sampled per action, the policy samples actions uniformly (exploration).
When β → ∞ , the policy greedily optimizes for the best trajectory (exploitation).
An illustration of the SoftTreeMax policy is given in Figure 1.
Like other TS methods, SoftTreeMax requires a forward model that can be used to expand the tree.
For an exhaustive search, the complexity of expanding the tree grows exponentially with the tree depth d.
However, thanks to our pruning technique, we reduce the complexity to be linear in d .
When the gradient ∇ θ log π θ is calculated at each time step, it updates w θ for all state-action pairs in the leaves, similarly to Siamese networks Bertinetto et al.
Subsequently, the network is updated even for states that were not observed and actions that were not chosen throughout the simulation trajectory.
This effect is essentially a variance reduction technique.
As we show in
Section 4, it indeed significantly reduces the noise of the PG process and leads to faster convergence and higher reward.
𝑊(𝑆 !"
#$,$ ) logits for logits for logits for 𝑎 !"
$($)
Policy network 𝑎 !"
$(() 𝑎 !" $($) 𝑎 !"
$(() 𝑎 !"
$($) 𝑎 !"
$ (() 𝑎 !")($) 𝑎 !")
(#) 𝑎 !")
(() 𝑎 !"
#(%) 𝑎 !"
#(’) 𝑎 !"
#(() 𝑆 !"
) 𝑆 !"
$($) 𝑆 !" $(#) 𝑆 !"
$(() 𝑆 !"
#($,$) 𝑆 !" #(#,$) 𝑆 !"
#($,() 𝑆 !"
#(#,() 𝑆 !"
#((,$) 𝑆 !"
#((,() 𝑊(𝑆 !"
#$,( ) 𝑊(𝑆 !" ##,$ ) 𝑊(𝑆 !"
##,( ) 𝑊(𝑆 !"
#(,$ ) 𝑊(𝑆 !"
E XPERIMENTS
We conduct our experiments on multiple games from the Atari simulation suite Bellemare et al.
As a baseline, we train a PPO (Schulman et al., 2017) agent with 256 workers in parallel.
In a hyperparameter search, we found this number of workers to be the best in terms of run-time.
The environment engine is the highly efficient Atari-CuLE Dalton et al.
a CUDA-based version of Atari that runs on GPU.
Similarly, we use Atari-CuLE for the GPU-based breadth-first TS as done in Dalal et al.
We then train SoftTreeMax for depths d = 1 . . .
8 , with a single worker.
For brevity, we exclude a few of the depths from the plots.
We use five seeds for each experiment.
For the implementation, we extend Stable-Baselines3 Raffin et al.
(2019) with all parameters taken as default from the original PPO paper Schulman et al.
We will release the code upon publication.
For depths d ≥ 3 , we limited the tree to a maximum width of 1024 nodes and pruned non-promising trajectories in terms of estimated weights.
Since the distributed PPO baseline advances significantly faster in terms of environment steps, for a fair comparison, we ran all experiments for 1 week on the same machine and use the wall-clock time as the x-axis.
We use Intel(R)
Xeon(R) CPU E5-2698 v @
2.20GHz equipped with one NVIDIA Tesla V100 32GB.
We provide the training curves in Figure 2.
As seen, there is a clear benefit for SoftTreeMax over distributed PPO with the standard soft-max policy.
In most games, PPO with the SoftTreeMax policy shows very high sample efficiency: it achieves higher episodic reward even though it observes much less episodes, for the same running time.
In Figure 3, we show the gradient variance during training, as computed for all samples in the batch during the PPO training phase.
As seen, the gradient variance of SoftTreeMax is consistently lower by three orders of magnitude than in PPO.
We also observe a correlation between the gradient variance and the TS depth – in most games, the variance monotonically reduces as the depth increases.
D ISCUSSION
Planning in RL is typically conducted with value-based algorithms due its seamless integration with the bellman operator, leaving aside the popular class of policy gradient methods.
In this work, we introduced for the first time a tree-search approach for policy gradient.
We show why our SoftTreeMax is essentially a variance reduction technique.
Mitigating the known sample-inefficiency issue, it achieves better performance than the widely used PPO with multiple workers and soft-max policy.
Our method can be further applied to continuous control tasks, or in tasks where the forward model is learned with some estimation error.
Other possible future directions are to study the theoretical implications of SoftTreeMax on the convergence rate of policy gradient, or to extend it to adaptively changing depths.