-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
18 changed files
with
124 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ notebooks | |
.hydra | ||
old | ||
.idea | ||
hub | ||
*old | ||
lightning_logs | ||
results_neurips | ||
|
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 was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
experiment="clip_hub" | ||
notes=" | ||
**Goal**: Save all pretrained models to pytorch hub. | ||
" | ||
|
||
# parses special mode for running the script | ||
source `dirname $0`/../utils.sh | ||
|
||
SCRIPT=`realpath $0` | ||
SCRIPTPATH=`dirname $SCRIPT` | ||
pretrained_path="$SCRIPTPATH"/../../hub | ||
|
||
|
||
# define all the arguments modified or added to `conf`. If they are added use `+` | ||
kwargs=" | ||
experiment=$experiment | ||
timeout=$time | ||
encoder.z_dim=512 | ||
data@data_feat=coco | ||
featurizer=bottleneck_clip_lossyZ | ||
checkpoint@checkpoint_pred=bestValLoss | ||
featurizer.is_train=false | ||
evaluation.communication.ckpt_path=null | ||
$add_kwargs | ||
" | ||
|
||
for beta in "1e-01" "5e-02" "1e-02" | ||
do | ||
|
||
col_val_subset="" | ||
python utils/save_hub.py \ | ||
load_pretrained.experiment=$experiment \ | ||
$col_val_subset \ | ||
$kwargs \ | ||
featurizer.loss.beta=$beta \ | ||
paths.pretrained.load=$pretrained_path/beta$beta \ | ||
server=local \ | ||
trainer.gpus=0 \ | ||
load_pretrained.mode=[] | ||
|
||
done | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# name is automatic | ||
mode: AdamW | ||
kwargs: | ||
lr: 1e-3 | ||
weight_decay: 1e-5 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Save the rate estimator from a pretrained model to hub. | ||
This should be called by `python utils/save_hub.py <conf>` where <conf> sets all configs used to | ||
pretrain the model in the first place`. | ||
""" | ||
import logging | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import torch | ||
|
||
import hydra | ||
from omegaconf import OmegaConf | ||
|
||
MAIN_DIR = os.path.abspath(str(Path(__file__).parents[1])) | ||
CURR_DIR = os.path.abspath(str(Path(__file__).parents[0])) | ||
sys.path.append(MAIN_DIR) | ||
sys.path.append(CURR_DIR) | ||
|
||
|
||
from utils.load_pretrained import PretrainedAnalyser # isort:skip | ||
from utils.helpers import format_resolver # isort:skip | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@hydra.main(config_path=f"{MAIN_DIR}/config", config_name="load_pretrained") | ||
def main_cli(cfg): | ||
# uses main_cli sot that `main` can be called from notebooks. | ||
try: | ||
return main(cfg) | ||
except: | ||
logger.exception("Failed to save pretrained with this error:") | ||
# don't raise error because if multirun want the rest to work | ||
pass | ||
|
||
|
||
def main(cfg): | ||
|
||
analyser = PretrainedAnalyser(**cfg.load_pretrained.kwargs) | ||
|
||
logger.info(f"Collecting the data ..") | ||
analyser.collect_data(cfg, **cfg.load_pretrained.collect_data) | ||
|
||
rate_estimator = analyser.modules["featurizer"].rate_estimator | ||
model_name = f"{MAIN_DIR}/hub/beta{cfg.featurizer.loss.beta:.0e}/factorized_rate.pt" | ||
torch.save( | ||
rate_estimator.state_dict(), model_name, | ||
) | ||
|
||
logger.info(f"Saved pretrained model to {model_name}...") | ||
|
||
|
||
if __name__ == "__main__": | ||
OmegaConf.register_new_resolver("format", format_resolver) | ||
main_cli() |