MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / test_roundtrip

Function test_roundtrip

subprojects/llama.cpp/tests/test-gguf.cpp:1084–1212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1082}
1083
1084static std::pair<int, int> test_roundtrip(ggml_backend_dev_t dev, const unsigned int seed, const bool only_meta) {
1085 ggml_backend_t backend = ggml_backend_dev_init(dev, nullptr);
1086 printf("%s: device=%s, backend=%s, only_meta=%s\n",
1087 __func__, ggml_backend_dev_description(dev), ggml_backend_name(backend), only_meta ? "yes" : "no");
1088
1089 int npass = 0;
1090 int ntest = 0;
1091
1092 struct gguf_context * gguf_ctx_0;
1093 struct ggml_context * ctx_0;
1094 ggml_backend_buffer_t bbuf;
1095 {
1096 struct random_gguf_context_result result = get_random_gguf_context(backend, seed);
1097 gguf_ctx_0 = result.gguf_ctx;
1098 ctx_0 = result.ctx;
1099 bbuf = result.buffer;
1100 }
1101
1102 FILE * file = tmpfile();
1103
1104#ifdef _WIN32
1105 if (!file) {
1106 printf("failed to create tmpfile(), needs elevated privileges on Windows");
1107 printf("skipping tests");
1108 return std::make_pair(0, 0);
1109 }
1110#else
1111 GGML_ASSERT(file);
1112#endif // _WIN32
1113
1114 {
1115 std::vector<int8_t> buf;
1116 gguf_write_to_buf(gguf_ctx_0, buf, only_meta);
1117 GGML_ASSERT(fwrite(buf.data(), 1, buf.size(), file) == buf.size());
1118 rewind(file);
1119 }
1120
1121 struct ggml_context * ctx_1 = nullptr;
1122 struct gguf_init_params gguf_params = {
1123 /*no_alloc =*/ false,
1124 /*ctx =*/ only_meta ? nullptr : &ctx_1,
1125 };
1126 struct gguf_context * gguf_ctx_1 = gguf_init_from_file_impl(file, gguf_params);
1127
1128 printf("%s: same_version: ", __func__);
1129 if (gguf_get_version(gguf_ctx_0) == gguf_get_version(gguf_ctx_1)) {
1130 printf("\033[1;32mOK\033[0m\n");
1131 npass++;
1132 } else {
1133 printf("\033[1;31mFAIL\033[0m\n");
1134 }
1135 ntest++;
1136
1137 printf("%s: same_n_kv: ", __func__);
1138 if (gguf_get_n_kv(gguf_ctx_0) == gguf_get_n_kv(gguf_ctx_1)) {
1139 printf("\033[1;32mOK\033[0m\n");
1140 npass++;
1141 } else {

Callers 1

mainFunction · 0.85

Calls 15

ggml_backend_dev_initFunction · 0.85
ggml_backend_nameFunction · 0.85
get_random_gguf_contextFunction · 0.85
gguf_write_to_bufFunction · 0.85
gguf_init_from_file_implFunction · 0.85
gguf_get_versionFunction · 0.85
gguf_get_n_kvFunction · 0.85
gguf_get_n_tensorsFunction · 0.85
all_kv_in_otherFunction · 0.85
all_tensors_in_otherFunction · 0.85
same_tensor_dataFunction · 0.85

Tested by

no test coverage detected