Evgueni Poloukarov Claude commited on
Commit
13db9d8
·
1 Parent(s): c85b8a5

fix: move expandable_segments to app.py before torch imports

Browse files

CRITICAL FIX: Previous attempt to set PYTORCH_CUDA_ALLOC_CONF failed
because it was set in chronos_inference.py AFTER torch was already
imported by Gradio or other dependencies.

Solution: Move environment variable to top of app.py BEFORE all imports
(except os/sys). This ensures PyTorch sees the config on first import.

Validation: OOM errors showed fragmentation (12.61 GB reserved but
unallocated) and PyTorch still suggested setting expandable_segments,
proving the previous fix wasn't being applied.

This fixes memory fragmentation that prevented allocating 10.75 GB
contiguous blocks even when 12.61 GB was reserved.

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

Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -2,15 +2,21 @@
2
  """
3
  FBMC Chronos-2 Forecasting API
4
  HuggingFace Space Gradio Interface
5
- Version: 1.0.1 (fixed target column bug)
6
  """
7
 
 
 
 
 
 
 
8
  import sys
9
  print(f"[STARTUP] Python version: {sys.version}", flush=True)
10
  print(f"[STARTUP] Python path: {sys.path[:3]}", flush=True)
 
11
 
12
  import gradio as gr
13
- import os
14
  from datetime import datetime
15
 
16
  print("[STARTUP] Basic imports successful", flush=True)
 
2
  """
3
  FBMC Chronos-2 Forecasting API
4
  HuggingFace Space Gradio Interface
5
+ Version: 1.0.2 (fixed memory fragmentation - expandable_segments)
6
  """
7
 
8
+ # CRITICAL: Set PyTorch memory allocator config BEFORE any imports
9
+ # This prevents memory fragmentation issues that cause OOM even with sufficient free memory
10
+ # Must be set before torch is imported the first time (including via gradio or other dependencies)
11
+ import os
12
+ os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
13
+
14
  import sys
15
  print(f"[STARTUP] Python version: {sys.version}", flush=True)
16
  print(f"[STARTUP] Python path: {sys.path[:3]}", flush=True)
17
+ print(f"[STARTUP] PyTorch memory config: {os.environ.get('PYTORCH_CUDA_ALLOC_CONF')}", flush=True)
18
 
19
  import gradio as gr
 
20
  from datetime import datetime
21
 
22
  print("[STARTUP] Basic imports successful", flush=True)