@@ -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
238251end
0 commit comments