Skip to content

Latest commit

 

History

History
147 lines (103 loc) · 3.23 KB

File metadata and controls

147 lines (103 loc) · 3.23 KB

Packaging Your Policy Server with Docker

Overview

This guide explains how to package your Python policy server into a Docker container, so that it can be run and tested consistently by instructors or TAs.


0. Local sanity check (before Docker)

Before you build a Docker image, make sure your policy server can:

  1. start successfully, and
  2. respond to at least one inference request.

0.1 Start the server (TD-MPC2 checkpoint example)

From the repo root:

cd grasp-cube-sample
python serve_policy.py \
  --host 0.0.0.0 --port 8000 \
  --policy.checkpoint rl/tdmpc2/step_00256000.pt \
  --policy.device auto

Notes:

  • If you want a fast CPU-only smoke test, add --policy.no-mpc (or reduce --policy.num-samples).
  • Your server should always listen on 0.0.0.0 (same requirement as Docker).

0.2 Send a single inference request

In another terminal:

cd grasp-cube-sample
python - <<'PY'
import numpy as np
from env_client.websocket_client_policy import WebsocketClientPolicy

client = WebsocketClientPolicy("127.0.0.1", 8000)
client.reset()
obs = {
  "images": {
    "front": (np.random.rand(480, 640, 3) * 255).astype(np.uint8),
    "left_wrist": (np.random.rand(480, 640, 3) * 255).astype(np.uint8),
    "right_wrist": (np.random.rand(480, 640, 3) * 255).astype(np.uint8),
  },
  "states": {
    "left_arm": np.random.randn(6).astype(np.float32),
    "right_arm": np.random.randn(6).astype(np.float32),
  },
}
resp = client.infer(obs)
print("action shape:", np.asarray(resp["action"]).shape)
print("server_timing:", resp.get("server_timing"))
PY

1. Project Structure

Your project may look like:

student_repo/
├── serve_policy.py
└── ...other files

2. Dockerfile Template

Create a file named Dockerfile in the root of your repo:

# Use a proper image
FROM ...

# Set working directory
WORKDIR /app

# Copy the needed files
COPY ...

# Install system dependencies if needed
RUN apt-get update && apt-get install -y \
    git \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
RUN ...

# Default command to run your policy server
CMD ["python", "serve_policy.py"]

Make sure your server listens on 0.0.0.0, not 127.0.0.1.


3. Build Docker Image

Run the following in your project directory:

docker build -t <your-policy-server> .

4. Run the Server

The instructor or TA can run the container and map any host port to the container port:

docker run --rm --gpus all -p 8000:8000 -v $(pwd)/models:/models <your-policy-server> [args for serve_policy.py]
  • Replace 8000 with any desired port.
  • The server inside the container must listen on 0.0.0.0.
  • run with GPU support (requires NVIDIA Container Toolkit)

5. Submission Guidelines

  1. Provide a Dockerfile in your repository, or a pre-built Docker image file (.tar).
  2. Make sure your server (serve_policy.py) listens on 0.0.0.0 so it can accept connections from outside the container.
  3. The image should be runnable by the TA without additional setup.
  • Export image as .tar:
docker save -o your-policy-server.tar your-policy-server
  • TA can import and run:
docker load -i your-policy-server.tar
docker run ...