Skip to content

Commit 6864a1f

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

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"
@@ -39,56 +40,6 @@ static const std::map<int, int> LLAMA_N_PARTS = {
3940
{ 8192, 8 },
4041
};
4142

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