+
    QV-j”B  ã                   óò  € ^ RI t ^ RIt^ RIt^ RIt^ RIHtHt ^ RIHt ^RI	H
t
 ^RIHtHt ]! 4       '       d4   ^ RIt^ RIHt Rt]P$                  P'                  4       '       d   ^ RItRtMRt]
P*                  ! ]4      tR	 t]P2                  ! R
4      tR R ltR tRR R lltRR R lltR R ltR t ]P2                  ! R4      t!R t"R t#R R lt$R R R llt%]! R!R7      ]R"R R ll4       4       t&R# )#é    N)ÚcontextmanagerÚredirect_stdout)ÚStringIO)Úlogging)Úis_torch_availableÚrequires)Ú	save_fileFTc                 ó¨   € \         '       d%   \        P                  P                  4       '       g   R# \        P                  P	                  4       ^ 8H  # )z7Return True if rank=0 or we aren't running distributed.T)Ú_torch_distributed_availableÚtorchÚdistributedÚis_initializedÚget_rank© ó    Ús/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/model_debugging_utils.pyÚ_is_rank_zeror   ,   s9   € ç(Ó(¬U×->Ñ->×-MÑ-M×-OÒ-OÙÜ×Ñ×%Ñ%Ó'¨1Ñ,Ð,r   zobject at 0x[0-9A-Fa-f]+c                ó0   € V ^8„  d   QhR\         R\         /# )é   Úx_strÚreturn©Ústr)Úformats   "r   Ú__annotate__r   6   s   € ÷ Cñ C¤3ð C¬3ñ Cr   c                ó.   € \         P                  RV 4      # )z�
Replace memory addresses in an object's repr with a stable placeholder
so that beautiful JSON diffs won't be ruined by ephemeral addresses.
zobject at 0xXXXXXXXX)ÚMEMORY_ADDRESS_REGEXÚsub)r   s   &r   Ú_sanitize_repr_for_diffr   6   s   € ô
  ×#Ñ#Ð$:¸EÓBÐBr   c                óV   € \        4       '       d   R\        V P                  4       2# R# )z@Return a stable string representation for a DTensor-like object.zDTensor (rank0) -> zDTensor(non-rank0))r   ÚreprÚ_local_tensor)Úxs   &r   Ú_dtensor_reprr$   >   s#   € ä‡‚Ø$¤T¨!¯/©/Ó%:Ð$;Ð<Ð<Ùr   c                óX   € V ^8„  d   QhR\         R,          R\        R\         R,          /# ©r   Ú
debug_pathNÚuse_reprÚpath_to_value©r   Úbool)r   s   "r   r   r   E   s.   € ÷ .ñ .Ü˜T•zð.Ü48ð.ÜPSÐVZÕPZñ.r   c                ó¬  € \         P                  ! RR7       V'       d   \        V 4      pM£V'       dˆ   VP                  R4      '       g
   VR,          pV'       d    \        P
                  P                  W4      MTp\        RV P                  4       P                  4       P                  4       /V4       RV 2pM\        RV: RV: R24      hR	\        V P                  4      R
\        V P                  4      RV/pV P                  \         P                  \         P                   \         P"                  09   dš   VP%                  R\'        \        V P)                  4       4      4      R\'        \        V P+                  4       4      4      R\'        \        V P-                  4       4      4      R\'        \        V P/                  4       4      4      /4       V# )aa  
Converts Tensors and DTensors to a JSON-serializable dictionary representation.

Args:
    value: Any Python object, often including torch Tensors, lists, dicts, etc.
    debug_path (`str`, *optional*, defaults to `None`): Directory to dump debug JSON and SafeTensors files.
    use_repr (bool, *optional*, defaults to `True`): Whether to save a `repr()`-ized version of the tensor as the
        `value` property in the asscoiated FULL_TENSORS.json file, or to store the full tensors in separate
        SafeTensors file and store the relative path to that file in the `value` property in the dictionary.
    path_to_value (`str`, *optional*, defaults to `None`): The file name for the SafeTensors file holding the full
        tensor value if `use_repr=False`.

