Skip to content

Adding CodeGen piece for MatrixFactorization trainer #4391

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

Merged
merged 13 commits into from
Oct 30, 2019

Conversation

maryamariyan
Copy link
Member

@maryamariyan maryamariyan commented Oct 25, 2019

This PR adds CodeGen piece for MatrixFactorization trainer (For the recommendation task)

cc: @eerhardt @LittleLittleCloud

TODO:

  • Add MatrixFactorization trainer generator
  • Add tests for the trainer generator
  • Review other CodeGen tests to find more use cases that can be tested

@maryamariyan maryamariyan requested review from a team as code owners October 25, 2019 23:21
@maryamariyan maryamariyan force-pushed the codegen-recommendation branch from 0fc8a38 to acdf78a Compare October 25, 2019 23:22
@@ -47,7 +48,10 @@ private void Initialize(PipelineNode node)
{
node.Properties.Add("LabelColumnName", "Label");
}
node.Properties.Add("FeatureColumnName", "Features");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FeatureColumnName gets added for all existing trainer generators. I added IncludeFeatureColumnName which is false for MatrixFactorization trainer generator only.

Copy link
Member Author

@maryamariyan maryamariyan Oct 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:

  • Look more closely at the implementation to see why it was expected for all Trainer Generators to have a FeatureColumn. if it is expected then it should also be added for MatrixFactorization trainer generator

@maryamariyan maryamariyan self-assigned this Oct 25, 2019
{
get
{
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of an anti-pattern: to return a new object every time a property is invoked. I see this is already being used in existing code, so you don't need to fix it in this PR. But in general, calling a property is supposed to be fast.

https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/property

Although properties are technically very similar to methods, they are quite different in terms of their usage scenarios. They should be seen as smart fields.

eerhardt
eerhardt previously approved these changes Oct 28, 2019
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@LittleLittleCloud
Copy link
Contributor

LittleLittleCloud commented Oct 28, 2019

I can't find changes in GenerateConsoleAppProjectContents and GenerateModelProjectFileContent, maybe we need to update that because we need include Microsoft.ML.Recommender if we want to use MatrixFactorization in generated project.

For example here we need to add something like IncludingRecommendationPackage
https://github.com/maryamariyan/machinelearning/blob/acdf78adb1fb671dec0c12bdc2318d21c45cadbb/src/Microsoft.ML.CodeGenerator/CodeGenerator/CSharp/CodeGenerator.cs#L278

@eerhardt eerhardt dismissed their stale review October 28, 2019 17:21

@LittleLittleCloud brings up a great point. We need to include the Recommender package.

Copy link
Contributor

@CESARDELATORRE CESARDELATORRE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks initially good to me. I'll have further feedback when testing it with the NuGet packages and when available from the CLI.

@maryamariyan maryamariyan force-pushed the codegen-recommendation branch 2 times, most recently from a8bbbd8 to 523e808 Compare October 29, 2019 03:50
@maryamariyan maryamariyan force-pushed the codegen-recommendation branch from 523e808 to d586c62 Compare October 29, 2019 05:48
…ation

 Conflicts:
	src/Microsoft.ML.CodeGenerator/CodeGenerator/CSharp/CodeGenerator.cs
	src/Microsoft.ML.CodeGenerator/CodeGenerator/CSharp/TrainerGeneratorFactory.cs
	src/Microsoft.ML.CodeGenerator/CodeGenerator/CSharp/TrainerGenerators.cs
	src/Microsoft.ML.CodeGenerator/Templates/Console/ModelProject.cs
	src/Microsoft.ML.CodeGenerator/Templates/Console/ModelProject.tt
	src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.cs
	src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.tt
	test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsoleAppProjectFileContentTest.approved.txt
	test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ModelProjectFileContentTestOnlyStableProjects.approved.txt
	test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.cs
@maryamariyan
Copy link
Member Author

maryamariyan commented Oct 29, 2019

I resolved the conflicts resulted from the image classification code gen submission.
Also applied some PR feedback.
Next is to:

  • Fix version issue

@@ -27,6 +27,10 @@ public CodeGeneratorSettings()

public GenerateTarget Target { get; set; }

public string StablePackageVersion { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JakeRadMSFT @LittleLittleCloud - what do you think of this approach? It at least removes hard-coded versions from the CodeGenerator assembly, and allows the "app" (CLI and Model Builder) to pick the version they require.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@maryamariyan
Copy link
Member Author

@eerhardt

  • the model project uses TargetFramework netstandard2.0 -> I'll change to netstandard2.1
  • the predict project uses TargetFramework netcoreapp2.1 -> I'll change to netcoreapp3.0

@eerhardt
Copy link
Member

the model project uses TargetFramework netstandard2.0 -> I'll change to netstandard2.1
the predict project uses TargetFramework netcoreapp2.1 -> I'll change to netcoreapp3.0

No, please don't make that change. Leave it as is.

…ation

 Conflicts:
	src/Microsoft.ML.CodeGenerator/Templates/Console/ModelProject.cs
	src/Microsoft.ML.CodeGenerator/Templates/Console/ModelProject.tt
	src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.cs
	src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.tt
@maryamariyan maryamariyan merged commit 3ec1844 into dotnet:master Oct 30, 2019
@maryamariyan maryamariyan deleted the codegen-recommendation branch October 30, 2019 22:56
@maryamariyan
Copy link
Member Author

Merged since the CI code coverage failures are unrelated to this PR:

https://github.com/dotnet/machinelearning/pull/4391/checks?check_run_id=282184827

Microsoft.ML.Scenarios.TensorFlowScenariosTests.TensorFlowImageClassificationWithPolynomialLRScheduling
Microsoft.ML.Scenarios.TensorFlowScenariosTests.TensorFlowImageClassificationEarlyStoppingDecreasing
Microsoft.ML.RunTests.TestPredictors.LinearClassifierTest
Microsoft.ML.Scenarios.TensorFlowScenariosTests.TensorFlowImageClassificationEarlyStoppingDecreasing

frank-dong-ms-zz pushed a commit to frank-dong-ms-zz/machinelearning that referenced this pull request Nov 4, 2019
* Add CodeGen piece for Recommendation Task using MatrixFactorization
frank-dong-ms-zz pushed a commit to frank-dong-ms-zz/machinelearning that referenced this pull request Nov 4, 2019
* Add CodeGen piece for Recommendation Task using MatrixFactorization
@ghost ghost locked as resolved and limited conversation to collaborators Mar 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants