feat(p1g): device policy GPU/CPU paramétrable pour la cascade vision
resolve_device(auto/cuda/cpu) avec garde-fou VRAM et fallback CPU propre.
Bascule EasyOCR/SoM/docTR sur GPU si VRAM libre, rollback env sans toucher au code.
- core/gpu/device_policy.py (nouveau) : resolve_device + garde-fou VRAM (max_total_gb)
- core/detection/som_engine.py, core/llm/ocr_extractor.py,
agent_v0/server_v1/resolve_engine.py : câblage device auto (35 lignes)
- tests/unit/test_device_policy.py : 15 tests (verts venv réel)
Rollback sans toucher au code : RPA_VISION_DEVICE=cpu (force CPU global) / RPA_EASYOCR_GPU=0.
Bench GPU réel (latence) + activation large après verdict Qwen. QG Qwen deja valide sur le patch.
Mergé depuis worktree agent-a4f390f410e00ad7c (base 5b2afa362), 3 fichiers cibles non modifiés
dans le principal (zéro écrasement), dry-run apply propre.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,14 +25,24 @@ _easyocr_reader = None
|
||||
def easyocr_gpu_enabled(default: bool = False) -> bool:
|
||||
"""Return whether EasyOCR may allocate GPU memory.
|
||||
|
||||
The replay server shares the GPU with Ollama. Defaulting EasyOCR to CPU
|
||||
keeps VRAM available for the VLM; set RPA_EASYOCR_GPU=1 only for a measured
|
||||
OCR benchmark or a runtime that has spare VRAM.
|
||||
Priorité :
|
||||
1. RPA_EASYOCR_GPU explicite (1/0) → décision forcée, compat héritée.
|
||||
2. Sinon, délègue à core.gpu.device_policy.resolve_device("auto") :
|
||||
GPU autorisé uniquement si la VRAM locale est libre (les VLM tournent
|
||||
désormais sur DGX distant, ~9 Go libres localement). Garde-fou VRAM
|
||||
intégré ; fallback CPU propre si pas de GPU.
|
||||
|
||||
`default` n'est utilisé que si la résolution échoue (sécurité).
|
||||
"""
|
||||
raw = os.getenv("RPA_EASYOCR_GPU", "")
|
||||
if not raw:
|
||||
if raw:
|
||||
return raw.strip().lower() in {"1", "true", "yes", "on"}
|
||||
try:
|
||||
from core.gpu.device_policy import resolve_device
|
||||
return resolve_device("auto") == "cuda"
|
||||
except Exception as e: # pragma: no cover - fallback prudent
|
||||
logger.debug("easyocr_gpu_enabled: resolve_device a échoué (%s)", e)
|
||||
return default
|
||||
return raw.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
def _get_reader():
|
||||
|
||||
Reference in New Issue
Block a user