react-native-executorch 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/rnexecutorch/TokenizerModule.cpp +3 -2
- package/common/rnexecutorch/TokenizerModule.h +1 -1
- package/lib/module/modules/computer_vision/TextToImageModule.js +8 -4
- package/lib/module/modules/computer_vision/TextToImageModule.js.map +1 -1
- package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/modules/computer_vision/TextToImageModule.ts +9 -4
- package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
- package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_model.h +84 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_tokenizer_base.h +6 -87
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/hf_tokenizer.h +28 -176
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/map_utils.h +174 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/model.h +151 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/normalizer.h +55 -1
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/padding.h +112 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/post_processor.h +101 -42
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/pre_tokenizer.h +25 -9
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/token_decoder.h +33 -6
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/tokenizer.h +2 -2
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/truncation.h +92 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/wordpiece_model.h +74 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/common/rnexecutorch/tests/CMakeLists.txt +0 -253
- package/common/rnexecutorch/tests/README.md +0 -73
- package/common/rnexecutorch/tests/integration/BaseModelTest.cpp +0 -207
- package/common/rnexecutorch/tests/integration/BaseModelTests.h +0 -120
- package/common/rnexecutorch/tests/integration/ClassificationTest.cpp +0 -117
- package/common/rnexecutorch/tests/integration/ImageEmbeddingsTest.cpp +0 -122
- package/common/rnexecutorch/tests/integration/ImageSegmentationTest.cpp +0 -152
- package/common/rnexecutorch/tests/integration/LLMTest.cpp +0 -155
- package/common/rnexecutorch/tests/integration/OCRTest.cpp +0 -128
- package/common/rnexecutorch/tests/integration/ObjectDetectionTest.cpp +0 -135
- package/common/rnexecutorch/tests/integration/SpeechToTextTest.cpp +0 -97
- package/common/rnexecutorch/tests/integration/StyleTransferTest.cpp +0 -112
- package/common/rnexecutorch/tests/integration/TextEmbeddingsTest.cpp +0 -164
- package/common/rnexecutorch/tests/integration/TextToImageTest.cpp +0 -149
- package/common/rnexecutorch/tests/integration/TokenizerModuleTest.cpp +0 -98
- package/common/rnexecutorch/tests/integration/VerticalOCRTest.cpp +0 -238
- package/common/rnexecutorch/tests/integration/VoiceActivityDetectionTest.cpp +0 -99
- package/common/rnexecutorch/tests/integration/assets/test_audio_float.raw +0 -0
- package/common/rnexecutorch/tests/integration/assets/we_are_software_mansion.jpg +0 -0
- package/common/rnexecutorch/tests/integration/libs/libfbjni.so +0 -0
- package/common/rnexecutorch/tests/integration/stubs/jsi_stubs.cpp +0 -45
- package/common/rnexecutorch/tests/integration/utils/TestUtils.h +0 -36
- package/common/rnexecutorch/tests/run_tests.sh +0 -333
- package/common/rnexecutorch/tests/unit/FileUtilsTest.cpp +0 -32
- package/common/rnexecutorch/tests/unit/LogTest.cpp +0 -529
- package/common/rnexecutorch/tests/unit/NumericalTest.cpp +0 -107
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
#include "BaseModelTests.h"
|
|
2
|
-
#include <gtest/gtest.h>
|
|
3
|
-
#include <rnexecutorch/Error.h>
|
|
4
|
-
#include <rnexecutorch/models/object_detection/Constants.h>
|
|
5
|
-
#include <rnexecutorch/models/object_detection/ObjectDetection.h>
|
|
6
|
-
|
|
7
|
-
using namespace rnexecutorch;
|
|
8
|
-
using namespace rnexecutorch::models::object_detection;
|
|
9
|
-
using namespace model_tests;
|
|
10
|
-
|
|
11
|
-
constexpr auto kValidObjectDetectionModelPath =
|
|
12
|
-
"ssdlite320-mobilenetv3-large.pte";
|
|
13
|
-
constexpr auto kValidTestImagePath =
|
|
14
|
-
"file:///data/local/tmp/rnexecutorch_tests/test_image.jpg";
|
|
15
|
-
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Common tests via typed test suite
|
|
18
|
-
// ============================================================================
|
|
19
|
-
namespace model_tests {
|
|
20
|
-
template <> struct ModelTraits<ObjectDetection> {
|
|
21
|
-
using ModelType = ObjectDetection;
|
|
22
|
-
|
|
23
|
-
static ModelType createValid() {
|
|
24
|
-
return ModelType(kValidObjectDetectionModelPath, nullptr);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static ModelType createInvalid() {
|
|
28
|
-
return ModelType("nonexistent.pte", nullptr);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static void callGenerate(ModelType &model) {
|
|
32
|
-
(void)model.generate(kValidTestImagePath, 0.5);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
} // namespace model_tests
|
|
36
|
-
|
|
37
|
-
using ObjectDetectionTypes = ::testing::Types<ObjectDetection>;
|
|
38
|
-
INSTANTIATE_TYPED_TEST_SUITE_P(ObjectDetection, CommonModelTest,
|
|
39
|
-
ObjectDetectionTypes);
|
|
40
|
-
|
|
41
|
-
// ============================================================================
|
|
42
|
-
// Model-specific tests
|
|
43
|
-
// ============================================================================
|
|
44
|
-
TEST(ObjectDetectionGenerateTests, InvalidImagePathThrows) {
|
|
45
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
46
|
-
EXPECT_THROW((void)model.generate("nonexistent_image.jpg", 0.5),
|
|
47
|
-
RnExecutorchError);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
TEST(ObjectDetectionGenerateTests, EmptyImagePathThrows) {
|
|
51
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
52
|
-
EXPECT_THROW((void)model.generate("", 0.5), RnExecutorchError);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
TEST(ObjectDetectionGenerateTests, MalformedURIThrows) {
|
|
56
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
57
|
-
EXPECT_THROW((void)model.generate("not_a_valid_uri://bad", 0.5),
|
|
58
|
-
RnExecutorchError);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
TEST(ObjectDetectionGenerateTests, NegativeThresholdThrows) {
|
|
62
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
63
|
-
EXPECT_THROW((void)model.generate(kValidTestImagePath, -0.1),
|
|
64
|
-
RnExecutorchError);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
TEST(ObjectDetectionGenerateTests, ThresholdAboveOneThrows) {
|
|
68
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
69
|
-
EXPECT_THROW((void)model.generate(kValidTestImagePath, 1.1),
|
|
70
|
-
RnExecutorchError);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
TEST(ObjectDetectionGenerateTests, ValidImageReturnsResults) {
|
|
74
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
75
|
-
auto results = model.generate(kValidTestImagePath, 0.3);
|
|
76
|
-
EXPECT_GE(results.size(), 0u);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
TEST(ObjectDetectionGenerateTests, HighThresholdReturnsFewerResults) {
|
|
80
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
81
|
-
auto lowThresholdResults = model.generate(kValidTestImagePath, 0.1);
|
|
82
|
-
auto highThresholdResults = model.generate(kValidTestImagePath, 0.9);
|
|
83
|
-
EXPECT_GE(lowThresholdResults.size(), highThresholdResults.size());
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
TEST(ObjectDetectionGenerateTests, DetectionsHaveValidBoundingBoxes) {
|
|
87
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
88
|
-
auto results = model.generate(kValidTestImagePath, 0.3);
|
|
89
|
-
|
|
90
|
-
for (const auto &detection : results) {
|
|
91
|
-
EXPECT_LE(detection.x1, detection.x2);
|
|
92
|
-
EXPECT_LE(detection.y1, detection.y2);
|
|
93
|
-
EXPECT_GE(detection.x1, 0.0f);
|
|
94
|
-
EXPECT_GE(detection.y1, 0.0f);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
TEST(ObjectDetectionGenerateTests, DetectionsHaveValidScores) {
|
|
99
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
100
|
-
auto results = model.generate(kValidTestImagePath, 0.3);
|
|
101
|
-
|
|
102
|
-
for (const auto &detection : results) {
|
|
103
|
-
EXPECT_GE(detection.score, 0.0f);
|
|
104
|
-
EXPECT_LE(detection.score, 1.0f);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
TEST(ObjectDetectionGenerateTests, DetectionsHaveValidLabels) {
|
|
109
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
110
|
-
auto results = model.generate(kValidTestImagePath, 0.3);
|
|
111
|
-
|
|
112
|
-
for (const auto &detection : results) {
|
|
113
|
-
EXPECT_GE(detection.label, 0);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
TEST(ObjectDetectionInheritedTests, GetInputShapeWorks) {
|
|
118
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
119
|
-
auto shape = model.getInputShape("forward", 0);
|
|
120
|
-
EXPECT_EQ(shape.size(), 4);
|
|
121
|
-
EXPECT_EQ(shape[0], 1);
|
|
122
|
-
EXPECT_EQ(shape[1], 3);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
TEST(ObjectDetectionInheritedTests, GetAllInputShapesWorks) {
|
|
126
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
127
|
-
auto shapes = model.getAllInputShapes("forward");
|
|
128
|
-
EXPECT_FALSE(shapes.empty());
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
TEST(ObjectDetectionInheritedTests, GetMethodMetaWorks) {
|
|
132
|
-
ObjectDetection model(kValidObjectDetectionModelPath, nullptr);
|
|
133
|
-
auto result = model.getMethodMeta("forward");
|
|
134
|
-
EXPECT_TRUE(result.ok());
|
|
135
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
#include "BaseModelTests.h"
|
|
2
|
-
#include "utils/TestUtils.h"
|
|
3
|
-
#include <gtest/gtest.h>
|
|
4
|
-
#include <rnexecutorch/Error.h>
|
|
5
|
-
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
|
|
6
|
-
|
|
7
|
-
using namespace rnexecutorch;
|
|
8
|
-
using namespace rnexecutorch::models::speech_to_text;
|
|
9
|
-
using namespace test_utils;
|
|
10
|
-
using namespace model_tests;
|
|
11
|
-
|
|
12
|
-
constexpr auto kValidEncoderPath = "whisper_tiny_en_encoder_xnnpack.pte";
|
|
13
|
-
constexpr auto kValidDecoderPath = "whisper_tiny_en_decoder_xnnpack.pte";
|
|
14
|
-
constexpr auto kValidTokenizerPath = "whisper_tokenizer.json";
|
|
15
|
-
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Common tests via typed test suite
|
|
18
|
-
// ============================================================================
|
|
19
|
-
namespace model_tests {
|
|
20
|
-
template <> struct ModelTraits<SpeechToText> {
|
|
21
|
-
using ModelType = SpeechToText;
|
|
22
|
-
|
|
23
|
-
static ModelType createValid() {
|
|
24
|
-
return ModelType(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
|
|
25
|
-
nullptr);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static ModelType createInvalid() {
|
|
29
|
-
return ModelType("nonexistent.pte", kValidDecoderPath, kValidTokenizerPath,
|
|
30
|
-
nullptr);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static void callGenerate(ModelType &model) {
|
|
34
|
-
auto audio = test_utils::loadAudioFromFile("test_audio_float.raw");
|
|
35
|
-
(void)model.transcribe(audio, "en");
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
} // namespace model_tests
|
|
39
|
-
|
|
40
|
-
using SpeechToTextTypes = ::testing::Types<SpeechToText>;
|
|
41
|
-
INSTANTIATE_TYPED_TEST_SUITE_P(SpeechToText, CommonModelTest,
|
|
42
|
-
SpeechToTextTypes);
|
|
43
|
-
|
|
44
|
-
// ============================================================================
|
|
45
|
-
// Model-specific tests
|
|
46
|
-
// ============================================================================
|
|
47
|
-
TEST(S2TCtorTests, InvalidDecoderPathThrows) {
|
|
48
|
-
EXPECT_THROW(SpeechToText(kValidEncoderPath, "nonexistent.pte",
|
|
49
|
-
kValidTokenizerPath, nullptr),
|
|
50
|
-
RnExecutorchError);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
TEST(S2TCtorTests, InvalidTokenizerPathThrows) {
|
|
54
|
-
EXPECT_THROW(SpeechToText(kValidEncoderPath, kValidDecoderPath,
|
|
55
|
-
"nonexistent.json", nullptr),
|
|
56
|
-
RnExecutorchError);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
TEST(S2TEncodeTests, EncodeReturnsNonNull) {
|
|
60
|
-
SpeechToText model(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
|
|
61
|
-
nullptr);
|
|
62
|
-
auto audio = loadAudioFromFile("test_audio_float.raw");
|
|
63
|
-
ASSERT_FALSE(audio.empty());
|
|
64
|
-
auto result = model.encode(audio);
|
|
65
|
-
EXPECT_NE(result, nullptr);
|
|
66
|
-
EXPECT_GT(result->size(), 0u);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
TEST(S2TTranscribeTests, TranscribeReturnsValidChars) {
|
|
70
|
-
SpeechToText model(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
|
|
71
|
-
nullptr);
|
|
72
|
-
auto audio = loadAudioFromFile("test_audio_float.raw");
|
|
73
|
-
ASSERT_FALSE(audio.empty());
|
|
74
|
-
auto result = model.transcribe(audio, "en");
|
|
75
|
-
ASSERT_FALSE(result.empty());
|
|
76
|
-
for (char c : result) {
|
|
77
|
-
EXPECT_GE(static_cast<unsigned char>(c), 0);
|
|
78
|
-
EXPECT_LE(static_cast<unsigned char>(c), 127);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
TEST(S2TTranscribeTests, EmptyResultOnSilence) {
|
|
83
|
-
SpeechToText model(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
|
|
84
|
-
nullptr);
|
|
85
|
-
auto audio = generateSilence(16000 * 5);
|
|
86
|
-
auto result = model.transcribe(audio, "en");
|
|
87
|
-
EXPECT_TRUE(result.empty());
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
TEST(S2TTranscribeTests, InvalidLanguageThrows) {
|
|
91
|
-
SpeechToText model(kValidEncoderPath, kValidDecoderPath, kValidTokenizerPath,
|
|
92
|
-
nullptr);
|
|
93
|
-
auto audio = loadAudioFromFile("test_audio_float.raw");
|
|
94
|
-
ASSERT_FALSE(audio.empty());
|
|
95
|
-
EXPECT_THROW((void)model.transcribe(audio, "invalid_language_code"),
|
|
96
|
-
RnExecutorchError);
|
|
97
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
#include "BaseModelTests.h"
|
|
2
|
-
#include "utils/TestUtils.h"
|
|
3
|
-
#include <filesystem>
|
|
4
|
-
#include <gtest/gtest.h>
|
|
5
|
-
#include <rnexecutorch/Error.h>
|
|
6
|
-
#include <rnexecutorch/models/style_transfer/StyleTransfer.h>
|
|
7
|
-
|
|
8
|
-
using namespace rnexecutorch;
|
|
9
|
-
using namespace rnexecutorch::models::style_transfer;
|
|
10
|
-
using namespace model_tests;
|
|
11
|
-
|
|
12
|
-
constexpr auto kValidStyleTransferModelPath =
|
|
13
|
-
"style_transfer_candy_xnnpack.pte";
|
|
14
|
-
constexpr auto kValidTestImagePath =
|
|
15
|
-
"file:///data/local/tmp/rnexecutorch_tests/test_image.jpg";
|
|
16
|
-
|
|
17
|
-
// ============================================================================
|
|
18
|
-
// Common tests via typed test suite
|
|
19
|
-
// ============================================================================
|
|
20
|
-
namespace model_tests {
|
|
21
|
-
template <> struct ModelTraits<StyleTransfer> {
|
|
22
|
-
using ModelType = StyleTransfer;
|
|
23
|
-
|
|
24
|
-
static ModelType createValid() {
|
|
25
|
-
return ModelType(kValidStyleTransferModelPath, nullptr);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static ModelType createInvalid() {
|
|
29
|
-
return ModelType("nonexistent.pte", nullptr);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static void callGenerate(ModelType &model) {
|
|
33
|
-
(void)model.generate(kValidTestImagePath);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
} // namespace model_tests
|
|
37
|
-
|
|
38
|
-
using StyleTransferTypes = ::testing::Types<StyleTransfer>;
|
|
39
|
-
INSTANTIATE_TYPED_TEST_SUITE_P(StyleTransfer, CommonModelTest,
|
|
40
|
-
StyleTransferTypes);
|
|
41
|
-
|
|
42
|
-
// ============================================================================
|
|
43
|
-
// Model-specific tests
|
|
44
|
-
// ============================================================================
|
|
45
|
-
TEST(StyleTransferGenerateTests, InvalidImagePathThrows) {
|
|
46
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
47
|
-
EXPECT_THROW((void)model.generate("nonexistent_image.jpg"),
|
|
48
|
-
RnExecutorchError);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
TEST(StyleTransferGenerateTests, EmptyImagePathThrows) {
|
|
52
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
53
|
-
EXPECT_THROW((void)model.generate(""), RnExecutorchError);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
TEST(StyleTransferGenerateTests, MalformedURIThrows) {
|
|
57
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
58
|
-
EXPECT_THROW((void)model.generate("not_a_valid_uri://bad"),
|
|
59
|
-
RnExecutorchError);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
TEST(StyleTransferGenerateTests, ValidImageReturnsFilePath) {
|
|
63
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
64
|
-
auto result = model.generate(kValidTestImagePath);
|
|
65
|
-
EXPECT_FALSE(result.empty());
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
TEST(StyleTransferGenerateTests, ResultIsValidFilePath) {
|
|
69
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
70
|
-
auto result = model.generate(kValidTestImagePath);
|
|
71
|
-
test_utils::trimFilePrefix(result);
|
|
72
|
-
EXPECT_TRUE(std::filesystem::exists(result));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
TEST(StyleTransferGenerateTests, ResultFileHasContent) {
|
|
76
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
77
|
-
auto result = model.generate(kValidTestImagePath);
|
|
78
|
-
test_utils::trimFilePrefix(result);
|
|
79
|
-
auto fileSize = std::filesystem::file_size(result);
|
|
80
|
-
EXPECT_GT(fileSize, 0u);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
TEST(StyleTransferGenerateTests, MultipleGeneratesWork) {
|
|
84
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
85
|
-
EXPECT_NO_THROW((void)model.generate(kValidTestImagePath));
|
|
86
|
-
auto result1 = model.generate(kValidTestImagePath);
|
|
87
|
-
auto result2 = model.generate(kValidTestImagePath);
|
|
88
|
-
test_utils::trimFilePrefix(result1);
|
|
89
|
-
test_utils::trimFilePrefix(result2);
|
|
90
|
-
EXPECT_TRUE(std::filesystem::exists(result1));
|
|
91
|
-
EXPECT_TRUE(std::filesystem::exists(result2));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
TEST(StyleTransferInheritedTests, GetInputShapeWorks) {
|
|
95
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
96
|
-
auto shape = model.getInputShape("forward", 0);
|
|
97
|
-
EXPECT_EQ(shape.size(), 4);
|
|
98
|
-
EXPECT_EQ(shape[0], 1);
|
|
99
|
-
EXPECT_EQ(shape[1], 3);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
TEST(StyleTransferInheritedTests, GetAllInputShapesWorks) {
|
|
103
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
104
|
-
auto shapes = model.getAllInputShapes("forward");
|
|
105
|
-
EXPECT_FALSE(shapes.empty());
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
TEST(StyleTransferInheritedTests, GetMethodMetaWorks) {
|
|
109
|
-
StyleTransfer model(kValidStyleTransferModelPath, nullptr);
|
|
110
|
-
auto result = model.getMethodMeta("forward");
|
|
111
|
-
EXPECT_TRUE(result.ok());
|
|
112
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
#include "BaseModelTests.h"
|
|
2
|
-
#include <cmath>
|
|
3
|
-
#include <gtest/gtest.h>
|
|
4
|
-
#include <rnexecutorch/Error.h>
|
|
5
|
-
#include <rnexecutorch/models/embeddings/text/TextEmbeddings.h>
|
|
6
|
-
#include <string>
|
|
7
|
-
|
|
8
|
-
using namespace rnexecutorch;
|
|
9
|
-
using namespace rnexecutorch::models::embeddings;
|
|
10
|
-
using namespace model_tests;
|
|
11
|
-
|
|
12
|
-
constexpr auto kValidTextEmbeddingsModelPath = "all-MiniLM-L6-v2_xnnpack.pte";
|
|
13
|
-
constexpr auto kValidTextEmbeddingsTokenizerPath = "tokenizer.json";
|
|
14
|
-
constexpr size_t kMiniLmEmbeddingDimensions = 384;
|
|
15
|
-
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Common tests via typed test suite
|
|
18
|
-
// ============================================================================
|
|
19
|
-
namespace model_tests {
|
|
20
|
-
template <> struct ModelTraits<TextEmbeddings> {
|
|
21
|
-
using ModelType = TextEmbeddings;
|
|
22
|
-
|
|
23
|
-
static ModelType createValid() {
|
|
24
|
-
return ModelType(kValidTextEmbeddingsModelPath,
|
|
25
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static ModelType createInvalid() {
|
|
29
|
-
return ModelType("nonexistent.pte", kValidTextEmbeddingsTokenizerPath,
|
|
30
|
-
nullptr);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static void callGenerate(ModelType &model) {
|
|
34
|
-
(void)model.generate("Hello, world!");
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
} // namespace model_tests
|
|
38
|
-
|
|
39
|
-
using TextEmbeddingsTypes = ::testing::Types<TextEmbeddings>;
|
|
40
|
-
INSTANTIATE_TYPED_TEST_SUITE_P(TextEmbeddings, CommonModelTest,
|
|
41
|
-
TextEmbeddingsTypes);
|
|
42
|
-
|
|
43
|
-
// ============================================================================
|
|
44
|
-
// Model-specific tests
|
|
45
|
-
// ============================================================================
|
|
46
|
-
TEST(TextEmbeddingsCtorTests, InvalidTokenizerPathThrows) {
|
|
47
|
-
EXPECT_THROW(TextEmbeddings(kValidTextEmbeddingsModelPath,
|
|
48
|
-
"this_tokenizer_does_not_exist.json", nullptr),
|
|
49
|
-
std::exception);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
TEST(TextEmbeddingsGenerateTests, EmptyStringReturnsResults) {
|
|
53
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
54
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
55
|
-
auto result = model.generate("");
|
|
56
|
-
EXPECT_NE(result, nullptr);
|
|
57
|
-
EXPECT_GT(result->size(), 0u);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
TEST(TextEmbeddingsGenerateTests, ValidTextReturnsResults) {
|
|
61
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
62
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
63
|
-
auto result = model.generate("Hello, world!");
|
|
64
|
-
EXPECT_NE(result, nullptr);
|
|
65
|
-
EXPECT_GT(result->size(), 0u);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
TEST(TextEmbeddingsGenerateTests, ResultsHaveCorrectSize) {
|
|
69
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
70
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
71
|
-
auto result = model.generate("This is a test sentence.");
|
|
72
|
-
size_t numFloats = result->size() / sizeof(float);
|
|
73
|
-
EXPECT_EQ(numFloats, kMiniLmEmbeddingDimensions);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
TEST(TextEmbeddingsGenerateTests, ResultsAreNormalized) {
|
|
77
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
78
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
79
|
-
auto result = model.generate("The quick brown fox jumps over the lazy dog.");
|
|
80
|
-
|
|
81
|
-
const float *data = reinterpret_cast<const float *>(result->data());
|
|
82
|
-
size_t numFloats = result->size() / sizeof(float);
|
|
83
|
-
|
|
84
|
-
float sumOfSquares = 0.0f;
|
|
85
|
-
for (size_t i = 0; i < numFloats; ++i) {
|
|
86
|
-
sumOfSquares += data[i] * data[i];
|
|
87
|
-
}
|
|
88
|
-
float norm = std::sqrt(sumOfSquares);
|
|
89
|
-
EXPECT_NEAR(norm, 1.0f, 0.01f);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
TEST(TextEmbeddingsGenerateTests, ResultsContainValidValues) {
|
|
93
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
94
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
95
|
-
auto result = model.generate("Testing valid values.");
|
|
96
|
-
|
|
97
|
-
const float *data = reinterpret_cast<const float *>(result->data());
|
|
98
|
-
size_t numFloats = result->size() / sizeof(float);
|
|
99
|
-
|
|
100
|
-
for (size_t i = 0; i < numFloats; ++i) {
|
|
101
|
-
EXPECT_FALSE(std::isnan(data[i]));
|
|
102
|
-
EXPECT_FALSE(std::isinf(data[i]));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
TEST(TextEmbeddingsGenerateTests, DifferentTextProducesDifferentEmbeddings) {
|
|
107
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
108
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
109
|
-
|
|
110
|
-
auto result1 = model.generate("Hello, world!");
|
|
111
|
-
auto result2 = model.generate("Goodbye, moon!");
|
|
112
|
-
|
|
113
|
-
const float *data1 = reinterpret_cast<const float *>(result1->data());
|
|
114
|
-
const float *data2 = reinterpret_cast<const float *>(result2->data());
|
|
115
|
-
size_t numFloats = result1->size() / sizeof(float);
|
|
116
|
-
|
|
117
|
-
bool allEqual = true;
|
|
118
|
-
for (size_t i = 0; i < numFloats; ++i) {
|
|
119
|
-
if (std::abs(data1[i] - data2[i]) > 1e-6f) {
|
|
120
|
-
allEqual = false;
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
EXPECT_FALSE(allEqual);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
TEST(TextEmbeddingsGenerateTests, SimilarTextProducesSimilarEmbeddings) {
|
|
128
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
129
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
130
|
-
|
|
131
|
-
auto result1 = model.generate("I love programming");
|
|
132
|
-
auto result2 = model.generate("I enjoy coding");
|
|
133
|
-
|
|
134
|
-
const float *data1 = reinterpret_cast<const float *>(result1->data());
|
|
135
|
-
const float *data2 = reinterpret_cast<const float *>(result2->data());
|
|
136
|
-
size_t numFloats = result1->size() / sizeof(float);
|
|
137
|
-
|
|
138
|
-
float dotProduct = 0.0f;
|
|
139
|
-
for (size_t i = 0; i < numFloats; ++i) {
|
|
140
|
-
dotProduct += data1[i] * data2[i];
|
|
141
|
-
}
|
|
142
|
-
EXPECT_GT(dotProduct, 0.5f);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
TEST(TextEmbeddingsInheritedTests, GetInputShapeWorks) {
|
|
146
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
147
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
148
|
-
auto shape = model.getInputShape("forward", 0);
|
|
149
|
-
EXPECT_GE(shape.size(), 2u);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
TEST(TextEmbeddingsInheritedTests, GetAllInputShapesWorks) {
|
|
153
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
154
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
155
|
-
auto shapes = model.getAllInputShapes("forward");
|
|
156
|
-
EXPECT_FALSE(shapes.empty());
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
TEST(TextEmbeddingsInheritedTests, GetMethodMetaWorks) {
|
|
160
|
-
TextEmbeddings model(kValidTextEmbeddingsModelPath,
|
|
161
|
-
kValidTextEmbeddingsTokenizerPath, nullptr);
|
|
162
|
-
auto result = model.getMethodMeta("forward");
|
|
163
|
-
EXPECT_TRUE(result.ok());
|
|
164
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
#include "BaseModelTests.h"
|
|
2
|
-
#include <gtest/gtest.h>
|
|
3
|
-
#include <rnexecutorch/Error.h>
|
|
4
|
-
#include <rnexecutorch/models/text_to_image/TextToImage.h>
|
|
5
|
-
#include <string>
|
|
6
|
-
|
|
7
|
-
using namespace rnexecutorch;
|
|
8
|
-
using namespace rnexecutorch::models::text_to_image;
|
|
9
|
-
using namespace model_tests;
|
|
10
|
-
|
|
11
|
-
namespace rnexecutorch {
|
|
12
|
-
std::shared_ptr<facebook::react::CallInvoker> createMockCallInvoker();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
constexpr auto kValidTokenizerPath = "t2i_tokenizer.json";
|
|
16
|
-
constexpr auto kValidEncoderPath = "t2i_encoder.pte";
|
|
17
|
-
constexpr auto kValidUnetPath = "t2i_unet.pte";
|
|
18
|
-
constexpr auto kValidDecoderPath = "t2i_decoder.pte";
|
|
19
|
-
|
|
20
|
-
constexpr float kSchedulerBetaStart = 0.00085f;
|
|
21
|
-
constexpr float kSchedulerBetaEnd = 0.012f;
|
|
22
|
-
constexpr int32_t kSchedulerNumTrainTimesteps = 1000;
|
|
23
|
-
constexpr int32_t kSchedulerStepsOffset = 1;
|
|
24
|
-
|
|
25
|
-
// ============================================================================
|
|
26
|
-
// Common tests via typed test suite
|
|
27
|
-
// ============================================================================
|
|
28
|
-
namespace model_tests {
|
|
29
|
-
template <> struct ModelTraits<TextToImage> {
|
|
30
|
-
using ModelType = TextToImage;
|
|
31
|
-
|
|
32
|
-
static ModelType createValid() {
|
|
33
|
-
return ModelType(kValidTokenizerPath, kValidEncoderPath, kValidUnetPath,
|
|
34
|
-
kValidDecoderPath, kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
35
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
36
|
-
rnexecutorch::createMockCallInvoker());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static ModelType createInvalid() {
|
|
40
|
-
return ModelType("nonexistent.json", kValidEncoderPath, kValidUnetPath,
|
|
41
|
-
kValidDecoderPath, kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
42
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
43
|
-
rnexecutorch::createMockCallInvoker());
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static void callGenerate(ModelType &model) {
|
|
47
|
-
(void)model.generate("a cat", 128, 1, 42, nullptr);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
} // namespace model_tests
|
|
51
|
-
|
|
52
|
-
using TextToImageTypes = ::testing::Types<TextToImage>;
|
|
53
|
-
INSTANTIATE_TYPED_TEST_SUITE_P(TextToImage, CommonModelTest, TextToImageTypes);
|
|
54
|
-
|
|
55
|
-
// ============================================================================
|
|
56
|
-
// Model-specific tests
|
|
57
|
-
// ============================================================================
|
|
58
|
-
TEST(TextToImageCtorTests, InvalidEncoderPathThrows) {
|
|
59
|
-
EXPECT_THROW(TextToImage(kValidTokenizerPath, "nonexistent.pte",
|
|
60
|
-
kValidUnetPath, kValidDecoderPath,
|
|
61
|
-
kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
62
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
63
|
-
createMockCallInvoker()),
|
|
64
|
-
RnExecutorchError);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
TEST(TextToImageCtorTests, InvalidUnetPathThrows) {
|
|
68
|
-
EXPECT_THROW(TextToImage(kValidTokenizerPath, kValidEncoderPath,
|
|
69
|
-
"nonexistent.pte", kValidDecoderPath,
|
|
70
|
-
kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
71
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
72
|
-
createMockCallInvoker()),
|
|
73
|
-
RnExecutorchError);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
TEST(TextToImageCtorTests, InvalidDecoderPathThrows) {
|
|
77
|
-
EXPECT_THROW(TextToImage(kValidTokenizerPath, kValidEncoderPath,
|
|
78
|
-
kValidUnetPath, "nonexistent.pte",
|
|
79
|
-
kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
80
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
81
|
-
createMockCallInvoker()),
|
|
82
|
-
RnExecutorchError);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
TEST(TextToImageGenerateTests, InvalidImageSizeThrows) {
|
|
86
|
-
TextToImage model(kValidTokenizerPath, kValidEncoderPath, kValidUnetPath,
|
|
87
|
-
kValidDecoderPath, kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
88
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
89
|
-
createMockCallInvoker());
|
|
90
|
-
EXPECT_THROW((void)model.generate("a cat", 100, 1, 42, nullptr),
|
|
91
|
-
RnExecutorchError);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
TEST(TextToImageGenerateTests, EmptyPromptThrows) {
|
|
95
|
-
TextToImage model(kValidTokenizerPath, kValidEncoderPath, kValidUnetPath,
|
|
96
|
-
kValidDecoderPath, kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
97
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
98
|
-
createMockCallInvoker());
|
|
99
|
-
EXPECT_THROW((void)model.generate("", 128, 1, 42, nullptr),
|
|
100
|
-
RnExecutorchError);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
TEST(TextToImageGenerateTests, ZeroStepsThrows) {
|
|
104
|
-
TextToImage model(kValidTokenizerPath, kValidEncoderPath, kValidUnetPath,
|
|
105
|
-
kValidDecoderPath, kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
106
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
107
|
-
createMockCallInvoker());
|
|
108
|
-
EXPECT_THROW((void)model.generate("a cat", 128, 0, 42, nullptr),
|
|
109
|
-
RnExecutorchError);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
TEST(TextToImageGenerateTests, GenerateReturnsNonNull) {
|
|
113
|
-
TextToImage model(kValidTokenizerPath, kValidEncoderPath, kValidUnetPath,
|
|
114
|
-
kValidDecoderPath, kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
115
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
116
|
-
createMockCallInvoker());
|
|
117
|
-
auto result = model.generate("a cat", 128, 1, 42, nullptr);
|
|
118
|
-
EXPECT_NE(result, nullptr);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
TEST(TextToImageGenerateTests, GenerateReturnsCorrectSize) {
|
|
122
|
-
TextToImage model(kValidTokenizerPath, kValidEncoderPath, kValidUnetPath,
|
|
123
|
-
kValidDecoderPath, kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
124
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
125
|
-
createMockCallInvoker());
|
|
126
|
-
int32_t imageSize = 128;
|
|
127
|
-
auto result = model.generate("a cat", imageSize, 1, 42, nullptr);
|
|
128
|
-
ASSERT_NE(result, nullptr);
|
|
129
|
-
size_t expectedSize = imageSize * imageSize * 4;
|
|
130
|
-
EXPECT_EQ(result->size(), expectedSize);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
TEST(TextToImageGenerateTests, SameSeedProducesSameResult) {
|
|
134
|
-
TextToImage model(kValidTokenizerPath, kValidEncoderPath, kValidUnetPath,
|
|
135
|
-
kValidDecoderPath, kSchedulerBetaStart, kSchedulerBetaEnd,
|
|
136
|
-
kSchedulerNumTrainTimesteps, kSchedulerStepsOffset,
|
|
137
|
-
createMockCallInvoker());
|
|
138
|
-
auto result1 = model.generate("a cat", 128, 1, 42, nullptr);
|
|
139
|
-
auto result2 = model.generate("a cat", 128, 1, 42, nullptr);
|
|
140
|
-
ASSERT_NE(result1, nullptr);
|
|
141
|
-
ASSERT_NE(result2, nullptr);
|
|
142
|
-
ASSERT_EQ(result1->size(), result2->size());
|
|
143
|
-
|
|
144
|
-
auto data1 = static_cast<uint8_t *>(result1->data());
|
|
145
|
-
auto data2 = static_cast<uint8_t *>(result2->data());
|
|
146
|
-
for (size_t i = 0; i < result1->size(); i++) {
|
|
147
|
-
EXPECT_EQ(data1[i], data2[i]) << "at index: " << i;
|
|
148
|
-
}
|
|
149
|
-
}
|