Skip to content

Commit

Permalink
modextravars->modextrapaths for TORCH_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasHoffmann77 committed Nov 15, 2023
1 parent a0a7e40 commit 88708c7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ exts_list = [
'patches': [
'Model-Angelo-1.0.9_relax_requirements.patch',
'Model-Angelo-1.0.9_add_init_py.patch',
'Model-Angelo-1.0.9_multi_torch_home.patch',
],
'source_urls': ['https://github.com/%(github_account)s/%(name)s/archive'],
'sources': ['v%(version)s.tar.gz'],
Expand All @@ -56,6 +57,8 @@ exts_list = [
'570217999537eb55f5e55bb842a60f58d00850eaace40e5726e2ac058d003986'},
{'Model-Angelo-1.0.9_add_init_py.patch':
'7d3144ddac92d5800d9a6993bf50a3850627bc836ad01917be531fdd690b72d3'},
{'Model-Angelo-1.0.9_multi_torch_home.patch':
'96c4da9739a267b2afd55a6cb4d1b55915f15557c7e14086bfd7d15da3239c2b'},
],
}),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Thomas Hoffmann, EMBL Heidelberg, [email protected], 2023/11
# allow to use TORCH_HOME with modextravars.
# Automatic download of models and language is disabled for multi TORCH_HOME.
diff -ru model-angelo-1.0.9/model_angelo/utils/misc_utils.py model-angelo-1.0.9_multi_torch_home/model_angelo/utils/misc_utils.py
--- model-angelo-1.0.9/model_angelo/utils/misc_utils.py 2023-10-27 16:42:58.000000000 +0200
+++ model-angelo-1.0.9_multi_torch_home/model_angelo/utils/misc_utils.py 2023-11-14 18:34:46.230638397 +0100
@@ -123,6 +123,8 @@
try:
model = esm.pretrained.load_model_and_alphabet_hub(esm_model_name)
except:
+ is_torch_home_multi=False if os.getenv('TORCH_HOME')==None else len(os.getenv('TORCH_HOME').split(':'))>1
+ assert is_torch_home_multi == False
model = esm.pretrained.load_model_and_alphabet_local(
os.path.join(
torch.hub.get_dir(), "checkpoints", esm_model_name + ".pt"
diff -ru model-angelo-1.0.9/model_angelo/utils/torch_utils.py model-angelo-1.0.9_multi_torch_home/model_angelo/utils/torch_utils.py
--- model-angelo-1.0.9/model_angelo/utils/torch_utils.py 2023-10-27 16:42:58.000000000 +0200
+++ model-angelo-1.0.9_multi_torch_home/model_angelo/utils/torch_utils.py 2023-11-14 18:35:39.669951044 +0100
@@ -446,7 +446,17 @@
dest = os.path.join(
torch.hub.get_dir(), "checkpoints", "model_angelo_v1.0", bundle_name
)
- if os.path.isfile(os.path.join(dest, "success.txt")):
+ is_torch_home_multi=False if os.getenv('TORCH_HOME')==None else len(os.getenv('TORCH_HOME').split(':'))>1
+ if (is_torch_home_multi):
+ torch_homes=os.getenv('TORCH_HOME').split(':')
+ for torch_home in torch_homes:
+ dest = os.path.join(
+ torch_home, "hub", "checkpoints", "model_angelo_v1.0", bundle_name
+ )
+ if os.path.isfile(os.path.join(dest, "success.txt")):
+ return dest
+ assert False, "Model ownload disabled, because multiple paths defined in $TORCH_HOME. %s" % dest
+ elif os.path.isfile(os.path.join(dest, "success.txt")):
return dest

print(f"Setting up bundle with name: {bundle_name} for the first time.")
@@ -503,6 +513,20 @@


def download_and_install_esm_model(esm_model_name: str) -> str:
+ is_torch_home_multi=False if os.getenv('TORCH_HOME')==None else len(os.getenv('TORCH_HOME').split(':'))>1
+ if is_torch_home_multi:
+ torch_homes = os.getenv('TORCH_HOME').split(':')
+ for torch_home in torch_homes:
+ dest_model = os.path.join(
+ torch_home, "checkpoints", esm_model_name + ".pt"
+ )
+ dest_regr = os.path.join(
+ torch_home, "checkpoints", esm_model_name + "-contact-regression.pt"
+ )
+ if os.path.isfile(dest_model) and os.path.isfile(dest_regr):
+ return dest_model
+ assert is_torch_home_multi==False, 'Language model download disabled, because multiple paths are set in $TORCH_HOME'
+
permissions = (
stat.S_IROTH
| stat.S_IXOTH
Only in model-angelo-1.0.9_multi_torch_home/model_angelo/utils: .torch_utils.py.swp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ sources = [
},
]
checksums = [
{'esm1b_t33_650M_UR50S.pt': 'fd2de9d62994cff03a301f43ce92e9c9a31e9317109e09276f750eddc1aa6b5e'},
{'esm1b_t33_650M_UR50S.pt': '0569754efaff7dcb7e068c27367bc73f10afb4b450ea30aac30d9bc60783a8b1'},
{'esm1b_t33_650M_UR50S-contact-regression.pt': '77193a8814f0db0b36a03aebb1a311adc6b4745f463c04839defc15407bbb28a'},
{'original-7733060.zip': '55bda1751045030f6ed70af55670819f9ada78055b042b9370080df881b6a5bd'},
{'original_no_seq-7733060.zip': '2e66c7748a446b7c7845e7ff60a2b4e515853ba2093062407cff00ce38550a42'},
Expand All @@ -95,7 +95,7 @@ _success = [

install_cmd = '%s ' % '&&'.join(_success)

modextravars = {'TORCH_HOME': '%%(installdir)s/%s' % _torch_home}
modextrapaths= {'TORCH_HOME': _torch_home}

sanity_check_paths = {
'files': [
Expand Down

0 comments on commit 88708c7

Please sign in to comment.