Skip to content

Commit 533ebe7

Browse files
committed
Keep the with loader save order the same as with schema overload, with ITransformer always first.
1 parent bf46cda commit 533ebe7

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ private static TransformerChain<ITransformer> CreateChain(ITransformer transform
3939
/// <summary>
4040
/// Save a transformer model and the loader used to create its input data to the stream.
4141
/// </summary>
42-
/// <param name="loader">The loader that was used to create data to train the model.</param>
4342
/// <param name="model">The trained model to be saved. Note that this can be <see langword="null"/>, as a shorthand
4443
/// for an empty data set. Upon loading with <see cref="LoadWithDataLoader(Stream, out IDataLoader{IMultiStreamSource})"/>
4544
/// the returned valued will be an empty <see cref="TransformerChain{TLastTransformer}"/>.</param>
45+
/// <param name="loader">The loader that was used to create data to train the model.</param>
4646
/// <param name="stream">A writeable, seekable stream to save to.</param>
47-
public void Save<TSource>(IDataLoader<TSource> loader, ITransformer model, Stream stream)
47+
public void Save<TSource>(ITransformer model, IDataLoader<TSource> loader, Stream stream)
4848
{
4949
_env.CheckValue(loader, nameof(loader));
5050
_env.CheckValueOrNull(model);
@@ -65,19 +65,19 @@ public void Save<TSource>(IDataLoader<TSource> loader, ITransformer model, Strea
6565
/// <summary>
6666
/// Save a transformer model and the loader used to create its input data to the file.
6767
/// </summary>
68-
/// <param name="loader">The loader that was used to create data to train the model.</param>
6968
/// <param name="model">The trained model to be saved. Note that this can be <see langword="null"/>, as a shorthand
7069
/// for an empty data set. Upon loading with <see cref="LoadWithDataLoader(Stream, out IDataLoader{IMultiStreamSource})"/>
7170
/// the returned valued will be an empty <see cref="TransformerChain{TLastTransformer}"/>.</param>
71+
/// <param name="loader">The loader that was used to create data to train the model.</param>
7272
/// <param name="filePath">Path where model should be saved.</param>
73-
public void Save<TSource>(IDataLoader<TSource> loader, ITransformer model, string filePath)
73+
public void Save<TSource>(ITransformer model, IDataLoader<TSource> loader, string filePath)
7474
{
75-
_env.CheckValue(loader, nameof(loader));
7675
_env.CheckValueOrNull(model);
76+
_env.CheckValue(loader, nameof(loader));
7777
_env.CheckNonEmpty(filePath, nameof(filePath));
7878

7979
using (var stream = File.Create(filePath))
80-
Save(loader, model, stream);
80+
Save(model, loader, stream);
8181
}
8282

8383
/// <summary>

test/Microsoft.ML.Functional.Tests/ModelLoading.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public void LoadModelAndExtractPredictor()
6666
// In this case we have combined the loader with the transformer model to form a "composite" loader, and are just
6767
// saving that one loader to this file.
6868
string compositeLoaderModelPath = GetOutputPath(FullTestName + "-composite-model.zip");
69-
_ml.Model.Save(compositeLoaderModel, null, compositeLoaderModelPath);
69+
_ml.Model.Save(null, compositeLoaderModel, compositeLoaderModelPath);
7070

7171
// In this case we are saving the transformer model, as well as the associated data loader.
7272
string loaderAndTransformerModelPath = GetOutputPath(FullTestName + "-loader-transformer.zip");
73-
_ml.Model.Save(loader, transformerModel, loaderAndTransformerModelPath);
73+
_ml.Model.Save(transformerModel, loader, loaderAndTransformerModelPath);
7474

7575
ITransformer loadedTransformerModel;
7676
IDataLoader<IMultiStreamSource> loadedCompositeLoader;
@@ -141,7 +141,7 @@ public void SaveAndLoadModelWithLoader()
141141

142142
// Save and reload.
143143
string modelPath = GetOutputPath(FullTestName + "-model.zip");
144-
_ml.Model.Save(loader, model, modelPath);
144+
_ml.Model.Save(model, loader, modelPath);
145145

146146
IDataLoader<IMultiStreamSource> loadedLoader;
147147
ITransformer loadedModelWithoutLoader;
@@ -196,7 +196,7 @@ public void LoadSchemaAndCreateNewData()
196196

197197
// Save and reload.
198198
string modelPath = GetOutputPath(FullTestName + "-model.zip");
199-
_ml.Model.Save(loader, model, modelPath);
199+
_ml.Model.Save(model, loader, modelPath);
200200

201201
ITransformer loadedModel;
202202
DataViewSchema loadedSchema;
@@ -219,7 +219,7 @@ public void SaveTextLoaderAndLoad()
219219
var loader = _ml.Data.CreateTextLoader<InputData>(hasHeader: true, dataSample: file);
220220

221221
string modelPath = GetOutputPath(FullTestName + "-model.zip");
222-
_ml.Model.Save(loader, null, modelPath);
222+
_ml.Model.Save(null, loader, modelPath);
223223

224224
Load(modelPath, out var loadedWithSchema, out var loadedSchema,
225225
out var loadedWithLoader, out var loadedLoaderWithTransformer);
@@ -248,7 +248,7 @@ public void SaveCompositeLoaderAndLoad()
248248
var model = composite.Fit(file);
249249

250250
string modelPath = GetOutputPath(FullTestName + "-model.zip");
251-
_ml.Model.Save(model, null, modelPath);
251+
_ml.Model.Save(null, model, modelPath);
252252

253253
Load(modelPath, out var loadedWithSchema, out var loadedSchema,
254254
out var loadedWithLoader, out var loadedLoaderWithTransformer);
@@ -294,7 +294,7 @@ public void SaveLoaderAndTransformerAndLoad()
294294
Assert.True(expectedInputSchema["Features"].HasSlotNames());
295295

296296
string modelPath = GetOutputPath(FullTestName + "-model.zip");
297-
_ml.Model.Save(loader, model, modelPath);
297+
_ml.Model.Save(model, loader, modelPath);
298298

299299
// Reload the loader and schema.
300300
Load(modelPath, out var loadedWithSchema, out var loadedInputSchema,

0 commit comments

Comments
 (0)