32 lines
876 B
Python
32 lines
876 B
Python
from abc import ABC, abstractmethod
|
|
from typing import Any, Dict, Iterator, Tuple
|
|
import logging
|
|
|
|
import torch
|
|
|
|
from config import BenchmarkConfig, DataLoaderConfig
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class BaseDataLoaderFactory(ABC):
|
|
"""Base class for creating and managing dataloaders."""
|
|
|
|
def __init__(self, benchmark_config: BenchmarkConfig):
|
|
self.benchmark_config = benchmark_config
|
|
|
|
def get_dataloader_config(self) -> DataLoaderConfig:
|
|
return self.benchmark_config.dataloader_config
|
|
|
|
@abstractmethod
|
|
def get_train_dataloader(self) -> Iterator[Tuple[torch.Tensor, torch.Tensor]]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_val_dataloader(self) -> Iterator[Tuple[torch.Tensor, torch.Tensor]]:
|
|
pass
|
|
|
|
def get_metrics(self) -> Dict[str, Any]:
|
|
"""Return metrics about dataloader performance."""
|
|
return {}
|