-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Added the assembly name of the custom transform to the model file #4989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2a2b655
87eb370
c77a09e
47966e7
db3dcb7
2fd1d40
019d7cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,10 @@ public override Action<MyInput, MyOutput> GetMapping() | |
} | ||
} | ||
|
||
[Fact] | ||
public void TestCustomTransformer() | ||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void TestCustomTransformer(bool registerAssembly) | ||
{ | ||
string dataPath = GetDataPath("adult.tiny.with-schema.txt"); | ||
var source = new MultiFileSource(dataPath); | ||
|
@@ -62,17 +64,13 @@ public void TestCustomTransformer() | |
var tempoEnv = new MLContext(1); | ||
var customEst = new CustomMappingEstimator<MyInput, MyOutput>(tempoEnv, MyLambda.MyAction, "MyLambda"); | ||
|
||
try | ||
{ | ||
TestEstimatorCore(customEst, data); | ||
Assert.True(false, "Cannot work without RegisterAssembly"); | ||
} | ||
catch (InvalidOperationException ex) | ||
{ | ||
if (!ex.IsMarked()) | ||
throw; | ||
} | ||
ML.ComponentCatalog.RegisterAssembly(typeof(MyLambda).Assembly); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder, what happens (and what should happen) if the user actually registers the assembly as done here and then tries to load the model? Will it throw an exception, or will it work anyway with the fix on this PR? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will work. The assembly can be registered multiple times. #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great. If anything, I would recommend using the InlineData trick I mentioned in another comment to test both cases: when the user registers the assembly manually (even if it's not necessary) and when they don't register it. #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// Before 1.5-preview3 it was required to register the assembly. | ||
// Now, the assembly information is automatically saved in the model and the assembly is registered | ||
// when loading. | ||
// This tests the case that the CustomTransformer still works even if you explicitly register the assembly | ||
if (registerAssembly) | ||
ML.ComponentCatalog.RegisterAssembly(typeof(MyLambda).Assembly); | ||
|
||
TestEstimatorCore(customEst, data); | ||
transformedData = customEst.Fit(data).Transform(data); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any case where the loaded model would actually require having a different name registered from the "FullName" retrieved from here? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or any case where trying to access that member of
_mapAction
would throw? #ResolvedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to Method can throw a MemberAccessException. But that would be up to the caller to fix in their code and the exception would help with that.
In reply to: 401790783 [](ancestors = 401790783)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should enforce the idea that the same transform that is used in training should be used in prediction as well. If they were to be different, then they are not the same pipelines and not the same models.
In reply to: 401431899 [](ancestors = 401431899)