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

Clean up CUDA kernels #23455

Merged
merged 1 commit into from
May 18, 2023
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
10 changes: 4 additions & 6 deletions src/transformers/models/deformable_detr/load_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
""" Loading of Deformable DETR's CUDA kernels"""

import os
from pathlib import Path


def load_cuda_kernels():
from torch.utils.cpp_extension import load

root = os.path.join(os.path.dirname(os.path.realpath(__file__)), "custom_kernel")
root = Path(__file__).resolve().parent.parent.parent / "kernels" / "deformable_detr"
src_files = [
os.path.join(root, filename)
root / filename
for filename in [
"vision.cpp",
os.path.join("cpu", "ms_deform_attn_cpu.cpp"),
Expand All @@ -33,10 +33,8 @@ def load_cuda_kernels():
load(
"MultiScaleDeformableAttention",
src_files,
# verbose=True,
with_cuda=True,
extra_include_paths=[root],
# build_directory=os.path.dirname(os.path.realpath(__file__)),
extra_include_paths=[str(root)],
extra_cflags=["-DWITH_CUDA=1"],
extra_cuda_cflags=[
"-DCUDA_HAS_FP16=1",
Expand Down
6 changes: 3 additions & 3 deletions src/transformers/models/yoso/modeling_yoso.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


import math
import os
from pathlib import Path
from typing import Optional, Tuple, Union

import torch
Expand Down Expand Up @@ -56,8 +56,8 @@ def load_cuda_kernels():
from torch.utils.cpp_extension import load

def append_root(files):
src_folder = os.path.dirname(os.path.realpath(__file__))
return [os.path.join(src_folder, file) for file in files]
src_folder = Path(__file__).resolve().parent.parent.parent / "kernels" / "yoso"
return [src_folder / file for file in files]

src_files = append_root(
["fast_lsh_cumulation_torch.cpp", "fast_lsh_cumulation.cu", "fast_lsh_cumulation_cuda.cu"]
Expand Down
4 changes: 2 additions & 2 deletions utils/check_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
FILES_TO_FIND = [
"kernels/rwkv/wkv_cuda.cu",
"kernels/rwkv/wkv_op.cpp",
"models/deformable_detr/custom_kernel/ms_deform_attn.h",
"models/deformable_detr/custom_kernel/cuda/ms_deform_im2col_cuda.cuh",
"kernels/deformable_detr/ms_deform_attn.h",
"kernels/deformable_detr/cuda/ms_deform_im2col_cuda.cuh",
"models/graphormer/algos_graphormer.pyx",
]

Expand Down