Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:OpenGVLab InternVL Segmentation Train

From Leeroopedia


Knowledge Sources
Domains Training, Segmentation, Distributed Systems
Last Updated 2026-02-07 14:00 GMT

Overview

Main training script for training semantic segmentation models using the MMSegmentation framework with InternVL-specific custom components.

Description

This script serves as the core training entry point for all InternVL segmentation experiments. The parse_args() function accepts CLI arguments for config file path, work directory, checkpoint loading/resuming, GPU configuration, random seed, deterministic mode, and distributed launcher settings. It supports auto-resume for automatically continuing from the latest checkpoint.

The main() function orchestrates the full training pipeline:

  1. Loads the MMSeg Config and applies CLI overrides
  2. Determines work directory (CLI > config > derived from config filename)
  3. Initializes distributed training via the chosen launcher (pytorch/slurm/mpi) or falls back to single-GPU mode
  4. Reverts SyncBatchNorm to standard BN for non-distributed (DP) training
  5. Sets up logging, environment info collection, and random seed initialization with optional deterministic mode
  6. Builds the segmentor model and datasets from config
  7. Saves checkpoint metadata (mmseg version, config, CLASSES, PALETTE)
  8. Calls train_segmentor() with validation support

The script imports mmcv_custom and mmseg_custom modules at the top level to trigger registration of InternVL-specific components (custom backbones, decode heads, dataset classes, optimizer constructors) with the MMSeg registries.

Usage

Use this script as the entry point for training segmentation models with InternVL backbones, invoked via dist_train.sh or slurm_train.sh shell scripts.

Code Reference

Source Location

Signature

def parse_args(): ...
def main(): ...

Import

# Standalone script:
# python segmentation/train.py <config> --work-dir <output_dir>

I/O Contract

Inputs

Name Type Required Description
config str Yes Path to the MMSeg training config file
--work-dir str No Directory for saving logs and model checkpoints
--load-from str No Checkpoint to load initial weights from
--resume-from str No Checkpoint to resume training from
--launcher str No Distributed launcher: none/pytorch/slurm/mpi
--seed int No Random seed for reproducibility
--deterministic flag No Enable deterministic CUDNN operations
--auto-resume flag No Auto-resume from latest checkpoint

Outputs

Name Type Description
work_dir directory Checkpoints, logs, and config dumps
checkpoints .pth files Model checkpoints with metadata
log_file .log Timestamped training log

Usage Examples

Basic Usage

# Single-GPU training:
# python segmentation/train.py configs/intern_vit_6b.py --work-dir work_dirs/internvit

# Distributed training:
# bash dist_train.sh configs/intern_vit_6b.py 8

# Resume training:
# python segmentation/train.py configs/intern_vit_6b.py --resume-from work_dirs/latest.pth

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment