-
Notifications
You must be signed in to change notification settings - Fork 740
670 add bundle example for multi-gpu training #673
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e8f8b26
[DLMED] draft config
Nic-Ma 43e9c9f
[DLMED] update for test
Nic-Ma 0b30d31
[DLMED] update based on enhancement
Nic-Ma d80a4da
[DLMED] update tutorial
Nic-Ma a7e0ed1
[DLMED] simplify to override
Nic-Ma 0efa61d
Merge branch 'master' into 670-support-multigpu
Nic-Ma f9781b2
[DLMED] update according to comments
Nic-Ma 7734d1a
[DLMED] remove test file
Nic-Ma de93f47
[DLMED] add evaluation config
Nic-Ma 3c7a0a5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 69fd508
[DLMED] simplify inference
Nic-Ma 453aca9
[DLMED] update according to comments
Nic-Ma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,58 @@ | ||
{ | ||
"validate#postprocessing":{ | ||
"_target_": "Compose", | ||
"transforms": [ | ||
{ | ||
"_target_": "Activationsd", | ||
"keys": "pred", | ||
"softmax": true | ||
}, | ||
{ | ||
"_target_": "Invertd", | ||
"keys": ["pred", "label"], | ||
"transform": "@validate#preprocessing", | ||
"orig_keys": "image", | ||
"meta_key_postfix": "meta_dict", | ||
"nearest_interp": [false, true], | ||
"to_tensor": true | ||
}, | ||
{ | ||
"_target_": "AsDiscreted", | ||
"keys": ["pred", "label"], | ||
"argmax": [true, false], | ||
"to_onehot": 2 | ||
}, | ||
{ | ||
"_target_": "SaveImaged", | ||
"keys": "pred", | ||
"meta_keys": "pred_meta_dict", | ||
"output_dir": "@output_dir", | ||
"resample": false, | ||
"squeeze_end_dims": true | ||
} | ||
] | ||
}, | ||
"validate#handlers": [ | ||
{ | ||
"_target_": "CheckpointLoader", | ||
"load_path": "$@ckpt_dir + '/model.pt'", | ||
"load_dict": {"model": "@network"} | ||
}, | ||
{ | ||
"_target_": "StatsHandler", | ||
"iteration_log": false | ||
}, | ||
{ | ||
"_target_": "MetricsSaver", | ||
"save_dir": "@output_dir", | ||
"metrics": ["val_mean_dice", "val_acc"], | ||
"metric_details": ["val_mean_dice"], | ||
"batch_transform": "$monai.handlers.from_engine(['image_meta_dict'])", | ||
"summary_ops": "*" | ||
} | ||
], | ||
"evaluating": [ | ||
"$setattr(torch.backends.cudnn, 'benchmark', True)", | ||
"$@validate#evaluator.run()" | ||
] | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -3,12 +3,11 @@ | |
"$import glob", | ||
"$import os" | ||
], | ||
"cudnn_opt": "$setattr(torch.backends.cudnn, 'benchmark', True)", | ||
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", | ||
"ckpt_path": "/workspace/data/tutorials/modules/bundles/spleen_segmentation/models/model.pt", | ||
"download_ckpt": "$monai.apps.utils.download_url('https://huggingface.co/MONAI/example_spleen_segmentation/resolve/main/model.pt', @ckpt_path)", | ||
"bundle_root": "/workspace/data/tutorials/modules/bundles/spleen_segmentation", | ||
"output_dir": "$@bundle_root + '/eval'", | ||
"dataset_dir": "/workspace/data/Task09_Spleen", | ||
"datalist": "$list(sorted(glob.glob(@dataset_dir + '/imagesTs/*.nii.gz')))", | ||
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", | ||
"network_def": { | ||
"_target_": "UNet", | ||
"spatial_dims": 3, | ||
|
@@ -101,16 +100,14 @@ | |
"_target_": "SaveImaged", | ||
"keys": "pred", | ||
"meta_keys": "pred_meta_dict", | ||
"output_dir": "eval" | ||
"output_dir": "@output_dir" | ||
} | ||
] | ||
}, | ||
"handlers": [ | ||
{ | ||
"_target_": "CheckpointLoader", | ||
"_requires_": "@download_ckpt", | ||
"_disabled_": "$not os.path.exists(@ckpt_path)", | ||
"load_path": "@ckpt_path", | ||
"load_path": "$@bundle_root + '/models/model.pt'", | ||
"load_dict": {"model": "@network"} | ||
}, | ||
{ | ||
|
@@ -120,13 +117,16 @@ | |
], | ||
"evaluator": { | ||
"_target_": "SupervisedEvaluator", | ||
"_requires_": "@cudnn_opt", | ||
"device": "@device", | ||
"val_data_loader": "@dataloader", | ||
"network": "@network", | ||
"inferer": "@inferer", | ||
"postprocessing": "@postprocessing", | ||
"val_handlers": "@handlers", | ||
"amp": true | ||
} | ||
}, | ||
"evaluating": [ | ||
"$setattr(torch.backends.cudnn, 'benchmark', True)", | ||
"[email protected]()" | ||
] | ||
} |
34 changes: 34 additions & 0 deletions
34
modules/bundles/spleen_segmentation/configs/multi_gpu_train.json
This file contains hidden or 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,34 @@ | ||
{ | ||
"device": "$torch.device(f'cuda:{dist.get_rank()}')", | ||
"network": { | ||
"_target_": "torch.nn.parallel.DistributedDataParallel", | ||
"module": "$@network_def.to(@device)", | ||
"device_ids": ["@device"] | ||
}, | ||
"train#sampler": { | ||
"_target_": "DistributedSampler", | ||
"dataset": "@train#dataset", | ||
"even_divisible": true, | ||
"shuffle": true | ||
}, | ||
"train#dataloader#sampler": "@train#sampler", | ||
"train#dataloader#shuffle": false, | ||
"train#trainer#train_handlers": "$@train#handlers[: 1 if dist.get_rank() > 0 else None]", | ||
"validate#sampler": { | ||
"_target_": "DistributedSampler", | ||
"dataset": "@validate#dataset", | ||
"even_divisible": false, | ||
"shuffle": false | ||
}, | ||
"validate#dataloader#sampler": "@validate#sampler", | ||
"validate#evaluator#val_handlers": "$None if dist.get_rank() > 0 else @validate#handlers", | ||
"training": [ | ||
"$import torch.distributed as dist", | ||
"$dist.init_process_group(backend='nccl')", | ||
"$torch.cuda.set_device(@device)", | ||
"$monai.utils.set_determinism(seed=123)", | ||
"$setattr(torch.backends.cudnn, 'benchmark', True)", | ||
"$@train#trainer.run()", | ||
"$dist.destroy_process_group()" | ||
] | ||
} |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.