Skip to content

[OpenVINO] Fix long context inference for Phi3.5 and Phi4#1744

Merged
echarlaix merged 38 commits into
huggingface:mainfrom
rkazants:phi_3_4_long
Jun 9, 2026
Merged

[OpenVINO] Fix long context inference for Phi3.5 and Phi4#1744
echarlaix merged 38 commits into
huggingface:mainfrom
rkazants:phi_3_4_long

Conversation

@rkazants

@rkazants rkazants commented May 21, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fix for the export was already done in this PR by providing the dedicated patch in the common patcher class: #1589

Fixes 170599

Before submitting

  • [N/A] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • [N/A] Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

eaidova and others added 23 commits May 12, 2025 16:31
- Explicitly disable torch.autocast to ensure float32 precision
- Add sources for adapted code
- Use self.attention_scaling instead of manual computation
- Save and restore original _orig_max_position_embeddings
- Modify F32_CONFIG to use EXECUTION_MODE_HINT
Exclude longrope for phi3-moe with _disable_longrope
- Add more comments
- Remove superfluous select_ext_factor function
- Rename long_rope to _phi3_longrope_forward for clarity
- rename tiny model to phi3
- add test for cumulative context
- revert F32_CONFIG change
- Set MIN_TRANSFORMERS_VERSION to 4.49 for Phi3
- Remove code specific for transformers<4.49
- Disable trust-remote-code for Phi3
- self.original_inv_freq is the same as self.inv_freq because self.inv_freq
  does not get updated during model export
@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.

Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com>

Copilot AI 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.

Pull request overview

This PR adds coverage and version/CLI guardrails to ensure Phi3 LongRoPE (long-context) models can be exported and used for inference reliably with OpenVINO, especially for contexts beyond the original max position embeddings.

Changes:

  • Add a new internal tiny test model entry and integrate a phi3-longrope architecture into the OpenVINO decoder test matrix.
  • Introduce a dedicated integration test that exercises Phi3 LongRoPE generation with contexts exceeding original_max_position_embeddings.
  • Enforce a minimum Transformers version for Phi3 OpenVINO export config and disable trust_remote_code for phi3 in the CLI exporter for with-past exports using default configs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/openvino/utils_tests.py Registers the phi3-longrope tiny model id in the shared test model mapping.
tests/openvino/test_decoder.py Adds phi3-longrope to supported architectures, sets expected SDPA count, and adds a LongRoPE long-context generation test.
optimum/exporters/openvino/model_configs.py Sets Phi3OpenVINOConfig.MIN_TRANSFORMERS_VERSION = 4.49.0 to prevent unsupported exports on older Transformers.
optimum/exporters/openvino/__main__.py Extends the CLI’s trust_remote_code disabling logic to include phi3 for with-past/default export configs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/openvino/test_decoder.py Outdated
Comment thread tests/openvino/test_decoder.py Outdated
echarlaix and others added 2 commits May 21, 2026 18:23
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@echarlaix echarlaix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the addition!

Comment thread tests/openvino/test_decoder.py
Comment thread optimum/exporters/openvino/model_patcher.py Outdated
@rkazants rkazants changed the title Fix long context inference for Phi3.5 and Phi4 [OpenVINO] Fix long context inference for Phi3.5 and Phi4 Jun 8, 2026
@rkazants rkazants requested a review from echarlaix June 9, 2026 05:32
@echarlaix echarlaix merged commit b5a5df0 into huggingface:main Jun 9, 2026
88 of 96 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.

7 participants