Proto is not affiliated with NVIDIA, Arc Institute, and University of California, San Francisco. This toolkit is open source and builds on the implementations produced by these organizations. Product names, logos, and trademarks are the property of their respective owners.
Background
Encodon is a BERT-style Transformer encoder trained with a masked-language-modeling objective over codon tokens (Darabi et al., 2025). Each coding sequence is split into in-frame codons, a fraction of codon tokens are masked, and the model predicts the original codon from its full bidirectional context. Because the vocabulary is codons rather than amino acids, the model learns the language of codon translation — which synonymous codon is expected in a given context — and not only the encoded protein. The released family spans four checkpoints (80M, 600M, 1B parameters, plus a codon-frequency-aware-masking 1B variant), all reading sequences up to 2048 tokens, i.e. coding sequences up to(2048 - 2) × 3 = 6138 nt after the CLS/SEP tokens.
Tools
CodonFM Fitness (codonfm-fitness)
Runs the upstream Encodon fitness routine: one unmasked forward pass, followed by the mean log-probability assigned to each visible non-padding input token. The mean includes the CLS and SEP special tokens as well as the codons. Higher is more model-typical, but this score is not masked pseudo-log-likelihood.API Reference
Input: CodonSequenceInput
Input: CodonSequenceInput
U maps to T and each length must be a multiple of 3 (codon-aligned) and at most 6138 nt.Config: CodonFMFitnessConfig
Config: CodonFMFitnessConfig
True is coerced to 1 and False to 0.None waits indefinitely.BaseToolOutput.approx_equal), and the seed participates in cache keys. When None, cacheable seed-sensitive tools skip cache until seeded.encodon_80m, encodon_600m, encodon_1b, encodon_1b_cdwtApplications
Sequence fitness is a zero-shot naturalness score for ranking or filtering coding sequences: comparing codon-optimized designs against wild type, screening synthetic constructs, or scoring candidate CDS variants without any task-specific training.Usage Tips
- Fitness is a relative score against Encodon’s training distribution, not an absolute quantity. It is most meaningful when comparing related sequences of similar length; the per-token mean already normalizes for length, but very short sequences are noisy.
batch_sizetrades memory for throughput. Lower it if you OOM on long CDS, raise it for short sequences.
CodonFM Score (codonfm-score)
Scores individual codon substitutions by the reference-vs-alternate log-likelihood ratio at the mutated position. The reference codon is masked and the model’s log-probability of the reference and alternate codons is compared; a positive llr (ref − alt) means the model favors the reference and the substitution is model-disfavored.API Reference
Input: CodonFMScoreInput
Input: CodonFMScoreInput
Config: CodonFMScoreConfig
Config: CodonFMScoreConfig
True is coerced to 1 and False to 0.None waits indefinitely.BaseToolOutput.approx_equal), and the seed participates in cache keys. When None, cacheable seed-sensitive tools skip cache until seeded.encodon_80m, encodon_600m, encodon_1b, encodon_1b_cdwtOutput: CodonFMScoreOutput
Output: CodonFMScoreOutput
Applications
The masked log-likelihood ratio is a canonical zero-shot variant-effect estimator. Because Encodon is codon-level, it discriminates synonymous substitutions (same amino acid, different codon) that an amino-acid model cannot see — useful for studying codon-usage effects on expression and mRNA stability.Usage Tips
- Each mutation carries its own reference sequence, codon position (1-based), and ref/alt codons. The reference codon is validated against the sequence at that position, so an off-by-one frame error is caught before dispatch rather than silently mis-scored.
- Scores are position-conditional. The same substitution scored in different sequence contexts will differ; that context-dependence is the point.
CodonFM Gradient (codonfm-gradient)
Computes the gradient of the mean masked negative log-likelihood with respect to a relaxed (L, 64) distribution over all 64 DNA codons, including the three standard stop codons (lexicographic order AAA, AAC, AAG, AAT, …). Each row’s current argmax codon is the masked-language-model target. The Encodon weights are frozen; the relaxed distribution passes through Encodon’s embedding layer and normalization, each codon position is masked in turn, and a per-chunk backward pass accumulates the gradient. An optional Straight-Through Estimator runs the forward on hard one-hot codons while routing gradients through the soft probabilities.API Reference
Input: CodonFMGradientInput
Input: CodonFMGradientInput
(L, 64) in lexicographic DNA codon order (AAA, AAC, AAG, AAT, ...; see :data:CODONFM_CODON_VOCAB). L must be ≤ 2046 (Encodon’s positional cap minus the CLS/SEP tokens); over-length inputs raise ValueError. Each row’s argmax codon is used as that position’s masked-language-model target.softmax(input / temperature) before computing the gradient. When None, every input row must already be a probability distribution.Config: CodonFMGradientConfig
Config: CodonFMGradientConfig
encodon_80m, encodon_600m, encodon_1b, encodon_1b_cdwtFalse, uses soft blended codon embeddings directly.False for forward-only masked-log-likelihood scoring.True is coerced to 1 and False to 0.None waits indefinitely.BaseToolOutput.approx_equal), and the seed participates in cache keys. When None, cacheable seed-sensitive tools skip cache until seeded.Output: CodonFMGradientOutput
Output: CodonFMGradientOutput
None when compute_gradient=False.Applications
This exposes Encodon as a differentiable, codon-level naturalness prior for continuous sequence design — usable inside gradient descent, MCMC, or any optimization loop over relaxed coding sequences (e.g. codon optimization with a learned constraint).Usage Tips
temperatureconverts the raw input into a per-position distribution. The default1.0appliessoftmax(logits / T); set it toNoneonly when every row is already a non-negative probability distribution summing to 1.use_steenables the Straight-Through Estimator for stronger guidance toward discrete codons while keeping a usable gradient.compute_gradient=Falseruns forward-only. Thegradientfield isNonebutlossandmetricsare still populated. This is a masked pseudo-log-likelihood objective; it is distinct from the visible-token objective returned bycodonfm-fitness.
CodonFM Sampling (codonfm-sample)
Resamples a subset of codons in a coding sequence. A number of codon positions (num_mutations, or mask_fraction of the codons) are chosen at random, masked, and refilled from Encodon’s distribution over the 61 sense codons in a single forward pass. The sequence length is preserved and sampling cannot introduce a new stop codon. It can replace an existing stop if that position is selected, so keep a required terminal stop outside the editable region or restore it afterward.API Reference
Input: MaskableCodonSequenceInput
Input: MaskableCodonSequenceInput
___ to choose which positions are resampled.Config: CodonFMSampleConfig
Config: CodonFMSampleConfig
encodon_80m, encodon_600m, encodon_1b, encodon_1b_cdwt___ masks, which name the positions outright. fixed_positions pins codons that must survive, which is how a start or stop codon is kept intact.True is coerced to 1 and False to 0.None waits indefinitely.BaseToolOutput.approx_equal), and the seed participates in cache keys. When None, cacheable seed-sensitive tools skip cache until seeded.Applications
Masked-codon resampling is the local-edit primitive behind coding-sequence design: it proposes model-plausible synonymous or missense codon changes for directed-evolution / MCMC / genetic-algorithm loops (e.g. as the mutation generator in a Proto Language optimizer, paired with thecodonfm-fitness constraint).Usage Tips
num_mutationsoverridesmask_fraction. It sets an exact number of positions to resample, not a guaranteed Hamming distance: the model can draw the original codon again.temperaturecontrols diversity. Below 1.0 sharpens toward the model’s favorite codon; above 1.0 broadens exploration. Because sampling is stochastic, pass aseedfor reproducible proposals.
Toolkit Notes
These apply to every CodonFM tool in this toolkit (codonfm-fitness, codonfm-score, codonfm-embedding, codonfm-gradient, codonfm-sample).
- Checkpoints download on demand. The
nvidia/NV-CodonFM-Encodon-*-v1repos are public; the standalone worker fetches the.safetensorsweights and theirconfig.jsonon first use and caches them. No HuggingFace token is required (one is used automatically if present). - A CUDA GPU is required. The pinned upstream Encodon attention implementation uses xFormers kernels that do not provide a CPU execution path.
- Inputs are codon-aligned nucleotide sequences. Each length must be a multiple of 3; RNA
Uis mapped toT, while ambiguous bases such asNare rejected because upstream tokenization would shift codon positions. Inputs are not checked for a start codon, terminal stop, internal stops, or coding-strand orientation. - Max sequence length is 6138 nt (2046 codons). Encodon’s positional cap is 2048 tokens; longer inputs raise
ValueErrorrather than truncating. - The default checkpoint is
encodon_80m. It is the fastest; the 600M/1B checkpoints trade throughput for fidelity. Pick a larger one for final scoring.

Arc Institute
UCSF