feat(optimization): layer-by-layer inference mode for batch/offline processing #1946
Description
Activity
- addedenhancementNew feature or requestNew feature or request
on Mar 19, 2026 Additional Techniques from Deeper airllm Analysis
1. Model Sharding with Crash-Safe Done Markers
The split-and-save pipeline should use
.safetensors.donemarker files for crash safety — if splitting is interrupted, only incomplete layers are reprocessed on retry. Also includes disk space pre-checking viacheck_space()before splitting begins.2. Buffers-Only GPU Initialization
When creating the empty-weight model scaffold, only model buffers (non-trainable tensors like LayerNorm stats, attention masks — a few KB total) should be moved to GPU. All weight parameters stay on meta device until loaded per-layer.
for buffer_name, buffer in model.named_buffers(): set_module_tensor_to_device(model, buffer_name, 'cuda', value=buffer, dtype=running_dtype)
Missing this distinction causes either errors (if buffers aren't on GPU) or wasted memory (if all params are on GPU).
3. Lazy Shard Downloading
Download individual model shards from HuggingFace on-demand during splitting rather than all at once. Combined with
delete_original=True, peak disk usage = (1 shard + all split layers so far) instead of (entire model + all split layers).4. Aggressive Model Reboot (Optional)
airllm deletes and recreates the empty model scaffold at the start of every forward pass (
del self.model; clean_memory(); self.init_model()) to guarantee no stale weights in GPU memory. AutoBot could adopt a softer version: rebuild every N inference calls as a memory leak safety net.These should all be incorporated into the layer-by-layer inference implementation.
- added and removedenhancementNew feature or requestNew feature or request
on Mar 27, 2026 Merged in PR #3089. Layer-by-layer inference for batch processing on memory-constrained GPUs.
- added a commit that references this issue
on Jul 30, 2026
Summary
Add a "memory-constrained" inference mode that uses airllm's layer-by-layer technique to run models exceeding available VRAM, targeting non-interactive batch workloads like knowledge base processing and research workflows.
Background
airllm enables running 70B–405B parameter models on as little as 4GB VRAM by loading one transformer layer at a time from disk, processing it, then evicting it. The tradeoff is speed — inference takes 30–120 seconds per response for 70B models.
This is not suitable for interactive chat but is viable for:
Currently AutoBot's largest local model is 13B. Layer-by-layer inference would allow running 70B+ models on the RTX 4070 (8GB VRAM) for tasks where the quality improvement justifies the latency cost.
Implementation
Approach A: Integrate airllm as a Provider
Approach B: Implement the Pattern Natively
Implement the core technique (model splitting + sequential layer loading) in the NPU inference server as an alternative backend mode, without depending on airllm directly.
Prerequisites
Key Files
autobot-backend/llm_interface_pkg/providers/— new provider or modeautobot-infrastructure/shared/scripts/ai-ml/optimize_llm_models.py— model splitting stepautobot-backend/llm_interface_pkg/optimization/router.py— routing to memory-constrained modeAcceptance Criteria
Effort
High effort, medium impact (enables new capabilities but limited to batch use cases).