How leaplabthu/dat works
Main Components
• Configuration & Hyperparameter Management:
• Files: config.py and the YAML files inside the “configs” directory.
• Role: Ingest and manage model settings, hyperparameters, and training configurations.
• Data Preprocessing & Loading:
• Files: data/__init__.py, data/build.py, data/samplers.py.
• Role: Prepare image data (likely ImageNet based on the README instructions), data augmentation, and batching.
• Model Construction:
• Files: models/__init__.py, models/build.py, and the specific modules like models/dat.py, models/dat_blocks.py, models/nat.py, models/qna.py, models/slide.py.
• Role: Define the backbone (Vision Transformer with Deformable Attention) including its core building blocks (attention modules, transformer layers, etc.).
• Training & Evaluation Pipeline:
• Entry Points: main.py, evaluate.sh, train.sh, slurm_main.sh, train_slurm.sh.
• Role: Handle training loop execution, evaluation metrics, multi-GPU/multi-node training configurations.
• Utilities & Scheduling:
• Files: lr_scheduler.py, optimizer.py, logger.py, utils.py.
• Role: Implement learning rate scheduling, optimization, logging of training progress and experimental results.
• Static Mapping Assets:
• File: map_22kto1k.pth.
• Role: Serve as a bridge for pretraining data mapping (e.g., adapting ImageNet-22K features to ImageNet-1K classification).
Relationships and Data Flow
• Start from the configuration layer: YAML files (in configs) are loaded through config.py to parameterize the training and evaluation pipelines.
• Data module: The “data” folder processes input images and prepares data loaders, passing data to the training loop.
• Training Controller: main.py (and its counterpart for multi-machine training in slurm_main.sh / train_slurm.sh) uses the processed configuration and data to instantiate the model.
• Model Assembly: The “models” directory contains the actual network architectures. The build functions are called from main.py to construct the specific variant of the network (e.g., DAT, NAT, QNA, or SLIDE variants).
• Training/Evaluation Loop: Using lr_scheduler, optimizer, and logger modules, the training loop processes batches, updates model parameters, and logs performance metrics.
• Evaluation Script: The evaluate.sh script handles loading pretrained weights, running inference, and outputting classification accuracies.
Architectural Patterns and Design Principles
• Modular Design: Clear separation between configurations, data processing, model building, and training/evaluation routines.
• Pipeline Abstraction: The data flow from raw inputs to preprocessed data, then to model training and evaluation illustrates a classic ML/pipeline design.
• Flexibility & Extensibility: The multiple model building functions and configuration files allow researchers to experiment with various DAT versions (Tiny, Small, Base) and resolutions (e.g., 224x224 vs 384x384).
• Integration of External Dependencies: The use of third-party libraries (PyTorch, timm, natten, etc.) is a key part of the technology stack and should be noted.
Final Elements
• Clear Labels: Each block (Configuration, Data Loader, Model Builder, Training/Evaluation Modules, Utility Modules, etc.) should be explicitly labeled.