liuhongwei-2026/FloodDiffusionTiny
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

FloodDiffusion: Tailored Diffusion Forcing for Streaming Motion Generation

A TINY version of the original FloodDiffusion

Paper | Github | Project Page

Installation

Prerequisites

  • Python 3.8+
  • CUDA-capable GPU with 16GB+ VRAM (recommended)
  • 16GB+ system RAM

Dependencies

Step 1: Install basic dependencies

pip install torch transformers huggingface_hub
pip install lightning diffusers omegaconf ftfy numpy

Step 2: Install Flash Attention (Required)

Flash attention requires CUDA and may need compilation. Choose the appropriate method:

pip install flash-attn --no-build-isolation

Note: Flash attention is required for this model. If installation fails, please refer to the official flash-attention installation guide.

Quick Start

Basic Usage

from transformers import AutoModel

# Load model
model = AutoModel.from_pretrained(
    "ShandaAI/FloodDiffusionTiny",
    trust_remote_code=True
)

# Generate motion from text (263-dim HumanML3D features)
motion = model("a person walking forward", length=60)
print(f"Generated motion: {motion.shape}")  # (~240, 263)

# Generate motion as joint coordinates (22 joints × 3 coords) with ema (alpha: 0.0-1.0)
motion_joints = model("a person walking forward", length=60, output_joints=True, smoothing_alpha=0.5)
print(f"Generated joints: {motion_joints.shape}")  # (~240, 22, 3)

Batch Generation

# Generate multiple motions efficiently
texts = [
    "a person walking forward",
    "a person running quickly", 
    "a person jumping up and down"
]
lengths = [60, 50, 40]  # Different lengths for each motion

motions = model(texts, length=lengths)

for i, motion in enumerate(motions):
    print(f"Motion {i}: {motion.shape}")

Multi-Text Motion Transitions

# Generate a motion sequence with smooth transitions between actions
motion = model(
    text=[["walk forward", "turn around", "run back"]],
    length=[120],
    text_end=[[40, 80, 120]]  # Transition points in latent tokens
)

# Output: ~480 frames showing all three actions smoothly connected
print(f"Transition motion: {motion[0].shape}")

API Reference

model(text, length=60, text_end=None, num_denoise_steps=None, output_joints=False, smoothing_alpha=1.0)

Generate motion sequences from text descriptions.

Parameters:

  • text (str, List[str], or List[List[str]]): Text description(s)

    • Single string: Generate one motion
    • List of strings: Batch generation
    • Nested list: Multiple text prompts per motion (for transitions)
  • length (int or List[int], default=60): Number of latent tokens to generate

    • Output frames ≈ length × 4 (due to VAE upsampling)
    • Example: length=60 → ~240 frames (~12 seconds at 20 FPS)
  • text_end (List[int] or List[List[int]], optional): Latent token positions for text transitions

    • Only used when text is a nested list
    • Specifies when to switch between different text descriptions
    • IMPORTANT: Must have the same length as the corresponding text list
      • Example: text=[["walk", "turn", "sit"]] requires text_end=[[20, 40, 60]] (3 endpoints for 3 texts)
    • Must be in ascending order
  • num_denoise_steps (int, optional): Number of denoising iterations

    • Higher values produce better quality but slower generation
    • Recommended range: 10-50
  • output_joints (bool, default=False): Output format selector

    • False: Returns 263-dimensional HumanML3D features
    • True: Returns 22×3 joint coordinates for direct visualization
  • smoothing_alpha (float, default=1.0): EMA smoothing factor for joint positions (only used when output_joints=True)

    • 1.0: No smoothing (default)
    • 0.5: Medium smoothing (recommended for smoother animations)
    • 0.0: Maximum smoothing
    • Range: 0.0 to 1.0

Returns:

  • Single motion:
    • output_joints=False: numpy.ndarray of shape (frames, 263)
    • output_joints=True: numpy.ndarray of shape (frames, 22, 3)
  • Batch: List[numpy.ndarray] with shapes as above

Example:

# Single generation (263-dim features)
motion = model("walk forward", length=60)  # Returns (240, 263)

# Single generation (joint coordinates)
joints = model("walk forward", length=60, output_joints=True)  # Returns (240, 22, 3)

# Batch generation
motions = model(["walk", "run"], length=[60, 50])  # Returns list of 2 arrays

# Multi-text transitions
motion = model(
    [["walk", "turn"]],
    length=[60],
    text_end=[[30, 60]]
)  # Returns list with 1 array of shape (240, 263)

昇腾 NPU 部署(AtomGit)

