paddlenlp/utils/tools.py
def dygraph_params_to_static(model, dygraph_tensor_dict, topo=None):
    """Simple tool for convert dygraph paramters to static paramters dict.

    **NOTE** The model must both support static graph and dygraph mode.

    Args:
        model (nn.Layer): the model of a neural network.
        dygraph_tensor_dict (string): path of which locate the saved paramters in static mode.

    Returns:
        [tensor dict]: a state dict the same as the dygraph mode.
    """
    state_dict = model.state_dict()

    ret_dict = dict()
    for name, parm in state_dict.items():
        if name not in dygraph_tensor_dict:
            logger.info("%s paramter is missing from you state dict." % name)
            continue

        tensor = dygraph_tensor_dict[name]
        if parm.is_distributed:
            assert topo is not None
            for dim, v in enumerate(tensor.shape):
                if parm.shape[dim] != v:
                    break

            splited = np.split(
                tensor, topo.mp_info.size, axis=dim)[topo.mp_info.rank]
            ret_dict[parm.name] = splited
        else:
            ret_dict[parm.name] = tensor

    return ret_dict
Simple tool for convert dygraph paramters to static paramters dict.

    **NOTE** The model must both support static graph and dygraph mode.

    Args:
        model (nn.Layer): the model of a neural network.
        dygraph_tensor_dict (string): path of which locate the saved paramters in static mode.

    Returns:
        [tensor dict]: a state dict the same as the dygraph mode.
    
Simple tool for convert dygraph paramters to static paramters dict.
NOTE** The model must both support static graph and dygraph mode.
Simple tool for convert dygraph paramters to static paramters dict . NOTE ** The model must both support static graph and dygraph mode .
def dygraph_params_to_static(model, dygraph_tensor_dict, topo=None):
    state_dict = model.state_dict()
    ret_dict = dict()
    for name, parm in state_dict.items():
        if name not in dygraph_tensor_dict:
            logger.info("%s paramter is missing from you state dict." % name)
            continue
        tensor = dygraph_tensor_dict[name]
        if parm.is_distributed:
            assert topo is not None
            for dim, v in enumerate(tensor.shape):
                if parm.shape[dim] != v:
                    break
            splited = np.split(
                tensor, topo.mp_info.size, axis=dim)[topo.mp_info.rank]
            ret_dict[parm.name] = splited
        else:
            ret_dict[parm.name] = tensor
    return ret_dict
def dygraph_params_to_static ( model , dygraph_tensor_dict , topo = None ) : state_dict = model . state_dict ( ) ret_dict = dict ( ) for name , parm in state_dict . items ( ) : if name not in dygraph_tensor_dict : logger . info ( "%s paramter is missing from you state dict." % name ) continue tensor = dygraph_tensor_dict [ name ] if parm . is_distributed : assert topo is not None for dim , v in enumerate ( tensor . shape ) : if parm . shape [ dim ] != v : break splited = np . split ( tensor , topo . mp_info . size , axis = dim ) [ topo . mp_info . rank ] ret_dict [ parm . name ] = splited else : ret_dict [ parm . name ] = tensor return ret_dict
Simple tool for convert dygraph paramters to static paramters dict.
Simple tool for convert dygraph paramters to static paramters dict .
"""Simple tool for convert dygraph paramters to static paramters dict.

    **NOTE** The model must both support static graph and dygraph mode.

    Args:
        model (nn.Layer): the model of a neural network.
        dygraph_tensor_dict (string): path of which locate the saved paramters in static mode.

    Returns:
        [tensor dict]: a state dict the same as the dygraph mode.
    """
a state dict the same as the dygraph mode.
a state dict the same as the dygraph mode .
[tensor dict]
model
the model of a neural network.
the model of a neural network .
dygraph_tensor_dict
path of which locate the saved paramters in static mode.
path of which locate the saved paramters in static mode .
topo