Commit ef01bb8
Zheng Te
fix(cli): restore winml --help startup speed (6.1s → 0.44s)
_warnings.py was eagerly importing torch.jit at module load, dragging
all of torch (~1.7s) into every winml CLI invocation. The
try:/except ImportError: guard was unreachable since torch is a hard
dependency in this project. Removed the filter; build.py already wraps
export_onnx() in catch_warnings()+filterwarnings("ignore"), which is
strictly broader than the deleted TracerWarning-only filter.
Also:
- onnx/__init__.py: standardize on _LAZY_IMPORTS dict pattern, matching
the other 6 subpackages and fixing 3 TestLazyImportsDict failures.
- sysinfo/device.py: add @lru_cache(maxsize=1) to _get_available_devices,
mirroring the existing decorator on _get_available_eps. Fixes a CI
flake where winml config -m <hf-model> --device <X> would re-run
Windows WMI/PowerShell hardware probes on every resolve_device call,
ballooning to 280s+ on cold runners. With the cache, the 2nd call is
~1M× faster (subprocess work happens once per process).
- tests/cli/: new top-level category for cross-cutting CLI-surface
tests; moved test_import_time.py and test_main.py here.
- tests/cli/test_import_time.py: removed TestCommandWithModel — those
tests invoke handler bodies (feature pipeline territory), not CLI
surface. Per-command runtime import budgets belong in
tests/unit/commands/ where mocks isolate dispatch from feature code.
- modelkit-ci.yml: include tests/cli in the "remaining" matrix group.
Previously test_import_time.py at tests/ root sat outside every
enumerated CI path, so the regression-detecting tests never ran.
- tests/CLAUDE.md: document the tests/cli/ category and require CI
matrix updates when adding new top-level test directories.
Constraint: torch is a hard dependency, so try:/except ImportError on torch.* is unreachable
Constraint: Hardware doesn't change during a process lifetime; lru_cache pattern is already established by _get_available_eps
Rejected: Relocate TracerWarning filter into a torch-loaded code path | build.py's catch_warnings is strictly broader; duplication not worthwhile
Rejected: Change _get_available_devices to return frozenset/tuple for cache safety | larger refactor with public-API ripples; current callers only iterate
Confidence: high
Scope-risk: narrow
Directive: Never use try:/except ImportError on a required dependency at startup — use a function-scoped lazy import if you don't want to pay the cost. Never add a top-level tests/ category without also adding it to .github/workflows/modelkit-ci.yml's path matrix. When two probe helpers have parallel structure and identical "doesn't change at runtime" justification, they should both have @lru_cache.
Not-tested: winml export (direct CLI path) now emits TracerWarning noise (UX-only). Eager-probe before device check in resolve_device is now near-zero cost on cached repeat calls — could be cleaned up for clarity, not perf.1 parent 8cca1fd commit ef01bb8
7 files changed
Lines changed: 63 additions & 89 deletions
File tree
- .github/workflows
- src/winml/modelkit
- onnx
- sysinfo
- tests
- cli
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
91 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
50 | 56 | | |
51 | 57 | | |
52 | | - | |
53 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
54 | 61 | | |
55 | | - | |
56 | | - | |
57 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
62 | | - | |
| 70 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | | - | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
84 | 95 | | |
85 | 96 | | |
86 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
Lines changed: 23 additions & 73 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
151 | 153 | | |
152 | 154 | | |
153 | 155 | | |
154 | | - | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
346 | 347 | | |
347 | 348 | | |
348 | 349 | | |
349 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
350 | 356 | | |
351 | 357 | | |
352 | 358 | | |
353 | 359 | | |
354 | | - | |
| 360 | + | |
355 | 361 | | |
356 | | - | |
357 | | - | |
| 362 | + | |
| 363 | + | |
358 | 364 | | |
359 | | - | |
| 365 | + | |
360 | 366 | | |
361 | 367 | | |
362 | | - | |
| 368 | + | |
363 | 369 | | |
364 | 370 | | |
365 | 371 | | |
| |||
393 | 399 | | |
394 | 400 | | |
395 | 401 | | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
File renamed without changes.
0 commit comments