# lmd0311/pointmamba architecture

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

- Interactive diagram: https://gitdiagram.com/lmd0311/pointmamba
- Repository: https://github.com/lmd0311/pointmamba

## Overview

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: [`tools/builder.py`](https://github.com/lmd0311/pointmamba/blob/main/tools/builder.py) (builder), [`models/point_mamba_scan.py`](https://github.com/lmd0311/pointmamba/blob/main/models/point_mamba_scan.py) (PointMamba), [`utils/config.py`](https://github.com/lmd0311/pointmamba/blob/main/utils/config.py) (config), [`datasets/build.py`](https://github.com/lmd0311/pointmamba/blob/main/datasets/build.py) (dataset build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry"]
  node_main_py(("main.py<br/>entry script<br/>[main.py]"))
  node_main_vis_py(("main_vis.py<br/>viz entry<br/>[main_vis.py]"))
end

subgraph group_config["Config"]
  node_parser_py["parser<br/>cli parse<br/>[parser.py]"]
  node_config_py["config<br/>[config.py]"]
  node_registry_py["registry<br/>[registry.py]"]
  node_pretrain_yaml["pretrain.yaml<br/>task config<br/>[pretrain.yaml]"]
  node_finetune_yaml["finetune_modelnet.yaml<br/>task config"]
  node_modelnet_yaml["ModelNet40.yaml<br/>dataset config<br/>[ModelNet40.yaml]"]
end

subgraph group_data["Data"]
  node_dataset_build_py["dataset build<br/>dataset factory<br/>[build.py]"]
  node_data_transforms_py["transforms<br/>point augment<br/>[data_transforms.py]"]
  node_io_py["point I/O<br/>point io<br/>[io.py]"]
end

subgraph group_model["Model"]
  node_model_build_py["model build<br/>model factory<br/>[build.py]"]
  node_point_mamba_scan_py["PointMamba<br/>point encoder"]
  node_hilbert_py["Hilbert order<br/>token ordering<br/>[hilbert.py]"]
  node_block_scan_py["scan blocks<br/>encoder blocks<br/>[block_scan.py]"]
  node_block_py["block<br/>[block.py]"]
end

subgraph group_runtime["Runtime"]
  node_runner_pretrain_py["pretrain loop<br/>training loop<br/>[runner_pretrain.py]"]
  node_runner_finetune_py["finetune loop<br/>training loop<br/>[runner_finetune.py]"]
  node_builder_py["builder<br/>[builder.py]"]
  node_checkpoint_py["checkpoint<br/>state save<br/>[checkpoint.py]"]
  node_dist_utils_py["distributed<br/>runtime helper<br/>[dist_utils.py]"]
  node_logger_py["logging<br/>runtime helper<br/>[logger.py]"]
end

subgraph group_native["Native"]
  node_selective_scan_interface_py["selective scan<br/>ssm core"]
  node_mamba_simple_py["Mamba block<br/>ssm module<br/>[mamba_simple.py]"]
  node_selective_scan_cpp["CUDA scan<br/>native kernel<br/>[selective_scan.cpp]"]
  node_chamfer_cuda_cpp["Chamfer<br/>cuda ext<br/>[chamfer_cuda.cpp]"]
  node_emd_py["EMD<br/>cuda ext<br/>[emd.py]"]
end

node_main_py -->|"args"| node_parser_py
node_main_py -->|"run"| node_builder_py
node_main_vis_py -->|"inspect"| node_builder_py
node_parser_py -->|"load"| node_config_py
node_pretrain_yaml -->|"define"| node_config_py
node_finetune_yaml -->|"define"| node_config_py
node_modelnet_yaml -->|"define"| node_config_py
node_config_py -->|"resolve"| node_registry_py
node_builder_py -->|"dataset"| node_dataset_build_py
node_builder_py -->|"model"| node_model_build_py
node_builder_py -->|"pretrain"| node_runner_pretrain_py
node_builder_py -->|"finetune"| node_runner_finetune_py
node_dataset_build_py -->|"lookup"| node_registry_py
node_dataset_build_py -->|"prep"| node_data_transforms_py
node_dataset_build_py -->|"read"| node_io_py
node_model_build_py -->|"lookup"| node_registry_py
node_model_build_py -->|"instantiate"| node_point_mamba_scan_py
node_point_mamba_scan_py -->|"order"| node_hilbert_py
node_point_mamba_scan_py -->|"encode"| node_block_scan_py
node_block_scan_py -->|"compose"| node_block_py
node_block_scan_py -->|"scan"| node_selective_scan_interface_py
node_selective_scan_interface_py -->|"core"| node_mamba_simple_py
node_mamba_simple_py -->|"kernel"| node_selective_scan_cpp
node_runner_pretrain_py -->|"save"| node_checkpoint_py
node_runner_finetune_py -->|"save"| node_checkpoint_py
node_runner_pretrain_py -->|"dist"| node_dist_utils_py
node_runner_finetune_py -->|"dist"| node_dist_utils_py
node_runner_pretrain_py -->|"log"| node_logger_py
node_runner_finetune_py -->|"log"| node_logger_py
node_point_mamba_scan_py -.->|"loss/metric"| node_chamfer_cuda_cpp
node_point_mamba_scan_py -.->|"loss/metric"| node_emd_py

click node_main_py "https://github.com/lmd0311/pointmamba/blob/main/main.py"
click node_main_vis_py "https://github.com/lmd0311/pointmamba/blob/main/main_vis.py"
click node_parser_py "https://github.com/lmd0311/pointmamba/blob/main/utils/parser.py"
click node_config_py "https://github.com/lmd0311/pointmamba/blob/main/utils/config.py"
click node_registry_py "https://github.com/lmd0311/pointmamba/blob/main/utils/registry.py"
click node_pretrain_yaml "https://github.com/lmd0311/pointmamba/blob/main/cfgs/pretrain.yaml"
click node_finetune_yaml "https://github.com/lmd0311/pointmamba/blob/main/cfgs/finetune_modelnet.yaml"
click node_modelnet_yaml "https://github.com/lmd0311/pointmamba/blob/main/cfgs/dataset_configs/ModelNet40.yaml"
click node_dataset_build_py "https://github.com/lmd0311/pointmamba/blob/main/datasets/build.py"
click node_data_transforms_py "https://github.com/lmd0311/pointmamba/blob/main/datasets/data_transforms.py"
click node_io_py "https://github.com/lmd0311/pointmamba/blob/main/datasets/io.py"
click node_model_build_py "https://github.com/lmd0311/pointmamba/blob/main/models/build.py"
click node_point_mamba_scan_py "https://github.com/lmd0311/pointmamba/blob/main/models/point_mamba_scan.py"
click node_hilbert_py "https://github.com/lmd0311/pointmamba/blob/main/models/hilbert.py"
click node_block_scan_py "https://github.com/lmd0311/pointmamba/blob/main/models/block_scan.py"
click node_block_py "https://github.com/lmd0311/pointmamba/blob/main/models/block.py"
click node_selective_scan_interface_py "https://github.com/lmd0311/pointmamba/blob/main/mamba/mamba_ssm/ops/selective_scan_interface.py"
click node_mamba_simple_py "https://github.com/lmd0311/pointmamba/blob/main/mamba/mamba_ssm/modules/mamba_simple.py"
click node_selective_scan_cpp "https://github.com/lmd0311/pointmamba/blob/main/mamba/csrc/selective_scan/selective_scan.cpp"
click node_runner_pretrain_py "https://github.com/lmd0311/pointmamba/blob/main/tools/runner_pretrain.py"
click node_runner_finetune_py "https://github.com/lmd0311/pointmamba/blob/main/tools/runner_finetune.py"
click node_builder_py "https://github.com/lmd0311/pointmamba/blob/main/tools/builder.py"
click node_checkpoint_py "https://github.com/lmd0311/pointmamba/blob/main/utils/checkpoint.py"
click node_dist_utils_py "https://github.com/lmd0311/pointmamba/blob/main/utils/dist_utils.py"
click node_logger_py "https://github.com/lmd0311/pointmamba/blob/main/utils/logger.py"
click node_chamfer_cuda_cpp "https://github.com/lmd0311/pointmamba/blob/main/extensions/chamfer_dist/chamfer_cuda.cpp"
click node_emd_py "https://github.com/lmd0311/pointmamba/blob/main/extensions/emd/emd.py"

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_main_py,node_main_vis_py toneBlue
class node_parser_py,node_config_py,node_registry_py,node_pretrain_yaml,node_finetune_yaml,node_modelnet_yaml toneAmber
class node_dataset_build_py,node_data_transforms_py,node_io_py toneMint
class node_model_build_py,node_point_mamba_scan_py,node_hilbert_py,node_block_scan_py,node_block_py toneRose
class node_runner_pretrain_py,node_runner_finetune_py,node_builder_py,node_checkpoint_py,node_dist_utils_py,node_logger_py toneIndigo
class node_selective_scan_interface_py,node_mamba_simple_py,node_selective_scan_cpp,node_chamfer_cuda_cpp,node_emd_py toneTeal
```

## Components

### Entry

Script entry points

- [main.py](https://github.com/lmd0311/pointmamba/blob/main/main.py): entry script · Primary training and evaluation entrypoint · `main.py`
- [main_vis.py](https://github.com/lmd0311/pointmamba/blob/main/main_vis.py): viz entry · Visualization and inspection entrypoint · `main_vis.py`

### Config

Experiment definitions and registry-driven setup

- [parser](https://github.com/lmd0311/pointmamba/blob/main/utils/parser.py): cli parse · Command-line and experiment argument parsing · `utils/parser.py`
- [config](https://github.com/lmd0311/pointmamba/blob/main/utils/config.py): config load · Configuration loading and experiment wiring · `utils/config.py`
- [registry](https://github.com/lmd0311/pointmamba/blob/main/utils/registry.py): factory registry · Registry used to resolve datasets and models from config · `utils/registry.py`
- [pretrain.yaml](https://github.com/lmd0311/pointmamba/blob/main/cfgs/pretrain.yaml): task config · Pretraining experiment definition · `cfgs/pretrain.yaml`
- [finetune_modelnet.yaml](https://github.com/lmd0311/pointmamba/blob/main/cfgs/finetune_modelnet.yaml): task config · ModelNet40 finetuning experiment definition · `cfgs/finetune_modelnet.yaml`
- [ModelNet40.yaml](https://github.com/lmd0311/pointmamba/blob/main/cfgs/dataset_configs/ModelNet40.yaml): dataset config · ModelNet40 dataset split and preprocessing config · `cfgs/dataset_configs/ModelNet40.yaml`

### Data

Point-cloud datasets and preprocessing

- [dataset build](https://github.com/lmd0311/pointmamba/blob/main/datasets/build.py): dataset factory · Builds active dataset and split from config · `datasets/build.py`
- [transforms](https://github.com/lmd0311/pointmamba/blob/main/datasets/data_transforms.py): point augment · Point-cloud augmentation and preprocessing pipeline · `datasets/data_transforms.py`
- [point I/O](https://github.com/lmd0311/pointmamba/blob/main/datasets/io.py): point io · Low-level point-cloud file reading and writing · `datasets/io.py`

### Model

PointMamba architecture and builders

- [model build](https://github.com/lmd0311/pointmamba/blob/main/models/build.py): model factory · Builds the active architecture from config · `models/build.py`
- [PointMamba](https://github.com/lmd0311/pointmamba/blob/main/models/point_mamba_scan.py): point encoder · Main point-cloud sequence model · `models/point_mamba_scan.py`
- [Hilbert order](https://github.com/lmd0311/pointmamba/blob/main/models/hilbert.py): token ordering · Geometric ordering and tokenization via space-filling curves · `models/hilbert.py`
- [scan blocks](https://github.com/lmd0311/pointmamba/blob/main/models/block_scan.py): encoder blocks · Mamba-style scan blocks for sequence modeling · `models/block_scan.py`
- [block](https://github.com/lmd0311/pointmamba/blob/main/models/block.py): reusable block · Reusable model block components · `models/block.py`

### Runtime

Training loops and experiment services

- [pretrain loop](https://github.com/lmd0311/pointmamba/blob/main/tools/runner_pretrain.py): training loop · Pretraining orchestration and optimization · `tools/runner_pretrain.py`
- [finetune loop](https://github.com/lmd0311/pointmamba/blob/main/tools/runner_finetune.py): training loop · Finetuning and evaluation orchestration · `tools/runner_finetune.py`
- [builder](https://github.com/lmd0311/pointmamba/blob/main/tools/builder.py): experiment builder · Assembles datasets, models, optimizers, and schedulers · `tools/builder.py`
- [checkpoint](https://github.com/lmd0311/pointmamba/blob/main/utils/checkpoint.py): state save · Checkpoint save and resume support · `utils/checkpoint.py`
- [distributed](https://github.com/lmd0311/pointmamba/blob/main/utils/dist_utils.py): runtime helper · Distributed training utilities · `utils/dist_utils.py`
- [logging](https://github.com/lmd0311/pointmamba/blob/main/utils/logger.py): runtime helper · Experiment logging and metric reporting · `utils/logger.py`

### Native

Performance-critical Mamba and CUDA/Triton code

- [selective scan](https://github.com/lmd0311/pointmamba/blob/main/mamba/mamba_ssm/ops/selective_scan_interface.py): ssm core · Interface to Mamba selective-scan computation · `mamba/mamba_ssm/ops/selective_scan_interface.py`
- [Mamba block](https://github.com/lmd0311/pointmamba/blob/main/mamba/mamba_ssm/modules/mamba_simple.py): ssm module · Core Mamba sequence module used by PointMamba · `mamba/mamba_ssm/modules/mamba_simple.py`
- [CUDA scan](https://github.com/lmd0311/pointmamba/blob/main/mamba/csrc/selective_scan/selective_scan.cpp): native kernel · Compiled selective-scan CUDA/C++ implementation · `mamba/csrc/selective_scan/selective_scan.cpp`
- [Chamfer](https://github.com/lmd0311/pointmamba/blob/main/extensions/chamfer_dist/chamfer_cuda.cpp): cuda ext · Native Chamfer distance extension · `extensions/chamfer_dist/chamfer_cuda.cpp`
- [EMD](https://github.com/lmd0311/pointmamba/blob/main/extensions/emd/emd.py): cuda ext · Earth Mover's Distance extension wrapper · `extensions/emd/emd.py`

## Connections

- 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
