Fix explicit position_ids generation on Transformers 4
#8
by ebrahim-ricursive - opened
Explicit position_ids passed to generate() crash on the first decoding step under Transformers 4.57.6. The generation loop keeps the prompt-length positions, while prepare_inputs_for_generation() indexes the next cache position beyond their end.
Extend explicit positions after generation updates only when the parent implementation leaves them unchanged. Preserve each row's final position and advance by the actual number of accepted tokens. Transformers 5.22.1 already extends positions, so it retains its existing behavior.
Validation (local harness retained with the validation artifacts):
- Seven regression tests pass under both Transformers 4.57.6 and 5.22.1. All seven fail under 4.57.6 before this fix.
- Coverage includes cached and uncached decoding, left padding, custom per-row positions, beam search, multi-token updates, and caller-input preservation. Generation is checked against independent full-forward decoding.
- Existing 65-case suites introduce no additional failures: 4.57.6 has 62 passes, 2 known unrelated failures and 1 skip; 5.22.1 has 62 passes and 3 known unrelated failures. Embeds-only, new-token-only prefix-cache reuse, and the existing TF5 chunked-prefill issues remain outside this change.
- Full BF16 RL700 on a B300 under Transformers 4.57.6 and 5.22.1: explicit-position cached and uncached outputs match their implicit-position controls. Under 5.22.1, full target plus DFlash2 also matches autoregressive output in six cases, including forced budgets 2, 3 and 64 after the companion convolution fix.
Companion fix for the separate DFlash short-block crash: https://github.com/z-lab/dflash/pull/180.
ebrahim-ricursive changed pull request status to merged