From b21d8c6c2ccc7680cc07eb241dec4df84128c43c Mon Sep 17 00:00:00 2001 From: Raf Gemmail Date: Thu, 4 May 2023 10:05:21 +1200 Subject: [PATCH] Force type as pytorch Tensor.type() has missing support for MPS. See https://github.com/pytorch/pytorch/issues/78929 --- bark/generation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bark/generation.py b/bark/generation.py index d1c7a6b..b7fbb9e 100644 --- a/bark/generation.py +++ b/bark/generation.py @@ -464,7 +464,10 @@ def generate_text_semantic( sorted_indices_to_remove[0] = False relevant_logits[sorted_indices[sorted_indices_to_remove]] = -np.inf relevant_logits = torch.from_numpy(relevant_logits) - relevant_logits = relevant_logits.to(logits_device).type(logits_dtype) + if GLOBAL_ENABLE_MPS: + relevant_logits = torch.tensor(relevant_logits, device="mps").to(torch.float) + else: + relevant_logits = relevant_logits.to(logits_device).type(logits_dtype) if top_k is not None: v, _ = torch.topk(relevant_logits, min(top_k, relevant_logits.size(-1))) relevant_logits[relevant_logits < v[-1]] = -float("Inf")