MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / handcrafted_check_tensor_data

Function handcrafted_check_tensor_data

tests/test-gguf.cpp:646–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

644}
645
646static bool handcrafted_check_tensor_data(const gguf_context * gguf_ctx, const unsigned int seed, FILE * file) {
647 if (!gguf_ctx) {
648 return false;
649 }
650
651 std::mt19937 rng(seed);
652
653 std::vector<tensor_config_t> tensor_configs = get_tensor_configs(rng);
654
655 bool ok = true;
656
657 for (int i = 0; i < int(tensor_configs.size()); ++i) {
658 const ggml_type type = tensor_configs[i].first;
659 const std::array<int64_t, GGML_MAX_DIMS> shape = tensor_configs[i].second;
660
661 int64_t ne = shape[0];
662 for (size_t j = 1; j < GGML_MAX_DIMS; ++j) {
663 ne *= shape[j];
664 }
665 const size_t size = ggml_row_size(type, ne);
666
667 const std::string name = "my_tensor_" + std::to_string(i);
668 const size_t offset = gguf_get_tensor_offset(gguf_ctx, gguf_find_tensor(gguf_ctx, name.c_str()));
669
670 std::vector<uint8_t> data(size);
671 GGML_ASSERT(fseek(file, gguf_get_data_offset(gguf_ctx) + offset, SEEK_SET) == 0);
672 GGML_ASSERT(fread(data.data(), 1, data.size(), file) == data.size());
673
674 for (size_t j = 0; j < size; ++j) {
675 const uint8_t expected_byte = (j + offset) % 256;
676 if (data[j] != expected_byte) {
677 ok = false;
678 }
679 }
680 }
681
682 return ok;
683}
684
685static std::pair<int, int> test_handcrafted_file(const unsigned int seed) {
686 int npass = 0;

Callers 1

test_handcrafted_fileFunction · 0.85

Calls 8

get_tensor_configsFunction · 0.85
ggml_row_sizeFunction · 0.85
gguf_get_tensor_offsetFunction · 0.85
gguf_find_tensorFunction · 0.85
gguf_get_data_offsetFunction · 0.85
to_stringFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected