harp-dev commited on
Commit
a8759fd
·
verified ·
1 Parent(s): 0ecae78

Load legacy checkpoints as torch did before 2.6, as other fleet Spaces already do.

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -1,4 +1,20 @@
1
  import spaces
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from pathlib import Path
3
  import yaml
4
  import time
 
1
  import spaces
2
+
3
+ try: # torch>=2.6 flipped torch.load(weights_only) to True; legacy ckpts need False
4
+ import torch as _torch
5
+
6
+ if getattr(_torch.load, "__harp_compat__", False) is False:
7
+ _torch_load_orig = _torch.load
8
+
9
+ def _torch_load_compat(*args, **kwargs):
10
+ kwargs.setdefault("weights_only", False)
11
+ return _torch_load_orig(*args, **kwargs)
12
+
13
+ _torch_load_compat.__harp_compat__ = True
14
+ _torch.load = _torch_load_compat
15
+ except Exception: # torch not installed / unexpected API -- nothing to patch
16
+ pass
17
+
18
  from pathlib import Path
19
  import yaml
20
  import time