How lmd0311/pointmamba works
1. Repository purpose and top-level flow
- PointMamba is a point-cloud classification/pretraining codebase built around a Mamba-style state space backbone.
- The main runtime path is: configuration file → dataset builder → model builder → training/evaluation runner → checkpoints/logs.
- It supports two main modes: pretraining on ShapeNet-like data and finetuning/classification on ModelNet40 and ScanObjectNN variants.
2. Entry points
- main.py is the primary training/evaluation entry script.
- main_vis.py is a secondary entry point for visualization/inspection.
- The tools/ package contains the execution orchestration layer, with separate runners for pretraining and finetuning.
3. Configuration boundary
- cfgs/ holds experiment definitions, split into dataset-specific configs and task-specific configs such as pretrain.yaml, finetune_modelnet.yaml, and ScanObjectNN variants.
- utils/config.py, utils/parser.py, and utils/registry.py indicate a config-driven, registry-based assembly pattern rather than hard-coded wiring.
- This means the diagram should show configs feeding both dataset and model instantiation.
4. Dataset subsystem
- datasets/ contains loaders for ModelNet40, ModelNet40FewShot, ScanObjectNN, and ShapeNet55.
- datasets/build.py likely constructs the active dataset/split based on config.
- datasets/data_transforms.py centralizes point-cloud augmentation and preprocessing, which is important because point ordering/tokenization is part of the model design.
- datasets/generate_few_shot_data.py is an offline utility for constructing few-shot splits, so it is a data-preparation boundary rather than part of the training loop.
5. Point cloud I/O and preprocessing
- datasets/io.py isolates low-level file reading/writing for point data.
- The data pipeline likely converts raw point clouds into normalized, augmented point sets before tokenization.
- For architecture diagrams, treat this as the boundary between dataset storage and model-ready tensors.
6. Model subsystem
- models/ contains the repository-specific architecture implementation: point_mamba_scan.py, block_scan.py, block.py, hilbert.py, serialization.py, and build.py.
- hilbert.py is a key architectural component: it suggests point ordering/tokenization via space-filling curves before sequence modeling.
- block_scan.py and block.py imply the core encoder is organized into reusable blocks, likely combining point embedding, sequence scan, and classification head logic.
7. Core architectural idea
- The model is non-hierarchical and sequence-based: point clouds are first ordered/tokenized, then processed by Mamba-style blocks rather than attention layers.
- The architecture therefore has a clear separation between:
- geometric preprocessing / ordering,
- token sequence modeling,
- task head for classification or representation learning.
- This is the most important conceptual boundary for the diagram.
8. Mamba dependency boundary
- The mamba/ directory is a vendored upstream Mamba implementation, not just a small utility.
- It includes custom CUDA/Triton selective-scan operators, model definitions, distributed helpers, and tests.
- In practice, PointMamba’s model code depends on these lower-level sequence operators as the computational core for linear-time state-space processing.
9. Custom CUDA extensions
- extensions/chamfer_dist/ and extensions/emd/ provide GPU-accelerated point-cloud losses or metrics.
- These are separate compiled extension modules, so they form a native-code boundary distinct from Python model code.
- Their presence suggests the repo supports reconstruction/shape-distance style objectives in addition to classification, especially for pretraining or auxiliary evaluation.
10. Training and experiment orchestration
- tools/runner_pretrain.py and tools/runner_finetune.py implement the task-specific loops.
- tools/builder.py likely assembles datasets, models, optimizers, and schedulers from config.
- The utils/ package provides cross-cutting services: logging, distributed utilities, checkpoints, metrics, and miscellaneous helpers.
11. Distributed/runtime behavior
- The repo is built for GPU training and includes distributed support through utils/dist_utils.py and Mamba’s distributed helpers.
- Checkpointing is explicit, so the main data flow is not only forward/backward passes but also save/resume across experiments.
- This matters for architecture diagrams because training is not a single-process script; it is a configurable distributed pipeline.
12. Outputs and artifacts
- The main outputs are trained checkpoints, logs, and optional visualizations.
- figure/ contains documentation images, not runtime assets.
- The repo also includes release-style pretrained weights referenced from the README, which implies reproducible experiment loading is a first-class flow.
13. What to show in an architecture diagram
- Show a thin experiment entry layer at the top, feeding config-driven builders.
- Show dataset loaders and transforms on one side, model construction on the other, and training/evaluation runners in the middle.
- Show the model internals as: point cloud → ordering/tokenization → Mamba blocks/selective scan → prediction head.
- Show native extensions and Mamba CUDA/Triton code as performance-critical lower layers underneath the Python model code.
Main entry points: builder.py builder · point_mamba_scan.py PointMamba · config.py config · build.py dataset build
Components 27
Entry
Script entry points
- main.py · Primary training and evaluation entrypoint
main.py - main_vis.py · Visualization and inspection entrypoint
main_vis.py
Config
Experiment definitions and registry-driven setup
- parser · Command-line and experiment argument parsing
utils/parser.py - config · Configuration loading and experiment wiring
utils/config.py - registry · Registry used to resolve datasets and models from config
utils/registry.py - pretrain.yaml · Pretraining experiment definition
cfgs/pretrain.yaml - finetune_modelnet.yaml · ModelNet40 finetuning experiment definition
cfgs/finetune_modelnet.yaml - ModelNet40.yaml · ModelNet40 dataset split and preprocessing config
cfgs/dataset_configs/ModelNet40.yaml
Data
Point-cloud datasets and preprocessing
- dataset build · Builds active dataset and split from config
datasets/build.py - transforms · Point-cloud augmentation and preprocessing pipeline
datasets/data_transforms.py - point I/O · Low-level point-cloud file reading and writing
datasets/io.py
Model
PointMamba architecture and builders
- model build · Builds the active architecture from config
models/build.py - PointMamba · Main point-cloud sequence model
models/point_mamba_scan.py - Hilbert order · Geometric ordering and tokenization via space-filling curves
models/hilbert.py - scan blocks · Mamba-style scan blocks for sequence modeling
models/block_scan.py - block · Reusable model block components
models/block.py
Runtime
Training loops and experiment services
- pretrain loop · Pretraining orchestration and optimization
tools/runner_pretrain.py - finetune loop · Finetuning and evaluation orchestration
tools/runner_finetune.py - builder · Assembles datasets, models, optimizers, and schedulers
tools/builder.py - checkpoint · Checkpoint save and resume support
utils/checkpoint.py - distributed · Distributed training utilities
utils/dist_utils.py - logging · Experiment logging and metric reporting
utils/logger.py
Native
Performance-critical Mamba and CUDA/Triton code
- selective scan · Interface to Mamba selective-scan computation
mamba/mamba_ssm/ops/selective_scan_interface.py - Mamba block · Core Mamba sequence module used by PointMamba
mamba/mamba_ssm/modules/mamba_simple.py - CUDA scan · Compiled selective-scan CUDA/C++ implementation
mamba/csrc/selective_scan/selective_scan.cpp - Chamfer · Native Chamfer distance extension
extensions/chamfer_dist/chamfer_cuda.cpp - EMD · Earth Mover's Distance extension wrapper
extensions/emd/emd.py
Connections 31
- main.py → parser: args · Parse runtime and experiment arguments
- main.py → builder: run · Launch the configured experiment pipeline
- main_vis.py → builder: inspect · Reuse the builder for visualization workflows
- parser → config: load · Turn CLI arguments into resolved config
- pretrain.yaml → config: define · Provide pretraining experiment settings
- finetune_modelnet.yaml → config: define · Provide finetuning experiment settings
- ModelNet40.yaml → config: define · Provide dataset-specific settings
- config → registry: resolve · Use registry-based assembly for components
- builder → dataset build: dataset · Construct the active dataset pipeline
- builder → model build: model · Construct the active model architecture
- builder → pretrain loop: pretrain · Hand off to the pretraining runner when configured
- builder → finetune loop: finetune · Hand off to the finetuning runner when configured
- dataset build → registry: lookup · Resolve dataset classes from config
- dataset build → transforms: prep · Attach point-cloud preprocessing and augmentation
- dataset build → point I/O: read · Load point-cloud data from storage
- model build → registry: lookup · Resolve model components from config
- model build → PointMamba: instantiate · Build the PointMamba backbone
- PointMamba → Hilbert order: order · Convert point clouds into ordered token sequences
- PointMamba → scan blocks: encode · Apply scan-based Mamba encoder blocks
- scan blocks → block: compose · Reuse common block components
- scan blocks → selective scan: scan · Invoke selective-scan sequence operations
- selective scan → Mamba block: core · Use the vendored Mamba sequence module
- Mamba block → CUDA scan: kernel · Back the sequence module with native CUDA/C++ operators
- pretrain loop → checkpoint: save · Persist and resume pretraining state
- finetune loop → checkpoint: save · Persist and resume finetuning state
- pretrain loop → distributed: dist · Coordinate distributed training
- finetune loop → distributed: dist · Coordinate distributed training
- pretrain loop → logging: log · Record metrics and experiment status
- finetune loop → logging: log · Record metrics and experiment status
- PointMamba → Chamfer: loss/metric · Optional native point-cloud distance path
- PointMamba → EMD: loss/metric · Optional native point-cloud distance path