From 7ffa43b16e4625322c9f157db12c9358f2f54cdf Mon Sep 17 00:00:00 2001 From: Ting PAN Date: Wed, 26 Jun 2024 23:25:26 +0800 Subject: [PATCH] FIX Avoid early import of torch extension by BOFT (#1879) --- src/peft/tuners/boft/layer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/peft/tuners/boft/layer.py b/src/peft/tuners/boft/layer.py index 1002398861..97a1baaa58 100644 --- a/src/peft/tuners/boft/layer.py +++ b/src/peft/tuners/boft/layer.py @@ -27,7 +27,6 @@ import torch.nn as nn import torch.nn.functional as F from torch.autograd import Function -from torch.utils.cpp_extension import load from peft.tuners.tuners_utils import BaseTunerLayer, check_adapters_to_merge @@ -78,6 +77,9 @@ def get_fbd_cuda(): if _FBD_CUDA is not None: return _FBD_CUDA + # This import initializes cuda context and should thus be local, see issue 1877 + from torch.utils.cpp_extension import load + curr_dir = os.path.dirname(__file__) # need ninja to build the extension try: