Cccccz's picture
Add files using upload-large-folder tool
37a82b7 verified
Raw
History Blame Contribute Delete
5.17 kB
# Copyright (c) 2025 SandAI. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
export MASTER_ADDR=localhost
export MASTER_PORT=6005
export GPUS_PER_NODE=1
export NNODES=1
export WORLD_SIZE=1
export CUDA_VISIBLE_DEVICES=0
export PAD_HQ=1
export PAD_DURATION=1
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
export OFFLOAD_T5_CACHE=true
export OFFLOAD_VAE_CACHE=true
export TORCH_CUDA_ARCH_LIST="8.9;9.0"
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MAGI_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
cd "$MAGI_ROOT"
PROMPT="${PROMPT:-a woman dancing.}"
TIMESTAMP="${RUN_ID:-$(date "+%Y-%m-%d_%H-%M-%S")}"
PROMPT_DIR_NAME="${PROMPT_DIR_NAME:-$(python3 - "$PROMPT" <<'PY'
import re
import sys
import unicodedata
prompt = unicodedata.normalize("NFKC", sys.argv[1]).strip()
prompt = re.sub(r"[\\/:\*\?\"<>\|\x00-\x1f]+", "_", prompt)
prompt = re.sub(r"\s+", "_", prompt)
prompt = prompt.strip("._")
print((prompt or "prompt")[:120])
PY
)}"
OUTPUT_ROOT="${OUTPUT_ROOT:-outputs}"
EXP_DIR="${RUN_DIR:-$OUTPUT_ROOT/${PROMPT_DIR_NAME}_$TIMESTAMP}"
mkdir -p "$EXP_DIR"
OUTPUT_PATH="${OUTPUT_PATH:-$EXP_DIR/output_$TIMESTAMP.mp4}"
RESIDUAL_JSON="${RESIDUAL_JSON:-$EXP_DIR/residual_stats_$TIMESTAMP.json}"
RESIDUAL_PNG="${RESIDUAL_PNG:-$EXP_DIR/residual_norms_$TIMESTAMP.png}"
L1_REL_JSON="${L1_REL_JSON:-$EXP_DIR/l1_rel_stats_$TIMESTAMP.json}"
L1_REL_PNG="${L1_REL_PNG:-$EXP_DIR/l1_rel_$TIMESTAMP.png}"
L1_REL_RATIO_PNG="${L1_REL_RATIO_PNG:-$EXP_DIR/l1_rel_ratio_$TIMESTAMP.png}"
X_EMBEDDER_L1_REL_PNG="${X_EMBEDDER_L1_REL_PNG:-$EXP_DIR/x_embedder_l1_rel_$TIMESTAMP.png}"
X_EMBEDDER_L1_REL_RATIO_PNG="${X_EMBEDDER_L1_REL_RATIO_PNG:-$EXP_DIR/x_embedder_l1_rel_ratio_$TIMESTAMP.png}"
FLOWCACHE_METRIC_JSON="${FLOWCACHE_METRIC_JSON:-$EXP_DIR/flowcache_metric_stats_$TIMESTAMP.json}"
FLOWCACHE_REL_L1_PNG="${FLOWCACHE_REL_L1_PNG:-$EXP_DIR/flowcache_rel_l1_$TIMESTAMP.png}"
FLOWCACHE_REL_L1_RATIO_PNG="${FLOWCACHE_REL_L1_RATIO_PNG:-$EXP_DIR/flowcache_rel_l1_ratio_$TIMESTAMP.png}"
FLOWCACHE_ACCUMULATED_REL_L1_PNG="${FLOWCACHE_ACCUMULATED_REL_L1_PNG:-$EXP_DIR/flowcache_accumulated_rel_l1_$TIMESTAMP.png}"
LOG_FILE="${LOG_FILE:-$EXP_DIR/infer_$TIMESTAMP.log}"
export PYTHONPATH="$MAGI_ROOT:${PYTHONPATH:-}"
python3 inference/pipeline/flowcache.py \
--config_file config/single_run/flowcache_t2v.json \
--mode t2v \
--prompt "$PROMPT" \
--output_path "$OUTPUT_PATH" \
--additional_config yaml_config/single_run/config.yaml \
--residual_stats_path "$RESIDUAL_JSON" \
--l1_rel_stats_path "$L1_REL_JSON" \
--flowcache_metric_stats_path "$FLOWCACHE_METRIC_JSON" \
2>&1 | tee "$LOG_FILE"
python3 tools/plot_residual_norms.py "$RESIDUAL_JSON" -o "$RESIDUAL_PNG"
python3 tools/plot_l1_rel.py "$L1_REL_JSON" -o "$L1_REL_PNG"
python3 tools/plot_l1_rel.py "$L1_REL_JSON" --y-field l1_rel_ratio -o "$L1_REL_RATIO_PNG"
python3 tools/plot_l1_rel.py "$L1_REL_JSON" --y-field x_embedder_l1_rel -o "$X_EMBEDDER_L1_REL_PNG"
python3 tools/plot_l1_rel.py "$L1_REL_JSON" --y-field x_embedder_l1_rel_ratio -o "$X_EMBEDDER_L1_REL_RATIO_PNG"
python3 tools/plot_l1_rel.py "$FLOWCACHE_METRIC_JSON" --x-field cur_denoise_step --y-field flowcache_rel_l1 -o "$FLOWCACHE_REL_L1_PNG"
python3 tools/plot_l1_rel.py "$FLOWCACHE_METRIC_JSON" --x-field cur_denoise_step --y-field flowcache_rel_l1_ratio -o "$FLOWCACHE_REL_L1_RATIO_PNG"
python3 tools/plot_l1_rel.py "$FLOWCACHE_METRIC_JSON" --x-field cur_denoise_step --y-field flowcache_accumulated_rel_l1 -o "$FLOWCACHE_ACCUMULATED_REL_L1_PNG"
python3 - "$FLOWCACHE_METRIC_JSON" <<'PY'
import json
import sys
with open(sys.argv[1], "r") as f:
payload = json.load(f)
summary = payload.get("chunk_execution_summary", {})
print("FlowCache actual execution summary:")
for chunk_id in sorted(summary, key=lambda value: int(value)):
item = summary[chunk_id]
print(
" chunk {chunk_idx}: reuse={reuse_steps}, compute={compute_steps}, "
"total={total_steps}, reuse_rate={reuse_rate:.2%}".format(**item)
)
PY
echo "Done."
echo " log: $LOG_FILE"
echo " video: $OUTPUT_PATH"
echo " residual json: $RESIDUAL_JSON"
echo " residual plot: $RESIDUAL_PNG"
echo " L1 rel json: $L1_REL_JSON"
echo " L1 rel plot: $L1_REL_PNG"
echo " L1 rel ratio plot: $L1_REL_RATIO_PNG"
echo " x_embedder L1 rel plot: $X_EMBEDDER_L1_REL_PNG"
echo " x_embedder L1 rel ratio plot: $X_EMBEDDER_L1_REL_RATIO_PNG"
echo " FlowCache metric json: $FLOWCACHE_METRIC_JSON"
echo " FlowCache rel L1 plot: $FLOWCACHE_REL_L1_PNG"
echo " FlowCache rel L1 ratio plot: $FLOWCACHE_REL_L1_RATIO_PNG"
echo " FlowCache accumulated rel L1 plot: $FLOWCACHE_ACCUMULATED_REL_L1_PNG"