Skip to content

Commit 3a61cf6

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

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"
@@ -46,56 +47,6 @@ static const std::map<int, int> LLAMA_N_PARTS = {
4647
{ 8192, 8 },
4748
};
4849

49-
// default hparams (LLaMA 7B)
50-
struct llama_hparams {
51-
int32_t n_vocab = 32000;
52-
int32_t n_ctx = 512; // this is provided as user input?
53-
int32_t n_embd = 4096;
54-
int32_t n_mult = 256;
55-
int32_t n_head = 32;
56-
int32_t n_layer = 32;
57-
int32_t n_rot = 64;
58-
int32_t f16 = 1;
59-
};
60-
61-
struct llama_layer {
62-
// normalization
63-
struct ggml_tensor * attention_norm;
64-
65-
// attention
66-
struct ggml_tensor * wq;
67-
struct ggml_tensor * wk;
68-
struct ggml_tensor * wv;
69-
struct ggml_tensor * wo;
70-
71-
// normalization
72-
struct ggml_tensor * ffn_norm;
73-
74-
// ff
75-
struct ggml_tensor * w1;
76-
struct ggml_tensor * w2;
77-
struct ggml_tensor * w3;
78-
};
79-
80-
struct llama_model {
81-
llama_hparams hparams;
82-
83-
struct ggml_tensor * tok_embeddings;
84-
85-
struct ggml_tensor * norm;
86-
struct ggml_tensor * output;
87-
88-
std::vector<llama_layer> layers;
89-
90-
// key + value memory
91-
struct ggml_tensor * memory_k;
92-
struct ggml_tensor * memory_v;
93-
94-
//
95-
struct ggml_context * ctx;
96-
std::map<std::string, struct ggml_tensor *> tensors;
97-
};
98-
9950
// load the model's weights from a file
10051

10152
bool llama_model_load(const std::string & fname, llama_model & model, llama_vocab & vocab, int n_ctx, int n_parts, ggml_type memory_type = GGML_TYPE_F32) {

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)