mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-10-03 00:55:14 -07:00
fix gated Llama tokenizer error by redirecting to ungated mirror
TADA hardcodes 'meta-llama/Llama-3.2-1B' as its tokenizer source in both the Aligner and TadaForCausalLM.from_pretrained(). That repo is gated and requires accepting Meta's license on HuggingFace. Monkey-patch AutoTokenizer.from_pretrained during model loading to redirect Llama tokenizer requests to 'unsloth/Llama-3.2-1B', an ungated mirror with identical tokenizer files. The patch is scoped to model loading only and restored immediately after.
This commit is contained in:
@@ -130,27 +130,59 @@ 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" which is gated;
|
||||||
|
# we redirect to unsloth's ungated copy at load time.
|
||||||
|
logger.info("Downloading Llama tokenizer (ungated mirror)...")
|
||||||
|
snapshot_download(
|
||||||
|
repo_id="unsloth/Llama-3.2-1B",
|
||||||
|
token=None,
|
||||||
|
allow_patterns=["tokenizer*", "special_tokens*"],
|
||||||
|
)
|
||||||
|
|
||||||
# Determine dtype — use bf16 on CUDA for ~50% memory savings
|
# Determine dtype — use bf16 on CUDA for ~50% memory savings
|
||||||
if device == "cuda" and torch.cuda.is_bf16_supported():
|
if device == "cuda" and torch.cuda.is_bf16_supported():
|
||||||
model_dtype = torch.bfloat16
|
model_dtype = torch.bfloat16
|
||||||
else:
|
else:
|
||||||
model_dtype = torch.float32
|
model_dtype = torch.float32
|
||||||
|
|
||||||
# Load encoder (only needed for voice prompt encoding)
|
# TADA hardcodes "meta-llama/Llama-3.2-1B" as the tokenizer
|
||||||
from tada.modules.encoder import Encoder
|
# source in its Aligner and TadaForCausalLM.from_pretrained().
|
||||||
logger.info("Loading TADA encoder...")
|
# That repo is gated (requires Meta license acceptance on HF).
|
||||||
self.encoder = Encoder.from_pretrained(
|
# Monkey-patch AutoTokenizer.from_pretrained to redirect to an
|
||||||
TADA_CODEC_REPO, subfolder="encoder"
|
# ungated mirror that ships the identical tokenizer files.
|
||||||
).to(device)
|
from transformers import AutoTokenizer
|
||||||
self.encoder.eval()
|
_orig_from_pretrained = AutoTokenizer.from_pretrained.__func__
|
||||||
|
|
||||||
# Load the causal LM (includes decoder for wav generation)
|
@classmethod # type: ignore[misc]
|
||||||
from tada.modules.tada import TadaForCausalLM
|
def _patched_from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
|
||||||
logger.info(f"Loading TADA {model_size} model...")
|
if "meta-llama/Llama-3.2" in str(pretrained_model_name_or_path):
|
||||||
self.model = TadaForCausalLM.from_pretrained(
|
pretrained_model_name_or_path = "unsloth/Llama-3.2-1B"
|
||||||
repo, torch_dtype=model_dtype
|
kwargs.setdefault("token", None)
|
||||||
).to(device)
|
logger.info("Redirecting Llama tokenizer to ungated mirror: unsloth/Llama-3.2-1B")
|
||||||
self.model.eval()
|
return _orig_from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs)
|
||||||
|
|
||||||
|
AutoTokenizer.from_pretrained = _patched_from_pretrained
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Load encoder (only needed for voice prompt encoding)
|
||||||
|
from tada.modules.encoder import Encoder
|
||||||
|
logger.info("Loading TADA encoder...")
|
||||||
|
self.encoder = Encoder.from_pretrained(
|
||||||
|
TADA_CODEC_REPO, subfolder="encoder"
|
||||||
|
).to(device)
|
||||||
|
self.encoder.eval()
|
||||||
|
|
||||||
|
# Load the causal LM (includes decoder for wav generation)
|
||||||
|
from tada.modules.tada import TadaForCausalLM
|
||||||
|
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