Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common : fix duplicated file name with hf_repo and hf_file #10550

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

ngxson
Copy link
Collaborator

@ngxson ngxson commented Nov 27, 2024

Currently, when using hf_repo and hf_file, the local file path is automatically set to {cache_dir}/{file_name}

This fails in 2 cases:

  • Same file name exists in different hf_repo
  • Same file name exists in the same hf_repo, but in different subdirs

For example:

Same file name, same repo, different subdir:

hf_repo hf_file
ggml-org/models bert-bge-small/ggml-model-f16.gguf
ggml-org/models jina-reranker-v1-tiny-en/ggml-model-f16.gguf

Same file name (Llama-3.2-1B-Instruct-Q4_K_M.gguf), different repo:


@ngxson ngxson requested a review from ggerganov November 27, 2024 18:34
@github-actions github-actions bot added examples python python script changes server labels Nov 27, 2024
@ngxson ngxson merged commit 9f91251 into ggerganov:master Nov 27, 2024
52 checks passed
Copy link

@Blondy4life2005 Blondy4life2005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting

@ochafik
Copy link
Collaborator

ochafik commented Dec 6, 2024

Quick script in case anyone else has a large cache directory to migrate to the new naming / doesn't want to redownload:

import json
from pathlib import Path
import platform
import os
import re

cache_dir = os.environ.get('LLAMA_CACHE')
if not cache_dir:
  if platform.system() == 'Darwin':
    cache_dir = os.environ['HOME'] + '/Library/Caches/llama.cpp'
  elif platform.system() == 'Windows':
    cache_dir = os.environ['LOCALAPPDATA'] + '/llama.cpp'
  else:
    cache_dir = os.environ['HOME'] + '/.cache/llama.cpp'
cache_dir = Path(cache_dir)

for json_file in cache_dir.glob('*.gguf.json'):
  data = json.loads(json_file.read_text())
  gguf_file = Path(json_file.as_posix().rstrip('.json'))
  if not gguf_file.exists():
    print(f'WARNING: {gguf_file} file does not exist. Deleting {json_file}')
    json_file.unlink()
    continue
  
  url = data['url']
  filename = os.path.basename(url)
  
  if (match := re.match(r'^https://huggingface.co/([^/]+)/([^/]+)/resolve/main/.*', url)):
    org = match.group(1)
    model = match.group(2)
    if gguf_file.name == filename:
      new_gguf_file = gguf_file.parent / f'{org}_{model}_{filename}'
      print(f'Renaming {gguf_file} to {new_gguf_file}')
      gguf_file.rename(new_gguf_file)
      json_file.rename(new_gguf_file.with_suffix('.json'))

arthw pushed a commit to arthw/llama.cpp that referenced this pull request Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples python python script changes server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants