Prefect-Ray provides integrations for the Prefect workflow orchestration framework with the Ray distributed execution framework. It enables Prefect flows to run tasks in parallel using Ray, either by creating a temporary local Ray instance or connecting to an existing remote one. The library is actively maintained and currently at version 0.4.5, with its own versioning separate from the main Prefect library.
pip install "prefect[ray]"Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a Prefect flow and tasks, then configure the flow to use the `RayTaskRunner`. By default, a temporary local Ray instance is created. You can also specify an `address` to connect to an existing Ray cluster.
Use a compatible Python version (e.g., `python<=3.12`).
Consult Ray documentation for ARM/M1 installation, typically involving `conda install grpcio` after `pip uninstall grpcio`.
Ensure `prefect-ray` and all task dependencies are installed on the Ray cluster. For remote clusters, explicitly pass `init_kwargs={'runtime_env': {'pip': ['prefect-ray', 'your-task-dep']}}` to `RayTaskRunner` for worker dependencies, and ensure the driver environment also has `prefect-ray` installed.Configure Prefect to use a robust external database (e.g., PostgreSQL) for production or parallel workloads. Refer to Prefect's documentation for database setup.
Explicitly include necessary environment variables in the `runtime_env` within `init_kwargs` for `RayTaskRunner` (e.g., `RayTaskRunner(address='...', init_kwargs={'runtime_env': {'env_vars': {'PREFECT_API_URL': 'http://your-prefect-api:4200/api'}}})`).Ensure `prefect-ray` is installed on all Ray cluster nodes. If using `RayTaskRunner(address=...)`, pass `init_kwargs={'runtime_env': {'pip': ['prefect-ray']}}` to ensure workers have it.Set `PREFECT_API_URL` explicitly in the `runtime_env` for the `RayTaskRunner`'s `init_kwargs`. For example: `RayTaskRunner(address="ray://your-remote-ray-head:10001", init_kwargs={"runtime_env": {"env_vars": {"PREFECT_API_URL": "http://your-prefect-api-url:4200/api"}}})`.This often points to a complex interaction between Ray and Prefect's async execution. Ensure compatible versions of Ray and Prefect. Simplifying resource specifications or re-evaluating the task execution model might be necessary. Check Prefect and Ray GitHub issues for similar reports and workarounds.
Try clearing the Prefect data directory (`~/.prefect`), uninstalling all Prefect-related packages (`prefect`, `prefect-ray`, etc.), and reinstalling them. Restarting the system can also help.