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
GroundingDinoTransformerEncoder raises NotImplementedError when num_cp > 0 but fairscale is missing. Both the encoder layers and the text-image fusion layers would need checkpoint_wrapper from fairscale.
Source
Thrown at mmdet/models/layers/transformer/grounding_dino_layers.py:160
def _init_layers(self) -> None:
"""Initialize encoder layers."""
self.layers = ModuleList([
DeformableDetrTransformerEncoderLayer(**self.layer_cfg)
for _ in range(self.num_layers)
])
self.text_layers = ModuleList([
DetrTransformerEncoderLayer(**self.text_layer_cfg)
for _ in range(self.num_layers)
])
self.fusion_layers = ModuleList([
SingleScaleBiAttentionBlock(**self.fusion_layer_cfg)
for _ in range(self.num_layers)
])
self.embed_dims = self.layers[0].embed_dims
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.fusion_layers[i] = checkpoint_wrapper(
self.fusion_layers[i])
def forward(self,
query: Tensor,
query_pos: Tensor,
key_padding_mask: Tensor,
spatial_shapes: Tensor,
level_start_index: Tensor,
valid_ratios: Tensor,
memory_text: Tensor = None,
text_attention_mask: Tensor = None,
pos_text: Tensor = None,View on GitHub (pinned to cfd5d3a985)
Solutions
- pip install fairscale
- Or set num_cp=0
Example fix
# before num_cp=1 # no fairscale installed # after pip install fairscale # or num_cp=0
Defensive patterns
Strategy: validation
Validate before calling
if num_cp > 0 and importlib.util.find_spec('fairscale') is None:
raise RuntimeError('install fairscale or set num_cp=0') Prevention
- Pin optional deps in requirements
- Document fairscale requirement in custom config headers
When it happens
Trigger: Configuring Grounding DINO with num_cp>0 in the encoder cfg while `checkpoint_wrapper` failed to import because fairscale is not installed.
Common situations: Running Grounding DINO training configs tuned for low-memory GPUs in a bare environment; docker images missing optional deps.
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
- There is not post_norm in {name}
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/d28cb8d89b3d2a16.
Report an issue: GitHub.