本仓库为 ShandaAI/FloodDiffusionTiny 的昇腾 910B NPU 部署版。模型走 PyTorch + torch_npu + FastAPI(非 vLLM),已在 Ascend910_9362 / CANN 8.5.1 上验证通过。

权重下载

# 方式一:git clone 镜像仓库(gitcode / atomgit hf_mirrors)
git clone https://ai.gitcode.com/hf_mirrors/ShandaAI/FloodDiffusionTiny.git weights
git clone https://ai.gitcode.com/hf_mirrors/google/umt5-base.git weights/umt5-base
# 注:克隆后 safetensors 为 LFS 指针,需 git-lfs pull 或 LFS batch API 下载实际权重

# 方式二:huggingface_hub(hf-mirror.com)
HF_ENDPOINT=https://hf-mirror.com python3 -c "from huggingface_hub import snapshot_download; \
  snapshot_download('ShandaAI/FloodDiffusionTiny', local_dir='weights'); \
  snapshot_download('google/umt5-base', local_dir='weights/umt5-base')"

# 方式三:ModelScope(国内 CDN 快,推荐 umt5-base 大文件)
#   https://modelscope.cn/models/google/umt5-base/resolve/master/pytorch_model.bin
wget -c https://modelscope.cn/models/google/umt5-base/resolve/master/pytorch_model.bin -O weights/umt5-base/pytorch_model.bin

注:hf-mirror 对大文件偶发断连,建议 wget -c 断点续传;已验证 ModelScope 的 pytorch_model.bin(2.4GB)与本仓库字节一致,可作为可靠替代。

NPU 适配说明

原始 ldf_models/tools/attention.py 强依赖 CUDA 的 flash-attn。本仓库对三处做了 昇腾适配(NPU 上自动生效,CUDA 行为不变):

  1. attention.py:flash_attention 在非 CUDA 设备上回退到手动 matmul + softmax(_manual_attention),保留变长掩码语义。CANN 的 aclnnFlashAttentionScore 不支持 fp32 + bool 掩码组合(报 161002)。
  2. wan_model.py rope_apply:复数 RoPE 内部使用 complex128,CANN 不支持 DT_COMPLEX128,整段回退到 CPU 计算后回传原设备。
  3. wan_model.py WanModel.forward:self.freqs(complex128)保持 CPU,不随 模型搬移到 NPU。

CLI 单次推理

# CPU 冒烟测试
python3 inference.py --model-path weights --device cpu --text "a person walking forward" --length 20

# 昇腾 NPU 推理(length=60 -> ~240 帧 @20FPS)
python3 inference.py --model-path weights --device npu:0 --text "a person walking forward" --length 60

# 关节坐标输出(22x3,EMA 平滑 alpha=0.5)
python3 inference.py --model-path weights --device npu:0 --text "a person walking forward" --length 20 --output-joints --smoothing-alpha 0.5

FastAPI 服务

python3 inference.py --serve --model-path weights --device npu:0 --port 8001
# Swagger: http://<host>:8001/docs
端点方法说明
/healthGET健康检查(返回设备/是否 NPU)
/v1/modelsGET模型信息
/v1/predictPOST{"text":"...", "length":60, "output_joints":false} → motion

实测结果

以下数值在昇腾 910B NPU(Ascend910_9362,CANN 8.5.1)上实测。

指标值
输入文本a person walking forward
length / 输出帧数60 / ~240
输出维度(240, 263),float32
root_speed_mean~0.05
feature_abs_mean~0.33
模型加载(含 2.4GB umt5-base)~5-9 s(首次冷加载 ~9s)
首次推理(含算子编译,length=60)~8.7 s
预热后推理(length=60,10 步去噪)~7.9 s
关节坐标推理(length=20,含 recovery)~3 s

生成的动作特征(263 维 HumanML3D)经 StreamJointRecovery263 还原为 22×3 关节坐标 演示输出站立高度(Y 向跨度)约 1.57 m,根节点沿 Z 轴平稳前移,符合 "person walking forward" 语义。

推理耗时主要来自扩散去噪(10 步 × 逐时间步前向);缩短 num_denoise_steps 或 length 可线性降低耗时。umt5-base 文本编码有缓存(同文本只编码一次)。

Citation

If you use this model in your research, please cite:

@article{cai2025flooddiffusion,
  title={FloodDiffusion: Tailored Diffusion Forcing for Streaming Motion Generation},
  author={Yiyi Cai, Yuhan Wu, Kunhang Li, You Zhou, Bo Zheng, Haiyang Liu},
  journal={arXiv preprint arXiv:2512.03520},
  year={2025}
}