Skip to content

Added a new test to check whether some transformations is applied during conversion or completion#1651

Open
alien-cyber wants to merge 3 commits intohuggingface:mainfrom
alien-cyber:add-test-transformations
Open

Added a new test to check whether some transformations is applied during conversion or completion#1651
alien-cyber wants to merge 3 commits intohuggingface:mainfrom
alien-cyber:add-test-transformations

Conversation

@alien-cyber
Copy link
Copy Markdown

@alien-cyber alien-cyber commented Mar 25, 2026

This checks whether a specific set of transformations has been applied during conversion or compilation for particular architectures

  • The set of transformations that needed to be checked for a particular architecture can be defined in a separate file called expected_transformations.txt
  • The test case runs for each architecture
  • The model is loaded and compiled in a separate subprocess so that the logs can be captured effectively
  • If a transformation is applied during conversion, then the log definitely contains its name along with time and '+' symbol
  • We run a scan of the logs using an algorithm to check if the transformations are applied based on that logic
  • Sometimes we may misspell the name of the transformation, so I used get_close_matches library which does fuzzy search and returns the possible matches

Closes #1645

Please review and let me know if any further improvements are needed.

…as been applied during conversion or compilation of a particular architecture
@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.

Copy link
Copy Markdown
Contributor

@MissLostCodes MissLostCodes left a comment

Choose a reason for hiding this comment

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

@popovaan @rkazants @alien-cyber

Hi !

I had a few suggestions and potential issues:

  • The test currently captures stdout, but OpenVINO logs are emitted to stderr, so this may miss the relevant transformation logs.
  • Setting OV_ENABLE_PROFILE_PASS at the top level leaks into the global test environment it seems sufficient to keep it scoped inside the subprocess.
  • The subprocess call may be expensive since it can trigger model export for each test case. Adding a cache_dir (or similar reuse strategy) could help reduce overhead.
  • The substring matching logic (key in a) could lead to false positives (e.g., MatMul matching MatMulFusionExtra). Exact matching would be safer.

Overall, the structure and idea of the test look great — addressing these points should make it more robust and CI-friendly.

import sys
import unittest

os.environ["OV_ENABLE_PROFILE_PASS"] = "1"
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.

i think setting OV_ENABLE_PROFILE_PASS at the top level might unintentionally leak into the global test environment . This variable is already being set inside the subprocess - line 49 . we can safely remove this line .

text=True,
)

return result.stdout
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.

I think this should use stderr instead of stdout since OpenVINO logs are emitted to stderr
even function name says capture stderr

- return result.stdout
+ return result.stderr

ARCH_TO_EXPECTED_TRANSFORMATIONS = _load_expected_transformations(_CONFIG_PATH)


def _capture_stderr_during(model_id, OPENVINO_DEVICE, trust_remote_code):
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.

I think the subprocess code here may be quite expensive since it invokes OVModelForCausalLM.from_pretrained(...) inside the string, which can trigger model export on every test run.

compile=True,
device="{OPENVINO_DEVICE}",
trust_remote_code={trust_remote_code},
)
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.

can add this param

cache_dir="./ov_cache"

we could pass a cache_dir so that models are reused across runs instead of being re-exported each time.

This should help make the test more scalable.

remaining = {normalize(w): w for w in words}

for key in list(remaining.keys()):
if any(key in a for a in applied_norm):
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.

I think substring matching here could cause false positives like MatMul matching MatMulFusionExtra
Using exact matching like if key in applied_norm: would be safer.

Copy link
Copy Markdown
Author

@alien-cyber alien-cyber Apr 2, 2026

Choose a reason for hiding this comment

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

Hi @MissLostCodes
Thanks for the analysis.

  • Now the string matching function is Fixed.
  • stderr and stdout are captured in the same place.
  • unnecessary OV_ENABLE_PROFILE_PASS is removed

Regarding cache_dir="./ov_cache", I believe it is not necessary in this context, as it mainly changes the default directory used for caching model files. The default Hugging Face cache should already handle reuse of downloaded model configuration.

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.

Add tests which check, that required transformations are applied

3 participants