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

Modernize packaging #643

Merged
merged 13 commits into from
Dec 9, 2024
Merged

Modernize packaging #643

merged 13 commits into from
Dec 9, 2024

Conversation

ur4t
Copy link
Contributor

@ur4t ur4t commented Nov 30, 2024

According to Python Packaging User Guide, python setup.py and the use of setup.py as a command line tool are deprecated.

This PR unifies setup.py and aot_setup.py and moves static fields to pyproject.toml.

@ur4t
Copy link
Contributor Author

ur4t commented Nov 30, 2024

Currently, setting the environment variable "FLASHINFER_ENABLE_AOT" to "1" will enable AOT. Or do we prefer command line arguments like apex?

Copy link
Collaborator

@yzh119 yzh119 left a comment

Choose a reason for hiding this comment

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

Hi @ur4t we definitely welcome this change!

do we prefer command line arguments like apex?

Can you further clarify?

version.txt Outdated Show resolved Hide resolved
@ur4t
Copy link
Contributor Author

ur4t commented Dec 1, 2024

Hi @ur4t we definitely welcome this change!

do we prefer command line arguments like apex?

Can you further clarify?

To provides flags to setup.py via sys.argv like this line.

In the build style, they are provided via python -m build --config-setting KEY[=VALUE].

@yzh119
Copy link
Collaborator

yzh119 commented Dec 1, 2024

I don't have preference among the two, using environment variable looks good to me.

cc @abcdabcd987 @zhyncs @nandor do you have any suggestions?

@zhyncs
Copy link
Member

zhyncs commented Dec 1, 2024

using environment variable looks good to me.

me too

@ur4t ur4t force-pushed the modernize-packaging branch from c8d22f0 to a331370 Compare December 1, 2024 09:07
@yzh119
Copy link
Collaborator

yzh119 commented Dec 1, 2024

Hi @ur4t , thanks for the update.
I keep encountering the following error compiling this branch, do you have any idea why? (I can confirm torch is already installed in this environment).

* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - setuptools
* Getting build dependencies for wheel...
Traceback (most recent call last):
  File "/home/***/miniforge3/envs/flashinfer16/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "/home/***/miniforge3/envs/flashinfer16/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zhye/miniforge3/envs/flashinfer16/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel
    return hook(config_settings)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-ymt3t60s/lib/python3.11/site-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=[])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-ymt3t60s/lib/python3.11/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-ymt3t60s/lib/python3.11/site-packages/setuptools/build_meta.py", line 320, in run_setup
    exec(code, locals())
  File "<string>", line 28, in <module>
ModuleNotFoundError: No module named 'torch'

@ur4t
Copy link
Contributor Author

ur4t commented Dec 1, 2024

  • Creating isolated environment: venv+pip...

If --no-isolation(short: -n) is not present, build will try to build the package in isolated environments and install packages listed in build-system.requires to the isolated environments from Pypi. Installing torch takes quite a long time if pip has not cached corresponding wheel packages. Usually we have torch and build already installed to build Torch extensions, so add --no-isolation should solve this issue.

@yzh119
Copy link
Collaborator

yzh119 commented Dec 1, 2024

I tried --no-isolation and it works well, thank you for the explaination.

Installing torch takes quite a long time if pip has not cached corresponding wheel packages

Seems I encountered the error before the build process attempt to install torch, I can reproduce this on two of my working environments, is it expected behavior?

@ur4t
Copy link
Contributor Author

ur4t commented Dec 1, 2024

Seems I encountered the error before the build process attempt to install torch, I can reproduce this on two of my working environments, is it expected behavior?

I not quite sure whether we should make torch a build dependency, because it it not necessary when targeting sdist and wheel in JIT mode. It is possible to sepcify build dependencies dynamically with some custom build backends.

It is much easier to specify torch (specific versions in AOT mode, whatever version in JIT mode) as a runtime dependency dynamically, just via the setup.py.

Besides, when creating sdist, I found two issues:

  1. README.md is not accessible as the readme field of [project], because it is "out-of-tree" (beyond the root directory of the python project).
  2. "Out-of-tree" files (include and 3rdparty/cutlass) shipped as package-data will appear in the root directory of the python project, which is quite annoying.

Could we emplace setup.py and pyproject in the real root instead of python to avoid those issues?

@yzh119
Copy link
Collaborator

yzh119 commented Dec 1, 2024

Could we emplace setup.py and pyproject in the real root instead of python to avoid those issues?

I have no problem with the move considering python is the most important frontend at the moment.

@ur4t
Copy link
Contributor Author

ur4t commented Dec 2, 2024

With the write_if_different I believe the unified generate.py can replace generation patterns in CMakeLists.txt. Trade off between a bit longer generation time when only part of generators change and better maintenance experience hah.

And there is a common file structure used by other projects (apex for example), within FlashInfer it will be like:

flashinfer
├── 3rdparty
├── benchmarks
├── cmake
├── docs
├── include
│   └── flashinfer
├── _aot_build_utils
├── csrc
├── flashinfer
├── scripts
├── src
└── tests

Will we switch the style or keep the current structure?

@yzh119
Copy link
Collaborator

yzh119 commented Dec 4, 2024

Will we switch the style or keep the current structure?

I have no problem switching the style.

Trade off between a bit longer generation time when only part of generators change and better maintenance experience hah.

Longer generation time is not a big issue at the moment and I believe better maintainance experience is much more important :)

@ur4t ur4t force-pushed the modernize-packaging branch from 10473ca to cced062 Compare December 4, 2024 17:00
@ur4t
Copy link
Contributor Author

ur4t commented Dec 4, 2024

@yzh119 I think this PR is ready to be merged. We have all 5 installations: Python AOT/JIT sdist/wheel and CMake and they build well. Please try locally and run tests in case.

There is no suitable method to distribute aot_config.py for all modes with both sdist and wheel. Currently sdist will contains all generated files, with which users of sdist can also install in AOT mode. Mode detection is performed via trying to import _kernels and _kernels_sm90, which might be finer grained in future. Kernel source classification could be finer grained as well when necessary.

@ur4t ur4t force-pushed the modernize-packaging branch 3 times, most recently from 119feac to 8cbe2b3 Compare December 5, 2024 15:39
@yzh119
Copy link
Collaborator

yzh119 commented Dec 8, 2024

@ur4t hi, it seems the JIT mode was broken because these paths (used for JIT compilation) no longer exists:

FLASHINFER_INCLUDE_DIR = _package_root / "data" / "include"
FLASHINFER_CSRC_DIR = _package_root / "data" / "csrc"
CUTLASS_INCLUDE_DIRS = [
_package_root / "data" / "cutlass" / "include",
_package_root / "data" / "cutlass" / "tools" / "util" / "include",
]

@ur4t ur4t force-pushed the modernize-packaging branch from 8cbe2b3 to 640f5af Compare December 9, 2024 03:26
@ur4t
Copy link
Contributor Author

ur4t commented Dec 9, 2024

JIT mode was broken because these paths (used for JIT compilation) no longer exists:

@yzh119 This is an editable mode specific issue. Fixed via symlinks.

Copy link
Collaborator

@yzh119 yzh119 left a comment

Choose a reason for hiding this comment

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

Thanks a lot @ur4t !
This pull request is awesome, huge props to you

@yzh119 yzh119 merged commit 8e3d258 into flashinfer-ai:main Dec 9, 2024
@ur4t ur4t deleted the modernize-packaging branch December 10, 2024 02:16
@ur4t
Copy link
Contributor Author

ur4t commented Dec 10, 2024

@yzh119 Cheers for ours improvement!

Our doc builder failed but I can not reproduce locally. Any idea to fix it?

@yzh119
Copy link
Collaborator

yzh119 commented Dec 10, 2024

Probably related to #573.

@ur4t
Copy link
Contributor Author

ur4t commented Dec 10, 2024

Probably related to #573.

Got it. Just leave it be. If doc builders continue failing we would try to fix then.

echo "::endgroup::"


echo "::group::Build wheel for FlashInfer"
cd "$PROJECT_ROOT/python"
Copy link
Member

Choose a reason for hiding this comment

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

Why remove the +cu info?

Copy link
Collaborator

Choose a reason for hiding this comment

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

local_version is concatenated to package version here:

return f"{package_version}+{local_version}"

I can produce correct wheel name locally but it doesn't work for nightly wheels.

Copy link
Member

Choose a reason for hiding this comment

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

I see

@zhyncs zhyncs mentioned this pull request Dec 14, 2024
@yzh119 yzh119 mentioned this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants