Skip to content

Instantly share code, notes, and snippets.

@tlrmchlsmth
Created July 15, 2024 19:41
Show Gist options
  • Save tlrmchlsmth/fee30cb75a80ff8841736f08f908abb1 to your computer and use it in GitHub Desktop.
Save tlrmchlsmth/fee30cb75a80ff8841736f08f908abb1 to your computer and use it in GitHub Desktop.
import pdb
import traceback
import inspect
def function_in_stack(function_name):
stack = traceback.extract_stack()
for frame in stack:
if frame.name == function_name:
return True
return False
# Using this to insert breakpoints when running on actual data.
# Useful when e.g. comparing hidden states for correctness.
# If profile_run is in our stack trace, we're profiling for KV cache usage
# If initialize_cache is in our stack trace, we're creating CUDA graphs.
if not function_in_stack("profile_run") or function_in_stack("initialize_cache"):
pdb.set_trace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment