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

Method load_data_for

smallthinker/src/llama-model-loader.cpp:875–896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

873}
874
875void llama_model_loader::load_data_for(struct ggml_tensor * cur) const {
876 const auto & w = require_weight(ggml_get_name(cur));
877
878 if (use_mmap) {
879 const auto & mapping = mappings.at(w.idx);
880 if (cur->data == nullptr) {
881 cur->data = (uint8_t *)mapping->addr() + w.offs;
882 } else {
883 memcpy(cur->data, (uint8_t *)mapping->addr() + w.offs, ggml_nbytes(cur));
884 }
885 } else {
886 GGML_ASSERT(cur->data != nullptr);
887 GGML_ASSERT(w.idx < files.size());
888 const auto & file = files.at(w.idx);
889 file->seek(w.offs, SEEK_SET);
890 file->read_raw(cur->data, ggml_nbytes(cur));
891 }
892
893 if (check_tensors && !ggml_validate_row_data(cur->type, cur->data, ggml_nbytes(cur))) {
894 throw std::runtime_error(format("tensor '%s' has invalid data", ggml_get_name(cur)));
895 }
896}
897
898bool llama_model_loader::load_all_data(
899 struct ggml_context * ctx,

Callers 1

Calls 8

ggml_validate_row_dataFunction · 0.85
addrMethod · 0.80
formatFunction · 0.70
ggml_get_nameFunction · 0.50
ggml_nbytesFunction · 0.50
sizeMethod · 0.45
seekMethod · 0.45
read_rawMethod · 0.45

Tested by

no test coverage detected