RVC-Boss/GPT-SoVITS · error · FileNotFoundError

Cannot locate {filename} in candidate dirs: {candidate_dirs}

Error message

Cannot locate {filename} in candidate dirs: {candidate_dirs}

What it means

FileNotFoundError from _load_json_from_candidates(): the g2pw (grapheme-to-pinyin with BERT) ONNX annotator looks for its metadata/config JSONs (e.g. polygraph / id maps) across a list of candidate directories and none of them contains the file. This is an incomplete-model-installation error: the G2PWModel directory exists only partially or the file names expected by this code version are absent.

Source

Thrown at GPT_SoVITS/text/g2pw/onnx_api.py:64

    preds = np.argmax(probs, axis=1).tolist()
    max_probs = []
    for index, arr in zip(preds, probs.tolist()):
        max_probs.append(arr[index])
    all_preds += [labels[pred] for pred in preds]
    all_confidences += max_probs

    return all_preds, all_confidences


def _load_json_from_candidates(filename: str, candidate_dirs: List[str]) -> Dict[str, Any]:
    for candidate_dir in candidate_dirs:
        if not candidate_dir:
            continue
        json_path = os.path.join(candidate_dir, filename)
        if os.path.exists(json_path):
            with open(json_path, "r", encoding="utf-8") as fr:
                return json.load(fr)
    raise FileNotFoundError(f"Cannot locate {filename} in candidate dirs: {candidate_dirs}")


def _find_first_existing_file(*paths: str) -> str:
    for path in paths:
        if path and os.path.exists(path):
            return path
    raise FileNotFoundError(f"Files not found: {paths}")


def download_and_decompress(model_dir: str = "G2PWModel/"):
    if not os.path.exists(model_dir):
        parent_directory = os.path.dirname(model_dir)
        zip_dir = os.path.join(parent_directory, "G2PWModel_1.1.zip")
        extract_dir = os.path.join(parent_directory, "G2PWModel_1.1")
        extract_dir_new = os.path.join(parent_directory, "G2PWModel")
        print("Downloading g2pw model...")
        modelscope_url = "https://www.modelscope.cn/models/kamiorinn/g2pw/resolve/master/G2PWModel_1.1.zip"
        with requests.get(modelscope_url, stream=True) as r:

View on GitHub (pinned to d523079fc0)

Solutions

  1. Re-download/re-extract the full G2PWModel bundle (download_and_decompress() or the manual zip) so all JSONs sit next to the .onnx.
  2. Compare the file list printed in the error against your G2PWModel directory and fetch the missing JSON specifically.
  3. If the model lives in a non-default location, add that directory to the candidate dirs passed into the loader (env/arg supported by the caller).
  4. Verify no empty-string candidate dirs silently skip your intended path.

Example fix

# before
converter = G2POnnxConverter(model_dir="G2PWModel/")  # FileNotFoundError: Cannot locate ... in candidate dirs

# after: ensure complete model dir, or extend candidates
# ls G2PWModel/  -> bert-base.onnx  polygraphunicode.txt  id2pinyin.json ... all present
converter = G2POnnxConverter(model_dir="G2PWModel/")
Defensive patterns

Strategy: validation

Validate before calling

import os
required = ["polygraphunicode.txt", "id2pinyin.json"]  # per error message
missing = [f for f in required if not any(os.path.exists(os.path.join(d, f)) for d in candidate_dirs)]
if missing:
    raise SystemExit(f"G2PWModel incomplete, missing {missing} — re-download bundle")

Try / catch

try:
    data = _load_json_from_candidates(filename, candidate_dirs)
except FileNotFoundError:
    download_and_decompress("GPT_SoVITS/text/g2pw/G2PWModel/")
    data = _load_json_from_candidates(filename, candidate_dirs + ["GPT_SoVITS/text/g2pw/G2PWModel"])

Prevention

When it happens

Trigger: Loading the g2pw ONNX model (G2POnnxConverter init → _load_json_from_candidates) when G2PWModel/ is missing, half-extracted, or from an older version lacking the JSON being requested; also when candidate dir strings are all empty/None.

Common situations: Zip extraction interrupted so only the .onnx landed; user downloaded an older G2PWModel_1.1 bundle while the code expects extra files; Docker image trimmed data files; project deployed with G2PWModel elsewhere and candidate dirs not including that location.

Related errors


AI-assisted analysis of RVC-Boss/GPT-SoVITS@d523079fc0 (2026-08-15). Data as JSON: /api/errors/731eabc21cd9ad9f. Report an issue: GitHub.