Spaces:
Paused
Paused
Tonic commited on
Commit ·
cf7c042
1
Parent(s): da0507e
solve device handling issue
Browse files
app.py
CHANGED
|
@@ -316,12 +316,16 @@ def make_prediction(symbol: str, timeframe: str = "1d", prediction_days: int = 5
|
|
| 316 |
# Take the most recent data points
|
| 317 |
normalized_prices = normalized_prices[-min_data_points:]
|
| 318 |
|
| 319 |
-
# Convert to tensor and ensure proper shape
|
| 320 |
-
context = torch.tensor(normalized_prices, dtype=torch.float32)
|
| 321 |
-
|
| 322 |
# Make prediction with GPU acceleration
|
| 323 |
pipe = load_pipeline()
|
| 324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
# Adjust prediction length based on timeframe
|
| 326 |
if timeframe == "1d":
|
| 327 |
max_prediction_length = 64 # Maximum 64 days for daily data
|
|
@@ -346,13 +350,14 @@ def make_prediction(symbol: str, timeframe: str = "1d", prediction_days: int = 5
|
|
| 346 |
print(f"Attempting prediction with context shape: {context.shape}")
|
| 347 |
print(f"Prediction length: {actual_prediction_length}")
|
| 348 |
|
| 349 |
-
# Move context to the same device as the model
|
| 350 |
-
context = context.to(device=pipe.model.device)
|
| 351 |
-
|
| 352 |
# Ensure context is properly formatted for Chronos
|
| 353 |
if len(context.shape) == 1:
|
| 354 |
context = context.unsqueeze(0) # Add batch dimension
|
| 355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
# Use predict_quantiles with proper formatting
|
| 357 |
quantiles, mean = pipe.predict_quantiles(
|
| 358 |
context=context,
|
|
|
|
| 316 |
# Take the most recent data points
|
| 317 |
normalized_prices = normalized_prices[-min_data_points:]
|
| 318 |
|
|
|
|
|
|
|
|
|
|
| 319 |
# Make prediction with GPU acceleration
|
| 320 |
pipe = load_pipeline()
|
| 321 |
|
| 322 |
+
# Get the model's device
|
| 323 |
+
device = next(pipe.model.parameters()).device
|
| 324 |
+
print(f"Model device: {device}")
|
| 325 |
+
|
| 326 |
+
# Convert to tensor and ensure proper shape and device
|
| 327 |
+
context = torch.tensor(normalized_prices, dtype=torch.float32, device=device)
|
| 328 |
+
|
| 329 |
# Adjust prediction length based on timeframe
|
| 330 |
if timeframe == "1d":
|
| 331 |
max_prediction_length = 64 # Maximum 64 days for daily data
|
|
|
|
| 350 |
print(f"Attempting prediction with context shape: {context.shape}")
|
| 351 |
print(f"Prediction length: {actual_prediction_length}")
|
| 352 |
|
|
|
|
|
|
|
|
|
|
| 353 |
# Ensure context is properly formatted for Chronos
|
| 354 |
if len(context.shape) == 1:
|
| 355 |
context = context.unsqueeze(0) # Add batch dimension
|
| 356 |
|
| 357 |
+
# Verify device
|
| 358 |
+
print(f"Context device: {context.device}")
|
| 359 |
+
print(f"Model device: {next(pipe.model.parameters()).device}")
|
| 360 |
+
|
| 361 |
# Use predict_quantiles with proper formatting
|
| 362 |
quantiles, mean = pipe.predict_quantiles(
|
| 363 |
context=context,
|