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

[LLM] Reconstruct fused transformer layers #7186

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
8 changes: 6 additions & 2 deletions paddlenlp/experimental/transformers/bloom/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from paddlenlp_ops import get_padding_offset

from paddlenlp.experimental.transformers.fused_transformer_layers import (
FusedMultiTransformer,
FusedMultiTransformerBase,
FusedMultiTransformerConfig,
)
from paddlenlp.experimental.transformers.generation_utils import (
GenerationInferenceModel,
Expand Down Expand Up @@ -112,7 +113,8 @@
ffn1_bias_attrs = [paddle.ParamAttr(name="fusemt.{}.ffn1_bias".format(i)) for i in range(config.n_layer)]
ffn2_weight_attrs = [paddle.ParamAttr(name="fusemt.{}.ffn2_weight".format(i)) for i in range(config.n_layer)]
ffn2_bias_attrs = [paddle.ParamAttr(name="fusemt.{}.ffn2_bias".format(i)) for i in range(config.n_layer)]
self.transformer_block = FusedMultiTransformer(

transformer_config = FusedMultiTransformerConfig(

Check warning on line 117 in paddlenlp/experimental/transformers/bloom/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/experimental/transformers/bloom/modeling.py#L117

Added line #L117 was not covered by tests
self.embed_dim,
self.n_head,
4 * self.embed_dim,
Expand All @@ -133,6 +135,8 @@
ffn2_weight_attrs=ffn2_weight_attrs,
ffn2_bias_attrs=ffn2_bias_attrs,
)

self.transformer_block = FusedMultiTransformerBase(transformer_config)

Check warning on line 139 in paddlenlp/experimental/transformers/bloom/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/experimental/transformers/bloom/modeling.py#L139

Added line #L139 was not covered by tests
self.cache_kvs = []

# Final Layer Norm
Expand Down
7 changes: 5 additions & 2 deletions paddlenlp/experimental/transformers/chatglm/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from paddlenlp_ops import get_padding_offset

from paddlenlp.experimental.transformers.fused_transformer_layers import (
FusedMultiTransformer,
FusedMultiTransformerBase,
FusedMultiTransformerConfig,
)
from paddlenlp.experimental.transformers.generation_utils import (
GenerationInferenceModel,
Expand Down Expand Up @@ -183,7 +184,8 @@
]
ffn2_bias_attrs = [paddle.ParamAttr(name="fusemt.{}.ffn2_bias".format(i)) for i in range(config.num_layers)]
alpha = (2 * self.config.num_hidden_layers) ** 0.5
self.transformer_block = FusedMultiTransformer(

transformer_config = FusedMultiTransformerConfig(

Check warning on line 188 in paddlenlp/experimental/transformers/chatglm/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/experimental/transformers/chatglm/modeling.py#L188

Added line #L188 was not covered by tests
config.hidden_size,
config.num_attention_heads,
4 * config.hidden_size,
Expand All @@ -209,6 +211,7 @@
norm_type="layernorm",
use_neox_rotary_style=True,
)
self.transformer_block = FusedMultiTransformerBase(transformer_config)

Check warning on line 214 in paddlenlp/experimental/transformers/chatglm/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/experimental/transformers/chatglm/modeling.py#L214

Added line #L214 was not covered by tests

def remove_padding(self, input_ids, seq_lens_this_time):
cum_offsets_now = paddle.cumsum(paddle.max(seq_lens_this_time) - seq_lens_this_time)
Expand Down
Loading