Returns:
    A nested Python structure (list, dict, or sanitized string) that is safe to json.dump.
T)Úsci_modez.safetensorsÚdataz./z	use_repr=z and path_to_value=z cannot both be falsy.ÚshapeÚdtypeÚvalueÚmeanÚstdÚminÚmax)r   Úset_printoptionsÚ_repr_to_listÚendswithÚosÚpathÚjoinr	   Ú
contiguousÚdetachÚcpuÚ
ValueErrorr!   r/   r0   Úfloat16Úfloat32Úbfloat16Úupdater   r2   r3   r4   r5   )r1   r'   r(   r)   Ú	value_outÚfilepathÚouts   &&&&   r   Ú_serialize_tensor_like_iorG   E   sa  € ô$ 
×Ò DÕ)çÜ! %Ó(‰	ß	Ø×%Ñ% n×5Ò5Ø˜^Õ+ˆMç>H”2—7‘7—<‘< 
Ô:ÈmˆÜ�6˜5×+Ñ+Ó-×4Ñ4Ó6×:Ñ:Ó<Ð=¸xÔHØ˜˜Ð(‰	ä˜I˜H™;Ð&:¨MÑ+;Ð;QÐRÓSÐSð 	”�e—k‘kÓ"Ø”�e—k‘kÓ"Ø�ð€Cð
 ‡{�{”u—}‘}¤e§m¡m´U·^±^ÐDÔDØ�
‰
àÔ/´°U·Z±Z³\Ó0BÓCØÔ.¬t°E·I±I³KÓ/@ÓAØÔ.¬t°E·I±I³KÓ/@ÓAØÔ.¬t°E·I±I³KÓ/@ÓAð	ô	
ð €Jr   c                óX   € V ^8„  d   QhR\         R,          R\        R\         R,          /# r&   r*   )r   s   "r   r   r   v   s,   € ÷ (0ñ (0¤S¨4¥Zð (0Ä$ð (0Ô^aÐdhÕ^hñ (0r   c                ó  € \        V \        \        34      '       d0   \        V 4       UUu. uF  w  rE\	        WQW# RV 2R7      NK  	  upp# \        V \
        4      '       d6   V P                  4        UUu/ uF  w  reV\	        WQW# RV 2R7      bK  	  upp# \        V R4      '       d   \        V P                  WVR7      # \        V \        P                  4      '       d   \        WW#R7      # \        \        V 4      4      # u uppi u uppi )aR  
Recursively build a JSON-serializable Python structure from `value`.
Tensors and DTensors become either sanitized repr strings, or are saved to disk as SafeTensors files and their
relative paths are recorded in the returned Python structure.
Lists/tuples/dicts are recursed into.
All memory addresses are replaced with a stable placeholder.

Args:
    value: Any Python object, often including torch Tensors, lists, dicts, etc.
    debug_path (`str`, *optional*, defaults to `None`): Directory to dump debug JSON and SafeTensors files.
    use_repr (bool, *optional*, defaults to `True`): Whether to save a `repr()`-ized version of the tensors as the
        `value` property in the asscoiated FULL_TENSORS.json file, or to store full tensors in separate SafeTensors
        files and store the relative path to that file in the `value` property.
    path_to_value (`str`, *optional*, defaults to `None`): The file name for the SafeTensors file holding the full
        tensor value if `use_repr=False`.

Returns:
    A nested Python structure (list, dict, or sanitized string) that is safe to json.dump.
Ú_©r'   r(   r)   r"   )Ú
isinstanceÚlistÚtupleÚ	enumerateÚ_serialize_ioÚdictÚitemsÚhasattrrG   r"   r   ÚTensorr   r!   )r1   r'   r(   r)   ÚiÚvÚks   &&&&   r   rP   rP   v   s  € ô( �%œ$¤˜×'Ò'ô " %Ô(ô
á(‘�ô ˜!¸XÐWfÐfgÐhiÐgjÐUk×lÙ(ò
ð 	
ô
 �%œ×Òð Ÿ™œô
á%‘�ð Œ}˜QÀÐZiÐijÐklÐjmÐXnÔoÒoÙ%ò
ð 	
ô
 ˆu�o×&Ò&Ü(Ø×Ñ¨JÐYfô
ð 	
ô �%œŸ™×&Ò&Ü(¨ÐPXÔvÐvä"¤4¨£;Ó/Ð/ùó'
ùó
s   «DÁ5Dc                ó8   € V ^8„  d   QhR\         P                  /# )r   r1   )r   rT   )r   s   "r   r   r   ¡   s   € ÷ 5ñ 5œŸ™ñ 5r   c           	     óT  € \         P                  ! R^xR7       \        4       ;_uu_ 4       p\        V4      ;_uu_ 4        \	        V 4       VP                  4       pRRR4       RRR4       \        X4      P                  4       #   + '       g   i     L1; i  + '       g   i     L<; i)zË
Converts a tensor into a sanitized multi-line string representation.

Args:
    value (`torch.Tensor`): The tensor to represent.

Returns:
    `list[str]`: List of string lines representing the tensor.
T)r-   Ú	linewidthN)r   r6   r   r   ÚprintÚgetvaluer   Ú
splitlines)r1   ÚbufÚraws   &  r   r7   r7   ¡   sd   € ô 
×Ò D°CÕ8Ü	�Œ�sœO¨C×0Õ0ÜˆeŒØ�l‰l‹nˆ÷ 1�ô # 3Ó'×2Ñ2Ó4Ð4÷ 1×0ú��ús"   «B¿B	ÁBÂBÂBÂB'	c                 ó’   € V P                  R 4      '       d0   V P                  RR4       V R ,           F  p\        V4       K  	  R# R# )ÚchildrenÚoutputsN)ÚgetÚpopÚprune_outputs_if_children)ÚnodeÚchilds   & r   re   re   ²   s@   € ð ‡x�x�
×ÒØ�‰�˜DÔ!Ø˜*×%Ð%ˆEÜ% eÖ,ó &ñ r   z(.*)\.(\d+)$c                óB  a€ \         P                  V P                  RR4      4      pV'       d   V P                  R4      '       g   R# VP                  ^4      o\        ;QJ d&    V3R lV R,           4       F  '       g   K   R# 	  R# ! V3R lV R,           4       4      # )z¯
Checks whether a node represents a layer block with submodules.

Args:
    node (`dict`): A node from the call tree.

Returns:
    `bool`: Whether the node is a layer block.
Úmodule_pathÚ ra   Fc              3   óV   <"  € T F  pR S R 2VP                  RR4      9   x € K   	  R# 5i)Ú.ri   rj   N©rc   )Ú.0rg   Únumbers   & €r   Ú	<genexpr>Ú!is_layer_block.<locals>.<genexpr>Ì   s+   øé € Ð[ÑJZÀ��6�(˜!ˆ} §	¡	¨-¸Ó <Ö<ÓJZùs   ƒ&)T)ÚLAYER_SUFFIX_REÚmatchrc   ÚgroupÚany)rf   rs   ro   s   & @r   Úis_layer_blockrv   ¾   st   ø€ ô ×!Ñ! $§(¡(¨=¸"Ó"=Ó>€Eß˜Ÿ™ ×,Ò,ÙØ�[‰[˜‹^€Fß‹3Ô[È$ÈzÖJZÓ[�3Œ3Ð[Š3Ð[ˆ3Ô[È$ÈzÖJZÓ[Ó[Ð[r   c                ó¶  € V P                  R4      '       g   R# \        V R,          4       UUu. uF  w  r\        V4      '       g   K  W3NK  	  ppp\        V4      ^8”  dJ   V^R  UUu. uF  w  rVNK	  	  ppp\        V R,          4       UUu. uF  w  rW9  g   K  VNK  	  uppV R&   V R,           F  p\	        V4       K  	  R# u uppi u uppi u uppi )zä
Recursively removes intermediate layers from the tree to improve readability.
Keeps at least the first and last layers if many consecutive layers are present.

Args:
    node (`dict`): The root or subnode to prune recursively.
ra   Néÿÿÿÿ)rc   rO   rv   ÚlenÚprune_intermediate_layers)rf   rU   rg   Úlayer_blocksrJ   Ú	to_removes   &     r   rz   rz   Ï   sÇ   € ð �8‰8�J×ÒÙÜ/8¸¸jÕ9IÔ/JÔdÑ/J¡8 1ÌnÐ]b×Nc”J�Q“JÑ/J€LÑdä
ˆ<Ó˜1ÔØ#/°°"Ñ#5Ô6Ñ#5™4˜1“QÑ#5ˆ	Ñ6Ü2;¸DÀÕ<LÔ2MÔdÑ2M¡h aÐQRÑQcŸE˜EÑ2MÒdˆˆZÑà�j×!Ð!ˆÜ! %Ö(ó "ùó eùó 7ùÛds   ¯C	Á	C	Á+CÂ
CÂCc                ó2   € V ^8„  d   QhR\         R,          /# )r   r'   Nr   )r   s   "r   r   r   ã   s   € ÷ (*ñ (*¤c¨D¥jñ (*r   c                 óT  a€ V '       dK    \         P                  ! V R R7       \         P                  P                  WP                  R,           4      pMVP                  R,           p\        P                  RV R24       VR,           pVR	,           p\        VP                  4       \        VR
4      ;_uu_ 4       p\        P                  ! VP                  V^R7       RRR4       V3R lo\        P                  ! \        P                  ! VP                  4      4      pS! V4       \        VR
4      ;_uu_ 4       p\        P                  ! Wv^R7       RRR4       R#   \
         d   p\        RT  R24      ThRp?ii ; i  + '       g   i     L¬; i  + '       g   i     R# ; i)T©Úexist_okÚ_debug_treeú"Unexpected or existing debug_path=rl   NzWriting model trace at z.jsonz_FULL_TENSORS.jsonz_SUMMARY.jsonÚw)Úindentc                 ó¸   <a€ V3R  loS! V P                  R/ 4      4       S! V P                  R/ 4      4       V P                  R. 4       F  pS! V4       K  	  R# )c                 óì   <€ \        V \        4      '       d4   V P                  R R4       V P                  4        F  pS! V4       K  	  R# \        V \        4      '       d   V  F  pS! V4       K  	  R# R# )r1   N)rL   rQ   rd   ÚvaluesrM   )ÚvalrV   ÚitemÚcleans   &  €r   rŠ   Ú:log_model_debug_trace.<locals>.strip_values.<locals>.cleanø   sX   ø€ Ü˜#œt×$Ò$Ø—‘˜ Ô&ØŸ™ž�AÙ˜!–Hó &ä˜C¤×&Ò&Û�DÙ˜$–Kó  ñ 'r   Úinputsrb   ra   Nrm   )rf   rg   rŠ   Ústrip_valuess   & @€r   r�   Ú+log_model_debug_trace.<locals>.strip_values÷   sM   ù€ õ	 ñ 	ˆd�h‰h�x Ó$Ô%Ùˆd�h‰h�y "Ó%Ô&à—X‘X˜j¨"Ö-ˆEÙ˜Öó .r   )r9   Úmakedirsr:   r;   Ú_debugger_module_dump_nameÚ	Exceptionr?   ÚloggerÚinfore   Ú
