Repository navigation
fix(build): wait for torch to finish importing before wrapping from_numpy - #1175
Merged
Merged
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pypolls fortorch.from_numpyand wraps it as soon as_Cbinds it, buttorch/__init__.pyhas not yet run_torch_docs, which then callsadd_docstr(torch.from_numpy, …)on our Python wrapper and raisesTypeError: don't know how to add docstring to type 'function'.Why 0.6 is affected. Before #1166 the hook silently no-op'd (the
_tNameError 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 fromrelease/0.6as it stands would crash on launch.Fix. Gate the poller on
hasattr(torch, "compile"), whichtorch/__init__.pydefines after_torch_docshas 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 ontorelease/0.6once merged and re-run the release dry run.Co-authored by VOIC-16.