Browse Source

Merge pull request #473 from josh1593/package-exo-fixes

Package exo fixes
Alex Cheema 7 months ago
parent
commit
c6219f4ce3
6 changed files with 25 additions and 17 deletions
  1. 2 0
      exo/api/chatgpt_api.py
  2. 12 9
      exo/download/hf/hf_helpers.py
  3. 0 1
      exo/helpers.py
  4. 7 1
      exo/main.py
  5. 3 5
      scripts/build_exo.py
  6. 1 1
      setup.py

+ 2 - 0
exo/api/chatgpt_api.py

@@ -8,7 +8,9 @@ from typing import List, Literal, Union, Dict
 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

+ 12 - 9
exo/download/hf/hf_helpers.py

@@ -17,7 +17,6 @@ from exo.helpers import DEBUG, is_frozen
 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")
 
@@ -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

+ 0 - 1
exo/helpers.py

@@ -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():

+ 7 - 1
exo/main.py

@@ -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()
@@ -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}")
 

+ 3 - 5
scripts/build_exo.py

@@ -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": 
@@ -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",
@@ -57,4 +55,4 @@ def run():
         print(f"An error occurred: {e}")
 
 if __name__ == "__main__":
-    run()
+    run()

+ 1 - 1
setup.py

@@ -13,7 +13,7 @@ install_requires = [
   "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",