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:
Dom
2026-06-08 15:20:52 +02:00
parent d00fe7b00b
commit 0e215da842
5 changed files with 337 additions and 9 deletions

View File

@@ -1648,6 +1648,15 @@ def _resolve_by_ocr_text(
reco_arch='crnn_vgg16_bn',
pretrained=True,
)
# Device paramétrable avec garde-fou VRAM (VLM sur DGX distant).
# cuda si VRAM locale libre, cpu sinon — jamais de hardcode cuda.
try:
from core.gpu.device_policy import resolve_device
if resolve_device("auto") == "cuda":
_V4_OCR_PREDICTOR = _V4_OCR_PREDICTOR.cuda()
logger.info("docTR V4 OCR chargé sur cuda")
except Exception as e:
logger.debug("docTR V4 OCR reste sur CPU (%s)", e)
doc = DocumentFile.from_images([screenshot_path])
result = _V4_OCR_PREDICTOR(doc)