Skip to content

Commit 3ac69ce

Browse files
committed
Internalization of more model saving infrastructure.
1 parent 9a80244 commit 3ac69ce

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

src/Microsoft.ML.Data/Dirty/PredictorUtils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static void SaveText(IChannel ch, IPredictor predictor, RoleMappedSchema
6464
}
6565

6666
/// <summary>
67-
/// Save the model in binary format (if it can save itself)
67+
/// Save the model in binary format (if it can save itself).
6868
/// </summary>
6969
public static void SaveBinary(IChannel ch, IPredictor predictor, BinaryWriter writer)
7070
{

src/Microsoft.ML.Data/EntryPoints/InputBase.cs

+22-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using Microsoft.Data.DataView;
88
using Microsoft.ML.CommandLine;
9+
using Microsoft.ML.Core.Data;
910
using Microsoft.ML.Data;
1011
using Microsoft.ML.Data.IO;
1112
using Microsoft.ML.Internal.Calibration;
@@ -18,11 +19,17 @@ namespace Microsoft.ML.EntryPoints
1819
[TlcModule.EntryPointKind(typeof(CommonInputs.ITransformInput))]
1920
public abstract class TransformInputBase
2021
{
22+
/// <summary>
23+
/// The input dataset. Used only in entry-point methods, since the normal API mechanism for feeding in a dataset to
24+
/// create an <see cref="ITransformer"/> is to use the <see cref="IEstimator{TTransformer}.Fit(IDataView)"/> method.
25+
/// </summary>
26+
[BestFriend]
2127
[Argument(ArgumentType.Required, HelpText = "Input dataset", Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly, SortOrder = 1)]
22-
public IDataView Data;
28+
internal IDataView Data;
2329
}
2430

25-
public enum CachingOptions
31+
[BestFriend]
32+
internal enum CachingOptions
2633
{
2734
Auto,
2835
Memory,
@@ -37,10 +44,13 @@ public enum CachingOptions
3744
public abstract class LearnerInputBase
3845
{
3946
/// <summary>
40-
/// The data to be used for training.
47+
/// The data to be used for training. Used only in entry-points, since in the API the expected mechanism is
48+
/// that the user iwll use the <see cref="IEstimator{TTransformer}.Fit(IDataView)"/> or some other train
49+
/// method.
4150
/// </summary>
51+
[BestFriend]
4252
[Argument(ArgumentType.Required, ShortName = "data", HelpText = "The data to be used for training", SortOrder = 1, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
43-
public IDataView TrainingData;
53+
internal IDataView TrainingData;
4454

4555
/// <summary>
4656
/// Column to use for features.
@@ -49,16 +59,20 @@ public abstract class LearnerInputBase
4959
public string FeatureColumn = DefaultColumnNames.Features;
5060

5161
/// <summary>
52-
/// Normalize option for the feature column.
62+
/// Normalize option for the feature column. Used only in entry-points, since in the API the user is expected to do this themselves.
5363
/// </summary>
64+
[BestFriend]
5465
[Argument(ArgumentType.AtMostOnce, HelpText = "Normalize option for the feature column", ShortName = "norm", SortOrder = 5, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
55-
public NormalizeOption NormalizeFeatures = NormalizeOption.Auto;
66+
internal NormalizeOption NormalizeFeatures = NormalizeOption.Auto;
5667

5768
/// <summary>
58-
/// Whether learner should cache input training data.
69+
/// Whether learner should cache input training data. Used only in entry-points, since the intended API mechanism
70+
/// is that the user will use the <see cref="DataOperationsCatalog.Cache(IDataView, string[])"/> or other method
71+
/// like <see cref="EstimatorChain{TLastTransformer}.AppendCacheCheckpoint(IHostEnvironment)"/>.
5972
/// </summary>
73+
[BestFriend]
6074
[Argument(ArgumentType.LastOccurenceWins, HelpText = "Whether learner should cache input training data", ShortName = "cache", SortOrder = 6, Visibility = ArgumentAttribute.VisibilityType.EntryPointsOnly)]
61-
public CachingOptions Caching = CachingOptions.Auto;
75+
internal CachingOptions Caching = CachingOptions.Auto;
6276
}
6377

6478
/// <summary>

src/Microsoft.ML.Data/Model/Onnx/OnnxNode.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace Microsoft.ML.Model.Onnx
1313
/// That method creates a with inputs and outputs, but this object can modify the node further
1414
/// by adding attributes (in ONNX parlance, attributes are more or less constant parameterizations).
1515
/// </summary>
16-
public abstract class OnnxNode
16+
[BestFriend]
17+
internal abstract class OnnxNode
1718
{
1819
public abstract void AddAttribute(string argName, double value);
1920
public abstract void AddAttribute(string argName, long value);

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ public interface ICanSaveModel
2424
}
2525

2626
/// <summary>
27-
/// For saving to a single stream.
27+
/// For saving to a single stream. Note that this interface is mostly deprecated in favor of
28+
/// saving more comprehensive and composable "model" objects, via <see cref="ICanSaveModel"/>.
2829
/// </summary>
29-
public interface ICanSaveInBinaryFormat
30+
[BestFriend]
31+
internal interface ICanSaveInBinaryFormat
3032
{
3133
void SaveAsBinary(BinaryWriter writer);
3234
}

src/Microsoft.ML.Data/Prediction/Calibrator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ private static NaiveCalibrator Create(IHostEnvironment env, ModelLoadContext ctx
10701070
return new NaiveCalibrator(env, ctx);
10711071
}
10721072

1073-
public void SaveAsBinary(BinaryWriter writer)
1073+
void ICanSaveInBinaryFormat.SaveAsBinary(BinaryWriter writer)
10741074
{
10751075
ModelSaveContext.Save(writer, SaveCore);
10761076
}
@@ -1717,7 +1717,7 @@ private static PavCalibrator Create(IHostEnvironment env, ModelLoadContext ctx)
17171717
return new PavCalibrator(env, ctx);
17181718
}
17191719

1720-
public void SaveAsBinary(BinaryWriter writer)
1720+
void ICanSaveInBinaryFormat.SaveAsBinary(BinaryWriter writer)
17211721
{
17221722
ModelSaveContext.Save(writer, SaveCore);
17231723
}

0 commit comments

Comments
 (0)