Lightning-AI/pytorch-lightning · error · KeyError
Found invalid table_kwargs key
Error message
Found invalid table_kwargs key: {key}. Should be within {valid_table_keys}. What it means
After excluding 'sort_by' and 'row_limit', remaining table_kwargs keys are validated against the signature of torch.autograd.EventList.table. Any key not in that signature raises KeyError, since it would be silently ignored or crash later when passed through.
Solutions
- Inspect allowed keys: import inspect, torch; print(inspect.signature(torch.autograd.EventList.table).parameters.keys()) and use only those
- Upgrade/downgrade Lightning or PyTorch so the kwarg set matches what you pass
- Drop the unsupported key if it's not essential
Example fix
# before
profiler = PyTorchProfiler(table_kwargs={"n_cols": 5}) # invalid key
# after
profiler = PyTorchProfiler(table_kwargs={"max_src_column_width": 100}) # real EventList.table kwarg Defensive patterns
Strategy: validation
Validate before calling
import inspect, torch
valid = set(inspect.signature(torch.autograd.EventList.table).parameters) - {"self", "sort_by", "row_limit"}
bad = set(table_kwargs) - valid
assert not bad, f"invalid table_kwargs: {bad}" Type guard
def valid_table_kwargs(kwargs: dict) -> dict:
import inspect, torch
valid = set(inspect.signature(torch.autograd.EventList.table).parameters) - {"self", "sort_by", "row_limit"}
return {k: v for k, v in kwargs.items() if k in valid} Prevention
- Validate kwargs against EventList.table's signature for your PyTorch version
- Pin Lightning and PyTorch versions in CI to avoid signature drift
- Filter unknown keys from config files before passing them
When it happens
Trigger: PyTorchProfiler(table_kwargs={"max_group_row_limit": 5}) where the key is not a parameter of EventList.table in your installed PyTorch version.
Common situations: Using kwargs valid for a different PyTorch version's EventList.table (signature changed across releases); guessing kwarg names from other profiling APIs.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Found invalid table_kwargs key
- Found sort_by_key: . Should be within .
- You requested to find
- Attempting to stop recording an action
- f"`gradient_clip_algorithm
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/b877a1c8de6b4132.
Report an issue: GitHub.
Appendix: source
Thrown at src/lightning/pytorch/profilers/pytorch.py:333
self._init_kineto(profiler_kwargs)
if self._sort_by_key not in self.AVAILABLE_SORT_KEYS:
raise MisconfigurationException(
f"Found sort_by_key: {self._sort_by_key}. Should be within {self.AVAILABLE_SORT_KEYS}. "
)
for key in self._table_kwargs:
if key in {"sort_by", "row_limit"}:
raise KeyError(
f"Found invalid table_kwargs key: {key}. This is already a positional argument of the Profiler."
)
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._scheduleView on GitHub (pinned to 9fed5c27d2)