Skip to content
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

Integrate featurizers #1573

Merged
merged 11 commits into from
Aug 15, 2019
Merged
7 changes: 7 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ option(onnxruntime_USE_NNAPI "Build with DNNLibrary for Android NNAPI support" O
option(onnxruntime_USE_MLAS "Use optimized blas library for GEMM and 2D Convolution" ON)
option(onnxruntime_USE_MKLDNN "Build with MKL-DNN support" OFF)
option(onnxruntime_USE_MKLML "Build MKL-DNN with MKL-ML binary dependency" OFF)
option(onnxruntime_USE_AUTOML "Build AutoML support" ON)
option(onnxruntime_USE_NGRAPH "Build with nGraph support" OFF)
option(onnxruntime_USE_OPENBLAS "Use openblas" OFF)
option(onnxruntime_DEV_MODE "Enable developer warnings and treat most of them as error." OFF)
Expand Down Expand Up @@ -646,6 +647,12 @@ include(onnxruntime_optimizer.cmake)
include(onnxruntime_session.cmake)
include(onnxruntime_mlas.cmake)

if(onnxruntime_USE_AUTOML)
add_definitions(-DMICROSOFT_AUTOML)
# Build shared featurizer library
include(onnxruntime_automl_featurizers.cmake)
endif()

if(WIN32)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES Shlwapi)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES debug Dbghelp)
Expand Down
44 changes: 44 additions & 0 deletions cmake/onnxruntime_automl_featurizers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# This source code should not depend on the onnxruntime and may be built independently

