Skip to content

Florence2 nodes fail with 'attempted relative import with no known parent package' after TTS-Audio-Suite RVC runs (models name collision) #208

Description

@zz13526585541-hash

Environment

  • ComfyUI 0.29.2, Python 3.12.10, torch 2.9.1+cu128, Windows
  • ComfyUI-RMBG 3.1.0 + TTS-Audio-Suite (latest)

Steps to reproduce

  1. Start ComfyUI, run any TTS-Audio-Suite voice-changer (RVC) workflow once. This inserts TTS-Audio-Suite\engines\rvc\impl\lib\infer_pack into sys.path[0] at runtime (see minimal_reference_wrapper.py).
  2. Run a workflow using any Florence2 node (e.g. CogFlorence-2.2-Large). Model files download/load fine.

Expected: Florence2 inference runs.

Actual: Node fails with:

File "py\AILab_Florence2.py", line 168, in _get_model
    from models.modeling_florence2 import Florence2ForConditionalGeneration
  File "TTS-Audio-Suite\engines\rvc\impl\lib\infer_pack\models.py", line 5, in <module>
    from . import modules
ImportError: attempted relative import with no known parent package

Root cause
AILab_Florence2.py uses a bare top-level import from models.modeling_florence2 import .... Python's PathFinder resolves models by walking sys.path in order; after TTS-Audio-Suite's RVC engine inserts its infer_pack directory at sys.path[0], the plain file infer_pack\models.py shadows this repo's models/ package. That file is then imported as a top-level models module, and its internal from . import modules fails (no parent package). The error is intermittent: it only appears after an RVC workflow has run in the same process.

Suggested fix
Resolve the import without relying on a bare models name, e.g. insert this repo's own models dir at sys.path[0] before importing:

sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "models")))
from modeling_florence2 import Florence2ForConditionalGeneration

(This is what I applied locally and it works; modeling_florence2.py has no relative imports so it loads fine as a top-level module.)

Additionally, TTS-Audio-Suite should be asked to stop globally polluting the process namespace: pushing a directory containing a generic models.py onto sys.path[0] at runtime is a landmine for any other custom node doing bare-name imports.

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