techlist.io

Openai Baselines

4 posts

OpenAI2017-08-173 min readCurated summary

OpenAI Baselines: ACKTR & A2C

# OpenAI Baselines: ACKTR and A2C OpenAI released two new reinforcement learning implementations in its Baselines library: ACKTR and A2C. A2C is a synchronous, deterministic version of Asynchronous Advantage Actor Critic (A3C) that matches A3C's performance, while ACKTR is more sample-efficient than both TRPO and A2C at only a slightly higher computational cost per update. The post presents both as practical, well-benchmarked options for researchers and practitioners. ## What ACKTR Is - ACKTR (Actor Critic using Kronecker-factored Trust Region) was developed by researchers at the University of Toronto and New York University, with OpenAI collaborating on the Baselines release. - It combines three techniques: actor-critic methods, trust region optimization for more consistent improvement, and distributed Kronecker factorization to improve sample efficiency and scalability. - The authors applied it to simulated robots (pixel input, continuous actions) and Atari agents (pixel input, discrete actions). ## Sample and Computational Efficiency - **Sample complexity** is the number of environment interaction timesteps needed, and **computational complexity** is the number of numerical operations required. - ACKTR takes a step along the natural gradient rather than the plain gradient (or a rescaled version such as ADAM's). The natural gradient gives the parameter-space direction with the largest improvement in the objective per unit change in the network's output distribution, measured by KL divergence. - Limiting the KL divergence keeps the new policy from changing radically from the old one, which could otherwise collapse performance. - The KFAC update used by ACKTR costs only 10–25% more per step than a standard gradient update. TRPO, by contrast, relies on Hessian-free optimization with a more expensive conjugate-gradient computation. - In a Q-Bert comparison across timesteps, ACKTR agents achieved higher scores than A2C agents. ## Benchmarks - The release includes benchmarks comparing ACKTR against A2C, PPO, and ACER across a range of tasks. - On 49 Atari games, ACKTR was compared with A2C, PPO, and ACER. Its hyperparameters were tuned by the algorithm's author on a single game, Breakout. - ACKTR scales well with batch size because it uses each batch both to estimate the gradient and to approximate the local curvature of the parameter space. This makes it well suited to large-scale distributed training with large batches. ## A2C and A3C A3C combined three ideas: updates over fixed-length experience segments (for example, 20 timesteps) used to estimate returns and the advantage function, policies and value functions sharing layers, and asynchronous updates. Researchers questioned whether the asynchrony actually improved performance or was just an implementation detail enabling faster CPU-based training. - A2C answers this with a synchronous, deterministic design: it waits for every actor to finish its segment, then performs a single update averaging over all actors. - This suits GPUs, which perform best with large batches. - OpenAI found the synchronous A2C outperforms its asynchronous implementations, with no evidence that asynchrony's noise helps performance. - A2C is more cost-effective than A3C on single-GPU machines and faster than CPU-only A3C when using larger policies. - Baselines includes code for training feedforward convnets and LSTMs on the Atari benchmark with A2C.

OpenAI2017-08-022 min readCurated summary

Gathering human feedback

# Summary of "Gathering Human Feedback" (RL-Teacher) OpenAI released RL-Teacher, an open-source system for training AI agents with occasional human feedback instead of hand-crafted reward functions. The technique is aimed at safer AI systems and at reinforcement learning tasks where rewards are difficult to specify. The entire system is under 1,000 lines of Python, excluding the example agents. ## Core Components - **Reward predictor:** A module that can be plugged into any agent. It learns to predict which actions a human would approve of. - **Example agent:** An agent that learns from a reward function produced by the reward predictor. RL-Teacher includes three pre-integrated algorithms, including OpenAI Baselines PPO. - **Web app:** An interface where humans give feedback. This feedback is the data used to train the reward predictor. ## Running an Experiment - The web server must be set up first. An experiment is then launched with `rl_teacher/teach.py`, using the `human` feedback mode, 175 pretraining labels, the `Reacher-v1` environment, and a run name. - Human raters give feedback through the web interface, which can run locally (not recommended) or on a separate machine. - Full documentation is in the project's GitHub repository. OpenAI invites researchers and engineers to experiment with the tool and share their results.

OpenAI2017-07-193 min readCurated summary

Proximal Policy Optimization

