Initial commit: source code for minimax-h3

This commit is contained in:
2026-09-28 18:15:15 +08:00
commit c31e52dcb9
23 changed files with 4184 additions and 0 deletions
Executable
+110
View File
@@ -0,0 +1,110 @@
#!/bin/bash
set -e
# ==============================================================================
# MiniMax-H3 FL2VA 3-step runner (使用 ref2va_step4.py 兼容 VAE 解碼)
# 用法: ./run_flh3.sh <project_name> [step]
# step 省略 = 依序跑全部 3 步
# 1 = Text encoder 編碼 prompt (text encoder 15G) → result1_te_*.pt
# 2 = DiT 去噪 (fl2va DiT 16G) → result2_video/audio_*.pt
# 3 = Video+Audio VAE 解碼 (video+audio VAE 1.9G)→ fl2va_output_*.mp4
#
# 注意: Step3 使用 ref2va_step4.py 取代原 fl2va_step3.py (功能完全相同)
# 保留原檔案以便 rollback 交叉測試
# ==============================================================================
if [ -z "$1" ]; then
echo "Usage: ./run_flh3.sh <project_name> [step]"
echo "Example: ./run_flh3.sh secretary_tease_5s 3"
echo "Step options (3-step architecture with ref2va_step4 for VAE decode):"
echo " 1 = Text encoder encode prompts (text encoder NF4 ~15GB) -> result1_te_*.pt"
echo " 2 = DiT denoise (fl2va NF4 ~16GB) -> result2_video/audio_*.pt"
echo " 3 = Video+Audio VAE decode using ref2va_step4.py (VAEs ~1.9GB)-> fl2va_output_*.mp4"
echo "Omit step to run all 3 in order."
echo ""
echo "Note: Original fl2va_step3.py is preserved for rollback testing."
exit 1
fi
PROJECT_NAME=$1
STEP=$2
BASE_DIR="/home/mikehu/data/AI/minimax-h3"
PROJECT_DIR="$BASE_DIR/outputs/$PROJECT_NAME"
VENV_PYTHON="$BASE_DIR/.venv/bin/python"
echo "----------------------------------------------------------------"
echo "🚀 Initializing MiniMax-H3 FL2VA Project: $PROJECT_NAME"
echo "📂 Project Dir: $PROJECT_DIR"
echo "🔧 Using ref2va_step4.py for Step 3 (VAE decode)"
echo "----------------------------------------------------------------"
# Create project directory
mkdir -p "$PROJECT_DIR"
# Copy template config.py to the project directory if it doesn't exist
if [ ! -f "$PROJECT_DIR/config.py" ]; then
cp "$BASE_DIR/config_template.py" "$PROJECT_DIR/config.py"
echo "📝 Copied template config.py to project folder. Please edit it for specific settings."
else
echo "📄 Using existing project config.py."
fi
# CRITICAL: Change working directory to the project folder
# This ensures that 'import config' finds the project-specific config.py
# and all relative paths like 'result1_te_*.pt' are saved/loaded here.
cd "$PROJECT_DIR"
export PYTHONPATH="$BASE_DIR:$PYTHONPATH"
# Validate step argument if provided
if [ -n "$STEP" ] && [[ ! "$STEP" =~ ^[1-3]$ ]]; then
echo "Error: Step must be 1, 2, or 3."
exit 1
fi
echo -e "\n----------------------------------------------------------------"
if [ -z "$STEP" ] || [ "$STEP" == "1" ]; then
echo -e "\n[1/3] Step 1: Text Encoding (fl2va_step1.py)..."
$VENV_PYTHON $BASE_DIR/fl2va_step1.py
fi
if [ -z "$STEP" ] || [ "$STEP" == "2" ]; then
echo -e "\n[2/3] Step 2: DiT Denoising (fl2va_step2.py)..."
$VENV_PYTHON $BASE_DIR/fl2va_step2.py
fi
if [ -z "$STEP" ] || [ "$STEP" == "3" ]; then
echo -e "\n[3/3] Step 3: VAE Decoding using ref2va_step4.py..."
# --- Path & File Alignment Fix ---
# 1. Align Output Directory
if [ -f "config.py" ]; then
CONF_OUTPUT_DIR=$(grep "OUTPUT_DIR =" config.py | sed -E 's/.*"([^"]+)".*/\1/')
if [ -n "$CONF_OUTPUT_DIR" ] && [ "$CONF_OUTPUT_DIR" != "$PROJECT_DIR" ]; then
echo "🔗 Aligning project path: $CONF_OUTPUT_DIR -> $PROJECT_DIR"
ln -sfn "$PROJECT_DIR" "$CONF_OUTPUT_DIR"
fi
fi
# 2. Align File Names (result2_..._l0.pt -> result3_....pt)
# ref2va_step4.py expects result3_video_0.pt and result3_audio_0.pt
for file in result2_{video,audio}_*_l0.pt; do
if [ -f "$file" ]; then
new_name=$(echo "$file" | sed -E 's/result2_(video|audio)_.*_l0\.pt/result3_\1_0.pt/')
echo "📝 Renaming $file -> $new_name"
cp -p "$file" "$new_name"
fi
done
# --------------------------
# Use ref2va_step4.py for FL2VA Step 3
# It reads result3_video/audio_*.pt and outputs fl2va_output_*.mp4
$VENV_PYTHON $BASE_DIR/ref2va_step4.py
fi
echo -e "\n----------------------------------------------------------------"
echo "✅ FL2VA Project $PROJECT_NAME Completed Successfully!"
echo "All assets (config, .pt, .mp4) are located in: $PROJECT_DIR"
echo "Note: Original fl2va_step3.py preserved for rollback testing."
echo "----------------------------------------------------------------"
date