Implementation:Facebookresearch Habitat lab BaseILTrainer
| Knowledge Sources | |
|---|---|
| Domains | Embodied_AI, Imitation_Learning |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
BaseILTrainer is an abstract base class for imitation learning (IL) trainers that provides common directory management, checkpoint saving, and evaluation scaffolding for IL-based training algorithms in Habitat.
Description
BaseILTrainer extends BaseTrainer to provide a foundation for all imitation learning trainers. Upon initialization it creates directories for logging, checkpoints, and evaluation results based on the provided configuration. It exposes a configurable flush_secs property for controlling TensorBoard flush intervals and defines abstract methods train, _eval_checkpoint, and load_checkpoint that subclasses must implement. The save_checkpoint method serializes a model state dictionary to the configured checkpoint folder using PyTorch's save mechanism.
Usage
Subclass BaseILTrainer when building a new imitation learning training algorithm. Override the train, _eval_checkpoint, and load_checkpoint methods with the specific training loop, evaluation logic, and checkpoint loading behavior for your IL approach.
Code Reference
Source Location
- Repository: Facebookresearch_Habitat_lab
- File: habitat-baselines/habitat_baselines/common/base_il_trainer.py
- Lines: 20-110
Signature
class BaseILTrainer(BaseTrainer):
device: torch.device
config: "DictConfig"
video_option: List[str]
_flush_secs: int
def __init__(self, config: "DictConfig"):
Import
from habitat_baselines.common.base_il_trainer import BaseILTrainer
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | DictConfig | Yes | Hydra/OmegaConf configuration object containing habitat_baselines IL settings |
Outputs
| Name | Type | Description |
|---|---|---|
| (instance) | BaseILTrainer | Initialized trainer with created directories for logs, checkpoints, and results |
Key Methods
save_checkpoint
def save_checkpoint(self, state_dict: OrderedDict, file_name: str) -> None
Saves a model state dictionary to the configured checkpoint folder.
_eval_checkpoint (abstract)
def _eval_checkpoint(
self,
checkpoint_path: str,
writer: TensorboardWriter,
checkpoint_index: int = 0,
) -> None
Evaluates a single checkpoint. Must be implemented by subclasses.
train (abstract)
def train(self) -> None
Runs the training loop. Must be implemented by subclasses.
load_checkpoint (abstract)
def load_checkpoint(self, checkpoint_path, *args, **kwargs) -> Dict
Loads a checkpoint from disk. Must be implemented by subclasses.
Usage Examples
Basic Usage
from collections import OrderedDict
from habitat_baselines.common.base_il_trainer import BaseILTrainer
from habitat_baselines.common.tensorboard_utils import TensorboardWriter
class MyILTrainer(BaseILTrainer):
def train(self) -> None:
# Custom IL training loop
for epoch in range(100):
loss = self._run_epoch()
state_dict = self.model.state_dict()
self.save_checkpoint(
OrderedDict(state_dict),
f"ckpt_{epoch}.pth"
)
def _eval_checkpoint(self, checkpoint_path, writer, checkpoint_index=0):
ckpt = self.load_checkpoint(checkpoint_path)
# Run evaluation with loaded checkpoint
pass
def load_checkpoint(self, checkpoint_path, *args, **kwargs):
return torch.load(checkpoint_path)
# Instantiate and train
trainer = MyILTrainer(config=my_config)
trainer.train()