hardware
zocrates.rag.hardware ¶
System hardware profiler and isolated Hugging Face embedding model validator.
DeviceLike ¶
Bases: Protocol
Protocol representing a PyTorch device-like object.
SystemHardwareInfo
dataclass
¶
System hardware diagnostic information.
to_dict ¶
Serialize hardware info to a JSON-serializable dict.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys |
dict[str, Any]
|
|
Source code in zocrates/rag/hardware.py
_detect_amd_sysfs ¶
Detect AMD GPU via Linux sysfs (/sys/class/drm/card* or /sys/bus/pci/drivers/amdgpu).
Returns:
| Type | Description |
|---|---|
tuple[str, float | None] | None
|
2-tuple of (gpu_name, vram_gb) if an AMD GPU is found, None otherwise. |
Source code in zocrates/rag/hardware.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
_detect_best_device ¶
Return the optimal torch device to use for local embedding inference.
Opportunistically probes CUDA and Apple Silicon MPS with a lightweight tensor sanity probe. Gracefully falls back to CPU if probes fail or no GPU accelerator is available.
Returns:
| Type | Description |
|---|---|
DeviceLike
|
A |
Source code in zocrates/rag/hardware.py
_detect_intel_sysfs ¶
Detect Intel GPU via Linux sysfs (/sys/class/drm/card* or /sys/bus/pci/devices/*).
Returns:
| Type | Description |
|---|---|
tuple[str, float | None] | None
|
2-tuple of (gpu_name, vram_gb) if an Intel GPU is found, None otherwise. |
Source code in zocrates/rag/hardware.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
_detect_nvidia_pci ¶
Check /sys/bus/pci/devices/* for an NVIDIA display controller (vendor 0x10de, class 0x03*).
Returns:
| Type | Description |
|---|---|
bool
|
True if an NVIDIA display controller is found, False otherwise. |
Source code in zocrates/rag/hardware.py
_detect_nvidia_procfs ¶
Read NVIDIA GPU model from /proc/driver/nvidia/gpus/*/information.
Returns:
| Type | Description |
|---|---|
str | None
|
Parsed model string (e.g. 'NVIDIA GeForce MX250') if found, None otherwise. |
Source code in zocrates/rag/hardware.py
_detect_nvidia_torch ¶
Attempt to detect NVIDIA GPU properties using PyTorch CUDA runtime.
Returns:
| Type | Description |
|---|---|
tuple[str, float, float] | None
|
3-tuple of (gpu_name, vram_gb, compute_capability) if CUDA is available |
tuple[str, float, float] | None
|
and at least one device is found, None otherwise. |
Source code in zocrates/rag/hardware.py
_is_cuda_functional ¶
Check in an isolated subprocess whether CUDA hardware execution works on this system.
If the first CUDA test fails, automatically invokes setup_torch.main()
to install the matching PyTorch CUDA build, then re-tests.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Source code in zocrates/rag/hardware.py
get_docling_hardware_assessment ¶
Assess system hardware capacity and recommend optimal local Docling configuration.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys |
dict[str, Any]
|
|
Source code in zocrates/rag/hardware.py
get_system_hardware_info ¶
Probe system memory and GPU accelerator information.
Caches result in memory to prevent repeated subprocess calls during server runtime.
Checks, in priority order: Apple Silicon MPS, NVIDIA via nvidia-smi or
PyTorch / procfs / sysfs fallback, AMD via rocm-smi or sysfs fallback,
Intel via xpu-smi or sysfs fallback, then falls back to CPU-only.
Returns:
| Type | Description |
|---|---|
SystemHardwareInfo
|
A |
SystemHardwareInfo
|
GPU name, VRAM, and compute capability ( |
Source code in zocrates/rag/hardware.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
get_system_ram_gb ¶
Return total system RAM in gigabytes.
Attempts to read RAM via psutil first, then falls back to parsing
/proc/meminfo. Returns 8.0 as a safe default if both methods fail.
Returns:
| Type | Description |
|---|---|
float
|
Total RAM in GiB, rounded to two decimal places. |
Source code in zocrates/rag/hardware.py
is_high_performance_gpu ¶
Check if the system possesses a high-performance GPU suitable for deep learning formula VLM.
Returns True if
- NVIDIA GPU with >= 6.0 GB VRAM
- Apple Silicon (MPS) with >= 16.0 GB unified RAM
- Other verified GPU with >= 6.0 GB VRAM
Returns:
| Type | Description |
|---|---|
bool
|
True if high-performance GPU is available, False otherwise. |
Source code in zocrates/rag/hardware.py
validate_model_compatibility ¶
Run an isolated subprocess test to load and encode a test string with the model.
Spawns a fresh Python process to avoid polluting the caller's GPU memory state and to enforce a wall-clock timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Hugging Face model identifier (e.g.
|
required |
timeout_seconds
|
int
|
Maximum seconds to wait for the subprocess. |
100
|
Returns:
| Type | Description |
|---|---|
bool
|
A 2-tuple of |
str
|
|