PyTorch
Adria / benchmarks /config.py
Nebulon33's picture
Upload 84 files
bd992b7 verified
Raw History Blame Contribute Delete
1.45 kB
import json
from pathlib import Path
CONFIGS_PATH = Path(__file__).parent / "configs.json"
def _load_all() -> dict:
if CONFIGS_PATH.exists():
with open(CONFIGS_PATH) as f:
return json.load(f)
return {}
def load_config(model_name: str, n_params: int) -> dict:
"""
Load saved kwargs for (model_name, n_params).
Raises KeyError if no config has been saved yet for this combination.
config_ui.py should be run to generate these configs.
:param model_name: The name of the model to load the config for.
:param n_params: The parameter count to load the config for.
:return: The kwargs dictionary for that model config
"""
configs = _load_all()
model_configs = configs.get(model_name)
if model_configs is None:
raise KeyError(f"No config for {model_name}")
key = str(n_params)
if key not in model_configs:
raise KeyError(f"No config for {model_name} with param count {n_params}")
return dict(model_configs[key])
def has_config(model_name: str, n_params: int) -> bool:
"""
Returns true if a saved config exists for (model_name, n_params).
:param model_name: The name of the model to check for the config for.
:param n_params: The parameter count to check for the config for.
:return: True if the config exists for (model_name, n_params).
"""
configs = _load_all()
return str(n_params) in configs.get(model_name, {})