From 0a29b6d2d093d827b0cb7180773bdbf30bf147e4 Mon Sep 17 00:00:00 2001 From: ur4t <46435411+ur4t@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:45:31 +0800 Subject: [PATCH] Revert "packaging: Use setuptools-scm (#666)" --- .gitignore | 1 - docs/conf.py | 8 +++----- docs/requirements.txt | 1 - flashinfer/__init__.py | 2 +- pyproject.toml | 7 ++----- scripts/run-ci-build-wheel.sh | 4 ++-- setup.py | 37 +++++++++++++++++++++++------------ version.txt | 1 + 8 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 version.txt diff --git a/.gitignore b/.gitignore index 3d48a621..f7c871fe 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ compile_commands.json csrc/generated/ docs/generated/ flashinfer/_build_meta.py -flashinfer/_version.py flashinfer/data/ flashinfer/jit/aot_config.py src/generated/ diff --git a/docs/conf.py b/docs/conf.py index 3fce1869..0310c907 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,8 +1,6 @@ import os import sys from pathlib import Path -from setuptools_scm import get_version -from packaging.version import Version # import tlcpack_sphinx_addon # Configuration file for the Sphinx documentation builder. @@ -22,9 +20,9 @@ author = "FlashInfer Contributors" copyright = f"2023-2024, {author}" -package_version = Version(get_version(root=root, version_scheme="only-version")) -version = str(package_version) -release = package_version.base_version +package_version = (root / "version.txt").read_text().strip() +version = package_version +release = package_version # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/docs/requirements.txt b/docs/requirements.txt index 479aea94..9811ed02 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,4 +3,3 @@ sphinx == 8.1.3 sphinx-reredirects == 0.1.5 sphinx-tabs == 3.4.5 sphinx-toolbox == 3.8.1 -setuptools-scm == 8.1.0 diff --git a/flashinfer/__init__.py b/flashinfer/__init__.py index 7963deab..339b3ecd 100644 --- a/flashinfer/__init__.py +++ b/flashinfer/__init__.py @@ -88,4 +88,4 @@ from .sampling import top_p_sampling_from_probs as top_p_sampling_from_probs from .sparse import BlockSparseAttentionWrapper as BlockSparseAttentionWrapper -from ._version import __version__ as __version__ +from ._build_meta import __version__ as __version__ diff --git a/pyproject.toml b/pyproject.toml index 86921787..d8ca69aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ urls = { Homepage = "https://github.com/flashinfer-ai/flashinfer" } dynamic = ["dependencies", "version"] [build-system] -requires = ["setuptools", "setuptools-scm"] +requires = ["setuptools"] build-backend = "custom_backend" backend-path = ["."] @@ -48,16 +48,13 @@ include-package-data = false "flashinfer.data" = [ "csrc/**", "include/**", + "version.txt" ] "flashinfer.data.cutlass" = [ "include/**", "tools/util/include/**" ] -[tool.setuptools_scm] -version_file = "flashinfer/_version.py" -version_scheme = "only-version" - [tool.mypy] ignore_missing_imports = false show_column_numbers = true diff --git a/scripts/run-ci-build-wheel.sh b/scripts/run-ci-build-wheel.sh index 577de984..c4e20fbc 100644 --- a/scripts/run-ci-build-wheel.sh +++ b/scripts/run-ci-build-wheel.sh @@ -32,13 +32,13 @@ echo "::endgroup::" echo "::group::Install build system" pip install ninja numpy -pip install --upgrade build setuptools setuptools-scm wheel +pip install --upgrade setuptools wheel build echo "::endgroup::" echo "::group::Build wheel for FlashInfer" cd "$PROJECT_ROOT" -FLASHINFER_ENABLE_AOT=1 python -m build --no-isolation --wheel +FLASHINFER_ENABLE_AOT=1 FLASHINFER_LOCAL_VERSION="cu${CUDA_MAJOR}${CUDA_MINOR}torch${FLASHINFER_CI_TORCH_VERSION}" python -m build --no-isolation --wheel python -m build --no-isolation --sdist ls -la dist/ echo "::endgroup::" diff --git a/setup.py b/setup.py index 65a2b9fe..7cb292f2 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,6 @@ root = Path(__file__).parent.resolve() gen_dir = root / "csrc" / "generated" -build_meta = root / "flashinfer" / "_build_meta.py" head_dims = os.environ.get("FLASHINFER_HEAD_DIMS", "64,128,256").split(",") pos_encoding_modes = os.environ.get("FLASHINFER_POS_ENCODING_MODES", "0").split(",") @@ -47,6 +46,24 @@ enable_fp8 = os.environ.get("FLASHINFER_ENABLE_FP8", "1") == "1" +def get_version(): + build_version = os.environ.get("FLASHINFER_BUILD_VERSION") + if build_version is not None: + return build_version + package_version = (root / "version.txt").read_text().strip() + local_version = os.environ.get("FLASHINFER_LOCAL_VERSION") + if local_version is None: + return package_version + return f"{package_version}+{local_version}" + + +def generate_build_meta(aot_build_meta: dict) -> None: + build_meta_str = f"__version__ = {get_version()!r}\n" + if len(aot_build_meta) != 0: + build_meta_str += f"build_meta = {aot_build_meta!r}\n" + (root / "flashinfer" / "_build_meta.py").write_text(build_meta_str) + + def generate_cuda() -> None: try: # no aot_build_utils in sdist sys.path.append(str(root)) @@ -81,16 +98,14 @@ def generate_cuda() -> None: ext_modules = [] cmdclass = {} -use_scm_version = {} install_requires = ["torch", "ninja"] -build_meta.write_text("\n") +generate_build_meta({}) generate_cuda() if enable_aot: import torch import torch.utils.cpp_extension as torch_cpp_ext from packaging.version import Version - from setuptools_scm.version import get_local_node_and_date as default def get_cuda_version() -> Version: if torch_cpp_ext.CUDA_HOME is None: @@ -116,9 +131,9 @@ def __init__(self, *args, **kwargs) -> None: raise RuntimeError("FlashInfer requires sm75+") cuda_version = get_cuda_version() - torch_full_version = Version(torch.__version__) - torch_version = f"{torch_full_version.major}.{torch_full_version.minor}" - local_version = f"cu{cuda_version.major}{cuda_version.minor}torch{torch_version}" + torch_version = Version(torch.__version__).base_version + cmdclass["build_ext"] = NinjaBuildExtension + install_requires = [f"torch == {torch_version}"] aot_build_meta = {} aot_build_meta["cuda_major"] = cuda_version.major @@ -126,11 +141,7 @@ def __init__(self, *args, **kwargs) -> None: aot_build_meta["torch"] = torch_version aot_build_meta["python"] = platform.python_version() aot_build_meta["TORCH_CUDA_ARCH_LIST"] = os.environ.get("TORCH_CUDA_ARCH_LIST") - build_meta.write_text(f"build_meta = {aot_build_meta!r}\n") - - cmdclass["build_ext"] = NinjaBuildExtension - use_scm_version["local_scheme"] = lambda x: f"{default(x)}.{local_version}" - install_requires = [f"torch == {torch_version}"] + generate_build_meta(aot_build_meta) if enable_bf16: torch_cpp_ext.COMMON_NVCC_FLAGS.append("-DFLASHINFER_ENABLE_BF16") @@ -219,9 +230,9 @@ def __init__(self, *args, **kwargs) -> None: ] setuptools.setup( + version=get_version(), ext_modules=ext_modules, cmdclass=cmdclass, options={"bdist_wheel": {"py_limited_api": "cp38"}}, install_requires=install_requires, - use_scm_version=use_scm_version, ) diff --git a/version.txt b/version.txt new file mode 100644 index 00000000..c946ee61 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.1.6