git:20260831.975bd94 to git:20260831.6248b66

15 added, 9 removed. Audit B to B.

---
name: hyperloom-qwen3-14b-fp8-12h
description: Run a 12-hour Hyperloom Qwen3-14B-FP8 optimization session. Use when the user wants a medium-length Hyperloom demo on the local AMD ROCm environment.
---
# Hyperloom Qwen3-14B-FP8 12h Run
Read `.env` first and resolve `HYPERLOOM_SKILL_PATH`. Read and follow the optimizer skill at `@${HYPERLOOM_SKILL_PATH}` before launching. If `HYPERLOOM_SKILL_PATH` is missing, fall back to `@hyperloom/inference_optimizer/SKILL.md` (wheel install) or `@src/hyperloom/inference_optimizer/SKILL.md` (source checkout). This skill provides the concrete workload and launch constraints for a 12-hour Qwen3-14B-FP8 demo.
## Run Mode
Resolve the run mode before launching Hyperloom:
1. If `HYPERLOOM_RUN_MODE=baremetal` or it is unset, run this demo directly on the host.
2. If `HYPERLOOM_RUN_MODE=docker`, this skill owns the Docker setup. Ask the user whether they want a `vllm` or `sglang` Docker image unless `HYPERLOOM_IMAGE` is already set. Use a ROCm image that already contains the selected framework; do not install the framework inside Docker.
In docker mode:
- If `hyperloom-setup` already ran, do **not** re-run setup on the host.
- Read `HYPERLOOM_DOCKER_TARGET_HOST` from `.env` when present. If it names a
host different from `$(hostname)`, first SSH to that host and continue this
Docker setup there; do not start Docker on the login/current host.
- Always run setup **inside the container** after `docker run`.
- Pass `--install-framework none --yes` in the container (ROCm/framework comes from
the image). Do **not** use `--skip-base-check` — let Phase 1 preflight validate
the container environment.
- Do not run `python -m hyperloom.inference_optimizer.cli optimize` on the host.
- ### Credential retry cleanup (required)
+ ### Prior workload cleanup (required)
- **Trigger (MUST):** whenever an LLM credential fails (401/403, invalid key,
- preflight auth error) and the user supplies a corrected key — **regardless of
- whether you reuse the existing Docker container or start a new one.** Agents
- often continue inside the same long-running container instead of `docker run`
- again; leftover optimizer or serving processes are the usual cause of misleading
- 0% validated gain (#1314).
+ **Trigger (MUST):** whenever a demo run fails, is abandoned, or you are about to
+ start a **replacement** workload after any error — not only LLM credential
+ failures (401/403, invalid key, gateway/auth misconfiguration). This also
+ covers optimizer crash, install/preflight failure, the user asking to
+ retry/restart, or any recovery where you would run `docker run`, `install.sh`,
+ or a new/fresh `optimize`. It applies **regardless of whether you reuse the
+ existing Docker container or start a new one.** Leftover optimizer or serving
+ processes are the usual cause of misleading 0% validated gain (#1314).
+ **Exception:** `--resume-from "$SESSION_DIR"` against the **same** session
+ immediately after a clean crash (no credential change, user explicitly wants
+ resume) may skip this gate — but if the probe below finds live or ambiguous
+ leftover workload, run it anyway and ask the user.
+
**Before** any replacement step (`docker run`, `docker exec`, `install.sh`, or
a new/resumed `optimize`), probe the environment that will launch the workload
(the current shell, or the target container via `docker exec`):
```bash
export USER_DATA_PATH="${USER_DATA_PATH:-$(grep '^USER_DATA_PATH=' .env | cut -d= -f2-)}"
export RUN_DIR="${USER_DATA_PATH}/optimizer_runs"
# Prior session handle (if any)
test -f "$RUN_DIR/last_launch.env" && . "$RUN_DIR/last_launch.env"
echo "prior_session=${SESSION_DIR:-none} prior_pid_file=${PID_FILE:-none}"
# Leftover Hyperloom optimizer
pgrep -af 'hyperloom\.inference_optimizer\.cli.*optimize' || true
# Leftover serving stacks (IR-1 foreign processes)
pgrep -af 'sglang\.launch_server|vllm\.entrypoints|Magpie' || true
```
In **docker mode**, also probe on the **docker host** (not only inside the
container):
```bash
docker ps --format '{{.Names}}' | grep -E '^hyperloom' || true
```
**If anything is found** (prior `SESSION_DIR`, optimizer PID, `sglang`/`vllm`/
Magpie process, or an extra `hyperloom*` container), stop and ask the user in
plain language — for example: *"The previous run may still be active (optimizer
- PID …, session …). Stop it before we continue with the corrected API key?"*
- Wait for explicit yes/no.
+ PID …, session …). Stop it before we continue?"* Wait for explicit yes/no.
- **Yes:** stop in this order: serving processes from the old run, then the
optimizer (`kill` the PID from `PID_FILE` or the `pgrep` match), then stale
`hyperloom*` containers on the docker host (`docker stop <name>`). Only after
cleanup, continue with `--resume-from "$SESSION_DIR"` or a fresh launch as
appropriate.
- **No:** continue, but warn that GPU contention or a stale baseline anchor
can depress benchmarks and show 0% validated gain.
Never kill processes or stop containers without the user's explicit approval.
Suggested Docker images:
- `vllm`: `docker.io/vllm/vllm-openai-rocm:v0.27.1`
- `sglang` MI300X: `docker.io/lmsysorg/sglang-rocm:v0.5.18-rocm724-mi30x-20260825`
- `sglang` MI355X: `docker.io/lmsysorg/sglang-rocm:v0.5.18-rocm724-mi35x-20260825`
In Docker mode, start a long-running container on `HYPERLOOM_DOCKER_TARGET_HOST`
(or the current host when it is unset) before running setup or optimize:
```bash
export REPO_ROOT="$(pwd -P)"
docker run -d \
--name "${HYPERLOOM_CONTAINER_NAME:-hyperloom-local}" \
--shm-size "${HYPERLOOM_SHM_SIZE:-64g}" \
--entrypoint tail \
--device /dev/kfd \
--device /dev/dri \
--group-add video \
-v "$REPO_ROOT:$REPO_ROOT" \
"$HYPERLOOM_IMAGE" \
-f /dev/null
```
Mount the Hyperloom workspace at the same absolute path (`-v "$REPO_ROOT:$REPO_ROOT"`) so paths in `.env`, logs, and session artifacts stay valid. If `USER_DATA_PATH` or a pre-downloaded model directory is outside the workspace, add matching `-v host_path:host_path` mounts before starting the container.
Then run the setup backend inside the container:
```bash
docker exec -w "$REPO_ROOT" "${HYPERLOOM_CONTAINER_NAME:-hyperloom-local}" bash -lc \
'REPO_ROOT="$(pwd -P)"; PYTHONPATH="$REPO_ROOT" python3 -m hyperloom.inference_optimizer.setup -- --install-framework none --yes'
```
After that, run all remaining commands for this demo inside the same container with `docker exec -w "$REPO_ROOT" ...`; do not run `python -m hyperloom.inference_optimizer.cli optimize` on the host in Docker mode. When the demo is finished, ask the user whether to stop the container. If they say yes, run:
```bash
docker stop "${HYPERLOOM_CONTAINER_NAME:-hyperloom-local}"
```
## Environment
- `MODEL_PATH=<optional; if unset, download Qwen/Qwen3-14B-FP8 from Hugging Face with the Python steps below, then set MODEL_PATH to that local path>`
- `FRAMEWORK=<provided by the existing environment or repository-root .env; do not invent it>`
- `GPU_TYPE=<do not set; omit --gpu-type and let Hyperloom auto-detect from ROCm/system info>`
Required optimize CLI flags:
- `--tp 1`
- `--conc 64`
- `--isl 1024`
- `--osl 1024`
- `--precision fp8`
- `--target-gain 50`
- `--max-hours 12`
- `--max-minutes-framework-pct 0.43`
- `--max-minutes-kernel-pct 0.42`
Before launch, read the repository-root `.env` file if it exists and load the needed environment variables from it, such as LLM API keys/base URLs, `FRAMEWORK`, and `HF_TOKEN`. Do not copy secret values into the prompt, terminal output, reports, or logs. Do not modify `USER_DATA_PATH`.
Before resolving or downloading any model, always ask the user which model path to use. Present the currently resolved option when `MODEL_PATH` is already set, and always offer a custom local path plus the demo default. Do not continue until the user chooses one.
Use this decision flow:
- If the user chooses the existing `MODEL_PATH`, inspect that path and use it only when it contains `config.json`; otherwise ask again for a valid path or the demo default.
- If the user provides a custom local path, export `MODEL_PATH` to that path and require `config.json` before launch.
- If the user chooses the demo default, set `MODEL_PATH=${REPO_ROOT}/.cache/hyperloom-models/Qwen3-14B-FP8` and download `Qwen/Qwen3-14B-FP8` there when `config.json` is not already present.
Do not assume the Hugging Face CLI exists; resolve or download the selected model with Python:
```bash
python -m pip install -U huggingface_hub
export REPO_ROOT="$(pwd -P)"
export MODEL_PATH="${MODEL_PATH:-${REPO_ROOT}/.cache/hyperloom-models/Qwen3-14B-FP8}"
python - <<'PY'
import os
from pathlib import Path
from huggingface_hub import snapshot_download
target = Path(os.environ["MODEL_PATH"]).expanduser()
if (target / "config.json").is_file():
print(f"Using existing model at {target.resolve()}")
else:
snapshot_download(
repo_id="Qwen/Qwen3-14B-FP8",
local_dir=str(target),
local_dir_use_symlinks=False,
)
print(target.resolve())
PY
```
## Pre-launch Runtime Install
Before the first `optimize` launch, run the full runtime installer in the same
environment that will launch the optimizer. Preflight loads `kernel-agent.env.sh`
before it can reach the later Ray/Magpie/InferenceX auto-install checks, so this
step must happen before launching.
For Docker mode, run this inside the container. For bare-metal mode, run it on
the host:
```bash
export REPO_ROOT="$(pwd -P)"
# .env fills gaps only: re-exporting the non-empty pre-source snapshot keeps every
# value the caller exported. Wider than install.sh, which guards a fixed list.
_dotenv_prev="$(export -p | grep -v -e '=""$' -e "=''\$")"
set -a; . "${REPO_ROOT}/.env"; set +a
eval "$_dotenv_prev"
unset _dotenv_prev
export USER_DATA_PATH="${USER_DATA_PATH:?USER_DATA_PATH missing}"
export PYTHONPATH="${REPO_ROOT}:${PYTHONPATH:-}"
ulimit -Sn 65536 || true
INSTALL_SH="${REPO_ROOT}/hyperloom/inference_optimizer/assets/install.sh"
if [ ! -f "$INSTALL_SH" ]; then
INSTALL_SH="${REPO_ROOT}/src/hyperloom/inference_optimizer/assets/install.sh"
fi
bash "$INSTALL_SH"
. "$USER_DATA_PATH/runtime/kernel-agent.env.sh"
export PYTHONPATH="${REPO_ROOT}:${PYTHONPATH:-}"
```
If `hyperloom/inference_optimizer/assets/install.sh` is not present (source
checkout layout), use `src/hyperloom/inference_optimizer/assets/install.sh`.
## User-visible Progress
Keep the user informed with concise status updates throughout the demo. Do not
dump full debug logs into chat; report the important values and paths so the user
can tell that work is progressing.
Before launch, report the launch plan:
- model path and whether it is an existing local model or a downloaded default;
- run mode (`baremetal` or `docker`) and target host/container when applicable;
- framework, TP, concurrency, ISL, OSL, precision, max hours, and required demo
flags;
- `USER_DATA_PATH` and where runtime artifacts will be written.
After the runtime install, report whether it succeeded and the path to
`kernel-agent.env.sh`. After starting the optimizer, report:
- optimizer PID;
- run log path;
- launch-info JSON path;
- resolved session directory;
- `state.json` path;
- initial health check result.
During monitoring, print a short summary at each 300-second check:
- process alive/stopped;
- phase and `stop_reason`;
- baseline throughput, current best throughput, and cumulative gain when present;
- latest benchmark result or candidate decision when available;
- the most relevant recent log lines, excluding secrets.
When the run finishes, report the final status, final report path, best result,
and the stop reason. Never print API keys, tokens, or custom header values.
## Launch Requirements
1. Run the pre-launch runtime install above and source
`$USER_DATA_PATH/runtime/kernel-agent.env.sh` before launching.
2. Keep `PYTHONPATH="$REPO_ROOT:${PYTHONPATH:-}"` in the launch shell so robustness
and critic subprocesses can import `hyperloom.agents` after changing cwd.
3. Run in background with `setsid nohup`.
4. Pass all required optimize CLI flags in the `python -m hyperloom.inference_optimizer.cli optimize` command. Do not rely on `.env` alone for `TP`, `CONC`, `ISL`, `OSL`, or `PRECISION`; CLI defaults can otherwise override the intended workload.
5. Report the session ID, log path, PID, and initial health check result.
6. Monitor the process every 300 seconds until work is done.
7. To recover an unexpected crash, only run `optimize --resume-from "$SESSION_DIR"` against the same session dir. After the first launch, never start a new `optimize`; that creates a new `<UTC_ts>` session and is forbidden.
8. If `stop_reason` in the current session `state.json` is final, stop and exit.