Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 4 |
from peft import PeftModel
|
| 5 |
from threading import Thread
|
| 6 |
|
| 7 |
-
# 1. Map both coordinates
|
| 8 |
BASE_MODEL = "Qwen/Qwen2.5-Coder-3B-Instruct"
|
| 9 |
ADAPTER_MODEL = "Cydercoder/qwen2.5-coder-3b"
|
| 10 |
|
| 11 |
print("Loading official base tokenizer...")
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
| 13 |
|
| 14 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
BASE_MODEL,
|
| 17 |
-
|
| 18 |
-
device_map="
|
| 19 |
)
|
| 20 |
|
| 21 |
print("Merging your custom fine-tuned engineering weights...")
|
| 22 |
-
# This layers your specialized tasks right over the active model architecture
|
| 23 |
model = PeftModel.from_pretrained(base_model, ADAPTER_MODEL)
|
| 24 |
|
| 25 |
def chat_function(message, history):
|
|
@@ -54,7 +64,7 @@ def chat_function(message, history):
|
|
| 54 |
demo = gr.ChatInterface(
|
| 55 |
fn=chat_function,
|
| 56 |
title="🤖 Cydercoder Qwen 3B AI Chatbot",
|
| 57 |
-
description="Your custom fine-tuned assistant running
|
| 58 |
examples=["Write a login form using React and Tailwind.", "Fix this code error: Cannot read properties of undefined"]
|
| 59 |
)
|
| 60 |
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer, BitsAndBytesConfig
|
| 5 |
from peft import PeftModel
|
| 6 |
from threading import Thread
|
| 7 |
|
| 8 |
+
# 1. Map both coordinates
|
| 9 |
BASE_MODEL = "Qwen/Qwen2.5-Coder-3B-Instruct"
|
| 10 |
ADAPTER_MODEL = "Cydercoder/qwen2.5-coder-3b"
|
| 11 |
|
| 12 |
print("Loading official base tokenizer...")
|
| 13 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
| 14 |
|
| 15 |
+
print("Configuring aggressive 4-bit CPU/GPU quantization parameters...")
|
| 16 |
+
# This config compresses the weights from 32-bit down to 4-bit integers to fit in RAM
|
| 17 |
+
quantization_config = BitsAndBytesConfig(
|
| 18 |
+
load_in_4bit=True,
|
| 19 |
+
bnb_4bit_compute_dtype=torch.float32,
|
| 20 |
+
bnb_4bit_quant_type="nf4",
|
| 21 |
+
bnb_4bit_use_double_quant=True,
|
| 22 |
+
llm_int8_enable_fp32_cpu_offload=True # Crucial fallback for free CPU spaces
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
print("Loading compressed base model...")
|
| 26 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 27 |
BASE_MODEL,
|
| 28 |
+
quantization_config=quantization_config,
|
| 29 |
+
device_map="auto"
|
| 30 |
)
|
| 31 |
|
| 32 |
print("Merging your custom fine-tuned engineering weights...")
|
|
|
|
| 33 |
model = PeftModel.from_pretrained(base_model, ADAPTER_MODEL)
|
| 34 |
|
| 35 |
def chat_function(message, history):
|
|
|
|
| 64 |
demo = gr.ChatInterface(
|
| 65 |
fn=chat_function,
|
| 66 |
title="🤖 Cydercoder Qwen 3B AI Chatbot",
|
| 67 |
+
description="Your custom fine-tuned assistant running compressed for speed in the cloud.",
|
| 68 |
examples=["Write a login form using React and Tailwind.", "Fix this code error: Cannot read properties of undefined"]
|
| 69 |
)
|
| 70 |
|