Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/paddlefleet/transformer/block_attn_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@ def forward(self, partial_block: Tensor, blocks: list[Tensor]) -> Tensor:
# Equivalent to einsum("n b s, n b s d -> b s d", weights, V)
h = (weights.unsqueeze(-1) * V).sum(axis=0)

if partial_block is not None and h.dtype != partial_block.dtype:
h = h.to(partial_block.dtype)

return h
5 changes: 5 additions & 0 deletions src/paddlefleet/transformer/transformer_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ def _forward_impl(
)

# Accumulate attn output into partial_block
if (
partial_block is not None
and partial_block.dtype != hidden_states.dtype
):
partial_block = partial_block.to(hidden_states.dtype)
partial_block = (
partial_block + hidden_states
if partial_block is not None
Expand Down
Loading