smares commited on
Commit
340a699
·
verified ·
1 Parent(s): e9cd024

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +178 -22
README.md CHANGED
@@ -1,23 +1,179 @@
1
- ---
2
- license: mit
3
- library_name: pytorch
4
- tags:
5
- - pMHC
6
- - HLA-A*02:01
7
- - ESM
8
- - immunology
9
- model-index:
10
- - name: ESMCBA-A0201 v0.1
11
- results: []
12
- ---
13
-
14
- # ESMCBA – A*02:01 checkpoint (v0.1)
15
-
16
- Fine-tuned ESM-based model for epitope prediction on HLA-A*02:01.
17
-
18
- ## Usage
19
- ```python
20
- from models.A0201_v0.1.model import ESMCBAA0201
21
- m = ESMCBAA0201.from_hub()
22
- # now run m(...) with your usual input pipeline
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ESMCBA on Hugging Face Hub
2
+ Code: https://github.com/sermare/ESMCBA
3
+ Models: https://huggingface.co/smares/ESMCBA
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ A quick, no-friction guide to upload, version, and download your ESMCBA weights on the Hugging Face Hub. It covers both the command line and the Python API, shows where files are cached, and includes a tiny wrapper pattern so users can run your repo code against weights fetched from the Hub.
6
+
7
+ What is this
8
+ - ESMCBA is a set of allele-specific pMHC-I binding models built by continued pretraining of an ESM backbone on epitope data, then fine-tuned for IC50 prediction.
9
+ - This README explains how to:
10
+ 1) Upload your .pth checkpoints to smares/ESMCBA
11
+ 2) Download either everything or a single file
12
+ 3) Run your code using files from the local Hub cache or a chosen directory
13
+ 4) Keep code and weights cleanly separated: GitHub for code, Hub for models
14
+
15
+ Recommended workflow: Code on GitHub, weights on Hugging Face. It is standard in ML, keeps repos lean, and plays nicely with large files and versioning.
16
+
17
+ Prerequisites
18
+ pip install -U huggingface_hub
19
+ Optional but convenient
20
+ pip install -U hf_transfer # faster large file transfers
21
+
22
+ Log in once so the CLI and Python API can push and pull:
23
+ huggingface-cli login
24
+ or:
25
+ hf login
26
+
27
+ Uploading models
28
+ Choose one of the three common paths below. Pick the one that fits your workflow.
29
+
30
+ 1) CLI upload of a whole folder (recommended)
31
+ Uploads every .pth under your weights directory into the model repo.
32
+
33
+ # Create repo if it does not exist yet
34
+ hf repo create smares/ESMCBA --type model
35
+
36
+ # Upload all .pth files from your weights directory
37
+ hf upload smares/ESMCBA /global/scratch/users/sergiomar10/ESMCBA/models/weights --repo-type model --include "**/*.pth"
38
+
39
+ Notes
40
+ - You can pass --commit-message "add B1402 and B1503 final weights"
41
+ - You can add --private at repo creation if needed
42
+
43
+ 2) Python API upload
44
+ from huggingface_hub import HfApi
45
+
46
+ api = HfApi()
47
+ api.create_repo("smares/ESMCBA", repo_type="model", exist_ok=True)
48
+
49
+ api.upload_folder(
50
+ repo_id="smares/ESMCBA",
51
+ repo_type="model",
52
+ folder_path="/global/scratch/users/sergiomar10/ESMCBA/models/weights",
53
+ allow_patterns=["**/*.pth"], # only upload checkpoints
54
+ commit_message="Bulk upload of allele-specific ESMCBA weights"
55
+ )
56
+
57
+ 3) Git LFS
58
+ git lfs install
59
+ git clone https://huggingface.co/smares/ESMCBA
60
+ cd ESMCBA
61
+ cp /global/scratch/users/sergiomar10/ESMCBA/models/weights/*.pth .
62
+ git add .
63
+ git commit -m "Add B1402 and B1503 checkpoints"
64
+ git push
65
+
66
+ Downloading models
67
+ You can fetch the entire repository or just one file.
68
+
69
+ Option A. CLI
70
+ All files to a directory:
71
+ hf download smares/ESMCBA --repo-type model --local-dir ./models
72
+
73
+ Single file to current directory:
74
+ hf download smares/ESMCBA "ESMCBA_epitope_0.95_30_ESMMASK_epitope_FT_25_0.001_5e-05_AUG_3_HLAB1402_2_1e-05_1e-06__1_B1402_0404_Hubber_B1402_final.pth" --repo-type model --local-dir .
75
+
76
+ Option B. Python API
77
+ Single file:
78
+ from huggingface_hub import hf_hub_download
79
+
80
+ local_ckpt = hf_hub_download(
81
+ repo_id="smares/ESMCBA",
82
+ filename="ESMCBA_epitope_0.95_30_ESMMASK_epitope_FT_25_0.001_5e-05_AUG_3_HLAB1402_2_1e-05_1e-06__1_B1402_0404_Hubber_B1402_final.pth",
83
+ repo_type="model"
84
+ )
85
+ print(local_ckpt) # absolute path to cached file
86
+
87
+ Whole snapshot:
88
+ from huggingface_hub import snapshot_download
89
+ local_dir = snapshot_download(repo_id="smares/ESMCBA", repo_type="model")
90
+
91
+ Option C. Direct HTTP
92
+ wget https://huggingface.co/smares/ESMCBA/resolve/main/ESMCBA_epitope_..._final.pth
93
+
94
+ Where are files saved
95
+ By default, CLI and Python API store files under your HF cache, for example:
96
+ /global/home/users/sergiomar10/.cache/huggingface/hub/
97
+
98
+ - The exact file you downloaded shows up in .../blobs/<sha>
99
+ - A friendly path is created in .../snapshots/<commit_sha>/YOUR_FILE.pth
100
+
101
+ To override location, either:
102
+ - Use --local-dir <dir> with hf download, or
103
+ - Set HF_HOME=/path/to/cache to move the entire cache, for example:
104
+ export HF_HOME=/global/scratch/users/sergiomar10/.hf_cache
105
+
106
+ Running your code with Hub downloads
107
+ Users need both the repo code and the weights. Recommended layout:
108
+
109
+ # 1) Get the code
110
+ git clone https://github.com/sermare/ESMCBA
111
+ cd ESMCBA
112
+
113
+ # 2) Create or activate your env
114
+ source /clusterfs/nilah/sergio/miniconda3/etc/profile.d/conda.sh
115
+ conda activate /clusterfs/nilah/sergio/miniconda3/envs/ESM_cambrian
116
+
117
+ # 3) Download a checkpoint next to the code
118
+ hf download smares/ESMCBA "ESMCBA_epitope_..._B5101_final.pth" --local-dir ./models
119
+
120
+ Now run your script with the chosen .pth:
121
+ python3 ESMCBA/embeddings_generation.py --model_path ./models/ESMCBA_epitope_0.5_20_ESMMASK_epitope_FT_15_0.0001_1e-05_AUG_6_HLAB5101_5_0.001_1e-06__3_B5101_Hubber_B5101_final.pth --name B5101-ESMCBA --hla B5101 --encoding epitope --output_dir ./outputs
122
+
123
+ Pattern: resolve from Hub inside your script
124
+ You can also let the script pull from the Hub automatically if the user passes --model_path hf://smares/ESMCBA/<filename>.pth or just the filename. Minimal pattern:
125
+
126
+ # inside embeddings_generation.py
127
+ import os
128
+ from huggingface_hub import hf_hub_download
129
+
130
+ def resolve_model_path(path_or_name):
131
+ if os.path.isfile(path_or_name):
132
+ return path_or_name
133
+ if path_or_name.startswith("hf://"):
134
+ _, repo_id, filename = path_or_name.split("/", 2)[-1].split("/", 2)
135
+ return hf_hub_download(repo_id=repo_id, filename=filename, repo_type="model")
136
+ # fallback: treat as filename in the model repo
137
+ return hf_hub_download(repo_id="smares/ESMCBA", filename=path_or_name, repo_type="model")
138
+
139
+ # then, before torch.load
140
+ import torch
141
+ resolved_path = resolve_model_path(args.model_path)
142
+ state = torch.load(resolved_path, map_location="cpu") # or safetensors
143
+
144
+ FAQ
145
+ Do users need both GitHub and Hugging Face?
146
+ Yes. GitHub holds the code and docs. Hugging Face stores large weight files and versions them efficiently.
147
+
148
+ I want to fetch to the current directory instead of the cache.
149
+ Use --local-dir . with hf download or snapshot_download(local_dir=...).
150
+
151
+ I only want one file.
152
+ hf download smares/ESMCBA "filename.pth" --local-dir .
153
+
154
+ Upload throws permission or quota errors.
155
+ Check that you are logged in with the right account. For very large assets, ensure LFS is active and consider HF_HUB_ENABLE_HF_TRANSFER=1 for faster uploads.
156
+
157
+ Short examples
158
+ Upload a single checkpoint
159
+ hf upload smares/ESMCBA /path/to/B1503_final.pth --repo-type model --path_in_repo B1503_final.pth
160
+
161
+ Download everything into ./models
162
+ hf download smares/ESMCBA --repo-type model --local-dir ./models
163
+
164
+ Download a single file then run
165
+ hf download smares/ESMCBA "ESMCBA_epitope_..._B1402_final.pth" --repo-type model --local-dir .
166
+ python3 ESMCBA/embeddings_generation.py --model_path ./ESMCBA_epitope_..._B1402_final.pth --hla B1402 --encoding epitope --name B1402 --output_dir ./out
167
+
168
+ Recommended repo structure
169
+ ESMCBA/ # code from GitHub
170
+ ESMCBA/
171
+ embeddings_generation.py
172
+ ...
173
+ models/ # pulled from Hugging Face
174
+ ESMCBA_epitope_..._final.pth
175
+ outputs/
176
+ ...
177
+
178
+ License
179
+ Follow the license in the GitHub repo for code and the model card in the Hub repo for weights and usage terms.