Skip to content
Open
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
27 changes: 16 additions & 11 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ cc_test(
":test_util",
":threading_context",
":weights",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//compression:compress",
"//compression:types",
"@highway//:hwy",
Expand Down Expand Up @@ -185,10 +185,12 @@ cc_test(

cc_library(
name = "test_util",
testonly = True,
hdrs = ["util/test_util.h"],
deps = [
":basics",
":mat",
"//testing/base/public:gunit_for_library_testonly",
"@highway//:hwy",
"@highway//:hwy_test_util",
"@highway//:nanobenchmark",
Expand All @@ -214,7 +216,7 @@ cc_test(
srcs = ["gemma/configs_test.cc"],
deps = [
":configs",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//compression:types",
"//io:fields",
],
Expand Down Expand Up @@ -360,7 +362,7 @@ cc_test(
":mat",
":tensor_info",
":weights",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//compression:compress",
"@highway//:hwy", # aligned_allocator.h
],
Expand Down Expand Up @@ -526,7 +528,7 @@ cc_test(
":ops",
":test_util",
":threading_context",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//compression:compress",
"//compression:test_util",
"@highway//:hwy",
Expand Down Expand Up @@ -557,7 +559,7 @@ cc_test(
":query",
":test_util",
":threading_context",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//compression:test_util",
"//compression:types",
"@highway//:hwy",
Expand All @@ -583,7 +585,7 @@ cc_test(
":matmul_static",
":ops",
":threading_context",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//compression:compress",
"//compression:test_util",
"@highway//:hwy",
Expand Down Expand Up @@ -881,7 +883,7 @@ cc_test(
":test_util",
":threading_context",
":weights",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//compression:compress",
"//compression:types",
"@highway//:hwy",
Expand Down Expand Up @@ -965,8 +967,8 @@ cc_test(
":benchmark_helper",
":configs",
":gemma_lib",
"@googletest//:gtest_main", # buildcleaner: keep
"//io",
":test_util",
"//testing/base/public:gunit_for_library_testonly", # buildcleaner: keep
"@highway//:hwy",
"@highway//:hwy_test_util",
],
Expand Down Expand Up @@ -1006,7 +1008,8 @@ cc_test(
deps = [
":benchmark_helper",
":gemma_lib",
"@googletest//:gtest_main", # buildcleaner: keep
":test_util",
"//testing/base/public:gunit_main", # buildcleaner: keep
"@highway//:hwy",
"@highway//:hwy_test_util",
"@highway//:nanobenchmark",
Expand Down Expand Up @@ -1039,7 +1042,8 @@ cc_test(
":benchmark_helper",
":configs",
":gemma_lib",
"@googletest//:gtest_main", # buildcleaner: keep
":test_util",
"//testing/base/public:gunit_for_library_testonly", # buildcleaner: keep
"//io",
"@highway//:abort_header_only",
"@highway//:hwy_test_util",
Expand Down Expand Up @@ -1104,6 +1108,7 @@ cc_binary(
deps = [
":benchmark_helper",
"@google_benchmark//:benchmark",
"//io",
"@highway//:hwy", # base.h
],
)
Expand Down
13 changes: 7 additions & 6 deletions compression/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cc_test(
srcs = ["distortion_test.cc"],
deps = [
":distortion",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//:test_util",
"@highway//:hwy_test_util",
"@highway//:nanobenchmark", # Unpredictable1
Expand Down Expand Up @@ -112,7 +112,7 @@ cc_test(
tags = ["hwy_ops_test"],
deps = [
":int",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//:test_util",
"@highway//:hwy",
"@highway//:hwy_test_util",
Expand All @@ -132,7 +132,7 @@ cc_test(
deps = [
":compress",
":q4_0",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//:test_util",
"@highway//:hwy",
"@highway//:hwy_test_util",
Expand All @@ -141,6 +141,7 @@ cc_test(

cc_library(
name = "test_util",
testonly = True,
textual_hdrs = [
"test_util-inl.h",
],
Expand All @@ -165,7 +166,7 @@ cc_test(
deps = [
":compress",
":distortion",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//:test_util",
"@highway//:hwy",
"@highway//:hwy_test_util",
Expand All @@ -185,7 +186,7 @@ cc_test(
deps = [
":distortion",
":nuq",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//:test_util",
"@highway//:hwy",
"@highway//:hwy_test_util",
Expand Down Expand Up @@ -230,7 +231,7 @@ cc_test(
":compress",
":distortion",
":test_util",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//:test_util",
"//:threading_context",
"@highway//:hwy",
Expand Down
2 changes: 2 additions & 0 deletions evals/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ int BenchmarkTriviaQA(GemmaEnv& env, const Path& json_file,
} // namespace gcpp

int main(int argc, char** argv) {
gcpp::InternalInit();

gcpp::ConsumedArgs consumed(argc, argv);
gcpp::GemmaArgs args(argc, argv, consumed);
gcpp::BenchmarkArgs benchmark_args(argc, argv, consumed);
Expand Down
5 changes: 1 addition & 4 deletions evals/benchmark_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
namespace gcpp {

GemmaEnv::GemmaEnv(const GemmaArgs& args)
: initializer_value_(gcpp::InternalInit()),
ctx_(args.threading),
env_(ctx_),
gemma_(args, ctx_) {
: ctx_(args.threading), env_(ctx_), gemma_(args, ctx_) {
const ModelConfig& config = gemma_.Config();

if (args.inference.verbosity >= 2) {
Expand Down
2 changes: 0 additions & 2 deletions evals/benchmark_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ class GemmaEnv {
MatMulEnv& MutableEnv() { return env_; }

private:
// This is used to ensure that InternalInit is called before anything else.
int initializer_value_ = 0;
ThreadingContext ctx_;
MatMulEnv env_;
Gemma gemma_;
Expand Down
3 changes: 3 additions & 0 deletions evals/benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "benchmark/benchmark.h"
#include "evals/benchmark_helper.h"
#include "evals/prompts.h"
#include "io/io.h"

namespace gcpp {

Expand Down Expand Up @@ -98,6 +99,8 @@ BENCHMARK(BM_coding_prompt)
->UseRealTime();

int main(int argc, char** argv) {
gcpp::InternalInit();

gcpp::ConsumedArgs consumed(argc, argv);
gcpp::GemmaArgs args(argc, argv, consumed);
consumed.AbortIfUnconsumed();
Expand Down
2 changes: 2 additions & 0 deletions evals/debug_prompt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class PromptArgs : public ArgsBase<PromptArgs> {
};

int Run(int argc, char** argv) {
InternalInit();

ConsumedArgs consumed(argc, argv);
const GemmaArgs args(argc, argv, consumed);
const PromptArgs prompt_args(argc, argv, consumed);
Expand Down
6 changes: 3 additions & 3 deletions evals/gemma_batch_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

#include "evals/benchmark_helper.h"
#include "gemma/gemma.h"
#include "util/test_util.h"
#include "hwy/base.h"
#include "hwy/nanobenchmark.h"
#include "hwy/profiler.h"
#include "hwy/tests/hwy_gtest.h"

namespace gcpp {
namespace {
Expand Down Expand Up @@ -144,6 +144,8 @@ TEST_F(GemmaBatchBench, RandomQuestionsBatched) {
} // namespace gcpp

int main(int argc, char** argv) {
gcpp::InternalInitTest();

fprintf(stderr, "GemmaEnv setup..\n");
gcpp::ConsumedArgs consumed(argc, argv);
gcpp::GemmaArgs args(argc, argv, consumed);
Expand All @@ -152,7 +154,5 @@ int main(int argc, char** argv) {
gcpp::GemmaEnv env(args);
gcpp::s_env = &env;

testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}
8 changes: 4 additions & 4 deletions evals/gemma_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

#include "evals/benchmark_helper.h"
#include "gemma/configs.h"
#include "util/test_util.h"
#include "hwy/base.h"
#include "hwy/tests/hwy_gtest.h"

// This test can be run manually with the downloaded gemma weights.
// To run the test, pass the following flags:
// --model <model> --tokenizer <tokenizer_path> --weights <weights_path>
// or just use the single-file weights file with --weights <weights_path>.
// It should pass for the following models:
// Gemma1: 2b-it (v1 and v1.1), 7b-it (v1 and v1.1), gr2b-it,
// Gemma2: gemma2-2b-it, 9b-it, 27b-it,
// Gemma2: gemma2-2b-it, 9b-it, 27b-it
// Gemma3: gemma3-270m-it

namespace gcpp {
namespace {
Expand Down Expand Up @@ -183,7 +183,7 @@ TEST_F(GemmaTest, CrossEntropySmall) {
} // namespace gcpp

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
gcpp::InternalInitTest();
gcpp::GemmaTest::InitEnv(argc, argv);
int ret = RUN_ALL_TESTS();
gcpp::GemmaTest::DeleteEnv();
Expand Down
2 changes: 2 additions & 0 deletions evals/run_mmlu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ void Run(GemmaEnv& env, JsonArgs& json) {
} // namespace gcpp

int main(int argc, char** argv) {
gcpp::InternalInit();

{
PROFILER_ZONE("Startup.all");
gcpp::ConsumedArgs consumed(argc, argv);
Expand Down
4 changes: 2 additions & 2 deletions evals/wheat_from_chaff_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "gemma/configs.h"
#include "gemma/gemma.h"
#include "io/io.h"
#include "util/test_util.h"
#include "hwy/base.h"
#include "hwy/tests/hwy_gtest.h"

// This test can be run manually with the downloaded gemma weights.
// To run the test, pass the following flags:
Expand Down Expand Up @@ -187,7 +187,7 @@ TEST_F(GemmaTest, WheatFromChaff) {
} // namespace gcpp

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
gcpp::InternalInitTest();
gcpp::GemmaTest::InitEnv(argc, argv);
int ret = RUN_ALL_TESTS();
gcpp::GemmaTest::DeleteEnv();
Expand Down
2 changes: 1 addition & 1 deletion io/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ cc_test(
deps = [
":blob_store",
":io",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_main", # buildcleaner: keep
"//:basics",
"//:threading_context",
"@highway//:hwy_test_util",
Expand Down
3 changes: 1 addition & 2 deletions io/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ bool IOBatch::Add(void* mem, size_t bytes) {
}

int InternalInit() {
// currently unused, except for init list ordering in GemmaEnv.
return 0;
return 0; // currently unused
}

uint64_t IOBatch::Read(const File& file) const {
Expand Down
2 changes: 2 additions & 0 deletions io/migrate_weights.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct WriterArgs : public ArgsBase<WriterArgs> {
} // namespace gcpp

int main(int argc, char** argv) {
gcpp::InternalInit();

gcpp::ConsumedArgs consumed(argc, argv);
gcpp::GemmaArgs args(argc, argv, consumed);
gcpp::WriterArgs writer_args(argc, argv, consumed);
Expand Down
3 changes: 2 additions & 1 deletion paligemma/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ cc_test(
],
deps = [
":paligemma_helper",
"@googletest//:gtest_main", # buildcleaner: keep
"//testing/base/public:gunit_for_library_testonly", # buildcleaner: keep
"//:allocator",
"//:benchmark_helper",
"//:configs",
"//:gemma_lib",
"//:test_util",
"@highway//:hwy_test_util",
],
)
4 changes: 2 additions & 2 deletions paligemma/paligemma_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "gemma/gemma.h"
#include "paligemma/paligemma_helper.h"
#include "util/allocator.h"
#include "hwy/tests/hwy_gtest.h"
#include "util/test_util.h"

// This test can be run manually with the downloaded PaliGemma weights.
// It should pass for `paligemma-3b-mix-224` and `paligemma2-3b-pt-448`.
Expand Down Expand Up @@ -70,7 +70,7 @@ TEST_F(PaliGemmaTest, QueryObjects) {
} // namespace gcpp

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
gcpp::InternalInitTest();

gcpp::ConsumedArgs consumed(argc, argv);
gcpp::GemmaArgs args(argc, argv, consumed);
Expand Down
5 changes: 5 additions & 0 deletions util/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cmath>
#include <iostream>

#include "gtest/gtest.h"
#include "util/basics.h" // RngStream
#include "util/mat.h"
#include "hwy/base.h"
Expand All @@ -35,6 +36,10 @@

namespace gcpp {

inline int InternalInitTest() {
return 0; // currently unused
}

// Excludes outliers; we might not have enough samples for a reliable mode.
HWY_INLINE double TrimmedMean(double* seconds, size_t num) {
std::sort(seconds, seconds + num);
Expand Down