partial_offload.h

src/inference/partial_offload.h

@file partial_offload.h @brief How many layers of an oversized GGUF fit the free VRAM, purely.

Owners: @tvanfossen

gpu_offload_refused

bool entropic::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.

src/inference/partial_offload.h:258

Show on the map →

Called by SCENARIO, config_admits

Calls none

Source · 7 lines
inline bool gpu_offload_refused(uint64_t file_bytes, int gpu_layers,
                                uint64_t free_vram_bytes) {
    const bool exempt = gpu_layers == 0
        || free_vram_bytes == 0
        || file_bytes <= kLargeModelThresholdBytes;
    return !exempt && free_vram_bytes <= kPartialOffloadReserveBytes;
}
Activity · 2 steps
lines 260–262const bool exempt = gpu_layers == 0 || free_vram_bytes == 0 || file_bytes <= kLargeModelThresholdBytes;lines 263–263return !exempt && free_vram_bytes <= kPartialOffloadReserveBytes;

Requirements

REQ-INFER-019

host_can_hold_warm_load

bool entropic::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.

src/inference/partial_offload.h:136

Show on the map →

Called by SCENARIO

Calls warm_load_needed_bytes

Source · 6 lines
inline bool host_can_hold_warm_load(
    uint64_t file_bytes, uint64_t available_bytes,
    uint64_t headroom_bytes = 1024ull * 1024 * 1024) {
    return available_bytes == 0
        || available_bytes >= warm_load_needed_bytes(file_bytes, headroom_bytes);
}

Requirements

REQ-INFER-019

large_model_tests_waived

bool entropic::large_model_tests_waived(uint64_t file_bytes)

Whether an operator has explicitly waived one LARGE model's test.

src/inference/partial_offload.h:173

Show on the map →

Called by SCENARIO, init_orchestrator_for_v219_family, skip_if_waived, verify_family_common_chat

Calls none

Source · 5 lines
inline bool large_model_tests_waived(uint64_t file_bytes) {
    if (file_bytes <= kLargeModelThresholdBytes) { return false; }
    const char* v = std::getenv("ENTROPIC_SKIP_LARGE_MODEL_TESTS");
    return v != nullptr && v[0] == '1';
}
Activity · 4 steps
lines 174–174◇ if (file_bytes <= kLargeModelThresholdBytes)lines 174–174return false;lines 175–175const char* v = std::getenv("ENTROPIC_SKIP_LARGE_MODEL_TESTS");lines 176–176return v != nullptr && v[0] == '1';

Requirements

REQ-INFER-019

mlock_refused

bool entropic::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.

src/inference/partial_offload.h:208

Show on the map →

Called by SCENARIO, config_admits

Calls none

Source · 24 lines
inline bool mlock_refused(bool use_mlock, uint64_t file_bytes,
                          int gpu_layers, uint64_t memlock_limit_bytes,
                          uint64_t host_expert_bytes = 0) {
    // v2.13.1: `gpu_layers < 0` exempts because the host side is then
    // TRANSIENT — nothing stays in host RAM to be pinned. An expert split
    // breaks that premise: `cpu_moe_layers` deliberately leaves expert
    // weights host-RESIDENT while every layer reports as offloaded, so the
    // sentinel alone would exempt exactly the configuration the rule exists
    // to catch. Reachable since v2.13.1, when `gpu_layers: auto` began
    // deriving expert splits and emitting -1 alongside them.
    const bool host_side_is_transient =
        gpu_layers < 0 && host_expert_bytes == 0;
    const bool exempt = !use_mlock
        || host_side_is_transient
        || file_bytes <= kLargeModelThresholdBytes      // never refuse small
        || memlock_limit_bytes == kMemlockUnlimited;
    if (exempt) { return false; }
    // Under an expert split it is the HOST-resident expert bytes that get
    // pinned, not the whole file; pricing the file would refuse splits that
    // comfortably fit the limit.
    const uint64_t pinned =
        host_expert_bytes > 0 ? host_expert_bytes : file_bytes;
    return pinned > memlock_limit_bytes;
}
Activity · 1 steps
lines 224–224return false;

Requirements

REQ-INFER-019

partial_gpu_layers_for

int entropic::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.

src/inference/partial_offload.h:53

Show on the map →

Called by SCENARIO, SCENARIO, fall_back_to_weights_estimate

Calls none

Source · 14 lines
inline int partial_gpu_layers_for(uint64_t file_bytes,
                                  uint64_t free_vram_bytes,
                                  int n_layers = 30) {
    if (file_bytes == 0 || n_layers <= 0) { return 0; }
    if (free_vram_bytes <= kPartialOffloadReserveBytes) { return 0; }
    const uint64_t budget = free_vram_bytes - kPartialOffloadReserveBytes;
    // Per-layer cost approximated from the file: exact enough to choose a
    // split, and it needs no GGUF metadata this header refuses to read.
    const uint64_t per_layer =
        file_bytes / static_cast<uint64_t>(n_layers);
    if (per_layer == 0) { return n_layers; }
    const auto fits = static_cast<int>(budget / per_layer);
    return std::clamp(fits, 0, n_layers);
}
Activity · 1 steps
lines 63–63return n_layers;

Requirements

REQ-INFER-019