column_parallel_linear.py 19.6 KB
Newer Older
Jee Jee Li's avatar
Jee Jee Li committed
1
2
3
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project

4
from typing import Optional, Union
Jee Jee Li's avatar
Jee Jee Li committed
5
6
7
8
9

import torch
import torch.nn as nn
from transformers import PretrainedConfig

10
from vllm.config.lora import LoRAConfig
11
from vllm.distributed import tensor_model_parallel_all_gather
Jee Jee Li's avatar
Jee Jee Li committed
12
from vllm.distributed.utils import divide
13
14
15
16
17
from vllm.model_executor.layers.linear import (
    ColumnParallelLinear,
    MergedColumnParallelLinear,
    QKVParallelLinear,
)
Jee Jee Li's avatar
Jee Jee Li committed
18
19
20
21
22
23
24
from vllm.platforms import current_platform

from .base_linear import BaseLinearLayerWithLoRA
from .utils import _fully_sharded_can_replace, _not_fully_sharded_can_replace


def _mcp_apply(x, bias, layer: "ColumnParallelLinearWithLoRA"):
25
26
    """
    For `ColumnParallelLinearWithLoRA` or classes that inherit from
Jee Jee Li's avatar
Jee Jee Li committed
27
28
    `ColumnParallelLinearWithLoRA`, they share the same `apply` logic.
    """
29
30
31
32
33
34
    assert (
        layer.n_slices
        == len(layer.lora_a_stacked)
        == len(layer.lora_b_stacked)
        == len(layer.output_slices)
    )
Jee Jee Li's avatar
Jee Jee Li committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

    output = layer.base_layer.quant_method.apply(layer.base_layer, x, bias)

    x = x.view(-1, x.shape[-1])
    output, out_orig_shape = output.view(-1, output.shape[-1]), output.shape

    # Since communication is needed, the buffer is directly initialized as a
    # tensor rather than a tuple of tensor.
    buffers = torch.zeros(
        (layer.n_slices, x.shape[0], layer.lora_a_stacked[0].shape[2]),
        dtype=torch.float32,
        device=x.device,
    )

    shrunk_buffers: Optional[torch.Tensor] = layer.punica_wrapper.add_shrink(
50
51
        buffers, x, layer.lora_a_stacked, 1.0
    )
Jee Jee Li's avatar
Jee Jee Li committed
52
53
54
55
56
57
58
59
60
61
62
63

    if not current_platform.can_update_inplace():
        buffers = shrunk_buffers

    buffers = tensor_model_parallel_all_gather(buffers)

    lora_output: Optional[torch.Tensor] = layer.punica_wrapper.add_expand(
        output,
        buffers,
        layer.lora_b_stacked,
        layer.output_slices,
        offset_start=0,
64
65
        add_input=True,
    )
Jee Jee Li's avatar
Jee Jee Li committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

    if not current_platform.can_update_inplace():
        output = lora_output

    output = output.view(*out_orig_shape)
    # now have column partitioned and packed output
    return output


class ColumnParallelLinearWithLoRA(BaseLinearLayerWithLoRA):
    """
    LoRA on top of ColumnParallelLinear layer.
    LoRA B is sliced for tensor parallelism.
    There are two types for the `base_layer`:
    1. ColumnParallelLinear, e.g.`dense_h_to_4h` in `FalconForCausalLM`.
    2. MergedColumnParallelLinear, e.g.`gate_up_proj` in `Phi3ForCausalLM`.
    """

    def __init__(self, base_layer: ColumnParallelLinear) -> None:
        super().__init__(base_layer)
        # The base_layer type is ColumnParallelLinear or
        # MergedColumnParallelLinear, their weight sharding logic is
        # inconsistent when TP is greater than 1.
89
        self.is_merged_col_linear = type(base_layer) is MergedColumnParallelLinear
Jee Jee Li's avatar
Jee Jee Li committed
90
91
92
93
94
95
96
97
98
99
100
101
        self.output_size = self.base_layer.output_size_per_partition
        # There is only one LoRA layer
        self.n_slices = 1

    def slice_lora_a(self, lora_a: torch.Tensor) -> torch.Tensor:
        return lora_a

    def slice_lora_b(self, lora_b: torch.Tensor) -> torch.Tensor:
        # Applicable to cases where the base_layer is
        # MergedColumnParallelLinear.
        if self.is_merged_col_linear:
            shard_size = self.output_size // 2
102
            offset = lora_b.shape[0] // 2
Jee Jee Li's avatar
Jee Jee Li committed
103

104
105
106
107
108
109
110
111
            left_weight = lora_b[
                self.tp_rank * shard_size : (self.tp_rank + 1) * shard_size, :
            ]
            right_weight = lora_b[
                offset + self.tp_rank * shard_size : offset
                + (self.tp_rank + 1) * shard_size,
                :,
            ]
112
            lora_b = torch.cat([left_weight, right_weight], dim=0)
Jee Jee Li's avatar
Jee Jee Li committed
113
114
115
116
        # Applicable to cases where the base_layer is
        # ColumnParallelLinear.
        else:
            shard_size = self.output_size
117
118
            start_idx = self.tp_rank * shard_size
            end_idx = (self.tp_rank + 1) * shard_size
119
            lora_b = lora_b[start_idx:end_idx, :]
Jee Jee Li's avatar
Jee Jee Li committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
        return lora_b

    def forward(
        self, input_: torch.Tensor
    ) -> Union[torch.Tensor, tuple[torch.Tensor, Optional[torch.Tensor]]]:
        """Forward of ColumnParallelLinear

        Args:
            input_: Tensor whose last dimension is `input_size`.

        Returns:
            - output
            - bias
        """
134
        bias = self.base_layer.bias if not self.base_layer.skip_bias_add else None
Jee Jee Li's avatar
Jee Jee Li committed
135
136
137

        # Matrix multiply.
        output_parallel = self.apply(input_, bias)
138
        if self.base_layer.gather_output and self.tp_size > 1:
Jee Jee Li's avatar
Jee Jee Li committed
139
140
141
142
143
144
145
146
            # All-gather across the partitions.
            output = tensor_model_parallel_all_gather(output_parallel)
        else:
            output = output_parallel

        if not self.base_layer.return_bias:
            return output

147
        output_bias = self.base_layer.bias if self.base_layer.skip_bias_add else None
Jee Jee Li's avatar
Jee Jee Li committed
148
149
150
151
152
153
154
155
156
157
158
159
160
        return output, output_bias

    @classmethod
    @_not_fully_sharded_can_replace
    def can_replace_layer(
        cls,
        source_layer: nn.Module,
        lora_config: LoRAConfig,
        packed_modules_list: list,
        model_config: Optional[PretrainedConfig],
    ) -> bool:
        return type(source_layer) is ColumnParallelLinear or (
            type(source_layer) is MergedColumnParallelLinear
161
162
            and len(packed_modules_list) == 1
        )
Jee Jee Li's avatar
Jee Jee Li committed
163
164
165
166
167
168
169
170
171
172
173
174


class MergedColumnParallelLinearWithLoRA(ColumnParallelLinearWithLoRA):
    """ColumnParallelLinear layer that is composed of 2 sublayers (slices)
    packed together (e.g. gate_proj + up_proj -> gate_up_proj).

    This means we have 2 LoRAs, each applied to one half of the layer.

    Both slices must have the same size.
    """

    def __init__(
175
176
        self, base_layer: Union[MergedColumnParallelLinear, QKVParallelLinear]
    ) -> None:
Jee Jee Li's avatar
Jee Jee Li committed
177
178
179
180
181
182
        super().__init__(base_layer)
        # There are two LoRA layers
        # the output_sizes in MergedColumnParallelLinear is not sharded by tp
        # we need to divide it by the tp_size to get correct slices size
        output_sizes = self.base_layer.output_sizes
        self.output_slices = tuple(
183
184
            divide(output_size, self.tp_size) for output_size in output_sizes
        )
Jee Jee Li's avatar
Jee Jee Li committed
185
        self.n_slices = len(self.output_slices)
186
        self.output_ids = (self.tp_rank,) * self.n_slices
Jee Jee Li's avatar
Jee Jee Li committed
187
188
189
190
191
192
193
194

    def create_lora_weights(
        self,
        max_loras: int,
        lora_config: LoRAConfig,
        model_config: Optional[PretrainedConfig] = None,
    ) -> None:
        """
195
        The main reason for overriding this function is to enhance  code
Jee Jee Li's avatar
Jee Jee Li committed
196
197
198
199
200
        maintainability.
        """
        self.lora_config = lora_config

        lora_a_output_size_per_partition = (
201
202
203
204
            lora_config.max_lora_rank
            if not lora_config.fully_sharded_loras
            else divide(lora_config.max_lora_rank, self.tp_size)
        )
Jee Jee Li's avatar
Jee Jee Li committed
205
206
207
208
209
210
211
212
213

        self.lora_a_stacked = tuple(
            torch.zeros(
                max_loras,
                1,
                lora_a_output_size_per_partition,
                self.input_size,
                dtype=lora_config.lora_dtype,
                device=self.device,
214
215
216
            )
            for _ in range(self.n_slices)
        )
Jee Jee Li's avatar
Jee Jee Li committed
217
218
219
220
221
222
223
224
        self.lora_b_stacked = tuple(
            torch.zeros(
                max_loras,
                1,
                output_size,
                lora_config.max_lora_rank,
                dtype=lora_config.lora_dtype,
                device=self.device,
225
226
227
            )
            for output_size in self.output_slices
        )
Jee Jee Li's avatar
Jee Jee Li committed
228
229
230
231
232
233
234
235
236
237
238

    def slice_lora_a(
        self, lora_a: list[Union[torch.Tensor, None]]
    ) -> list[Union[torch.Tensor, None]]:
        return lora_a

    def slice_lora_b(
        self, lora_b: list[Union[torch.Tensor, None]]
    ) -> list[Union[torch.Tensor, None]]:
        sliced_lora_b = [None] * self.n_slices
        for i, (shard_id, shard_size) in enumerate(
239
240
            zip(self.output_ids, self.output_slices)
        ):
Jee Jee Li's avatar
Jee Jee Li committed
241
            if (lora_b_i := lora_b[i]) is not None:
242
243
244
                sliced_lora_b[i] = lora_b_i[
                    shard_size * shard_id : shard_size * (shard_id + 1), :
                ]
Jee Jee Li's avatar
Jee Jee Li committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
        return sliced_lora_b

    def set_lora(
        self,
        index: int,
        lora_a: torch.Tensor,
        lora_b: torch.Tensor,
        embeddings_tensor: Optional[torch.Tensor],
    ):
        self.reset_lora(index)

        if self.tp_size > 1:
            lora_a = self.slice_lora_a(lora_a)
            lora_b = self.slice_lora_b(lora_b)

        for i in range(self.n_slices):
            if (lora_a_i := lora_a[i]) is not None:
                self.lora_a_stacked[i][
263
264
                    index, 0, : lora_a_i.shape[0], : lora_a_i.shape[1]
                ].copy_(lora_a_i, non_blocking=True)
Jee Jee Li's avatar
Jee Jee Li committed
265
266
            if (lora_b_i := lora_b[i]) is not None:
                self.lora_b_stacked[i][
267
268
                    index, 0, : lora_b_i.shape[0], : lora_b_i.shape[1]
                ].copy_(lora_b_i, non_blocking=True)
Jee Jee Li's avatar
Jee Jee Li committed
269
270
271
272
273
274
275
276
277
278

    @classmethod
    @_not_fully_sharded_can_replace
    def can_replace_layer(
        cls,
        source_layer: nn.Module,
        lora_config: LoRAConfig,
        packed_modules_list: list,
        model_config: Optional[PretrainedConfig],
    ) -> bool:
279
280
281
282
        return (
            type(source_layer) is MergedColumnParallelLinear
            and len(packed_modules_list) == 2
        )
Jee Jee Li's avatar
Jee Jee Li committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299


class QKVParallelLinearWithLoRA(ColumnParallelLinearWithLoRA):
    """
    ColumnParallelLinear layer that is specifically designed for
    qkv_proj. Certain models, such as chatglm3 and baichuan-7b,
    only contains a single LoRA within their qkv_proj layer.

    During inference with Tensor Parallel, the weights of lora_b
    must be accurately partitioned according to the respective ranks.

    Q slice may have different shape than K and V slices (which both have
    the same shape).
    """

    def __init__(self, base_layer: QKVParallelLinear) -> None:
        super().__init__(base_layer)
300
301
302
303
304
305
306
307
308
309
        self.q_proj_total_size = (
            self.base_layer.total_num_heads * self.base_layer.head_size
        )
        self.q_proj_shard_size = self.base_layer.num_heads * self.base_layer.head_size
        self.kv_proj_shard_size = (
            self.base_layer.num_kv_heads * self.base_layer.head_size
        )
        self.kv_proj_total_size = (
            self.base_layer.total_num_kv_heads * self.base_layer.head_size
        )
Jee Jee Li's avatar
Jee Jee Li committed
310
311
312
313
        # There is only one LoRA layer
        self.n_slices = 1

    def slice_lora_b(self, lora_b: torch.Tensor) -> torch.Tensor:
314
315
        self.q_shard_id = self.tp_rank
        self.kv_shard_id = self.tp_rank // self.base_layer.num_kv_head_replicas
316
317
318
319
320
        lora_b_q = lora_b[
            self.q_proj_shard_size * self.q_shard_id : self.q_proj_shard_size
            * (self.q_shard_id + 1),
            :,
        ]
Jee Jee Li's avatar
Jee Jee Li committed
321
        k_offset = self.q_proj_total_size
322
323
324
325
326
        lora_b_k = lora_b[
            k_offset + self.kv_proj_shard_size * self.kv_shard_id : k_offset
            + self.kv_proj_shard_size * (self.kv_shard_id + 1),
            :,
        ]
Jee Jee Li's avatar
Jee Jee Li committed
327
        v_offset = k_offset + self.kv_proj_total_size
328
329
330
331
332
        lora_b_v = lora_b[
            v_offset + self.kv_proj_shard_size * self.kv_shard_id : v_offset
            + self.kv_proj_shard_size * (self.kv_shard_id + 1),
            :,
        ]
333
        lora_b = torch.cat([lora_b_q, lora_b_k, lora_b_v], dim=0)
Jee Jee Li's avatar
Jee Jee Li committed
334
335
336
337
        return lora_b

    @classmethod
    @_not_fully_sharded_can_replace
338
339
340
341
342
343
344
345
    def can_replace_layer(
        cls,
        source_layer: nn.Module,
        lora_config: LoRAConfig,
        packed_modules_list: list,
        model_config: Optional[PretrainedConfig],
    ) -> bool:
        return type(source_layer) is QKVParallelLinear and len(packed_modules_list) == 1
Jee Jee Li's avatar
Jee Jee Li committed
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363


class MergedQKVParallelLinearWithLoRA(MergedColumnParallelLinearWithLoRA):
    """MergedColumnParallelLinear layer that is composed of 3 sublayers (slices)
    packed together in qkv proj fashion
    (q_proj + k_proj + v_proj -> qkv_proj).

    This means we have 3 LoRAs, each applied to one slice of the layer.

    Q slice may have different shape than K and V slices (which both have
    the same shape).
    """

    def __init__(self, base_layer: QKVParallelLinear) -> None:
        super().__init__(base_layer)
        # There are three LoRA layer.
        self.n_slices = len(self.base_layer.output_sizes)

364
365
366
367
        self.q_proj_shard_size = self.base_layer.num_heads * self.base_layer.head_size
        self.kv_proj_shard_size = (
            self.base_layer.num_kv_heads * self.base_layer.head_size
        )
Jee Jee Li's avatar
Jee Jee Li committed
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
        self.q_shard_id = self.tp_rank
        self.kv_shard_id = self.tp_rank // self.base_layer.num_kv_head_replicas

        self.output_slices = (
            self.q_proj_shard_size,
            self.kv_proj_shard_size,
            self.kv_proj_shard_size,
        )
        self.output_ids = (
            self.q_shard_id,
            self.kv_shard_id,
            self.kv_shard_id,
        )

    def create_lora_weights(
        self,
        max_loras: int,
        lora_config: LoRAConfig,
        model_config: Optional[PretrainedConfig] = None,
    ) -> None:
        """
389
        The main reason for overloading this function is to handle inconsistent
Jee Jee Li's avatar
Jee Jee Li committed
390
391
392
393
394
395
396
397
398
399
400
401
402
        weight dimensions in qkv lora.
        """
        super().create_lora_weights(max_loras, lora_config, model_config)

    @classmethod
    @_not_fully_sharded_can_replace
    def can_replace_layer(
        cls,
        source_layer: nn.Module,
        lora_config: LoRAConfig,
        packed_modules_list: list,
        model_config: Optional[PretrainedConfig],
    ) -> bool:
