What’s Next After PyTorch and TensorFlow? A Look at Emerging Machine Learning Technologies
From the publisher’s feed, collected in the ZeroLabs newsroom.
In this article, we are going to explore the machine learning technologies that every machine learning engineer needs to know beyond Pytorch and Tensorflow. As everyone knows, PyTorch and TensorFlow are prominent open-source deep learning frameworks used for building and training neural networks.IntroductionThere are various deep learning libraries, but the two most famous libraries are PyTorch and TensorFlow. Though both are open source libraries but sometimes it becomes difficult to figure out the difference between the two. They are extensively used in commercial code and academic research.PytorchPyTorch is an open-source library used in machine learning. It was developed by Facebook and was released to the public for the first time in 2016, and is currently being developed with support from the Linux Foundation. The successor to Torch, PyTorch provides a high-level API that builds upon optimised, low-level implementations of deep learning algorithms and architectures, such as the Transformer or SGD. Notably, this API simplifies model training and inference to a few lines of code. PyTorch allows for automatic parallelization of training and, internally, implements CUDA bindings that speed training further by leveraging GPU resources.PyTorch utilises the tensor as a fundamental data type, similarly to NumPy. Training is facilitated by a reversed automatic differentiation system, Autograd, that constructs a directed acyclic graph of the operations (and their arguments) executed by a model during its forward pass. With a loss, backpropagation is then undertaken.TensorFlowTensorFlow is also an open-source library used in machine learning. It was developed by Google and was released in 2015. It can be used across a range of tasks, but is used mainly for training and inference of neural networks. It is one of the most popular deep learning frameworks, alongside others such as PyTorch. TensorFlow can be used in a wide variety of programming languages, including Python, JavaScript, C++, and Java, facilitating its use in a range of applications in many sectors. Production and research are the main uses of TensorFlow. Neural networks mostly use Tensorflow to develop machine learning applications.What are the alternatives to PyTorch and TensorFlow?The choice between PyTorch and TensorFlow often depends on whether the priority is research flexibility or production-grade scalability. These technologies are used mostly because of their strong ecosystem support, a Large community to support, Excellent tooling for training, deployment, and debugging, and their wide acceptance in the industry. Other frameworks can overcome their dominance if they can provide better performance, scalability, and ease of deployment. As of now, PyTorch and TensorFlow dominate, but other frameworks are gaining traction for specific needs:Below are the Frameworks that are getting attention:JAXJAX is an open-source machine learning framework developed by Google, designed for high-performance numerical computing and machine learning research. It distinguishes itself by combining NumPy-like syntax with powerful features like automatic differentiation, Just-In-Time (JIT) compilation, and seamless scaling across various hardware accelerators, including GPUs and TPUs. It is renowned for its numerical computation and automatic differentiation capabilities, which help in the development of many machine learning algorithms. Although JAX is a relatively new machine learning framework, it has some helpful features for developing machine learning models.Key Features of JAXIt can automatically differentiate functions using the reverse-mode differentiation technique. This helps to seamlessly calculate gradients and provide accurate values in training models.It runs on CPU, GPU, and TPU, which provides faster numerical computations.It is compatible with NumPy and other Python libraries, making it easier to integrate existing Python codebases.It uses built-in Just-In-Time (JIT) compilation, which results in faster training time for machine learning models that involve complex computations.It is highly flexible; developers can create custom neural network architectures using JAX.It offers automatic parallelization and vectorization across multiple devices.Pros of JAX:High Performance: JAX leverages XLA (Accelerated Linear Algebra) for Just-In-Time (JIT) compilation and hardware acceleration, leading to significant speedups, especially on GPUs and TPUs. This is particularly beneficial for large-scale models and complex computations.Automatic Differentiation: JAX provides powerful and flexible automatic differentiation capabilities, including grad, vmap, jit, and pmap, which are crucial for optimizing machine learning models and exploring new algorithmsFunctional Programming Paradigm: JAX encourages a functional programming style, which can lead to more predictable and easier-to-debug code by minimizing side effects.Composability of Transformations: JAX’s core transformations (like jit, grad, vmap, pmap) can be composed and nested, offering a high degree of flexibility for building complex computational pipelines.Research-Oriented: JAX’s design makes it well-suited for research and prototyping, allowing researchers to rapidly experiment with new ideas and architectures.Cons of JAX:Steeper Learning Curve: JAX’s functional paradigm and explicit handling of transformations can be a departure from more imperative frameworks like PyTorch or TensorFlow, requiring a greater initial investment in learning.Less Mature Ecosystem: Compared to established frameworks like TensorFlow and PyTorch, JAX has a smaller community and a less extensive ecosystem of pre-trained models, libraries, and tools. This may necessitate implementing more components from scratch.Debugging Challenges: Debugging JIT-compiled code in JAX can be more challenging than in frameworks with dynamic computation graphs, as errors may manifest during compilation rather than during execution.Functional Purity Requirements: JAX’s jit compilation requires functional purity, meaning that functions should not have side effects. This can require adapting existing code or being mindful of how Python-level operations interact with JAX arrays.Limited High-Level APIs: While JAX provides powerful low-level primitives, it offers fewer high-level APIs and abstractions for common machine learning tasks compared to frameworks like Keras (in TensorFlow) or PyTorch Lightning. This often means more manual implementation for standard model architectures or training loops.Flax (for JAX)Flax is a neural network library specifically designed to work with JAX, a high-performance numerical computation library. It provides a flexible and end-to-end user experience for researchers and developers building neural networks using JAX.Key Features of Flax (for JAX)Built on JAX: Flax leverages the power of JAX, including its automatic differentiation, JIT compilation, and ability to run on various accelerators like GPUs and TPUs.Functional Paradigm: Flax embraces JAX’s functional programming paradigm, promoting explicit and composable code. This leads to a clear separation of model parameters and logic.Modules and NNX: At its core, Flax provides a system for building neural network layers and models using flax.linen.Module. More recently, the modern API Flax NNX was introduced, offering a more Pythonic and intuitive way to define models using standard Python object semantics.Flexibility and Control: Flax offers fine-grained control over model state and random number generation, providing more expressiveness than many other neural network frameworks.Integration: It seamlessly integrates with other JAX-based libraries like Optax for optimization and Chex for testing.Used in Research and Industry: Flax is used in numerous projects within the open-source community and at Google for developing advanced models like PaLM and Imagen.Pros of Flax:JAX’s strengths: Flax inherits all the advantages of JAX, including automatic differentiation, JIT compilation for performance on various accelerators (CPUs, GPUs, TPUs), and robust support for multi-device parallelism.High-level API: Flax provides a more structured and user-friendly API for building neural networks compared to raw JAX, making it more accessible for machine learning practitioners.Modular design: Flax promotes a modular approach to model building, separating concerns like model parameters, state, and randomness, which enhances code maintainability and debugging.Pythonic design (NNX): The newer NNX API in Flax utilizes standard Python object semantics, making it feel natural for developers familiar with object-oriented programming in Python.Community and ecosystem: Flax has a growing community and a good ecosystem, with many models available on platforms like Hugging Face Hub.Cons of Flax:JAX’s constraints: Flax, being built on JAX, also inherits JAX’s functional programming paradigm and its associated constraints, such as the immutability of data structures and the need to manage random number generation explicitly with PRNG keys.Learning curve: While Flax simplifies JAX for neural networks, there is still a learning curve associated with understanding JAX’s functional programming model, especially for those accustomed to imperative frameworks like PyTorch or TensorFlow.Maturity of high-level libraries: While Flax is relatively stable, the JAX ecosystem for high-level machine learning libraries is still evolving compared to more established frameworks, which may lead to fewer readily available resources or production-ready tools in some niches.Production readiness: JAX and its libraries, including Flax, are often considered research-first, making them excellent for prototyping and research, but potentially less mature for large-scale production deployments compared to frameworks with extensive production-oriented features.OptaxOptax is a specialized gradient processing and optimization library for JAX, designed to provide building blocks for researchers and practitioners to easily combine into custom optimization algorithms. It is not a full machine learning framework itself, but it works in conjunction with JAX and other libraries like Flax or Equinox.Key Features of OptaxJAX Integration: Optax is built specifically for the JAX ecosystem, leveraging its automatic differentiation (jax.grad) and JIT compilation capabilities.Composability: Its core philosophy is modularity. It provides low-level, well-tested components (e.g., momentum, adaptive scaling, weight decay) that can be chained together using optax.chain to create complex, custom optimizers.Comprehensive Optimizers and Losses: It includes implementations of many popular optimizers like Adam, AdamW, RMSprop, and SGD, as well as various loss functions (e.g., L2 loss, cross-entropy, Huber loss).Research Productivity: It is intended to accelerate the adoption of new research ideas by making it simple to experiment with novel optimization techniques.Integration with Neural Network Libraries: Optax is typically used alongside neural network libraries like Flax or Equinox to manage model parameters and training states.Pros of OptaxModularity and Flexibility: Optax is designed around “gradient transformations” as building blocks that can be easily chained together, allowing researchers to quickly compose and test custom optimizers and complex training routines (e.g., learning rate schedules, gradient clipping).Integration with JAX Ecosystem: It integrates seamlessly with JAX’s core functionality (like jax.grad and JIT compilation), enabling high-performance, scalable computation on various hardware accelerators (GPUs, TPUs).Well-tested and Efficient Implementations: It provides robust, well-tested, and efficient implementations of many popular optimizers (Adam, AdamW, RMSProp, etc.) and loss functions, ensuring correctness and performance in production environments.Functional Approach: Aligning with JAX’s functional paradigm makes the code easier to reason about, as parameters and optimizer states are handled explicitly, which aids in reproducibility and debugging.Support for Advanced Techniques: The library supports advanced techniques like meta-learning (optimizing the optimizer’s hyperparameters), mixed-precision training, and gradient accumulation.Cons of OptaxSteeper Learning Curve: Using Optax requires a solid understanding of JAX’s functional programming model, which can be a significant shift for users coming from imperative frameworks like PyTorch.Requires Explicit State Management: Due to JAX’s pure functions, the optimizer state must be manually managed and passed around the training loop, which can result in more verbose code compared to object-oriented frameworks.Smaller Ecosystem/Community than PyTorch/TensorFlow: While growing, the JAX/Optax ecosystem and community are smaller than those of PyTorch or TensorFlow, which can mean fewer pre-trained models or community resources available off-the-shelf.Debugging Challenges with JIT: JAX’s JIT compilation (which Optax leverages for performance) can sometimes make runtime debugging more challenging, as errors may be raised after the code has been compiled.Dependence on JAX: Optax is intrinsically tied to JAX; it cannot be used independently with other frameworks, limiting portability to non-JAX environments.Conclusion:As the machine learning ecosystem evolves at an increasingly rapid rate, trying to find one tool that can fulfill your needs will not be possible. This article describes only three of the many tools that are becoming available: JAX, Flax, and Optax. However, they are not representative of all the changes that are occurring within the machine learning industry, as new frameworks and technologies are being developed. Each of these new frameworks or technologies is designed for a specific type of application, such as high-performance kernels, optimizations that are specific to certain types of hardware, and cross-platform deployment.It is clear that the future of the machine learning industry is going to be multi-framework. As machine learning applications continue to grow, and as more deployment environments become available to us, machine learning engineers are going to want to have more flexibility rather than be limited to one framework. It will be much more beneficial for them to be able to use multiple tools to be able to take advantage of different features of those tools and select the best tool for the specific job rather than being locked into using only one ecosystem. The machine learning engineers who adapt, continue to learn, and remain tool-agnostic will be the ones who will succeed in the future of machine learning development.In addition to discussing JAX, Flax, and Optax in depth in this article, the ecosystem for machine learning has many other notable technologies currently available that are designed to advance machine learning’s performance, portability, and productivity. These additional technologies include: PyTorch 2.0; TensorFlow / Keras 3; Mojo; Triton; MLX; ONNX Runtime; Apache TVM; and many others.What’s Next After PyTorch and TensorFlow? A Look at Emerging Machine Learning Technologies was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.