# facebookresearch/convnext-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/facebookresearch/convnext-v2
- Repository: https://github.com/facebookresearch/convnext-v2

## Overview

ConvNeXt V2 is a PyTorch image-recognition model family with two principal workflows: FCMAE self-supervised pretraining and supervised fine-tuning/evaluation. Both begin with user-supplied images and produce trained or evaluated model checkpoints; pretraining uses a masked sparse-convolution autoencoder, while fine-tuning uses the classifier backbone. The README documents multiple model sizes and pretrained checkpoints. Edges reflect shown calls, the SOURCE INDEX, or README statements; unsampled details are not inferred.

Main entry points: [`main_finetune.py`](https://github.com/facebookresearch/convnext-v2/blob/main/main_finetune.py) (Fine-tune runner), [`main_pretrain.py`](https://github.com/facebookresearch/convnext-v2/blob/main/main_pretrain.py) (Pretrain runner), [`models/fcmae.py`](https://github.com/facebookresearch/convnext-v2/blob/main/models/fcmae.py) (FCMAE), [`models/convnextv2.py`](https://github.com/facebookresearch/convnext-v2/blob/main/models/convnextv2.py) (ConvNeXt V2 classifier)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Training entrypoints"]
  node_pretrain["Pretrain runner<br/>[main_pretrain.py]"]
  node_finetune["Fine-tune runner<br/>[main_finetune.py]"]
end

subgraph group_data["Image data"]
  node_dataset_builder["Dataset transforms<br/>[datasets.py]"]
  node_image_data[("Image datasets")]
end

subgraph group_models["Model architecture"]
  node_fcmae["FCMAE<br/>[fcmae.py]"]
  node_sparse_backbone["Sparse backbone"]
  node_classifier["ConvNeXt V2 classifier<br/>[convnextv2.py]"]
  node_model_layers["Normalization and GRN<br/>[utils.py]"]
end

subgraph group_runtime["Training runtime"]
  node_pretrain_engine["Pretrain epoch<br/>[engine_pretrain.py]"]
  node_finetune_engine["Fine-tune and eval<br/>[engine_finetune.py]"]
  node_optimizer["Optimizer factory<br/>[optim_factory.py]"]
  node_runtime_utils["Distributed, logging, checkpoints<br/>[utils.py]"]
end

node_user(("Researcher"))
node_checkpoint[("Pretrained weights and checkpoints")]
node_trained_model["Trained model"]

node_user -->|"starts pretraining"| node_pretrain
node_user -->|"starts fine-tuning or evaluation"| node_finetune
node_pretrain -->|"loads images"| node_image_data
node_finetune -->|"builds datasets"| node_dataset_builder
node_dataset_builder -->|"reads and transforms"| node_image_data
node_pretrain -->|"constructs model"| node_fcmae
node_pretrain -->|"trains epochs"| node_pretrain_engine
node_pretrain_engine -->|"computes masked loss"| node_fcmae
node_fcmae -->|"uses encoder"| node_sparse_backbone
node_fcmae -->|"uses backbone components"| node_classifier
node_sparse_backbone -->|"uses sparse layers"| node_model_layers
node_classifier -->|"uses model layers"| node_model_layers
node_finetune -->|"constructs model"| node_classifier
node_finetune -->|"runs training or evaluation"| node_finetune_engine
node_finetune_engine -->|"computes predictions"| node_classifier
node_finetune -->|"creates optimizer"| node_optimizer
node_pretrain -->|"builds parameter groups"| node_optimizer
node_pretrain -->|"initializes distributed runtime"| node_runtime_utils
node_finetune -->|"loads and saves checkpoints"| node_runtime_utils
node_runtime_utils -->|"loads weights"| node_checkpoint
node_checkpoint -.->|"initializes fine-tuning"| node_finetune
node_pretrain -->|"produces checkpoint"| node_trained_model
node_finetune -->|"produces checkpoint"| node_trained_model

click node_pretrain "https://github.com/facebookresearch/convnext-v2/blob/main/main_pretrain.py"
click node_finetune "https://github.com/facebookresearch/convnext-v2/blob/main/main_finetune.py"
click node_pretrain_engine "https://github.com/facebookresearch/convnext-v2/blob/main/engine_pretrain.py"
click node_finetune_engine "https://github.com/facebookresearch/convnext-v2/blob/main/engine_finetune.py"
click node_dataset_builder "https://github.com/facebookresearch/convnext-v2/blob/main/datasets.py"
click node_fcmae "https://github.com/facebookresearch/convnext-v2/blob/main/models/fcmae.py"
click node_sparse_backbone "https://github.com/facebookresearch/convnext-v2/blob/main/models/convnextv2_sparse.py"
click node_classifier "https://github.com/facebookresearch/convnext-v2/blob/main/models/convnextv2.py"
click node_model_layers "https://github.com/facebookresearch/convnext-v2/blob/main/models/utils.py"
click node_optimizer "https://github.com/facebookresearch/convnext-v2/blob/main/optim_factory.py"
click node_runtime_utils "https://github.com/facebookresearch/convnext-v2/blob/main/utils.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_pretrain,node_finetune toneBlue
class node_dataset_builder,node_image_data,node_checkpoint toneAmber
class node_fcmae,node_sparse_backbone,node_classifier,node_model_layers toneMint
class node_pretrain_engine,node_finetune_engine,node_optimizer,node_runtime_utils toneRose
class node_user,node_trained_model toneIndigo
```

## Components

### Training entrypoints

- [Pretrain runner](https://github.com/facebookresearch/convnext-v2/blob/main/main_pretrain.py): `main_pretrain.py`
- [Fine-tune runner](https://github.com/facebookresearch/convnext-v2/blob/main/main_finetune.py): `main_finetune.py`

### Image data

- [Dataset transforms](https://github.com/facebookresearch/convnext-v2/blob/main/datasets.py): `datasets.py`
- **Image datasets**

### Model architecture

- [FCMAE](https://github.com/facebookresearch/convnext-v2/blob/main/models/fcmae.py): `models/fcmae.py`
- [Sparse backbone](https://github.com/facebookresearch/convnext-v2/blob/main/models/convnextv2_sparse.py): `models/convnextv2_sparse.py`
- [ConvNeXt V2 classifier](https://github.com/facebookresearch/convnext-v2/blob/main/models/convnextv2.py): `models/convnextv2.py`
- [Normalization and GRN](https://github.com/facebookresearch/convnext-v2/blob/main/models/utils.py): `models/utils.py`

### Training runtime

- [Pretrain epoch](https://github.com/facebookresearch/convnext-v2/blob/main/engine_pretrain.py): `engine_pretrain.py`
- [Fine-tune and eval](https://github.com/facebookresearch/convnext-v2/blob/main/engine_finetune.py): `engine_finetune.py`
- [Optimizer factory](https://github.com/facebookresearch/convnext-v2/blob/main/optim_factory.py): `optim_factory.py`
- [Distributed, logging, checkpoints](https://github.com/facebookresearch/convnext-v2/blob/main/utils.py): `utils.py`

### Other components

- **Researcher**
- **Pretrained weights and checkpoints**
- **Trained model**

## Connections

- Researcher → Pretrain runner: starts pretraining (evidence: `README.md`)
- Researcher → Fine-tune runner: starts fine-tuning or evaluation (evidence: `README.md`)
- Pretrain runner → Image datasets: loads images (evidence: `main_pretrain.py`)
- Fine-tune runner → Dataset transforms: builds datasets (evidence: `main_finetune.py`)
- Dataset transforms → Image datasets: reads and transforms (evidence: `datasets.py`)
- Pretrain runner → FCMAE: constructs model (evidence: `main_pretrain.py`)
- Pretrain runner → Pretrain epoch: trains epochs (evidence: `main_pretrain.py`)
- Pretrain epoch → FCMAE: computes masked loss (evidence: `engine_pretrain.py`)
- FCMAE → Sparse backbone: uses encoder (evidence: `models/fcmae.py`)
- FCMAE → ConvNeXt V2 classifier: uses backbone components (evidence: `models/fcmae.py`)
- Sparse backbone → Normalization and GRN: uses sparse layers (evidence: `models/convnextv2_sparse.py`)
- ConvNeXt V2 classifier → Normalization and GRN: uses model layers (evidence: `models/convnextv2.py`)
- Fine-tune runner → ConvNeXt V2 classifier: constructs model (evidence: `main_finetune.py`)
- Fine-tune runner → Fine-tune and eval: runs training or evaluation (evidence: `main_finetune.py`)
- Fine-tune and eval → ConvNeXt V2 classifier: computes predictions (evidence: `engine_finetune.py`)
- Fine-tune runner → Optimizer factory: creates optimizer (evidence: `main_finetune.py`)
- Pretrain runner → Optimizer factory: builds parameter groups (evidence: `main_pretrain.py`)
- Pretrain runner → Distributed, logging, checkpoints: initializes distributed runtime (evidence: `main_pretrain.py`)
- Fine-tune runner → Distributed, logging, checkpoints: loads and saves checkpoints (evidence: `main_finetune.py`)
- Distributed, logging, checkpoints → Pretrained weights and checkpoints: loads weights (evidence: `utils.py`)
- Pretrained weights and checkpoints → Fine-tune runner: initializes fine-tuning (evidence: `README.md`)
- Pretrain runner → Trained model: produces checkpoint (evidence: `main_pretrain.py`)
- Fine-tune runner → Trained model: produces checkpoint (evidence: `main_finetune.py`)
