+
    jHàjjn  ã                  ó´  a € 0 t $ R t^ RIHt ^ RIHt ^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ]P0                  ! ]4      tRNtROtR	tRNtR
tRPt RQt!Rt"Rt#^t$Rt%RRt&Rt'Rs(R])R&   ]	PT                  ! R4      t+R R lt,]-! 0 RSm4      t.R R lt/R R lt0R t1R R lt2Rs3R])R&   R R lt4R R  lt5Rs6R!])R"&   R#t7]73R$ R% llt8R& R' lt9R( t:R) R* lt;R+ R, lt</ t=R-])R.&   R/R0/R1 R2 llt>R3 R4 lt?R5R6R7RR8R9/R: R; llt@RTR< R= lltAR> R? ltBRUR@ RA lltCRURB RC lltDRD RE ltERF RG ltFRHR0/RI RJ lltGRK^ /RL RM lltHR# )Vu”  Live hardware budget probe.

Budget-source rule: discrete cards may trust the device query (measured honest within rounding);
unified-memory devices must budget from OS free physical memory minus headroom â€” their device
queries have been observed off by 3x in both directions. Every probe here must work under a
stripped PATH â€” gateway and service sessions don't inherit the interactive environment.
)Úannotations)ÚsuppressN)Úreplace)ÚPath©ÚGGML_DEVICE_GPU)ÚHardwareBudget)Ú	gpu_classg
×£p=
·?gš™™™™™É?g      ø?g      è?iÞ  g      N@z3tuple[float, tuple[int, bool | None] | None] | NoneÚ_pool_probe_cachez/CUDA\d+:.*\((\d+)\s*MiB,\s*\d+\s*MiB free\)\s*$c               ó    € V ^8„  d   QhRRRR/# )é   ÚargvÚstrÚreturn© )Úformats   "ÚF/home/ubuntu/.hermes/hermes-agent/hermes_cli/local_runtime/hardware.pyÚ__annotate__r   I   s   € ÷ ñ �3ð ˜3ñ ó    c            
     ób   € \         P                  ! \        V 4      R R RR^RR7      P                  # )Túutf-8r   F)Úcapture_outputÚtextÚencodingÚerrorsÚtimeoutÚcheck)Ú
