Skip to content

Commit a170669

Browse files
committed
llama : remove redundant keywords (struct, enum)
ggml-ci
1 parent bcee6dd commit a170669

9 files changed

+609
-611
lines changed

include/llama.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ extern "C" {
471471

472472
LLAMA_API const struct llama_model * llama_get_model (const struct llama_context * ctx); // TODO: remove const?
473473
LLAMA_API struct llama_kv_cache * llama_get_kv_self ( struct llama_context * ctx);
474-
LLAMA_API enum llama_pooling_type llama_pooling_type(const struct llama_context * ctx);
474+
LLAMA_API enum llama_pooling_type llama_pooling_type(const struct llama_context * ctx); // TODO: rename to llama_get_pooling_type
475475

476476
LLAMA_API const struct llama_vocab * llama_model_get_vocab(const struct llama_model * model);
477477
LLAMA_API enum llama_rope_type llama_model_rope_type(const struct llama_model * model);

src/llama-adapter.cpp

+14-15
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
#include "llama-mmap.h"
55
#include "llama-model.h"
66

7-
#include <algorithm>
87
#include <map>
98
#include <cassert>
109
#include <stdexcept>
1110

1211
// vec
1312

14-
struct ggml_tensor * llama_adapter_cvec::tensor_for(int il) const {
13+
ggml_tensor * llama_adapter_cvec::tensor_for(int il) const {
1514
if (il < 0 || il < layer_start || il > layer_end || (size_t) il >= tensors.size()) {
1615
return nullptr;
1716
}
1817

1918
return tensors[il];
2019
}
2120

22-
struct ggml_tensor * llama_adapter_cvec::apply_to(struct ggml_context * ctx, struct ggml_tensor * cur, int il) const {
21+
ggml_tensor * llama_adapter_cvec::apply_to(ggml_context * ctx, ggml_tensor * cur, int il) const {
2322
ggml_tensor * layer_dir = tensor_for(il);
2423
if (layer_dir != nullptr) {
2524
cur = ggml_add(ctx, cur, layer_dir);
@@ -40,7 +39,7 @@ bool llama_adapter_cvec::init(const llama_model & model) {
4039
auto ctx_for_buft = [&](ggml_backend_buffer_type_t buft) -> ggml_context * {
4140
auto it = ctx_map.find(buft);
4241
if (it == ctx_map.end()) {
43-
struct ggml_init_params params = {
42+
ggml_init_params params = {
4443
/*.mem_size =*/ hparams.n_layer*ggml_tensor_overhead(),
4544
/*.mem_buffer =*/ NULL,
4645
/*.no_alloc =*/ true,
@@ -135,7 +134,7 @@ bool llama_adapter_cvec::apply(
135134

136135
// lora
137136

138-
llama_adapter_lora_weight * llama_adapter_lora::get_weight(struct ggml_tensor * w) {
137+
llama_adapter_lora_weight * llama_adapter_lora::get_weight(ggml_tensor * w) {
139138
const std::string name(w->name);
140139

141140
const auto pos = ab_map.find(name);
@@ -146,11 +145,11 @@ llama_adapter_lora_weight * llama_adapter_lora::get_weight(struct ggml_tensor *
146145
return nullptr;
147146
}
148147

149-
static void llama_adapter_lora_init_impl(struct llama_model & model, const char * path_lora, struct llama_adapter_lora & adapter) {
148+
static void llama_adapter_lora_init_impl(llama_model & model, const char * path_lora, llama_adapter_lora & adapter) {
150149
LLAMA_LOG_INFO("%s: loading lora adapter from '%s' ...\n", __func__, path_lora);
151150

152151
ggml_context * ctx_init;
153-
struct gguf_init_params meta_gguf_params = {
152+
gguf_init_params meta_gguf_params = {
154153
/* .no_alloc = */ true,
155154
/* .ctx = */ &ctx_init,
156155
};
@@ -201,7 +200,7 @@ static void llama_adapter_lora_init_impl(struct llama_model & model, const char
201200
auto it = ctx_map.find(buft);
202201
if (it == ctx_map.end()) {
203202
// add a new context
204-
struct ggml_init_params params = {
203+
ggml_init_params params = {
205204
/*.mem_size =*/ n_tensors*ggml_tensor_overhead(),
206205
/*.mem_buffer =*/ NULL,
207206
/*.no_alloc =*/ true,
@@ -264,7 +263,7 @@ static void llama_adapter_lora_init_impl(struct llama_model & model, const char
264263
throw std::runtime_error("LoRA tensor '" + name + "' does not exist in base model (hint: maybe wrong base model?)");
265264
}
266265

267-
struct ggml_context * dev_ctx = ctx_for_buft(ggml_backend_buffer_get_type(model_tensor->buffer));
266+
ggml_context * dev_ctx = ctx_for_buft(ggml_backend_buffer_get_type(model_tensor->buffer));
268267
// validate tensor shape
269268
if (is_token_embd) {
270269
// expect B to be non-transposed, A and B are flipped; see llm_build_inp_embd()
@@ -281,8 +280,8 @@ static void llama_adapter_lora_init_impl(struct llama_model & model, const char
281280
}
282281

283282
// save tensor to adapter
284-
struct ggml_tensor * tensor_a = ggml_dup_tensor(dev_ctx, w.a);
285-
struct ggml_tensor * tensor_b = ggml_dup_tensor(dev_ctx, w.b);
283+
ggml_tensor * tensor_a = ggml_dup_tensor(dev_ctx, w.a);
284+
ggml_tensor * tensor_b = ggml_dup_tensor(dev_ctx, w.b);
286285
ggml_set_name(tensor_a, w.a->name);
287286
ggml_set_name(tensor_b, w.b->name);
288287
adapter.ab_map[name] = llama_adapter_lora_weight(tensor_a, tensor_b);
@@ -308,7 +307,7 @@ static void llama_adapter_lora_init_impl(struct llama_model & model, const char
308307
{
309308
llama_file gguf_file(path_lora, "rb");
310309
std::vector<uint8_t> read_buf;
311-
auto set_tensor = [&](struct ggml_tensor * orig, struct ggml_tensor * dev) {
310+
auto set_tensor = [&](ggml_tensor * orig, ggml_tensor * dev) {
312311
size_t offs = gguf_get_data_offset(ctx_gguf.get()) + gguf_get_tensor_offset(ctx_gguf.get(), gguf_find_tensor(ctx_gguf.get(), orig->name));
313312
size_t size = ggml_nbytes(orig);
314313
read_buf.resize(size);
@@ -327,8 +326,8 @@ static void llama_adapter_lora_init_impl(struct llama_model & model, const char
327326
LLAMA_LOG_INFO("%s: loaded %zu tensors from lora file\n", __func__, adapter.ab_map.size()*2);
328327
}
329328

330-
struct llama_adapter_lora * llama_adapter_lora_init(struct llama_model * model, const char * path_lora) {
331-
struct llama_adapter_lora * adapter = new llama_adapter_lora();
329+
llama_adapter_lora * llama_adapter_lora_init(llama_model * model, const char * path_lora) {
330+
llama_adapter_lora * adapter = new llama_adapter_lora();
332331

333332
try {
334333
llama_adapter_lora_init_impl(*model, path_lora, *adapter);
@@ -342,6 +341,6 @@ struct llama_adapter_lora * llama_adapter_lora_init(struct llama_model * model,
342341
return nullptr;
343342
}
344343

345-
void llama_adapter_lora_free(struct llama_adapter_lora * adapter) {
344+
void llama_adapter_lora_free(llama_adapter_lora * adapter) {
346345
delete adapter;
347346
}

src/llama-adapter.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
//
1616

1717
struct llama_adapter_cvec {
18-
struct ggml_tensor * tensor_for(int il) const;
18+
ggml_tensor * tensor_for(int il) const;
1919

20-
struct ggml_tensor * apply_to(struct ggml_context * ctx, struct ggml_tensor * cur, int il) const;
20+
ggml_tensor * apply_to(ggml_context * ctx, ggml_tensor * cur, int il) const;
2121

2222
bool apply(
2323
const llama_model & model,
@@ -36,16 +36,16 @@ struct llama_adapter_cvec {
3636
std::vector<ggml_context_ptr> ctxs;
3737
std::vector<ggml_backend_buffer_ptr> bufs;
3838

39-
std::vector<struct ggml_tensor *> tensors; // per layer
39+
std::vector<ggml_tensor *> tensors; // per layer
4040
};
4141

4242
//
4343
// llama_adapter_lora
4444
//
4545

4646
struct llama_adapter_lora_weight {
47-
struct ggml_tensor * a = nullptr;
48-
struct ggml_tensor * b = nullptr;
47+
ggml_tensor * a = nullptr;
48+
ggml_tensor * b = nullptr;
4949

5050
// get actual scale based on rank and alpha
5151
float get_scale(float alpha, float adapter_scale) const {
@@ -55,12 +55,12 @@ struct llama_adapter_lora_weight {
5555
}
5656

5757
llama_adapter_lora_weight() = default;
58-
llama_adapter_lora_weight(struct ggml_tensor * a, struct ggml_tensor * b) : a(a), b(b) {}
58+
llama_adapter_lora_weight(ggml_tensor * a, ggml_tensor * b) : a(a), b(b) {}
5959
};
6060

6161
struct llama_adapter_lora {
6262
// map tensor name to lora_a_b
63-
std::unordered_map<std::string, struct llama_adapter_lora_weight> ab_map;
63+
std::unordered_map<std::string, llama_adapter_lora_weight> ab_map;
6464

6565
std::vector<ggml_context_ptr> ctxs;
6666
std::vector<ggml_backend_buffer_ptr> bufs;
@@ -70,7 +70,7 @@ struct llama_adapter_lora {
7070
llama_adapter_lora() = default;
7171
~llama_adapter_lora() = default;
7272

73-
llama_adapter_lora_weight * get_weight(struct ggml_tensor * w);
73+
llama_adapter_lora_weight * get_weight(ggml_tensor * w);
7474
};
7575

76-
using llama_adapter_loras = std::unordered_map<struct llama_adapter_lora *, float>;
76+
using llama_adapter_loras = std::unordered_map<llama_adapter_lora *, float>;

0 commit comments

Comments
 (0)