[Proposal] RoBERTa masked-LM adapter for TransformerBridge
I maintainer di solito rispondono entro 1 giorno
@Canonik ci sta già lavorando.
Dal 8/10/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
[Proposal] RoBERTa masked-LM adapter for TransformerBridge
Proposal
Add a RobertaArchitectureAdapter so RobertaForMaskedLM checkpoints (roberta-base, roberta-large, distilroberta-base and the many fine-tunes that keep the MLM head) load through TransformerBridge.boot_transformers.
Right now this fails at adapter selection:
ValueError: Unsupported architecture: RobertaForMaskedLM
even though transformer_lens/utilities/architectures.py already lists RobertaForMaskedLM under MASKED_LM_ARCHITECTURES and routes it to the masked-LM loader. The classifier knows about the family; but the factory doesn't.
Motivation
BERT is the only encoder-only text model the bridge supports. For anything that compares pretraining recipes, or reuses an existing probing / patching setup on a model that isn't BERT, RoBERTa is usually the next model people reach for, and it's currently a dead end in both HookedEncoder and the bridge. The concrete case is running the same activation-patching or probing code on bert-base-cased, roberta-base and distilroberta-base without changing anything but the model id.
I searched issues and PRs for "roberta" (open and closed) and found nothing. #918 added DistilBERT to the legacy loading_from_pretrained path and was closed unmerged in May 2025; it never touched the bridge, so I don't think it counts as prior art here.
Pitch
This is close to a prefix rename of the existing BERT adapter. I instantiated a tiny RobertaForMaskedLM and diffed its module tree against what bert.py maps:
| BERT | RoBERTa |
|---|---|
bert.embeddings.word_embeddings |
roberta.embeddings.word_embeddings |
bert.embeddings.position_embeddings |
roberta.embeddings.position_embeddings |
bert.encoder.layer |
roberta.encoder.layer |
cls.predictions.transform.LayerNorm |
lm_head.layer_norm |
cls.predictions.decoder |
lm_head.decoder |
Everything inside a layer (attention.self.{query,key,value}, attention.output.dense, both LayerNorms, intermediate.dense, output.dense) is identical, so the per-block submodules, the q/k/v/o rearrange conversions, supports_fold_ln = False for post-LN and supports_generation = False all carry over as-is. The decoder weight is tied to the word embeddings in both models.
So the plan would be:
supported_architectures/roberta.pywithRobertaArchitectureAdapter(BertArchitectureAdapter)that only overridescomponent_mappingwith the new names. Same shape asOlmo3ArchitectureAdapter(Olmo2ArchitectureAdapter).- The four registration sites from
supported_architectures/AGENTS.md:__init__.py,SUPPORTED_ARCHITECTURESin the factory,HF_SUPPORTED_ARCHITECTURES+CANONICAL_AUTHORS_BY_ARCH(["FacebookAI", "distilbert"]) intools/model_registry/__init__.py, andARCHITECTURE_DESCRIPTIONSingenerate_report.py(that one already has a RoBERTa string, it just isn't reachable). supported_models.jsonentries forFacebookAI/roberta-baseanddistilbert/distilroberta-basewithstatus: 0, then averify_modelsrun on both. distilroberta is 6 layers / 82M params so it's cheap to iterate on; roberta-base is the one people will actually use.- Tests: a unit adapter test next to
test_bert_adapter.py, and an integration test asserting HF logit parity, hook caching and a basic intervention on distilroberta. There is no bridge-side BERT integration test to copy (the BERT ones undertests/integrationandtests/acceptanceareHookedEncodertests), so this would be the first one for an encoder.
Two things that are not a rename and need a decision:
n_ctx.sources/transformers.pysetsn_ctx = max_position_embeddings, which is 514 for RoBERTa because HF reserves positions 0 and 1 (padding_idx + 1offset). Usable context is 512. The adapter should correct this son_ctxmatches what you can actually feed the model. Related:hook_pos_embedwill see position ids starting at 2, not 0, since HF computes them insideRobertaEmbeddings. The bridge runs the HF forward so the values are right, but anyone comparing position-embedding activations against BERT should know about the offset; Worth a line in the adapter docstring.- Tokenizer policy. RoBERTa is byte-level BPE with
<s>/</s>rather than WordPiece with[CLS]/[SEP]. Per the per-model tokenizer rule insupported_architectures/AGENTS.md,default_prepend_bosand padding side should come from each checkpoint'stokenizer_config.json, not be inherited from the BERT adapter.
Alternatives
- Load through
transformersdirectly and register forward hooks by hand. Works, but it's exactly the thing the bridge exists to avoid, and you loserun_with_cache, the hook aliases, and compatibility mode. - Port RoBERTa to
HookedEncoder. AGENTS.md says the bridge is the default for new work, and the BERT NSP note inmigrating_to_v3.mdalready points people at the bridge for new encoder features, so this seems like the wrong direction. - A single generic "BERT-like" adapter keyed on prefix., which is tempting, but the head module names differ enough between BERT, RoBERTa, ALBERT and ELECTRA that I think one subclass per family is clearer and matches how the repo handles other sibling families.
Additional context
distilbert/distilroberta-baseandFacebookAI/roberta-baseboth declarearchitectures: ["RobertaForMaskedLM"],model_type: roberta,pad_token_id: 1,type_vocab_size: 1,max_position_embeddings: 514. They differ only innum_hidden_layers(6 vs 12).token_type_embeddingsexists in both BERT and RoBERTa but withtype_vocab_size = 1in RoBERTa it's a constant. The BERT adapter doesn't map it either, so no change there.- Happy to do the PR, based on
dev, following the adapter workflow insupported_architectures/AGENTS.md. I can run verification for both models locally. Mostly opening this to check nobody else has it in flight and that aBertArchitectureAdaptersubclass is the shape you want.
Checklist
- I have checked that there is no similar issue in the repo (required)
- Lingua principale
- Python
- Stelle
- 3.9k
- Fork
- 708
- Merge medio
- 1g 17h
- PR unite (30g)
- 70
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TransformerLensOrg/TransformerLens
-
[Proposal] Backward Lens: support gated MLP gate/ up/ down gradient factorsForse già presa @janmenjayap l’ha presa 7 giorni fa. Apertacomplexity-moderate enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1832 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] Sparse probing: optional groups argument so rows from one prompt can't straddle the splitForse già presa @lorenzozanee l’ha presa 13 giorni fa. Apertacomplexity-simple enhancement help wanted TransformerBridge
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
TransformerLensOrg/TransformerLens#1813 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug Report] _BLOCK_LIST_ATTRS hardcoded name list silently drops Raven's blocks from composition-score / head-label analysisForse già presa @LightWork666 l’ha presa 17 giorni fa. Apertabug complexity-moderate TransformerBridge
TransformerLensOrg/TransformerLens#1791 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] SVD Circuits: singular-vector decomposition of a head's QK/ OV into causally-validated subfunctionsForse già presa @janmenjayap l’ha presa 28 giorni fa. Apertacomplexity-high enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1767 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] Relevance Lens (R-lens): a RelP/ LRP-based transport-matrix estimator for Jacobian Lens (J-lens) fit, readout, and interventionForse già presa @janmenjayap l’ha presa 30 giorni fa. Apertacomplexity-high enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1755 · 6 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TransformerLensOrg/TransformerLens
Issue simili
-
HTML: <template> content is extracted as document textForse già presa @ryanmeowy l’ha presa oggi. Apertabug html
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
docling-project/docling#4714 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] Qdrant RAG client applies score_threshold to raw cosine similarity, not the 0-1 score it returnsForse già presa @roydonsequeira l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Host test failure in core/direct_io.zig on Linux kernel 6.17: O_DIRECT open succeeds on procfs, so the test's 'plain' fd is not plainForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ashhart/TensorFold#536 ·
I maintainer di solito rispondono entro 1 giorno
-
area/install-update comp/cli duplicate P2 python:uv sweeper:risk-compatibility type/bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
NousResearch/hermes-agent#135440 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Deepak3699/Ai_Mentor#244 ·
I maintainer di solito rispondono entro 1 giorno