README: fix package path (esmfold2_trimul_kernel), use from_pretrained(use_kernels=True), note build layout
Browse files
README.md
CHANGED
|
@@ -25,33 +25,50 @@ visibility)`, reading its parameters (`norm_start`/`norm_mix`/`proj_bundle`/
|
|
| 25 |
attribute names and forward signature** — that's the contract.
|
| 26 |
|
| 27 |
```python
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
out = model.infer_protein(seq)
|
| 31 |
```
|
| 32 |
|
| 33 |
## Layout
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
```
|
| 36 |
-
build.toml
|
| 37 |
-
flake.nix
|
| 38 |
-
torch-ext/
|
| 39 |
-
__init__.py
|
| 40 |
-
layers.py
|
| 41 |
-
trimul_with_residual.py
|
| 42 |
-
fused_dual_gemm.py
|
| 43 |
-
fused_ln_residual.py
|
| 44 |
-
trimul_einsum_triton.py
|
|
|
|
| 45 |
```
|
| 46 |
|
| 47 |
## Build & publish
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
```bash
|
| 50 |
nix build .#bundle # or: kernel-builder build (see kernel-builder docs)
|
| 51 |
-
# then push the built repo to the Hub and set repo_id in transformers'
|
| 52 |
-
# hub_kernels.py (currently the placeholder biohub/esmfold2-trimul-kernel).
|
| 53 |
```
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
## Validation
|
| 56 |
|
| 57 |
Swapped into all 124 `TriangleMultiplicativeBlock` instances of the real model
|
|
|
|
| 25 |
attribute names and forward signature** — that's the contract.
|
| 26 |
|
| 27 |
```python
|
| 28 |
+
import torch
|
| 29 |
+
from transformers import ESMFold2Model
|
| 30 |
+
|
| 31 |
+
# use_kernels=True swaps in this kernel for the 124 trimul sites (CUDA + inference).
|
| 32 |
+
model = ESMFold2Model.from_pretrained(
|
| 33 |
+
"biohub/ESMFold2", dtype=torch.bfloat16, device_map="cuda", use_kernels=True
|
| 34 |
+
).eval()
|
| 35 |
out = model.infer_protein(seq)
|
| 36 |
```
|
| 37 |
|
| 38 |
## Layout
|
| 39 |
|
| 40 |
+
The package name must match `kernels`' repo-derived name
|
| 41 |
+
(`repo_id.split("/")[-1].replace("-", "_")`), i.e. **`esmfold2_trimul_kernel`** for the
|
| 42 |
+
repo `…/esmfold2-trimul-kernel`, and `build.toml`'s `[general] name` must match it too.
|
| 43 |
+
`kernels.get_kernel` loads from `build/torch-universal/` (not `torch-ext/`).
|
| 44 |
+
|
| 45 |
```
|
| 46 |
+
build.toml # kernel-builder config (universal/Triton)
|
| 47 |
+
flake.nix # kernel-builder entry (verify vs current version)
|
| 48 |
+
torch-ext/esmfold2_trimul_kernel/ # source (read by kernel-builder)
|
| 49 |
+
__init__.py # exports the layer + the functional entry
|
| 50 |
+
layers.py # ESMFold2TriangleMultiplication (the Hub layer)
|
| 51 |
+
trimul_with_residual.py # kernel entrypoint
|
| 52 |
+
fused_dual_gemm.py # helper: gated dual GEMM
|
| 53 |
+
fused_ln_residual.py # helper: LN + transpose / residual-link epilogues
|
| 54 |
+
trimul_einsum_triton.py # helper: batched triangular einsum
|
| 55 |
+
build/torch-universal/esmfold2_trimul_kernel/ # loaded by kernels.get_kernel (same files)
|
| 56 |
```
|
| 57 |
|
| 58 |
## Build & publish
|
| 59 |
|
| 60 |
+
The `build/torch-universal/` dir checked in here is a hand-built universal layout
|
| 61 |
+
(the Triton package copied in — no compile step), which is sufficient for
|
| 62 |
+
`kernels.get_kernel`. To regenerate it properly with kernel-builder:
|
| 63 |
+
|
| 64 |
```bash
|
| 65 |
nix build .#bundle # or: kernel-builder build (see kernel-builder docs)
|
|
|
|
|
|
|
| 66 |
```
|
| 67 |
|
| 68 |
+
Mapped from transformers in `integrations/hub_kernels.py` under the layer name
|
| 69 |
+
`ESMFold2TriangleMultiplication`. Currently `repo_id = Rocketknight1/esmfold2-trimul-kernel`
|
| 70 |
+
(testing); move it to a `kernels-community` org and update `repo_id` before merging.
|
| 71 |
+
|
| 72 |
## Validation
|
| 73 |
|
| 74 |
Swapped into all 124 `TriangleMultiplicativeBlock` instances of the real model
|