Skip to content

feat(transformers): Add HuggingFace Transformers integration - #676

Open
Abhijeet Prasad (AbhiPrasad) wants to merge 2 commits into
mainfrom
abhi-huggingface-transformers
Open

feat(transformers): Add HuggingFace Transformers integration#676
Abhijeet Prasad (AbhiPrasad) wants to merge 2 commits into
mainfrom
abhi-huggingface-transformers

Conversation

@AbhiPrasad

Copy link
Copy Markdown
Member

resolves #517

Add integration-API instrumentation for supported local Transformers pipelines, including normalized chat-style input/output, compact tensor shape output, pipeline metadata, error spans, and transformers-auto provenance.

Direct integration setup:

from braintrust.integrations.transformers import setup_transformers
from transformers import pipeline

setup_transformers()
generator = pipeline("text-generation", model="my-model")

Automatic instrumentation:

import braintrust

braintrust.auto_instrument(transformers=True)

from transformers import pipeline

generator = pipeline("text-generation", model="my-model")

Manual instrumentation:

from braintrust.integrations.transformers import wrap_transformers
from transformers import pipeline

generator = wrap_transformers(
    pipeline("text-generation", model="my-model")
)

Example trace waterfall:

time ------------------------------------------------------------->
application request [task]                    =====================
  huggingface.transformers.text_generation    =====
  huggingface.transformers.summarization            ======
  huggingface.transformers.feature_extraction              ====

Exercise real tiny CPU models across the supported Python/Transformers matrix, using CPU-only PyTorch and a shared Hugging Face model cache in CI.

Add integration-API instrumentation for supported local Transformers
pipelines, including normalized chat-style input/output, compact tensor shape
output, pipeline metadata, error spans, and transformers-auto provenance.

Direct integration setup:

```python
from braintrust.integrations.transformers import setup_transformers
from transformers import pipeline

setup_transformers()
generator = pipeline("text-generation", model="my-model")
```

Automatic instrumentation:

```python
import braintrust

braintrust.auto_instrument(transformers=True)

from transformers import pipeline

generator = pipeline("text-generation", model="my-model")
```

Manual instrumentation:

```python
from braintrust.integrations.transformers import wrap_transformers
from transformers import pipeline

generator = wrap_transformers(
    pipeline("text-generation", model="my-model")
)
```

Example trace waterfall:

```text
time ------------------------------------------------------------->
application request [task]                    =====================
  huggingface.transformers.text_generation    =====
  huggingface.transformers.summarization            ======
  huggingface.transformers.feature_extraction              ====
```

Exercise real tiny CPU models across the supported Python/Transformers
matrix, using CPU-only PyTorch and a shared Hugging Face model cache in CI.
Preserve explicit uv indexes when installing exported dependency groups so the Transformers sessions can resolve the locked CPU-only PyTorch wheel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant