backpropagation through the voidgroeder/static/camtalk.pdfbackpropagation cannot be applied • in...

34
BACKPROPAGATION THROUGH THE VOID Optimizing Control Variates for Black-Box Gradient Estimation 27 Nov 2017, University of Cambridge Speaker: Geoffrey Roeder, University of Toronto

Upload: others

Post on 31-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

BACKPROPAGATION THROUGH THE VOID

Optimizing Control Variates for Black-Box Gradient Estimation

27 Nov 2017, University of CambridgeSpeaker: Geoffrey Roeder, University of Toronto

Page 2: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

OPTIMIZING EXPECTATIONS

• Variational inference: Evidence Lower Bound

• Reinforcement learning: Expected Reward Function

• Hard attention mechanism

• How to choose the parameters to maximize this expectation?

L(✓) = Ep(b|✓)f(b)

Page 3: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

GRADIENT-BASED OPTIMIZATION

• Reverse-mode automatic differentiation (backpropagation) computes exact gradients of deterministic, differentiable objectives

• Reparameterization trick (Williams, 1992; Kingma & Welling 2014; Rezende 2014): using backprop, gives unbiased, low-variance estimates of gradients of expectations

• This has allows effective stochastic optimization of large probabilistic continuous latent-variable models

Page 4: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

GRADIENT-BASED OPTIMIZATION: LIMITATIONS

• There many relevant objective functions in ML to which backpropagation cannot be applied

• In RL, in fact, the reward function is unknown: a black box from the perspective of an agent

• Discrete latent variable models: discrete sampling creates discontinuities, giving the objective function zero gradient w.r.t. its parameters

Page 5: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

GRADIENT-BASED OPTIMIZATION: LIMITATIONS

• But, gradients are appealing: in high dimensions, provides information on how to adjust each parameter individually

• Moreover, stochastic optimization is essential for scalability

• However, are only guaranteed to converge to a fixed point of an objective if a gradient estimator is unbiased

Page 6: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

How can we build unbiased stochastic estimators of ?@

@✓L(✓)

Page 7: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

SCORE-FUNCTION ESTIMATOR (“REINFORCE”, WILLIAMS 1992)

Page 8: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

SCORE-FUNCTION ESTIMATOR (“REINFORCE”, WILLIAMS 1992)

• We can estimate this quantity with Monte Carlo integration:

• High variance: convergence to good solution challenging

@

@✓Ep(b|✓)f(b) =

Z@

@✓p(b|✓)f(b)d✓

= Ep(b|✓)

f(b)

@

@✓log p(b|✓)

Page 9: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

SCORE-FUNCTION ESTIMATOR (“REINFORCE”, WILLIAMS 1992)

• Log-derivative trick allows us to rewrite gradient of expectation as expectation of gradient (under weak regularity conditions)

• We can estimate this quantity with Monte Carlo integration:

• High variance: convergence to good solution challenging

@

@✓Ep(b|✓)f(b) =

Z@

@✓p(b|✓)f(b)d✓

= Ep(b|✓)

f(b)

@

@✓log p(b|✓)

Page 10: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

SCORE-FUNCTION ESTIMATOR (“REINFORCE”, WILLIAMS 1992)

• Log-derivative trick allows us to rewrite gradient of expectation as expectation of gradient (under weak regularity conditions)

• Yields unbiased, but high variance estimator

gSF = f(b)@

@✓log p(b|✓)

@

@✓Ep(b|✓)f(b) =

Z@

@✓p(b|✓)f(b)d✓

= Ep(b|✓)

f(b)

@

@✓log p(b|✓)

Page 11: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

REPARAMETERIZATION TRICK

• Requires function to be known and differentiable

• Requires distribution to be reparameterizable through a transformation

• Unbiased; lower variance empirically

gREP [f(b)] =@

@✓f(b) =

@f

@T@T@✓

, b = T (✓, ✏), ✏ ⇠ p(✏)

p(b|✓)T (✓, ✏)

Page 12: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

CONCRETE REPARAMETERIZATION(MADDISON ET AL. 2016)

• Works well with careful hyper parameter choices

• Lower variance than score-function estimator due to reparameterization

• Biased estimator

• Temperature parameter

• Requires to be known and differentiable

• Requires to be reparamaterizable

gCON [f(b)] =@

@✓f(b) =

@f

@��(z)

@��(z)

@✓, z = T (✓, ✏), ✏ ⇠ p(✏)

f

p(b|✓)

Page 13: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

REBAR (TUCKER ET AL. 2017)

• Improves over concrete distribution (rebar is stronger than concrete)

• Uses continuous relaxation of discrete random variables (concrete) to build unbiased, lower-variance gradient estimator

• Using the reparameterization from the Concrete distribution, construct a control variate for the score-function estimator

• Show how tune additional parameters of the estimator (e.g., temperature ) online�

Page 14: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

Digression: control variates for Monte Carlo estimators

Page 15: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

CONTROL VARIATES: DIGRESSION

• New estimator is equal in expectation to old estimator (bias is unchanged)

• Variance is reduced when |corr(c, g)| > 0

• We exploit the difference between the function c and its known mean during optimization to “correct” the value of the estimator

gnew(b) = g(b)� ⌘�c(b)� Ep(b)[c(b)]

⌘? = �Cov[g, c]

Var[g]

Page 16: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

CONTROL VARIATES:FREE-FORM

• If we choose a neural network as our parameterized differentiable function, then the above formulation can be simplified to the above

• The scaling constant will be absorbed into the weights of the network, and optimality is determined by training

• How should we update the weights of the free-form control variate?

gnew(b) = g(b)� c�(b) + Ep(b) [c�(b)]

Page 17: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

What is essential for a control variate?

Page 18: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

LEARNING FREE-FORM CONTROL VARIATE: LOSS FUNCTION

• For unbiased estimator, we can form a Monte-Carlo estimate for the variance of the estimator overall

• We use this as the training signal for the parameters of the control variate, adapting the parameters during training

@

@�Var[g] =

@

@�E[g2]� @

@�E[g]2

=@

@�E[g2] = E[2g @g

@�]

Page 19: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

GENERALIZING REBAR

• Start with score function (SF) estimator of gradient of

• Introduce a parametrized differentiable function

• Use SF estimator of as a control variate, subtracting its mean estimated through the lower-variance reparameterization estimator

• This generalizes Tucker et al. 2017 to free-form control variates: no longer require continuous relaxations

b = T (✓, ✏), ✏ ⇠ p(✏)

gLAX = gSF [f ]� gSF [c�] + gREP [c�]

= [f(b)� c�(b)]@

@✓log p(b|✓) + @

@✓c�(b),

c�

f

c�

Page 20: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

RELAX: EXTENSION TO DISCRETE RANDOM VARIABLES

• When b is discrete, we introduce a related distribution and a function H where

• We use a conditional reparameterization scheme developed by Tucker et al. 2017 for REBAR

• This estimator is unbiased for all choices of

gRELAX = [f(b)� c�(z)]@

@✓log p(b|✓) + @

@✓c�(z)�

@

@✓c�(z),

z ⇠ p(z|✓), b = H(z), z ⇠ p(z|b, ✓)

H(z) = b ⇠ p(b|✓)

c�

Page 21: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

RELAX: EXTENSION TO DISCRETE RANDOM VARIABLES

• When b is discrete, we introduce a related distribution and a function H where

• We use a conditional reparameterization scheme developed by Tucker et al. 2017 for REBAR

• This estimator is unbiased for all choices of

gRELAX = [f(b)� c�(z)]@

@✓log p(b|✓) + @

@✓c�(z)�

@

@✓c�(z),

z ⇠ p(z|✓), b = H(z), z ⇠ p(z|b, ✓)

H(z) = b ⇠ p(b|✓)

c�

Page 22: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

EXPERIMENTAL RESULTS

Page 23: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

SIMPLE EXAMPLEEp(b|✓)

⇥(t� b)2

• Validated idea with simple function above

• Used to validate REBAR estimator, fixing t=0.45

• We chose t = 0.499

b ⇠ Ber(✓)

Page 24: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

SIMPLE EXAMPLEEp(b|✓)

⇥(t� b)2

• (Right) RELAX finds a reasonable solution, REINFORCE and REBAR oscillate

• (Left) Variance is considerably reduced in our estimator

Page 25: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

A MORE INTERESTING APPLICATION

• Discrete Variational Autoencoder

• Latent state: 2 layers of 200 Bernoulli variables

• Discrete sampling renders reparameterization estimator unusable

log p(x) � L(✓) = Eq(b|x) [log p(x|b) + log p(b)� log q(b|x)]

c�(z) = f(�(z)) + r⇢(z)

Page 26: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

MNIST RESULTS

Page 27: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

OMNIGLOT RESULTS

Page 28: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

QUANTITATIVE RESULTS

MNIST Omniglot

-ELB

O

Figure 3: Training curves for the VAE Experiments with the 1 layer linear model. The horizontaldashed line indicates the lowest validation error obtained by REBAR.

in REBAR. In all experiments, the learned control variate improved the training performance, overthe state-of-the-art baseline of REBAR. In both linear models, we achieved improved validationperformance as well increased convergence speed. We believe the decrease in validation performancefor the nonlinear models was due to overfitting caused by improved optimization of an under-regularized model. We leave exploring this phenomenon to further work.

Dataset Model Concrete NVIL MuProp REBAR RELAX

Nonlinear �102.2 �101.5 -101.1 -81.01 -78.13MNIST linear 1 layer -111.3 �112.5 �111.7 -111.6 -111.20

linear 2 layer -99.62 �99.6 �99.07 -98.22 -98.00Nonlinear �110.4 �109.58 -108.72 -56.76 -56.12

Omniglot linear 1 layer -117.23 �117.44 �117.09 -116.63 -116.57linear 2 layer -109.95 �109.98 �109.55 -108.71 -108.54

Table 1: Best obtained training objective for discrete variational autoencoders.

To obtain training curves we created our own implementation of REBAR, which gave identical orslightly improved performance compared to the implementation of Tucker et al. (2017).

While we obtained a modest improvement in training and validation scores (tables 1 and 3), themost notable improvement provided by RELAX is in its rate of convergence. Training curves forall models can be seen in figure 3 and in appendix D. In table 4 we compare the number of trainingepochs that are required to match the best validation score of REBAR. In both linear models, RELAXprovides an increase in rate of convergence.

6.3 REINFORCEMENT LEARNING

We apply our gradient estimator to a few simple reinforcement learning environments with discreteand continuous actions. We use the RELAX and LAX estimators for discrete and continuous actions,respectively. We compare with the advantage actor-critic algorithm (A2C) (Sutton et al., 2000) as abaseline. Full details of our experiments can be found in Appendix E.

In the discrete action setting, we test our approach on the Cart Pole and Lunar Lander environmentsas provided by the OpenAI gym (Brockman et al., 2016). In the continuous action setting, we teston the MuJoCo-simulated (Todorov et al., 2012) environments Inverted Pendulum and InvertedDouble Pendulum also found in the OpenAI gym. In all tested environments we observe improvedperformance and sample efficiency using our method. The results of our experiments can be seen infigure 4, and table 2.

Page 29: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

OVERFITTING 1 LAYER: MNIST (LEFT), OMNIGLOT (RIGHT)

Page 30: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

REINFORCEMENT LEARNING• Policy gradient methods effective for finding policy

parameters (A2C, A3C, ACKTR)

• Goal:

• Need estimate of

• True reward function unknown (black-box, from environment)

argmax✓ E⌧⇠⇡(⌧ |✓) [R(⌧)]

@

@✓E⌧⇠⇡(⌧ |✓) [R(⌧)]

Page 31: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

ADVANTAGE ACTOR CRITIC (SUTTON, 2000)

• is an estimate of the value function

• This is exactly the REINFORCE estimator using an estimate of the value function as a control variate

• Why not use action in control variate?

• Dependence on action would add bias

gA2C =

1X

t=1

@

@✓log ⇡(at|st, ✓)

" 1X

t0=t

rt0 � c�(st)

#, at ⇠ ⇡(at|st, ✓)

c�

Page 32: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

EXTENDING LAX TO RL

• Allows for action-dependence in control variate

• Remains unbiased estimator

• Similar extension possible for discrete action spaces, see paper Appendix C.2

gRLLAX =

1X

t=1

@

@✓log ⇡(at|st; ✓)

" 1X

t0=t

rt0 � c�(at, st)

#+

@

@✓c�(at, st)

at = at(✏t, st, ✓), ✏t ⇠ p(✏t)

Page 33: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

RL BENCHMARK RESULTSCart-pole Lunar lander Inverted pendulum Inverted double pendulum

Rew

ard

Log-

Varia

nce

Figure 4: Top row: Reward curves. Bottom row: Variance of policy gradients (log scale). In eachcurve, the center line indicates the mean reward over 5 random seeds. The opaque bars in the toprow indicate the 25th and 75th percentiles. The opaque bars in the bottom row indicate 1 standarddeviation. After every 10th training episode 100 episodes were run and the sample log-variance isreported averaged over all policy parameters.

Model Cart-pole Lunar lander Inverted pendulum Inverted double pendulum

A2C 1152± 90 162374± 17241 9916± 235 78260± 1877

LAX/RELAX 472± 114 68712± 20668 6237± 45 60967± 1669

Table 2: Mean episodes to solve tasks. Definitions of solving each task can be found in appendix E.

We found that our estimator produced policy gradients with drastically reduced variance (see figure 4)allowing for larger learning rates to be used while maintaining stable training. In both discreteenvironments our estimator achieved great than a 2-times speedup in convergence over the baseline.

