2025-02-02 14:58:18 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2025-06-03 11:20:17 -07:00
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
2025-02-02 14:58:18 -05:00
|
|
|
|
2026-01-23 08:22:56 -10:00
|
|
|
import argparse
|
2025-09-15 17:43:40 +01:00
|
|
|
import glob
|
2026-01-23 08:22:56 -10:00
|
|
|
import sys
|
2025-09-15 17:43:40 +01:00
|
|
|
|
2026-01-23 08:22:56 -10:00
|
|
|
# Only strip targeted libraries when checking prefix
|
|
|
|
|
TORCH_LIB_PREFIXES = (
|
|
|
|
|
# requirements/*.txt/in
|
|
|
|
|
"torch=",
|
|
|
|
|
"torchvision=",
|
|
|
|
|
"torchaudio=",
|
|
|
|
|
# pyproject.toml
|
|
|
|
|
'"torch =',
|
|
|
|
|
'"torchvision =',
|
|
|
|
|
'"torchaudio =',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
description="Strip torch lib requirements to use installed version."
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--prefix",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Strip prefix matches only (default: False)",
|
|
|
|
|
)
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
|
|
|
|
|
|
for file in (
|
|
|
|
|
*glob.glob("requirements/*.txt"),
|
|
|
|
|
*glob.glob("requirements/*.in"),
|
|
|
|
|
"pyproject.toml",
|
|
|
|
|
):
|
|
|
|
|
with open(file) as f:
|
|
|
|
|
lines = f.readlines()
|
|
|
|
|
if "torch" in "".join(lines).lower():
|
|
|
|
|
with open(file, "w") as f:
|
|
|
|
|
for line in lines:
|
|
|
|
|
if (
|
|
|
|
|
args.prefix
|
|
|
|
|
and not line.lower().strip().startswith(TORCH_LIB_PREFIXES)
|
|
|
|
|
or not args.prefix
|
|
|
|
|
and "torch" not in line.lower()
|
|
|
|
|
):
|
|
|
|
|
f.write(line)
|
|
|
|
|
else:
|
|
|
|
|
print(f">>> removed from {file}:", line.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main(sys.argv[1:])
|