Peter Larnholt commited on
Commit
5130472
·
1 Parent(s): cda3840

Add sitecustomize.py to patch pyairports module globally

Browse files
Files changed (3) hide show
  1. app.py +2 -9
  2. requirements.txt +2 -5
  3. sitecustomize.py +14 -0
app.py CHANGED
@@ -10,7 +10,7 @@ import os, time, threading, subprocess, requests
10
  from fastapi import FastAPI, Request, Response
11
  import gradio as gr
12
 
13
- os.environ["VLLM_USE_OUTLINES"] = "0" # turn off outlines so pyairports isn't imported
14
 
15
  MODEL_ID = os.environ.get("MODEL_ID", "Qwen/Qwen2.5-14B-Instruct-AWQ")
16
  API_PORT = int(os.environ.get("API_PORT", "8000")) # vLLM internal port
@@ -34,15 +34,8 @@ if "AWQ" in MODEL_ID.upper():
34
 
35
  def launch_vllm():
36
  print(f"[vLLM] Launch: {MODEL_ID}")
37
- # Debug: check if pyairports is available
38
- try:
39
- import pyairports
40
- print(f"[DEBUG] pyairports found: {pyairports.__file__}")
41
- except ImportError as e:
42
- print(f"[DEBUG] pyairports NOT found: {e}")
43
-
44
  env = os.environ.copy()
45
- env["VLLM_USE_OUTLINES"] = "0" # disable outlines to avoid pyairports import
46
  subprocess.Popen(VLLM_ARGS, env=env)
47
 
48
  def wait_vllm_ready(timeout=900, interval=3):
 
10
  from fastapi import FastAPI, Request, Response
11
  import gradio as gr
12
 
13
+ os.environ["VLLM_USE_OUTLINES"] = "0" # turn off outlines (pyairports patched via sitecustomize.py)
14
 
15
  MODEL_ID = os.environ.get("MODEL_ID", "Qwen/Qwen2.5-14B-Instruct-AWQ")
16
  API_PORT = int(os.environ.get("API_PORT", "8000")) # vLLM internal port
 
34
 
35
  def launch_vllm():
36
  print(f"[vLLM] Launch: {MODEL_ID}")
 
 
 
 
 
 
 
37
  env = os.environ.copy()
38
+ env["VLLM_USE_OUTLINES"] = "0" # disable outlines
39
  subprocess.Popen(VLLM_ARGS, env=env)
40
 
41
  def wait_vllm_ready(timeout=900, interval=3):
requirements.txt CHANGED
@@ -11,8 +11,5 @@ transformers>=4.44
11
  accelerate>=0.30
12
 
13
  # Structured outputs stack used by vLLM
14
- # Note: Even with VLLM_USE_OUTLINES=0, vLLM 0.5.5 imports outlines at module level
15
- outlines==0.0.46
16
- numba==0.59.1
17
- pycountry==24.6.1
18
- git+https://github.com/mborsetti/pyairports.git@v2.1.1
 
11
  accelerate>=0.30
12
 
13
  # Structured outputs stack used by vLLM
14
+ # outlines is imported by vLLM 0.5.5 even with VLLM_USE_OUTLINES=0
15
+ # We skip outlines dependencies and will patch the import
 
 
 
sitecustomize.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Sitecustomize to patch pyairports module before any imports.
3
+ This runs automatically for all Python processes.
4
+ """
5
+ import sys
6
+ from types import ModuleType
7
+
8
+ # Create fake pyairports module to satisfy outlines import
9
+ # vLLM 0.5.5 imports outlines even when VLLM_USE_OUTLINES=0
10
+ pyairports = ModuleType('pyairports')
11
+ pyairports.airports = ModuleType('pyairports.airports')
12
+ pyairports.airports.AIRPORT_LIST = []
13
+ sys.modules['pyairports'] = pyairports
14
+ sys.modules['pyairports.airports'] = pyairports.airports