siddiVinayaka commited on
Commit
aa72d8d
·
verified ·
1 Parent(s): 5b489b7

Auto-recover Git LFS pointer files in inference.py

Browse files
Files changed (1) hide show
  1. inference.py +31 -3
inference.py CHANGED
@@ -74,9 +74,37 @@ def load_cortex_model(
74
 
75
  ckpt_file = Path(checkpoint_path)
76
  if not ckpt_file.is_file():
77
- raise FileNotFoundError(f"Checkpoint not found at: {ckpt_file.resolve()}")
78
-
79
- print(f"[*] Loading weights from {ckpt_file.name}...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  ckpt = torch.load(ckpt_file, map_location="cpu", weights_only=False)
81
  cfg = ckpt.get("base_cfg", ckpt.get("cfg", {}))
82
 
 
74
 
75
  ckpt_file = Path(checkpoint_path)
76
  if not ckpt_file.is_file():
77
+ try:
78
+ from huggingface_hub import hf_hub_download
79
+ print(f"[*] Checkpoint not found locally. Downloading {checkpoint_path} from Hugging Face...")
80
+ ckpt_file = Path(hf_hub_download(repo_id="siddiVinayaka/Cortex-System-One", filename=checkpoint_path))
81
+ except Exception:
82
+ raise FileNotFoundError(f"Checkpoint not found at: {ckpt_file.resolve()}")
83
+
84
+ # Check if the file is just a Git LFS text pointer
85
+ if ckpt_file.stat().st_size < 2048:
86
+ try:
87
+ with open(ckpt_file, "r", encoding="utf-8", errors="ignore") as f:
88
+ header = f.read(100)
89
+ if "version https://git-lfs" in header:
90
+ print(f"[!] Detected Git LFS pointer ({ckpt_file.stat().st_size} bytes) instead of binary weights.")
91
+ try:
92
+ from huggingface_hub import hf_hub_download
93
+ print("[*] Automatically resolving and downloading full 2.21 GB weights via huggingface_hub...")
94
+ downloaded = hf_hub_download(repo_id="siddiVinayaka/Cortex-System-One", filename=ckpt_file.name)
95
+ ckpt_file = Path(downloaded)
96
+ except Exception as lfs_err:
97
+ raise RuntimeError(
98
+ f"The file '{ckpt_file.name}' is only a Git LFS pointer text file.\n"
99
+ "To pull the actual 2.21 GB weights in Google Colab / Linux, run:\n"
100
+ " !cd /content/Cortex-System-One && git lfs pull\n"
101
+ "Or install huggingface_hub: 'pip install huggingface_hub'"
102
+ ) from lfs_err
103
+ except Exception as e:
104
+ if "Git LFS pointer" in str(e):
105
+ raise e
106
+
107
+ print(f"[*] Loading weights from {ckpt_file.name} ({ckpt_file.stat().st_size / (1024**2):.1f} MB)...")
108
  ckpt = torch.load(ckpt_file, map_location="cpu", weights_only=False)
109
  cfg = ckpt.get("base_cfg", ckpt.get("cfg", {}))
110