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

Method load

engine/src/core/mtp.cpp:346–689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344}
345
346bool MtpDrafter::load(const std::string& rt_dir, const ModelGeometry& g, SessionState& ss, int max_t, std::string& err,
347 int64_t window, const MtpDrafter* shared) {
348#if defined(STRATA_GPU_METAL)
349 (void) window; (void) shared;
350 g_ = &g;
351 ss_ = &ss;
352 max_t_ = max_t;
353 if (!strata::metal_engine::mtp_load(rt_dir, max_t, err)) return false;
354 strata::metal_engine::mtp_bind_state(st_); // the parked conversation's draft K/V is the window's own buffers
355 return true;
356#endif
357 cudaGetDevice(&device_); // a layer split's last stage on another GPU: the drafter lives there
358 g_ = &g;
359 ss_ = &ss;
360 if (ple_ss_ == nullptr) ple_ss_ = &ss;
361 max_t_ = max_t;
362 rt_dir_ = rt_dir;
363 // (the draft layer's kernels - the resident grouping, the grouped experts, the fused reads - are built for the narrow window)
364 if (max_t < 1 || max_t > strata::kernels::kVerifyNarrowT) { err = "mtp: max_t out of range"; return false; }
365 if (shared != nullptr) {
366 if (shared->device_ != device_ || shared->g_ != &g || shared->dense_ == nullptr ||
367 shared->experts_ == nullptr || shared->rt_dir_ != rt_dir) {
368 err = "mtp: incompatible shared weights";
369 return false;
370 }
371 dense_ = shared->dense_;
372 experts_ = shared->experts_;
373 native_experts_ = shared->native_experts_;
374 expert_layout_ = shared->expert_layout_;
375 expert_blob_bytes_ = shared->expert_blob_bytes_;
376 tensors_ = shared->tensors_;
377 owns_weights_ = false;
378 owns_draft_head_ = false;
379 }
380 // Loader fix (0.1.15+loaderfix.2): the two reads below are the whole “drafter files” cost; reporting
381 // them apart from the rest of the stage is what makes the next regression visible.
382 const auto t_files = std::chrono::steady_clock::now();
383 // ---- the index and the dense weights
384 if (shared == nullptr) {
385 std::ifstream idx(rt_dir + "/dense.txt");
386 if (!idx) { err = "mtp: cannot open " + rt_dir + "/dense.txt (run tools/mtp_rt.py)"; return false; }
387 std::string line;
388 while (std::getline(idx, line)) {
389 if (line.empty()) continue;
390 std::istringstream is(line);
391 Tensor t;
392 is >> t.name >> t.kind >> t.rows >> t.cols >> t.off >> t.bytes;
393 if (!is) { err = "mtp: malformed dense.txt line: " + line; return false; }
394 tensors_.push_back(t);
395 }
396 std::vector<uint8_t> blob;
397 if (!read_file(rt_dir + "/dense.bin", blob)) { err = "mtp: cannot read dense.bin"; return false; }
398 const cudaError_t alloc = cudaMalloc((void**) &dense_, blob.size());
399 if (alloc != cudaSuccess) {
400 size_t free_bytes = 0, total_bytes = 0;
401 const cudaError_t info = cudaMemGetInfo(&free_bytes, &total_bytes);
402 err = "mtp: dense weights allocation failed (" + std::string(cudaGetErrorString(alloc)) +
403 "), requested " + std::to_string(blob.size() >> 20) + " MiB, CUDA0 free " +

Callers 15

mainFunction · 0.45
adaptMethod · 0.45
mainFunction · 0.45
runMethod · 0.45
mainFunction · 0.45
raceFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
ckpt_test_pointFunction · 0.45
mainFunction · 0.45
g_megakernelFunction · 0.45
diag_active_verifierFunction · 0.45

Calls 15

mtp_loadFunction · 0.85
mtp_bind_stateFunction · 0.85
advise_willneedFunction · 0.85
mtp_q8_sm60Function · 0.85
gr_workspace_bytesFunction · 0.85
gfx_arch_is_gfx12Function · 0.85
push_backMethod · 0.80

Tested by 13

mainFunction · 0.36
mainFunction · 0.36
raceFunction · 0.36
mainFunction · 0.36
mainFunction · 0.36
mainFunction · 0.36
mainFunction · 0.36
restrictionFunction · 0.36
format_round_tripFunction · 0.36
selftestFunction · 0.36
clientFunction · 0.36
run_configFunction · 0.36