Skip to content

Commit d885ebc

Browse files
authored
Movement and Internalization Phase 2 (#1626)
* Internalize ITrainer * Internalize TrainContext * Internalization of environment implementations * Internalize HostEnvironmentBase/ConsoleEnvironment * Limit usage of ConsoleEnvironment * Internalize ICommandLineComponentFactory * Internalize ICommand and all implementations * Internalize much of the entry-point attribute support * Internalize much of the channel and message infrastructure * Fix two tests from failing by writing to same path from two concurrently running tests.
1 parent 31ee766 commit d885ebc

File tree

169 files changed

+4081
-4377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+4081
-4377
lines changed

Microsoft.ML.sln

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.CpuMath", "src
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.PipelineInference", "src\Microsoft.ML.PipelineInference\Microsoft.ML.PipelineInference.csproj", "{2D7391C9-8254-4B8F-BF26-FADAF8F02F44}"
1919
EndProject
20-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.InferenceTesting", "test\Microsoft.ML.InferenceTesting\Microsoft.ML.InferenceTesting.csproj", "{E278EC99-E6EE-49FE-92E6-0A309A478D98}"
21-
EndProject
2220
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Data", "src\Microsoft.ML.Data\Microsoft.ML.Data.csproj", "{AD92D96B-0E96-4F22-8DCE-892E13B1F282}"
2321
EndProject
2422
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Onnx", "src\Microsoft.ML.Onnx\Microsoft.ML.Onnx.csproj", "{65D0603E-B96C-4DFC-BDD1-705891B88C18}"
@@ -175,14 +173,6 @@ Global
175173
{2D7391C9-8254-4B8F-BF26-FADAF8F02F44}.Release|Any CPU.Build.0 = Release|Any CPU
176174
{2D7391C9-8254-4B8F-BF26-FADAF8F02F44}.Release-Intrinsics|Any CPU.ActiveCfg = Release-Intrinsics|Any CPU
177175
{2D7391C9-8254-4B8F-BF26-FADAF8F02F44}.Release-Intrinsics|Any CPU.Build.0 = Release-Intrinsics|Any CPU
178-
{E278EC99-E6EE-49FE-92E6-0A309A478D98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
179-
{E278EC99-E6EE-49FE-92E6-0A309A478D98}.Debug|Any CPU.Build.0 = Debug|Any CPU
180-
{E278EC99-E6EE-49FE-92E6-0A309A478D98}.Debug-Intrinsics|Any CPU.ActiveCfg = Debug-Intrinsics|Any CPU
181-
{E278EC99-E6EE-49FE-92E6-0A309A478D98}.Debug-Intrinsics|Any CPU.Build.0 = Debug-Intrinsics|Any CPU
182-
{E278EC99-E6EE-49FE-92E6-0A309A478D98}.Release|Any CPU.ActiveCfg = Release|Any CPU
183-
{E278EC99-E6EE-49FE-92E6-0A309A478D98}.Release|Any CPU.Build.0 = Release|Any CPU
184-
{E278EC99-E6EE-49FE-92E6-0A309A478D98}.Release-Intrinsics|Any CPU.ActiveCfg = Release-Intrinsics|Any CPU
185-
{E278EC99-E6EE-49FE-92E6-0A309A478D98}.Release-Intrinsics|Any CPU.Build.0 = Release-Intrinsics|Any CPU
186176
{AD92D96B-0E96-4F22-8DCE-892E13B1F282}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
187177
{AD92D96B-0E96-4F22-8DCE-892E13B1F282}.Debug|Any CPU.Build.0 = Debug|Any CPU
188178
{AD92D96B-0E96-4F22-8DCE-892E13B1F282}.Debug-Intrinsics|Any CPU.ActiveCfg = Debug-Intrinsics|Any CPU
@@ -520,7 +510,6 @@ Global
520510
{EC743D1D-7691-43B7-B9B0-5F2F7018A8F6} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
521511
{46F2F967-C23F-4076-858D-33F7DA9BD2DA} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
522512
{2D7391C9-8254-4B8F-BF26-FADAF8F02F44} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
523-
{E278EC99-E6EE-49FE-92E6-0A309A478D98} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
524513
{AD92D96B-0E96-4F22-8DCE-892E13B1F282} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
525514
{65D0603E-B96C-4DFC-BDD1-705891B88C18} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
526515
{707BB22C-7E5F-497A-8C2F-74578F675705} = {09EADF06-BE25-4228-AB53-95AE3E15B530}

src/Microsoft.ML.Api/GenerateCodeCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Microsoft.ML.Runtime.Api
2424
///
2525
/// REVIEW: Consider adding support for generating VBuffers instead of arrays, maybe for high dimensionality vectors.
2626
/// </summary>
27-
public sealed class GenerateCodeCommand : ICommand
27+
internal sealed class GenerateCodeCommand : ICommand
2828
{
2929
public const string LoadName = "GenerateSamplePredictionCode";
3030
private const string CodeTemplatePath = "Microsoft.ML.Api.GeneratedCodeTemplate.csresource";

src/Microsoft.ML.Api/TypedCursor.cs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,6 @@ public ICursor GetRootCursor()
528528
/// </summary>
529529
public static class CursoringUtils
530530
{
531-
private const string NeedEnvObsoleteMessage = "This method is obsolete. Please use the overload that takes an additional 'env' argument. An environment can be created via new LocalEnvironment().";
532-
533531
/// <summary>
534532
/// Generate a strongly-typed cursorable wrapper of the <see cref="IDataView"/>.
535533
/// </summary>
@@ -550,24 +548,6 @@ public static ICursorable<TRow> AsCursorable<TRow>(this IDataView data, IHostEnv
550548
return TypedCursorable<TRow>.Create(env, data, ignoreMissingColumns, schemaDefinition);
551549
}
552550

553-
/// <summary>
554-
/// Generate a strongly-typed cursorable wrapper of the <see cref="IDataView"/>.
555-
/// </summary>
556-
/// <typeparam name="TRow">The user-defined row type.</typeparam>
557-
/// <param name="data">The underlying data view.</param>
558-
/// <param name="ignoreMissingColumns">Whether to ignore the case when a requested column is not present in the data view.</param>
559-
/// <param name="schemaDefinition">Optional user-provided schema definition. If it is not present, the schema is inferred from the definition of T.</param>
560-
/// <returns>The cursorable wrapper of <paramref name="data"/>.</returns>
561-
[Obsolete(NeedEnvObsoleteMessage)]
562-
public static ICursorable<TRow> AsCursorable<TRow>(this IDataView data, bool ignoreMissingColumns = false,
563-
SchemaDefinition schemaDefinition = null)
564-
where TRow : class, new()
565-
{
566-
// REVIEW: Take an env as a parameter.
567-
var env = new ConsoleEnvironment();
568-
return data.AsCursorable<TRow>(env, ignoreMissingColumns, schemaDefinition);
569-
}
570-
571551
/// <summary>
572552
/// Convert an <see cref="IDataView"/> into a strongly-typed <see cref="IEnumerable{TRow}"/>.
573553
/// </summary>
@@ -589,24 +569,5 @@ public static IEnumerable<TRow> AsEnumerable<TRow>(this IDataView data, IHostEnv
589569
var engine = new PipeEngine<TRow>(env, data, ignoreMissingColumns, schemaDefinition);
590570
return engine.RunPipe(reuseRowObject);
591571
}
592-
593-
/// <summary>
594-
/// Convert an <see cref="IDataView"/> into a strongly-typed <see cref="IEnumerable{TRow}"/>.
595-
/// </summary>
596-
/// <typeparam name="TRow">The user-defined row type.</typeparam>
597-
/// <param name="data">The underlying data view.</param>
598-
/// <param name="reuseRowObject">Whether to return the same object on every row, or allocate a new one per row.</param>
599-
/// <param name="ignoreMissingColumns">Whether to ignore the case when a requested column is not present in the data view.</param>
600-
/// <param name="schemaDefinition">Optional user-provided schema definition. If it is not present, the schema is inferred from the definition of T.</param>
601-
/// <returns>The <see cref="IEnumerable{TRow}"/> that holds the data in <paramref name="data"/>. It can be enumerated multiple times.</returns>
602-
[Obsolete(NeedEnvObsoleteMessage)]
603-
public static IEnumerable<TRow> AsEnumerable<TRow>(this IDataView data, bool reuseRowObject,
604-
bool ignoreMissingColumns = false, SchemaDefinition schemaDefinition = null)
605-
where TRow : class, new()
606-
{
607-
// REVIEW: Take an env as a parameter.
608-
var env = new ConsoleEnvironment();
609-
return data.AsEnumerable<TRow>(env, reuseRowObject, ignoreMissingColumns, schemaDefinition);
610-
}
611572
}
612573
}

src/Microsoft.ML.Core/CommandLine/CmdParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ internal enum SettingsFlags
4040
///
4141
/// This allows components to be created by name, signature type, and a settings string.
4242
/// </summary>
43-
public interface ICommandLineComponentFactory : IComponentFactory
43+
[BestFriend]
44+
internal interface ICommandLineComponentFactory : IComponentFactory
4445
{
4546
Type SignatureType { get; }
4647
string Name { get; }

src/Common/AssemblyLoadingUtils.cs renamed to src/Microsoft.ML.Core/ComponentModel/AssemblyLoadingUtils.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
using System;
77
using System.IO;
88
using System.IO.Compression;
9-
using System.Linq;
109
using System.Reflection;
1110

1211
namespace Microsoft.ML.Runtime
1312
{
13+
[Obsolete("The usage for this is intended for the internal command line utilities and is not intended for anything related to the API. " +
14+
"Please consider another way of doing whatever it is you're attempting to accomplish.")]
15+
[BestFriend]
1416
internal static class AssemblyLoadingUtils
1517
{
1618
/// <summary>

src/Microsoft.ML.Core/Data/ICommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ namespace Microsoft.ML.Runtime.Command
1111
/// <summary>
1212
/// The signature for commands.
1313
/// </summary>
14-
public delegate void SignatureCommand();
14+
[BestFriend]
15+
internal delegate void SignatureCommand();
1516

16-
public interface ICommand
17+
[BestFriend]
18+
internal interface ICommand
1719
{
1820
void Run();
1921
}

src/Microsoft.ML.Core/Data/IFileHandle.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public sealed class SimpleFileHandle : IFileHandle
6161
// handle has been disposed.
6262
private List<Stream> _streams;
6363

64-
private bool IsDisposed { get { return _streams == null; } }
64+
private bool IsDisposed => _streams == null;
6565

6666
public SimpleFileHandle(IExceptionContext ectx, string path, bool needsWrite, bool autoDelete)
6767
{
@@ -84,15 +84,9 @@ public SimpleFileHandle(IExceptionContext ectx, string path, bool needsWrite, bo
8484
_streams = new List<Stream>();
8585
}
8686

87-
public bool CanWrite
88-
{
89-
get { return !_wrote && !IsDisposed; }
90-
}
87+
public bool CanWrite => !_wrote && !IsDisposed;
9188

92-
public bool CanRead
93-
{
94-
get { return _wrote && !IsDisposed; }
95-
}
89+
public bool CanRead => _wrote && !IsDisposed;
9690

9791
public void Dispose()
9892
{

src/Microsoft.ML.Core/Data/IHostEnvironment.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public interface IHostEnvironment : IChannelProvider, IProgressChannelProvider
7272
/// The suffix and prefix are optional. A common use for suffix is to specify an extension, eg, ".txt".
7373
/// The use of suffix and prefix, including whether they have any affect, is up to the host environment.
7474
/// </summary>
75+
[Obsolete("The host environment is not disposable, so it is inappropriate to use this method. " +
76+
"Please handle your own temporary files within the component yourself, including their proper disposal and deletion.")]
7577
IFileHandle CreateTempFile(string suffix = null, string prefix = null);
7678

7779
/// <summary>
@@ -188,7 +190,8 @@ public readonly struct ChannelMessage
188190
/// </summary>
189191
public string Message => _args != null ? string.Format(_message, _args) : _message;
190192

191-
public ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string message)
193+
[BestFriend]
194+
internal ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string message)
192195
{
193196
Contracts.CheckNonEmpty(message, nameof(message));
194197
Kind = kind;
@@ -197,7 +200,8 @@ public ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, s
197200
_args = null;
198201
}
199202

200-
public ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string fmt, params object[] args)
203+
[BestFriend]
204+
internal ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string fmt, params object[] args)
201205
{
202206
Contracts.CheckNonEmpty(fmt, nameof(fmt));
203207
Contracts.CheckNonEmpty(args, nameof(args));

src/Microsoft.ML.Core/Data/ProgressReporter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace Microsoft.ML.Runtime.Data
1414
/// <summary>
1515
/// The progress reporting classes used by <see cref="HostEnvironmentBase{THostEnvironmentBase}"/> descendants.
1616
/// </summary>
17-
public static class ProgressReporting
17+
[BestFriend]
18+
internal static class ProgressReporting
1819
{
1920
/// <summary>
2021
/// The progress channel for <see cref="ConsoleEnvironment"/>.

src/Microsoft.ML.Core/Data/ServerChannel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace Microsoft.ML.Runtime
1919
/// delegates will be published in some fashion, with the target scenario being
2020
/// that the library will publish some sort of restful API.
2121
/// </summary>
22-
public sealed class ServerChannel : ServerChannel.IPendingBundleNotification, IDisposable
22+
[BestFriend]
23+
internal sealed class ServerChannel : ServerChannel.IPendingBundleNotification, IDisposable
2324
{
2425
// See ServerChannel.md for a more elaborate discussion of high level usage and design.
2526
private readonly IChannelProvider _chp;
@@ -250,7 +251,8 @@ public void AddDoneAction(Action onDone)
250251
}
251252
}
252253

253-
public static class ServerChannelUtilities
254+
[BestFriend]
255+
internal static class ServerChannelUtilities
254256
{
255257
/// <summary>
256258
/// Convenience method for <see cref="ServerChannel.Start"/> that looks more idiomatic to typical

0 commit comments

Comments
 (0)