subprocessÚrunÚlistÚstdout)r   s   *r   Ú_stdoutr!   I   s/   € Ü�>Š>ÜˆT‹
 4¨d¸WÈYÐ`aØô÷ �fðr   c               ó   € V ^8„  d   QhRR/# ©r   r   z
str | Noner   )r   s   "r   r   r   S   s   € ÷ ñ ˜Zñ r   c                 ó^   €  \        R4      P                  RR7      #   \         d     R# i ; i)z6Raw /proc/meminfo, or None when procfs cannot be read.z/proc/meminfor   )r   N)r   Ú	read_textÚOSErrorr   r   r   Ú_linux_meminfo_textr'   S   s2   € ðÜ�OÓ$×.Ñ.¸Ð.Ó@Ð@øÜô Úðús   ‚ �,«,c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   ztuple[int, int] | Noner   )r   s   "r   r   r   [   s   € ÷  ñ   #ð  Ð*@ñ  r   c                ó  € / p V P                  4        Fw  pVP                  R4      w  r4pV'       d   V\        9  d   K,  VP                  4       p\	        V4      ^8w  g   V^,          R8w  d   K\  \        V^ ,          4      R,          W&   Ky  	  VP                  R4      pRV9   d   VR,          pMVP                  R4      pVe   V^ 8:  g   Ve   ^ Tu;8:  d
   V8:  g    R#  R# Wx3#   \        \        \        3 d     R# i ; i)u1  (total, available) from meminfo text, or None if it cannot be trusted.

MemAvailable includes reclaimable page cache, which ``getconf _AVPHYS_PAGES``
counts as used. Kernels that omit MemAvailable fall back to MemFree. Zero is
a real available value â€” a missing-field check must not treat it as absent.
Ú:ÚkBi   ÚMemTotalÚMemAvailableÚMemFreeN)
Ú
splitlinesÚ	partitionÚ_LINUX_RAM_KEYSÚsplitÚlenÚintÚgetÚAttributeErrorÚ	TypeErrorÚ
ValueError)	r   ÚfieldsÚlineÚnameÚ	separatorÚvalueÚpartsÚtotalÚ	availables	   &        r   Ú_linux_ram_from_meminforA   [   só   € ð  €FðØ—O‘OÖ%ˆDØ%)§^¡^°CÓ%8Ñ"ˆD˜Uß ¬OÔ ;ÙØ—K‘K“MˆEÜ�5‹z˜QŒ %¨¥(¨dÔ"2ÙÜ˜u Q�x›=¨4Õ/ˆF‹Lñ &ð —
‘
˜:Ó&ˆà˜VÔ#Ø˜~Õ.‰IàŸ
™
 9Ó-ˆIàŠMØ˜ŒzØÒ Ø˜	Ö* UÕ*áð +áØÐÐøÜœI¤zÐ2ô Úðús   „CC) Ã#C) Ã&C) Ã)DÄDc                 ó$  a€ ^ RI o ! V3R lRSP                  4      p  V ! 4       pSP                  V 4      Vn        SP                  P
                  P                  SP                  V4      4      '       g   R# V#   \        \        3 d     R# i ; i)z*GlobalMemoryStatusEx, or None off Windows.Nc                  ó¢   <€ ] tR t^‚tR ZP                  3R ZP                  3.R U u. uF  q SP
                  3NK  	  up ,           tRtR# u up i )Ú._windows_memory_status.<locals>.MEMORYSTATUSEXÚdwLengthÚdwMemoryLoadr   N)ÚullTotalPhysÚullAvailPhysÚullTotalPageFileÚullAvailPageFileÚullTotalVirtualÚullAvailVirtualÚullAvailExtendedVirtual)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Úc_ulongÚc_ulonglongÚ_fields_Ú__static_attributes__)r;   Úctypess   0€r   ÚMEMORYSTATUSEXrD   ‚   sW   ø† Ø ¡&§.¡.Ð1°NÁFÇNÁNÐ3SÐTñ?Yó Zñ ?Y°d˜f×0Ñ0Ó1ñ ?Yñ ZõZŒùòZs   ©ArW   )
rV   Ú	StructureÚsizeofrE   ÚwindllÚkernel32ÚGlobalMemoryStatusExÚbyrefr6   r&   )rW   ÚstatrV   s     @r   Ú_windows_memory_statusr_   ~   sz   ø€ ã÷[˜×)Ñ)ô [ðÙÓˆØŸ™ nÓ5ˆŒØ�}‰}×%Ñ%×:Ñ:¸6¿<¹<ÈÓ;M×NÒNÙØˆøÜœGÐ$ô Úðús   ŸAA: Á8A: Á:BÂBc               ó   € V ^8„  d   QhRR/# )r   r   ztuple[int, int]r   )r   s   "r   r   r   ’   s   € ÷ 'ñ '�Oñ 'r   c                 óv  aa	€ \        4       p V e   V P                  V P                  3#  \        P                  R8X  dÔ   \        \        RRR4      P                  4       ;'       g    ^ 4      pV^ 8:  d   R# V^,          p\        \        \        4      ;_uu_ 4        \        R4      o	\        P                  ! RS	4      pV'       d   \        VP                  ^4      4      MRp\        VV	3R	 lR 4       4      pV^ 8”  d	   WT,          pRRR4       W3# \        P                  P                  R
4      '       d    \!        4       pVe   \#        V4      pVe   V# \        \        RR4      ;'       g    R4      p\        \        RR4      ;'       g    ^ 4      V,          pV^,          p\        \        \        4      ;_uu_ 4        \        \        RR4      ;'       g    ^ 4      V,          ;'       g    TpRRR4       W3#   + '       g   i     Lý; i  + '       g   i     L&; i  \        \        3 d    Ru # i ; i)z:(total, available) physical memory, cross-platform stdlib.NÚdarwinz/usr/sbin/sysctlz-nz
hw.memsizez/usr/bin/vm_statzpage size of (\d+)i @  c              3  ó    <"  € T FC  p\         P                  ! V R 2S4      ;o'       g   K'  \        SP                  ^4      4      x € KE  	  R# 5i)z:\s+(\d+)\.N)ÚreÚsearchr4   Úgroup)Ú.0ÚkeyÚmÚouts   & €€r   Ú	<genexpr>Ú_ram_bytes.<locals>.<genexpr>¥   sL   øé € ð Dñ 8\°äŸYšY¨3¨%¨{Ð';¸SÓAÐA˜ÓAô ,œC §¡¨£
ŸO˜Oó 8\ùs
   ƒ$A¬"AÚlinuxÚgetconfÚ	PAGE_SIZEi   Ú_PHYS_PAGESÚ_AVPHYS_PAGES)é    rr   )z
Pages freezPages inactivezPages purgeablezPages speculative)r_   rG   rH   ÚsysÚplatformr4   r!   Ústripr   r&   r8   rd   re   rf   ÚsumÚ
startswithr'   rA   )
r^   r?   ÚavailÚpage_mÚpageÚpagesÚmeminfoÚ	linux_ramri   rj   s
           @@r   Ú
_ram_bytesr~   ’   sØ  ù€ ä!Ó#€DØÒØ× Ñ  $×"3Ñ"3Ð3Ð3ð"Ü�<‰<˜8Ô#ô œÐ 2°D¸,ÓG×MÑMÓO×TÐTÐSTÓUˆEØ˜ŒzØ�Ø˜Q•JˆEÜœ'¤:×.Õ.ÜÐ0Ó1�ÜŸšÐ#8¸#Ó>�ß/5”s˜6Ÿ<™<¨›?Ô+¸5�ô õ Dñ 8\ó Dó D�ð ˜1”9Ø!�L�E÷ /ð �<ÐÜ�<‰<×"Ñ" 7×+Ò+Ü)Ó+ˆGØÒ"Ü3°GÓ<�	ØÒ(Ø$Ð$ä”7˜9 kÓ2×:Ð:°dÓ;ˆÜ”G˜I }Ó5×:Ð:¸Ó;¸dÕBˆØ˜•
ˆÜ”gœz×*Õ*Üœ 	¨?Ó;×@Ð@¸qÓAÀDÕH×QÐQÈEˆE÷ +àˆ|Ð÷1 /×.ú÷, +×*ûô ”ZÐ ô ØŠðúsr   ª;H" Á&H" Á6%H" ÂA,G<Ä
H" Ä$H" Ä7H" ÅH" Å.H" Æ3H" Ç -HÇ.HÇ1
H" Ç<H	ÈH" ÈH	ÈH" È"H8È7H8ztuple[str | None] | NoneÚ_smi_path_cachec               ó   € V ^8„  d   QhRR/# r#   r   )r   s   "r   r   r   Â   s   € ÷ ñ ˜*ñ r   c                 óT  € \         e   \         ^ ,          # \        P                  ! R4      p V f¡   \        P                  R8X  dŒ   \        P
                  P                  RR4      p\        V4      R,          R,          \        \        P
                  P                  RR	4      4      R
,          R,          R,          3p\        R V 4       R4      p MUV fR   \        P                  P                  R4      '       d-   \        R4      pVP                  4       '       d   \        V4      p V 3s V # )z‰Absolute path to nvidia-smi, or None. PATH first (respects user overrides), then the
driver's known install locations on Windows and WSL.Nz
nvidia-smiÚntÚ
SystemRootz
C:\WindowsÚSystem32znvidia-smi.exeÚProgramFileszC:\Program FileszNVIDIA CorporationÚNVSMIc              3  óf   "  € T F'  qP                  4       '       g   K  \        V4      x € K)  	  R # 5i)N)Úexistsr   )rg   Úcs   & r   rk   Ú#_nvidia_smi_path.<locals>.<genexpr>Ò   s   é € Ð?¡j ·H±H·J”f”c˜!—f�f£jùs   ‚1ž1rm   z/usr/lib/wsl/lib/nvidia-smi)r   ÚshutilÚwhichÚosr;   Úenvironr5   r   Únextrs   rt   rw   rˆ   r   )ÚfoundÚwindirÚ
candidatesÚ	candidates       r   Ú_nvidia_smi_pathr”   Â   sð   € ô Ò"Ü˜qÕ!Ð!Ü�LŠL˜Ó&€EØ‚}œŸ™ DœÜ—‘—‘ ¨mÓ<ˆô �‹L˜:Õ%Ð(8Õ8ä”—‘—‘ Ð0CÓDÓEØ"õ#Ø%,õ-Ø/?õ@ð	
ˆ
ô Ñ?¡jÓ?ÀÓF‰Ø	Šœ3Ÿ<™<×2Ñ2°7×;Ò;ô Ð6Ó7ˆ	Ø×Ñ×ÒÜ˜	“NˆEØ�h€OØ€Lr   c               ó   € V ^8„  d   QhRR/# )r   r   z'tuple[int, int, str, int | None] | Noner   )r   s   "r   r   r   Ý   s   € ÷ añ aÐ=ñ ar   c                 óv   € \        4       p V f   R# V R,          V R,          V R,          V P                  R4      3# )zb(total bytes, free bytes, name, optional packed PCI ID) from the shared nvidia-smi query, or None.NÚtotal_bytesÚ
free_bytesÚgpu_nameÚ
gpu_pci_id)Ú_cached_nvidia_gpu_queryr5   )Úquerys    r   Ú_nvidia_vramr�   Ý   s:   € ä$Ó&€EØ‚}ÙØ�Õ  |Õ!4°e¸JÕ6GÈÏÉÐS_ÓI`Ð`Ð`r   z tuple[float, dict | None] | NoneÚ_gpu_query_cacheg      @c               ó    € V ^8„  d   QhRRRR/# )r   Úttl_sÚfloatr   údict | Noner   )r   s   "r   r   r   î   s   € ÷ +ñ + Eð +Àñ +r   c                óò  € \         P                  ! 4       p\        e'   V\        ^ ,          ,
          V 8  d   \        ^,          # \        4       pVf   VR3sR# ^ RIHp \        \        \        \        P                  4      ;_uu_ 4        \        P                  ! VRR.RRRR^
