9
9
import re
10
10
import subprocess
11
11
import sys
12
+ import shutil
12
13
from pathlib import Path
13
14
from shutil import which
14
15
@@ -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,49 @@ 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
- f"Failed to get vLLM wheel from { wheel_location } " ) from e
372
+ f"Failed to get vLLM wheel from { wheel_location } "
373
+ ) from e
374
+
375
+ # During a docker build shortcut: clean dist/, determine correct filename, copy
376
+ if envs .VLLM_DOCKER_BUILD_CONTEXT :
377
+ dist_dir = "/workspace/dist"
378
+ os .makedirs (dist_dir , exist_ok = True )
379
+ # Determine correct wheel filename from METADATA
380
+ with zipfile .ZipFile (wheel_path , "r" ) as z :
381
+ metadata_file = next (
382
+ (n for n in z .namelist () if n .endswith (".dist-info/METADATA" )),
383
+ None ,
384
+ )
385
+ if not metadata_file :
386
+ raise RuntimeError ("Could not find METADATA in precompiled wheel." )
387
+ metadata = z .read (metadata_file ).decode ()
388
+ version_line = next (
389
+ (l for l in metadata .splitlines () if l .startswith ("Version: " )), None
390
+ )
391
+ if not version_line :
392
+ raise RuntimeError ("Could not determine version from METADATA." )
393
+ version = version_line .split (": " )[1 ].strip ()
394
+
395
+ # Build correct filename using internal version
396
+ arch_tag = "cp38-abi3-manylinux1_x86_64"
397
+ corrected_wheel_name = f"vllm-{ version } -{ arch_tag } .whl"
398
+ final_wheel_path = os .path .join (dist_dir , corrected_wheel_name )
399
+
400
+ print (
401
+ f"Docker build context detected, copying precompiled wheel "
402
+ f"({ version } ) to { final_wheel_path } "
403
+ )
404
+ shutil .copy2 (wheel_path , final_wheel_path )
405
+ return
372
406
407
+ # Unzip the wheel when not in Docker context
373
408
with zipfile .ZipFile (wheel_path ) as wheel :
374
409
files_to_copy = [
375
410
"vllm/_C.abi3.so" ,
@@ -378,36 +413,28 @@ def run(self) -> None:
378
413
"vllm/vllm_flash_attn/_vllm_fa2_C.abi3.so" ,
379
414
"vllm/vllm_flash_attn/_vllm_fa3_C.abi3.so" ,
380
415
"vllm/cumem_allocator.abi3.so" ,
381
- # "vllm/_version.py", # not available in nightly wheels yet
382
416
]
383
-
384
417
file_members = list (
385
- 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)`
418
+ filter (lambda x : x .filename in files_to_copy , wheel .filelist )
419
+ )
390
420
compiled_regex = re .compile (
391
- r"vllm/vllm_flash_attn/(?:[^/.][^/]*/)*(?!\.)[^/]*\.py" )
421
+ r"vllm/vllm_flash_attn/(?:[^/.][^/]*/)*(?!\.)[^/]*\.py"
422
+ )
392
423
file_members += list (
393
- filter (lambda x : compiled_regex .match (x .filename ),
394
- wheel . filelist ) )
424
+ filter (lambda x : compiled_regex .match (x .filename ), wheel . filelist )
425
+ )
395
426
396
427
for file in file_members :
397
- print (f"Extracting and including { file .filename } "
398
- "from existing wheel" )
428
+ print (f"Extracting and including { file .filename } from existing wheel" )
399
429
package_name = os .path .dirname (file .filename ).replace ("/" , "." )
400
430
file_name = os .path .basename (file .filename )
401
431
402
432
if package_name not in package_data :
403
433
package_data [package_name ] = []
404
434
405
435
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 )
436
+ if not file_name .endswith (".py" ):
437
+ package_data [package_name ].append (file_name )
411
438
412
439
413
440
def _is_hpu () -> bool :
@@ -438,6 +465,9 @@ def _no_device() -> bool:
438
465
439
466
440
467
def _is_cuda () -> bool :
468
+ # Allow forced CUDA in Docker/precompiled builds, even without torch.cuda
469
+ if envs .VLLM_USE_PRECOMPILED and envs .VLLM_DOCKER_BUILD_CONTEXT :
470
+ return True
441
471
has_cuda = torch .version .cuda is not None
442
472
return (VLLM_TARGET_DEVICE == "cuda" and has_cuda
443
473
and not (_is_neuron () or _is_tpu () or _is_hpu ()))
0 commit comments