Skip to content
Open
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
13 changes: 9 additions & 4 deletions Samples/WindowsML/Shared/cpp/ArgumentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Shared
return false;
}

bool disable_ep = false; // tracks --ep_policy DISABLE locally for validation

for (size_t i = 1; i < arguments.size(); ++i)
{
if (arguments[i] == L"--compile")
Expand Down Expand Up @@ -67,11 +69,14 @@ namespace Shared
}
else if (policy_str == L"DISABLE")
{
options.ep_policy = std::nullopt;
disable_ep = true;
options.ep_policy.reset();
}
else
{
std::wcout << L"Unknown EP policy: " << policy_str << L", using default (DISABLE)\n";
std::wcout << L"Unknown EP policy: " << policy_str << L"\n";
PrintUsage();
return false;
}
}
else if (arguments[i] == L"--perf_mode" && i + 1 < arguments.size())
Expand Down Expand Up @@ -117,8 +122,8 @@ namespace Shared
return false;
}

// Require one selection method
if (!options.ep_policy.has_value() && options.ep_name.empty())
// Require one selection method (unless disabled)
if (!disable_ep && !options.ep_policy.has_value() && options.ep_name.empty())
{
std::wcout << L"ERROR: You must specify one of --ep_policy or --ep_name.\n";
PrintUsage();
Expand Down
9 changes: 7 additions & 2 deletions Samples/WindowsML/Shared/cpp/InferenceEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace Shared
std::cout << "Using EP Selection Policy: " << ArgumentParser::ToString(options.ep_policy.value()) << std::endl;
sessionOptions.SetEpSelectionPolicy(options.ep_policy.value());
}
else
else if (!options.ep_name.empty())
{
// Use explicit configuration
// Use explicit EP configuration
std::cout << "Using explicit EP configuration" << std::endl;
ExecutionProviderManager::ConfigureSelectedExecutionProvider(
sessionOptions,
Expand All @@ -31,6 +31,11 @@ namespace Shared
options.device_type,
options.perf_mode);
}
Comment thread
yeelam-gordon marked this conversation as resolved.
else
{
// DISABLE: no EP policy or explicit EP — use ONNX Runtime defaults (CPU + DML)
std::cout << "EP selection disabled, using ONNX Runtime defaults" << std::endl;
}

return sessionOptions;
}
Expand Down
12 changes: 7 additions & 5 deletions Samples/WindowsML/Shared/cs/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static class ArgumentParser
public static Options ParseOptions(string[] args)
{
Options options = new();
bool disableEp = false; // tracks --ep_policy DISABLE locally for validation

for (int i = 0; i < args.Length; i++)
{
Expand All @@ -76,12 +77,13 @@ public static Options ParseOptions(string[] args)
options.EpPolicy = ExecutionProviderDevicePolicy.DEFAULT;
break;
case "DISABLE":
disableEp = true;
options.EpPolicy = null;
break;
default:
Console.WriteLine($"Unknown EP policy: {policyStr}, using default (DISABLE)");
options.EpPolicy = null;
break;
Console.WriteLine($"Unknown EP policy: {policyStr}");
PrintHelp();
throw new ArgumentException($"Unknown EP policy: {policyStr}", "--ep_policy");
}
Comment thread
yeelam-gordon marked this conversation as resolved.
}
break;
Expand Down Expand Up @@ -173,11 +175,11 @@ public static Options ParseOptions(string[] args)
throw new Exception("Mutually exclusive EP options");
}

if (!options.EpPolicy.HasValue && string.IsNullOrEmpty(options.EpName))
if (!disableEp && !options.EpPolicy.HasValue && string.IsNullOrEmpty(options.EpName))
{
Console.WriteLine("ERROR: You must specify one of --ep_policy or --ep_name.");
PrintHelp();
throw new Exception("Missing EP selection");
throw new ArgumentException("Missing EP selection");
}

if (!string.IsNullOrEmpty(options.DeviceType))
Expand Down
8 changes: 3 additions & 5 deletions Samples/WindowsML/Shared/cs/ModelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ public static InferenceSession CreateSession(string modelPath, Options options,
}
else
{
throw new Exception("Could not find an EP selection policy or an explicit execution provider.");
// DISABLE: no EP policy or explicit EP — use ONNX Runtime defaults (CPU + DML)
Console.WriteLine("EP selection disabled, using ONNX Runtime defaults");
}

return new InferenceSession(modelPath, sessionOptions);
Expand Down Expand Up @@ -344,10 +345,7 @@ public static string ResolveActualModelPath(Options options, string modelPath, s
throw new Exception("Failed to configure selected execution provider");
}
}
else
{
throw new Exception("Could not find an EP selection policy or an explicit execution provider.");
}
// else: DISABLE — compile with ONNX Runtime defaults
Comment thread
yeelam-gordon marked this conversation as resolved.

CompileModel(tempSessionOptions, modelPath, compiledModelPath);

Expand Down
Loading