基于 EPFL-VILAB/videoflextok_d18_d28 的昇腾 NPU(torch_npu)适配实现。视频 tokenizer:输入视频帧,输出离散 FSQ token 序列。
该变体为 encoder 深度 18、decoder 深度 28(d18_d28),运行分辨率 256×256,VidTok VAE 潜变量网格 [5, 32, 32],patch [1, 2, 2],输出 token 序列形状 [1, 5, 256](共 1280 个 FSQ token)。
.cuda() / torch.device('cuda'),模型与输入张量全部迁移至 npu:0,并带 try-except NPU 初始化异常捕获。torch.nn.attention.flex_attention 的 ArgSort 内核算子在昇腾 NPU 上不可用,替换为等价的 dense bool-mask + torch.nn.functional.scaled_dot_product_attention 实现(该配置未使用 score_mod,替换无损)。torch.amp.autocast('cuda') 全部替换为 'npu'。./model_weights/EPFL-VILAB/videoflextok_d18_d28/,优先加载本地缓存,避免重复下载。python inference.py --input demo_frames/ # 输入帧目录(或 zip / 单张图片)真实输出示例(npu:0):
device: npu:0 | tokens shape: [1, 5, 256] | total FSQ tokens: 1280python inference.py --serve # 监听 0.0.0.0:8000GET /:上传页面(支持 zip / 单张图片 / JSON {"mode":"demo"})POST /predict:返回推理 JSONpython inference.py --input demo_frames/ → exit 0,输出 token 序列 [1, 5, 256](1280 FSQ token,与 config n_max=256 一致)GET / 200,POST /predict(JSON 与 zip 上传)200assets/:agent_workflow.png / npu_device_call.png / model_result.png