Skip to content

Skip unsupported JAX devices during module preload#1634

Open
fallintoplace wants to merge 2 commits into
NVIDIA:mainfrom
fallintoplace:agent/fix-jax-device-preload
Open

Skip unsupported JAX devices during module preload#1634
fallintoplace wants to merge 2 commits into
NVIDIA:mainfrom
fallintoplace:agent/fix-jax-device-preload

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 9, 2026

Copy link
Copy Markdown

Summary

  • Centralize ALL_DEVICES module preloading for FfiKernel and FfiCallable.
  • Skip unsupported JAX platforms when device_from_jax() raises its documented RuntimeError.
  • Add regression coverage for unsupported devices appearing before and after a CUDA device.

Root cause

The preload loops caught conversion failures but continued into dev.is_cuda. That could read an unbound local on the first unsupported device or reuse the previous device on later failures.

Validation

  • Targeted JAX preload regression passes with CPU JAX 0.5+.
  • Ruff lint and format checks pass.
  • Python compilation and git diff --check pass.

Summary by CodeRabbit

  • Bug Fixes
    • Improved JAX interop behavior when preloading modules across devices.
    • Unsupported devices are now skipped, ensuring supported CUDA devices load correctly.
    • Ensured consistent preload behavior for both FFI kernels and FFI callables.
  • Tests
    • Added coverage for skipping unsupported devices during all-devices preload when JAX is available.

Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 4c5d14c8-c3d1-4343-b7b5-a8d8f5acb0af

📥 Commits

Reviewing files that changed from the base of the PR and between c3e52be and 7b2b881.

📒 Files selected for processing (1)
  • warp/tests/interop/test_jax.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • warp/tests/interop/test_jax.py

📝 Walkthrough

Walkthrough

The change centralizes JAX device module preloading, skips devices that cannot map to Warp, updates both FFI call paths, and adds coverage for mixed supported and unsupported devices.

Changes

JAX FFI preload handling

Layer / File(s) Summary
Shared device preload helper
warp/_src/jax/ffi.py
Adds shared CUDA-device preloading and uses it from FfiKernel.__call__ and FfiCallable.__call__.
Unsupported-device preload test
warp/tests/interop/test_jax.py
Adds and registers a mocked test confirming unsupported devices are skipped and supported CUDA devices load once.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: skipping unsupported JAX devices during module preload.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a bug in the JAX FFI preload loop where catching an exception and using pass left dev either unbound (on the first failure) or holding a stale value from the previous iteration. The fix centralizes the loop into a _preload_module_on_all_devices() helper with a proper continue, and narrows the caught exception type from Exception to RuntimeError to match the documented contract of device_from_jax.

  • Bug fix: Replaced except Exception: pass + fallthrough with except RuntimeError: continue so an unsupported device can never allow dev.is_cuda to access an unbound or stale variable.
  • DRY refactor: Both FfiKernel and FfiCallable share one helper function instead of duplicating the loop.
  • Regression test: New test exercises both orderings (unsupported device before and after a CUDA device) using mocks, confirming module.load is called exactly once on the supported CUDA device.

Confidence Score: 5/5

Safe to merge — the change is a narrow, well-tested bug fix with no behavioural regressions for the supported path.

The only logic change is replacing except Exception: pass + fallthrough with except RuntimeError: continue, which is strictly safer: it eliminates the unbound/stale dev reference and aligns the caught type with the documented contract of device_from_jax. The helper is exercised by a new regression test that covers both device orderings. No other call sites are affected.

No files require special attention.

Important Files Changed

Filename Overview
warp/_src/jax/ffi.py Extracts duplicate ALL_DEVICES preload loops into _preload_module_on_all_devices(); fixes unbound/stale dev bug by using continue instead of pass after catching RuntimeError.
warp/tests/interop/test_jax.py Adds regression test covering both orderings of unsupported/CUDA devices using mocks; correctly verifies module.load is called exactly once on the supported device.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[_preload_module_on_all_devices] --> B[iterate jax.local_devices]
    B --> C{device_from_jax}
    C -->|RuntimeError| D[continue - skip device]
    D --> B
    C -->|returns dev| E{dev.is_cuda?}
    E -->|No| B
    E -->|Yes| F[module.load dev]
    F --> B
    B -->|done| G[return]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[_preload_module_on_all_devices] --> B[iterate jax.local_devices]
    B --> C{device_from_jax}
    C -->|RuntimeError| D[continue - skip device]
    D --> B
    C -->|returns dev| E{dev.is_cuda?}
    E -->|No| B
    E -->|Yes| F[module.load dev]
    F --> B
    B -->|done| G[return]
Loading

Reviews (2): Last reviewed commit: "Capitalize JAX in preload test message" | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
warp/_src/jax/ffi.py (1)

69-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a Google-style docstring for the helper.

This helper encodes an important exception contract—unsupported JAX platforms raise RuntimeError and are skipped—but currently documents neither its arguments nor that behavior.

As per coding guidelines, Python files must follow Google-style docstrings.

Proposed documentation
 def _preload_module_on_all_devices(module, jax):
+    """Preload a module on local JAX devices that map to CUDA.
+
+    Args:
+        module: Warp module to preload.
+        jax: JAX module-like object providing ``local_devices()``.
+
+    A ``RuntimeError`` from JAX-to-Warp device conversion is treated as an
+    unsupported platform and skipped.
+    """
     for d in jax.local_devices():
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@warp/_src/jax/ffi.py` around lines 69 - 79, Add a Google-style docstring to
`_preload_module_on_all_devices` documenting the `module` and `jax` arguments,
the helper’s device-preloading behavior, and that `RuntimeError` from
unsupported JAX platforms is caught and skipped.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@warp/tests/interop/test_jax.py`:
- Line 865: Update the skip message in the `_jax_version` test decorator to use
the correctly capitalized name, changing “Jax version too old” to “JAX version
too old”.

---

Nitpick comments:
In `@warp/_src/jax/ffi.py`:
- Around line 69-79: Add a Google-style docstring to
`_preload_module_on_all_devices` documenting the `module` and `jax` arguments,
the helper’s device-preloading behavior, and that `RuntimeError` from
unsupported JAX platforms is caught and skipped.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 64d1395a-2a94-4107-ad07-7a4c12f2fb15

📥 Commits

Reviewing files that changed from the base of the PR and between 8667276 and c3e52be.

📒 Files selected for processing (2)
  • warp/_src/jax/ffi.py
  • warp/tests/interop/test_jax.py

Comment thread warp/tests/interop/test_jax.py Outdated
Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant