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

[XPU] add lora optimization (#8527) #9187

Closed
wants to merge 1 commit into from
Closed
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
58 changes: 50 additions & 8 deletions paddlenlp/peft/lora/lora_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,57 @@ class RowSequenceParallelLinear:
from ...utils.log import logger
from ...utils.tools import get_env_device
from .lora_config import LoRAConfig
from .lora_layers import (
ColumnParallelLoRALinear,
ColumnSequenceParallelLoRALinear,
LoRAConv2D,
LoRALinear,
RowParallelLoRALinear,
RowSequenceParallelLoRALinear,
)


def get_lora_layers():
try:
if get_env_device() == "xpu":
# If paddle_xpu is not installed, just use PaddleNLP's native lora layers
from paddle_xpu.layers.nn.lora_layers import (
XPUColumnParallelLoRALinear as ColumnParallelLoRALinear,
)
from paddle_xpu.layers.nn.lora_layers import (
XPUColumnSequenceParallelLoRALinear as ColumnSequenceParallelLoRALinear,
)
from paddle_xpu.layers.nn.lora_layers import XPULoRALinear as LoRALinear
from paddle_xpu.layers.nn.lora_layers import (
XPURowParallelLoRALinear as RowParallelLoRALinear,
)
from paddle_xpu.layers.nn.lora_layers import (
XPURowSequenceParallelLoRALinear as RowSequenceParallelLoRALinear,
)

from .lora_layers import LoRAConv2D

else:
raise ImportError # Force to use the fallback if not XPU
except ImportError:
from .lora_layers import (
ColumnParallelLoRALinear,
ColumnSequenceParallelLoRALinear,
LoRAConv2D,
LoRALinear,
RowParallelLoRALinear,
RowSequenceParallelLoRALinear,
)

return {
"ColumnParallelLoRALinear": ColumnParallelLoRALinear,
"ColumnSequenceParallelLoRALinear": ColumnSequenceParallelLoRALinear,
"LoRAConv2D": LoRAConv2D,
"LoRALinear": LoRALinear,
"RowParallelLoRALinear": RowParallelLoRALinear,
"RowSequenceParallelLoRALinear": RowSequenceParallelLoRALinear,
}


lora_layers = get_lora_layers()
ColumnParallelLoRALinear = lora_layers["ColumnParallelLoRALinear"]
ColumnSequenceParallelLoRALinear = lora_layers["ColumnSequenceParallelLoRALinear"]
LoRAConv2D = lora_layers["LoRAConv2D"]
LoRALinear = lora_layers["LoRALinear"]
RowParallelLoRALinear = lora_layers["RowParallelLoRALinear"]
RowSequenceParallelLoRALinear = lora_layers["RowSequenceParallelLoRALinear"]
AVALIABLE_LAYERS = [
ColumnParallelLoRALinear,
ColumnSequenceParallelLoRALinear,
Expand Down
Loading