Spaces:
Runtime error
Runtime error
binqiangliu
commited on
Commit
•
790c7af
1
Parent(s):
cdf6cb1
Update app.py
Browse files
app.py
CHANGED
@@ -17,4 +17,45 @@ from langchain.document_loaders import PyPDFDirectoryLoader
|
|
17 |
from langchain.chains import ConversationalRetrievalChain
|
18 |
from langchain.memory import ConversationBufferMemory
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
17 |
from langchain.chains import ConversationalRetrievalChain
|
18 |
from langchain.memory import ConversationBufferMemory
|
19 |
|
20 |
+
# specify model huggingface mode name
|
21 |
+
model_name = "anakin87/zephyr-7b-alpha-sharded"
|
22 |
+
#https://huggingface.co/anakin87/zephyr-7b-alpha-sharded
|
23 |
+
|
24 |
+
#HuggingFaceH4/zephyr-7b-alpha
|
25 |
+
#https://huggingface.co/HuggingFaceH4/zephyr-7b-alpha
|
26 |
+
|
27 |
+
# function for loading 4-bit quantized model
|
28 |
+
def load_quantized_model(model_name: str):
|
29 |
+
"""
|
30 |
+
:param model_name: Name or path of the model to be loaded.
|
31 |
+
:return: Loaded quantized model.
|
32 |
+
"""
|
33 |
+
bnb_config = BitsAndBytesConfig(
|
34 |
+
load_in_4bit=True,
|
35 |
+
bnb_4bit_use_double_quant=True,
|
36 |
+
bnb_4bit_quant_type="nf4",
|
37 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
38 |
+
)
|
39 |
+
|
40 |
+
model = AutoModelForCausalLM.from_pretrained(
|
41 |
+
model_name,
|
42 |
+
load_in_4bit=True,
|
43 |
+
torch_dtype=torch.bfloat16,
|
44 |
+
quantization_config=bnb_config
|
45 |
+
)
|
46 |
+
return model
|
47 |
+
|
48 |
+
# fucntion for initializing tokenizer
|
49 |
+
def initialize_tokenizer(model_name: str):
|
50 |
+
"""
|
51 |
+
Initialize the tokenizer with the specified model_name.
|
52 |
+
|
53 |
+
:param model_name: Name or path of the model for tokenizer initialization.
|
54 |
+
:return: Initialized tokenizer.
|
55 |
+
"""
|
56 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
57 |
+
tokenizer.bos_token_id = 1 # Set beginning of sentence token id
|
58 |
+
return tokenizer
|
59 |
+
|
60 |
+
|
61 |
|