
    g                         d dl Z d dlZd dlmZmZmZ  ej                      ej        d          Zddede	de	fdZ
defd	Zd
 Z	 	 	 ddZd Zedk    r e             dS dS )    N)UnivNetConfigUnivNetModelloggingztransformers.models.univnet config
old_prefix
new_prefixc                    i }| d|| d<   | d|| d<   | d|| d<   t          | j                  D ]h}| d| d|| d	| d
<   | d| d|| d	| d<   | d| d|| d	| d<   | d| d|| d	| d<   | d| d|| d	| d<   | d| d|| d	| d<   i| d|| d<   | d|| d<   | d|| d<   | d|| d<   | d|| d<   | d|| d<   |S )Nz.input_conv.weight_gz.input_conv.0.weight_gz.input_conv.weight_vz.input_conv.0.weight_vz.input_conv.biasz.input_conv.0.bias.resblocks.z.conv1.weight_gz.residual_convs..1.weight_gz.conv1.weight_v.1.weight_vz.conv1.bias.1.biasz.conv2.weight_gz.3.weight_gz.conv2.weight_vz.3.weight_vz.conv2.biasz.3.biasz.kernel_conv.weight_gz.kernel_conv.weight_vz.kernel_conv.biasz.bias_conv.weight_gz.bias_conv.weight_vz.bias_conv.bias)rangekernel_predictor_num_blocks)r   r   r	   mappingis        g/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/univnet/convert_univnet.py get_kernel_predictor_key_mappingr      s=   G8B5X5X5XGz11128B5X5X5XGz11124>1P1P1PGz---. 6566 f fDNAmAm[\AmAmAm:==q===>DNAmAm[\AmAmAm:==q===>@J=e=eWX=e=e=e:99q999:DNAmAm[\AmAmAm:==q===>DNAmAm[\AmAmAm:==q===>@J=e=eWX=e=e=e:99q999:: 8B4X4X4XGz00017A4X4X4XGz00013=0P0P0PGz,,,- 6@2T2T2TGz.../5?2T2T2TGz.../1;.L.L.LGz***+N    c           	         i }t          t          | j                            D ]}d| d|d| d<   d| d|d| d<   d| d|d| d<   t          | d| d	d| d	
          }|                    |           t          t          | j        |                             D ];}d| d| d|d| d| d<   d| d| d|d| d| d<   d| d| d|d| d| d<   <d|d<   d|d<   d|d<   |S )Nz
resblocks.z.convt_pre.weight_gz
res_stack.z.convt_pre.1.weight_gz.convt_pre.weight_vz.convt_pre.1.weight_vz.convt_pre.biasz.convt_pre.1.biasz.kernel_predictor)r   r	   r   z.conv.weight_gz.conv_blocks.r   z.conv.weight_vr   z
.conv.biasr   zconv_post.weight_gzconv_post.1.weight_gzconv_post.weight_vzconv_post.1.weight_vzconv_post.biaszconv_post.1.bias)r   lenresblock_stride_sizesr   updateresblock_dilation_sizes)r   r   r   kernel_predictor_mappingjs        r   get_key_mappingr   8   s   G
 3v34455 h h9\a9\9\9\5Q55569\a9\9\9\5Q55565T!5T5T5T1Q1112 $D@A@@@MnZ[MnMnMn$
 $
 $
  	/000 s69!<==>> 	h 	hACoPQCoCo^_CoCoCoG??????@CoPQCoCo^_CoCoCoG??????@?gA?g?gZ[?g?g?gG;;;;;;<<	h ';G"#&:G"#"2GNr   c                 v    i }|                                  D ]!\  }}||v r
||v r||         }|||<   |||<   "|S )N)items)
state_dictkeys_to_modifykeys_to_removemodel_state_dictkeyvaluenew_keys          r   rename_state_dictr'   X   sl     &&(( * *
U.  .  $S)G(-W%%$)S!!r   Fc                    t          j        | d          }|d         }|t          j        |          }nt                      }t	          |          }t                      }	t          |||	          }
t          |          }|                                 |	                    |
           |
                                 |                    ||           |r&t          d           |                    |           d S d S )Ncpu)map_locationmodel_g)safe_serializationzPushing to the hub...)torchloadr   from_pretrainedr   setr'   r   apply_weight_normload_state_dictremove_weight_normsave_pretrainedprintpush_to_hub)checkpoint_pathpytorch_dump_folder_pathconfig_pathrepo_idr,   model_state_dict_baser    r   r!   r"   hf_state_dictmodels               r   convert_univnet_checkpointr>   f   s    "JUKKK&y1J.{;;$V,,NUUN%j..QQM  E		-(((		2GYZZZ #%&&&'"""""# #r   c                     t          j                    } |                     ddd t          d           |                     dd t          d           |                     ddd t          d	           |                     d
d t          d           |                     ddd           |                                 }t          |j        |j        |j        |j	        |j
                   d S )Nz--checkpoint_pathTzPath to original checkpoint)requireddefaulttypehelpz--config_pathz*Path to hf config.json of model to convert)rA   rB   rC   z--pytorch_dump_folder_pathz!Path to the output PyTorch model.z--push_to_hubu4   Where to upload the converted model on the 🤗 hub.z--safe_serialization
store_truez.Whether to save the model using `safetensors`.)actionrC   )argparseArgumentParseradd_argumentstr
parse_argsr>   r7   r8   r9   r6   r,   )parserargss     r   mainrM      s   $&&F
+dDsYvwww
CFrsss
$tTRu     C6l     |:j     D%    r   __main__)r   r   )NNF)rF   r-   transformersr   r   r   set_verbosity_info
get_loggerloggerrI   r   r   r'   r>   rM   __name__ r   r   <module>rU      s
     = = = = = = = = = =     		9	:	: ]  ^a    <M    @  " # # # #D  2 zDFFFFF r   