Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion packages/server/engine-lib/rocketlib-python/lib/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,34 @@ def _save_hash(hash_file: str, hash_value: str):
f.write(hash_value)


def _cpu_only() -> bool:
"""True when this host should resolve CPU-only wheels.

Opt-in via ``ROCKETRIDE_CPU_ONLY_DEPS=1``. Deliberately NOT auto-detected:
guessing "no GPU visible, therefore CPU" would silently downgrade a machine
whose driver simply is not loaded yet, and a silent downgrade of an
inference host is far worse than an oversized install.
"""
return os.environ.get('ROCKETRIDE_CPU_ONLY_DEPS', '').strip().lower() in ('1', 'true', 'yes')


def _combine_requirements(file_paths: list[str], output_path: str):
"""Concatenate all requirement files into one."""
with open(output_path, 'w', encoding='utf-8') as out:
if _cpu_only():
# PyPI's default `torch` wheel is the CUDA build, which drags in
# ~13 nvidia-* packages plus triton. On the cloud ALB that measured
# 6.6 GB of the pod's 8.2 GB site-packages — on an m7i-flex.large
# with no GPU, no /dev/nvidia*, and no models (inference goes out to
# the H100). It was downloaded and written on every pod start and
# never once executed. See rocketride-server #1697.
#
# Pointing at the CPU index makes torch resolve to +cpu (~200 MB)
# and the nvidia-* packages are never selected at all. Verified with
# `uv pip compile` over the four nodes that pull torch transitively:
# 119 packages / 13 nvidia-* -> 105 packages / 0 nvidia-*.
out.write('# CPU-only resolve: ROCKETRIDE_CPU_ONLY_DEPS is set.\n')
out.write('--extra-index-url https://download.pytorch.org/whl/cpu\n\n')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
for path in file_paths:
out.write(f'# Source: {path}\n')
with open(path, 'r', encoding='utf-8') as inp:
Expand Down Expand Up @@ -782,8 +807,17 @@ def _write_excludes_file() -> str:
"""
excludes_path = os.path.join(engine_cache_dir(), 'excludes.txt')
excludes = 'uv\n'
if platform.system() != 'Darwin':
# The onnxruntime exclusion keys on OS, which is not the question being
# asked. "Not a Mac" was used as a proxy for "has CUDA", and it is wrong on
# every Linux box without a GPU — including the cloud ALB, where it forces
# the GPU build and blocks the CPU one from ever being installed. Excluding
# it there would defeat the CPU-only resolve above, so honour that flag.
if platform.system() != 'Darwin' and not _cpu_only():
excludes += 'onnxruntime\n'
elif _cpu_only():
# Mirror image: on a CPU-only host the GPU build is the one that must
# not win, for the same clobbering reason the original comment gives.
excludes += 'onnxruntime-gpu\n'
Comment on lines +810 to +820

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the file and inspect the relevant function and surrounding documentation/tests.
sed -n '760,840p' packages/server/engine-lib/rocketlib-python/lib/depends.py

printf '\n--- _cpu_only definition/usages ---\n'
rg -n "def _cpu_only|_cpu_only\(|cpu_only|onnxruntime-gpu|excludes" packages/server/engine-lib/rocketlib-python/lib/depends.py

printf '\n--- related docs/comments ---\n'
rg -n -C 3 "CUDA|cpu|Darwin|onnxruntime-gpu|onnxruntime" packages/server/engine-lib/rocketlib-python/lib/depends.py packages/server/engine-lib -g '*.py' -g '*.md' | head -n 200

Repository: rocketride-org/rocketride-server

Length of output: 15816


Keep the CPU-only exclusion OS-gated as documented.

_write_excludes_file() says the onnxruntime exclusions apply to non-Darwin hosts, but elif _cpu_only() excludes onnxruntime-gpu on Darwin too. If macOS CPU-only hosts may require the GPU build, either gate this branch with platform.system() != 'Darwin' or update the docstring/comments to make macOS behavior an explicit contract.

🧰 Tools
🪛 ast-grep (0.45.0)

[warning] 820-820: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(excludes_path, 'w', encoding='utf-8')
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(open-filename-from-request)

🤖 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 `@packages/server/engine-lib/rocketlib-python/lib/depends.py` around lines 810
- 820, Update the onnxruntime-gpu exclusion branch in _write_excludes_file to
remain gated by platform.system() != 'Darwin', matching the documented
non-Darwin scope; preserve the existing CPU-only behavior on non-Darwin hosts.

with open(excludes_path, 'w', encoding='utf-8') as f:
f.write(excludes)
return excludes_path
Expand Down
Loading