Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -252,40 +252,32 @@ def get_hub_or_local_checkpoint(repo_id: str, filename: str):
|
|
| 252 |
return ckpt_path
|
| 253 |
|
| 254 |
def download_gemma_model(repo_id: str):
|
| 255 |
-
"""
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
local_repo_dir.mkdir(parents=True, exist_ok=True)
|
| 260 |
-
|
| 261 |
-
log_event(f"Downloading Gemma model from {repo_id} into {local_repo_dir}...")
|
| 262 |
-
local_dir = snapshot_download(
|
| 263 |
-
repo_id=repo_id,
|
| 264 |
-
local_dir=local_repo_dir,
|
| 265 |
-
)
|
| 266 |
-
log_event(f"Gemma model downloaded to {local_dir}")
|
| 267 |
return local_dir
|
| 268 |
|
| 269 |
# Initialize model ledger and text encoder at startup (load once, keep in memory)
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
|
| 274 |
checkpoint_path = get_hub_or_local_checkpoint(DEFAULT_REPO_ID, DEFAULT_CHECKPOINT_FILENAME)
|
| 275 |
gemma_local_path = download_gemma_model(DEFAULT_GEMMA_REPO_ID)
|
| 276 |
-
device =
|
| 277 |
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
|
| 283 |
|
| 284 |
model_ledger = ModelLedger(
|
| 285 |
dtype=torch.bfloat16,
|
| 286 |
device=device,
|
| 287 |
checkpoint_path=checkpoint_path,
|
| 288 |
-
gemma_root_path=
|
| 289 |
local_files_only=False
|
| 290 |
)
|
| 291 |
|
|
|
|
| 252 |
return ckpt_path
|
| 253 |
|
| 254 |
def download_gemma_model(repo_id: str):
|
| 255 |
+
"""Download the full Gemma model directory."""
|
| 256 |
+
print(f"Downloading Gemma model from {repo_id}...")
|
| 257 |
+
local_dir = snapshot_download(repo_id=repo_id)
|
| 258 |
+
print(f"Gemma model downloaded to {local_dir}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
return local_dir
|
| 260 |
|
| 261 |
# Initialize model ledger and text encoder at startup (load once, keep in memory)
|
| 262 |
+
print("=" * 80)
|
| 263 |
+
print("Loading Gemma Text Encoder...")
|
| 264 |
+
print("=" * 80)
|
| 265 |
|
| 266 |
checkpoint_path = get_hub_or_local_checkpoint(DEFAULT_REPO_ID, DEFAULT_CHECKPOINT_FILENAME)
|
| 267 |
gemma_local_path = download_gemma_model(DEFAULT_GEMMA_REPO_ID)
|
| 268 |
+
device = "cuda"
|
| 269 |
|
| 270 |
+
print(f"Initializing text encoder with:")
|
| 271 |
+
print(f" checkpoint_path={checkpoint_path}")
|
| 272 |
+
print(f" gemma_root={gemma_local_path}")
|
| 273 |
+
print(f" device={device}")
|
| 274 |
|
| 275 |
|
| 276 |
model_ledger = ModelLedger(
|
| 277 |
dtype=torch.bfloat16,
|
| 278 |
device=device,
|
| 279 |
checkpoint_path=checkpoint_path,
|
| 280 |
+
gemma_root_path=DEFAULT_GEMMA_REPO_ID,
|
| 281 |
local_files_only=False
|
| 282 |
)
|
| 283 |
|