Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert setuptools-scm #671

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
docker run --rm -t \
-v "$CI_RUNNER_CACHE_DIR":/ci-cache \
-v "$GITHUB_WORKSPACE":/app \
-e FLASHINFER_CI_CACHE=/ci-cache \
-e FLASHINFER_CI_CUDA_VERSION=${{ matrix.cuda }} \
-e FLASHINFER_CI_TORCH_VERSION=${{ matrix.torch }} \
-e TORCH_CUDA_ARCH_LIST="$TORCH_CUDA_ARCH_LIST" \
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
8 changes: 3 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
furo == 2024.8.6
setuptools == 75.6.0
setuptools-scm == 8.1.0
sphinx == 8.1.3
sphinx-reredirects == 0.1.5
sphinx-tabs == 3.4.5
Expand Down
2 changes: 1 addition & 1 deletion flashinfer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["."]

Expand All @@ -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
Expand Down
15 changes: 10 additions & 5 deletions scripts/run-ci-build-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ assert_env() {
fi
}

assert_env FLASHINFER_CI_TORCH_VERSION
assert_env FLASHINFER_CI_CACHE
assert_env FLASHINFER_CI_CUDA_VERSION
assert_env FLASHINFER_CI_TORCH_VERSION
assert_env TORCH_CUDA_ARCH_LIST
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
export CONDA_pkgs_dirs="${FLASHINFER_CI_CACHE:=/ci-cache}/conda-pkgs"
export XDG_CACHE_HOME="${FLASHINFER_CI_CACHE:=/ci-cache}/xdg-cache"
export CONDA_pkgs_dirs="${FLASHINFER_CI_CACHE}/conda-pkgs"
export XDG_CACHE_HOME="${FLASHINFER_CI_CACHE}/xdg-cache"
mkdir -p "$CONDA_pkgs_dirs" "$XDG_CACHE_HOME"
export HOME=/tmp/home
mkdir -p $HOME
Expand All @@ -25,20 +26,24 @@ CUDA_MINOR="${FLASHINFER_CI_CUDA_VERSION#*.}"
TORCH_MAJOR="${FLASHINFER_CI_TORCH_VERSION%.*}"
TORCH_MINOR="${FLASHINFER_CI_TORCH_VERSION#*.}"

FLASHINFER_LOCAL_VERSION="cu${CUDA_MAJOR}${CUDA_MINOR}torch${FLASHINFER_CI_TORCH_VERSION}"
if [ -n "${FLASHINFER_GIT_SHA}" ]; then
FLASHINFER_LOCAL_VERSION="${FLASHINFER_GIT_SHA}.${FLASHINFER_LOCAL_VERSION}"
fi

echo "::group::Install PyTorch"
pip install torch==$FLASHINFER_CI_TORCH_VERSION --index-url "https://download.pytorch.org/whl/cu${CUDA_MAJOR}${CUDA_MINOR}"
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=$FLASHINFER_LOCAL_VERSION python -m build --no-isolation --wheel
python -m build --no-isolation --sdist
ls -la dist/
echo "::endgroup::"
31 changes: 20 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
Expand All @@ -47,6 +46,21 @@
enable_fp8 = os.environ.get("FLASHINFER_ENABLE_FP8", "1") == "1"


def get_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))
Expand Down Expand Up @@ -81,16 +95,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:
Expand Down Expand Up @@ -118,19 +130,16 @@ def __init__(self, *args, **kwargs) -> None:
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}"
cmdclass["build_ext"] = NinjaBuildExtension
install_requires = [f"torch == {torch_version}"]

aot_build_meta = {}
aot_build_meta["cuda_major"] = cuda_version.major
aot_build_meta["cuda_minor"] = cuda_version.minor
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")
Expand Down Expand Up @@ -219,9 +228,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,
)
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.6