Repository navigation
fix: lazily import onnxruntime for the 25Hz tokenizer - #356
Open
Destination2020 wants to merge 1 commit into
Open
Destination2020 wants to merge 1 commit into
Destination2020 wants to merge 1 commit into
Conversation
ONNX Runtime is only needed by the CAMPPlus x-vector extractor, but the module-level import loads its native runtime for 12Hz users as well. Import it when XVectorExtractor is initialized and cover both the 12Hz import path and the 25Hz on-demand path.
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.
Summary
onnxruntimeimport from module scope intoXVectorExtractor.__init__.Problem
qwen_ttsimports both tokenizer implementations. Consequently, importing Qwen3-TTS for a released 12Hz model also importstokenizer_25hz/vq/speech_vq.pyand loads the ONNX Runtime native library, even though the 12Hz tokenizer never uses it.On an affected Ray/SGLang worker, the following initialization order reproduced the failure:
The last call raised:
Ray workers hit the same error in
ray._private.worker.connect()atfaulthandler.enable(all_threads=False), then failed to register with the raylet. This later surfaced as secondary Ray connection/worker errors.Observed environment:
This change is intentionally not gated on a Linux kernel version. Whether the native initialization conflict is observable depends on CPU features, Python and ONNX Runtime builds, and initialization order;
< 5.14is therefore not a reliable applicability boundary. Avoiding an unused native import benefits every 12Hz import path.The underlying alternate-signal-stack/AMX class of issue is discussed in python/cpython#91124 and python/cpython#31789. This PR does not claim to fix that platform-level issue; it prevents the 12Hz path from loading a native runtime it does not need.
Unlike #109, this keeps TokenizerV1/25Hz available. When
XVectorExtractoris actually initialized, it imports and uses ONNX Runtime exactly as before.Validation
The tests verify that:
Qwen3TTSTokenizerandQwen3TTSTokenizerV2Modeldoes not loadonnxruntime.XVectorExtractorloads ONNX Runtime on demand and creates the CPU inference session.Additional validation on the affected host:
import qwen_tts; faulthandler.enable()succeeds with ONNX Runtime still unloaded.