# litinglin/lorat architecture

> Architecture diagram of the GitHub repository litinglin/lorat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/litinglin/lorat
- Repository: https://github.com/litinglin/lorat

## Overview

##### Project Type & Purpose
- This is a research‐grade, full-stack Python codebase for training and evaluating visual object trackers using Low-rank Adaptation (LoRA).
- It orchestrates configuration, dataset ingestion, model building (backbones, LoRA adapters, heads), training (single/multi-GPU, DeepSpeed), evaluation (VOT toolkit, GOT-10k, TrackingNet), logging (WandB, local), checkpointing and distributed services.

##### Top-Level Components
a. Entry Point
- run.sh / python main.py / python sweep.py / python vot_main.py
- Parses CLI args, loads YAML configs, sets up environment variables.
b. Configuration Layer (config/)
- Hierarchical YAML mixins for datasets, training hyperparameters, evaluation protocols, ablations.
- consts.yaml holds user paths to raw datasets and VOT workspaces.
c. Core Bootstrapping (trackit/core/boot)
- init_application, load_config, setup_wandb, spawn distributed processes.
- Builds a GlobalContext capturing run_id, device info, configuration tree.
d. Builder / Factory Abstractions
- Declarative “builder” modules under trackit/data/builder.py, trackit/models/backbone/builder.py, trackit/models/methods/LoRAT/builder.py, trackit/runners/builder.py
- Implements the Builder Pattern: config → Python object graph.
e. Data Pipeline (trackit/data)
- DataSources (SOT, MOT, DET, CLS), sampling strategies (per_frame, per_sequence), transforms & augmentations.
- DataLoader abstraction to yield batches for train or eval.
f. Model Stack (trackit/models)
- Backbones: DINOv2, ConvNeXt, Swin, MAE, CLIP, EVA.
- LoRA adapters, PEFT modules, head modules (conv, MLP, OStrack).
- Compiling/tracing options (torch.compile, TorchScript, auto-mixed-precision).
g. Runners (trackit/runners)
- Training Runner: handles forward/backward passes, optimizers, schedulers, gradient accumulation, DeepSpeed integration.
- Evaluation Runner: distributed evaluation, VOT toolkit integration, segmentation via SAM models.
- Common services: checkpoint manager, garbage collector, event bus, distributed collective communication.
h. Logging & Monitoring
- MetricLogger with local and WandB adaptors.
- Profiling: flop count, latency, parameter count.
i. Persistence & Checkpointing
- CheckpointService for saving/loading model weights and training state (resumable), file scheduling.
j. External Integrations
- WandB, VOT Toolkit, DeepSpeed, file system datasets.

##### Relationships & Data Flow
- Entry Point → Bootstrapping → Config Loader → Builder modules instantiate DataPipeline, Model, Runner, Services.
- DataPipeline fetches raw data → Transform → Batch → feeds into Model.
- Runner orchestrates training loop: Model → Loss (trackit/criteria) → Optimizer → Backprop → CheckpointService → MetricLogger.
- Evaluation Runner orchestrates inference loops, result collection (trackit/data/components/result_collector) → persistence and reporting.
- Services (checkpoint, event, communication) operate concurrently in background threads or distributed contexts.

##### Architectural Patterns & Design Principles
- Configuration-Driven: decouple code from hyperparameters and protocols via mixins.
- Builder/Factory: uniform instantiation API for data, models, runners, services.
- Modular Plugins: transforms, sampling strategies, criterion modules, segmentation adaptors.
- Separation of Concerns: core/tracking logic vs. dataset handling vs. model definition vs. runtime services.
- Extensibility: plug new datasets, backbones, LoRA modules by registering builders and adding YAML.

