Skip to content

add fast test for whisper#2484

Draft
xadupre wants to merge 8 commits into
mainfrom
xadupre/fast_whisper
Draft

add fast test for whisper#2484
xadupre wants to merge 8 commits into
mainfrom
xadupre/fast_whisper

Conversation

@xadupre
Copy link
Copy Markdown
Member

@xadupre xadupre commented Jun 1, 2026

Describe your changes

Add fast test for whisper encoder and decoder in a dedicated test/cli/test_cli_whisper_smoke.py file. Refactored transformers imports to be local imports inside the functions where they are needed (_save_local_tiny_llama and _save_local_tiny_whisper) instead of at the module level. Switched WhisperConfig(...) keyword-argument style to WhisperConfig.from_dict({...}) to fix PYLINT unexpected-keyword-arg errors, matching the existing LlamaConfig.from_dict pattern.

Also fixed a bug in olive/passes/onnx/model_builder.py where onnxruntime-genai's save_model for multi-component models like Whisper (encoder + decoder) prematurely deletes the shared cache_dir between component saves. The encoder's save_model cleanup removes the cache_dir when it is empty (no HF downloads for local models), causing the decoder's save_model to fail with FileNotFoundError. The fix creates a temporary marker file (.olive_build_<pid>) in HF_HUB_CACHE before calling create_model so the directory is never considered empty and never deleted prematurely; the marker is removed in a finally block after create_model completes.

precision is a configurable class attribute on TestCliWhisperSmoke (defaulting to "fp32") and a parameter of _run_whisper_capture_onnx_flow, making it easy to override in subclasses or from the command line.

All Whisper-specific code (DEFAULT_WHISPER_MODEL_IDS, _save_local_tiny_whisper, _run_whisper_capture_onnx_flow, TestCliWhisperSmoke) lives in test/cli/test_cli_whisper_smoke.py, separate from the existing LLaMA smoke tests in test/cli/test_cli_test_model_smoke.py. The CI workflow (test-model-fast.yml) is updated to run both files.

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.

(Optional) Issue link

Comment thread test/cli/test_cli_test_model_smoke.py Outdated
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
Comment thread test/cli/test_cli_test_model_smoke.py Fixed
@xadupre
Copy link
Copy Markdown
Member Author

xadupre commented Jun 2, 2026

@copilot SUBFAILED(model_id='openai/whisper-tiny') test/cli/test_cli_test_model_smoke.py::TestCliWhisperSmoke::test_whisper_capture_onnx_graph - AssertionError: Expected encoder.onnx in output, got: set()
assert 'encoder.onnx' in set()
SUBFAILED(model_id='microsoft/whisper-base') test/cli/test_cli_test_model_smoke.py::TestCliWhisperSmoke::test_whisper_capture_onnx_graph - AssertionError: Expected encoder.onnx in output, got: set()
assert 'encoder.onnx' in set() (it works locally)

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 2, 2026

@copilot SUBFAILED(model_id='openai/whisper-tiny') test/cli/test_cli_test_model_smoke.py::TestCliWhisperSmoke::test_whisper_capture_onnx_graph - AssertionError: Expected encoder.onnx in output, got: s...

The root cause is that onnxruntime-genai's create_model calls os.listdir(cache_dir) unconditionally inside save_model, which raises FileNotFoundError when /home/runner/.cache/huggingface/hub doesn't exist (fresh CI runner with no prior HF downloads). Fixed in olive/passes/onnx/model_builder.py by adding Path(HF_HUB_CACHE).mkdir(parents=True, exist_ok=True) before calling create_model. Also switched WhisperConfig(...) to WhisperConfig.from_dict({...}) to fix the PYLINT unexpected-keyword-arg errors, matching the existing LlamaConfig.from_dict pattern.

@xadupre
Copy link
Copy Markdown
Member Author

xadupre commented Jun 2, 2026

@copilot still unresolved FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/.cache/huggingface/hub'

…_dir between Whisper encoder and decoder saves
Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 2, 2026

@copilot still unresolved FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/.cache/huggingface/hub'

The root cause was more subtle than a missing directory. The create_model function in onnxruntime_genai already calls os.makedirs(cache_dir, exist_ok=True) internally, so the directory always exists when building starts. The real issue is in the Whisper-specific model saving flow: WhisperModel.save_model calls encoder.save_model then decoder.save_model. The encoder's save_model cleanup (in base.py:828) does if not os.listdir(self.cache_dir): os.rmdir(self.cache_dir) — for a local model there are no downloads so the cache dir is empty, gets deleted by the encoder, and then the decoder's save_model fails with FileNotFoundError on the same path.

Fixed in the latest commit by placing a temporary marker file (.olive_build_<pid>) in HF_HUB_CACHE before calling create_model. This keeps the directory non-empty throughout the build so onnxruntime_genai's cleanup never removes it. The marker is deleted in a finally block after create_model completes.

Comment thread test/cli/test_cli_test_model_smoke.py Outdated
Comment thread test/cli/test_cli_test_model_smoke.py Outdated
).save_pretrained(model_path)


def _save_local_tiny_whisper(model_path: Path):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot can you move the new code into a separate file

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.

Done. Moved all Whisper-specific code (_save_local_tiny_whisper, _run_whisper_capture_onnx_flow, TestCliWhisperSmoke, DEFAULT_WHISPER_MODEL_IDS) into a new test/cli/test_cli_whisper_smoke.py. The workflow now runs both files.

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 2, 2026

@copilot SUBFAILED(model_id='openai/whisper-tiny') test/cli/test_cli_test_model_smoke.py::TestCliWhisperSmoke::test_whisper_capture_onnx_graph - AssertionError: Expected encoder.onnx in output, got: s...

This was fixed in commit be34bc8 by placing a temporary marker file in HF_HUB_CACHE before calling create_model, preventing onnxruntime-genai's cleanup from deleting the shared cache_dir between the encoder and decoder saves. The latest "Test model fast" CI run passed successfully.

@copilot still unresolved FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/.cache/huggingface/hub'

Fixed in be34bc8. The root cause was onnxruntime-genai's save_model cleanup deleting the shared cache_dir after the encoder build (because it was empty for local models), causing the decoder build to fail. The fix keeps a temporary marker file (.olive_build_<pid>) in HF_HUB_CACHE for the duration of create_model, so the directory is never considered empty. The latest CI run confirmed the fix works.

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.

3 participants