{"record":{"id":"fc8e29955b1155a3","repo":"Lightning-AI/pytorch-lightning","slug":"you-cannot-set-both-auto-wrapper-callable-and-a","errorCode":null,"errorMessage":"You cannot set both `auto_wrapper_callable` and `activation_checkpointing_policy`. Choose one","messagePattern":"You cannot set both `auto_wrapper_callable` and `activation_checkpointing_policy`\\. Choose one","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/strategies/xla_fsdp.py","lineNumber":659,"sourceCode":"        # this is not transformer specific despite the name\n        policy = partial(transformer_auto_wrap_policy, transformer_layer_cls=policy)\n    kwargs[\"auto_wrap_policy\"] = policy\n    return kwargs\n\n\ndef _activation_checkpointing_auto_wrapper(policy: _POLICY_SET, module: Module, *args: Any, **kwargs: Any) -> Module:\n    from torch_xla.distributed.fsdp import XlaFullyShardedDataParallel as XLAFSDP\n    from torch_xla.distributed.fsdp import checkpoint_module\n\n    module = checkpoint_module(module) if isinstance(module, tuple(policy)) else module\n    return XLAFSDP(module, *args, **kwargs)\n\n\ndef _activation_checkpointing_kwargs(policy: Optional[_POLICY_SET], kwargs: dict) -> dict:\n    if not policy:\n        return kwargs\n    if \"auto_wrapper_callable\" in kwargs:\n        raise ValueError(\n            \"You cannot set both `auto_wrapper_callable` and `activation_checkpointing_policy`. Choose one\"\n        )\n    if not isinstance(policy, set):\n        raise TypeError(\n            f\"`activation_checkpointing_policy` must be a set, found {policy}. You can try defining and\"\n            \" passing `auto_wrapper_callable` instead.\"\n        )\n    auto_wrapper_callable = partial(_activation_checkpointing_auto_wrapper, policy)\n    kwargs[\"auto_wrapper_callable\"] = auto_wrapper_callable\n    return kwargs\n\n\nclass _XLAFSDPBackwardSyncControl(_BackwardSyncControl):\n    @override\n    def no_backward_sync(self, module: Module, enabled: bool) -> AbstractContextManager:\n        \"\"\"Blocks gradient synchronization inside the :class:`~torch_xla.distributed.fsdp.XlaFullyShardedDataParallel`\n        wrapper.\"\"\"\n        if not enabled:","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/strategies/xla_fsdp.py#L641-L677","documentation":"Raised by _activation_checkpointing_kwargs (called from XLAFSDPStrategy kwargs parsing) when the user sets both activation_checkpointing_policy and an auto_wrapper_callable in the FSDP kwargs. The policy is implemented by building an auto_wrapper callable internally, so an explicit auto_wrapper_callable conflicts with it and only one may be provided.","triggerScenarios":"XLAFSDPStrategy(activation_checkpointing_policy={...}, auto_wrapper_callable=my_wrapper) or passing auto_wrapper_callable through XLAFSDPStrategy(..., **fsdp_kwargs) alongside the policy.","commonSituations":"Copy-pasting FSDP configs from other examples that include auto_wrapper_callable and then adding the Lightning convenience argument activation_checkpointing_policy; migrating from DDP/FSDP strategies where both were combined.","solutions":["Remove auto_wrapper_callable and keep activation_checkpointing_policy if you just want selective activation checkpointing","Alternatively drop activation_checkpointing_policy and implement the behavior entirely inside your own auto_wrapper_callable"],"exampleFix":"# before\nstrategy = XLAFSDPStrategy(\n    activation_checkpointing_policy={MyBlock},\n    auto_wrapper_callable=partial(apply_activation_checkpointing, check_fn=lambda m: isinstance(m, MyBlock)),\n)\n\n# after\nstrategy = XLAFSDPStrategy(activation_checkpointing_policy={MyBlock})","handlingStrategy":"validation","validationCode":"kwargs = dict(fsdp_kwargs)\nif 'auto_wrapper_callable' in kwargs:\n    assert not activation_checkpointing_policy, 'choose one of auto_wrapper_callable or activation_checkpointing_policy'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep FSDP kwargs in one place and document which convenience args are active","Linter rule: forbid specifying both keys in strategy config dicts"],"tags":["xla","fsdp","activation-checkpointing","config-conflict","lightning-fabric"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}