Skip to content

Commit

Permalink
Merge pull request #32 from glide-the/quantized
Browse files Browse the repository at this point in the history
load a 4-bit or 8-bit quantized version
  • Loading branch information
zRzRzRzRzRzRzR authored Oct 28, 2024
2 parents eb140fc + b5530ee commit 88c5c52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions model_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse
from transformers import AutoModel, AutoTokenizer
from transformers import AutoModel, AutoTokenizer, BitsAndBytesConfig
import torch
import uvicorn

Expand Down Expand Up @@ -56,8 +56,16 @@ def __next__(self):
class ModelWorker:
def __init__(self, model_path, device='cuda'):
self.device = device
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)

self.glm_model = AutoModel.from_pretrained(model_path, trust_remote_code=True,
device=device).to(device).eval()
quantization_config=bnb_config,
device_map={"":0}).eval()
self.glm_tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)

@torch.inference_mode()
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ wget==3.2
WeTextProcessing==1.0.3
torch==2.3.0
torchaudio==2.3.0
python-multipart==0.0.12

# load a 4-bit or 8-bit quantized version
bitsandbytes==0.44.1
accelerate==1.0.1

0 comments on commit 88c5c52

Please sign in to comment.