_call_treeÚopenÚjsonÚdumpÚloadsÚdumps)	r'   ÚmodelÚbaseÚeÚ	full_pathÚsummary_pathÚfÚ	tree_copyr�   s	   &&      @r   Úlog_model_debug_tracer¡   ã   s?  ø€ ßð	XÜ�KŠK˜
¨TÕ2Ü—7‘7—<‘< 
×,LÑ,LÈ}Õ,\Ó]‰Dð ×/Ñ/°-Õ?ˆä
‡K�KÐ)¨$¨¨uÐ5Ô6ØÐ+Õ+€IØ˜/Õ)€Lä˜e×.Ñ.Ô/ä	ˆi˜×	Ô	 Ü�	Š	�%×"Ñ" A¨aÕ0÷ 
õ ô  —
’
œ4Ÿ:š: e×&6Ñ&6Ó7Ó8€IÙ�Ôä	ˆl˜C×	 Ô	  AÜ�	Š	�) qÕ)÷ 
!Ñ	 øôE ô 	XÜÐAÀ*ÀÈQÐOÓPÐVWÐWûð	Xú÷ 
×	ú÷. 
!×	 Ð	 ús0   ‹AE  Â;$FÄ=FÅ F Å+E;Å;F ÆF	ÆF'	c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r   r'   Údo_prune_layersr(   r*   )r   s   "r   r   r     s-   € ÷ |(ñ |(äð|(ô ð|(ô ñ	|(r   c                óÞ  a aaaa	a
€ S P                   P                  o	RS	RRRRR. /S n        . S n        S	S n        S'       d    \
        P                  ! SRR7       VV V3R
 lpS P                  4        F  w  rgVR8X  d   K  V! VS	 R	V 24       K  	  S P                  o