V! 4       RR	7      pVP                  ^ 8w  g!   VP                  P                  4       '       g   VR3s RRR4       R# \        \         P"                  ! VP                  P                  4       P%                  4       RR
7      4      w  rVrxršRp\        \        4      ;_uu_ 4        \'        V^4      pRRR4       RVP                  4       R\'        V4      ^,          R\'        V4      ^,          R\'        V	4      ^,          R\'        V
4      RV/pW3sVuuRRR4       #   + '       g   i     Lt; i  + '       g   i     M; iTR3sR# )uB  One nvidia-smi read shared by the budget probe and the hardware endpoint.

Returns ``dict(gpu_name=, total_bytes=, free_bytes=, used_bytes=, gpu_util_percent=,
gpu_pci_id=)`` or None when nvidia-smi is absent, fails, or is not an NVIDIA card.
Cached for ``ttl_s`` (failures too â€” a missing smi must not spawn per poll).
N)Úwindows_hide_flagszS--query-gpu=memory.total,memory.free,name,pci.device_id,memory.used,utilization.gpuz--format=csv,noheader,nounitsTr   r   F)r   r   r   r   r   Úcreationflagsr   )Úskipinitialspacer™   r—   r˜   Ú
used_bytesÚgpu_util_percentrš   )ÚtimeÚ	monotonicrž   r”   Úhermes_cli._subprocess_compatr¤   r   r&   r8   r   ÚTimeoutExpiredr   Ú
returncoder    ru   r�   ÚcsvÚreaderr/   r4   )r    ÚnowÚexer¤   rj   Ú	total_mibÚfree_mibr;   Úraw_idÚused_mibÚutilÚpci_idÚdatas   &            r   r›   r›   î   s¨  € ô �.Š.Ó
€CÜÒ#¨Ô.>¸qÕ.AÕ(AÀEÔ(IÜ Õ"Ð"ä
Ó
€CØ
‚{Ø ˜;ÐÙå@Ü	”'œ:¤z×'@Ñ'@×	AÕ	AÜ�nŠnØÐgØ,ð.à d°WÀYÐXZÙ,Ó.°eô	=ˆð
 �>‰>˜QÔ c§j¡j×&6Ñ&6×&8Ò&8Ø # T˜{ÐØ÷ 
BÑ	Aô =AÜ�JŠJ�s—z‘z×'Ñ'Ó)×4Ñ4Ó6ÈÔNó=PÑ9ˆ	˜T¨8àˆÜ”j×!Õ!Ü˜ “_ˆF÷ "ð ˜Ÿ
™
›Øœ3˜y›>¨RÕ/Øœ#˜h›-¨2Õ-Øœ#˜h›-¨2Õ-Ø¤ D£	Ø˜&ð
ˆð  ˜;ÐØ÷/ 
BÒ	A÷ "×!ú÷ 
B×	Aúð0 ˜T�{ÐÙs3   Â	AG Ã!G Ã0A$G ÅG	Å!A!G ÇGÇG Ç G0	c               ó   € V ^8„  d   QhRR/# ©r   r   ztuple[int, bool | None] | Noner   )r   s   "r   r   r     s   € ÷ ñ Ð9ñ r   c                 ó8  € ^ RI p R F  p V P                  V4      p M	  R# \        \        \        4      ;_uu_ 4        VP                  ^ 4      ^ 8w  d    RRR4       R# V P                  4       pVP                  V P                  V4      ^ 4      ^ 8w  d    RRR4       R# V P                  4       p\        VRR4      ;'       g    VP                  pV! V P                  V4      V4      ^ 8w  g   VP                  ^ 8:  d    RRR4       R# RpV P                  4       pVP                  V P                  V4      \        V4      ^ 8X  d   \        VP                  4      pVP                  V3uuRRR4       #   \         d     EK}  i ; i  + '       g   i     R# ; i)uD  (allocator_total_bytes, integrated_or_None) from the CUDA driver API via ctypes against the
driver's own DLL/SO â€” no toolkit, no subprocess, ~ms. INTEGRATED is the vendor's own
unified-memory declaration; total is the pool the allocator will actually hand out (on
carve-out devices, several times what nvidia-smi reports).NÚcuDeviceTotalMem_v2)z
nvcuda.dllzlibcuda.so.1z
libcuda.so)rV   ÚCDLLr&   r   r6   ÚcuInitÚc_intÚcuDeviceGetr]   Úc_size_tÚgetattrÚcuDeviceTotalMemr=   ÚcuDeviceGetAttributeÚ_CU_DEVICE_ATTRIBUTE_INTEGRATEDÚbool)rV   r;   ÚcudaÚdevr?   ÚgetterÚ
integratedÚattrs           r   Ú_cuda_driver_poolrÌ     sb  € ó
 ã<ˆð	Ø—;‘;˜tÓ$ˆDÙñ =ñ Ü	”'œ>×	*Õ	*Ø�;‰;�q‹>˜QÔØ÷ 
