| 35 | } // namespace |
| 36 | |
| 37 | bool ExpertStream::wanted(const gguf::File& f, const mtl::Context& cx) { |
| 38 | const char* e = std::getenv("STRATA_METAL_STREAM"); |
| 39 | if (e && std::string(e) == "1") return true; |
| 40 | if (e && std::string(e) == "0") return false; |
| 41 | // auto: stream when the mapped weights (experts and dense) and ~12 GiB beside them (the prompt buffers, KV, the |
| 42 | // draft layer, macOS) do not fit the resident footprint cap: the GPU working set, or on a big Mac the RAM less the |
| 43 | // 30% macOS and its file cache keep (arena_budget.h: footprint_cap). |
| 44 | uint64_t all = 0; |
| 45 | for (const auto& kv : f.tensors) |
| 46 | if (kv.first != "per_layer_token_embd.weight") all += kv.second.bytes; |
| 47 | uint64_t phys = 0; |
| 48 | size_t len = sizeof phys; |
| 49 | sysctlbyname("hw.memsize", &phys, &len, nullptr, 0); |
| 50 | return !resident_fits((double) phys, (double) cx.recommended_working_set(), (double) all, 12.0 * (1ull << 30)); |
| 51 | } |
| 52 | |
| 53 | ExpertStream::~ExpertStream() { |
| 54 | { |