# Proximal Policy Optimization: A Simpler, Robust Policy Gradient Method OpenAI introduces Proximal Policy Optimization (PPO), a new family of reinforcement learning algorithms that matches or beats state-of-the-art methods while being far simpler to implement and tune. The post argues that PPO strikes a practical balance between ease of implementation, sample efficiency, and ease of tuning, and reports that it has become OpenAI's default RL algorithm as a result. ## The Problems with Policy Gradient Methods - Policy gradient methods underpin many deep RL successes, including video games, 3D locomotion, and Go. - They are highly sensitive to the step size: too small and learning is painfully slow, too large and noise overwhelms the signal or performance collapses. - They often have poor sample efficiency, needing millions or billions of timesteps to learn simple tasks. ## Earlier Fixes: TRPO and ACER - TRPO and ACER constrain or otherwise optimize the size of each policy update to address these issues. - ACER is considerably more complex than PPO, requiring off-policy corrections and a replay buffer, while only marginally outperforming PPO on Atari. - TRPO works well for continuous control but is hard to combine with architectures that share parameters between the policy and value function, or that use auxiliary losses, which are common in vision-heavy domains like Atari. ## The PPO Objective - Supervised learning is predictable, whereas RL algorithms have many interacting parts that are hard to debug and require heavy tuning. - PPO computes each update to minimize the cost function while keeping the new policy close to the previous one. - An earlier PPO variant used an adaptive KL penalty to control policy change. The new version replaces this with a clipped surrogate objective built from the probability ratio between the new and old policies, multiplied by the estimated advantage, with a clipping hyperparameter ε typically set to 0.1 or 0.2. - This objective approximates a trust region update while remaining compatible with stochastic gradient descent. It removes the KL penalty and the need for adaptive update schedules. - In tests, PPO performed best on continuous control tasks and nearly matched ACER on Atari. ## Demonstration: Controllable Robots - Interactive agents trained with PPO were shown in Roboschool, where a user set new target positions for a robot via keyboard. - Although the input sequences differed from the training distribution, the agent generalized to them. ## Released Implementations - OpenAI Baselines now includes scalable, parallel implementations of PPO and TRPO that use MPI for data passing, written in Python 3 and TensorFlow. - Pre-trained policies for the robots are available in the Roboschool agent zoo. - A later update added PPO2, a GPU-enabled implementation that runs about 3x faster than the original PPO baseline on Atari. - The update also added ACER, which uses a replay buffer to perform multiple gradient updates per sample and a Q-function approximator trained with the Retrace algorithm. ## Conclusion PPO offers a practical default for policy gradient reinforcement learning: it is simpler than TRPO and ACER, performs comparably or better across continuous control and Atari, and is easier to tune. Its open-source implementations in Baselines make it straightforward to adopt.

OpenAI2017-05-233 min readCurated summary

OpenAI Baselines: DQN

# OpenAI Baselines: DQN OpenAI is open-sourcing Baselines, an internal library of reinforcement learning algorithms whose implementations are verified to match published results. The first release includes DQN and three of its variants, and the authors argue that known-good implementations make it harder for apparent RL advances to come from comparisons against buggy or undertuned baselines. The post pairs the release with practical advice on avoiding the bugs that commonly make RL results hard to reproduce. ## Why RL Results Are Hard to Reproduce - Performance is very noisy, so results can look like progress when they are not. - Algorithms have many interacting parts, and subtle bugs can hide inside them. - Papers often omit tricks that are needed to reach the reported performance. ## Practical Debugging Practices - **Compare against a random baseline.** An agent taking random actions can appear to learn early in training, as seen in the H.E.R.O. example, so an agent should always outperform a random one to show real learning. - **Watch for silent bugs.** In a review of ten popular RL reimplementations, six had subtle bugs confirmed by their authors. These ranged from ignored gradients and incorrect causal convolutions to implementations reporting scores higher than the true results. - **Inspect what the agent sees.** Converting frames to grayscale with miscalibrated green-channel coefficients erased the fish in Seaquest, which caused poor performance. Gym's new `play` function lets researchers view the same observations the agent receives. - **Fix bugs before tuning hyperparameters.** Bugs can push researchers toward compensating hyperparameter choices. Epsilon annealing had a large effect on performance, with the final schedule decreasing it to 0.1 over the first million steps and then to 0.01 over the next 24 million. - **Interpret papers carefully.** The DQN Nature paper's instruction to clip the error term to between -1 and 1 can mean clipping the objective, which zeroes gradients for high-error transitions, or clipping the gradient multiplier, which corresponds to Huber loss. The second interpretation is the correct one. Checking gradients with TensorFlow's `compute_gradients` can reveal such mistakes. - **Review code repeatedly.** Most bugs were found by re-reading the code line by line and asking what could go wrong, and experienced researchers often underestimate how many passes this takes. ## The Released Algorithms - **DQN:** Combines Q-learning with deep neural networks so RL can handle high-dimensional inputs such as video games and robotics. - **Double Q-learning:** Reduces the tendency of DQN to overestimate action values. - **Prioritized Replay:** Extends experience replay by sampling transitions where actual and expected rewards differ significantly. - **Dueling DQN:** Splits the network into a value stream and an advantage stream, which are combined into a single action-value estimate. ## Getting Started The release installs with `pip install baselines`. Users can train a CartPole model with `baselines.deepq.experiments.train_cartpole`, then visualize the learned policy with `enjoy_cartpole`. Pretrained Atari agents are also available, such as a dueling, prioritized-replay Breakout model that can be downloaded and run with the `atari.download_model` and `atari.enjoy` scripts. ## Benchmarks An included notebook compares the Atari performance of the DQN variants, including Dueling Double Q-learning with Prioritized Replay, Double Q-learning with Prioritized Replay, Dueling Double Q-learning, and Double Q-learning. ## Conclusion Reusable, verified implementations let researchers spend less time reimplementing existing algorithms and more time designing new ones. Anyone reproducing RL results should check against a random baseline, inspect the agent's observations, fix bugs before tuning, verify ambiguous paper details through gradient checks, and review the code thoroughly.