Merge pull request #2224 from pipecat-ai/khk/mps
Add MPS backend auto-detection to local smart-turn v2
This commit is contained in:
@@ -62,8 +62,12 @@ class LocalSmartTurnAnalyzerV2(BaseSmartTurn):
|
|||||||
self._turn_model = _Wav2Vec2ForEndpointing.from_pretrained(smart_turn_model_path)
|
self._turn_model = _Wav2Vec2ForEndpointing.from_pretrained(smart_turn_model_path)
|
||||||
# Load the corresponding feature extractor for preprocessing audio
|
# Load the corresponding feature extractor for preprocessing audio
|
||||||
self._turn_processor = Wav2Vec2Processor.from_pretrained(smart_turn_model_path)
|
self._turn_processor = Wav2Vec2Processor.from_pretrained(smart_turn_model_path)
|
||||||
# Set device to GPU if available, else CPU
|
# Use platform-optimized backend if available (MPS for Apple silicon, CUDA for NVIDIA)
|
||||||
self._device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
self._device = "cpu"
|
||||||
|
if torch.backends.mps.is_available():
|
||||||
|
self._device = "mps"
|
||||||
|
elif torch.cuda.is_available():
|
||||||
|
self._device = "cuda"
|
||||||
# Move model to selected device and set it to evaluation mode
|
# Move model to selected device and set it to evaluation mode
|
||||||
self._turn_model = self._turn_model.to(self._device)
|
self._turn_model = self._turn_model.to(self._device)
|
||||||
self._turn_model.eval()
|
self._turn_model.eval()
|
||||||
|
|||||||
Reference in New Issue
Block a user