Skip to content

Open-Source Frontier Voice AI

Python

fix: use weights_only=True with safe_globals for voice preset loading (CWE-502)

pengzhiliang303b2833e01c
diff --git a/demo/realtime_model_inference_from_file.py b/demo/realtime_model_inference_from_file.py
index 1d56b07..2a2e711 100644
--- a/demo/realtime_model_inference_from_file.py
+++ b/demo/realtime_model_inference_from_file.py
@@ -10,6 +10,8 @@ import glob
from vibevoice.modular.modeling_vibevoice_streaming_inference import VibeVoiceStreamingForConditionalGenerationInference
from vibevoice.processor.vibevoice_streaming_processor import VibeVoiceStreamingProcessor
+from transformers.cache_utils import DynamicCache
+from transformers.modeling_outputs import BaseModelOutputWithPast
from transformers.utils import logging
logging.set_verbosity_info()
@@ -222,7 +224,8 @@ def main():
target_device = args.device if args.device != "cpu" else "cpu"
voice_sample = voice_mapper.get_voice_path(args.speaker_name)
print(f"Using voice preset for {args.speaker_name}: {voice_sample}")
- all_prefilled_outputs = torch.load(voice_sample, map_location=target_device, weights_only=False)
+ with torch.serialization.safe_globals([BaseModelOutputWithPast, DynamicCache]):
+ all_prefilled_outputs = torch.load(voice_sample, map_location=target_device, weights_only=True)
# Prepare inputs for the model
inputs = processor.process_input_with_cached_prompt(
diff --git a/demo/web/app.py b/demo/web/app.py
index 1b45117..4985c7d 100644
--- a/demo/web/app.py
+++ b/demo/web/app.py
@@ -11,6 +11,8 @@ from typing import Any, Callable, Dict, Iterator, Optional, Tuple, cast
import numpy as np
import torch
+from transformers.cache_utils import DynamicCache
+from transformers.modeling_outputs import BaseModelOutputWithPast
from fastapi import FastAPI, WebSocket
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
@@ -158,11 +160,12 @@ class StreamingTTSService:
preset_path = self.voice_presets[key]
print(f"[startup] Loading voice preset {key} from {preset_path}")
print(f"[startup] Loading prefilled prompt from {preset_path}")
- prefilled_outputs = torch.load(
- preset_path,
- map_location=self._torch_device,
- weights_only=False,
- )
+ with torch.serialization.safe_globals([BaseModelOutputWithPast, DynamicCache]):
+ prefilled_outputs = torch.load(
+ preset_path,
+ map_location=self._torch_device,
+ weights_only=True,
+ )
self._voice_cache[key] = prefilled_outputs
return self._voice_cache[key]