
    Vh_	                     F   d Z ddlZddlmZmZ ddlmZ ddlmZ  edej                  ej                  j                  j                  j                  ej                  j                  j                  j                  d      Zej                  e      d	        Z ed
ej                  d ej"                  j$                  j&                  d      Zej(                  j*                  j-                  e       ej                  e      d        Zej                  e      d        Zy)a   This module implements tensor version operations for Dynamo tracing.

It provides primitives for handling tensor versioning during tracing, particularly in the
context of functionalization where version operations are handled eagerly on fake tensors.

When we functionalize _tensor_version + _unsafe_set_version_counter, the ops disappear from
the traced graph. We run them eagerly on the fake tensors used for tracing, in order to get
past asserts that would fail in autograd.

Why is this ok?
1) Versions on functional tensors do not make any sense since you cannot mutate a functional
   tensor.
2) The whole point of version munging is to trick autograd into doing what we want, and after
   AotAutograd there is no longer any need for these ops.

Note this is similar to how no_grad is handled.
    N)
_make_primRETURN_TYPE)FakeTensorMode)FunctionalTensorModez&_tensor_version(Tensor self) -> SymIntz9Tracable unbacked SymInt version of torch.Tensor._version)schemareturn_typemeta	impl_atendocc                 6    | j                   j                         S )z
    The initial dynamo capture of _tensor_version + _unsafe_set_version_counter turns the
    `._version` into an unbacked SymInt so that we don't need to specialize on the `._version`
    of input tensors to the graph.
    )	shape_envcreate_unbacked_symint)	fake_modeself_tensors     O/home/dcms/DCMS/lib/python3.12/site-packages/torch/_dynamo/tensor_version_op.py_tensor_version_faker   $   s     5577    zF_unsafe_set_version_counter(Tensor[] tensors, SymInt[] versions) -> ()c                      y N )selfversions     r   <lambda>r   1   s    r   zITracable+SymInt version of torch._C._autograd._unsafe_set_version_counterc                     |j                   S r   )_version)moder   s     r   _tensor_version_functionalr   8   s    ==r   c                 X    t         j                  j                  j                  ||       y r   )torch_C	_autograd_unsafe_set_version_counter)ctxtensorsversionss      r   &_unsafe_set_version_counter_functionalr&   =   s    	HH227HEr   )__doc__r   torch._primsr   r   torch._subclassesr   #torch._subclasses.functional_tensorr   NEWopsatenr   default_tensor_versionpy_implr   r    r!   r"   fxnodehas_side_effectr   r&   r   r   r   <module>r4      s	  $  0 , D 3		 	 	(	(iinn%%--C (8 )8 )S	#hh  <<S    9 : -. / $$%9:F ;Fr   