Instructions to use daruokta/prism-t5gemma2-4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use daruokta/prism-t5gemma2-4b with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("daruokta/prism-t5gemma2-4b", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Prism-T5Gemma2-4B
- Overview
- Why Non-Autoregressive?
- Reranker vs. Decision Model: Overlap & Synergy
- Flexibility and True Stacking (
1 + 1 > 2) - Parameter Orthogonality & INTRA Mathematical Compression
- Context Window & Merged Attention Token Flow
- Multimodal Image Support
- Reproducible Benchmarks (
eval/) - 4-Bit NF4 Variant (
weights/nf4/) - Quickstart & Feature Recipes
- Repository Structure
- License & Upstream Attribution
- Overview
Prism-T5Gemma2-4B
One Bidirectional Multimodal Encoder-Decoder Backbone. Three Non-Autoregressive Paradigms. Compressed Reranking (Lychee/KaLM-R2) Β· System-One Calibrated Judgment (Bongard) Β· Reverse-QWK Memory Mechanics (INTRA)
Overview
Prism-T5Gemma2-4B unifies the complementary, nearly orthogonal adaptations of Lychee / KaLM-Reranker-V1-Large-R2 and Bongard-Mini onto their shared google/t5gemma-2-4b-4b base weights, paired with the algebraic memory mechanics of INTRA (Reverse-QWK) and Hydragen (Partitioned LSE Attention).
Just as a prism refracts a single beam of light into distinct wavelengths, Prism-T5Gemma2-4B encodes text or image evidence once and refracts that single cached encoder state into:
- Compressed Reranking & Multi-Hop Retrieval (Lychee / KaLM-R2 + INTRA): Score hundreds of cached text or image documents via hierarchical MEP compression (
r=16 -> r=2) and Reverse-QWK memory compression (54xβ870xsmaller than FP16 cross-KV). - Calibrated System-One Decisions (Bongard): Run typed probabilistic judgments β
choice(2β255 options),noul(True / False / Null verification),score(2β10 ordinal rubric grading), multi-question single-state batching (judge_many), and JEPA scoped representations β directly over the same cached encoder states.
*End-to-end single-pass token journey on a real multimodal example ([invoice_orion.png] + 1,024-token document): Phase 1 encodes 256 visual + 1,024 text tokens once through the 34-layer bidirectional 4-norm sandwich encoder (H_enc [1,280, 2560]); Phase 2 compresses them offline via hierarchical Lychee MEP (1,280 -> 320 -> 80 tokens) and RoPE-free INTRA INT8 k_bar (870.4x smaller); Phase 3 runs single-pass 34-layer decoder Merged Self+Cross Attention (concat(K_self, K_cross)); Phase 4 reads out both heads simultaneously β KaLM P(yes) = 0.964 (Rank #1) and Bongard choice = "2026-03-14" (94.2%) / noul = True (88.2%).*
Why Non-Autoregressive?
google/t5gemma-2-4b-4b is a pretrained base checkpoint (no official instruction-tuned release), and neither KaLM-Reranker-V1-Large-R2 nor AgentBull/bongard-mini is trained with autoregressive chat objectives.
Rather than forcing noisy free-form text generation out of discriminative weights, Prism-T5Gemma2-4B is built strictly as a Non-Autoregressive Discriminative & Retrieval Engine:
- Zero token-by-token decoding loops β every query completes in a single forward pass with calibrated probabilities.
- Drop-in companion for any external LLM β handle fast retrieval, compression, multimodal reranking, fact/null verification (
noul), rubric grading (score), and routing (choice) locally in milliseconds.
Reranker vs. Decision Model: Overlap & Synergy
Both a Reranker (KaLM/Lychee) and a Decision Model (Bongard) score inputs without generating textβP(yes | query, doc) resembles a binary noul check, while choice/score can rank a small set of candidates. Yet they operate on opposite scaling axes and solve complementary problems:
| Dimension | KaLM / Lychee Reranker (lm_head yes/no) |
Bongard System-One (JudgmentHead bilinear) |
|---|---|---|
| Scaling Axis | 1 Query Γ Many Documents (100β10,000 cached chunks) | 1 Evidence State Γ Many Questions & Options |
| Comparison Geometry | Pointwise (Independent): Doc A never sees Doc B | Listwise (Comparative): Global vector g at <decision_end> interacts multiplicatively with every candidate h_i via (W_c h_i)^T (W_g g) / β256 |
| Extreme Compression | Trained for MEP r=2..128 & Cascade r=16->2 β 100% accuracy at 16x compression |
Sharpest at r=1..8 for fine-grained reading over narrowed evidence |
| Probability Semantics | Optimized for rank ordering (nDCG/MRR) | Trained with Proper Scoring + Temperature Scaling for true/false/null abstention, risk thresholds, and expected ordinal scores |
| Best Use Cases | Search & Triage Funnel: RAG top-100->top-5, multi-hop chaining, long-memory dialogue search, multimodal image search | Judge & Router: Fact/hallucination check (noul), multi-class routing (choice), rubric grading 0β4 (score), visual OCR QA, agent actions |
Aren't They Both Just "Ranking"?
At first glance both models output numerical scores, so it is tempting to view a Decision Model as just a reranker run differently. Technically, they differ in three fundamental ways:
- Closed-Door Audition (Pointwise) vs. Courtroom Debate (Listwise): A reranker evaluates each document in isolationβwhen scoring Document A, it has no knowledge of Document B, and sorting happens externally in Python. A Bongard Decision Model places all candidates into a single decoder sequence (
[opt_1 <cand>, ..., opt_K <cand>, <decision_end>]) so the global readoutgcan cross-compare and down-rank Option A specifically because Option B is stronger or contradicts it. - Rank Order vs. Honest Probability (Calibration): If a reranker scores a relevant doc
0.91and an irrelevant doc0.85, ranking is 100% correctβyet0.85is a misleading probability for automated action. System-One models are trained with proper scoring rules so80%truly means ~80% empirical accuracy, ambiguous evidence stays honest near50/50(enabling safe abstention/null detection), and ordinal expected scores (E[score] = Ξ£ k Β· P(k)) are mathematically meaningful. - The Librarian vs. Judge Analogy: Think of KaLM/Lychee as a high-speed librarian pulling the top-3 relevant files out of 1,000 compressed shelves, and Bongard as the judge who reads those 3 files on the desk, weighs all competing options simultaneously, and delivers a calibrated verdict (
choice,noul, orscore).
Flexibility and True Stacking (1 + 1 > 2)
Combining these three papers into one model delivers both deployment flexibility and genuine cross-paper capability stacking:
- Modular Flexibility (1 Model, Pick Your Mode): Load a single
~15 GBBF16 checkpoint instead of running 2β3 separate specialist servers. Call only what each request needsβtext/image reranking, binarynoulverification, multi-classchoice, ordinalscore, batchedjudge_many, or JEPA representations. - True Cross-Paper Stacking (
1 + 1 > 2):- INTRA RQWK Γ Lychee MEP (
870.4xCompression): INTRA compresses cross-KV54.4x(FP16 KV β INT8k_bar) and Lychee MEP compresses sequence length4xβ16x; stacked together they cut cross-memory from142.61 MBto0.16 MBper 1K tokens from a singler=2cache. - KaLM MEP β Bongard Compression Resilience: Pure
bongard-miniwas never trained with MEP pooling and degrades under heavy compression (r=16); inheriting KaLM's MEP-trained encoder attention keeps Bongard accurate on compressed long documents (r=1..8) and4x-compressed visual tokens (256 -> 64tokens per image). - Bongard Multimodal β Zero-Shot KaLM Image Reranking:
KaLM-Reranker-V1-Large-R2was trained strictly on text, yet stacking Bongard's adaptedmulti_modal_projectorover the intact 417M SigLIP encoder unlocks zero-shot image reranking directly in the KaLM headβeven atr=4visual compression. - Zero Re-Encoding Funnel β Judge + De-Anisotropy: Documents selected by KaLM flow directly as cached encoder tensors into Bongard with zero online encoder calls, while encoder anisotropy drops from
0.833(base) and0.673(Bongard) down to0.459.
- INTRA RQWK Γ Lychee MEP (
Honest Trade-Off: Static weight merging without retraining slightly narrows raw logit margins compared to standalone specialists (e.g., KaLM raw margin
+0.43vs.+0.88pure; Bongard logits require the rescaledmergedtemperatures provided intemperatures.json), while preserving100%task accuracy across our evaluation suite. Choose Prism-T5Gemma2-4B when you want one unified, multimodal, memory-compressed Funnel + Judge engine; keep separate specialists only if you optimize exclusively for the final fraction of raw margin on a single task regardless of VRAM cost.
Parameter Orthogonality & INTRA Mathematical Compression
Direct audit across all 1,327 tensors of google/t5gemma-2-4b-4b confirms that ΞW_KaLM and ΞW_Bongard occupy almost perfectly orthogonal subspaces (cos = 0.0013 in encoder attention, 0.0007 in decoder attention, and 0% overlap across all 204 MLP tensors, 410 norms, o_proj, and output heads).
Because T5Gemma-2 applies RoPE only to decoder self-attention, INTRA's Reverse-QWK identity holds algebraically over our merged weights:
Combined with Lychee Hierarchical MEP and INT8 quantization, cross-memory shrinks up to 870.4x per 1K tokens while deriving coarser compression levels directly from a single r=2 cache:
Merge Recipe (Split: K1 + B_mlp0.5)
Context Window & Merged Attention Token Flow
In T5Gemma 2 / Prism-T5Gemma2-4B, encoder and decoder positional capacities are independent, while the decoder's merged softmax sums active KV columns from both sides:
- Independent RoPE Index Spaces (
0 .. N_enc - 1& Reset0 .. N_dec - 1): Both stacks declare their ownmax_position_embeddings = 131072. Because decoder cross-keys (K_cross = k_norm(W_K Β· H_mep)) apply no RoPE, even a 32Kβ131K encoder context consumes zero decoder RoPE positions β the decoder always starts fresh from position0. - Merged Self + Cross Attention Width (
concat(K_self, K_cross)): Every decoder layer attends jointly over[K_self ; K_cross]in one softmax. Crucially, thesliding_window = 1024mask on the 5/6 local SWA decoder layers clips onlyK_selfwhile keepingK_cross100% unclipped (min(N_dec, 1024) + N_enc/rcolumns on SWA layers;N_dec + N_enc/ron every 6th global layer). - Practical Context Budgets: Because encoder states are computed once offline and compressed via MEP (
r=2..16) + INTRA INT8 (k_bar), an asymmetric budget (longN_encin static memory + short single-passN_decprompts/options) lets this 8B-total NF4 model handle long contexts comfortably inside 6 GB laptop VRAM.
Multimodal Image Support
Because the 417M SigLIP vision tower from google/t5gemma-2-4b-4b remains 100% intact and AgentBull/bongard-mini adapts multi_modal_projector on multimodal data, Prism-T5Gemma2-4B natively accepts image + text inputs across both discriminative heads:
- Multimodal System-One Decisions (
encode_image_state+judge_*): Encode one or more PIL images (256 SigLIP visual tokens per image) together with text instructions and evaluatechoice,noul(visual verification / OCR checks), orscore(rubric rating) directly over the visual encoder states. - Zero-Shot Multimodal Image Reranking (
rerank_images): Score and rank collections of PIL images against natural-language queries (monolingual or cross-lingual) using the KaLM/Lychee headβwithout any image-reranking retraining. - Compressed Visual Tokens (
chunk_size=4): Apply Lychee MEP pooling directly over the 256 visual tokens per image (256 -> 64tokens) to cut online decoder compute on both image reranking and visual judgment.
Reproducible Benchmarks (eval/)
Every number below is reproducible directly from the uploaded safetensors shards using python eval/benchmark_suite.py --model-path . --variant bf16 against the bundled datasets in eval/datasets/ (full output recorded in eval/benchmark_results_bf16.json):
| Capability | Bundled Evaluation Suite | Result |
|---|---|---|
| Lychee / KaLM Reranking | rerank_eval.jsonl β Pairwise Accuracy at r=2, 4, 8, 16 |
100% at all levels (margin: +0.486 -> +0.435, 35.9β37.5 ms) |
Bongard choice |
bongard_eval.jsonl β 6 Decision Tasks (2β4 options, reversed order, rule induction, logic) |
6/6 (100%) (mean confidence 0.714) |
Bongard noul |
bongard_eval.jsonl β True / Contradicted / Missing-Null Verification |
3/3 (100%) (p_true = 0.824 supported, p_false = 0.882 contradicted, p_false = 0.745 null) |
Bongard score |
bongard_eval.jsonl β 0β4 Ordinal Rubric Grading (accurate vs. off-topic) |
2.79 / 4.0 (level 3) vs. 0.34 / 4.0 (level 0, p=0.837) |
Bongard judge_many |
benchmark_suite.py β 1 Encoder Pass -> 3 Mixed Questions (noul + choice + score) |
100% (212.8 ms total for all 3 isolated questions) |
| Bongard + Lychee MEP | bongard_eval.jsonl β Long-Document Retrieval Decision (608 tokens, 4-way cyclic rotation) |
Correct at r=1 (0.694), r=4 (0.653), r=8 (0.417) |
| Unified 2-Hop Pipeline | multihop_eval.jsonl β Offline r=2 cache (78.4x comp.) -> Hop-1 + Bridged Hop-2 -> Judge |
Hop-1 3/3 | Hop-2 3/3 | Answer 3/3 (0.88β0.94 conf, ~310 ms, 0 online encoder calls) |
| INTRA & Hydragen Math | benchmark_suite.py β Exact RQWK / k_bar cos / Hierarchical MEP / Hydragen LSE |
1.22e-4 / 0.9971 / 5.96e-8 / 3.91e-3 |
4-Bit NF4 Variant (weights/nf4/)
This repository includes a pre-quantized, calibration-free BitsAndBytes NF4 + Double Quantization variant under weights/nf4/ (llm_int8_skip_modules=["multi_modal_projector", "lm_head"], compute_dtype=bfloat16). Both weights/bf16/ and weights/nf4/ share tokenizer/ and weights/head/ with zero file duplication, and the NF4 variant runs natively on Windows and Linux CUDA GPUs with 6 GB+ VRAM (pip install bitsandbytes accelerate).
Metric (eval/benchmark_suite.py) |
BF16 (weights/bf16/) |
4-Bit NF4 (weights/nf4/) |
|---|---|---|
| Weight Size on Disk | 15.05 GB |
4.89 GB (3.08x smaller) |
| VRAM (Load / Peak) | ~15.05 GB |
4.89 GB / 5.61 GB (fits 6 GB GPUs) |
| Reload Speed (from disk) | β | 2.29 s |
Lychee / KaLM Rerank (r=2, 4, 8, 16) |
100% (r=4 mrg +0.430) |
100% (r=4 mrg +0.404) |
Bongard noul (True / False / Null) |
3/3 (100%) |
3/3 (100%) |
Bongard score (0β4 Rubric) |
2.79 vs 0.34 |
2.68 vs 0.37 |
Bongard judge_many (1 pass -> 3 Qs) |
100% (212.8 ms) |
100% (330.3 ms) |
Bongard choice (6 tasks) |
6/6 (100%) |
5/6 (rule_3opt borderline) |
Bongard Long-Doc MEP (r=1, 4, 8) |
OK (r=1, 4, 8) |
OK (r=1, 4, 8) |
| Unified 2-Hop Pipeline | Hop-1 3/3 | Hop-2 3/3 | Ans 3/3 |
Hop-1 3/3 | Hop-2 3/3 | Ans 3/3 (0.91+ conf) |
Full NF4 results are recorded in eval/benchmark_results_nf4.json.
Quickstart & Feature Recipes
from prism_t5gemma2 import PrismT5Gemma2
# Option A: Full BF16 weights (~15 GB VRAM)
prism = PrismT5Gemma2.from_pretrained("<path-or-repo-id>", variant="bf16")
# Option B: Pre-quantized 4-Bit NF4 variant (~4.9 GB VRAM β fits 6 GB Windows/Linux GPUs)
# Requires: pip install bitsandbytes accelerate
prism = PrismT5Gemma2.from_pretrained("<path-or-repo-id>", variant="nf4")
1. Compressed Reranking & Test-Time Cascade (r=16 -> r=2)
docs = [
"Lychee-Reranker applies Multi-granularity Encoder Pooling (MEP) to compress encoder tokens.",
"Bongard trains a 1.31M bilinear head over T5Gemma-2 hidden states.",
"ColBERT stores per-token embeddings for late-interaction MaxSim.",
]
cache = prism.encode_corpus_cache(docs, base_chunk_size=2, quantize_kbar_int8=True)
print(cache.memory_report())
ranked = prism.rerank_cascade(
"How does Lychee-Reranker compress tokens?",
cache,
coarse_chunk_size=16,
fine_chunk_size=2,
top_k=2,
)
2. Bongard Typed Primitives (noul, score, choice, judge_many)
# True / False / Missing-Null Guardrail
noul = prism.judge_noul(
state_text="Meeting notes: Discussed Q3 server migration schedule and backup policies.",
instructions="Does the text specify the exact budget in USD for the migration?",
)
# 0..4 Ordinal Rubric Grading
score = prism.judge_score(
state_text="Caching encoder outputs offline lets queries reuse pooled states without re-encoding.",
instructions="Rate the technical clarity and accuracy of this explanation.",
rubric=["Off-topic", "Mostly wrong", "Vague", "Accurate and clear", "Exceptional"],
)
# 1 Encoder Pass -> Multiple Isolated Questions
many = prism.judge_many(
state_text="Order #501: Express shipping to Tokyo. Payment verified ($180).",
questions={
"paid": {"type": "noul", "instructions": "Has payment been verified?"},
"dest": {"type": "choice", "instructions": "Destination city?", "options": ["Osaka", "Tokyo", "Seoul"]},
"clarity": {"type": "score", "instructions": "Completeness?", "rubric": ["Poor", "Fair", "Good", "Great"]},
},
)
3. Multimodal Image Judgment & Zero-Shot Image Reranking
from PIL import Image
img = Image.open("invoice.png").convert("RGB")
enc_hs, enc_mask = prism.encode_image_state(
[img],
state_text="Inspect the attached document image.",
question_instructions=["Has this invoice been paid?"],
chunk_size=4, # 4x MEP compression on 256 visual tokens!
)
paid = prism.judge_noul(None, "Has this invoice been paid?", encoder_hidden_states=enc_hs, encoder_attention_mask=enc_mask)
# Zero-shot image reranking across multiple PIL images
scores = prism.rerank_images("Find the document image showing a settled payment receipt.", [img1, img2, img3], chunk_size=4)
4. End-to-End 2-Hop Unified Pipeline & Benchmark Suite
result = prism.unified_pipeline(
query="What river flows through the birthplace of the Analytical Engine designer?",
cache=cache,
documents=corpus,
options=["River Thames", "Nile River", "Amazon River", "Danube River"],
)
# Benchmark BF16 weights
python eval/benchmark_suite.py --model-path . --variant bf16
# Benchmark 4-Bit NF4 weights (6 GB+ GPU)
python eval/benchmark_suite.py --model-path . --variant nf4
Repository Structure
.
βββ README.md # Model card & documentation
βββ prism_t5gemma2.py # Unified Python runtime (BF16 + NF4, Text + Images)
βββ prism_merge_config.json # Reproducible merge recipe & orthogonality audit
βββ weights/
β βββ bf16/ # Full-precision BF16 backbone (15.05 GB)
β β βββ config.json
β β βββ model.safetensors.index.json
β β βββ model-00001..00004.safetensors
β βββ nf4/ # Pre-quantized 4-Bit BitsAndBytes NF4 backbone (4.89 GB)
β β βββ config.json
β β βββ model.safetensors.index.json
β β βββ model-00001..00002.safetensors
β βββ head/ # Shared Bongard 1.31M bilinear head & calibration
β βββ head.safetensors
β βββ temperatures.json
βββ tokenizer/ # Shared tokenizer & multimodal SigLIP processor
β βββ tokenizer.json
β βββ tokenizer_config.json
β βββ processor_config.json
βββ assets/ # Animated token-flow GIFs & benchmark chart
β βββ prism_architecture_animated.gif
β βββ token_window_flow_animated.gif
β βββ funnel_vs_judge_animated.gif
β βββ compression_and_orthogonality.png
βββ eval/ # Standalone evaluation suite, datasets & results
βββ benchmark_suite.py
βββ benchmark_results_bf16.json
βββ benchmark_results_nf4.json
βββ datasets/
βββ rerank_eval.jsonl
βββ bongard_eval.jsonl
βββ multihop_eval.jsonl
License & Upstream Attribution
Distributed under the Gemma Terms of Use (gemma), inherited from google/t5gemma-2-4b-4b and AgentBull/bongard-mini. KaLM-Embedding/KaLM-Reranker-V1-Large-R2 is licensed under Apache-2.0.
- T5Gemma 2: Zhang et al., T5Gemma 2: Seeing, Reading, and Understanding Longer,
arXiv:2512.14856(google/t5gemma-2-4b-4b). - Lychee / KaLM-Reranker-V1: HITsz-TMG, Lychee-Reranker: Fast but Not Late Interaction for Compressed Document Reranking,
arXiv:2606.22807(KaLM-Embedding/KaLM-Reranker-V1-Large-R2). - Bongard: AgentBull Pte Ltd, Bongard: Training Machine Intuition,
arXiv:2609.39111(AgentBull/bongard-mini). - INTRA: Hoffer et al. (NVIDIA & Technion), Retrieval from Within: An Intrinsic Capability of Attention-Based Models,
arXiv:2605.05806.



