Implementation of LlamaDiskCache lacks capacity setting.

Open Beginner friendly
#1,402 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
80/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

The issue is in the LlamaDiskCache class in the llama-cpp-python codebase. Look for the file containing this class, likely in a cache module. The fix is to pass the capacity_bytes parameter as size_limit to diskcache.Cache. After making the change, run any existing tests related to caching to ensure the capacity setting works correctly.

Written by the indexing model from the issue text.

Description

LlamaDiskCache utilizes diskcache module to hold cache.
While LlamaDiskCache.__init__ can have capacity setting, it's not passed to diskcache.Cache.__init__, which is causing capacity mismatch, and it fails to store data of size greater than 1GB (default capacity of diskcache).

Current implementation:

class LlamaDiskCache(BaseLlamaCache):
    """Cache for a llama.cpp model using disk."""

    def __init__(
        self, cache_dir: str = ".cache/llama_cache", capacity_bytes: int = (2 << 30)
    ):
        super().__init__(capacity_bytes)
        self.cache = diskcache.Cache(cache_dir)

This I guess is required:

class LlamaDiskCache(BaseLlamaCache):
    """Cache for a llama.cpp model using disk."""

    def __init__(
        self, cache_dir: str = ".cache/llama_cache", capacity_bytes: int = (2 << 30)
    ):
        super().__init__(capacity_bytes)
        self.cache = diskcache.Cache(cache_dir, size_limit=capacity_bytes) # Added size_limit configuration.
Dominant language
Python
Stars
10.6k
Forks
1.5k
Avg merge
23m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from abetlen/llama-cpp-python

All issues in abetlen/llama-cpp-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.