{"record":{"id":"5de22dae91c9cafb","repo":"Lightning-AI/pytorch-lightning","slug":"fabric-launch-function-function-needs-to-take","errorCode":null,"errorMessage":"`Fabric.launch(function={function})` needs to take at least one argument. The launcher will pass in the `Fabric` object so you can use it inside the function.","messagePattern":"`Fabric\\.launch\\(function=(.+?)\\)` needs to take at least one argument\\. The launcher will pass in the `Fabric` object so you can use it inside the function\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/fabric.py","lineNumber":1001,"sourceCode":"                # ... training code ...\n\n            fabric = Fabric(accelerator=\"tpu\", devices=8)\n            fabric.launch(train_function)\n\n        \"\"\"\n        if _is_using_cli():\n            raise RuntimeError(\n                \"This script was launched through the CLI, and processes have already been created. Calling \"\n                \" `.launch()` again is not allowed.\"\n            )\n        if function is not _do_nothing:\n            if not callable(function):\n                raise TypeError(\n                    f\"`Fabric.launch(...)` needs to be a callable, but got {function}.\"\n                    \" HINT: do `.launch(your_fn)` instead of `.launch(your_fn())`\"\n                )\n            if not inspect.signature(function).parameters:\n                raise TypeError(\n                    f\"`Fabric.launch(function={function})` needs to take at least one argument. The launcher will\"\n                    \" pass in the `Fabric` object so you can use it inside the function.\"\n                )\n        elif isinstance(self.strategy.launcher, (_MultiProcessingLauncher, _XLALauncher)):\n            raise TypeError(\n                f\"To spawn processes with the `{type(self.strategy).__name__}` strategy, `.launch()` needs to be called\"\n                \" with a function that contains the code to launch in processes.\"\n            )\n        return self._wrap_and_launch(function, self, *args, **kwargs)\n\n    def _filter_kwargs_for_callback(self, method: Callable, kwargs: dict[str, Any]) -> dict[str, Any]:\n        \"\"\"Filter keyword arguments to only include those that match the callback method's signature.\n\n        Args:\n            method: The callback method to inspect\n            kwargs: The keyword arguments to filter\n\n        Returns:","sourceCodeStart":983,"sourceCodeEnd":1019,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/fabric.py#L983-L1019","documentation":"The function passed to fabric.launch() must accept at least one parameter because the launcher injects the Fabric instance as the first argument (fn(fabric, *args, **kwargs)). inspect.signature(function).parameters is empty for zero-arg functions, so they fail with TypeError.","triggerScenarios":"fabric.launch(lambda: train()) or def train(): ... — any zero-parameter callable. Note: builtins without introspectable signatures can also trip inspect.signature.","commonSituations":"Wrapping an existing training function that used a global Fabric object; using functools.partial with no remaining free parameters.","solutions":["Add a fabric parameter: def train(fabric): ... and use it inside instead of globals","For lambdas: .launch(lambda fabric: train(fabric))"],"exampleFix":"# before\ndef train(): ...\nfabric.launch(train)\n# after\ndef train(fabric): ...\nfabric.launch(train)","handlingStrategy":"validation","validationCode":"import inspect\nassert inspect.signature(train_fn).parameters, 'launch fn must accept fabric'","typeGuard":"import inspect\ndef takes_fabric(fn):\n    try:\n        return len(inspect.signature(fn).parameters) > 0\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":null,"preventionTips":["Standardize: every launched function's first parameter is named fabric"],"tags":["lightning","fabric","launch","signature"],"backgroundTag":"callback-signature-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}