Hi Phil Wang,
Created a little demo on how you can easily load pre-trained weights from the HuggingFace hub into your Enformer model. I've basically followed this guide which Sylvain (@sgugger) wrote recently. It's a new feature that let's you push model weights to the hub and allows to load them into any custom PyTorch/TF/Flax model.
From this PR, you can do (after pip install enformer-pytorch):
from enformer_pytorch import Enformer
model = Enformer.from_pretrained("nielsr/enformer-preview")
If you consent, then I'll transfer all weights to the eleutherai
organization on the hub, such that you can do from_pretrained("eleutherai/enformer-preview")
.
The weights are hosted here: https://huggingface.co/nielsr/enformer-preview. As you can see in the "files and versions" tab, it contains a pytorch_model.bin
file, which has a size of about 1GB. You can also load the other variant, as follows:
model = Enformer.from_pretrained("nielsr/enformer-corr_coef_obj")
To make it work, the only thing that is required is encapsulating all hyperparameters regarding the model architecture into a separate EnformerConfig
object (which I've defined in config_enformer.py). It can be instantiated as follows:
from enformer_pytorch import EnformerConfig
config = EnformerConfig(
dim = 1536,
depth = 11,
heads = 8,
output_heads = dict(human = 5313, mouse = 1643),
target_length = 896,
)
To initialize an Enformer model with randomly initialized weights, you can do:
from enformer_pytorch import Enformer
model = Enformer(config)
There's no need for the config.yml
and model_loader.py
files anymore, as these are now handled by HuggingFace :)
Let me know what you think about it :)
Kind regards,
Niels
To do:
- [x] upload remaining checkpoints to the hub
- [x] transfer checkpoints to the eleutherai organization
- [x] remove config.yml and model_loading.py scripts
- [x] update README