{"record":{"id":"d28cb8d89b3d2a16","repo":"open-mmlab/mmdetection","slug":"if-you-want-to-reduce-gpu-memory-usage-d28cb8","errorCode":null,"errorMessage":"If you want to reduce GPU memory usage,                     please install fairscale by executing the                     following command: pip install fairscale.","messagePattern":"If you want to reduce GPU memory usage,                     please install fairscale by executing the                     following command: pip install fairscale\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"mmdet/models/layers/transformer/grounding_dino_layers.py","lineNumber":160,"sourceCode":"\n    def _init_layers(self) -> None:\n        \"\"\"Initialize encoder layers.\"\"\"\n        self.layers = ModuleList([\n            DeformableDetrTransformerEncoderLayer(**self.layer_cfg)\n            for _ in range(self.num_layers)\n        ])\n        self.text_layers = ModuleList([\n            DetrTransformerEncoderLayer(**self.text_layer_cfg)\n            for _ in range(self.num_layers)\n        ])\n        self.fusion_layers = ModuleList([\n            SingleScaleBiAttentionBlock(**self.fusion_layer_cfg)\n            for _ in range(self.num_layers)\n        ])\n        self.embed_dims = self.layers[0].embed_dims\n        if self.num_cp > 0:\n            if checkpoint_wrapper is None:\n                raise NotImplementedError(\n                    'If you want to reduce GPU memory usage, \\\n                    please install fairscale by executing the \\\n                    following command: pip install fairscale.')\n            for i in range(self.num_cp):\n                self.layers[i] = checkpoint_wrapper(self.layers[i])\n                self.fusion_layers[i] = checkpoint_wrapper(\n                    self.fusion_layers[i])\n\n    def forward(self,\n                query: Tensor,\n                query_pos: Tensor,\n                key_padding_mask: Tensor,\n                spatial_shapes: Tensor,\n                level_start_index: Tensor,\n                valid_ratios: Tensor,\n                memory_text: Tensor = None,\n                text_attention_mask: Tensor = None,\n                pos_text: Tensor = None,","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/layers/transformer/grounding_dino_layers.py#L142-L178","documentation":"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.","triggerScenarios":"Configuring Grounding DINO with num_cp>0 in the encoder cfg while `checkpoint_wrapper` failed to import because fairscale is not installed.","commonSituations":"Running Grounding DINO training configs tuned for low-memory GPUs in a bare environment; docker images missing optional deps.","solutions":["pip install fairscale","Or set num_cp=0"],"exampleFix":"# before\nnum_cp=1  # no fairscale installed\n# after\npip install fairscale  # or num_cp=0","handlingStrategy":"validation","validationCode":"if num_cp > 0 and importlib.util.find_spec('fairscale') is None:\n    raise RuntimeError('install fairscale or set num_cp=0')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin optional deps in requirements","Document fairscale requirement in custom config headers"],"tags":["mmdet","grounding-dino","fairscale","dependency","gpu-memory"],"backgroundTag":"missing-dependency","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}