Skip to content

perf(rl): add opt-in CUDA image preprocessing for HIL-SERL - #4916

Draft
Han-Shen-math wants to merge 1 commit into
huggingface:mainfrom
Han-Shen-math:codex/hil-serl-cuda-preprocessing
Draft

Han-Shen-math wants to merge 1 commit into
huggingface:mainfrom
Han-Shen-math:codex/hil-serl-cuda-preprocessing

Conversation

@Han-Shen-math

Copy link
Copy Markdown

Summary / Motivation

The HIL-SERL observation pipeline converts and normalizes camera frames on CPU, then transfers float32 images after crop/resize. This adds an opt-in image_device setting: transfer uint8 frames to the selected device first, then convert layout and normalize there. The real-robot pipeline's existing crop/resize step follows the image device. CPU remains the default.

Related issues

What changed

  • Add env.processor.image_preprocessing.image_device and pass it to both the real-robot and gym_hil observation processors.
  • Serialize the processor's image device; old empty processor configs still load as CPU.
  • Keep state tensors on CPU through the existing state/kinematics steps and retain the final device processor. Preserve the existing MPS crop/resize fallback and simulator image sizes.
  • Use a synchronous image transfer, avoiding additional camera-buffer lifetime requirements.

How was this tested (or how to run locally)

On macOS arm64, Python 3.12.14, PyTorch 2.11.0:

pytest -q -rs tests/processor/test_observation_processor.py tests/rl/test_gym_manipulator_processors.py

39 passed, 3 skipped because CUDA is unavailable. This covers unchanged CPU outputs, saved/legacy configs, both factory branches, CPU crop/resize, and the existing MPS crop/resize fallback. CUDA tests are included for image placement, CPU state placement and crop/resize parity, but were not executed locally.

All applicable pre-commit hooks passed on the six changed files, including mypy. No training, CUDA performance benchmark, or robot rollout was run.

To try on a CUDA machine, set this field in an existing HIL-SERL environment config:

{
  "env": {
    "processor": {
      "image_preprocessing": {
        "image_device": "cuda"
      }
    }
  }
}

Keep the other environment settings and use the same CUDA device as the policy/final processor. Measure after warmup and synchronize CUDA before and after timing. This PR makes no measured speedup or control-frequency claim.

Checklist

Reviewer notes

Draft pending real CUDA validation and maintainer feedback on the configuration/API. Implemented and reviewed with significant Codex assistance.

@s1lent4gnt s1lent4gnt self-assigned this Oct 11, 2026

This branch has not been deployed

No deployments
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