+Ñ	*ð �l‰l‹nˆØ×Ñ˜FŸL™L¨Ó-¨qÓ1°QÔ6Ø÷ 
+Ñ	*ð —‘Ó!ˆÜ˜Ð4°dÓ;×TÐT¸t×?TÑ?TˆÙ�&—,‘,˜uÓ% sÓ+¨qÔ0°E·K±KÀ1Ô4DØ÷ 
+Ñ	*ð #'ˆ
Ø�|‰|‹~ˆØ×$Ñ$Ø—‘˜TÓ"Ô$CÀSóJØMNôOä˜dŸj™jÓ)ˆJØ�{‰{˜JÐ&÷ 
+Ò	*øô	 ô 	Ûð	ú÷ 
+Ö	*ñ  ús5   ‹E5¾FÁ 7FÂ!#FÃ<FÄAFÅ5FÆFÆF	c                 óÂ   € ^ RI Hp  ^ RIHp ^ RIHp V! 4       pVe   V# V ! 4       P                  R4      ;'       g    / pT! VP                  R4      ;'       g    R4      # )z�The engine the probes below run: the managed server's own when one is up or booting, else
the installed engine for ``local_runtime.backend``.©Úload_config_readonly)Úinstalled_engine)Úserving_engineÚlocal_runtimeÚbackendÚauto)Úhermes_cli.configrÏ   Ú!hermes_cli.local_runtime.binariesrÐ   Ú"hermes_cli.local_runtime.bootstraprÑ   r5   )rÏ   rÐ   rÑ   ÚengineÚsections        r   Ú_configured_enginerÚ   >  sW   € õ 7ÝBÝAáÓ€FØÒØˆÙ"Ó$×(Ñ(¨Ó9×?Ð?¸R€GÙ˜GŸK™K¨	Ó2×<Ð<°fÓ=Ð=r   c               ó   € V ^8„  d   QhRR/# rº   r   )r   s   "r   r   r   L  s   € ÷ ñ Ð;ñ r   c                 ód  € \        \        4      ;_uu_ 4        \        4       p V f    RRR4       R# V P                  p\        P
                  ! \        V4      R.RRRR^\        VP                  4      RR7      pVP                  ^ 8w  d    RRR4       R# VP                  VP                  ,           P                  4        FO  p\        P                  V4      pV'       g   K"  \        VP                  ^4      4      ^,          R3u uuRRR4       # 	  RRR4       R#   + '       g   i     R# ; i)uð   (engine_total_bytes, None) from the installed runtime's own --list-devices, or None. The
fallback when the driver API is unreachable: asks the exact binary that will do the
allocating. Carries no integrated verdict â€” callers must gate it.Nz--list-devicesTr   r   F)r   r   r   r   r   Úcwdr   )r   Ú	ExceptionrÚ   Úbinaryr   r   r   Úparentr­   r    Ústderrr/   Ú_DEVICE_LINE_REre   r4   rf   )rØ   r±   rj   r:   ri   s        r   Ú_engine_device_poolrã   L  sõ   € ô 
”)×	Õ	Ü#Ó%ˆØŠ>Ø÷ 
Ñ	ð �m‰mˆÜ�nŠnœc #›hÐ(8Ð9È$Ø"&°ÀÐTVÔ\_Ð`c×`jÑ`jÓ\kÐsxôzˆà�>‰>˜QÔØ÷ 
Ñ	ð —Z‘Z #§*¡*Õ,×8Ñ8Ö:ˆDÜ×&Ñ& tÓ,ˆAß‰qÜ˜1Ÿ7™7 1›:“¨"Õ,¨dÐ2Ñ2÷ 
Ò	ñ ;÷ 
ñ ÷ 
Ö	ñ ús$   ˜D²ADÂADÃ#$DÄDÄD/	c               ó   € V ^8„  d   QhRR/# rº   r   )r   s   "r   r   r   `  s   € ÷ ñ Ð9ñ r   c                 ó¼   € \         P                  ! 4       p \        e    \        w  rVf   W,
          \        8  d   V# \	        4       ;'       g    \        4       pW3sV# )z¯Best available allocator-side view, cached: a hit is permanent for the process, a miss
