diff --git a/HISTORY.md b/HISTORY.md index a851154847..2a6775a9da 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,13 +1,17 @@ ### mlpack ?.?.? ###### ????-??-?? +### mlpack 4.1.0 +###### 2023-04-26 + * Adapt HardTanH layer (#3454). * Adapt Softmin layer for new neural network API (#3437). * Adapt PReLU layer for new neural network API (#3420). - * Add CF decomposition methods: `QUIC_SVDPolicy` and `BlockKrylovSVDPolicy` (#3413, #3404). + * Add CF decomposition methods: `QUIC_SVDPolicy` and `BlockKrylovSVDPolicy` + (#3413, #3404). * Update outdated code in tutorials (#3398, #3401). @@ -19,6 +23,9 @@ * Avoid deprecation warnings in Armadillo 11.4.4+ (#3405). + * Issue runtime error when serialization of neural networks is attempted but + `MLPACK_ENABLE_ANN_SERIALIZATION` is not defined (#3451). + ### mlpack 4.0.1 ###### 2022-12-23 * Fix mapping of categorical data for Julia bindings (#3305). diff --git a/README.md b/README.md index 3cc3641897..999d68953c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ src="https://cdn.rawgit.com/mlpack/mlpack.org/e7d36ed8/mlpack-black.svg" style="

Download: - current stable version (4.0.1) + current stable version (4.1.0)

