Languages: English | 中文
This project introduces how to deploy the 8-bit quantized sqlcoder model on Alibaba Cloud for free, and apply the large model to the Chat2DB client.
!!! Please note that the sqlcoder project is mainly for SQL generation, so it performs better in natural language to SQL, but slightly worse in SQL interpretation, optimization and transformation. Use it for reference only, do not blame the model or product.
Model | Minimum GPU Memory (Inference) | Minimum GPU Memory (Efficient Tuning) |
---|---|---|
sqlcoder-int8 | 20GB | 20GB |
-
Apply for free trial of Alibaba Cloud DSW.
-
Create a DSW instance, select the resource group that can deduct resource package, and select the instance image pytorch:1.12-gpu-py39-cu113-ubuntu20.04
-
Install the dependencies in requirements.txt
pip install -r requirements.txt
-
Download the latest bitsandbytes package to support 8-bit models:
pip install -i https://test.pypi.org/simple/ bitsandbytes
-
Create folders named sqlcoder-model and sqlcoder in DSW instance under the path "/mnt/workspace".
-
Download sqlcoder model under sqlcoder-model folder:
git clone https://huggingface.co/defog/sqlcoder
-
Copy api.py and prompt.md to sqlcoder folder.
-
Install FastAPI related packages:
pip install fastapi nest-asyncio pyngrok uvicorn
-
Start the API service under sqlcoder folder:
python api.py
-
You will get an API url like
https://dfb1-34-87-2-137.ngrok.io
. -
Configure the API url in Chat2DB client to use the model for SQL generation.
-
If resources permit, you can try deploying the non-quantized sqlcoder model, which will have slightly higher accuracy in SQL generation than the 8-bit model, but requires more GPU memory and longer inference time.
-
Just modify the model loading in api.py to fp16 model:
model = AutoModelForCausalLM.from_pretrained("/mnt/workspace/sqlcoder-model/sqlcoder", trust_remote_code=True, torch_dtype=torch.float16, device_map="auto", use_cache=True)
- Although this tutorial uses Alibaba Cloud DSW as example, the scripts and commands have no customization. In theory, sqlcoder can be deployed on any cloud by following the steps above.