Repository navigation
Fix AdvancedProfiler.__reduce__ dump_stats state loss and SimpleProfiler(extended=False) empty summary crash - #22053
Open
deep1blue wants to merge 1 commit into
Conversation
…ler(extended=False) empty summary crash Signed-off-by: Parth Vadera <parthvadera@gmail.com>
deep1blue
requested review from
ethanwharris,
justusschock and
tchaton
as code owners
October 24, 2026 08:00
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes two self-discovered profiler edge-case bugs in
lightning.pytorch.profilers:AdvancedProfiler.__reduce__silently resetsdump_stats=TruetoFalse(src/lightning/pytorch/profilers/advanced.py):AdvancedProfiler.__reduce__returns(self.__class__, (), {...})socProfile.Profileobjects do not raiseTypeErrorduring pickling/deepcopy (e.g., when cloning the trainer/callbacks or spawning worker processes).__init__is invoked with()(wheredump_stats=Falseby default) and the returned state dictionary omitted"dump_stats": self.dump_stats, anycopy.deepcopy(profiler)orpickle.loads(pickle.dumps(profiler))silently resetprofiler.dump_statsfromTrueback toFalse, preventing.proffiles from being written indescribe()."dump_stats": self.dump_statsto the__reduce__state dictionary preservesdump_statsacross pickling anddeepcopy.SimpleProfiler(extended=False).summary()raisesValueError: max() iterable argument is emptywhen no actions have been recorded (src/lightning/pytorch/profilers/simple.py):SimpleProfiler.summary(), theif self.extended:branch guardsmax(len(k) for k in self.recorded_durations)withif len(self.recorded_durations) > 0:, returning an empty report header when called before any actions are recorded.else:branch (extended=False) omitted that guard and unconditionally calledmax(len(k) for k in self.recorded_durations), raisingValueError: max() iterable argument is emptyifsummary()ordescribe()is called on an emptySimpleProfiler(extended=False).else:withelif len(self.recorded_durations) > 0:makesSimpleProfiler(extended=False)consistent withSimpleProfiler(extended=True).Testing
Acknowledgements
Credit to the Lightning AI team and contributors (
@Borda,@carmocca,@awaelchli,@ajstewart,@bhimrajyadav) for the design and maintenance ofSimpleProfilerandAdvancedProfiler.