{"record":{"id":"e9439e2e2c982422","repo":"Lightning-AI/pytorch-lightning","slug":"fabric-launch-needs-to-be-a-callable-but-g","errorCode":null,"errorMessage":"`Fabric.launch(...)` needs to be a callable, but got {function}. HINT: do `.launch(your_fn)` instead of `.launch(your_fn())`","messagePattern":"`Fabric\\.launch\\(\\.\\.\\.\\)` needs to be a callable, but got (.+?)\\. HINT: do `\\.launch\\(your_fn\\)` instead of `\\.launch\\(your_fn\\(\\)\\)`","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/fabric.py","lineNumber":996,"sourceCode":"\n        Example::\n\n            def train_function(fabric):\n                model, optimizer = fabric.setup(model, optimizer)\n                # ... 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","sourceCodeStart":978,"sourceCodeEnd":1014,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/fabric.py#L978-L1014","documentation":"fabric.launch(function) expects a function reference, detected via callable(). Passing the result of calling the function — .launch(train()) — yields a non-callable return value and raises TypeError with a hint showing the correct pattern.","triggerScenarios":"fabric.launch(main()) instead of fabric.launch(main); also passing a class instance without __call__, a string name, or a non-callable object.","commonSituations":"Paren typo when adapting quickstart examples; passing an object thinking launch accepts a callable instance's method result.","solutions":["Remove the parentheses: .launch(main)","Verify with callable(main) before passing"],"exampleFix":"# before\nfabric.launch(train())\n# after\nfabric.launch(train)","handlingStrategy":"type-guard","validationCode":"assert callable(train_fn), 'pass the function reference, not its result'","typeGuard":"def is_launchable(fn):\n    return callable(fn)","tryCatchPattern":null,"preventionTips":["Write .launch(name) with no parentheses; linters flag call-in-argument"],"tags":["lightning","fabric","launch","callable","typo"],"backgroundTag":"called-function-instead-of-reference","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}