Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Distribution-based dataset creator #748

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions compiler_gym/datasets/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,35 @@ def benchmarks(self, with_deprecated: bool = False) -> Iterable[Benchmark]:
(d.benchmarks() for d in self.datasets(with_deprecated=with_deprecated))
)

def benchmarks_from_distrib(
self,
datasets: List[str] = None,
weights: List[float] = None,
dataset_size: int = -1,
) -> Iterable[Benchmark]:
"""
Foivos WIP.
Select a dataset to sample from with some weight probability.
If weights is None, select among `datasets` uniformly.
"""
datasets = datasets or list(self._datasets.values())
if weights is None:
weights = [1 / len(datasets)] * len(datasets)
if len(weights) != len(datasets):
raise ValueError(
"Mismatch between datasets size: {} and sampling weights length: {}!".format(
len(datasets), len(weights)
)
)
idx = 0
while dataset_size == -1 or idx < dataset_size:
sampled_key = np.random.choice(datasets, p=weights)
if sampled_key not in self._datasets:
raise LookupError(f"Dataset not found: {sampled_key}")
dataset = self._datasets[sampled_key]
return round_robin_iterables((dataset,))
return

def benchmark_uris(self, with_deprecated: bool = False) -> Iterable[str]:
"""Enumerate the (possibly infinite) benchmark URIs.

Expand Down