Skip to content

Centralize ONNX export warning suppression in export_pytorch()#460

Merged
chinazhangchao merged 7 commits into
mainfrom
copilot/fix-tracerwarning-to-stderr
May 8, 2026
Merged

Centralize ONNX export warning suppression in export_pytorch()#460
chinazhangchao merged 7 commits into
mainfrom
copilot/fix-tracerwarning-to-stderr

Conversation

Copy link
Copy Markdown

Copilot AI commented May 7, 2026

After removing eager TracerWarning filtering at startup, several ONNX export paths began leaking TracerWarning/export-time noise to stderr because suppression existed only in one caller. This change moves suppression to the shared export implementation so all call sites behave consistently.

  • Export path hardening

    • Moved warning suppression into src/winml/modelkit/export/pytorch.py::export_pytorch().
    • Wrapped exporter invocation with warnings.catch_warnings() + warnings.filterwarnings("ignore") so all transitive callers (CLI export, HF build path, perf path, etc.) inherit suppression.
  • Caller cleanup

    • Removed the now-redundant local warnings wrapper from src/winml/modelkit/commands/build.py.
    • Keeps behavior but eliminates per-caller duplication/footgun.
  • Documentation alignment

    • Updated src/winml/modelkit/_warnings.py note to reflect that suppression is now handled in export_pytorch() rather than build.py.
  • Focused regression coverage

    • Added tests/unit/test_pytorch_warning_suppression.py to verify:
      • warning context is actually entered in export_pytorch()
      • warnings emitted during export do not propagate to callers
# src/winml/modelkit/export/pytorch.py
with warnings.catch_warnings():
    warnings.filterwarnings("ignore")
    return exporter.export(...)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • releases.astral.sh
    • Triggering command: /home/REDACTED/.local/bin/uv /home/REDACTED/.local/bin/uv run ruff check (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 3 commits May 7, 2026 07:10
Agent-Logs-Url: https://github.com/microsoft/WinML-ModelKit/sessions/208a704a-029f-4bb4-a2d2-c8d4a76a413a

Co-authored-by: chinazhangchao <3822520+chinazhangchao@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/WinML-ModelKit/sessions/208a704a-029f-4bb4-a2d2-c8d4a76a413a

Co-authored-by: chinazhangchao <3822520+chinazhangchao@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/WinML-ModelKit/sessions/208a704a-029f-4bb4-a2d2-c8d4a76a413a

Co-authored-by: chinazhangchao <3822520+chinazhangchao@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TracerWarning leaks to stderr on winml export Centralize ONNX export warning suppression in export_pytorch() May 7, 2026
Copilot AI requested a review from chinazhangchao May 7, 2026 07:17
@chinazhangchao chinazhangchao marked this pull request as ready for review May 8, 2026 02:45
@chinazhangchao chinazhangchao requested a review from a team as a code owner May 8, 2026 02:45
@chinazhangchao chinazhangchao merged commit 3ec8881 into main May 8, 2026
9 checks passed
@chinazhangchao chinazhangchao deleted the copilot/fix-tracerwarning-to-stderr branch May 8, 2026 09:15
vortex-captain pushed a commit that referenced this pull request May 20, 2026
Move the `_normalize_exported_model` call inside the
`warnings.catch_warnings()` block so the optimizer's shape-inference
and ORT warnings stay suppressed for callers. PR #460 centralized
warning suppression here; the new normalization call had escaped it
and was leaking warnings to stderr. Addresses DingmaomaoBJTU's first
review finding on #681.
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.

Bug: TracerWarning leaks to stderr on winml export, build/hf.py paths

3 participants