Hugging Face Transformers

All integration guides. Use an offline, randomly initialized tiny model over remote text and write a scalar feature through ADBC. This demonstrates plumbing, not useful pretrained predictions.

Install

Start with the server and sample table. Run from the repository root, using Python 3.12 in a separate environment:

python3.12 -m venv .venv-transformers
. .venv-transformers/bin/activate
python -m pip install -r requirements/integrations/models.txt

The profile pins the versions used in the November 3 run. It may install other tools in the same profile. Use a client-reachable FLIGHT_URI if the endpoint is elsewhere; the default below is a local unauthenticated development server.

Read, write and verify

Save the following as transformers_example.py and run it with python transformers_example.py in the active environment. The code reads flight_tool_sample, writes the tool's output to a unique SQL table, verifies it with a fresh ordered SELECT and drops only that output table. Keep the shared input table until you finish the guides.

import os
import uuid
import pyarrow as pa
import adbc_driver_flightsql.dbapi as sql

uri = os.environ.get("FLIGHT_URI", "grpc://localhost:8815")
with sql.connect(uri, autocommit=True) as conn, conn.cursor() as cur:
    cur.execute("SELECT id, label, amount FROM flight_tool_sample ORDER BY id")
    source = cur.fetch_arrow_table()

os.environ["HF_HUB_OFFLINE"] = "1"
os.environ["TRANSFORMERS_OFFLINE"] = "1"
import torch
from tokenizers import Tokenizer
from tokenizers.models import WordLevel
from tokenizers.pre_tokenizers import Whitespace
from transformers import BertConfig, BertModel, PreTrainedTokenizerFast
local = Tokenizer(WordLevel({"[UNK]": 0, "[PAD]": 1, "one": 2, "three": 3}, unk_token="[UNK]"))
local.pre_tokenizer = Whitespace()
tokenizer = PreTrainedTokenizerFast(tokenizer_object=local, unk_token="[UNK]", pad_token="[PAD]")
batch = tokenizer([value or "" for value in source["label"].to_pylist()],
                  padding=True, return_tensors="pt")
model = BertModel(BertConfig(vocab_size=4, hidden_size=16, num_hidden_layers=1,
                             num_attention_heads=2, intermediate_size=32)).eval()
with torch.no_grad():
    vectors = model(**batch).last_hidden_state[:, 0, :]
# SQL example stores a scalar; named Flight datasets can preserve vector columns.
output = pa.table({"id": source["id"], "feature": vectors[:, 0].tolist()})

# Write the tool's output through Flight SQL, then verify the stored values.
name = "guide_" + uuid.uuid4().hex
with sql.connect(uri, autocommit=True) as conn, conn.cursor() as cur:
    try:
        cur.adbc_ingest(name, output, mode="create")
        cur.execute(f'SELECT * FROM "{name}" ORDER BY id')
        received = cur.fetch_arrow_table()
        assert received.equals(output)
        print(received)
    finally:
        cur.execute(f'DROP TABLE IF EXISTS "{name}"')
        cur.fetch_arrow_table()

Validation and limits

The live guide recipe run passed this example's remote read, output write, fresh ordered read-back and cleanup. The report records runtime versions and the precise scope. Writes use Arrow ingestion through Flight SQL; native writer API support is not implied.

Use a separate interpreter for each model example. The recorded combined XGBoost/PyTorch runtime aborted; the runner isolates native ML runtimes.

SQL uses autocommit. Client results are materialized in memory; these examples do not establish distributed execution, Enterprise qualification or TLS/auth. Remove the shared input with the fixture cleanup.