Skip to content

Commit 59a7f5f

Browse files
committed
Move struct definitions in llama.cpp to llama.h
Signed-off-by: Thiago Padilha <[email protected]>
1 parent 67148a8 commit 59a7f5f

File tree

2 files changed

+60
-50
lines changed

2 files changed

+60
-50
lines changed

llama.cpp

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "llama.h"
12
#include "ggml.h"
23

34
#include "utils.h"
@@ -37,56 +38,6 @@ static const std::map<int, int> LLAMA_N_PARTS = {
3738
{ 8192, 8 },
3839
};
3940

40-
// default hparams (LLaMA 7B)
41-
struct llama_hparams {
42-
int32_t n_vocab = 32000;
43-
int32_t n_ctx = 512; // this is provided as user input?
44-
int32_t n_embd = 4096;
45-
int32_t n_mult = 256;
46-
int32_t n_head = 32;
47-
int32_t n_layer = 32;
48-
int32_t n_rot = 64;
49-
int32_t f16 = 1;
50-
};
51-
52-
struct llama_layer {
53-
// normalization
54-
struct ggml_tensor * attention_norm;
55-
56-
// attention
57-
struct ggml_tensor * wq;
58-
struct ggml_tensor * wk;
59-
struct ggml_tensor * wv;
60-
struct ggml_tensor * wo;
61-
62-
// normalization
63-
struct ggml_tensor * ffn_norm;
64-
65-
// ff
66-
struct ggml_tensor * w1;
67-
struct ggml_tensor * w2;
68-
struct ggml_tensor * w3;
69-
};
70-
71-
struct llama_model {
72-
llama_hparams hparams;
73-
74-
struct ggml_tensor * tok_embeddings;
75-
76-
struct ggml_tensor * norm;
77-
struct ggml_tensor * output;
78-
79-
std::vector<llama_layer> layers;
80-
81-
// key + value memory
82-
struct ggml_tensor * memory_k;
83-
struct ggml_tensor * memory_v;
84-
85-
//
86-
struct ggml_context * ctx;
87-
std::map<std::string, struct ggml_tensor *> tensors;
88-
};
89-
9041
// load the model's weights from a file
9142
bool llama_model_load(const std::string & fname, llama_model & model, gpt_vocab & vocab, int n_ctx, ggml_type memory_type = GGML_TYPE_F32) {
9243
fprintf(stderr, "%s: loading model from '%s' - please wait ...\n", __func__, fname.c_str());

llama.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <map>
5+
#include <cstdio>
6+
#include <string>
7+
8+
#include "ggml.h"
9+
10+
11+
// default hparams (LLaMA 7B)
12+
struct llama_hparams {
13+
int32_t n_vocab = 32000;
14+
int32_t n_ctx = 512; // this is provided as user input?
15+
int32_t n_embd = 4096;
16+
int32_t n_mult = 256;
17+
int32_t n_head = 32;
18+
int32_t n_layer = 32;
19+
int32_t n_rot = 64;
20+
int32_t f16 = 1;
21+
};
22+
23+
struct llama_layer {
24+
// normalization
25+
struct ggml_tensor * attention_norm;
26+
27+
// attention
28+
struct ggml_tensor * wq;
29+
struct ggml_tensor * wk;
30+
struct ggml_tensor * wv;
31+
struct ggml_tensor * wo;
32+
33+
// normalization
34+
struct ggml_tensor * ffn_norm;
35+
36+
// ff
37+
struct ggml_tensor * w1;
38+
struct ggml_tensor * w2;
39+
struct ggml_tensor * w3;
40+
};
41+
42+
struct llama_model {
43+
llama_hparams hparams;
44+
45+
struct ggml_tensor * tok_embeddings;
46+
47+
struct ggml_tensor * norm;
48+
struct ggml_tensor * output;
49+
50+
std::vector<llama_layer> layers;
51+
52+
// key + value memory
53+
struct ggml_tensor * memory_k;
54+
struct ggml_tensor * memory_v;
55+
56+
//
57+
struct ggml_context * ctx;
58+
std::map<std::string, struct ggml_tensor *> tensors;
59+
};

0 commit comments

Comments
 (0)