-
Notifications
You must be signed in to change notification settings - Fork 8
Add dependency verification documentation #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c9a9086
Add dependency verification documentation
jmhsieh 43e6105
First setup of updates from comments
jmhsieh 03b93e1
Reorganize dependency verification doc to place solutions with output…
jmhsieh e091f55
seperate packages and env variables into two separate steps
jmhsieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,340 @@ | ||
| --- | ||
| title: Dependency Verification | ||
| sidebarTitle: Dependency Verification | ||
| description: Diagnose and resolve package version mismatches between local and Ray worker environments. | ||
| icon: magnifying-glass-chart | ||
| --- | ||
|
|
||
| When running Geneva UDFs on Ray, your code is serialized locally and executed on remote workers. If the worker environment differs from your local environment, you may encounter subtle and difficult-to-debug errors. | ||
|
|
||
| ## Example environment mismatch errors | ||
|
|
||
| | Symptom | Likely Cause | | ||
| |---------|--------------| | ||
| | `TypeError: Enum.__new__() missing 1 required positional argument` | `attrs` version mismatch | | ||
| | `TypeError: Can't instantiate abstract class` | Package structure differences | | ||
| | `ArrowInvalid: cannot cast` / serialization errors | NumPy 1.x vs 2.x mismatch | | ||
| | `ModuleNotFoundError` on workers | Package only installed locally | | ||
| | Model loading failures | PyTorch version mismatch | | ||
| | Permission denied errors | Missing API keys in envrionment variables | | ||
|
|
||
| These issues are notoriously difficult to debug because the error messages often don't indicate the root cause. | ||
|
|
||
|
|
||
| ## The `compare_ray_environments` Tool | ||
|
|
||
| Geneva provides a diagnostic tool to compare your local environment against Ray workers. | ||
|
|
||
| If you are encountering a hang or exception you can use the following diagnosis worklflow to resolve the problem. | ||
|
|
||
| <Steps> | ||
| <Step> | ||
| **Run the diagnostic tool** programatically or via the CLI. | ||
| </Step> | ||
| <Step> | ||
| **Check PACKAGES and ENV VARS output sections for mismatches**. | ||
| </Step> | ||
| <Step> | ||
| **Identify critical packages**: numpy, torch, pyarrow, attrs, pydantic. | ||
| </Step> | ||
| <Step> | ||
| **Identify inconsistent environment variables**: `AWS_*`, `GOOGLE_APPLICATION_CREDENTIALS` | ||
| </Step> | ||
| <Step> | ||
| **Fix with manifest** for quick testing: | ||
| ```python | ||
| from geneva.manifest.builder import GenevaManifestBuilder | ||
| manifest = GenevaManifestBuilder.create("fix").pip(["numpy==1.26.4"]).build() | ||
| ``` | ||
| </Step> | ||
| <Step> | ||
| **OPTIONAL: Build custom image** for production (if using KubeRay). | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| ### Programmatic Usage | ||
|
|
||
| <CodeGroup> | ||
| ```python Python icon="python" | ||
| from geneva.runners.ray.compare_env import compare_ray_environments | ||
|
|
||
| # Compare and print (requires Geneva context to be initialize via `with db.context(..)`) | ||
| result = compare_ray_environments() | ||
|
|
||
| # Compare environments, filtering environment variables with specified prefix | ||
| result = compare_ray_environments(env_prefix="PY") | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| ### CLI Usage | ||
|
|
||
| <CodeGroup> | ||
| ```bash CLI icon="terminal" | ||
| # Connect to existing Ray cluster | ||
| python -m geneva.runners.ray.compare_env | ||
|
|
||
| # Start new local Ray cluster | ||
| python -m geneva.runners.ray.compare_env --address local | ||
|
|
||
| # Filter env vars by prefix | ||
| python -m geneva.runners.ray.compare_env --env-prefix RAY | ||
|
|
||
| # Show full JSON snapshots | ||
| python -m geneva.runners.ray.compare_env --show-all | ||
|
|
||
| # Skip sys.path comparison | ||
| python -m geneva.runners.ray.compare_env --no-sys-path | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| ## Understanding the Output | ||
|
|
||
| The tool outputs several sections to help you identify mismatches. | ||
|
|
||
| ### PYTHON / PLATFORM | ||
|
|
||
| Shows Python version and OS information for both environments: | ||
|
|
||
| ``` | ||
| === PYTHON / PLATFORM === | ||
| Local: | ||
| Python: 3.11.9 (main, Apr 19 2024, 16:48:06) [GCC 11.2.0] | ||
| Impl : CPython | ||
| Exec : /home/user/.venv/bin/python | ||
| OS : Linux 5.15.0-generic (x86_64) | ||
|
|
||
| Remote: | ||
| Python: 3.11.9 (main, Apr 19 2024, 16:48:06) [GCC 11.2.0] | ||
| Impl : CPython | ||
| Exec : /home/ray/anaconda3/bin/python | ||
| OS : Linux 5.4.0-aws (x86_64) | ||
| ``` | ||
|
|
||
| <Warning> | ||
| Watch for different Python versions or different OS types (macOS local vs Linux remote). | ||
| </Warning> | ||
|
|
||
| #### Architecture Mismatch (macOS to Linux) | ||
|
|
||
| If you see different OS types (e.g., `Darwin` locally vs `Linux` remotely), compiled extensions may fail with `ModuleNotFoundError` or segfaults. | ||
|
|
||
| **Solution**: Run Geneva from the same OS/architecture as your cluster (typically Linux x86_64). Use a Linux VM, container, or remote development environment. | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| Environment variables present in only one environment: | ||
|
|
||
| ``` | ||
| === ENV VARS: keys only in LOCAL === | ||
| + CONDA_PREFIX | ||
| + VIRTUAL_ENV | ||
|
|
||
| === ENV VARS: keys only in REMOTE === | ||
| + RAY_ADDRESS | ||
| + KUBERNETES_SERVICE_HOST | ||
| ``` | ||
|
|
||
| <Warning> | ||
| Missing `AWS_*` or `GOOGLE_APPLICATION_CREDENTIALS` can cause storage authentication failures. | ||
| </Warning> | ||
|
|
||
| #### Passing Environment Variables to Workers | ||
|
|
||
| If critical environment variables are missing on workers, you can pass them via the manifest or cluster configuration. | ||
|
|
||
| **Option 1: Via Manifest** | ||
|
|
||
| <CodeGroup> | ||
| ```python Python icon="python" | ||
| from geneva.manifest.builder import GenevaManifestBuilder | ||
| import os | ||
|
|
||
| manifest = ( | ||
| GenevaManifestBuilder.create("my-manifest") | ||
| .env({ | ||
| "AWS_ACCESS_KEY_ID": os.environ["AWS_ACCESS_KEY_ID"], | ||
| "AWS_SECRET_ACCESS_KEY": os.environ["AWS_SECRET_ACCESS_KEY"], | ||
| "MY_API_KEY": os.environ["MY_API_KEY"], | ||
| }) | ||
| .build() | ||
| ) | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| **Option 2: Via Cluster Configuration** | ||
|
|
||
| <CodeGroup> | ||
| ```python Python icon="python" | ||
| from geneva.cluster.builder import GenevaClusterBuilder | ||
| import os | ||
|
|
||
| cluster = ( | ||
| GenevaClusterBuilder.create("my-cluster") | ||
| .ray_init_kwargs({ | ||
| "runtime_env": { | ||
| "env_vars": { | ||
| "AWS_ACCESS_KEY_ID": os.environ["AWS_ACCESS_KEY_ID"], | ||
| "AWS_SECRET_ACCESS_KEY": os.environ["AWS_SECRET_ACCESS_KEY"], | ||
| } | ||
| } | ||
| }) | ||
| .build() | ||
| ) | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| <Warning> | ||
| Avoid hardcoding secrets. Use `os.environ` to pass values from your local environment, or use a secrets manager in production. | ||
| </Warning> | ||
|
|
||
| ### Packages | ||
|
|
||
| The tool shows version mismatches and packages only present in one environment: | ||
|
|
||
| ``` | ||
| === PACKAGES: version mismatches === | ||
| * numpy: local=1.26.4 remote=2.2.6 | ||
| * torch: local=2.0.1 remote=2.8.0+cpu | ||
| * attrs: local=23.2.0 remote=24.2.0 | ||
| * pyarrow: local=14.0.1 remote=17.0.0 | ||
|
|
||
| === PACKAGES: only in LOCAL === | ||
| + my-custom-package | ||
| + dev-tools | ||
|
|
||
| === PACKAGES: only in REMOTE === | ||
| + kuberay-client | ||
| ``` | ||
|
|
||
| <Warning> | ||
| Watch for major version differences (NumPy 1.x vs 2.x) and PyTorch version mismatches. | ||
| </Warning> | ||
|
|
||
| #### Common Package Issues | ||
|
|
||
| | Issue | Symptoms | Fix | | ||
jmhsieh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| |-------|----------|-----| | ||
| | **NumPy 1.x vs 2.x** | `ArrowInvalid`, `ValueError: cannot convert`, serialization failures | Pin `numpy==1.26.4` | | ||
| | **PyTorch mismatch** | Model loading failures, CUDA errors, unexpected inference results | Pin to matching `torch` version | | ||
| | **attrs mismatch** | `TypeError: Enum.__new__() missing 1 required positional argument` | Pin `attrs` to local version | | ||
| | **Missing package** | `ModuleNotFoundError: No module named 'xyz'` | Add package to manifest | | ||
|
|
||
| #### Fixing Package Mismatches | ||
|
|
||
| **Option 1: Manifest pip Dependencies** | ||
|
|
||
| Specify packages in a Geneva manifest for a quick fix: | ||
|
|
||
| <CodeGroup> | ||
| ```python Python icon="python" | ||
| from geneva.manifest.builder import GenevaManifestBuilder | ||
|
|
||
| manifest = ( | ||
| GenevaManifestBuilder.create("my-manifest") | ||
| .pip([ | ||
| "numpy==1.26.4", | ||
| "torch==2.0.1", | ||
| "attrs==23.2.0", | ||
| ]) | ||
| .build() | ||
| ) | ||
|
|
||
| # Then use with db.context() | ||
| conn = geneva.connect("s3://my-bucket/my-db") | ||
| conn.define_manifest("my-manifest", manifest) | ||
| with conn.context(cluster="my-cluster", manifest="my-manifest"): | ||
| conn.open_table("my-table").backfill("my-column") | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| *Pros*: Quick, reusable across sessions, stored with your database. | ||
|
|
||
| *Cons*: Slower startup (downloads packages), may not work for complex dependencies. | ||
|
|
||
| **Option 2: Custom Ray Worker Image** | ||
|
|
||
| For KubeRay deployments, build a custom worker image: | ||
|
|
||
| <CodeGroup> | ||
| ```dockerfile Dockerfile icon="docker" | ||
| # Dockerfile.ray-worker | ||
| FROM rayproject/ray:2.30.0-py311 | ||
|
|
||
| # Install exact versions | ||
| RUN pip install \ | ||
| numpy==1.26.4 \ | ||
| torch==2.0.1 \ | ||
| attrs==23.2.0 \ | ||
| geneva==0.8.0 | ||
|
|
||
| # Copy any custom packages | ||
| COPY ./my_udfs /app/my_udfs | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| Then reference in RayCluster spec: | ||
|
|
||
| <CodeGroup> | ||
| ```yaml Kubernetes icon="kubernetes" | ||
| spec: | ||
| workerGroupSpecs: | ||
| - template: | ||
| spec: | ||
| containers: | ||
| - image: your-registry/ray-worker:latest | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| *Pros*: Fastest startup, reproducible. | ||
|
|
||
| *Cons*: Requires image build/push workflow. | ||
|
|
||
| **Option 3: Conda Environment** | ||
|
|
||
| Use a conda environment on workers via the cluster builder: | ||
|
|
||
| <CodeGroup> | ||
| ```python Python icon="python" | ||
| from geneva.cluster.builder import GenevaClusterBuilder | ||
|
|
||
| cluster = ( | ||
| GenevaClusterBuilder.create("my-cluster") | ||
| .ray_init_kwargs({ | ||
| "runtime_env": {"conda": "environment.yml"} | ||
| }) | ||
| .build() | ||
| ) | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| Or specify conda channels and dependencies inline: | ||
|
|
||
| <CodeGroup> | ||
| ```python Python icon="python" | ||
| cluster = ( | ||
| GenevaClusterBuilder.create("my-cluster") | ||
| .ray_init_kwargs({ | ||
| "runtime_env": { | ||
| "conda": { | ||
| "channels": ["conda-forge"], | ||
| "dependencies": [ | ||
| "python=3.10", | ||
| "ffmpeg<8", | ||
| "torchvision=0.22.1" | ||
| ] | ||
| }, | ||
| "config": {"eager_install": True} | ||
| } | ||
| }) | ||
| .build() | ||
| ) | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| *Pros*: Best for complex dependencies with native libraries (ffmpeg, CUDA). | ||
|
|
||
| *Cons*: Slower environment creation, requires conda on workers. | ||
|
|
||
| ## API Reference | ||
|
|
||
| For detailed API documentation on the environment comparison functions, see the [Geneva Diagnostics API Reference](https://lancedb.github.io/geneva/api/diagnostics). | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.