Skip to content

Commit 5862d1f

Browse files
veluca93atoreroeustassboukorttszabadka
committed
Add a benchmark and additional tests.
Also add a script to help running sanitizer builds, and do some cleanup. Co-authored-by: Andrey Mikhaylov <amik@google.com> Co-authored-by: Eugene Kliuchnikov <eustas@google.com> Co-authored-by: Sami Boukortt <sboukortt@google.com> Co-authored-by: Zoltan Szabadka <szabadka@google.com>
1 parent 325ef06 commit 5862d1f

16 files changed

Lines changed: 1217 additions & 46 deletions

File tree

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Checks: "-*,\
9090
-concurrency-mt-unsafe,\
9191
-cppcoreguidelines-avoid-c-arrays,\
9292
-cppcoreguidelines-avoid-const-or-ref-data-members,\
93+
-cppcoreguidelines-avoid-do-while,\
9394
-cppcoreguidelines-avoid-goto,\
9495
-cppcoreguidelines-avoid-magic-numbers,\
9596
-cppcoreguidelines-avoid-non-const-global-variables,\

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
name: build
22

33
# Trigger on push, pull request, or via manual dispatch.
4-
on: [push, pull_request, workflow_dispatch]
4+
on:
5+
push:
6+
pull_request:
7+
types: [opened, reopened, labeled, unlabeled, synchronize]
8+
workflow_dispatch:
59

610
jobs:
711
build:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.cache/
2+
bazel-*/
3+
build-*/
4+
python/*/__pycache__

BUILD.bazel

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ cc_library(
8686
],
8787
)
8888

89+
cc_test(
90+
name = "gemma_test",
91+
srcs = ["gemma_test.cc"],
92+
deps = [
93+
":args",
94+
":gemma_lib",
95+
":ops",
96+
"@googletest//:gtest_main",
97+
"@hwy//:hwy_test_util",
98+
"@hwy//:thread_pool",
99+
],
100+
)
101+
89102
cc_library(
90103
name = "app",
91104
hdrs = [
@@ -132,3 +145,22 @@ cc_binary(
132145
"@hwy//:thread_pool",
133146
],
134147
)
148+
149+
cc_binary(
150+
name = "benchmark",
151+
srcs = [
152+
"benchmark.cc",
153+
],
154+
deps = [
155+
":app",
156+
":args",
157+
":gemma_lib",
158+
# "//base",
159+
"//compression:compress",
160+
"@hwy//:hwy",
161+
"@hwy//:nanobenchmark",
162+
"@hwy//:profiler",
163+
"@hwy//:thread_pool",
164+
"@nlohmann_json//:json",
165+
],
166+
)

CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ FetchContent_MakeAvailable(highway)
3030
FetchContent_Declare(sentencepiece GIT_REPOSITORY https://github.com/google/sentencepiece GIT_TAG 53de76561cfc149d3c01037f0595669ad32a5e7c EXCLUDE_FROM_ALL)
3131
FetchContent_MakeAvailable(sentencepiece)
3232

33+
FetchContent_Declare(json GIT_REPOSITORY https://github.com/nlohmann/json.git GIT_TAG 9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03 EXCLUDE_FROM_ALL)
34+
FetchContent_MakeAvailable(json)
35+
3336
set(SOURCES
3437
gemma.cc
3538
compression/blob_store.cc
@@ -60,17 +63,7 @@ if (WEIGHT_TYPE)
6063
add_definitions(-DGEMMA_WEIGHT_T=${WEIGHT_TYPE})
6164
endif()
6265

63-
# Executable Target
64-
65-
add_executable(gemma run.cc)
66-
target_sources(gemma PRIVATE ${SOURCES})
67-
set_property(TARGET gemma PROPERTY CXX_STANDARD 17)
68-
target_link_libraries(gemma hwy hwy_contrib sentencepiece)
69-
target_include_directories(gemma PRIVATE ./)
7066
FetchContent_GetProperties(sentencepiece)
71-
target_include_directories(gemma PRIVATE ${sentencepiece_SOURCE_DIR})
72-
target_compile_definitions(gemma PRIVATE $<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS NOMINMAX>)
73-
target_compile_options(gemma PRIVATE $<$<PLATFORM_ID:Windows>:-Wno-deprecated-declarations>)
7467

7568
## Library Target
7669

@@ -84,11 +77,21 @@ target_include_directories(libgemma PUBLIC ${sentencepiece_SOURCE_DIR})
8477
target_compile_definitions(libgemma PRIVATE $<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS NOMINMAX>)
8578
target_compile_options(libgemma PRIVATE $<$<PLATFORM_ID:Windows>:-Wno-deprecated-declarations>)
8679

80+
# Executable Target
81+
82+
add_executable(gemma run.cc)
83+
target_link_libraries(gemma libgemma hwy hwy_contrib)
84+
85+
add_executable(benchmark benchmark.cc)
86+
target_link_libraries(benchmark libgemma hwy hwy_contrib nlohmann_json::nlohmann_json)
87+
88+
## Tests
8789
set(GEMMA_ENABLE_TESTS OFF CACHE BOOL "Enable Gemma tests")
8890
if (GEMMA_ENABLE_TESTS)
8991

9092
set(GEMMA_TEST_FILES
9193
ops_test.cc
94+
gemma_test.cc
9295
)
9396

9497
foreach (TESTFILE IN LISTS GEMMA_TEST_FILES)

MODULE.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ http_archive(
2020
strip_prefix = "highway-1.1.0",
2121
)
2222

23+
http_archive(
24+
name = "nlohmann_json",
25+
urls = ["https://github.com/nlohmann/json/archive/refs/tags/v3.11.3.zip"],
26+
integrity = "sha256-BAIrBdgG61/3MCPCgLaGl9Erk+G3JnoLIqGjnsdXgGk=",
27+
strip_prefix = "json-3.11.3",
28+
)
29+
2330
http_archive(
2431
name = "com_google_sentencepiece",
2532
sha256 = "8409b0126ebd62b256c685d5757150cf7fcb2b92a2f2b98efb3f38fc36719754",

0 commit comments

Comments
 (0)