Skip to content

Commit 04a03e4

Browse files
committed
llama : mmap
ggml-ci
1 parent 8233c18 commit 04a03e4

File tree

11 files changed

+654
-597
lines changed

11 files changed

+654
-597
lines changed

examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,12 @@ static void print_matrix(struct ggml_tensor * probs) {
434434
}
435435
}
436436

437-
struct llama_file {
437+
struct my_llama_file {
438438
// use FILE * so we don't have to re-open the file to mmap
439439
FILE * fp;
440440
size_t size;
441441

442-
llama_file(const char * fname, const char * mode) {
442+
my_llama_file(const char * fname, const char * mode) {
443443
fp = std::fopen(fname, mode);
444444
if (fp == NULL) {
445445
size = 0;
@@ -500,15 +500,15 @@ struct llama_file {
500500
return std::string(chars.data(), len);
501501
}
502502

503-
~llama_file() {
503+
~my_llama_file() {
504504
if (fp) {
505505
std::fclose(fp);
506506
}
507507
}
508508
};
509509

510510
static bool is_ggml_file(const char * filename) {
511-
llama_file file(filename, "rb");
511+
my_llama_file file(filename, "rb");
512512
if (file.size < 4) {
513513
return false;
514514
}
@@ -576,7 +576,7 @@ static void load_vocab(const char * filename, const Config * config, struct my_l
576576
} else {
577577
// assume llama2.c vocabulary
578578
LOG_INF("%s: Assuming llama2.c vocabulary since %s is not a gguf file\n", __func__, filename);
579-
llama_file file(filename, "rb");
579+
my_llama_file file(filename, "rb");
580580
if (!file.fp) {
581581
die_fmt("%s: %s", strerror(errno), filename);
582582
}

src/llama-adapter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <vector>
99
#include <map>
10+
#include <algorithm>
1011

1112
//
1213
// llama_adapter_vec

src/llama-arch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <map>
4+
#include <string>
45

56
//
67
// gguf constants (sync with gguf.py)

src/llama-batch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "llama.h"
44

55
#include <vector>
6+
#include <cstring>
7+
#include <algorithm>
68

79
// very similar to llama_batch,
810
// but has more metadata about sequences

src/llama-context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ static bool llama_state_load_file_internal(struct llama_context * ctx, const cha
799799

800800
// restore the context state
801801
{
802-
const size_t n_state_size_cur = file.size - file.tell();
802+
const size_t n_state_size_cur = file.size() - file.tell();
803803

804804
llama_data_read_file data_ctx(&file);
805805
const size_t n_read = llama_state_set_data_internal(ctx, data_ctx);
@@ -936,7 +936,7 @@ static size_t llama_state_seq_load_file_internal(struct llama_context * ctx, con
936936

937937
// restore the context state
938938
{
939-
const size_t state_size = file.size - file.tell();
939+
const size_t state_size = file.size() - file.tell();
940940
llama_data_read_file data_ctx(&file);
941941
const size_t nread = llama_state_seq_set_data_internal(ctx, data_ctx, dest_seq_id);
942942
if (!nread) {

src/llama-impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ LLAMA_ATTRIBUTE_FORMAT(2, 3)
2424
void llama_log_internal (ggml_log_level level, const char * format, ...);
2525
void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data);
2626

27+
// TODO: rename to llama_format ?
2728
LLAMA_ATTRIBUTE_FORMAT(1, 2)
2829
std::string format(const char * fmt, ...);
2930

src/llama-kv-cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <set>
1010
#include <vector>
11+
#include <limits>
1112

1213
struct llama_kv_cell {
1314
llama_pos pos = -1;

0 commit comments

Comments
 (0)