Free Lab Series 06: Learning by Consequence — Deep Reinforcement Learning & Policy Gradients
This dedicated lab series translates Hugging Face Learn modules and official documentation into ten step-by-step, reproducible engineering exercises that run cleanly on a standard Debian 12/13 CPU workstation or rootless OCI container—with zero CUDA or paid GPU subscription required.
Authored by Imad Soltani (human author, sole release authority) with Antigravity (Google DeepMind, non-human co-author).
1. Series Architecture, Hardware & Hugging Face Curriculum Linkage
- Permanent Series ID:
LAB-FREE-06· Cost / Tier (11E): Hugging Face Free ($0/mo) - Hardware Profile (10A): Hybrid: CPU-only for CartPole/LunarLander (4 vCPU, 8 GB RAM) OR 1x 8 GB VRAM GPU / ZeroGPU Free (~5 min/day) for Atari/MuJoCo
- Hugging Face Learn (10F): https://huggingface.co/learn/deep-rl-course
- Hugging Face Docs (10F): https://huggingface.co/docs/hub/models-libraries
- GitHub Lab Sources: github.com/ximad/solarisk/lab/v106.0/free/series_06_deep-rl-policy-gradients
7. Self-Check Comprehension Gate
Why does this lab series enforce a non-root multi-stage OCI container and idempotent Debian setup?
Multi-stage builds strip compilers and build secrets from the runtime layer, non-root UID execution limits blast radius if a dependency or prompt-triggered tool misbehaves, and idempotent Debian setup ensures repeatable runs across workstations and CI without hidden host drift.
How does the 30/30/30/10 progression split map to operational readiness?
Labs 01–03 establish clean data and deterministic baselines (Beginner), Labs 04–06 integrate adaptation, paired evaluation, and OCI packaging (Practitioner), Labs 07–09 harden latency, security boundaries, and governance compliance (Expert), and Lab 10 consolidates artifacts and primary documentation links (Capstone).
Complete 10-Lab Progression (30% Beginner · 30% Practitioner · 30% Expert · 10% Capstone & Resources)
| ID (10B) | Lab Module | Level | Duration | Cost / Tier | Expected Result & Capability (10F) |
|---|---|---|---|---|---|
| LAB-FREE-06-01 | Environment Bootstrap, Hub Auth & First Reproducible Pipeline | Beginner | 35 min | Hugging Face Free ($0/mo) | Verified Debian virtual environment & OCI container returning deterministic Hugging Face output. Capability (10F): After completing LAB-FREE-06-01, the reader can design & deploy reproducible 'environment bootstrap, hub auth & first reproducible pipeline' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-02 | Data Loading, Schema Inspection & SafeTensors Integrity Verification | Beginner | 40 min | Hugging Face Free ($0/mo) | Reproducible dataset split checksummed with zero pickle execution risk. Capability (10F): After completing LAB-FREE-06-02, the reader can design & deploy reproducible 'data loading, schema inspection & safetensors integrity verification' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-03 | Baseline Inference, Latency Profiling & Memory Measurement | Beginner | 45 min | Hugging Face Free ($0/mo) | Logged p50/p95 latency and RAM/VRAM footprint baseline in JSON. Capability (10F): After completing LAB-FREE-06-03, the reader can design & deploy reproducible 'baseline inference, latency profiling & memory measurement' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-04 | Task Adaptation, Prompt/Context Engineering & Structured Outputs | Practitioner | 50 min | Hugging Face Free ($0/mo) | Validated schema-compliant task output improving baseline accuracy by >= 10%. Capability (10F): After completing LAB-FREE-06-04, the reader can design & deploy reproducible 'task adaptation, prompt/context engineering & structured outputs' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-05 | Evaluation Harness, Paired Benchmarking & Error Analysis | Practitioner | 55 min | Hugging Face Free ($0/mo) | Reproducible paired evaluation table separating genuine gains from prompt noise. Capability (10F): After completing LAB-FREE-06-05, the reader can design & deploy reproducible 'evaluation harness, paired benchmarking & error analysis' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-06 | Packaging as an OCI Non-Root Service & Gradio/API Endpoint | Practitioner | 60 min | Hugging Face Free ($0/mo) | Hardened non-root OCI image running cleanly under Docker, containerd, and CRI-O. Capability (10F): After completing LAB-FREE-06-06, the reader can design & deploy reproducible 'packaging as an oci non-root service & gradio/api endpoint' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-07 | Performance Optimization: Quantization, Batching & Hardware Sizing | Expert | 65 min | Hugging Face Free ($0/mo) | Measured memory reduction and throughput gain under controlled latency SLOs. Capability (10F): After completing LAB-FREE-06-07, the reader can design & deploy reproducible 'performance optimization: quantization, batching & hardware sizing' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-08 | Adversarial Security Testing, Prompt-Injection & Policy Sandboxing | Expert | 70 min | Hugging Face Free ($0/mo) | Zero unauthorized tool/file egress under automated red-team test suite. Capability (10F): After completing LAB-FREE-06-08, the reader can design & deploy reproducible 'adversarial security testing, prompt-injection & policy sandboxing' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-09 | Governance, Model Card Provenance & EU AI Act Transparency Audit | Expert | 75 min | Hugging Face Free ($0/mo) | Complete Model Card + Article 50 / SPDX license disclosure bundle. Capability (10F): After completing LAB-FREE-06-09, the reader can design & deploy reproducible 'governance, model card provenance & eu ai act transparency audit' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
| LAB-FREE-06-10 | Series Capstone Architecture Review, Concept Recap & Upstream URLs | Synthesis & Resources (10%) | 45 min | Hugging Face Free ($0/mo) | Consolidated portfolio summary, updated Semantics glossary entries, and curated Hugging Face Learn/Docs syllabus. Capability (10F): After completing LAB-FREE-06-10, the reader can design & deploy reproducible 'series capstone architecture review, concept recap & upstream urls' workflows aligned with https://huggingface.co/learn/deep-rl-course and https://huggingface.co/docs/hub/models-libraries. |
Debian 12/13 Commented Idempotent Setup & Python Runner (10C)
setup.sh (Debian 12/13 Bash)
#!/usr/bin/env bash
# ==============================================================================
# SolarisK Lab Series Setup — LAB-FREE-06 (deep-rl-policy-gradients)
# Compatible with latest stable Debian Linux (Debian 12 Bookworm / 13 Trixie)
# Idempotent setup script with inline comments and destructive-action safety.
# ==============================================================================
set -euo pipefail
# Define isolated project virtual environment path (never pollutes global system Python)
LAB_VENV="${HOME}/.venvs/solarisk-free-06"
# Warn before any destructive reset requested via --reset
if [[ "${1:-}" == "--reset" ]]; then
echo "[WARNING] Destructive operation: removing existing virtualenv ${LAB_VENV} in 5s (Ctrl+C to abort)..."
sleep 5
rm -rf "${LAB_VENV}"
fi
# Verify Debian Python 3 & venv availability (idempotent check)
if ! command -v python3 >/dev/null 2>&1; then
echo "[ERROR] python3 not found. Install via: sudo apt-get update && sudo apt-get install -y python3 python3-venv python3-pip"
exit 1
fi
# GPU host check (required ONLY for NVIDIA GPU labs; CPU-only labs skip this cleanly)
if command -v nvidia-smi >/dev/null 2>&1; then
echo '[INFO] NVIDIA GPU detected:'
nvidia-smi --query-gpu=name,memory.total --format=csv,noheader
else
echo '[INFO] No local NVIDIA GPU detected — falling back to CPU or Hugging Face ZeroGPU Spaces.'
fi
# Create virtual environment idempotently if missing
if [[ ! -d "${LAB_VENV}" ]]; then
echo "[SETUP] Creating isolated Python virtual environment at ${LAB_VENV}..."
python3 -m venv "${LAB_VENV}"
fi
# Upgrade pip and install pinned baseline Hugging Face client packages inside the venv
"${LAB_VENV}/bin/pip" install --quiet --upgrade pip
"${LAB_VENV}/bin/pip" install --quiet huggingface_hub safetensors
echo "[READY] Activate with: source ${LAB_VENV}/bin/activate"
echo "[READY] Run lab harness: ${LAB_VENV}/bin/python3 run_lab.py --check"
run_lab.py (Executable Python Source)
#!/usr/bin/env python3
"""
SolarisK Reproducible Lab Runner — LAB-FREE-06: Deep Reinforcement Learning: Q-Learning, Policy Gradients & PPO
Hugging Face Learn: https://huggingface.co/learn/deep-rl-course
Hugging Face Docs: https://huggingface.co/docs/hub/models-libraries
"""
import argparse, json, os, platform, sys
from datetime import datetime, timezone
def main():
parser = argparse.ArgumentParser(description="SolarisK Lab Series LAB-FREE-06")
parser.add_argument("--check", action="store_true", help="Verify runtime environment and Hugging Face token visibility")
args = parser.parse_args()
report = {
"series_id": "LAB-FREE-06",
"slug": "deep-rl-policy-gradients",
"tier": "FREE",
"timestamp_utc": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"python": platform.python_version(),
"os": platform.platform(),
"hf_token_configured": bool(os.environ.get("HF_TOKEN")),
"learn_module": "https://huggingface.co/learn/deep-rl-course",
"docs_module": "https://huggingface.co/docs/hub/models-libraries",
"status": "READY"
}
print(json.dumps(report, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()
OCI Multi-Stage Non-Root Container & Docker / containerd / CRI-O Runbook (10D)
Containerfile (opencontainers.org)
# Multi-stage OCI-compliant Containerfile (opencontainers.org) — NVIDIA GPU Lab (deep-rl-policy-gradients)
# NOTE: NVIDIA Container Toolkit is required ONLY when executing GPU stages on an NVIDIA host.
FROM debian:bookworm-slim AS builder
ENV PIP_NO_CACHE_DIR=1 PYTHONDONTWRITEBYTECODE=1
RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-venv python3-pip ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --upgrade pip && pip install torch transformers datasets safetensors huggingface_hub accelerate
FROM debian:bookworm-slim AS runtime
LABEL org.opencontainers.image.title="solarisk-hf-lab-deep-rl-policy-gradients" \
org.opencontainers.image.source="https://github.com/ximad/solarisk" \
org.opencontainers.image.licenses="MIT"
RUN apt-get update && apt-get install -y --no-install-recommends python3 ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --create-home --uid 10001 --shell /usr/sbin/nologin solarisk
COPY --from=builder /opt/venv /opt/venv
WORKDIR /home/solarisk/lab
COPY --chown=10001:10001 run_lab.py /home/solarisk/lab/run_lab.py
ENV PATH="/opt/venv/bin:$PATH" HF_HOME="/home/solarisk/.cache/huggingface"
USER 10001:10001
ENTRYPOINT ["python3", "/home/solarisk/lab/run_lab.py"]
Docker, containerd (nerdctl), and CRI-O Commands
# GPU lab: NVIDIA Container Toolkit (nvidia-ctk) is required ONLY for local NVIDIA GPU execution.
# 1. Docker (OCI-compliant multi-stage non-root image)
docker build -f Containerfile -t solarisk/lab-free-06:latest .
docker run --rm --gpus all --read-only --tmpfs /tmp -e HF_TOKEN="$HF_TOKEN" solarisk/lab-free-06:latest
# 2. containerd via nerdctl (rootless OCI workflow)
nerdctl build -f Containerfile -t solarisk/lab-free-06:latest .
nerdctl run --rm --gpus all --read-only --tmpfs /tmp -e HF_TOKEN="$HF_TOKEN" solarisk/lab-free-06:latest
# 3. CRI-O / Podman (Kubernetes CRI-O node verification via crictl / podman)
podman build -f Containerfile -t localhost/solarisk/lab-free-06:latest .
podman run --rm --device nvidia.com/gpu=all --userns=keep-id -e HF_TOKEN="$HF_TOKEN" localhost/solarisk/lab-free-06:latest
# On CRI-O cluster nodes, pull the OCI image and inspect pod sandbox via: crictl images | grep lab-free-06Troubleshooting: Two Most Common Errors & Deterministic Fixes (10E)
Occurs when batch size or sequence length exceeds available VRAM or when the host NVIDIA driver is older than the container CUDA runtime. Reduce micro-batch size, enable gradient checkpointing or 4-bit NF4 quantization, verify `nvidia-smi` on the Debian host, and ensure `nvidia-ctk runtime configure` is applied before launching Docker/containerd/CRI-O.
Occurs when system Python packages shadow the isolated `.venv` or `HF_TOKEN` lacks read scope for a gated repository. Re-run `setup.sh` inside a clean virtual environment, export a fine-grained `HF_TOKEN`, and accept the model card license on huggingface.co.
Living Semantics Chapter — Human Glossary & Machine-Readable RAG Index (12A–12D)
| Term / Concept (12A–12C) | Category | Explanation & Operational Boundary |
|---|---|---|
| Hugging Face Hub Token (`HF_TOKEN`) | Security | Scoped bearer token granting read/write access to gated models, private datasets, and Inference Providers without embedding credentials in code. |
| OCI Multi-Stage Non-Root Image | Infrastructure | Container specification (`opencontainers.org`) separating build dependencies from a minimal runtime stage running under non-privileged UID `10001`. |
| SafeTensors (`.safetensors`) | Security | Memory-safe tensor storage format replacing Python `pickle` to prevent arbitrary code execution on checkpoint load. |
| ZeroGPU / Inference Providers | Compute | Managed Hugging Face GPU sharing (Free ~5 min/day vs PRO 8x priority) and serverless API routing (`router.huggingface.co`). |
| Paired Evaluation Harness | Reliability | Controlled benchmark execution holding prompts, seeds, and dataset splits constant to measure true capability deltas. |
| 30 / 30 / 30 / 10 Mastery Progression | Pedagogy | Curriculum pacing allocating 30% of labs/time to Beginner foundations, 30% to Practitioner integration, 30% to Expert hardening/optimization, and 10% to Capstone synthesis and primary resource indexing. |
| Idempotent Debian Setup & Rootless OCI Runtime | Reproducibility | Execution hygiene guaranteeing that setup.sh can be re-run safely on Debian 12/13 without state corruption and that the same workflow runs identically under Docker, containerd (nerdctl), or CRI-O under a non-root UID. |
No comments:
Post a Comment