Skip to content

Commit

Permalink
Merge pull request #36 from NexaAI/ethan/dev
Browse files Browse the repository at this point in the history
Ethan/dev
  • Loading branch information
zhiyuan8 authored Aug 22, 2024
2 parents 11ff000 + aeb33c8 commit 5f2fc11
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 37 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-wheels-cpu-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
env:
# disable repair
CIBW_REPAIR_WHEEL_COMMAND: ""
CIBW_BUILD_FRONTEND: "build"
CIBW_ENVIRONMENT: CMAKE_ARGS="-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64 "
CIBW_BUILD: "cp310-* cp311-* cp312-*"
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/build-wheels-cpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
env:
# disable repair
CIBW_REPAIR_WHEEL_COMMAND: ""
CIBW_BUILD_FRONTEND: "build"
CIBW_SKIP: "*musllinux*"
CIBW_BUILD: "cp310-* cp311-* cp312-*"
CMAKE_BUILD_PARALLEL_LEVEL: 4
Expand Down Expand Up @@ -77,6 +78,7 @@ jobs:
env:
# disable repair
CIBW_REPAIR_WHEEL_COMMAND: ""
CIBW_BUILD_FRONTEND: "build"
CIBW_BUILD: "cp310-* cp311-* cp312-*"
CMAKE_BUILD_PARALLEL_LEVEL: 16
with:
Expand Down Expand Up @@ -104,8 +106,9 @@ jobs:
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_SKIP: "*musllinux* pp*"
CIBW_REPAIR_WHEEL_COMMAND: ""
CIBW_BUILD_FRONTEND: "build"
CIBW_SKIP: "*musllinux* pp*"
CIBW_ARCHS: "aarch64"
CIBW_BUILD: "cp310-* cp311-* cp312-*"
CMAKE_BUILD_PARALLEL_LEVEL: $(nproc)
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-wheels-metal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
env:
# disable repair
CIBW_REPAIR_WHEEL_COMMAND: ""
CIBW_BUILD_FRONTEND: "build"
CIBW_ARCHS: "arm64"
CIBW_BUILD: "cp310-* cp311-* cp312-*"
CIBW_ENVIRONMENT: CMAKE_ARGS="-DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_APPLE_SILICON_PROCESSOR=arm64 -DGGML_METAL=ON -DSD_METAL=ON"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fetch-depth: 0 # This fetches all history so you can access any version of the submodules

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
2 changes: 1 addition & 1 deletion nexa/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "0.0.5"
11 changes: 11 additions & 0 deletions nexa/cli/entry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import uvicorn

from nexa import __version__

def run_onnx_inference(args):
kwargs = {k: v for k, v in vars(args).items() if v is not None}
model_path = kwargs.pop("model_path")
Expand Down Expand Up @@ -73,6 +75,15 @@ def main():
parser = argparse.ArgumentParser(
description="Nexa CLI tool for handling various model operations."
)

parser.add_argument(
"-V",
"--version",
action="version",
version=__version__,
help="Show the version of the Nexa SDK.",
)

subparsers = parser.add_subparsers(dest="command", help="sub-command help")

# ONNX subparsers
Expand Down
23 changes: 10 additions & 13 deletions nexa/gguf/lib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
from pathlib import Path
from typing import List

from nexa.utils import (
is_nexa_cuda_installed,
is_nexa_metal_installed,
)


def is_gpu_available():
current_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -72,17 +67,19 @@ def load_library(lib_base_name: str):


def _add_windows_dll_directories(base_path: Path) -> None:
try_add_cuda_lib_path()
os.add_dll_directory(str(base_path))
os.environ["PATH"] = str(base_path) + os.pathsep + os.environ["PATH"]

if sys.version_info >= (3, 8):
if "CUDA_PATH" in os.environ:
os.add_dll_directory(os.path.join(os.environ["CUDA_PATH"], "bin"))
os.add_dll_directory(os.path.join(os.environ["CUDA_PATH"], "lib"))
if "HIP_PATH" in os.environ:
os.add_dll_directory(os.path.join(os.environ["HIP_PATH"], "bin"))
os.add_dll_directory(os.path.join(os.environ["HIP_PATH"], "lib"))
if is_gpu_available():
try_add_cuda_lib_path()

if sys.version_info >= (3, 8):
if "CUDA_PATH" in os.environ:
os.add_dll_directory(os.path.join(os.environ["CUDA_PATH"], "bin"))
os.add_dll_directory(os.path.join(os.environ["CUDA_PATH"], "lib"))
if "HIP_PATH" in os.environ:
os.add_dll_directory(os.path.join(os.environ["HIP_PATH"], "bin"))
os.add_dll_directory(os.path.join(os.environ["HIP_PATH"], "lib"))


def try_add_cuda_lib_path():
Expand Down
37 changes: 26 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ build-backend = "scikit_build_core.build"

[project]
name = "nexaai"
version = "0.0.5.1"
dynamic = ["version"]
description = "Nexa AI SDK"
readme = "README.md"
license = { text = "MIT" }
authors = [{ name = "Nexa AI", email = "[email protected]" }]
dependencies = [
"faster_whisper",
"typing-extensions>=4.5.0", # For ggml
"typing-extensions>=4.5.0", # For ggml
"numpy>=1.20.0",
"diskcache>=5.6.1",
"jinja2>=2.11.3",
Expand All @@ -21,9 +21,9 @@ dependencies = [
"pydantic",
"pillow",
"prompt_toolkit",
"tqdm", # Shared dependencies
"tqdm", # Shared dependencies
"tabulate",
"streamlit"
"streamlit",
]
classifiers = [
"Programming Language :: Python :: 3",
Expand All @@ -36,8 +36,8 @@ classifiers = [
[project.optional-dependencies]
onnx = [
"librosa",
"optimum[onnxruntime]", # for CPU version
"diffusers", # required for image generation
"optimum[onnxruntime]", # for CPU version
"diffusers", # required for image generation
"optuna",
"pydantic",
"PyYAML",
Expand All @@ -46,7 +46,7 @@ onnx = [
"soundfile",
"streamlit_audiorec",
"transformers",
"ttstokenizer"
"ttstokenizer",
]

[project.urls]
Expand All @@ -71,15 +71,30 @@ wheel.packages = [
"nexa.gguf.server",
"nexa.onnx",
"nexa.onnx.streamlit",
"nexa.onnx.server"
"nexa.onnx.server",
]
sdist.include = [
"CMakeLists.txt",
"dependency/llama.cpp/*",
"dependency/stable-diffusion.cpp/*",
]
sdist.exclude = [
".github",
"build",
"dist",
"nexa.egg-info",
"dependency/llama.cpp/build",
"dependency/stable-diffusion.cpp/build",
]
sdist.include = ["CMakeLists.txt", "dependency/llama.cpp/*", "dependency/stable-diffusion.cpp/*"]
sdist.exclude = [".github", "build", "dist", "nexa.egg-info", "dependency/llama.cpp/build", "dependency/stable-diffusion.cpp/build"]
build.verbose = true
cmake.build-type = "Release"
cmake.version = ">=3.16"
# cmake.args = ["-DCMAKE_CXX_FLAGS=-fopenmp"] # for macOS with Intel Silicon
cmake.args = ["-DCMAKE_BUILD_PARALLEL_LEVEL=16"]

[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "nexa/__init__.py"

[tool.pytest.ini_options]
testpaths = ["tests"]
testpaths = ["tests"]
6 changes: 3 additions & 3 deletions scripts/releases-to-pep-503.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ if [ "$version" == "cpu" ]; then
echo " <h1>NEXAAI SDK Python Wheels</h1>" >> "$root_dir/index.html"
echo " <a href=\"cpu/\">CPU</a><br>" >> "$root_dir/index.html"
echo " <a href=\"metal/\">Metal</a><br>" >> "$root_dir/index.html"
echo " <a href=\"cu121/\">CUDA 12.1</a><br>" >> "$root_dir/index.html"
echo " <a href=\"cu122/\">CUDA 12.2</a><br>" >> "$root_dir/index.html"
echo " <a href=\"cu123/\">CUDA 12.3</a><br>" >> "$root_dir/index.html"
# echo " <a href=\"cu121/\">CUDA 12.1</a><br>" >> "$root_dir/index.html"
# echo " <a href=\"cu122/\">CUDA 12.2</a><br>" >> "$root_dir/index.html"
# echo " <a href=\"cu123/\">CUDA 12.3</a><br>" >> "$root_dir/index.html"
echo " <a href=\"cu124/\">CUDA 12.4</a><br>" >> "$root_dir/index.html"
echo " </body>" >> "$root_dir/index.html"
echo "</html>" >> "$root_dir/index.html"
Expand Down
14 changes: 7 additions & 7 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@

def download_model(url, output_dir):
"""
Download a file from a given URL using wget, if it doesn't already exist.
Download a file from a given URL using curl, if it doesn't already exist.
Args:
- url: str, the URL of the file to download.
- output_dir: str, the directory where the file should be saved.
Returns:
- str: The path to the downloaded file.
"""
file_name = url.split("/")[-1]
output_path = os.path.join(output_dir, file_name)

if os.path.exists(output_path):
print(f"File {file_name} already exists in {output_dir}. Skipping download.")
return output_path

try:
subprocess.run(["wget", url, "-O", output_path], check=True)
subprocess.run(["curl", url, "--output", output_path], check=True)
print(f"Downloaded {file_name} to {output_dir}")
except subprocess.CalledProcessError as e:
print(f"Failed to download {file_name}: {e}")
raise

return output_path

0 comments on commit 5f2fc11

Please sign in to comment.