Skip to content

Fix Phi3 LongRoPE cache rebuild at the context boundary - #49361

Merged
Rocketknight1 merged 1 commit into
huggingface:mainfrom
LE0-Lin:fix/phi3-longrope-cache-reset
Oct 7, 2026
Merged

Rocketknight1 merged 1 commit into
huggingface:mainfrom
LE0-Lin:fix/phi3-longrope-cache-reset

Conversation

@LE0-Lin

@LE0-Lin LE0-Lin commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

CPU CI GPU run-slow

What does this PR do?

Fixes #49334.

When Phi3 generation crosses the original context limit, it clears the KV cache to recompute the prefix with the long RoPE factors. However, next_sequence_length=1 still makes the base input preparation keep only the last token. I reset that argument alongside the cache so the forward pass receives the full prefix.

The regression compares each generation step with an uncached full-prefix forward before, at, and after the boundary, with and without a sliding window. Phimoe's existing copied method and both generated files are synchronized by make fix-repo.

Coordinated in #49334. Searches of the issue timeline and open Phi3/LongRoPE PRs did not find an overlapping fix. AI assistance was used.

Validation

  • New regressions: 2 failed before the fix; 2 passed after.
  • python -m pytest tests/models/phi3/test_modeling_phi3.py tests/models/phimoe/test_modeling_phimoe.py -m 'not slow' -q -o addopts= --disable-warnings: 303 passed, 233 skipped, 101 deselected on CPU. These are the two files selected by utils/tests_fetcher.py.
  • Original issue reproduction: the reset forward receives all 9 prefix tokens, and the generated next tokens [32, 26] match the uncached reference.
  • make fix-repo, make check-repo, make style, and git diff --check: passed.

GPU, distributed, and large-checkpoint slow tests were not run locally.

Before submitting

  • Contributor guidelines and PR checks read.
  • Discussed with a maintainer in the linked issue.
  • Necessary regression tests added.
  • Documentation: no API or configuration change.

@LE0-Lin

LE0-Lin commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

I checked the failed fetcher job: the runner pod failed to come online (phase status Failed) during container initialization. Checkout and test selection were skipped, so the model tests did not run. The PR CI status failure propagates this setup failure.

Could the failed jobs be rerun once the runner is healthy?

@Rocketknight1
Rocketknight1 force-pushed the fix/phi3-longrope-cache-reset branch from aae0f6b to 4a2f93b Compare October 7, 2026 12:59

@Rocketknight1 Rocketknight1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, fix looks good and the failing test is just CI issues. I'll rerun everything before merging. Thank you!

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: phi3, phimoe

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 37484886830:2
Result: success | Jobs: 2 | Tests: 26 | Failures: 0 | Duration: 2m 47s

@Rocketknight1
Rocketknight1 added this pull request to the merge queue Oct 7, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Merged via the queue into huggingface:main with commit 6a33cb5 Oct 7, 2026
39 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.

Phi3 LongRoPE generation loses the prefix when clearing KV at the short/long crossing

3 participants