\        P                  ! S
4      V	VVV V
V3R l4       pVS n
        R#   \         d   p\        RS R	24      ThRp?ii ; i)a´  
Attaches a debugging wrapper to every module in the model.

This records structured inputs and outputs during the forward pass into a call tree.

Args:
    model (`PreTrainedModel`, `nn.Module`): Model to wrap.
    debug_path (`str`): Optional directory to dump debug JSON files.
    do_prune_layers (`bool`, *optional*, defaults to `True`): Whether to prune intermediate layers.
    use_repr (bool, *optional*, defaults to `True`): Whether to save a `repr()`-ized version of the tensors as the
        `value` property in the associated FULL_TENSORS.json file, or to store full tensors in separate SafeTensors
        files and store the relative path to that file in the `value` property.
ri   rŒ   Nrb   ra   Tr   r‚   rl   c                 ó|   <a aa€ S P                   o\        P                  ! S4      VVVV VV3R  l4       pVS n         R# )c            
      ó  <€ \        4       '       dl   R V RV/pV Uu/ uF$  p\        W#,          4      ^ 8”  g   K  W2V,          bK&  	  ppRSR\        VSSS R2R7      RRR. /pS	P                  P	                  V4       \
        P                  ! 4       ;_uu_ 4        S! V / VB pRRR4       \        4       '       d¶   \        R	 S
