How gengzezhou/navgpt-2 works
1. Repository shape
This repo is split into two main execution paths: a LAVIS-based training stack under map_nav_src/models for NavGPT-2 visual instruction tuning, and an R2R navigation stack under map_nav_src/r2r for policy finetuning and evaluation.
2. End-to-end data flow
The pipeline starts with download.py, which populates datasets/ with R2R navigation assets and instruction-tuning data, and can also fetch pretrained checkpoints. Those artifacts are then consumed by the stage-1 and stage-2 training/evaluation scripts.
3. Stage 1: visual instruction tuning
Stage 1 is driven by map_nav_src/models/train.py and the shell scripts in map_nav_src/models/run_scripts/. This stage fine-tunes the NavGPT-2 Q-former on NavGPT instruction data using the LAVIS framework, producing checkpoints in map_nav_src/models/lavis/output.
4. Stage 1 model boundary
The core NavGPT-2 model definitions live in map_nav_src/models/lavis/models/blip2_models/, especially the NavGPT-specific variants such as blip2_t5_instruct_nav.py and blip2_vicuna_instruct_nav.py. These wrap a visual encoder plus Q-former and connect to different frozen LLM backends such as FlanT5 or Vicuna.
5. LAVIS as the training framework
The vendored LAVIS subtree provides the config-driven infrastructure for datasets, processors, tasks, runners, distributed training, and checkpointing. Relevant entry points are configs/, datasets/, processors/, tasks/, and runners/, with NavGPT-specific project configs under projects/blip2/train/.
6. Stage 2: navigation policy finetuning
Stage 2 is centered in map_nav_src/r2r/ and launched by scripts like scripts/run_r2r_xl.sh and scripts/val_r2r_xl.sh. This stage loads the pretrained NavGPT-2 Q-former and finetunes the navigation policy on the R2R benchmark.
7. Navigation runtime
The R2R runtime is organized around main_nav.py, agent.py, env.py, and supporting modules like parser.py and prompt_template.py. The agent reads language instructions, interacts with the environment, and produces action sequences for navigation.
8. Simulator and scene graph dependency
The runtime depends on the Matterport3D simulator and precomputed R2R connectivity/feature data. The environment boundary is important: the policy does not operate on raw RGB from scratch; it uses dataset-provided features and scene connectivity information to reason over navigable viewpoints.
9. Evaluation path
Evaluation utilities live in map_nav_src/r2r/eval_utils.py, with rollout and scoring driven from the same navigation entrypoint. The repo is set up to report standard R2R metrics such as navigation error and success/spl metrics, and to save finetuning experiments under datasets/R2R/exprs_map/finetune.
10. Model variant switching
The architecture is designed around interchangeable LLM backends. The same navigation/instruction-tuning pipeline can be run with FlanT5-XL/XXL or Vicuna-7B/13B, with the variant selected by the corresponding shell script and YAML config.
11. Shared support code
map_nav_src/utils/, map_nav_src/models/ops.py, transformer.py, vilmodel.py, and the various distributed/logging helpers provide common infrastructure across both stages. These are supporting layers rather than separate subsystems, but they matter for how training is parallelized and how checkpoints/logs are handled.
12. Vendored but secondary components
The repo includes large third-party subtrees such as lavis/common/annotator, uniformer, and mmseg. These are part of the bundled dependency surface, but they are not the main NavGPT-2 architecture; the diagram should treat them as embedded support libraries unless specifically depicting the broader codebase.
Main entry points: r2r R2R runtime · blip2_models NavGPT models · lavis LAVIS runtime · train.py Train entry
Components 17
Data & artifacts
Downloaded datasets, pretrained checkpoints, and experiment outputs used by both stages.
Stage 1: LAVIS tuning
Visual instruction tuning built on the vendored LAVIS training stack.
- Train entry · Launches LAVIS-based visual instruction tuning.
map_nav_src/models/train.py - Train scripts · Shell wrappers for FlanT5 and Vicuna variants.
map_nav_src/models/run_scripts - Nav configs · NavGPT-specific model and dataset configurations for stage 1.
map_nav_src/models/lavis/configs - LAVIS runtime · Config-driven datasets, processors, tasks, runners, and checkpointing.
map_nav_src/models/lavis - NavGPT models · NavGPT-2 BLIP2 variants that combine a visual encoder, Q-former, and frozen LLM backend.
map_nav_src/models/lavis/models/blip2_models
Stage 2: R2R policy
Navigation policy finetuning and evaluation on the R2R benchmark.
- Nav entry · Runs R2R finetuning and evaluation from a single navigation entrypoint.
map_nav_src/r2r/main_nav.py - R2R scripts · Convenience wrappers for training and validation runs.
map_nav_src/scripts - R2R runtime · Argument parsing, prompts, environment interaction, and agent control.
map_nav_src/r2r - Agent · Consumes instructions and produces navigation actions.
map_nav_src/r2r/agent.py - Environment · Interfaces with Matterport3D connectivity and precomputed features.
map_nav_src/r2r/env.py - Eval utils · Rollout scoring and standard R2R metric computation.
map_nav_src/r2r/eval_utils.py
Shared support
Common utilities and bundled third-party dependencies.
- Shared utils · Logging, distributed helpers, math utilities, and common data helpers used across stages.
map_nav_src/utils - LLM backends · Interchangeable FlanT5 and Vicuna backends selected by config and script.
map_nav_src/models/lavis/models/blip2_models - Vendored deps · Bundled LAVIS dependencies and secondary third-party subtrees such as annotator, uniformer, and mmseg.
map_nav_src/models/lavis/common/annotator
Connections 20
- Download → Datasets: populates · Downloads benchmark assets and instruction data.
- Download → Checkpoints: fetches · Can also retrieve pretrained checkpoints.
- Datasets → Nav configs: feeds · Datasets and metadata referenced by training configs.
- Train entry → Train scripts: launched by · Stage-1 shell entry points call the training driver.
- Train entry → LAVIS runtime: uses · Training is executed through the LAVIS framework.
- Nav configs → NavGPT models: selects · Config files choose the NavGPT model variant and backend.
- LAVIS runtime → NavGPT models: instantiates · Builds the multimodal model and training task.
- LAVIS runtime → Vendored deps: depends on · Vendored support libraries provide the framework surface.
- NavGPT models → LLM backends: wraps · NavGPT variants connect to FlanT5 or Vicuna backends.
- NavGPT models → Shared utils: uses · Shared model code relies on common support utilities.
- LAVIS runtime → Checkpoints: writes · Emits checkpoints and logs after tuning.
- R2R scripts → Nav entry: launched by · Shell wrappers start training or validation runs.
- Nav entry → R2R runtime: orchestrates · Main entrypoint coordinates parsing, agent execution, and scoring.
- R2R runtime → Agent: drives · Agent implements the navigation policy loop.
- R2R runtime → Environment: steps · Policy actions are evaluated inside the simulator boundary.
- R2R runtime → Eval utils: scores · Rollouts are measured with R2R metrics.
- Environment → Datasets: reads · Uses features, connectivity graphs, and benchmark data.
- Agent → NavGPT models: loads · Finetuning starts from the pretrained NavGPT Q-former boundary.
- R2R runtime → Shared utils: uses · Shares logging, distributed, and data helpers.
- Train entry → Shared utils: uses · Stage-1 training also relies on shared utilities.