From 3222959c5ed6f3f5cdb29c785387fba37e53fd14 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 10 Nov 2023 04:05:05 +0000 Subject: [PATCH 1/4] changes to support pytorch2.0 --- eval_copy_detection.py | 7 ++++++- eval_image_retrieval.py | 8 +++++++- eval_knn.py | 7 ++++++- eval_linear.py | 6 +++++- main_dino.py | 12 ++++++++++-- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/eval_copy_detection.py b/eval_copy_detection.py index 73dcd5078..320800a79 100644 --- a/eval_copy_detection.py +++ b/eval_copy_detection.py @@ -223,7 +223,12 @@ def extract_features(image_list, model, args): parser.add_argument('--num_workers', default=10, type=int, help='Number of data loading workers per GPU.') parser.add_argument("--dist_url", default="env://", type=str, help="""url used to set up distributed training; see https://pytorch.org/docs/stable/distributed.html""") - parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") + # In pytorch 2.0 argument name changes to --local-rank + if torch.__version__ >= "2.0.0": + parser.add_argument("--local-rank", default=0, type=int, help="Please ignore and do not set this argument.") + else : + parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") + args = parser.parse_args() utils.init_distributed_mode(args) diff --git a/eval_image_retrieval.py b/eval_image_retrieval.py index 999f8c900..2017a9c04 100644 --- a/eval_image_retrieval.py +++ b/eval_image_retrieval.py @@ -94,7 +94,13 @@ def config_qimname(cfg, i): parser.add_argument('--num_workers', default=10, type=int, help='Number of data loading workers per GPU.') parser.add_argument("--dist_url", default="env://", type=str, help="""url used to set up distributed training; see https://pytorch.org/docs/stable/distributed.html""") - parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") + # In pytorch 2.0 argument name changes to --local-rank + if torch.__version__ >= "2.0.0": + parser.add_argument("--local-rank", default=0, type=int, help="Please ignore and do not set this argument.") + else : + parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") + + args = parser.parse_args() utils.init_distributed_mode(args) diff --git a/eval_knn.py b/eval_knn.py index fe99a2604..15330ded0 100644 --- a/eval_knn.py +++ b/eval_knn.py @@ -209,7 +209,12 @@ def __getitem__(self, idx): parser.add_argument('--num_workers', default=10, type=int, help='Number of data loading workers per GPU.') parser.add_argument("--dist_url", default="env://", type=str, help="""url used to set up distributed training; see https://pytorch.org/docs/stable/distributed.html""") - parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") + # In pytorch 2.0 argument name changes to --local-rank + if torch.__version__ >= "2.0.0": + parser.add_argument("--local-rank", default=0, type=int, help="Please ignore and do not set this argument.") + else : + parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") + parser.add_argument('--data_path', default='/path/to/imagenet/', type=str) args = parser.parse_args() diff --git a/eval_linear.py b/eval_linear.py index cdef16b47..03e383b24 100644 --- a/eval_linear.py +++ b/eval_linear.py @@ -270,7 +270,11 @@ def forward(self, x): parser.add_argument('--batch_size_per_gpu', default=128, type=int, help='Per-GPU batch-size') parser.add_argument("--dist_url", default="env://", type=str, help="""url used to set up distributed training; see https://pytorch.org/docs/stable/distributed.html""") - parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") + # In pytorch 2.0 argument name changes to --local-rank + if torch.__version__ >= "2.0.0": + parser.add_argument("--local-rank", default=0, type=int, help="Please ignore and do not set this argument.") + else : + parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") parser.add_argument('--data_path', default='/path/to/imagenet/', type=str) parser.add_argument('--num_workers', default=10, type=int, help='Number of data loading workers per GPU.') parser.add_argument('--val_freq', default=1, type=int, help="Epoch frequency for validation.") diff --git a/main_dino.py b/main_dino.py index cade9873d..78a91304e 100644 --- a/main_dino.py +++ b/main_dino.py @@ -125,9 +125,13 @@ def get_args_parser(): parser.add_argument('--num_workers', default=10, type=int, help='Number of data loading workers per GPU.') parser.add_argument("--dist_url", default="env://", type=str, help="""url used to set up distributed training; see https://pytorch.org/docs/stable/distributed.html""") - parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") - return parser + # In pytorch 2.0 argument name changes to --local-rank + if torch.__version__ >= "2.0.0": + parser.add_argument("--local-rank", default=0, type=int, help="Please ignore and do not set this argument.") + else : + parser.add_argument("--local_rank", default=0, type=int, help="Please ignore and do not set this argument.") + return parser def train_dino(args): utils.init_distributed_mode(args) @@ -221,6 +225,10 @@ def train_dino(args): args.epochs, ).cuda() + # torch.compile() is a new feature in PyTorch 2.0 that can improve the performance of PyTorch code. + if torch.__version__ >= "2.0.0": + dino_loss = torch.compile(dino_loss) + # ============ preparing optimizer ... ============ params_groups = utils.get_params_groups(student) if args.optimizer == "adamw": From c1d09d225ce20a4c131530305867a049e7f5c078 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 10 Nov 2023 05:10:32 +0000 Subject: [PATCH 2/4] adding test code --- main_dino.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main_dino.py b/main_dino.py index 78a91304e..78a9ea781 100644 --- a/main_dino.py +++ b/main_dino.py @@ -227,6 +227,7 @@ def train_dino(args): # torch.compile() is a new feature in PyTorch 2.0 that can improve the performance of PyTorch code. if torch.__version__ >= "2.0.0": + print("In Compile") dino_loss = torch.compile(dino_loss) # ============ preparing optimizer ... ============ From d0f3ccb5219b8b9247e5929726331229d0ce1b4c Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Wed, 22 Nov 2023 04:27:47 +0000 Subject: [PATCH 3/4] pytorch2.0 support changes --- .idea/vcs.xml | 6 +++ .idea/workspace.xml | 92 +++++++++++++++++++++++++++++++++++++++++++++ main_dino.py | 1 - 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 000000000..c4b75ed62 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1699588090574 + + + + + + + true + + \ No newline at end of file diff --git a/main_dino.py b/main_dino.py index 78a9ea781..78a91304e 100644 --- a/main_dino.py +++ b/main_dino.py @@ -227,7 +227,6 @@ def train_dino(args): # torch.compile() is a new feature in PyTorch 2.0 that can improve the performance of PyTorch code. if torch.__version__ >= "2.0.0": - print("In Compile") dino_loss = torch.compile(dino_loss) # ============ preparing optimizer ... ============ From 5d77c35db4e942cd5ab12ad0082adb69aad2c21f Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Wed, 22 Nov 2023 04:28:01 +0000 Subject: [PATCH 4/4] pytorch2.0 support changes --- .idea/vcs.xml | 6 --- .idea/workspace.xml | 92 --------------------------------------------- 2 files changed, 98 deletions(-) delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfb..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index c4b75ed62..000000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1699588090574 - - - - - - - true - - \ No newline at end of file