open-mmlab/mmdetection · error · NotImplementedError
If you want to reduce GPU memory usage,
Error message
If you want to reduce GPU memory usage, please install fairscale by executing the following command: pip install fairscale.
What it means
Raised when DetrTransformerEncoder has num_cp > 0 but fairscale is not installed. The encoder layers are wrapped with fairscale's checkpoint_wrapper to trade compute for GPU memory; without the package this is impossible.
Source
Thrown at mmdet/models/layers/transformer/detr_layers.py:54
init_cfg: OptConfigType = None) -> None:
super().__init__(init_cfg=init_cfg)
self.num_layers = num_layers
self.layer_cfg = layer_cfg
self.num_cp = num_cp
assert self.num_cp <= self.num_layers
self._init_layers()
def _init_layers(self) -> None:
"""Initialize encoder layers."""
self.layers = ModuleList([
DetrTransformerEncoderLayer(**self.layer_cfg)
for _ in range(self.num_layers)
])
if self.num_cp > 0:
if checkpoint_wrapper is None:
raise NotImplementedError(
'If you want to reduce GPU memory usage, \
please install fairscale by executing the \
following command: pip install fairscale.')
for i in range(self.num_cp):
self.layers[i] = checkpoint_wrapper(self.layers[i])
self.embed_dims = self.layers[0].embed_dims
def forward(self, query: Tensor, query_pos: Tensor,
key_padding_mask: Tensor, **kwargs) -> Tensor:
"""Forward function of encoder.
Args:
query (Tensor): Input queries of encoder, has shape
(bs, num_queries, dim).
query_pos (Tensor): The positional embeddings of the queries, has
shape (bs, num_queries, dim).
key_padding_mask (Tensor): The `key_padding_mask` of `self_attn`View on GitHub (pinned to cfd5d3a985)
Solutions
- pip install fairscale
- Or remove/zero num_cp in the encoder config
Example fix
# before num_cp=6, fairscale not installed # after pip install fairscale # or set num_cp=0
Defensive patterns
Strategy: validation
Validate before calling
if cfg.get('num_cp', 0) > 0:
import fairscale # raises ImportError early with a clear message Prevention
- Keep fairscale in the env when memory-saving configs are used
- CI smoke-test model builds to catch env mismatches
When it happens
Trigger: Config with with_cp=True or num_cp>0 on a DETR transformer encoder while fairscale is absent from the environment.
Common situations: Using memory-saving configs on machines without fairscale; upgrading mmdet versions where the checkpointing path changed.
Related errors
- If you want to reduce GPU memory usage,
- If you want to reduce GPU memory usage,
- imagecorruptions is not installed
- albumentations is not installed
- DETR do not build sampler.
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/82172860e387b3a4.
Report an issue: GitHub.