Skip to content

Commit

Permalink
Merge pull request #14 from UnicornChan/feature-support-pypi
Browse files Browse the repository at this point in the history
[feature] support for pypi install
  • Loading branch information
UnicornChan authored Jul 29, 2024
2 parents a25320b + dd18a11 commit 2562082
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 124 deletions.
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,37 @@ Some preparation:
conda activate ktransformers # you may need to run ‘conda init’ and reopen shell first
```

Download source code:
- Make sure that PyTorch, packaging, ninja is installed
```
pip install torch packaging ninja
```

<h3>Installation</h3>
You can install using Pypi:

```
pip install ktransformers --no-build-isolation
```

Or download source code and compile:
- init source code
```sh
git clone https://github.com/kvcache-ai/ktransformers.git
cd ktransformers
git submodule init
git submodule update
```
- [Optional] If you want to run with website, please [compile the website](./doc/en/api/server/website.md) before execute ```bash install.sh```
- Compile and install
```
bash install.sh
```

<h3>Local Chat</h3>
We provide a simple command-line local chat Python script that you can run for testing.

> Note that this is a very simple test tool only support one round chat without any memory about last input, if you want to try full ability of the model, you may go to [RESTful API and Web UI](#id_666). We use the DeepSeek-V2-Lite-Chat-GGUF model as an example here. But we alse support other models, you can replace it with any other model that you want to test.
<h4>Install</h4>

```sh
bash install.sh
```

<h4>Run Example</h4>

Expand All @@ -109,11 +122,11 @@ wget https://huggingface.co/mzwing/DeepSeek-V2-Lite-Chat-GGUF/resolve/main/DeepS
cd .. # Move to repo's root dir

# Start local chat
python ktransformers/local_chat.py --model_path deepseek-ai/DeepSeek-V2-Lite-Chat --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF
python -m ktransformers.local_chat --model_path deepseek-ai/DeepSeek-V2-Lite-Chat --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF

# If you see “OSError: We couldn't connect to 'https://huggingface.co' to load this file”, try:
# GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite
# python ktransformers/local_chat.py --model_path ./DeepSeek-V2-Lite --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF
# python ktransformers.local_chat --model_path ./DeepSeek-V2-Lite --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF
```


Expand Down Expand Up @@ -154,7 +167,7 @@ wget https://huggingface.co/Qwen/Qwen2-57B-A14B-Instruct-GGUF/resolve/main/qwen2

cd ..

python ktransformers/local_chat.py --model_name Qwen/Qwen2-57B-A14B-Instruct --gguf_path ./Qwen2-57B-GGUF
python -m ktransformers.local_chat --model_name Qwen/Qwen2-57B-A14B-Instruct --gguf_path ./Qwen2-57B-GGUF

# If you see “OSError: We couldn't connect to 'https://huggingface.co' to load this file”, try:
# GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/Qwen/Qwen2-57B-A14B-Instruct
Expand All @@ -172,11 +185,11 @@ wget https://huggingface.co/bartowski/DeepSeek-V2-Chat-0628-GGUF/resolve/main/De

cd ..

python ktransformers/local_chat.py --model_name deepseek-ai/DeepSeek-V2-Chat-0628 --gguf_path ./DeepSeek-V2-Chat-0628-GGUF
python -m ktransformers.local_chat --model_name deepseek-ai/DeepSeek-V2-Chat-0628 --gguf_path ./DeepSeek-V2-Chat-0628-GGUF

# If you see “OSError: We couldn't connect to 'https://huggingface.co' to load this file”, try:
# GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/deepseek-ai/DeepSeek-V2-Chat-0628
# python ktransformers/local_chat.py --model_path ./DeepSeek-V2-Chat-0628 --gguf_path ./DeepSeek-V2-Chat-0628-GGUF
# python -m ktransformers.local_chat --model_path ./DeepSeek-V2-Chat-0628 --gguf_path ./DeepSeek-V2-Chat-0628-GGUF
```

| model name | weights download link |
Expand All @@ -193,15 +206,6 @@ python ktransformers/local_chat.py --model_name deepseek-ai/DeepSeek-V2-Chat-062

<h3>RESTful API and Web UI</h3>

<h4>Install</h4>

[Optional] If you want to run with website, please [compile the website](./doc/en/api/server/website.md) before execute ```pip install .```

Install ktransformers with source.
```
pip install -r requirements-local_chat.txt
pip install . --no-build-isolation
```

Start without website:

Expand Down
14 changes: 2 additions & 12 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ rm -rf ktransformers/ktransformers_ext/cuda/*.egg-info
echo "Installing python dependencies from requirements.txt"
pip install -r requirements-local_chat.txt

echo "Installing ktransformers cpuinfer"
mkdir -p ktransformers/ktransformers_ext/build
cd ktransformers/ktransformers_ext/build
cmake ..
cmake --build . --config Release

echo "Installing ktransformers gpu kernel, this may take for a while, please wait"
sleep 3

cd ../cuda
python setup.py install
cd ../../..
echo "Installing ktransformers"
pip install . --no-build-isolation
echo "Installation completed successfully"
60 changes: 60 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,63 @@ requires = [
"packaging"
]
build-backend = "setuptools.build_meta"

[project]

name = "ktransformers"

dynamic = ["version"]

dependencies = [
"torch >= 2.3.0",
"transformers == 4.43.2",
"fastapi >= 0.111.0",
"langchain >= 0.2.0",
"blessed >= 1.20.0",
"accelerate >= 0.31.0",
"sentencepiece >= 0.1.97",
"setuptools",
"ninja",
"wheel",
"colorlog",
"build",
"fire"
]

requires-python = ">=3.11"

authors = [
{name = "KVCache.AI", email = "[email protected]"}
]

maintainers = [
{name = "james0zan", email = "[email protected]"},
{name = "awake", email = "[email protected]"},
{name = "unicorn chan", email = "[email protected]"}
]

description = "KTransformers, pronounced as Quick Transformers, is designed to enhance your Transformers experience with advanced kernel optimizations and placement/parallelism strategies."

readme = "README.md"
license = {file = "LICENSE"}

keywords = ["ktransformers", "llm"]

classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]

[project.urls]
Homepage = "https://kvcache.ai"
Repository = "https://github.com/kvcache-ai/ktransformers.git"
Issues = "https://github.com/kvcache-ai/ktransformers/issues"


[project.scripts]
ktransformers = "ktransformers.server.main:main"

[tool.setuptools.packages.find]
where = ["./", ]
include = ["ktransformers"]
Loading

0 comments on commit 2562082

Please sign in to comment.