file(GLOB automl_featurizers_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/automl/featurizers/src/FeaturizerPrep/*.h"
"${ONNXRUNTIME_ROOT}/core/automl/featurizers/src/FeaturizerPrep/Featurizers/*.h"
"${ONNXRUNTIME_ROOT}/core/automl/featurizers/src/FeaturizerPrep/Featurizers/*.cpp"
)

source_group(TREE ${ONNXRUNTIME_ROOT}/core/automl/ FILES ${onnxruntime_automl_featurizers_srcs})

add_library(automl_featurizers ${automl_featurizers_srcs})

target_include_directories(automl_featurizers PRIVATE ${ONNXRUNTIME_ROOT} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

set_target_properties(automl_featurizers PROPERTIES FOLDER "AutoMLFeaturizers")

# Individual featurizers unit tests added at bulk
file(GLOB automl_featurizers_tests_srcs
"${ONNXRUNTIME_ROOT}/core/automl/featurizers/src/FeaturizerPrep/Featurizers/UnitTests/*.cpp"
)

list(APPEND automl_featurizers_tests_srcs
"${ONNXRUNTIME_ROOT}/core/automl/featurizers/src/FeaturizerPrep/UnitTests/Traits_UnitTests.cpp"
"${ONNXRUNTIME_ROOT}/core/automl/featurizers/src/FeaturizerPrep/UnitTests/Featurizer_UnitTest.cpp"
"${ONNXRUNTIME_ROOT}/core/automl/featurizers/src/FeaturizerPrep/UnitTests/test_main.cpp"
)

add_executable(automl_featurizers_unittests ${automl_featurizers_tests_srcs})
add_dependencies(automl_featurizers_unittests automl_featurizers)
target_link_libraries(automl_featurizers_unittests PRIVATE gtest automl_featurizers)
source_group(TREE ${ONNXRUNTIME_ROOT}/core/automl/ FILES ${automl_featurizers_tests_srcs})
set_target_properties(automl_featurizers_unittests PROPERTIES FOLDER "AutoMLFeaturizers")
add_test(NAME automl_featurizers_unittests
COMMAND automl_featurizers_unittests
WORKING_DIRECTORY $<TARGET_FILE_DIR:automl_featurizers_unittests>
)


if (WIN32)
# Add Code Analysis properties to enable C++ Core checks. Have to do it via a props file include.
set_target_properties(automl_featurizers PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/ConfigureVisualStudioCodeAnalysis.props)
endif()
8 changes: 8 additions & 0 deletions cmake/onnxruntime_graph.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ if (onnxruntime_DISABLE_CONTRIB_OPS)
)
endif()

if(NOT onnxruntime_USE_AUTOML)
list(REMOVE_ITEM onnxruntime_graph_src
"${ONNXRUNTIME_ROOT}/core/graph/automl_ops/*.h"
"${ONNXRUNTIME_ROOT}/core/graph/automl_ops/*.cc"
)
endif()

file(GLOB_RECURSE onnxruntime_ir_defs_src CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/defs/*.cc"
)

add_library(onnxruntime_graph ${onnxruntime_graph_src} ${onnxruntime_ir_defs_src})
add_dependencies(onnxruntime_graph onnx_proto gsl)
onnxruntime_add_include_to_target(onnxruntime_graph onnxruntime_common gsl onnx onnx_proto protobuf::libprotobuf)

target_include_directories(onnxruntime_graph PRIVATE ${ONNXRUNTIME_ROOT})
set_target_properties(onnxruntime_graph PROPERTIES FOLDER "ONNXRuntime")
set_target_properties(onnxruntime_graph PROPERTIES LINKER_LANGUAGE CXX)
Expand Down
35 changes: 29 additions & 6 deletions cmake/onnxruntime_providers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ file(GLOB_RECURSE onnxruntime_cuda_contrib_ops_cu_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/contrib_ops/cuda/*.cuh"
)

file(GLOB onnxruntime_cpu_automl_cc_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/automl_ops/cpu_automl_kernels.h"
"${ONNXRUNTIME_ROOT}/automl_ops/cpu_automl_kernels.cc"
"${ONNXRUNTIME_ROOT}/automl_ops/automl_types.h"
"${ONNXRUNTIME_ROOT}/automl_ops/automl_types.cc"
"${ONNXRUNTIME_ROOT}/automl_ops/automl_featurizers.h"
"${ONNXRUNTIME_ROOT}/automl_ops/cpu/*.h"
"${ONNXRUNTIME_ROOT}/automl_ops/cpu/*.cc"
)

file(GLOB onnxruntime_providers_common_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/*.h"
"${ONNXRUNTIME_ROOT}/core/providers/*.cc"
Expand Down Expand Up @@ -55,17 +65,30 @@ if(onnxruntime_USE_NNAPI)
list(APPEND ONNXRUNTIME_PROVIDER_NAMES nnapi)
endif()
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_common_srcs} ${onnxruntime_providers_srcs})
# add using ONNXRUNTIME_ROOT so they show up under the 'contrib_ops' folder in Visual Studio
source_group(TREE ${ONNXRUNTIME_ROOT} FILES ${onnxruntime_cpu_contrib_ops_srcs})

set(onnxruntime_providers_src ${onnxruntime_providers_common_srcs} ${onnxruntime_providers_srcs})

# disable contrib ops conditionally
if(onnxruntime_DISABLE_CONTRIB_OPS)
add_library(onnxruntime_providers ${onnxruntime_providers_common_srcs} ${onnxruntime_providers_srcs})
else()
add_library(onnxruntime_providers ${onnxruntime_providers_common_srcs} ${onnxruntime_providers_srcs} ${onnxruntime_cpu_contrib_ops_srcs})
if(NOT onnxruntime_DISABLE_CONTRIB_OPS)
# add using ONNXRUNTIME_ROOT so they show up under the 'contrib_ops' folder in Visual Studio
source_group(TREE ${ONNXRUNTIME_ROOT} FILES ${onnxruntime_cpu_contrib_ops_srcs})
list(APPEND onnxruntime_providers_src ${onnxruntime_cpu_contrib_ops_srcs})
endif()

if (onnxruntime_USE_AUTOML)
source_group(TREE ${ONNXRUNTIME_ROOT}/ FILES ${onnxruntime_cpu_automl_cc_srcs})
list(APPEND onnxruntime_providers_src ${onnxruntime_cpu_automl_cc_srcs})
endif()

add_library(onnxruntime_providers ${onnxruntime_providers_src})
onnxruntime_add_include_to_target(onnxruntime_providers onnxruntime_common onnxruntime_framework gsl onnx onnx_proto protobuf::libprotobuf)

if (onnxruntime_USE_AUTOML)
add_dependencies(onnxruntime_providers automl_featurizers)
onnxruntime_add_include_to_target(onnxruntime_providers automl_featurizers)
target_link_libraries(onnxruntime_providers automl_featurizers)
endif()

if(HAS_DEPRECATED_COPY)
#temporarily ignore this warning
#see: https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)
Expand Down
10 changes: 10 additions & 0 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ if(NOT onnxruntime_DISABLE_CONTRIB_OPS)
"${TEST_SRC_DIR}/contrib_ops/*.cc")
endif()

if(onnxruntime_USE_AUTOML)
list(APPEND onnxruntime_test_providers_src_patterns
"${TEST_SRC_DIR}/automl_ops/*.h"
"${TEST_SRC_DIR}/automl_ops/*.cc")
endif()

file(GLOB onnxruntime_test_providers_src CONFIGURE_DEPENDS
${onnxruntime_test_providers_src_patterns})
file(GLOB_RECURSE onnxruntime_test_providers_cpu_src CONFIGURE_DEPENDS
Expand Down Expand Up @@ -209,6 +215,10 @@ if(onnxruntime_USE_NNAPI)
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_nnapi)
endif()

if(onnxruntime_USE_AUTOML)
list(APPEND onnxruntime_test_providers_dependencies automl_featurizers)
endif()

file(GLOB_RECURSE onnxruntime_test_tvm_src CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/test/tvm/*.h"
"${ONNXRUNTIME_ROOT}/test/tvm/*.cc"
Expand Down
5 changes: 5 additions & 0 deletions include/onnxruntime/core/framework/op_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ template <typename T>
KernelCreateInfo BuildKernelCreateInfo();
} // namespace contrib

namespace automl {
template <typename T>
KernelCreateInfo BuildKernelCreateInfo();
} // namespace automl

namespace contrib {
namespace cuda {
template <typename T>
Expand Down
1 change: 1 addition & 0 deletions include/onnxruntime/core/graph/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ constexpr const char* kOnnxDomainAlias = "ai.onnx";
constexpr const char* kMLDomain = "ai.onnx.ml";
constexpr const char* kMSDomain = "com.microsoft";
constexpr const char* kMSNchwcDomain = "com.microsoft.nchwc";
constexpr const char* kMSAutoMLDomain = "com.microsoft.automl";
constexpr const char* kNGraphDomain = "com.intel.ai";
constexpr const char* kCpuExecutionProvider = "CPUExecutionProvider";
constexpr const char* kCudaExecutionProvider = "CUDAExecutionProvider";
Expand Down
8 changes: 8 additions & 0 deletions onnxruntime/automl_ops/automl_featurizers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// Cumulative header with automl featurizers includes exposed to
// ORT
#pragma once

#include "core/automl/featurizers/src/FeaturizerPrep/Featurizers/DateTimeFeaturizer.h"
39 changes: 39 additions & 0 deletions onnxruntime/automl_ops/automl_types.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "core/common/common.h"
#include "core/framework/data_types.h"
#include "core/framework/op_kernel.h"

#include "automl_ops/automl_types.h"
#include "automl_ops/automl_featurizers.h"

namespace dtf = Microsoft::Featurizer::DateTimeFeaturizer;

namespace onnxruntime {

// This temporary to register custom types so ORT is aware of it
// although it still can not serialize such a type.
// These character arrays must be extern so the resulting instantiated template
// is globally unique

extern const char kMsAutoMLDomain[] = "com.microsoft.automl";

extern const char kTimepointName[] = "DateTimeFeaturizer_TimePoint";
// This has to be under onnxruntime to properly specialize a function template
ORT_REGISTER_OPAQUE_TYPE(dtf::TimePoint, kMsAutoMLDomain, kTimepointName);

namespace automl {

#define REGISTER_CUSTOM_PROTO(TYPE, reg_fn) \
{ \
MLDataType mltype = DataTypeImpl::GetType<TYPE>(); \
reg_fn(mltype); \
}

void RegisterAutoMLTypes(const std::function<void(MLDataType)>& reg_fn) {
REGISTER_CUSTOM_PROTO(dtf::TimePoint, reg_fn);
}
#undef REGISTER_CUSTOM_PROTO
} // namespace automl
} // namespace onnxruntime
13 changes: 13 additions & 0 deletions onnxruntime/automl_ops/automl_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once

#include "core/framework/data_types.h"
#include <functional>

namespace onnxruntime {
namespace automl {
void RegisterAutoMLTypes(const std::function<void(MLDataType)>& reg_fn);
} // namespace automl
} // namespace onnxruntime
42 changes: 42 additions & 0 deletions onnxruntime/automl_ops/cpu/datetime_transformer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "core/common/common.h"
#include "core/framework/data_types.h"
#include "core/framework/op_kernel.h"

#include "core/automl/featurizers/src/FeaturizerPrep/Featurizers/DateTimeFeaturizer.h"

namespace dtf = Microsoft::Featurizer::DateTimeFeaturizer;

namespace onnxruntime {
namespace automl {

class DateTimeTransformer final : public OpKernel {
public:
explicit DateTimeTransformer(const OpKernelInfo& info) : OpKernel(info) {}
Status Compute(OpKernelContext* context) const override;
};

Status DateTimeTransformer::Compute(OpKernelContext* ctx) const {
Status s;
auto input_tensor = ctx->Input<Tensor>(0);
dtf::TimePoint* output = ctx->Output<dtf::TimePoint>(0);

int64_t tp = *input_tensor->Data<int64_t>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be a transformer that transforms a tensor (not necessarily a scalar) of ints to a tensor/array of time_points? Or, is it supposed to be restricted to the case where the input is a scalar? Assuming that automl needs to work with batches of inputs, I would have expected support for a tensor of ints, not just a scalar.

Copy link
Member Author

Choose a reason for hiding this comment

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

The answer to this is no. This transformer transforms a single timepoint into a Featurizer specific type. We may come to batches. This kernel is very experimental to verify that we can share the code, create models on a .MET side and run them.

std::chrono::system_clock::time_point sys_time{std::chrono::seconds(tp)};
*output = std::move(dtf::SystemToDPTimePoint(sys_time));
return s;
}

ONNX_OPERATOR_KERNEL_EX(
DateTimeTransformer,
kMSAutoMLDomain,
1,
kCpuExecutionProvider,
KernelDefBuilder()
.TypeConstraint("T1", DataTypeImpl::GetTensorType<int64_t>())
.TypeConstraint("T2", DataTypeImpl::GetType<Microsoft::Featurizer::DateTimeFeaturizer::TimePoint>()),
DateTimeTransformer);
} // namespace automl
} // namespace onnxruntime
25 changes: 25 additions & 0 deletions onnxruntime/automl_ops/cpu_automl_kernels.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "automl_ops/cpu_automl_kernels.h"
#include "core/graph/constants.h"
#include "core/framework/data_types.h"

namespace onnxruntime {
namespace automl {

class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSAutoMLDomain, 1, DateTimeTransformer);

void RegisterCpuAutoMLKernels(KernelRegistry& kernel_registry) {
static const BuildKernelCreateInfoFn function_table[] = {
// add more kernels here
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSAutoMLDomain, 1, DateTimeTransformer)>
};

for (auto& function_table_entry : function_table) {
kernel_registry.Register(function_table_entry());
}
}

} // namespace automl
} // namespace onnxruntime
13 changes: 13 additions & 0 deletions onnxruntime/automl_ops/cpu_automl_kernels.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once

#include "core/framework/op_kernel.h"
#include "core/framework/kernel_registry.h"

namespace onnxruntime {
namespace automl {
void RegisterCpuAutoMLKernels(KernelRegistry& kernel_registry);
} // namespace automl
} // namespace onnxruntime
Loading