acsaco commited on
Commit
7d94962
·
verified ·
1 Parent(s): 523047d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -9,34 +9,22 @@ from fastapi import FastAPI
9
  from fastapi.responses import StreamingResponse
10
  from pydantic import BaseModel
11
  from typing import List, Optional, Dict
12
- from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer, AwqConfig
 
13
  from threading import Thread
14
  import gradio as gr
15
 
16
- # Desactivar kernels Marlin incompatibles con el init en CPU de ZeroGPU
17
- os.environ["GPTQMODEL_DISABLE_MARLIN"] = "1"
18
- os.environ["AUTOAWQ_USE_MARLIN"] = "0"
19
-
20
  MODEL_ID = "Qwen/Qwen2.5-Coder-32B-Instruct-AWQ"
21
 
22
- # Cargar Tokenizer
23
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
24
 
25
- # Forzar backend GEMM estándar de AWQ para evitar fallos de repacking en CPU
26
- quant_config = AwqConfig(
27
- bits=4,
28
- version="gemm",
29
- fuse_max_seq_len=4096,
30
- do_fuse=False
31
- )
32
-
33
- # Cargar modelo en modo device_map="auto" compatible con ZeroGPU
34
- model = AutoModelForCausalLM.from_pretrained(
35
  MODEL_ID,
36
- dtype=torch.float16,
37
- quantization_config=quant_config,
38
- device_map="auto",
39
- trust_remote_code=True
40
  )
41
 
42
  app = FastAPI(title="Qwen2.5-Coder-32B OpenAI API")
 
9
  from fastapi.responses import StreamingResponse
10
  from pydantic import BaseModel
11
  from typing import List, Optional, Dict
12
+ from transformers import AutoTokenizer, TextIteratorStreamer
13
+ from awq import AutoAWQForCausalLM
14
  from threading import Thread
15
  import gradio as gr
16
 
 
 
 
 
17
  MODEL_ID = "Qwen/Qwen2.5-Coder-32B-Instruct-AWQ"
18
 
19
+ # 1. Cargar Tokenizer
20
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
21
 
22
+ # 2. Cargar modelo directamente con AutoAWQ
23
+ model = AutoAWQForCausalLM.from_quantized(
 
 
 
 
 
 
 
 
24
  MODEL_ID,
25
+ fuse_layers=True,
26
+ trust_remote_code=True,
27
+ safetensors=True
 
28
  )
29
 
30
  app = FastAPI(title="Qwen2.5-Coder-32B OpenAI API")