Skip to content

[Bug fixes] Offset block attn-res boundary by head empty layers - #1766

Merged
Waynezee merged 1 commit into
PaddlePaddle:developfrom
Waynezee:fix-block-attn-res-head-offset
Aug 18, 2026
Merged

[Bug fixes] Offset block attn-res boundary by head empty layers#1766
Waynezee merged 1 commit into
PaddlePaddle:developfrom
Waynezee:fix-block-attn-res-head-offset

Conversation

@Waynezee

Copy link
Copy Markdown
Collaborator

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

TransformerLayer._is_block_boundary used the physical layer_number to decide which layers open an attention-residual block. However, the spec builders (gpt_layer_specs.get_gpt_decoder_layers_spec) shift layer_number by num_empty_layers_add_in_head so the empty head layers occupy the leading slots. The block schedule is defined on the logical decoder index, so the physical index must have that offset subtracted before the modulo.

Without this fix, whenever num_empty_layers_add_in_head > 0 the entire block layout slides by the offset and logical layer 0 never opens a block — silently changing the residual topology of every layer for a K3 warm start.

This PR subtracts num_empty_layers_add_in_head from layer_number before the block-span modulo, and adds tests covering:

  • the head-offset shift (offsets 0/1/2), asserting boundaries land on the shifted logical layers;
  • the non-positive span guard now raising ValueError instead of silently no-op'ing.

是否引起精度变化

`_is_block_boundary` used the physical `layer_number`, but the spec
builders shift it by `num_empty_layers_add_in_head` so empty head layers
occupy the leading slots. The schedule is defined on the logical decoder
index, so subtract that offset before the modulo; otherwise the whole
block layout slides and logical layer 0 never opens a block, silently
changing the residual topology for a K3 warm start.

Add tests covering the head-offset shift and the non-positive span error.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

序号 位置 优先级 状态
1 - -
Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@3733768). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             develop     #1766   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         2           
  Branches           ?         0           
===========================================
  Hits               ?         2           
  Misses             ?         0           
  Partials           ?         0           
Flag Coverage Δ
coverage_combine 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/paddlefleet/transformer/transformer_layer.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Waynezee
Waynezee merged commit 219e684 into PaddlePaddle:develop Aug 18, 2026
28 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants