owiedotch commited on
Commit
555a678
1 Parent(s): 9f23276

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -19,9 +19,8 @@ except Exception as e:
19
  print(f"Error detecting GPU. Using CPU. Error: {e}")
20
  torch_device = torch.device("cpu")
21
 
22
- # Load the SemantiCodec model
23
  semanticodec = SemantiCodec(token_rate=100, semantic_vocab_size=32768)
24
- semanticodec.to(torch_device)
25
 
26
  # Global variables for cancellation
27
  cancel_encode = False
@@ -105,18 +104,16 @@ def decode_audio(encoded_file_path):
105
  tokens_numpy = np.frombuffer(tokens_numpy_bytes, dtype=np.int64).reshape(shape)
106
 
107
  # Move the tensor to the same device as the model
108
- tokens = torch.from_numpy(tokens_numpy).to(device=semanticodec.device)
109
-
110
- print(f"Tokens shape: {tokens.shape}, dtype: {tokens.dtype}, device: {tokens.device}")
111
- print(f"Model device: {semanticodec.device}")
112
-
113
- # Ensure all model parameters are on the correct device
114
- semanticodec.to(semanticodec.device)
115
 
116
  # Decode the audio
117
  with torch.no_grad():
118
  waveform = semanticodec.decode(tokens)
119
 
 
 
120
  # Move waveform to CPU for saving
121
  waveform_cpu = waveform.cpu()
122
 
@@ -149,13 +146,9 @@ async def stream_decode_audio(encoded_file_path) -> Generator[tuple, None, None]
149
  tokens_numpy = np.frombuffer(tokens_numpy_bytes, dtype=np.int64).reshape(shape)
150
 
151
  # Move the tensor to the same device as the model
152
- tokens = torch.from_numpy(tokens_numpy).to(device=semanticodec.device)
153
-
154
- print(f"Streaming tokens shape: {tokens.shape}, dtype: {tokens.dtype}, device: {tokens.device}")
155
- print(f"Model device: {semanticodec.device}")
156
-
157
- # Ensure all model parameters are on the correct device
158
- semanticodec.to(semanticodec.device)
159
 
160
  # Decode the audio in chunks
161
  chunk_size = sample_rate * 2 # Adjust chunk size as needed
 
19
  print(f"Error detecting GPU. Using CPU. Error: {e}")
20
  torch_device = torch.device("cpu")
21
 
22
+ # Load the SemantiCodec model without specifying a device
23
  semanticodec = SemantiCodec(token_rate=100, semantic_vocab_size=32768)
 
24
 
25
  # Global variables for cancellation
26
  cancel_encode = False
 
104
  tokens_numpy = np.frombuffer(tokens_numpy_bytes, dtype=np.int64).reshape(shape)
105
 
106
  # Move the tensor to the same device as the model
107
+ tokens = torch.from_numpy(tokens_numpy)
108
+ print(f"Tokens device: {tokens.device}")
109
+ print(f"Model device: {next(semanticodec.parameters()).device}")
 
 
 
 
110
 
111
  # Decode the audio
112
  with torch.no_grad():
113
  waveform = semanticodec.decode(tokens)
114
 
115
+ print(f"Waveform device: {waveform.device}")
116
+
117
  # Move waveform to CPU for saving
118
  waveform_cpu = waveform.cpu()
119
 
 
146
  tokens_numpy = np.frombuffer(tokens_numpy_bytes, dtype=np.int64).reshape(shape)
147
 
148
  # Move the tensor to the same device as the model
149
+ tokens = torch.from_numpy(tokens_numpy)
150
+ print(f"Streaming tokens device: {tokens.device}")
151
+ print(f"Model device: {next(semanticodec.parameters()).device}")
 
 
 
 
152
 
153
  # Decode the audio in chunks
154
  chunk_size = sample_rate * 2 # Adjust chunk size as needed