| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
C++ implementation of Qwen-LM for real-time chatting on your MacBook.
Highlights:
Support Matrix:
Preparation
Make sure you install the re2, on MacOS:
brew install re2Clone the qwen.cpp repository into your local machine:
git clone --recursive https://github.com/QwenLM/qwen.cpp && cd qwen.cppIf you forgot the --recursive flag when cloning the repository, run the following command in the qwen.cpp folder:
git submodule update --init --recursiveDownload the qwen.tiktoken file from Hugging Face or modelscope.
Quantize Model
Use convert.py to transform Qwen-LM into quantized GGML format. For example, to convert the fp16 original model to q4_0 (quantized int4) GGML model, run:
python3 qwen_cpp/convert.py -i Qwen/Qwen-7B-Chat -t q4_0 -o qwen7b-ggml.binThe original model (-i <model_name_or_path>) can be a HuggingFace model name or a local path to your pre-downloaded model. Currently supported models are:
You are free to try any of the below quantization types by specifying -t <type>:
Build & Run
Compile the project using CMake:
cmake -B build
cmake --build build -j --config ReleaseNow you may chat with the quantized Qwen-7B-Chat model by running:
./build/bin/main -m qwen7b-ggml.bin --tiktoken Qwen-7B-Chat/qwen.tiktoken -p 你好
# 你好!很高兴为你提供帮助。To run the model in interactive mode, add the -i flag. For example:
./build/bin/main -m qwen7b-ggml.bin --tiktoken Qwen-7B-Chat/qwen.tiktoken -iIn interactive mode, your chat history will serve as the context for the next-round conversation.
Run ./build/bin/main -h to explore more options!
The Python binding provides high-level chat and stream_chat interface similar to the original Hugging Face Qwen-7B.
Installation
Install from PyPI (recommended): WIP.
You may also install from source.
# install from the latest source hosted on GitHub
pip install git+https://github.com/QwenLM/qwen.cpp.git@master
# or install from your local source after git cloning the repo
pip install .We provide pure C++ tiktoken implementation. After installation, the usage is the same as openai tiktoken:
import tiktoken_cpp as tiktoken
enc = tiktoken.get_encoding("cl100k_base")
assert enc.decode(enc.encode("hello world")) == "hello world"Benchmark
The speed of tiktoken.cpp is on par with openai tiktoken:
cd tests
RAYON_NUM_THREADS=1 python benchmark.pyUnit Test
To perform unit tests, add this CMake flag -DQWEN_ENABLE_TESTING=ON to enable testing. Recompile and run the unit test (including benchmark).
mkdir -p build && cd build
cmake .. -DQWEN_ENABLE_TESTING=ON && make -j
./bin/qwen_testLint
To format the code, run make lint inside the build folder. You should have clang-format, black and isort pre-installed.
| Back | FazBrowse Home | New Git URL |