Skip to content

feat: 重新支持 Intel Mac,纯 Rust VM 替代 ort/ONNX Runtime——PureVox6/AEC7 权重编译期内嵌 - #366

Merged
OrientCOMPASS merged 4 commits into
MicYou-Dev:masterfrom
OrientCOMPASS:feat/pure-rust-inference
Oct 9, 2026
Merged

OrientCOMPASS merged 4 commits into
MicYou-Dev:masterfrom
OrientCOMPASS:feat/pure-rust-inference

Conversation

@OrientCOMPASS

Copy link
Copy Markdown
Contributor

摘要

移除后端的 ort / ONNX Runtime 依赖:PureVox6 降噪与 AEC7 消回声改为零依赖纯 Rust 推理 VM(新 crate micyou-infer)执行编译期内嵌的静态编译权重(MCYI blob,include_bytes!),并借此解锁 Intel Mac 完整 AI 音频功能(CI 新增 x86_64 macOS 安装包)。

该移植已在实验性后端 libmicyou 完成完整的开发—对拍—性能验证闭环(七层验证矩阵 + 与 ort 的同机基准对比),本 PR 只包含运行时整合与权重产物;模型生产工具链与 golden 测试设施留在实验仓库(见「两仓库分工」)。

BREAKING CHANGE:micyou_audio::init_ort_runtime 移除;后端不再加载 libonnxruntime、不再发现 .onnx 文件。模型编译进二进制、永远可用,「模型缺失」降级路径随之消失。

动机与依据

  1. 分发与鲁棒性:现状需在仓库内提交 78MB 的三平台 onnxruntime 动态库 + 7MB .onnx 模型并随包分发,运行时要走「探测 dylib → 动态加载 → 发现模型文件 → 建 Session」链路,任何一环缺失都会让 AI 降噪/AEC 静默降级。内嵌编译期权重后,这一整类故障不存在。
  2. Intel Mac 被 ort 卡死(实证):仓库捆绑的 libonnxruntime.dylib 是 arm64-only thin binary(Mach-O cputype 0x100000c,非 universal)——这是桌面端此前只发布 macOS arm64 安装包、Intel Mac 无法使用 AI 降噪/AEC 的直接原因。纯 Rust VM 无此约束:x86_64 路径带 AVX2+FMA 运行时派发(is_x86_feature_detected!,不满足时回落 baseline 标量路径),零 C 依赖可在 arm64 runner 直接交叉编译。本 PR 同步为 development/release/pre-release 三条流水线增加 x86_64-apple-darwin 构建,MirrorChyan 上传清单增加 macos/x64 条目。
  3. 可行性早已验证:两模型全部算子(28/30 种,Conv/ConvT/GRU/LN/BN/Resize/…)静态 shape、batch=1,可全静态编译;每帧计算量 2.75/8.4 MMAC,10ms 帧预算内余量充足。方法论对齐 silero_v4 纯 Rust 移植(numpy 参照实现 → 位精确对拍 → 权重平面化 → Rust 机械转写 → golden 测试)。

变更清单

新增

  • tauri-app/crates/micyou-infer/:零运行时依赖推理 VM(std only)。~26 个定形算子内核,预打包 f32 arena,每帧零分配、零图解析;AVX2+FMA 运行时派发 + 通用回落;唯一 unsafe 不变量(同 op 输出/输入 arena 区间不重叠)由编译器活跃区间打包保证、debug 构建逐 op 复验
  • tauri-app/crates/micyou-audio/src/assets/{purevox6,aec7}.mcy:静态编译权重(2.09MB + 4.78MB;purevox6 1105 ONNX 节点→440 指令,aec7 1581→616)
  • docs/pure-rust-inference.md:设计文档(可行性评估、MCYI 格式、验证矩阵、性能实测、边界与模型更新流程)

