-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [XPU] llama add xpu support * fix * use try import * fix * refine * refine * refine * refine
- Loading branch information
1 parent
62b58a3
commit ba9d9bd
Showing
3 changed files
with
135 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
This file is used for replacing Paddle's native Linear implementations with vendors' customized implementations | ||
""" | ||
|
||
import paddle.distributed.fleet.meta_parallel as mpu | ||
from paddle import nn | ||
from paddle.distributed.fleet.utils import sequence_parallel_utils | ||
|
||
from paddlenlp.transformers.mc2_parallel_linear import ( | ||
MC2ColumnSeqParallelLinear, | ||
MC2RowSeqParallelLinear, | ||
) | ||
from paddlenlp.utils.tools import get_env_device | ||
|
||
Linear = nn.Linear | ||
ColumnParallelLinear = mpu.ColumnParallelLinear | ||
RowParallelLinear = mpu.RowParallelLinear | ||
ColumnSequenceParallelLinear = sequence_parallel_utils.ColumnSequenceParallelLinear | ||
RowSequenceParallelLinear = sequence_parallel_utils.RowSequenceParallelLinear | ||
|
||
if get_env_device() == "npu": | ||
if MC2ColumnSeqParallelLinear is not None and MC2RowSeqParallelLinear is not None: | ||
ColumnSequenceParallelLinear = MC2ColumnSeqParallelLinear | ||
RowSequenceParallelLinear = MC2RowSeqParallelLinear | ||
elif get_env_device() == "xpu": | ||
try: | ||
from paddle_xpu.layers.nn import ColumnParallelLinear as XPUColumnParallelLinear | ||
from paddle_xpu.layers.nn import Linear as XPULinear | ||
from paddle_xpu.layers.nn import RowParallelLinear as XPURowParallelLinear | ||
from paddle_xpu.layers.nn.sequence_parallel import ( | ||
XPUColumnSequenceParallelLinear, | ||
XPURowSequenceParallelLinear, | ||
) | ||
|
||
Linear = XPULinear | ||
ColumnParallelLinear = XPUColumnParallelLinear | ||
RowParallelLinear = XPURowParallelLinear | ||
ColumnSequenceParallelLinear = XPUColumnSequenceParallelLinear | ||
RowSequenceParallelLinear = XPURowSequenceParallelLinear | ||
except ImportError: | ||
# If paddle_xpu is not installed, just use Paddle's native Linear implementations | ||
pass | ||
else: | ||
# By default, use Paddle's native Linear implementations | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters