fix: update ARCHITECTURE.md — SAM 3.1 → jetjodh/sam3.1, align with current component stack (DINOv3-L, Qwen3-Embedding)
Browse files15 unmodified lines161718192021222324252627282930313233345 unmodified lines40414243444546474849505152535455565758596061626364656667686913 unmodified lines83848586878889909192939456 unmodified lines1511521531541551561571581591601611621631641651661671681691701711721731741751761776 unmodified lines1841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242253 unmodified lines22923023123223323423523623712 unmodified lines2502512522532542552566 unmodified lines26326426526626726826927027127227327427527627717 unmodified lines29529629729829930030130230315 unmodified lines└──────────────────────────────────────────┘┌─────────┐ ┌─────────────┐ ┌──────────────┐│ DINOv2/v3│────▶│ Evidence │────▶│ Latent │──▶ Answer│ Visual │ │ Memory │ │ Rollout │ Heads│ Backbone │ │ (Perceiver)│ │ K=3 steps │└─────────┘ └──────┬──────┘ └──────┬───────┘│ │┌─────────┐ │ ┌──────┴───────┐│ DeBERTa │────────────┘ │ Target ││ Text │ │ Encoder ││ Encoder │ │ (EMA) │└─────────┘ └──────────────┘│┌─────────┐ JEPA Loss:│Optional:│ L₂ prediction│OCR,SAM, │──────────┘ + SIGReg│Layout │└─────────┘5 unmodified lines### 2.1 Visual Backbone**Primary choice: DINOv2-L/14** (`facebook/dinov2-large`)- Architecture: ViT-L/14 with 300M parameters- Output: 1024-dim patch tokens, 518×518 input → 1369 patches- 4 register tokens + CLS token (skipped, only patch tokens used)- Pre-trained with self-supervised DINO objective on LVD-142M- **Why DINOv2 over CLIP/SigLIP**: Dense patch features are critical for evidence extraction. CLIP-style models optimize for global image-text alignment but lose local spatial information. DINOv2 produces patch-level features that capture fine-grained visual details needed for chart reading, document OCR, and diagram understanding.**Alternative: DINOv3-L/16** (`timm/vit_large_patch16_dinov3.lvd1689m`)- Architecture: ViT-L/16 with RoPE positional encoding- Advantages: Better resolution generalization, Gram anchoring prevents feature degradation- Trained on LVD-1689M (10× more data)**Purist branch: DINOv2-B/14** (`facebook/dinov2-base`)- 768-dim output, 86M params- Compensated by deeper rollout (K=5)### 2.2 Text Encoder**DeBERTa-v3-Large** (`microsoft/deberta-v3-large`)- 1024-dim hidden, 24 layers, 304M params- Processes: question text + answer options (concatenated with separators)- Output: token-level embeddings for cross-attention + CLS for option scoring**Why DeBERTa over BERT/RoBERTa**: DeBERTa-v3's disentangled attention mechanism explicitly models content vs. position, giving stronger performance on complex NLU tasks. Its relative position bias is particularly useful for understanding mathematical notation and structured question formats.### 2.3 Evidence Memory13 unmodified lines**Input tokens (concatenated KV sequence):**| Source | Tokens | Dimension | Phase ||--------|--------|-----------|-------|| DINOv2-L patches | 1369 | 1024→768 (projected) | 1+ || DeBERTa text | 256 | 1024→768 (projected) | 1+ || OCR tokens | 128 | 768 | 3 || Layout tokens | 64 | 256→768 (projected) | 3 || Chart tokens | 64 | 512→768 (projected) | 3 || SAM2 segments | 32 | 256→768 (projected) | 3 (optional) |**Modality type embeddings** (learned, added to distinguish token sources).56 unmodified lines### 2.6 JEPA Objective**Prediction loss** (from I-JEPA):```L_JEPA = (1/K) Σ_{k=1}^{K} ||z_pred_k - sg(z*_k)||²```Only steps k=1..K are supervised (z₀ is deterministic from evidence).**Anti-collapse regularization** (from LeWorldModel):```L_SIGReg = (1/M) Σ_{m=1}^{M} T(Z · u_m)```Where T is the Epps-Pulley normality test statistic, u_m are random unit vectors.This encourages latent embeddings to remain Gaussian-distributed, preventing collapse.**Total loss**:```L_total = L_JEPA + L_task + λ · L_SIGReg + α · L_genWhere:L_task = CrossEntropy(disc_head(z_K), answer_label) # MC scoringL_gen = CE(gen_head(z_K), target_answer_tokens) # Short answerλ = 0.1 (SIGReg weight)α = 0.1 (generative weight)```6 unmodified linesprobs = softmax(scores, mask=valid_options)```**Generative Head (Secondary)** — for open-ended questions:```Small transformer decoder (4 layers):- Causal self-attention- Cross-attention to z_K (latent state)- Cross-attention to evidence memory (evidence-constrained)- FFNMax 64 tokens output. Weight-tied embedding + LM head.```---## 3. Training Protocol### Phase 1: Reasoning Core (20 epochs)| Component | Status | LR ||-----------|--------|-----|| DINOv2-L | **Frozen** | — || DeBERTa | **Frozen** | — || Evidence Memory | Training | 3e-4 || Latent Rollout | Training | 3e-4 || Answer Heads | Training | 3e-4 || Target Encoder | EMA update | — |**Data**: ScienceQA train (12.7K) + any available train splits**Objective**: Full JEPA + task + SIGReg**Batch size**: 32 × 4 accum = 128 effective### Phase 2: Perception Fine-tuning (10 epochs)| Component | Status | LR ||-----------|--------|-----|| DINOv2-L (last 6 layers) | **Training** | 1e-5 || DeBERTa (last 4 layers) | **Training** | 1e-5 || Evidence Memory | Training | 1e-4 || Latent Rollout | Training | 1e-4 || Answer Heads | Training | 1e-4 |3 unmodified lines| Component | Status | LR ||-----------|--------|-----|| All above | Training | 5e-5 || OCR tokens | **Enabled** | 5e-5 || Layout tokens | **Enabled** | 5e-5 || Chart tokens | **Enabled** | 5e-5 |**Focus benchmarks**: DocVQA, TextVQA, ChartQA12 unmodified lines| **K=1** | Shallow rollout | Worse than K=3 || **K=5** | Deeper rollout | Diminishing returns || **No SIGReg** | Remove anti-collapse | Training instability || **Purist branch** | DINOv2-B, no enriched evidence | Lower absolute scores, but validates JEPA contribution |### Cross-benchmark analysis:- JEPA contribution should be highest on **reasoning** benchmarks (MathVista, MMMU, ScienceQA)6 unmodified lines| Component | Parameters | Trainable (Phase 1) ||-----------|-----------|---------------------|| DINOv2-L | 300M | 0 || DeBERTa-v3-L | 304M | 0 || Evidence Memory | ~3M | 3M || Latent Rollout | ~3M | 3M || Disc Head | ~2M | 2M || Gen Head | ~25M | 25M || **Total** | **~637M** | **~33M** |Phase 1 trains only ~5% of total parameters. The model is computationally efficient — the JEPA reasoning core is lightweight compared to the frozen perception backbones.---17 unmodified lines1. **I-JEPA** (Assran et al., 2023) — arxiv:2301.08243: JEPA architecture, EMA target encoder, L2 prediction loss, narrow predictor2. **V-JEPA** (Bardes et al., 2024) — arxiv:2412.10925: Temporal extension, multi-step prediction in latent space3. **LeWorldModel** (Maes et al., 2025) — arxiv:2603.19312: SIGReg anti-collapse, end-to-end JEPA from pixels, 2474 GitHub stars4. **Coconut** (Yu et al., 2024) — arxiv:2412.06769: Chain of Continuous Thought, latent reasoning paradigm5. **SoftCoT++** (Xu et al., 2025) — arxiv:2505.11484: Soft chain-of-thought with perturbation and contrastive learning6. **DINOv2** (Oquab et al., 2023) — arxiv:2304.07193: Dense SSL visual backbone7. **DINOv3** (Meta, 2025) — arxiv:2508.10104: Improved SSL with RoPE, Gram anchoring8. **SigLIP2** (Google, 2025) — arxiv:2502.14786: CLIP-style with DINO features + captioning15 unmodified lines161718192021222324252627282930313233345 unmodified lines40414243444546474849505152535455565758596061626364656667686913 unmodified lines83848586878889909192939456 unmodified lines1511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801816 unmodified lines1881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252263 unmodified lines23023123223323423523623723823912 unmodified lines2522532542552562572586 unmodified lines26526626726826927027127227327427527627727817 unmodified lines29629729829930030130230315 unmodified lines└──────────────────────────────────────────┘┌─────────┐ ┌─────────────┐ ┌──────────────┐│ DINOv3 │────▶│ Evidence │────▶│ Latent │──▶ Answer│ Visual │ │ Memory │ │ Rollout │ Heads│ Backbone │ │ (Perceiver)│ │ K=3 steps │└─────────┘ └──────┬──────┘ └──────┬───────┘│ │┌─────────┐ │ ┌──────┴───────┐│ Qwen3 │────────────┘ │ Target ││ Embed │ │ Encoder ││ 0.6B │ │ (EMA) │└─────────┘ └──────────────┘│┌─────────┐ JEPA Loss:│Optional:│ SmoothL1/Cosine│OCR,SAM, │──────────┘ + SIGReg│Layout │└─────────┘5 unmodified lines### 2.1 Visual Backbone**Primary choice: DINOv3-L/16** (`timm/vit_large_patch16_dinov3.lvd1689m`)- Architecture: ViT-L/16 with RoPE positional encoding, 300M parameters- Output: 1024-dim patch tokens, 256×256 input → 256 patches- CLS + 4 register tokens (skipped, only patch tokens used)- Pre-trained with self-supervised DINO objective on LVD-1689M (10× DINOv2 data)- Gram anchoring prevents feature degradation- **Why DINOv3 over CLIP/SigLIP**: Dense patch features are critical for evidence extraction. CLIP-style models optimize for global image-text alignment but lose local spatial information. DINOv3 produces patch-level features that capture fine-grained visual details needed for chart reading, document OCR, and diagram understanding.**Ablation baseline: DINOv2-L/14** (`facebook/dinov2-large`)- Architecture: ViT-L/14, 1024-dim, 518×518 input → 1369 patches- 4 register tokens + CLS token (skipped)**Purist branch: DINOv3-B/16** (`timm/vit_base_patch16_dinov3.lvd1689m`)- 768-dim output, smaller model- Compensated by deeper rollout (K=5)### 2.2 Text Encoder**Qwen3-Embedding-0.6B** (`Qwen/Qwen3-Embedding-0.6B`)- 1024-dim hidden, 596M params, causal LM architecture used as encoder- Processes: question text + answer options (concatenated with separators)- Output: token-level embeddings for cross-attention + mean pooling for option scoring**Why Qwen3-Embedding**: Best quality/cost ratio for text embeddings. 1024-dim output matches DINOv3-L exactly. Stronger NLU capabilities than DeBERTa-v3-Large while being a purpose-built embedding model.### 2.3 Evidence Memory13 unmodified lines**Input tokens (concatenated KV sequence):**| Source | Tokens | Dimension | Phase ||--------|--------|-----------|-------|| DINOv3-L patches | 256 | 1024→768 (projected) | 1+ || Qwen3-Embedding text | 192 | 1024→768 (projected) | 1+ || OCR tokens | 128 | 768 | 3 || Layout tokens | 64 | 256→768 (projected) | 3 || Chart tokens | 64 | 512→768 (projected) | 3 || SAM 3.1 segments | 32 | 256→768 (projected) | 3 (optional) |**Modality type embeddings** (learned, added to distinguish token sources).56 unmodified lines### 2.6 JEPA Objective**Prediction loss** (hybrid branch — SmoothL1 from I-JEPA, more robust than L2):```L_JEPA = (1/K) Σ_{k=1}^{K} SmoothL1(z_pred_k, sg(z*_k))```Only steps k=1..K are supervised (z₀ is deterministic from evidence).**Alternative (purist branch)**: Cosine similarity loss.**Anti-collapse regularization** (from LeWorldModel — SIGReg):```L_SIGReg = (1/M) Σ_{m=1}^{M} T(Z · u_m)```Where T is the Epps-Pulley normality test statistic, u_m are random unit vectors.This encourages latent embeddings to remain Gaussian-distributed, preventing collapse.**Alternative (hybrid branch)**: VICReg (variance-invariance-covariance) regularization.**Total loss**:```L_total = L_JEPA + L_task + λ · L_reg + α · L_genWhere:L_task = CrossEntropy(disc_head(z_K), answer_label) # MC scoringL_gen = CE(gen_head(z_K), target_answer_tokens) # Short answer (Phase 3)λ = 0.1 (regularization weight)α = 0.1 (generative weight)```6 unmodified linesprobs = softmax(scores, mask=valid_options)```**Generative Head (Secondary, Phase 3)** — for open-ended questions:```Qwen3.5-4B (or SmolLM3-3B) decoder:- Cross-attention to z_K (latent state)- Cross-attention to evidence memory (evidence-constrained)- Max 64 tokens output```---## 3. Training Protocol### Phase 1: Reasoning Core (15–20 epochs)| Component | Status | LR ||-----------|--------|-----|| DINOv3-L | **Frozen** | — || Qwen3-Embedding | **Frozen** | — || Evidence Memory | Training | 3e-4 || Latent Rollout | Training | 3e-4 || Answer Heads | Training | 3e-4 || Target Encoder | EMA update | — |**Data**: ScienceQA train (12.7K)**Objective**: Full JEPA + task + SIGReg/VICReg**Batch size**: 16 × 4 accum = 64 effective### Phase 2: Perception Fine-tuning (10 epochs)| Component | Status | LR ||-----------|--------|-----|| DINOv3-L (last 6 layers) | **Training** | 1e-5 || Qwen3-Embedding (last 4 layers) | **Training** | 1e-5 || Evidence Memory | Training | 1e-4 || Latent Rollout | Training | 1e-4 || Answer Heads | Training | 1e-4 |3 unmodified lines| Component | Status | LR ||-----------|--------|-----|| All above | Training | 5e-5 || OCR tokens (PaddleOCR-VL-1.5) | **Enabled** | 5e-5 || Layout tokens | **Enabled** | 5e-5 || Chart tokens | **Enabled** | 5e-5 || SAM 3.1 segments (jetjodh/sam3.1) | **Enabled (optional)** | 5e-5 |**Focus benchmarks**: DocVQA, TextVQA, ChartQA12 unmodified lines| **K=1** | Shallow rollout | Worse than K=3 || **K=5** | Deeper rollout | Diminishing returns || **No SIGReg** | Remove anti-collapse | Training instability || **Purist branch** | DINOv3-B, no enriched evidence | Lower absolute scores, but validates JEPA contribution |### Cross-benchmark analysis:- JEPA contribution should be highest on **reasoning** benchmarks (MathVista, MMMU, ScienceQA)6 unmodified lines| Component | Parameters | Trainable (Phase 1) ||-----------|-----------|---------------------|| DINOv3-L | 300M | 0 || Qwen3-Embedding-0.6B | 596M | 0 || Evidence Memory | ~3M | 3M || Latent Rollout | ~3M | 3M || Disc Head | ~2M | 2M || **Total (Phase 1)** | **~904M** | **~8M** |Phase 1 trains only ~1% of total parameters. The model is computationally efficient — the JEPA reasoning core is lightweight compared to the frozen perception backbones.---17 unmodified lines1. **I-JEPA** (Assran et al., 2023) — arxiv:2301.08243: JEPA architecture, EMA target encoder, L2 prediction loss, narrow predictor2. **V-JEPA** (Bardes et al., 2024) — arxiv:2412.10925: Temporal extension, multi-step prediction in latent space3. **LeWorldModel** (Maes et al., 2025) — arxiv:2603.19312: SIGReg anti-collapse, end-to-end JEPA from pixels4. **Coconut** (Yu et al., 2024) — arxiv:2412.06769: Chain of Continuous Thought, latent reasoning paradigm5. **SoftCoT++** (Xu et al., 2025) — arxiv:2505.11484: Soft chain-of-thought with perturbation and contrastive learning6. **DINOv3** (Meta, 2025) — arxiv:2508.10104: Dense SSL with RoPE, Gram anchoring, LVD-1689M7. **SigLIP2** (Google, 2025) — arxiv:2502.14786: CLIP-style with DINO features + captioning
mr_jepa/ARCHITECTURE.md+55-55