Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokenizer test #21

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def define_common_targets():
]),
visibility = [
"@EXECUTORCH_CLIENTS",
"//pytorch/tokenizers/...",
],
header_namespace = "",
)
Expand All @@ -29,12 +30,14 @@ def define_common_targets():
],
visibility = [
"@EXECUTORCH_CLIENTS",
"//pytorch/tokenizers/...",
],
compiler_flags = [
"-D_USE_INTERNAL_STRING_VIEW",
],
external_deps = [
"sentencepiece",
"abseil-cpp",
],
)

Expand All @@ -49,6 +52,7 @@ def define_common_targets():
],
visibility = [
"@EXECUTORCH_CLIENTS",
"//pytorch/tokenizers/...",
],
compiler_flags = [
"-D_USE_INTERNAL_STRING_VIEW",
Expand Down Expand Up @@ -84,6 +88,7 @@ def define_common_targets():
],
visibility = [
"@EXECUTORCH_CLIENTS",
"//pytorch/tokenizers/...",
],
compiler_flags = [
"-D_USE_INTERNAL_STRING_VIEW",
Expand All @@ -104,5 +109,6 @@ def define_common_targets():
],
visibility = [
"@EXECUTORCH_CLIENTS",
"//pytorch/tokenizers/...",
],
)
8 changes: 8 additions & 0 deletions test/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Any targets that should be shared between fbcode and xplat must be defined in
# targets.bzl. This file can contain fbcode-only targets.

load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()
87 changes: 87 additions & 0 deletions test/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
load(
"@fbsource//tools/build_defs:default_platform_defs.bzl",
"ANDROID",
"CXX",
)
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def define_common_targets():
"""Defines targets that should be shared between fbcode and xplat.

The directory containing this targets.bzl file should also contain both
TARGETS and BUCK files that call this function.
"""
runtime.cxx_test(
name = "test_base64",
srcs = [
"test_base64.cpp",
],
deps = [
"//pytorch/tokenizers:headers",
],
)

runtime.cxx_test(
name = "test_llama2c_tokenizer",
srcs = [
"test_llama2c_tokenizer.cpp",
],
deps = [
"//pytorch/tokenizers:llama2c_tokenizer",
],
env = {
"RESOURCES_PATH": "$(location :resources)/resources",
},
platforms = [CXX, ANDROID], # Cannot bundle resources on Apple platform.
)

runtime.cxx_test(
name = "test_pre_tokenizer",
srcs = [
"test_pre_tokenizer.cpp",
],
deps = [
"//pytorch/tokenizers:headers",
"//pytorch/tokenizers:hf_tokenizer",
],
)

runtime.cxx_test(
name = "test_sentencepiece",
srcs = [
"test_sentencepiece.cpp",
],
deps = ["//pytorch/tokenizers:sentencepiece"],
external_deps = [
"sentencepiece",
"abseil-cpp",
],
env = {
"RESOURCES_PATH": "$(location :resources)/resources",
},
platforms = [CXX, ANDROID], # Cannot bundle resources on Apple platform.
)

runtime.cxx_test(
name = "test_tiktoken",
srcs = [
"test_tiktoken.cpp",
],
deps = [
"//pytorch/tokenizers:tiktoken",
],
env = {
"RESOURCES_PATH": "$(location :resources)/resources",
},
platforms = [CXX, ANDROID], # Cannot bundle resources on Apple platform.
external_deps = [
"re2",
],
)

runtime.filegroup(
name = "resources",
srcs = native.glob([
"resources/**",
]),
)
8 changes: 1 addition & 7 deletions test/test_llama2c_tokenizer.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.

#ifdef TOKENIZERS_FB_BUCK
#include <TestResourceUtils/TestResourceUtils.h>
Expand Down
9 changes: 0 additions & 9 deletions test/test_sentencepiece.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@
*/
// @lint-ignore-every LICENSELINT

#ifdef TOKENIZERS_FB_BUCK
#include <TestResourceUtils/TestResourceUtils.h>
#endif
#include <gtest/gtest.h>
#include <pytorch/tokenizers/sentencepiece.h>

namespace tokenizers {

namespace {
static inline std::string _get_resource_path(const std::string& name) {
#ifdef TOKENIZERS_FB_BUCK
return facebook::xplat::testing::getPathForTestResource(
"test/resources/" + name);
#else
return std::getenv("RESOURCES_PATH") + std::string("/") + name;
#endif
}

} // namespace

TEST(SPTokenizerTest, TestEncodeWithoutLoad) {
Expand Down
8 changes: 0 additions & 8 deletions test/test_tiktoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
*/
// @lint-ignore-every LICENSELINT

#ifdef TOKENIZERS_FB_BUCK
#include <TestResourceUtils/TestResourceUtils.h>
#endif
#include <gtest/gtest.h>
#include <pytorch/tokenizers/tiktoken.h>

Expand Down Expand Up @@ -45,12 +42,7 @@ static inline std::unique_ptr<std::vector<std::string>> _get_special_tokens() {
}

static inline std::string _get_resource_path(const std::string& name) {
#ifdef TOKENIZERS_FB_BUCK
return facebook::xplat::testing::getPathForTestResource(
"test/resources/" + name);
#else
return std::getenv("RESOURCES_PATH") + std::string("/") + name;
#endif
}

} // namespace
Expand Down