{"record":{"id":"c0e2accadd40b2c6","repo":"Lightning-AI/pytorch-lightning","slug":"found-invalid-table-kwargs-key-key-this-is-alr","errorCode":null,"errorMessage":"Found invalid table_kwargs key: {key}. This is already a positional argument of the Profiler.","messagePattern":"Found invalid table_kwargs key: (.+?)\\. This is already a positional argument of the Profiler\\.","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/profilers/pytorch.py","lineNumber":324,"sourceCode":"        self.function_events: Optional[EventList] = None\n        self._lightning_module: Optional[LightningModule] = None  # set by ProfilerConnector\n        self._register: Optional[RegisterRecordFunction] = None\n        self._parent_profiler: Optional[AbstractContextManager] = None\n        self._recording_map: dict[str, record_function] = {}\n        self._start_action_name: Optional[str] = None\n        self._schedule: Optional[ScheduleWrapper] = None\n\n        if _KINETO_AVAILABLE:\n            self._init_kineto(profiler_kwargs)\n\n        if self._sort_by_key not in self.AVAILABLE_SORT_KEYS:\n            raise MisconfigurationException(\n                f\"Found sort_by_key: {self._sort_by_key}. Should be within {self.AVAILABLE_SORT_KEYS}. \"\n            )\n\n        for key in self._table_kwargs:\n            if key in {\"sort_by\", \"row_limit\"}:\n                raise KeyError(\n                    f\"Found invalid table_kwargs key: {key}. This is already a positional argument of the Profiler.\"\n                )\n            valid_table_keys = set(inspect.signature(EventList.table).parameters.keys()) - {\n                \"self\",\n                \"sort_by\",\n                \"row_limit\",\n            }\n            if key not in valid_table_keys:\n                raise KeyError(f\"Found invalid table_kwargs key: {key}. Should be within {valid_table_keys}.\")\n\n    def _init_kineto(self, profiler_kwargs: Any) -> None:\n        has_schedule = \"schedule\" in profiler_kwargs\n        self._has_on_trace_ready = \"on_trace_ready\" in profiler_kwargs\n\n        schedule = profiler_kwargs.get(\"schedule\", None)\n        if schedule is not None:\n            if not callable(schedule):\n                raise MisconfigurationException(f\"Schedule should be a callable. Found: {schedule}\")","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/profilers/pytorch.py#L306-L342","documentation":"PyTorchProfiler passes table_kwargs through to torch.autograd.EventList.table, whose sort_by and row_limit are already dedicated positional/keyword parameters of the profiler itself. Supplying either key inside table_kwargs raises KeyError to avoid conflicting double specification.","triggerScenarios":"PyTorchProfiler(table_kwargs={\"sort_by\": \"cpu_time\"}) or PyTorchProfiler(table_kwargs={\"row_limit\": 20}).","commonSituations":"Copy-pasting a torch.profiler.table(...) kwargs dict into Lightning's table_kwargs; assuming the profiler table function accepts the same arguments directly.","solutions":["Pass sort_by via the profiler's sort_by_key argument and row_limit via the profiler's row_limit argument instead of table_kwargs","Remove 'sort_by' and 'row_limit' entries from the table_kwargs dict","Use only keys accepted by EventList.table for remaining entries"],"exampleFix":"# before\nprofiler = PyTorchProfiler(table_kwargs={\"sort_by\": \"cpu_time\", \"row_limit\": 10})\n\n# after\nprofiler = PyTorchProfiler(sort_by_key=\"cpu_time\", row_limit=10)","handlingStrategy":"validation","validationCode":"table_kwargs.pop(\"sort_by\", None)\ntable_kwargs.pop(\"row_limit\", None)\nassert not {\"sort_by\", \"row_limit\"} & table_kwargs.keys()","typeGuard":null,"tryCatchPattern":"try:\n    PyTorchProfiler(table_kwargs=kwargs)\nexcept KeyError as e:\n    kwargs.pop(e.args[0].split(':')[1].strip().strip('`'), None)\n    PyTorchProfiler(table_kwargs=kwargs)","preventionTips":["Pass sort_by/row_limit as top-level profiler arguments","Keep table_kwargs limited to EventList.table parameters","Document in config schemas which keys go where"],"tags":["profiler","invalid-argument","kwargs","pytorch-lightning"],"backgroundTag":"invalid-argument-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}