diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..18dad30 --- /dev/null +++ b/BUILD @@ -0,0 +1,116 @@ +# gemma.cpp is a lightweight, standalone C++ inference engine for the Gemma +# foundation models from Google. + +load("@rules_license//rules:license.bzl", "license") + +package( + default_applicable_licenses = ["//:license"], + default_visibility = ["//visibility:public"], +) + +license( + name = "license", + package_name = "gemma_cpp", +) + +# Dual-licensed Apache 2 and 3-clause BSD. +licenses(["notice"]) + +exports_files(["LICENSE"]) + +cc_library( + name = "transformer_ops", + hdrs = [ + "ops.h", + ], + deps = [ + "//compression:compress", + # copybara:import_next_line:hwy + "//:algo", + # copybara:import_next_line:hwy + "//:dot", + # copybara:import_next_line:hwy + "//:hwy", + # copybara:import_next_line:hwy + "//:math", + # copybara:import_next_line:hwy + "//:matvec", + # copybara:import_next_line:hwy + "//:profiler", + # copybara:import_next_line:hwy + "//:thread_pool", + "//hwy/contrib/sort:vqsort", + ], +) + +cc_library( + name = "args", + hdrs = [ + "util/args.h", + ], + deps = [ + # copybara:import_next_line:hwy + "//:hwy", + ], +) + +cc_library( + name = "app", + hdrs = [ + "util/app.h", + ], + deps = [ + ":args", + # copybara:import_next_line:hwy + "//:hwy", + ], +) + +cc_library( + name = "gemma_lib", + srcs = [ + "gemma.cc", + ], + hdrs = [ + "configs.h", + "gemma.h", + ], + deps = [ + ":args", + ":transformer_ops", + "//base", + "//compression:compress", + # copybara:import_next_line:hwy + "//:hwy", + # copybara:import_next_line:hwy + "//:matvec", + # copybara:import_next_line:hwy + "//:nanobenchmark", # timer + # copybara:import_next_line:hwy + "//:profiler", + # copybara:import_next_line:hwy + "//:thread_pool", + ":sentencepiece_processor", + ], +) + +cc_binary( + name = "gemma", + srcs = [ + "run.cc", + ], + deps = [ + ":app", + ":args", + ":gemma_lib", + "//compression:compress", + # copybara:import_next_line:hwy + "//:hwy", + # copybara:import_next_line:hwy + "//:nanobenchmark", + # copybara:import_next_line:hwy + "//:profiler", + # copybara:import_next_line:hwy + "//:thread_pool", + ], +) diff --git a/compression/BUILD b/compression/BUILD new file mode 100644 index 0000000..f6f9420 --- /dev/null +++ b/compression/BUILD @@ -0,0 +1,161 @@ +# Weight compression, I/O and analysis + +package( + default_applicable_licenses = ["//third_party/gemma_cpp:license"], + default_visibility = [ + "//learning/gemini/prod/contrib/gemini_cpp:__subpackages__", + "//third_party/gemma_cpp:__subpackages__", + ], +) + +cc_library( + name = "blob_store", + srcs = [ + "blob_store.cc", + ], + hdrs = [ + "blob_store.h", + ], + deps = [ + # copybara:import_next_line:hwy + "//:hwy", + # copybara:import_next_line:hwy + "//:thread_pool", + ], +) + +cc_library( + name = "stats", + srcs = [ + "stats.cc", + ], + hdrs = [ + "distortion.h", + "stats.h", + ], + deps = [ + # copybara:import_next_line:hwy + "//:hwy", + ], +) + +cc_library( + name = "sfp", + hdrs = [ + "sfp.h", + ], + textual_hdrs = [ + "sfp-inl.h", + ], + deps = [ + # copybara:import_next_line:hwy + "//:hwy", + ], +) + +cc_test( + name = "sfp_test", + size = "small", + srcs = ["sfp_test.cc"], + features = ["fully_static_link"], + linkstatic = True, + local_defines = ["HWY_IS_TEST"], + # for test_suite. + tags = ["hwy_ops_test"], + deps = [ + ":sfp", + ":stats", + "//testing/base/public:gunit_main_no_google3", + # copybara:import_next_line:hwy + "//:hwy", + # copybara:import_next_line:hwy + "//:hwy_test_util", + # copybara:import_next_line:hwy + "//:nanobenchmark", + # copybara:import_next_line:hwy + "//:thread_pool", + ], +) + +cc_library( + name = "nuq", + hdrs = [ + "nuq.h", + ], + textual_hdrs = [ + "nuq-inl.h", + ], + deps = [ + ":sfp", + # copybara:import_next_line:hwy + "//:hwy", + "//third_party/highway/hwy/contrib/sort:vqsort", + ], +) + +cc_test( + name = "nuq_test", + size = "small", + srcs = ["nuq_test.cc"], + features = ["fully_static_link"], + linkstatic = True, + local_defines = ["HWY_IS_TEST"], + # for test_suite. + tags = ["hwy_ops_test"], + deps = [ + ":nuq", + ":sfp", + ":stats", + "//testing/base/public:gunit_main_no_google3", + # copybara:import_next_line:hwy + "//:hwy", + # copybara:import_next_line:hwy + "//:hwy_test_util", + # copybara:import_next_line:hwy + "//:nanobenchmark", + ], +) + +cc_library( + name = "compress", + hdrs = [ + "compress.h", + "nuq.h", + "sfp.h", + ], + textual_hdrs = [ + "compress-inl.h", + ], + deps = [ + ":blob_store", + ":nuq", + ":sfp", + ":stats", + # copybara:import_next_line:hwy + "//:dot", + # copybara:import_next_line:hwy + "//:hwy", + # copybara:import_next_line:hwy + "//:thread_pool", + ], +) + +# For internal experimentation +cc_library( + name = "analyze", + textual_hdrs = [ + "analyze.h", + ], + deps = [ + ":nuq", + ":sfp", + ":stats", + # copybara:import_next_line:hwy + "//:hwy", + # copybara:import_next_line:hwy + "//:nanobenchmark", # timer + # copybara:import_next_line:hwy + "//:thread_pool", + "//third_party/highway/hwy/contrib/sort:vqsort", + ], +) diff --git a/gemma.cc b/gemma.cc index 70777ac..2a51b34 100644 --- a/gemma.cc +++ b/gemma.cc @@ -60,8 +60,7 @@ #include "hwy/aligned_allocator.h" #include "hwy/base.h" #include "hwy/contrib/thread_pool/thread_pool.h" -// copybara:import_next_line:sentencepiece -#include "src/sentencepiece_processor.h" +#include "sentencepiece_processor.h" namespace gcpp { diff --git a/gemma.h b/gemma.h index 5dc9f62..1c9caf8 100644 --- a/gemma.h +++ b/gemma.h @@ -33,8 +33,7 @@ #include "hwy/aligned_allocator.h" #include "hwy/base.h" // hwy::bfloat16_t #include "hwy/contrib/thread_pool/thread_pool.h" -// copybara:import_next_line:sentencepiece -#include "src/sentencepiece_processor.h" +#include "sentencepiece_processor.h" namespace gcpp {