Skip to content

Commit b6cac9c

Browse files
committed
Make model path mandatory in export to ONNX and restart the build.
1 parent 94a3d90 commit b6cac9c

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/Microsoft.ML.Onnx/SaveOnnxCommand.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed class SaveOnnxCommand : DataCommand.ImplBase<SaveOnnxCommand.Argum
2828

2929
public sealed class Arguments : DataCommand.ArgumentsBase
3030
{
31-
[Argument(ArgumentType.AtMostOnce, HelpText = "The path to write the output ONNX to.", SortOrder = 1)]
31+
[Argument(ArgumentType.Required, HelpText = "The path to write the output ONNX to.", SortOrder = 1)]
3232
public string Onnx;
3333

3434
[Argument(ArgumentType.AtMostOnce, HelpText = "The path to write the output JSON to.", SortOrder = 2)]
@@ -74,13 +74,18 @@ public SaveOnnxCommand(IHostEnvironment env, Arguments args)
7474
: base(env, args, LoadName)
7575
{
7676
Host.CheckValue(args, nameof(args));
77+
Host.CheckNonWhiteSpace(args.Onnx, nameof(args.Onnx));
78+
7779
Utils.CheckOptionalUserDirectory(args.Onnx, nameof(args.Onnx));
78-
_outputModelPath = string.IsNullOrWhiteSpace(args.Onnx) ? null : args.Onnx;
80+
_outputModelPath = args.Onnx;
7981
_outputJsonModelPath = string.IsNullOrWhiteSpace(args.Json) ? null : args.Json;
80-
if (args.Name == null && _outputModelPath != null)
82+
if (args.Name == null)
8183
_name = Path.GetFileNameWithoutExtension(_outputModelPath);
82-
else if (!string.IsNullOrWhiteSpace(args.Name))
84+
else
85+
{
86+
Host.CheckNonWhiteSpace(args.Name, nameof(args.Name));
8387
_name = args.Name;
88+
}
8489

8590
_loadPredictor = args.LoadPredictor;
8691
_inputsToDrop = CreateDropMap(args.InputsToDropArray ?? args.InputsToDrop?.Split(','));
@@ -237,12 +242,9 @@ private void Run(IChannel ch)
237242
}
238243

239244
var model = ctx.MakeModel();
240-
if (_outputModelPath != null)
241-
{
242-
using (var file = Host.CreateOutputFile(_outputModelPath))
243-
using (var stream = file.CreateWriteStream())
244-
model.WriteTo(stream);
245-
}
245+
using (var file = Host.CreateOutputFile(_outputModelPath))
246+
using (var stream = file.CreateWriteStream())
247+
model.WriteTo(stream);
246248

247249
if (_outputJsonModelPath != null)
248250
{

src/Microsoft.ML/Models/OnnxConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed partial class OnnxConverter
2828
/// path defined through the Json option.
2929
///
3030
/// This API supports the following arguments:
31-
/// <see cref="Onnx"/> indicates the file to write the ONNX protocol buffer file to. This is optional.
31+
/// <see cref="Onnx"/> indicates the file to write the ONNX protocol buffer file to. This is required.
3232
/// <see cref="Json"/> indicates the file to write the JSON representation of the ONNX model. This is optional.
3333
/// <see cref="Name"/> indicates the name property in the ONNX model. If left unspecified, it will
3434
/// be the extension-less name of the file specified in the onnx indicates the protocol buffer file

test/BaselineOutput/Common/EntryPoints/core_manifest.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,10 +2417,9 @@
24172417
"Name": "Onnx",
24182418
"Type": "String",
24192419
"Desc": "The path to write the output ONNX to.",
2420-
"Required": false,
2420+
"Required": true,
24212421
"SortOrder": 1.0,
2422-
"IsNullable": false,
2423-
"Default": null
2422+
"IsNullable": false
24242423
},
24252424
{
24262425
"Name": "Json",

0 commit comments

Comments
 (0)