Skip to content

Commit 09a7e75

Browse files
jan-wassenbergcopybara-github
authored andcommitted
Prep for sharding gemma.cc: split into kv_cache, tokenizer.
Move activations.h to backprop/ to make space for another activations.h. PiperOrigin-RevId: 648744500
1 parent 85fcd3c commit 09a7e75

19 files changed

+337
-201
lines changed

BUILD.bazel

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,35 @@ cc_library(
9494
],
9595
)
9696

97+
cc_library(
98+
name = "tokenizer",
99+
srcs = ["gemma/tokenizer.cc"],
100+
hdrs = ["gemma/tokenizer.h"],
101+
deps = [
102+
"//compression:io",
103+
"@hwy//:hwy",
104+
"@hwy//:nanobenchmark", # timer
105+
"@hwy//:profiler",
106+
"@com_google_sentencepiece//:sentencepiece_processor",
107+
],
108+
)
109+
110+
cc_library(
111+
name = "kv_cache",
112+
srcs = ["gemma/kv_cache.cc"],
113+
hdrs = ["gemma/kv_cache.h"],
114+
deps = [
115+
":common",
116+
"@hwy//:hwy",
117+
],
118+
)
119+
97120
cc_library(
98121
name = "gemma_lib",
99122
srcs = [
100123
"gemma/gemma.cc",
101124
],
102125
hdrs = [
103-
"gemma/activations.h",
104126
"gemma/gemma.h",
105127
],
106128
exec_properties = {
@@ -114,6 +136,8 @@ cc_library(
114136
deps = [
115137
":common",
116138
":ops",
139+
":tokenizer",
140+
":kv_cache",
117141
":weights",
118142
"//compression:compress",
119143
"//compression:io",
@@ -122,7 +146,6 @@ cc_library(
122146
"@hwy//:nanobenchmark", # timer
123147
"@hwy//:profiler",
124148
"@hwy//:thread_pool",
125-
"@com_google_sentencepiece//:sentencepiece_processor",
126149
],
127150
)
128151

@@ -321,6 +344,7 @@ cc_library(
321344
"backprop/forward.cc",
322345
],
323346
hdrs = [
347+
"backprop/activations.h",
324348
"backprop/backward.h",
325349
"backprop/backward-inl.h",
326350
"backprop/forward.h",
@@ -340,6 +364,7 @@ cc_library(
340364
cc_library(
341365
name = "backprop_scalar",
342366
hdrs = [
367+
"backprop/activations.h",
343368
"backprop/backward_scalar.h",
344369
"backprop/common_scalar.h",
345370
"backprop/forward_scalar.h",

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(SOURCES
4949
compression/sfp.h
5050
compression/sfp-inl.h
5151
compression/test_util.h
52+
backprop/activations.h
5253
backprop/backward.cc
5354
backprop/backward.h
5455
backprop/backward-inl.h
@@ -62,18 +63,21 @@ set(SOURCES
6263
backprop/optimizer.h
6364
evals/cross_entropy.cc
6465
evals/cross_entropy.h
65-
gemma/configs.h
66-
gemma/activations.h
6766
gemma/benchmark_helper.cc
6867
gemma/benchmark_helper.h
6968
gemma/common.cc
7069
gemma/common.h
70+
gemma/configs.h
7171
gemma/gemma.cc
7272
gemma/gemma.h
73+
gemma/kv_cache.cc
74+
gemma/kv_cache.h
7375
gemma/ops.h
76+
gemma/tokenizer.cc
77+
gemma/tokenizer.h
78+
gemma/weights_raw.h
7479
gemma/weights.cc
7580
gemma/weights.h
76-
gemma/weights_raw.h
7781
util/app.h
7882
util/args.h
7983
)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#ifndef THIRD_PARTY_GEMMA_CPP_GEMMA_ACTIVATIONS_H_
17-
#define THIRD_PARTY_GEMMA_CPP_GEMMA_ACTIVATIONS_H_
16+
#ifndef THIRD_PARTY_GEMMA_CPP_BACKPROP_ACTIVATIONS_H_
17+
#define THIRD_PARTY_GEMMA_CPP_BACKPROP_ACTIVATIONS_H_
1818

1919
#include <stddef.h>
2020

@@ -86,4 +86,4 @@ class ActivationsWrapper {
8686

8787
} // namespace gcpp
8888

89-
#endif // THIRD_PARTY_GEMMA_CPP_GEMMA_ACTIVATIONS_H_
89+
#endif // THIRD_PARTY_GEMMA_CPP_BACKPROP_ACTIVATIONS_H_

backprop/backward-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
#include <stddef.h>
2424

25-
#include <algorithm>
2625
#include <cmath>
26+
#include <vector>
2727

28+
#include "backprop/activations.h"
2829
#include "backprop/prompt.h"
29-
#include "gemma/activations.h"
3030
#include "gemma/common.h"
3131
#include "hwy/base.h"
3232
#include "hwy/contrib/thread_pool/thread_pool.h"

backprop/backward.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "backprop/backward.h"
1717

18+
#include "backprop/activations.h"
1819
#include "backprop/prompt.h"
19-
#include "gemma/activations.h"
2020
#include "gemma/common.h"
2121
#include "hwy/contrib/thread_pool/thread_pool.h"
2222

backprop/backward_scalar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#include <cmath>
2323
#include <vector>
2424

25+
#include "backprop/activations.h"
2526
#include "backprop/common_scalar.h"
2627
#include "backprop/prompt.h"
27-
#include "gemma/activations.h"
2828
#include "gemma/common.h" // EmbeddingScaling
2929
#include "gemma/weights_raw.h"
3030

backprop/backward_scalar_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
#include <vector>
2727

2828
#include "gtest/gtest.h"
29+
#include "backprop/activations.h"
2930
#include "backprop/common_scalar.h"
3031
#include "backprop/forward_scalar.h"
3132
#include "backprop/prompt.h"
3233
#include "backprop/sampler.h"
3334
#include "backprop/test_util.h"
34-
#include "gemma/activations.h"
3535
#include "gemma/configs.h"
3636
#include "gemma/weights_raw.h"
3737

backprop/backward_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
#include <random>
2525
#include <vector>
2626

27+
#include "backprop/activations.h"
2728
#include "backprop/backward_scalar.h"
2829
#include "backprop/common_scalar.h"
2930
#include "backprop/forward_scalar.h"
3031
#include "backprop/sampler.h"
3132
#include "backprop/test_util.h"
32-
#include "gemma/activations.h"
3333
#include "gemma/configs.h"
3434
#include "gemma/weights_raw.h"
3535
#include "hwy/base.h"

backprop/forward-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <cmath>
2424
#include <vector>
2525

26-
#include "gemma/activations.h"
26+
#include "backprop/activations.h"
2727
#include "gemma/common.h"
2828
#include "gemma/configs.h"
2929
#include "hwy/base.h"

backprop/forward.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "backprop/forward.h"
1717

18+
#include "backprop/activations.h"
1819
#include "backprop/prompt.h"
19-
#include "gemma/activations.h"
2020
#include "gemma/common.h"
2121
#include "hwy/contrib/thread_pool/thread_pool.h"
2222

0 commit comments

Comments
 (0)