← back to Exo
fix weight_map resolution. previously we were always defaulting to allow pattern *.safetensors
8f65e1e6979259a1f7b0a177befd2cc194d04756 · 2024-09-05 15:50:18 +0100 · Alex Cheema
Files touched
A exo/download/__init__.pyA exo/download/hf/__init__.pyM exo/download/hf/hf_helpers.py
Diff
commit 8f65e1e6979259a1f7b0a177befd2cc194d04756
Author: Alex Cheema <alexcheema123@gmail.com>
Date: Thu Sep 5 15:50:18 2024 +0100
fix weight_map resolution. previously we were always defaulting to allow pattern *.safetensors
---
exo/download/__init__.py | 0
exo/download/hf/__init__.py | 0
exo/download/hf/hf_helpers.py | 56 ++++++++++++++++++++++++++-----------------
3 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/exo/download/__init__.py b/exo/download/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/exo/download/hf/__init__.py b/exo/download/hf/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/exo/download/hf/hf_helpers.py b/exo/download/hf/hf_helpers.py
index 14bed136..d4251388 100644
--- a/exo/download/hf/hf_helpers.py
+++ b/exo/download/hf/hf_helpers.py
@@ -200,6 +200,36 @@ async def download_file(
if DEBUG >= 2: print(f"Downloaded: {file_path}")
+async def resolve_revision_to_commit_hash(repo_id: str, revision: str) -> str:
+ repo_root = get_repo_root(repo_id)
+ refs_dir = repo_root/"refs"
+ refs_file = refs_dir/revision
+
+ # Check if we have a cached commit hash
+ if await aios.path.exists(refs_file):
+ async with aiofiles.open(refs_file, 'r') as f:
+ commit_hash = (await f.read()).strip()
+ if DEBUG >= 2: print(f"Commit hash is already cached at {refs_file}: {commit_hash}")
+ return commit_hash
+
+ # Fetch the commit hash for the given revision
+ async with aiohttp.ClientSession() as session:
+ api_url = f"https://huggingface.co/api/models/{repo_id}/revision/{revision}"
+ headers = await get_auth_headers()
+ async with session.get(api_url, headers=headers) as response:
+ if response.status != 200:
+ raise Exception(f"Failed to fetch revision info from {api_url}: {response.status}")
+ revision_info = await response.json()
+ commit_hash = revision_info['sha']
+
+ # Cache the commit hash
+ await aios.makedirs(refs_dir, exist_ok=True)
+ async with aiofiles.open(refs_file, 'w') as f:
+ await f.write(commit_hash)
+
+ return commit_hash
+
+
async def download_repo_files(
repo_id: str,
revision: str = "main",
@@ -209,34 +239,15 @@ async def download_repo_files(
max_parallel_downloads: int = 4
) -> Path:
repo_root = get_repo_root(repo_id)
- refs_dir = repo_root/"refs"
snapshots_dir = repo_root/"snapshots"
cachedreqs_dir = repo_root/"cachedreqs"
# Ensure directories exist
- await aios.makedirs(refs_dir, exist_ok=True)
await aios.makedirs(snapshots_dir, exist_ok=True)
await aios.makedirs(cachedreqs_dir, exist_ok=True)
- # Check if we have a cached commit hash
- refs_file = refs_dir/revision
- if await aios.path.exists(refs_file):
- async with aiofiles.open(refs_file, 'r') as f:
- commit_hash = (await f.read()).strip()
- if DEBUG >= 2: print(f"Commit hash is already hashed at {refs_file}: {commit_hash}")
- else:
- async with aiohttp.ClientSession() as session:
- # Fetch the commit hash for the given revision
- api_url = f"https://huggingface.co/api/models/{repo_id}/revision/{revision}"
- headers = await get_auth_headers()
- async with session.get(api_url, headers=headers) as response:
- if response.status != 200:
- raise Exception(f"Failed to fetch revision info from {api_url}: {response.status}")
- revision_info = await response.json()
- commit_hash = revision_info['sha']
- # Cache the commit hash
- async with aiofiles.open(refs_file, 'w') as f:
- await f.write(commit_hash)
+ # Resolve revision to commit hash
+ commit_hash = await resolve_revision_to_commit_hash(repo_id, revision)
# Set up the snapshot directory
snapshot_dir = snapshots_dir/commit_hash
@@ -356,7 +367,8 @@ async def get_weight_map(repo_id: str, revision: str = "main") -> Optional[Dict[
# Check if the file exists
repo_root = get_repo_root(repo_id)
- snapshot_dir = repo_root/"snapshots"
+ commit_hash = await resolve_revision_to_commit_hash(repo_id, revision)
+ snapshot_dir = repo_root/"snapshots"/commit_hash
index_file = next((f for f in await aios.listdir(snapshot_dir) if f.endswith("model.safetensors.index.json")), None)
if index_file:
← 6881722b simplify non-blocking mlx inference
·
back to Exo
·
use sets for shard specific patterns e0fda94d →