Skip to content

fix(pattern): skip ONNX validation when external data is unloaded#412

Closed
xieofxie wants to merge 1 commit into
mainfrom
hualxie/skip_when_unloaded
Closed

fix(pattern): skip ONNX validation when external data is unloaded#412
xieofxie wants to merge 1 commit into
mainfrom
hualxie/skip_when_unloaded

Conversation

@xieofxie

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a regression from Skip loading external weight data during static analysis. #379 where models loaded with load_external_data=False caused PatternMatcher to log WARNING Model validation failed for pattern matching and skip all pattern detection entirely.
  • Root cause: check_onnx_model called onnx.checker.check_model on a proto whose tensors had data_location=EXTERNAL but no raw_data; the checker couldn't find the sidecar .data file and raised ValidationError.
  • Adds skip_if_unloaded_external_data: bool = False to check_onnx_model. Default is False so existing callers are unaffected; PatternMatcher opts in explicitly.
  • _build_lookups skips numpy_helper.to_array for unloaded external initializers and records their names in _external_unloaded_names.
  • _check_constant_constraints skips the value comparison for those names so topology-based pattern matching (Gelu, LayerNorm, etc.) still works without tensor data.
  • Adds has_unloaded_external_data utility exported from winml.modelkit.onnx.
  • New tests/unit/onnx/test_onnx_utils.py and TestPatternMatchingWithUnloadedExternalData.

@xieofxie xieofxie requested a review from a team as a code owner April 28, 2026 08:26
@xieofxie

Copy link
Copy Markdown
Contributor Author

See warnings like WARNING PatternMatchingValidator: Pattern matching failed - Model validation failed during pattern matching initialization

from __future__ import annotations

import numpy as np
import onnx
@xieofxie

Copy link
Copy Markdown
Contributor Author

@xieofxie xieofxie closed this Apr 28, 2026
@xieofxie xieofxie deleted the hualxie/skip_when_unloaded branch June 10, 2026 02:35
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