buildborderless/CommunityForensics-DeepfakeDet-ViTvit_small_patch16_384.augreg_in21k_ft_in1k based, 12 layers, hidden 384, 6 heads, intermediate 1536)本次适配验证为 vision-encoder / image-classification 路线,inspect 报告 route=unknown 但依据 model_type=vit 与 ViTForImageClassification 按分类头契约验证 embeddings 对应改为 logits/prob。未启用 trust_remote_code,无自定义 Python 风险。
npu:0 (PhysID 10, Bus 0000:0A:00.0)python .claude/skills/npu-adapt-skills/scripts/check_npu.py 返回 passed:true, torch_npu_available:true, device_count:2npu-smi info 输出 (节选):
| 5 Ascend910 OK 169.9W 47C 3111/65536 MB |
| Chip 0 Phy-ID 10 Bus-Id 0000:0A:00.0 AICore 0% Memory 0/0 HBM 3111/65536 |pip install -r requirements.txt
# requirements.txt:
# torch>=2.0.0
# torch_npu>=2.0.0
# transformers>=4.44.0
# Pillow>=9.0.0
# numpy>=1.24.0
# safetensors>=0.4.0
# huggingface_hub>=0.20.0如需从 Hugging Face 拉取权重 (自动缓存):
python -c "from huggingface_hub import snapshot_download; snapshot_download('buildborderless/CommunityForensics-DeepfakeDet-ViT', local_dir='./model')"或本仓已演示的 hf_hub_download 单文件下载。本地 model/ 目录含 config.json + preprocessor_config.json + model.safetensors 即可推理,无需联网。
默认在 npu:0 执行真实 NPU 推理,含首次编译与稳定推理分开计时,同步点 torch.npu.synchronize():
python inference.py
# 或
python inference.py --mode validate # CPU vs NPU 一致性
python inference.py --mode benchmark # 10 次稳定推理性能加载后端: transformers ViTForImageClassification.from_pretrained,processor: AutoImageProcessor (CLIPImageProcessor),dtype float32,device 显式 .to("npu:0"),输入 pixel_values.to("npu:0")。
首次执行需约 210-220 ms 编译,之后稳定 ~5.9 ms / 384×384 图像。
使用固定伪造/真实混合的 3 张合成图像 (确定性,无外部数据集依赖):
red_500x700: 纯红 500×700 (短边 500 → 缩放 440, 裁剪 384)green_384x384: 纯绿 384×384gradient_1024x768: 梯度图 1024×768本次真实 python inference.py 输出 (NPU, npu:0, float32):
model_name: buildborderless/CommunityForensics-DeepfakeDet-ViT
torch_npu_available: True npu_device_name: Ascend910_9362 npu_device_count: 2
model_first_param_device: npu:0 model_dtype: torch.float32 target_device: npu:0
input: red_500x700 original_size=(500, 700) pixel_values shape=(1, 3, 384, 384) mean=-0.4340
output: red_500x700 logit=-3.892607 fake_prob=0.019985 real_prob=0.980015 verdict=real latency=220.73ms
input: green_384x384 original_size=(384, 384) pixel_values shape=(1, 3, 384, 384) mean=-0.3992
output: green_384x384 logit=3.531634 fake_prob=0.971575 real_prob=0.028425 verdict=fake latency=6.58ms
input: gradient_1024x768 original_size=(1024, 768) pixel_values shape=(1, 3, 384, 384) mean=0.1877
output: gradient_1024x768 logit=-3.734825 fake_prob=0.023321 real_prob=0.976679 verdict=real latency=6.49ms
avg_latency_ms: 77.93ms total_images=3
cpu_npu_logit_diff (first sample): 0.023084 cpu=-3.869523 npu=-3.892607
consistency: PASS (diff 0.023084 <= atol 0.05)
[PASS] NPU inference completed successfully说明:
first_param_device 确认模型驻留 npu:0,无 CPU fallback。同一权重、同一输入、同一预处理、同一 dtype (float32), batch=1,对比 logits:
python inference.py --mode validate真实输出:
red_500x700 diff=0.023084 cpu=-3.869523 npu=-3.892607
green_384x384 diff=0.006612 cpu=3.525022 npu=3.531634
gradient_1024x768 diff=0.013078 cpu=-3.747903 npu=-3.734825
max_diff=0.023084 mean_diff=0.014258abs(cpu - npu),阈值 atol 0.05 (结合 float32 与 NPU 编译容差)npu:0。条件: npu:0, float32, 384×384, batch 1, processor 含 resize+crop+normalize (计时含在 model forward 区间,torch.npu.synchronize() 前后).
benchmark_runs: 10 image_size: 384x384 dtype: float32 device: npu:0
times_ms: [5.94,5.92,5.94,5.87,5.94,5.83,5.89,5.85,5.92,5.93]
avg=5.91 min=5.83 max=5.95 p50=5.92 p90=5.95 p95=5.95
吞吐: ~169 images/s (1/0.00591)三张 PNG 由本提交 xterm.js 依据真实日志渲染 (--style raw),SHA-256 对应源日志:
assets/agent_workflow.png — 工作流: 下载/侦察/检查/NPU 推理/验证/性能 的真实 stdoutassets/npu_device_call.png — 设备调用: npu-smi info、torch.npu.is_available()、设备名、参数 device/dtypeassets/model_result.png — 模型结果: python inference.py 真实任务输出与 PASS

生成命令:
npm --prefix .claude/skills/npu-adapt-skills/scripts install
node .claude/skills/npu-adapt-skills/scripts/render_xterm_evidence.mjs --manifest evidence/manifest.json --output-dir buildborderless-CommunityForensics-DeepfakeDet-ViT-NPU/assets --style raw
python .claude/skills/npu-adapt-skills/scripts/validate_submission.py buildborderless-CommunityForensics-DeepfakeDet-ViT-NPUViTImageProcessor 不支持 shortest_edge 语法,需使用 AutoImageProcessor (实际为 CLIPImageProcessor);若使用 fast processor 需确认 size 语义一致,否则将静默 squash 图像。unknown (非 CLIP/SAM/FLUX/VLM),本仓按 image-classification 分类头契约验收 embedding 不适用。Hardware: NPU NPU Ascend Ascend910 Ascend910B ViT deepfake image-classification vision forensics