From cbb67b4ee009001217432ba48ac7ba371edcc42e Mon Sep 17 00:00:00 2001 From: Jan Wassenberg Date: Mon, 8 Jul 2024 01:12:28 -0700 Subject: [PATCH] Move benchmark_helper to evals/, weights_raw to compression/. PiperOrigin-RevId: 650155983 --- BUILD.bazel | 22 +++++----------------- CMakeLists.txt | 6 +++--- backprop/backward_scalar.h | 2 +- backprop/backward_scalar_test.cc | 2 +- backprop/backward_test.cc | 2 +- backprop/forward_scalar.h | 2 +- backprop/test_util.h | 2 +- compression/BUILD | 21 ++++++++++++++++----- compression/compress_weights.cc | 4 ++-- {gemma => compression}/weights_raw.h | 18 ++++++++++-------- evals/benchmark.cc | 2 +- {gemma => evals}/benchmark_helper.cc | 2 +- {gemma => evals}/benchmark_helper.h | 6 +++--- evals/benchmarks.cc | 2 +- evals/debug_prompt.cc | 2 +- evals/gemma_test.cc | 2 +- evals/run_mmlu.cc | 2 +- gemma/run.cc | 2 +- 18 files changed, 51 insertions(+), 50 deletions(-) rename {gemma => compression}/weights_raw.h (93%) rename {gemma => evals}/benchmark_helper.cc (99%) rename {gemma => evals}/benchmark_helper.h (95%) diff --git a/BUILD.bazel b/BUILD.bazel index 90ec0c0..b4f1148 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -82,18 +82,6 @@ cc_library( ], ) -cc_library( - name = "weights_raw", - hdrs = ["gemma/weights_raw.h"], - deps = [ - ":common", - ":weights", - "//compression:compress", - "@hwy//:hwy", - "@hwy//:thread_pool", - ], -) - cc_library( name = "tokenizer", srcs = ["gemma/tokenizer.cc"], @@ -205,8 +193,8 @@ cc_library( cc_library( name = "benchmark_helper", - srcs = ["gemma/benchmark_helper.cc"], - hdrs = ["gemma/benchmark_helper.h"], + srcs = ["evals/benchmark_helper.cc"], + hdrs = ["evals/benchmark_helper.h"], deps = [ ":app", ":args", @@ -369,7 +357,7 @@ cc_library( ":common", ":gemma_lib", ":prompt", - ":weights_raw", + "//compression:weights_raw", ], ) @@ -386,8 +374,8 @@ cc_test( ":gemma_lib", ":prompt", ":sampler", - ":weights_raw", "@googletest//:gtest_main", + "//compression:weights_raw", ], ) @@ -409,8 +397,8 @@ cc_test( ":gemma_lib", ":ops", ":sampler", - ":weights_raw", "@googletest//:gtest_main", + "//compression:weights_raw", "@hwy//:hwy", "@hwy//:hwy_test_util", "@hwy//:thread_pool", diff --git a/CMakeLists.txt b/CMakeLists.txt index 819bec7..bc6dc14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ set(SOURCES compression/sfp.h compression/sfp-inl.h compression/test_util.h + compression/weights_raw.h backprop/activations.h backprop/backward.cc backprop/backward.h @@ -61,11 +62,11 @@ set(SOURCES backprop/forward_scalar.h backprop/optimizer.cc backprop/optimizer.h + evals/benchmark_helper.cc + evals/benchmark_helper.h evals/cross_entropy.cc evals/cross_entropy.h gemma/activations.h - gemma/benchmark_helper.cc - gemma/benchmark_helper.h gemma/common.cc gemma/common.h gemma/configs.h @@ -95,7 +96,6 @@ set(SOURCES gemma/ops.h gemma/tokenizer.cc gemma/tokenizer.h - gemma/weights_raw.h gemma/weights.cc gemma/weights.h util/app.h diff --git a/backprop/backward_scalar.h b/backprop/backward_scalar.h index 8a23272..697d386 100644 --- a/backprop/backward_scalar.h +++ b/backprop/backward_scalar.h @@ -25,8 +25,8 @@ #include "backprop/activations.h" #include "backprop/common_scalar.h" #include "backprop/prompt.h" +#include "compression/weights_raw.h" #include "gemma/common.h" // EmbeddingScaling -#include "gemma/weights_raw.h" namespace gcpp { template diff --git a/backprop/backward_scalar_test.cc b/backprop/backward_scalar_test.cc index 706b0ef..b261359 100644 --- a/backprop/backward_scalar_test.cc +++ b/backprop/backward_scalar_test.cc @@ -32,8 +32,8 @@ #include "backprop/prompt.h" #include "backprop/sampler.h" #include "backprop/test_util.h" +#include "compression/weights_raw.h" #include "gemma/configs.h" -#include "gemma/weights_raw.h" namespace gcpp { diff --git a/backprop/backward_test.cc b/backprop/backward_test.cc index 0cbf69d..94b164f 100644 --- a/backprop/backward_test.cc +++ b/backprop/backward_test.cc @@ -30,8 +30,8 @@ #include "backprop/forward_scalar.h" #include "backprop/sampler.h" #include "backprop/test_util.h" +#include "compression/weights_raw.h" #include "gemma/configs.h" -#include "gemma/weights_raw.h" #include "hwy/base.h" #include "hwy/contrib/thread_pool/thread_pool.h" diff --git a/backprop/forward_scalar.h b/backprop/forward_scalar.h index 60c8025..5e33d1d 100644 --- a/backprop/forward_scalar.h +++ b/backprop/forward_scalar.h @@ -26,8 +26,8 @@ #include "backprop/activations.h" #include "backprop/common_scalar.h" #include "backprop/prompt.h" +#include "compression/weights_raw.h" #include "gemma/common.h" // EmbeddingScaling -#include "gemma/weights_raw.h" namespace gcpp { diff --git a/backprop/test_util.h b/backprop/test_util.h index 45ab97b..ef257e7 100644 --- a/backprop/test_util.h +++ b/backprop/test_util.h @@ -23,7 +23,7 @@ #include #include "gtest/gtest.h" -#include "gemma/weights_raw.h" +#include "compression/weights_raw.h" namespace gcpp { diff --git a/compression/BUILD b/compression/BUILD index 962573f..ac03bff 100644 --- a/compression/BUILD +++ b/compression/BUILD @@ -181,17 +181,28 @@ cc_library( ], ) +cc_library( + name = "weights_raw", + hdrs = ["weights_raw.h"], + deps = [ + "//:common", + "//compression:compress", + "@hwy//:hwy", + "@hwy//:thread_pool", + ], +) + cc_binary( name = "compress_weights", srcs = ["compress_weights.cc"], deps = [ ":compress", + ":weights_raw", # Placeholder for internal dep, do not remove., - "//third_party/gemma_cpp:args", - "//third_party/gemma_cpp:common", - "//third_party/gemma_cpp:gemma_lib", - "//third_party/gemma_cpp:weights", - "//third_party/gemma_cpp:weights_raw", + "//:args", + "//:common", + "//:gemma_lib", + "//:weights", "@hwy//:hwy", "@hwy//:nanobenchmark", "@hwy//:profiler", diff --git a/compression/compress_weights.cc b/compression/compress_weights.cc index b2ca0b0..d57a2a1 100644 --- a/compression/compress_weights.cc +++ b/compression/compress_weights.cc @@ -38,9 +38,9 @@ #include // NOLINT #include "compression/io.h" // Path -#include "gemma/common.h" // Model +#include "compression/weights_raw.h" +#include "gemma/common.h" // Model #include "gemma/weights.h" -#include "gemma/weights_raw.h" #include "util/args.h" #include "hwy/base.h" #include "hwy/contrib/thread_pool/thread_pool.h" diff --git a/gemma/weights_raw.h b/compression/weights_raw.h similarity index 93% rename from gemma/weights_raw.h rename to compression/weights_raw.h index cb66876..774c6f2 100644 --- a/gemma/weights_raw.h +++ b/compression/weights_raw.h @@ -13,14 +13,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_GEMMA_CPP_GEMMA_WEIGHTS_RAW_H_ -#define THIRD_PARTY_GEMMA_CPP_GEMMA_WEIGHTS_RAW_H_ +#ifndef THIRD_PARTY_GEMMA_CPP_COMPRESSION_WEIGHTS_RAW_H_ +#define THIRD_PARTY_GEMMA_CPP_COMPRESSION_WEIGHTS_RAW_H_ -// NOTE: this file should only be used by compress_weights; it is currently -// also referenced by backprop, but we plan to remove that. Historical note: -// this was the original f32-only simple on-disk format created by a Python -// export script. BlobStore is now the preferred on-disk format, and we load -// that into CompressedWeights. +// Historical note: this was the original f32-only simple on-disk format +// created by convert_weights.py. BlobStore is now the preferred on-disk +// format, and we load that into CompressedWeights. +// +// NOTE: this file should only be used by compress_weights. It is currently +// also referenced by backprop because it supports T = std::complex, and +// CompressedWeights might not yet. #include @@ -239,4 +241,4 @@ class WeightsWrapper { } // namespace gcpp -#endif // THIRD_PARTY_GEMMA_CPP_GEMMA_WEIGHTS_RAW_H_ +#endif // THIRD_PARTY_GEMMA_CPP_COMPRESSION_WEIGHTS_RAW_H_ diff --git a/evals/benchmark.cc b/evals/benchmark.cc index d9d354d..9b0d609 100644 --- a/evals/benchmark.cc +++ b/evals/benchmark.cc @@ -10,8 +10,8 @@ #include #include "compression/io.h" // Path +#include "evals/benchmark_helper.h" #include "evals/cross_entropy.h" -#include "gemma/benchmark_helper.h" #include "gemma/common.h" #include "gemma/gemma.h" #include "util/args.h" diff --git a/gemma/benchmark_helper.cc b/evals/benchmark_helper.cc similarity index 99% rename from gemma/benchmark_helper.cc rename to evals/benchmark_helper.cc index 58da6a0..fd3593d 100644 --- a/gemma/benchmark_helper.cc +++ b/evals/benchmark_helper.cc @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gemma/benchmark_helper.h" +#include "evals/benchmark_helper.h" #include #include diff --git a/gemma/benchmark_helper.h b/evals/benchmark_helper.h similarity index 95% rename from gemma/benchmark_helper.h rename to evals/benchmark_helper.h index 25f40b4..1de6d70 100644 --- a/gemma/benchmark_helper.h +++ b/evals/benchmark_helper.h @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef THIRD_PARTY_GEMMA_CPP_GEMMA_BENCHMARK_HELPER_H_ -#define THIRD_PARTY_GEMMA_CPP_GEMMA_BENCHMARK_HELPER_H_ +#ifndef THIRD_PARTY_GEMMA_CPP_EVALS_BENCHMARK_HELPER_H_ +#define THIRD_PARTY_GEMMA_CPP_EVALS_BENCHMARK_HELPER_H_ #include @@ -116,4 +116,4 @@ void ShowHelp(LoaderArgs& loader, InferenceArgs& inference, AppArgs& app); } // namespace gcpp -#endif // THIRD_PARTY_GEMMA_CPP_GEMMA_BENCHMARK_HELPER_H_ +#endif // THIRD_PARTY_GEMMA_CPP_EVALS_BENCHMARK_HELPER_H_ diff --git a/evals/benchmarks.cc b/evals/benchmarks.cc index 283500c..6b90159 100644 --- a/evals/benchmarks.cc +++ b/evals/benchmarks.cc @@ -19,7 +19,7 @@ #include #include "benchmark/benchmark.h" -#include "gemma/benchmark_helper.h" +#include "evals/benchmark_helper.h" namespace gcpp { diff --git a/evals/debug_prompt.cc b/evals/debug_prompt.cc index 7bc33e5..8a4cc8f 100644 --- a/evals/debug_prompt.cc +++ b/evals/debug_prompt.cc @@ -19,7 +19,7 @@ #include #include "compression/io.h" -#include "gemma/benchmark_helper.h" +#include "evals/benchmark_helper.h" #include "gemma/gemma.h" // LayersOutputFunc #include "util/args.h" #include "hwy/base.h" diff --git a/evals/gemma_test.cc b/evals/gemma_test.cc index 97d1af3..d24425f 100644 --- a/evals/gemma_test.cc +++ b/evals/gemma_test.cc @@ -21,7 +21,7 @@ #include #include -#include "gemma/benchmark_helper.h" +#include "evals/benchmark_helper.h" #include "gemma/common.h" #include "hwy/aligned_allocator.h" #include "hwy/tests/hwy_gtest.h" diff --git a/evals/run_mmlu.cc b/evals/run_mmlu.cc index f6f4640..981f8c8 100644 --- a/evals/run_mmlu.cc +++ b/evals/run_mmlu.cc @@ -20,7 +20,7 @@ #include #include "compression/io.h" // Path -#include "gemma/benchmark_helper.h" +#include "evals/benchmark_helper.h" #include "gemma/gemma.h" // Gemma #include "util/args.h" #include "hwy/base.h" diff --git a/gemma/run.cc b/gemma/run.cc index cb2a2d5..1a7a0c3 100644 --- a/gemma/run.cc +++ b/gemma/run.cc @@ -22,7 +22,7 @@ #include // Placeholder for internal header, do not modify. -#include "gemma/benchmark_helper.h" +#include "evals/benchmark_helper.h" #include "gemma/common.h" #include "gemma/gemma.h" // Gemma #include "util/app.h"