Spaces:
Sleeping
Sleeping
Evgueni Poloukarov
commited on
Commit
·
748ef95
1
Parent(s):
2ea0150
fix: handle forecast shape correctly for quantile calculation
Browse files- Add logic to detect forecast shape (samples, time) vs (time, samples)
- Compute quantiles along correct axis based on shape
- Add median shape validation logging
- This should fix the dimension mismatch error
- Bump to v1.0.7
src/forecasting/chronos_inference.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"""
|
| 3 |
Chronos-2 Inference Pipeline
|
| 4 |
Standalone inference script for HuggingFace Space deployment.
|
| 5 |
-
FORCE REBUILD: v1.0.
|
| 6 |
"""
|
| 7 |
|
| 8 |
import os
|
|
@@ -188,11 +188,26 @@ class ChronosInferencePipeline:
|
|
| 188 |
forecast_numpy = forecast.numpy()
|
| 189 |
print(f"[DEBUG] Forecast shape: {forecast_numpy.shape}, Expected: ({num_samples}, {prediction_hours})", flush=True)
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
# Store results
|
| 192 |
results['borders'][border] = {
|
| 193 |
-
'median':
|
| 194 |
-
'q10':
|
| 195 |
-
'q90':
|
| 196 |
'inference_time_s': time.time() - border_start
|
| 197 |
}
|
| 198 |
|
|
|
|
| 2 |
"""
|
| 3 |
Chronos-2 Inference Pipeline
|
| 4 |
Standalone inference script for HuggingFace Space deployment.
|
| 5 |
+
FORCE REBUILD: v1.0.7
|
| 6 |
"""
|
| 7 |
|
| 8 |
import os
|
|
|
|
| 188 |
forecast_numpy = forecast.numpy()
|
| 189 |
print(f"[DEBUG] Forecast shape: {forecast_numpy.shape}, Expected: ({num_samples}, {prediction_hours})", flush=True)
|
| 190 |
|
| 191 |
+
# Compute quantiles along the sample axis (axis=0 for shape (num_samples, time))
|
| 192 |
+
# If shape is transposed (time, num_samples), use axis=1
|
| 193 |
+
if forecast_numpy.shape[0] == prediction_hours:
|
| 194 |
+
# Shape is (time, samples) - use axis=1
|
| 195 |
+
median = np.median(forecast_numpy, axis=1)
|
| 196 |
+
q10 = np.quantile(forecast_numpy, 0.1, axis=1)
|
| 197 |
+
q90 = np.quantile(forecast_numpy, 0.9, axis=1)
|
| 198 |
+
else:
|
| 199 |
+
# Shape is (samples, time) - use axis=0
|
| 200 |
+
median = np.median(forecast_numpy, axis=0)
|
| 201 |
+
q10 = np.quantile(forecast_numpy, 0.1, axis=0)
|
| 202 |
+
q90 = np.quantile(forecast_numpy, 0.9, axis=0)
|
| 203 |
+
|
| 204 |
+
print(f"[DEBUG] Median shape: {median.shape}, Expected: ({prediction_hours},)", flush=True)
|
| 205 |
+
|
| 206 |
# Store results
|
| 207 |
results['borders'][border] = {
|
| 208 |
+
'median': median.tolist(),
|
| 209 |
+
'q10': q10.tolist(),
|
| 210 |
+
'q90': q90.tolist(),
|
| 211 |
'inference_time_s': time.time() - border_start
|
| 212 |
}
|
| 213 |
|