Summary
This RPC proposes dropping support for Pydantic v1 in Ray and migrating all code to use Pydantic v2 native APIs. This will simplify the codebase, remove technical debt from the compatibility layer, and allow Ray to take advantage of Pydantic v2's performance improvements and modern features.
Motivation
Current State
Ray currently supports both Pydantic v1 and Pydantic v2 through a compatibility layer (ray._common.pydantic_compat). When Pydantic v2 is installed, Ray imports from pydantic.v1 to maintain backward compatibility. This approach has several drawbacks, but most prominent are Performance and Feature limitation.
Pydantic v1 End of Life
- Pydantic v1 has been superseded by v2 since June 2024
- Pydantic v2 has been stable for over 2 years
- The Python ecosystem has largely migrated to Pydantic v2
- Continued v1 support limits Ray's ability to adopt modern dependencies
Proposal
Migration Timeline
We propose a phased approach to dropping Pydantic v1 support:
Phase 1: Announcement (Ray 2.53)
Phase 2: Drop Support (Ray 2.56)
Phase 3: Migrate Ray Code to v2 (Ray 2.59)
References
Summary
This RPC proposes dropping support for Pydantic v1 in Ray and migrating all code to use Pydantic v2 native APIs. This will simplify the codebase, remove technical debt from the compatibility layer, and allow Ray to take advantage of Pydantic v2's performance improvements and modern features.
Motivation
Current State
Ray currently supports both Pydantic v1 and Pydantic v2 through a compatibility layer (
ray._common.pydantic_compat). When Pydantic v2 is installed, Ray imports frompydantic.v1to maintain backward compatibility. This approach has several drawbacks, but most prominent are Performance and Feature limitation.Pydantic v1 End of Life
Proposal
Migration Timeline
We propose a phased approach to dropping Pydantic v1 support:
Phase 1: Announcement (Ray 2.53)
Phase 2: Drop Support (Ray 2.56)
setup.pyto set pydantic version constraint:pydantic>=2.5,<3Phase 3: Migrate Ray Code to v2 (Ray 2.59)
python/ray/_common/pydantic_compat.pycompatibility layerray.servecomponentsray.traincomponentsray.llmcomponentsray.util.statecomponentsIS_PYDANTIC_2conditional checkspydantic.v1topydanticthroughout codebaseReferences