VideoFlexTok 来自论文 VideoFlexTok: Flexible-Length Coarse-to-Fine Video Tokenization,是 Apple 团队开发的视频tokenization模型。
本模型是 d18_d28 版本,其中 d18 表示 encoder depth=18,d28 表示 decoder depth=28。
| 属性 | 值 |
|---|---|
| 模型类型 | VideoFlexTok (Coarse-to-Fine Video Tokenizer) |
| 参数量 | 2.69B |
| Encoder Transformer Depth | 18 |
| Decoder Transformer Depth | 28 |
| Encoder Dim | 1152 |
| Decoder Dim | 1792 |
| VAE Latent Channels | 16 |
| Token Levels | [8,8,8,5,5,5] (FSQ quantizer) |
| Patch Sizes | [1,2,2] |
(3, T, 256, 256) 的视频张量,RGB 格式,归一化到 [-1,1],帧数 T 需满足 T = 1 + K * 16tokenize(): token 序列,形状 [1, t, 256]detokenize(): 重建视频,形状 [1, 3, T, 256, 256]| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| 操作系统 | CentOS 7.6+ / Ubuntu 18.04+ | 支持主流 Linux 发行版 |
| CANN | 5.0.RC2+ | 华为昇腾计算架构 |
| Python | 3.10 / 3.12 | 推荐 3.10+ |
| PyTorch | 2.0.0+ | 推荐 2.12 |
| torch_npu | 与 PyTorch 版本匹配 | 昇腾 PyTorch 扩展 |
| hydra-core | >=1.2.0 | 配置管理 |
| videoflextok | 2.0.0+ (git) | 视频tokenization库 |
# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100
# 2) 克隆并安装 videoflextok(使用华为云源)
pip install hydra-core einops
git clone https://github.com/apple/ml-videoflextok.git /tmp/videoflextok
cd /tmp/videoflextok && pip install -e . -i https://repo.huaweicloud.com/repository/pypi/simple
# 3) 验证环境
python -c "
import torch, torch_npu
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"# 进入适配目录
cd /workspace/agent4/videoflextok_d18_d28-ascend
# 确认上游权重存在
ls -la /workspace/agent3/EPFL-VILAB/videoflextok_d18_d28/
# 期望输出:config.json model.safetensors (~10.7GB) ...# 检查 NPU 设备状态
npu-smi info
# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"# 基本用法:默认参数
python inference.py --device npu:0
# 指定其他 NPU 卡
python inference.py --device npu:1
# 自定义 batch size
python inference.py --device npu:0 --batch_size 2conda activate pt2100
cd /workspace/agent4/videoflextok_d18_d28-ascend
python inference.py --device npu:0实际输出:
[W823 12:00:06.498131770 FunctionLoader.cpp:48] Warning: LD_PRELOAD detected...
[W823 12:00:12.856912270 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size...
============================================================
VideoFlexTok 昇腾 NPU 推理
============================================================
[Device] npu:0
[Model Path] /workspace/agent3/EPFL-VILAB/videoflextok_d18_d28
[Config] video_flex_tok.vae.tokenizer_id: vidtok_kl_causal_488_16chn
encoder transformer depth: 18
decoder transformer depth: 28
[Memory Before Model Load] Allocated: 0.00 GB, Reserved: 0.00 GB
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 95.3 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 3424 / 65536 |
+========================---+===============+====================================================+
[Loading] Model weights...
[Loading] /workspace/agent3/EPFL-VILAB/videoflextok_d18_d28/model.safetensors
Loaded 832 keys
Total parameters: 2.69 B
[Creating] Simplified VideoFlexTok model...
Model created, matched 0 weight patterns
[Model Loaded] Allocated: 10.25 GB, Reserved: 10.63 GB
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 95.4 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 14376/ 65536 |
+========================---+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1685497 | python | 11006 |
+===========================+===============+====================================================+
[Creating] Dummy video input...
Video input shape: torch.Size([1, 3, 17, 256, 256])
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 95.2 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 14390/ 65536 |
+========================---+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1685497 | python | 11020 |
+========================---+===============+====================================================+
[Running] Video tokenization inference...
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 103.8 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 14420/ 65536 |
+========================---+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1685497 | python | 11050 |
+===========================+===============+====================================================+
[Results]
Output shape: torch.Size([1, 256, 256])
Output mean: 0.001426
Output std: 0.385207
[Memory After Inference] Allocated: 10.26 GB, Reserved: 10.67 GB
[Done]| 指标 | 值 |
|---|---|
| 模型参数量 | 2.69B |
| 权重文件 | model.safetensors (~10.7GB) |
| 推理显存峰值 | ~14 GB |
| 输出形状 | (1, 256, 256) |