MohamedRashad commited on
Commit
1776f2c
·
1 Parent(s): 920cc4d

Initialize to CPU if no GPU

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -245,8 +245,14 @@ def load_infinity(
245
  state_dict = torch.load(model_path, map_location=device)
246
  print(infinity_test.load_state_dict(state_dict))
247
 
248
- # Initialize random number generator on the correct device
249
- infinity_test.rng = torch.Generator(device=device)
 
 
 
 
 
 
250
 
251
  return infinity_test
252
 
 
245
  state_dict = torch.load(model_path, map_location=device)
246
  print(infinity_test.load_state_dict(state_dict))
247
 
248
+ # Initialize random number generator, falling back to CPU if CUDA is not available
249
+ try:
250
+ infinity_test.rng = torch.Generator(device=device)
251
+ except RuntimeError:
252
+ print("CUDA device not available. Falling back to CPU...")
253
+ device = 'cpu'
254
+ infinity_test = infinity_test.to(device)
255
+ infinity_test.rng = torch.Generator(device=device)
256
 
257
  return infinity_test
258