Config

Config holds every optimization setting. Pass it to wrap() or optimize(). With no Config, MemScale uses Config() — balanced mode with sensible defaults.

from memscale import Config, OptimizationMode
 
config = Config(
    mode=OptimizationMode.BALANCED,
    enable_offloading=True,
    max_cpu_offload_gb=64,
)

OptimizationMode

An enum with three values — CONSERVATIVE, BALANCED, AGGRESSIVE. See Optimization Modes.

Fields

Core

FieldTypeDefaultDescription
modeOptimizationModeBALANCEDOptimization aggressiveness.
enable_checkpointingboolTrueApply gradient checkpointing.
enable_offloadingboolTrueApply CPU offloading.
enable_tilingboolFalseApply activation tiling (more experimental).
use_mixed_precisionboolFalseUse BF16/FP16 mixed precision.
use_8bit_optimizerboolFalseUse an 8-bit optimizer (requires bitsandbytes).

Memory budget

FieldTypeDefaultDescription
max_cpu_offload_gbfloat | NoneNoneCap on CPU RAM used for offloading. None = use available CPU RAM.
target_gpu_utilizationfloat0.85Fraction of GPU memory the engine aims to use.
force_optimizeboolFalseOptimize even when the model fits comfortably (bypasses the smart-skip).

Profiling

FieldTypeDefaultDescription
use_static_profilingboolTrueTry torch.fx static analysis first.
use_empirical_fallbackboolTrueFall back to runtime profiling if static fails.
warmup_stepsint2Warmup steps for empirical profiling.

Observability

FieldTypeDefaultDescription
enable_loggingboolTrueLog hardware detection and the optimization plan.
log_filestr | NoneNoneLog file path. None = stdout only.
observability_portint | NoneNoneIf set, expose Prometheus metrics on this port.
verify_correctnessboolFalseRun a baseline comparison to verify correctness (slow).

Experimental

FieldTypeDefaultDescription
async_offloadboolFalseEnable the tier-aware async CPU offload engine.
async_configAsyncOffloadConfigNonePower-user tuning for the async path.
auto_policyboolFalseOpt in to the v1.2 ML policy Stage 1.

auto_policy defaults to False — the v1.2 ML policy is off unless you opt in. With auto_policy=False, MemScale uses your Config exactly as given, which keeps explicit-config runs bit-for-bit reproducible.

Example: aggressive with an explicit budget

config = Config(
    mode=OptimizationMode.AGGRESSIVE,
    use_mixed_precision=True,
    use_8bit_optimizer=True,
    max_cpu_offload_gb=32,
)
model = wrap(model, config)