Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Python test with site-packages #8

Merged
merged 31 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
354845c
feat: Add Python test with site-packages
CameronNg May 14, 2024
35b9a80
fix: Update LD_LIBRARY_PATH for Linux test
CameronNg May 14, 2024
aaa00d9
fix: Update LD_LIBRARY_PATH for Linux test v2
CameronNg May 15, 2024
0419192
fix: Update LD_LIBRARY_PATH for Linux test v3
CameronNg May 15, 2024
dd434b7
fix: Add XZUtils lib for Linux build
CameronNg May 15, 2024
c76f7dc
fix: Add XZUtils lib for Linux build v2
CameronNg May 15, 2024
0b5e4b2
fix: Add XZUtils lib for Linux build v3
CameronNg May 15, 2024
ac3c0e2
fix: Add OpenSSL lib for Linux build
CameronNg May 15, 2024
7903798
fix: Remove OpenSSL lib for Linux build
CameronNg May 15, 2024
5128649
fix: Remove OpenSSL lib for Linux build v2
CameronNg May 15, 2024
30ea17b
fix: Remove OpenSSL lib for Linux build v3
CameronNg May 15, 2024
b2d7a2c
fix: Add OpenSSL lib for Python installation from source
CameronNg May 15, 2024
097c696
fix: Add OpenSSL lib for Python installation from source v2
CameronNg May 15, 2024
dae1eb5
fix: Remove OpenSSL lib for Linux build v4
CameronNg May 15, 2024
dee2263
Merge branch 'main' into feat-add-python-site-packages-test
CameronNg May 15, 2024
2daddef
fix: Missing OpenSSL for python
CameronNg May 15, 2024
1d15a6e
fix: Missing OpenSSL for python v2
CameronNg May 15, 2024
06c282a
fix: Missing OpenSSL for python v3
CameronNg May 15, 2024
f1bb4b9
fix: Missing OpenSSL for python v4
CameronNg May 15, 2024
01e5cd6
fix: Explicit install OpenSSL for Linux
CameronNg May 15, 2024
5d09030
fix: Explicit install OpenSSL for Linux v2
CameronNg May 15, 2024
62dd653
fix: Add python lib to package release
CameronNg May 15, 2024
c94a8d2
fix: missing package
CameronNg May 16, 2024
ffaf4ef
feat: add more testing machine
CameronNg May 16, 2024
384543d
feat: fix zlib error on Mac arm
CameronNg May 16, 2024
7a79915
feat: fix zlib error on Mac arm v2
CameronNg May 16, 2024
4fafefd
feat: fix zlib error on Mac arm v3
CameronNg May 16, 2024
f3db8a8
feat: fix zlib error on Mac arm v4
CameronNg May 16, 2024
b858f69
fix: build
sangjanai May 16, 2024
08128a2
fix: add quality-gate.yml
sangjanai May 20, 2024
dddf524
fix: test
sangjanai May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions .github/scripts/e2e-test-server-linux-and-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ max=11000
range=$((max - min + 1))
PORT=$((RANDOM % range + min))

# Install numpy for Python
export PYTHONHOME=$(pwd)/python/
export LD_LIBRARY_PATH="$PYTHONHOME:$LD_LIBRARY_PATH"
echo "Set Python HOME to $PYTHONHOME"
./python/bin/python3 -m ensurepip
./python/bin/python3 -m pip install --upgrade pip
./python/bin/python3 -m pip install numpy --target=$PYTHONHOME/lib/python/site-packages/

# Start the binary file
"$BINARY_PATH" 127.0.0.1 $PORT >/tmp/server.log &

Expand All @@ -41,14 +49,35 @@ response1=$(curl --connect-timeout 60 -o /tmp/python-file-execution-res.log -s -
"file_execution_path": "'$PYTHON_FILE_EXECUTION_PATH'"
}')


error_occurred=0

# Verify the response
if [[ "$response1" -ne 200 ]]; then
echo "The python file execution curl command failed with status code: $response1"
cat /tmp/python-file-execution-res.log
error_occurred=1
fi

# Verify the output of the Python file in output.txt
OUTPUT_FILE="./output.txt"
EXPECTED_OUTPUT="1 2 3" # Replace with the expected content

if [[ -f "$OUTPUT_FILE" ]]; then
actual_output=$(cat "$OUTPUT_FILE")
if [[ "$actual_output" != "$EXPECTED_OUTPUT" ]]; then
echo "The output of the Python file does not match the expected output."
echo "Expected: $EXPECTED_OUTPUT"
echo "Actual: $actual_output"
error_occurred=1
else
echo "The output of the Python file matches the expected output."
fi
else
echo "Output file $OUTPUT_FILE does not exist."
error_occurred=1
fi


if [[ "$error_occurred" -eq 1 ]]; then
echo "Server test run failed!!!!!!!!!!!!!!!!!!!!!!"
echo "Server Error Logs:"
Expand All @@ -62,7 +91,6 @@ echo "----------------------"
echo "Log server:"
cat /tmp/server.log


echo "Server test run successfully!"

# Kill the server process
Expand Down
25 changes: 25 additions & 0 deletions .github/scripts/e2e-test-server-windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ set /a max=11000
set /a range=max-min+1
set /a PORT=%min% + %RANDOM% %% %range%

rem Install numpy for Python
set "PYTHONHOME=%cd%\python"
echo Set Python HOME to %PYTHONHOME%
%PYTHONHOME%\python.exe -m ensurepip
%PYTHONHOME%\python.exe -m pip install --upgrade pip
%PYTHONHOME%\python.exe -m pip install numpy --target=%PYTHONHOME%\Lib\site-packages\

rem Start the binary file
start "" /B "%BINARY_PATH%" "127.0.0.1" %PORT% > "%TEMP%\server.log" 2>&1

Expand Down Expand Up @@ -74,6 +81,24 @@ echo Log python file execution:
type %TEMP%\response1.log
echo.

rem Verification step: Check the contents of output.txt
set "expected_output=1 2 3"
set "actual_output="
if exist "output.txt" (
for /f "delims=" %%x in (output.txt) do set "actual_output=%%x"
if "!actual_output!"=="!expected_output!" (
echo Verification succeeded: output.txt contains the expected data.
) else (
echo Verification failed: output.txt does not contain the expected data.
echo Expected: !expected_output!
echo Actual: !actual_output!
set "error_occurred=1"
)
) else (
echo Verification failed: output.txt does not exist.
set "error_occurred=1"
)

echo ----------------------
echo Server logs:
type %TEMP%\server.log
Expand Down
6 changes: 6 additions & 0 deletions .github/scripts/python-file-to-test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import sys;
for path in sys.path:
print(path)

import numpy as np
print("Numpy version: " + np.__version__)

with open('output.txt', 'w') as file:
file.write(' '.join(map(str, np.array([1, 2, 3]))))
92 changes: 85 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,91 @@
name: CI

on:
pull_request:
types: [opened, synchronize, reopened]
push:
tags: ["v[0-9]+.[0-9]+.[0-9]+"]
paths:
[
".github/scripts/**",
".github/workflows/build.yml",
"**/CMakeLists.txt",
"**/Makefile",
"**/*.h",
"**/*.hpp",
"**/*.c",
"**/*.cpp",
"**/*.cu",
"**/*.cc",
"**/*.cxx",
"llama.cpp",
"!docs/**",
"!.gitignore",
"!README.md",
]
workflow_dispatch:

jobs:
create-draft-release:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.get_version.outputs.version }}
permissions:
contents: write
steps:
- name: Extract tag name without v prefix
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV && echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
env:
GITHUB_REF: ${{ github.ref }}
- name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: "${{ env.VERSION }}"
draft: true
prerelease: false

build-and-test:
runs-on: ${{ matrix.runs-on }}
needs: [create-draft-release]
timeout-minutes: 40
strategy:
matrix:
include:
# - os: "linux"
# name: "ubuntu-18-04"
# runs-on: "ubuntu-18-04"
- os: "linux"
name: "ubuntu-18-04"
runs-on: "ubuntu-18-04"
# run-e2e: true
name: "latest"
runs-on: "ubuntu-latest"
- os: "mac"
name: "arm64"
runs-on: "mac-silicon"
- os: "windows"
- os: "mac"
name: "amd64"
runs-on: "windows-cuda-12-0"
runs-on: "macos-13"
# - os: "windows"
# name: "amd64"
# runs-on: "windows-cuda-12-0"
- os: "windows"
name: "latest"
runs-on: "windows-latest"

steps:
- name: Clone
id: checkout
uses: actions/checkout@v3

- name: Install OpenSSL on Ubuntu
if: matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y openssl libssl-dev

- name: Install make on Windows
if: runner.os == 'windows'
run: |
Expand All @@ -48,3 +106,23 @@ jobs:
- name: Run e2e test
run: |
make run-e2e-test

- name: Package
run: |
make package

- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: cortex.python-runtime-${{ matrix.os }}-${{ matrix.name }}
path: ./cortex.python-runtime.tar.gz

- uses: actions/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
asset_path: ./cortex.python-runtime.tar.gz
asset_name: cortex.python-runtime-${{ needs.create-draft-release.outputs.version }}-${{ matrix.os }}-${{ matrix.name }}.tar.gz
asset_content_type: application/gzip
74 changes: 74 additions & 0 deletions .github/workflows/quality-gate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI

on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

jobs:
build-and-test:
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 40
strategy:
matrix:
include:
# - os: "linux"
# name: "ubuntu-18-04"
# runs-on: "ubuntu-18-04"
- os: "linux"
name: "latest"
runs-on: "ubuntu-latest"
- os: "mac"
name: "arm64"
runs-on: "mac-silicon"
- os: "mac"
name: "amd64"
runs-on: "macos-13"
# - os: "windows"
# name: "amd64"
# runs-on: "windows-cuda-12-0"
- os: "windows"
name: "latest"
runs-on: "windows-latest"

steps:
- name: Clone
id: checkout
uses: actions/checkout@v3

- name: Install OpenSSL on Ubuntu
if: matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y openssl libssl-dev

- name: Install make on Windows
if: runner.os == 'windows'
run: |
choco install make -y

- name: Install dependencies
run: |
make install-dependencies

- name: Build engine
run: |
make build-engine

- name: Build example server
run: |
make build-example-server

- name: Run e2e test
run: |
make run-e2e-test

- name: Package
run: |
make package

- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: cortex.python-runtime-${{ matrix.os }}-${{ matrix.name }}
path: ./cortex.python-runtime.tar.gz
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ find_library(TRANTOR
# Copy the python3 related files to the build folder
if (WIN32)
# Copy the whole library
file(COPY ${THIRD_PARTY_PATH}/python DESTINATION ${CMAKE_BINARY_DIR}/Release)
file(COPY ${THIRD_PARTY_PATH}/python DESTINATION ${CMAKE_BINARY_DIR})
else() # APPLE and LINUX
# Copy library files
file(GLOB PYTHON_LIBS ${THIRD_PARTY_PATH}/lib/python*)
Expand All @@ -73,7 +73,9 @@ else() # APPLE and LINUX
if(EXISTS ${SYMLINK_PATH})
file(REMOVE_RECURSE ${SYMLINK_PATH})
endif()
file(CREATE_LINK ${FIRST_PYTHON_LIB} ${SYMLINK_PATH} SYMBOLIC)

file(RELATIVE_PATH REL_PATH ${CMAKE_BINARY_DIR}/python/lib ${FIRST_PYTHON_LIB})
file(CREATE_LINK ${REL_PATH} ${SYMLINK_PATH} SYMBOLIC)
endif()

# Copy executable files
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@ endif

build-engine:
ifeq ($(OS),Windows_NT)
cmd /C "mkdir build && cd build && cmake .. && cmake --build . --config Release -j12"
@powershell -Command "mkdir -p build; cd build; cmake .. $(CMAKE_EXTRA_FLAGS); cmake --build . --config Release;"
else
mkdir -p build
cd build && cmake .. && cmake --build . --config Release -j12
endif

build-example-server:
ifeq ($(OS),Windows_NT)
cmd /C "mkdir examples\\server\\build && cd examples\\server\\build && cmake .. && cmake --build . --config Release -j12"
@powershell -Command "mkdir -p .\examples\server\build; cd .\examples\server\build; cmake .. $(CMAKE_EXTRA_FLAGS); cmake --build . --config Release; cp -r ..\..\..\build\python .\Release\python"
else
mkdir -p examples/server/build
cd examples/server/build && cmake .. && cmake --build . --config Release -j12 && \
cp -r ../../../build/python ./ && cd python/lib && ln -s python3.10 python
cd examples/server/build && cmake .. && cmake --build . --config Release -j12
cp -r build/python examples/server/build
endif

package:
ifeq ($(OS),Windows_NT)
@powershell -Command "New-Item -ItemType Directory -Path cortex.python-runtime -Force; cp build\Release\engine.dll cortex.python-runtime\; Compress-Archive -Path cortex.python-runtime\* -DestinationPath cortex.python-runtime.zip;"
@powershell -Command "mkdir -p cortex.python-runtime; cp build\Release\engine.dll cortex.python-runtime\; cp -r build\python cortex.python-runtime\; 7z a -ttar temp.tar cortex.python-runtime\*; 7z a -tgzip cortex.python-runtime.tar.gz temp.tar;"
else
@mkdir -p cortex.python-runtime && \
cp build/libengine.$(shell uname | tr '[:upper:]' '[:lower:]' | sed 's/darwin/dylib/;s/linux/so/') cortex.python-runtime/ && \
cp build/libengine.$(shell uname | tr '[:upper:]' '[:lower:]' | sed 's/darwin/dylib/;s/linux/so/') cortex.python-runtime && \
cp -r build/python cortex.python-runtime
tar -czvf cortex.python-runtime.tar.gz cortex.python-runtime
endif

Expand All @@ -47,8 +48,7 @@ ifeq ($(RUN_TESTS),false)
@echo "Skipping tests"
else
ifeq ($(OS),Windows_NT)
@mkdir examples\server\build\Release\engines\cortex.python-runtime && \
cmd /C "cd examples\server\build\Release && copy ..\..\..\..\build\Release\engine.dll engines\cortex.python-runtime && ..\..\..\..\.github\scripts\e2e-test-server-windows.bat server.exe ..\..\..\..\\$(PYTHON_FILE_EXECUTION_PATH)"
@powershell -Command "mkdir -p .\examples\server\build\Release\engines\cortex.python-runtime; cd examples\server\build\Release; cp ..\..\..\..\build\Release\engine.dll engines\cortex.python-runtime; ..\..\..\..\.github\scripts\e2e-test-server-windows.bat server.exe ..\..\..\..\$(PYTHON_FILE_EXECUTION_PATH);"
else
@mkdir -p examples/server/build/engines/cortex.python-runtime && \
cd examples/server/build && \
Expand Down
Loading
Loading