Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into xingyu/docker
Browse files Browse the repository at this point in the history
  • Loading branch information
xyyimian committed Aug 22, 2024
2 parents cbaf98a + 50361e5 commit dd2b628
Show file tree
Hide file tree
Showing 18 changed files with 550 additions and 489 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Python CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: recursive # This will clone the repository with all its submodules
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
with:
python-version: '3.10' # Specify the Python version you want

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build pytest
- name: Build DLL
run: |
python -m pip install -e .
- name: Run tests
run: |
python -m pytest tests
113 changes: 62 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
cmake_minimum_required(VERSION 3.16)

if (GGML_CUDA OR GGML_METAL)
set(EMPTY_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib/empty_file.txt")
add_custom_command(
OUTPUT ${EMPTY_FILE_PATH}
COMMAND ${CMAKE_COMMAND} -E touch ${EMPTY_FILE_PATH}
COMMENT "Creating an empty file because MY_FEATURE is ON"
)
add_custom_target(create_empty_file ALL DEPENDS ${EMPTY_FILE_PATH})
endif()

# Project: stable_diffusion_cpp
project(stable_diffusion_cpp)

option(STABLE_DIFFUSION_BUILD "Build stable-diffusion.cpp shared library and install alongside python package" ON)

if (STABLE_DIFFUSION_BUILD)
set(BUILD_SHARED_LIBS "ON")
option(SD_BUILD_SHARED_LIBS "" "ON")

# Building llama
if (APPLE AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
# Need to disable these llama.cpp flags on Apple x86_64,
# otherwise users may encounter invalid instruction errors
set(GGML_AVX "Off" CACHE BOOL "ggml: enable AVX" FORCE)
set(GGML_AVX2 "Off" CACHE BOOL "ggml: enable AVX2" FORCE)
set(GGML_FMA "Off" CACHE BOOL "ggml: enable FMA" FORCE)
set(GGML_F16C "Off" CACHE BOOL "ggml: enable F16C" FORCE)
endif()

add_subdirectory(dependency/stable-diffusion.cpp)
install(
TARGETS stable-diffusion
LIBRARY DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
RUNTIME DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
ARCHIVE DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
FRAMEWORK DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
RESOURCE DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
)

message(STATUS "SKBUILD_PLATLIB_DIR: ${SKBUILD_PLATLIB_DIR}")
# Temporary fix for https://github.com/scikit-build/scikit-build-core/issues/374
install(
TARGETS stable-diffusion
LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
ARCHIVE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
FRAMEWORK DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
RESOURCE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
)
# Workaround for Windows + CUDA
if (WIN32)
install(
FILES $<TARGET_RUNTIME_DLLS:stable-diffusion>
DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
)
install(
FILES $<TARGET_RUNTIME_DLLS:stable-diffusion>
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
)
endif()
endif()

# Project: llama_cpp
project(llama_cpp)

Expand Down Expand Up @@ -123,54 +185,3 @@ if (LLAMA_BUILD)
endif()
endif()

# Project: stable_diffusion_cpp
project(stable_diffusion_cpp)

option(STABLE_DIFFUSION_BUILD "Build stable-diffusion.cpp shared library and install alongside python package" ON)

if (STABLE_DIFFUSION_BUILD)
set(BUILD_SHARED_LIBS "ON")
option(SD_BUILD_SHARED_LIBS "" "ON")

# Building llama
if (APPLE AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
# Need to disable these llama.cpp flags on Apple x86_64,
# otherwise users may encounter invalid instruction errors
set(GGML_AVX "Off" CACHE BOOL "ggml: enable AVX" FORCE)
set(GGML_AVX2 "Off" CACHE BOOL "ggml: enable AVX2" FORCE)
set(GGML_FMA "Off" CACHE BOOL "ggml: enable FMA" FORCE)
set(GGML_F16C "Off" CACHE BOOL "ggml: enable F16C" FORCE)
endif()

add_subdirectory(dependency/stable-diffusion.cpp)
install(
TARGETS stable-diffusion
LIBRARY DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
RUNTIME DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
ARCHIVE DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
FRAMEWORK DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
RESOURCE DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
)

message(STATUS "SKBUILD_PLATLIB_DIR: ${SKBUILD_PLATLIB_DIR}")
# Temporary fix for https://github.com/scikit-build/scikit-build-core/issues/374
install(
TARGETS stable-diffusion
LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
ARCHIVE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
FRAMEWORK DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
RESOURCE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
)
# Workaround for Windows + CUDA
if (WIN32)
install(
FILES $<TARGET_RUNTIME_DLLS:stable-diffusion>
DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib
)
install(
FILES $<TARGET_RUNTIME_DLLS:stable-diffusion>
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib
)
endif()
endif()
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,24 @@ check if you have GPU acceleration (torch required)
```
CMAKE_ARGS="-DGGML_CUDA=on -DSD_CUBLAS=ON" pip install nexaai-gpu
```
Or you prefer to install our pre-built wheel:
```bash
pip install nexaai-cuda --index-url https://nexaai.github.io/nexa-sdk/whl/cu124 --extra-index-url https://pypi.org/simple
```
</details>
<details>
<summary>Apple M Chip:</summary>
Apple icon -> about this mac -> Graphics

if True:

```
CMAKE_ARGS="-DGGML_METAL=on -DSD_METAL=ON" pip install nexaai-gpu
```
Or you prefer to install our pre-built wheel:
```bash
pip install nexaai-metal --index-url https://nexaai.github.io/nexa-sdk/whl/metal --extra-index-url https://pypi.org/simple
```
</details>

<details>
Expand Down Expand Up @@ -79,18 +87,26 @@ check if you have GPU acceleration (torch required)
```
</details>

Or you prefer to install the pre-built wheel:
```bash
pip install nexaai --index-url https://nexaai.github.io/nexa-sdk/whl/cpu --extra-index-url https://pypi.org/simple
```

### Docker Usage
Note: Docker doesn't support GPU acceleration

```
docker pull nexa4ai/sdk:latest
# replace following placeholder with your path and command
docker run -v <your_model_dir>:/model -it nexa4ai/sdk:latest [nexa_command] [your_model_relative_path]
```
`docker pull nexa4ai/sdk:latest`

replace following placeholder with your path and command

`docker run -v <your_model_dir>:/model -it nexa4ai/sdk:latest [nexa_command] [your_model_relative_path]`

Example:

`docker run -v /home/ubuntu/.cache/nexa/hub/official:/model -it nexa4ai/sdk:latest nexa gen-text /model/Phi-3-mini-128k-instruct/q4_0.gguf`

will create an interactive session with text generation
```
## Nexa CLI commands
Expand Down
4 changes: 3 additions & 1 deletion nexa/gguf/lib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@


def is_gpu_available():
return is_nexa_cuda_installed() or is_nexa_metal_installed()
current_dir = os.path.dirname(os.path.abspath(__file__))
sentinel_file_exists = os.path.exists(os.path.join(current_dir, "lib", "empty_file.txt"))
return sentinel_file_exists

# Load the library
def load_library(lib_base_name: str):
Expand Down
Loading

0 comments on commit dd2b628

Please sign in to comment.