Skip to content

【打包改进】macOS 桌面版建议内置 mlx-whisper 运行时(当前 UI 提示的 pip install 对冻结环境不可行) #466

Open

Description

@TomRush-qn

现状

桌面版(PyInstaller 打包)的转写器下拉提供 MLX Whisper(仅macOS) 选项,但 requirements.txt 不含 mlx-whisper,打包产物中没有 mlx 运行时。设置页/侧边栏的提示是:

MLX Whisper 当前不可用。需要 macOS 平台并安装 pip install mlx_whisper,安装后重启后端生效。

这条提示只对源码部署有效:冻结的 PyInstaller 环境不读取外部 site-packages(也无 PYTHONPATH 通道),桌面用户装了也不会生效。transcriber_provider.py 启动时 from app.transcriber.mlx_whisper_transcriber import MLXWhisperTranscriber 失败后即标记不可用,后端无任何运行时安装机制(已核对 app/routers/config.py 无 pip/subprocess 安装逻辑)。

影响

Apple Silicon(M 系)用户恰恰是 MLX 收益最大的人群——GPU/统一内存转写比 faster-whisper 的 CPU 路径快数倍——目前却只能:① 用 CPU 的 faster-whisper;② 做不可移植的手工注入(把 uv 建的同版本 venv 包合并进 Contents/Frameworks/,即 sys._MEIPASS)。

建议(任选其一或组合)

  1. requirements.txt 加环境标记,macOS 构建自然带上:
    mlx-whisper; sys_platform == "darwin" and platform_machine == "arm64"
    
    代价:dmg 体积增加(mlx-whisper 依赖链含 torch,约 +200MB)。
  2. 或拆分 requirements-mlx.txt,由打包 workflow 按 platform 装入,PyInstaller 侧确认 hiddenimports 覆盖 mlx_whisper/mlx(onnxruntime/ctranslate2 已有打包先例可参照)。

附加经验(供打包时参考)

  • 本地验证过可行路径:uv 建与 bundle 同版本(CPython 3.11)的 venv 装 mlx-whisper 0.4.3(mlx 0.32.4),把缺失包以"只增不覆盖"方式合并进 Contents/Frameworks/ 后,/api/transcriber_config 返回 mlx_whisper_available: true,全档位模型可用。
  • 若打包 torch,注意冻结环境下 torch.distributed.rpc 可能 pybind 重复注册(实测报 generic_type: cannot initialize type "RpcBackendOptions": an object with that name is already defined),可在打包配置排除 torch.distributed.rpc 或运行时垫片 is_available()->False(mlx_whisper 不使用 rpc)。
  • mlx-whisper 依赖链会引入 scipy 等科学计算包,其中 scipy.signal 需要 cmath 等 C 扩展型标准库模块,PyInstaller 分析时如未覆盖需显式加入 hiddenimports。

如果维护者认可方向,我可以在自己的环境配合验证 macOS 打包产物。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions