Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions src/models/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ std::vector<int32_t> Tokenizer::EncodeBatch(std::span<const std::string> strings
}

std::shared_ptr<Tensor> Tokenizer::EncodeBatch(std::span<const char*> strings) const {
if (strings.empty()) {
throw std::runtime_error("EncodeBatch: input strings must not be empty");
}

Comment thread
kunal-vaishnavi marked this conversation as resolved.
std::vector<std::vector<int32_t>> sequences;
std::vector<std::span<const int32_t>> span_sequences;
for (size_t i = 0; i < strings.size(); i++) {
Expand Down
10 changes: 10 additions & 0 deletions test/c_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ TEST(CAPITests, TokenizerCAPI) {
#endif
}

TEST(CAPITests, EncodeBatchEmptyInputThrows) {
#if TEST_PHI2
auto model = OgaModel::Create(PHI2_PATH);
auto tokenizer = OgaTokenizer::Create(*model);

// EncodeBatch with zero strings should throw, not crash with SIGFPE
ASSERT_THROW(tokenizer->EncodeBatch(nullptr, 0), std::runtime_error);
Comment thread
Copilot marked this conversation as resolved.
#endif
}

TEST(CAPITests, TokenizerUpdateOptions) {
#if TEST_PHI2
auto config = OgaConfig::Create(PHI2_PATH);
Expand Down
Loading