Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0d9682822 | ||
|
|
f7198bb06f |
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"title": "llama.cpp",
|
||||
"title": "llama.cpp inference",
|
||||
"description": "Run llama.cpp inference using serverless RunPod workers!",
|
||||
"type": "serverless",
|
||||
"category": "language",
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ However, this will cause every worker to download the model from the Hugging Fac
|
||||
A naive way to cache the model would be to store it on a network volume in RunPod and reference the model files this way:
|
||||
|
||||
```bash
|
||||
-m /runpod-volume/model.gguf --ctx-size 4096 # etc...
|
||||
-hf /runpod-volume/model.gguf --ctx-size 4096 # etc...
|
||||
```
|
||||
|
||||
Unfortunately, network volume performance is often not sufficient for loading large models, leading to long load times. RunPod introduced a [caching mechanism](https://docs.runpod.io/serverless/endpoints/model-caching) to solve this problem.
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ from utils import JobInput
|
||||
|
||||
client = OpenAI(
|
||||
base_url="http://localhost:3098/v1/",
|
||||
api_key="none",
|
||||
api_key="",
|
||||
)
|
||||
|
||||
|
||||
|
||||
+33
-28
@@ -1,64 +1,69 @@
|
||||
"""
|
||||
Finds the full LLM GGUF path from the Hugging Face cache.
|
||||
Finds the full GGUF path from the Hugging Face cache using huggingface_hub.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
CACHE_DIR = "/runpod-volume/huggingface-cache/hub"
|
||||
import os
|
||||
from huggingface_hub import snapshot_download, scan_cache_dir
|
||||
|
||||
|
||||
def find_model_path(model_name, gguf_in_repo="model.gguf"):
|
||||
def find_model_path(model_name: str, gguf_in_repo: str) -> str | None:
|
||||
"""
|
||||
Find the path to a cached model.
|
||||
Resolve the GGUF file path from the Hugging Face cache.
|
||||
|
||||
Args:
|
||||
model_name: The model name from Hugging Face
|
||||
model_name: Hugging Face repo id (e.g. TheBloke/Mistral-7B-GGUF)
|
||||
gguf_in_repo: Relative path to the GGUF file inside the repo
|
||||
|
||||
Returns:
|
||||
The full path to the cached model, or None if not found
|
||||
Full filesystem path to the GGUF file, or None if not found
|
||||
"""
|
||||
|
||||
cache_name = model_name.replace("/", "--").lower()
|
||||
snapshots_dir = os.path.join(
|
||||
CACHE_DIR, f"models--{cache_name}", "snapshots"
|
||||
# First try the official way: resolve snapshot path from cache
|
||||
try:
|
||||
snapshot_path = snapshot_download(
|
||||
repo_id=model_name,
|
||||
local_files_only=True
|
||||
)
|
||||
candidate = os.path.join(snapshot_path, gguf_in_repo)
|
||||
if os.path.isfile(candidate):
|
||||
return candidate
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if os.path.exists(snapshots_dir):
|
||||
snapshots = os.listdir(snapshots_dir)
|
||||
|
||||
if snapshots:
|
||||
return os.path.join(snapshots_dir, snapshots[0], gguf_in_repo)
|
||||
# Fallback: scan cache metadata explicitly (no downloads)
|
||||
cache = scan_cache_dir()
|
||||
for repo in cache.repos:
|
||||
if repo.repo_id == model_name:
|
||||
for revision in repo.revisions:
|
||||
candidate = os.path.join(revision.snapshot_path, gguf_in_repo)
|
||||
if os.path.isfile(candidate):
|
||||
return candidate
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main function to find and print the model path.
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Find the full GGUF path from the Hugging Face cache."
|
||||
)
|
||||
parser.add_argument(
|
||||
"model", type=str, help="The model name from Hugging Face"
|
||||
"model",
|
||||
type=str,
|
||||
help="Hugging Face model repo id (e.g. TheBloke/Mistral-7B-GGUF)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"path",
|
||||
type=str,
|
||||
help="The path to the GGUF file within the model repository",
|
||||
help="Relative path to the GGUF file inside the repo",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
model_path = find_model_path(args.model, args.path)
|
||||
|
||||
if model_path is None:
|
||||
print(
|
||||
f"Error: Cached model not found. Model='{args.model}', GGUF='{args.path}', Cache dir='{CACHE_DIR}'",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
raise SystemExit("GGUF file not found in Hugging Face cache")
|
||||
|
||||
print(model_path, end="")
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
runpod==1.9.1
|
||||
python-dotenv==1.2.2
|
||||
openai==2.41.1
|
||||
runpod
|
||||
python-dotenv
|
||||
openai
|
||||
huggingface_hub
|
||||
hf-transfer
|
||||
+1
-7
@@ -17,13 +17,7 @@ cleanup() {
|
||||
CACHED_LLAMA_ARGS=""
|
||||
|
||||
find_cached_path() {
|
||||
local model_path
|
||||
model_path=$(python ./find_cached.py "$LLAMA_CACHED_MODEL" "$LLAMA_CACHED_GGUF_PATH")
|
||||
if [ $? -ne 0 ] || [ -z "$model_path" ]; then
|
||||
echo "start.sh: Error: Could not resolve cached model path. Check that LLAMA_CACHED_MODEL and LLAMA_CACHED_GGUF_PATH are correct and the model is fully cached on the network volume."
|
||||
exit 1
|
||||
fi
|
||||
CACHED_LLAMA_ARGS="-m $model_path"
|
||||
CACHED_LLAMA_ARGS="-m $(python ./find_cached.py $LLAMA_CACHED_MODEL $LLAMA_CACHED_GGUF_PATH)"
|
||||
}
|
||||
|
||||
# check if $LLAMA_CACHED_MODEL is set and not empty
|
||||
|
||||
Reference in New Issue
Block a user