##### Key Technologies, Frameworks & Libraries
- Python 3.8+, PyTorch ≥2.0, TorchScript, torch.compile
- DeepSpeed for large-scale training
- WandB for experiment tracking
- VOT Toolkit for visual-object-tracking benchmarks
- YAML (Ω OmegaConf/Custom YAML Loader) for config
- CUDA, CPU, MPS support for macOS

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI1["run.sh"]:::core
        UI2["main.py"]:::core
        UI3["sweep.py"]:::core
        UI4["vot_main.py"]:::core
    end

    %% Configuration Layer
    subgraph "Configuration Layer"
        CFG1["config/"]:::config
        CFG2["config/_dataset/"]:::config
        CFG3["config/_mixin/"]:::config
        CFG4["config/LoRAT/"]:::config
        CFG5["config/LoRAT/_mixin/deepspeed.yaml"]:::config
        CFG6["config/LoRAT/_mixin/deepspeed-stage_3.yaml"]:::config
        CFG7["consts.yaml.template"]:::config
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        OR1["trackit/core/boot/main.py"]:::core
        OR2["load_config"]:::core
        OR3["torch_distributed_do_spawn_workers.py"]:::core
        OR4["init_application.py"]:::core
        OR5["setup_wandb.py"]:::core
        OR6["trackit/core/boot/vot.py"]:::core
        OR7["trackit/core/boot/sweep.py"]:::core
    end

    %% Builder Layer
    subgraph "Builder Layer"
        B1["trackit/data/builder.py"]:::core
        B2["trackit/models/backbone/builder.py"]:::core
        B3["trackit/models/methods/LoRAT/builder.py"]:::core
        B4["trackit/runners/builder.py"]:::core
        B5["trackit/criteria/builder.py"]:::core
    end

    %% Execution Layer
    subgraph "Execution Layer"
        subgraph "Data Pipeline" 
            DP1["trackit/data/"]:::data
            DP2["trackit/data/source/builder.py"]:::data
            DP3["trackit/data/sampling/"]:::data
            DP4["trackit/data/methods/.../transform/"]:::data
            DP5["trackit/data/components/result_collector/"]:::data
        end
        subgraph "Model Stack"
            M1["trackit/models/backbone/"]:::model
            M2["trackit/models/methods/LoRAT/modules/"]:::model
            M3["trackit/models/methods/LoRAT/ablation/"]:::model
            M4["trackit/models/compiling/"]:::model
        end
        subgraph "Runners"
            R1["trackit/runners/training/default/runner.py"]:::core
            R2["trackit/runners/training/with_deepspeed/runner.py"]:::core
            R3["trackit/runners/evaluation/distributed/"]:::core
            R4["trackit/runners/evaluation/common/"]:::core
            R5["trackit/runners/context.py"]:::core
        end
        subgraph "Services"
            S1["trackit/core/runtime/services/checkpoint.py"]:::services
            S2["trackit/core/runtime/metric_logger/"]:::services
            S3["adaptors/local/builder.py"]:::services
            S4["adaptors/wandb/builder.py"]:::services
            S5["trackit/core/runtime/utils/checkpoint/save/"]:::services
            S6["trackit/core/runtime/utils/checkpoint/load.py"]:::services
            S7["trackit/core/runtime/utils/checkpoint/save/scheduling/"]:::services
        end
    end

    %% External Services
    subgraph "External Services"
        EXT1["WandB"]:::external
        EXT2["DeepSpeed"]:::external
        EXT3["VOT Toolkit"]:::external
        EXT4["File System Datasets"]:::external
        EXT5["SAM Segmentation"]:::external
    end

    %% Connections
    UI1 -->|start| OR1
    UI2 -->|start| OR1
    UI3 -->|start| OR7
    UI4 -->|start| OR6

    OR1 -->|loads| OR2
    OR2 -->|reads| CFG1
    OR2 --> CFG2
    OR2 --> CFG3
    OR2 --> CFG4
    CFG4 --> CFG5
    CFG4 --> CFG6
    CFG1 --> CFG7

    OR1 -->|spawns| OR3
    OR1 -->|init| OR4
    OR1 -->|setup| OR5

    OR5 --> EXT1
    OR6 --> EXT3
    OR7 --> OR2

    OR2 -->|instantiates| B1
    OR2 --> B2
    OR2 --> B3
    OR2 --> B4
    OR2 --> B5

    B1 -->|builds| DP1
    B1 --> DP2
    B1 --> DP3
    B1 --> DP4

    B2 -->|builds| M1
    B3 --> M2
    B3 --> M3
    B4 --> R1
    B4 --> R2
    B4 --> R3
    B4 --> R4
    B5 -->|builds loss| R1

    DP1 -->|batch data| DP5
    DP5 ---|input| M1
    M1 -->|forward| M4
    M2 -->|inject adapter| M4
    M4 -->|compiled model| R1

    R1 -->|train loop| S1
    R1 -->|log metrics| S2
    S2 --> EXT1
    R2 --> EXT2

    R3 -->|eval loop| DP5
    R3 --> EXT3
    R3 --> EXT5

    S1 -->|save/load| S5
    S1 -->|load| S6
    S1 -->|schedule| S7

    %% Click Events
    click UI1 "https://github.com/litinglin/lorat/blob/main/run.sh"
    click UI2 "https://github.com/litinglin/lorat/blob/main/main.py"
    click UI3 "https://github.com/litinglin/lorat/blob/main/sweep.py"
    click UI4 "https://github.com/litinglin/lorat/blob/main/vot_main.py"
    click CFG1 "https://github.com/litinglin/lorat/tree/main/config/"
    click CFG2 "https://github.com/litinglin/lorat/tree/main/config/_dataset/"
    click CFG3 "https://github.com/litinglin/lorat/tree/main/config/_mixin/"
    click CFG4 "https://github.com/litinglin/lorat/tree/main/config/LoRAT/"
    click CFG5 "https://github.com/litinglin/lorat/blob/main/config/LoRAT/_mixin/deepspeed.yaml"
    click CFG6 "https://github.com/litinglin/lorat/blob/main/config/LoRAT/_mixin/deepspeed-stage_3.yaml"
    click CFG7 "https://github.com/litinglin/lorat/blob/main/consts.yaml.template"
    click OR1 "https://github.com/litinglin/lorat/blob/main/trackit/core/boot/main.py"
    click OR2 "https://github.com/litinglin/lorat/blob/main/trackit/core/boot/funcs/main/load_config.py"
    click OR3 "https://github.com/litinglin/lorat/blob/main/trackit/core/boot/funcs/main/torch_distributed_do_spawn_workers.py"
    click OR4 "https://github.com/litinglin/lorat/blob/main/trackit/core/boot/funcs/main/init_application.py"
    click OR5 "https://github.com/litinglin/lorat/blob/main/trackit/core/boot/funcs/main/setup_wandb.py"
    click OR6 "https://github.com/litinglin/lorat/blob/main/trackit/core/boot/vot.py"
    click OR7 "https://github.com/litinglin/lorat/blob/main/trackit/core/boot/sweep.py"
    click B1 "https://github.com/litinglin/lorat/blob/main/trackit/data/builder.py"
    click B2 "https://github.com/litinglin/lorat/blob/main/trackit/models/backbone/builder.py"
    click B3 "https://github.com/litinglin/lorat/blob/main/trackit/models/methods/LoRAT/builder.py"
    click B4 "https://github.com/litinglin/lorat/blob/main/trackit/runners/builder.py"
    click B5 "https://github.com/litinglin/lorat/blob/main/trackit/criteria/builder.py"
    click DP2 "https://github.com/litinglin/lorat/blob/main/trackit/data/source/builder.py"
    click DP3 "https://github.com/litinglin/lorat/tree/main/trackit/data/sampling/"
    click DP4 "https://github.com/litinglin/lorat/tree/main/trackit/data/methods/.../transform/"
    click DP5 "https://github.com/litinglin/lorat/tree/main/trackit/data/components/result_collector/"
    click M1 "https://github.com/litinglin/lorat/tree/main/trackit/models/backbone/"
    click M2 "https://github.com/litinglin/lorat/tree/main/trackit/models/methods/LoRAT/modules/"
    click M3 "https://github.com/litinglin/lorat/tree/main/trackit/models/methods/LoRAT/ablation/"
    click M4 "https://github.com/litinglin/lorat/tree/main/trackit/models/compiling/"
    click R1 "https://github.com/litinglin/lorat/blob/main/trackit/runners/training/default/runner.py"
    click R2 "https://github.com/litinglin/lorat/blob/main/trackit/runners/training/with_deepspeed/runner.py"
    click R3 "https://github.com/litinglin/lorat/tree/main/trackit/runners/evaluation/distributed/"
    click R4 "https://github.com/litinglin/lorat/tree/main/trackit/runners/evaluation/common/"
    click R5 "https://github.com/litinglin/lorat/blob/main/trackit/runners/context.py"
    click S1 "https://github.com/litinglin/lorat/blob/main/trackit/core/runtime/services/checkpoint.py"
    click S2 "https://github.com/litinglin/lorat/tree/main/trackit/core/runtime/metric_logger/"
    click S3 "https://github.com/litinglin/lorat/blob/main/trackit/core/runtime/metric_logger/adaptors/local/builder.py"
    click S4 "https://github.com/litinglin/lorat/blob/main/trackit/core/runtime/metric_logger/adaptors/wandb/builder.py"
    click S5 "https://github.com/litinglin/lorat/tree/main/trackit/core/runtime/utils/checkpoint/save/"
    click S6 "https://github.com/litinglin/lorat/blob/main/trackit/core/runtime/utils/checkpoint/load.py"
    click S7 "https://github.com/litinglin/lorat/tree/main/trackit/core/runtime/utils/checkpoint/save/scheduling/"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef data fill:#90EE90,stroke:#000,stroke-width:1px
    classDef model fill:#FFA500,stroke:#000,stroke-width:1px
    classDef services fill:#DDA0DD,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef config fill:#F5DEB3,stroke:#000,stroke-width:1px
```