@@ -180,6 +180,8 @@ g++ -O3 -std=c++14 -o my_program my_program.cpp -larmadillo -fopenmp Note that if you want to serialize (save or load) neural networks, you should add `#define MLPACK_ENABLE_ANN_SERIALIZATION` before including ``. +If you don't define `MLPACK_ENABLE_ANN_SERIALIZATION` and your code serializes a +neural network, a compilation error will occur. See the [C++ quickstart](doc/quickstart/cpp.md) and the [examples](https://github.com/mlpack/examples) repository for some examples of @@ -198,7 +200,8 @@ reduce compilation time: * Only use the `MLPACK_ENABLE_ANN_SERIALIZATION` definition if you are serializing neural networks in your code. When this define is enabled, compilation time will increase significantly, as the compiler must generate - code for every possible type of layer. + code for every possible type of layer. (The large amount of extra + compilation overhead is why this is not enabled by default.) * If you are using mlpack in multiple .cpp files, consider using [`extern templates`](https://isocpp.org/wiki/faq/cpp11-language-templates) so that the @@ -252,7 +255,7 @@ build in parallel; e.g., `make -j4` will use 4 cores to build. mlpack's Python bindings are available on [PyPI](https://pypi.org/project/mlpack) and -[conda-forge](https://conda-forge.org/packages/mlpack), and can be installed +[conda-forge](https://anaconda.org/conda-forge/mlpack), and can be installed with either `pip install mlpack` or `conda install -c conda-forge mlpack`. These sources are recommended, as building the Python bindings by hand can be complex. diff --git a/doc/examples/sample-ml-app/sample-ml-app/sample-ml-app.vcxproj b/doc/examples/sample-ml-app/sample-ml-app/sample-ml-app.vcxproj index ca7b09267a..5aae6d9ce7 100644 --- a/doc/examples/sample-ml-app/sample-ml-app/sample-ml-app.vcxproj +++ b/doc/examples/sample-ml-app/sample-ml-app/sample-ml-app.vcxproj @@ -104,7 +104,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) Default - C:\mlpack\armadillo-11.4.1\include;C:\mlpack\mlpack-4.0.1\include\;C:\mlpack\cereal-1.3.2\include;C:\mlpack\ensmallen-2.19.0\include\%(AdditionalIncludeDirectories) + C:\mlpack\armadillo-11.4.1\include;C:\mlpack\mlpack-4.1.0\include\;C:\mlpack\cereal-1.3.2\include;C:\mlpack\ensmallen-2.19.0\include\%(AdditionalIncludeDirectories) stdcpp17 false /Zc:__cplusplus %(AdditionalOptions) diff --git a/doc/user/build_windows.md b/doc/user/build_windows.md index 61cbae34ef..69b4cbbf71 100644 --- a/doc/user/build_windows.md +++ b/doc/user/build_windows.md @@ -261,5 +261,5 @@ If you are facing issues during the build process of mlpack, you may take a look at other third-party tutorials for Windows, but they may be out of date: * [Github wiki Windows Build page](https://github.com/mlpack/mlpack/wiki/WindowsBuild) - * [Keon's tutorial for mlpack 2.0.3](http://keon.io/mlpack-on-windows) + * [Keon's tutorial for mlpack 2.0.3](https://keon.github.io/mlpack-on-windows/) * [Kirizaki's tutorial for mlpack 2](https://overdosedblog.wordpress.com/2016/08/15/once_again/) diff --git a/doc/user/sample_ml_app.md b/doc/user/sample_ml_app.md index 07eb62ab99..17b3a9775a 100644 --- a/doc/user/sample_ml_app.md +++ b/doc/user/sample_ml_app.md @@ -27,13 +27,13 @@ dependencies in Release Mode). - Under C/C++ > General > Additional Include Directories add: ``` - C:\mlpack\armadillo-9.800.3\include - - C:\mlpack\mlpack-4.0.1\src + - C:\mlpack\mlpack-4.1.0\src - C:\mlpack\ensmallen-2.19.0\include - C:\mlpack\cereal-3.1.2\include ``` - Under Build Events > Post-Build Event > Command Line add: ``` - - xcopy /y "C:\mlpack\mlpack-4.0.1\packages\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll" $(OutDir) + - xcopy /y "C:\mlpack\mlpack-4.1.0\packages\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.dll" $(OutDir) ``` *Note*: recent versions of Visual Studio set "Conformance Mode" enabled by diff --git a/src/mlpack/core/util/version.hpp b/src/mlpack/core/util/version.hpp index 77fa1394e3..9fd554d3db 100644 --- a/src/mlpack/core/util/version.hpp +++ b/src/mlpack/core/util/version.hpp @@ -17,8 +17,8 @@ // The version of mlpack. If this is a git repository, this will be a version // with higher number than the most recent release. #define MLPACK_VERSION_MAJOR 4 -#define MLPACK_VERSION_MINOR 0 -#define MLPACK_VERSION_PATCH 2 +#define MLPACK_VERSION_MINOR 1 +#define MLPACK_VERSION_PATCH 1 // The name of the version (for use by --version). namespace mlpack { diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index ee9a55f821..e3e1b69ddb 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -374,34 +374,46 @@ void FFN< MatType >::serialize(Archive& ar, const uint32_t /* version */) { - // Serialize the output layer and initialization rule. - ar(CEREAL_NVP(outputLayer)); - ar(CEREAL_NVP(initializeRule)); + #ifndef MLPACK_ENABLE_ANN_SERIALIZATION + // Note: if you define MLPACK_IGNORE_ANN_SERIALIZATION_WARNING, you had + // better ensure that every layer you are serializing has had + // CEREAL_REGISTER_TYPE() called somewhere. See layer/serialization.hpp for + // more information. + #ifndef MLPACK_ANN_IGNORE_SERIALIZATION_WARNING + throw std::runtime_error("Cannot serialize a neural network unless " + "MLPACK_ENABLE_ANN_SERIALIZATION is defined! See the \"Additional " + "build options\" section of the README for more information."); + #endif + #else + // Serialize the output layer and initialization rule. + ar(CEREAL_NVP(outputLayer)); + ar(CEREAL_NVP(initializeRule)); - // Serialize the network itself. - ar(CEREAL_NVP(network)); - ar(CEREAL_NVP(parameters)); + // Serialize the network itself. + ar(CEREAL_NVP(network)); + ar(CEREAL_NVP(parameters)); - // Serialize the expected input size. - ar(CEREAL_NVP(inputDimensions)); + // Serialize the expected input size. + ar(CEREAL_NVP(inputDimensions)); - // If we are loading, we need to initialize the weights. - if (cereal::is_loading()) - { - // We can clear these members, since it's not possible to serialize in the - // middle of training and resume. - predictors.clear(); - responses.clear(); + // If we are loading, we need to initialize the weights. + if (cereal::is_loading()) + { + // We can clear these members, since it's not possible to serialize in the + // middle of training and resume. + predictors.clear(); + responses.clear(); - networkOutput.clear(); - networkDelta.clear(); + networkOutput.clear(); + networkDelta.clear(); - layerMemoryIsSet = false; - inputDimensionsAreSet = false; + layerMemoryIsSet = false; + inputDimensionsAreSet = false; - // The weights in `parameters` will be correctly set for each layer in the - // first call to Forward(). - } + // The weights in `parameters` will be correctly set for each layer in the + // first call to Forward(). + } + #endif } templateWeightSize(); - arma::Mat tmp = arma::mat(parameters.memptr() + offset, + arma::Mat tmp = arma::Mat(parameters.memptr() + offset, weight, 1, false, false); initializeRule.Initialize(tmp, tmp.n_elem, 1); diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp index 5c15c8803a..b3a2913962 100644 --- a/src/mlpack/methods/ann/rnn_impl.hpp +++ b/src/mlpack/methods/ann/rnn_impl.hpp @@ -290,17 +290,29 @@ void RNN< >::serialize( Archive& ar, const uint32_t /* version */) { - ar(CEREAL_NVP(bpttSteps)); - ar(CEREAL_NVP(single)); - ar(CEREAL_NVP(network)); + #ifndef MLPACK_ENABLE_ANN_SERIALIZATION + // Note: if you define MLPACK_IGNORE_ANN_SERIALIZATION_WARNING, you had + // better ensure that every layer you are serializing has had + // CEREAL_REGISTER_TYPE() called somewhere. See layer/serialization.hpp for + // more information. + #ifndef MLPACK_IGNORE_ANN_SERIALIZATION_WARNING + throw std::runtime_error("Cannot serialize a neural network unless " + "MLPACK_ENABLE_ANN_SERIALIZATION is defined! See the \"Additional " + "build options\" section of the README for more information."); + #endif + #else + ar(CEREAL_NVP(bpttSteps)); + ar(CEREAL_NVP(single)); + ar(CEREAL_NVP(network)); - if (Archive::is_loading::value) - { - // We can clear these members, since it's not possible to serialize in the - // middle of training and resume. - predictors.clear(); - responses.clear(); - } + if (Archive::is_loading::value) + { + // We can clear these members, since it's not possible to serialize in the + // middle of training and resume. + predictors.clear(); + responses.clear(); + } + #endif } template< diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index 17704fbd45..ed8b5b9ed3 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -221,7 +221,14 @@ else() target_compile_definitions(mlpack_test PUBLIC -DMLPACK_SUPPRESS_FATAL) endif() -set_target_properties(mlpack_test PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "../core.hpp") +# This has to be added here so that cotire picks it up (even though it is in +# individual tests). +target_compile_definitions(mlpack_test PUBLIC -DMLPACK_ENABLE_ANN_SERIALIZATION) +set_target_properties(mlpack_test PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT + "../core.hpp") +# TODO: use the source below, but this requires the DET test to be refactored +# and cleaned up. +# "../../mlpack.hpp") cotire(mlpack_test) # Copy test data into right place. diff --git a/src/mlpack/tests/ann/feedforward_network_test.cpp b/src/mlpack/tests/ann/feedforward_network_test.cpp index de959e68fb..9bcbefa94c 100644 --- a/src/mlpack/tests/ann/feedforward_network_test.cpp +++ b/src/mlpack/tests/ann/feedforward_network_test.cpp @@ -10,7 +10,9 @@ * 3-clause BSD license along with mlpack. If not, see * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ -#define MLPACK_ENABLE_ANN_SERIALIZATION +#ifndef MLPACK_ENABLE_ANN_SERIALIZATION + #define MLPACK_ENABLE_ANN_SERIALIZATION +#endif #include #include #include diff --git a/src/mlpack/tests/ann/layer/batch_norm.cpp b/src/mlpack/tests/ann/layer/batch_norm.cpp index 35ef57e58b..2e73a3e135 100644 --- a/src/mlpack/tests/ann/layer/batch_norm.cpp +++ b/src/mlpack/tests/ann/layer/batch_norm.cpp @@ -10,7 +10,9 @@ * 3-clause BSD license along with mlpack. If not, see * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ -#define MLPACK_ENABLE_ANN_SERIALIZATION +#ifndef MLPACK_ENABLE_ANN_SERIALIZATION + #define MLPACK_ENABLE_ANN_SERIALIZATION +#endif #include #include diff --git a/src/mlpack/tests/ann/layer/hard_tanh.cpp b/src/mlpack/tests/ann/layer/hard_tanh.cpp index 2276981cac..8ceb8d953f 100644 --- a/src/mlpack/tests/ann/layer/hard_tanh.cpp +++ b/src/mlpack/tests/ann/layer/hard_tanh.cpp @@ -2,8 +2,12 @@ * @file tests/ann/layer/hard_tanh.cpp * @author Vaibhav Pathak * - * Tests the hard_tanh layer + * Tests the hard_tanh layer. * + * mlpack is free software; you may redistribute it and/or modify it under the + * terms of the 3-clause BSD license. You should have received a copy of the + * 3-clause BSD license along with mlpack. If not, see + * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #include diff --git a/src/mlpack/tests/main.cpp b/src/mlpack/tests/main.cpp index 92f445af72..1a6292e3b4 100644 --- a/src/mlpack/tests/main.cpp +++ b/src/mlpack/tests/main.cpp @@ -8,6 +8,9 @@ * 3-clause BSD license along with mlpack. If not, see * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ +#ifndef MLPACK_ENABLE_ANN_SERIALIZATION + #define MLPACK_ENABLE_ANN_SERIALIZATION +#endif #include // #define CATCH_CONFIG_MAIN // catch.hpp will define main()