# sail-sg/treemeshgpt architecture

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

- Interactive diagram: https://gitdiagram.com/sail-sg/treemeshgpt
- Repository: https://github.com/sail-sg/treemeshgpt

## Overview

TreeMeshGPT turns a dense input mesh into a conditioned point cloud, then autoregressively generates an artistic mesh. Its training path tokenizes meshes into tree-ordered edge/target sequences, loads prepared samples, and optimizes the same model family. The graph preserves both workflows and the point-cloud encoder and transformer layers. Training-data preparation is documented and partially shown; relationships are limited to explicit calls, imports listed in the source index, and README statements.

Main entry points: [`inference.py`](https://github.com/sail-sg/treemeshgpt/blob/main/inference.py) (Inference runner), [`train.py`](https://github.com/sail-sg/treemeshgpt/blob/main/train.py) (Training entry), [`model/treemeshgpt_train.py`](https://github.com/sail-sg/treemeshgpt/blob/main/model/treemeshgpt_train.py) (Training model), [`tokenizer.py`](https://github.com/sail-sg/treemeshgpt/blob/main/tokenizer.py) (Tree tokenizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["Mesh generation"]
  node_inference["Inference runner<br/>[inference.py]"]
  node_mesh_prep["Mesh preparation<br/>[inference.py]"]
  node_point_sampling["Point sampling<br/>[fns.py]"]
end

subgraph group_training_data["Training data"]
  node_mesh_utils["Mesh utilities<br/>[fns.py]"]
  node_tokenizer["Tree tokenizer<br/>[tokenizer.py]"]
  node_preprocess_runner["Tokenization runner"]
  node_dataset["Edge dataset"]
end

subgraph group_model["Model internals"]
  node_train_model["Training model"]
  node_inference_model["Generation model"]
  node_cloud_encoder["Point cloud encoder<br/>[pc_encoder.py]"]
  node_train_transformer["Training transformer"]
  node_inference_transformer["Inference transformer"]
end

subgraph group_training["Model training"]
  node_train_entry["Training entry<br/>[train.py]"]
  node_trainer["Training loop<br/>[trainer.py]"]
end

node_user(("User"))
node_input_mesh["Input mesh"]
node_generated_mesh["Generated mesh"]
node_tokenized_samples["Tokenized samples"]
node_checkpoint["Model checkpoint"]

node_user -->|"runs"| node_inference
node_input_mesh -->|"supplies"| node_inference
node_inference -->|"prepares"| node_mesh_prep
node_mesh_prep -.->|"samples points"| node_point_sampling
node_inference -->|"generates with"| node_inference_model
node_inference -.->|"loads"| node_checkpoint
node_inference -->|"writes"| node_generated_mesh
node_user -->|"runs"| node_preprocess_runner
node_preprocess_runner -->|"invokes"| node_tokenizer
node_tokenizer -->|"uses"| node_mesh_utils
node_tokenizer -->|"produces"| node_tokenized_samples
node_tokenized_samples -->|"loads"| node_dataset
node_user -->|"runs"| node_train_entry
node_train_entry -->|"creates"| node_dataset
node_train_entry -->|"creates"| node_train_model
node_train_entry -->|"configures"| node_trainer
node_trainer -.->|"reads batches"| node_dataset
node_trainer -.->|"optimizes"| node_train_model
node_train_model -->|"encodes point cloud"| node_cloud_encoder
node_train_model -->|"uses"| node_train_transformer
node_inference_model -->|"encodes point cloud"| node_cloud_encoder
node_inference_model -->|"uses"| node_inference_transformer

click node_inference "https://github.com/sail-sg/treemeshgpt/blob/main/inference.py"
click node_mesh_prep "https://github.com/sail-sg/treemeshgpt/blob/main/inference.py"
click node_point_sampling "https://github.com/sail-sg/treemeshgpt/blob/main/fns.py"
click node_mesh_utils "https://github.com/sail-sg/treemeshgpt/blob/main/fns.py"
click node_tokenizer "https://github.com/sail-sg/treemeshgpt/blob/main/tokenizer.py"
click node_preprocess_runner "https://github.com/sail-sg/treemeshgpt/blob/main/train_create_pkl.py"
click node_dataset "https://github.com/sail-sg/treemeshgpt/blob/main/train_dataloader.py"
click node_train_entry "https://github.com/sail-sg/treemeshgpt/blob/main/train.py"
click node_trainer "https://github.com/sail-sg/treemeshgpt/blob/main/trainer.py"
click node_train_model "https://github.com/sail-sg/treemeshgpt/blob/main/model/treemeshgpt_train.py"
click node_inference_model "https://github.com/sail-sg/treemeshgpt/blob/main/model/treemeshgpt_inference.py"
click node_cloud_encoder "https://github.com/sail-sg/treemeshgpt/blob/main/model/pc_encoder.py"
click node_train_transformer "https://github.com/sail-sg/treemeshgpt/blob/main/model/custom_transformers_training.py"
click node_inference_transformer "https://github.com/sail-sg/treemeshgpt/blob/main/model/custom_transformers_inference.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_inference,node_mesh_prep,node_point_sampling,node_user toneBlue
class node_mesh_utils,node_tokenizer,node_preprocess_runner,node_dataset toneAmber
class node_train_model,node_inference_model,node_cloud_encoder,node_train_transformer,node_inference_transformer toneMint
class node_train_entry,node_trainer toneRose
class node_input_mesh,node_generated_mesh,node_tokenized_samples,node_checkpoint toneIndigo
```

## Components

### Mesh generation

- [Inference runner](https://github.com/sail-sg/treemeshgpt/blob/main/inference.py): `inference.py`
- [Mesh preparation](https://github.com/sail-sg/treemeshgpt/blob/main/inference.py): `inference.py`
- [Point sampling](https://github.com/sail-sg/treemeshgpt/blob/main/fns.py): `fns.py`

### Training data

- [Mesh utilities](https://github.com/sail-sg/treemeshgpt/blob/main/fns.py): `fns.py`
- [Tree tokenizer](https://github.com/sail-sg/treemeshgpt/blob/main/tokenizer.py): `tokenizer.py`
- [Tokenization runner](https://github.com/sail-sg/treemeshgpt/blob/main/train_create_pkl.py): `train_create_pkl.py`
- [Edge dataset](https://github.com/sail-sg/treemeshgpt/blob/main/train_dataloader.py): `train_dataloader.py`

### Model internals

- [Training model](https://github.com/sail-sg/treemeshgpt/blob/main/model/treemeshgpt_train.py): `model/treemeshgpt_train.py`
- [Generation model](https://github.com/sail-sg/treemeshgpt/blob/main/model/treemeshgpt_inference.py): `model/treemeshgpt_inference.py`
- [Point cloud encoder](https://github.com/sail-sg/treemeshgpt/blob/main/model/pc_encoder.py): `model/pc_encoder.py`
- [Training transformer](https://github.com/sail-sg/treemeshgpt/blob/main/model/custom_transformers_training.py): `model/custom_transformers_training.py`
- [Inference transformer](https://github.com/sail-sg/treemeshgpt/blob/main/model/custom_transformers_inference.py): `model/custom_transformers_inference.py`

### Model training

- [Training entry](https://github.com/sail-sg/treemeshgpt/blob/main/train.py): `train.py`
- [Training loop](https://github.com/sail-sg/treemeshgpt/blob/main/trainer.py): `trainer.py`

### Other components

- **User**
- **Input mesh**
- **Generated mesh**
- **Tokenized samples**
- **Model checkpoint**

## Connections

- User → Inference runner: runs (evidence: `README.md`)
- Input mesh → Inference runner: supplies (evidence: `README.md`)
- Inference runner → Mesh preparation: prepares (evidence: `inference.py`)
- Mesh preparation → Point sampling: samples points (evidence: `inference.py`)
- Inference runner → Generation model: generates with (evidence: `inference.py`)
- Inference runner → Model checkpoint: loads
- Inference runner → Generated mesh: writes (evidence: `inference.py`)
- User → Tokenization runner: runs (evidence: `README.md`)
- Tokenization runner → Tree tokenizer: invokes (evidence: `train_create_pkl.py`)
- Tree tokenizer → Mesh utilities: uses (evidence: `tokenizer.py`)
- Tree tokenizer → Tokenized samples: produces (evidence: `tokenizer.py`)
- Tokenized samples → Edge dataset: loads (evidence: `train_dataloader.py`)
- User → Training entry: runs (evidence: `README.md`)
- Training entry → Edge dataset: creates (evidence: `train.py`)
- Training entry → Training model: creates (evidence: `train.py`)
- Training entry → Training loop: configures (evidence: `train.py`)
- Training loop → Edge dataset: reads batches
- Training loop → Training model: optimizes
- Training model → Point cloud encoder: encodes point cloud (evidence: `model/treemeshgpt_train.py`)
- Training model → Training transformer: uses (evidence: `model/treemeshgpt_train.py`)
- Generation model → Point cloud encoder: encodes point cloud (evidence: `model/treemeshgpt_inference.py`)
- Generation model → Inference transformer: uses (evidence: `model/treemeshgpt_inference.py`)
