[Bug Report] Inspect RemoteBridge silently ignores attention_mask

Cerrado
#1,851 1 comentario 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@emerardd ya está trabajando en esto.

Desde el 5/10/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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
Lenguaje dominante
Python
Estrellas
3.9k
Forks
708
Merge medio
1 d 10 h
PR fusionados (30 d)
82

Preparar el entorno

Abrir en Codespaces

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TransformerLensOrg/TransformerLens

Todos los issues de TransformerLensOrg/TransformerLens

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.