Skip to content

Commit eca4c6e

Browse files
committed
Internalize much of the entry-point attribute support
1 parent 9ebc122 commit eca4c6e

File tree

8 files changed

+31
-16
lines changed

8 files changed

+31
-16
lines changed

src/Microsoft.ML.Core/EntryPoints/EntryPointModuleAttribute.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ namespace Microsoft.ML.Runtime.EntryPoints
99
/// <summary>
1010
/// This is a signature for classes that are 'holders' of entry points and components.
1111
/// </summary>
12-
public delegate void SignatureEntryPointModule();
12+
[BestFriend]
13+
internal delegate void SignatureEntryPointModule();
1314

1415
/// <summary>
1516
/// A simplified assembly attribute for marking EntryPoint modules.
1617
/// </summary>
1718
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
18-
public sealed class EntryPointModuleAttribute : LoadableClassAttributeBase
19+
[BestFriend]
20+
internal sealed class EntryPointModuleAttribute : LoadableClassAttributeBase
1921
{
2022
public EntryPointModuleAttribute(Type loaderType)
2123
: base(null, typeof(void), loaderType, null, new[] { typeof(SignatureEntryPointModule) }, loaderType.FullName)

src/Microsoft.ML.Core/EntryPoints/EntryPointUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
namespace Microsoft.ML.Runtime.EntryPoints
1414
{
15-
public static class EntryPointUtils
15+
[BestFriend]
16+
internal static class EntryPointUtils
1617
{
1718
private static bool IsValueWithinRange<T>(TlcModule.RangeAttribute range, object obj)
1819
{

src/Microsoft.ML.Core/EntryPoints/IMlState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ namespace Microsoft.ML.Runtime.EntryPoints
1010
/// black box to the graph. The macro itself will then case to the concrete type.
1111
/// </summary>
1212
public interface IMlState
13-
{}
13+
{ }
1414
}

src/Microsoft.ML.Core/EntryPoints/ModuleArgs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace Microsoft.ML.Runtime.EntryPoints
1818
/// This class defines attributes to annotate module inputs, outputs, entry points etc. when defining
1919
/// the module interface.
2020
/// </summary>
21-
public static class TlcModule
21+
[BestFriend]
22+
internal static class TlcModule
2223
{
2324
/// <summary>
2425
/// An attribute used to annotate the component.

src/Microsoft.ML.Legacy/Runtime/EntryPoints/JsonUtils/GraphRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void SetInput<TInput>(string name, TInput input)
140140
/// <summary>
141141
/// Get the data kind of a particular port.
142142
/// </summary>
143-
public TlcModule.DataKind GetPortDataKind(string name)
143+
internal TlcModule.DataKind GetPortDataKind(string name)
144144
{
145145
_host.CheckNonEmpty(name, nameof(name));
146146
EntryPointVariable variable;

src/Microsoft.ML.PipelineInference/AutoMlUtils.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public static AutoInference.LevelDependencyMap ComputeColumnResponsibilities(IDa
338338
return mapping;
339339
}
340340

341-
public static TlcModule.SweepableParamAttribute[] GetSweepRanges(Type learnerInputType)
341+
internal static TlcModule.SweepableParamAttribute[] GetSweepRanges(Type learnerInputType)
342342
{
343343
var paramSet = new List<TlcModule.SweepableParamAttribute>();
344344
foreach (var prop in learnerInputType.GetProperties(BindingFlags.Instance |
@@ -370,7 +370,7 @@ public static TlcModule.SweepableParamAttribute[] GetSweepRanges(Type learnerInp
370370
return paramSet.ToArray();
371371
}
372372

373-
public static IValueGenerator ToIValueGenerator(TlcModule.SweepableParamAttribute attr)
373+
internal static IValueGenerator ToIValueGenerator(TlcModule.SweepableParamAttribute attr)
374374
{
375375
if (attr is TlcModule.SweepableLongParamAttribute sweepableLongParamAttr)
376376
{
@@ -430,7 +430,7 @@ private static void SetValue(PropertyInfo pi, IComparable value, object entryPoi
430430
/// <summary>
431431
/// Updates properties of entryPointObj instance based on the values in sweepParams
432432
/// </summary>
433-
public static bool UpdateProperties(object entryPointObj, TlcModule.SweepableParamAttribute[] sweepParams)
433+
internal static bool UpdateProperties(object entryPointObj, TlcModule.SweepableParamAttribute[] sweepParams)
434434
{
435435
bool result = true;
436436
foreach (var param in sweepParams)
@@ -501,7 +501,7 @@ public static void PopulateSweepableParams(RecipeInference.SuggestedRecipe.Sugge
501501
}
502502
}
503503

504-
public static bool CheckEntryPointStateMatchesParamValues(object entryPointObj,
504+
internal static bool CheckEntryPointStateMatchesParamValues(object entryPointObj,
505505
TlcModule.SweepableParamAttribute[] sweepParams)
506506
{
507507
foreach (var param in sweepParams)
@@ -584,7 +584,7 @@ public static IRunResult[] ConvertToRunResults(PipelinePattern[] history, bool i
584584
/// Method to convert set of sweepable hyperparameters into <see cref="IComponentFactory"/> instances used
585585
/// by the current smart hyperparameter sweepers.
586586
/// </summary>
587-
public static IComponentFactory<IValueGenerator>[] ConvertToComponentFactories(TlcModule.SweepableParamAttribute[] hps)
587+
internal static IComponentFactory<IValueGenerator>[] ConvertToComponentFactories(TlcModule.SweepableParamAttribute[] hps)
588588
{
589589
var results = new IComponentFactory<IValueGenerator>[hps.Length];
590590

src/Microsoft.ML.PipelineInference/Interfaces/IPipelineNode.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected string GetEpName(Type type)
6060
return epName;
6161
}
6262

63-
protected void PropagateParamSetValues(ParameterSet hyperParams,
63+
private protected void PropagateParamSetValues(ParameterSet hyperParams,
6464
TlcModule.SweepableParamAttribute[] sweepParams)
6565
{
6666
var spMap = sweepParams.ToDictionary(sp => sp.Name);
@@ -79,9 +79,9 @@ public sealed class TransformPipelineNode : PipelineNodeBase, IPipelineNode<ITra
7979
private readonly CommonInputs.ITransformInput _entryPointObj;
8080
private readonly CommonInputs.ITrainerInput _subTrainerObj;
8181

82-
public TlcModule.SweepableParamAttribute[] SweepParams { get; }
82+
internal TlcModule.SweepableParamAttribute[] SweepParams { get; }
8383

84-
public TransformPipelineNode(CommonInputs.ITransformInput entryPointObj,
84+
internal TransformPipelineNode(CommonInputs.ITransformInput entryPointObj,
8585
IEnumerable<TlcModule.SweepableParamAttribute> sweepParams = null,
8686
CommonInputs.ITrainerInput subTrainerObj = null)
8787
{
@@ -136,9 +136,10 @@ public sealed class TrainerPipelineNode : PipelineNodeBase, IPipelineNode<IPredi
136136
{
137137
private readonly CommonInputs.ITrainerInput _entryPointObj;
138138

139-
public TlcModule.SweepableParamAttribute[] SweepParams { get; }
139+
[BestFriend]
140+
internal TlcModule.SweepableParamAttribute[] SweepParams { get; }
140141

141-
public TrainerPipelineNode(CommonInputs.ITrainerInput entryPointObj,
142+
internal TrainerPipelineNode(CommonInputs.ITrainerInput entryPointObj,
142143
IEnumerable<TlcModule.SweepableParamAttribute> sweepParams = null,
143144
ParameterSet hyperParameterSet = null)
144145
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.CompilerServices;
6+
using Microsoft.ML;
7+
8+
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Predictor.Tests" + PublicKey.TestValue)]
9+
10+
[assembly: WantsToBeBestFriends]

0 commit comments

Comments
 (0)