{"record":{"id":"3e25eb0185bfcc1e","repo":"facebookresearch/detectron2","slug":"lr-factor-func-requires-base-lr","errorCode":null,"errorMessage":"lr_factor_func requires base_lr","messagePattern":"lr_factor_func requires base_lr","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"detectron2/solver/build.py","lineNumber":202,"sourceCode":"        defaults[\"lr\"] = base_lr\n    if weight_decay is not None:\n        defaults[\"weight_decay\"] = weight_decay\n    bias_overrides = {}\n    if bias_lr_factor is not None and bias_lr_factor != 1.0:\n        # NOTE: unlike Detectron v1, we now by default make bias hyperparameters\n        # exactly the same as regular weights.\n        if base_lr is None:\n            raise ValueError(\"bias_lr_factor requires base_lr\")\n        bias_overrides[\"lr\"] = base_lr * bias_lr_factor\n    if weight_decay_bias is not None:\n        bias_overrides[\"weight_decay\"] = weight_decay_bias\n    if len(bias_overrides):\n        if \"bias\" in overrides:\n            raise ValueError(\"Conflicting overrides for 'bias'\")\n        overrides[\"bias\"] = bias_overrides\n    if lr_factor_func is not None:\n        if base_lr is None:\n            raise ValueError(\"lr_factor_func requires base_lr\")\n    norm_module_types = (\n        torch.nn.BatchNorm1d,\n        torch.nn.BatchNorm2d,\n        torch.nn.BatchNorm3d,\n        torch.nn.SyncBatchNorm,\n        # NaiveSyncBatchNorm inherits from BatchNorm2d\n        torch.nn.GroupNorm,\n        torch.nn.InstanceNorm1d,\n        torch.nn.InstanceNorm2d,\n        torch.nn.InstanceNorm3d,\n        torch.nn.LayerNorm,\n        torch.nn.LocalResponseNorm,\n    )\n    params: List[Dict[str, Any]] = []\n    memo: Set[torch.nn.parameter.Parameter] = set()\n    for module_name, module in model.named_modules():\n        for module_param_name, value in module.named_parameters(recurse=False):\n            if not value.requires_grad:","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/facebookresearch/detectron2/blob/a2f4a8771ab77e8411c26b27f24f9489a28a2453/detectron2/solver/build.py#L184-L220","documentation":"An lr_factor_func (per-module LR multiplier function) needs the base LR to scale parameters; if base_lr is None the multiplier cannot be applied, so get_default_optimizer_params raises.","triggerScenarios":"Passing lr_factor_func (e.g. LRDetectionHeadMultiplier or LingUNetMultipliers) to build_optimizer while base_lr is None.","commonSituations":"Custom optimizers that set per-module LR factors via overrides instead of SOLVER.BASE_LR, leaving base_lr unset.","solutions":["Pass base_lr=cfg.SOLVER.BASE_LR to build_optimizer/get_default_optimizer_params","Set cfg.SOLVER.BASE_LR in the config","Remove lr_factor_func if per-module scaling is not needed"],"exampleFix":"# before\nbuild_optimizer(cfg, model, lr_factor_func=lr_multiplier)\n# after\nbuild_optimizer(cfg, model, base_lr=cfg.SOLVER.BASE_LR, lr_factor_func=lr_multiplier)","handlingStrategy":"validation","validationCode":"if lr_factor_func is not None:\n    assert base_lr is not None, 'lr_factor_func requires base_lr'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass base_lr whenever using per-module LR functions","Wire cfg.SOLVER.BASE_LR through custom build_optimizer wrappers"],"tags":["detectron2","optimizer","solver"],"backgroundTag":"missing-required-parameter","analyzedSha":"a2f4a8771ab77e8411c26b27f24f9489a28a2453","analyzedAt":"2026-08-27T12:08:21.260Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}