Skip to content

Commit

Permalink
[Fix] Fix accepting an unexpected argument local-rank in PyTorch 2.0 (
Browse files Browse the repository at this point in the history
  • Loading branch information
xiexinch committed Mar 30, 2023
1 parent 15979db commit 23fb3a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def parse_args():
help='job launcher')
parser.add_argument(
'--tta', action='store_true', help='Test time augmentation')
parser.add_argument('--local_rank', type=int, default=0)
# When using PyTorch version >= 2.0.0, the `torch.distributed.launch`
# will pass the `--local-rank` parameter to `tools/train.py` instead
# of `--local_rank`.
parser.add_argument('--local_rank', '--local-rank', type=int, default=0)
args = parser.parse_args()
if 'LOCAL_RANK' not in os.environ:
os.environ['LOCAL_RANK'] = str(args.local_rank)
Expand Down
5 changes: 4 additions & 1 deletion tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def parse_args():
choices=['none', 'pytorch', 'slurm', 'mpi'],
default='none',
help='job launcher')
parser.add_argument('--local_rank', type=int, default=0)
# When using PyTorch version >= 2.0.0, the `torch.distributed.launch`
# will pass the `--local-rank` parameter to `tools/train.py` instead
# of `--local_rank`.
parser.add_argument('--local_rank', '--local-rank', type=int, default=0)
args = parser.parse_args()
if 'LOCAL_RANK' not in os.environ:
os.environ['LOCAL_RANK'] = str(args.local_rank)
Expand Down

0 comments on commit 23fb3a9

Please sign in to comment.