techlist.io

Tensorflow

8 posts

OpenAI2018-03-063 min readCurated summary

Reptile: A scalable meta-learning algorithm

# Reptile: A Simple, Scalable Meta-Learning Algorithm Reptile is a meta-learning algorithm that finds a neural network initialization from which new tasks can be learned quickly from few examples. It works by repeatedly sampling a task, running standard SGD on it, and moving the initial parameters toward the adapted result. Mathematically it resembles first-order MAML, but it needs only black-box access to an optimizer such as SGD or Adam, and it achieves similar performance with lower computational cost. ## Meta-Learning and the Few-Shot Setting - Meta-learning takes a distribution of tasks, each a learning problem, and produces a learner that generalizes from a small number of examples. - A well-studied case is few-shot classification, where the learner sees only 1–5 examples per class before classifying new inputs. ## How Reptile Differs from MAML - MAML unrolls and differentiates through the gradient descent computation graph, which requires second derivatives. - Reptile runs ordinary SGD on each task and never builds a computation graph or computes second derivatives, so it uses less computation and memory. - The update moves the initialization toward the task-adapted parameters. Treating that difference as a gradient allows plugging it into a more sophisticated optimizer such as Adam. ## Why It Works - With one SGD step per task (k=1), the method reduces to joint training on the mixture of all tasks. Joint training learns little when zero-shot learning is impossible, such as when output labels are randomly permuted. - Reptile requires multiple steps (k>1), where the update depends on higher-order derivatives of the loss. - A Taylor-series analysis shows that the Reptile update maximizes the inner product between gradients from different minibatches of the same task, which corresponds to better generalization. The authors suggest this may also help explain the generalization of SGD outside meta-learning. - Reptile and MAML produce similar updates, containing the same two terms with different weights. ## Experimental Results - On the Omniglot and Mini-ImageNet few-shot classification benchmarks, Reptile and MAML perform similarly. - Reptile converges faster because its update has lower variance. - Summing different combinations of SGD minibatch gradients yields a family of algorithms. Using only the second gradient corresponds to first-order MAML. Including more gradients speeds learning through variance reduction, and using only the first gradient makes no progress, as the analysis predicts. ## Implementations - The official implementation uses TensorFlow and includes code to replicate the Omniglot and Mini-ImageNet experiments. - A smaller JavaScript implementation fine-tunes a TensorFlow-pretrained model and powers the interactive 1-shot classification demo. - A minimal PyTorch example performs few-shot regression on random sine waves from 10 (x, y) pairs. ## Relationship to Prior Work The authors note that first-order MAML and Reptile are more closely related than the names suggest. They take different perspectives but compute similar updates. Reptile's contribution builds on Shortest Descent and on avoiding second derivatives in meta-learning. The post's first paragraph was updated to reflect this.

OpenAI2017-12-053 min readCurated summary

Block-sparse GPU kernels

# Block-Sparse GPU Kernels for Neural Networks OpenAI releases highly optimized GPU kernels for neural networks whose weight matrices are block-sparse, meaning most blocks are exactly zero. Depending on the sparsity level, these kernels run orders of magnitude faster than cuBLAS or cuSPARSE, and the authors use them to reach state-of-the-art results in text sentiment analysis and in generative modeling of text and images. The post presents the kernels as a promising but not definitive foundation, and invites the community to explore the architectures they make practical. ## Why Sparse Weights Matter - Sparse weight matrices contain a large number of entries exactly equal to zero. - Matrix multiplication and convolution with block-sparse weights cost only in proportion to the number of non-zero blocks. - For a fixed parameter and compute budget, sparsity allows much wider and deeper networks, such as LSTMs with tens of thousands of hidden units, while the largest LSTMs trained at the time had only thousands. ## The Kernels - They support block-sparse weights in both fully connected and convolutional layers. - In convolutional layers, sparsity applies to input and output feature dimensions, while spatial connectivity is unchanged. - Sparsity is defined per block, with kernels optimized for 8x8, 16x16, and 32x32 blocks. The block-level pattern is fully configurable. - Skipped zero blocks mean compute and parameter storage scale with the number of non-zero weights rather than the number of input and output features. - Benchmarks on a Titan X Pascal GPU (CUDA 8), with 12288 hidden units, 32x32 blocks, and minibatch size 32, show speed-ups over cuBLAS at various sparsity levels. Speed-ups over cuSPARSE were even larger. ## Using the Kernels - The post includes a TensorFlow example that creates a random block-level sparsity pattern, builds a `BlocksparseMatMul` object with a chosen block size, initializes block-sparse weights from `bsmm.w_shape`, and runs the multiplication as a graph operation. ## Small-World LSTMs - Small-world graphs connect any two nodes through a small number of steps, even at very large scale, and brain connectivity shows similar properties. - The authors hypothesized that small-world sparse connectivity keeps information propagating quickly despite high sparsity. - Using this structure, they trained LSTMs with nearly 20,000 hidden units, about 5 times wider than a dense network with similar parameter counts, improving results on text generation and semi-supervised sentiment classification. ## Results - **Sentiment:** Using the setup from their sentiment neuron experiment, the sparse model beat the dense model on all sentiment datasets. On the document-level IMDB dataset, error dropped from 5.91% (Miyato et al., 2016) to 5.01%, a state-of-the-art result. Previous results had only performed best on shorter sentence-level datasets. - **Text compression:** With equal parameter counts (about 100 million), bits-per-character fell from 1.059 to 1.048 using sparse, wide LSTMs. - **Images:** Replacing regular 2D convolutions with sparse kernels in PixelCNN++ on CIFAR-10, while deepening the network and keeping other hyperparameters fixed, reduced bits-per-dimension from 2.92 to 2.90, a new state of the art on that dataset. ## Open Research Directions - **Inference speed-up:** How much wall-clock speed-up can pruning after training achieve when combined with these kernels? - **Learning sparsity structure:** Can gradients learn the sparsity pattern as well as the weights, similar to how biological brains partly determine connectivity during development? Related work includes learning block-sparse RNNs and L0 regularization. - **Application domains:** Sparse layers allow huge weight matrices at the same parameter count and compute cost as smaller dense models. Which domains will benefit most?

