Lightning-AI/pytorch-lightning · error · TypeError

`Fabric.launch(...)` needs to be a callable, but got {functi

Error message

`Fabric.launch(...)` needs to be a callable, but got {function}. HINT: do `.launch(your_fn)` instead of `.launch(your_fn())`

What it means

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.

Source

Thrown at src/lightning/fabric/fabric.py:996

        Example::

            def train_function(fabric):
                model, optimizer = fabric.setup(model, optimizer)
                # ... training code ...

            fabric = Fabric(accelerator="tpu", devices=8)
            fabric.launch(train_function)

        """
        if _is_using_cli():
            raise RuntimeError(
                "This script was launched through the CLI, and processes have already been created. Calling "
                " `.launch()` again is not allowed."
            )
        if function is not _do_nothing:
            if not callable(function):
                raise TypeError(
                    f"`Fabric.launch(...)` needs to be a callable, but got {function}."
                    " HINT: do `.launch(your_fn)` instead of `.launch(your_fn())`"
                )
            if not inspect.signature(function).parameters:
                raise TypeError(
                    f"`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."
                )
        elif isinstance(self.strategy.launcher, (_MultiProcessingLauncher, _XLALauncher)):
            raise TypeError(
                f"To spawn processes with the `{type(self.strategy).__name__}` strategy, `.launch()` needs to be called"
                " with a function that contains the code to launch in processes."
            )
        return self._wrap_and_launch(function, self, *args, **kwargs)

    def _filter_kwargs_for_callback(self, method: Callable, kwargs: dict[str, Any]) -> dict[str, Any]:
        """Filter keyword arguments to only include those that match the callback method's signature.

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Remove the parentheses: .launch(main)
  2. Verify with callable(main) before passing

Example fix

# before
fabric.launch(train())
# after
fabric.launch(train)
Defensive patterns

Strategy: type-guard

Validate before calling

assert callable(train_fn), 'pass the function reference, not its result'

Type guard

def is_launchable(fn):
    return callable(fn)

Prevention

When it happens

Trigger: fabric.launch(main()) instead of fabric.launch(main); also passing a class instance without __call__, a string name, or a non-callable object.

Common situations: Paren typo when adapting quickstart examples; passing an object thinking launch accepts a callable instance's method result.

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/e9439e2e2c982422. Report an issue: GitHub.