| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import argparse |
| 5 | import glob |
| 6 | import sys |
| 7 | |
| 8 | # Only strip targeted libraries when checking prefix |
| 9 | TORCH_LIB_PREFIXES = ( |
| 10 | # requirements/*.txt/in |
| 11 | "torch=", |
| 12 | "torchvision=", |
| 13 | "torchaudio=", |
| 14 | "torchcodec=", |
| 15 | # pyproject.toml |
| 16 | '"torch =', |
| 17 | '"torchvision =', |
| 18 | '"torchaudio =', |
| 19 | '"torchcodec =', |
| 20 | ) |
| 21 | |
| 22 | |
| 23 | def main(argv): |
| 24 | parser = argparse.ArgumentParser( |
| 25 | description="Strip torch lib requirements to use installed version." |
| 26 | ) |
| 27 | parser.add_argument( |
| 28 | "--prefix", |
| 29 | action="store_true", |
| 30 | help="Strip prefix matches only (default: False)", |
| 31 | ) |
| 32 | args = parser.parse_args(argv) |
| 33 | |
| 34 | for file in ( |
| 35 | *glob.glob("requirements/**/*.txt", recursive=True), |
| 36 | *glob.glob("requirements/**/*.in", recursive=True), |
| 37 | *glob.glob("pyproject.toml"), |
| 38 | ): |
| 39 | with open(file) as f: |
| 40 | lines = f.readlines() |
| 41 | if "torch" in "".join(lines).lower(): |
| 42 | with open(file, "w") as f: |
| 43 | for line in lines: |
| 44 | if ( |
| 45 | args.prefix |
| 46 | and not line.lower().strip().startswith(TORCH_LIB_PREFIXES) |
| 47 | or not args.prefix |
| 48 | and "torch" not in line.lower() |
| 49 | ): |
| 50 | f.write(line) |
| 51 | else: |
| 52 | print(f">>> removed from {file}:", line.strip()) |
| 53 | |
| 54 | |
| 55 | if __name__ == "__main__": |
| 56 | main(sys.argv[1:]) |