OpenAI2017-09-283 min readCurated summary

Nonlinear computation in deep linear networks

# Nonlinear Computation in Deep Linear Networks The post argues that deep linear networks, when implemented with floating-point arithmetic, are not truly linear. Near zero, float32 rounding and underflow introduce genuine nonlinearities, and evolution strategies can exploit them to solve problems that a standard linear network trained by backpropagation handles poorly. On MNIST, this approach lifts a linear network's test accuracy from 92% to 96.7%. ## Why Floating-Point Arithmetic Is Nonlinear - Neural networks normally alternate linear layers with nonlinear activations like tanh or ReLU. In exact math, stacked linear layers collapse into one linear layer. - Computers approximate real numbers with finite bits. In IEEE float32, a number has 1 sign bit, 8 exponent bits, and 23 fraction bits. - The smallest normal positive number is `min` = 1.0...0 × 2^-126. The gap between 0 and `min` is about 2^20 times larger than the gap between `min` and the next representable number, so values below `min` underflow to zero. - Because of this underflow, arithmetic near zero stops obeying the usual algebraic laws. The post gives two examples: - With a = 0.4×min, b = 0.5×min, c = 1/min, the expression (a+b)×c evaluates to 0, while (a×c)+(b×c) evaluates to 0.9. - With a = 2.5×min, b = −1.6×min, c = 1×min, (a+b)+c gives min, but (b+c)+a gives 2.5×min. - TensorFlow builds its primitives with denormals disabled (`ftz=true`), so any non-matrix-multiply operation near magnitude 1e-38 carries an implicit nonlinearity. ## Exploiting the Nonlinearity with Evolution Strategies - Standard backpropagation relies on symbolic differentiation, which cannot see these tiny-scale nonlinearities, so it struggles to train networks that depend on them. - Evolution strategies (ES) estimate gradients by sampling perturbations of the parameters instead of differentiating the computation, so they can exploit the behavior. - The authors scale activations so they fall into float32's nonlinear near-zero range. The architecture is a 784→512→512→10 network with no nonlinear activations, using scaling factors of 2^125 to keep intermediate values in that range. ## Results - A deep linear network trained with backpropagation reached about 94% training and 92% test accuracy on MNIST. - The same linear architecture trained with ES reached over 99% training and 96.7% test accuracy. - The authors attribute the gain to the float32 nonlinearities, which let each layer form nonlinear combinations of lower-level features. ## Future Directions - The authors suggest extending the approach to recurrent neural networks. - They also propose using these nonlinearities to improve harder tasks such as language modeling and machine translation.

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.

OpenAI2016-08-284 min readCurated summary

Infrastructure for deep learning

