[Bugfix] Fix tokenizer config for higgs-audio-v3 test error (#4918)
Signed-off-by: herotai214 <herotai214@gmail.com>
This commit is contained in:
1 parent
9ceca4ec85
commit
d4a869fe5e
3 files changed
+52
-6
No files matched your search
Regular → Executable
+20
-4
@@ -22,6 +22,7 @@ generation.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import Any
|
||||
@@ -170,14 +171,25 @@ _AUDIO_TOKENIZER_PATH_ENVS = (
|
||||
)
|
||||
|
||||
|
||||
def _is_higgs_audio_tokenizer_config(config_path: str) -> bool:
|
||||
try:
|
||||
with open(config_path, encoding="utf-8") as f:
|
||||
config = json.load(f)
|
||||
except (OSError, json.JSONDecodeError):
|
||||
return False
|
||||
return config.get("model_type") == "higgs_audio_v2_tokenizer"
|
||||
|
||||
|
||||
def _normalize_audio_tokenizer_dir(path: str) -> str | None:
|
||||
if not path:
|
||||
return None
|
||||
expanded = os.path.abspath(os.path.expanduser(path))
|
||||
if os.path.isfile(os.path.join(expanded, "config.json")):
|
||||
config_path = os.path.join(expanded, "config.json")
|
||||
if os.path.isfile(config_path) and _is_higgs_audio_tokenizer_config(config_path):
|
||||
return expanded
|
||||
nested = os.path.join(expanded, _K2_OMNIVOICE_SUBDIR)
|
||||
if os.path.isfile(os.path.join(nested, "config.json")):
|
||||
nested_config_path = os.path.join(nested, "config.json")
|
||||
if os.path.isfile(nested_config_path) and _is_higgs_audio_tokenizer_config(nested_config_path):
|
||||
return nested
|
||||
return None
|
||||
|
||||
@@ -201,7 +213,9 @@ def _resolve_audio_tokenizer_dir() -> str | None:
|
||||
filename=f"{_K2_OMNIVOICE_SUBDIR}/config.json",
|
||||
)
|
||||
if isinstance(cached_config, str) and os.path.isfile(cached_config):
|
||||
return os.path.dirname(cached_config)
|
||||
candidate = _normalize_audio_tokenizer_dir(os.path.dirname(cached_config))
|
||||
if candidate is not None:
|
||||
return candidate
|
||||
|
||||
from huggingface_hub.constants import HF_HUB_CACHE
|
||||
|
||||
@@ -240,7 +254,9 @@ def _load_audio_tokenizer():
|
||||
_K2_OMNIVOICE_REPO,
|
||||
allow_patterns=[f"{_K2_OMNIVOICE_SUBDIR}/*"],
|
||||
)
|
||||
audio_tokenizer_dir = os.path.join(repo_path, _K2_OMNIVOICE_SUBDIR)
|
||||
audio_tokenizer_dir = _normalize_audio_tokenizer_dir(repo_path)
|
||||
if audio_tokenizer_dir is None:
|
||||
raise RuntimeError(f"Downloaded {_K2_OMNIVOICE_REPO} does not contain a valid Higgs audio tokenizer")
|
||||
device = current_omni_platform.get_torch_device()
|
||||
model = HiggsAudioV2TokenizerModel.from_pretrained(audio_tokenizer_dir).to(device)
|
||||
return model.eval()
|
||||
|
||||
Reference in new issue
Block a user