mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-15 04:40:40 -07:00
fix tokenizer patch corrupting AutoTokenizer for other engines
Replace the monkey-patch on AutoTokenizer.from_pretrained (which broke the classmethod descriptor and caused 'Tokenizer not loaded' errors when loading Qwen after TADA) with two targeted config patches: - Set AlignerConfig.tokenizer_name to the local ungated tokenizer path - Pre-load TadaConfig, inject tokenizer_name, pass config= to from_pretrained No global state is modified; other engines are unaffected.
This commit is contained in:
@@ -130,11 +130,13 @@ class HumeTadaBackend:
|
|||||||
allow_patterns=["*.safetensors", "*.json", "*.txt", "*.bin", "*.model"],
|
allow_patterns=["*.safetensors", "*.json", "*.txt", "*.bin", "*.model"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Pre-download the Llama tokenizer from an ungated mirror.
|
# TADA hardcodes "meta-llama/Llama-3.2-1B" as the tokenizer
|
||||||
# TADA hardcodes "meta-llama/Llama-3.2-1B" which is gated;
|
# source in its Aligner and TadaForCausalLM.from_pretrained().
|
||||||
# we redirect to unsloth's ungated copy at load time.
|
# That repo is gated (requires Meta license acceptance).
|
||||||
|
# Download the tokenizer from an ungated mirror and get its
|
||||||
|
# local cache path so we can point TADA at it directly.
|
||||||
logger.info("Downloading Llama tokenizer (ungated mirror)...")
|
logger.info("Downloading Llama tokenizer (ungated mirror)...")
|
||||||
snapshot_download(
|
tokenizer_path = snapshot_download(
|
||||||
repo_id="unsloth/Llama-3.2-1B",
|
repo_id="unsloth/Llama-3.2-1B",
|
||||||
token=None,
|
token=None,
|
||||||
allow_patterns=["tokenizer*", "special_tokens*"],
|
allow_patterns=["tokenizer*", "special_tokens*"],
|
||||||
@@ -146,43 +148,34 @@ class HumeTadaBackend:
|
|||||||
else:
|
else:
|
||||||
model_dtype = torch.float32
|
model_dtype = torch.float32
|
||||||
|
|
||||||
# TADA hardcodes "meta-llama/Llama-3.2-1B" as the tokenizer
|
# Patch the Aligner config class to use the local tokenizer
|
||||||
# source in its Aligner and TadaForCausalLM.from_pretrained().
|
# path instead of the gated "meta-llama/Llama-3.2-1B" default.
|
||||||
# That repo is gated (requires Meta license acceptance on HF).
|
# This avoids monkey-patching AutoTokenizer.from_pretrained
|
||||||
# Monkey-patch AutoTokenizer.from_pretrained to redirect to an
|
# which corrupts the classmethod descriptor for other engines.
|
||||||
# ungated mirror that ships the identical tokenizer files.
|
from tada.modules.aligner import AlignerConfig
|
||||||
from transformers import AutoTokenizer
|
AlignerConfig.tokenizer_name = tokenizer_path
|
||||||
_orig_from_pretrained = AutoTokenizer.from_pretrained.__func__
|
|
||||||
|
|
||||||
@classmethod # type: ignore[misc]
|
# Load encoder (only needed for voice prompt encoding)
|
||||||
def _patched_from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
|
from tada.modules.encoder import Encoder
|
||||||
if "meta-llama/Llama-3.2" in str(pretrained_model_name_or_path):
|
logger.info("Loading TADA encoder...")
|
||||||
pretrained_model_name_or_path = "unsloth/Llama-3.2-1B"
|
self.encoder = Encoder.from_pretrained(
|
||||||
kwargs.setdefault("token", None)
|
TADA_CODEC_REPO, subfolder="encoder"
|
||||||
logger.info("Redirecting Llama tokenizer to ungated mirror: unsloth/Llama-3.2-1B")
|
).to(device)
|
||||||
return _orig_from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs)
|
self.encoder.eval()
|
||||||
|
|
||||||
AutoTokenizer.from_pretrained = _patched_from_pretrained
|
# Load the causal LM (includes decoder for wav generation).
|
||||||
|
# TadaForCausalLM.from_pretrained() calls
|
||||||
try:
|
# getattr(config, "tokenizer_name", "meta-llama/Llama-3.2-1B")
|
||||||
# Load encoder (only needed for voice prompt encoding)
|
# which hits the gated repo. Pre-load the config from HF,
|
||||||
from tada.modules.encoder import Encoder
|
# inject the local tokenizer path, then pass it in.
|
||||||
logger.info("Loading TADA encoder...")
|
from tada.modules.tada import TadaForCausalLM, TadaConfig
|
||||||
self.encoder = Encoder.from_pretrained(
|
logger.info(f"Loading TADA {model_size} model...")
|
||||||
TADA_CODEC_REPO, subfolder="encoder"
|
config = TadaConfig.from_pretrained(repo)
|
||||||
).to(device)
|
config.tokenizer_name = tokenizer_path
|
||||||
self.encoder.eval()
|
self.model = TadaForCausalLM.from_pretrained(
|
||||||
|
repo, config=config, torch_dtype=model_dtype
|
||||||
# Load the causal LM (includes decoder for wav generation)
|
).to(device)
|
||||||
from tada.modules.tada import TadaForCausalLM
|
self.model.eval()
|
||||||
logger.info(f"Loading TADA {model_size} model...")
|
|
||||||
self.model = TadaForCausalLM.from_pretrained(
|
|
||||||
repo, torch_dtype=model_dtype
|
|
||||||
).to(device)
|
|
||||||
self.model.eval()
|
|
||||||
finally:
|
|
||||||
# Restore original to avoid affecting other code
|
|
||||||
AutoTokenizer.from_pretrained = _orig_from_pretrained
|
|
||||||
|
|
||||||
logger.info(f"HumeAI TADA {model_size} loaded successfully on {device}")
|
logger.info(f"HumeAI TADA {model_size} loaded successfully on {device}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user