deepmd.pd.utils.finetune
========================

.. py:module:: deepmd.pd.utils.finetune


Attributes
----------

.. autoapisummary::

   deepmd.pd.utils.finetune.log


Functions
---------

.. autoapisummary::

   deepmd.pd.utils.finetune.get_finetune_rule_single
   deepmd.pd.utils.finetune.get_finetune_rules


Module Contents
---------------

.. py:data:: log

.. py:function:: get_finetune_rule_single(_single_param_target: dict, _model_param_pretrained: dict, from_multitask: bool = False, model_branch: str = 'Default', model_branch_from: str = '', change_model_params: bool = False) -> dict

.. py:function:: get_finetune_rules(finetune_model: str, model_config: dict, model_branch: str = '', change_model_params: bool = True) -> tuple[dict, str]

   
   Get fine-tuning rules and (optionally) change the model_params according to the pretrained one.

   This function gets the fine-tuning rules and (optionally) changes input in different modes as follows:
   1. Single-task fine-tuning from a single-task pretrained model:
       - The model will be fine-tuned based on the pretrained model.
       - (Optional) Updates the model parameters based on the pretrained model.
   2. Single-task fine-tuning from a multi-task pretrained model:
       - The model will be fine-tuned based on the selected branch in the pretrained model.
         The chosen branch can be defined from the command-line or `finetune_head` input parameter.
         If not defined, model parameters in the fitting network will be randomly initialized.
       - (Optional) Updates the model parameters based on the selected branch in the pretrained model.
   3. Multi-task fine-tuning from a single-task pretrained model:
       - The model in each branch will be fine-tuned or resumed based on the single branch ('Default') in the pretrained model.
         The chosen branches can be defined from the `finetune_head` input parameter of each branch.
         - If `finetune_head` is defined as 'Default',
           it will be fine-tuned based on the single branch ('Default') in the pretrained model.
         - If `finetune_head` is not defined and the model_key is 'Default',
           it will resume from the single branch ('Default') in the pretrained model without fine-tuning.
         - If `finetune_head` is not defined and the model_key is not 'Default',
           it will be fine-tuned based on the single branch ('Default') in the pretrained model,
           while model parameters in the fitting network of the branch will be randomly initialized.
       - (Optional) Updates model parameters in each branch based on the single branch ('Default') in the pretrained model.
   4. Multi-task fine-tuning from a multi-task pretrained model:
       - The model in each branch will be fine-tuned or resumed based on the chosen branches in the pretrained model.
         The chosen branches can be defined from the `finetune_head` input parameter of each branch.
           - If `finetune_head` is defined as one of the branches in the pretrained model,
             it will be fine-tuned based on the chosen branch in the pretrained model.
           - If `finetune_head` is not defined and the model_key is the same as one of those in the pretrained model,
             it will resume from the model_key branch in the pretrained model without fine-tuning.
           - If `finetune_head` is not defined and a new model_key is used,
             it will be fine-tuned based on the chosen branch in the pretrained model,
             while model parameters in the fitting network of the branch will be randomly initialized.
       - (Optional) Updates model parameters in each branch based on the chosen branches in the pretrained model.

   :Parameters:

       **finetune_model**
           The pretrained model.

       **model_config**
           The fine-tuning input parameters.

       **model_branch**
           The model branch chosen in command-line mode, only for single-task fine-tuning.

       **change_model_params**
           Whether to change the model parameters according to the pretrained one.



   :Returns:

       model_config:
           Updated model parameters.

       finetune_links:
           Fine-tuning rules in a dict format, with `model_branch`: FinetuneRuleItem pairs.











   ..
       !! processed by numpydoc !!

