Size Aware LRU Cache For Resident LoRA Adapters

Last updated: November 29, 2026

Quick Overview

Design a cache that keeps LoRA adapters loaded in a fixed GPU memory budget, evicting least recently used adapters by size, but never evicting an adapter that still has in-flight requests. Implement acquire and release.

Fireworks AI
Coding & Algorithms
Machine Learning Engineer
Fireworks AI
November 29, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Design a cache that keeps LoRA adapters loaded in a fixed GPU memory budget, evicting least recently used adapters by size, but never evicting an adapter that still has in-flight requests. Implement acquire and release.

Fireworks serves many fine-tuned LoRAs on one base model and loads adapters dynamically, so adapter residency is a real serving concern. The interviewer is checking that the candidate combines LRU ordering with variable sizes and pinning without corrupting state on failure.

What the Interviewer Expects
  • Use an ordered map for O(1) recency updates
  • Evict multiple entries when a large adapter needs room
  • Never evict pinned adapters with active requests
  • Check feasibility before evicting so a failed load leaves the cache untouched
  • Track used memory exactly
Key Topics to Cover
LRU cache
Reference counting
Multi-LoRA serving
GPU memory
OrderedDict
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you avoid thrashing when the working set slightly exceeds the budget?
  • Adapter loads take tens of milliseconds. How do you deduplicate concurrent loads of the same adapter?
  • Would you prefer a frequency-aware policy for a few hot tenants and a long tail?
  • How does this cache interact with the batch scheduler choosing which requests to run next?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

acquire(name) makes an adapter resident and pins it for one request; release(name) drops one pin. Total resident size must stay within the budget. Eviction picks least recently used adapters first...

High-Level Design

OrderedDict from name to size gives LRU order (oldest first) with O(1) move_to_end. A separate dict holds refcounts. _make_room first sums evictable bytes to decide feasibility, then walks from ...


Submit Your Answer
Markdown supported

Related Questions