Contrastive Intrinsic Control for Unsupervised Reinforcement Learning
Abstract
We introduce Contrastive Intrinsic Control (CIC), an unsupervised reinforcement learning (RL) algorithm that maximizes the mutual information between statetransitions and latent skill vectors.
CIC utilizes contrastive learning between state-transitions and skills vectors to learn behaviour embeddings and maximizes the entropy of these embeddings as an intrinsic reward to encourage behavioural diversity.
We evaluate our algorithm on the Unsupervised RL Benchmark (URLB) in the asymptotic state-based setting, which consists of a long reward-free pretraining phase followed by a short adaptation phase to downstream tasks with extrinsic rewards.
We find that CIC improves over prior exploration algorithms in terms of adaptation efficiency to downstream tasks on state-based URLB.
Deep RL is a powerful approach toward solving complex control tasks in the presence of extrinsic rewards.
Successful applications include playing video games from pixels [1], mastering the game of
Go [2, 3], robotic locomotion [4, 5, 6] and dexterous manipulation [7, 8, 9] policies.
While effective, the above advances produced agents that are unable to generalize to new downstream tasks beyond the one they were trained to solve.
Humans and animals on the other hand are able to acquire skills with minimal supervision and apply them to solve a variety of downstream tasks.
In this work, we seek to train agents that acquire skills without supervision with generalization capabilities by efficiently adapting these skills to downstream tasks.
Over the last few years unsupervised RL has emerged as a promising framework for developing RL agents that can generalize to new tasks.
In the unsupervised RL setting, agents are first pre-trained with self-supervised intrinsic rewards and then finetuned to downstream tasks with extrinsic rewards.
Unsupervised RL algorithms broadly fall into three categories - knowledge-based, data-based and competence-based methods 2 .
Knowledge-based methods maximize the error or uncertainty of a predictive model [12, 13, 14].
Data-based methods maximize the entropy of the agent’s visitation [15, 16].
Competence-based methods learn skills that generate diverse behaviors [17, 18].
This work falls into the latter category of competence-based exploration methods.
Unlike knowledge-based and data-based algorithms, competence-based algorithms simultaneously address both the exploration challenge as well as distilling the generated experience in the form of reusable skills.
This makes them particularly appealing, since the resulting skill-based policies (or skills themselves) can be finetuned to efficiently solve downstream tasks.
While there are many self-supervised objectives that can be utilized, our work falls into a family of methods that learns skills by maximizing the mutual information between visited states and latent skill vectors.
Many earlier [Figure] works have investigated optimizing such objectives [17, 18, 19, 20].
However, competence-based methods have been empirically challenging to train and have under-performed when compared to knowledge and data-based methods [21].
In this work, we take a closer look at the challenges of pre-training agents with competence-based algorithms.
We introduce Contrastive Intrinsic Control (CIC) – an exploration algorithm that uses a new estimator for the mutual information objective.
CIC combines particle estimation for state entropy [22, 15] and noise contrastive estimation [23] for the conditional entropy which enables it to both generate diverse behaviors (explore) and discriminate high-dimensional continuous skills (exploit) .
To the best of our knowledge, CIC is the first exploration algorithm to utilize noise contrastive estimation to discriminate between state transitions and latent skill vectors.
Empirically, we show that CIC adapts to downstream tasks more efficiently than prior exploration approaches on the state-based Unsupervised Reinforcement Learning Benchmark (URLB).
CIC achieves 79% higher returns on downstream tasks than prior competence-based algorithms and 18% higher returns than the next-best exploration algorithm overall.
Background and Notation
Markov Decision Process: We operate under the assumption that our system is described by a
Markov Decision Process (MDP) [24].
An MDP consists of the tuple ( S , A , P , r, γ ) which has states s ∈ S , actions a ∈ A , transition dynamics p ( s ′ | s, a ) ∼ P , a reward function r , and a discount factor γ .
In an MDP, at each timestep t , an agent observes the current state s , selects an action from a policy a ∼ π ( ·| s ) , and then observes the reward r and next state s ′ once it acts in the environment.
Note that usually r refers to an extrinsic reward.
However, in this work we will first be pre-training an agent with intrinsic rewards r int and finetuning on extrinsic rewards r ext .
For convenience we also introduce the variable τ =
( s, s ′ ) which is a tuple denoting a transition between two consecutive states.
Importantly, τ does not denote a state-action trajectory.
In addition to the standard MDP notation, we will also be learning skills z ∈ Z where Z is the skill set, which can be a discrete or continuous real-valued vector space, and our policy will be skill-conditioned a ∼ π ( ·| s, z ) .
Unsupervised Skill Discovery through Mutual Information Maximization: Most competencebased approaches to exploration maximize the mutual information between states and skills.
Our work and a large body of prior research [17, 20, 18, 25, 26, 27] aims to maximize a mutual information objective with the following general form:
[Equation]
Competence-based algorithms use different choices for τ and can condition on additional information such as actions or starting states.
For a full summary of competence-based algorithms and their objectives see Table 2. [Figure]
Lower Bound Estimates of Mutual Information: The mutual information I ( s ; z ) is intractable to compute directly.
Since we wish to maximize I ( s ; z ) , we can approximate this objective by instead maximizing a lower bound estimate.
Most known mutual information maximization algorithms use the variational lower bound introduced in [28]:
[Equation]
The variational lower bound can be applied to both decompositions of the mutual information.
The design decisions of a competence-based algorithm therefore come down to (i) which decomposition of I ( τ ; z ) to use, (ii) whether to use discrete or continuous skills, (iii) how to estimate H ( z ) or H ( τ ) , and finally (iv) how to estimate H ( z | τ ) or H ( τ | z ) .
Motivation
Results from the recent Unsupervised Reinforcement Learning Benchmark (URLB) [21] show that competence-based approaches underperform relative to knowledge-based and data-based baselines on DeepMind Control (DMC).
We argue that the underlying issue with current competence-based algorithms when deployed on harder exploration environments like DMC has to do with the currently used estimators for I ( τ ; z ) rather than the objective itself.
To produce structured skills that lead to diverse behaviors, I ( τ ; z ) estimators must (i) explicitly encourage diverse behaviors and (ii) have the capacity to discriminate between high-dimensional continuous skills.
Current approaches do not satisfy both criteria.
Competence-base algorithms do not ensure diverse behaviors: Most of the best known competencebased approaches [17, 18, 25, 26], optimize the first decomposition of the mutual information
H ( z ) − H ( z | τ ) .
The issue with this decomposition is that while it ensures diversity of skill vectors it does not ensure diverse behavior from the policy, meaning max H ( z ) does not imply max H ( τ ) .
Of course, if H ( z ) − H ( z | τ ) is maximized and the skill dimension is sufficiently large, then H ( τ ) will also be maximized implicitly.
Yet in practice, to learn an accurate discriminator q ( z | τ ) , the above methods assume skill spaces that are much smaller than the state space (see Table 2), and thus behavioral diversity may not be guaranteed.
In contrast, the decomposition I ( τ ; z )
= H ( τ ) − H ( τ | z ) ensures diverse behaviors through the entropy term H ( τ ) .
Methods that utilize this decomposition include [27, 20].
Why it is important to utilize high-dimensional skills: Once a policy is capable of generating diverse behaviors, it is important that the discriminator can distill these behaviors into distinct skills.
If the set of behaviors outnumbers the set of skills, this will result in degenerate skills – when one skill maps to multiple different behaviors.
It is therefore important that the discriminator can accommodate continuous skills of sufficiently high dimension.
Empirically, the discriminators used in prior work utilize only low-dimensional continuous skill vectors.
DIAYN [17] utilized 16 dimensional skills,
DADS [20] utilizes continuous skills of dimension 2 − 5 , while APS [27], an algorithm that utilizes successor features [30, 31] for the discriminator, is only capable of learning continuous skills with [Figure] dimension 10 .
We show how small skill spaces can lead to ineffective exploration in a simple gridworld setting in Appendix G and evidence that skill dimension affects performance in Fig.
On the importance of benchmarks for evaluation: While prior competence-based approaches such as DIAYN [17] were evaluated on OpenAI Gym [32], Gym environment episodes terminate when the agent loses balance thereby leaking some aspects of extrinsic signal to the exploration agent.
On the other hand, DMC episodes have fixed length.
We show in Fig 3 that this small difference in environments results in large performance differences.
Specifically, we find that DIAYN is able to learn diverse skills in Gym but not in DMC, which is consistent with both observations from DIAYN and URLB papers.
Due to fixed episode lengths, DMC tasks are harder for reward-free exploration since agents must learn to balance without supervision.
Method 3.1 Contrastive Intrinsic Control
From Section 2 we are motivated to find a lower bound for I ( τ ; z ) with a discriminator that is capable of supporting high-dimensional continuous skills 3 .
Additionally, we wish to increase the diversity of behaviors so that the discriminator can continue learning new skills throughout training.
We choose the forward decomposition of MI I ( τ ; z ) =
H ( τ ) − H ( τ | z ) similar to [27] and estimate the lower bound with Eq.
The entropy is estimated H ( τ ) with a particle-based estimator similar to [15].
As such, the primary technical contribution of this work is a novel estimator for the discriminator.
To improve the discriminator, we propose to utilize noise contrastive estimation (NCE) [23] between state-transitions and latent skills as a lower bound for I ( τ ; z ) .
It has been shown previously that such estimators provide a valid lower bound for mutual information [33].
However, to the best of our knowledge, this is the first work to investigate contrastive representation learning for intrinsic control.
Representation Learning: Specifically, we propose to learn embeddings by parameterizing the discriminator with a contrastive density estimator.
This is a novel choice that differs from prior works which utilize a classifier [17] or non-contrastive density estimation [20].
[Equation]
where f ( τ, z ) is any real valued function.
For our practical algorithm, we parameterize this function as
[Equation] 2 ( z ) ∥ T where τ =
( s, s ′ ) is a transition tuple, g ψ k are neural encoders [Equation] and T is a temperature parameter.
This inner product is similar to the one used in
SimCLR [34] [Equation]
The representation learning loss backpropagates gradients from the NCE loss which maximizes similarity between state-transitions and corresponding skills.
[Equation]
where N − 1 is the number of negatives.
The total number of elements in the summation is N because it includes one positive, so the index j includes the positive index i similar to the objective in [33].
We provide pseudocode for the CIC representation learning loss:
[Equation]
17logits matmul(
T
/ temp #
labels arange(
.shape
# positives are diagonal 20#
PyTorch docs loss =
softmax_cross_entropy( ) 23return loss
Listing 1: Pseudocode for the CIC loss. Intrinsic reward: Although we have a representation learning objective, we still need to specify the intrinsic reward for the algorithm for which there can be multiple choices.
Prior works consider specifying an intrinsic reward that is proportional to state-transition entropy [15], the discriminator [17], a similarity score between states and skills [36], and the uncertainty of the discriminator [37]. P r o j e c t e d N o t p r o j e c t e d 0.
{+N o r m a li z e d S c o r e (a) Skill projection 8 
 32 64 128 Skill dimension 0. N o r m a li z e d s c o r e (b) Skill dimension+}
Z e r o R a n d .
C E M B e t a C E M G a u s s .
G r i d S w e e p 0.
N o r m a li z e d S c
o r e (
[Figure] [Figure]
N [Figure] [Figure] We investigate each of these choices in Section 6 and find that an intrinsic reward that maximizes state-transition entropy coupled with representation learning via the CPC loss defined in Sec.
3.1 is the simplest variant that also performs well (see Table 1), which we use for all other experiments.
For the intrinsic reward, we use a particle estimate [22, 38] as in [15] of the state-transition entropy.
Similar to [15, 16] we estimate the entropy up to a proportionality constant, because we want the agent to maximize entropy rather than estimate its exact value.
The APT particle entropy estimate is proportional to the distance between the current visited state transition and previously seen neighboring points.
[Equation]
where h i is an embedding of τ i shown in Fig.
2, h ∗ i is a kNN embedding, N k is the number of kNNs.
Explore and Exploit: With these design choices the two components of the CIC algorithm can be interpreted as exploration with intrinsic rewards and exploitation using representation learning to distill behaviors into skills.
The marginal entropy maximizes the diversity of state-transition embeddings while the contrastive discriminator log q ( τ | z ) encourages exploitation by ensuring that skills z lead to predictable states τ .
Together the two terms incentivize the discovery of diverse yet predictable behaviors from the RL agent.
While CIC shares a similar intrinsic reward structure to APT [15], we show that the new representation learning loss from the CIC estimator results in substantial performance gains in Sec 6.
Practical Implementation
Our practical implementation consists of two main components: the RL optimization algorithm and the CIC architecture.
For fairness and clarity of comparison, we use the same RL optimization algorithm for our method and all baselines in this work.
Since the baselines implemented in
URLB [21] use a DDPG 4 [29] as their backbone, we opt for the same DDPG architecture to optimize our method as well (see Appendix B).
CIC Architecture: We use a particle estimator as in [15] to estimate H ( τ ) .
To compute the variational density q ( τ | z ) , we first sample skills from uniform noise z ∼ p ( z ) where p ( z ) is the uniform distribution over the [0 , 1] interval.
We then use two MLP encoders to embed g ψ 1 ( τ ) and g ψ 2 ( z ) , and optimize the parameters ψ 1 , ψ 2 with the CPC loss similar to SimCLR [34] since f ( τ, z ) =
g ψ 1 ( τ ) T g ψ 2 ( z ) .
We fix the hyperparameters across all domains and downstream tasks.
We refer the reader to the Appendices D and E for the full algorithm and a full list of hyperparameters.
Adapting to downstream tasks: To adapt to downstream tasks we follow the same procedure for competence-based method adaptation as in URLB [21].
During the first 4k environment interactions we populate the DDPG replay buffer with samples and use the extrinsic rewards collected during this period to finetune the skill vector z .
While it’s common to finetune skills with Cross Entropy
Adaptation (CMA), given our limited budget of 4k samples (only 4 episodes) we find that a simple grid sweep of skills over the interval [0 , 1] produces the best results (see Fig. 5).
After this, we fix the skill z and finetune the DDPG actor-critic parameters against the extrinsic reward for the remaining 96k steps.
Note that competence-based methods in URLB also finetune their skills during the first 4k finetuning steps ensuring a fair comparison between the methods.
The full adaptation procedure is detailed in Appendix D.
Experimental Setup
Environments We evaluate our approach on tasks from URLB, which consists of twelve downstream tasks across three challenging continuous control domains for exploration algorithms – walker, quadruped, and Jaco arm.
Walker requires a biped constrained to a 2D vertical plane to perform locomotion tasks while balancing.
Quadruped is more challenging due to a higher-dimensional state-action space and requires a quadruped to in a 3D environment to learn locomotion skills.
Jaco arm is a 6-DOF robotic arm with a three-finger gripper to move and manipulate objects without locking.
All three environments are challenging in the absence of an extrinsic reward.
Baselines: We implemented CIC using the URLB [21] codebase 5 and compare CIC to baselines included in URLB across all three exploration categories.
Knowledge-based basedlines include
ICM [12], Disagreement [13], and RND [14].
Data-based baselines incude APT [15] and ProtoRL [16].
Competence-based baselines include DIAYN [17], SMM [26], and APS [27].
The closest baselines to CIC are APT, which is similar to CIC but without state-skill CPC representation learning (no discriminator), and APS which uses the same decomposition of mutual information as CIC and also uses a particle entropy estimate for H ( τ ) .
The main difference between APS and CIC is that
APS uses successor features while CIC uses a contrastive estimator for the discriminator.
For further details regarding baselines we refer the reader to Appendix C.
Evaluation: We follow an identical evaluation to the 2M pre-training setup in URLB.
First, we pre-train each RL agent with the intrinsic rewards for 2M steps.
Then, we finetune each agent to the downstream task with extrinsic rewards for 100k steps.
All baselines were run for 10 seeds per downstream task for each algorithm using the code and hyperparameters provided by URLB [21].
Built on top of URLB, CIC is also run for 10 seeds per task.
A total of 1080 = 9 algorithms × 12 tasks × 10 seeds experiments were run for the main results.
Importantly, all baselines and CIC use a DDPG agent as their backbone.
To ensure that our evaluation statistics are unbiased we use stratified bootstrap confidence intervals to report aggregate statistics across M runs with N seeds as described in Rliable [35] to report statistics for our main results in Fig.
Our primary success metric is the interquartile mean (IQM) and the
Optimality Gap (OG).
IQM discards the top and bottom 25 % of runs and then computes the mean.
It is less susceptible to outliers than the mean and was shown to be the most reliable statistic for reporting results for RL experiments in [35].
OG measures how far a policy is from optimal (expert) performance.
To define expert performance we use the convention in URLB, which is the score achieved by a randomly initialized DDPG after 2M steps of finetuning (20x more steps than our finetuning budget).
Results
We investigate empirical answers to the following research questions: (Q1)
How does CIC adaptation efficiency compare to prior competence-based algorithms and exploration algorithms more broadly? (Q2)
Which intrinsic reward instantiation of CIC performs best?
(Q3)
How do the two terms in the
CIC objective affect algorithm performance?
(Q4)
How does skill selection affect the quality of the pre-trained policy?
(Q5)
Which architecture details matter most?
Adaptation efficiency of CIC and exploration baslines: Expert normalized scores of CIC and exploration algorithms from URLB are shown in Fig.
We find that CIC substantially outperforms prior competence-based algorithms (DIAYN, SMM, APS) achieving a 79% higher IQM than the next best competence-based method (APS) and, more broadly, achieving a 18% higher IQM than the next best overall baseline (ProtoRL).
In further ablations, we find that the contributing factors to CIC’s performance are its ability to accommodate substantially larger continuous skill spaces than prior competence-based methods.
Intrinsic reward specification: The intrinsic reward for competence-based algorithms can be instantiated in many different ways.
Here, we analyze intrinsic reward for CIC with the form r int = H ( τ ) + D ( τ, z ) , where D is some function of ( τ, z ) .
Prior works, select D to be (i) the discriminator [27], (ii) a cosine similarity between embeddings [36], (iii) uncertainty of the discriminator [37], and (iv) just the entropy D ( τ, z ) =
We run CIC with each of these variants on the walker and quadruped tasks and measure the final mean performance across the downstream tasks (see Tab. 1).
The results show that the entropy-only intrinsic reward performs best followed by an uncertainty-based intrinsic reward.
We hypothesize that the reason why a simple entropy-only intrinsic reward works well is that state-skill CPC representation learning clusters similar behaviors together.
Since similar behaviors are clustered, maximizing the entropy of state-transition embeddings produces increasingly diverse behaviors.
[Table]
The importance of representation learning: To what extent does representation learning with the state-skill CIC loss affect the agent’s exploration capability?
To answer this question we train the CIC agent with the entropy intrinsic reward with and without the representation learning auxiliary loss for 2M steps.
The zero-shot reward plotted in Fig.
6 indicates that without representation learning the policy collapses.
With representation learning, the agent is able to discover diverse skills evidenced by the non-zero reward.
This result suggests that state-skill CPC representation learning is a critical part of CIC.
Qualitative analysis of CIC behaviors: Qualitatively, we find that CIC is able to learn locomotion behaviors in DMC without extrinsic information such as early termination as in OpenAI Gym.
While most skills are higher entropy and thus more chaotic, we show in Fig 1 that structured behaviors can be isolated by fixing a particular skill vector.
For example, in the walker and quadruped domainsbalancing, walking, and flipping skills can be isolated.
For more qualitative investigations we refer the reader to Appendix H.
Skill architecture and adaptation ablations: We find that projecting the skill to a latent space before inputting it as the key for the contrastive loss is an important design decision (see Fig.
5a), most likely because this reduces the diversity of the skill vector making the discriminator task simpler.
We also find empirically that the skill dimension is an important hyperparameter and that larger skills results in better zero-shot performance (see Fig. 5b), which empirically supports the hypothesis posed in Section 2 and Appendix G that larger skill spaces are important for internalizing diverse behaviors.
Interestingly, CIC zero-shot performance is poor in lower skill dimensions (e.g. dim ( z ) < 10 ), [Figure] suggesting that when dim ( z ) is small CIC performs no better than prior competence-based methods such as DIAYN, and that scaling to larger skills enables CIC to pre-train effectively.
To measure the effect of skill finetuning described in Section 4, we sweep mean skill values along the interval of the uniform prior [0 , 1] with a budget of 4k total environment interactions and read out the performance on the downstream task.
By sweeping, we mean simply iterating over the interval [0 , 1] with fixed step size (e.g. v = 0 , 0 . 1 , . . .
and setting z i = v for all i .
This is not an optimal skill sampling strategy but works well due to the extremely limited number of samples for skill selection.
We evaluate this ablation on the Quadruped Stand and Run downstream tasks.
The results shown in Fig.
5 indicate that skill selection can substantially affect zero-shot downstream task performance.
Related Work
The most closely related prior algorithms to CIC are APT [15] and APS [27].
Both CIC and
APS use the H ( τ ) − H ( τ | z ) decomposition of the mutual information and both used a particle estimator [22] to compute the state entropy as in [15].
The main difference between CIC and APS is the discriminator.
APS uses successor features as in [31] for its discriminator while CIC uses a noise contrastive estimator.
Unlike successor features, which empirically only accommodate low-dimensional continuous skill spaces (see Table 2), the noise contrastive discriminator is able to leverage higher continuous dimensional skill vectors.
Like APT, CIC has an intrinsic reward that maximizes H ( τ ) .
However, CIC also does contrastive skill learning to shape the embedding space and outputs a skill-conditioned policy.
The CIC discriminator is similar to the one used in DISCERN [36], a goal-conditioned unsupervised
RL algorithm.
Both methods use a contrastive discriminator by sampling negatives and computing an inner product between queries and keys.
The main differences are (i) that DISCERN maximizes
I ( τ ; g ) where g are image goal embeddings while CIC maximizes I ( τ ; z ) where z are abstract skill vectors; (ii) DISCERN uses the DIAYN-style decomposition I ( τ ; g )
=
H ( g ) − H ( g | τ ) while
CIC decomposes through H ( τ ) − H ( τ | z ) , and (iii) DISCERN discards the H ( g ) term by sampling goals uniformly while CIC explicitly maximizes H ( τ ) .
While DISCERN and CIC share similarities,
DISCERN operates over image goals while CIC operates over abstract skill vectors so the two methods are not directly comparable.
Finally, another similar algorithm to CIC is DADS [20] which also decomposes through H ( τ ) −
H ( τ | z ) .
While CIC uses a contrastive density estimate for the discriminator, DADS uses a maximum likelihood estimator similar to DIAYN.
DADS maximizes I ( s ′ | s, z ) and estimates entropy H ( s ′ | s ) by marginalizing over z such that H ( s [-
-]′ | s )
= − log (cid:80)
i q ( s ′ | s, z i ) while CIC uses a particle estimator.
[Table]
Limitations and Impact
While CIC achieves leading results on state-based URLB, we would also like to address its limitations.
First, in this paper we only consider MDPs (and not partially observed MDPs) where the full state is observable.
We focus on MDPs because generating diverse behaviors in environments with large state spaces has been the primary bottleneck for competence-based exploration.
Combining CIC with visual representation learning to scale this method to pixel-based inputs is a promising future direction for research not considered in this work.
One issue with unsupervised RL algorithms (and hence CIC) in terms of potentially negative societal impact is that self-supervised exploration can be dangerous.
Since self-supervised agents maximize intrinsic rewards, this can lead to destructive behavior.
For example, when deploying CIC on a Walker or Quadruped robot it learns chaotic exploration behaviors 6 that would most likely break the robot in real-world settings.
Alignment of exploration agents to prevent them from learning dangerous policies is a promising direction for future work.
Conclusion
We have introduced a new competence-based algorithm – Contrastive Intrinsic Control (CIC) – which enables more effective exploration than prior unsupervised skill discovery algorithms by explicitly encouraging diverse behavior while distilling predictable behaviors into skills with a contrastive discriminator.
We showed that CIC is the first competence-based approach to achieve leading performance on URLB.
We hope that this encourages further research in developing RL agents capable of generalization A Competence-based Exploration Algorithms
The competence-based algorithms considered in this work aim to maximize I ( τ ; s ) .
The algorithms differ by ho they decompose mutual information, whether they explicitly maximize behavioral entropy, their skill space (discrete or continuous) and their intrinsic reward structure.
We provide a list of common competence-based algorithms in Table 2.
B Deep Deterministic Policy Gradient (DDPG)
A DDPG is an actor-critic RL algorithm that performs off-policy gradient updates and learns a Q function Q ϕ ( s, a ) and an actor π θ ( a | s ) .
The critic is trained by satisfying the Bellman equation.
[Equation]
Here, ¯ ϕ is the Polyak average of the parameters ϕ .
As the critic minimizes the Bellman error, the actor maximizes the action-value function.
[Equation]
C Baselines
For baselines, we choose the existing set of benchmarked unsupervised RL algorithms on URLB.
We provide a quick summary of each method.
For more detailed descriptions of each baseline we refer the reader to URLB [21]
Competence-based Baselines: CIC is a competence-based exploration algorithm.
For baselines, we compare it to DIAYN [17], SMM [26], and APS [27].
Each of these algorithms is described in
Table 2.
Notably, APS is a recent state-of-the-art competence-based method that is the most closely related algorithm to the CIC algorithm.
Knowledge-based Baselines
: For knowledge-based baselines, we compare to ICM [12], Disagreement [13], and RND [14].
ICM and RND train a dynamics model and random network prediction model and define the intrinsic reward to be proportional to the prediction error.
Disagreement trains an ensemble of dynamics models and defines the intrinsic reward to be proportional to the uncertainty of an ensemble.
Data-based Baselines: For data-based baselines we compare to APT [15] and ProtoRL [16].
Both methods use a particle estimator to estimate the state visitation entropy.
ProtoRL also performs discrete contrastive clustering as in [43] as an auxiliary task and uses the resulting clusters to compute the particle entropy.
While ProtoRL is more effective than APT when learning from pixels, on statebased URLB APT is competitive with ProtoRL.
Our method CIC is effectively a skill-conditioned
APT agent with a contrastive discriminator.
D Full CIC Algorithm
The full CIC algorithm with both pre-training and fine-tuning phases is shown in Algorithm 1.
We pre-train CIC for 2M steps, and finetune it on each task for 100k steps.
do
Sample
Encode
Observe
Add
D ← D
Sample a minibatch
, compute CIC
7: end for 8: for T do tuning 9:
Initialize
D . 10: do 11:
Take random action
Select
Sample minibatch from D
Q
14: end for 15:
Fix grid
16: for
N do 17:
Encode s t , z )
+ ϵ where ϵ ∼ N (0 , σ 2 ) 18:
Observe next state and reward s t +1 , r ext t ∼ P ( ·| s t , a t ) 19:
Add transition to replay buffer D
D
( s t a t , ext t , s t +1 ) 20:
Sample minibatch from D actor and critic Q
21: end for 22:
Evaluate performance
T k 23: end for
E Hyper-parameters
Baseline hyperparameters are taken from URLB [21], which were selected by performing a grid sweep over tasks and picking the best performing set of hyperparameters.
Except for the skill dimension, hyperparameters for CIC are borrowed from URLB.
[Table]
[Table]
CIC improves
F Raw Numerical Results
We provide a list of raw numerical results for finetuning CIC and baselines in Tables 5 and 6.
All baselines were run using the code by URLB [21] for 10 seeds per downstream task
[Table]
the code provided by URLB [21].
A total of 1080 = 9 algorithms × 12 tasks × 10 seeds experiments were run.
We illustrate the need for larger skill spaces with a gridworld example.
Suppose we have an agent in a 10 × 10 sized gridworld and that we have four discrete skills at our disposal.
Now let τ = s and consider how we may achieve maximal I ( τ ; z ) in this setting.
If we decompose
I ( τ ; z ) =
H ( z ) − H
( z | τ ) then we can achieve maximal H ( z ) by sampling the four skills uniformly z ∼ p ( z ) .
We can achieve H ( z | τ ) = 0 by mapping each skill to a distinct neighboring state of the agent.
Thus, our mutual information is maximized but as a result the agent only explores four out of the hundrend available states in the gridworld.
Now suppose we consider the second decomposition
I ( τ ; z ) =
H ( τ ) − H ( τ | z ) .
Since the agent is maximizing H ( τ ) it is likely to visit a diverse set of states at first.
However, as soon as it learns an accurate discriminator we will have H ( τ | z ) and again the skills can be mapped to neighboring states to achieve minimal conditional entropy.
As a result, the skill conditioned policy will only be able to reach four out of the hundrend possible states in this gridworld.
This argument is shown visually in
Fig.
Skill spaces that are too large can also be an issue.
Consider if we had 100 skills at our disposal in the same gridworld.
Then the agent could minimize the conditional entropy by mapping each skill to a unique state which would result in the agent memorizing the environment by finding a one-toone mapping between states and skills.
While this is a potential issue it has not been encountered in practice yet since current competence-based methods support small skill spaces relative to the observation space of the environment.
H Qualitative Analysis of Skills
We provide two additional qualitative analyses of behaviors learned with the CIC algorithm.
First, we take a simple pointmass setting and set the skill dimension to 1 in order to ablate the skills learned by the CIC agent in a simple setting.
We sweep over different values of z and plot the behavioral flow vector field (direction in which point mass moves) in Fig.8.
We find that the pointmass learns skills that produce continuous motion and that the direction of the motion changes as a function of the skill value.
Near the origin the pointmass learns skills that span all directions, while near the edges the point mass learns to avoid wall collisions.
Qualitatively, many behaviors are periodic.
Qualitatively, we find that methods like DIAYN that only support low dimensional skill vectors and do not explicitly incentivize diverse behaviors in their objective produce policies that map skills to a small set of static behaviors.
These behaviors shown in Fig.
9 are non-trivial but also have low behavioral diversity and are not particularly useful for solving the downstream task.
This observation is consistent with [44] where the authors found that DIAYN maps to static “yoga" poses in DeepMind Control.
In contrast, behaviors produce by CIC are dynamic resulting flipping, jumping, and locomotive behaviors that can then be adapted to efficiently solve downstream tasks.
I OpenAI Gym vs. DeepMind control: How Early Termination Leaks Extrinsic Signal
Prior work on unsupervised skill discovery for continuous control [17, 20] was evaluated on OpenAI
Gym [32] and showed diverse exploration on Gym environments.
However, Gym environment episodes terminate early when the agent loses balance, thereby leaking information about the extrinsic task (e g. balancing or moving).
However, DeepMind Control (DMC) episodes have a fixed length of 1k steps.
In DMC, exploration is therefore harder since the agent needs to learn to balance without any extrinsic signal.
To evaluate whether the difference in the two environments has impact on competence-based exploration we run DIAYN on the hopper environments from both Gym and DMC.
We compare to ICM, a popular exploration baseline and a Fixed baseline where the agent receives an intrinsic reward of 1 for each timestep and no algorithms receive extrinsic rewards.
We then measure the extrinsic reward, which loosely corresponds to the diversity of behaviors learned.
Our results in Fig.
3 show that indeed DIAYN is able to learn diverse behaviors in Gym but not in DMC while ICM is able to learn diverse behaviors in both environments.
Interestingly, the Fixed baseline achieves the highest reward on the Gym environment by learning to stand and balance.
These results further motivate us to evaluate on URLB which is built on top of DMC.
J CIC vs Other Types of Contrastive Learning for RL
Contrastive learning in CIC is different than prior vision-based contrastive learning in RL such as
CURL [45], since we are not performing contrastive learning over augmented images but rather over state transitions and skills.
The contrastive objective in CIC is used for unsupervised learning of behaviors while in CURL it is used for unsupervised learning of visual features.
We provide pseudocode for the CIC loss below: 1 def discriminator_loss(states , next_states , skills , temp): """ - states and skills are sampled from replay buffer - skills were sampled from uniform dist [0,1] during agent rollout - states / next_states: dim (B, D_state) - skills: dim (B, D_skill) """ 8transitions = concat(states , next_states , dim=1)
10query =
skill_net(skills)
# (B, D_hidden) -> (B, D_hidden) key = transition_net(transitions)
# (B, 2*D_state) -> (B, D_hidden ) 13query
= normalize(query , dim=1) key = normalize(key , dim=1)
16logits =
matmul(query , key.
T) / temp # (B, B) labels =
{+arange(logits.shape [0]) 
+}
# positives are on diagonal , negatives are off diagonal # for each skill , negatives are sampled from transitions # while skills are fixed loss = cross_entropy(logits , labels) 24return loss
Listing 2: CIC discriminator loss
This is substantially different from prior contrastive learning works in RL such as CURL [45], which perform contrastive learning over images.
def curl
loss
obs
W
temp
return loss
Listing 3: CURL contrastive loss
K On estimates of Mutual Information
In this work we have presented CIC - a new competence-based algorithm that achieves leading performance on URLB compared to prior unsupervised RL methods.
One might wonder whether estimating the exact mutual information (MI) or maximizing the tightest lower bound thereof is really the goal for unsupervised RL.
In unsupervised representation learning, state-of-the-art methods like CPC and SimCLR maximize the lower bound of MI based on Noise
Contrastive Estimation (NCE).
However, as proven in CPC [33] and illustrated in [46] NCE is upper bounded by log N , meaning that the bound is loose when the MI is larger than log N .
Nevertheless, these methods have been repeatedly shown to excel in practice.
In [47] the authors show that the effectiveness of NCE results from the inductive bias in both the choice of feature extractor architectures and the parameterization of the employed MI estimators.
We have a similar belief for unsupervised RL - that with the right parameterization and inductive bias, the MI objective will facilitate behavior learning in unsupervised RL.
This is why CIC lower bounds
MI with (i) the particle based entropy estimator to ensure explicit exploration and (ii) a contrastive conditional entropy estimator to leverage the power of contrastive learning to discriminate skills.
As demonstrated in our experiments, CIC outperforms prior methods, showing the effectiveness of optimizing an intrinsic reward with the CIC MI estimator.
L Compute Resources
CIC runs on a single GPU.
In our experiments we used 4 NVIDIA TITAN RTX GPUs.
Pre-training one seed of CIC for 2M steps takes 12-24 hours while fine-tuning to downstream tasks for 100k steps takes 30min - 1 hour.