Code for all experiments can be found at github.com/duvenaud/relax.

7 CONCLUSIONS AND FUTURE WORK

In this work we synthesized and generalized several standard approaches for constructing gradi-ent estimators. We proposed a generic gradient estimator that can be applied to expectations ofknown or black-box functions of discrete or continuous random variables, and adds little computa-tional overhead. We also derived a simple extension to reinforcement learning in both discrete andcontinuous-action domains.

Future applications of this method could include training models with hard attention or memoryindexing (Zaremba & Sutskever, 2015). One could also apply our estimators to continuous latent-variable models whose likelihood is non-differentiable, such as a 3D rendering engine. There isalso room to explore other architecture choices for the control variate.In the reinforcement learningsetting, our method could be combined with other variance-reduction techniques such as generalizedadvantage estimation (Kimura et al., 2000), or other optimization methods, such as KFAC (Wu et al.,2017). One could also train our control variate off-policy, as in Q-prop (Gu et al., 2016).

ACKNOWLEDGEMENTS

We thank Dougal Maclaurin, Tian Qi Chen, Elliot Creager, and Bowen Xu for helpful discussions.We also thank Christopher Prohm for pointing out an error in one of our derivations.

Page 34: BACKPROPAGATION THROUGH THE VOIDgroeder/static/camtalk.pdfbackpropagation cannot be applied • In RL, in fact, the reward function is unknown: a black box from the perspective of

BERNOULLI REPARAM

APPENDICES

A THE RELAX ALGORITHM

We prove that gRELAX is unbiased. Following Tucker et al. (2017):

E [gRELAX] = (12)

Ep(b|✓)

⇥f(b)� E

p(z|b,✓)[c�(z)]⇤ @

@✓log p(b|✓)� @

@✓Ep(z|b,✓)[c�(z)]

�+

@

@✓Ep(z|✓)[c�(z)]

=

@

@✓Ep(b|✓)

⇥f(b)� E

p(z|b,✓) [c�(z)]⇤+

@

@✓Ep(z|✓)[c�(z)]

=

@

@✓Ep(b|✓)[f(b)]�

@

@✓Ep(z|✓)[c�(z)] +

@

@✓Ep(z|✓)[c�(z)] =

@

@✓Ep(b|✓)[ f(b)]

(13)

Algorithm 2 RELAX: Low-variance control variate optimization for black-box gradient estimation.Require: f(·), log p(b|✓), reparameterized samplers b = H(z), z = S(✏, ✓) and z = S(✏, ✓|b),

neural network c�

(·)while not converged do

✏i

, e✏i

⇠ p(✏) . Sample noisezi

S(✏i

, ✓) . Compute unconditional relaxed inputbi

H(zi

) . Compute inputezi

S(e✏i

, ✓|bi

) . Compute conditional relaxed inputg✓

[f(bi

)� c�

(ezi

)]r✓

log p+r✓

c�

(zi

)�r✓

c�

(ezi

) . Estimate gradientg�

2g✓

@g✓

@�

. Estimate gradient of variance of gradient✓ ✓ + ↵1g✓ . Update parameters� �+ ↵2g� . Update control variate

end whilereturn ✓

B CONDITIONAL RE-SAMPLING FOR DISCRETE RANDOM VARIABLES

When applying the RELAX estimator to a function of discrete random variables b ⇠ p(b|✓), werequire that there exists a distribution p(z|✓) and a deterministic mapping H(z) such that if z ⇠ p(z|✓)then H(z) = b ⇠ p(b|✓). Treating both b and z as random, this procedure defines a probabalisticmodel p(b, z|✓) = p(b|z)p(z|✓). The RELAX estimator requires reparameterized samples fromp(z|✓) and p(z|b, ✓). We describe how to sample from these distributions in the common cases ofp(b|✓) = Bernoulli(✓) and p(b|✓) = Categorical(✓).

Bernoulli When p(b|✓) is Bernoulli distribution we let H(z) = I(z > 0) and we sample fromp(z|✓) with

z = log

1� ✓+ log

u

1� u, u ⇠ uniform[0, 1].

We can sample from p(z|b, ✓) with

v0 =

⇢v · (1� ✓) b = 0

v · ✓ + (1� ✓) b = 1

z = log

1� ✓+ log

v0

1� v0, v ⇠ uniform[0, 1].

Categorical When p(b|✓) is a Categorical distribution where ✓i

= p(b = i|✓), we let H(z) =

argmax(z) and we sample from p(z|✓) with

z = log ✓ � log(� log u), u ⇠ uniform[0, 1]k