react-native-executorch 0.7.0 → 0.7.1
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/package.json +2 -1
- 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,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
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
#include <gtest/gtest.h>
|
|
2
|
-
#include <rnexecutorch/Error.h>
|
|
3
|
-
#include <rnexecutorch/TokenizerModule.h>
|
|
4
|
-
|
|
5
|
-
using namespace rnexecutorch;
|
|
6
|
-
|
|
7
|
-
constexpr auto kValidTokenizerPath = "tokenizer.json";
|
|
8
|
-
|
|
9
|
-
TEST(TokenizerCtorTests, InvalidPathThrows) {
|
|
10
|
-
EXPECT_THROW(TokenizerModule("nonexistent_tokenizer.json", nullptr),
|
|
11
|
-
RnExecutorchError);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
TEST(TokenizerCtorTests, ValidPathDoesntThrow) {
|
|
15
|
-
EXPECT_NO_THROW(TokenizerModule(kValidTokenizerPath, nullptr));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
TEST(TokenizerMemoryTests, MemoryLowerBoundIsPositive) {
|
|
19
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
20
|
-
EXPECT_GT(tokenizer.getMemoryLowerBound(), 0u);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
TEST(TokenizerEncodeTests, EmptyStringReturnsEmptyString) {
|
|
24
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
25
|
-
auto tokens = tokenizer.encode("");
|
|
26
|
-
EXPECT_TRUE(tokens.empty());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
TEST(TokenizerEncodeTests, SimpleTextReturnsTokens) {
|
|
30
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
31
|
-
auto tokens = tokenizer.encode("Hello world");
|
|
32
|
-
EXPECT_GT(tokens.size(), 0u);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
TEST(TokenizerEncodeTests, SameTextReturnsSameTokens) {
|
|
36
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
37
|
-
auto tokens1 = tokenizer.encode("test");
|
|
38
|
-
auto tokens2 = tokenizer.encode("test");
|
|
39
|
-
EXPECT_EQ(tokens1, tokens2);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
TEST(TokenizerEncodeTests, DifferentTextReturnsDifferentTokens) {
|
|
43
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
44
|
-
auto tokens1 = tokenizer.encode("hello");
|
|
45
|
-
auto tokens2 = tokenizer.encode("goodbye");
|
|
46
|
-
EXPECT_NE(tokens1, tokens2);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
TEST(TokenizerEncodeTests, SpecialCharactersWork) {
|
|
50
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
51
|
-
auto tokens = tokenizer.encode("!@#$%^&*()");
|
|
52
|
-
EXPECT_GT(tokens.size(), 0u);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
TEST(TokenizerEncodeTests, VeryLongTextWorks) {
|
|
56
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
57
|
-
std::string longText(10000, 'a');
|
|
58
|
-
EXPECT_NO_THROW((void)tokenizer.encode(longText));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
TEST(TokenizerDecodeTests, DecodeEncodedTextReturnsOriginal) {
|
|
62
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
63
|
-
std::string original = "szponcik";
|
|
64
|
-
auto tokens = tokenizer.encode(original);
|
|
65
|
-
auto decoded = tokenizer.decode(tokens, true);
|
|
66
|
-
EXPECT_EQ(decoded, original);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
TEST(TokenizerDecodeTests, DecodeEmptyVectorReturnsEmpty) {
|
|
70
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
71
|
-
auto decoded = tokenizer.decode({}, true);
|
|
72
|
-
EXPECT_TRUE(decoded.empty());
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
TEST(TokenizerIdToTokenTests, ValidIdReturnsToken) {
|
|
76
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
77
|
-
auto token = tokenizer.idToToken(0);
|
|
78
|
-
EXPECT_FALSE(token.empty());
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
TEST(TokenizerTokenToIdTests, RoundTripWorks) {
|
|
82
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
83
|
-
auto token = tokenizer.idToToken(100);
|
|
84
|
-
auto id = tokenizer.tokenToId(token);
|
|
85
|
-
EXPECT_EQ(id, 100);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
TEST(TokenizerVocabTests, VocabSizeIsPositive) {
|
|
89
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
90
|
-
EXPECT_GT(tokenizer.getVocabSize(), 0u);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
TEST(TokenizerVocabTests, VocabSizeIsReasonable) {
|
|
94
|
-
TokenizerModule tokenizer(kValidTokenizerPath, nullptr);
|
|
95
|
-
auto vocabSize = tokenizer.getVocabSize();
|
|
96
|
-
EXPECT_GT(vocabSize, 1000u);
|
|
97
|
-
EXPECT_LT(vocabSize, 1000000u);
|
|
98
|
-
}
|