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

Generate model paths for end2end tests at build. #136

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions src/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ source_set("webnn_end2end_tests_sources") {
configs += [ "${webnn_root}/src/common:dawn_internal" ]
testonly = true

_models_folder_relative_path =
"../../node/third_party/webnn-polyfill/test-data/models/"

_data_path = rebase_path(_models_folder_relative_path, webnn_root)
_webnn_root_data_path =
get_path_info("${webnn_root}" + "${_data_path}", "dir")
_models_folder_absolute_path = rebase_path(_webnn_root_data_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe the end_2_end can't be run if all binaries are packaged to run in other directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fujunwei, we should be able to run the end2end tests from any directory (eg. under .\third_party), so long as they don't assume to load files using relative paths (ex. node\folder).

This is how _models_folder_absolute_path gets set, eg. C:\Users\bryan\src\webnn_native\node\models or C:\Users\bryan\src\<some project>\third_party\webnn_native\node\modes, depending on webnn_root.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We will public webNN-native with node.js to npm, users get the package and install in their local system that is not the webnn_root(C:\Users\bryan\src), it will fail to run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fujunwei, we can't run these tests with an unresolved install-time path (custom path vs DEPS). This change assumes DEPS path is used, like how BUILD.gn locates source-files. If the user wants to install their own custom node package, they (still) need to use the same path (install under .\node) or say, be given an option to override the DEPS path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fujunwei PTAL. We cannot run end2end tests under .\third_party without this fix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's merge it first, we can add the relative path option to run model test when we have the requirement. Thanks.


defines =
[ "WEBNN_END2END_TEST_MODEL_PATH=\"${_models_folder_absolute_path}\"" ]

deps = [
":gmock_and_gtest",
"${webnn_root}/examples:webnn_sample_utils",
Expand Down
5 changes: 3 additions & 2 deletions src/tests/end2end/models/MobileNetV2BatchNormNchw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "examples/MobileNetV2/MobileNetV2.h"
#include "src/tests/WebnnTest.h"

static const std::string kModelPath = WEBNN_END2END_TEST_MODEL_PATH;

class MobileNetV2BatchNormNchwTests : public WebnnTest {
public:
void TestMobileNetV2Nchw(const std::string& inputFile,
const std::string& expectedFile,
bool fused = true) {
MobileNetV2 mobilenetv2;
mobilenetv2.mFused = fused;
const std::string nchwPath =
"node/third_party/webnn-polyfill/test-data/models/mobilenetv2_batchnorm_nchw/";
const std::string nchwPath = kModelPath + "/mobilenetv2_batchnorm_nchw/";
mobilenetv2.mWeightsPath = nchwPath + "weights/";
const ml::GraphBuilder builder = ml::CreateGraphBuilder(GetContext());
ml::Operand output = mobilenetv2.LoadBatchNormNCHW(builder, false);
Expand Down
5 changes: 3 additions & 2 deletions src/tests/end2end/models/MobileNetV2Nchw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "examples/MobileNetV2/MobileNetV2.h"
#include "src/tests/WebnnTest.h"

static const std::string kModelPath = WEBNN_END2END_TEST_MODEL_PATH;

class MobileNetV2NchwTests : public WebnnTest {
public:
void TestMobileNetV2Nchw(const std::string& inputFile,
const std::string& expectedFile,
bool fused = true) {
MobileNetV2 mobilenetv2;
mobilenetv2.mFused = fused;
const std::string nchwPath =
"node/third_party/webnn-polyfill/test-data/models/mobilenetv2_nchw/";
const std::string nchwPath = kModelPath + "/mobilenetv2_nchw/";
mobilenetv2.mWeightsPath = nchwPath + "weights/";
const ml::GraphBuilder builder = ml::CreateGraphBuilder(GetContext());
ml::Operand output = mobilenetv2.LoadNCHW(builder, false);
Expand Down
5 changes: 3 additions & 2 deletions src/tests/end2end/models/MobileNetV2Nhwc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "examples/MobileNetV2/MobileNetV2.h"
#include "src/tests/WebnnTest.h"

static const std::string kModelPath = WEBNN_END2END_TEST_MODEL_PATH;

class MobileNetV2NhwcTests : public WebnnTest {
public:
void TestMobileNetV2Nhwc(const std::string& inputFile,
const std::string& expectedFile,
bool fused = true) {
MobileNetV2 mobilenetv2;
mobilenetv2.mFused = fused;
const std::string nhwcPath =
"node/third_party/webnn-polyfill/test-data/models/mobilenetv2_nhwc/";
const std::string nhwcPath = kModelPath + "/mobilenetv2_nhwc/";
mobilenetv2.mWeightsPath = nhwcPath + "weights/";
mobilenetv2.mLayout = "nhwc";
const ml::GraphBuilder builder = ml::CreateGraphBuilder(GetContext());
Expand Down
5 changes: 3 additions & 2 deletions src/tests/end2end/models/ResNetNchw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "examples/ResNet/ResNet.h"
#include "src/tests/WebnnTest.h"

static const std::string kModelPath = WEBNN_END2END_TEST_MODEL_PATH;

class ResNetNchwTests : public WebnnTest {
public:
void TestResNetNchw(const std::string& inputFile,
const std::string& expectedFile,
bool fused = true) {
ResNet resnet;
resnet.mFused = fused;
const std::string nchwPath =
"node/third_party/webnn-polyfill/test-data/models/resnet50v2_nchw/";
const std::string nchwPath = kModelPath + "/resnet50v2_nchw/";
resnet.mWeightsPath = nchwPath + "weights/";
const ml::GraphBuilder builder = ml::CreateGraphBuilder(GetContext());
ml::Operand output = resnet.LoadNCHW(builder, false);
Expand Down
5 changes: 3 additions & 2 deletions src/tests/end2end/models/ResNetNhwc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "examples/ResNet/ResNet.h"
#include "src/tests/WebnnTest.h"

static const std::string kModelPath = WEBNN_END2END_TEST_MODEL_PATH;

class ResNetNhwcTests : public WebnnTest {
public:
void TestResNetNhwc(const std::string& inputFile,
const std::string& expectedFile,
bool fused = true) {
ResNet resnet;
resnet.mFused = fused;
const std::string nhwcPath =
"node/third_party/webnn-polyfill/test-data/models/resnet101v2_nhwc/";
const std::string nhwcPath = kModelPath + "/resnet101v2_nhwc/";
resnet.mWeightsPath = nhwcPath + "weights/";
const ml::GraphBuilder builder = ml::CreateGraphBuilder(GetContext());
ml::Operand output = resnet.LoadNHWC(builder, false);
Expand Down
5 changes: 3 additions & 2 deletions src/tests/end2end/models/SqueezeNetNchw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "examples/SqueezeNet/SqueezeNet.h"
#include "src/tests/WebnnTest.h"

static const std::string kModelPath = WEBNN_END2END_TEST_MODEL_PATH;

class SqueezeNetNchwTests : public WebnnTest {
public:
void TestSqueezeNetNchw(const std::string& inputFile,
const std::string& expectedFile,
bool fused = true) {
SqueezeNet squeezenet;
squeezenet.mFused = fused;
const std::string nchwPath =
"node/third_party/webnn-polyfill/test-data/models/squeezenet1.1_nchw/";
const std::string nchwPath = kModelPath + "/squeezenet1.1_nchw/";
squeezenet.mWeightsPath = nchwPath + "weights/";
const ml::GraphBuilder builder = ml::CreateGraphBuilder(GetContext());
ml::Operand output = squeezenet.LoadNCHW(builder, false);
Expand Down
5 changes: 3 additions & 2 deletions src/tests/end2end/models/SqueezeNetNhwc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "examples/SqueezeNet/SqueezeNet.h"
#include "src/tests/WebnnTest.h"

static const std::string kModelPath = WEBNN_END2END_TEST_MODEL_PATH;

class SqueezeNetNhwcTests : public WebnnTest {
public:
void TestSqueezeNetNhwc(const std::string& inputFile,
const std::string& expectedFile,
bool fused = true) {
SqueezeNet squeezenet;
squeezenet.mFused = fused;
const std::string nhwcPath =
"node/third_party/webnn-polyfill/test-data/models/squeezenet1.0_nhwc/";
const std::string nhwcPath = kModelPath + "/squeezenet1.0_nhwc/";
squeezenet.mWeightsPath = nhwcPath + "weights/";
squeezenet.mLayout = "nhwc";
const ml::GraphBuilder builder = ml::CreateGraphBuilder(GetContext());
Expand Down
1 change: 1 addition & 0 deletions third_party/gpgmm
Submodule gpgmm added at 8cab51