-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
43 lines (31 loc) · 1.1 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import torch
import chainlit
from utils_for_app import load_fine_tune_model, generate_ft
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load fine-tuned model and tokenizer
print(f"Loading finetuned model ...")
base_model_id = "meta-llama/Llama-3.2-1B-Instruct"
lora_weights = "LLAMA32_ft_python_code.pth"
model_ft, tokenizer = load_fine_tune_model(base_model_id, lora_weights)
total_params=sum(p.numel() for p in model_ft.parameters())
trainable_params=sum(p.numel() for p in model_ft.parameters() if p.requires_grad)
print(f"Total parameters: {total_params:,}")
print(f"Trainable parameters: {trainable_params:,}")
@chainlit.on_message
async def main(message: chainlit.Message):
"""
The main Chainlit function.
"""
torch.manual_seed(123)
prompt = message.content
response = generate_ft(
model=model_ft,
prompt=prompt,
tokenizer=tokenizer,
max_new_tokens=256,
temperature=0.8,
top_k=5
)
await chainlit.Message(
content=f"{response}", # This returns the model response to the interface
).send()