Spaces:
Paused
Paused
Tonic commited on
Commit ·
2c138aa
1
Parent(s): 548b797
move all model and components to cuda
Browse files
app.py
CHANGED
|
@@ -352,29 +352,31 @@ def make_prediction(symbol: str, timeframe: str = "1d", prediction_days: int = 5
|
|
| 352 |
# Move model to evaluation mode
|
| 353 |
pipe.model.eval()
|
| 354 |
|
| 355 |
-
#
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
| 361 |
|
| 362 |
-
# Move all
|
| 363 |
-
for param in pipe.model.
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
if hasattr(pipe.model, 'distribution_head'):
|
| 370 |
-
pipe.model.distribution_head = pipe.model.distribution_head.to(device)
|
| 371 |
|
| 372 |
# Use predict_quantiles with proper formatting
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
|
|
|
| 378 |
|
| 379 |
if quantiles is None or mean is None:
|
| 380 |
raise ValueError("Chronos returned empty prediction")
|
|
|
|
| 352 |
# Move model to evaluation mode
|
| 353 |
pipe.model.eval()
|
| 354 |
|
| 355 |
+
# Move the main model to GPU but keep distribution head on CPU
|
| 356 |
+
if hasattr(pipe.model, 'encoder'):
|
| 357 |
+
pipe.model.encoder = pipe.model.encoder.to(device)
|
| 358 |
+
if hasattr(pipe.model, 'decoder'):
|
| 359 |
+
pipe.model.decoder = pipe.model.decoder.to(device)
|
| 360 |
+
if hasattr(pipe.model, 'embed_tokens'):
|
| 361 |
+
pipe.model.embed_tokens = pipe.model.embed_tokens.to(device)
|
| 362 |
+
if hasattr(pipe.model, 'final_layer_norm'):
|
| 363 |
+
pipe.model.final_layer_norm = pipe.model.final_layer_norm.to(device)
|
| 364 |
|
| 365 |
+
# Move all parameters and buffers except distribution head
|
| 366 |
+
for name, param in pipe.model.named_parameters():
|
| 367 |
+
if 'distribution_head' not in name:
|
| 368 |
+
param.data = param.data.to(device)
|
| 369 |
+
for name, buffer in pipe.model.named_buffers():
|
| 370 |
+
if 'distribution_head' not in name:
|
| 371 |
+
buffer.data = buffer.data.to(device)
|
|
|
|
|
|
|
| 372 |
|
| 373 |
# Use predict_quantiles with proper formatting
|
| 374 |
+
with torch.cuda.amp.autocast():
|
| 375 |
+
quantiles, mean = pipe.predict_quantiles(
|
| 376 |
+
context=context,
|
| 377 |
+
prediction_length=actual_prediction_length,
|
| 378 |
+
quantile_levels=[0.1, 0.5, 0.9]
|
| 379 |
+
)
|
| 380 |
|
| 381 |
if quantiles is None or mean is None:
|
| 382 |
raise ValueError("Chronos returned empty prediction")
|