retries after a short TTL (the engine binary can appear mid-session via a pane install).)r©   rª   r
   Ú_POOL_NEGATIVE_TTL_SrÌ   rã   )r°   ÚstampÚviews      r   Ú_device_pool_viewré   `  sS   € ô �.Š.Ó
€CÜÒ$Ü'‰ˆØÒ˜s�{Ô-AÔAØˆKÜÓ×7Ð7Ô"5Ó"7€DØ˜ÐØ€Kr   z$dict[str, tuple[float, dict | None]]Ú_accelerator_cacheÚfreshFc               ó    € V ^8„  d   QhRRRR/# )r   rë   rÆ   r   r¢   r   )r   s   "r   r   r   q  s   € ÷ ñ  $ð °;ñ r   c                óZ  € \        \        4      ;_uu_ 4        ^ RIHp \	        4       pVe   VP
                  \        9  d    RRR4       R# \        VP                  4      \        P                  ! 4       rC\        P                  V4      pV '       g;   Ve7   V^,          f   WE^ ,          ,
          \        8  d   V^,          uuRRR4       # V! VP                  P                  VP
                  4      p\        VR RR7      pWG3\        V&   VuuRRR4       #   + '       g   i     R# ; i)aû  The device a Vulkan/HIP engine will place layers on, or None (no such engine, probe miss).

Mirrors llama.cpp's own placement: discrete devices whenever one exists, an integrated one only
otherwise; among discrete devices the largest. Cached per engine binary like
``_device_pool_view`` (a hit lasts the process, a miss retries after the TTL): the hardware
endpoint polls this every few seconds and each probe initializes the GPU driver. ``fresh`` skips
the cache read for a launch-time free-memory answer.
)Úprobe_devicesNc                ó4   € V R ,          \         8H  V R,          3# )Útyper?   r   )Úds   &r   Ú<lambda>Ú%_accelerator_device.<locals>.<lambda>…  s   € ¨Q¨v­Y¼/Ñ-IÈ1ÈWÍ:Ñ,Vr   )rh   Údefault)r   rÞ   Ú hermes_cli.local_runtime.devicesrî   rÚ   rÓ   Ú_GPU_ENGINE_BACKENDSr   rß   r©   rª   rê   r5   ræ   rà   Úmax)rë   rî   rØ   rh   r°   ÚcachedÚdevicesÚdevices   $       r   Ú_accelerator_devicerû   q  sß   € ô 
”)×	Õ	ÝBä#Ó%ˆØŠ>˜VŸ^™^Ô3GÔGØ÷ 
Ñ	ô �v—}‘}Ó%¤t§~¢~Ó'7ˆSÜ#×'Ñ'¨Ó,ˆß˜Ò+°¸µÒ1FÈ#ÐWXÕPYÍ/Ô\pÔJpØ˜!•9÷ 
Ò	ñ   §¡× 4Ñ 4°f·n±nÓEˆÜ�WÑ"VÐ`dÔeˆØ#& -Ô˜3ÑØ÷ 
×	×	Ñ	ñ ús   ˜+DÁA5DÃADÄD*	c               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú	smi_totalr4   Ú	ram_totalr   ú
int | Noner   )r   s   "r   r   r   ‹  s!   € ÷ ñ  3ð °3ð ¸:ñ r   c                óÚ   € \        4       pVf   R# Vw  r4Ve   V'       d   V# R# V ^ 8”  d@   V\        V \        ,          4      8¼  d%   V^ 8”  d   V\        V\        ,          4      8¼  d   V# R# )a  The real pool size when this NVIDIA device is unified memory behind a carve-out, else None.

