-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_experiment.py
More file actions
42 lines (31 loc) · 1.12 KB
/
run_experiment.py
File metadata and controls
42 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Copyright (c) 2024 Qualcomm Technologies, Inc.
# All Rights Reserved.
import logging
import os
import random
from typing import Any
import hydra
import numpy as np
import torch
from hydra.utils import instantiate
from omegaconf import DictConfig, OmegaConf
log = logging.getLogger(__name__)
@hydra.main(config_path="pkg://scripts/config", config_name="config.yaml", version_base="1.3")
def parse(conf: DictConfig) -> Any:
# Set environment variable if specified.
# This is broken in hydra because of issues with variable interpolations.
# See: https://github.com/facebookresearch/hydra/issues/2800
if "env" in conf:
for name, value in conf.env.items():
os.environ[name] = value
# Set up the random seeds
torch.manual_seed(conf.experiment.seed)
random.seed(conf.experiment.seed)
np.random.seed(conf.experiment.seed)
log.info(f"Running experiment {conf.experiment.run_id}")
run = instantiate(conf.experiment.script, _partial_=True)
return_values = run(conf)
return return_values
if __name__ == "__main__":
OmegaConf.register_new_resolver("eval", eval)
parse()