Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/winml/modelkit/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,9 @@ def _validate_loader_tasks_for_model(
show_default=True,
help="Enable quantization (use --no-quant to skip, overrides config)",
)
@click.option(
"--no-compile/--compile",
"no_compile",
@cli_utils.compile_option(
default=None,
help="Override compilation. --compile forces enable (config must have a compile section). "
help_text="Override compilation. --compile forces enable (config must have a compile section). "
"--no-compile forces skip. Default: inherit from config; when auto-generating "
"config (no -c), compilation is off unless --compile is passed.",
)
Expand Down
6 changes: 2 additions & 4 deletions src/winml/modelkit/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ def _apply_stage_overrides(cfg: Any, *, no_quant: bool, no_compile: bool) -> Non
show_default=True,
help="Include quantization in generated config (use --no-quant to exclude, sets quant=None)",
)
@click.option(
"--no-compile/--compile",
"no_compile",
@cli_utils.compile_option(
default=True,
help="Exclude compilation from generated config (sets compile=None). Default: exclude.",
help_text="Exclude compilation from generated config (sets compile=None). Default: exclude.",
)
@cli_utils.trust_remote_code_option()
@cli_utils.verbosity_options()
Expand Down
9 changes: 9 additions & 0 deletions src/winml/modelkit/commands/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class BenchmarkConfig:
batch_size: int = 1
output_path: Path | None = None
no_quantize: bool = False
no_compile: bool = True
rebuild: bool = False
ignore_cache: bool = False
skip_build: bool = True
Expand Down Expand Up @@ -361,6 +362,7 @@ def _load_model(self) -> None:
"force_rebuild": force_rebuild,
"shape_config": self.config.shape_config,
"allow_unsupported_nodes": self.config.allow_unsupported_nodes,
"no_compile": self.config.no_compile,
}

if is_onnx:
Expand Down Expand Up @@ -1086,6 +1088,11 @@ def _run_simple_loop(
help="Build from scratch in a temp folder (discard after benchmarking)",
)
@cli_utils.skip_build_option()
@cli_utils.compile_option(
default=True,
help_text="Compile the model during build. Default: off (skip compilation); "
"use --compile to enable.",
)
@cli_utils.allow_unsupported_nodes_option()
@click.option(
"--module",
Expand Down Expand Up @@ -1131,6 +1138,7 @@ def perf(
rebuild: bool,
ignore_cache: bool,
skip_build: bool,
no_compile: bool,
allow_unsupported_nodes: bool,
module_class: str | None,
monitor: bool,
Expand Down Expand Up @@ -1270,6 +1278,7 @@ def perf(
rebuild=rebuild,
ignore_cache=ignore_cache,
skip_build=skip_build,
no_compile=no_compile,
allow_unsupported_nodes=allow_unsupported_nodes,
monitor=monitor,
ep=ep,
Expand Down
7 changes: 7 additions & 0 deletions src/winml/modelkit/config/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def generate_onnx_build_config(
precision: str = "auto",
ep: EPNameOrAlias | None = None,
override: WinMLBuildConfig | None = None,
no_compile: bool = False,
) -> WinMLBuildConfig:
"""Generate build config for a pre-exported ONNX model (Scenario D).

Expand All @@ -388,6 +389,8 @@ def generate_onnx_build_config(
"int16", or "w{x}a{y}" e.g. "w8a16").
ep: Explicit execution provider override.
override: Partial WinMLBuildConfig to merge on top of auto-detected.
no_compile: If True, drop the compile stage (compile=None) regardless
of device/precision policy or override. Applied last so it always wins.

Returns:
WinMLBuildConfig with export=None and device/precision applied.
Expand Down Expand Up @@ -443,6 +446,10 @@ def generate_onnx_build_config(
# "already exported, skip export stage".
config.export = None

# no_compile overrides policy and override — applied last so it always wins
if no_compile:
config.compile = None

return config


Expand Down
2 changes: 2 additions & 0 deletions src/winml/modelkit/models/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def from_onnx(
use_cache: bool = True,
force_rebuild: bool = False,
skip_build: bool = False,
no_compile: bool = False,
allow_unsupported_nodes: bool = False,
session_options: Any | None = None,
hf_config: PretrainedConfig | None = None,
Expand Down Expand Up @@ -181,6 +182,7 @@ def from_onnx(
precision=precision,
ep=ep,
override=config,
no_compile=no_compile,
)

# Resolve task from explicit arg or generated config
Expand Down
34 changes: 34 additions & 0 deletions src/winml/modelkit/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,40 @@ def _warn_callback(ctx: click.Context, param: click.Parameter, value: bool) -> b
)


def compile_option(
default: bool | None = None,
help_text: str | None = None,
) -> Callable[[F], F]:
"""Add shared ``--no-compile/--compile`` toggle to a Click command.

The flag is exposed as the ``no_compile`` parameter. Note the inverted
sense — ``--no-compile`` maps to ``no_compile=True``:

* ``--no-compile`` -> ``no_compile=True`` (force skip compilation)
* ``--compile`` -> ``no_compile=False`` (force enable compilation)

Args:
default: Value for ``no_compile`` when neither flag is passed.
``None`` -> tri-state inherit (e.g. ``winml build`` inherits from
the config file); ``True`` -> exclude compilation by default
(e.g. ``winml config`` omits the compile section).
help_text: Command-specific help string. Falls back to a generic
description when not provided.

Returns:
Decorator function.
"""
if help_text is None:
help_text = "Override compilation. --compile forces enable; --no-compile forces skip."

return click.option(
"--no-compile/--compile",
"no_compile",
default=default,
help=help_text,
)


def allow_unsupported_nodes_option(optional_message: str | None = None) -> Callable[[F], F]:
"""Add shared --allow-unsupported-nodes option to a Click command.

Expand Down
Loading