Skip to content

Commit 5b23df1

Browse files
authored
Merge pull request #33 from ausimian/fix-distilbert-qa-vocab-mismatch
conformance: use real DistilBERT-QA checkpoint for batched_run test
2 parents 1e9b702 + 15e20d6 commit 5b23df1

2 files changed

Lines changed: 36 additions & 21 deletions

File tree

test/emily/conformance/distilbert_test.exs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ defmodule Emily.Conformance.DistilbertTest do
2020
(`~/.cache/bumblebee`). Invoke explicitly:
2121
2222
mix test --only conformance
23+
24+
The single `Nx.Serving.batched_run` test is additionally tagged
25+
`:distilbert_full` because it needs a real QA checkpoint
26+
(`distilbert-base-uncased-distilled-squad`, ~250 MB) — the tiny-
27+
random model's 1124-row embedding can't be driven by the full
28+
tokenizer without relying on backend-specific OOB-gather behaviour.
29+
Run explicitly:
30+
31+
mix test --only distilbert_full
2332
"""
2433

2534
use ExUnit.Case, async: false
@@ -200,18 +209,20 @@ defmodule Emily.Conformance.DistilbertTest do
200209
end
201210

202211
describe "Nx.Serving.batched_run" do
203-
# Exercises Bumblebee's question-answering serving end-to-end:
204-
# tokenizer, forward pass, postprocess, and Nx.Serving's batching
205-
# pipeline. The tiny-random model produces meaningless answers, so
206-
# we assert structure rather than content — the point is that the
207-
# batched path runs cleanly against Emily.Backend.
212+
# Exercises Bumblebee's question-answering serving end-to-end on a
213+
# real SQuAD-fine-tuned DistilBERT checkpoint: tokenizer, forward
214+
# pass, postprocess, and Nx.Serving's batching pipeline. A real
215+
# model is required here — pairing the full uncased tokenizer
216+
# (vocab 30522) with a tiny-random model (1124-row embedding)
217+
# feeds out-of-range token ids into gather and relies on backend
218+
# OOB behaviour, which is how we originally hit a :nan score.
219+
@tag :distilbert_full
208220
test "batched_run drives DistilBERT-QA through Nx.Serving" do
209221
{:ok, model_info} =
210-
Bumblebee.load_model(
211-
{:hf, "hf-internal-testing/tiny-random-DistilBertForQuestionAnswering"}
212-
)
222+
Bumblebee.load_model({:hf, "distilbert-base-uncased-distilled-squad"})
213223

214-
{:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, "distilbert-base-uncased"})
224+
{:ok, tokenizer} =
225+
Bumblebee.load_tokenizer({:hf, "distilbert-base-uncased-distilled-squad"})
215226

216227
serving = Bumblebee.Text.question_answering(model_info, tokenizer)
217228

@@ -224,15 +235,17 @@ defmodule Emily.Conformance.DistilbertTest do
224235

225236
results = Nx.Serving.batched_run(__MODULE__.Serving, inputs)
226237

227-
assert length(results) == 2
228-
229-
for result <- results do
230-
assert %{results: [%{text: text, score: score, start: s, end: e}]} = result
231-
assert is_binary(text)
232-
assert is_float(score)
233-
assert is_integer(s)
234-
assert is_integer(e)
235-
end
238+
assert [
239+
%{results: [%{text: t1, score: sc1, start: s1, end: e1}]},
240+
%{results: [%{text: t2, score: sc2, start: s2, end: e2}]}
241+
] = results
242+
243+
assert t1 =~ ~r/sarah/i
244+
assert t2 =~ ~r/london/i
245+
assert is_float(sc1) and sc1 > 0.0
246+
assert is_float(sc2) and sc2 > 0.0
247+
assert is_integer(s1) and is_integer(e1) and s1 < e1
248+
assert is_integer(s2) and is_integer(e2) and s2 < e2
236249
end
237250
end
238251
end

test/test_helper.exs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
# conformance variants that download full-size weight checkpoints, so
1010
# they are excluded even from `--only conformance`; run explicitly:
1111
#
12-
# mix test --only qwen3_full # ~1.5 GB checkpoint
13-
# mix test --only vit_full # ~330 MB checkpoint
14-
# mix test --only whisper_full # ~150 MB checkpoint
12+
# mix test --only qwen3_full # ~1.5 GB checkpoint
13+
# mix test --only vit_full # ~330 MB checkpoint
14+
# mix test --only whisper_full # ~150 MB checkpoint
15+
# mix test --only distilbert_full # ~250 MB checkpoint
1516
#
1617
# (Soak tests deliberately stay in the default suite; see
1718
# `test/soak/memory_test.exs` for the rationale.)
@@ -51,6 +52,7 @@ ExUnit.start(
5152
:qwen3_quant_full,
5253
:vit_full,
5354
:whisper_full,
55+
:distilbert_full,
5456
:training_full,
5557
:fast_kernels_full
5658
]

0 commit comments

Comments
 (0)