Skip to content

Commit 6db6f2b

Browse files
dougbtvdiegocastanibm
authored andcommitted
For VLLM_USE_PRECOMPILED, only compiled .so files should be extracted (vllm-project#21964)
Signed-off-by: Diego-Castan <[email protected]>
1 parent 7c82af2 commit 6db6f2b

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

setup.py

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -371,40 +371,31 @@ def run(self) -> None:
371371
raise SetupError(
372372
f"Failed to get vLLM wheel from {wheel_location}") from e
373373

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)
374+
# Set the dist_dir for Docker build context
375+
dist_dir = ("/workspace/dist"
376+
if envs.VLLM_DOCKER_BUILD_CONTEXT else "dist")
377+
os.makedirs(dist_dir, exist_ok=True)
400378

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
379+
# Extract only necessary compiled .so files from precompiled wheel
407380
with zipfile.ZipFile(wheel_path) as wheel:
381+
# Get version from METADATA (optional, mostly useful for logging)
382+
metadata_file = next((n for n in wheel.namelist()
383+
if n.endswith(".dist-info/METADATA")), None)
384+
if not metadata_file:
385+
raise RuntimeError(
386+
"Could not find METADATA in precompiled wheel.")
387+
metadata = wheel.read(metadata_file).decode()
388+
version_line = next((line for line in metadata.splitlines()
389+
if line.startswith("Version: ")), None)
390+
if not version_line:
391+
raise RuntimeError(
392+
"Could not determine version from METADATA.")
393+
version = version_line.split(": ")[1].strip()
394+
395+
print(f"Extracting precompiled kernels from vLLM wheel version: "
396+
f"{version}")
397+
398+
# List of compiled shared objects to extract
408399
files_to_copy = [
409400
"vllm/_C.abi3.so",
410401
"vllm/_moe_C.abi3.so",
@@ -413,6 +404,7 @@ def run(self) -> None:
413404
"vllm/vllm_flash_attn/_vllm_fa3_C.abi3.so",
414405
"vllm/cumem_allocator.abi3.so",
415406
]
407+
416408
file_members = list(
417409
filter(lambda x: x.filename in files_to_copy, wheel.filelist))
418410
compiled_regex = re.compile(
@@ -430,9 +422,26 @@ def run(self) -> None:
430422
if package_name not in package_data:
431423
package_data[package_name] = []
432424

433-
wheel.extract(file)
434-
if not file_name.endswith(".py"):
435-
package_data[package_name].append(file_name)
425+
output_base = (dist_dir
426+
if envs.VLLM_DOCKER_BUILD_CONTEXT else ".")
427+
target_path = os.path.join(output_base, file.filename)
428+
os.makedirs(os.path.dirname(target_path), exist_ok=True)
429+
with wheel.open(file.filename) as src, open(target_path,
430+
"wb") as dst:
431+
shutil.copyfileobj(src, dst)
432+
433+
package_data[package_name].append(file_name)
434+
435+
# Copy wheel into dist dir for Docker to consume (e.g., via --mount)
436+
if envs.VLLM_DOCKER_BUILD_CONTEXT:
437+
arch_tag = "cp38-abi3-manylinux1_x86_64"
438+
corrected_wheel_name = f"vllm-{version}-{arch_tag}.whl"
439+
final_wheel_path = os.path.join(dist_dir, corrected_wheel_name)
440+
441+
print(
442+
"Docker build context detected, copying precompiled wheel to "
443+
f"{final_wheel_path}")
444+
shutil.copy2(wheel_path, final_wheel_path)
436445

437446

438447
def _no_device() -> bool:

0 commit comments

Comments
 (0)