DragMesh-3-Scene / batch_parallel.sh
Neptune-T's picture
Add files using upload-large-folder tool
327ef01 verified
Raw History Blame Contribute Delete
11.4 kB
#!/usr/bin/env bash
# Parallel batch: 3 workers generate 10 household scenes (SceneSmith + DeepSeek).
# Worker A (GPU0, default ports): waits for running home_03, then home_04, home_08
# Worker B (GPU0, ports +10): home_05, home_09, home_01(rerun)
# Worker C (GPU1, ports +20): home_06, home_07, home_10
#
# Each scene: `timeout 780m docker run ...` in background + poll scene log for
# completion marker; when marker appears, kill the docker client (container
# output is already on the mounted volume). Success dir recorded from the
# "Outputs will be saved to:" line in the scene log.
set -u
REPO="/home/zhanghao/scene/scenesmith_full"
LOG_DIR="$HOME/scene/batch_logs"
mkdir -p "$LOG_DIR"
export OPENAI_API_KEY="sk-4da9903b2b7b4c7f96b8332ab1fcb152"
export OPENAI_BASE_URL="https://api.deepseek.com/v1"
export OPENAI_MODEL="deepseek-chat"
export OPENAI_AGENTS_DISABLE_TRACING=1
export SCENESMITH_VLM_API_KEY="sk-ws-H.ELXPHPI.SFDT.MEQCIG5rBZw6Zsm11s-WdY0gR1SWqWfuyst_G_FfKgMthtD4AiAzxunTBDfHuTR_xEtpPOclT9LepHRF2OdxpT0zksZRZw"
export SCENESMITH_VLM_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
export SCENESMITH_VLM_MODEL="qwen-vl-max"
# name|prompt
SCENES=(
"home_01_kitchen|A modern kitchen with articulated base cabinets with opening doors along the back wall, a refrigerator with a door that opens, a drawer chest with three pull-out drawers, a microwave on the counter with a drop-down door, an oven with a drop-down door, and a window on the back wall. Include a countertop."
"home_02_bedroom|A cozy bedroom with a large wardrobe with two sliding cabinet doors, a nightstand with one drawer on each side of the bed, a dresser with three drawers, a bed with a headboard, and a window with curtains."
"home_03_living|A bright living room with a TV console with two cabinet doors and two drawers, a sideboard with four doors along the wall, a bookshelf with two glass doors, a sofa, a coffee table, and a floor lamp."
"home_04_dining|An elegant dining room with a sideboard cabinet with four doors and two drawers, a wine cabinet with glass doors, a dining table with four chairs, and a window with curtains on the side wall."
"home_05_study|A quiet study room with a bookcase with two glass cabinet doors, a writing desk with two drawers, a filing cabinet with three drawers, a desk chair, and a window on the left wall."
"home_06_bathroom|A clean bathroom with a vanity cabinet with two doors and one drawer under the sink, a mirror cabinet with two doors above the sink, a toilet, a shower with glass panels, and a window."
"home_07_laundry|A laundry room with a front-loading washing machine with a round door that opens, a dryer with a round door, a storage cabinet with two doors on the wall, a countertop, and a utility sink."
"home_08_entryway|A compact entryway with a shoe cabinet with two doors, a coat wardrobe with one door and a mirror, a small chest with two drawers, a bench, and a front door with a window."
"home_09_kidsroom|A cheerful kids bedroom with a wardrobe with two sliding doors, a toy cabinet with two doors and two drawers, a small desk with one drawer, a bed, and a window with colorful curtains."
"home_10_storage|A utility storage room with a tall storage cabinet with four doors, a tool cabinet with two drawers, a shelf unit with a cabinet door, and a workbench."
)
# Map scene name -> prompt
get_prompt() {
local NAME="$1"
for entry in "${SCENES[@]}"; do
if [ "${entry%%|*}" = "$NAME" ]; then
echo "${entry#*|}"
return
fi
done
}
# True if a final scene_state.json exists under scene_000/room_*/scene_states/
has_final_state() {
find "$1/scene_000" -path "*/scene_states/final_scene/scene_state.json" 2>/dev/null | grep -q .
}
run_one() {
# run_one <name> <port_offset> <gpu> <log_suffix>
local NAME="$1" OFFSET="$2" GPU="$3"
local PROMPT LOG=""
PROMPT=$(get_prompt "$NAME")
if [ -z "$PROMPT" ]; then echo "[$NAME] unknown scene"; return; fi
LOG="$LOG_DIR/${NAME}.log"
# append-mode log (worker B reruns home_01 into same file)
echo "===== [$NAME] START $(date '+%H:%M:%S') worker-offset=${OFFSET} =====" >> "$LOG"
# Skip only if recorded as a VERIFIED success (final scene state exists)
if [ -f "$LOG_DIR/${NAME}.dir" ] && grep -q "2026" "$LOG_DIR/${NAME}.dir" 2>/dev/null \
&& has_final_state "$(cat "$LOG_DIR/${NAME}.dir")" 2>/dev/null; then
echo "[$NAME] already done: $(cat "$LOG_DIR/${NAME}.dir")" >> "$LOG"
return 0
fi
# stale/mispointed .dir -> clear so the scene reruns
rm -f "$LOG_DIR/${NAME}.dir"
cd "$REPO"
local EXTRA=()
if [ "$OFFSET" -gt 0 ]; then
local AP; local MP; local OP; local BLO; local BHI; local CLO; local CHI
AP=$((7007 + OFFSET)); MP=$((7008 + OFFSET)); OP=$((7009 + OFFSET))
BLO=$((8400 + OFFSET * 40)); BHI=$((BLO + 299))
CLO=$((7500 + OFFSET * 40)); CHI=$((CLO + 299))
EXTRA=(
"experiment.articulated_retrieval_server.port=${AP}"
"experiment.materials_retrieval_server.port=${MP}"
"experiment.objaverse_retrieval_server.port=${OP}"
"furniture_agent.rendering.blender_server_port_range=[${BLO},${BHI}]"
"manipuland_agent.rendering.blender_server_port_range=[${BLO},${BHI}]"
"wall_agent.rendering.blender_server_port_range=[${BLO},${BHI}]"
"ceiling_agent.rendering.blender_server_port_range=[${BLO},${BHI}]"
"floor_plan_agent.rendering.blender_server_port_range=[${BLO},${BHI}]"
"furniture_agent.collision_geometry.server_port_range=[${CLO},${CHI}]"
"manipuland_agent.collision_geometry.server_port_range=[${CLO},${CHI}]"
"wall_agent.collision_geometry.server_port_range=[${CLO},${CHI}]"
"ceiling_agent.collision_geometry.server_port_range=[${CLO},${CHI}]"
)
fi
local OK=0
for attempt in 1 2 3; do
echo " attempt $attempt $(date '+%H:%M:%S')" >> "$LOG"
timeout 780m docker run --rm \
--gpus all --network host --ipc=host \
--cap-add SYS_ADMIN --cap-add SYS_CHROOT \
--security-opt apparmor=unconfined --security-opt seccomp=unconfined \
-e OPENAI_API_KEY="${OPENAI_API_KEY}" \
-e OPENAI_BASE_URL="${OPENAI_BASE_URL}" \
-e OPENAI_MODEL="${OPENAI_MODEL}" \
-e OPENAI_AGENTS_DISABLE_TRACING=1 \
-e SCENESMITH_VLM_API_KEY="${SCENESMITH_VLM_API_KEY}" \
-e SCENESMITH_VLM_BASE_URL="${SCENESMITH_VLM_BASE_URL}" \
-e SCENESMITH_VLM_MODEL="${SCENESMITH_VLM_MODEL}" \
-e HF_ENDPOINT=https://hf-mirror.com \
-e CUDA_VISIBLE_DEVICES="${GPU}" \
-v "${REPO}:/app" \
scenesmith:latest \
python main.py +name="${NAME}" \
experiment.prompts="[\"${PROMPT}\"]" \
experiment.num_workers=1 \
furniture_agent.openai.model=deepseek-chat \
floor_plan_agent.openai.model=deepseek-chat \
wall_agent.openai.model=deepseek-chat \
ceiling_agent.openai.model=deepseek-chat \
manipuland_agent.openai.model=deepseek-chat \
furniture_agent.asset_manager.general_asset_source=objaverse \
manipuland_agent.asset_manager.general_asset_source=objaverse \
wall_agent.asset_manager.general_asset_source=objaverse \
ceiling_agent.asset_manager.general_asset_source=objaverse \
furniture_agent.asset_manager.router.strategies.generated.enabled=false \
manipuland_agent.asset_manager.router.strategies.generated.enabled=false \
wall_agent.asset_manager.router.strategies.generated.enabled=false \
ceiling_agent.asset_manager.router.strategies.generated.enabled=false \
"${EXTRA[@]}" \
>> "$LOG" 2>&1 &
local DPID=$!
# Poll the scene log for the completion marker (up to ~13h).
local DONE=0
for i in $(seq 1 780); do
sleep 60
if ! kill -0 "$DPID" 2>/dev/null; then
# docker client exited on its own (timeout or normal end)
wait "$DPID" 2>/dev/null
break
fi
if grep -q "Scene generation completed successfully" "$LOG" 2>/dev/null; then
sleep 10
# kill this scene's container first: the docker run client
# forwards SIGTERM to the container's python, which hangs after
# completion - the client only exits once the container dies.
for c in $(docker ps -q --filter ancestor=scenesmith:latest); do
docker inspect --format '{{.Config.Cmd}}' "$c" 2>/dev/null | grep -q "+name=$NAME" && docker kill "$c" >/dev/null 2>&1 && break
done
kill "$DPID" 2>/dev/null
wait "$DPID" 2>/dev/null
DONE=1
break
fi
if ! grep -q "startup" "$LOG" 2>/dev/null && grep -qE "Error|Traceback|ValueError: Port" "$LOG" 2>/dev/null; then
# early startup failure (port conflict etc.) - kill, retry now
kill "$DPID" 2>/dev/null
wait "$DPID" 2>/dev/null
break
fi
done
# Locate the exact output dir from the scene log line:
# Outputs will be saved to: /app/outputs/2026-08-09/03-45-12
local OUTDIR=""
OUTDIR=$(grep -oE "Outputs will be saved to: /app/outputs/[0-9-]+/[0-9-]+" "$LOG" | tail -1 | sed 's|Outputs will be saved to: ||; s|^/app|/home/zhanghao/scene/scenesmith_full|')
if [ -z "$OUTDIR" ]; then
# fallback: newest dir containing a scene.log with completion marker
OUTDIR=$(ls -td "$REPO"/outputs/*/*/ 2>/dev/null | while read d; do
if grep -q "Scene generation completed successfully" "$d/scene_000/scene.log" 2>/dev/null; then echo "$d"; fi
done | head -1 | sed 's|/$||')
fi
# Success check: final scene state exists (robust marker)
if [ -n "$OUTDIR" ] && has_final_state "$OUTDIR"; then
echo "[$NAME] SUCCESS attempt $attempt -> $OUTDIR" >> "$LOG"
echo "$OUTDIR" > "$LOG_DIR/${NAME}.dir"
OK=1
break
else
echo "[$NAME] attempt $attempt not successful (dir=${OUTDIR:-none}), retry" >> "$LOG"
fi
done
if [ "$OK" -ne 1 ]; then
echo "[$NAME] FAILED after 3 attempts" >> "$LOG"
echo "FAILED" > "$LOG_DIR/${NAME}.dir"
fi
}
# ---------- Worker role ----------
ROLE="${1:-A}"
echo "worker ${ROLE} starting $(date '+%H:%M:%S')"
case "$ROLE" in
A)
# home_03: rerun from scratch (previous container was killed when a
# stale completion marker in home_02's dir mispointed the wait loop)
run_one home_03_living 0 0
run_one home_04_dining 0 0
run_one home_08_entryway 0 0
;;
B)
run_one home_05_study 10 0
run_one home_09_kidsroom 10 0
run_one home_01_kitchen 10 0
;;
C)
run_one home_06_bathroom 20 1
run_one home_07_laundry 20 1
run_one home_10_storage 20 1
;;
esac
echo "worker ${ROLE} DONE $(date '+%H:%M:%S')" >> "$LOG_DIR/parallel_${ROLE}.done"