-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47bf010
commit 8620bbb
Showing
8 changed files
with
138 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
Train a diffusion model on images. | ||
""" | ||
|
||
import argparse | ||
import os | ||
from multiprocessing import set_start_method | ||
from shutil import copyfile | ||
|
||
import conf_mgt | ||
from guided_diffusion import dist_util, logger | ||
from guided_diffusion.resample import create_named_schedule_sampler | ||
from guided_diffusion.script_util import ( | ||
model_and_diffusion_defaults, | ||
create_model_and_diffusion, | ||
select_args, | ||
) | ||
from guided_diffusion.train_util import TrainLoop | ||
from utils import yamlread | ||
|
||
|
||
def main(conf: conf_mgt.Default_Conf): | ||
global_rank = dist_util.setup_dist() | ||
experiment_dir = os.getenv("EXPERIMENT_DIR") if os.getenv("EXPERIMENT_DIR") is not None else './experiments/debug/' | ||
|
||
logger.configure(dir=experiment_dir, global_rank=global_rank) | ||
logger.log(f'experiment_dir: {experiment_dir}') | ||
logger.log("creating model and diffusion...") | ||
|
||
conf_path = args.get('conf_path') | ||
if os.path.isdir(experiment_dir) and os.path.isfile(conf_path): | ||
_, conf_filename = os.path.split(conf_path) | ||
copyfile(conf_path, os.path.join(experiment_dir, conf_filename)) | ||
|
||
model, diffusion = create_model_and_diffusion(conf=conf, | ||
**select_args( | ||
conf, | ||
model_and_diffusion_defaults().keys() | ||
)) | ||
model.to(dist_util.dev()) | ||
schedule_sampler = create_named_schedule_sampler(conf.schedule_sampler, diffusion) | ||
|
||
logger.log("creating data loader...") | ||
train_name = conf.get_default_train_name() | ||
data = conf.get_dataloader(dsName=train_name) | ||
|
||
logger.log("training...") | ||
TrainLoop(model=model, | ||
diffusion=diffusion, | ||
data=data, | ||
schedule_sampler=schedule_sampler, | ||
conf=conf | ||
).run_loop() | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--conf_path', type=str, required=False, default=None) | ||
args = vars(parser.parse_args()) | ||
|
||
conf_arg = conf_mgt.conf_base.Default_Conf() | ||
conf_arg.update(yamlread(args.get('conf_path'))) | ||
|
||
set_start_method('forkserver', force=True) | ||
|
||
main(conf_arg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/bash | ||
|
||
SCRIPTS_DIR="${HOME}/SI-DDPM-FMO/" | ||
|
||
cd "${SCRIPTS_DIR}" || exit | ||
|
||
source "$(pipenv --venv)/bin/activate" | ||
|
||
python -m torch.distributed.run --standalone --nnodes=1 --nproc_per_node=1 scripts/image_train.py --conf_path confs/baseline.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/bash | ||
|
||
SCRIPTS_DIR="${HOME}/SI-DDPM-FMO/" | ||
|
||
cd "${SCRIPTS_DIR}" || exit | ||
|
||
source "$(pipenv --venv)/bin/activate" | ||
|
||
python -m torch.distributed.run --standalone --nnodes=1 --nproc_per_node=1 scripts/image_train.py --conf_path confs/siddpmfmo.yml |