改造

  • micyou-audio/dsp.rs:PureVoxProcessor/AecProcessor 由 ort Session 改驱动 micyou_infer::Session;STFT/iSTFT/OLA 布线与 cache 反馈顺序不变;新增 3 个零夹具行为测试(PureVox 衰减稳态噪声、AEC7 压制对齐噪声回声、全链 smoke),cargo test -p micyou-audio --features noise-suppression 即可运行
  • micyou-core:服务启动不再探测/加载 ORT 动态库(service.rs);resources.rs 资源目录 marker 改为 ALSA/PipeWire 配置(向后兼容:含 .onnx 的旧安装树仍可解析,覆盖升级无感)
  • workspace:ort、ndarray 依赖移除;noise-suppression feature 改拉 micyou-infer;Cargo.lock 同步(−231 行)
  • 打包:删除 src-tauri/libs/(78MB onnxruntime ×3)与 src-tauri/resources/*.onnx(7MB,LICENSE-PureVox/LICENSE-AEC7 署名文件保留随包);prepare-sidecars.js/installer.iss 的 ort 拷贝步骤移除
  • 设置页降噪选项标签 PureVox (ONNX) → PureVox (AI)
  • CI:三条构建流水线 macOS matrix 增加 x86_64 条目;about.toml targets 补 x86_64-apple-darwin;AGENTS.md crate 表与 CI 描述更新

正确性验证

完整七层验证矩阵在 libmicyou 的 CI 执行并通过(工具链所在仓库);本 PR 的运行时逻辑与验证版本逐行一致、权重 blob 逐字节一致(fork 上保留的对拍存档分支 feat/pure-rust-inference-full 与本分支的全部源码差异仅为文档注释指向与移除的 golden 测试文件;存档分支携带完整工具链与 golden,合并后可删):

层 对拍双方 结果
① 算子语义 numpy 解释器 ↔ onnxruntime(32 流式帧全输出 + 全 1105/1581 中间张量逐层) max_abs ≤ ~2e-5(f32 求和序噪声级)
② 编译忠实性 MCYI blob(numpy 重放)↔ 解释器 位精确(绝大多数 0.0)
③ blob 新鲜度 重编译 ↔ 已提交产物 字节级一致(格式确定性)
④ Rust 内核 VM ↔ numpy golden(182 个单算子用例,含负步长 Slice、双向 GRU、im2col Conv、output_padding ConvT、shrink Resize 等边界) abs ≤ 2e-4
⑤ Rust 端到端 VM 流式自反馈 16 帧 ↔ 解释器轨迹 worst rel 4.8e-6 (pv) / 1.2e-5 (aec);确定性重跑位一致
⑥ DSP 布线 处理器时域输出 ↔ numpy 时域复刻 STFT/cache/OLA 接线 golden 通过
⑦ 性能 见下节 与 ort 打平

存档分支 CI:Native Inference run 37889534944(①–⑥ 全部门禁 + ubuntu/windows/macos 三 OS VM 测试矩阵,全绿)。

本 PR 分支 CI:Development Build run 37895348875(Windows 安装器 / Linux deb+rpm+AppImage / macOS arm64 / macOS x86_64 / Android 五任务全绿,artifact 可下载)。本地另有 cargo test -p micyou-audio --features noise-suppression 27/27、cargo check --locked -p micyou-core -p micyou-cli -p micyou-tui 零告警。

流式反馈稳定性:f32 求和序与 ORT 存在 ~1e-6 级差异(与 silero 移植同量级),16 帧自反馈漂移实测 ≤1.4e-5,系统收缩性良好、不发散,听感无影响。

性能(与 ort 版同机对比)

libmicyou 移植 CI 在同一 GitHub runner(ubuntu-22.04,单线程)对 ort 2.0.0-rc.13 + onnxruntime 1.19.2(intra/inter_threads=1,官方 Microsoft 构建)与纯 Rust VM 运行同一 harness(相同确定性信号、300 warmup + 3000 计量帧、480 样本/帧 = 10ms 实时预算):

配置 ort mean native mean native/ort native p95 native RTF
purevox6 1002 µs 985 µs 0.98× 1000 µs 0.098
aec7 2380 µs 3062 µs 1.29× 3155 µs 0.306
aec7 + purevox6(生产组合) 3712 µs 3844 µs 1.04× 3943 µs 0.384

组合链与 ort 基本打平,RTF 0.384 → 实时余量 ~2.6×。x86_64 上 AVX2+FMA 运行时派发对标 MLAS 的做法;非 x86(含 Apple Silicon)走自动向量化通用路径(macOS arm64 CI 构建与测试通过)。

体积影响

项 变化
仓库 −85MB(删 78MB onnxruntime 库 + 7MB .onnx;增 6.9MB 权重 blob)
Windows 安装器 +5MB(33 vs 28;不再含 15.8MB dll 与模型,三个二进制各嵌权重、固体压缩部分去重)
Linux deb/rpm / AppImage +3MB
macOS dmg +2MB(不再含 39MB dylib 与模型)
安装后磁盘足迹 基本持平
新增平台 macOS x86_64 dmg(43MB,此前不存在)

兼容性与升级

  • AecFailure 事件协议、settings.json 字段、降噪类型 id(PureVox/RNNoise/Speexdsp)全部不变;ModelMissing 枚举保留(不再可达)
  • 覆盖升级:旧安装树残留的 .onnx/onnxruntime 文件不影响新版(资源目录 marker 向后兼容),装完即用
  • RNNoise / Speexdsp 备选降噪、插件链、Web 模式(DSP bypass)不受影响

两仓库分工与模型更新流程

本仓库只含运行时产物(VM + .mcy 权重);模型生产与验证设施(numpy 参照解释器、ONNX→MCYI 编译器、对拍/golden 生成器、ONNX 源模型、验证 CI、bench harness)在 libmicyou。更换/升级模型时:在 libmicyou 重跑 compile_models.py 与 golden 生成、通过其 CI 全链验证后,把新 .mcy 提交回本仓库即可(流程已写入 docs/pure-rust-inference.md §7;不支持的算子会在编译期显式报错而非静默降级)。

参考

…el blobs

Mechanical Rust transcription of the numpy reference kernels from the
libmicyou experimental backend: broadcasting elementwise ops, batched
MatMul, NCHW Conv (pointwise-GEMM / depthwise / im2col paths), scatter
ConvTranspose, GRU (fwd/bwd/bidi, linear_before_reset), BatchNorm,
LayerNorm, Resize (linear+half_pixel), structural ops (transpose/concat/
slice/pad/expand/gather/reduce/copy) over a pre-packed f32 arena — no
allocations per frame, no graph parsing at runtime, no C dependencies.

Performance (measured in the libmicyou port CI, ubuntu-22.04 single
thread, vs ort 2.0.0-rc.13 + onnxruntime 1.19.2 with intra/inter=1):
AVX2+FMA runtime dispatch, branchless exp/tanh, GRU weight pre-transpose
and L1 reuse bring the combined aec7+purevox6 chain to 1.04x of ort
(RTF 0.384, ~2.6x real-time headroom); purevox6 alone beats MLAS (0.98x).

Soundness invariant (per-op output/input arena regions disjoint) is
enforced by the compiler's live-range packing and re-validated in debug
builds.

The model-generation toolchain, ONNX sources, golden fixtures and the
full verification matrix (numpy<->onnxruntime parity, blob freshness,
per-op / streaming / time-domain goldens, native-vs-ort bench) live in
the libmicyou repository; docs/pure-rust-inference.md records the design
and the results. This repository ships the runtime artifacts only.
@micyou-automation micyou-automation Bot added reviewing 正在复核 size/xxl 1000+ 行 labels Oct 9, 2026
BREAKING CHANGE: micyou_audio::init_ort_runtime is removed; AI noise
suppression and AEC no longer load libonnxruntime or discover .onnx
files. The compiled MCYI models are embedded in the binary
(include_bytes!) and always available — the model-missing degradation
path is gone.

- dsp.rs: PureVoxProcessor/AecProcessor now drive micyou_infer::Session
  over the embedded blobs; STFT/iSTFT/OLA framing and cache feedback
  order are unchanged; fixture-free property tests pin the integration
  (PureVox attenuates stationary noise, AEC7 crushes aligned noise echo,
  full-chain smoke) — golden/parity verification of the blobs themselves
  lives in the libmicyou repository
- micyou-core: server startup no longer probes/loads the ORT shared
  library; resources.rs markers reduce to the ALSA/PipeWire config
  (legacy trees with .onnx files still resolve)
- protocol surface: AecFailure::ModelMissing is removed — the backend
  can no longer report a missing model — together with its frontend
  notification mapping and the aecDisabledModelMissing key in all seven
  locales; the failure-code stability test keeps pinning the rest
- bundling: the committed onnxruntime shared libraries (src-tauri/libs/,
  78 MB) and the .onnx models (src-tauri/resources/, 7 MB) are removed
  along with the prepare-sidecars/installer.iss steps that copied them;
  the LICENSE-PureVox/LICENSE-AEC7 attribution files stay bundled;
  settings UI renames the PureVox entry from "(ONNX)" to "(AI)"
- workspace: ort and ndarray dependencies removed; micyou-audio's
  noise-suppression feature now pulls micyou-infer

Size: each desktop binary (GUI/CLI/TUI) grows ~6.9 MB (embedded
weights; installers net +3–5 MB after compression) while the payload
drops the per-platform onnxruntime library and the models; installed
footprint is roughly unchanged and the entire ONNX Runtime
distribution/discovery failure class is gone.
…cord

docs/pure-rust-inference.md records why the two models compile to a
static instruction stream (op census, per-frame MAC budget, folded node
counts), the MCYI blob format, the seven-layer verification matrix run
in the libmicyou CI, the measured native-vs-ort performance (1.04x
combined, RTF 0.384), the two-repo split (generation toolchain there,
runtime artifacts here) and the known VM boundaries. AGENTS.md gains the
micyou-infer crate row and the embedded-model wording.
The previously bundled libonnxruntime.dylib was an arm64-only thin
binary — the reason the desktop only shipped macOS arm64 installers and
Intel Macs had no working AI noise suppression/AEC. The pure-Rust VM
removes that constraint: the x86_64 path has AVX2+FMA runtime dispatch
with a baseline scalar fallback, and the zero-C-dependency tree
cross-compiles from the arm64 runners (verified locally: cargo check
-p micyou-infer --target x86_64-apple-darwin).

- development/release/pre-release: macOS matrix gains the x86_64 entry
  (artifacts named MicYou-macOS-<ver>-x86_64.dmg; the release publish
  job picks them up automatically via download-all-artifacts)
- mirrorchyan_release.yml: macos/x64 upload entry for the new dmg
- about.toml: resolve licenses for x86_64-apple-darwin as well
- docs: Intel Mac rationale in docs/pure-rust-inference.md; AGENTS.md
  CI description
@OrientCOMPASS
OrientCOMPASS force-pushed the feat/pure-rust-inference branch from acdcd2b to 38a9280 Compare October 9, 2026 09:10
@OrientCOMPASS

Copy link
Copy Markdown
Contributor Author

ModelMissing 枚举已删除。

@OrientCOMPASS
OrientCOMPASS merged commit 27da3a1 into MicYou-Dev:master Oct 9, 2026
9 of 10 checks passed
@micyou-automation micyou-automation Bot added done 完成 and removed reviewing 正在复核 labels Oct 9, 2026
@OrientCOMPASS
OrientCOMPASS deleted the feat/pure-rust-inference branch October 10, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

done 完成 size/xxl 1000+ 行

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant