Skip to content

Commit

Permalink
Merge pull request #473 from josh1593/package-exo-fixes
Browse files Browse the repository at this point in the history
Package exo fixes
  • Loading branch information
AlexCheema authored Nov 23, 2024
2 parents 4bbe0b4 + 357e338 commit c6219f4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 2 additions & 0 deletions exo/api/chatgpt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from aiohttp import web
import aiohttp_cors
import traceback
import os
import signal
import sys
from exo import DEBUG, VERSION
from exo.download.download_progress import RepoProgressEvent
from exo.helpers import PrefixDict, shutdown
Expand Down
21 changes: 12 additions & 9 deletions exo/download/hf/hf_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from exo.download.download_progress import RepoProgressEvent, RepoFileProgressEvent, RepoProgressCallback, RepoFileProgressCallback
from exo.inference.shard import Shard
import aiofiles
from aiofiles import os as aios

T = TypeVar("T")

Expand Down Expand Up @@ -109,16 +108,20 @@ async def move_models_to_hf(seed_dir: Union[str, Path]):
"""Move model in resources folder of app to .cache/huggingface/hub"""
source_dir = Path(seed_dir)
dest_dir = get_hf_home()/"hub"
await aios.makedirs(dest_dir, exist_ok=True)
async for path in source_dir.iterdir():
if path.is_dir() and path.startswith("models--"):
await aios.makedirs(dest_dir, exist_ok=True)
for path in source_dir.iterdir():
if path.is_dir() and path.name.startswith("models--"):
dest_path = dest_dir / path.name
if dest_path.exists():
if DEBUG>=1: print(f"skipping moving {dest_path}. File already exists")
if await aios.path.exists(dest_path):
print('Skipping moving model to .cache directory')
else:
await aios.rename(str(path), str(dest_path))


try:
await aios.rename(str(path), str(dest_path))
except Exception as e:
print(f'Error moving model to .cache: {e}')



async def fetch_file_list(session, repo_id, revision, path=""):
api_url = f"{get_hf_endpoint()}/api/models/{repo_id}/tree/{revision}"
url = f"{api_url}/{path}" if path else api_url
Expand Down
1 change: 0 additions & 1 deletion exo/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ async def shutdown(signal, loop, server):
print(f"Cancelling {len(server_tasks)} outstanding tasks")
await asyncio.gather(*server_tasks, return_exceptions=True)
await server.stop()
loop.stop()


def is_frozen():
Expand Down
8 changes: 7 additions & 1 deletion exo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ async def run_model_cli(node: Node, inference_engine: InferenceEngine, model_nam
finally:
node.on_token.deregister(callback_id)

def clean_path(path):
"""Clean and resolve path"""
if path.startswith("Optional("):
path = path.strip('Optional("').rstrip('")')
return os.path.expanduser(path)

async def main():
loop = asyncio.get_running_loop()
Expand All @@ -212,7 +217,8 @@ async def main():

if not args.models_seed_dir is None:
try:
await move_models_to_hf(args.models_seed_dir)
models_seed_dir = clean_path(args.models_seed_dir)
await move_models_to_hf(models_seed_dir)
except Exception as e:
print(f"Error moving models to .cache/huggingface: {e}")

Expand Down
8 changes: 3 additions & 5 deletions scripts/build_exo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def run():
"--follow-imports",
"--standalone",
"--output-filename=exo",
"--onefile",
"--python-flag=no_site"
"--python-flag=no_site",
"--onefile"
]

if sys.platform == "darwin":
Expand All @@ -24,8 +24,6 @@ def run():
"--macos-app-mode=gui",
"--macos-app-version=0.0.1",
"--macos-signed-app-name=com.exolabs.exo",
"--macos-sign-identity=auto",
"--macos-sign-notarization",
"--include-distribution-meta=mlx",
"--include-module=mlx._reprlib_fix",
"--include-module=mlx._os_warning",
Expand Down Expand Up @@ -57,4 +55,4 @@ def run():
print(f"An error occurred: {e}")

if __name__ == "__main__":
run()
run()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Jinja2==3.1.4",
"netifaces==0.11.0",
"numpy==2.0.0",
"nuitka==2.4.10",
"nuitka==2.5.1",
"nvidia-ml-py==12.560.30",
"pillow==10.4.0",
"prometheus-client==0.20.0",
Expand Down

0 comments on commit c6219f4

Please sign in to comment.