P                  4        4       4      ^ 8”  d   RXR&   M\        XSSS R
2R7      XR&   S	P                  P                  4       pVR,          '       g   VP                  R4       S	P                  '       d*   S	P                  R,          R,          P	                  V4       X# u upi   + '       g   i     LÜ; i)ÚargsÚkwargsri   rŒ   Ú_inputsrK   rb   Nra   c              3   ó&   "  € T F  p^x € K	  	  R# 5i)é   Nr   )rn   rJ   s   & r   rp   ÚX_attach_debugger_logic.<locals>.wrap_forward.<locals>.wrapped_forward.<locals>.<genexpr>F  s   é € Ð:Ñ"9˜Q•qÓ"9ùs   ‚Ú_outputsrx   )
r   ry   rP   Ú_debugger_model_call_stackÚappendr   Úno_gradÚsumÚnamed_childrenrd   )ÚinpsÚkwsÚdict_inputsrW   rf   rF   Úfinishedr'   r�   rš   ÚmoduleÚorig_forwardr(   s   *,     €€€€€€r   Úwrapped_forwardÚE_attach_debugger_logic.<locals>.wrap_forward.<locals>.wrapped_forward1  si  ø€ ä�ŠØ% t¨X°sÐ;�Ù:EÓa¹+°QÌÈ[Í^ÓI\Ð_`ÑI`Ô0˜q¨a¥.Ò0¹+�Ðaà! 9ØœmØ#Ø#-Ø!)Ø)2¨°7Ð&;ô	ð ˜tØ ð
�ð ×0Ñ0×7Ñ7¸Ô=Ü—’—•Ù" DÐ0¨CÑ0�÷ !ô �ŠÜÑ: &×"7Ñ"7Ô"9Ó:Ó:¸QÔ>Ø&*�D˜’Oä&3ØØ#-Ø!)Ø)2¨°8Ð&<ô	'�D˜‘Oð !×;Ñ;×?Ñ?ÓA�à 
×+Ô+Ø—L‘L Ô,à×3×3Ð3Ø×4Ñ4°RÕ8¸ÕD×KÑKÈHÔUØˆJùòE b÷ !—ús   œE2¹E2Â	E7Å7F	N)ÚforwardÚ	functoolsÚwraps)r·   r�   r¹   r¸   r'   rš   r(   s   ff @€€€r   Úwrap_forwardÚ,_attach_debugger_logic.<locals>.wrap_forward.  s6   û€ Ø—~‘~ˆä	�Š˜Ó	&÷%	ñ %	ó 
'ð%	ðN )ˆŽr   rj   c            
      ó  <€ \        4       '       d=   R S R2R\        RV RV/SSS R2R7      RRR	. /pS	P                  P                  V4       S
