Update reviewed server files: deployment/space/generation.py, deployment/space/app.py
Browse files- deployment/space/app.py +1 -1
- deployment/space/generation.py +10 -5
deployment/space/app.py
CHANGED
|
@@ -233,7 +233,7 @@ def assistant(inspection_id: str, question: str, session: str, token: str='', wo
|
|
| 233 |
@server.get('/api/health')
|
| 234 |
def health():
|
| 235 |
return {'data':{'status':'ok','mode':'cloud_session_workspace','models':list(CARDS.values()),
|
| 236 |
-
'encoder_configured':True,'llm_model':'
|
| 237 |
'staff_persistence_enabled':CLOUD_CONFIG is not None,
|
| 238 |
'community_gallery_enabled':GALLERY is not None,
|
| 239 |
'personal_workspace_enabled':PERSONAL_ENABLED,
|
|
|
|
| 233 |
@server.get('/api/health')
|
| 234 |
def health():
|
| 235 |
return {'data':{'status':'ok','mode':'cloud_session_workspace','models':list(CARDS.values()),
|
| 236 |
+
'encoder_configured':True,'llm_model':'Qwen2.5-3B-Instruct fine-tuned for DefectRAG (QLoRA, merged)' if WORKFLOW and ZERO else 'Qwen2.5:3b (local Ollama)' if WORKFLOW else 'generation migration in progress','zero_gpu':ZERO,
|
| 237 |
'staff_persistence_enabled':CLOUD_CONFIG is not None,
|
| 238 |
'community_gallery_enabled':GALLERY is not None,
|
| 239 |
'personal_workspace_enabled':PERSONAL_ENABLED,
|
deployment/space/generation.py
CHANGED
|
@@ -53,14 +53,19 @@ class CpuBGE(Embeddings):
|
|
| 53 |
return self.embed_documents(['Represent this sentence for searching relevant passages: '+text])[0]
|
| 54 |
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
TOKENIZER=None
|
| 59 |
MODEL=None
|
| 60 |
if os.getenv('SPACES_ZERO_GPU')=='1' and os.getenv('DEFECTRAG_LIVE_RAG')=='1':
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
dtype=torch.bfloat16,attn_implementation='sdpa').eval().to('cuda')
|
| 65 |
MODEL.requires_grad_(False)
|
| 66 |
|
|
|
|
| 53 |
return self.embed_documents(['Represent this sentence for searching relevant passages: '+text])[0]
|
| 54 |
|
| 55 |
|
| 56 |
+
# Fine-tuned Qwen2.5-3B-Instruct (QLoRA adapter merged into the base weights, bf16, about 6 GB).
|
| 57 |
+
# Results: docs/QWEN_FINETUNING_RESULTS.md. Improved using Qwen (Qwen Research License, non-commercial).
|
| 58 |
+
MODEL_ID=os.getenv('DEFECTRAG_MODEL_ID','Wizzas/defectrag-qwen2.5-3b-evidence')
|
| 59 |
+
REVISION=os.getenv('DEFECTRAG_MODEL_REVISION','e6308fa8d6428895403d62e6ba77bcf6555a540d') # pinned upload commit
|
| 60 |
+
HF_TOKEN=os.getenv('HF_TOKEN') # Space secret; needed while the model repo is private
|
| 61 |
TOKENIZER=None
|
| 62 |
MODEL=None
|
| 63 |
if os.getenv('SPACES_ZERO_GPU')=='1' and os.getenv('DEFECTRAG_LIVE_RAG')=='1':
|
| 64 |
+
if not REVISION:
|
| 65 |
+
raise RuntimeError('Set DEFECTRAG_MODEL_REVISION to the pinned commit of the fine-tuned model')
|
| 66 |
+
# Download/cache in the Space only. Never place another 6 GB on the laptop.
|
| 67 |
+
TOKENIZER=AutoTokenizer.from_pretrained(MODEL_ID,revision=REVISION,token=HF_TOKEN)
|
| 68 |
+
MODEL=AutoModelForCausalLM.from_pretrained(MODEL_ID,revision=REVISION,token=HF_TOKEN,
|
| 69 |
dtype=torch.bfloat16,attn_implementation='sdpa').eval().to('cuda')
|
| 70 |
MODEL.requires_grad_(False)
|
| 71 |
|