7
7
import logging
8
8
import os
9
9
import re
10
+ import shutil
10
11
import subprocess
11
12
import sys
12
13
from pathlib import Path
@@ -297,6 +298,10 @@ def get_base_commit_in_main_branch(self) -> str:
297
298
]).decode ("utf-8" )
298
299
upstream_main_commit = json .loads (resp_json )["sha" ]
299
300
301
+ # In Docker build context, .git may be immutable or missing.
302
+ if envs .VLLM_DOCKER_BUILD_CONTEXT :
303
+ return upstream_main_commit
304
+
300
305
# Check if the upstream_main_commit exists in the local repo
301
306
try :
302
307
subprocess .check_output (
@@ -357,19 +362,48 @@ def run(self) -> None:
357
362
# create a temporary directory to store the wheel
358
363
temp_dir = tempfile .mkdtemp (prefix = "vllm-wheels" )
359
364
wheel_path = os .path .join (temp_dir , wheel_filename )
360
-
361
365
print (f"Downloading wheel from { wheel_location } to { wheel_path } " )
362
-
363
366
from urllib .request import urlretrieve
364
-
365
367
try :
366
368
urlretrieve (wheel_location , filename = wheel_path )
367
369
except Exception as e :
368
370
from setuptools .errors import SetupError
369
-
370
371
raise SetupError (
371
372
f"Failed to get vLLM wheel from { wheel_location } " ) from e
372
373
374
+ # During a docker build: determine correct filename, copy wheel.
375
+ if envs .VLLM_DOCKER_BUILD_CONTEXT :
376
+ dist_dir = "/workspace/dist"
377
+ os .makedirs (dist_dir , exist_ok = True )
378
+ # Determine correct wheel filename from METADATA
379
+ with zipfile .ZipFile (wheel_path , "r" ) as z :
380
+ metadata_file = next (
381
+ (n for n in z .namelist ()
382
+ if n .endswith (".dist-info/METADATA" )),
383
+ None ,
384
+ )
385
+ if not metadata_file :
386
+ raise RuntimeError (
387
+ "Could not find METADATA in precompiled wheel." )
388
+ metadata = z .read (metadata_file ).decode ()
389
+ version_line = next ((line for line in metadata .splitlines ()
390
+ if line .startswith ("Version: " )), None )
391
+ if not version_line :
392
+ raise RuntimeError (
393
+ "Could not determine version from METADATA." )
394
+ version = version_line .split (": " )[1 ].strip ()
395
+
396
+ # Build correct filename using internal version
397
+ arch_tag = "cp38-abi3-manylinux1_x86_64"
398
+ corrected_wheel_name = f"vllm-{ version } -{ arch_tag } .whl"
399
+ final_wheel_path = os .path .join (dist_dir , corrected_wheel_name )
400
+
401
+ print (f"Docker build context detected, copying precompiled wheel "
402
+ f"({ version } ) to { final_wheel_path } " )
403
+ shutil .copy2 (wheel_path , final_wheel_path )
404
+ return
405
+
406
+ # Unzip the wheel when not in Docker context
373
407
with zipfile .ZipFile (wheel_path ) as wheel :
374
408
files_to_copy = [
375
409
"vllm/_C.abi3.so" ,
@@ -378,15 +412,9 @@ def run(self) -> None:
378
412
"vllm/vllm_flash_attn/_vllm_fa2_C.abi3.so" ,
379
413
"vllm/vllm_flash_attn/_vllm_fa3_C.abi3.so" ,
380
414
"vllm/cumem_allocator.abi3.so" ,
381
- # "vllm/_version.py", # not available in nightly wheels yet
382
415
]
383
-
384
416
file_members = list (
385
417
filter (lambda x : x .filename in files_to_copy , wheel .filelist ))
386
-
387
- # vllm_flash_attn python code:
388
- # Regex from
389
- # `glob.translate('vllm/vllm_flash_attn/**/*.py', recursive=True)`
390
418
compiled_regex = re .compile (
391
419
r"vllm/vllm_flash_attn/(?:[^/.][^/]*/)*(?!\.)[^/]*\.py" )
392
420
file_members += list (
@@ -403,18 +431,18 @@ def run(self) -> None:
403
431
package_data [package_name ] = []
404
432
405
433
wheel .extract (file )
406
- if file_name .endswith (".py" ):
407
- # python files shouldn't be added to package_data
408
- continue
409
-
410
- package_data [package_name ].append (file_name )
434
+ if not file_name .endswith (".py" ):
435
+ package_data [package_name ].append (file_name )
411
436
412
437
413
438
def _no_device () -> bool :
414
439
return VLLM_TARGET_DEVICE == "empty"
415
440
416
441
417
442
def _is_cuda () -> bool :
443
+ # Allow forced CUDA in Docker/precompiled builds, even without torch.cuda
444
+ if envs .VLLM_USE_PRECOMPILED and envs .VLLM_DOCKER_BUILD_CONTEXT :
445
+ return True
418
446
has_cuda = torch .version .cuda is not None
419
447
return (VLLM_TARGET_DEVICE == "cuda" and has_cuda
420
448
and not (_is_neuron () or _is_tpu ()))
0 commit comments