# Infrastructure for Deep Learning Research OpenAI's 2016 post argues that the quality of a research group's infrastructure multiplies its rate of progress in deep learning, which is an empirical science. The authors describe how deep learning work moves from rapid, ad-hoc experiments to long, carefully managed multi-GPU training runs, and explain the stack they built to support both phases. They also open-source kubernetes-ec2-autoscaler, a batch-optimized scaling manager for Kubernetes. ## The Research Workflow Deep learning research happens in two distinct phases, and the infrastructure has to serve both: - **Early exploration** is fast and unstructured. Researchers want to SSH into a machine, run a script in `screen`, and see a result within an hour. - **Scaling up** requires multi-day jobs on many GPUs, careful experiment tracking, and deliberate hyperparameter selection. - Making a model work often means watching it fail in many ways, so infrastructure must support flexible introspection of models rather than only summary statistics. ## A Worked Example: Improved GAN Training The post traces how one idea moved from concept to large-scale result. The idea was to give the GAN discriminator a whole minibatch of samples instead of one, so it can detect when the generator collapses to a single output. - The idea was prototyped on MNIST and CIFAR-10 with small models, producing some of the best CIFAR-10 samples the team had seen. - Scaling to ImageNet required parallelizing across multiple GPUs, with jobs driving machines to about 90% CPU and GPU utilization and training for many days. - The authors note that the final results were good but short of expectations, and they have not yet identified the reason. ## Software and Hardware Choices - **Software:** Mostly Python 2.7 with TensorFlow (occasionally Theano), with Keras used on top in some cases. Anaconda handles difficult packages such as OpenCV. - **GPUs:** Multi-GPU scaling is usually sublinear, so top-of-the-line GPUs matter. CPU-heavy workloads such as simulators and reinforcement learning environments run separately from GPU workloads. - **Hybrid cloud:** AWS donated compute for CPU instances and horizontally scaled GPU jobs, while the team also runs physical servers, mainly with Titan X GPUs, to experiment with different hardware. ## Provisioning and Orchestration - **Provisioning:** Terraform manages AWS resources, Chef configures Ubuntu nodes on both cloud and physical hardware, and Packer pre-bakes cluster AMIs for faster spin-up. Clusters use non-overlapping IP ranges and connect over OpenVPN and strongSwan. - **Storage:** Home directories, datasets, and results live on NFS for physical hardware and on EFS or S3 in AWS. - **Scheduling:** Kubernetes schedules jobs across three AWS regions, since bursty demand can exhaust capacity in a single region. Each job runs as a Docker container for dependency isolation and code snapshotting, and tooling ships laptop code into a standard image to avoid slow rebuilds. - **Networking:** Kubernetes' flannel network is exposed directly to researchers' laptops, so services like TensorBoard are reachable without creating a Kubernetes Service for each port. ## kubernetes-ec2-autoscaler Research workloads are bursty. One experiment grew from a single Titan X to 60 Titan Xs and then to nearly 1,600 AWS GPUs within weeks. Standard Auto Scaling policies add nodes piecemeal, and scale-in can kill in-flight jobs unless nodes are drained first. - The autoscaler runs as a normal Pod and requires only that worker nodes belong to Auto Scaling groups. - It polls the Kubernetes master to compute the cluster's resource demand and capacity, then sizes Auto Scaling groups to match in one step. - Excess nodes are drained and terminated. Drained nodes can be uncordoned to skip spin-up time when demand returns. - It handles multiple Auto Scaling groups, resources beyond CPU (memory and GPUs), and constraints such as region and instance size. - When AWS reports capacity errors, it fails over to a secondary region. The authors chose to build on Kubernetes rather than raw EC2 because the surrounding tooling for logging, monitoring, and managing physical nodes was worth keeping, and making Kubernetes autoscale was simpler than rebuilding that ecosystem.

OpenAI2016-04-263 min readCurated summary

OpenAI Gym Beta

# OpenAI Gym Beta: A Shared Toolkit for Reinforcement Learning Research OpenAI has released the public beta of OpenAI Gym, an open toolkit for developing and comparing reinforcement learning (RL) algorithms. It pairs a growing suite of environments, ranging from simple control tasks to Atari games and simulated robots, with a site for comparing and reproducing results. The authors built it to speed up their own research and hope it becomes equally useful to the wider community. ## Why RL Needs Better Infrastructure - RL covers any problem involving a sequence of decisions, such as robot locomotion, pricing and inventory management, video games, and board games. It has also been applied to supervised problems with sequential or structured outputs. - Recent deep RL systems, including DeepMind's Atari work, BRETT, and AlphaGo, make few assumptions about their environments, so they transfer across settings. Earlier RL methods required heavy problem-specific engineering. - Two obstacles slow progress: - **Weak benchmarks:** Supervised learning advanced through large labeled datasets like ImageNet. RL lacks an equivalent, and existing open-source environment collections are narrow and often hard to set up. - **Inconsistent environments:** Small differences in reward functions or action sets can change a task's difficulty dramatically, which makes published results hard to reproduce or compare. ## The Environment Suite - **Classic control and toy text:** Small-scale tasks from the RL literature, intended as a starting point. - **Algorithmic:** Tasks such as adding multi-digit numbers or reversing sequences, learned purely from examples. Difficulty scales with sequence length. - **Atari:** Classic games through an easy-to-install integration of the Arcade Learning Environment. - **Board games:** Go on 9x9 and 19x19 boards against a fixed Pachi opponent. Multi-player support is planned. - **2D and 3D robots:** Simulated control tasks built on the MuJoCo physics engine, including environments from a UC Berkeley benchmark. MuJoCo is proprietary but offers free trial licenses. Each environment carries a version number, such as Hopper-v0. Any change to an environment produces a new version, so results on a given version stay comparable over time. ## Evaluation Without Leaderboards - Users can upload results, but OpenAI chose not to build traditional leaderboards, since raw scores can be gamed through overfitting or hand-crafted solutions. - Instead, a curated list highlights contributions that show something interesting about algorithmic capability. The long-term goal is for this curation to be community-led. - Partners supporting the launch include NVIDIA (technical Q&A), Nervana (a DQN agent implementation), and AWS (US$250 credit vouchers for promising, resource-constrained researchers). ## Getting Involved - Work through the tutorial, or reproduce an existing result. - During the beta, feedback is requested on making the tool better for research. Contributors can push the state of the art on each environment, reproduce published results, or build new environments. Community chat is open.