The driver's INTEGRATED attribute decides in BOTH directions when readable; only the
attribute-less engine fallback needs the two numeric gates, both of which must hold.
N)ré   r4   Ú_POOL_DISAGREEMENT_FACTORÚ_POOL_RAM_FRACTION)rý   rþ   rè   ÚpoolrÊ   s   &&   r   Ú_unified_pool_bytesr  ‹  si   € ô Ó€DØ‚|ÙØÑ€DØÒß!ˆtÐ+ tÐ+Ø�AŒ˜$¤# iÔ2KÕ&KÓ"LÔLØ˜A” $¬#¨iÔ:LÕ.LÓ*MÔ"MØˆÙr   r™   Ú rš   Ú
lazy_readsTc               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )r   Úbaser4   r?   r™   r   rš   rÿ   r  rÆ   r   r   r   )r   s   "r   r   r   �  sA   € ÷ Hñ H�cð H #ð H°Cð HØ&ðHØ;?ðHØKYñHr   c               óŽ   € \        ^ \        V ^\        ,
          ,          4      4      p\        WQ^ RV\        P
                  W4R7      # )rr   T)Úusable_vram_bytesÚtotal_device_bytesÚram_available_bytesÚumar™   rt   rš   r  )r÷   r4   Ú_UMA_HEADROOM_FRACTIONr   rs   rt   )r  r?   r™   rš   r  Úusables   &&$$$ r   Ú_uma_budgetr  �  sB   € ä�”C˜ Ô$:Õ :Õ;Ó<Ó=€FÜ¨FØ./°TÀHÔWZ×WcÑWcØ%/ôHð Hr   c               ó    € V ^8„  d   QhRRRR/# )r   Ú	own_bytesr4   r   rÿ   r   )r   s   "r   r   r   ¥  s   € ÷ Kñ K Cð K°
ñ Kr   c                ó  € \        4       pVe   VP                  '       g   R# \        \        \	        VP
                  \        ,          4      4      p\        ^ \	        VP                  4      \        ^ V 4      ,           V,
          4      # )a¨  Commit the managed server may take on Windows right now, or None off Windows.

Windows charges every GPU allocation to commit: the RAM Windows can see plus the page file.
Memory carved out for the GPU is invisible to Windows, so a bigger carve-out leaves less
commit for the model it was meant to hold. ``own_bytes`` is what the managed server holds now
and frees before the new instance loads. A desktop margin stays free.
N)r_   rI   r÷   Ú_MARGIN_FLOORr4   rG   Ú_MARGIN_FRACTIONrJ   )r  r^   Úmargins   &  r   Ú_windows_commit_roomr  ¥  se   € ô "Ó#€DØ‚|˜4×0×0Ð0ÙÜ”¤ D×$5Ñ$5Ô8HÕ$HÓ IÓJ€FÜˆq”#�d×+Ñ+Ó,¬s°1°iÓ/@Õ@À6ÕIÓJÐJr   c               ó    € V ^8„  d   QhRRRR/# )r   Úmodel_bytesr4   r   r   )r   s   "r   r   r   ´  s   € ÷ ;ñ ; Cð ;¨Cñ ;r   c                ó<   € \        V ^\        ,
          ,          4      # )z�What Windows charges to commit for a model estimated at ``model_bytes`` of device memory:
the estimate runs ~20% under the charge, which is the UMA headroom.)r4   r  )r  s   &r   Úmodel_commit_bytesr  ´  s   € ô ˆ{˜aÔ"8Õ8Õ9Ó:Ð:r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   ÚliveúHardwareBudget | Noner  r4   Ú	residentsr   rÿ   r   )r   s   "r   r   r   º  s+   € ÷ 6ñ 6Ð2ð 6Àð 6ÐQTð 6Ð]gñ 6r   c           	     óè   € V e   V P                   MRpVe   V^ 8:  d   R# \        ^V4      p\        V4      p\        \        \        ^ W2V,          ,
          4      V,          4      pV\
        8¼  d   V# ^ # )a~  Size for llama-server's prompt cache beside a model of ``model_bytes`` (the estimate the
window was planned with), or None when the engine default applies.

Windows unified memory only: each loaded model's cache comes out of the same commit as the
models, so each of the ``residents`` models the router may hold at once (its ``--models-max``)
gets an even share of what they leave.
N)Úcommit_room_bytesr÷   r  ÚminÚ_PROMPT_CACHE_MAXÚ_PROMPT_CACHE_MIN)r  r  r  ÚroomÚmodel_commitÚcaches   &&&   r   Úprompt_cache_bytesr(  º  so   € ð &*Ò%5ˆ4×!Ò!¸4€DØ‚|�{ aÔ'ÙÜ�A�yÓ!€IÜ% kÓ2€LÜÔ!¤3 q¨$¸\Õ1IÕ*IÓ#JÈiÕ#WÓX€EØÔ.Ô.ˆ5Ð5°AÐ5r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r  r   r  r4   r   r   )r   s   "r   r   r   Ë  s&   € ÷ Zñ Z ^ð ZÀð ZÈCñ Zr   c                óÈ   € V P                   \        ^V4      ,          \        ,
          p\        V P                  \        ^ \        V^\        ,
          ,          4      4      4      # )z·Device memory a model may plan with on Windows unified memory and still leave each of the
``residents`` models the smallest useful prompt cache: the inverse of ``prompt_cache_bytes``.)r!  r÷   r$  r"  r
  r4   r  )r  r  Úshares   && r   Úusable_beside_prompt_cacher,  Ë  sK   € ð ×"Ñ"¤c¨!¨YÓ&7Õ7Ô:KÕK€EÜˆt×%Ñ%¤s¨1¬c°%¸1Ô?UÕ;UÕ2VÓ.WÓ'XÓYÐYr   c               ó   € V ^8„  d   QhRR/# )r   r   rÆ   r   )r   s   "r   r   r   Ò  s   € ÷ ñ  Dñ r   c                 ól  € \        \        4      ;_uu_ 4        \        4       p V e   V P                  \        9   uuRRR4       # ^ RIHp ^ RIHp V! 4       P                  R4      ;'       g    / pT! VP                  R4      ;'       g    R4      \        9   uuRRR4       #   + '       g   i     R# ; i)zµWhether a Vulkan/HIP engine runs the model: the serving or installed engine, else the one
