Skip to content

fix(workers): preserve Marker GPU allocation from Ray resources - #452

Closed
hedhoud wants to merge 1 commit into
refactor/hexagonalfrom
fix/451-marker-gpu-ray-resources
Closed

fix(workers): preserve Marker GPU allocation from Ray resources#452
hedhoud wants to merge 1 commit into
refactor/hexagonalfrom
fix/451-marker-gpu-ray-resources

Conversation

@hedhoud

@hedhoud hedhoud commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Context: Phase 11 made Marker PDF parsing much slower because GPU allocation can be decided from a Ray actor that does not itself own GPU resources.\n\nThis keeps Marker worker GPU requests based on Ray cluster resources, while still falling back safely when GPU resources are absent. That prevents PDF serialization from silently becoming CPU-bound on GPU deployments.\n\nCloses #451.

Summary by CodeRabbit

  • Bug Fixes
    • Improved GPU detection for the marker parser: non-positive GPU requests are treated as zero, and GPU honoring now checks cluster-reported resources with a safer fallback when cluster queries fail.
  • Tests
    • Added a unit test covering GPU-detection behavior and refactored an existing dispatcher test for clearer async mocking.

@coderabbitai

coderabbitai Bot commented Jun 8, 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.yaml

Review profile: CHILL

Plan: Pro

Run ID: eeb474d8-81b0-41f0-87e6-93c63431f69d

📥 Commits

Reviewing files that changed from the base of the PR and between b95d4f8 and 4f263b2.

📒 Files selected for processing (3)
  • openrag/services/workers/parsers/marker_workers.py
  • tests/unit/services/workers/parsers/test_marker_workers.py
  • tests/unit/services/workers/test_dispatcher.py
✅ Files skipped from review due to trivial changes (1)
  • tests/unit/services/workers/test_dispatcher.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • openrag/services/workers/parsers/marker_workers.py
  • tests/unit/services/workers/parsers/test_marker_workers.py

📝 Walkthrough

Walkthrough

_marker_num_gpus now returns 0 for non-positive requests, checks Ray's cluster_resources for "GPU" when configured >0, and falls back to torch.cuda.is_available() on Ray errors; tests added to validate the Ray-path; a dispatcher test had AsyncMock formatting adjusted.

Changes

Marker GPU Allocation Robustness

Layer / File(s) Summary
GPU allocation with Ray cluster resource fallback
openrag/services/workers/parsers/marker_workers.py
_marker_num_gpus short-circuits non-positive requests, queries ray.cluster_resources() for "GPU" when >0, and on exceptions logs a warning and uses torch.cuda.is_available() as fallback.
Ray cluster resource fallback test
tests/unit/services/workers/parsers/test_marker_workers.py
New unit test monkeypatches torch.cuda.is_available and ray.cluster_resources to assert _marker_num_gpus returns the configured GPU fraction when CUDA is hidden but Ray reports GPUs.
Dispatcher test AsyncMock reformatting
tests/unit/services/workers/test_dispatcher.py
Formatting change: multi-line AsyncMock(...) setup for mocked async repo/vector-store calls; call ordering and behavior unchanged.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I peeked where Ray keeps its shining cores,
And nudged Marker to count those hidden stores.
When CUDA's shy and the cluster still gleams,
Workers wake up and reclaim their dreams. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing Marker GPU allocation by preserving Ray resource detection, which is the core objective of this PR.
Linked Issues check ✅ Passed The code changes directly address issue #451 by implementing Ray cluster resource detection for GPU allocation in _marker_num_gpus(), with fallback to torch.cuda.is_available().
Out of Scope Changes check ✅ Passed All changes are directly scoped to the GPU allocation issue: marker_workers.py implements the fix, test_marker_workers.py adds validation, and test_dispatcher.py contains only formatting changes to existing tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/451-marker-gpu-ray-resources

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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.

🧹 Nitpick comments (1)
openrag/services/workers/parsers/marker_workers.py (1)

27-34: ⚡ Quick win

Consider adding observability to the exception fallback path.

When ray.cluster_resources() raises an exception and the function falls back to the CUDA check, there's no log indicating this occurred. Adding a warning log would help operators understand GPU allocation decisions and diagnose issues when Ray cluster resources are unavailable.

📊 Suggested addition for observability
 def _marker_num_gpus(config) -> float:
     requested_gpus = config.loader.marker_num_gpus
     if requested_gpus <= 0:
         return 0
     try:
         return requested_gpus if ray.cluster_resources().get("GPU", 0) > 0 else 0
     except Exception:
+        logger.warning(
+            "Failed to query Ray cluster resources for GPU detection; falling back to CUDA check"
+        )
         return requested_gpus if torch.cuda.is_available() else 0
🤖 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 `@openrag/services/workers/parsers/marker_workers.py` around lines 27 - 34, In
_marker_num_gpus, add a warning log in the except block so operators know
ray.cluster_resources() failed and the code is falling back to
torch.cuda.is_available(); capture and include the exception details in the log
(e.g., use logging.getLogger(__name__).warning or the module's existing logger)
and then proceed to return the existing fallback value based on
torch.cuda.is_available() and config.loader.marker_num_gpus; reference symbols:
_marker_num_gpus, config.loader.marker_num_gpus, ray.cluster_resources(),
torch.cuda.is_available().

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.

Nitpick comments:
In `@openrag/services/workers/parsers/marker_workers.py`:
- Around line 27-34: In _marker_num_gpus, add a warning log in the except block
so operators know ray.cluster_resources() failed and the code is falling back to
torch.cuda.is_available(); capture and include the exception details in the log
(e.g., use logging.getLogger(__name__).warning or the module's existing logger)
and then proceed to return the existing fallback value based on
torch.cuda.is_available() and config.loader.marker_num_gpus; reference symbols:
_marker_num_gpus, config.loader.marker_num_gpus, ray.cluster_resources(),
torch.cuda.is_available().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 913f814d-55e6-440d-9a11-e6b2517d5015

📥 Commits

Reviewing files that changed from the base of the PR and between e8a5580 and b95d4f8.

📒 Files selected for processing (2)
  • openrag/services/workers/parsers/marker_workers.py
  • tests/unit/services/workers/parsers/test_marker_workers.py

@Ahmath-Gadji

Copy link
Copy Markdown
Collaborator

@hedhoud, this fix is already included in the refactor/hexagonal branch (see commit from PR #444: a0fba51).

I think this PR can be closed since the change has already been implemented.

@hedhoud
hedhoud deleted the fix/451-marker-gpu-ray-resources branch August 31, 2026 08:36
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.

2 participants