Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions tests/unit/model_bridge/compatibility/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,11 @@ def test_device_compatibility(self, model):

def test_generation_compatibility(self, model):
"""Test that generation works correctly with TransformerBridge."""
if not model.adapter.supports_generation:
pytest.skip("Generation not supported for this architecture")
prompt = "Once upon a time"

# Test basic generation if supported
try:
generated = model.generate(prompt, max_new_tokens=5)
assert isinstance(generated, (str, list, torch.Tensor))
except (AttributeError, RuntimeError):
# Generation might not be implemented yet for all bridge models
pytest.skip("Generation not supported for this TransformerBridge model")
generated = model.generate(prompt, max_new_tokens=5)
assert isinstance(generated, (str, list, torch.Tensor))

@pytest.mark.parametrize("method", ["to_tokens", "to_string", "to_str_tokens"])
def test_tokenization_methods(self, model, method):
Expand Down
4 changes: 4 additions & 0 deletions transformer_lens/model_bridge/architecture_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ArchitectureAdapter:
# documented in ~/.claude/plans/ssm-verification-compatibility.md.
applicable_phases: list[int] = [1, 2, 3, 4]

# Whether this architecture supports text generation via generate().
# Encoder-only models (e.g. BERT, HuBERT) should set this to False.
supports_generation: bool = True

def __init__(self, cfg: TransformerBridgeConfig) -> None:
"""Initialize the architecture adapter.

Expand Down
2 changes: 2 additions & 0 deletions transformer_lens/model_bridge/supported_architectures/bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
class BertArchitectureAdapter(ArchitectureAdapter):
"""Architecture adapter for BERT models."""

supports_generation: bool = False

def __init__(self, cfg: Any) -> None:
"""Initialize the BERT architecture adapter.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class HubertArchitectureAdapter(ArchitectureAdapter):
prepare_model() detects this and adjusts component paths.
"""

supports_generation: bool = False

def __init__(self, cfg: Any) -> None:
super().__init__(cfg)

Expand Down
Loading