[Bug Report] Inspect RemoteBridge silently ignores attention_mask

Chiusa
#1,851 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@emerardd ci sta già lavorando.

Dal 5/10/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug complexity-moderate TransformerBridge

Describe the bug

The Inspect backend silently drops an attention_mask passed to RemoteBridge.forward() or run_with_cache(). InspectDriver.forward() accepts the argument in **kwargs, but its profile request contains only input IDs, capture keys, interventions and the logits flag. The HF provider consequently runs an unmasked forward. Returned logits and cached activations can therefore reflect padding as real context, even though RemoteBridge later applies the supplied mask when aggregating loss.

Code example

import torch
from transformer_lens.model_bridge.remote_bridge import RemoteBridge

bridge = RemoteBridge.boot_inspect("gpt2", provider="tl_bridge", device="cpu")
tokens = torch.tensor([[0, 0, 7, 8]])
mask = torch.tensor([[0, 0, 1, 1]])
logits, cache = bridge.run_with_cache(tokens, attention_mask=mask)

On dev at 6affbe99, an offline driver probe for this input sent input_ids=[0, 0, 7, 8] with no attention_mask in the provider request. A separate random tiny eager GPT-2 control compared the provider-equivalent unmasked forward with a masked forward using mask-derived positions: the final-logit maximum difference was about 0.159, while the masked result matched the unpadded [7, 8] control within 3e-8. These checks establish the request omission and its numerical consequence; a live downloaded-model Inspect run was not used for this report.

System Info

TransformerLens installed from source with uv; Windows, Python 3.12.10, Torch 2.11.0+cpu, Transformers 5.13.0. Reproduced on current dev at 6affbe99.

Additional context

The omission spans sources/inspect/driver.py, profiles.py, and transformers_provider.py. This is separate from the local Bridge position-id fix (#1610) and the direct vLLM driver padding fix (#1804).

I plan to propagate and validate a single-sequence 2-D mask through the HF-backed Inspect path, handle padding positions consistently, and add regressions covering logits, captures and masked loss. Providers that cannot honor masks should reject them explicitly before execution; tl_bridge_vllm and third-party provider capabilities need their own handling.

Checklist
  • I have checked that there is no similar issue in the repo
Lingua principale
Python
Stelle
3.9k
Fork
708
Merge medio
1g 10h
PR unite (30g)
82

Preparare l'ambiente

Apri in Codespaces

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TransformerLensOrg/TransformerLens

Tutte le issue di TransformerLensOrg/TransformerLens

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.