Skip to content

Commit 464ee35

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Fix test with resources
Summary: Fix test failure due to resources not handled correctly by ios tests. Differential Revision: D66392647
1 parent b3f2a79 commit 464ee35

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

examples/models/llama/tokenizer/test/test_tiktoken.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
#include <gtest/gtest.h>
1616

17+
#ifdef EXECUTORCH_FB_BUCK
18+
#include <TestResourceUtils/TestResourceUtils.h>
19+
#endif
20+
1721
using namespace ::testing;
1822

1923
using ::example::Version;
@@ -26,8 +30,13 @@ class MultimodalTiktokenV5ExtensionTest : public Test {
2630
void SetUp() override {
2731
executorch::runtime::runtime_init();
2832
tokenizer_ = get_tiktoken_for_llama(Version::Multimodal);
33+
#ifdef EXECUTORCH_FB_BUCK
34+
modelPath_ =
35+
facebook::xplat::testing::getPathForTestResource("resources/test_tiktoken_tokenizer.model");
36+
#else
2937
modelPath_ = std::getenv("RESOURCES_PATH") +
3038
std::string("/test_tiktoken_tokenizer.model");
39+
#endif
3140
}
3241

3342
std::unique_ptr<Tokenizer> tokenizer_;

extension/llm/tokenizer/test/test_bpe_tokenizer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
#ifdef EXECUTORCH_FB_BUCK
10+
#include <TestResourceUtils/TestResourceUtils.h>
11+
#endif
912
#include <executorch/extension/llm/tokenizer/bpe_tokenizer.h>
1013
#include <executorch/runtime/platform/runtime.h>
1114
#include <gtest/gtest.h>
@@ -23,8 +26,13 @@ class TokenizerExtensionTest : public Test {
2326
void SetUp() override {
2427
executorch::runtime::runtime_init();
2528
tokenizer_ = std::make_unique<BPETokenizer>();
29+
#ifdef EXECUTORCH_FB_BUCK
30+
modelPath_ =
31+
facebook::xplat::testing::getPathForTestResource("resources/test_bpe_tokenizer.model");
32+
#else
2633
modelPath_ =
2734
std::getenv("RESOURCES_PATH") + std::string("/test_bpe_tokenizer.bin");
35+
#endif
2836
}
2937

3038
std::unique_ptr<Tokenizer> tokenizer_;

extension/llm/tokenizer/test/test_tiktoken.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
#ifdef EXECUTORCH_FB_BUCK
10+
#include <TestResourceUtils/TestResourceUtils.h>
11+
#endif
912
#include <executorch/extension/llm/tokenizer/tiktoken.h>
1013
#include <executorch/runtime/platform/runtime.h>
1114
#include <gmock/gmock.h>
@@ -55,8 +58,13 @@ class TiktokenExtensionTest : public Test {
5558
executorch::runtime::runtime_init();
5659
tokenizer_ = std::make_unique<Tiktoken>(
5760
_get_special_tokens(), kBOSTokenIndex, kEOSTokenIndex);
61+
#ifdef EXECUTORCH_FB_BUCK
62+
modelPath_ =
63+
facebook::xplat::testing::getPathForTestResource("resources/test_tiktoken_tokenizer.model");
64+
#else
5865
modelPath_ = std::getenv("RESOURCES_PATH") +
5966
std::string("/test_tiktoken_tokenizer.model");
67+
#endif
6068
}
6169

6270
std::unique_ptr<Tokenizer> tokenizer_;
@@ -144,44 +152,58 @@ TEST_F(TiktokenExtensionTest, ConstructionWithInvalidEOSIndex) {
144152
}
145153

146154
TEST_F(TiktokenExtensionTest, LoadWithInvalidPath) {
147-
auto invalidModelPath =
148-
std::getenv("RESOURCES_PATH") + std::string("/nonexistent.model");
149-
150-
Error res = tokenizer_->load(invalidModelPath.c_str());
155+
auto invalidModelPath = "./nonexistent.model";
156+
Error res = tokenizer_->load(invalidModelPath);
151157
EXPECT_EQ(res, Error::InvalidArgument);
152158
}
153159

154160
TEST_F(TiktokenExtensionTest, LoadTiktokenFileWithInvalidRank) {
161+
#ifdef EXECUTORCH_FB_BUCK
162+
auto invalidModelPath =
163+
facebook::xplat::testing::getPathForTestResource("resources/test_tiktoken_invalid_rank.model");
164+
#else
155165
auto invalidModelPath = std::getenv("RESOURCES_PATH") +
156166
std::string("/test_tiktoken_invalid_rank.model");
157-
167+
#endif
158168
Error res = tokenizer_->load(invalidModelPath.c_str());
159169

160170
EXPECT_EQ(res, Error::InvalidArgument);
161171
}
162172

163173
TEST_F(TiktokenExtensionTest, LoadTiktokenFileWithInvalidBase64) {
174+
#ifdef EXECUTORCH_FB_BUCK
175+
auto invalidModelPath =
176+
facebook::xplat::testing::getPathForTestResource("resources/test_tiktoken_invalid_base64.model");
177+
#else
164178
auto invalidModelPath = std::getenv("RESOURCES_PATH") +
165179
std::string("/test_tiktoken_invalid_base64.model");
166-
180+
#endif
167181
Error res = tokenizer_->load(invalidModelPath.c_str());
168182

169183
EXPECT_EQ(res, Error::InvalidArgument);
170184
}
171185

172186
TEST_F(TiktokenExtensionTest, LoadTiktokenFileWithNoSpace) {
187+
#ifdef EXECUTORCH_FB_BUCK
188+
auto invalidModelPath =
189+
facebook::xplat::testing::getPathForTestResource("resources/test_tiktoken_no_space.model");
190+
#else
173191
auto invalidModelPath = std::getenv("RESOURCES_PATH") +
174192
std::string("/test_tiktoken_no_space.model");
175-
193+
#endif
176194
Error res = tokenizer_->load(invalidModelPath.c_str());
177195

178196
EXPECT_EQ(res, Error::InvalidArgument);
179197
}
180198

181199
TEST_F(TiktokenExtensionTest, LoadTiktokenFileWithBPEFile) {
200+
#ifdef EXECUTORCH_FB_BUCK
201+
auto invalidModelPath =
202+
facebook::xplat::testing::getPathForTestResource("resources/test_bpe_tokenizer.bin");
203+
#else
182204
auto invalidModelPath =
183205
std::getenv("RESOURCES_PATH") + std::string("/test_bpe_tokenizer.bin");
184-
206+
#endif
185207
Error res = tokenizer_->load(invalidModelPath.c_str());
186208

187209
EXPECT_EQ(res, Error::InvalidArgument);

0 commit comments

Comments
 (0)