ML Training Pipeline - Quick Reference
End-to-end walkthrough of how training works in this repo. For the full paper extraction see
docs/paper_spec.md; for every unspecified-detail decision see docs/assumptions.md.
The data flow
Raw images + annotations
│
▼
backend/tools/convert_dataset.py (per-dataset converter → JSONL manifest)
│
▼
backend/data/dataset.py: MMRSDataset (loads manifest, resolves images, runs modality processor)
│
▼
backend/data/collator.py: MMRSCollator (renders conversation, tokenizes, builds response-only labels)
│
▼
DataLoader(batch_size, shuffle, collate_fn)
│
▼
backend/training/trainer.py: Trainer (forward → loss → backward → step → checkpoint)
│
▼
backend/checkpoints/stage{1,2}/final/ (model.pt + tokenizer/ + metadata.json)
The model forward pass
input_ids + images_per_sample + labels
│
▼
EarthOneVisionModel.build_multimodal_inputs()
│
├─ SigLIP2VisionEncoder.encode_image() → F_N + 3 intermediate features
│
├─ ACSA(f_N, [F_l1, F_l2, F_l3]) → F̃_N (enhanced final feature)
│
├─ VisionLanguageProjector(F̃_N, grid) → visual tokens [N/4, D_llm]
│
├─ _splice_one_sample() → replace <image> placeholders with visual embeddings
│
├─ DeepStackInjector.stage_multi_image() → project intermediate features, stage for hooks
│
└─ Qwen3ForCausalLM(inputs_embeds=...) → logits + loss (response-only masked CE)
Loss function
L = -Σ_{t∈R} log P(y_t | y_<t, x)
Where R = response token indices only. Prompt tokens, image placeholder positions, visual token
embeddings, and padding all have labels = -100 (ignored by PyTorch's cross_entropy).
Implemented in backend/training/loss.py:
build_response_only_labels(input_ids, response_mask)- sets non-response positions to -100response_only_cross_entropy(logits, labels)- shift+CE (standalone, for testing)- In training,
Qwen3ForCausalLM.forward(labels=...)does the same internally
PCMA two-stage curriculum
Stage 1: Viewpoint gap (natural → optical RS)
- Goal: Bridge the gap between natural-scene images and optical remote-sensing imagery
- Data: LLaVA-OneVision-Data + optical RS (RSVQA, VRSBench)
- LR: 2e-5 (paper) / 3e-5 (baseline)
- Config:
backend/configs/stage1.yaml - Output:
backend/checkpoints/stage1/final/
Stage 2: Physics gap (optical → non-optical) + optical replay
- Goal: Introduce SAR, infrared, multispectral, temporal, video, fusion modalities
- Data: Stage 2 non-optical + full Stage 1 optical replay (prevents catastrophic forgetting)
- LR: 5e-6 (10× lower than Stage 1)
- Init: Loads Stage 1 checkpoint
- Config:
backend/configs/stage2.yaml - Output:
backend/checkpoints/stage2/final/
Running training
2x NVIDIA A40 (primary target)
cd backend
bash scripts/train_stage1.sh # or: python training/train.py --config configs/stage1.yaml
bash scripts/train_stage2.sh
CUDA multi-GPU with DeepSpeed ZeRO-2
cd backend
deepspeed --num_gpus=2 training/train.py \
--config configs/stage1.yaml \
--deepspeed configs/deepspeed_zero2.json \
--manifest data/manifests/stage1_train.jsonl \
--images_root data/converted
deepspeed --num_gpus=2 training/train.py \
--config configs/stage2.yaml \
--deepspeed configs/deepspeed_zero2.json \
--manifest data/manifests/stage2_train.jsonl \
--images_root data/converted
Baseline (what was actually run)
cd backend
SATQUERY_CHECKPOINT=checkpoints/baseline-rsvqa \
uvicorn app.backend.main:app --port 8000
This used configs/baseline_train.yaml (stage 0, Qwen3-0.6B, 1 epoch, 772 RSVQA images).
Checkpoint contents
checkpoints/stage1/final/
├── model.pt # PyTorch state dict
├── tokenizer/ # HF tokenizer (save_pretrained)
├── earth_onevision_metadata.json # EarthOneVisionConfig + step/epoch + vocab extension sizes
├── optimizer.pt # (optional)
└── scheduler.pt # (optional)
Every checkpoint is labeled earth_onevision_reproduction_checkpoint with
is_official_earth_onevision_checkpoint: false - load_checkpoint refuses to load anything
claiming otherwise (docs/assumptions.md #A11).
Key hyperparameters (paper → this repo)
| Parameter | Paper | This repo |
|---|---|---|
| LLM | Qwen3 2B | Qwen/Qwen3-1.7B (A1) |
| Vision | SigLIP-2 0.3B NaFlex | google/siglip2-base-patch16-naflex |
| Optimizer | AdamW, wd=0.05 | Same (PAPER_EXPLICIT) |
| LR schedule | Cosine, warmup=0.03 | Same (PAPER_EXPLICIT) |
| Max seq length | 5400 | Same (PAPER_EXPLICIT) |
| Batch size | 4/GPU | 4/GPU (A40) |
| Epochs | 4 (both stages) | Same (PAPER_EXPLICIT) |
| Precision | bf16 | bf16 (CUDA) |
| Distributed | 8×H100 ZeRO-2 | 2×A40 ZeRO-2 |
| Vision tower | Frozen (inferred) | Frozen by default (A3) |
Device adaptation
backend/training/distributed.py: get_device_strategy() auto-detects:
- CUDA: bf16 + DeepSpeed ZeRO-2 if multi-GPU
- CPU: fp32 (smoke-test scale only)
Gradient accumulation stands in for the paper's 8-GPU batch parallelism on single devices.