Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
partial_offload.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
22#pragma once
23
24#include <algorithm>
25#include <cstdint>
26#include <cstdlib>
27
28namespace entropic {
29
34constexpr uint64_t kPartialOffloadReserveBytes = 2048ull * 1024 * 1024;
35
55 int n_layers = 30) {
56 if (file_bytes == 0 || n_layers <= 0) { return 0; }
59 // Per-layer cost approximated from the file: exact enough to choose a
60 // split, and it needs no GGUF metadata this header refuses to read.
61 const uint64_t per_layer =
62 file_bytes / static_cast<uint64_t>(n_layers);
63 if (per_layer == 0) { return n_layers; }
64 const auto fits = static_cast<int>(budget / per_layer);
65 return std::clamp(fits, 0, n_layers);
66}
67
113 uint64_t headroom_bytes = 1024ull * 1024 * 1024) {
114 if (available_bytes == 0) { return true; }
115 // WARM and ACTIVE residencies can overlap across the reload boundary.
116 const uint64_t peak = file_bytes + (file_bytes / 2);
118}
119
124constexpr uint64_t kLargeModelThresholdBytes = 10ull * 1024 * 1024 * 1024;
125
151 if (file_bytes <= kLargeModelThresholdBytes) { return false; }
152 const char* v = std::getenv("ENTROPIC_SKIP_LARGE_MODEL_TESTS");
153 return v != nullptr && v[0] == '1';
154}
155
158
185inline bool mlock_refused(bool use_mlock, uint64_t file_bytes,
186 int gpu_layers, uint64_t memlock_limit_bytes,
187 uint64_t host_expert_bytes = 0) {
188 // v2.13.1: `gpu_layers < 0` exempts because the host side is then
189 // TRANSIENT — nothing stays in host RAM to be pinned. An expert split
190 // breaks that premise: `cpu_moe_layers` deliberately leaves expert
191 // weights host-RESIDENT while every layer reports as offloaded, so the
192 // sentinel alone would exempt exactly the configuration the rule exists
193 // to catch. Reachable since v2.13.1, when `gpu_layers: auto` began
194 // deriving expert splits and emitting -1 alongside them.
195 const bool host_side_is_transient =
196 gpu_layers < 0 && host_expert_bytes == 0;
197 const bool exempt = !use_mlock
199 || file_bytes <= kLargeModelThresholdBytes // never refuse small
201 if (exempt) { return false; }
202 // Under an expert split it is the HOST-resident expert bytes that get
203 // pinned, not the whole file; pricing the file would refuse splits that
204 // comfortably fit the limit.
205 const uint64_t pinned =
206 host_expert_bytes > 0 ? host_expert_bytes : file_bytes;
208}
209
235inline bool gpu_offload_refused(uint64_t file_bytes, int gpu_layers,
237 const bool exempt = gpu_layers == 0
238 || free_vram_bytes == 0
241}
242
243} // namespace entropic
long budget
Max content bytes; <= 0 = unbounded.
Activate model on GPU (WARM → ACTIVE).
bool gpu_offload_refused(uint64_t file_bytes, int gpu_layers, uint64_t free_vram_bytes)
Whether a requested GPU offload provably cannot fit free VRAM.
@ optional
optional: every escape asks the host's path approver
int partial_gpu_layers_for(uint64_t file_bytes, uint64_t free_vram_bytes, int n_layers=30)
Layers to place on the GPU for an oversized model.
bool host_can_hold_warm_load(uint64_t file_bytes, uint64_t available_bytes, uint64_t headroom_bytes=1024ull *1024 *1024)
Whether the host can hold a model's WARM load.
constexpr uint64_t kMemlockUnlimited
Sentinel for an unlimited RLIMIT_MEMLOCK (gh#148).
constexpr uint64_t kLargeModelThresholdBytes
Size above which a model counts as "large" for the waiver below.
bool mlock_refused(bool use_mlock, uint64_t file_bytes, int gpu_layers, uint64_t memlock_limit_bytes, uint64_t host_expert_bytes=0)
Whether an explicit use_mlock would be fatal for this model.
constexpr uint64_t kPartialOffloadReserveBytes
VRAM held back for compute/graph buffers, which scale with ubatch and model internals rather than wit...
bool large_model_tests_waived(uint64_t file_bytes)
Whether an operator has explicitly waived one LARGE model's test.