[Proposal] RoBERTa masked-LM adapter for TransformerBridge
Los mantenedores suelen responder en 1 día
@Canonik ya está trabajando en esto.
Desde el 8/10/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
[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)
- Lenguaje dominante
- Python
- Estrellas
- 3.9k
- Forks
- 708
- Merge medio
- 1 d 17 h
- PR fusionados (30 d)
- 70
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TransformerLensOrg/TransformerLens
-
[Proposal] Backward Lens: support gated MLP gate/ up/ down gradient factorsPosiblemente ocupada @janmenjayap la tomó hace 8 días. Abiertocomplexity-moderate enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1832 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Proposal] Sparse probing: optional groups argument so rows from one prompt can't straddle the splitPosiblemente ocupada @lorenzozanee la tomó hace 13 días. Abiertocomplexity-simple enhancement help wanted TransformerBridge
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
TransformerLensOrg/TransformerLens#1813 ·
Los mantenedores suelen responder en 1 día
-
[Bug Report] _BLOCK_LIST_ATTRS hardcoded name list silently drops Raven's blocks from composition-score / head-label analysisPosiblemente ocupada @LightWork666 la tomó hace 17 días. Abiertobug complexity-moderate TransformerBridge
TransformerLensOrg/TransformerLens#1791 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Proposal] SVD Circuits: singular-vector decomposition of a head's QK/ OV into causally-validated subfunctionsPosiblemente ocupada @janmenjayap la tomó hace 29 días. Abiertocomplexity-high enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1767 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Proposal] Relevance Lens (R-lens): a RelP/ LRP-based transport-matrix estimator for Jacobian Lens (J-lens) fit, readout, and interventionPosiblemente ocupada @janmenjayap la tomó hace 31 días. Abiertocomplexity-high enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1755 · 6 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de TransformerLensOrg/TransformerLens
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
MystenLabs/MemWal#1163 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
infertopics leaves new nodes without a topic when untopiced neighbours outnumber topiced onesPosiblemente ocupada @moneebullah25 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
FinanceFlash/unvibecode#218 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
NVIDIA/earth2studio#1241 ·
Los mantenedores suelen responder en 3 días