
    9jf                        d dl Z d dl mZ ddlmZ e j                  j                  dde j                  j                         e j                  j                  d      de j                  d	e
d
efd       Ze j                  j                  dd      de j                  d	e
d
e
fd       Zdedee
   d
efdZe j                  j!                  dd      dedee
   d
efd       Zej                  dedee
   d
efd       Zdedee
   d
efdZe j                  j!                  dd      dedee
   d
efd       Zej                  dedee
   d
efd       Zy)    N)SymInt   )
DeviceMeshz/device_mesh::_runtime_compute_coordinate_on_dimz'(Tensor full_mesh, int index) -> SymInt)tags	full_meshindexreturnc                    ddl m} t        j                  j                  j                         }|j                  }|j                         }| j                  |dz         } ||dt        |t              r|dz
  nd        	 t        j                  j                  j                  j                         }|r/|j                   j#                  |j$                  j&                         |S # t        $ r d}Y @w xY w)Nr   )_constrain_range_for_size   )minmaxF)%torch.fx.experimental.symbolic_shapesr   torch
_custom_opimplget_ctx
_shape_envcreate_unbacked_symintsize
isinstanceint_dynamosymbolic_convertInstructionTranslator
current_txAttributeError ignorable_fresh_unbacked_symbolsappendnode_expr)r   r   r   ctx	shape_envsz	mesh_size	in_dynamos           b/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/torch/distributed/_ops/device_mesh.py'_runtime_compute_coordinate_on_dim_faker(      s     P





'
'
)CI 
	)	)	+B
 uqy)I

9c(By1}MM22HHSSU	  	2299"''--HI  	s    2C% %C32C3CompositeExplicitAutogradc                     t         j                  j                         }t        j                  |       }t        j
                  ||      }|t        ||   S N)r   distributedget_rankr   _get_mesh_tensor_from_full_mesh_compute_coordinates_from_meshAssertionError)r   r   rankmeshmesh_coordss        r'   '_runtime_compute_coordinate_on_dim_implr4   7   sQ     %%'D55i@D;;D$GKu    r2   	mesh_dimsc                 \    ddl m}  || t        |            }|t        d| d|        |S )Nr   )"_get_flattened_mesh_by_layout_implz&No flattened mesh found for mesh_dims=z on )&torch.distributed.tensor._redistributer8   tuple
ValueError)r2   r6   r8   results       r'   _get_flattened_submesh_implr=   C   s?     0eI6FGF~A)DQUPVWXXMr5   z#device_mesh::_get_flattened_submesh )mutates_argsc                     t        | |      S r+   r=   r2   r6   s     r'   _get_flattened_submeshrC   N       &tY77r5   c                     t        | |      S r+   rA   rB   s     r'   _get_flattened_submesh_fakerF   S   rD   r5   c                     | j                   t        d|        t        fd|D              }t        |      dk(  r| |d      S | |   S )Nz%Cannot slice mesh without dim names: c              3   (   K   | ]	  }|     y wr+   r>   ).0iall_dim_namess     r'   	<genexpr>z$_get_submesh_impl.<locals>.<genexpr>\   s     :1mA&:s   r   r   )_mesh_dim_namesr;   r:   len)r2   r6   	dim_namesrK   s      @r'   _get_submesh_implrP   X   s\    ((M@GHH:	::I
9~IaL!!	?r5   zdevice_mesh::_get_submeshc                     t        | |      S r+   rP   rB   s     r'   _get_submeshrS   b       T9--r5   c                     t        | |      S r+   rR   rB   s     r'   _get_submesh_fakerV   g   rT   r5   )r   r   device_meshr   librarydefineTagpt2_compliant_tagregister_fakeTensorr   r(   r   r4   listr=   	custom_oprC   rF   rP   rS   rV   r>   r5   r'   <module>r`      s     $   5-		$	$   NO"||"$'"" P"J 57Ru|| C TW j T#Y :  >RP8 8S	 8j 8 Q8 %%8j 8T#Y 8: 8 &8J 49   42F.z .d3i .J . G. .J .49 . . .r5   