Skip to content
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

Changes to support pytorch2.0 #262

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion eval_copy_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion eval_image_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion eval_knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 5 additions & 1 deletion eval_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
13 changes: 11 additions & 2 deletions main_dino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -221,6 +225,11 @@ 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":
print("In Compile")
dino_loss = torch.compile(dino_loss)

# ============ preparing optimizer ... ============
params_groups = utils.get_params_groups(student)
if args.optimizer == "adamw":
Expand Down