Skip to content

[TorchFX] Fix TinyLlama weight compression example for transformers 5.5 - #4289

Open
AlexanderDokuchaev wants to merge 5 commits into
openvinotoolkit:developfrom
AlexanderDokuchaev:ad/fx_llm_example
Open

AlexanderDokuchaev wants to merge 5 commits into
openvinotoolkit:developfrom
AlexanderDokuchaev:ad/fx_llm_example

Conversation

@AlexanderDokuchaev

@AlexanderDokuchaev AlexanderDokuchaev commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

  • Use stock transformers.integrations.executorch.convert_and_export_with_cache and
    TorchExportableModuleForDecoderOnlyLM.generate instead of the custom wrappers; modelling.py removed.
  • Calibration inputs are now {"input_ids", "cache_position"} dicts truncated to the cache length.
  • Generation runs under torch.no_grad(); one warm-up forward before timing; optimum dependency dropped
  • update tests/cross_fw/examples/test_durations.json

Reason for changes

The example fails with transformers 5.x:

  • IndexError: index_copy_(): index 512 is out of bounds — the custom forward skipped the cumulative_length
    reset of StaticCache, so calibration samples were appended until the 512-token cache overflowed.
  • KeyError: 'cache_position' — generate() no longer passes cache_position.

Related tickets

N/A

Tests

Test examples - success

@AlexanderDokuchaev
AlexanderDokuchaev marked this pull request as ready for review October 28, 2026 09:59
@AlexanderDokuchaev
AlexanderDokuchaev requested a review from a team as a code owner October 28, 2026 09:59
Copilot AI balanced review requested due to automatic review settings October 28, 2026 09:59

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.

🟡 Changes recommended

The pinned generation helper duplicates the final prompt token and changes generated output, while an unconditional xfail masks a failing Linux accuracy check.

3 open issues
What changed in this PR

Updates NNCF’s TorchFX TinyLlama weight-compression example for Transformers 5.5, replacing custom export and generation wrappers with upstream helpers.

Changes:

  • Uses named calibration inputs truncated to the static-cache length.
  • Adds no-gradient generation, a warm-up forward, and baseline/compressed model reporting.
  • Removes the custom wrappers and optimum dependency, and refreshes example test durations.
File Description
tests/​cross_fw/​examples/​test_durations.json Refreshes example timing data and removes one entry.
examples/​llm_compression/​torch_fx/​tiny_llama/​requirements.txt Drops the optimum dependency.
examples/​llm_compression/​torch_fx/​tiny_llama/​modelling.py Deletes custom export and generation wrappers.
examples/​llm_compression/​torch_fx/​tiny_llama/​main.py Adopts upstream helpers and updates calibration, generation, and reporting.

Review effort: Balanced

Comment thread examples/llm_compression/torch_fx/tiny_llama/main.py
Comment thread examples/llm_compression/torch_fx/tiny_llama/main.py
Comment thread examples/llm_compression/torch_fx/tiny_llama/main.py

This branch has not been deployed

No deployments
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.

2 participants