403
        return type(source_layer) is QKVParallelLinear and len(packed_modules_list) == 3
Jee Jee Li's avatar
Jee Jee Li committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424


# These following layers are based on the tensor parallelism strategy given in
# Y. Sheng et al., S-LoRA: Serving Thousands of Concurrent LoRA Adapters. 2023,
# https://arxiv.org/abs/2311.03285.


class ColumnParallelLinearWithShardedLoRA(ColumnParallelLinearWithLoRA):
    """
    Differs from ColumnParallelLinearWithLoRA by slicing LoRA A also.

    Based on S-LoRA, slicing happens along the rank dim.
    """

    # For all LoRA layers where the `base_layer` is `ColumnParallelLinear`,
    # their `lora_a` and `lora_b` have different sharding patterns. After
    # completing the `lora_a` GEMM , a gather operation is performed.
    # Therefore, the sharding of `lora_a` only needs to correspond with the
    # gather operation.
    def slice_lora_a(self, lora_a: torch.Tensor) -> torch.Tensor:
        shard_size = self.lora_a_stacked[0].shape[2]
425
        start_idx = self.tp_rank * shard_size
426
        lora_a = lora_a[start_idx : start_idx + shard_size, :]
Jee Jee Li's avatar
Jee Jee Li committed
427
428
        return lora_a

429
430
431
    def apply(
        self, x: torch.Tensor, bias: Optional[torch.Tensor] = None
    ) -> torch.Tensor:
Jee Jee Li's avatar
Jee Jee Li committed
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
        return _mcp_apply(x, bias, self)

    @classmethod
    @_fully_sharded_can_replace
    def can_replace_layer(
        cls,
        source_layer: nn.Module,
        lora_config: LoRAConfig,
        packed_modules_list: list,
        model_config: Optional[PretrainedConfig],
    ) -> bool:
        # specifying kwargs so they can be easily accessed in decorator
        return super().can_replace_layer(
            source_layer=source_layer,
            lora_config=lora_config,
            packed_modules_list=packed_modules_list,
            model_config=model_config,
            decorate=False,
        )


453
class MergedColumnParallelLinearWithShardedLoRA(MergedColumnParallelLinearWithLoRA):
Jee Jee Li's avatar
Jee Jee Li committed
454
455
456
457
458
459
460
461
462
463
    """
    Differs from MergedColumnParallelLinearWithLoRA by slicing the
    LoRA A's also.

    Based on S-LoRA, slicing happens along the rank dim.
    """

    def slice_lora_a(
        self, lora_a: list[Union[torch.Tensor, None]]
    ) -> list[Union[torch.Tensor, None]]:
464
        # NOTE: lora_a contains 2 subloras, and each sublora could be None.
Jee Jee Li's avatar
Jee Jee Li committed
465
466
467
        output_shard_size = self.lora_a_stacked[0].shape[2]
        output_start_idx = self.tp_rank * output_shard_size
        lora_a = [
468
469
470
471
472
473
            lora_a[0][output_start_idx : output_start_idx + output_shard_size, :]
            if lora_a[0] is not None
            else None,
            lora_a[1][output_start_idx : output_start_idx + output_shard_size, :]
            if lora_a[1] is not None
            else None,
Jee Jee Li's avatar
Jee Jee Li committed
474
475
476
        ]
        return lora_a

477
478
479
    def apply(
        self, x: torch.Tensor, bias: Optional[torch.Tensor] = None
    ) -> torch.Tensor:
