Evgueni Poloukarov Claude commited on
Commit
caf0333
·
1 Parent(s): 7a9aff9

docs: update activity.md with Session 11 progress

Browse files

Session 11: CUDA OOM Troubleshooting & Memory Optimization
- Documented root cause investigation (batch_size=256, 9 quantiles)
- Explained memory optimization fix (commit 7a9aff9)
- Listed next steps for resuming work
- Status: Waiting for HF Space rebuild

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Files changed (1) hide show
  1. doc/activity.md +343 -0
doc/activity.md CHANGED
@@ -2,6 +2,349 @@
2
 
3
  ---
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ## Session 9: Batch Inference Optimization & GPU Memory Management
6
  **Date**: 2025-11-15
7
  **Duration**: ~4 hours
 
2
 
3
  ---
4
 
5
+ ## Session 11: CUDA OOM Troubleshooting & Memory Optimization
6
+ **Date**: 2025-11-17
7
+ **Duration**: ~3 hours
8
+ **Status**: IN PROGRESS - Memory fix committed, awaiting HF Space rebuild
9
+
10
+ ### Objectives
11
+ 1. ✓ Recover workflow after unexpected session termination
12
+ 2. ✓ Validate multivariate forecasting with smoke test
13
+ 3. ✓ Diagnose CUDA OOM error (18GB memory usage on 24GB GPU)
14
+ 4. ✓ Implement memory optimization fix
15
+ 5. ⏳ Run October 2024 evaluation (pending HF Space rebuild)
16
+ 6. ⏳ Calculate MAE metrics D+1 through D+14
17
+ 7. ⏳ Document results and complete Day 4
18
+
19
+ ### Problem: CUDA Out of Memory Error
20
+
21
+ **HF Space Error**:
22
+ ```
23
+ CUDA out of memory. Tried to allocate 10.75 GiB.
24
+ GPU 0 has a total capacity of 22.03 GiB of which 3.96 GiB is free.
25
+ Including non-PyTorch memory, this process has 18.06 GiB memory in use.
26
+ ```
27
+
28
+ **Initial Confusion**: Why is 18GB being used for:
29
+ - Model: Chronos-2 (120M params) = ~240MB in bfloat16
30
+ - Data: 25MB parquet file
31
+ - Context: 256h × 615 features
32
+
33
+ This made no sense - should require <2GB total.
34
+
35
+ ### Root Cause Investigation
36
+
37
+ Investigated multiple potential causes:
38
+ 1. **Historical features in context** - Initially suspected 2,514 features (603+12+1899) was the issue
39
+ 2. **User challenge** - Correctly questioned whether historical features should be excluded
40
+ 3. **Documentation review** - Confirmed context SHOULD include historical features (for pattern learning)
41
+ 4. **Deep dive into defaults** - Found the real culprits
42
+
43
+ ### Root Causes Identified
44
+
45
+ #### 1. Default batch_size = 256 (not overridden)
46
+ ```python
47
+ # predict_df() default parameters
48
+ batch_size: 256 # Processes 256 rows in parallel!
49
+ ```
50
+
51
+ With 256h context × 2,514 features × batch_size 256 → massive memory allocation
52
+
53
+ #### 2. Default quantile_levels = 9 quantiles
54
+ ```python
55
+ quantile_levels: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] # Computing 9 quantiles
56
+ ```
57
+
58
+ We only use 3 quantiles (0.1, 0.5, 0.9) - the other 6 waste GPU memory
59
+
60
+ #### 3. Transformer attention memory explosion
61
+ Chronos-2's group attention mechanism creates intermediate tensors proportional to:
62
+ - (sequence_length × num_features)²
63
+ - With batch_size=256 and 9 quantiles, memory explodes exponentially
64
+
65
+ ### The Fix (Commit 7a9aff9)
66
+
67
+ **Changed**: `src/forecasting/chronos_inference.py` lines 203-213
68
+
69
+ ```python
70
+ # BEFORE (using defaults)
71
+ forecasts_df = pipeline.predict_df(
72
+ context_data,
73
+ future_df=future_data,
74
+ prediction_length=prediction_hours,
75
+ id_column='border',
76
+ timestamp_column='timestamp',
77
+ target='target'
78
+ # batch_size defaults to 256
79
+ # quantile_levels defaults to [0.1-0.9] (9 values)
80
+ )
81
+
82
+ # AFTER (memory optimized)
83
+ forecasts_df = pipeline.predict_df(
84
+ context_data,
85
+ future_df=future_data,
86
+ prediction_length=prediction_hours,
87
+ id_column='border',
88
+ timestamp_column='timestamp',
89
+ target='target',
90
+ batch_size=32, # Reduce from 256 → ~87% memory reduction
91
+ quantile_levels=[0.1, 0.5, 0.9] # Only compute needed quantiles → ~67% reduction
92
+ )
93
+ ```
94
+
95
+ **Expected Memory Savings**:
96
+ - batch_size: 256 → 32 = ~87% reduction
97
+ - quantiles: 9 → 3 = ~67% reduction
98
+ - **Combined**: ~95% reduction in inference memory usage
99
+
100
+ **Impact on Quality**:
101
+ - **NONE** - batch_size only affects computation speed, not forecast values
102
+ - **NONE** - we only use 3 quantiles anyway, others were discarded
103
+
104
+ ### Git Activity
105
+
106
+ ```
107
+ 7a9aff9 - fix: reduce batch_size to 32 and quantiles to 3 for GPU memory optimization
108
+ - Comprehensive commit message documenting the fix
109
+ - No quality impact (batch_size is computational only)
110
+ - Should resolve CUDA OOM on 24GB L4 GPU
111
+ ```
112
+
113
+ Pushed to GitHub: https://github.com/evgspacdmy/fbmc_chronos2
114
+
115
+ ### Files Modified
116
+ - `src/forecasting/chronos_inference.py` - Added batch_size and quantile_levels parameters
117
+ - `scripts/evaluate_october_2024.py` - Created evaluation script (uses local data)
118
+
119
+ ### Testing Results
120
+
121
+ **Smoke Test (before fix)**:
122
+ - ✓ Single border (AT_CZ) works fine
123
+ - ✓ Forecast shows variation (mean 287 MW, std 56 MW)
124
+ - ✓ API connection successful
125
+
126
+ **Full 38-border test (before fix)**:
127
+ - ✗ CUDA OOM on first border
128
+ - Error shows 18GB usage + trying to allocate 10.75GB
129
+ - Returns debug file instead of parquet
130
+
131
+ **Full 38-border test (after fix)**:
132
+ - ⏳ Waiting for HF Space rebuild with commit 7a9aff9
133
+ - HF Spaces auto-rebuild can take 5-20 minutes
134
+ - May require manual "Factory Rebuild" from Space settings
135
+
136
+ ### Current Status
137
+
138
+ - [x] Root cause identified (batch_size=256, 9 quantiles)
139
+ - [x] Memory optimization implemented
140
+ - [x] Committed to git (7a9aff9)
141
+ - [x] Pushed to GitHub
142
+ - [ ] HF Space rebuild (in progress)
143
+ - [ ] Smoke test validation (pending rebuild)
144
+ - [ ] Full Oct 1-14, 2024 forecast (pending rebuild)
145
+ - [ ] Calculate MAE D+1 through D+14 (pending forecast)
146
+ - [ ] Document results in activity.md (pending evaluation)
147
+
148
+ ### Next Steps (Resume Here Next Session)
149
+
150
+ **PRIORITY 1**: Wait for HF Space rebuild or trigger manual Factory Rebuild
151
+ - Go to: https://huggingface.co/spaces/evgueni-p/fbmc-chronos2/settings
152
+ - Click "Factory Rebuild" if auto-rebuild hasn't triggered
153
+ - Wait ~5 minutes for rebuild completion
154
+
155
+ **PRIORITY 2**: Validate memory fix works
156
+ ```bash
157
+ cd /c/Users/evgue/projects/fbmc_chronos2
158
+ .venv/Scripts/python.exe scripts/evaluate_october_2024.py
159
+ ```
160
+
161
+ **PRIORITY 3**: If successful, proceed with original Day 4 plan
162
+ - Calculate MAE metrics for D+1 through D+14
163
+ - Update activity.md with Session 11 results
164
+ - Create HANDOVER_GUIDE.md
165
+ - Archive test scripts
166
+ - Commit and push final results
167
+
168
+ **PRIORITY 4**: If still OOM, consider alternatives:
169
+ - Further reduce batch_size to 16 or 8
170
+ - Reduce context_hours from 256h to 128h
171
+ - Document as limitation requiring A100 40GB GPU for production
172
+
173
+ ### Key Learnings
174
+
175
+ 1. **Always check default parameters** - Libraries often have defaults optimized for different use cases
176
+ 2. **batch_size doesn't affect quality** - It's purely a computational optimization parameter
177
+ 3. **Memory usage isn't linear** - Transformer attention creates quadratic memory growth
178
+ 4. **Test with realistic data sizes** - Smoke tests (1 border) can hide multi-border issues
179
+ 5. **Document assumptions** - User correctly challenged the historical features assumption
180
+ 6. **HF Space rebuild delays** - May need manual trigger, not instant after push
181
+
182
+ ### Technical Notes
183
+
184
+ **Why batch_size=32 vs 256**:
185
+ - batch_size controls parallel processing of rows within a single border forecast
186
+ - Larger = faster but more memory
187
+ - Smaller = slower but less memory
188
+ - **No impact on final forecast values** - same predictions either way
189
+
190
+ **Context features breakdown**:
191
+ - Full-horizon D+14: 603 features (always available)
192
+ - Partial D+1: 12 features (load forecasts)
193
+ - Historical: 1,899 features (prices, gen, demand)
194
+ - **Total context**: 2,514 features
195
+ - **Future covariates**: 615 features (603 + 12)
196
+
197
+ **Why historical features in context**:
198
+ - Help model learn patterns from past behavior
199
+ - Not available in future (can't forecast price/demand)
200
+ - But provide context for understanding historical trends
201
+ - Standard practice in time series forecasting with covariates
202
+
203
+ ---
204
+
205
+ **Status**: [IN PROGRESS] Waiting for HF Space rebuild with memory optimization
206
+ **Timestamp**: 2025-11-17 16:30 UTC
207
+ **Next Action**: Trigger Factory Rebuild or wait for auto-rebuild, then run evaluation
208
+
209
+ ---
210
+
211
+ ## Session 10: CRITICAL FIX - Enable Multivariate Covariate Forecasting
212
+ **Date**: 2025-11-15
213
+ **Duration**: ~2 hours
214
+ **Status**: CRITICAL REGRESSION FIXED - Awaiting HF Space rebuild
215
+
216
+ ### Critical Issue Discovered
217
+
218
+ **Problem**: HF Space deployment was using **univariate forecasting** (target values only), completely ignoring all 615 collected features!
219
+
220
+ **Impact**:
221
+ - Weather per zone: IGNORED
222
+ - Generation per zone: IGNORED
223
+ - CNEC outages (200 CNECs): IGNORED
224
+ - LTA allocations: IGNORED
225
+ - Load forecasts: IGNORED
226
+
227
+ **Root Cause**: When optimizing for batch inference in Session 9, we switched from DataFrame API (`predict_df()`) to tensor API (`predict()`), which doesn't support covariates. The entire covariate-informed forecasting capability was accidentally disabled.
228
+
229
+ ### The Fix (Commit 0b4284f)
230
+
231
+ **Changes Made**:
232
+
233
+ 1. **Switched to Chronos2Pipeline** - Model that supports covariates
234
+ ```python
235
+ # OLD (Session 9)
236
+ from chronos import ChronosPipeline
237
+ pipeline = ChronosPipeline.from_pretrained("amazon/chronos-t5-large")
238
+
239
+ # NEW (Session 10)
240
+ from chronos import Chronos2Pipeline
241
+ pipeline = Chronos2Pipeline.from_pretrained("amazon/chronos-2")
242
+ ```
243
+
244
+ 2. **Changed inference API** - DataFrame API supports covariates
245
+ ```python
246
+ # OLD - Tensor API (univariate only)
247
+ forecasts = pipeline.predict(
248
+ inputs=batch_tensor, # Only target values!
249
+ prediction_length=168
250
+ )
251
+
252
+ # NEW - DataFrame API (multivariate with covariates)
253
+ forecasts = pipeline.predict_df(
254
+ context_data, # Historical data with ALL features
255
+ future_df=future_data, # Future covariates (615 features)
256
+ prediction_length=168,
257
+ id_column='border',
258
+ timestamp_column='timestamp',
259
+ target='target'
260
+ )
261
+ ```
262
+
263
+ 3. **Model configuration updates**:
264
+ - Model: `amazon/chronos-t5-large` → `amazon/chronos-2`
265
+ - Dtype: `bfloat16` → `float32` (required for chronos-2)
266
+
267
+ 4. **Removed batch inference** - Reverted to per-border processing to enable covariate support
268
+ - Per-border processing allows full feature utilization
269
+ - Chronos-2's group attention mechanism shares information across covariates
270
+
271
+ **Files Modified**:
272
+ - `src/forecasting/chronos_inference.py` (v1.1.0):
273
+ - Lines 1-22: Updated imports and docstrings
274
+ - Lines 31-47: Changed model initialization
275
+ - Lines 66-70: Updated model loading
276
+ - Lines 164-252: Complete inference rewrite for covariates
277
+
278
+ **Expected Impact**:
279
+ - **Significantly improved forecast accuracy** by leveraging all 615 collected features
280
+ - Model now uses Chronos-2's in-context learning with exogenous features
281
+ - Zero-shot multivariate forecasting as originally intended
282
+
283
+ ### Git Activity
284
+
285
+ ```
286
+ 0b4284f - feat: enable multivariate covariate forecasting with 615 features
287
+ - Switch from ChronosPipeline to Chronos2Pipeline
288
+ - Change from predict() to predict_df() API
289
+ - Now passes both context_data AND future_data
290
+ - Enables zero-shot multivariate forecasting capability
291
+ ```
292
+
293
+ Pushed to:
294
+ - GitHub: https://github.com/evgspacdmy/fbmc_chronos2
295
+ - HF Space: https://huggingface.co/spaces/evgueni-p/fbmc-chronos2 (rebuild in progress)
296
+
297
+ ### Current Status
298
+
299
+ - [x] Code changes complete
300
+ - [x] Committed to git (0b4284f)
301
+ - [x] Pushed to GitHub
302
+ - [ ] HF Space rebuild (in progress)
303
+ - [ ] Smoke test validation
304
+ - [ ] Full Oct 1-14 forecast with covariates
305
+ - [ ] Calculate MAE D+1 through D+14
306
+
307
+ ### Next Steps
308
+
309
+ 1. **PRIORITY 1**: Wait for HF Space rebuild with commit 0b4284f
310
+ 2. **PRIORITY 2**: Run smoke test and verify logs show "Using 615 future covariates"
311
+ 3. **PRIORITY 3**: Run full Oct 1-14, 2024 forecast with all 38 borders
312
+ 4. **PRIORITY 4**: Calculate MAE for D+1 through D+14 (user's explicit request)
313
+ 5. **PRIORITY 5**: Compare accuracy vs univariate baseline (Session 9 results)
314
+ 6. **PRIORITY 6**: Document final results and handover
315
+
316
+ ### Key Learnings
317
+
318
+ 1. **API mismatch risk**: Tensor API vs DataFrame API have different capabilities
319
+ 2. **Always verify feature usage**: Don't assume features are being used without checking
320
+ 3. **Regression during optimization**: Speed improvements can accidentally break functionality
321
+ 4. **Testing is critical**: Should have validated feature usage in Session 9
322
+ 5. **User feedback essential**: User caught the issue immediately
323
+
324
+ ### Technical Notes
325
+
326
+ **Why Chronos-2 supports multivariate forecasting in zero-shot**:
327
+ - Group attention mechanism shares information across time series AND covariates
328
+ - In-context learning (ICL) handles arbitrary exogenous features
329
+ - No fine-tuning required - works in zero-shot mode
330
+ - Model pre-trained on diverse time series with various covariate patterns
331
+
332
+ **Feature categories now being used**:
333
+ - Weather: 52 grid points × multiple variables = ~200 features
334
+ - Generation: 13 zones × fuel types = ~100 features
335
+ - CNEC outages: 200 CNECs with weighted binding scores = ~200 features
336
+ - LTA: Long-term allocations per border = ~38 features
337
+ - Load forecasts: Per-zone load predictions = ~77 features
338
+ - **Total**: 615 features actively used in multivariate forecasting
339
+
340
+ ---
341
+
342
+ **Status**: [IN PROGRESS] Waiting for HF Space rebuild at commit 0b4284f
343
+ **Timestamp**: 2025-11-15 23:20 UTC
344
+ **Next Action**: Monitor rebuild, then test smoke test with covariate logs
345
+
346
+ ---
347
+
348
  ## Session 9: Batch Inference Optimization & GPU Memory Management
349
  **Date**: 2025-11-15
350
  **Duration**: ~4 hours