From 3222959c5ed6f3f5cdb29c785387fba37e53fd14 Mon Sep 17 00:00:00 2001 From: Tulsi Shah <tulsishah@google.com> 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 <tulsishah@google.com> 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 <tulsishah@google.com> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="AutoImportSettings"> + <option name="autoReloadType" value="SELECTIVE" /> + </component> + <component name="ChangeListManager"> + <list default="true" id="0736ecc7-e6dd-4609-afcc-ecedb85c6899" name="Changes" comment=""> + <change beforePath="$PROJECT_DIR$/main_dino.py" beforeDir="false" afterPath="$PROJECT_DIR$/main_dino.py" afterDir="false" /> + </list> + <option name="SHOW_DIALOG" value="false" /> + <option name="HIGHLIGHT_CONFLICTS" value="true" /> + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> + <option name="LAST_RESOLUTION" value="IGNORE" /> + </component> + <component name="G3PluginsProjectSettings"> + <appliedSettings> + <entry key="LinkifyInternalShortlinks" value="true" /> + <entry key="RecognizedNullableAnnotations" value="true" /> + </appliedSettings> + </component> + <component name="Git.Settings"> + <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> + </component> + <component name="MarkdownSettingsMigration"> + <option name="stateVersion" value="1" /> + </component> + <component name="ProjectId" id="2Xy4fjGc4QUEXOOWOMMxbamNGM7" /> + <component name="ProjectViewState"> + <option name="hideEmptyMiddlePackages" value="true" /> + <option name="showLibraryContents" value="true" /> + </component> + <component name="PropertiesComponent"><![CDATA[{ + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.go.formatter.settings.were.checked": "true", + "RunOnceActivity.go.migrated.go.modules.settings": "true", + "WebServerToolWindowFactoryState": "false", + "go.import.settings.migrated": "true", + "last_opened_file_path": "/usr/local/google/home/tulsishah/dino", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" + } +}]]></component> + <component name="RunManager"> + <configuration default="true" type="PythonConfigurationType" factoryName="Python"> + <module name="dino" /> + <option name="INTERPRETER_OPTIONS" value="" /> + <option name="PARENT_ENVS" value="true" /> + <envs> + <env name="PYTHONUNBUFFERED" value="1" /> + </envs> + <option name="SDK_HOME" value="" /> + <option name="WORKING_DIRECTORY" value="" /> + <option name="IS_MODULE_SDK" value="false" /> + <option name="ADD_CONTENT_ROOTS" value="true" /> + <option name="ADD_SOURCE_ROOTS" value="true" /> + <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> + <option name="SCRIPT_NAME" value="" /> + <option name="PARAMETERS" value="" /> + <option name="SHOW_COMMAND_LINE" value="false" /> + <option name="EMULATE_TERMINAL" value="false" /> + <option name="MODULE_MODE" value="false" /> + <option name="REDIRECT_INPUT" value="false" /> + <option name="INPUT_FILE" value="" /> + <method v="2" /> + </configuration> + </component> + <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> + <component name="TaskManager"> + <task active="true" id="Default" summary="Default task"> + <changelist id="0736ecc7-e6dd-4609-afcc-ecedb85c6899" name="Changes" comment="" /> + <created>1699588090574</created> + <option name="number" value="Default" /> + <option name="presentableId" value="Default" /> + <updated>1699588090574</updated> + <workItem from="1699588091851" duration="3209000" /> + <workItem from="1700627221699" duration="7000" /> + </task> + <servers /> + </component> + <component name="TypeScriptGeneratedFilesManager"> + <option name="version" value="3" /> + </component> + <component name="VgoProject"> + <settings-migrated>true</settings-migrated> + </component> +</project> \ 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 <tulsishah@google.com> 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 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="VcsDirectoryMappings"> - <mapping directory="" vcs="Git" /> - </component> -</project> \ 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 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="AutoImportSettings"> - <option name="autoReloadType" value="SELECTIVE" /> - </component> - <component name="ChangeListManager"> - <list default="true" id="0736ecc7-e6dd-4609-afcc-ecedb85c6899" name="Changes" comment=""> - <change beforePath="$PROJECT_DIR$/main_dino.py" beforeDir="false" afterPath="$PROJECT_DIR$/main_dino.py" afterDir="false" /> - </list> - <option name="SHOW_DIALOG" value="false" /> - <option name="HIGHLIGHT_CONFLICTS" value="true" /> - <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> - <option name="LAST_RESOLUTION" value="IGNORE" /> - </component> - <component name="G3PluginsProjectSettings"> - <appliedSettings> - <entry key="LinkifyInternalShortlinks" value="true" /> - <entry key="RecognizedNullableAnnotations" value="true" /> - </appliedSettings> - </component> - <component name="Git.Settings"> - <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> - </component> - <component name="MarkdownSettingsMigration"> - <option name="stateVersion" value="1" /> - </component> - <component name="ProjectId" id="2Xy4fjGc4QUEXOOWOMMxbamNGM7" /> - <component name="ProjectViewState"> - <option name="hideEmptyMiddlePackages" value="true" /> - <option name="showLibraryContents" value="true" /> - </component> - <component name="PropertiesComponent"><![CDATA[{ - "keyToString": { - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "RunOnceActivity.go.formatter.settings.were.checked": "true", - "RunOnceActivity.go.migrated.go.modules.settings": "true", - "WebServerToolWindowFactoryState": "false", - "go.import.settings.migrated": "true", - "last_opened_file_path": "/usr/local/google/home/tulsishah/dino", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)", - "nodejs_package_manager_path": "npm", - "vue.rearranger.settings.migration": "true" - } -}]]></component> - <component name="RunManager"> - <configuration default="true" type="PythonConfigurationType" factoryName="Python"> - <module name="dino" /> - <option name="INTERPRETER_OPTIONS" value="" /> - <option name="PARENT_ENVS" value="true" /> - <envs> - <env name="PYTHONUNBUFFERED" value="1" /> - </envs> - <option name="SDK_HOME" value="" /> - <option name="WORKING_DIRECTORY" value="" /> - <option name="IS_MODULE_SDK" value="false" /> - <option name="ADD_CONTENT_ROOTS" value="true" /> - <option name="ADD_SOURCE_ROOTS" value="true" /> - <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> - <option name="SCRIPT_NAME" value="" /> - <option name="PARAMETERS" value="" /> - <option name="SHOW_COMMAND_LINE" value="false" /> - <option name="EMULATE_TERMINAL" value="false" /> - <option name="MODULE_MODE" value="false" /> - <option name="REDIRECT_INPUT" value="false" /> - <option name="INPUT_FILE" value="" /> - <method v="2" /> - </configuration> - </component> - <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> - <component name="TaskManager"> - <task active="true" id="Default" summary="Default task"> - <changelist id="0736ecc7-e6dd-4609-afcc-ecedb85c6899" name="Changes" comment="" /> - <created>1699588090574</created> - <option name="number" value="Default" /> - <option name="presentableId" value="Default" /> - <updated>1699588090574</updated> - <workItem from="1699588091851" duration="3209000" /> - <workItem from="1700627221699" duration="7000" /> - </task> - <servers /> - </component> - <component name="TypeScriptGeneratedFilesManager"> - <option name="version" value="3" /> - </component> - <component name="VgoProject"> - <settings-migrated>true</settings-migrated> - </component> -</project> \ No newline at end of file