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

[AutoParallel]:fix baichuan d2s fail #9478

Merged
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
7 changes: 4 additions & 3 deletions paddlenlp/transformers/llama/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from functools import partial
from typing import Optional, Tuple

import numpy as np
import paddle
import paddle.distributed.fleet.meta_parallel as mpu
import paddle.nn.functional as F
Expand Down Expand Up @@ -100,14 +101,14 @@

def _get_interleave(n):
def _get_interleave_power_of_2(n):
start = 2 ** (-(2 ** -(math.log2(n) - 3)))
start = 2 ** (-(2 ** -(np.log2(n) - 3)))

Check warning on line 104 in paddlenlp/transformers/llama/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling.py#L104

Added line #L104 was not covered by tests
ratio = start
return [start * ratio**i for i in range(n)]

if math.log2(n).is_integer():
if np.log2(n).is_integer():

Check warning on line 108 in paddlenlp/transformers/llama/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling.py#L108

Added line #L108 was not covered by tests
return _get_interleave_power_of_2(n)
else:
closest_power_of_2 = 2 ** math.floor(math.log2(n))
closest_power_of_2 = int(2 ** np.floor(np.log2(n)))

Check warning on line 111 in paddlenlp/transformers/llama/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling.py#L111

Added line #L111 was not covered by tests
return (
_get_interleave_power_of_2(closest_power_of_2)
+ _get_interleave(2 * closest_power_of_2)[0::2][: n - closest_power_of_2]
Expand Down
2 changes: 1 addition & 1 deletion paddlenlp/transformers/llama/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@
alibi = dist.shard_tensor(alibi, global_mesh, alibi_place)
else:
alibi = None
if self.config.use_flash_attention:
if self.config.use_flash_attention and not self.config.alibi:

Check warning on line 1002 in paddlenlp/transformers/llama/modeling_auto.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling_auto.py#L1002

Added line #L1002 was not covered by tests
# attention_mask in flash_attn is always None for pretrain
# atttenton_mask is used in scaled_dot_product_attention with alibi_tensor
attention_mask = None
Expand Down
Loading