Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,23 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# Custom device map: Place most layers on GPU, offload rest to CPU
|
| 14 |
-
device_map = {
|
| 15 |
-
"transformer": "cuda", # Main layers on GPU
|
| 16 |
-
"lm_head": "cpu" # Output layer to CPU
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 20 |
-
model_name,
|
| 21 |
-
load_in_4bit=True,
|
| 22 |
-
device_map=device_map,
|
| 23 |
-
llm_int8_enable_fp32_cpu_offload=True, # Enable CPU offloading
|
| 24 |
-
torch_dtype=torch.float16, # Reduce memory with FP16
|
| 25 |
-
trust_remote_code=True
|
| 26 |
)
|
| 27 |
|
| 28 |
def chat(message, history):
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
history.append((message, response))
|
| 36 |
return history, ""
|
| 37 |
|
| 38 |
demo = gr.ChatInterface(chat)
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from llama_cpp import Llama
|
|
|
|
| 4 |
|
| 5 |
+
# No cache redirect needed for GGUF
|
| 6 |
+
model_path = "Qwen/Qwen2.5-Coder-14B-Instruct-GGUF" # Auto-downloads Q4_K_M (~9GB)
|
| 7 |
+
llm = Llama(
|
| 8 |
+
model_path,
|
| 9 |
+
n_ctx=4096, # Adjust for coding tasks
|
| 10 |
+
n_gpu_layers=99, # Offload to T4 GPU
|
| 11 |
+
verbose=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
)
|
| 13 |
|
| 14 |
def chat(message, history):
|
| 15 |
+
response = llm.create_chat_completion(
|
| 16 |
+
messages=[{"role": "user", "content": message}],
|
| 17 |
+
max_tokens=512,
|
| 18 |
+
temperature=0.7
|
| 19 |
+
)
|
| 20 |
+
history.append((message, response["choices"][0]["message"]["content"]))
|
|
|
|
| 21 |
return history, ""
|
| 22 |
|
| 23 |
demo = gr.ChatInterface(chat)
|