Views
No views yet
| Parameter | Value |
|---|---|
| Layers | 30 |
| Attention heads | 10 |
| Embedding dimension | 640 |
| FFN hidden dimension | 1792 (SwiGLU, multiple_of=256) |
| Vocabulary size | 37 |
| Positional encoding | RoPE (base=10000, non-interleaved) |
| Normalization | RMSNorm |
| Architecture | Pre-LN Transformer with SwiGLU FFN |
| Max sequence length | 4096 |
<cls>, <pad>, <eos>, <unk>, the 25 amino-acid
letters (L A G V S E R T I D P K Q N F Y M H W C X B U Z O, uppercase),
the 4 DNA nucleotides (a t c g, lowercase), strand markers <+> / <->,
and <mask> / <sep>. Amino-acid and nucleotide tokens share the alphabet
by case (uppercase = amino acid, lowercase = nucleotide).tattabio/gLM2_150Mtattabio/gLM2_150M
weights with attn_implementation="sdpa". The added eager and
flash_attention_2 backends agree within fp32 kernel drift (maximum
full-network eager difference 4.43e-4) and bf16 cosine similarity >= 0.9994,
respectively. Verified on an NVIDIA H100 with PyTorch 2.7 / CUDA 12.1import torch
2from transformers import AutoTokenizer, AutoModel
3
4tokenizer = AutoTokenizer.from_pretrained("Taykhoom/gLM-150M", trust_remote_code=True)
5model = AutoModel.from_pretrained("Taykhoom/gLM-150M", trust_remote_code=True)
6model.eval()
7
8# Canonical gLM2 input: amino acids (uppercase) + DNA (lowercase) + strand markers.
9sequence = (
10 "<+>MALTKVEKRNRIKRRVRGKISGTQASPRLSVYKSNK"
11 "<+>aatttaaggaa"
12 "<->MLGIDNIERVKPGGLELVDRLVAVNRVTKVTKGGRAFGFSAIVVVGNED"
13)
14enc = tokenizer([sequence], return_tensors="pt")
15
16with torch.no_grad():
17 out = model(**enc)
18
19token_emb = out.last_hidden_state # (batch, seq_len, 640)
20mask = enc.attention_mask.unsqueeze(-1).to(token_emb.dtype)
21mean_emb = (token_emb * mask).sum(1) / mask.sum(1) # masked mean pooling
22
23# Intermediate layers
24out_all = model(**enc, output_hidden_states=True)
25layer15_emb = out_all.hidden_states[15] # after block 15U/u with t, and prepends
<+>. The three calls below produce identical token sequences:1dna_tokenizer = AutoTokenizer.from_pretrained(
2 "Taykhoom/gLM-150M", trust_remote_code=True, auto_prepare_dna=True
3)
4dna_tokenizer(["ATCGATCG", "atcgatcg", "AUCGAUCG"], return_tensors="pt")1from transformers import AutoTokenizer, AutoModelForMaskedLM
2
3tokenizer = AutoTokenizer.from_pretrained("Taykhoom/gLM-150M", trust_remote_code=True)
4model = AutoModelForMaskedLM.from_pretrained("Taykhoom/gLM-150M", trust_remote_code=True)
5model.eval()
6
7enc = tokenizer(["<+>MA<mask>K"], return_tensors="pt")
8with torch.no_grad():
9 logits = model(**enc).logits # (1, seq_len, 37)1# SDPA (PyTorch 2.0+, default upstream backend) -- recommended for fp32
2model = AutoModel.from_pretrained("Taykhoom/gLM-150M", trust_remote_code=True,
3 attn_implementation="sdpa")
4
5# Flash Attention 2 (requires flash-attn package) -- fastest on long sequences
6model = AutoModel.from_pretrained("Taykhoom/gLM-150M", trust_remote_code=True,
7 attn_implementation="flash_attention_2",
8 dtype=torch.bfloat16)flash_attention_2 as separate
implementations selectable via attn_implementation, with eager falling back
automatically when output_attentions=True is requested.flash_attention_2 in mixed precision. When output_attentions=True, all
backends use eager attention and return fp32 post-softmax probabilities.auto_prepare_dna=True is provided only for
callers that explicitly want plain DNA/RNA normalization. Strand markers are
exposed as additional special tokens so downstream masking utilities can
exclude them.1@article{cornman2024_glm2,
2 title = {The {OMG} dataset: An Open MetaGenomic corpus for mixed-modality genomic language modeling},
3 author = {Cornman, Andre and West-Roberts, Jacob and Camargo, Antonio Pedro and Roux, Simon and Beracochea, Martin and Mirdita, Milot and Ovchinnikov, Sergey and Hwang, Yunha},
4 journal = {bioRxiv},
5 year = {2024},
6 doi = {10.1101/2024.08.14.607850}
7}tattabio/gLM2_150M on the Hub.
Hugging Face port maintained by Taykhoom Dalal.