Skip to content

feat: add gym env prefetch for baking server venvs into the container - #2255

Merged
kajalj22 merged 5 commits into
add-docker-containerfrom
add-prefetch-venvs
Aug 4, 2026
Merged

kajalj22 merged 5 commits into
add-docker-containerfrom
add-prefetch-venvs

Conversation

@kajalj22

@kajalj22 kajalj22 commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2161 (standalone Gym container). Implements gym env prefetch — a proper config-driven CLI command for pre-warming server venvs at container build time, similar to how RL's prefetch_venvs.py works.

What this replaces

PR #2161 has NEMO_GYM_PREFETCH_SERVERS which takes space-separated directory paths. This PR replaces it with NEMO_GYM_PREFETCH_CONFIGS which takes Gym config files — the same format as gym env start. This is the approach Ananth described in the review.

How it works

gym env prefetch "+config_paths=[config1.yaml,config2.yaml]"
  1. Parses configs the same way gym env start does
  2. For each server found in the config, calls setup_env_command() — creates the venv and installs deps serially
  3. Exits — no Ray initialised, no server processes started

Serial installation reduces uv cache size (same reasoning as dry_run mode in RunHelper.start).

Dockerfile usage

# Pre-warm venvs for your server configs at build time:
docker buildx build \
  --build-arg NEMO_GYM_PREFETCH_CONFIGS="responses_api_models/local_vllm_model/configs/local_vllm_model.yaml,resources_servers/math/configs/math.yaml" \
  -f docker/Dockerfile .

Changes

  • nemo_gym/cli/env.py — gym env prefetch command
  • docker/Dockerfile — NEMO_GYM_PREFETCH_CONFIGS replaces NEMO_GYM_PREFETCH_SERVERS

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Jul 31, 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.

kajalj22 and others added 2 commits August 3, 2026 09:41
Placeholder for 'gym env prefetch' implementation.
Addresses review feedback from #2161.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Signed-off-by: Kajal Jain <[email protected]>
Implements 'gym env prefetch' — accepts the same config format as
'gym env start', installs each server's venv serially via
setup_env_command(), and exits without starting any server process
or initialising Ray.

This mirrors RL's prefetch_venvs.py approach: accepts a list of
configs, does a dry install of deps for each configured server, and
bakes the venvs into the container image so no network access is
needed at runtime.

Dockerfile updated to use NEMO_GYM_PREFETCH_CONFIGS (comma-separated
config paths) instead of NEMO_GYM_PREFETCH_SERVERS (space-separated
directory paths), enabling config-driven prefetch consistent with the
rest of the Gym CLI.

Example:
  docker buildx build \
    --build-arg NEMO_GYM_PREFETCH_CONFIGS="responses_api_models/local_vllm_model/configs/local_vllm_model.yaml" \
    -f docker/Dockerfile .

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Signed-off-by: Kajal Jain <[email protected]>
@kajalj22
kajalj22 force-pushed the add-prefetch-venvs branch from d6029b3 to 51cc88e Compare August 3, 2026 14:43
@kajalj22
kajalj22 changed the base branch from main to add-docker-container August 3, 2026 14:43
@kajalj22
kajalj22 marked this pull request as ready for review August 3, 2026 15:03
@kajalj22
kajalj22 requested a review from a team as a code owner August 3, 2026 15:03
kajalj22 and others added 2 commits August 3, 2026 10:07
Two blockers from code review:
1. prefetch() was defined but never added to the COMMANDS dispatch
   table in main.py — 'gym env prefetch' raised unknown-command.
   Added entry mirroring 'env start' flags (CONFIG, BENCHMARK,
   ENVIRONMENT, RESOURCES_SERVER_CONFIG, MODEL_TYPE, SEARCH_DIR).

2. process.communicate() discarded the return code — a failed
   'uv pip install' would print "Prefetch complete." with exit 0,
   silently baking a broken venv into the container image.
   Now uses process.wait() and raises SystemExit on non-zero,
   so the Docker build fails loudly if any install fails.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Signed-off-by: Kajal Jain <[email protected]>
If the same server dir appears under multiple top-level config keys
(e.g. two configs both referencing local_vllm_model), the previous
implementation would run setup_env_command twice against the same
.venv. Track seen dir_paths in a set and skip duplicates — mirrors
RL's prefetch_venvs.py which groups by py_executable to avoid
redundant installs.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Signed-off-by: Kajal Jain <[email protected]>
@kajalj22 kajalj22 added the r0.5.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge. label Aug 3, 2026
@kajalj22
kajalj22 merged commit 5c4b5bf into add-docker-container Aug 4, 2026
15 of 16 checks passed
@kajalj22
kajalj22 deleted the add-prefetch-venvs branch August 4, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r0.5.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant