From 21109e19834ad852e54daef7c7729b535e2241ba Mon Sep 17 00:00:00 2001 From: Laurent Mazare Date: Sat, 2 Sep 2023 17:19:35 +0200 Subject: [PATCH] Recommend using maturin. (#717) --- Makefile | 12 +----------- candle-pyo3/README.md | 12 ++++-------- candle-pyo3/quant-llama.py | 14 -------------- candle-pyo3/test.py | 15 --------------- 4 files changed, 5 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 1c4009b4..72e95dbe 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,4 @@ -pyo3-test: - cargo build --profile=release-with-debug --package candle-pyo3 - cp -f ./target/release-with-debug/libcandle.so candle.so - PYTHONPATH=.:$PYTHONPATH python3 candle-pyo3/test.py - -pyo3-test-macos: - cargo build --profile=release-with-debug --package candle-pyo3 - cp -f ./target/release-with-debug/libcandle.dylib candle.so - PYTHONPATH=.:$PYTHONPATH python3 candle-pyo3/test.py - -.PHONY: pyo3-test pyo3-test-macos clean-ptx clean test +.PHONY: clean-ptx clean test clean-ptx: find target -name "*.ptx" -type f -delete diff --git a/candle-pyo3/README.md b/candle-pyo3/README.md index f716b092..07dff468 100644 --- a/candle-pyo3/README.md +++ b/candle-pyo3/README.md @@ -1,11 +1,7 @@ -From the top level directory run the following for linux. -``` -cargo build --profile=release-with-debug --package candle-pyo3 && cp -f ./target/release-with-debug/libcandle.so candle.so -PYTHONPATH=. python3 candle-pyo3/test.py -```bash +From the `candle-pyo3` directory, enable a virtual env where you will want the +candle package to be installed then run. - Or for macOS users: ```bash -cargo build --profile=release-with-debug --package candle-pyo3 && cp -f ./target/release-with-debug/libcandle.dylib candle.so -PYTHONPATH=. python3 candle-pyo3/test.py +maturin develop +python test.py ``` diff --git a/candle-pyo3/quant-llama.py b/candle-pyo3/quant-llama.py index 092c1faa..7d74c25e 100644 --- a/candle-pyo3/quant-llama.py +++ b/candle-pyo3/quant-llama.py @@ -1,19 +1,5 @@ # This example shows how the candle Python api can be used to replicate llama.cpp. -import os import sys - -# The "import candle" statement below works if there is a "candle.so" file in sys.path. -# Here we check for shared libraries that can be used in the build directory. -BUILD_DIR = "./target/release-with-debug" -so_file = BUILD_DIR + "/candle.so" -if os.path.islink(so_file): os.remove(so_file) -for lib_file in ["libcandle.dylib", "libcandle.so"]: - lib_file_ = BUILD_DIR + "/" + lib_file - if os.path.isfile(lib_file_): - os.symlink(lib_file, so_file) - sys.path.insert(0, BUILD_DIR) - break - import candle MAX_SEQ_LEN = 4096 diff --git a/candle-pyo3/test.py b/candle-pyo3/test.py index f76dee9b..7f24b49d 100644 --- a/candle-pyo3/test.py +++ b/candle-pyo3/test.py @@ -1,18 +1,3 @@ -import os -import sys - -# The "import candle" statement below works if there is a "candle.so" file in sys.path. -# Here we check for shared libraries that can be used in the build directory. -BUILD_DIR = "./target/release-with-debug" -so_file = BUILD_DIR + "/candle.so" -if os.path.islink(so_file): os.remove(so_file) -for lib_file in ["libcandle.dylib", "libcandle.so"]: - lib_file_ = BUILD_DIR + "/" + lib_file - if os.path.isfile(lib_file_): - os.symlink(lib_file, so_file) - sys.path.insert(0, BUILD_DIR) - break - import candle t = candle.Tensor(42.0)