Run this model with HF Jobs
Run ruisv/rcdl-pe-core on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ruisv/rcdl-pe-core. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ruisv/rcdl-pe-core on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use ruisv/rcdl-pe-core with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PerceptionEncoder
How to use ruisv/rcdl-pe-core with PerceptionEncoder:
# Use any PE model as a vision encoder import core.vision_encoder.pe as pe model = pe.VisionTransformer.from_config("ruisv/rcdl-pe-core", pretrained=True) - Notebooks
- Google Colab
- Kaggle
PE-Core-S16-384 for RK3588: image embeddings and zero-shot classification
A compiled model for the Rockchip RK3588 / RK3588S NPU, ready to load: no
ONNX export, no conversion. It is the image tower of Meta's Perception
Encoder PE-Core-S16-384, as an .rnpu file: an fp16 build made by the NPU
compiler of RCDL and run by RCDL's own NPU
runtime, which drives the board's rknpu kernel driver directly. librknnrt and
rknn-toolkit2 are not involved, and there is no .rknn build of this model. It
comes with a text-embedding table for the 80 COCO labels, so zero-shot
classification works out of the box. RCDL is a C++17 / Python library that
drives the NPU, RGA and VPU on these boards as one zero-copy pipeline. Its NPU
stack is described in
docs/OPEN_NPU.md.
Upstream: Perception Encoder
PE-Core-S16-384 (Meta): a ViT-S/16 image tower at 384 with 2-D rotary
positions and attention pooling. Exported from perception_models
(CLIP.from_config("PE-Core-S16-384"), its .visual), opset 17.
Redistributable, including commercially. Meta releases PE-Core under Apache-2.0, on the code and on the weights, and the text table is that same model's output. See Licence.
Files
| file | what it is | size |
|---|---|---|
pe_core_s16_384_fp16.rnpu |
image encoder: 384×384 RGB, stretched → 512-d unit vector | 69.1 MB |
pe_core_s16_384_text_coco80.npy |
text embeddings of the 80 COCO labels, [80, 512] |
160 KB |
pe_core_s16_384_labels.txt |
the 80 labels, one per line, in the table's row order | 1 KB |
Only the image tower runs on the board. It takes uint8 RGB, with
(x − 127.5) / 127.5 inside the build, and the whole frame is stretched onto
the 384×384 input. The text side is a fixed table, computed off the board by
the same model's text tower: unit vectors of a photo of a <name>. over the 80
COCO names. Zero-shot classification is then one dot product per label.
Measured on RK3588S and RK3588
| model | infer, RK3588S | whole task, RK3588S | infer, RK3588 | whole task, RK3588 | result |
|---|---|---|---|---|---|
| PE-Core-S16-384 | 169.59 ms | 170.9 ms | 166.79 ms | 168.1 ms | bus.jpg → bus, bird.jpg → bird, the space shuttle → airplane |
From RCDL's
benchmark:
RCDL 0.3.0 conda packages on RCDL's own NPU runtime, NPU driver 0.9.8, one NPU
core, the performance CPU governor with the process pinned to the A76 cores,
median of nine runs after at least a second of warm-up. The RK3588S ran BSP
kernel 6.1.118, the RK3588 6.1.141. Infer is the model run as the runtime
times it: its NPU segments and the CPU operators between them. Whole task
is one frame to one embedding.
Against the float model on 23 images (20 COCO images, the bus, the bird and the
space shuttle), the embeddings agree to a cosine of 0.99991 on average,
0.99981 at worst. Every image's best COCO name is the float model's. On
bus.jpg the top label is bus at +0.30, with the runner-up at +0.23.
On an RK3588 it takes 167 ms on one core and 143 ms on three.
Use it
On the board (linux-aarch64), with RCDL 0.3.1 or newer:
conda create -n rcdl -c https://mirrors.ruis.ai/conda -c conda-forge rcdl
conda activate rcdl
curl -LO https://huggingface.co/ruisv/rcdl-pe-core/resolve/main/pe_core_s16_384_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-pe-core/resolve/main/pe_core_s16_384_text_coco80.npy
curl -LO https://huggingface.co/ruisv/rcdl-pe-core/resolve/main/pe_core_s16_384_labels.txt
import cv2, numpy as np, rcdl
emb = rcdl.Engine("pe_core_s16_384_fp16.rnpu").embedder()
table = np.load("pe_core_s16_384_text_coco80.npy") # [80, 512]
labels = [l.strip() for l in open("pe_core_s16_384_labels.txt") if l.strip()]
for name in ("bus.jpg", "bird.jpg"):
v = np.asarray(rcdl.embed(emb, cv2.imread(name)), np.float32).ravel()
v /= np.linalg.norm(v)
sims = table @ v
top = np.argsort(-sims)[:3]
print(name, "->", ", ".join(f"{labels[i]} {sims[i]:+.3f}" for i in top))
rcdl.embed(emb, img, box=(x1, y1, x2, y2)) embeds a crop instead of the
whole frame.
What to know before deploying
Three cores gain little, because part of the model runs on the CPU. The rotary positions, and the per-head splits around them, run on the CPU: 90 conversions each way between the NPU and the CPU. The attention on the NPU is ready for them, but RCDL's compiler does not yet place a rotary embedding there. Hence 167 ms on one core and 143 ms on three.
Read the margin, not the raw cosine. The labels' cosines sit close
together: on bus.jpg, bus scores +0.30 and the runner-up +0.23. Decide on
the gap to the next label rather than on a fixed cosine.
Another vocabulary needs no reconversion. Swap the table, not the model: run the text tower of the same checkpoint on any machine over your labels, with the same prompt form, and save the unit vectors in your label file's row order. A table only works with the model that made it.
A smaller alternative to SigLIP base/16. RCDL also ships SigLIP base/16, whose embeddings are 768-d. Both use the same 80 COCO names in the same order, but neither's text table fits the other's image tower.
Time it under the performance governor. The boards default to
schedutil, which clocks the CPU down while it waits for the NPU. Under it,
benchmark rows that alternate NPU and CPU work measured up to about four times
the numbers above, and different ones on every run. The results did not change.
.rnpu is RCDL's own format, and its NPU stack is marked experimental.
The .rnpu format may still change. This file runs on RK3588 / RK3588S
through the rknpu driver of the vendor BSP kernels (rknpu 0.9.8, verified on
kernels 6.1.118 and 6.1.141). RK3576 and RK356x are not verified, and the
mainline kernel's rocket driver is not supported.
Licence
Apache-2.0, as Meta releases PE-Core, on the code and on the weights. The text table and labels are derived from that same model and carry the same terms.
RCDL itself is Apache-2.0 and is unrelated to these terms. It is a
general-purpose runtime that loads any .rnpu or .rknn. The licence above
applies to these weights and these compiled files only.
How the build was made, and the input contract for every model, are documented
in RCDL's
docs/MODELS.md. The
licence status of every model RCDL has verified is in
model_zoo/.
中文说明
Meta 的 Perception Encoder PE-Core-S16-384 的图像塔,为 瑞芯微 RK3588 /
RK3588S NPU 编译好的模型,下载后直接加载,不用导出 ONNX,也不用转换。文件是
.rnpu 格式的 fp16 构建:由 RCDL 自研的 NPU 编译器
生成,由 RCDL 自己的 NPU 运行时直接驱动板子上的 rknpu 内核驱动来运行,不需要
librknnrt,也不需要 rknn-toolkit2;这个模型没有 .rknn 版本。另附一张 COCO 80 类的
文本嵌入表,零样本分类开箱即用。自研 NPU 栈的介绍见
docs/OPEN_NPU.zh.md。
上游是 Perception Encoder
的 PE-Core-S16-384:384 输入的 ViT-S/16 图像塔,带二维旋转位置编码和注意力池化,从
perception_models 导出(CLIP.from_config("PE-Core-S16-384") 的 .visual,
opset 17)。Meta 以 Apache-2.0 发布代码和权重,文本表也是这个模型自己的输出,
可以再分发,包括商用。
文件
| 文件 | 内容 | 大小 |
|---|---|---|
pe_core_s16_384_fp16.rnpu |
图像编码器:384×384 RGB(拉伸)→ 512 维单位向量 | 69.1 MB |
pe_core_s16_384_text_coco80.npy |
COCO 80 个类名的文本嵌入,[80, 512] |
160 KB |
pe_core_s16_384_labels.txt |
这 80 个类名,每行一个,顺序与表的行一致 | 1 KB |
板上只跑图像塔。它吃 uint8 RGB,(x − 127.5) / 127.5 已经放进模型里,整帧拉伸到
384×384 输入上。文本这边是一张固定的表,由同一模型的文本塔在板外算好:对 80 个 COCO
类名套用 a photo of a <name>. 得到的单位向量。零样本分类就是每个类名做一次点积。
实测
| 模型 | 推理 RK3588S | 整个任务 RK3588S | 推理 RK3588 | 整个任务 RK3588 | 结果 |
|---|---|---|---|---|---|
| PE-Core-S16-384 | 169.59 ms | 170.9 ms | 166.79 ms | 168.1 ms | bus.jpg → bus,bird.jpg → bird,航天飞机 → airplane |
数据来自 RCDL 的 benchmark:
RCDL 0.3.0 的 conda 包,自研 NPU 运行时,NPU 驱动 0.9.8,单个 NPU 核,CPU 调频策略
performance、进程绑在 A76 大核上,预热至少一秒后取九次运行的中位数。RK3588S 的
BSP 内核是 6.1.118,RK3588 是 6.1.141。「推理」是运行时自己计时的一次模型运行(NPU 段
加上夹在中间的 CPU 算子),「整个任务」是一帧图像到一个嵌入向量。
与浮点模型在 23 张图上对比(20 张 COCO 图,加上公交车、鸟和航天飞机):嵌入向量的
余弦相似度平均 0.99991,最差 0.99981;每张图得分最高的 COCO 类名都与浮点模型相同。
bus.jpg 的第一名是 bus,+0.30,第二名 +0.23。在 RK3588 上单核 167 ms,三核 143 ms。
用法
需要 RCDL 0.3.1 或更新版本,安装、下载和调用见上面的代码。
rcdl.embed(emb, img, box=(x1, y1, x2, y2)) 可以只对图中的一块区域求嵌入。
部署前须知
- 三核提速有限,因为有一部分在 CPU 上跑。 旋转位置编码和它前后按头拆分的操作在 CPU 上运行,NPU 与 CPU 之间来回各转换 90 次。NPU 上的注意力已经能接住它们,只是 RCDL 的编译器还不会把旋转位置编码放到 NPU 上。所以单核 167 ms,三核也要 143 ms。
- 看领先幅度,不看余弦的绝对值。 各类名的余弦挨得很近:
bus.jpg上bus是 +0.30,第二名 +0.23。判断时看与第二名的差距,而不是卡一个固定的余弦值。 - 换一套词表不用重新编译。 换表不换模型:在任意机器上用同一个 checkpoint 的文本塔、 同样的提示词格式,对你的类名算出单位向量,按类名文件的行序存下来即可。一张表只能配 算出它的那个模型用。
- 比 SigLIP base/16 更小的替代。 RCDL 也提供 SigLIP base/16,它的嵌入是 768 维。 两者用的是同样顺序的 80 个 COCO 类名,但各自的文本表不能给对方的图像塔用。
- 测速请用
performance调频策略。 板子默认的schedutil会在 CPU 等 NPU 时降频; 在它下面,NPU 和 CPU 交替工作的测试项最多慢到上表的约四倍,而且每次都不一样,结果 本身不变。 .rnpu是 RCDL 自己的格式,自研 NPU 栈仍标为实验性,格式以后还可能变。这个 文件在 RK3588 / RK3588S 上通过厂商 BSP 内核的 rknpu 驱动运行(rknpu 0.9.8,已在 6.1.118 和 6.1.141 两个内核上验证);RK3576、RK356x 未验证,主线内核的rocket驱动不支持。
许可
Meta 以 Apache-2.0 发布 PE-Core 的代码和权重;文本表和类名文件由同一模型得出,条款
相同。RCDL 本身是 Apache-2.0,与这些条款无关:它是能加载任意 .rnpu 或 .rknn
的通用运行时,上面的许可只适用于这些权重和这些编译好的文件。构建的做法和输入约定见
docs/MODELS.md,RCDL
核实过的每个模型的许可情况见
model_zoo/。
Model tree for ruisv/rcdl-pe-core
Base model
facebook/PE-Core-S16-384
# Use any PE model as a vision encoder import core.vision_encoder.pe as pe model = pe.VisionTransformer.from_config("ruisv/rcdl-pe-core", pretrained=True)