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.
Files changed (46) hide show
  1. package/common/rnexecutorch/TokenizerModule.cpp +3 -2
  2. package/common/rnexecutorch/TokenizerModule.h +1 -1
  3. package/package.json +2 -1
  4. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  5. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  6. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_model.h +84 -0
  7. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_tokenizer_base.h +6 -87
  8. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/hf_tokenizer.h +28 -176
  9. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/map_utils.h +174 -0
  10. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/model.h +151 -0
  11. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/normalizer.h +55 -1
  12. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/padding.h +112 -0
  13. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/post_processor.h +101 -42
  14. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/pre_tokenizer.h +25 -9
  15. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/token_decoder.h +33 -6
  16. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/tokenizer.h +2 -2
  17. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/truncation.h +92 -0
  18. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/wordpiece_model.h +74 -0
  19. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  20. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  21. package/common/rnexecutorch/tests/CMakeLists.txt +0 -253
  22. package/common/rnexecutorch/tests/README.md +0 -73
  23. package/common/rnexecutorch/tests/integration/BaseModelTest.cpp +0 -207
  24. package/common/rnexecutorch/tests/integration/BaseModelTests.h +0 -120
  25. package/common/rnexecutorch/tests/integration/ClassificationTest.cpp +0 -117
  26. package/common/rnexecutorch/tests/integration/ImageEmbeddingsTest.cpp +0 -122
  27. package/common/rnexecutorch/tests/integration/ImageSegmentationTest.cpp +0 -152
  28. package/common/rnexecutorch/tests/integration/LLMTest.cpp +0 -155
  29. package/common/rnexecutorch/tests/integration/OCRTest.cpp +0 -128
  30. package/common/rnexecutorch/tests/integration/ObjectDetectionTest.cpp +0 -135
  31. package/common/rnexecutorch/tests/integration/SpeechToTextTest.cpp +0 -97
  32. package/common/rnexecutorch/tests/integration/StyleTransferTest.cpp +0 -112
  33. package/common/rnexecutorch/tests/integration/TextEmbeddingsTest.cpp +0 -164
  34. package/common/rnexecutorch/tests/integration/TextToImageTest.cpp +0 -149
  35. package/common/rnexecutorch/tests/integration/TokenizerModuleTest.cpp +0 -98
  36. package/common/rnexecutorch/tests/integration/VerticalOCRTest.cpp +0 -238
  37. package/common/rnexecutorch/tests/integration/VoiceActivityDetectionTest.cpp +0 -99
  38. package/common/rnexecutorch/tests/integration/assets/test_audio_float.raw +0 -0
  39. package/common/rnexecutorch/tests/integration/assets/we_are_software_mansion.jpg +0 -0
  40. package/common/rnexecutorch/tests/integration/libs/libfbjni.so +0 -0
  41. package/common/rnexecutorch/tests/integration/stubs/jsi_stubs.cpp +0 -45
  42. package/common/rnexecutorch/tests/integration/utils/TestUtils.h +0 -36
  43. package/common/rnexecutorch/tests/run_tests.sh +0 -333
  44. package/common/rnexecutorch/tests/unit/FileUtilsTest.cpp +0 -32
  45. package/common/rnexecutorch/tests/unit/LogTest.cpp +0 -529
  46. package/common/rnexecutorch/tests/unit/NumericalTest.cpp +0 -107
@@ -1,238 +0,0 @@
1
- #include "BaseModelTests.h"
2
- #include <gtest/gtest.h>
3
- #include <rnexecutorch/Error.h>
4
- #include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
5
- #include <string>
6
-
7
- using namespace rnexecutorch;
8
- using namespace rnexecutorch::models::ocr;
9
- using namespace model_tests;
10
-
11
- namespace rnexecutorch {
12
- std::shared_ptr<facebook::react::CallInvoker> createMockCallInvoker();
13
- }
14
-
15
- constexpr auto kValidVerticalDetectorPath = "xnnpack_craft_quantized.pte";
16
- constexpr auto kValidVerticalRecognizerPath = "xnnpack_crnn_english.pte";
17
- constexpr auto kValidVerticalTestImagePath =
18
- "file:///data/local/tmp/rnexecutorch_tests/we_are_software_mansion.jpg";
19
-
20
- // English alphabet symbols (must match alphabets.english from symbols.ts)
21
- const std::string ENGLISH_SYMBOLS =
22
- "0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ "
23
- "\xE2\x82\xAC" // Euro sign (€)
24
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
25
-
26
- // ============================================================================
27
- // Common tests via typed test suite
28
- // ============================================================================
29
- namespace model_tests {
30
- template <> struct ModelTraits<VerticalOCR> {
31
- using ModelType = VerticalOCR;
32
-
33
- static ModelType createValid() {
34
- return ModelType(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
35
- ENGLISH_SYMBOLS, false,
36
- rnexecutorch::createMockCallInvoker());
37
- }
38
-
39
- static ModelType createInvalid() {
40
- return ModelType("nonexistent.pte", kValidVerticalRecognizerPath,
41
- ENGLISH_SYMBOLS, false,
42
- rnexecutorch::createMockCallInvoker());
43
- }
44
-
45
- static void callGenerate(ModelType &model) {
46
- (void)model.generate(kValidVerticalTestImagePath);
47
- }
48
- };
49
- } // namespace model_tests
50
-
51
- using VerticalOCRTypes = ::testing::Types<VerticalOCR>;
52
- INSTANTIATE_TYPED_TEST_SUITE_P(VerticalOCR, CommonModelTest, VerticalOCRTypes);
53
-
54
- // ============================================================================
55
- // VerticalOCR-specific tests
56
- // ============================================================================
57
-
58
- // Constructor tests
59
- TEST(VerticalOCRCtorTests, InvalidRecognizerPathThrows) {
60
- EXPECT_THROW(VerticalOCR(kValidVerticalDetectorPath, "nonexistent.pte",
61
- ENGLISH_SYMBOLS, false, createMockCallInvoker()),
62
- RnExecutorchError);
63
- }
64
-
65
- TEST(VerticalOCRCtorTests, EmptySymbolsThrows) {
66
- EXPECT_THROW(VerticalOCR(kValidVerticalDetectorPath,
67
- kValidVerticalRecognizerPath, "", false,
68
- createMockCallInvoker()),
69
- RnExecutorchError);
70
- }
71
-
72
- TEST(VerticalOCRCtorTests, IndependentCharsTrueDoesntThrow) {
73
- EXPECT_NO_THROW(VerticalOCR(kValidVerticalDetectorPath,
74
- kValidVerticalRecognizerPath, ENGLISH_SYMBOLS,
75
- true, createMockCallInvoker()));
76
- }
77
-
78
- TEST(VerticalOCRCtorTests, IndependentCharsFalseDoesntThrow) {
79
- EXPECT_NO_THROW(VerticalOCR(kValidVerticalDetectorPath,
80
- kValidVerticalRecognizerPath, ENGLISH_SYMBOLS,
81
- false, createMockCallInvoker()));
82
- }
83
-
84
- // Generate tests - Independent Characters strategy
85
- TEST(VerticalOCRGenerateTests, IndependentCharsInvalidImageThrows) {
86
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
87
- ENGLISH_SYMBOLS, true, createMockCallInvoker());
88
- EXPECT_THROW((void)model.generate("nonexistent_image.jpg"),
89
- RnExecutorchError);
90
- }
91
-
92
- TEST(VerticalOCRGenerateTests, IndependentCharsEmptyImagePathThrows) {
93
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
94
- ENGLISH_SYMBOLS, true, createMockCallInvoker());
95
- EXPECT_THROW((void)model.generate(""), RnExecutorchError);
96
- }
97
-
98
- TEST(VerticalOCRGenerateTests, IndependentCharsMalformedURIThrows) {
99
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
100
- ENGLISH_SYMBOLS, true, createMockCallInvoker());
101
- EXPECT_THROW((void)model.generate("not_a_valid_uri://bad"),
102
- RnExecutorchError);
103
- }
104
-
105
- TEST(VerticalOCRGenerateTests, IndependentCharsValidImageReturnsResults) {
106
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
107
- ENGLISH_SYMBOLS, true, createMockCallInvoker());
108
- auto results = model.generate(kValidVerticalTestImagePath);
109
- EXPECT_GE(results.size(), 0u);
110
- }
111
-
112
- TEST(VerticalOCRGenerateTests, IndependentCharsDetectionsHaveValidBBoxes) {
113
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
114
- ENGLISH_SYMBOLS, true, createMockCallInvoker());
115
- auto results = model.generate(kValidVerticalTestImagePath);
116
-
117
- for (const auto &detection : results) {
118
- EXPECT_EQ(detection.bbox.size(), 4u);
119
- for (const auto &point : detection.bbox) {
120
- EXPECT_GE(point.x, 0.0f);
121
- EXPECT_GE(point.y, 0.0f);
122
- }
123
- }
124
- }
125
-
126
- TEST(VerticalOCRGenerateTests, IndependentCharsDetectionsHaveValidScores) {
127
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
128
- ENGLISH_SYMBOLS, true, createMockCallInvoker());
129
- auto results = model.generate(kValidVerticalTestImagePath);
130
-
131
- for (const auto &detection : results) {
132
- EXPECT_GE(detection.score, 0.0f);
133
- EXPECT_LE(detection.score, 1.0f);
134
- }
135
- }
136
-
137
- TEST(VerticalOCRGenerateTests, IndependentCharsDetectionsHaveNonEmptyText) {
138
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
139
- ENGLISH_SYMBOLS, true, createMockCallInvoker());
140
- auto results = model.generate(kValidVerticalTestImagePath);
141
-
142
- for (const auto &detection : results) {
143
- EXPECT_FALSE(detection.text.empty());
144
- }
145
- }
146
-
147
- // Generate tests - Joint Characters strategy
148
- TEST(VerticalOCRGenerateTests, JointCharsInvalidImageThrows) {
149
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
150
- ENGLISH_SYMBOLS, false, createMockCallInvoker());
151
- EXPECT_THROW((void)model.generate("nonexistent_image.jpg"),
152
- RnExecutorchError);
153
- }
154
-
155
- TEST(VerticalOCRGenerateTests, JointCharsEmptyImagePathThrows) {
156
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
157
- ENGLISH_SYMBOLS, false, createMockCallInvoker());
158
- EXPECT_THROW((void)model.generate(""), RnExecutorchError);
159
- }
160
-
161
- TEST(VerticalOCRGenerateTests, JointCharsMalformedURIThrows) {
162
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
163
- ENGLISH_SYMBOLS, false, createMockCallInvoker());
164
- EXPECT_THROW((void)model.generate("not_a_valid_uri://bad"),
165
- RnExecutorchError);
166
- }
167
-
168
- TEST(VerticalOCRGenerateTests, JointCharsValidImageReturnsResults) {
169
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
170
- ENGLISH_SYMBOLS, false, createMockCallInvoker());
171
- auto results = model.generate(kValidVerticalTestImagePath);
172
- EXPECT_GE(results.size(), 0u);
173
- }
174
-
175
- TEST(VerticalOCRGenerateTests, JointCharsDetectionsHaveValidBBoxes) {
176
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
177
- ENGLISH_SYMBOLS, false, createMockCallInvoker());
178
- auto results = model.generate(kValidVerticalTestImagePath);
179
-
180
- for (const auto &detection : results) {
181
- EXPECT_EQ(detection.bbox.size(), 4u);
182
- for (const auto &point : detection.bbox) {
183
- EXPECT_GE(point.x, 0.0f);
184
- EXPECT_GE(point.y, 0.0f);
185
- }
186
- }
187
- }
188
-
189
- TEST(VerticalOCRGenerateTests, JointCharsDetectionsHaveValidScores) {
190
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
191
- ENGLISH_SYMBOLS, false, createMockCallInvoker());
192
- auto results = model.generate(kValidVerticalTestImagePath);
193
-
194
- for (const auto &detection : results) {
195
- EXPECT_GE(detection.score, 0.0f);
196
- EXPECT_LE(detection.score, 1.0f);
197
- }
198
- }
199
-
200
- TEST(VerticalOCRGenerateTests, JointCharsDetectionsHaveNonEmptyText) {
201
- VerticalOCR model(kValidVerticalDetectorPath, kValidVerticalRecognizerPath,
202
- ENGLISH_SYMBOLS, false, createMockCallInvoker());
203
- auto results = model.generate(kValidVerticalTestImagePath);
204
-
205
- for (const auto &detection : results) {
206
- EXPECT_FALSE(detection.text.empty());
207
- }
208
- }
209
-
210
- // Strategy comparison tests
211
- TEST(VerticalOCRStrategyTests, BothStrategiesRunSuccessfully) {
212
- VerticalOCR independentModel(kValidVerticalDetectorPath,
213
- kValidVerticalRecognizerPath, ENGLISH_SYMBOLS,
214
- true, createMockCallInvoker());
215
- VerticalOCR jointModel(kValidVerticalDetectorPath,
216
- kValidVerticalRecognizerPath, ENGLISH_SYMBOLS, false,
217
- createMockCallInvoker());
218
-
219
- EXPECT_NO_THROW((void)independentModel.generate(kValidVerticalTestImagePath));
220
- EXPECT_NO_THROW((void)jointModel.generate(kValidVerticalTestImagePath));
221
- }
222
-
223
- TEST(VerticalOCRStrategyTests, BothStrategiesReturnValidResults) {
224
- VerticalOCR independentModel(kValidVerticalDetectorPath,
225
- kValidVerticalRecognizerPath, ENGLISH_SYMBOLS,
226
- true, createMockCallInvoker());
227
- VerticalOCR jointModel(kValidVerticalDetectorPath,
228
- kValidVerticalRecognizerPath, ENGLISH_SYMBOLS, false,
229
- createMockCallInvoker());
230
-
231
- auto independentResults =
232
- independentModel.generate(kValidVerticalTestImagePath);
233
- auto jointResults = jointModel.generate(kValidVerticalTestImagePath);
234
-
235
- // Both should return some results (or none if no text detected)
236
- EXPECT_GE(independentResults.size(), 0u);
237
- EXPECT_GE(jointResults.size(), 0u);
238
- }
@@ -1,99 +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/voice_activity_detection/VoiceActivityDetection.h>
6
-
7
- using namespace rnexecutorch;
8
- using namespace rnexecutorch::models::voice_activity_detection;
9
- using namespace test_utils;
10
- using namespace model_tests;
11
-
12
- constexpr auto kValidVadModelPath = "fsmn-vad_xnnpack.pte";
13
-
14
- // ============================================================================
15
- // Common tests via typed test suite
16
- // ============================================================================
17
- namespace model_tests {
18
- template <> struct ModelTraits<VoiceActivityDetection> {
19
- using ModelType = VoiceActivityDetection;
20
-
21
- static ModelType createValid() {
22
- return ModelType(kValidVadModelPath, nullptr);
23
- }
24
-
25
- static ModelType createInvalid() {
26
- return ModelType("nonexistent.pte", nullptr);
27
- }
28
-
29
- static void callGenerate(ModelType &model) {
30
- auto audio = loadAudioFromFile("test_audio_float.raw");
31
- (void)model.generate(audio);
32
- }
33
- };
34
- } // namespace model_tests
35
-
36
- using VADTypes = ::testing::Types<VoiceActivityDetection>;
37
- INSTANTIATE_TYPED_TEST_SUITE_P(VAD, CommonModelTest, VADTypes);
38
-
39
- // ============================================================================
40
- // Model-specific tests
41
- // ============================================================================
42
- TEST(VADGenerateTests, SilenceReturnsNoSegments) {
43
- VoiceActivityDetection model(kValidVadModelPath, nullptr);
44
- auto silence = generateSilence(16000 * 5);
45
- auto segments = model.generate(silence);
46
- EXPECT_TRUE(segments.empty());
47
- }
48
-
49
- TEST(VADGenerateTests, SegmentsHaveValidBounds) {
50
- VoiceActivityDetection model(kValidVadModelPath, nullptr);
51
- auto audio = loadAudioFromFile("test_audio_float.raw");
52
- ASSERT_FALSE(audio.empty());
53
- auto segments = model.generate(audio);
54
-
55
- for (const auto &segment : segments) {
56
- EXPECT_LE(segment.start, segment.end);
57
- EXPECT_LE(segment.end, audio.size());
58
- }
59
- }
60
-
61
- TEST(VADGenerateTests, SegmentsAreNonOverlapping) {
62
- VoiceActivityDetection model(kValidVadModelPath, nullptr);
63
- auto audio = loadAudioFromFile("test_audio_float.raw");
64
- ASSERT_FALSE(audio.empty());
65
- auto segments = model.generate(audio);
66
- for (size_t i = 1; i < segments.size(); ++i) {
67
- EXPECT_LE(segments[i - 1].end, segments[i].start);
68
- }
69
- }
70
-
71
- TEST(VADGenerateTests, LongAudioSegmentBoundsValid) {
72
- VoiceActivityDetection model(kValidVadModelPath, nullptr);
73
- auto audio = loadAudioFromFile("test_audio_float.raw");
74
- ASSERT_FALSE(audio.empty());
75
- auto segments = model.generate(audio);
76
-
77
- for (const auto &segment : segments) {
78
- EXPECT_LE(segment.start, segment.end);
79
- EXPECT_LE(segment.end, audio.size());
80
- }
81
- }
82
-
83
- TEST(VADInheritedTests, GetInputShapeWorks) {
84
- VoiceActivityDetection model(kValidVadModelPath, nullptr);
85
- auto shape = model.getInputShape("forward", 0);
86
- EXPECT_GE(shape.size(), 2u);
87
- }
88
-
89
- TEST(VADInheritedTests, GetAllInputShapesWorks) {
90
- VoiceActivityDetection model(kValidVadModelPath, nullptr);
91
- auto shapes = model.getAllInputShapes("forward");
92
- EXPECT_FALSE(shapes.empty());
93
- }
94
-
95
- TEST(VADInheritedTests, GetMethodMetaWorks) {
96
- VoiceActivityDetection model(kValidVadModelPath, nullptr);
97
- auto result = model.getMethodMeta("forward");
98
- EXPECT_TRUE(result.ok());
99
- }
@@ -1,45 +0,0 @@
1
- // Stub implementations for JSI and other symbols to satisfy the linker
2
- // These are never actually called in tests
3
-
4
- #include <ReactCommon/CallInvoker.h>
5
- #include <cstddef>
6
- #include <functional>
7
- #include <jsi/jsi.h>
8
- #include <string>
9
- #include <vector>
10
-
11
- namespace facebook::jsi {
12
-
13
- // MutableBuffer destructor - needed by OwningArrayBuffer
14
- MutableBuffer::~MutableBuffer() {}
15
- Value::~Value() {}
16
- Value::Value(Value &&other) noexcept {}
17
- } // namespace facebook::jsi
18
-
19
- namespace facebook::react {
20
-
21
- // Needed by LLM test
22
- class MockCallInvoker : public CallInvoker {
23
- public:
24
- void invokeAsync(CallFunc &&func) noexcept override {}
25
-
26
- void invokeSync(CallFunc &&func) override {}
27
- };
28
-
29
- } // namespace facebook::react
30
-
31
- namespace rnexecutorch {
32
-
33
- // Stub for fetchUrlFunc - used by ImageProcessing for remote URLs
34
- // Tests only use local files, so this is never called
35
- using FetchUrlFunc_t = std::function<std::vector<std::byte>(std::string)>;
36
- FetchUrlFunc_t fetchUrlFunc = [](std::string) -> std::vector<std::byte> {
37
- return {};
38
- };
39
-
40
- // Global mock call invoker for tests
41
- std::shared_ptr<facebook::react::CallInvoker> createMockCallInvoker() {
42
- return std::make_shared<facebook::react::MockCallInvoker>();
43
- }
44
-
45
- } // namespace rnexecutorch
@@ -1,36 +0,0 @@
1
- #pragma once
2
-
3
- #include <fstream>
4
- #include <string>
5
- #include <vector>
6
-
7
- namespace test_utils {
8
-
9
- inline void trimFilePrefix(std::string &filepath) {
10
- constexpr std::string_view prefix = "file://";
11
- if (filepath.starts_with(prefix)) {
12
- filepath.erase(0, prefix.size());
13
- }
14
- }
15
-
16
- inline std::vector<float> loadAudioFromFile(const std::string &filepath) {
17
- std::ifstream file(filepath, std::ios::binary | std::ios::ate);
18
- if (!file.is_open()) {
19
- return {};
20
- }
21
-
22
- std::streamsize size = file.tellg();
23
- file.seekg(0, std::ios::beg);
24
-
25
- size_t numSamples = size / sizeof(float);
26
- std::vector<float> buffer(numSamples);
27
-
28
- file.read(reinterpret_cast<char *>(buffer.data()), size);
29
- return buffer;
30
- }
31
-
32
- inline std::vector<float> generateSilence(size_t numSamples) {
33
- return std::vector<float>(numSamples, 0.0f);
34
- }
35
-
36
- } // namespace test_utils