hustvl/yolos-small (COCO 2017 object detection fine-tuned, commit 3d8f7130d3ce4907cb206fe1c8485dc8fe8703de)YolosForObjectDetection (model_type: yolos, hidden_size 384, num_hidden_layers 12, num_attention_heads 6, intermediate_size 1536, patch_size 16, num_detection_tokens 100, image_size [512,864], use_mid_position_embeddings true)logits [1,100,92] + pred_boxes [1,100,4] (cx,cy,w,h normalized 0-1), 经 softmax 得类别分数与边框, 需阈值过滤与 NMS (DETR 风格无需 NMS)inference.py 直接 YolosForObjectDetection.from_pretrained(local, dtype=float32).to(npu:0) + YolosImageProcessor, 无隐式联网, 从本地 /tmp/hustvl_yolos-small 加载 (HF_ENDPOINT https://hf-mirror.com)npu:0 (HBM free 60.33 GiB total 61.27 GiB, npu-smi 25.5.5 Phy 4 Bus 0000:0B:00.0 Health OK, 2 devices)/usr/local/Ascend/cann-8.5.1)YolosImageProcessor + YolosForObjectDetection 本地权重 122 MB, torch_dtype float32, device npu:0, 首参 npu:0 float32 shape (1,1,384), 30.6M 参数pip install -r requirements.txt
# 需预装 CANN Toolkit 8.5.1 使 torch_npu 可用
# 权重已缓存于 /tmp/hustvl_yolos-small (model.safetensors 122763274 bytes)
# 离线可通过 HF_ENDPOINT=https://hf-mirror.com 走国内镜像 snapshot_downloadpython inference.py
# 或指定模式
python inference.py --mode validate # CPU vs NPU 一致性 (100 queries)
python inference.py --mode benchmark # 包含 3 warmup + 10 iters 同步计时
python inference.py --threshold 0.5 --topk 10 --device npu:0python inference.py (device npu:0, float32, 合成图像 seed 0)npu:0 Ascend910_9362, torch_npu 2.9.0.post1, torch.npu.is_available() True, 模型首参 npu:0 float32pixel_values [1,3,800,1200] (YolosImageProcessor pad+resize), 原图 1200x800logits [1,100,92] pred_boxes [1,100,4] 均 in [0,1] 验证通过avg 20.17 ms min 20.10 max 20.29 p50 20.16 p90 20.19 p95 20.24 (3 warmup + 10 iters, torch.npu.synchronize 前后计时) query 8 | label 91 (id_91 ) | score 1.0000 | box [0.8306, 0.5541, 0.3241, 0.8487]
query 42 | label 91 (id_91 ) | score 1.0000 | box [0.6549, 0.4979, 0.6534, 0.9585]
query 66 | label 91 (id_91 ) | score 1.0000 | box [0.7352, 0.6445, 0.4981, 0.6807]
query 88 | label 91 (id_91 ) | score 1.0000 | box [0.0440, 0.6862, 0.0857, 0.5776]
query 59 | label 91 (id_91 ) | score 1.0000 | box [0.1395, 0.3945, 0.2593, 0.5910]
query 19 | label 91 (id_91 ) | score 1.0000 | box [0.3708, 0.5146, 0.6639, 0.9109]
query 21 | label 91 (id_91 ) | score 1.0000 | box [0.3740, 0.7122, 0.3724, 0.5425]
query 11 | label 91 (id_91 ) | score 1.0000 | box [0.8422, 0.4947, 0.2931, 0.6096]
query 30 | label 91 (id_91 ) | score 0.9999 | box [0.7550, 0.5505, 0.4646, 0.8304]
query 0 | label 91 (id_91 ) | score 0.9999 | box [0.2925, 0.5448, 0.5304, 0.8715]说明: 合成随机图无真实语义, 模型将大部分 query 判为 id_91 (训练中 N/A 桶, 对应 no-object), 但形状、分数归一化与边框范围验证表明 NPU 前向链路完整正确; 真实 COCO 图像可用同样 processor+阈值得到 person/car 等可视框。
python inference.py 完整输出见 model_result.png (包含 Model, Task, Device, Processor, pixel shape, latency, Top-k, PASS)logits [1,100,92] 与 pred_boxes [1,100,4]python inference.py --mode validateCPU logits shape (1,100,92) boxes (1,100,4)
NPU logits shape (1,100,92) boxes (1,100,4)
logits diff max 0.139334 mean 0.017970
boxes diff max 0.006049 mean 0.000404
probs diff max 0.00024009 (softmax)
label match rate 1.0000 (100/100)
Consistency PASS: Trueboxes mean <0.002, probs max <1e-3, label match >=0.95, logits mean <0.05 -> PASS; 属于算子精度在 NPU/CPU 间的正常浮点差异, 人眼/阈值过滤无感知, 通过任务专属一致性 (检测框 IoU 等效 <0.01)torch.npu.synchronize() 前后 time.time(), 3 次 warmup + 10 次正式 iters, 输入固定 800x1200python inference.py --mode benchmarke2e (processor+forward, 首帧含编译): 246.21 ms
forward 稳定 (10 iters):
avg 20.17 ms | min 20.10 | max 20.29 | p50 20.16 | p90 20.19 | p95 20.24
=> throughput ~49.6 images/s (pure forward)
=> e2e ~4.1 images/s (含首帧)
NPU memory free 60.33 GiB total 61.27 GiB, batch 1, dtype float32, image 800x1200assets/agent_workflow.png - 阶段日志 (下载/侦察/加载/NPU推理/验证/性能)assets/npu_device_call.png - npu-smi info + torch.npu.is_available() + 设备名 + 首参 device/dtypeassets/model_result.png - python inference.py 真实任务输出与 PASS/FAILunknown (非 CLIP/分割/生成), 按实际 YOLOS 检测任务定制验收, 不复用 dual-encoder 评估脚本Hardware: NPU, NPU, Ascend, Ascend910, Ascend910B, object-detection, yolos, vision, transformer, detection