Skip to content

Port SymSGD #556

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

Closed
wants to merge 104 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
8cdbf0f
Initial commit plus use ITrainer that returns predictor in SymSGD.
codemzs Jul 19, 2018
ca13e8d
Add tests.
codemzs Jul 25, 2018
7934cd5
Allow CpuMath to reference C# Hardware Intrinsics APIs. (#542)
eerhardt Jul 19, 2018
d456552
PipelineSweeperMacro for Multi-Class Classification (#539)
abgoswam Jul 19, 2018
ffeb1c9
Ensure ONNX export is compatible with Windows RS5 (#550)
codemzs Jul 23, 2018
91eb4fd
Move Windows and Linux CI to VSTS (#566)
safern Jul 23, 2018
e04a28f
Fix Linux CI to actually run inside a docker container (#574)
safern Jul 23, 2018
02a0a6d
Don't fail in case of const field in Collection source and extended s…
Ivanidzo4ka Jul 23, 2018
5287ce8
Schema comprehension doc (#572)
Zruty0 Jul 24, 2018
e5d90fe
Initial code analyzer for Microsoft.ML, use limited StyleCop (#557)
TomFinley Jul 25, 2018
cfd8caa
Sweep Range of L2RegularizerWeight in AveragedPerceptron (#579)
SolyarA Jul 25, 2018
40f128f
PR feedback.:
codemzs Jul 26, 2018
320f167
Fixed the TextTransform bug where chargrams where being computed diff…
zeahmed Jul 26, 2018
200ac53
Pass fold index to cross validation metrics. (#575)
Ivanidzo4ka Jul 26, 2018
c3730a0
Add reference to MKL nuget.
codemzs Jul 28, 2018
22224ec
Fixes #591: typos, adding the type attribute to lists, and moving the…
sfilipi Jul 28, 2018
cc194a4
openmp flag for linux and os x
codemzs Jul 28, 2018
8e3af20
openmp flag for linux and os x
codemzs Jul 28, 2018
45aaa9a
openmp flag for linux and os x
codemzs Jul 28, 2018
303f463
openmp flag for linux and os x
codemzs Jul 28, 2018
a332312
openmp flag for linux and os x
codemzs Jul 28, 2018
8378afd
openmp flag for linux and os x
codemzs Jul 28, 2018
edbcef4
openmp flag for linux and os x
codemzs Jul 28, 2018
5d4d119
openmp flag for linux and os x
codemzs Jul 28, 2018
5413530
openmp flag for linux and os x
codemzs Jul 28, 2018
bea513e
openmp flag for linux and os x
codemzs Jul 28, 2018
c515ac6
openmp flag for linux and os x
codemzs Jul 28, 2018
87c3f57
openmp flag for linux and os x
codemzs Jul 28, 2018
a5907db
openmp flag for linux and os x
codemzs Jul 28, 2018
a279a9f
openmp flag for linux and os x
codemzs Jul 28, 2018
c442145
openmp flag for linux and os x
codemzs Jul 28, 2018
8f139c3
openmp flag for linux and os x
codemzs Jul 28, 2018
434b60e
openmp flag for linux and os x
codemzs Jul 28, 2018
6dabc51
remove openmp dependency.
codemzs Jul 29, 2018
e0e8114
openmp flag for linux and os x
codemzs Jul 29, 2018
864d94e
openmp flag for linux and os x
codemzs Jul 29, 2018
956f425
fix deletion of void* in native code.
codemzs Jul 29, 2018
1cde6ae
fix deletion of void* in native code.
codemzs Jul 29, 2018
8bc6833
fix deletion of void* in native code.
codemzs Jul 29, 2018
3a78e09
fix deletion of void* in native code.
codemzs Jul 29, 2018
1c4cd7a
fix deletion of void* in native code.
codemzs Jul 29, 2018
c46dd0d
Replace openmp constructs with c++11 threading routines.
codemzs Jul 30, 2018
c414029
Replace openmp constructs with c++11 threading routines.
codemzs Jul 30, 2018
accb42a
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
a9d1a26
Replace openmp constructs with c++11 threading routines.
codemzs Jul 30, 2018
7255613
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
037c7ee
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
4965c24
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
f01d542
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
82d9a8d
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
1e03fe9
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
43f9a8c
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
1510520
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
9a99493
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
8e13400
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
d890c63
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
874867c
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
7fd9199
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
5a1808f
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
a761faa
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
fe5ffb1
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
f57233e
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
b366efb
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
09685ff
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
bf54d18
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
f79cde7
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
7e9ad36
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
12940bf
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
1583494
Rename mkl binaries from dll to .so for linux and .dylib for macOS.
codemzs Jul 30, 2018
c1993d6
changes.
codemzs Jul 30, 2018
760cef2
Fix creation of dataviews inferred with .NET types with sparse vector…
xadupre Jul 28, 2018
884574d
adding a dependency to the MlNEtMklDeps package (#594)
sfilipi Jul 30, 2018
e428c1c
changes.
codemzs Jul 30, 2018
a187a9e
make symsgd single threaded.
codemzs Jul 30, 2018
cd361a2
tests.
codemzs Jul 30, 2018
8903d02
cmake stuff.
codemzs Jul 31, 2018
7687cd4
cmake fix.
codemzs Jul 31, 2018
4821a1b
cmake stuff.
codemzs Jul 31, 2018
ee813b6
upgrade to mkl nuget 0.0.0.4
codemzs Jul 31, 2018
c758a81
upgrade to mkl nuget 0.0.0.4
codemzs Jul 31, 2018
8f7e497
load mkl native before symSGD is loaded.
codemzs Jul 31, 2018
5667701
load mkl native before symSGD is loaded.
codemzs Jul 31, 2018
e830980
load mkl native before symSGD is loaded.
codemzs Jul 31, 2018
bc87d62
support validation and incremental trainers (#610)
Ivanidzo4ka Jul 30, 2018
966b0f3
Add needed param to warning for L2 in SDCA (#597)
justinormont Jul 30, 2018
52d96b4
word embedding transform (#545)
Ivanidzo4ka Jul 31, 2018
2cb7dc6
Image support (#528)
Ivanidzo4ka Jul 31, 2018
767800c
load mkl native before symSGD is loaded.
codemzs Jul 31, 2018
89c06c0
load mkl native before symSGD is loaded.
codemzs Jul 31, 2018
41cba77
fixes.
codemzs Jul 31, 2018
4b27ec8
Rpath for linux and os x.
codemzs Aug 1, 2018
be8c6c8
Rpath for linux and os x.
codemzs Aug 1, 2018
6fe7e1a
Rpath for linux and os x.
codemzs Aug 1, 2018
2d8c15b
load mkl native before symSGD is loaded.
codemzs Aug 1, 2018
20b448b
Splitting OLS to a separate package called AdditionalLearners (#611)
sfilipi Aug 1, 2018
b9fe01d
Rpath for linux and os x.
codemzs Aug 1, 2018
ebd5bcd
Rpath for OS X
codemzs Aug 1, 2018
de999a8
Rpath for linux and os x.
codemzs Aug 1, 2018
573781d
Rpath for linux and os x.
codemzs Aug 1, 2018
9d8f297
Rpath for linux and os x.
codemzs Aug 1, 2018
1b4273a
Rpath for linux and os x.
codemzs Aug 1, 2018
294c3d7
move symsgd under HALLearners.
codemzs Aug 1, 2018
6ec9d70
documentation.
codemzs Aug 1, 2018
65c97f1
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs Aug 1, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Microsoft.ML.Console/Microsoft.ML.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ProjectReference Include="..\Microsoft.ML.Data\Microsoft.ML.Data.csproj" />
<ProjectReference Include="..\Microsoft.ML.Ensemble\Microsoft.ML.Ensemble.csproj" />
<ProjectReference Include="..\Microsoft.ML.FastTree\Microsoft.ML.FastTree.csproj" />
<ProjectReference Include="..\Microsoft.ML.HalLearners\Microsoft.ML.HalLearners.csproj" />
<ProjectReference Include="..\Microsoft.ML.KMeansClustering\Microsoft.ML.KMeansClustering.csproj" />
<ProjectReference Include="..\Microsoft.ML.LightGBM\Microsoft.ML.LightGBM.csproj" />
<ProjectReference Include="..\Microsoft.ML.Maml\Microsoft.ML.Maml.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.ML.HalLearners/Microsoft.ML.HalLearners.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IncludeInPackage>Microsoft.ML.HalLearners</IncludeInPackage>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
850 changes: 850 additions & 0 deletions src/Microsoft.ML.HalLearners/SymSgdClassificationTrainer.cs

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions src/Microsoft.ML.HalLearners/doc.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<doc>
<members>

Expand All @@ -22,6 +22,24 @@
</code>
</example>
</member>

<member name="SymSGD">
<summary>
Parallel Stochastic Gradient Descent trainer.
</summary>
<remarks>
<a href='https://en.wikipedia.org/wiki/Stochastic_gradient_descent'>Stochastic gradient descent (SGD)</a> is an interative algorithm
that optimizes a differentiable objective function. <a href='https://arxiv.org/abs/1705.08030'>SYMSGD</a> parallelizes SGD using Sound Combiners.
</remarks>
<example>
<code language="csharp">
new SymSgdBinaryClassifier()
{
NumberOfIterations = 50,
L2Regularization = 0,
Shuffle = true
}
</code>
</example>
</member>
</members>
</doc>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -11,6 +11,7 @@
<ProjectReference Include="..\Microsoft.ML.CpuMath\Microsoft.ML.CpuMath.csproj" />
<ProjectReference Include="..\Microsoft.ML.Data\Microsoft.ML.Data.csproj" />
<ProjectReference Include="..\Microsoft.ML\Microsoft.ML.csproj" />
<PackageReference Include="MlNetMklDeps" Version="$(MlNetMklDepsPackageVersion)" />
</ItemGroup>

</Project>
134 changes: 134 additions & 0 deletions src/Microsoft.ML/CSharpApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,18 @@ public void Add(Microsoft.ML.Trainers.StochasticGradientDescentBinaryClassifier
_jsonNodes.Add(Serialize("Trainers.StochasticGradientDescentBinaryClassifier", input, output));
}

public Microsoft.ML.Trainers.SymSgdBinaryClassifier.Output Add(Microsoft.ML.Trainers.SymSgdBinaryClassifier input)
{
var output = new Microsoft.ML.Trainers.SymSgdBinaryClassifier.Output();
Add(input, output);
return output;
}

public void Add(Microsoft.ML.Trainers.SymSgdBinaryClassifier input, Microsoft.ML.Trainers.SymSgdBinaryClassifier.Output output)
{
_jsonNodes.Add(Serialize("Trainers.SymSgdBinaryClassifier", input, output));
}

public Microsoft.ML.Transforms.ApproximateBootstrapSampler.Output Add(Microsoft.ML.Transforms.ApproximateBootstrapSampler input)
{
var output = new Microsoft.ML.Transforms.ApproximateBootstrapSampler.Output();
Expand Down Expand Up @@ -9761,6 +9773,128 @@ public StochasticGradientDescentBinaryClassifierPipelineStep(Output output)
}
}

namespace Trainers
{

/// <summary>
/// Train a symbolic SGD.
/// </summary>
Copy link
Member

@sfilipi sfilipi Jul 31, 2018

Choose a reason for hiding this comment

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

Not sure how much documentation we have about SymSGD. If any, might be nice to include it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

public sealed partial class SymSgdBinaryClassifier : Microsoft.ML.Runtime.EntryPoints.CommonInputs.ITrainerInputWithLabel, Microsoft.ML.Runtime.EntryPoints.CommonInputs.ITrainerInput, Microsoft.ML.ILearningPipelineItem
{


/// <summary>
/// Degree of lock-free parallelism. Determinism not guaranteed. Multi-threading is not supported currently.
/// </summary>
public int? NumberOfThreads { get; set; }

/// <summary>
/// Number of passes over the data.
/// </summary>
[TlcModule.SweepableDiscreteParamAttribute("NumberOfIterations", new object[]{1, 5, 10, 20, 30, 40, 50})]
public int NumberOfIterations { get; set; } = 50;

/// <summary>
/// Tolerance for difference in average loss in consecutive passes.
/// </summary>
public float Tol { get; set; } = 0.0001f;

/// <summary>
/// Learning rate
/// </summary>
[TlcModule.SweepableDiscreteParamAttribute("LearningRate", new object[]{"<Auto>", 10f, 1f, 0.1f, 0.01f, 0.001f})]
public float? LearningRate { get; set; }

/// <summary>
/// L2 regularization
/// </summary>
[TlcModule.SweepableDiscreteParamAttribute("L2Regularization", new object[]{0f, 1E-05f, 1E-05f, 1E-06f, 1E-07f})]
public float L2Regularization { get; set; }

/// <summary>
/// The number of iterations each thread learns a local model until combining it with the global model. Low value means more updated global model and high value means less cache traffic.
/// </summary>
[TlcModule.SweepableDiscreteParamAttribute("UpdateFrequency", new object[]{"<Auto>", 5, 20})]
public int? UpdateFrequency { get; set; }

/// <summary>
/// The acceleration memory budget in MB
/// </summary>
public long MemorySize { get; set; } = 1024;

/// <summary>
/// Shuffle data?
/// </summary>
public bool Shuffle { get; set; } = true;

/// <summary>
/// Apply weight to the positive class, for imbalanced data
/// </summary>
public float PositiveInstanceWeight { get; set; } = 1f;

/// <summary>
/// Column to use for labels
/// </summary>
public string LabelColumn { get; set; } = "Label";

/// <summary>
/// The data to be used for training
/// </summary>
public Var<Microsoft.ML.Runtime.Data.IDataView> TrainingData { get; set; } = new Var<Microsoft.ML.Runtime.Data.IDataView>();

/// <summary>
/// Column to use for features
/// </summary>
public string FeatureColumn { get; set; } = "Features";

/// <summary>
/// Normalize option for the feature column
/// </summary>
public Microsoft.ML.Models.NormalizeOption NormalizeFeatures { get; set; } = Microsoft.ML.Models.NormalizeOption.Auto;

/// <summary>
/// Whether learner should cache input training data
/// </summary>
public Microsoft.ML.Models.CachingOptions Caching { get; set; } = Microsoft.ML.Models.CachingOptions.Auto;


public sealed class Output : Microsoft.ML.Runtime.EntryPoints.CommonOutputs.IBinaryClassificationOutput, Microsoft.ML.Runtime.EntryPoints.CommonOutputs.ITrainerOutput
{
/// <summary>
/// The trained model
/// </summary>
public Var<Microsoft.ML.Runtime.EntryPoints.IPredictorModel> PredictorModel { get; set; } = new Var<Microsoft.ML.Runtime.EntryPoints.IPredictorModel>();

}
public Var<IDataView> GetInputData() => TrainingData;

public ILearningPipelineStep ApplyStep(ILearningPipelineStep previousStep, Experiment experiment)
{
if (previousStep != null)
{
if (!(previousStep is ILearningPipelineDataStep dataStep))
{
throw new InvalidOperationException($"{ nameof(SymSgdBinaryClassifier)} only supports an { nameof(ILearningPipelineDataStep)} as an input.");
}

TrainingData = dataStep.Data;
}
Output output = experiment.Add(this);
return new SymSgdBinaryClassifierPipelineStep(output);
}

private class SymSgdBinaryClassifierPipelineStep : ILearningPipelinePredictorStep
{
public SymSgdBinaryClassifierPipelineStep(Output output)
{
Model = output.PredictorModel;
}

public Var<IPredictorModel> Model { get; }
}
}
}

namespace Transforms
{

Expand Down
1 change: 1 addition & 0 deletions src/Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,4 @@ add_subdirectory(CpuMathNative)
add_subdirectory(FastTreeNative)
add_subdirectory(LdaNative)
add_subdirectory(FactorizationMachineNative)
add_subdirectory(SymSgdNative)
32 changes: 32 additions & 0 deletions src/Native/SymSgdNative/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
project (SymSgdNative)

set(SOURCES
SymSgdNative.cpp
)

if(WIN32)
find_library(MKL_LIBRARY MklImports HINTS ${CMAKE_SOURCE_DIR}/../../packages/mlnetmkldeps/0.0.0.5/runtimes/win-x64/native)
else()
list(APPEND SOURCES ${VERSION_FILE_PATH})
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
message("Linking SymSgdNative with MKL on macOS.")
find_library(MKL_LIBRARY libMklImports.dylib HINTS "${CMAKE_SOURCE_DIR}/../../packages/mlnetmkldeps/0.0.0.5/runtimes/osx-x64/native")
else()
message("Linking SymSgdNative with MKL on linux.")
find_library(MKL_LIBRARY libMklImports.so HINTS ${CMAKE_SOURCE_DIR}/../../packages/mlnetmkldeps/0.0.0.5/runtimes/linux-x64/native)
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_SOURCE_DIR}/../../packages/mlnetmkldeps/0.0.0.5/runtimes")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_SOURCE_DIR}/../../packages/mlnetmkldeps/0.0.0.5/runtimes")
endif()
endif()

add_library(SymSgdNative SHARED ${SOURCES} ${RESOURCES})
target_link_libraries(SymSgdNative PUBLIC ${MKL_LIBRARY})

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set_target_properties(SymSgdNative PROPERTIES INSTALL_RPATH "${CMAKE_SOURCE_DIR}/../../packages/mlnetmkldeps/0.0.0.5/runtimes/osx-x64/native")
endif()

install_library_and_symbols (SymSgdNative)
9 changes: 9 additions & 0 deletions src/Native/SymSgdNative/Macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#pragma once
#define MIN(__X__, __Y__) (((__X__) > (__Y__)) ? (__Y__) : (__X__))

// This is a very large prime number used for permutation
#define VERYLARGEPRIME 961748941
27 changes: 27 additions & 0 deletions src/Native/SymSgdNative/SparseBLAS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#pragma once
#include "../Stdafx.h"

extern "C" float cblas_sdot(const int vecSize, const float* denseVecX, const int incX, const float* denseVecY, const int incY);
extern "C" float cblas_sdoti(const int sparseVecSize, const float* sparseVecValues, const int* sparseVecIndices, float* denseVec);
extern "C" void cblas_saxpy(const int vecSize, const float coef, const float* denseVecX, const int incX, float* denseVecY, const int incY);
extern "C" void cblas_saxpyi(const int sparseVecSize, const float coef, const float* sparseVecValues, const int* sparseVecIndices, float* denseVec);

float SDOT(const int vecSize, const float* denseVecX, const float* denseVecY) {
return cblas_sdot(vecSize, denseVecX, 1, denseVecY, 1);
}

float SDOTI(const int sparseVecSize, const int* sparseVecIndices, const float* sparseVecValues, float* denseVec) {
return cblas_sdoti(sparseVecSize, sparseVecValues, sparseVecIndices, denseVec);
}

void SAXPY(const int vecSize, const float* denseVecX, float* denseVecY, float coef) {
return cblas_saxpy(vecSize, coef, denseVecX, 1, denseVecY, 1);
}

void SAXPYI(const int sparseVecSize, const int* sparseVecIndices, const float* sparseVecValues, float* denseVec, float coef) {
cblas_saxpyi(sparseVecSize, coef, sparseVecValues, sparseVecIndices, denseVec);
}
Loading