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

Function same_tensor_data

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

Source from the content-addressed store, hash-verified

1044}
1045
1046static bool same_tensor_data(const struct ggml_context * orig, const struct ggml_context * read) {
1047 bool ok = true;
1048
1049 struct ggml_tensor * t_orig = ggml_get_first_tensor(orig);
1050 struct ggml_tensor * t_read = ggml_get_first_tensor(read);
1051
1052 if (std::string(t_read->name) != "GGUF tensor data binary blob") {
1053 return false;
1054 }
1055 t_read = ggml_get_next_tensor(read, t_read);
1056
1057 while (t_orig) {
1058 if (!t_read) {
1059 ok = false;
1060 break;
1061 }
1062
1063 const size_t nbytes = ggml_nbytes(t_orig);
1064 if (ggml_nbytes(t_read) != nbytes) {
1065 ok = false;
1066 break;
1067 }
1068 std::vector<char> data_orig(nbytes);
1069 ggml_backend_tensor_get(t_orig, data_orig.data(), 0, nbytes);
1070 if (!std::equal(data_orig.data(), data_orig.data() + nbytes, reinterpret_cast<const char *>(t_read->data))) {
1071 ok = false;
1072 }
1073
1074 t_orig = ggml_get_next_tensor(orig, t_orig);
1075 t_read = ggml_get_next_tensor(read, t_read);
1076 }
1077 if (t_read) {
1078 ok = false;
1079 }
1080
1081 return ok;
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);

Callers 1

test_roundtripFunction · 0.85

Calls 6

ggml_get_first_tensorFunction · 0.85
stringClass · 0.85
ggml_get_next_tensorFunction · 0.85
ggml_nbytesFunction · 0.85
ggml_backend_tensor_getFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected