-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
440f837
commit ac2b0f0
Showing
5 changed files
with
51 additions
and
25 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
Empty file.
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,43 @@ | ||
""" | ||
Runs either `.fit()` or `.test()` on a single node across multiple gpus. | ||
""" | ||
from argparse import ArgumentParser | ||
|
||
from pytorch_lightning import Trainer, seed_everything | ||
from tests.base import EvalModelTemplate | ||
import os | ||
import torch | ||
|
||
|
||
def main(): | ||
seed_everything(1234) | ||
parser = ArgumentParser(add_help=False) | ||
parser = Trainer.add_argparse_args(parser) | ||
parser.add_argument('--trainer_method', default='fit') | ||
parser.add_argument('--tmpdir') | ||
parser.set_defaults(gpus=2) | ||
parser.set_defaults(distributed_backend="ddp") | ||
args = parser.parse_args() | ||
|
||
model = EvalModelTemplate() | ||
trainer = Trainer.from_argparse_args(args) | ||
|
||
result = {} | ||
if args.trainer_method == 'fit': | ||
trainer.fit(model) | ||
result = {'status': 'complete', 'method': args.trainer_method, 'result': None} | ||
if args.trainer_method == 'test': | ||
result = trainer.test(model) | ||
result = {'status': 'complete', 'method': args.trainer_method, 'result': result} | ||
if args.trainer_method == 'fit_test': | ||
trainer.fit(model) | ||
result = trainer.test(model) | ||
result = {'status': 'complete', 'method': args.trainer_method, 'result': result} | ||
|
||
if len(result) > 0: | ||
file_path = os.path.join(args.tmpdir, 'ddp.result') | ||
torch.save(result, file_path) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |