项目简介
SANA 是一个面向高效高分辨率图像与视频生成的开源代码库,提供完整的训练与推理流程。基于线性扩散 Transformer,支持文生图、文生视频以及世界模型等任务。
README 预览
\n \n\n\n\n📚 Docs | SANA | SANA-1.5 | SANA-Sprint | SANA-Video | SANA-WM | Sol-RL\n \nDemo | 🤗 HuggingFace | ComfyUI | SGLang | Cosmos-RL\n\n\n\n\n  \n  \n  \n  \n  \n\n\n\n  \n  \n\n\nICLR 2025 Oral | ICML 2025 | ICCV 2025 Highlight | ICLR 2026 Oral \n\n**SANA** is an efficiency-oriented codebase for high-resolution image and video generation, providing complete training and inference pipelines. This repository contains code for [SANA](https://nvlabs.github.io/Sana/), [SANA-1.5](https://nvlabs.github.io/Sana/Sana-1.5/), [SANA-Sprint](https://nvlabs.github.io/Sana/Sprint/), [SANA-Video](https://nvlabs.github.io/Sana/Video/), [SANA-WM](https://nvlabs.github.io/Sana/WM/), and [Sol-RL](https://nvlabs.github.io/Sana/Sol-RL/). More details can be found in our [📚 documentation](https://nvlabs.github.io/Sana/docs/).\n\nJoin our [Discord](https://discord.gg/rde6eaE5Ta) to engage in discussions with the community! If you have any questions, run into issues, or are interested in contributing, don't hesitate to reach out!\n\n\n \n\n\n## News\n\n- 🔥 [2026/05] 🌍 **SANA-WM: 2.6B Controllable World Model** is released! Supports 720p, 1-min video generation with 6-DoF camera control. A new baseline for World Modeling and Embodied AI. See [Project](https://nvlabs.github.io/Sana/WM/) | [Paper](https://huggingface.co/papers/2605.15178).\n- 🔥 [2026/04] ⚡ **Sol-RL: NVFP4 Rollout, BF16 Training RL** is available! All training recipes for **SANA**, **FLUX.1**, and **SD3.5-L**, together with bundled post-training datasets, are released. See [Sol-RL doc](https://nvlabs.github.io/Sana/docs/sol_rl/) | [Page](https://nvlabs.github.io/Sana/Sol-RL/) | [Paper](https://arxiv.org/abs/2604.06916).\n- 🔥 [2026/03] 📺 **SANA-Video 720p model with LTX-VAE** is released. Use it with LTX2 Refiner to upscale the videos to 2K resolution! See [Model Zoo](https://nvlabs.github.io/Sana/docs/model_zoo/#sana-video), [SANA-Video doc](https://nvlabs.github
常见问题 (4)
故障排除如何将自定义训练的基础扩散模型转换为diffusers格式,以便用于Dreambooth和LoRA微调?
使用提供的脚本:python tools/convert_sana_to_diffusers.py。该脚本将非diffusers权重转换为预期的diffusers状态字典格式,使模型与Dreambooth和LoRA训练脚本兼容。
故障排除为什么 Sol-H3 Stage 2 的唇形同步效果很差,在没有人说话时嘴唇也会动?我该如何修复?
在 Sol-H3-Spark / Sol-H3-RTX5090 中,Stage 2 会对 H3 音频进行编码,将其重新加噪至第一个 Stage-2 sigma(0.909375),并与视频联合去噪,随后丢弃该音频并混流原始的 H3 PCM。唇部是参照重新生成的音轨进行细化的——该音轨是听起来像英语的无意义杂音,甚至可能在无声停顿中包含语音——因此唇形同步会发生漂移(SyncNet LSE-C 从 ~8.2 降至 ~4.4),并且嘴巴可能在环境底噪期间运动。修复方法(已合并至 PR #543):在 Stage-2 细化期间保持音频干净且冻结,完全按照 LTX-2 的 a2vid_two_stage.py 的做法——以 ModalitySpec(frozen=True, noise_scale=0.0, initial_latent=encoded_audio_latent) 的形式传入音频,而不是对其加噪。这恢复了唇形同步(LSE-C ~4.4 → 7.8),渲染时间相同,输出音频不变。更新至 commit 62da34b 之后的版本即可获得该修复。
故障排除如何解决 LongSana 在 Ascend NPU 上崩溃并提示 "Torch not compiled with CUDA enabled" 或 NCCL 错误的问题?
LongSana 在分布式初始化和 FSDP 设备设置中硬编码了 CUDA/NCCL,因此在非 CUDA 加速器(例如搭载 torch_npu 的 Ascend NPU 910B)上会运行失败。此问题已由 PR #514 修复。请应用以下更改:(1)在 diffusion/longsana/utils/distributed.py 中,添加设备/后端解析辅助函数:get_device_type()、get_current_device()、get_default_dtype()、set_device() 和 get_distributed_backend(),它们在 Ascend 上返回 npu/hccl,在 CUDA 上返回 cuda/nccl,在仅 CPU 环境下返回 cpu/gloo。(2)替换硬编码调用:将 launch_distributed_job(backend="nccl")(第 83 行)改为使用 get_distributed_backend();将 torch.cuda.set_device(local_rank)(第 97 行)替换为 set_device(local_rank);将 FSDP 封装中(第 69 行)的 device_id=torch.cuda.current_device() 替换为 get_current_device()。(3)在 diffusion/longsana/trainer/ode.py:41 和 trainer/self_forcing_trainer.py:47 中,将 self.device = torch.cuda.current_device() 替换为该解析器。(4)在各 pipeline 文件(sana_training_pipeline.py、sana_inference_pipeline.py、sana_inference_interactive_pipeline.py、sana_inference_interactive_pipeline_long_chunk.py)中,将 torch.device("cuda" if torch.cuda.is_available() else "cpu") 以及 fp32 回退 dtype 替换为 get_device_type()/get_default_dtype(),以便正确检测到 NPU,而不是静默回退到 CPU/fp32。打补丁后,torchrun --nproc_per_node=N longsana_trainer.py 可以正确初始化 HCCL,并且 FSDP 会在 npu:<rank> 上封装参数。CUDA 行为保持不变。
故障排除为什么LongSanaVideoPipeline从diffusers中缺失,以及如何运行LongSana?
LongSanaVideoPipeline在diffusers库中尚未实现(即使在最新的开发版本中)。Hugging Face模型页面显示其状态为“即将推出”。作为替代方案,请克隆官方的Sana仓库:git clone https://github.com/nvlabs/Sana.git,并按照其推理指南操作。如果您需要视频生成,也可以尝试已有的SANA-Video pipeline。