Write external data of all tensors to files on disk.

    Note: This function also strips basepath information from all tensors' external_data fields.

    @params
    model: Model object which is the source of tensors to serialize.
    filepath: System path to the directory which should be treated as base path for external data.

    @return
    The modified model object.

def write_external_data_tensors(model, filepath):  # type: (ModelProto, Text) -> ModelProto
    """
    Write external data of all tensors to files on disk.

    Note: This function also strips basepath information from all tensors' external_data fields.

    @params
    model: Model object which is the source of tensors to serialize.
    filepath: System path to the directory which should be treated as base path for external data.

    @return
    The modified model object.
    """
    for tensor in _get_all_tensors(model):
        if uses_external_data(tensor):
            save_external_data(tensor, filepath)
            tensor.ClearField(str('raw_data'))

    return model