Linux: read ahead of the head, embedding and vision encoder loads; time them
The native output head (437 MB) and the token embedding (260 MiB) were copied out of the mapped GGUF one page fault at a time, and strata-vision's projector (907 MB) went through llama.cpp's sequential reads, all before the server was ready. Each now asks for its bytes ahead (the vision encoder honours STRATA_READ_AHEAD=0 too), and the head, the embedding, the projector load, the encoder warm-up and the pinned cache complement log their times.
This commit is contained in:
1 parent
cb33c0bac5
commit
760c775434
4 files changed
+37
-6
No files matched your search
@@ -1380,6 +1380,7 @@ bool FileExpertSource::pin_cache_complement(
|
||||
const std::vector<std::pair<int32_t, int32_t>>& additional_gpu_pairs, int64_t lend_from_slot,
|
||||
uint64_t headroom_bytes, uint64_t budget_bytes, const std::vector<std::pair<int32_t, int32_t>>* rank) {
|
||||
err.clear();
|
||||
const auto pin_t0 = std::chrono::steady_clock::now();
|
||||
if (base_ == nullptr) { err = "FileExpertSource: open the mapped experts before pinning a complement"; return false; }
|
||||
if (complement_ready_) { err = "FileExpertSource: the cache complement is already pinned"; return false; }
|
||||
if (!cache.valid()) { err = "FileExpertSource: the GPU expert cache is not open"; return false; }
|
||||
@@ -1780,9 +1781,10 @@ bool FileExpertSource::pin_cache_complement(
|
||||
complement_lock_off_ = lock_off;
|
||||
complement_lent_slots_ = lend ? n_slots - keep_from : 0;
|
||||
complement_ready_ = true;
|
||||
std::fprintf(stderr, "FileExpertSource: %s cache complement ready: resident %.2f GiB, pinned %.2f GiB%s%s\n",
|
||||
std::fprintf(stderr, "FileExpertSource: %s cache complement ready: resident %.2f GiB, pinned %.2f GiB in %.0f s%s%s\n",
|
||||
complement_pinned_ ? "mapped pinned" : pin ? "locked resident" : "pageable resident",
|
||||
(double) resident_bytes() / 1073741824.0, (double) pinned_bytes() / 1073741824.0,
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - pin_t0).count(),
|
||||
note.empty() ? "" : "; ", note.c_str());
|
||||
if (lend)
|
||||
std::fprintf(stderr, "FileExpertSource: %lld of the prompt path's %lld lendable slots keep their experts in RAM "
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "strata/artifact/gguf_reader.hpp"
|
||||
#include "strata/kernels/iq_kernels.hpp"
|
||||
#include "strata/kernels/native_mmvq.hpp"
|
||||
#include "strata/platform/memory.hpp"
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <climits>
|
||||
@@ -47,6 +48,7 @@ bool NativeHead::load(const std::vector<std::string>& shards, int64_t n_in, int6
|
||||
cudaError_t status = cudaMalloc(&weights, bytes);
|
||||
if (status == cudaSuccess)
|
||||
status = cudaMalloc(&scratch, strata::kernels::native_q8_1_bytes((int) n_in, 1));
|
||||
strata::platform::advise_willneed(gguf.tensor_data(*tensor), bytes);
|
||||
if (status == cudaSuccess)
|
||||
status = cudaMemcpy(weights, gguf.tensor_data(*tensor), bytes, cudaMemcpyHostToDevice);
|
||||
if (status != cudaSuccess) {
|
||||
@@ -130,6 +132,7 @@ bool NativeEmbed::load(const std::vector<std::string>& shards, int64_t n_embd, i
|
||||
bytes_ = 0;
|
||||
return false;
|
||||
}
|
||||
strata::platform::advise_willneed(gguf.tensor_data(*t), bytes_); // copied out of the mapping below
|
||||
if (cudaHostAlloc(&host_, bytes_, cudaHostAllocMapped | cudaHostAllocPortable) != cudaSuccess) {
|
||||
// Under WSL2 the driver's pinned/mapped host budget (~1 GiB) can be spent by the GPU contexts
|
||||
// themselves (three cards). The table is only gathered from, so keep it in the current device's VRAM
|
||||
|
||||
@@ -2326,6 +2326,7 @@ int main(int argc, char** argv) {
|
||||
return 2;
|
||||
}
|
||||
const strata::core::ModelGeometry g0;
|
||||
const auto embed_t0 = std::chrono::steady_clock::now();
|
||||
if (!native_embed.load(o.embd_gguf.empty() ? o.native_shards : std::vector<std::string>{o.embd_gguf}, g0.n_embd,
|
||||
248320, err)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
@@ -2333,9 +2334,10 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
strata::core::set_native_embed(&native_embed);
|
||||
std::fprintf(stderr, "strata generate: native pack: %s experts (largest blob %.2f MB), token embedding "
|
||||
"%s in mapped host memory (%.0f MiB)\n",
|
||||
"%s in mapped host memory (%.0f MiB, %.1f s)\n",
|
||||
o.pack.c_str(), (double) strata::kernels::cpu::expert_layout().max_blob / 1e6,
|
||||
strata::ggml_type_name((uint32_t) native_embed.type()), (double) native_embed.bytes() / 1048576.0);
|
||||
strata::ggml_type_name((uint32_t) native_embed.type()), (double) native_embed.bytes() / 1048576.0,
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - embed_t0).count());
|
||||
}
|
||||
// Plan v0.3 P1: tensors served in native form are not also loaded in canonical form (~2.7 GB of VRAM back
|
||||
// to the expert cache with --native). `--keep-canonical` loads both, as before.
|
||||
@@ -3306,12 +3308,14 @@ int main(int argc, char** argv) {
|
||||
const int64_t n_vocab = wo->ne1;
|
||||
strata::core::NativeHead native_head;
|
||||
if (!o.native_head_gguf.empty() && !multi_gpu) { // a layer split's head is on its last stage
|
||||
const auto head_t0 = std::chrono::steady_clock::now();
|
||||
if (!native_head.load(o.native_head_shards, g.n_embd, n_vocab, err)) {
|
||||
std::fprintf(stderr, "strata generate: %s%s\n", err.c_str(), vram_free_note().c_str());
|
||||
return 1;
|
||||
}
|
||||
std::fprintf(stderr, "strata generate: experimental native Q5_K head, %llu bytes\n",
|
||||
(unsigned long long) native_head.weight_bytes());
|
||||
std::fprintf(stderr, "strata generate: experimental native Q5_K head, %llu bytes, in %.1f s\n",
|
||||
(unsigned long long) native_head.weight_bytes(),
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - head_t0).count());
|
||||
}
|
||||
std::vector<float> logits((size_t) n_vocab);
|
||||
float* d_logits = nullptr;
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
#include "mtmd-helper.h"
|
||||
|
||||
#include <algorithm>
|
||||
#if !defined(_WIN32)
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -90,6 +94,20 @@ int main(int argc, char** argv) {
|
||||
mtmd_helper_log_set(quiet_log, nullptr);
|
||||
llama_backend_init();
|
||||
|
||||
const auto load_t0 = std::chrono::steady_clock::now();
|
||||
#if !defined(_WIN32)
|
||||
// ask the OS for the projector file up front (128 KiB steps) so the loader's sequential reads find it cached;
|
||||
// STRATA_READ_AHEAD=0 turns it off, as in the engine
|
||||
if (const char* ra = std::getenv("STRATA_READ_AHEAD"); ra == nullptr || std::atoi(ra) != 0) {
|
||||
const int fd = open(mmproj.c_str(), O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
const off_t n = lseek(fd, 0, SEEK_END);
|
||||
for (off_t at = 0; at < n; at += (off_t) (128 << 10))
|
||||
(void) posix_fadvise(fd, at, std::min<off_t>((off_t) (128 << 10), n - at), POSIX_FADV_WILLNEED);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
llama_model_params mp = llama_model_default_params();
|
||||
mp.vocab_only = true;
|
||||
llama_model* text = llama_model_load_from_file(model.c_str(), mp);
|
||||
@@ -111,6 +129,8 @@ int main(int argc, char** argv) {
|
||||
std::fflush(stdout);
|
||||
return 1;
|
||||
}
|
||||
std::fprintf(stderr, "strata-vision: model files loaded in %.1f s\n",
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - load_t0).count());
|
||||
// a vocab-only model reports no hparams, so the width comes from the projector: its output is the model's input
|
||||
int n_embd = 0;
|
||||
{
|
||||
@@ -129,6 +149,7 @@ int main(int argc, char** argv) {
|
||||
// (~6 s at 1,024 tokens).
|
||||
if (!gpu) std::fprintf(stderr, "strata-vision: on the CPU, %d threads, no warm-up\n", threads);
|
||||
else {
|
||||
const auto warm_t0 = std::chrono::steady_clock::now();
|
||||
const uint32_t side = 2048;
|
||||
std::vector<unsigned char> rgb((size_t) side * side * 3, 128);
|
||||
mtmd_bitmap* bm = mtmd_bitmap_init(side, side, rgb.data());
|
||||
@@ -144,7 +165,8 @@ int main(int argc, char** argv) {
|
||||
warm_tokens = (int) mtmd_input_chunk_get_n_tokens(ch);
|
||||
}
|
||||
}
|
||||
std::fprintf(stderr, "strata-vision: warmed up at %d image tokens\n", warm_tokens);
|
||||
std::fprintf(stderr, "strata-vision: warmed up at %d image tokens in %.1f s\n", warm_tokens,
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - warm_t0).count());
|
||||
mtmd_input_chunks_free(chunks);
|
||||
if (bm) mtmd_bitmap_free(bm);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user