# gengzezhou/navgpt-2 architecture

> Architecture diagram of the GitHub repository gengzezhou/navgpt-2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gengzezhou/navgpt-2
- Repository: https://github.com/gengzezhou/navgpt-2

## Overview

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: [`map_nav_src/r2r`](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/r2r) (R2R runtime), [`map_nav_src/models/lavis/models/blip2_models`](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/models/blip2_models) (NavGPT models), [`map_nav_src/models/lavis`](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis) (LAVIS runtime), [`map_nav_src/models/train.py`](https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/models/train.py) (Train entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_data["Data & artifacts"]
  node_download_py["Download<br/>bootstrap script<br/>[download.py]"]
  node_datasets_dir[("Datasets<br/>data root")]
  node_lavis_output[("Checkpoints<br/>training outputs")]
end

subgraph group_group_stage1["Stage 1: LAVIS tuning"]
  node_train_py["Train entry<br/>stage-1 entrypoint<br/>[train.py]"]
  node_run_scripts["Train scripts<br/>launch scripts"]
  node_nav_configs["Nav configs<br/>yaml configs"]
  node_lavis_runner["LAVIS runtime<br/>framework core"]
  node_nav_models["NavGPT models<br/>multimodal model"]
end

subgraph group_group_stage2["Stage 2: R2R policy"]
  node_main_nav["Nav entry<br/>stage-2 entrypoint<br/>[main_nav.py]"]
  node_r2r_scripts["R2R scripts<br/>launch scripts"]
  node_r2r_core["R2R runtime<br/>navigation runtime"]
  node_nav_agent["Agent<br/>policy<br/>[agent.py]"]
  node_nav_env["Environment<br/>simulator boundary<br/>[env.py]"]
  node_eval_utils["Eval utils<br/>metrics<br/>[eval_utils.py]"]
end

subgraph group_group_support["Shared support"]
  node_shared_utils["Shared utils<br/>support code"]
  node_llm_backends["LLM backends<br/>frozen language models"]
  node_third_party["Vendored deps<br/>embedded libraries"]
end

node_download_py -->|"populates"| node_datasets_dir
node_download_py -->|"fetches"| node_lavis_output
node_datasets_dir -->|"feeds"| node_nav_configs
node_train_py -->|"launched by"| node_run_scripts
node_train_py -->|"uses"| node_lavis_runner
node_nav_configs -->|"selects"| node_nav_models
node_lavis_runner -->|"instantiates"| node_nav_models
node_lavis_runner -->|"depends on"| node_third_party
node_nav_models -->|"wraps"| node_llm_backends
node_nav_models -->|"uses"| node_shared_utils
node_lavis_runner -->|"writes"| node_lavis_output
node_r2r_scripts -->|"launched by"| node_main_nav
node_main_nav -->|"orchestrates"| node_r2r_core
node_r2r_core -->|"drives"| node_nav_agent
node_r2r_core -->|"steps"| node_nav_env
node_r2r_core -->|"scores"| node_eval_utils
node_nav_env -->|"reads"| node_datasets_dir
node_nav_agent -->|"loads"| node_nav_models
node_r2r_core -->|"uses"| node_shared_utils
node_train_py -->|"uses"| node_shared_utils

click node_download_py "https://github.com/gengzezhou/navgpt-2/blob/master/download.py"
click node_datasets_dir "https://github.com/gengzezhou/navgpt-2/tree/master/datasets"
click node_train_py "https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/models/train.py"
click node_run_scripts "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/run_scripts"
click node_nav_configs "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/configs"
click node_lavis_runner "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis"
click node_nav_models "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/models/blip2_models"
click node_main_nav "https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/r2r/main_nav.py"
click node_r2r_scripts "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/scripts"
click node_r2r_core "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/r2r"
click node_nav_agent "https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/r2r/agent.py"
click node_nav_env "https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/r2r/env.py"
click node_eval_utils "https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/r2r/eval_utils.py"
click node_shared_utils "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/utils"
click node_llm_backends "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/models/blip2_models"
click node_third_party "https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/common/annotator"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_download_py,node_datasets_dir,node_lavis_output toneBlue
class node_train_py,node_run_scripts,node_nav_configs,node_lavis_runner,node_nav_models toneAmber
class node_main_nav,node_r2r_scripts,node_r2r_core,node_nav_agent,node_nav_env,node_eval_utils toneMint
class node_shared_utils,node_llm_backends,node_third_party toneRose
```

## Components

### Data & artifacts

Downloaded datasets, pretrained checkpoints, and experiment outputs used by both stages.

- [Download](https://github.com/gengzezhou/navgpt-2/blob/master/download.py): bootstrap script · Populates datasets and can fetch pretrained checkpoints. · `download.py`
- [Datasets](https://github.com/gengzezhou/navgpt-2/tree/master/datasets): data root · R2R assets, instruction-tuning data, features, and connectivity files. · `datasets`
- **Checkpoints**: training outputs · Stage-1 checkpoints and logs emitted by NavGPT training.

### Stage 1: LAVIS tuning

Visual instruction tuning built on the vendored LAVIS training stack.

- [Train entry](https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/models/train.py): stage-1 entrypoint · Launches LAVIS-based visual instruction tuning. · `map_nav_src/models/train.py`
- [Train scripts](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/run_scripts): launch scripts · Shell wrappers for FlanT5 and Vicuna variants. · `map_nav_src/models/run_scripts`
- [Nav configs](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/configs): yaml configs · NavGPT-specific model and dataset configurations for stage 1. · `map_nav_src/models/lavis/configs`
- [LAVIS runtime](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis): framework core · Config-driven datasets, processors, tasks, runners, and checkpointing. · `map_nav_src/models/lavis`
- [NavGPT models](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/models/blip2_models): multimodal model · 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](https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/r2r/main_nav.py): stage-2 entrypoint · Runs R2R finetuning and evaluation from a single navigation entrypoint. · `map_nav_src/r2r/main_nav.py`
- [R2R scripts](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/scripts): launch scripts · Convenience wrappers for training and validation runs. · `map_nav_src/scripts`
- [R2R runtime](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/r2r): navigation runtime · Argument parsing, prompts, environment interaction, and agent control. · `map_nav_src/r2r`
- [Agent](https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/r2r/agent.py): policy · Consumes instructions and produces navigation actions. · `map_nav_src/r2r/agent.py`
- [Environment](https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/r2r/env.py): simulator boundary · Interfaces with Matterport3D connectivity and precomputed features. · `map_nav_src/r2r/env.py`
- [Eval utils](https://github.com/gengzezhou/navgpt-2/blob/master/map_nav_src/r2r/eval_utils.py): metrics · 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](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/utils): support code · Logging, distributed helpers, math utilities, and common data helpers used across stages. · `map_nav_src/utils`
- [LLM backends](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/models/blip2_models): frozen language models · Interchangeable FlanT5 and Vicuna backends selected by config and script. · `map_nav_src/models/lavis/models/blip2_models`
- [Vendored deps](https://github.com/gengzezhou/navgpt-2/tree/master/map_nav_src/models/lavis/common/annotator): embedded libraries · Bundled LAVIS dependencies and secondary third-party subtrees such as annotator, uniformer, and mmseg. · `map_nav_src/models/lavis/common/annotator`

## Connections

- 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.
