Spaces:
Runtime error
Runtime error
Rename app.py to compress.py
Browse files- app.py +0 -19
- compress.py +18 -0
app.py
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
!pip install langchain
|
2 |
-
import langchain
|
3 |
-
|
4 |
-
import streamlit as st
|
5 |
-
from langchain.embeddings import OpenAIEmbeddings
|
6 |
-
|
7 |
-
# Load model from HF Spaces
|
8 |
-
model = OpenAIEmbeddings(model_name="PyaeSoneK/legalQAcustom")
|
9 |
-
|
10 |
-
# Streamlit UI
|
11 |
-
st.header("Seon's Legal QA for Dummies")
|
12 |
-
input_text = st.text_input("Give me your wildest legal thoughts:")
|
13 |
-
|
14 |
-
if st.button("Generate"):
|
15 |
-
# Get embeddings
|
16 |
-
embeddings = model(input_text)
|
17 |
-
|
18 |
-
# Display results
|
19 |
-
st.write(embeddings)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compress.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
+
|
4 |
+
# Load model
|
5 |
+
model = AutoModelForCausalLM.from_pretrained("PyaeSoneK/LlamaV2LegalFineTuned")
|
6 |
+
|
7 |
+
# Compress model...
|
8 |
+
|
9 |
+
# Pruning
|
10 |
+
import torchprune as prune
|
11 |
+
pruned_model = prune.ln_structured(model, amount=0.3)
|
12 |
+
|
13 |
+
# Quantization
|
14 |
+
from torchquant import quantize
|
15 |
+
quantized_model = quantize(pruned_model, dtype=torch.qint8)
|
16 |
+
|
17 |
+
# Export smaller model
|
18 |
+
quantized_model.save_pretrained("/path/to/smaller_model")
|