Skip to content

feat: Restore convenience FLASHINFER_ENABLE_AOT option #1235

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions custom_backend.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
from pathlib import Path

Expand Down Expand Up @@ -109,5 +110,10 @@ def build_sdist(sdist_directory, config_settings=None):


def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
if os.environ.get("FLASHINFER_ENABLE_AOT", "0") == "1":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider accepting more truthy values for the FLASHINFER_ENABLE_AOT environment variable to improve user experience. The current implementation only accepts "1", which might be less intuitive for users accustomed to boolean flags with values like true or yes.

Suggested change
if os.environ.get("FLASHINFER_ENABLE_AOT", "0") == "1":
if os.environ.get("FLASHINFER_ENABLE_AOT", "0").lower() in ("1", "true", "yes", "on", "t", "y"):

from flashinfer.aot import main as aot_main

aot_main([])

_prepare_for_wheel()
return orig.build_wheel(wheel_directory, config_settings, metadata_directory)
7 changes: 4 additions & 3 deletions flashinfer/aot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import os
import shutil
import sys
from itertools import product
from pathlib import Path
from typing import List, Tuple
Expand Down Expand Up @@ -375,7 +376,7 @@ def parse_head_dim(head_dim: str) -> Tuple[int, int]:
return qo, kv


def main():
def main(args: list[str]):
parser = argparse.ArgumentParser(
description="Ahead-of-Time (AOT) build all modules"
)
Expand Down Expand Up @@ -426,7 +427,7 @@ def main():
type=parse_bool,
help="Add kernels for Gemma Model (head_dim=256, use_sliding_window, use_logits_soft_cap)",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Pass args to parse_args only when args is not None to maintain the original CLI behavior when the function is called directly from the command line.

    args = parser.parse_args() if args is None else parser.parse_args(args)

args = parser.parse_args()
args = parser.parse_args(args)

# Default values
project_root = Path(__file__).resolve().parents[1]
Expand Down Expand Up @@ -561,4 +562,4 @@ def main():


if __name__ == "__main__":
main()
main(sys.argv[1:])