Commit 0a4ae3f
fix: restore Shape(input_ids) for query_length in create_attention_bias()
Commit fd85bdf changed query_length to use Shape(attention_mask, start=1, end=2)
so that the EliminateShape WebGPU rule would fire on it. But attention_mask
always has shape (batch, total_seq_len), so:
query_length = Shape(attention_mask, 1) → total_seq_len
total_length = Shape(attention_mask, 1) → total_seq_len
start = Sub(total_length, query_length) → 0
start=0 means Slice selects ALL positions as queries. During decode,
input_ids is (batch, 1), so query_length should be 1 and start should be
total_seq_len - 1, slicing only the last row. With start=0 the returned
bias has shape (batch, 1, total_seq_len, total_seq_len) instead of the
correct (batch, 1, 1, total_seq_len), causing completely wrong attention
scores and garbage model output.
Fix: revert query_length to Shape(input_ids, start=1, end=2).
- total_length stays on attention_mask (EliminateShape still fires for it).
- On WebGPU (concrete dims), Shape(input_ids, 1) is constant-folded away,
so no dynamic Shape op survives in the WebGPU export.
Add test: test_query_length_from_input_ids_not_attention_mask verifies
that a Shape node reading from input_ids is present in the graph, guarding
against future regressions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>1 parent b6ebf8d commit 0a4ae3f
2 files changed
Lines changed: 33 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
198 | 202 | | |
199 | 203 | | |
200 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
94 | 119 | | |
95 | 120 | | |
96 | 121 | | |
| |||
0 commit comments