MCPcopy Create free account
hub / github.com/Niko1221/Strata / load

Method load

engine/src/core/native_dense.cpp:353–680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

351}
352
353bool NativeDense::load(const std::vector<std::string>& shards, WeightTable& table, std::string& err,
354 bool include_ple_key, int64_t layer_lo, int64_t layer_hi) {
355 auto outside = [&](const std::string& name) { // a blk.<l>. tensor of another stage's layers
356 if (layer_hi < 0 || name.rfind("blk.", 0) != 0) return false;
357 const long l = std::strtol(name.c_str() + 4, nullptr, 10);
358 return l < layer_lo || l >= layer_hi;
359 };
360 auto layer_of = [&](const std::string& name) -> int64_t { // the layer of a blk.<l>. tensor, -1 otherwise
361 if (name.rfind("blk.", 0) != 0) return -1;
362 return std::strtoll(name.c_str() + 4, nullptr, 10);
363 };
364 if (scratch_ || !weights_.empty()) { err = "native dense: already loaded"; return false; }
365 if (shards.empty()) { err = "native dense: at least one GGUF shard is required"; return false; }
366 try {
367 std::vector<Pending> pending;
368 std::set<std::string> seen;
369 int max_in = 0;
370 uint64_t total = 0, hc_q8_bytes = 0, allocated = 0, hc_q8_skipped_bytes = 0, hc_q8_skipped = 0;
371 std::vector<uint64_t> per_layer;
372 uint64_t split_count = 0, split_tensors = 0;
373 std::set<uint64_t> split_numbers;
374 bool have_architecture = false;
375 for (const auto& path : shards) {
376 strata::GgufFile gguf(path);
377 const auto* count = gguf.get("split.count");
378 const auto* number = gguf.get("split.no");
379 const auto* tensors = gguf.get("split.tensors.count");
380 if (gguf.get("general.architecture") && (!number || number->u == 0)) {
381 // splitter may copy general.architecture into every shard (Huihui abliterated re-split)
382 // Validate that the file can be read before selecting the execution backend.
383 err = strata::check_architecture(gguf);
384 if (!err.empty()) return false;
385 have_architecture = true;
386 if (count && number && tensors && number->u == 0 && count->u > 1) {
387 split_count = count->u;
388 split_tensors = tensors->u;
389 }
390 } else if (!have_architecture || !split_count || !count || !number || !tensors ||
391 count->u != split_count || number->u == 0 || number->u >= split_count ||
392 tensors->u != split_tensors) {
393 err = "native dense: additional shard must match the architecture-validated first shard's split metadata";
394 return false;
395 }
396 if (number && !split_numbers.insert(number->u).second) {
397 err = "native dense: duplicate split shard number"; return false;
398 }
399 std::vector<uint64_t> offsets;
400 for (const auto& tensor : gguf.tensors()) offsets.push_back(tensor.offset);
401 std::sort(offsets.begin(), offsets.end());
402 if (std::adjacent_find(offsets.begin(), offsets.end()) != offsets.end()) {
403 err = "native dense: tensor payload offsets overlap"; return false;
404 }
405 // Validate every directory span, including tensors we do not upload:
406 // an ignored tensor must not overlap the native matrix that follows it.
407 const uint64_t payload = gguf.file_size() - gguf.data_start();
408 for (const auto& tensor : gguf.tensors()) {
409 int block_elements = 0, block_bytes = 0;
410 uint64_t elements = 1;

Callers

nothing calls this directly

Calls 15

check_architectureFunction · 0.85
sortFunction · 0.85
block_geometryFunction · 0.85
advise_willneedFunction · 0.85
bf16_as_q8_0Function · 0.85
alloc_bytesFunction · 0.85
moveFunction · 0.85
gguf_type_nameFunction · 0.85
hc_q8_inject_envFunction · 0.85
hc_q8_stage_localFunction · 0.85

Tested by

no test coverage detected