def METHOD_NAME(checkpoint_path, layer=None):
    state_dict = torch.load(checkpoint_path)
    weights = state_dict["weights"]
    config = state_dict["config"]
    if layer is not None:
        config["nLevelsGRU"] = layer
    encoder = CPCEncoder(config["hiddenEncoder"])
    ar_net = CPCAR(
        config["hiddenEncoder"], config["hiddenGar"], False, config["nLevelsGRU"]
    )
    model = CPCModel(encoder, ar_net)
    model.load_state_dict(weights, strict=False)
    model.config = config
    return model