! V / VB p\        4       '       Ed   S	P                  '       Ed   \        VSSS R
2R7      XR&   S	P                  P	                  4       pVR,          S	P
                  R&   VR,          S	P
                  R&   VR	,          S	P
                  R	&   \        S	P
                  P                  4       4       Uu. uF:  pS	P
                  V,          '       d   K  S	P
                  P	                  VR4      NK<  	   pS'       d   \        S	P
                  4       \        SS	R7       V# u upi )ri   z (top-level)rŒ   r§   r¨   r©   rK   rb   Nra   r­   )r'   rš   )
r   rP   r®   r¯   rd   r”   rM   Úkeysrz   r¡   )r³   r´   Útop_noderF   r¶   rW   Ú
class_namer'   r£   rš   Úreal_top_forwardr(   s   *,    €€€€€€r   Útop_wrapped_forwardÚ3_attach_debugger_logic.<locals>.top_wrapped_forwardd  su  ø€ ä�?Š?à * ¨\Ð:Øœ-Ø˜T 8¨SÐ1Ø)Ø%Ø%/ L°Ð"8ô	ð ˜4Ø˜Bð
ˆHð ×,Ñ,×3Ñ3°HÔ=á Ð,¨Ñ,ˆÜ�?‹?˜u×?×?Ñ?Ü"/ØØ%Ø!Ø!+ ¨HÐ5ô	#ˆH�YÑð ×7Ñ7×;Ñ;Ó=ˆHØ)1°(Õ);ˆE×Ñ˜XÑ&Ø*2°9Õ*=ˆE×Ñ˜YÑ'Ø+3°JÕ+?ˆE×Ñ˜ZÑ(ä48¸×9IÑ9I×9NÑ9NÓ9PÔ4QÓmÑ4Q¨qÐY^×YiÑYiÐjk×YlÑYlÔ*ˆU×Ñ×!Ñ! ! TÖ*Ñ4QÑm÷ Ü)¨%×*:Ñ*:Ô;ä!¨Z¸uÕEØˆ
ùò ns   ÄE>Ä0 E>)Ú	__class__Ú__name__r”   r®   r�   r9   r�   r‘   r?   Únamed_modulesr»   r¼   r½   )rš   r'   r£   r(   rœ   r¾   ÚnameÚ	submodulerÅ   rÃ   rÄ   s   ffff     @@r   Ú_attach_debugger_logicrÌ     sø   ý€ ð& —‘×)Ñ)€Jð & z°8¸TÀ9ÈdÐT^Ð`bÐc€EÔØ')€EÔ$Ø'1€EÔ$çð	XÜ�KŠK˜
¨TÕ2÷+)ð\ !×.Ñ.Ö0‰ˆØ�2Œ:ÙÙ�Y : ,¨a°¨vÐ 6Ö7ñ 1ð —}‘}Ðä‡_‚_Ð%Ó&÷#ñ #ó 'ð#ðJ (€E†Møô ô 	XÜÐAÀ*ÀÈQÐOÓPÐVWÐWûð	Xús   ÁC ÃC,ÃC'Ã'C,)Úbackendsc                óJ   € V ^8„  d   QhR\         R,          R\        R\        /# )r   r'   Nr£   r(   r*   )r   s   "r   r   r   �  s,   € ÷ 85ñ 85ä�d•
ð85ô ð85ô ñ	85r   c              #  ó8  "  € V P                  4        UUu/ uF  w  rEWUP                  bK  	  pppV P                  W`&   \        WW#4        V x € VP                  4        F  w  rxW‡n        K  	  R# u uppi   TP                  4        F  w  rxY‡n        K  	  i ; i5i)a©  
# Model addition debugger - context manager for model adders
This context manager is a power user tool intended for model adders.

It tracks all forward calls within a model forward and logs a slice of each input and output on a nested JSON file.
If `use_repr=True` (the default), the JSON file will record a `repr()`-ized version of the tensors as a list of
strings. If `use_repr=False`, the full tensors will be stored in separate SafeTensors files and the JSON file will
provide a relative path to that file.

To note, this context manager enforces `torch.no_grad()`.

## Usage

add the context manager to a model to debug

```python
import torch

from PIL import Image
from transformers import LlavaProcessor, LlavaForConditionalGeneration, model_addition_debugger_context

torch.random.manual_seed(673)

# load pretrained model and processor
model_id = "llava-hf/llava-1.5-7b-hf"
processor = LlavaProcessor.from_pretrained(model_id)
model = LlavaForConditionalGeneration.from_pretrained(model_id)

# create random image input
random_image = Image.fromarray(torch.randint(0, 256, (224, 224, 3), dtype=torch.uint8).numpy())

# prompt
prompt = "<image>Describe this image."

# process inputs
inputs = processor(text=prompt, images=random_image, return_tensors="pt")

# call forward method (not .generate!)
with model_addition_debugger_context(model, debug_path="Your_debug_path", do_prune_layers=False):
    output = model.forward(**inputs)
```

N)rÉ   r»   rÌ   rR   )	rš   r'   r£   r(   rJ   ÚmÚorig_forwardsÚmodule_instanceÚforward_methods	   &&&&     r   Úmodel_addition_debugger_contextrÔ   �  s’   é € ðf /4×.AÑ.AÔ.CÔDÑ.C¡d a�QŸ	™	’\Ñ.C€MÑDØ Ÿ=™=€MÑÜ˜5¨oÔHð5ØŠà/<×/BÑ/BÖ/DÑ+ˆOØ&4Ö#ó 0Eùó Eøð 0=×/BÑ/BÖ/DÑ+ˆOØ&4Ö#ò 0Eüs'   ‚B–A0­BÁA6 Á'BÁ6!BÂB)NTN)rl   TT)r   )NTT)'r¼   r–   r9   ÚreÚ
contextlibr   r   Úior   Úutilsr   Úutils.import_utilsr   r   r   Úsafetensors.torchr	   r   r   Úis_availableÚtorch.distributed.tensorÚ
get_loggerrÈ   r’   r   Úcompiler   r   r$   rG   rP   r7   re   rr   rv   rz   r¡   rÌ   rÔ   r   r   r   Ú<module>rß      sî   ðó  Û Û 	Û 	ß 6Ý å ß <ñ ×ÒÛÝ+à#(Ð à×Ñ×%Ñ%×'Ò'Û'à'+Ð$øà#(Ð ð 
×	Ò	˜HÓ	%€ò-ð —z’zÐ"=Ó>Ð õCò ÷.÷b(0õV5ò"-ð —*’*˜_Ó-€ò\ò")õ((*÷V|(ñ~ 
�:ÔØö85ó ó ò85r   