Skip to content

fix(build): wait for torch to finish importing before wrapping from_numpy - #1175

Merged
capy-ai-staging[bot] merged 1 commit into
mainfrom
fix/numpy-compat-hook-race
Oct 4, 2026
Merged

capy-ai-staging[bot] merged 1 commit into
mainfrom
fix/numpy-compat-hook-race

Conversation

@jamiepine

Copy link
Copy Markdown
Owner

Landing VOIC-16's fix (commit 80ae4a4 from #1168) on its own because it blocks the 0.6 release, not just OmniVoice.

Problem. With torch 2.14.1 the frozen server dies at startup: pyi_rth_numpy_compat.py polls for torch.from_numpy and wraps it as soon as _C binds it, but torch/__init__.py has not yet run _torch_docs, which then calls add_docstr(torch.from_numpy, …) on our Python wrapper and raises TypeError: don't know how to add docstring to type 'function'.

Why 0.6 is affected. Before #1166 the hook silently no-op'd (the _t NameError was swallowed), so the race could not happen. #1166 fixed the shim, which armed the race. The 2026-10-04 release dry run installed torch 2.14.1 on the Windows CPU, macOS arm64 and macOS Intel jobs (CUDA job pinned 2.11, ROCm 2.2.2), so every CPU/MLX 0.6 binary built from release/0.6 as it stands would crash on launch.

Fix. Gate the poller on hasattr(torch, "compile"), which torch/__init__.py defines after _torch_docs has run. Six lines.

Verification. VOIC-16 built a Linux CPU onefile (PyInstaller 6.22.3, torch 2.14.1) with this change: boots, serves /health, /models/load, /generate (report: reports/VOIC-16.md in the Captain drive). I'll cherry-pick this onto release/0.6 once merged and re-run the release dry run.

Co-authored by VOIC-16.

Open in Capy

…umpy

With torch 2.14 the frozen server dies at startup with
"TypeError: don't know how to add docstring to type 'function'" from
torch/_torch_docs.py: torch.from_numpy is bound early in torch/__init__.py
and the numpy-compat runtime hook's poller wrapped it before
torch.nn.functional imported _torch_docs, which then tried to attach a
docstring to our Python wrapper. Gate the poller on torch.compile, which
torch/__init__.py defines after that import.

Co-authored-by: capy-ai-staging[bot] <305915985+capy-ai-staging[bot]@users.noreply.github.com>
(cherry picked from commit 80ae4a4)

@capy-ai-staging capy-ai-staging Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 3 other findings in Capy.

Open in Capy

@capy-ai-staging
capy-ai-staging Bot merged commit 82caf7d into main Oct 4, 2026
1 check passed
@capy-ai-staging
capy-ai-staging Bot deleted the fix/numpy-compat-hook-race branch October 4, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant