Skip to content

Conversation

@ZzEeKkAa
Copy link
Contributor

@ZzEeKkAa ZzEeKkAa commented Oct 2, 2024

I've picked up some useful changes from #1905 and pushed them here. Also organized python library build.

So basically it is a clean up with some features added and get it ready for the 2025 release

List of changes:

  • Add benchmark project artifacts to gitignore
  • Compile python library using dedicated cmake api: https://cmake.org/cmake/help/latest/module/FindPython3.html
  • Suppress old style warning of xetla library
  • Prevent cmake build on clean up commands (before that it was unconditional
  • If there is no ipex, library will be compiled in no ipex mode with user warning
  • More modular setup.py
  • Verbose output of cmake commands being run
  • CMakeLists.txt cleanup
  • Fix shadow import usage of cmake library

Closes #1905

@ZzEeKkAa ZzEeKkAa requested review from anmyachev and yudongsi October 2, 2024 19:08
@ZzEeKkAa ZzEeKkAa self-assigned this Oct 2, 2024
endif()

find_package(Python3 COMPONENTS Interpreter)
find_package(Python 3.9 REQUIRED
Copy link
Contributor

Choose a reason for hiding this comment

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

Why Python 3.9?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the minimum version of python that is requested. Do we support triton from 3.9?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, the syntax is a little bit confusing. Why we not specifying the upper end, for example 3.9...3.12?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, we can, but do we want to keep it updating every new python release. I guess I'll update it just for find_package(Python3 REQUIRED. If any issue will appear - we can add restrictions later.

@vlad-penkin vlad-penkin linked an issue Oct 3, 2024 that may be closed by this pull request
@ZzEeKkAa ZzEeKkAa force-pushed the feature/benchmark_improvements branch 3 times, most recently from 2ef5c79 to 8fe5f9f Compare October 3, 2024 17:19
@ZzEeKkAa ZzEeKkAa force-pushed the feature/benchmark_improvements branch 3 times, most recently from 245cea0 to 810be92 Compare October 10, 2024 14:13
@ZzEeKkAa ZzEeKkAa marked this pull request as ready for review October 10, 2024 14:51
@ZzEeKkAa ZzEeKkAa changed the title Feature/benchmark improvements Benchmark improvements Oct 10, 2024
@ZzEeKkAa
Copy link
Contributor Author

Pre-commit checks fails here, but not locally. I've added them to ignore list, but they are still appear in the CI. @pbchekin do you know what I'm missing?

@pbchekin
Copy link
Contributor

Pre-commit checks fails here, but not locally. I've added them to ignore list, but they are still appear in the CI. @pbchekin do you know what I'm missing?

What is the ignore list? The complain is legit, distutils is deprecated, https://peps.python.org/pep-0632/#migration-advice.

@ZzEeKkAa ZzEeKkAa force-pushed the feature/benchmark_improvements branch 2 times, most recently from 6b2f1c7 to e4c05a5 Compare October 10, 2024 16:20
@ZzEeKkAa
Copy link
Contributor Author

ZzEeKkAa commented Oct 10, 2024

Pre-commit checks fails here, but not locally. I've added them to ignore list, but they are still appear in the CI. @pbchekin do you know what I'm missing?

What is the ignore list?

I mean #noqa comments. It feels that different configurations are being picked in the CI and localy. I'm also getting bunch of errors locally, that does not appear here:

pylint for benchmarks....................................................Failed
- hook id: pylint
- exit code: 16

************* Module triton_kernels_benchmark.benchmark_driver
benchmarks/triton_kernels_benchmark/benchmark_driver.py:12:0: C0411: third party import "torch" should be placed before first party imports "triton.backends.compiler.GPUTarget", "triton.backends.driver.DriverBase", "triton.runtime.cache.get_cache_manager", "triton.runtime.build._build"  (wrong-import-order)
benchmarks/triton_kernels_benchmark/benchmark_driver.py:13:0: C0411: third party import "intel_extension_for_pytorch" should be placed before first party imports "triton.backends.compiler.GPUTarget", "triton.backends.driver.DriverBase", "triton.runtime.cache.get_cache_manager", "triton.runtime.build._build"  (wrong-import-order)
************* Module triton_kernels_benchmark.flash_attention_fwd_benchmark
benchmarks/triton_kernels_benchmark/flash_attention_fwd_benchmark.py:6:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
benchmarks/triton_kernels_benchmark/flash_attention_fwd_benchmark.py:7:0: C0411: third party import "xetla_kernel" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
************* Module triton_kernels_benchmark.fused_softmax
benchmarks/triton_kernels_benchmark/fused_softmax.py:15:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language", "triton.runtime.driver"  (wrong-import-order)
benchmarks/triton_kernels_benchmark/fused_softmax.py:16:0: C0411: third party import "xetla_kernel" should be placed before first party imports "triton", "triton.language", "triton.runtime.driver"  (wrong-import-order)
************* Module triton_kernels_benchmark.gemm_benchmark
benchmarks/triton_kernels_benchmark/gemm_benchmark.py:15:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
benchmarks/triton_kernels_benchmark/gemm_benchmark.py:16:0: C0411: third party import "xetla_kernel" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
************* Module triton_kernels_benchmark.gemm_postop_addmatrix_benchmark
benchmarks/triton_kernels_benchmark/gemm_postop_addmatrix_benchmark.py:13:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
************* Module triton_kernels_benchmark.gemm_postop_gelu_benchmark
benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py:15:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
************* Module triton_kernels_benchmark.gemm_preop_exp_benchmark
benchmarks/triton_kernels_benchmark/gemm_preop_exp_benchmark.py:14:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
************* Module triton_kernels_benchmark.gemm_splitk_benchmark
benchmarks/triton_kernels_benchmark/gemm_splitk_benchmark.py:5:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
************* Module triton_kernels_benchmark.gemm_streamk_benchmark
benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py:12:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)
************* Module triton_kernels_benchmark.prefix_sums
benchmarks/triton_kernels_benchmark/prefix_sums.py:5:0: C0411: third party import "triton_kernels_benchmark" should be placed before first party imports "triton", "triton.language"  (wrong-import-order)

------------------------------------------------------------------
Your code has been rated at 9.90/10 (previous run: 9.90/10, +0.00)

The complain is legit, distutils is deprecated, https://peps.python.org/pep-0632/#migration-advice.

Indeed. I've dig deeper in the setuptools source code - they vendor distutills.

@ZzEeKkAa ZzEeKkAa force-pushed the feature/benchmark_improvements branch from e4c05a5 to d11b65d Compare October 10, 2024 16:35
@ZzEeKkAa
Copy link
Contributor Author

Okay, using vendored distutil from setuptools should be done through import distutils. I bet linter is not aware that distutil was monkey patched (at least partially by setuptools) and should not be considered deprecated.

Importing setuptools._distutils results in a well know issue:
pypa/setuptools#3743

@ZzEeKkAa ZzEeKkAa force-pushed the feature/benchmark_improvements branch 4 times, most recently from 45cea57 to cc6a5e2 Compare October 10, 2024 17:42

find_package(Python3 COMPONENTS Interpreter)
find_package(Python3 REQUIRED
COMPONENTS Development.Module)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need interpreter for cmake (like calling python scripts), but we need to compile python library.
You can find out more here: https://cmake.org/cmake/help/latest/module/FindPython.html

XeTLA library from https://github.com/intel/xetla into
${XeTLALibrary_SOURCE_DIR}")
file(READ xetla-library.conf XeTLALibrary_TAG)
file(READ xetla_kernel/xetla-library.conf XeTLALibrary_TAG)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved library requirements to the top level cmake.

os.path.dirname(__file__)))


class build_ext(_build_ext):
Copy link
Contributor

Choose a reason for hiding this comment

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

The name does not match the class naming style. CamelCase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a class that overrides specific class of setuptools, so it kept that way to be consistent with the library.

@anmyachev
Copy link
Contributor

So basically it is a clean up with some features added and get it ready for the 2025 release

@ZzEeKkAa could you highlight the new features at the top of this pull request? This will allow us to use them without reading the code :)


from setuptools import setup
# TODO: update once there is replacement for clean:
# https://github.com/pypa/setuptools/discussions/2838
Copy link
Contributor

Choose a reason for hiding this comment

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

I read the discussion and it seems like it will never happen.

Should we just switch to pip install command instead of python setup.py install here:

?

The replacement is described here: https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html#summary

Moreover, the build env setup is usually up to the build front-end (pip or pypa/build, for example) and they often just create "throw-away" virtualenvs under /tmp that you wouldn't need to clean up

Given that pip creates a temporary folder and there is no need to clean it up, we can avoid using the deprecated API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm personally using setup.py as main tool. It also makes challenging to clean up when you build without isolation in pip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In other words, until they come up with a better approach on cleaning, I would prefer to keep this deprecated API.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok for now, but most likely from everything I read, they can't provide such an API anymore, but delegate this task to other tools

Copy link
Contributor

@anmyachev anmyachev left a comment

Choose a reason for hiding this comment

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

LGTM! @ZzEeKkAa please fix conflicts.

@pbchekin ?

@pbchekin
Copy link
Contributor

LGTM! @ZzEeKkAa please fix conflicts.

@pbchekin ?

LGTM!

@ZzEeKkAa ZzEeKkAa force-pushed the feature/benchmark_improvements branch from f1b25a9 to 368ef37 Compare October 16, 2024 18:53
@ZzEeKkAa ZzEeKkAa merged commit f4fdd8f into intel:main Oct 16, 2024
5 checks passed
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.

[Benchmarks] XeTLA kernel python library build

3 participants