Skip to content

Commit

Permalink
Add cache group field to cache prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Semmler committed Jan 29, 2024
1 parent 8c7e587 commit 81e8cb4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
11 changes: 7 additions & 4 deletions scripts/calculate_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import os
import pickle
import time
from pathlib import Path

import click
import numpy as np
Expand Down Expand Up @@ -95,9 +94,13 @@ def _calculate_values(
)

params = load_params_fast()
cache = PrefixedMemcachedCacheBackend(
config=MemcachedClientConfig(), prefix=f"{experiment_name}/{dataset_name}"
)
cache = None
if "cache_group" in params["valuation_methods"][valuation_method_name]:
cache_group = params["valuation_methods"][valuation_method_name]["cache_group"]
prefix = f"{experiment_name}/{dataset_name}/{cache_group}"
cache = PrefixedMemcachedCacheBackend(
config=MemcachedClientConfig(), prefix=prefix
)

val_set = Accessor.datasets(experiment_name, dataset_name).loc[0, "val_set"]

Expand Down
17 changes: 11 additions & 6 deletions scripts/evaluate_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
directory. The metrics are usually stored as `*.csv` files. Each metric consists of
a single value and a curve. The curve is stored as `*.curve.csv` file.
"""

import logging
import os
from functools import partial, reduce
from pathlib import Path

import click
import pandas as pd
from pydvl.parallel import ParallelConfig
from pydvl.utils import DiskCacheBackend, MemcachedClientConfig
from pydvl.utils import MemcachedClientConfig
from pydvl.utils.functional import maybe_add_argument

from re_classwise_shapley.cache import PrefixedMemcachedCacheBackend
Expand Down Expand Up @@ -127,9 +125,16 @@ def _evaluate_metrics(

n_pipeline_step = 5
seed = pipeline_seed(repetition_id, n_pipeline_step)
cache = PrefixedMemcachedCacheBackend(
config=MemcachedClientConfig(), prefix=f"{experiment_name}/{dataset_name}"
)
cache = None
if (
"eval_model" in metric_kwargs
and "cache_group" in params["valuation_methods"][valuation_method_name]
):
cache_group = params["valuation_methods"][valuation_method_name]["cache_group"]
prefix = f"{experiment_name}/{dataset_name}/{cache_group}"
cache = PrefixedMemcachedCacheBackend(
config=MemcachedClientConfig(), prefix=prefix
)

logger.info("Evaluating metric...")
with n_threaded(n_threads=1):
Expand Down
4 changes: 2 additions & 2 deletions src/re_classwise_shapley/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@


class PrefixedMemcachedCacheBackend(MemcachedCacheBackend):
def __init__(self, *args, prefix: str, **kwargs):
def __init__(self, *args, **kwargs):
self._prefix = kwargs["prefix"]
super().__init__(*args, **kwargs)
self._prefix = prefix

def get(self, key: str) -> Optional[Any]:
return super().get(f"{self._prefix}/{key}")
Expand Down

0 comments on commit 81e8cb4

Please sign in to comment.