Initial commit: source code for minimax-h3
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
# ==============================================================================
|
||||
import gc
|
||||
import torch
|
||||
|
||||
# 強制啟用 PyTorch ROCm 的記憶體高效與 Flash 注意力後端
|
||||
torch.backends.cuda.enable_flash_sdp(True)
|
||||
torch.backends.cuda.enable_mem_efficient_sdp(True)
|
||||
torch.backends.cuda.enable_math_sdp(False) # 關閉最吃顯存的原生 Math 計算
|
||||
|
||||
# 🎞️ MiniMax-H3 Project Configuration Template (T2V/FL2VA)
|
||||
# 🎞️ MiniMax-H3 Project Configuration Template (T2V/FL2VA)
|
||||
# ==============================================================================
|
||||
# 使用指南 (For Prompt Engineering AI):
|
||||
# 1. 此文件為專案「基因錨點」,定義了所有生成參數。
|
||||
# 2. 每個專案只需修改 TASK_REGISTRY 中的內容。
|
||||
# 3. Prompt 撰寫規範 (Base Mode - T2VA/I2VA/FL2VA/L2VA):
|
||||
# - 語言:描述必須使用 English;對白/歌詞保留原語言 (e.g. [對白: ...])。
|
||||
# - 時長:建議 4-15 秒。
|
||||
# - 必備欄位:
|
||||
# * integrated_multimodal_description: 整合視覺與動作的詳細時間軸描述。
|
||||
# * overall_soundscape: 整體環境音效、氛圍描述。
|
||||
# * non_diegetic_music: 背景音樂、配樂描述。
|
||||
# - 標記 Flag:使用 <Picture 1>, <Video 1>, <Audio 1> 等標記同步多模態內容。
|
||||
# 4. 參數規範:
|
||||
# - name: 任務名稱 (用於紀錄與辨識)
|
||||
# - prompts: 必須是 [List[str]] 格式。即便只有一個 Prompt,也請放在方括號內。
|
||||
# - enabled: True (執行) / False (跳過)
|
||||
# - num_frames: 影片總幀數 (建議 124, 必須滿足 num_frames % 17 == 5)
|
||||
# - width: 寬度 (Low: 832, Mid: 1024, High: 1344)
|
||||
# - height: 高度 (Low: 480, Mid: 576, High: 768)
|
||||
# - steps: 步數 (Turbo LoRA: Low=8, Mid=12, High=16)
|
||||
# - first_frame: 首幀參考圖路徑 (Optional)
|
||||
# - last_frame: 末幀參考圖路徑 (Optional)
|
||||
# ==============================================================================
|
||||
|
||||
import os
|
||||
import torch
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List, Optional, Dict, Any
|
||||
|
||||
# 基礎路徑 (禁止修改)
|
||||
MODELS_DIR = "/home/mikehu/data/AI/minimax-h3/DiffSynth-Studio/models"
|
||||
OUTPUT_DIR = "/home/mikehu/data/AI/minimax-h3/outputs/<project_name>"
|
||||
|
||||
# VRAM 設定 (確保 CPU Offload 以避免 OOM)
|
||||
VRAM_CONFIG = {
|
||||
"onload_device": "cpu",
|
||||
"offload_device": "cpu",
|
||||
"preparing_device": "cpu",
|
||||
"vram_limit": 8.0
|
||||
}
|
||||
|
||||
# 影片基礎設定
|
||||
VIDEO_SETTINGS = {
|
||||
"default_fps": 24,
|
||||
"default_audio_sample_rate": 32000,
|
||||
}
|
||||
|
||||
# 運行配置 (Required for fl2va_step2.py)
|
||||
RUN_CONFIG = {
|
||||
"model_name": "fl2va",
|
||||
"device": "cuda",
|
||||
"use_half": True,
|
||||
"default_num_inference_steps": 8,
|
||||
}
|
||||
|
||||
@dataclass
|
||||
class TaskConfig:
|
||||
name: str
|
||||
prompts: List[str]
|
||||
enabled: bool = True
|
||||
num_frames: int = 124
|
||||
width: int = 832
|
||||
height: int = 480
|
||||
steps: int = 8
|
||||
first_frame: Optional[str] = None
|
||||
last_frame: Optional[str] = None
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 🎯 任務註冊表 (在此定義您的劇本)
|
||||
# 格式: { ID: TaskConfig(name=\"...\", prompts=[\"...\"], enabled=True, ...) }
|
||||
# ------------------------------------------------------------------------------
|
||||
TASK_REGISTRY = {
|
||||
0: TaskConfig(
|
||||
name="Example_Scene_01",
|
||||
prompts=["A high-oblique wide angle shot of a beautiful East Asian woman..."],
|
||||
enabled=True,
|
||||
num_frames=124,
|
||||
width=832,
|
||||
height=480,
|
||||
steps=8,
|
||||
first_frame=None,
|
||||
last_frame=None,
|
||||
),
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# --- 內部 API (禁止修改) ---
|
||||
# ------------------------------------------------------------------------------
|
||||
def get_enabled_tasks() -> List[int]:
|
||||
return [idx for idx, task in TASK_REGISTRY.items() if task.enabled]
|
||||
|
||||
def get_task_params(task_idx: int, loop_idx: int) -> Dict[str, Any]:
|
||||
task = TASK_REGISTRY[task_idx]
|
||||
prompt_idx = min(loop_idx, len(task.prompts) - 1)
|
||||
return {
|
||||
"name": task.name,
|
||||
"prompt": task.prompts[prompt_idx],
|
||||
"num_frames": task.num_frames,
|
||||
"width": task.width,
|
||||
"height": task.height,
|
||||
"steps": task.steps,
|
||||
}
|
||||
Reference in New Issue
Block a user