
    Pi{                        d dl mZ d dlZd dlmZ d dlmZ 	 d
dZej        j	        j
        eej        j	        j        eej        j	        j        eej        j	        j         eed          ej        j	        j        eej        j	        j         eed	          ej        j	        j         eed          ej        j	        j         eed	          iZdS )    )partialN)SparseSemiStructuredTensor)semi_structured_sparsify_like c           	      "    d|D ]}t          |t                    r|J  fdfdt          |          D             }                    j          d |D              j          d |D              j        j                  S )a  
    adds pointwise op support for semi-structured tensors.

    Assumes that at least one of the arguments in arg is a SparseSemiStructuredTensor.
    The last instance of a SparseSemiStructuredTensor is used as the reference mask to sparsify the others tensors passed in args.
    sparsify_like_args_list is used to specify which arguments to sparsify like the reference tensor.
    Nc                    t          |t          j                  r3t          |t                    sh| v rt	          |          }nt          dj         dj         dt                     dt                     d|  dt          |                     |j	        oj	        h|j	        
                                j	        
                                k    s4|j	                                        j	                                        k    r@t          dj         dj         dt                     dt                     d	          |S )Nz
Operation .z on z requires all operands to be z, but operand z is a z with the same sparsity pattern)
isinstancetorchTensorr   r   
ValueError
__module____name__typecompressed_swizzled_bitmaskdata_ptrstride)itensorfuncreference_sparse_tensorsparsify_like_args_lists     {/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchao/sparsity/training/pointwise_ops.py
handle_argz-_semi_sparse_pointwise_op.<locals>.handle_arg   s   fel++ 	 f&@AA ///: 7 FF %cT_ c ct} c c$OfJgJg c c"#:;;c cKLc cTXY_T`T`c c   6>.JR9BBDD.JSSUUV V9@@BB.JQQSST T %ZT_ Z Zt} Z Z$OfJgJg Z Z 788Z Z Z       c                 .    g | ]\  }} ||          S r   r   ).0r   r   r   s      r   
<listcomp>z-_semi_sparse_pointwise_op.<locals>.<listcomp>?   s)    KKKiaJJq&))KKKr   c                 J    g | ] }t          |t                    r|j        n|!S r   )r
   r   packedr   xs     r   r   z-_semi_sparse_pointwise_op.<locals>.<listcomp>D   s>        'q*DEEL1  r   c                 J    g | ] }t          |t                    r|j        n|!S r   )r
   r   packed_tr!   s     r   r   z-_semi_sparse_pointwise_op.<locals>.<listcomp>K   s>        ),FGGN

Q  r   )r
   r   	enumerate	__class__shapemetameta_tr   )	r   typesargskwargsr   r   args_updatedr   r   s	   `   `  @@r   _semi_sparse_pointwise_opr.      s	    # - -f899 	-&,#"...      B LKKK9T??KKKL",,% %  	
 	 $ %  	
 	 &;!  r   )r      )r   )r   )r   Nr   )	functoolsr   r   torch.sparser   "torchao.sparsity.training.autogradr   r.   opsatenrelugelusilumuladdgelu_backwardsilu_backwardthreshold_backward#CUTLASS_POINTWISE_OP_DISPATCH_TABLEr   r   r   <module>r>      s<          3 3 3 3 3 3 L L L L L L @BD D D DR 
IN2	IN2	IN2	IN! &  
 
IN1 
IN ''!4# # # 
IN ''!6# # # 
IN%ww! $( ( (%' # # #r   