Jee Jee Li's avatar
Jee Jee Li committed
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
        return _mcp_apply(x, bias, self)

    @classmethod
    @_fully_sharded_can_replace
    def can_replace_layer(
        cls,
        source_layer: nn.Module,
        lora_config: LoRAConfig,
        packed_modules_list: list,
        model_config: Optional[PretrainedConfig],
    ) -> bool:
        # specifying kwargs so they can be easily accessed in decorator
        return super().can_replace_layer(
            source_layer=source_layer,
            lora_config=lora_config,
            packed_modules_list=packed_modules_list,
            model_config=model_config,
            decorate=False,
        )


class QKVParallelLinearWithShardedLoRA(QKVParallelLinearWithLoRA):
    """
    Differs from QKVParallelLinearWithLoRA by slicing the
    LoRA A's also.

    Based on S-LoRA, slicing happens along the rank dim.
    """

    def slice_lora_a(self, lora_a: torch.Tensor) -> torch.Tensor:
        shard_size = self.lora_a_stacked[0].shape[2]
511
        start_idx = self.tp_rank * shard_size
512
        lora_a = lora_a[start_idx : start_idx + shard_size, :]
Jee Jee Li's avatar
Jee Jee Li committed
513
514
        return lora_a

515
516
517
    def apply(
        self, x: torch.Tensor, bias: Optional[torch.Tensor] = None
    ) -> torch.Tensor:
Jee Jee Li's avatar
Jee Jee Li committed
518
519
520
521
        return _mcp_apply(x, bias, self)

    @classmethod
    @_fully_sharded_can_replace
522
523
524
525
526
527
528
    def can_replace_layer(
        cls,
        source_layer: nn.Module,
        lora_config: LoRAConfig,
        packed_modules_list: list,
        model_config: Optional[PretrainedConfig],
    ) -> bool:
Jee Jee Li's avatar
Jee Jee Li committed
529
530
531
532
533
534
535
536
537
538
539
540
        # specifying kwargs so they can be easily accessed in decorator
        return super().can_replace_layer(
            source_layer=source_layer,
            lora_config=lora_config,
            packed_modules_list=packed_modules_list,
            model_config=model_config,
            decorate=False,
        )


class MergedQKVParallelLinearWithShardedLoRA(MergedQKVParallelLinearWithLoRA):
    """
541
    Differs from MergedQKVParallelLinearWithLoRA by slicing the
Jee Jee Li's avatar
Jee Jee Li committed
542
543
544
545
546
547
548
549
550
551
552
553
    LoRA A's also.

    Based on S-LoRA, slicing happens along the rank dim.
    """

    def slice_lora_a(
        self, lora_a: list[Union[torch.Tensor, None]]
    ) -> list[Union[torch.Tensor, None]]:
        # NOTE: lora_a contains 3 subloras, and each sublora could be None.
        shard_size = [self.lora_a_stacked[i].shape[2] for i in range(3)]
        start_idx = [self.tp_rank * shard_size[i] for i in range(3)]
        lora_a = [
554
555
556
557
558
559
560
561
562
            lora_a[0][start_idx[0] : start_idx[0] + shard_size[0], :]
            if lora_a[0] is not None
            else None,
            lora_a[1][start_idx[1] : start_idx[1] + shard_size[1], :]
            if lora_a[1] is not None
            else None,
            lora_a[2][start_idx[2] : start_idx[2] + shard_size[2], :]
            if lora_a[2] is not None
            else None,
Jee Jee Li's avatar
Jee Jee Li committed
563
564
565
        ]
        return lora_a

566
567
568
    def apply(
        self, x: torch.Tensor, bias: Optional[torch.Tensor] = None
    ) -> torch.Tensor:
Jee Jee Li's avatar
Jee Jee Li committed
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
        return _mcp_apply(x, bias, self)

    @classmethod
    @_fully_sharded_can_replace
    def can_replace_layer(
        cls,
        source_layer: nn.Module,
        lora_config: LoRAConfig,
        packed_modules_list: list,
        model_config: Optional[PretrainedConfig],
    ) -> bool:
        # specifying kwargs so they can be easily accessed in decorator
        return super().can_replace_layer(
            source_layer=source_layer,
            lora_config=lora_config,
            packed_modules_list=packed_modules_list,
            model_config=model_config,
            decorate=False,
        )