NexaAI / nexa-sdk

Nexa SDK is a comprehensive toolkit for supporting GGML and ONNX models. It supports text generation, image generation, vision-language models (VLM), Audio Language Model, auto-speech-recognition (ASR), and text-to-speech (TTS) capabilities.
https://docs.nexa.ai/
Apache License 2.0
4.43k stars 654 forks source link

[BUG] Circular Import Error when Importing NexaTTSInference or NexaVoiceInference #202

Closed WpythonW closed 3 weeks ago

WpythonW commented 4 weeks ago

Issue Description

When trying to import and use components (NexaTTSInference and NexaVoiceInference) following the official documentation examples, the code fails with a circular import error. The error suggests there's a circular dependency between nexa.general, nexa.constants, and nexa.gguf modules.

Expected behavior: The code from the documentation should work without any import errors for both TTS and Voice Recognition:

# TTS Example
from nexa.onnx import NexaTTSInference
model_path = "ljspeech"
inference = NexaTTSInference(
    model_path=model_path,
    local_path=None
)

# Voice Recognition Example
from nexa.onnx import NexaVoiceInference
model_path = "whisper-tiny"
inference = NexaVoiceInference(
    model_path=model_path,
    local_path=None
)

Actual behavior: Both imports fail with the same error:

ImportError: cannot import name 'pull_model' from partially initialized module 'nexa.general' (most likely due to a circular import) (/opt/conda/lib/python3.10/site-packages/nexa/general.py)

Full Error Traceback

ImportError                               Traceback (most recent call last)
Cell In[8], line 1
----> 1 from nexa.onnx import NexaVoiceInference
      3 model_path = "whisper-tiny"
      4 inference = NexaVoiceInference(
      5     model_path=model_path,
      6     local_path=None
      7 )

File /opt/conda/lib/python3.10/site-packages/nexa/onnx/__init__.py:1
----> 1 from .nexa_inference_image import NexaImageInference
      2 from .nexa_inference_text import NexaTextInference
      3 from .nexa_inference_tts import NexaTTSInference

[... rest of the traceback as provided in the error message ...]

ImportError: cannot import name 'pull_model' from partially initialized module 'nexa.general' (most likely due to a circular import) (/opt/conda/lib/python3.10/site-packages/nexa/general.py)

Additional Notes

Steps to Reproduce

  1. Install the required packages:

    CMAKE_ARGS="-DGGML_CUDA=ON -DSD_CUBLAS=ON" pip install nexaai --prefer-binary --index-url https://nexaai.github.io/nexa-sdk/whl/cu124 --extra-index-url https://pypi.org/simple --no-cache-dir
    pip install optimum
  2. Try either of these examples:

    
    # Example 1: TTS
    from nexa.onnx import NexaTTSInference
    model_path = "ljspeech"
    inference = NexaTTSInference(
    model_path=model_path,
    local_path=None
    )

Example 2: Voice Recognition

from nexa.onnx import NexaVoiceInference model_path = "whisper-tiny" inference = NexaVoiceInference( model_path=model_path, local_path=None )



3. The error occurs immediately on import for both components.

### OS

Kaggle Notebook Environment

### Python Version

3.10

### Nexa SDK Version

Latest from the provided index URL

### GPU (if using one)

NVIDIA (CUDA 12.4 compatible)
zhiyuan8 commented 3 weeks ago

Thank you for reaching out with your request! We are actively addressing issues and will fix this in next public release.

Davidqian123 commented 3 weeks ago

fix in https://github.com/NexaAI/nexa-sdk/pull/210