JAX/Flax port of AbLang2's AbRep encoder: antibody language-model embeddings and per-block attention.
Project description
ablanx
ablanx is a faithful JAX/Flax port of the AbLang2 AbRep encoder. It loads the original AbLang2 weights unchanged and returns per-residue embeddings and per-block attention in a single JAX forward pass, so an antibody sequence prior can sit inside a larger JAX/Flax model.
AbLang2 is the work of the Oxford Protein Informatics Group (OPIG); this repository is a port, not a new model. Provenance and citation are in ATTRIBUTION.md and CITATION.cff.
Why use it
- Drop-in AbLang2 embeddings inside JAX/Flax workflows.
- No PyTorch dependency at inference (weights load from a plain npz).
- Pure JAX forward:
jit/vmap/grad-compatible and composable in a larger model. - Per-block attention returned directly from the same call.
- Numerically verified against the reference implementation (max abs 3.9e-6 across a 30-Fv panel).
Quickstart
Install:
pip install git+https://github.com/fabricagen/ablanx
# from a clone: pip install .
# imports as `ablang_jax`; PyPI (pip install ablanx) is planned.
Embeddings:
import numpy as np, jax.numpy as jnp
from ablang_jax import Ablanx, load_ablanx_params
model = Ablanx()
params = {"params": load_ablanx_params(dict(np.load("ablang2_weights.npz")))} # AbRep weights
tokens = jnp.array([[...]], dtype=jnp.int32) # AbLang2 token ids, shape [B, L]
mask = jnp.ones_like(tokens, dtype=jnp.float32) # 1 = keep, 0 = pad
hidden, attentions = model.apply(params, tokens, mask, return_attn=True)
# hidden: [B, L, 480] per-residue embeddings
# attentions: [12, B, 20, L, L] per-block attention maps
See Weights for the npz.
What it is
AbLang2 is an antibody-specific protein language model. Its encoder (AbRep) is a 12-block pre-norm
transformer: hidden 480, 20 heads, SwiGLU feed-forward, rotary position embeddings, vocab 26,
trained on paired antibody sequences. ablanx re-expresses AbRep in Flax so the original
BSD-3-Clause weights load without change, returning per-residue hidden states and per-block attention
maps in one forward pass.
Differentiability
The forward is a pure JAX function, so it composes inside a larger model and runs under jit,
vmap, and grad. Useful gradients flow with respect to:
- the model parameters (
params), and - any continuous input substituted for the token lookup, for example a soft or one-hot embedding passed in place of integer ids.
The public interface takes integer tokens, which are discrete and do not themselves admit
gradients; to optimize a sequence through the encoder, feed a continuous representation rather than
token ids. In the seam folder, ablanx runs frozen as a fixed sequence prior.
What works today
- The Flax AbRep encoder,
ablang_jax.model.Ablanx. - The PyTorch-to-Flax weight key mapping,
ablang_jax.model.load_ablanx_params, which maps an AbLang2 AbRepstate_dict(as numpy arrays) into the Flax parameter tree. - A weight exporter,
export_weights.py, that writes the AbRep weight npz from the reference model. - A precompute script,
ablang_jax.precompute, that runs the reference PyTorch AbLang2 over a set of antibody records and stores per-residue embeddings.
Validation
The JAX forward reproduces reference PyTorch AbLang2 to float32 precision. Across a 30-Fv panel (25
paired VH+VL and 5 VH-only, drawn from public PDB structures), per-residue embeddings match the
reference with maximum absolute difference 3.9e-6 (median 2.4e-6 per Fv) and cosine above 0.999999,
using the same weights. The weights are byte-identical to the reference AbRep state_dict (207 tensors,
exact match). Reproduce with test_agreement.py.
Weights
The weights are the original AbLang2 AbRep weights, unmodified (207 tensors).
- Export from the reference model (works today, no release needed):
pip install ablang2 torch && python export_weights.pywritesablang2_weights.npz, verified byte-identical to the reference. - A torch-free
ablang2_weights.npzis also attached to the GitHub release once one is tagged.
Point ABLANG_WEIGHTS at the npz, or pass dict(np.load(...)) to load_ablanx_params.
Not included
- Only the AbRep encoder (embeddings and attention) is ported. The amino-acid likelihood head used for the pseudo-log-likelihood (sequence naturalness) is not part of this encoder port; use the reference AbLang2 for likelihoods.
Precompute
Precompute embeddings for a set of records with the reference PyTorch ablang2:
export ABLANG_JAX_DATA=/path/to/records
python -m ablang_jax.precompute --data $ABLANG_JAX_DATA
Input records are npz shards named {train,test}_*.npz; see ablang_jax/precompute.py for the
expected per-record fields. Outputs default to ./out/ when paths are not set.
Tests
python test_shapes.py # forward, weight-key mapping, masking
ABLANG_WEIGHTS=ablang2_weights.npz python test_agreement.py # agreement vs reference (needs weights)
test_shapes.py needs no weights. test_agreement.py loads the committed golden panel
(golden_ablang2_panel.npz, reference embeddings for 30 Fvs) and checks the JAX forward matches every
one; it skips under pytest if ABLANG_WEIGHTS is unset.
Attribution
- Original model, training, and weights: AbLang2, Oxford Protein Informatics Group. https://github.com/oxpig/AbLang2 (BSD-3-Clause, Copyright (c) 2021, Tobias Hegelund Olsen).
- Paper: Olsen, Moal, Deane, "Addressing the antibody germline bias and its effect on language models for improved antibody design", bioRxiv 2024, doi:10.1101/2024.02.02.578678.
- This port: Fabricagen.
ablanx is the language-model component of the seam bundle, a JAX antibody Fv structure predictor that couples jaxfvld with ablanx. For antibody developability screening and repair, see sift: https://sift.fabricagen.ai (coming soon, ca 08/26)
License
BSD-3-Clause. This port preserves the original AbLang2 copyright (Copyright (c) 2021, Tobias Hegelund
Olsen) and adds Copyright (c) 2026, Fabricagen for the port. The upstream AbLang2 license was
confirmed BSD-3-Clause. See ATTRIBUTION.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ablanx-0.1.0.tar.gz.
File metadata
- Download URL: ablanx-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e96b5e62277dc4c1485c79f5973fc7ca50bbb63a545fa3b22c85c72d2726d8ec
|
|
| MD5 |
18bbbce6c36fbb4dabb714e4e2f82dca
|
|
| BLAKE2b-256 |
30cd10db8893f7659741a759889eba7ecc2c24399dc9e27a216ee9cf145b8668
|
Provenance
The following attestation bundles were made for ablanx-0.1.0.tar.gz:
Publisher:
publish.yml on fabricagen/ablanx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ablanx-0.1.0.tar.gz -
Subject digest:
e96b5e62277dc4c1485c79f5973fc7ca50bbb63a545fa3b22c85c72d2726d8ec - Sigstore transparency entry: 2209360826
- Sigstore integration time:
-
Permalink:
fabricagen/ablanx@28f787bddfc0cfbf7371ff91c0c92bcf3fc668df -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fabricagen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@28f787bddfc0cfbf7371ff91c0c92bcf3fc668df -
Trigger Event:
release
-
Statement type:
File details
Details for the file ablanx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ablanx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4c524edd6415b58a2d9e5acfba49cd635ff7fc6addc87a0566f0b9ce397ffee
|
|
| MD5 |
ab318dcede1ebb884de672a5b752cfc0
|
|
| BLAKE2b-256 |
93748a9ecc36d94cffcbeb7bb67eb0df024f1f2383b50cb60581cb4b53943b87
|
Provenance
The following attestation bundles were made for ablanx-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on fabricagen/ablanx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ablanx-0.1.0-py3-none-any.whl -
Subject digest:
a4c524edd6415b58a2d9e5acfba49cd635ff7fc6addc87a0566f0b9ce397ffee - Sigstore transparency entry: 2209360862
- Sigstore integration time:
-
Permalink:
fabricagen/ablanx@28f787bddfc0cfbf7371ff91c0c92bcf3fc668df -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fabricagen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@28f787bddfc0cfbf7371ff91c0c92bcf3fc668df -
Trigger Event:
release
-
Statement type: