MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / handcrafted_check_tensor_data

Function handcrafted_check_tensor_data

smallthinker/tests/test-gguf.cpp:623–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

621}
622
623static bool handcrafted_check_tensor_data(const gguf_context * gguf_ctx, const unsigned int seed, FILE * file) {
624 if (!gguf_ctx) {
625 return false;
626 }
627
628 std::mt19937 rng(seed);
629
630 std::vector<tensor_config_t> tensor_configs = get_tensor_configs(rng);
631
632 bool ok = true;
633
634 for (int i = 0; i < int(tensor_configs.size()); ++i) {
635 const ggml_type type = tensor_configs[i].first;
636 const std::array<int64_t, GGML_MAX_DIMS> shape = tensor_configs[i].second;
637
638 int64_t ne = shape[0];
639 for (size_t j = 1; j < GGML_MAX_DIMS; ++j) {
640 ne *= shape[j];
641 }
642 const size_t size = ggml_row_size(type, ne);
643
644 const std::string name = "my_tensor_" + std::to_string(i);
645 const size_t offset = gguf_get_tensor_offset(gguf_ctx, gguf_find_tensor(gguf_ctx, name.c_str()));
646
647 std::vector<uint8_t> data(size);
648 GGML_ASSERT(fseek(file, gguf_get_data_offset(gguf_ctx) + offset, SEEK_SET) == 0);
649 GGML_ASSERT(fread(data.data(), 1, data.size(), file) == data.size());
650
651 for (size_t j = 0; j < size; ++j) {
652 const uint8_t expected_byte = (j + offset) % 256;
653 if (data[j] != expected_byte) {
654 ok = false;
655 }
656 }
657 }
658
659 return ok;
660}
661
662static std::pair<int, int> test_handcrafted_file(const unsigned int seed) {
663 int npass = 0;

Callers 1

test_handcrafted_fileFunction · 0.85

Calls 9

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

Tested by

no test coverage detected