[Paper Review] EagerPy: Writing Code That Works Natively with PyTorch, TensorFlow, JAX, and NumPy
EagerPy is a Python framework that enables writing framework-agnostic deep learning code that natively works with PyTorch, TensorFlow, JAX, and NumPy without performance overhead. It unifies their APIs through transparent dispatch, supports method chaining, and provides comprehensive type annotations, allowing libraries to be implemented once and used across multiple frameworks with full performance and type safety.
EagerPy is a Python framework that lets you write code that automatically works natively with PyTorch, TensorFlow, JAX, and NumPy. Library developers no longer need to choose between supporting just one of these frameworks or reimplementing the library for each framework and dealing with code duplication. Users of such libraries can more easily switch frameworks without being locked in by a specific 3rd party library. Beyond multi-framework support, EagerPy also brings comprehensive type annotations and consistent support for method chaining to any framework. The latest documentation is available online at https://eagerpy.jonasrauber.de and the code can be found on GitHub at https://github.com/jonasrauber/eagerpy.
Motivation & Objective
- To eliminate the need for library developers to maintain separate implementations for PyTorch, TensorFlow, JAX, and NumPy.
- To allow users to switch between deep learning frameworks without being locked into a single library.
- To provide a unified, performant, and type-safe API that preserves the native performance of underlying frameworks.
- To enable seamless integration of framework-agnostic code with framework-specific code for gradual adoption.
- To improve code maintainability and reduce duplication across deep learning frameworks.
Proposed method
- EagerPy introduces a unified API that maps operations transparently to the underlying framework’s native tensor operations without intermediate NumPy conversions.
- It maintains native performance by directly delegating operations to the original framework’s tensors, avoiding costly CPU-GPU memory transfers.
- The framework supports method chaining by exposing all operations as methods on tensor objects, enabling fluent, readable code like x.square().sum().sqrt().
- Comprehensive type annotations are implemented using MyPy, enabling static type checking and early bug detection across all function parameters and return values.
- EagerPy supports multiple backends—including PyTorch, TensorFlow 2, JAX, and NumPy—by defining framework-specific translation layers for each operation.
- The framework uses test-driven development with end-to-end tests to ensure consistent behavior and API correctness across all supported frameworks.
Experimental results
Research questions
- RQ1Can a single, unified API be built that natively supports PyTorch, TensorFlow, JAX, and NumPy without performance degradation?
- RQ2How can method chaining and consistent API design be achieved across frameworks with divergent syntactic and semantic conventions?
- RQ3To what extent can comprehensive type annotations improve code safety and maintainability in deep learning libraries?
- RQ4Can framework-agnostic code be incrementally adopted in existing libraries without requiring full refactoring?
- RQ5How can automatic differentiation APIs across PyTorch, TensorFlow, and JAX be abstracted into a consistent, high-level interface?
Key findings
- EagerPy enables writing framework-agnostic code that runs natively on PyTorch, TensorFlow, JAX, and NumPy with zero performance overhead by directly delegating to native tensors.
- The framework successfully supports method chaining, allowing intuitive, fluent code such as x.square().sum().sqrt() across all supported backends.
- Comprehensive type annotations are implemented and validated using MyPy, significantly improving code safety and developer confidence.
- The framework has been successfully adopted as the foundation for Foolbox Native, enabling a single codebase to support multiple frameworks with native performance and full type safety.
- EagerPy's test-driven development approach ensures consistent behavior and API correctness across all supported frameworks, reducing regression risks.
- Libraries like GUDHI have adopted EagerPy to add automatic differentiation support across PyTorch, TensorFlow, and JAX without code duplication.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.