|
46 | 46 | import onnx_ir as ir |
47 | 47 | from onnxscript import OpBuilder, nn |
48 | 48 |
|
49 | | -from mobius.components._common import INT64_MAX, LayerNormNoBias, Linear |
| 49 | +from mobius.components._common import LayerNormNoBias, Linear |
50 | 50 | from mobius.components._conv import CausalDepthwiseConv1d, Conv2dNoBias |
51 | 51 | from mobius.components._rms_norm import RMSNorm |
52 | 52 |
|
@@ -211,11 +211,16 @@ def _mask_and_downsample( |
211 | 211 | # Broadcast mask [B, T] → [B, 1, T, 1] over C and F dims |
212 | 212 | mask_4d = op.Unsqueeze(mask, [1, 3]) # [B, 1, T, 1] |
213 | 213 | x = op.Mul(x, op.CastLike(mask_4d, x)) |
214 | | - # Downsample mask by conv stride (2): mask[:, ::2] |
| 214 | + # Downsample mask by conv stride (2): mask[:, ::2]. Bound the slice |
| 215 | + # ``ends`` to the dynamic time length rather than ``INT64_MAX``: shape |
| 216 | + # inference does not clamp a concrete ``INT64_MAX`` end to the (symbolic) |
| 217 | + # input dim, so it derives an output length of ``INT64_MAX // 2`` (2^62), |
| 218 | + # which then overflows the downstream flatten Reshape at model load. |
| 219 | + mask_len = op.Shape(mask, start=1, end=2) # [1] — the time dim size |
215 | 220 | mask = op.Slice( |
216 | 221 | mask, |
217 | 222 | [0], # starts |
218 | | - [INT64_MAX], # ends |
| 223 | + mask_len, # ends (clamped to the real length) |
219 | 224 | [1], # axes |
220 | 225 | [2], # steps |
221 | 226 | ) # [B, T//2] |
@@ -477,7 +482,10 @@ def _build_causal_window_mask(self, op: OpBuilder, seq_len: ir.Value) -> ir.Valu |
477 | 482 | """Build [1, 1, T, T] causal sliding-window attention bias.""" |
478 | 483 | zero = op.Constant(value_int=0) |
479 | 484 | one = op.Constant(value_int=1) |
480 | | - positions = op.Range(zero, seq_len, one) # [T] int64 |
| 485 | + # ``seq_len`` is a 1-D [1] tensor from op.Shape; Range requires a |
| 486 | + # scalar limit, so squeeze the singleton axis. |
| 487 | + seq_len_scalar = op.Squeeze(seq_len, [0]) |
| 488 | + positions = op.Range(zero, seq_len_scalar, one) # [T] int64 |
481 | 489 | q_pos = op.Unsqueeze(positions, [1]) # [T, 1] |
482 | 490 | k_pos = op.Unsqueeze(positions, [0]) # [1, T] |
483 | 491 | diff = op.Sub(q_pos, k_pos) # [T, T]: i - j |
@@ -570,7 +578,9 @@ def forward( |
570 | 578 | # pos_embed is ordered [ctx_left-1, ..., 0], so distance d maps to index ctx_left-1-d |
571 | 579 | zero_i = op.Constant(value_int=0) |
572 | 580 | one_i = op.Constant(value_int=1) |
573 | | - positions = op.Range(zero_i, seq_len, one_i) # [T] |
| 581 | + # Range requires a scalar limit; ``seq_len`` is a 1-D [1] shape tensor. |
| 582 | + seq_len_scalar = op.Squeeze(seq_len, [0]) |
| 583 | + positions = op.Range(zero_i, seq_len_scalar, one_i) # [T] |
574 | 584 | q_pos_i = op.Unsqueeze(positions, [1]) # [T, 1] |
575 | 585 | k_pos_i = op.Unsqueeze(positions, [0]) # [1, T] |
576 | 586 | diff_i = op.Sub(q_pos_i, k_pos_i) # [T, T]: i-j |
|
0 commit comments