Lightning-AI/pytorch-lightning · error · MisconfigurationException
Schedule should return a `torch.profiler.ProfilerAction`. Fo
Error message
Schedule should return a `torch.profiler.ProfilerAction`. Found: {action} What it means
_init_kineto probes the user schedule by calling schedule(0) and requires the return value to be a torch.profiler.ProfilerAction enum member. Lightning's ScheduleWrapper relies on ProfilerAction transitions, so a custom callable returning something else (None, string, int) fails validation immediately.
Source
Thrown at src/lightning/pytorch/profilers/pytorch.py:345
valid_table_keys = set(inspect.signature(EventList.table).parameters.keys()) - {
"self",
"sort_by",
"row_limit",
}
if key not in valid_table_keys:
raise KeyError(f"Found invalid table_kwargs key: {key}. Should be within {valid_table_keys}.")
def _init_kineto(self, profiler_kwargs: Any) -> None:
has_schedule = "schedule" in profiler_kwargs
self._has_on_trace_ready = "on_trace_ready" in profiler_kwargs
schedule = profiler_kwargs.get("schedule", None)
if schedule is not None:
if not callable(schedule):
raise MisconfigurationException(f"Schedule should be a callable. Found: {schedule}")
action = schedule(0)
if not isinstance(action, ProfilerAction):
raise MisconfigurationException(
f"Schedule should return a `torch.profiler.ProfilerAction`. Found: {action}"
)
self._default_schedule()
schedule = schedule if has_schedule else self._default_schedule()
self._schedule = ScheduleWrapper(schedule) if schedule is not None else schedule
self._profiler_kwargs["schedule"] = self._schedule
activities = profiler_kwargs.get("activities", None)
self._profiler_kwargs["activities"] = activities or self._default_activities()
self._export_to_flame_graph = profiler_kwargs.get("export_to_flame_graph", False)
self._metric = profiler_kwargs.get("metric", "self_cpu_time_total")
with_stack = profiler_kwargs.get("with_stack", False) or self._export_to_flame_graph
self._profiler_kwargs["with_stack"] = with_stack
@property
def _total_steps(self) -> Union[int, float]:
assert self._schedule is not None
assert self._lightning_module is not NoneView on GitHub (pinned to 9fed5c27d2)
Solutions
- Import from torch.profiler import ProfilerAction and return ProfilerAction members (NONE, WARMUP, RECORD, RECORD_AND_SAVE) for every step input
- Handle all branches of your callable so it never returns None
- Prefer composing torch.profiler.schedule() rather than writing a custom callable
Example fix
# before
profiler = PyTorchProfiler(schedule=lambda step: "WARMUP" if step < 3 else "RECORD") # invalid
# after
from torch.profiler import ProfilerAction
profiler = PyTorchProfiler(
schedule=lambda step: ProfilerAction.WARMUP if step < 3 else ProfilerAction.RECORD_AND_SAVE
) Defensive patterns
Strategy: type-guard
Validate before calling
from torch.profiler import ProfilerAction assert schedule(0) is not None and isinstance(schedule(0), ProfilerAction)
Type guard
def returns_profiler_action(schedule) -> bool:
from torch.profiler import ProfilerAction
try:
return isinstance(schedule(0), ProfilerAction)
except Exception:
return False Prevention
- Import ProfilerAction and return enum members in every branch of custom schedules
- Test custom schedules with schedule(0) before passing to the profiler
- Prefer composing torch.profiler.schedule over custom callables
When it happens
Trigger: Passing a hand-written schedule callable such as lambda step: None or a function returning a string/int instead of torch.profiler.ProfilerAction (e.g. ProfilerAction.WARMUP vs 'WARMUP').
Common situations: Writing a custom schedule without importing torch.profiler.ProfilerAction; returning the enum's name string; early-returning None in one branch of a conditional custom schedule.
Related errors
- Schedule should be a callable. Found: {schedule}
- You are trying to use `ScheduleWrapper` which require kineto
- The PyTorch Profiler default schedule will be overridden as
- You requested to find {num_devices} devices but this machine
- The FSDP strategy can only work with the `FSDPPrecision` plu
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/b8b90d11f95186fb.
Report an issue: GitHub.