keras/src/saving/saving_lib.py/load_weights_only
def load_weights_only(
    model, filepath, skip_mismatch=False, objects_to_skip=None
):
    """Load the weights of a model from a filepath (.keras or .weights.h5).

    Note: only supports h5 for now.
    """
    archive = None
    filepath = str(filepath)
    if filepath.endswith(".weights.h5"):
        # TODO: download file if h5 filepath is remote
        weights_store = H5IOStore(filepath, mode="r")
    elif filepath.endswith(".keras"):
        archive = zipfile.ZipFile(filepath, "r")
        weights_store = H5IOStore(_VARS_FNAME_H5, archive=archive, mode="r")

    failed_saveables = set()
    if objects_to_skip is not None:
        visited_saveables = set(id(o) for o in objects_to_skip)
    else:
        visited_saveables = set()
    error_msgs = {}
    _load_state(
        model,
        weights_store=weights_store,
        assets_store=None,
        inner_path="",
        skip_mismatch=skip_mismatch,
        visited_saveables=visited_saveables,
        failed_saveables=failed_saveables,
        error_msgs=error_msgs,
    )
    weights_store.close()
    if archive:
        archive.close()

    if failed_saveables:
        _raise_loading_failure(error_msgs, warn_only=skip_mismatch)