setup would install for ``local_runtime.backend``. False when the engine can't be resolved.NrÎ   )Úresolve_backendrÒ   rÓ   rÔ   F)
r   rÞ   rÚ   rÓ   rö   rÕ   rÏ   rÖ   r/  r5   )rØ   rÏ   r/  rÙ   s       r   Ú_gpu_engine_runs_the_modelr0  Ò  sˆ   € ô 
”)×	Õ	Ü#Ó%ˆØÒØ—>‘>Ô%9Ñ9÷ 
Ò	õ 	;ÝEá&Ó(×,Ñ,¨_Ó=×CÐCÀˆÙ˜wŸ{™{¨9Ó5×?Ð?¸Ó@ÔDXÑX÷ 
×	×	Ñ	ñ ús   ˜!B"Á(B"Á-B"Â
B"Â"B3	c               ó    € V ^8„  d   QhRRRR/# )r   rú   r¢   r   rÿ   r   )r   s   "r   r   r   á  s   € ÷ &ñ & ð &°
ñ &r   c                ó´  € ^ RI Hp V! 4        Uu. uF  q"P                  '       d   K  VNK  	  ppV Uu. uF$  q f   K  VP                  V R,          8X  g   K"  VNK&  	  ppT;'       g)    V Uu. uF  q"P                  \
        8w  g   K  VNK  	  upp\        V4      ^8w  g   V f   \        4       '       g   R# V^ ,          P                  # u upi u upi u upi )aÈ  What Windows lets the integrated GPU allocate (Task Manager's GPU memory), or None.

The adapter is the one the engine named, else the only non-NVIDIA hardware adapter when a
Vulkan/HIP engine will run the model; the CPU engine (chosen, or the only build for a Snapdragon)
keeps the model in system RAM. Not the engine's own figure: ggml-vulkan sums every memory heap
of an integrated GPU, host-visible ones included, so it can exceed what Windows grants.
)Úwindows_gpu_adaptersNÚdescription)	Ú!hermes_platform.host.gpu_adaptersr3  Úsoftwarer4  Ú	vendor_idÚ_NVIDIA_VENDOR_IDr3   r0  Úmemory_bytes)rú   r3  ÚaÚhardwareÚnamedr’   s   &     r   Ú_windows_igpu_bytesr=  á  s°   € õ Gá/Ô1ÓDÑ1�a¿½—�Ñ1€HÐDÙ Ób™�1ŒQ¸1¿=¹=ÈFÐS`ÕLaÑ;a�QˆQ™€EÐbØ×SÐS¡hÓS¡h ·+±+ÔARÑ2RŸ1˜1¡hÑS€JÜ
ˆ:ƒ˜!Ô ¢Ô7Q×7SÒ7SÙØ�a�=×%Ñ%Ð%ùò EùÚbùÚSs&   �C¨C´C¾CÁCÁ.CÂ	CÚplanningc               ó    € V ^8„  d   QhRRRR/# )r   r>  rÆ   r   r   r   )r   s   "r   r   r   ó  s   € ÷ 9fñ 9f˜dð 9f¨~ñ 9fr   c           
     óR  € \        4       w  r\        4       p\        V'       d
   V^ ,          M^ V4      pVe¨   \        P	                  RV\
        ,          V'       d   V^ ,          \
        ,          R R2MR4       V '       d   TpM%V'       d   V^,          V,           MTp\        WF4      p\        YTV'       d
   V^,          MRV'       d   V^,          R7      # RR7      # VfÙ   \        4       pVe€   VR,          \        8X  dn   VR	,          p\        \        \        V\        ,          4      4      p	\        \        ^ W‰,
          4      TV '       d   TMTR
VR,          \        P                   R7      # \        T\#        V4      ;'       g    T4      p
\        V '       d   T
M
\        W¢4      V
\%        4       R9  R7      # Vw  r‹rÍ\        \        \        V\        ,          4      4      p	\        \        ^ V '       d   TMTV	,
          4      TV '       d   TMTR
V\        P                   VR7      # )uˆ  Construct the budget per the source rules above.

``planning=False``: LIVE budget (free VRAM now) for launch-time fit and growth re-grants.
``planning=True``: CAPACITY budget (total minus margin) for catalog pricing and quant
selection â€” pricing against live-free while a model was loaded made every row read as too
large. The managed server unloads/relaunches itself, so capacity is real.
Nziunified-memory NVIDIA device: allocator pool %.1f GiB (nvidia-smi carve-out: %s); budgeting from the poolz.1fz GiBÚunavailabler  )r™   rš   rð   r?   Fr4  )r
  r  r  r  r™   rt   )r  )r
  r  r  r  r™   rt   rš   )ÚamdÚintel)r~   r�   r  ÚloggerÚinfoÚ_GIBr"  r  rû   r   r÷   r  r4   r  r   rs   rt   r=  r	   )r>  rþ   Ú	ram_availÚvramÚunifiedr  r  rú   r?   r  r  Úfreer™   rš   s   $             r   Úprobe_budgetrK  ó  sÙ  € ô &›<Ñ€IÜ‹>€Dô "¯T $ q¦'°q¸)ÓD€GØÒÜ�‰ðBà”d�Nß+/ˆt�A�wœ�~˜cÐ" $Ñ'°]ô		D÷
 Ø‰D÷
 -1�D˜•G˜iÖ'°iˆDÜ�wÓ%ˆDÜ˜4¿d°4¸¶7Èß15 d¨1¥gôAð 	AØ;?ôAð 	Að ‚|Ü$Ó&ˆØÒ &¨¥.´OÔ"Cð ˜7•OˆEÜœ¬¨EÔ4DÕ,DÓ(EÓFˆFÜ!´C¸¸5½>Ó4JÐ_dßCK±iÐQZØ&+°f¸]Õ6KÔVY×VbÑVbôdð dô �9Ô1°&Ó9×FÐF¸YÓGˆÜ§8™4´°TÓ1EÀtÜ&/£kÐ9IÑ&IôKð 	Kð )-Ñ%€E�Ü”¤ EÔ,<Õ$<Ó =Ó>€FÜ¬C°¿X±EÈ4ÐSYÕ3YÓ,ZØ-2ß;C©iÈØ#¨hÄÇÁÐZdôfð fr   r  c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úcapacityr   r  r4   r   r  r   )r   s   "r   r   r   /  s"   € ÷  7ñ  7˜Nð  7¸#ð  7ÐF[ñ  7r   c               óR  € V P                   '       db   \        V^ 8”  d   \        V4      M^ 4      pVf   R# \        V P                  \        V^\        ,
          ,          4      4      p\        WVR7      # \        4       pVe   V^ ,          V^,          reM5\        RR7      pVe   VR,          \        8w  d   R# VR,          VR,          re\        ^ WV,
          \        ^ V4      ,
          4      p\        V P                  \        ^ WX,
          \        ,
          4      4      p\        WR7      # )	aì  Capacity less what other programs hold on the card right now, or None when that can't apply.

Capacity assumes other programs hold no more than the fixed margin. Beside a heavier desktop the
capacity-sized window doesn't fit, and Windows pages part of the model to host memory without
an error: a 32 GiB card with 4.5-6.3 GiB held by other apps decoded at ~24 tok/s at the
capacity window, and at ~90 tok/s at a window sized from free memory.

``own_bytes`` is the device-memory estimate of what the managed server holds now and frees
before the new instance loads. A stopped server's memory reads as free by the time its process
has exited (measured on Windows: free memory was fully back at the first reading after exit).
Unified memory: free commit on Windows (the model and its prompt cache must fit there), with
``own_bytes`` converted to the commit Windows charged for it, else None (its live budget is
already free memory). None too when the device query fails, so callers keep the capacity plan.
N)r
  r!  T)rë   rð   r?   rJ  )r
  )r  r  r  r"  r
  r4   r  r   r�   rû   r   r÷   Ú_LAUNCH_HEADROOM)	rM  r  r%  r  rH  r?   rJ  rú   Úotherss	   &$       r   Úlaunch_budgetrQ  /  sî   € ð ‡|‡|€|Ü#ÀYÐQRÄ]Ô$6°yÔ$AÐXYÓZˆØŠ<ÙÜ�X×/Ñ/´°T¸QÔAWÕ=WÕ5XÓ1YÓZˆÜ�xÈTÔRÐRÜ‹>€DØÒØ˜1•g˜t A�w‰tô %¨4Ô0ˆØŠ>˜V F�^¬Ô>ÙØ˜W•o v¨f¥~ˆtÜ��E•L¤3 q¨)Ó#4Õ4Ó5€FÜ�×+Ñ+¬S°°EµNÔEUÕ4UÓ-VÓW€FÜ�8Ô6Ð6r   i   @l        l        i    )ÚvulkanÚhip>   r.   r,   r-   )rr   )é   )IÚ__conditional_annotations__Ú__doc__Ú
__future__r   Ú
contextlibr   r®   Úloggingr�   rd   r‹   r   rs   r©   Údataclassesr   Úpathlibr   rõ   r   Ú"hermes_cli.local_runtime.estimatorr   Úhermes_platform.host.factsr	   Ú	getLoggerrN   rD  rF  r  r  rO  r  r#  r$  r  r  rÅ   r8  rö   ræ   r
   Ú__annotations__Úcompilerâ   r!   Ú	frozensetr1   r'   rA   r_   r~   r   r”   r�   rž   Ú_GPU_QUERY_TTL_Sr›   rÌ   rÚ   rã   ré   rê   rû   r  r  r  r  r(  r,  r0  r=  rK  rQ  )rU  s   @r   Ú<module>rc     s¶  øðôõ #å Û 
Û Û 	Û 	Û Û Û 
Û Ý Ý å <Ý =Ý 0à	×	Ò	˜8Ó	$€à€ð €ØÐ ð Ð ð Ð ð Ð ØÐ ð  Ð ØÐ ð #%Ð ØÐ à(Ð ð Ð ØIMÐ ÐFÓ Mð —*’*ÐOÓP€õñ ÒCÓD€õõ òFõ('ðZ -1€Ð)Ó 0õõ6að 6:Ð Ð2Ó 9ð Ð ð -=÷ +õ\òD>õõ(ð <>Ð Ð8Ó =ð¨÷ õ4ð$H¸"ð HØ)-ðHØBF÷H÷Kõ;÷6÷"Zõõ&ð$9f U÷ 9fðx 7À÷  7ñ  7r   