zandervdm commited on
Commit
77f9eec
·
verified ·
1 Parent(s): bbca86b

Bundle the qevi inference engine in-repo

Browse files
Files changed (1) hide show
  1. qevi/__init__.py +58 -0
qevi/__init__.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Qevi: answer typed questions about an image in one forward pass, without generating text.
2
+
3
+ A normal vision-language model answers a question by decoding tokens one at a time, and
4
+ re-encodes the image for every question you ask. When the answer is known to be one of a small
5
+ fixed set ("Yes"/"No", "A"/"B"/"C"/"D", "Poor"/"Fair"/"Good"), both of those costs are waste.
6
+
7
+ Qevi instead encodes the image once, packs every question into a single sequence behind a
8
+ block-diagonal attention mask that keeps the questions provably isolated from each other, runs
9
+ one forward pass, and reads the model's own LM-head logits at the position where it would have
10
+ started writing each answer. Softmax over just that question's candidate tokens gives a
11
+ calibrated probability.
12
+
13
+ from transformers import AutoProcessor, Qwen3VLForConditionalGeneration
14
+ from qevi import build_readouts, noul_question, forward_logits, softmax
15
+
16
+ model = Qwen3VLForConditionalGeneration.from_pretrained(MODEL, dtype="bfloat16").cuda()
17
+ processor = AutoProcessor.from_pretrained(MODEL)
18
+
19
+ specs = [(noul_question("There is a ladder in this image."), ["Yes", "No"])]
20
+ readouts = build_readouts(processor.tokenizer, specs)
21
+ logits = forward_logits(model, processor, image, readouts)
22
+ print(softmax(logits[0], T=2.45)) # -> [0.97, 0.03]
23
+
24
+ Everything here works with a stock Qwen3-VL checkpoint. The fine-tuned weights are simply more
25
+ accurate through the same path; no custom architecture and no trust_remote_code is involved.
26
+ """
27
+
28
+ from .core import (
29
+ Readout,
30
+ build_readouts,
31
+ forward_logits,
32
+ softmax,
33
+ unwrap,
34
+ wrap_turn,
35
+ noul_question,
36
+ choice_question,
37
+ choice_question_generic,
38
+ score_question,
39
+ score_question_generic,
40
+ NOUL_TEMPLATE,
41
+ LETTERS,
42
+ PREFIX_PRE,
43
+ PREFIX_POST,
44
+ )
45
+ from .pack import Question, PackedBatch, Segment, build_packed_batch, permute_questions
46
+
47
+ __version__ = "0.1.0"
48
+
49
+ DEFAULT_TEMPERATURES = {"noul": 2.45, "choice": 1.9, "score": 3.0}
50
+
51
+ __all__ = [
52
+ "Readout", "build_readouts", "forward_logits", "softmax", "unwrap", "wrap_turn",
53
+ "noul_question", "choice_question", "choice_question_generic",
54
+ "score_question", "score_question_generic",
55
+ "NOUL_TEMPLATE", "LETTERS", "PREFIX_PRE", "PREFIX_POST",
56
+ "Question", "PackedBatch", "Segment", "build_packed_batch", "permute_questions",
57
+ "DEFAULT_TEMPERATURES", "__version__",
58
+ ]