-
Notifications
You must be signed in to change notification settings - Fork 839
Support PaddlePaddle with compatible API #1642
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
Changes from all commits
975b86a
9bb59d4
ee20442
40c40f1
930cd62
5d7c443
22c4a5e
b7a8db4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| ) | ||
|
|
||
| from . import env as jit_env | ||
| from ..utils import use_paddle_compatible_api | ||
| from ..compilation_context import CompilationContext | ||
|
|
||
|
|
||
|
|
@@ -75,13 +76,26 @@ def generate_ninja_build_for_op( | |
| ) -> str: | ||
| system_includes = [ | ||
| sysconfig.get_path("include"), | ||
| "$torch_home/include", | ||
| "$torch_home/include/torch/csrc/api/include", | ||
| "$cuda_home/include", | ||
| "$cuda_home/include/cccl", | ||
| jit_env.FLASHINFER_INCLUDE_DIR.resolve(), | ||
| jit_env.FLASHINFER_CSRC_DIR.resolve(), | ||
| ] | ||
| if use_paddle_compatible_api(): | ||
| system_includes.extend( | ||
| [ | ||
| "$torch_home/include", | ||
| "$torch_home/include/torch/csrc/api/include", | ||
| ] | ||
| ) | ||
| else: | ||
| system_includes.extend( | ||
| [ | ||
| "$torch_home/include", | ||
| "$torch_home/include/paddle/phi/api/include/compat", | ||
| "$torch_home/include/paddle/phi/api/include/compat/torch/csrc/api/include", | ||
| ] | ||
| ) | ||
| system_includes += [p.resolve() for p in jit_env.CUTLASS_INCLUDE_DIRS] | ||
| system_includes.append(jit_env.SPDLOG_INCLUDE_DIR.resolve()) | ||
|
|
||
|
|
@@ -144,15 +158,35 @@ def generate_ninja_build_for_op( | |
|
|
||
| ldflags = [ | ||
| "-shared", | ||
| "-L$torch_home/lib", | ||
| "-L$cuda_home/lib64", | ||
| "-lc10", | ||
| "-lc10_cuda", | ||
| "-ltorch_cpu", | ||
| "-ltorch_cuda", | ||
| "-ltorch", | ||
| "-lcudart", | ||
| ] | ||
|
Comment on lines
159
to
162
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ldflags = []
if use_paddle_compatible_api():
ldflags.extend(
[
"-shared",
"-L$torch_home/lib",
"-L$cuda_home/lib64",
"-lc10",
"-lc10_cuda",
"-ltorch_cpu",
"-ltorch_cuda",
"-ltorch",
"-lcudart",
]
)
else:
ldflags.extend(
[
"-shared",
"-L$torch_home/libs",
"-L$torch_home/base",
"-L$cuda_home/lib64",
"-lpaddle",
"-lphi",
"-lphi_core",
"-lphi_gpu",
"-lcommon",
"-lcudart",
]
) |
||
| if use_paddle_compatible_api(): | ||
| ldflags.extend( | ||
| [ | ||
| "-L$torch_home/lib", | ||
| "-L$cuda_home/lib64", | ||
| "-lc10", | ||
| "-lc10_cuda", | ||
| "-ltorch_cpu", | ||
| "-ltorch_cuda", | ||
| "-ltorch", | ||
| ] | ||
| ) | ||
| else: | ||
| ldflags.extend( | ||
| [ | ||
| "-shared", | ||
| "-L$torch_home/libs", | ||
| "-L$torch_home/base", | ||
| "-L$cuda_home/lib64", | ||
| "-lpaddle", | ||
| "-lphi", | ||
| "-lphi_core", | ||
| "-lphi_gpu", | ||
| "-lcommon", | ||
| "-lcudart", | ||
| ] | ||
| ) | ||
|
|
||
| env_extra_ldflags = os.environ.get("FLASHINFER_EXTRA_LDFLAGS") | ||
| if env_extra_ldflags: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,10 @@ | |||||||||||||||||||
| enable_aot = aot_ops_package_dir.is_dir() and any(aot_ops_package_dir.iterdir()) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def use_paddle_compatible_api() -> bool: | ||||||||||||||||||||
| return os.environ.get("PADDLE_COMPATIBLE_API", "0").lower() in ["1", "on", "true"] | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def write_if_different(path: Path, content: str) -> None: | ||||||||||||||||||||
| if path.exists() and path.read_text() == content: | ||||||||||||||||||||
| return | ||||||||||||||||||||
|
|
@@ -55,7 +59,6 @@ def generate_build_meta(aot_build_meta: dict) -> None: | |||||||||||||||||||
| cmdclass: Mapping[str, type[setuptools.Command]] = {} | ||||||||||||||||||||
| install_requires = [ | ||||||||||||||||||||
| "numpy", | ||||||||||||||||||||
| "torch", | ||||||||||||||||||||
| "ninja", | ||||||||||||||||||||
| "requests", | ||||||||||||||||||||
| "pynvml", | ||||||||||||||||||||
|
|
@@ -66,9 +69,17 @@ def generate_build_meta(aot_build_meta: dict) -> None: | |||||||||||||||||||
| "packaging>=24.2", | ||||||||||||||||||||
| "nvidia-cudnn-frontend>=1.13.0", | ||||||||||||||||||||
| ] | ||||||||||||||||||||
| if not use_paddle_compatible_api(): | ||||||||||||||||||||
| install_requires.append("torch") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| generate_build_meta({}) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if enable_aot: | ||||||||||||||||||||
| if use_paddle_compatible_api(): | ||||||||||||||||||||
| import paddle | ||||||||||||||||||||
|
Comment on lines
77
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a check to ensure
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| paddle.compat.enable_torch_proxy() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import torch | ||||||||||||||||||||
| import torch.utils.cpp_extension as torch_cpp_ext | ||||||||||||||||||||
| from packaging.version import Version | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
system_includes.extendmethod is called within theifblock, but thesystem_includeslist already contains some default paths. This could lead to duplicate include paths ifuse_paddle_compatible_api()returnsTrue, potentially causing issues during compilation. Consider adding the default paths within theelseblock to avoid duplication.Alternatively, you can initialize
system_includesas an empty list and populate it entirely within theifandelseblocks to ensure no overlap.